[Xquartz-changes] xserver: Branch 'server-1.17-apple' - 399 commits

Jeremy Huddleston jeremyhu at freedesktop.org
Sat Feb 7 14:51:49 PST 2015


Rebased ref, commits from common ancestor:
commit 1298d92e044632b04d5693db7ac695ff709d2183
Author: Jeremy Huddleston Sequoia <jeremyhu at apple.com>
Date:   Sat May 31 13:14:20 2014 -0700

    fb: Revert fb changes that broke XQuartz
    
        http://bugs.freedesktop.org/show_bug.cgi?id=26124
    
    Revert "Use new pixman_glyph_cache_t API that will be in pixman 0.28.0"
    Revert "fb: Fix origin of source picture in fbGlyphs"
    Revert "fb: Publish fbGlyphs and fbUnrealizeGlyph"
    
    This reverts commit 9cbcb5bd6a5360a128d15b77a02d8d3351f74366.
    This reverts commit 983e30361f49a67252d0b5d82630e70724d69dbf.
    This reverts commit 3c2c59eed3c68c0e5a93c38cf01eedad015e3157.

diff --git a/fb/fb.h b/fb/fb.h
index dd91cae..0b3bc95 100644
--- a/fb/fb.h
+++ b/fb/fb.h
@@ -1135,9 +1135,6 @@ extern _X_EXPORT void
 extern _X_EXPORT Bool
  fbPictureInit(ScreenPtr pScreen, PictFormatPtr formats, int nformats);
 
-extern _X_EXPORT void
-fbDestroyGlyphCache(void);
-
 /*
  * fbpixmap.c
  */
diff --git a/fb/fbpict.c b/fb/fbpict.c
index 2ff9ae2..9c4cc42 100644
--- a/fb/fbpict.c
+++ b/fb/fbpict.c
@@ -65,152 +65,6 @@ fbComposite(CARD8 op,
     free_pixman_pict(pDst, dest);
 }
 
-static pixman_glyph_cache_t *glyphCache;
-
-void
-fbDestroyGlyphCache(void)
-{
-    if (glyphCache)
-    {
-	pixman_glyph_cache_destroy (glyphCache);
-	glyphCache = NULL;
-    }
-}
-
-void
-fbUnrealizeGlyph(ScreenPtr pScreen,
-		 GlyphPtr pGlyph)
-{
-    if (glyphCache)
-	pixman_glyph_cache_remove (glyphCache, pGlyph, NULL);
-}
-
-void
-fbGlyphs(CARD8 op,
-	 PicturePtr pSrc,
-	 PicturePtr pDst,
-	 PictFormatPtr maskFormat,
-	 INT16 xSrc,
-	 INT16 ySrc, int nlist,
-	 GlyphListPtr list,
-	 GlyphPtr *glyphs)
-{
-#define N_STACK_GLYPHS 512
-    ScreenPtr pScreen = pDst->pDrawable->pScreen;
-    pixman_glyph_t stack_glyphs[N_STACK_GLYPHS];
-    pixman_glyph_t *pglyphs = stack_glyphs;
-    pixman_image_t *srcImage, *dstImage;
-    int srcXoff, srcYoff, dstXoff, dstYoff;
-    GlyphPtr glyph;
-    int n_glyphs;
-    int x, y;
-    int i, n;
-    int xDst = list->xOff, yDst = list->yOff;
-
-    miCompositeSourceValidate(pSrc);
-    
-    n_glyphs = 0;
-    for (i = 0; i < nlist; ++i)
-	n_glyphs += list[i].len;
-
-    if (!glyphCache)
-	glyphCache = pixman_glyph_cache_create();
-
-    pixman_glyph_cache_freeze (glyphCache);
-    
-    if (n_glyphs > N_STACK_GLYPHS) {
-	if (!(pglyphs = malloc (n_glyphs * sizeof (pixman_glyph_t))))
-	    goto out;
-    }
-    
-    i = 0;
-    x = y = 0;
-    while (nlist--) {
-        x += list->xOff;
-        y += list->yOff;
-        n = list->len;
-        while (n--) {
-	    const void *g;
-
-            glyph = *glyphs++;
-
-	    if (!(g = pixman_glyph_cache_lookup (glyphCache, glyph, NULL))) {
-		pixman_image_t *glyphImage;
-		PicturePtr pPicture;
-		int xoff, yoff;
-
-		pPicture = GetGlyphPicture(glyph, pScreen);
-		if (!pPicture) {
-		    n_glyphs--;
-		    goto next;
-		}
-
-		if (!(glyphImage = image_from_pict(pPicture, FALSE, &xoff, &yoff)))
-		    goto out;
-
-		g = pixman_glyph_cache_insert(glyphCache, glyph, NULL,
-					      glyph->info.x,
-					      glyph->info.y,
-					      glyphImage);
-
-		free_pixman_pict(pPicture, glyphImage);
-
-		if (!g)
-		    goto out;
-	    }
-
-	    pglyphs[i].x = x;
-	    pglyphs[i].y = y;
-	    pglyphs[i].glyph = g;
-	    i++;
-
-	next:
-            x += glyph->info.xOff;
-            y += glyph->info.yOff;
-	}
-	list++;
-    }
-
-    if (!(srcImage = image_from_pict(pSrc, FALSE, &srcXoff, &srcYoff)))
-	goto out;
-
-    if (!(dstImage = image_from_pict(pDst, TRUE, &dstXoff, &dstYoff)))
-	goto out_free_src;
-
-    if (maskFormat) {
-	pixman_format_code_t format;
-	pixman_box32_t extents;
-
-	format = maskFormat->format | (maskFormat->depth << 24);
-
-	pixman_glyph_get_extents(glyphCache, n_glyphs, pglyphs, &extents);
-
-	pixman_composite_glyphs(op, srcImage, dstImage, format,
-				xSrc + srcXoff + extents.x1 - xDst, ySrc + srcYoff + extents.y1 - yDst,
-				extents.x1, extents.y1,
-				extents.x1 + dstXoff, extents.y1 + dstYoff,
-				extents.x2 - extents.x1,
-				extents.y2 - extents.y1,
-				glyphCache, n_glyphs, pglyphs);
-    }
-    else {
-	pixman_composite_glyphs_no_mask(op, srcImage, dstImage,
-					xSrc + srcXoff - xDst, ySrc + srcYoff - yDst,
-					dstXoff, dstYoff,
-					glyphCache, n_glyphs, pglyphs);
-    }
-
-    free_pixman_pict(pDst, dstImage);
-
-out_free_src:
-    free_pixman_pict(pSrc, srcImage);
-
-out:
-    pixman_glyph_cache_thaw(glyphCache);
-    if (pglyphs != stack_glyphs)
-	free(pglyphs);
-}
-
 static pixman_image_t *
 create_solid_fill_image(PicturePtr pict)
 {
@@ -461,8 +315,7 @@ fbPictureInit(ScreenPtr pScreen, PictFormatPtr formats, int nformats)
         return FALSE;
     ps = GetPictureScreen(pScreen);
     ps->Composite = fbComposite;
-    ps->Glyphs = fbGlyphs;
-    ps->UnrealizeGlyph = fbUnrealizeGlyph;
+    ps->Glyphs = miGlyphs;
     ps->CompositeRects = miCompositeRects;
     ps->RasterizeTrapezoid = fbRasterizeTrapezoid;
     ps->AddTraps = fbAddTraps;
diff --git a/fb/fbpict.h b/fb/fbpict.h
index 8b0f59f..110f32d 100644
--- a/fb/fbpict.h
+++ b/fb/fbpict.h
@@ -65,24 +65,11 @@ fbTrapezoids(CARD8 op,
              INT16 xSrc, INT16 ySrc, int ntrap, xTrapezoid * traps);
 
 extern _X_EXPORT void
+
 fbTriangles(CARD8 op,
             PicturePtr pSrc,
             PicturePtr pDst,
             PictFormatPtr maskFormat,
             INT16 xSrc, INT16 ySrc, int ntris, xTriangle * tris);
 
-extern _X_EXPORT void
-fbUnrealizeGlyph(ScreenPtr pScreen,
-		 GlyphPtr pGlyph);
-
-extern _X_EXPORT void
-fbGlyphs(CARD8 op,
-	 PicturePtr pSrc,
-	 PicturePtr pDst,
-	 PictFormatPtr maskFormat,
-	 INT16 xSrc,
-	 INT16 ySrc, int nlist,
-	 GlyphListPtr list,
-	 GlyphPtr *glyphs);
-
 #endif                          /* _FBPICT_H_ */
diff --git a/fb/fbscreen.c b/fb/fbscreen.c
index 71bcc5d..55330fc 100644
--- a/fb/fbscreen.c
+++ b/fb/fbscreen.c
@@ -32,7 +32,6 @@ fbCloseScreen(ScreenPtr pScreen)
     int d;
     DepthPtr depths = pScreen->allowedDepths;
 
-    fbDestroyGlyphCache();
     for (d = 0; d < pScreen->numDepths; d++)
         free(depths[d].vids);
     free(depths);
commit e21b429acf631776d3ebe14c3d5db9fa7f3656d7
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 5099b0f..dd91cae 100644
--- a/fb/fb.h
+++ b/fb/fb.h
@@ -1383,8 +1383,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 8e99cbe..2ff9ae2 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);
@@ -289,20 +284,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)
@@ -321,57 +318,31 @@ create_bits_picture(PicturePtr pict, Bool has_clip, int *xoff, int *yoff)
         if (pict->clientClip)
             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) {
@@ -399,10 +370,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);
@@ -436,8 +405,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;
 
@@ -445,7 +413,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;
@@ -463,19 +431,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 07c2bb05052b9084055ed27e9c3637bfddabea41
Author: Jeremy Huddleston Sequoia <jeremyhu at apple.com>
Date:   Sat Nov 2 11:00:23 2013 -0700

    Use old miTrapezoids and miTriangles routines
    
    Reverts commits:
        788ccb9a8bcf6a4fb4054c507111eec3338fb969
        566f1931ee2916269e164e114bffaf2da1d039d1
    
    http://xquartz.macosforge.org/trac/ticket/525
    
    Signed-off-by: Jeremy Huddleston Sequoia <jeremyhu at apple.com>

diff --git a/fb/fbpict.c b/fb/fbpict.c
index 7a9e46a..8e99cbe 100644
--- a/fb/fbpict.c
+++ b/fb/fbpict.c
@@ -499,10 +499,8 @@ fbPictureInit(ScreenPtr pScreen, PictFormatPtr formats, int nformats)
     ps->UnrealizeGlyph = fbUnrealizeGlyph;
     ps->CompositeRects = miCompositeRects;
     ps->RasterizeTrapezoid = fbRasterizeTrapezoid;
-    ps->Trapezoids = fbTrapezoids;
     ps->AddTraps = fbAddTraps;
     ps->AddTriangles = fbAddTriangles;
-    ps->Triangles = fbTriangles;
 
     return TRUE;
 }
diff --git a/render/mipict.c b/render/mipict.c
index a725104..e14293a 100644
--- a/render/mipict.c
+++ b/render/mipict.c
@@ -575,8 +575,8 @@ miPictureInit(ScreenPtr pScreen, PictFormatPtr formats, int nformats)
     ps->Composite = 0;          /* requires DDX support */
     ps->Glyphs = miGlyphs;
     ps->CompositeRects = miCompositeRects;
-    ps->Trapezoids = 0;
-    ps->Triangles = 0;
+    ps->Trapezoids = miTrapezoids;
+    ps->Triangles = miTriangles;
 
     ps->RasterizeTrapezoid = 0; /* requires DDX support */
     ps->AddTraps = 0;           /* requires DDX support */
diff --git a/render/mipict.h b/render/mipict.h
index a16dd31..ee90b58 100644
--- a/render/mipict.h
+++ b/render/mipict.h
@@ -122,6 +122,16 @@ miCompositeRects(CARD8 op,
                  xRenderColor * color, int nRect, xRectangle *rects);
 
 extern _X_EXPORT void
+miTriangles (CARD8	    op,
+	     PicturePtr	    pSrc,
+	     PicturePtr	    pDst,
+	     PictFormatPtr  maskFormat,
+	     INT16	    xSrc,
+	     INT16	    ySrc,
+	     int	    ntri,
+	     xTriangle	    *tris);
+
+extern _X_EXPORT void
 
 miTriStrip(CARD8 op,
            PicturePtr pSrc,
@@ -137,10 +147,27 @@ miTriFan(CARD8 op,
          PictFormatPtr maskFormat,
          INT16 xSrc, INT16 ySrc, int npoints, xPointFixed * points);
 
+extern _X_EXPORT PicturePtr
+miCreateAlphaPicture (ScreenPtr	    pScreen, 
+		      PicturePtr    pDst,
+		      PictFormatPtr pPictFormat,
+		      CARD16	    width,
+		      CARD16	    height);
+
 extern _X_EXPORT void
  miTrapezoidBounds(int ntrap, xTrapezoid * traps, BoxPtr box);
 
 extern _X_EXPORT void
+miTrapezoids (CARD8        op,
+             PicturePtr    pSrc,
+             PicturePtr    pDst,
+             PictFormatPtr maskFormat,
+             INT16         xSrc,
+             INT16         ySrc,
+             int           ntrap,
+             xTrapezoid    *traps);
+
+extern _X_EXPORT void
  miPointFixedBounds(int npoint, xPointFixed * points, BoxPtr bounds);
 
 extern _X_EXPORT void
diff --git a/render/mitrap.c b/render/mitrap.c
index 17b6dcd..71c1857 100644
--- a/render/mitrap.c
+++ b/render/mitrap.c
@@ -34,6 +34,55 @@
 #include "picturestr.h"
 #include "mipict.h"
 
+PicturePtr
+miCreateAlphaPicture (ScreenPtr	    pScreen, 
+		      PicturePtr    pDst,
+		      PictFormatPtr pPictFormat,
+		      CARD16	    width,
+		      CARD16	    height)
+{
+    PixmapPtr	    pPixmap;
+    PicturePtr	    pPicture;
+    GCPtr	    pGC;
+    int		    error;
+    xRectangle	    rect;
+
+    if (width > 32767 || height > 32767)
+	return 0;
+
+    if (!pPictFormat)
+    {
+	if (pDst->polyEdge == PolyEdgeSharp)
+	    pPictFormat = PictureMatchFormat (pScreen, 1, PICT_a1);
+	else
+	    pPictFormat = PictureMatchFormat (pScreen, 8, PICT_a8);
+	if (!pPictFormat)
+	    return 0;
+    }
+
+    pPixmap = (*pScreen->CreatePixmap) (pScreen, width, height, 
+					pPictFormat->depth, 0);
+    if (!pPixmap)
+	return 0;
+    pGC = GetScratchGC (pPixmap->drawable.depth, pScreen);
+    if (!pGC)
+    {
+	(*pScreen->DestroyPixmap) (pPixmap);
+	return 0;
+    }
+    ValidateGC (&pPixmap->drawable, pGC);
+    rect.x = 0;
+    rect.y = 0;
+    rect.width = width;
+    rect.height = height;
+    (*pGC->ops->PolyFillRect)(&pPixmap->drawable, pGC, 1, &rect);
+    FreeScratchGC (pGC);
+    pPicture = CreatePicture (0, &pPixmap->drawable, pPictFormat,
+			      0, 0, serverClient, &error);
+    (*pScreen->DestroyPixmap) (pPixmap);
+    return pPicture;
+}
+
 static xFixed
 miLineFixedX(xLineFixed * l, xFixed y, Bool ceil)
 {
@@ -79,3 +128,65 @@ miTrapezoidBounds(int ntrap, xTrapezoid * traps, BoxPtr box)
             box->x2 = x2;
     }
 }
+
+
+void
+miTrapezoids (CARD8        op,
+             PicturePtr    pSrc,
+             PicturePtr    pDst,
+             PictFormatPtr maskFormat,
+             INT16         xSrc,
+             INT16         ySrc,
+             int           ntrap,
+             xTrapezoid    *traps)
+{
+    ScreenPtr          pScreen = pDst->pDrawable->pScreen;
+    PictureScreenPtr    ps = GetPictureScreen(pScreen);
+
+    /*
+     * Check for solid alpha add
+     */
+    if (op == PictOpAdd && miIsSolidAlpha (pSrc))
+    {
+       for (; ntrap; ntrap--, traps++)
+           (*ps->RasterizeTrapezoid) (pDst, traps, 0, 0);
+    } 
+    else if (maskFormat)
+    {
+       PicturePtr      pPicture;
+       BoxRec          bounds;
+       INT16           xDst, yDst;
+       INT16           xRel, yRel;
+       
+       xDst = traps[0].left.p1.x >> 16;
+       yDst = traps[0].left.p1.y >> 16;
+
+       miTrapezoidBounds (ntrap, traps, &bounds);
+       if (bounds.y1 >= bounds.y2 || bounds.x1 >= bounds.x2)
+           return;
+       pPicture = miCreateAlphaPicture (pScreen, pDst, maskFormat,
+                                        bounds.x2 - bounds.x1,
+                                        bounds.y2 - bounds.y1);
+       if (!pPicture)
+           return;
+       for (; ntrap; ntrap--, traps++)
+           (*ps->RasterizeTrapezoid) (pPicture, traps, 
+                                      -bounds.x1, -bounds.y1);
+       xRel = bounds.x1 + xSrc - xDst;
+       yRel = bounds.y1 + ySrc - yDst;
+       CompositePicture (op, pSrc, pPicture, pDst,
+                         xRel, yRel, 0, 0, bounds.x1, bounds.y1,
+                         bounds.x2 - bounds.x1,
+                         bounds.y2 - bounds.y1);
+       FreePicture (pPicture, 0);
+    }
+    else
+    {
+       if (pDst->polyEdge == PolyEdgeSharp)
+           maskFormat = PictureMatchFormat (pScreen, 1, PICT_a1);
+       else
+           maskFormat = PictureMatchFormat (pScreen, 8, PICT_a8);
+       for (; ntrap; ntrap--, traps++)
+           miTrapezoids (op, pSrc, pDst, maskFormat, xSrc, ySrc, 1, traps);
+    }
+}
diff --git a/render/mitri.c b/render/mitri.c
index 922f22a..bdca9ca 100644
--- a/render/mitri.c
+++ b/render/mitri.c
@@ -65,3 +65,64 @@ miTriangleBounds(int ntri, xTriangle * tris, BoxPtr bounds)
 {
     miPointFixedBounds(ntri * 3, (xPointFixed *) tris, bounds);
 }
+
+
+void
+miTriangles (CARD8	    op,
+	     PicturePtr	    pSrc,
+	     PicturePtr	    pDst,
+	     PictFormatPtr  maskFormat,
+	     INT16	    xSrc,
+	     INT16	    ySrc,
+	     int	    ntri,
+	     xTriangle	    *tris)
+{
+    ScreenPtr		pScreen = pDst->pDrawable->pScreen;
+    PictureScreenPtr    ps = GetPictureScreen(pScreen);
+    
+    /*
+     * Check for solid alpha add
+     */
+    if (op == PictOpAdd && miIsSolidAlpha (pSrc))
+    {
+	(*ps->AddTriangles) (pDst, 0, 0, ntri, tris);
+    }
+    else if (maskFormat)
+    {
+	BoxRec		bounds;
+	PicturePtr	pPicture;
+	INT16		xDst, yDst;
+	INT16		xRel, yRel;
+	
+	xDst = tris[0].p1.x >> 16;
+	yDst = tris[0].p1.y >> 16;
+
+	miTriangleBounds (ntri, tris, &bounds);
+	if (bounds.x2 <= bounds.x1 || bounds.y2 <= bounds.y1)
+	    return;
+	pPicture = miCreateAlphaPicture (pScreen, pDst, maskFormat,
+					 bounds.x2 - bounds.x1,
+					 bounds.y2 - bounds.y1);
+	if (!pPicture)
+	    return;
+	(*ps->AddTriangles) (pPicture, -bounds.x1, -bounds.y1, ntri, tris);
+	
+	xRel = bounds.x1 + xSrc - xDst;
+	yRel = bounds.y1 + ySrc - yDst;
+	CompositePicture (op, pSrc, pPicture, pDst,
+			  xRel, yRel, 0, 0, bounds.x1, bounds.y1,
+			  bounds.x2 - bounds.x1, bounds.y2 - bounds.y1);
+	FreePicture (pPicture, 0);
+    }
+    else
+    {
+	if (pDst->polyEdge == PolyEdgeSharp)
+	    maskFormat = PictureMatchFormat (pScreen, 1, PICT_a1);
+	else
+	    maskFormat = PictureMatchFormat (pScreen, 8, PICT_a8);
+	
+	for (; ntri; ntri--, tris++)
+	    miTriangles (op, pSrc, pDst, maskFormat, xSrc, ySrc, 1, tris);
+    }
+}
+
commit 21b64fe49a2a26d0d57ce135a72a12c9736f5866
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 de8ee6c..a6678a5 100644
--- a/mi/miexpose.c
+++ b/mi/miexpose.c
@@ -408,7 +408,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)
@@ -437,23 +438,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;
 
@@ -478,6 +493,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;
 
@@ -486,6 +513,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;
@@ -548,6 +581,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 19ba0d4ad155a66fcdbda925a1509273263db805
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 30f7c8f..22156d4 100644
--- a/hw/xfree86/Makefile.am
+++ b/hw/xfree86/Makefile.am
@@ -48,8 +48,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 = $(XORG_INCS) -I$(srcdir)/parser -I$(top_srcdir)/miext/cw \
+AM_CPPFLAGS = $(DIX_CFLAGS) @XORG_CFLAGS@ $(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 -I$(top_srcdir)/dri3
 
@@ -135,7 +134,7 @@ CLEANFILES = sdksyms.c sdksyms.dep Xorg.sh
 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) $(AM_CPPFLAGS)
+	$(AM_V_GEN)CPP='$(CPP)' AWK='$(AWK)' $(SHELL) $(srcdir)/sdksyms.sh $(top_srcdir) $(CPPFLAGS) $(AM_CPPFLAGS)
 
 SDKSYMS_DEP = sdksyms.dep
 -include $(SDKSYMS_DEP)
commit e572bcc7f4236b7e0f23ab762f225b3bce37db59
Author: Adam Jackson <ajax at redhat.com>
Date:   Mon Jun 23 15:24:35 2014 -0400

    fb: Remove even/odd tile slow-pathing
    
    Again, clearly meant to be a fast path, but this turns out not to be the
    case.
    
    Reviewed-by: Keith Packard <keithp at keithp.com>
    Signed-off-by: Adam Jackson <ajax at redhat.com>

diff --git a/fb/Makefile.am b/fb/Makefile.am
index ff6dc3a..65b5d94 100644
--- a/fb/Makefile.am
+++ b/fb/Makefile.am
@@ -44,7 +44,6 @@ libfb_la_SOURCES = 	\
 	fbseg.c		\
 	fbsetsp.c	\
 	fbsolid.c	\
-	fbtile.c	\
 	fbtrap.c	\
 	fbutil.c	\
 	fbwindow.c
diff --git a/fb/fb.h b/fb/fb.h
index 9a67b9d..5099b0f 100644
--- a/fb/fb.h
+++ b/fb/fb.h
@@ -1332,45 +1332,6 @@ fbSolid24(FbBits * dst,
           int dstX, int width, int height, FbBits and, FbBits xor);
 
 /*
- * fbtile.c
- */
-
-extern _X_EXPORT void
-
-fbEvenTile(FbBits * dst,
-           FbStride dstStride,
-           int dstX,
-           int width,
-           int height,
-           FbBits * tile,
-           FbStride tileStride,
-           int tileHeight, int alu, FbBits pm, int xRot, int yRot);
-
-extern _X_EXPORT void
-
-fbOddTile(FbBits * dst,
-          FbStride dstStride,
-          int dstX,
-          int width,
-          int height,
-          FbBits * tile,
-          FbStride tileStride,
-          int tileWidth,
-          int tileHeight, int alu, FbBits pm, int bpp, int xRot, int yRot);
-
-extern _X_EXPORT void
-
-fbTile(FbBits * dst,
-       FbStride dstStride,
-       int dstX,
-       int width,
-       int height,
-       FbBits * tile,
-       FbStride tileStride,
-       int tileWidth,
-       int tileHeight, int alu, FbBits pm, int bpp, int xRot, int yRot);
-
-/*
  * fbutil.c
  */
 extern _X_EXPORT FbBits fbReplicatePixel(Pixel p, int bpp);
diff --git a/fb/fbfill.c b/fb/fbfill.c
index ad09671..05d81ab 100644
--- a/fb/fbfill.c
+++ b/fb/fbfill.c
@@ -27,6 +27,44 @@
 #include "fb.h"
 
 static void
+fbTile(FbBits * dst, FbStride dstStride, int dstX, int width, int height,
+       FbBits * tile, FbStride tileStride, int tileWidth, int tileHeight,
+       int alu, FbBits pm, int bpp, int xRot, int yRot)
+{
+    int tileX, tileY;
+    int widthTmp;
+    int h, w;
+    int x, y;
+
+    modulus(-yRot, tileHeight, tileY);
+    y = 0;
+    while (height) {
+        h = tileHeight - tileY;
+        if (h > height)
+            h = height;
+        height -= h;
+        widthTmp = width;
+        x = dstX;
+        modulus(dstX - xRot, tileWidth, tileX);
+        while (widthTmp) {
+            w = tileWidth - tileX;
+            if (w > widthTmp)
+                w = widthTmp;
+            widthTmp -= w;
+            fbBlt(tile + tileY * tileStride,
+                  tileStride,
+                  tileX,
+                  dst + y * dstStride,
+                  dstStride, x, w, h, alu, pm, bpp, FALSE, FALSE);
+            x += w;
+            tileX = 0;
+        }
+        y += h;
+        tileY = 0;
+    }
+}
+
+static void
 fbStipple(FbBits * dst, FbStride dstStride,
           int dstX, int dstBpp,
           int width, int height,
diff --git a/fb/fbtile.c b/fb/fbtile.c
deleted file mode 100644
index 785c5f0..0000000
--- a/fb/fbtile.c
+++ /dev/null
@@ -1,163 +0,0 @@
-/*
- * Copyright © 1998 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 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_DIX_CONFIG_H
-#include <dix-config.h>
-#endif
-
-#include "fb.h"
-
-/*
- * Accelerated tile fill -- tile width is a power of two not greater
- * than FB_UNIT
- */
-
-void
-fbEvenTile(FbBits * dst,
-           FbStride dstStride,
-           int dstX,
-           int width,
-           int height,
-           FbBits * tile,
-           FbStride tileStride,
-           int tileHeight, int alu, FbBits pm, int xRot, int yRot)
-{
-    FbBits *t, *tileEnd, bits;
-    FbBits startmask, endmask;
-    FbBits and, xor;
-    int n, nmiddle;
-    int tileX, tileY;
-    int rot;
-    int startbyte, endbyte;
-
-    dst += dstX >> FB_SHIFT;
-    dstX &= FB_MASK;
-    FbMaskBitsBytes(dstX, width, FbDestInvarientRop(alu, pm),
-                    startmask, startbyte, nmiddle, endmask, endbyte);
-    if (startmask)
-        dstStride--;
-    dstStride -= nmiddle;
-
-    /*
-     * Compute tile start scanline and rotation parameters
-     */
-    tileEnd = tile + tileHeight * tileStride;
-    modulus(-yRot, tileHeight, tileY);
-    t = tile + tileY * tileStride;
-    modulus(-xRot, FB_UNIT, tileX);
-    rot = tileX;
-
-    while (height--) {
-
-        /*
-         * Pick up bits for this scanline
-         */
-        bits = READ(t);
-        t += tileStride;
-        if (t >= tileEnd)
-            t = tile;
-        bits = FbRotLeft(bits, rot);
-        and = fbAnd(alu, bits, pm);
-        xor = fbXor(alu, bits, pm);
-
-        if (startmask) {
-            FbDoLeftMaskByteRRop(dst, startbyte, startmask, and, xor);
-            dst++;
-        }
-        n = nmiddle;
-        if (!and)
-            while (n--)
-                WRITE(dst++, xor);
-        else
-            while (n--) {
-                WRITE(dst, FbDoRRop(READ(dst), and, xor));
-                dst++;
-            }
-        if (endmask)
-            FbDoRightMaskByteRRop(dst, endbyte, endmask, and, xor);
-        dst += dstStride;
-    }
-}
-
-void
-fbOddTile(FbBits * dst,
-          FbStride dstStride,
-          int dstX,
-          int width,
-          int height,
-          FbBits * tile,
-          FbStride tileStride,
-          int tileWidth,
-          int tileHeight, int alu, FbBits pm, int bpp, int xRot, int yRot)
-{
-    int tileX, tileY;
-    int widthTmp;
-    int h, w;
-    int x, y;
-
-    modulus(-yRot, tileHeight, tileY);
-    y = 0;
-    while (height) {
-        h = tileHeight - tileY;
-        if (h > height)
-            h = height;
-        height -= h;
-        widthTmp = width;
-        x = dstX;
-        modulus(dstX - xRot, tileWidth, tileX);
-        while (widthTmp) {
-            w = tileWidth - tileX;
-            if (w > widthTmp)
-                w = widthTmp;
-            widthTmp -= w;
-            fbBlt(tile + tileY * tileStride,
-                  tileStride,
-                  tileX,
-                  dst + y * dstStride,
-                  dstStride, x, w, h, alu, pm, bpp, FALSE, FALSE);
-            x += w;
-            tileX = 0;
-        }
-        y += h;
-        tileY = 0;
-    }
-}
-
-void
-fbTile(FbBits * dst,
-       FbStride dstStride,
-       int dstX,
-       int width,
-       int height,
-       FbBits * tile,
-       FbStride tileStride,
-       int tileWidth,
-       int tileHeight, int alu, FbBits pm, int bpp, int xRot, int yRot)
-{
-    if (FbEvenTile(tileWidth))
-        fbEvenTile(dst, dstStride, dstX, width, height,
-                   tile, tileStride, tileHeight, alu, pm, xRot, yRot);
-    else
-        fbOddTile(dst, dstStride, dstX, width, height,
-                  tile, tileStride, tileWidth, tileHeight,
-                  alu, pm, bpp, xRot, yRot);
-}
diff --git a/fb/wfbrename.h b/fb/wfbrename.h
index d32c7a4..30221c5 100644
--- a/fb/wfbrename.h
+++ b/fb/wfbrename.h
@@ -58,7 +58,6 @@
 #define fbDots24 wfbDots24
 #define fbDots32 wfbDots32
 #define fbDots8 wfbDots8
-#define fbEvenTile wfbEvenTile
 #define fbExpandDirectColors wfbExpandDirectColors
 #define fbFill wfbFill
 #define fbFillRegionSolid wfbFillRegionSolid
@@ -83,7 +82,6 @@
 #define fbInitVisuals wfbInitVisuals
 #define fbListInstalledColormaps wfbListInstalledColormaps
 #define FbMergeRopBits wFbMergeRopBits
-#define fbOddTile wfbOddTile
 #define fbOver wfbOver
 #define fbOver24 wfbOver24
 #define fbOverlayCloseScreen wfbOverlayCloseScreen
@@ -139,7 +137,6 @@
 #define fbSolid wfbSolid
 #define fbSolid24 wfbSolid24
 #define fbSolidBoxClipped wfbSolidBoxClipped
-#define fbTile wfbTile
 #define fbTrapezoids wfbTrapezoids
 #define fbTriangles wfbTriangles
 #define fbUninstallColormap wfbUninstallColormap
commit 836bb27726441e048bb300664343a136bc596a5b
Author: Adam Jackson <ajax at redhat.com>
Date:   Tue Jun 17 12:25:42 2014 -0400

    fb: Remove unused fbReduceRasterOp
    
    Appears to have been cargo-culted in from cfb and then never used.
    
    Reviewed-by: Keith Packard <keithp at keithp.com>
    Signed-off-by: Adam Jackson <ajax at redhat.com>

diff --git a/fb/fb.h b/fb/fb.h
index f7cbaf9..9a67b9d 100644
--- a/fb/fb.h
+++ b/fb/fb.h
@@ -1375,9 +1375,6 @@ fbTile(FbBits * dst,
  */
 extern _X_EXPORT FbBits fbReplicatePixel(Pixel p, int bpp);
 
-extern _X_EXPORT void
- fbReduceRasterOp(int rop, FbBits fg, FbBits pm, FbBits * andp, FbBits * xorp);
-
 #ifdef FB_ACCESS_WRAPPER
 extern _X_EXPORT ReadMemoryProcPtr wfbReadMemory;
 extern _X_EXPORT WriteMemoryProcPtr wfbWriteMemory;
diff --git a/fb/fbutil.c b/fb/fbutil.c
index 078fc42..c1d5923 100644
--- a/fb/fbutil.c
+++ b/fb/fbutil.c
@@ -39,84 +39,6 @@ fbReplicatePixel(Pixel p, int bpp)
     return b;
 }
 
-void
-fbReduceRasterOp(int rop, FbBits fg, FbBits pm, FbBits * andp, FbBits * xorp)
-{
-    FbBits and, xor;
-
-    switch (rop) {
-    default:
-    case GXclear:              /* 0 0 0 0 */
-        and = 0;
-        xor = 0;
-        break;
-    case GXand:                /* 0 0 0 1 */
-        and = fg;
-        xor = 0;
-        break;
-    case GXandReverse:         /* 0 0 1 0 */
-        and = fg;
-        xor = fg;
-        break;
-    case GXcopy:               /* 0 0 1 1 */
-        and = 0;
-        xor = fg;
-        break;
-    case GXandInverted:        /* 0 1 0 0 */
-        and = ~fg;
-        xor = 0;
-        break;
-    case GXnoop:               /* 0 1 0 1 */
-        and = FB_ALLONES;
-        xor = 0;
-        break;
-    case GXxor:                /* 0 1 1 0 */
-        and = FB_ALLONES;
-        xor = fg;
-        break;
-    case GXor:                 /* 0 1 1 1 */
-        and = ~fg;
-        xor = fg;
-        break;
-    case GXnor:                /* 1 0 0 0 */
-        and = ~fg;
-        xor = ~fg;
-        break;
-    case GXequiv:              /* 1 0 0 1 */
-        and = FB_ALLONES;
-        xor = ~fg;
-        break;
-    case GXinvert:             /* 1 0 1 0 */
-        and = FB_ALLONES;
-        xor = FB_ALLONES;
-        break;
-    case GXorReverse:          /* 1 0 1 1 */
-        and = ~fg;
-        xor = FB_ALLONES;
-        break;
-    case GXcopyInverted:       /* 1 1 0 0 */
-        and = 0;
-        xor = ~fg;
-        break;
-    case GXorInverted:         /* 1 1 0 1 */
-        and = fg;
-        xor = ~fg;
-        break;
-    case GXnand:               /* 1 1 1 0 */
-        and = fg;
-        xor = FB_ALLONES;
-        break;
-    case GXset:                /* 1 1 1 1 */
-        and = 0;
-        xor = FB_ALLONES;
-        break;
-    }
-    and |= ~pm;
-    xor &= pm;
-    *andp = and;
-    *xorp = xor;
-}
-
 #define O 0
 #define I FB_ALLONES
 
diff --git a/fb/wfbrename.h b/fb/wfbrename.h
index c8be10f..d32c7a4 100644
--- a/fb/wfbrename.h
+++ b/fb/wfbrename.h
@@ -126,8 +126,6 @@
 #define fbQueryBestSize wfbQueryBestSize
 #define fbRasterizeTrapezoid wfbRasterizeTrapezoid
 #define fbRealizeFont wfbRealizeFont
-#define fbRealizeWindow wfbRealizeWindow
-#define fbReduceRasterOp wfbReduceRasterOp
 #define fbReplicatePixel wfbReplicatePixel
 #define fbResolveColor wfbResolveColor
 #define fbScreenPrivateKeyRec wfbScreenPrivateKeyRec
commit 167ccd33e0d2c4bd68aebcdba5a512d24c5eb49a
Author: Adam Jackson <ajax at redhat.com>
Date:   Tue Jun 17 12:21:19 2014 -0400

    fb: Move fbStipple*Bits near their only consumer
    
    And remove fbStippleTable since gcc can't figure that out itself.
    
    Reviewed-by: Keith Packard <keithp at keithp.com>
    Signed-off-by: Adam Jackson <ajax at redhat.com>

diff --git a/fb/fbbltone.c b/fb/fbbltone.c
index bd3229a..d5806e5 100644
--- a/fb/fbbltone.c
+++ b/fb/fbbltone.c
@@ -26,6 +26,101 @@
 
 #include "fb.h"
 
+/*
+ * Stipple masks are independent of bit/byte order as long
+ * as bitorder == byteorder.  FB doesn't handle the case
+ * where these differ
+ */
+#define BitsMask(x,w)	((FB_ALLONES << ((x) & FB_MASK)) & \
+			 (FB_ALLONES >> ((FB_UNIT - ((x) + (w))) & FB_MASK)))
+
+#define Mask(x,w)	BitsMask((x)*(w),(w))
+
+#define SelMask(b,n,w)	((((b) >> n) & 1) * Mask(n,w))
+
+#define C1(b,w) \
+    (SelMask(b,0,w))
+
+#define C2(b,w) \
+    (SelMask(b,0,w) | \
+     SelMask(b,1,w))
+
+#define C4(b,w) \
+    (SelMask(b,0,w) | \
+     SelMask(b,1,w) | \
+     SelMask(b,2,w) | \
+     SelMask(b,3,w))
+
+#define C8(b,w) \
+    (SelMask(b,0,w) | \
+     SelMask(b,1,w) | \
+     SelMask(b,2,w) | \
+     SelMask(b,3,w) | \
+     SelMask(b,4,w) | \
+     SelMask(b,5,w) | \
+     SelMask(b,6,w) | \
+     SelMask(b,7,w))
+
+static const FbBits fbStipple8Bits[256] = {
+    C8(0, 4), C8(1, 4), C8(2, 4), C8(3, 4), C8(4, 4), C8(5, 4),
+    C8(6, 4), C8(7, 4), C8(8, 4), C8(9, 4), C8(10, 4), C8(11, 4),
+    C8(12, 4), C8(13, 4), C8(14, 4), C8(15, 4), C8(16, 4), C8(17, 4),
+    C8(18, 4), C8(19, 4), C8(20, 4), C8(21, 4), C8(22, 4), C8(23, 4),
+    C8(24, 4), C8(25, 4), C8(26, 4), C8(27, 4), C8(28, 4), C8(29, 4),
+    C8(30, 4), C8(31, 4), C8(32, 4), C8(33, 4), C8(34, 4), C8(35, 4),
+    C8(36, 4), C8(37, 4), C8(38, 4), C8(39, 4), C8(40, 4), C8(41, 4),
+    C8(42, 4), C8(43, 4), C8(44, 4), C8(45, 4), C8(46, 4), C8(47, 4),
+    C8(48, 4), C8(49, 4), C8(50, 4), C8(51, 4), C8(52, 4), C8(53, 4),
+    C8(54, 4), C8(55, 4), C8(56, 4), C8(57, 4), C8(58, 4), C8(59, 4),
+    C8(60, 4), C8(61, 4), C8(62, 4), C8(63, 4), C8(64, 4), C8(65, 4),
+    C8(66, 4), C8(67, 4), C8(68, 4), C8(69, 4), C8(70, 4), C8(71, 4),
+    C8(72, 4), C8(73, 4), C8(74, 4), C8(75, 4), C8(76, 4), C8(77, 4),
+    C8(78, 4), C8(79, 4), C8(80, 4), C8(81, 4), C8(82, 4), C8(83, 4),
+    C8(84, 4), C8(85, 4), C8(86, 4), C8(87, 4), C8(88, 4), C8(89, 4),
+    C8(90, 4), C8(91, 4), C8(92, 4), C8(93, 4), C8(94, 4), C8(95, 4),
+    C8(96, 4), C8(97, 4), C8(98, 4), C8(99, 4), C8(100, 4), C8(101, 4),
+    C8(102, 4), C8(103, 4), C8(104, 4), C8(105, 4), C8(106, 4), C8(107, 4),
+    C8(108, 4), C8(109, 4), C8(110, 4), C8(111, 4), C8(112, 4), C8(113, 4),
+    C8(114, 4), C8(115, 4), C8(116, 4), C8(117, 4), C8(118, 4), C8(119, 4),
+    C8(120, 4), C8(121, 4), C8(122, 4), C8(123, 4), C8(124, 4), C8(125, 4),
+    C8(126, 4), C8(127, 4), C8(128, 4), C8(129, 4), C8(130, 4), C8(131, 4),
+    C8(132, 4), C8(133, 4), C8(134, 4), C8(135, 4), C8(136, 4), C8(137, 4),
+    C8(138, 4), C8(139, 4), C8(140, 4), C8(141, 4), C8(142, 4), C8(143, 4),
+    C8(144, 4), C8(145, 4), C8(146, 4), C8(147, 4), C8(148, 4), C8(149, 4),
+    C8(150, 4), C8(151, 4), C8(152, 4), C8(153, 4), C8(154, 4), C8(155, 4),
+    C8(156, 4), C8(157, 4), C8(158, 4), C8(159, 4), C8(160, 4), C8(161, 4),
+    C8(162, 4), C8(163, 4), C8(164, 4), C8(165, 4), C8(166, 4), C8(167, 4),
+    C8(168, 4), C8(169, 4), C8(170, 4), C8(171, 4), C8(172, 4), C8(173, 4),
+    C8(174, 4), C8(175, 4), C8(176, 4), C8(177, 4), C8(178, 4), C8(179, 4),
+    C8(180, 4), C8(181, 4), C8(182, 4), C8(183, 4), C8(184, 4), C8(185, 4),
+    C8(186, 4), C8(187, 4), C8(188, 4), C8(189, 4), C8(190, 4), C8(191, 4),
+    C8(192, 4), C8(193, 4), C8(194, 4), C8(195, 4), C8(196, 4), C8(197, 4),
+    C8(198, 4), C8(199, 4), C8(200, 4), C8(201, 4), C8(202, 4), C8(203, 4),
+    C8(204, 4), C8(205, 4), C8(206, 4), C8(207, 4), C8(208, 4), C8(209, 4),
+    C8(210, 4), C8(211, 4), C8(212, 4), C8(213, 4), C8(214, 4), C8(215, 4),
+    C8(216, 4), C8(217, 4), C8(218, 4), C8(219, 4), C8(220, 4), C8(221, 4),
+    C8(222, 4), C8(223, 4), C8(224, 4), C8(225, 4), C8(226, 4), C8(227, 4),
+    C8(228, 4), C8(229, 4), C8(230, 4), C8(231, 4), C8(232, 4), C8(233, 4),
+    C8(234, 4), C8(235, 4), C8(236, 4), C8(237, 4), C8(238, 4), C8(239, 4),
+    C8(240, 4), C8(241, 4), C8(242, 4), C8(243, 4), C8(244, 4), C8(245, 4),
+    C8(246, 4), C8(247, 4), C8(248, 4), C8(249, 4), C8(250, 4), C8(251, 4),
+    C8(252, 4), C8(253, 4), C8(254, 4), C8(255, 4),
+};
+
+static const FbBits fbStipple4Bits[16] = {
+    C4(0, 8), C4(1, 8), C4(2, 8), C4(3, 8), C4(4, 8), C4(5, 8),
+    C4(6, 8), C4(7, 8), C4(8, 8), C4(9, 8), C4(10, 8), C4(11, 8),
+    C4(12, 8), C4(13, 8), C4(14, 8), C4(15, 8),
+};
+
+static const FbBits fbStipple2Bits[4] = {
+    C2(0, 16), C2(1, 16), C2(2, 16), C2(3, 16),
+};
+
+static const FbBits fbStipple1Bits[2] = {
+    C1(0, 32), C1(1, 32),
+};
+
 #ifdef __clang__
 /* shift overflow is intentional */
 #pragma clang diagnostic ignored "-Wshift-overflow"
@@ -153,8 +248,22 @@ fbBltOne(FbStip * src, FbStride srcStride,      /* FbStip units per scanline */
      * Get pointer to stipple mask array for this depth
      */
     fbBits = 0;                 /* unused */
-    if (pixelsPerDst <= 8)
-        fbBits = fbStippleTable[pixelsPerDst];
+    switch (pixelsPerDst) {
+    case 8:
+        fbBits = fbStipple8Bits;
+        break;
+    case 4:
+        fbBits = fbStipple4Bits;
+        break;
+    case 2:
+        fbBits = fbStipple2Bits;
+        break;
+    case 1:
+        fbBits = fbStipple1Bits;
+        break;
+    default:
+        return;
+    }
 
     /*
      * Compute total number of destination words written, but 
diff --git a/fb/fbrop.h b/fb/fbrop.h
index b995f23..872ae52 100644
--- a/fb/fbrop.h
+++ b/fb/fbrop.h
@@ -95,12 +95,6 @@ extern _X_EXPORT const FbMergeRopRec FbMergeRopBits[16];
  * Stippling operations; 
  */
 
-extern _X_EXPORT const FbBits fbStipple8Bits[256];
-extern _X_EXPORT const FbBits fbStipple4Bits[16];
-extern _X_EXPORT const FbBits fbStipple2Bits[4];
-extern _X_EXPORT const FbBits fbStipple1Bits[2];
-extern _X_EXPORT const FbBits *const fbStippleTable[];
-
 #define FbStippleRRop(dst, b, fa, fx, ba, bx) \
     (FbDoRRop(dst, fa, fx) & b) | (FbDoRRop(dst, ba, bx) & ~b)
 
diff --git a/fb/fbutil.c b/fb/fbutil.c
index 9d66c2a..078fc42 100644
--- a/fb/fbutil.c
+++ b/fb/fbutil.c
@@ -139,110 +139,3 @@ const FbMergeRopRec FbMergeRopBits[16] = {
     {O, O, O, I},               /* set           0xf         1 */
 };
 
-/*
- * Stipple masks are independent of bit/byte order as long
- * as bitorder == byteorder.  FB doesn't handle the case
- * where these differ
- */
-#define BitsMask(x,w)	((FB_ALLONES << ((x) & FB_MASK)) & \
-			 (FB_ALLONES >> ((FB_UNIT - ((x) + (w))) & FB_MASK)))
-
-#define Mask(x,w)	BitsMask((x)*(w),(w))
-
-#define SelMask(b,n,w)	((((b) >> n) & 1) * Mask(n,w))
-
-#define C1(b,w) \
-    (SelMask(b,0,w))
-
-#define C2(b,w) \
-    (SelMask(b,0,w) | \
-     SelMask(b,1,w))
-
-#define C4(b,w) \
-    (SelMask(b,0,w) | \
-     SelMask(b,1,w) | \
-     SelMask(b,2,w) | \
-     SelMask(b,3,w))
-
-#define C8(b,w) \
-    (SelMask(b,0,w) | \
-     SelMask(b,1,w) | \
-     SelMask(b,2,w) | \
-     SelMask(b,3,w) | \
-     SelMask(b,4,w) | \
-     SelMask(b,5,w) | \
-     SelMask(b,6,w) | \
-     SelMask(b,7,w))
-
-#define fbStipple16Bits 0
-const FbBits fbStipple8Bits[256] = {
-    C8(0, 4), C8(1, 4), C8(2, 4), C8(3, 4), C8(4, 4), C8(5, 4),
-    C8(6, 4), C8(7, 4), C8(8, 4), C8(9, 4), C8(10, 4), C8(11, 4),
-    C8(12, 4), C8(13, 4), C8(14, 4), C8(15, 4), C8(16, 4), C8(17, 4),
-    C8(18, 4), C8(19, 4), C8(20, 4), C8(21, 4), C8(22, 4), C8(23, 4),
-    C8(24, 4), C8(25, 4), C8(26, 4), C8(27, 4), C8(28, 4), C8(29, 4),
-    C8(30, 4), C8(31, 4), C8(32, 4), C8(33, 4), C8(34, 4), C8(35, 4),
-    C8(36, 4), C8(37, 4), C8(38, 4), C8(39, 4), C8(40, 4), C8(41, 4),
-    C8(42, 4), C8(43, 4), C8(44, 4), C8(45, 4), C8(46, 4), C8(47, 4),
-    C8(48, 4), C8(49, 4), C8(50, 4), C8(51, 4), C8(52, 4), C8(53, 4),
-    C8(54, 4), C8(55, 4), C8(56, 4), C8(57, 4), C8(58, 4), C8(59, 4),
-    C8(60, 4), C8(61, 4), C8(62, 4), C8(63, 4), C8(64, 4), C8(65, 4),
-    C8(66, 4), C8(67, 4), C8(68, 4), C8(69, 4), C8(70, 4), C8(71, 4),
-    C8(72, 4), C8(73, 4), C8(74, 4), C8(75, 4), C8(76, 4), C8(77, 4),
-    C8(78, 4), C8(79, 4), C8(80, 4), C8(81, 4), C8(82, 4), C8(83, 4),
-    C8(84, 4), C8(85, 4), C8(86, 4), C8(87, 4), C8(88, 4), C8(89, 4),
-    C8(90, 4), C8(91, 4), C8(92, 4), C8(93, 4), C8(94, 4), C8(95, 4),
-    C8(96, 4), C8(97, 4), C8(98, 4), C8(99, 4), C8(100, 4), C8(101, 4),
-    C8(102, 4), C8(103, 4), C8(104, 4), C8(105, 4), C8(106, 4), C8(107, 4),
-    C8(108, 4), C8(109, 4), C8(110, 4), C8(111, 4), C8(112, 4), C8(113, 4),
-    C8(114, 4), C8(115, 4), C8(116, 4), C8(117, 4), C8(118, 4), C8(119, 4),
-    C8(120, 4), C8(121, 4), C8(122, 4), C8(123, 4), C8(124, 4), C8(125, 4),
-    C8(126, 4), C8(127, 4), C8(128, 4), C8(129, 4), C8(130, 4), C8(131, 4),
-    C8(132, 4), C8(133, 4), C8(134, 4), C8(135, 4), C8(136, 4), C8(137, 4),
-    C8(138, 4), C8(139, 4), C8(140, 4), C8(141, 4), C8(142, 4), C8(143, 4),
-    C8(144, 4), C8(145, 4), C8(146, 4), C8(147, 4), C8(148, 4), C8(149, 4),
-    C8(150, 4), C8(151, 4), C8(152, 4), C8(153, 4), C8(154, 4), C8(155, 4),
-    C8(156, 4), C8(157, 4), C8(158, 4), C8(159, 4), C8(160, 4), C8(161, 4),
-    C8(162, 4), C8(163, 4), C8(164, 4), C8(165, 4), C8(166, 4), C8(167, 4),
-    C8(168, 4), C8(169, 4), C8(170, 4), C8(171, 4), C8(172, 4), C8(173, 4),
-    C8(174, 4), C8(175, 4), C8(176, 4), C8(177, 4), C8(178, 4), C8(179, 4),
-    C8(180, 4), C8(181, 4), C8(182, 4), C8(183, 4), C8(184, 4), C8(185, 4),
-    C8(186, 4), C8(187, 4), C8(188, 4), C8(189, 4), C8(190, 4), C8(191, 4),
-    C8(192, 4), C8(193, 4), C8(194, 4), C8(195, 4), C8(196, 4), C8(197, 4),
-    C8(198, 4), C8(199, 4), C8(200, 4), C8(201, 4), C8(202, 4), C8(203, 4),
-    C8(204, 4), C8(205, 4), C8(206, 4), C8(207, 4), C8(208, 4), C8(209, 4),
-    C8(210, 4), C8(211, 4), C8(212, 4), C8(213, 4), C8(214, 4), C8(215, 4),
-    C8(216, 4), C8(217, 4), C8(218, 4), C8(219, 4), C8(220, 4), C8(221, 4),
-    C8(222, 4), C8(223, 4), C8(224, 4), C8(225, 4), C8(226, 4), C8(227, 4),
-    C8(228, 4), C8(229, 4), C8(230, 4), C8(231, 4), C8(232, 4), C8(233, 4),
-    C8(234, 4), C8(235, 4), C8(236, 4), C8(237, 4), C8(238, 4), C8(239, 4),
-    C8(240, 4), C8(241, 4), C8(242, 4), C8(243, 4), C8(244, 4), C8(245, 4),
-    C8(246, 4), C8(247, 4), C8(248, 4), C8(249, 4), C8(250, 4), C8(251, 4),
-    C8(252, 4), C8(253, 4), C8(254, 4), C8(255, 4),
-};
-
-const FbBits fbStipple4Bits[16] = {
-    C4(0, 8), C4(1, 8), C4(2, 8), C4(3, 8), C4(4, 8), C4(5, 8),
-    C4(6, 8), C4(7, 8), C4(8, 8), C4(9, 8), C4(10, 8), C4(11, 8),
-    C4(12, 8), C4(13, 8), C4(14, 8), C4(15, 8),
-};
-
-const FbBits fbStipple2Bits[4] = {
-    C2(0, 16), C2(1, 16), C2(2, 16), C2(3, 16),
-};
-
-const FbBits fbStipple1Bits[2] = {
-    C1(0, 32), C1(1, 32),
-};
-
-const FbBits *const fbStippleTable[] = {
-    0,
-    fbStipple1Bits,
-    fbStipple2Bits,
-    0,
-    fbStipple4Bits,
-    0,
-    0,
-    0,
-    fbStipple8Bits,
-};
diff --git a/fb/wfbrename.h b/fb/wfbrename.h
index 0bd233e..c8be10f 100644
--- a/fb/wfbrename.h
+++ b/fb/wfbrename.h
@@ -141,12 +141,6 @@
 #define fbSolid wfbSolid
 #define fbSolid24 wfbSolid24
 #define fbSolidBoxClipped wfbSolidBoxClipped
-#define fbStipple1Bits wfbStipple1Bits
-#define fbStipple24Bits wfbStipple24Bits
-#define fbStipple2Bits wfbStipple2Bits
-#define fbStipple4Bits wfbStipple4Bits
-#define fbStipple8Bits wfbStipple8Bits
-#define fbStippleTable wfbStippleTable
 #define fbTile wfbTile
 #define fbTrapezoids wfbTrapezoids
 #define fbTriangles wfbTriangles
commit 7430fdb689678b98ac63f5a8dad13719bac777e0
Author: Adam Jackson <ajax at redhat.com>
Date:   Tue Dec 17 14:46:38 2013 -0500

    fb: Remove even/odd stipple slow-pathing
    
    This is clearly meant to be a fast path, but it appears to be a net
    loss at this point.
    
    If you really wanted to ricer-tune here, note that the inner loop of
    fbBltOne is a bit too complicated for gcc (at least 4.8.2), it doesn't
    specialize the loop for the handful of legal values of bitsPerDst, which
    means computing at runtime what could have been const-propped.
    
    Reviewed-by: Keith Packard <keithp at keithp.com>
    Signed-off-by: Adam Jackson <ajax at redhat.com>

diff --git a/fb/Makefile.am b/fb/Makefile.am
index 752eabe..ff6dc3a 100644
--- a/fb/Makefile.am
+++ b/fb/Makefile.am
@@ -44,7 +44,6 @@ libfb_la_SOURCES = 	\
 	fbseg.c		\
 	fbsetsp.c	\
 	fbsolid.c	\
-	fbstipple.c	\
 	fbtile.c	\
 	fbtrap.c	\
 	fbutil.c	\
diff --git a/fb/fb.h b/fb/fb.h
index 6db5803..f7cbaf9 100644
--- a/fb/fb.h
+++ b/fb/fb.h
@@ -452,7 +452,6 @@ typedef struct {
     FbBits bgand, bgxor;        /* for stipples */
     FbBits fg, bg, pm;          /* expanded and filled */
     unsigned int dashLength;    /* total of all dash elements */
-    unsigned char evenStipple;  /* stipple is even */
     unsigned char bpp;          /* current drawable bpp */
 } FbGCPrivRec, *FbGCPrivPtr;
 
@@ -545,11 +544,6 @@ typedef struct {
  * Accelerated tiles are power of 2 width <= FB_UNIT
  */
 #define FbEvenTile(w)	    ((w) <= FB_UNIT && FbPowerOfTwo(w))
-/*
- * Accelerated stipples are power of 2 width and <= FB_UNIT/dstBpp
- * with dstBpp a power of 2 as well
- */
-#define FbEvenStip(w,bpp)   ((w) * (bpp) <= FB_UNIT && FbPowerOfTwo(w) && FbPowerOfTwo(bpp))
 
 /*
  * fb24_32.c
@@ -1338,58 +1332,6 @@ fbSolid24(FbBits * dst,
           int dstX, int width, int height, FbBits and, FbBits xor);
 
 /*
- * fbstipple.c
- */
-
-extern _X_EXPORT void
- fbTransparentSpan(FbBits * dst, FbBits stip, FbBits fgxor, int n);
-
-extern _X_EXPORT void
-
-fbEvenStipple(FbBits * dst,
-              FbStride dstStride,
-              int dstX,
-              int dstBpp,
-              int width,
-              int height,
-              FbStip * stip,
-              FbStride stipStride,
-              int stipHeight,
-              FbBits fgand,
-              FbBits fgxor, FbBits bgand, FbBits bgxor, int xRot, int yRot);
-
-extern _X_EXPORT void
-
-fbOddStipple(FbBits * dst,
-             FbStride dstStride,
-             int dstX,
-             int dstBpp,
-             int width,
-             int height,
-             FbStip * stip,
-             FbStride stipStride,
-             int stipWidth,
-             int stipHeight,
-             FbBits fgand,
-             FbBits fgxor, FbBits bgand, FbBits bgxor, int xRot, int yRot);
-
-extern _X_EXPORT void
-
-fbStipple(FbBits * dst,
-          FbStride dstStride,
-          int dstX,
-          int dstBpp,
-          int width,
-          int height,
-          FbStip * stip,
-          FbStride stipStride,
-          int stipWidth,
-          int stipHeight,
-          Bool even,
-          FbBits fgand,
-          FbBits fgxor, FbBits bgand, FbBits bgxor, int xRot, int yRot);
-
-/*
  * fbtile.c
  */
 
diff --git a/fb/fbbltone.c b/fb/fbbltone.c
index 3042c4b..bd3229a 100644
--- a/fb/fbbltone.c
+++ b/fb/fbbltone.c
@@ -62,26 +62,6 @@
 	bits = (src < srcEnd ? READ(src++) : 0); \
 }
 
-#define LaneCases1(n,a)	    case n: FbLaneCase(n,a); break
-#define LaneCases2(n,a)	    LaneCases1(n,a); LaneCases1(n+1,a)
-#define LaneCases4(n,a)	    LaneCases2(n,a); LaneCases2(n+2,a)
-#define LaneCases8(n,a)	    LaneCases4(n,a); LaneCases4(n+4,a)
-#define LaneCases16(n,a)    LaneCases8(n,a); LaneCases8(n+8,a)
-
-#define LaneCases(a)	    LaneCases16(0,a)
-
-static const CARD8 fb8Lane[16] = {
-    0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15
-};
-
-static const CARD8 fb16Lane[16] = {
-    0, 3, 12, 15, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
-};
-
-static const CARD8 fb32Lane[16] = {
-    0, 15, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
-};
-
 void
 fbBltOne(FbStip * src, FbStride srcStride,      /* FbStip units per scanline */
          int srcX,              /* bit position of source */
@@ -110,7 +90,6 @@ fbBltOne(FbStip * src, FbStride srcStride,      /* FbStip units per scanline */
     Bool transparent;           /* accelerate 0 nop */
     int srcinc;                 /* source units consumed */
     Bool endNeedsLoad = FALSE;  /* need load for endmask */
-    const CARD8 *fbLane;
     int startbyte, endbyte;
 
     if (dstBpp == 24) {
@@ -176,15 +155,6 @@ fbBltOne(FbStip * src, FbStride srcStride,      /* FbStip units per scanline */
     fbBits = 0;                 /* unused */
     if (pixelsPerDst <= 8)
         fbBits = fbStippleTable[pixelsPerDst];
-    fbLane = 0;
-    if (transparent && fgand == 0) {
-        if (dstBpp == 8)
-            fbLane = fb8Lane;
-        if (dstBpp == 16)
-            fbLane = fb16Lane;
-        if (dstBpp == 32)
-            fbLane = fb32Lane;
-    }
 
     /*
      * Compute total number of destination words written, but 
@@ -235,15 +205,10 @@ fbBltOne(FbStip * src, FbStride srcStride,      /* FbStip units per scanline */
              */
             if (startmask) {
                 mask = fbBits[FbLeftStipBits(bits, pixelsPerDst)];
-                if (fbLane) {
-                    fbTransparentSpan(dst, mask & startmask, fgxor, 1);
-                }
-                else {
-                    if (mask || !transparent)
-                        FbDoLeftMaskByteStippleRRop(dst, mask,
-                                                    fgand, fgxor, bgand, bgxor,
-                                                    startbyte, startmask);
-                }
+                if (mask || !transparent)
+                    FbDoLeftMaskByteStippleRRop(dst, mask,
+                                                fgand, fgxor, bgand, bgxor,
+                                                startbyte, startmask);
                 bits = FbStipLeft(bits, pixelsPerDst);
                 dst++;
                 n--;
@@ -263,29 +228,15 @@ fbBltOne(FbStip * src, FbStride srcStride,      /* FbStip units per scanline */
                     }
                 }
                 else {
-                    if (fbLane) {
-                        while (bits && n) {
-                            switch (fbLane[FbLeftStipBits(bits, pixelsPerDst)]) {
-                                LaneCases((CARD8 *) dst);
-                            }
-                            bits = FbStipLeft(bits, pixelsPerDst);
-                            dst++;
-                            n--;
-                        }
-                        dst += n;
-                    }
-                    else {
-                        while (n--) {
-                            left = FbLeftStipBits(bits, pixelsPerDst);
-                            if (left || !transparent) {
-                                mask = fbBits[left];
-                                WRITE(dst, FbStippleRRop(READ(dst), mask,
-                                                         fgand, fgxor, bgand,
-                                                         bgxor));
-                            }
-                            dst++;
-                            bits = FbStipLeft(bits, pixelsPerDst);
+                    while (n--) {
+                        left = FbLeftStipBits(bits, pixelsPerDst);
+                        if (left || !transparent) {
+                            mask = fbBits[left];
+                            WRITE(dst, FbStippleRRop(READ(dst), mask, fgand,
+                                                     fgxor, bgand, bgxor));
                         }
+                        dst++;
+                        bits = FbStipLeft(bits, pixelsPerDst);
                     }
                 }
                 if (!w)
@@ -307,15 +258,9 @@ fbBltOne(FbStip * src, FbStride srcStride,      /* FbStip units per scanline */
                 LoadBits;
             }
             mask = fbBits[FbLeftStipBits(bits, pixelsPerDst)];
-            if (fbLane) {
-                fbTransparentSpan(dst, mask & endmask, fgxor, 1);
-            }
-            else {
-                if (mask || !transparent)
-                    FbDoRightMaskByteStippleRRop(dst, mask,
-                                                 fgand, fgxor, bgand, bgxor,
-                                                 endbyte, endmask);
-            }
+            if (mask || !transparent)
+                FbDoRightMaskByteStippleRRop(dst, mask, fgand, fgxor,
+                                             bgand, bgxor, endbyte, endmask);
         }
         dst += dstStride;
         src += srcStride;
diff --git a/fb/fbfill.c b/fb/fbfill.c
index de9d6b3..ad09671 100644
--- a/fb/fbfill.c
+++ b/fb/fbfill.c
@@ -26,6 +26,50 @@
 
 #include "fb.h"
 
+static void
+fbStipple(FbBits * dst, FbStride dstStride,
+          int dstX, int dstBpp,
+          int width, int height,
+          FbStip * stip, FbStride stipStride,
+          int stipWidth, int stipHeight,
+          FbBits fgand, FbBits fgxor,
+          FbBits bgand, FbBits bgxor,
+          int xRot, int yRot)
+{
+    int stipX, stipY, sx;
+    int widthTmp;
+    int h, w;
+    int x, y;
+
+    modulus(-yRot, stipHeight, stipY);
+    modulus(dstX / dstBpp - xRot, stipWidth, stipX);
+    y = 0;
+    while (height) {
+        h = stipHeight - stipY;
+        if (h > height)
+            h = height;
+        height -= h;
+        widthTmp = width;
+        x = dstX;
+        sx = stipX;
+        while (widthTmp) {
+            w = (stipWidth - sx) * dstBpp;
+            if (w > widthTmp)
+                w = widthTmp;
+            widthTmp -= w;
+            fbBltOne(stip + stipY * stipStride,
+                     stipStride,
+                     sx,
+                     dst + y * dstStride,
+                     dstStride, x, dstBpp, w, h, fgand, fgxor, bgand, bgxor);
+            x += w;
+            sx = 0;
+        }
+        y += h;
+        stipY = 0;
+    }
+}
+
 void
 fbFill(DrawablePtr pDrawable, GCPtr pGC, int x, int y, int width, int height)
 {
@@ -97,7 +141,7 @@ fbFill(DrawablePtr pDrawable, GCPtr pGC, int x, int y, int width, int height)
             fbStipple(dst + (y + dstYoff) * dstStride, dstStride,
                       (x + dstXoff) * dstBpp, dstBpp, width * dstBpp, height,
                       stip, stipStride, stipWidth, stipHeight,
-                      pPriv->evenStipple, fgand, fgxor, bgand, bgxor,
+                      fgand, fgxor, bgand, bgxor,
                       pGC->patOrg.x + pDrawable->x + dstXoff,
                       pGC->patOrg.y + pDrawable->y - y);
             fbFinishAccess(&pStip->drawable);
diff --git a/fb/fbgc.c b/fb/fbgc.c
index f4d7f3a..21c9b03 100644
--- a/fb/fbgc.c
+++ b/fb/fbgc.c
@@ -110,80 +110,6 @@ fbPadPixmap(PixmapPtr pPixmap)
     fbFinishAccess(&pPixmap->drawable);
 }
 
-/*
- * Verify that 'bits' repeats every 'len' bits
- */
-static Bool
-fbBitsRepeat(FbBits bits, int len, int width)
-{
-    FbBits mask = FbBitsMask(0, len);
-    FbBits orig = bits & mask;
-    int i;
-
-    if (width > FB_UNIT)
-        width = FB_UNIT;
-    for (i = 0; i < width / len; i++) {
-        if ((bits & mask) != orig)
-            return FALSE;
-        bits = FbScrLeft(bits, len);
-    }
-    return TRUE;
-}
-
-/*
- * Check whether an entire bitmap line is a repetition of
- * the first 'len' bits
- */
-static Bool
-fbLineRepeat(FbBits * bits, int len, int width)
-{
-    FbBits first = bits[0];
-
-    if (!fbBitsRepeat(first, len, width))
-        return FALSE;
-    width = (width + FB_UNIT - 1) >> FB_SHIFT;
-    bits++;
-    while (--width)
-        if (READ(bits) != first)
-            return FALSE;
-    return TRUE;
-}
-
-/*
- * The even stipple code wants the first FB_UNIT/bpp bits on
- * each scanline to represent the entire stipple
- */
-static Bool
-fbCanEvenStipple(PixmapPtr pStipple, int bpp)
-{
-    int len = FB_UNIT / bpp;
-    FbBits *bits;
-    int stride;
-    int stip_bpp;
-    _X_UNUSED int stipXoff, stipYoff;
-    int h;
-
-    /* can't even stipple 24bpp drawables */
-    if ((bpp & (bpp - 1)) != 0)
-        return FALSE;
-    /* make sure the stipple width is a multiple of the even stipple width */
-    if (pStipple->drawable.width % len != 0)
-        return FALSE;
-    fbGetDrawable(&pStipple->drawable, bits, stride, stip_bpp, stipXoff,
-                  stipYoff);
-    h = pStipple->drawable.height;
-    /* check to see that the stipple repeats horizontally */
-    while (h--) {
-        if (!fbLineRepeat(bits, len, pStipple->drawable.width)) {
-            fbFinishAccess(&pStipple->drawable);
-            return FALSE;
-        }
-        bits += stride;
-    }
-    fbFinishAccess(&pStipple->drawable);
-    return TRUE;
-}
-
 void
 fbValidateGC(GCPtr pGC, unsigned long changes, DrawablePtr pDrawable)
 {
@@ -239,16 +165,7 @@ fbValidateGC(GCPtr pGC, unsigned long changes, DrawablePtr pDrawable)
             fbPadPixmap(pGC->tile.pixmap);
     }
     if (changes & GCStipple) {
-        pPriv->evenStipple = FALSE;
-
         if (pGC->stipple) {
-
-            /* can we do an even stipple ?? */
-            if (FbEvenStip(pGC->stipple->drawable.width,
-                           pDrawable->bitsPerPixel) &&
-                (fbCanEvenStipple(pGC->stipple, pDrawable->bitsPerPixel)))
-                pPriv->evenStipple = TRUE;
-
             if (pGC->stipple->drawable.width * pDrawable->bitsPerPixel <
                 FB_UNIT)
                 fbPadPixmap(pGC->stipple);
diff --git a/fb/fbstipple.c b/fb/fbstipple.c
deleted file mode 100644
index 9a877c1..0000000
--- a/fb/fbstipple.c
+++ /dev/null
@@ -1,243 +0,0 @@
-/*
- * Copyright © 1998 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 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_DIX_CONFIG_H
-#include <dix-config.h>
-#endif
-
-#include "fb.h"
-
-/*
- * This is a slight abuse of the preprocessor to generate repetitive
- * code, the idea is to generate code for each case of a copy-mode
- * transparent stipple
- */
-#define LaneCases1(c,a)	    case c: \
-				while (n--) { FbLaneCase(c,a); a++; } \
-				break
-#define LaneCases2(c,a)	    LaneCases1(c,a); LaneCases1(c+1,a)
-#define LaneCases4(c,a)	    LaneCases2(c,a); LaneCases2(c+2,a)
-#define LaneCases8(c,a)	    LaneCases4(c,a); LaneCases4(c+4,a)
-#define LaneCases16(c,a)    LaneCases8(c,a); LaneCases8(c+8,a)
-
-#define LaneCases(a)	    LaneCases16(0,a)
-
-/*
- * Repeat a transparent stipple across a scanline n times
- */
-
-void
-fbTransparentSpan(FbBits * dst, FbBits stip, FbBits fgxor, int n)
-{
-    FbStip s;
-
-    s = ((FbStip) (stip) & 0x01);
-    s |= ((FbStip) (stip >> 8) & 0x02);
-    s |= ((FbStip) (stip >> 16) & 0x04);
-    s |= ((FbStip) (stip >> 24) & 0x08);
-    switch (s) {
-        LaneCases(dst);
-    }
-}
-
-void
-fbEvenStipple(FbBits * dst,
-              FbStride dstStride,
-              int dstX,
-              int dstBpp,
-              int width,
-              int height,
-              FbStip * stip,
-              FbStride stipStride,
-              int stipHeight,
-              FbBits fgand,
-              FbBits fgxor, FbBits bgand, FbBits bgxor, int xRot, int yRot)
-{
-    FbBits startmask, endmask;
-    FbBits mask, and, xor;
-    int nmiddle, n;
-    FbStip *s, *stipEnd, bits;
-    int rot, stipX, stipY;
-    int pixelsPerDst;
-    const FbBits *fbBits;
-    Bool transparent;
-    int startbyte, endbyte;
-
-    /*
-     * Check for a transparent stipple (stencil)
-     */
-    transparent = FALSE;
-    if (dstBpp >= 8 && fgand == 0 && bgand == FB_ALLONES && bgxor == 0)
-        transparent = TRUE;
-
-    pixelsPerDst = FB_UNIT / dstBpp;
-    /*
-     * Adjust dest pointers
-     */
-    dst += dstX >> FB_SHIFT;
-    dstX &= FB_MASK;
-    FbMaskBitsBytes(dstX, width, fgand == 0 && bgand == 0,
-                    startmask, startbyte, nmiddle, endmask, endbyte);
-
-    if (startmask)
-        dstStride--;
-    dstStride -= nmiddle;
-
-    xRot *= dstBpp;
-    /*
-     * Compute stip start scanline and rotation parameters
-     */
-    stipEnd = stip + stipStride * stipHeight;
-    modulus(-yRot, stipHeight, stipY);
-    s = stip + stipStride * stipY;
-    modulus(-xRot, FB_UNIT, stipX);
-    rot = stipX;
-
-    /*
-     * Get pointer to stipple mask array for this depth
-     */
-    /* fbStippleTable covers all valid bpp (4,8,16,32) */
-    fbBits = fbStippleTable[pixelsPerDst];
-
-    while (height--) {
-        /*
-         * Extract stipple bits for this scanline;
-         */
-        bits = READ(s);
-        s += stipStride;
-        if (s == stipEnd)
-            s = stip;
-        mask = fbBits[FbLeftStipBits(bits, pixelsPerDst)];
-        /*
-         * Rotate into position and compute reduced rop values
-         */
-        mask = FbRotLeft(mask, rot);
-        and = (fgand & mask) | (bgand & ~mask);
-        xor = (fgxor & mask) | (bgxor & ~mask);
-
-        if (transparent) {
-            if (startmask) {
-                fbTransparentSpan(dst, mask & startmask, fgxor, 1);
-                dst++;
-            }
-            fbTransparentSpan(dst, mask, fgxor, nmiddle);
-            dst += nmiddle;
-            if (endmask)
-                fbTransparentSpan(dst, mask & endmask, fgxor, 1);
-        }
-        else {
-            /*
-             * Fill scanline
-             */
-            if (startmask) {
-                FbDoLeftMaskByteRRop(dst, startbyte, startmask, and, xor);
-                dst++;
-            }
-            n = nmiddle;
-            if (!and)
-                while (n--)
-                    WRITE(dst++, xor);
-            else {
-                while (n--) {
-                    WRITE(dst, FbDoRRop(READ(dst), and, xor));
-                    dst++;
-                }
-            }
-            if (endmask)
-                FbDoRightMaskByteRRop(dst, endbyte, endmask, and, xor);
-        }
-        dst += dstStride;
-    }
-}
-
-void
-fbOddStipple(FbBits * dst,
-             FbStride dstStride,
-             int dstX,
-             int dstBpp,
-             int width,
-             int height,
-             FbStip * stip,
-             FbStride stipStride,
-             int stipWidth,
-             int stipHeight,
-             FbBits fgand,
-             FbBits fgxor, FbBits bgand, FbBits bgxor, int xRot, int yRot)
-{
-    int stipX, stipY, sx;
-    int widthTmp;
-    int h, w;
-    int x, y;
-
-    modulus(-yRot, stipHeight, stipY);
-    modulus(dstX / dstBpp - xRot, stipWidth, stipX);
-    y = 0;
-    while (height) {
-        h = stipHeight - stipY;
-        if (h > height)
-            h = height;
-        height -= h;
-        widthTmp = width;
-        x = dstX;
-        sx = stipX;
-        while (widthTmp) {
-            w = (stipWidth - sx) * dstBpp;
-            if (w > widthTmp)
-                w = widthTmp;
-            widthTmp -= w;
-            fbBltOne(stip + stipY * stipStride,
-                     stipStride,
-                     sx,
-                     dst + y * dstStride,
-                     dstStride, x, dstBpp, w, h, fgand, fgxor, bgand, bgxor);
-            x += w;
-            sx = 0;
-        }
-        y += h;
-        stipY = 0;
-    }
-}
-
-void
-fbStipple(FbBits * dst,
-          FbStride dstStride,
-          int dstX,
-          int dstBpp,
-          int width,
-          int height,
-          FbStip * stip,
-          FbStride stipStride,
-          int stipWidth,
-          int stipHeight,
-          Bool even,
-          FbBits fgand,
-          FbBits fgxor, FbBits bgand, FbBits bgxor, int xRot, int yRot)
-{
-    if (even)
-        fbEvenStipple(dst, dstStride, dstX, dstBpp, width, height,
-                      stip, stipStride, stipHeight,
-                      fgand, fgxor, bgand, bgxor, xRot, yRot);
-    else
-        fbOddStipple(dst, dstStride, dstX, dstBpp, width, height,
-                     stip, stipStride, stipWidth, stipHeight,
-                     fgand, fgxor, bgand, bgxor, xRot, yRot);
-}
diff --git a/fb/wfbrename.h b/fb/wfbrename.h
index a80858a..0bd233e 100644
--- a/fb/wfbrename.h
+++ b/fb/wfbrename.h
@@ -58,7 +58,6 @@
 #define fbDots24 wfbDots24
 #define fbDots32 wfbDots32
 #define fbDots8 wfbDots8
-#define fbEvenStipple wfbEvenStipple
 #define fbEvenTile wfbEvenTile
 #define fbExpandDirectColors wfbExpandDirectColors
 #define fbFill wfbFill
@@ -84,7 +83,6 @@
 #define fbInitVisuals wfbInitVisuals
 #define fbListInstalledColormaps wfbListInstalledColormaps
 #define FbMergeRopBits wFbMergeRopBits
-#define fbOddStipple wfbOddStipple
 #define fbOddTile wfbOddTile
 #define fbOver wfbOver
 #define fbOver24 wfbOver24
@@ -143,7 +141,6 @@
 #define fbSolid wfbSolid
 #define fbSolid24 wfbSolid24
 #define fbSolidBoxClipped wfbSolidBoxClipped
-#define fbStipple wfbStipple
 #define fbStipple1Bits wfbStipple1Bits
 #define fbStipple24Bits wfbStipple24Bits
 #define fbStipple2Bits wfbStipple2Bits
@@ -151,7 +148,6 @@
 #define fbStipple8Bits wfbStipple8Bits
 #define fbStippleTable wfbStippleTable
 #define fbTile wfbTile
-#define fbTransparentSpan wfbTransparentSpan
 #define fbTrapezoids wfbTrapezoids
 #define fbTriangles wfbTriangles
 #define fbUninstallColormap wfbUninstallColormap
commit a1983736853814d34450c0a0de1c4f6ee308423d
Author: Adam Jackson <ajax at redhat.com>
Date:   Tue Jun 17 11:24:06 2014 -0400

    fb: FB_SHIFT is 5 (and FB_UNIT is 32)
    
    The other paths don't build or work, PCI and other buses are almost
    always 32 bit data paths, and X doesn't really support pixels bigger
    than that anyway.
    
    Reviewed-by: Keith Packard <keithp at keithp.com>
    Signed-off-by: Adam Jackson <ajax at redhat.com>

diff --git a/fb/fb.h b/fb/fb.h
index d176bb3..6db5803 100644
--- a/fb/fb.h
+++ b/fb/fb.h
@@ -83,11 +83,7 @@
 #define FB_SHIFT    LOG2_BITMAP_PAD
 #endif
 
-#if FB_SHIFT < LOG2_BITMAP_PAD
-error FB_SHIFT must be >= LOG2_BITMAP_PAD
-#endif
 #define FB_UNIT	    (1 << FB_SHIFT)
-#define FB_HALFUNIT (1 << (FB_SHIFT-1))
 #define FB_MASK	    (FB_UNIT - 1)
 #define FB_ALLONES  ((FbBits) -1)
 #if GLYPHPADBYTES != 4
@@ -105,37 +101,15 @@ error FB_SHIFT must be >= LOG2_BITMAP_PAD
 #define FbStipStrideToBitsStride(s) (((s) >> (FB_SHIFT - FB_STIP_SHIFT)))
 #define FbBitsStrideToStipStride(s) (((s) << (FB_SHIFT - FB_STIP_SHIFT)))
 #define FbFullMask(n)   ((n) == FB_UNIT ? FB_ALLONES : ((((FbBits) 1) << n) - 1))
-#if FB_SHIFT == 6
-#ifdef WIN32
-typedef unsigned __int64 FbBits;
-#else
-#if defined(__alpha__) || defined(__alpha) || \
-      defined(ia64) || defined(__ia64__) || \
-      defined(__sparc64__) || defined(_LP64) || \
-      defined(__s390x__) || \
-      defined(amd64) || defined (__amd64__) || \
-      defined (__powerpc64__)
-typedef unsigned long FbBits;
-#else
-typedef unsigned long long FbBits;
-#endif
-#endif
-#endif
 
 #if FB_SHIFT == 5
 typedef CARD32 FbBits;
-#endif
-
-#if FB_SHIFT == 4
-typedef CARD16 FbBits;
+#else
+#error "Unsupported FB_SHIFT"
 #endif
 
 #if LOG2_BITMAP_PAD == FB_SHIFT
 typedef FbBits FbStip;
-#else
-#if LOG2_BITMAP_PAD == 5
-typedef CARD32 FbStip;
-#endif
 #endif
 
 typedef int FbStride;
@@ -264,122 +238,8 @@ extern _X_EXPORT void fbSetBits(FbStip * bits, int stride, FbStip data);
     n >>= FB_SHIFT; \
 }
 
-#if FB_SHIFT == 6
-#define FbDoLeftMaskByteRRop6Cases(dst,xor) \
-    case (sizeof (FbBits) - 7) | (1 << (FB_SHIFT - 3)): \
-	FbStorePart(dst,sizeof (FbBits) - 7,CARD8,xor); \
-	break; \
-    case (sizeof (FbBits) - 7) | (2 << (FB_SHIFT - 3)): \
-	FbStorePart(dst,sizeof (FbBits) - 7,CARD8,xor); \
-	FbStorePart(dst,sizeof (FbBits) - 6,CARD8,xor); \
-	break; \
-    case (sizeof (FbBits) - 7) | (3 << (FB_SHIFT - 3)): \
-	FbStorePart(dst,sizeof (FbBits) - 7,CARD8,xor); \
-	FbStorePart(dst,sizeof (FbBits) - 6,CARD16,xor); \
-	break; \
-    case (sizeof (FbBits) - 7) | (4 << (FB_SHIFT - 3)): \
-	FbStorePart(dst,sizeof (FbBits) - 7,CARD8,xor); \
-	FbStorePart(dst,sizeof (FbBits) - 6,CARD16,xor); \
-	FbStorePart(dst,sizeof (FbBits) - 4,CARD8,xor); \
-	break; \
-    case (sizeof (FbBits) - 7) | (5 << (FB_SHIFT - 3)): \
-	FbStorePart(dst,sizeof (FbBits) - 7,CARD8,xor); \
-	FbStorePart(dst,sizeof (FbBits) - 6,CARD16,xor); \
-	FbStorePart(dst,sizeof (FbBits) - 4,CARD16,xor); \
-	break; \
-    case (sizeof (FbBits) - 7) | (6 << (FB_SHIFT - 3)): \
-	FbStorePart(dst,sizeof (FbBits) - 7,CARD8,xor); \
-	FbStorePart(dst,sizeof (FbBits) - 6,CARD16,xor); \
-	FbStorePart(dst,sizeof (FbBits) - 4,CARD16,xor); \
-	FbStorePart(dst,sizeof (FbBits) - 2,CARD8,xor); \
-	break; \
-    case (sizeof (FbBits) - 7): \
-	FbStorePart(dst,sizeof (FbBits) - 7,CARD8,xor); \
-	FbStorePart(dst,sizeof (FbBits) - 6,CARD16,xor); \
-	FbStorePart(dst,sizeof (FbBits) - 4,CARD32,xor); \
-	break; \
-    case (sizeof (FbBits) - 6) | (1 << (FB_SHIFT - 3)): \
-	FbStorePart(dst,sizeof (FbBits) - 6,CARD8,xor); \
-	break; \
-    case (sizeof (FbBits) - 6) | (2 << (FB_SHIFT - 3)): \
-	FbStorePart(dst,sizeof (FbBits) - 6,CARD16,xor); \
-	break; \
-    case (sizeof (FbBits) - 6) | (3 << (FB_SHIFT - 3)): \
-	FbStorePart(dst,sizeof (FbBits) - 6,CARD16,xor); \
-	FbStorePart(dst,sizeof (FbBits) - 4,CARD8,xor); \
-	break; \
-    case (sizeof (FbBits) - 6) | (4 << (FB_SHIFT - 3)): \
-	FbStorePart(dst,sizeof (FbBits) - 6,CARD16,xor); \
-	FbStorePart(dst,sizeof (FbBits) - 4,CARD16,xor); \
-	break; \
-    case (sizeof (FbBits) - 6) | (5 << (FB_SHIFT - 3)): \
-	FbStorePart(dst,sizeof (FbBits) - 6,CARD16,xor); \
-	FbStorePart(dst,sizeof (FbBits) - 4,CARD16,xor); \
-	FbStorePart(dst,sizeof (FbBits) - 2,CARD8,xor); \
-	break; \
-    case (sizeof (FbBits) - 6): \
-	FbStorePart(dst,sizeof (FbBits) - 6,CARD16,xor); \
-	FbStorePart(dst,sizeof (FbBits) - 4,CARD32,xor); \
-	break; \
-    case (sizeof (FbBits) - 5) | (1 << (FB_SHIFT - 3)): \
-	FbStorePart(dst,sizeof (FbBits) - 5,CARD8,xor); \
-	break; \
-    case (sizeof (FbBits) - 5) | (2 << (FB_SHIFT - 3)): \
-	FbStorePart(dst,sizeof (FbBits) - 5,CARD8,xor); \
-	FbStorePart(dst,sizeof (FbBits) - 4,CARD8,xor); \
-	break; \
-    case (sizeof (FbBits) - 5) | (3 << (FB_SHIFT - 3)): \
-	FbStorePart(dst,sizeof (FbBits) - 5,CARD8,xor); \
-	FbStorePart(dst,sizeof (FbBits) - 4,CARD16,xor); \
-	break; \
-    case (sizeof (FbBits) - 5) | (4 << (FB_SHIFT - 3)): \
-	FbStorePart(dst,sizeof (FbBits) - 5,CARD8,xor); \
-	FbStorePart(dst,sizeof (FbBits) - 4,CARD16,xor); \
-	FbStorePart(dst,sizeof (FbBits) - 2,CARD8,xor); \
-	break; \
-    case (sizeof (FbBits) - 5): \
-	FbStorePart(dst,sizeof (FbBits) - 5,CARD8,xor); \
-	FbStorePart(dst,sizeof (FbBits) - 4,CARD32,xor); \
-	break; \
-    case (sizeof (FbBits) - 4) | (1 << (FB_SHIFT - 3)): \
-	FbStorePart(dst,sizeof (FbBits) - 4,CARD8,xor); \
-	break; \
-    case (sizeof (FbBits) - 4) | (2 << (FB_SHIFT - 3)): \
-	FbStorePart(dst,sizeof (FbBits) - 4,CARD16,xor); \
-	break; \
-    case (sizeof (FbBits) - 4) | (3 << (FB_SHIFT - 3)): \
-	FbStorePart(dst,sizeof (FbBits) - 4,CARD16,xor); \
-	FbStorePart(dst,sizeof (FbBits) - 2,CARD8,xor); \
-	break; \
-    case (sizeof (FbBits) - 4): \
-	FbStorePart(dst,sizeof (FbBits) - 4,CARD32,xor); \
-	break;
-
-#define FbDoRightMaskByteRRop6Cases(dst,xor) \
-    case 4: \
-	FbStorePart(dst,0,CARD32,xor); \
-	break; \
-    case 5: \
-	FbStorePart(dst,0,CARD32,xor); \
-	FbStorePart(dst,4,CARD8,xor); \
-	break; \
-    case 6: \
-	FbStorePart(dst,0,CARD32,xor); \
-	FbStorePart(dst,4,CARD16,xor); \
-	break; \
-    case 7: \
-	FbStorePart(dst,0,CARD32,xor); \
-	FbStorePart(dst,4,CARD16,xor); \
-	FbStorePart(dst,6,CARD8,xor); \
-	break;
-#else
-#define FbDoLeftMaskByteRRop6Cases(dst,xor)
-#define FbDoRightMaskByteRRop6Cases(dst,xor)
-#endif
-
 #define FbDoLeftMaskByteRRop(dst,lb,l,and,xor) { \
     switch (lb) { \
-    FbDoLeftMaskByteRRop6Cases(dst,xor) \
     case (sizeof (FbBits) - 3) | (1 << (FB_SHIFT - 3)): \
 	FbStorePart(dst,sizeof (FbBits) - 3,CARD8,xor); \
 	break; \
@@ -416,7 +276,6 @@ extern _X_EXPORT void fbSetBits(FbStip * bits, int stride, FbStip data);
 	FbStorePart(dst,0,CARD16,xor); \
 	FbStorePart(dst,2,CARD8,xor); \
 	break; \
-    FbDoRightMaskByteRRop6Cases(dst,xor) \
     default: \
 	WRITE(dst, FbDoMaskRRop (READ(dst), and, xor, r)); \
     } \
@@ -470,21 +329,7 @@ extern _X_EXPORT void fbSetBits(FbStip * bits, int stride, FbStip data);
 	FbLaneCase2((n)>>2,a,(o)+2)					\
     }
 
-#define FbLaneCase8(n,a,o)						\
-    if ((n) == 0x0ff) {							\
-	*(FbBits *) ((a)+(o)) = fgxor;					\
-    } else {								\
-	FbLaneCase4((n)&15,a,o)						\
-	FbLaneCase4((n)>>4,a,(o)+4)					\
-    }
-
-#if FB_SHIFT == 6
-#define FbLaneCase(n,a)   FbLaneCase8(n,(CARD8 *) (a),0)
-#endif
-
-#if FB_SHIFT == 5
 #define FbLaneCase(n,a)   FbLaneCase4(n,(CARD8 *) (a),0)
-#endif
 
 /* Rotate a filled pixel value to the specified alignement */
 #define FbRot24(p,b)	    (FbScrRight(p,b) | FbScrLeft(p,24-(b)))
@@ -497,19 +342,6 @@ extern _X_EXPORT void fbSetBits(FbStip * bits, int stride, FbStip data);
 #define FbPrev24Stip(p)	(FbRot24(p,FB_STIP_UNIT%24))
 
 /* step a rotation value to the next/previous rotation value */
-#if FB_UNIT == 64
-#define FbNext24Rot(r)        ((r) == 16 ? 0 : (r) + 8)
-#define FbPrev24Rot(r)        ((r) == 0 ? 16 : (r) - 8)
-
-#if IMAGE_BYTE_ORDER == MSBFirst
-#define FbFirst24Rot(x)		(((x) + 8) % 24)
-#else
-#define FbFirst24Rot(x)		((x) % 24)
-#endif
-
-#endif
-
-#if FB_UNIT == 32
 #define FbNext24Rot(r)        ((r) == 0 ? 16 : (r) - 8)
 #define FbPrev24Rot(r)        ((r) == 16 ? 0 : (r) + 8)
 
@@ -518,7 +350,6 @@ extern _X_EXPORT void fbSetBits(FbStip * bits, int stride, FbStip data);
 #else
 #define FbFirst24Rot(x)		((x) % 24)
 #endif
-#endif
 
 #define FbNext24RotStip(r)        ((r) == 0 ? 16 : (r) - 8)
 #define FbPrev24RotStip(r)        ((r) == 16 ? 0 : (r) + 8)
diff --git a/fb/fbbits.c b/fb/fbbits.c
index ac44f3e..d7d089c 100644
--- a/fb/fbbits.c
+++ b/fb/fbbits.c
@@ -70,9 +70,6 @@
 #define POLYSEGMENT fbPolySegment16
 #define BITS	    CARD16
 #define BITS2	    CARD32
-#if FB_SHIFT == 6
-#define BITS4	    FbBits
-#endif
 
 #include "fbbits.h"
 
@@ -85,9 +82,6 @@
 #undef POLYSEGMENT
 #undef BITS
 #undef BITS2
-#if FB_SHIFT == 6
-#undef BITS4
-#endif
 
 #define BRESSOLID   fbBresSolid24
 #define BRESDASH    fbBresDash24
@@ -155,9 +149,6 @@
 #define POLYLINE    fbPolyline32
 #define POLYSEGMENT fbPolySegment32
 #define BITS	    CARD32
-#if FB_SHIFT == 6
-#define BITS2	    FbBits
-#endif
 
 #include "fbbits.h"
 
@@ -169,6 +160,3 @@
 #undef POLYLINE
 #undef POLYSEGMENT
 #undef BITS
-#if FB_SHIFT == 6
-#undef BITS2
-#endif
diff --git a/fb/fbblt.c b/fb/fbblt.c
index c615106..b412365 100644
--- a/fb/fbblt.c
+++ b/fb/fbblt.c
@@ -520,277 +520,12 @@ fbBlt24(FbBits * srcLine,
 #endif
 }
 
-#if FB_SHIFT == FB_STIP_SHIFT + 1
-
-/*
- * Could be generalized to FB_SHIFT > FB_STIP_SHIFT + 1 by
- * creating an ring of values stepped through for each line
- */
-
-void
-fbBltOdd(FbBits * srcLine,
-         FbStride srcStrideEven,
-         FbStride srcStrideOdd,
-         int srcXEven,
-         int srcXOdd,
-         FbBits * dstLine,
-         FbStride dstStrideEven,
-         FbStride dstStrideOdd,
-         int dstXEven,
-         int dstXOdd, int width, int height, int alu, FbBits pm, int bpp)
-{
-    FbBits *src;
-    int leftShiftEven, rightShiftEven;
-    FbBits startmaskEven, endmaskEven;
-    int nmiddleEven;
-
-    FbBits *dst;
-    int leftShiftOdd, rightShiftOdd;
-    FbBits startmaskOdd, endmaskOdd;
-    int nmiddleOdd;
-
-    int leftShift, rightShift;
-    FbBits startmask, endmask;
-    int nmiddle;
-
-    int srcX, dstX;
-
-    FbBits bits, bits1;
-    int n;
-
-    Bool destInvarient;
-    Bool even;
-
-    FbDeclareMergeRop();
-
-    FbInitializeMergeRop(alu, pm);
-    destInvarient = FbDestInvarientMergeRop();
-
-    srcLine += srcXEven >> FB_SHIFT;
-    dstLine += dstXEven >> FB_SHIFT;
-    srcXEven &= FB_MASK;
-    dstXEven &= FB_MASK;
-    srcXOdd &= FB_MASK;
-    dstXOdd &= FB_MASK;
-
-    FbMaskBits(dstXEven, width, startmaskEven, nmiddleEven, endmaskEven);
-    FbMaskBits(dstXOdd, width, startmaskOdd, nmiddleOdd, endmaskOdd);
-
-    even = TRUE;
-    InitializeShifts(srcXEven, dstXEven, leftShiftEven, rightShiftEven);
-    InitializeShifts(srcXOdd, dstXOdd, leftShiftOdd, rightShiftOdd);
-    while (height--) {
-        src = srcLine;
-        dst = dstLine;
-        if (even) {
-            srcX = srcXEven;
-            dstX = dstXEven;
-            startmask = startmaskEven;
-            endmask = endmaskEven;
-            nmiddle = nmiddleEven;
-            leftShift = leftShiftEven;
-            rightShift = rightShiftEven;
-            srcLine += srcStrideEven;
-            dstLine += dstStrideEven;
-            even = FALSE;
-        }
-        else {
-            srcX = srcXOdd;
-            dstX = dstXOdd;
-            startmask = startmaskOdd;
-            endmask = endmaskOdd;
-            nmiddle = nmiddleOdd;
-            leftShift = leftShiftOdd;
-            rightShift = rightShiftOdd;
-            srcLine += srcStrideOdd;
-            dstLine += dstStrideOdd;
-            even = TRUE;
-        }
-        if (srcX == dstX) {
-            if (startmask) {
-                bits = READ(src++);
-                WRITE(dst, FbDoMaskMergeRop(bits, READ(dst), startmask));
-                dst++;
-            }
-            n = nmiddle;
-            if (destInvarient) {
-                while (n--) {
-                    bits = READ(src++);
-                    WRITE(dst, FbDoDestInvarientMergeRop(bits));
-                    dst++;
-                }
-            }
-            else {
-                while (n--) {
-                    bits = READ(src++);
-                    WRITE(dst, FbDoMergeRop(bits, READ(dst)));
-                    dst++;
-                }
-            }
-            if (endmask) {
-                bits = READ(src);
-                WRITE(dst, FbDoMaskMergeRop(bits, READ(dst), endmask));
-            }
-        }
-        else {
-            bits = 0;
-            if (srcX > dstX)
-                bits = READ(src++);
-            if (startmask) {
-                bits1 = FbScrLeft(bits, leftShift);
-                bits = READ(src++);
-                bits1 |= FbScrRight(bits, rightShift);
-                WRITE(dst, FbDoMaskMergeRop(bits1, READ(dst), startmask));
-                dst++;
-            }
-            n = nmiddle;
-            if (destInvarient) {
-                while (n--) {
-                    bits1 = FbScrLeft(bits, leftShift);
-                    bits = READ(src++);
-                    bits1 |= FbScrRight(bits, rightShift);
-                    WRITE(dst, FbDoDestInvarientMergeRop(bits1));
-                    dst++;
-                }
-            }
-            else {
-                while (n--) {
-                    bits1 = FbScrLeft(bits, leftShift);
-                    bits = READ(src++);
-                    bits1 |= FbScrRight(bits, rightShift);
-                    WRITE(dst, FbDoMergeRop(bits1, READ(dst)));
-                    dst++;
-                }
-            }
-            if (endmask) {
-                bits1 = FbScrLeft(bits, leftShift);
-                if (FbScrLeft(endmask, rightShift)) {
-                    bits = READ(src);
-                    bits1 |= FbScrRight(bits, rightShift);
-                }
-                WRITE(dst, FbDoMaskMergeRop(bits1, READ(dst), endmask));
-            }
-        }
-    }
-}
-
-void
-fbBltOdd24(FbBits * srcLine,
-           FbStride srcStrideEven,
-           FbStride srcStrideOdd,
-           int srcXEven,
-           int srcXOdd,
-           FbBits * dstLine,
-           FbStride dstStrideEven,
-           FbStride dstStrideOdd,
-           int dstXEven, int dstXOdd, int width, int height, int alu, FbBits pm)
-{
-    Bool even = TRUE;
-
-    while (height--) {
-        if (even) {
-            fbBlt24Line(srcLine, srcXEven, dstLine, dstXEven,
-                        width, alu, pm, FALSE);
-            srcLine += srcStrideEven;
-            dstLine += dstStrideEven;
-            even = FALSE;
-        }
-        else {
-            fbBlt24Line(srcLine, srcXOdd, dstLine, dstXOdd,
-                        width, alu, pm, FALSE);
-            srcLine += srcStrideOdd;
-            dstLine += dstStrideOdd;
-            even = TRUE;
-        }
-    }
-}
-
-#endif
-
-#if FB_STIP_SHIFT != FB_SHIFT
-void
-fbSetBltOdd(FbStip * stip,
-            FbStride stipStride,
-            int srcX,
-            FbBits ** bits,
-            FbStride * strideEven,
-            FbStride * strideOdd, int *srcXEven, int *srcXOdd)
-{
-    int srcAdjust;
-    int strideAdjust;
-
-    /*
-     * bytes needed to align source
-     */
-    srcAdjust = (((int) stip) & (FB_MASK >> 3));
-    /*
-     * FbStip units needed to align stride
-     */
-    strideAdjust = stipStride & (FB_MASK >> FB_STIP_SHIFT);
-
-    *bits = (FbBits *) ((char *) stip - srcAdjust);
-    if (srcAdjust) {
-        *strideEven = FbStipStrideToBitsStride(stipStride + 1);
-        *strideOdd = FbStipStrideToBitsStride(stipStride);
-
-        *srcXEven = srcX + (srcAdjust << 3);
-        *srcXOdd = srcX + (srcAdjust << 3) - (strideAdjust << FB_STIP_SHIFT);
-    }
-    else {
-        *strideEven = FbStipStrideToBitsStride(stipStride);
-        *strideOdd = FbStipStrideToBitsStride(stipStride + 1);
-
-        *srcXEven = srcX;
-        *srcXOdd = srcX + (strideAdjust << FB_STIP_SHIFT);
-    }
-}
-#endif
-
 void
 fbBltStip(FbStip * src, FbStride srcStride,     /* in FbStip units, not FbBits units */
           int srcX, FbStip * dst, FbStride dstStride,   /* in FbStip units, not FbBits units */
           int dstX, int width, int height, int alu, FbBits pm, int bpp)
 {
-#if FB_STIP_SHIFT != FB_SHIFT
-    if (FB_STIP_ODDSTRIDE(srcStride) || FB_STIP_ODDPTR(src) ||
-        FB_STIP_ODDSTRIDE(dstStride) || FB_STIP_ODDPTR(dst)) {
-        FbStride srcStrideEven, srcStrideOdd;
-        FbStride dstStrideEven, dstStrideOdd;
-        int srcXEven, srcXOdd;
-        int dstXEven, dstXOdd;
-        FbBits *s, *d;
-        int sx, dx;
-
-        src += srcX >> FB_STIP_SHIFT;
-        srcX &= FB_STIP_MASK;
-        dst += dstX >> FB_STIP_SHIFT;
-        dstX &= FB_STIP_MASK;
-
-        fbSetBltOdd(src, srcStride, srcX,
-                    &s, &srcStrideEven, &srcStrideOdd, &srcXEven, &srcXOdd);
-
-        fbSetBltOdd(dst, dstStride, dstX,
-                    &d, &dstStrideEven, &dstStrideOdd, &dstXEven, &dstXOdd);
-
-        if (bpp == 24 && !FbCheck24Pix(pm)) {
-            fbBltOdd24(s, srcStrideEven, srcStrideOdd,
-                       srcXEven, srcXOdd,
-                       d, dstStrideEven, dstStrideOdd,
-                       dstXEven, dstXOdd, width, height, alu, pm);
-        }
-        else {
-            fbBltOdd(s, srcStrideEven, srcStrideOdd,
-                     srcXEven, srcXOdd,
-                     d, dstStrideEven, dstStrideOdd,
-                     dstXEven, dstXOdd, width, height, alu, pm, bpp);
-        }
-    }
-    else
-#endif
-    {
-        fbBlt((FbBits *) src, FbStipStrideToBitsStride(srcStride),
-              srcX,
-              (FbBits *) dst, FbStipStrideToBitsStride(dstStride),
-              dstX, width, height, alu, pm, bpp, FALSE, FALSE);
-    }
+    fbBlt((FbBits *) src, FbStipStrideToBitsStride(srcStride), srcX,
+          (FbBits *) dst, FbStipStrideToBitsStride(dstStride), dstX,
+          width, height, alu, pm, bpp, FALSE, FALSE);
 }
diff --git a/fb/fbbltone.c b/fb/fbbltone.c
index d2f0416..3042c4b 100644
--- a/fb/fbbltone.c
+++ b/fb/fbbltone.c
@@ -67,59 +67,9 @@
 #define LaneCases4(n,a)	    LaneCases2(n,a); LaneCases2(n+2,a)
 #define LaneCases8(n,a)	    LaneCases4(n,a); LaneCases4(n+4,a)
 #define LaneCases16(n,a)    LaneCases8(n,a); LaneCases8(n+8,a)
-#define LaneCases32(n,a)    LaneCases16(n,a); LaneCases16(n+16,a)
-#define LaneCases64(n,a)    LaneCases32(n,a); LaneCases32(n+32,a)
-#define LaneCases128(n,a)   LaneCases64(n,a); LaneCases64(n+64,a)
-#define LaneCases256(n,a)   LaneCases128(n,a); LaneCases128(n+128,a)
 
-#if FB_SHIFT == 6
-#define LaneCases(a)	    LaneCases256(0,a)
-#endif
-
-#if FB_SHIFT == 5
 #define LaneCases(a)	    LaneCases16(0,a)
-#endif
-
-#if FB_SHIFT == 6
-static const CARD8 fb8Lane[256] = {
-    0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,
-        21,
-    22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
-    41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59,
-    60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78,
-    79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97,
-    98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112,
-        113, 114, 115,
-    116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130,
-        131, 132, 133,
-    134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148,
-        149, 150, 151,
-    152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166,
-        167, 168, 169,
-    170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184,
-        185, 186, 187,
-    188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 200, 201, 202,
-        203, 204, 205,
-    206, 207, 208, 209, 210, 211, 212, 213, 214, 215, 216, 217, 218, 219, 220,
-        221, 222, 223,
-    224, 225, 226, 227, 228, 229, 230, 231, 232, 233, 234, 235, 236, 237, 238,
-        239, 240, 241,
-    242, 243, 244, 245, 246, 247, 248, 249, 250, 251, 252, 253, 254, 255,
-};
-
-static const CARD8 fb16Lane[256] = {
-    0x00, 0x03, 0x0c, 0x0f,
-    0x30, 0x33, 0x3c, 0x3f,
-    0xc0, 0xc3, 0xcc, 0xcf,
-    0xf0, 0xf3, 0xfc, 0xff,
-};
-
-static const CARD8 fb32Lane[16] = {
-    0x00, 0x0f, 0xf0, 0xff,
-};
-#endif
 
-#if FB_SHIFT == 5
 static const CARD8 fb8Lane[16] = {
     0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15
 };
@@ -131,7 +81,6 @@ static const CARD8 fb16Lane[16] = {
 static const CARD8 fb32Lane[16] = {
     0, 15, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
 };
-#endif
 
 void
 fbBltOne(FbStip * src, FbStride srcStride,      /* FbStip units per scanline */
@@ -285,12 +234,7 @@ fbBltOne(FbStip * src, FbStride srcStride,      /* FbStip units per scanline */
              * Consume stipple bits for startmask
              */
             if (startmask) {
-#if FB_UNIT > 32
-                if (pixelsPerDst == 16)
-                    mask = FbStipple16Bits(FbLeftStipBits(bits, 16));
-                else
-#endif
-                    mask = fbBits[FbLeftStipBits(bits, pixelsPerDst)];
+                mask = fbBits[FbLeftStipBits(bits, pixelsPerDst)];
                 if (fbLane) {
                     fbTransparentSpan(dst, mask & startmask, fgxor, 1);
                 }
@@ -312,12 +256,7 @@ fbBltOne(FbStip * src, FbStride srcStride,      /* FbStip units per scanline */
                 w -= n;
                 if (copy) {
                     while (n--) {
-#if FB_UNIT > 32
-                        if (pixelsPerDst == 16)
-                            mask = FbStipple16Bits(FbLeftStipBits(bits, 16));
-                        else
-#endif
-                            mask = fbBits[FbLeftStipBits(bits, pixelsPerDst)];
+                        mask = fbBits[FbLeftStipBits(bits, pixelsPerDst)];
                         WRITE(dst, FbOpaqueStipple(mask, fgxor, bgxor));
                         dst++;
                         bits = FbStipLeft(bits, pixelsPerDst);
@@ -367,12 +306,7 @@ fbBltOne(FbStip * src, FbStride srcStride,      /* FbStip units per scanline */
             if (endNeedsLoad) {
                 LoadBits;
             }
-#if FB_UNIT > 32
-            if (pixelsPerDst == 16)
-                mask = FbStipple16Bits(FbLeftStipBits(bits, 16));
-            else
-#endif
-                mask = fbBits[FbLeftStipBits(bits, pixelsPerDst)];
+            mask = fbBits[FbLeftStipBits(bits, pixelsPerDst)];
             if (fbLane) {
                 fbTransparentSpan(dst, mask & endmask, fgxor, 1);
             }
@@ -410,47 +344,6 @@ fbBltOne(FbStip * src, FbStride srcStride,      /* FbStip units per scanline */
 
 #define SelMask24(b,n,r)	((((b) >> n) & 1) * Mask24(n,r))
 
-/*
- * Untested for MSBFirst or FB_UNIT == 32
- */
-
-#if FB_UNIT == 64
-#define C4_24(b,r) \
-    (SelMask24(b,0,r) | \
-     SelMask24(b,1,r) | \
-     SelMask24(b,2,r) | \
-     SelMask24(b,3,r))
-
-#define FbStip24New(rot)    (2 + (rot != 0))
-#define FbStip24Len	    4
-
-const FbBits fbStipple24Bits[3][1 << FbStip24Len] = {
-    /* rotate 0 */
-    {
-     C4_24(0, 0), C4_24(1, 0), C4_24(2, 0), C4_24(3, 0),
-     C4_24(4, 0), C4_24(5, 0), C4_24(6, 0), C4_24(7, 0),
-     C4_24(8, 0), C4_24(9, 0), C4_24(10, 0), C4_24(11, 0),
-     C4_24(12, 0), C4_24(13, 0), C4_24(14, 0), C4_24(15, 0),
-     },
-    /* rotate 8 */
-    {
-     C4_24(0, 8), C4_24(1, 8), C4_24(2, 8), C4_24(3, 8),
-     C4_24(4, 8), C4_24(5, 8), C4_24(6, 8), C4_24(7, 8),
-     C4_24(8, 8), C4_24(9, 8), C4_24(10, 8), C4_24(11, 8),
-     C4_24(12, 8), C4_24(13, 8), C4_24(14, 8), C4_24(15, 8),
-     },
-    /* rotate 16 */
-    {
-     C4_24(0, 16), C4_24(1, 16), C4_24(2, 16), C4_24(3, 16),
-     C4_24(4, 16), C4_24(5, 16), C4_24(6, 16), C4_24(7, 16),
-     C4_24(8, 16), C4_24(9, 16), C4_24(10, 16), C4_24(11, 16),
-     C4_24(12, 16), C4_24(13, 16), C4_24(14, 16), C4_24(15, 16),
-     }
-};
-
-#endif
-
-#if FB_UNIT == 32
 #define C2_24(b,r)  \
     (SelMask24(b,0,r) | \
      SelMask24(b,1,r))
@@ -476,7 +369,6 @@ const FbBits fbStipple24Bits[3][1 << FbStip24Len] = {
      C2_24(0, 16), C2_24(1, 16), C2_24(2, 16), C2_24(3, 16),
      }
 };
-#endif
 
 #if BITMAP_BIT_ORDER == LSBFirst
 
diff --git a/fb/fbglyph.c b/fb/fbglyph.c
index 4f2904c..8484782 100644
--- a/fb/fbglyph.c
+++ b/fb/fbglyph.c
@@ -56,11 +56,7 @@ fbGlyphIn(RegionPtr pRegion, int x, int y, int width, int height)
 #define WRITE1(d,n,fg)	WRITE((d) + (n), (CARD8) fg)
 #define WRITE2(d,n,fg)	WRITE((CARD16 *) &(d[n]), (CARD16) fg)
 #define WRITE4(d,n,fg)	WRITE((CARD32 *) &(d[n]), (CARD32) fg)
-#if FB_UNIT == 6 && IMAGE_BYTE_ORDER == LSBFirst
-#define WRITE8(d)	WRITE((FbBits *) &(d[0]), fg)
-#else
 #define WRITE8(d)	WRITE4(d,0,_ABCA), WRITE4(d,4,_BCAB)
-#endif
 
 /*
  * This is a bit tricky, but it's brief.  Write 12 bytes worth
diff --git a/fb/fbpict.c b/fb/fbpict.c
index f9c9917..7a9e46a 100644
--- a/fb/fbpict.c
+++ b/fb/fbpict.c
@@ -309,17 +309,9 @@ create_bits_picture(PicturePtr pict, Bool has_clip, int *xoff, int *yoff)
         return NULL;
 
 #ifdef FB_ACCESS_WRAPPER
-#if FB_SHIFT==5
-
     pixman_image_set_accessors(image,
                                (pixman_read_memory_func_t) wfbReadMemory,
                                (pixman_write_memory_func_t) wfbWriteMemory);
-
-#else
-
-#error The pixman library only works when FbBits is 32 bits wide
-
-#endif
 #endif
 
     /* pCompositeClip is undefined for source pictures, so
diff --git a/fb/fbrop.h b/fb/fbrop.h
index 4362adb..b995f23 100644
--- a/fb/fbrop.h
+++ b/fb/fbrop.h
@@ -95,10 +95,6 @@ extern _X_EXPORT const FbMergeRopRec FbMergeRopBits[16];
  * Stippling operations; 
  */
 
-extern _X_EXPORT const FbBits fbStipple16Bits[256];     /* half of table */
-
-#define FbStipple16Bits(b) \
-    (fbStipple16Bits[(b)&0xff] | fbStipple16Bits[(b) >> 8] << FB_HALFUNIT)
 extern _X_EXPORT const FbBits fbStipple8Bits[256];
 extern _X_EXPORT const FbBits fbStipple4Bits[16];
 extern _X_EXPORT const FbBits fbStipple2Bits[4];
diff --git a/fb/fbstipple.c b/fb/fbstipple.c
index f6c84a2..9a877c1 100644
--- a/fb/fbstipple.c
+++ b/fb/fbstipple.c
@@ -38,18 +38,8 @@
 #define LaneCases4(c,a)	    LaneCases2(c,a); LaneCases2(c+2,a)
 #define LaneCases8(c,a)	    LaneCases4(c,a); LaneCases4(c+4,a)
 #define LaneCases16(c,a)    LaneCases8(c,a); LaneCases8(c+8,a)
-#define LaneCases32(c,a)    LaneCases16(c,a); LaneCases16(c+16,a)
-#define LaneCases64(c,a)    LaneCases32(c,a); LaneCases32(c+32,a)
-#define LaneCases128(c,a)   LaneCases64(c,a); LaneCases64(c+64,a)
-#define LaneCases256(c,a)   LaneCases128(c,a); LaneCases128(c+128,a)
 
-#if FB_SHIFT == 6
-#define LaneCases(a)	    LaneCases256(0,a)
-#endif
-
-#if FB_SHIFT == 5
 #define LaneCases(a)	    LaneCases16(0,a)
-#endif
 
 /*
  * Repeat a transparent stipple across a scanline n times
@@ -64,12 +54,6 @@ fbTransparentSpan(FbBits * dst, FbBits stip, FbBits fgxor, int n)
     s |= ((FbStip) (stip >> 8) & 0x02);
     s |= ((FbStip) (stip >> 16) & 0x04);
     s |= ((FbStip) (stip >> 24) & 0x08);
-#if FB_SHIFT > 5
-    s |= ((FbStip) (stip >> 32) & 0x10);
-    s |= ((FbStip) (stip >> 40) & 0x20);
-    s |= ((FbStip) (stip >> 48) & 0x40);
-    s |= ((FbStip) (stip >> 56) & 0x80);
-#endif
     switch (s) {
         LaneCases(dst);
     }
@@ -142,12 +126,7 @@ fbEvenStipple(FbBits * dst,
         s += stipStride;
         if (s == stipEnd)
             s = stip;
-#if FB_UNIT > 32
-        if (pixelsPerDst == 16)
-            mask = FbStipple16Bits(FbLeftStipBits(bits, 16));
-        else
-#endif
-            mask = fbBits[FbLeftStipBits(bits, pixelsPerDst)];
+        mask = fbBits[FbLeftStipBits(bits, pixelsPerDst)];
         /*
          * Rotate into position and compute reduced rop values
          */
diff --git a/fb/fbutil.c b/fb/fbutil.c
index 2ca80d1..9d66c2a 100644
--- a/fb/fbutil.c
+++ b/fb/fbutil.c
@@ -174,24 +174,6 @@ const FbMergeRopRec FbMergeRopBits[16] = {
      SelMask(b,6,w) | \
      SelMask(b,7,w))
 
-#if FB_UNIT == 16
-#define fbStipple16Bits 0
-#define fbStipple8Bits 0
-const FbBits fbStipple4Bits[16] = {
-    C4(0, 4), C4(1, 4), C4(2, 4), C4(3, 4), C4(4, 4), C4(5, 4),
-    C4(6, 4), C4(7, 4), C4(8, 4), C4(9, 4), C4(10, 4), C4(11, 4),
-    C4(12, 4), C4(13, 4), C4(14, 4), C4(15, 4),
-};
-
-const FbBits fbStipple2Bits[4] = {
-    C2(0, 8), C2(1, 8), C2(2, 8), C2(3, 8),
-};
-
-const FbBits fbStipple1Bits[2] = {
-    C1(0, 16), C1(1, 16),
-};
-#endif
-#if FB_UNIT == 32
 #define fbStipple16Bits 0
 const FbBits fbStipple8Bits[256] = {
     C8(0, 4), C8(1, 4), C8(2, 4), C8(3, 4), C8(4, 4), C8(5, 4),
@@ -252,112 +234,7 @@ const FbBits fbStipple2Bits[4] = {
 const FbBits fbStipple1Bits[2] = {
     C1(0, 32), C1(1, 32),
 };
-#endif
-#if FB_UNIT == 64
-const FbBits fbStipple16Bits[256] = {
-    C8(0, 4), C8(1, 4), C8(2, 4), C8(3, 4), C8(4, 4), C8(5, 4),
-    C8(6, 4), C8(7, 4), C8(8, 4), C8(9, 4), C8(10, 4), C8(11, 4),
-    C8(12, 4), C8(13, 4), C8(14, 4), C8(15, 4), C8(16, 4), C8(17, 4),
-    C8(18, 4), C8(19, 4), C8(20, 4), C8(21, 4), C8(22, 4), C8(23, 4),
-    C8(24, 4), C8(25, 4), C8(26, 4), C8(27, 4), C8(28, 4), C8(29, 4),
-    C8(30, 4), C8(31, 4), C8(32, 4), C8(33, 4), C8(34, 4), C8(35, 4),
-    C8(36, 4), C8(37, 4), C8(38, 4), C8(39, 4), C8(40, 4), C8(41, 4),
-    C8(42, 4), C8(43, 4), C8(44, 4), C8(45, 4), C8(46, 4), C8(47, 4),
-    C8(48, 4), C8(49, 4), C8(50, 4), C8(51, 4), C8(52, 4), C8(53, 4),
-    C8(54, 4), C8(55, 4), C8(56, 4), C8(57, 4), C8(58, 4), C8(59, 4),
-    C8(60, 4), C8(61, 4), C8(62, 4), C8(63, 4), C8(64, 4), C8(65, 4),
-    C8(66, 4), C8(67, 4), C8(68, 4), C8(69, 4), C8(70, 4), C8(71, 4),
-    C8(72, 4), C8(73, 4), C8(74, 4), C8(75, 4), C8(76, 4), C8(77, 4),
-    C8(78, 4), C8(79, 4), C8(80, 4), C8(81, 4), C8(82, 4), C8(83, 4),
-    C8(84, 4), C8(85, 4), C8(86, 4), C8(87, 4), C8(88, 4), C8(89, 4),
-    C8(90, 4), C8(91, 4), C8(92, 4), C8(93, 4), C8(94, 4), C8(95, 4),
-    C8(96, 4), C8(97, 4), C8(98, 4), C8(99, 4), C8(100, 4), C8(101, 4),
-    C8(102, 4), C8(103, 4), C8(104, 4), C8(105, 4), C8(106, 4), C8(107, 4),
-    C8(108, 4), C8(109, 4), C8(110, 4), C8(111, 4), C8(112, 4), C8(113, 4),
-    C8(114, 4), C8(115, 4), C8(116, 4), C8(117, 4), C8(118, 4), C8(119, 4),
-    C8(120, 4), C8(121, 4), C8(122, 4), C8(123, 4), C8(124, 4), C8(125, 4),
-    C8(126, 4), C8(127, 4), C8(128, 4), C8(129, 4), C8(130, 4), C8(131, 4),
-    C8(132, 4), C8(133, 4), C8(134, 4), C8(135, 4), C8(136, 4), C8(137, 4),
-    C8(138, 4), C8(139, 4), C8(140, 4), C8(141, 4), C8(142, 4), C8(143, 4),
-    C8(144, 4), C8(145, 4), C8(146, 4), C8(147, 4), C8(148, 4), C8(149, 4),
-    C8(150, 4), C8(151, 4), C8(152, 4), C8(153, 4), C8(154, 4), C8(155, 4),
-    C8(156, 4), C8(157, 4), C8(158, 4), C8(159, 4), C8(160, 4), C8(161, 4),
-    C8(162, 4), C8(163, 4), C8(164, 4), C8(165, 4), C8(166, 4), C8(167, 4),
-    C8(168, 4), C8(169, 4), C8(170, 4), C8(171, 4), C8(172, 4), C8(173, 4),
-    C8(174, 4), C8(175, 4), C8(176, 4), C8(177, 4), C8(178, 4), C8(179, 4),
-    C8(180, 4), C8(181, 4), C8(182, 4), C8(183, 4), C8(184, 4), C8(185, 4),
-    C8(186, 4), C8(187, 4), C8(188, 4), C8(189, 4), C8(190, 4), C8(191, 4),
-    C8(192, 4), C8(193, 4), C8(194, 4), C8(195, 4), C8(196, 4), C8(197, 4),
-    C8(198, 4), C8(199, 4), C8(200, 4), C8(201, 4), C8(202, 4), C8(203, 4),
-    C8(204, 4), C8(205, 4), C8(206, 4), C8(207, 4), C8(208, 4), C8(209, 4),
-    C8(210, 4), C8(211, 4), C8(212, 4), C8(213, 4), C8(214, 4), C8(215, 4),
-    C8(216, 4), C8(217, 4), C8(218, 4), C8(219, 4), C8(220, 4), C8(221, 4),
-    C8(222, 4), C8(223, 4), C8(224, 4), C8(225, 4), C8(226, 4), C8(227, 4),
-    C8(228, 4), C8(229, 4), C8(230, 4), C8(231, 4), C8(232, 4), C8(233, 4),
-    C8(234, 4), C8(235, 4), C8(236, 4), C8(237, 4), C8(238, 4), C8(239, 4),
-    C8(240, 4), C8(241, 4), C8(242, 4), C8(243, 4), C8(244, 4), C8(245, 4),
-    C8(246, 4), C8(247, 4), C8(248, 4), C8(249, 4), C8(250, 4), C8(251, 4),
-    C8(252, 4), C8(253, 4), C8(254, 4), C8(255, 4),
-};
-
-const FbBits fbStipple8Bits[256] = {
-    C8(0, 8), C8(1, 8), C8(2, 8), C8(3, 8), C8(4, 8), C8(5, 8),
-    C8(6, 8), C8(7, 8), C8(8, 8), C8(9, 8), C8(10, 8), C8(11, 8),
-    C8(12, 8), C8(13, 8), C8(14, 8), C8(15, 8), C8(16, 8), C8(17, 8),
-    C8(18, 8), C8(19, 8), C8(20, 8), C8(21, 8), C8(22, 8), C8(23, 8),
-    C8(24, 8), C8(25, 8), C8(26, 8), C8(27, 8), C8(28, 8), C8(29, 8),
-    C8(30, 8), C8(31, 8), C8(32, 8), C8(33, 8), C8(34, 8), C8(35, 8),
-    C8(36, 8), C8(37, 8), C8(38, 8), C8(39, 8), C8(40, 8), C8(41, 8),
-    C8(42, 8), C8(43, 8), C8(44, 8), C8(45, 8), C8(46, 8), C8(47, 8),
-    C8(48, 8), C8(49, 8), C8(50, 8), C8(51, 8), C8(52, 8), C8(53, 8),
-    C8(54, 8), C8(55, 8), C8(56, 8), C8(57, 8), C8(58, 8), C8(59, 8),
-    C8(60, 8), C8(61, 8), C8(62, 8), C8(63, 8), C8(64, 8), C8(65, 8),
-    C8(66, 8), C8(67, 8), C8(68, 8), C8(69, 8), C8(70, 8), C8(71, 8),
-    C8(72, 8), C8(73, 8), C8(74, 8), C8(75, 8), C8(76, 8), C8(77, 8),
-    C8(78, 8), C8(79, 8), C8(80, 8), C8(81, 8), C8(82, 8), C8(83, 8),
-    C8(84, 8), C8(85, 8), C8(86, 8), C8(87, 8), C8(88, 8), C8(89, 8),
-    C8(90, 8), C8(91, 8), C8(92, 8), C8(93, 8), C8(94, 8), C8(95, 8),
-    C8(96, 8), C8(97, 8), C8(98, 8), C8(99, 8), C8(100, 8), C8(101, 8),
-    C8(102, 8), C8(103, 8), C8(104, 8), C8(105, 8), C8(106, 8), C8(107, 8),
-    C8(108, 8), C8(109, 8), C8(110, 8), C8(111, 8), C8(112, 8), C8(113, 8),
-    C8(114, 8), C8(115, 8), C8(116, 8), C8(117, 8), C8(118, 8), C8(119, 8),
-    C8(120, 8), C8(121, 8), C8(122, 8), C8(123, 8), C8(124, 8), C8(125, 8),
-    C8(126, 8), C8(127, 8), C8(128, 8), C8(129, 8), C8(130, 8), C8(131, 8),
-    C8(132, 8), C8(133, 8), C8(134, 8), C8(135, 8), C8(136, 8), C8(137, 8),
-    C8(138, 8), C8(139, 8), C8(140, 8), C8(141, 8), C8(142, 8), C8(143, 8),
-    C8(144, 8), C8(145, 8), C8(146, 8), C8(147, 8), C8(148, 8), C8(149, 8),
-    C8(150, 8), C8(151, 8), C8(152, 8), C8(153, 8), C8(154, 8), C8(155, 8),
-    C8(156, 8), C8(157, 8), C8(158, 8), C8(159, 8), C8(160, 8), C8(161, 8),
-    C8(162, 8), C8(163, 8), C8(164, 8), C8(165, 8), C8(166, 8), C8(167, 8),
-    C8(168, 8), C8(169, 8), C8(170, 8), C8(171, 8), C8(172, 8), C8(173, 8),
-    C8(174, 8), C8(175, 8), C8(176, 8), C8(177, 8), C8(178, 8), C8(179, 8),
-    C8(180, 8), C8(181, 8), C8(182, 8), C8(183, 8), C8(184, 8), C8(185, 8),
-    C8(186, 8), C8(187, 8), C8(188, 8), C8(189, 8), C8(190, 8), C8(191, 8),
-    C8(192, 8), C8(193, 8), C8(194, 8), C8(195, 8), C8(196, 8), C8(197, 8),
-    C8(198, 8), C8(199, 8), C8(200, 8), C8(201, 8), C8(202, 8), C8(203, 8),
-    C8(204, 8), C8(205, 8), C8(206, 8), C8(207, 8), C8(208, 8), C8(209, 8),
-    C8(210, 8), C8(211, 8), C8(212, 8), C8(213, 8), C8(214, 8), C8(215, 8),
-    C8(216, 8), C8(217, 8), C8(218, 8), C8(219, 8), C8(220, 8), C8(221, 8),
-    C8(222, 8), C8(223, 8), C8(224, 8), C8(225, 8), C8(226, 8), C8(227, 8),
-    C8(228, 8), C8(229, 8), C8(230, 8), C8(231, 8), C8(232, 8), C8(233, 8),
-    C8(234, 8), C8(235, 8), C8(236, 8), C8(237, 8), C8(238, 8), C8(239, 8),
-    C8(240, 8), C8(241, 8), C8(242, 8), C8(243, 8), C8(244, 8), C8(245, 8),
-    C8(246, 8), C8(247, 8), C8(248, 8), C8(249, 8), C8(250, 8), C8(251, 8),
-    C8(252, 8), C8(253, 8), C8(254, 8), C8(255, 8),
-};
-
-const FbBits fbStipple4Bits[16] = {
-    C4(0, 16), C4(1, 16), C4(2, 16), C4(3, 16), C4(4, 16), C4(5, 16),
-    C4(6, 16), C4(7, 16), C4(8, 16), C4(9, 16), C4(10, 16), C4(11, 16),
-    C4(12, 16), C4(13, 16), C4(14, 16), C4(15, 16),
-};
 
-const FbBits fbStipple2Bits[4] = {
-    C2(0, 32), C2(1, 32), C2(2, 32), C2(3, 32),
-};
-
-#define fbStipple1Bits 0
-#endif
 const FbBits *const fbStippleTable[] = {
     0,
     fbStipple1Bits,
commit 3d35bd6b79957a3441abd87a377f0beb058997ed
Author: Adam Jackson <ajax at redhat.com>
Date:   Mon Mar 24 12:01:54 2014 -0400

    fb: Eliminate fbLaneTable, staticize fb{8,16,32}Lane
    
    gcc doesn't appear to be smart enough to fold away the indirection here,
    even if you make fbLaneTable const.
    
    Reviewed-by: Keith Packard <keithp at keithp.com>
    Signed-off-by: Adam Jackson <ajax at redhat.com>

diff --git a/fb/fbbltone.c b/fb/fbbltone.c
index bfcb5a2..d2f0416 100644
--- a/fb/fbbltone.c
+++ b/fb/fbbltone.c
@@ -81,7 +81,7 @@
 #endif
 
 #if FB_SHIFT == 6
-CARD8 fb8Lane[256] = {
+static const CARD8 fb8Lane[256] = {
     0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,
         21,
     22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
@@ -107,40 +107,32 @@ CARD8 fb8Lane[256] = {
     242, 243, 244, 245, 246, 247, 248, 249, 250, 251, 252, 253, 254, 255,
 };
 
-CARD8 fb16Lane[256] = {
+static const CARD8 fb16Lane[256] = {
     0x00, 0x03, 0x0c, 0x0f,
     0x30, 0x33, 0x3c, 0x3f,
     0xc0, 0xc3, 0xcc, 0xcf,
     0xf0, 0xf3, 0xfc, 0xff,
 };
 
-CARD8 fb32Lane[16] = {
+static const CARD8 fb32Lane[16] = {
     0x00, 0x0f, 0xf0, 0xff,
 };
 #endif
 
 #if FB_SHIFT == 5
-CARD8 fb8Lane[16] = {
+static const CARD8 fb8Lane[16] = {
     0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15
 };
 
-CARD8 fb16Lane[16] = {
+static const CARD8 fb16Lane[16] = {
     0, 3, 12, 15, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
 };
 
-CARD8 fb32Lane[16] = {
+static const CARD8 fb32Lane[16] = {
     0, 15, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
 };
 #endif
 
-CARD8 *fbLaneTable[33] = {
-    0, 0, 0, 0, 0, 0, 0, 0,
-    fb8Lane, 0, 0, 0, 0, 0, 0, 0,
-    fb16Lane, 0, 0, 0, 0, 0, 0, 0,
-    0, 0, 0, 0, 0, 0, 0, 0,
-    fb32Lane
-};
-
 void
 fbBltOne(FbStip * src, FbStride srcStride,      /* FbStip units per scanline */
          int srcX,              /* bit position of source */
@@ -169,7 +161,7 @@ fbBltOne(FbStip * src, FbStride srcStride,      /* FbStip units per scanline */
     Bool transparent;           /* accelerate 0 nop */
     int srcinc;                 /* source units consumed */
     Bool endNeedsLoad = FALSE;  /* need load for endmask */
-    CARD8 *fbLane;
+    const CARD8 *fbLane;
     int startbyte, endbyte;
 
     if (dstBpp == 24) {
@@ -236,8 +228,14 @@ fbBltOne(FbStip * src, FbStride srcStride,      /* FbStip units per scanline */
     if (pixelsPerDst <= 8)
         fbBits = fbStippleTable[pixelsPerDst];
     fbLane = 0;
-    if (transparent && fgand == 0 && dstBpp >= 8)
-        fbLane = fbLaneTable[dstBpp];
+    if (transparent && fgand == 0) {
+        if (dstBpp == 8)
+            fbLane = fb8Lane;
+        if (dstBpp == 16)
+            fbLane = fb16Lane;
+        if (dstBpp == 32)
+            fbLane = fb32Lane;
+    }
 
     /*
      * Compute total number of destination words written, but 
diff --git a/fb/wfbrename.h b/fb/wfbrename.h
index 749c6d0..a80858a 100644
--- a/fb/wfbrename.h
+++ b/fb/wfbrename.h
@@ -1,4 +1,3 @@
-#define fb16Lane wfb16Lane
 #define fb24_32CopyMtoN wfb24_32CopyMtoN
 #define fb24_32CreateScreenResources wfb24_32CreateScreenResources
 #define fb24_32GetImage wfb24_32GetImage
@@ -7,8 +6,6 @@
 #define fb24_32PutZImage wfb24_32PutZImage
 #define fb24_32ReformatTile wfb24_32ReformatTile
 #define fb24_32SetSpans wfb24_32SetSpans
-#define fb32Lane wfb32Lane
-#define fb8Lane wfb8Lane
 #define fbAddTraps wfbAddTraps
 #define fbAddTriangles wfbAddTriangles
 #define fbAllocatePrivates wfbAllocatePrivates
@@ -85,8 +82,6 @@
 #define fbIn wfbIn
 #define fbInitializeColormap wfbInitializeColormap
 #define fbInitVisuals wfbInitVisuals
-#define fbInstallColormap wfbInstallColormap
-#define fbLaneTable wfbLaneTable
 #define fbListInstalledColormaps wfbListInstalledColormaps
 #define FbMergeRopBits wFbMergeRopBits
 #define fbOddStipple wfbOddStipple
commit 86ce6262975a7d53d9331723beb49cbe7bd02b48
Author: Adam Jackson <ajax at redhat.com>
Date:   Fri Sep 26 12:39:38 2014 -0400

    mi: Fold micursor.c into mipointer.c
    
    Reviewed-by: Keith Packard <keithp at keithp.com>
    Signed-off-by: Adam Jackson <ajax at redhat.com>

diff --git a/mi/Makefile.am b/mi/Makefile.am
index ce416c4..110c3f5 100644
--- a/mi/Makefile.am
+++ b/mi/Makefile.am
@@ -16,7 +16,6 @@ libmi_la_SOURCES = 	\
 	micmap.h	\
 	micoord.h	\
 	micopy.c	\
-	micursor.c	\
 	midash.c	\
 	midispcur.c	\
 	mieq.c		\
diff --git a/mi/micursor.c b/mi/micursor.c
deleted file mode 100644
index 13ce776..0000000
--- a/mi/micursor.c
+++ /dev/null
@@ -1,68 +0,0 @@
-/***********************************************************
-
-Copyright 1987, 1998  The Open Group
-
-Permission to use, copy, modify, distribute, and sell this software and its
-documentation for any purpose is hereby granted without fee, provided that
-the above copyright notice appear in all copies and that both that
-copyright notice and this permission notice appear in supporting
-documentation.
-
-The above copyright notice and this permission notice shall be included in
-all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
-OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
-AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
-CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-
-Except as contained in this notice, the name of The Open Group shall not be
-used in advertising or otherwise to promote the sale, use or other dealings
-in this Software without prior written authorization from The Open Group.
-
-Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
-
-                        All Rights Reserved
-
-Permission to use, copy, modify, and distribute this software and its 
-documentation for any purpose and without fee is hereby granted, 
-provided that the above copyright notice appear in all copies and that
-both that copyright notice and this permission notice appear in 
-supporting documentation, and that the name of Digital not be
-used in advertising or publicity pertaining to distribution of the
-software without specific, written prior permission.  
-
-DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
-ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
-DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
-ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
-WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
-ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
-SOFTWARE.
-
-******************************************************************/
-#ifdef HAVE_DIX_CONFIG_H
-#include <dix-config.h>
-#endif
-
-#include "scrnintstr.h"
-#include "cursor.h"
-#include "misc.h"
-#include "mi.h"
-#include "inputstr.h"
-
-void
-miRecolorCursor(DeviceIntPtr pDev, ScreenPtr pScr,
-                CursorPtr pCurs, Bool displayed)
-{
-    /*
-     * This is guaranteed to correct any color-dependent state which may have
-     * been bound up in private state created by RealizeCursor
-     */
-    pScr->UnrealizeCursor(pDev, pScr, pCurs);
-    pScr->RealizeCursor(pDev, pScr, pCurs);
-    if (displayed)
-        pScr->DisplayCursor(pDev, pScr, pCurs);
-}
diff --git a/mi/mipointer.c b/mi/mipointer.c
index 6fa416d..9805425 100644
--- a/mi/mipointer.c
+++ b/mi/mipointer.c
@@ -273,6 +273,20 @@ miPointerSetCursorPosition(DeviceIntPtr pDev, ScreenPtr pScreen,
     return TRUE;
 }
 
+void
+miRecolorCursor(DeviceIntPtr pDev, ScreenPtr pScr,
+                CursorPtr pCurs, Bool displayed)
+{
+    /*
+     * This is guaranteed to correct any color-dependent state which may have
+     * been bound up in private state created by RealizeCursor
+     */
+    pScr->UnrealizeCursor(pDev, pScr, pCurs);
+    pScr->RealizeCursor(pDev, pScr, pCurs);
+    if (displayed)
+        pScr->DisplayCursor(pDev, pScr, pCurs);
+}
+
 /**
  * Set up sprite information for the device.
  * This function will be called once for each device after it is initialized
commit 3b63900e90f44cf85a4d3391d23407b3bb6db52b
Author: Adam Jackson <ajax at redhat.com>
Date:   Fri Sep 26 12:34:15 2014 -0400

    mi: Fold mipolyutil.c into mipoly.c
    
    Reviewed-by: Keith Packard <keithp at keithp.com>
    Signed-off-by: Adam Jackson <ajax at redhat.com>

diff --git a/mi/Makefile.am b/mi/Makefile.am
index 44e4f20..ce416c4 100644
--- a/mi/Makefile.am
+++ b/mi/Makefile.am
@@ -40,7 +40,6 @@ libmi_la_SOURCES = 	\
 	mipolyrect.c	\
 	mipolyseg.c	\
 	mipolytext.c	\
-	mipolyutil.c	\
 	mipushpxl.c	\
 	miscanfill.h	\
 	miscrinit.c	\
diff --git a/mi/mipoly.c b/mi/mipoly.c
index 3d49789..0ed2edb 100644
--- a/mi/mipoly.c
+++ b/mi/mipoly.c
@@ -61,6 +61,291 @@ SOFTWARE.
 #include "mipoly.h"
 #include "regionstr.h"
 
+/*
+ * Insert the given edge into the edge table.  First we must find the correct
+ * bucket in the Edge table, then find the right slot in the bucket.  Finally,
+ * we can insert it.
+ */
+static Bool
+miInsertEdgeInET(EdgeTable * ET, EdgeTableEntry * ETE, int scanline,
+                 ScanLineListBlock ** SLLBlock, int *iSLLBlock)
+{
+    EdgeTableEntry *start, *prev;
+    ScanLineList *pSLL, *pPrevSLL;
+    ScanLineListBlock *tmpSLLBlock;
+
+    /*
+     * find the right bucket to put the edge into
+     */
+    pPrevSLL = &ET->scanlines;
+    pSLL = pPrevSLL->next;
+    while (pSLL && (pSLL->scanline < scanline)) {
+        pPrevSLL = pSLL;
+        pSLL = pSLL->next;
+    }
+
+    /*
+     * reassign pSLL (pointer to ScanLineList) if necessary
+     */
+    if ((!pSLL) || (pSLL->scanline > scanline)) {
+        if (*iSLLBlock > SLLSPERBLOCK - 1) {
+            tmpSLLBlock = malloc(sizeof(ScanLineListBlock));
+            if (!tmpSLLBlock)
+                return FALSE;
+            (*SLLBlock)->next = tmpSLLBlock;
+            tmpSLLBlock->next = NULL;
+            *SLLBlock = tmpSLLBlock;
+            *iSLLBlock = 0;
+        }
+        pSLL = &((*SLLBlock)->SLLs[(*iSLLBlock)++]);
+
+        pSLL->next = pPrevSLL->next;
+        pSLL->edgelist = NULL;
+        pPrevSLL->next = pSLL;
+    }
+    pSLL->scanline = scanline;
+
+    /*
+     * now insert the edge in the right bucket
+     */
+    prev = NULL;
+    start = pSLL->edgelist;
+    while (start && (start->bres.minor < ETE->bres.minor)) {
+        prev = start;
+        start = start->next;
+    }
+    ETE->next = start;
+
+    if (prev)
+        prev->next = ETE;
+    else
+        pSLL->edgelist = ETE;
+    return TRUE;
+}
+
+static void
+miFreeStorage(ScanLineListBlock * pSLLBlock)
+{
+    ScanLineListBlock *tmpSLLBlock;
+
+    while (pSLLBlock) {
+        tmpSLLBlock = pSLLBlock->next;
+        free(pSLLBlock);
+        pSLLBlock = tmpSLLBlock;
+    }
+}
+
+/*
+ * CreateEdgeTable
+ *
+ * This routine creates the edge table for scan converting polygons.
+ * The Edge Table (ET) looks like:
+ *
+ * EdgeTable
+ *  --------
+ * |  ymax  |        ScanLineLists
+ * |scanline|-->------------>-------------->...
+ *  --------   |scanline|   |scanline|
+ *             |edgelist|   |edgelist|
+ *             ---------    ---------
+ *                 |             |
+ *                 |             |
+ *                 V             V
+ *           list of ETEs   list of ETEs
+ *
+ * where ETE is an EdgeTableEntry data structure, and there is one ScanLineList
+ * per scanline at which an edge is initially entered.
+ */
+
+static Bool
+miCreateETandAET(int count, DDXPointPtr pts, EdgeTable * ET,
+                 EdgeTableEntry * AET, EdgeTableEntry * pETEs,
+                 ScanLineListBlock * pSLLBlock)
+{
+    DDXPointPtr top, bottom;
+    DDXPointPtr PrevPt, CurrPt;
+    int iSLLBlock = 0;
+
+    int dy;
+
+    if (count < 2)
+        return TRUE;
+
+    /*
+     *  initialize the Active Edge Table
+     */
+    AET->next = NULL;
+    AET->back = NULL;
+    AET->nextWETE = NULL;
+    AET->bres.minor = MININT;
+
+    /*
+     *  initialize the Edge Table.
+     */
+    ET->scanlines.next = NULL;
+    ET->ymax = MININT;
+    ET->ymin = MAXINT;
+    pSLLBlock->next = NULL;
+
+    PrevPt = &pts[count - 1];
+
+    /*
+     *  for each vertex in the array of points.
+     *  In this loop we are dealing with two vertices at
+     *  a time -- these make up one edge of the polygon.
+     */
+    while (count--) {
+        CurrPt = pts++;
+
+        /*
+         *  find out which point is above and which is below.
+         */
+        if (PrevPt->y > CurrPt->y) {
+            bottom = PrevPt, top = CurrPt;
+            pETEs->ClockWise = 0;
+        }
+        else {
+            bottom = CurrPt, top = PrevPt;
+            pETEs->ClockWise = 1;
+        }
+
+        /*
+         * don't add horizontal edges to the Edge table.
+         */
+        if (bottom->y != top->y) {
+            pETEs->ymax = bottom->y - 1; /* -1 so we don't get last scanline */
+
+            /*
+             *  initialize integer edge algorithm
+             */
+            dy = bottom->y - top->y;
+            BRESINITPGONSTRUCT(dy, top->x, bottom->x, pETEs->bres);
+
+            if (!miInsertEdgeInET(ET, pETEs, top->y, &pSLLBlock, &iSLLBlock)) {
+                miFreeStorage(pSLLBlock->next);
+                return FALSE;
+            }
+
+            ET->ymax = max(ET->ymax, PrevPt->y);
+            ET->ymin = min(ET->ymin, PrevPt->y);
+            pETEs++;
+        }
+
+        PrevPt = CurrPt;
+    }
+    return TRUE;
+}
+
+/*
+ * This routine moves EdgeTableEntries from the EdgeTable into the Active Edge
+ * Table, leaving them sorted by smaller x coordinate.
+ */
+
+static void
+miloadAET(EdgeTableEntry * AET, EdgeTableEntry * ETEs)
+{
+    EdgeTableEntry *pPrevAET;
+    EdgeTableEntry *tmp;
+
+    pPrevAET = AET;
+    AET = AET->next;
+    while (ETEs) {
+        while (AET && (AET->bres.minor < ETEs->bres.minor)) {
+            pPrevAET = AET;
+            AET = AET->next;
+        }
+        tmp = ETEs->next;
+        ETEs->next = AET;
+        if (AET)
+            AET->back = ETEs;
+        ETEs->back = pPrevAET;
+        pPrevAET->next = ETEs;
+        pPrevAET = ETEs;
+
+        ETEs = tmp;
+    }
+}
+
+/*
+ * computeWAET
+ *
+ * This routine links the AET by the nextWETE (winding EdgeTableEntry) link for
+ * use by the winding number rule.  The final Active Edge Table (AET) might
+ * look something like:
+ *
+ * AET
+ * ----------  ---------   ---------
+ * |ymax    |  |ymax    |  |ymax    |
+ * | ...    |  |...     |  |...     |
+ * |next    |->|next    |->|next    |->...
+ * |nextWETE|  |nextWETE|  |nextWETE|
+ * ---------   ---------   ^--------
+ *     |                   |       |
+ *     V------------------->       V---> ...
+ *
+ */
+static void
+micomputeWAET(EdgeTableEntry * AET)
+{
+    EdgeTableEntry *pWETE;
+    int inside = 1;
+    int isInside = 0;
+
+    AET->nextWETE = NULL;
+    pWETE = AET;
+    AET = AET->next;
+    while (AET) {
+        if (AET->ClockWise)
+            isInside++;
+        else
+            isInside--;
+
+        if ((!inside && !isInside) || (inside && isInside)) {
+            pWETE->nextWETE = AET;
+            pWETE = AET;
+            inside = !inside;
+        }
+        AET = AET->next;
+    }
+    pWETE->nextWETE = NULL;
+}
+
+/*
+ * Just a simple insertion sort using pointers and back pointers to sort the
+ * Active Edge Table.
+ */
+
+static int
+miInsertionSort(EdgeTableEntry * AET)
+{
+    EdgeTableEntry *pETEchase;
+    EdgeTableEntry *pETEinsert;
+    EdgeTableEntry *pETEchaseBackTMP;
+    int changed = 0;
+
+    AET = AET->next;
+    while (AET) {
+        pETEinsert = AET;
+        pETEchase = AET;
+        while (pETEchase->back->bres.minor > AET->bres.minor)
+            pETEchase = pETEchase->back;
+
+        AET = AET->next;
+        if (pETEchase != pETEinsert) {
+            pETEchaseBackTMP = pETEchase->back;
+            pETEinsert->back->next = AET;
+            if (AET)
+                AET->back = pETEinsert->back;
+            pETEinsert->next = pETEchase;
+            pETEchase->back->next = pETEinsert;
+            pETEchase->back = pETEinsert;
+            pETEinsert->back = pETEchaseBackTMP;
+            changed = 1;
+        }
+    }
+    return changed;
+}
+
 /* Find the index of the point with the smallest y */
 static int
 getPolyYBounds(DDXPointPtr pts, int n, int *by, int *ty)
diff --git a/mi/mipoly.h b/mi/mipoly.h
index 02fcfc8..fc5a5cf 100644
--- a/mi/mipoly.h
+++ b/mi/mipoly.h
@@ -171,20 +171,3 @@ typedef struct _ScanLineListBlock {
       pAET = pAET->next; \
    } \
 }
-
-/* mipolyutil.c */
-
-extern Bool miCreateETandAET(int /*count */ ,
-                             DDXPointPtr /*pts */ ,
-                             EdgeTable * /*ET*/,
-                             EdgeTableEntry * /*AET*/,
-                             EdgeTableEntry * /*pETEs */ ,
-                             ScanLineListBlock *      /*pSLLBlock */);
-
-extern void miloadAET(EdgeTableEntry * /*AET*/, EdgeTableEntry * /*ETEs */);
-
-extern void micomputeWAET(EdgeTableEntry * /*AET*/);
-
-extern int miInsertionSort(EdgeTableEntry * /*AET*/);
-
-extern void miFreeStorage(ScanLineListBlock * /*pSLLBlock */);
diff --git a/mi/mipolyutil.c b/mi/mipolyutil.c
deleted file mode 100644
index 5e6301d..0000000
--- a/mi/mipolyutil.c
+++ /dev/null
@@ -1,369 +0,0 @@
-/***********************************************************
-
-Copyright 1987, 1998  The Open Group
-
-Permission to use, copy, modify, distribute, and sell this software and its
-documentation for any purpose is hereby granted without fee, provided that
-the above copyright notice appear in all copies and that both that
-copyright notice and this permission notice appear in supporting
-documentation.
-
-The above copyright notice and this permission notice shall be included in
-all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
-OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
-AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
-CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-
-Except as contained in this notice, the name of The Open Group shall not be
-used in advertising or otherwise to promote the sale, use or other dealings
-in this Software without prior written authorization from The Open Group.
-
-Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
-
-                        All Rights Reserved
-
-Permission to use, copy, modify, and distribute this software and its 
-documentation for any purpose and without fee is hereby granted, 
-provided that the above copyright notice appear in all copies and that
-both that copyright notice and this permission notice appear in 
-supporting documentation, and that the name of Digital not be
-used in advertising or publicity pertaining to distribution of the
-software without specific, written prior permission.  
-
-DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
-ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
-DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
-ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
-WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
-ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
-SOFTWARE.
-
-******************************************************************/
-#ifdef HAVE_DIX_CONFIG_H
-#include <dix-config.h>
-#endif
-
-#include "regionstr.h"
-#include "gc.h"
-#include "miscanfill.h"
-#include "mipoly.h"
-#include "misc.h"               /* MAXINT */
-
-/*
- *     fillUtils.c
- *
- *     Written by Brian Kelleher;  Oct. 1985
- *
- *     This module contains all of the utility functions
- *     needed to scan convert a polygon.
- *
- */
-
-/*
- *     InsertEdgeInET
- *
- *     Insert the given edge into the edge table.
- *     First we must find the correct bucket in the
- *     Edge table, then find the right slot in the
- *     bucket.  Finally, we can insert it.
- *
- */
-static Bool
-miInsertEdgeInET(EdgeTable * ET, EdgeTableEntry * ETE, int scanline,
-                 ScanLineListBlock ** SLLBlock, int *iSLLBlock)
-{
-    EdgeTableEntry *start, *prev;
-    ScanLineList *pSLL, *pPrevSLL;
-    ScanLineListBlock *tmpSLLBlock;
-
-    /*
-     * find the right bucket to put the edge into
-     */
-    pPrevSLL = &ET->scanlines;
-    pSLL = pPrevSLL->next;
-    while (pSLL && (pSLL->scanline < scanline)) {
-        pPrevSLL = pSLL;
-        pSLL = pSLL->next;
-    }
-
-    /*
-     * reassign pSLL (pointer to ScanLineList) if necessary
-     */
-    if ((!pSLL) || (pSLL->scanline > scanline)) {
-        if (*iSLLBlock > SLLSPERBLOCK - 1) {
-            tmpSLLBlock = malloc(sizeof(ScanLineListBlock));
-            if (!tmpSLLBlock)
-                return FALSE;
-            (*SLLBlock)->next = tmpSLLBlock;
-            tmpSLLBlock->next = NULL;
-            *SLLBlock = tmpSLLBlock;
-            *iSLLBlock = 0;
-        }
-        pSLL = &((*SLLBlock)->SLLs[(*iSLLBlock)++]);
-
-        pSLL->next = pPrevSLL->next;
-        pSLL->edgelist = NULL;
-        pPrevSLL->next = pSLL;
-    }
-    pSLL->scanline = scanline;
-
-    /*
-     * now insert the edge in the right bucket
-     */
-    prev = NULL;
-    start = pSLL->edgelist;
-    while (start && (start->bres.minor < ETE->bres.minor)) {
-        prev = start;
-        start = start->next;
-    }
-    ETE->next = start;
-
-    if (prev)
-        prev->next = ETE;
-    else
-        pSLL->edgelist = ETE;
-    return TRUE;
-}
-
-/*
- *     CreateEdgeTable
- *
- *     This routine creates the edge table for
- *     scan converting polygons. 
- *     The Edge Table (ET) looks like:
- *
- *    EdgeTable
- *     --------
- *    |  ymax  |        ScanLineLists
- *    |scanline|-->------------>-------------->...
- *     --------   |scanline|   |scanline|
- *                |edgelist|   |edgelist|
- *                ---------    ---------
- *                    |             |
- *                    |             |
- *                    V             V
- *              list of ETEs   list of ETEs
- *
- *     where ETE is an EdgeTableEntry data structure,
- *     and there is one ScanLineList per scanline at
- *     which an edge is initially entered.
- *
- */
-
-Bool
-miCreateETandAET(int count, DDXPointPtr pts, EdgeTable * ET,
-                 EdgeTableEntry * AET, EdgeTableEntry * pETEs,
-                 ScanLineListBlock * pSLLBlock)
-{
-    DDXPointPtr top, bottom;
-    DDXPointPtr PrevPt, CurrPt;
-    int iSLLBlock = 0;
-
-    int dy;
-
-    if (count < 2)
-        return TRUE;
-
-    /*
-     *  initialize the Active Edge Table
-     */
-    AET->next = NULL;
-    AET->back = NULL;
-    AET->nextWETE = NULL;
-    AET->bres.minor = MININT;
-
-    /*
-     *  initialize the Edge Table.
-     */
-    ET->scanlines.next = NULL;
-    ET->ymax = MININT;
-    ET->ymin = MAXINT;
-    pSLLBlock->next = NULL;
-
-    PrevPt = &pts[count - 1];
-
-    /*
-     *  for each vertex in the array of points.
-     *  In this loop we are dealing with two vertices at
-     *  a time -- these make up one edge of the polygon.
-     */
-    while (count--) {
-        CurrPt = pts++;
-
-        /*
-         *  find out which point is above and which is below.
-         */
-        if (PrevPt->y > CurrPt->y) {
-            bottom = PrevPt, top = CurrPt;
-            pETEs->ClockWise = 0;
-        }
-        else {
-            bottom = CurrPt, top = PrevPt;
-            pETEs->ClockWise = 1;
-        }
-
-        /*
-         * don't add horizontal edges to the Edge table.
-         */
-        if (bottom->y != top->y) {
-            pETEs->ymax = bottom->y - 1;        /* -1 so we don't get last scanline */
-
-            /*
-             *  initialize integer edge algorithm
-             */
-            dy = bottom->y - top->y;
-            BRESINITPGONSTRUCT(dy, top->x, bottom->x, pETEs->bres);
-
-            if (!miInsertEdgeInET(ET, pETEs, top->y, &pSLLBlock, &iSLLBlock)) {
-                miFreeStorage(pSLLBlock->next);
-                return FALSE;
-            }
-
-            ET->ymax = max(ET->ymax, PrevPt->y);
-            ET->ymin = min(ET->ymin, PrevPt->y);
-            pETEs++;
-        }
-
-        PrevPt = CurrPt;
-    }
-    return TRUE;
-}
-
-/*
- *     loadAET
- *
- *     This routine moves EdgeTableEntries from the
- *     EdgeTable into the Active Edge Table,
- *     leaving them sorted by smaller x coordinate.
- *
- */
-
-void
-miloadAET(EdgeTableEntry * AET, EdgeTableEntry * ETEs)
-{
-    EdgeTableEntry *pPrevAET;
-    EdgeTableEntry *tmp;
-
-    pPrevAET = AET;
-    AET = AET->next;
-    while (ETEs) {
-        while (AET && (AET->bres.minor < ETEs->bres.minor)) {
-            pPrevAET = AET;
-            AET = AET->next;
-        }
-        tmp = ETEs->next;
-        ETEs->next = AET;
-        if (AET)
-            AET->back = ETEs;
-        ETEs->back = pPrevAET;
-        pPrevAET->next = ETEs;
-        pPrevAET = ETEs;
-
-        ETEs = tmp;
-    }
-}
-
-/*
- *     computeWAET
- *
- *     This routine links the AET by the
- *     nextWETE (winding EdgeTableEntry) link for
- *     use by the winding number rule.  The final 
- *     Active Edge Table (AET) might look something
- *     like:
- *
- *     AET
- *     ----------  ---------   ---------
- *     |ymax    |  |ymax    |  |ymax    | 
- *     | ...    |  |...     |  |...     |
- *     |next    |->|next    |->|next    |->...
- *     |nextWETE|  |nextWETE|  |nextWETE|
- *     ---------   ---------   ^--------
- *         |                   |       |
- *         V------------------->       V---> ...
- *
- */
-void
-micomputeWAET(EdgeTableEntry * AET)
-{
-    EdgeTableEntry *pWETE;
-    int inside = 1;
-    int isInside = 0;
-
-    AET->nextWETE = NULL;
-    pWETE = AET;
-    AET = AET->next;
-    while (AET) {
-        if (AET->ClockWise)
-            isInside++;
-        else
-            isInside--;
-
-        if ((!inside && !isInside) || (inside && isInside)) {
-            pWETE->nextWETE = AET;
-            pWETE = AET;
-            inside = !inside;
-        }
-        AET = AET->next;
-    }
-    pWETE->nextWETE = NULL;
-}
-
-/*
- *     InsertionSort
- *
- *     Just a simple insertion sort using
- *     pointers and back pointers to sort the Active
- *     Edge Table.
- *
- */
-
-int
-miInsertionSort(EdgeTableEntry * AET)
-{
-    EdgeTableEntry *pETEchase;
-    EdgeTableEntry *pETEinsert;
-    EdgeTableEntry *pETEchaseBackTMP;
-    int changed = 0;
-
-    AET = AET->next;
-    while (AET) {
-        pETEinsert = AET;
-        pETEchase = AET;
-        while (pETEchase->back->bres.minor > AET->bres.minor)
-            pETEchase = pETEchase->back;
-
-        AET = AET->next;
-        if (pETEchase != pETEinsert) {
-            pETEchaseBackTMP = pETEchase->back;
-            pETEinsert->back->next = AET;
-            if (AET)
-                AET->back = pETEinsert->back;
-            pETEinsert->next = pETEchase;
-            pETEchase->back->next = pETEinsert;
-            pETEchase->back = pETEinsert;
-            pETEinsert->back = pETEchaseBackTMP;
-            changed = 1;
-        }
-    }
-    return changed;
-}
-
-/*
- *     Clean up our act.
- */
-void
-miFreeStorage(ScanLineListBlock * pSLLBlock)
-{
-    ScanLineListBlock *tmpSLLBlock;
-
-    while (pSLLBlock) {
-        tmpSLLBlock = pSLLBlock->next;
-        free(pSLLBlock);
-        pSLLBlock = tmpSLLBlock;
-    }
-}
commit 21b041ef48c49ff6fc06f6e4482ffe54cb763493
Author: Adam Jackson <ajax at redhat.com>
Date:   Fri Sep 26 12:27:22 2014 -0400

    mi: Fold mipoly{con,gen}.c into mipoly.c
    
    Reviewed-by: Keith Packard <keithp at keithp.com>
    Signed-off-by: Adam Jackson <ajax at redhat.com>

diff --git a/mi/Makefile.am b/mi/Makefile.am
index d9139a3..44e4f20 100644
--- a/mi/Makefile.am
+++ b/mi/Makefile.am
@@ -36,8 +36,6 @@ libmi_la_SOURCES = 	\
 	mipointrst.h	\
 	mipoly.c	\
 	mipoly.h	\
-	mipolycon.c	\
-	mipolygen.c	\
 	mipolypnt.c	\
 	mipolyrect.c	\
 	mipolyseg.c	\
diff --git a/mi/mi.h b/mi/mi.h
index 5a455c9..3269d9b 100644
--- a/mi/mi.h
+++ b/mi/mi.h
@@ -288,22 +288,6 @@ extern _X_EXPORT void miFillPolygon(DrawablePtr /*dst */ ,
                                     DDXPointPtr /*pPts */
     );
 
-/* mipolycon.c */
-
-extern _X_EXPORT Bool miFillConvexPoly(DrawablePtr /*dst */ ,
-                                       GCPtr /*pgc */ ,
-                                       int /*count */ ,
-                                       DDXPointPtr      /*ptsIn */
-    );
-
-/* mipolygen.c */
-
-extern _X_EXPORT Bool miFillGeneralPoly(DrawablePtr /*dst */ ,
-                                        GCPtr /*pgc */ ,
-                                        int /*count */ ,
-                                        DDXPointPtr     /*ptsIn */
-    );
-
 /* mipolypnt.c */
 
 extern _X_EXPORT void miPolyPoint(DrawablePtr /*pDrawable */ ,
diff --git a/mi/mipoly.c b/mi/mipoly.c
index 07d9818..3d49789 100644
--- a/mi/mipoly.c
+++ b/mi/mipoly.c
@@ -47,11 +47,6 @@ SOFTWARE.
  *  mipoly.c
  *
  *  Written by Brian Kelleher; June 1986
- *
- *  Draw polygons.  This routine translates the point by the
- *  origin if pGC->miTranslate is non-zero, and calls
- *  to the appropriate routine to actually scan convert the
- *  polygon.
  */
 #ifdef HAVE_DIX_CONFIG_H
 #include <dix-config.h>
@@ -62,8 +57,337 @@ SOFTWARE.
 #include "gcstruct.h"
 #include "pixmapstr.h"
 #include "mi.h"
+#include "miscanfill.h"
+#include "mipoly.h"
 #include "regionstr.h"
 
+/* Find the index of the point with the smallest y */
+static int
+getPolyYBounds(DDXPointPtr pts, int n, int *by, int *ty)
+{
+    DDXPointPtr ptMin;
+    int ymin, ymax;
+    DDXPointPtr ptsStart = pts;
+
+    ptMin = pts;
+    ymin = ymax = (pts++)->y;
+
+    while (--n > 0) {
+        if (pts->y < ymin) {
+            ptMin = pts;
+            ymin = pts->y;
+        }
+        if (pts->y > ymax)
+            ymax = pts->y;
+
+        pts++;
+    }
+
+    *by = ymin;
+    *ty = ymax;
+    return ptMin - ptsStart;
+}
+
+/*
+ * Written by Brian Kelleher; Dec. 1985.
+ *
+ * Fill a convex polygon.  If the given polygon is not convex, then the result
+ * is undefined.  The algorithm is to order the edges from smallest y to
+ * largest by partitioning the array into a left edge list and a right edge
+ * list.  The algorithm used to traverse each edge is an extension of
+ * Bresenham's line algorithm with y as the major axis.  For a derivation of
+ * the algorithm, see the author of this code.
+ */
+static Bool
+miFillConvexPoly(DrawablePtr dst, GCPtr pgc, int count, DDXPointPtr ptsIn)
+{
+    int xl = 0, xr = 0;         /* x vals of left and right edges */
+    int dl = 0, dr = 0;         /* decision variables             */
+    int ml = 0, m1l = 0;        /* left edge slope and slope+1    */
+    int mr = 0, m1r = 0;        /* right edge slope and slope+1   */
+    int incr1l = 0, incr2l = 0; /* left edge error increments     */
+    int incr1r = 0, incr2r = 0; /* right edge error increments    */
+    int dy;                     /* delta y                        */
+    int y;                      /* current scanline               */
+    int left, right;            /* indices to first endpoints     */
+    int i;                      /* loop counter                   */
+    int nextleft, nextright;    /* indices to second endpoints    */
+    DDXPointPtr ptsOut, FirstPoint;     /* output buffer               */
+    int *width, *FirstWidth;    /* output buffer                  */
+    int imin;                   /* index of smallest vertex (in y) */
+    int ymin;                   /* y-extents of polygon            */
+    int ymax;
+
+    /*
+     *  find leftx, bottomy, rightx, topy, and the index
+     *  of bottomy. Also translate the points.
+     */
+    imin = getPolyYBounds(ptsIn, count, &ymin, &ymax);
+
+    dy = ymax - ymin + 1;
+    if ((count < 3) || (dy < 0))
+        return TRUE;
+    ptsOut = FirstPoint = malloc(sizeof(DDXPointRec) * dy);
+    width = FirstWidth = malloc(sizeof(int) * dy);
+    if (!FirstPoint || !FirstWidth) {
+        free(FirstWidth);
+        free(FirstPoint);
+        return FALSE;
+    }
+
+    nextleft = nextright = imin;
+    y = ptsIn[nextleft].y;
+
+    /*
+     *  loop through all edges of the polygon
+     */
+    do {
+        /*
+         *  add a left edge if we need to
+         */
+        if (ptsIn[nextleft].y == y) {
+            left = nextleft;
+
+            /*
+             *  find the next edge, considering the end
+             *  conditions of the array.
+             */
+            nextleft++;
+            if (nextleft >= count)
+                nextleft = 0;
+
+            /*
+             *  now compute all of the random information
+             *  needed to run the iterative algorithm.
+             */
+            BRESINITPGON(ptsIn[nextleft].y - ptsIn[left].y,
+                         ptsIn[left].x, ptsIn[nextleft].x,
+                         xl, dl, ml, m1l, incr1l, incr2l);
+        }
+
+        /*
+         *  add a right edge if we need to
+         */
+        if (ptsIn[nextright].y == y) {
+            right = nextright;
+
+            /*
+             *  find the next edge, considering the end
+             *  conditions of the array.
+             */
+            nextright--;
+            if (nextright < 0)
+                nextright = count - 1;
+
+            /*
+             *  now compute all of the random information
+             *  needed to run the iterative algorithm.
+             */
+            BRESINITPGON(ptsIn[nextright].y - ptsIn[right].y,
+                         ptsIn[right].x, ptsIn[nextright].x,
+                         xr, dr, mr, m1r, incr1r, incr2r);
+        }
+
+        /*
+         *  generate scans to fill while we still have
+         *  a right edge as well as a left edge.
+         */
+        i = min(ptsIn[nextleft].y, ptsIn[nextright].y) - y;
+        /* in case we're called with non-convex polygon */
+        if (i < 0) {
+            free(FirstWidth);
+            free(FirstPoint);
+            return TRUE;
+        }
+        while (i-- > 0) {
+            ptsOut->y = y;
+
+            /*
+             *  reverse the edges if necessary
+             */
+            if (xl < xr) {
+                *(width++) = xr - xl;
+                (ptsOut++)->x = xl;
+            }
+            else {
+                *(width++) = xl - xr;
+                (ptsOut++)->x = xr;
+            }
+            y++;
+
+            /* increment down the edges */
+            BRESINCRPGON(dl, xl, ml, m1l, incr1l, incr2l);
+            BRESINCRPGON(dr, xr, mr, m1r, incr1r, incr2r);
+        }
+    } while (y != ymax);
+
+    /*
+     * Finally, fill the <remaining> spans
+     */
+    (*pgc->ops->FillSpans) (dst, pgc,
+                            ptsOut - FirstPoint, FirstPoint, FirstWidth, 1);
+    free(FirstWidth);
+    free(FirstPoint);
+    return TRUE;
+}
+
+/*
+ * Written by Brian Kelleher;  Oct. 1985
+ *
+ * Routine to fill a polygon.  Two fill rules are supported: frWINDING and
+ * frEVENODD.
+ */
+static Bool
+miFillGeneralPoly(DrawablePtr dst, GCPtr pgc, int count, DDXPointPtr ptsIn)
+{
+    EdgeTableEntry *pAET;       /* the Active Edge Table   */
+    int y;                      /* the current scanline    */
+    int nPts = 0;               /* number of pts in buffer */
+    EdgeTableEntry *pWETE;      /* Winding Edge Table      */
+    ScanLineList *pSLL;         /* Current ScanLineList    */
+    DDXPointPtr ptsOut;         /* ptr to output buffers   */
+    int *width;
+    DDXPointRec FirstPoint[NUMPTSTOBUFFER];     /* the output buffers */
+    int FirstWidth[NUMPTSTOBUFFER];
+    EdgeTableEntry *pPrevAET;   /* previous AET entry      */
+    EdgeTable ET;               /* Edge Table header node  */
+    EdgeTableEntry AET;         /* Active ET header node   */
+    EdgeTableEntry *pETEs;      /* Edge Table Entries buff */
+    ScanLineListBlock SLLBlock; /* header for ScanLineList */
+    int fixWAET = 0;
+
+    if (count < 3)
+        return TRUE;
+
+    if (!(pETEs = malloc(sizeof(EdgeTableEntry) * count)))
+        return FALSE;
+    ptsOut = FirstPoint;
+    width = FirstWidth;
+    if (!miCreateETandAET(count, ptsIn, &ET, &AET, pETEs, &SLLBlock)) {
+        free(pETEs);
+        return FALSE;
+    }
+    pSLL = ET.scanlines.next;
+
+    if (pgc->fillRule == EvenOddRule) {
+        /*
+         *  for each scanline
+         */
+        for (y = ET.ymin; y < ET.ymax; y++) {
+            /*
+             *  Add a new edge to the active edge table when we
+             *  get to the next edge.
+             */
+            if (pSLL && y == pSLL->scanline) {
+                miloadAET(&AET, pSLL->edgelist);
+                pSLL = pSLL->next;
+            }
+            pPrevAET = &AET;
+            pAET = AET.next;
+
+            /*
+             *  for each active edge
+             */
+            while (pAET) {
+                ptsOut->x = pAET->bres.minor;
+                ptsOut++->y = y;
+                *width++ = pAET->next->bres.minor - pAET->bres.minor;
+                nPts++;
+
+                /*
+                 *  send out the buffer when its full
+                 */
+                if (nPts == NUMPTSTOBUFFER) {
+                    (*pgc->ops->FillSpans) (dst, pgc,
+                                            nPts, FirstPoint, FirstWidth, 1);
+                    ptsOut = FirstPoint;
+                    width = FirstWidth;
+                    nPts = 0;
+                }
+                EVALUATEEDGEEVENODD(pAET, pPrevAET, y);
+                EVALUATEEDGEEVENODD(pAET, pPrevAET, y);
+            }
+            miInsertionSort(&AET);
+        }
+    }
+    else {                      /* default to WindingNumber */
+
+        /*
+         *  for each scanline
+         */
+        for (y = ET.ymin; y < ET.ymax; y++) {
+            /*
+             *  Add a new edge to the active edge table when we
+             *  get to the next edge.
+             */
+            if (pSLL && y == pSLL->scanline) {
+                miloadAET(&AET, pSLL->edgelist);
+                micomputeWAET(&AET);
+                pSLL = pSLL->next;
+            }
+            pPrevAET = &AET;
+            pAET = AET.next;
+            pWETE = pAET;
+
+            /*
+             *  for each active edge
+             */
+            while (pAET) {
+                /*
+                 *  if the next edge in the active edge table is
+                 *  also the next edge in the winding active edge
+                 *  table.
+                 */
+                if (pWETE == pAET) {
+                    ptsOut->x = pAET->bres.minor;
+                    ptsOut++->y = y;
+                    *width++ = pAET->nextWETE->bres.minor - pAET->bres.minor;
+                    nPts++;
+
+                    /*
+                     *  send out the buffer
+                     */
+                    if (nPts == NUMPTSTOBUFFER) {
+                        (*pgc->ops->FillSpans) (dst, pgc, nPts, FirstPoint,
+                                                FirstWidth, 1);
+                        ptsOut = FirstPoint;
+                        width = FirstWidth;
+                        nPts = 0;
+                    }
+
+                    pWETE = pWETE->nextWETE;
+                    while (pWETE != pAET)
+                        EVALUATEEDGEWINDING(pAET, pPrevAET, y, fixWAET);
+                    pWETE = pWETE->nextWETE;
+                }
+                EVALUATEEDGEWINDING(pAET, pPrevAET, y, fixWAET);
+            }
+
+            /*
+             *  reevaluate the Winding active edge table if we
+             *  just had to resort it or if we just exited an edge.
+             */
+            if (miInsertionSort(&AET) || fixWAET) {
+                micomputeWAET(&AET);
+                fixWAET = 0;
+            }
+        }
+    }
+
+    /*
+     *     Get any spans that we missed by buffering
+     */
+    (*pgc->ops->FillSpans) (dst, pgc, nPts, FirstPoint, FirstWidth, 1);
+    free(pETEs);
+    miFreeStorage(SLLBlock.next);
+    return TRUE;
+}
+
+/*
+ *  Draw polygons.  This routine translates the point by the origin if
+ *  pGC->miTranslate is non-zero, and calls to the appropriate routine to
+ *  actually scan convert the polygon.
+ */
 void
 miFillPolygon(DrawablePtr dst, GCPtr pgc,
               int shape, int mode, int count, DDXPointPtr pPts)
diff --git a/mi/mipolycon.c b/mi/mipolycon.c
deleted file mode 100644
index e831633..0000000
--- a/mi/mipolycon.c
+++ /dev/null
@@ -1,235 +0,0 @@
-/***********************************************************
-
-Copyright 1987, 1998  The Open Group
-
-Permission to use, copy, modify, distribute, and sell this software and its
-documentation for any purpose is hereby granted without fee, provided that
-the above copyright notice appear in all copies and that both that
-copyright notice and this permission notice appear in supporting
-documentation.
-
-The above copyright notice and this permission notice shall be included in
-all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
-OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
-AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
-CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-
-Except as contained in this notice, the name of The Open Group shall not be
-used in advertising or otherwise to promote the sale, use or other dealings
-in this Software without prior written authorization from The Open Group.
-
-Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
-
-                        All Rights Reserved
-
-Permission to use, copy, modify, and distribute this software and its 
-documentation for any purpose and without fee is hereby granted, 
-provided that the above copyright notice appear in all copies and that
-both that copyright notice and this permission notice appear in 
-supporting documentation, and that the name of Digital not be
-used in advertising or publicity pertaining to distribution of the
-software without specific, written prior permission.  
-
-DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
-ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
-DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
-ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
-WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
-ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
-SOFTWARE.
-
-******************************************************************/
-
-#ifdef HAVE_DIX_CONFIG_H
-#include <dix-config.h>
-#endif
-
-#include "gcstruct.h"
-#include "pixmap.h"
-#include "mi.h"
-#include "miscanfill.h"
-
-static int getPolyYBounds(DDXPointPtr pts, int n, int *by, int *ty);
-
-/*
- *     convexpoly.c
- *
- *     Written by Brian Kelleher; Dec. 1985.
- *
- *     Fill a convex polygon.  If the given polygon
- *     is not convex, then the result is undefined.
- *     The algorithm is to order the edges from smallest
- *     y to largest by partitioning the array into a left
- *     edge list and a right edge list.  The algorithm used
- *     to traverse each edge is an extension of Bresenham's
- *     line algorithm with y as the major axis.
- *     For a derivation of the algorithm, see the author of
- *     this code.
- */
-Bool
-miFillConvexPoly(DrawablePtr dst, GCPtr pgc, int count, /* number of points        */
-                 DDXPointPtr ptsIn      /* the points              */
-    )
-{
-    int xl = 0, xr = 0;         /* x vals of left and right edges */
-    int dl = 0, dr = 0;         /* decision variables             */
-    int ml = 0, m1l = 0;        /* left edge slope and slope+1    */
-    int mr = 0, m1r = 0;        /* right edge slope and slope+1   */
-    int incr1l = 0, incr2l = 0; /* left edge error increments     */
-    int incr1r = 0, incr2r = 0; /* right edge error increments    */
-    int dy;                     /* delta y                        */
-    int y;                      /* current scanline               */
-    int left, right;            /* indices to first endpoints     */
-    int i;                      /* loop counter                   */
-    int nextleft, nextright;    /* indices to second endpoints    */
-    DDXPointPtr ptsOut, FirstPoint;     /* output buffer               */
-    int *width, *FirstWidth;    /* output buffer                  */
-    int imin;                   /* index of smallest vertex (in y) */
-    int ymin;                   /* y-extents of polygon            */
-    int ymax;
-
-    /*
-     *  find leftx, bottomy, rightx, topy, and the index
-     *  of bottomy. Also translate the points.
-     */
-    imin = getPolyYBounds(ptsIn, count, &ymin, &ymax);
-
-    dy = ymax - ymin + 1;
-    if ((count < 3) || (dy < 0))
-        return TRUE;
-    ptsOut = FirstPoint = malloc(sizeof(DDXPointRec) * dy);
-    width = FirstWidth = malloc(sizeof(int) * dy);
-    if (!FirstPoint || !FirstWidth) {
-        free(FirstWidth);
-        free(FirstPoint);
-        return FALSE;
-    }
-
-    nextleft = nextright = imin;
-    y = ptsIn[nextleft].y;
-
-    /*
-     *  loop through all edges of the polygon
-     */
-    do {
-        /*
-         *  add a left edge if we need to
-         */
-        if (ptsIn[nextleft].y == y) {
-            left = nextleft;
-
-            /*
-             *  find the next edge, considering the end
-             *  conditions of the array.
-             */
-            nextleft++;
-            if (nextleft >= count)
-                nextleft = 0;
-
-            /*
-             *  now compute all of the random information
-             *  needed to run the iterative algorithm.
-             */
-            BRESINITPGON(ptsIn[nextleft].y - ptsIn[left].y,
-                         ptsIn[left].x, ptsIn[nextleft].x,
-                         xl, dl, ml, m1l, incr1l, incr2l);
-        }
-
-        /*
-         *  add a right edge if we need to
-         */
-        if (ptsIn[nextright].y == y) {
-            right = nextright;
-
-            /*
-             *  find the next edge, considering the end
-             *  conditions of the array.
-             */
-            nextright--;
-            if (nextright < 0)
-                nextright = count - 1;
-
-            /*
-             *  now compute all of the random information
-             *  needed to run the iterative algorithm.
-             */
-            BRESINITPGON(ptsIn[nextright].y - ptsIn[right].y,
-                         ptsIn[right].x, ptsIn[nextright].x,
-                         xr, dr, mr, m1r, incr1r, incr2r);
-        }
-
-        /*
-         *  generate scans to fill while we still have
-         *  a right edge as well as a left edge.
-         */
-        i = min(ptsIn[nextleft].y, ptsIn[nextright].y) - y;
-        /* in case we're called with non-convex polygon */
-        if (i < 0) {
-            free(FirstWidth);
-            free(FirstPoint);
-            return TRUE;
-        }
-        while (i-- > 0) {
-            ptsOut->y = y;
-
-            /*
-             *  reverse the edges if necessary
-             */
-            if (xl < xr) {
-                *(width++) = xr - xl;
-                (ptsOut++)->x = xl;
-            }
-            else {
-                *(width++) = xl - xr;
-                (ptsOut++)->x = xr;
-            }
-            y++;
-
-            /* increment down the edges */
-            BRESINCRPGON(dl, xl, ml, m1l, incr1l, incr2l);
-            BRESINCRPGON(dr, xr, mr, m1r, incr1r, incr2r);
-        }
-    } while (y != ymax);
-
-    /*
-     * Finally, fill the <remaining> spans
-     */
-    (*pgc->ops->FillSpans) (dst, pgc,
-                            ptsOut - FirstPoint, FirstPoint, FirstWidth, 1);
-    free(FirstWidth);
-    free(FirstPoint);
-    return TRUE;
-}
-
-/*
- *     Find the index of the point with the smallest y.
- */
-static int
-getPolyYBounds(DDXPointPtr pts, int n, int *by, int *ty)
-{
-    DDXPointPtr ptMin;
-    int ymin, ymax;
-    DDXPointPtr ptsStart = pts;
-
-    ptMin = pts;
-    ymin = ymax = (pts++)->y;
-
-    while (--n > 0) {
-        if (pts->y < ymin) {
-            ptMin = pts;
-            ymin = pts->y;
-        }
-        if (pts->y > ymax)
-            ymax = pts->y;
-
-        pts++;
-    }
-
-    *by = ymin;
-    *ty = ymax;
-    return ptMin - ptsStart;
-}
diff --git a/mi/mipolygen.c b/mi/mipolygen.c
deleted file mode 100644
index 2031b42..0000000
--- a/mi/mipolygen.c
+++ /dev/null
@@ -1,213 +0,0 @@
-/***********************************************************
-
-Copyright 1987, 1998  The Open Group
-
-Permission to use, copy, modify, distribute, and sell this software and its
-documentation for any purpose is hereby granted without fee, provided that
-the above copyright notice appear in all copies and that both that
-copyright notice and this permission notice appear in supporting
-documentation.
-
-The above copyright notice and this permission notice shall be included in
-all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
-OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
-AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
-CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-
-Except as contained in this notice, the name of The Open Group shall not be
-used in advertising or otherwise to promote the sale, use or other dealings
-in this Software without prior written authorization from The Open Group.
-
-Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
-
-                        All Rights Reserved
-
-Permission to use, copy, modify, and distribute this software and its 
-documentation for any purpose and without fee is hereby granted, 
-provided that the above copyright notice appear in all copies and that
-both that copyright notice and this permission notice appear in 
-supporting documentation, and that the name of Digital not be
-used in advertising or publicity pertaining to distribution of the
-software without specific, written prior permission.  
-
-DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
-ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
-DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
-ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
-WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
-ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
-SOFTWARE.
-
-******************************************************************/
-#ifdef HAVE_DIX_CONFIG_H
-#include <dix-config.h>
-#endif
-
-#include <X11/X.h>
-#include "gcstruct.h"
-#include "miscanfill.h"
-#include "mipoly.h"
-#include "pixmap.h"
-#include "mi.h"
-
-/*
- *
- *     Written by Brian Kelleher;  Oct. 1985
- *
- *     Routine to fill a polygon.  Two fill rules are
- *     supported: frWINDING and frEVENODD.
- *
- *     See fillpoly.h for a complete description of the algorithm.
- */
-
-Bool
-miFillGeneralPoly(DrawablePtr dst, GCPtr pgc, int count,        /* number of points        */
-                  DDXPointPtr ptsIn     /* the points              */
-    )
-{
-    EdgeTableEntry *pAET;       /* the Active Edge Table   */
-    int y;                      /* the current scanline    */
-    int nPts = 0;               /* number of pts in buffer */
-    EdgeTableEntry *pWETE;      /* Winding Edge Table      */
-    ScanLineList *pSLL;         /* Current ScanLineList    */
-    DDXPointPtr ptsOut;         /* ptr to output buffers   */
-    int *width;
-    DDXPointRec FirstPoint[NUMPTSTOBUFFER];     /* the output buffers */
-    int FirstWidth[NUMPTSTOBUFFER];
-    EdgeTableEntry *pPrevAET;   /* previous AET entry      */
-    EdgeTable ET;               /* Edge Table header node  */
-    EdgeTableEntry AET;         /* Active ET header node   */
-    EdgeTableEntry *pETEs;      /* Edge Table Entries buff */
-    ScanLineListBlock SLLBlock; /* header for ScanLineList */
-    int fixWAET = 0;
-
-    if (count < 3)
-        return TRUE;
-
-    if (!(pETEs = malloc(sizeof(EdgeTableEntry) * count)))
-        return FALSE;
-    ptsOut = FirstPoint;
-    width = FirstWidth;
-    if (!miCreateETandAET(count, ptsIn, &ET, &AET, pETEs, &SLLBlock)) {
-        free(pETEs);
-        return FALSE;
-    }
-    pSLL = ET.scanlines.next;
-
-    if (pgc->fillRule == EvenOddRule) {
-        /*
-         *  for each scanline
-         */
-        for (y = ET.ymin; y < ET.ymax; y++) {
-            /*
-             *  Add a new edge to the active edge table when we
-             *  get to the next edge.
-             */
-            if (pSLL && y == pSLL->scanline) {
-                miloadAET(&AET, pSLL->edgelist);
-                pSLL = pSLL->next;
-            }
-            pPrevAET = &AET;
-            pAET = AET.next;
-
-            /*
-             *  for each active edge
-             */
-            while (pAET) {
-                ptsOut->x = pAET->bres.minor;
-                ptsOut++->y = y;
-                *width++ = pAET->next->bres.minor - pAET->bres.minor;
-                nPts++;
-
-                /*
-                 *  send out the buffer when its full
-                 */
-                if (nPts == NUMPTSTOBUFFER) {
-                    (*pgc->ops->FillSpans) (dst, pgc,
-                                            nPts, FirstPoint, FirstWidth, 1);
-                    ptsOut = FirstPoint;
-                    width = FirstWidth;
-                    nPts = 0;
-                }
-                EVALUATEEDGEEVENODD(pAET, pPrevAET, y)
-                    EVALUATEEDGEEVENODD(pAET, pPrevAET, y);
-            }
-            miInsertionSort(&AET);
-        }
-    }
-    else {                      /* default to WindingNumber */
-
-        /*
-         *  for each scanline
-         */
-        for (y = ET.ymin; y < ET.ymax; y++) {
-            /*
-             *  Add a new edge to the active edge table when we
-             *  get to the next edge.
-             */
-            if (pSLL && y == pSLL->scanline) {
-                miloadAET(&AET, pSLL->edgelist);
-                micomputeWAET(&AET);
-                pSLL = pSLL->next;
-            }
-            pPrevAET = &AET;
-            pAET = AET.next;
-            pWETE = pAET;
-
-            /*
-             *  for each active edge
-             */
-            while (pAET) {
-                /*
-                 *  if the next edge in the active edge table is
-                 *  also the next edge in the winding active edge
-                 *  table.
-                 */
-                if (pWETE == pAET) {
-                    ptsOut->x = pAET->bres.minor;
-                    ptsOut++->y = y;
-                    *width++ = pAET->nextWETE->bres.minor - pAET->bres.minor;
-                    nPts++;
-
-                    /*
-                     *  send out the buffer
-                     */
-                    if (nPts == NUMPTSTOBUFFER) {
-                        (*pgc->ops->FillSpans) (dst, pgc, nPts, FirstPoint,
-                                                FirstWidth, 1);
-                        ptsOut = FirstPoint;
-                        width = FirstWidth;
-                        nPts = 0;
-                    }
-
-                    pWETE = pWETE->nextWETE;
-                    while (pWETE != pAET)
-                        EVALUATEEDGEWINDING(pAET, pPrevAET, y, fixWAET);
-                    pWETE = pWETE->nextWETE;
-                }
-                EVALUATEEDGEWINDING(pAET, pPrevAET, y, fixWAET);
-            }
-
-            /*
-             *  reevaluate the Winding active edge table if we
-             *  just had to resort it or if we just exited an edge.
-             */
-            if (miInsertionSort(&AET) || fixWAET) {
-                micomputeWAET(&AET);
-                fixWAET = 0;
-            }
-        }
-    }
-
-    /*
-     *     Get any spans that we missed by buffering
-     */
-    (*pgc->ops->FillSpans) (dst, pgc, nPts, FirstPoint, FirstWidth, 1);
-    free(pETEs);
-    miFreeStorage(SLLBlock.next);
-    return TRUE;
-}
commit 7679afd4da8b86aed27e5916ba723116a3c8bb4a
Author: Adam Jackson <ajax at redhat.com>
Date:   Fri Sep 26 12:01:37 2014 -0400

    mi: Fold mifpolycon.c into miarc.c
    
    Also put mifpoly.h on a diet, and stop including it from places that
    don't need it.
    
    Reviewed-by: Keith Packard <keithp at keithp.com>
    Signed-off-by: Adam Jackson <ajax at redhat.com>

diff --git a/hw/xfree86/sdksyms.sh b/hw/xfree86/sdksyms.sh
index 9c3c02f..2305073 100755
--- a/hw/xfree86/sdksyms.sh
+++ b/hw/xfree86/sdksyms.sh
@@ -217,7 +217,6 @@ cat > sdksyms.c << EOF
 #include "micoord.h"
 #include "mifillarc.h"
 #include "mistruct.h"
-#include "mifpoly.h"
 #include "mioverlay.h"
 
 
diff --git a/mi/Makefile.am b/mi/Makefile.am
index 149dc06..d9139a3 100644
--- a/mi/Makefile.am
+++ b/mi/Makefile.am
@@ -24,7 +24,6 @@ libmi_la_SOURCES = 	\
 	mifillarc.c	\
 	mifillarc.h	\
 	mifillrct.c	\
-	mifpolycon.c	\
 	mifpoly.h	\
 	migc.c		\
 	migc.h		\
diff --git a/mi/miarc.c b/mi/miarc.c
index e55108a..7bbe5b3 100644
--- a/mi/miarc.c
+++ b/mi/miarc.c
@@ -63,6 +63,22 @@ SOFTWARE.
 #include "mifillarc.h"
 #include <X11/Xfuncproto.h>
 
+#define EPSILON	0.000001
+#define ISEQUAL(a,b) (fabs((a) - (b)) <= EPSILON)
+#define UNEQUAL(a,b) (fabs((a) - (b)) > EPSILON)
+#define PTISEQUAL(a,b) (ISEQUAL(a.x,b.x) && ISEQUAL(a.y,b.y))
+#define SQSECANT 108.856472512142   /* 1/sin^2(11/2) - for 11o miter cutoff */
+
+/* Point with sub-pixel positioning. */
+typedef struct _SppPoint {
+    double x, y;
+} SppPointRec, *SppPointPtr;
+
+typedef struct _SppArc {
+    double x, y, width, height;
+    double angle1, angle2;
+} SppArcRec, *SppArcPtr;
+
 static double miDsin(double a);
 static double miDcos(double a);
 static double miDasin(double v);
@@ -1110,6 +1126,195 @@ miWideArc(DrawablePtr pDraw, GCPtr pGC, int narcs, xArc * parcs)
     }
 }
 
+/* Find the index of the point with the smallest y.also return the
+ * smallest and largest y */
+static int
+GetFPolyYBounds(SppPointPtr pts, int n, double yFtrans, int *by, int *ty)
+{
+    SppPointPtr ptMin;
+    double ymin, ymax;
+    SppPointPtr ptsStart = pts;
+
+    ptMin = pts;
+    ymin = ymax = (pts++)->y;
+
+    while (--n > 0) {
+        if (pts->y < ymin) {
+            ptMin = pts;
+            ymin = pts->y;
+        }
+        if (pts->y > ymax)
+            ymax = pts->y;
+
+        pts++;
+    }
+
+    *by = ICEIL(ymin + yFtrans);
+    *ty = ICEIL(ymax + yFtrans - 1);
+    return ptMin - ptsStart;
+}
+
+/*
+ *	miFillSppPoly written by Todd Newman; April. 1987.
+ *
+ *	Fill a convex polygon.  If the given polygon
+ *	is not convex, then the result is undefined.
+ *	The algorithm is to order the edges from smallest
+ *	y to largest by partitioning the array into a left
+ *	edge list and a right edge list.  The algorithm used
+ *	to traverse each edge is digital differencing analyzer
+ *	line algorithm with y as the major axis. There's some funny linear
+ *	interpolation involved because of the subpixel postioning.
+ */
+static void
+miFillSppPoly(DrawablePtr dst, GCPtr pgc, int count,    /* number of points */
+              SppPointPtr ptsIn,        /* the points */
+              int xTrans, int yTrans,   /* Translate each point by this */
+              double xFtrans, double yFtrans    /* translate before conversion
+                                                   by this amount.  This provides
+                                                   a mechanism to match rounding
+                                                   errors with any shape that must
+                                                   meet the polygon exactly.
+                                                 */
+    )
+{
+    double xl = 0.0, xr = 0.0,  /* x vals of left and right edges */
+        ml = 0.0,               /* left edge slope */
+        mr = 0.0,               /* right edge slope */
+        dy,                     /* delta y */
+        i;                      /* loop counter */
+    int y,                      /* current scanline */
+     j, imin,                   /* index of vertex with smallest y */
+     ymin,                      /* y-extents of polygon */
+     ymax, *width, *FirstWidth, /* output buffer */
+    *Marked;                    /* set if this vertex has been used */
+    int left, right,            /* indices to first endpoints */
+     nextleft, nextright;       /* indices to second endpoints */
+    DDXPointPtr ptsOut, FirstPoint;     /* output buffer */
+
+    if (pgc->miTranslate) {
+        xTrans += dst->x;
+        yTrans += dst->y;
+    }
+
+    imin = GetFPolyYBounds(ptsIn, count, yFtrans, &ymin, &ymax);
+
+    y = ymax - ymin + 1;
+    if ((count < 3) || (y <= 0))
+        return;
+    ptsOut = FirstPoint = malloc(sizeof(DDXPointRec) * y);
+    width = FirstWidth = malloc(sizeof(int) * y);
+    Marked = malloc(sizeof(int) * count);
+
+    if (!ptsOut || !width || !Marked) {
+        free(Marked);
+        free(width);
+        free(ptsOut);
+        return;
+    }
+
+    for (j = 0; j < count; j++)
+        Marked[j] = 0;
+    nextleft = nextright = imin;
+    Marked[imin] = -1;
+    y = ICEIL(ptsIn[nextleft].y + yFtrans);
+
+    /*
+     *  loop through all edges of the polygon
+     */
+    do {
+        /* add a left edge if we need to */
+        if ((y > (ptsIn[nextleft].y + yFtrans) ||
+             ISEQUAL(y, ptsIn[nextleft].y + yFtrans)) &&
+            Marked[nextleft] != 1) {
+            Marked[nextleft]++;
+            left = nextleft++;
+
+            /* find the next edge, considering the end conditions */
+            if (nextleft >= count)
+                nextleft = 0;
+
+            /* now compute the starting point and slope */
+            dy = ptsIn[nextleft].y - ptsIn[left].y;
+            if (dy != 0.0) {
+                ml = (ptsIn[nextleft].x - ptsIn[left].x) / dy;
+                dy = y - (ptsIn[left].y + yFtrans);
+                xl = (ptsIn[left].x + xFtrans) + ml * max(dy, 0);
+            }
+        }
+
+        /* add a right edge if we need to */
+        if ((y > ptsIn[nextright].y + yFtrans) ||
+            (ISEQUAL(y, ptsIn[nextright].y + yFtrans)
+             && Marked[nextright] != 1)) {
+            Marked[nextright]++;
+            right = nextright--;
+
+            /* find the next edge, considering the end conditions */
+            if (nextright < 0)
+                nextright = count - 1;
+
+            /* now compute the starting point and slope */
+            dy = ptsIn[nextright].y - ptsIn[right].y;
+            if (dy != 0.0) {
+                mr = (ptsIn[nextright].x - ptsIn[right].x) / dy;
+                dy = y - (ptsIn[right].y + yFtrans);
+                xr = (ptsIn[right].x + xFtrans) + mr * max(dy, 0);
+            }
+        }
+
+        /*
+         *  generate scans to fill while we still have
+         *  a right edge as well as a left edge.
+         */
+        i = (min(ptsIn[nextleft].y, ptsIn[nextright].y) + yFtrans) - y;
+
+        if (i < EPSILON) {
+            if (Marked[nextleft] && Marked[nextright]) {
+                /* Arrgh, we're trapped! (no more points)
+                 * Out, we've got to get out of here before this decadence saps
+                 * our will completely! */
+                break;
+            }
+            continue;
+        }
+        else {
+            j = (int) i;
+            if (!j)
+                j++;
+        }
+        while (j > 0) {
+            int cxl, cxr;
+
+            ptsOut->y = (y) + yTrans;
+
+            cxl = ICEIL(xl);
+            cxr = ICEIL(xr);
+            /* reverse the edges if necessary */
+            if (xl < xr) {
+                *(width++) = cxr - cxl;
+                (ptsOut++)->x = cxl + xTrans;
+            }
+            else {
+                *(width++) = cxl - cxr;
+                (ptsOut++)->x = cxr + xTrans;
+            }
+            y++;
+
+            /* increment down the edges */
+            xl += ml;
+            xr += mr;
+            j--;
+        }
+    } while (y <= ymax);
+
+    /* Finally, fill the spans we've collected */
+    (*pgc->ops->FillSpans) (dst, pgc,
+                            ptsOut - FirstPoint, FirstPoint, FirstWidth, 1);
+    free(Marked);
+    free(FirstWidth);
+    free(FirstPoint);
+}
 static double
 angleBetween(SppPointRec center, SppPointRec point1, SppPointRec point2)
 {
diff --git a/mi/midash.c b/mi/midash.c
index 78cbaf2..50b0fbe 100644
--- a/mi/midash.c
+++ b/mi/midash.c
@@ -49,7 +49,6 @@ SOFTWARE.
 
 #include "regionstr.h"
 #include "mistruct.h"
-#include "mifpoly.h"
 
 void
 miStepDash(int dist,            /* distance to step */
diff --git a/mi/mifillarc.c b/mi/mifillarc.c
index 9a5e785..246d70f 100644
--- a/mi/mifillarc.c
+++ b/mi/mifillarc.c
@@ -36,7 +36,6 @@ Author:  Bob Scheifler, MIT X Consortium
 #include "regionstr.h"
 #include "gcstruct.h"
 #include "pixmapstr.h"
-#include "mifpoly.h"
 #include "mi.h"
 #include "mifillarc.h"
 
diff --git a/mi/mifpoly.h b/mi/mifpoly.h
index 4b27d1c..9304c6f 100644
--- a/mi/mifpoly.h
+++ b/mi/mifpoly.h
@@ -49,24 +49,6 @@ SOFTWARE.
 
 #include <X11/Xfuncproto.h>
 
-#define EPSILON	0.000001
-#define ISEQUAL(a,b) (fabs((a) - (b)) <= EPSILON)
-#define UNEQUAL(a,b) (fabs((a) - (b)) > EPSILON)
-#define WITHINHALF(a, b) (((a) - (b) > 0.0) ? (a) - (b) < 0.5 : \
-					     (b) - (a) <= 0.5)
-#define ROUNDTOINT(x)   ((int) (((x) > 0.0) ? ((x) + 0.5) : ((x) - 0.5)))
-#define ISZERO(x) 	(fabs((x)) <= EPSILON)
-#define PTISEQUAL(a,b) (ISEQUAL(a.x,b.x) && ISEQUAL(a.y,b.y))
-#define PTUNEQUAL(a,b) (UNEQUAL(a.x,b.x) || UNEQUAL(a.y,b.y))
-#define PtEqual(a, b) (((a).x == (b).x) && ((a).y == (b).y))
-
-#define NotEnd		0
-#define FirstEnd	1
-#define SecondEnd	2
-
-#define SQSECANT 108.856472512142       /* 1/sin^2(11/2) - for 11o miter cutoff */
-#define D2SECANT 5.21671526231167       /* 1/2*sin(11/2) - max extension per width */
-
 static _X_INLINE int
 ICEIL(double x)
 {
@@ -75,27 +57,4 @@ ICEIL(double x)
     return ((x == _cTmp) || (x < 0.0)) ? _cTmp : _cTmp + 1;
 }
 
-/* Point with sub-pixel positioning.  In this case we use doubles, but
- * see mifpolycon.c for other suggestions 
- */
-typedef struct _SppPoint {
-    double x, y;
-} SppPointRec, *SppPointPtr;
-
-typedef struct _SppArc {
-    double x, y, width, height;
-    double angle1, angle2;
-} SppArcRec, *SppArcPtr;
-
-/* mifpolycon.c */
-
-extern void miFillSppPoly(DrawablePtr /*dst */ ,
-                          GCPtr /*pgc */ ,
-                          int /*count */ ,
-                          SppPointPtr /*ptsIn */ ,
-                          int /*xTrans */ ,
-                          int /*yTrans */ ,
-                          double /*xFtrans */ ,
-                          double      /*yFtrans */);
-
 #endif                          /* __MIFPOLY_H__ */
diff --git a/mi/mifpolycon.c b/mi/mifpolycon.c
deleted file mode 100644
index b133731..0000000
--- a/mi/mifpolycon.c
+++ /dev/null
@@ -1,249 +0,0 @@
-/***********************************************************
-
-Copyright 1987, 1998  The Open Group
-
-Permission to use, copy, modify, distribute, and sell this software and its
-documentation for any purpose is hereby granted without fee, provided that
-the above copyright notice appear in all copies and that both that
-copyright notice and this permission notice appear in supporting
-documentation.
-
-The above copyright notice and this permission notice shall be included in
-all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
-OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
-AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
-CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-
-Except as contained in this notice, the name of The Open Group shall not be
-used in advertising or otherwise to promote the sale, use or other dealings
-in this Software without prior written authorization from The Open Group.
-
-Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
-
-                        All Rights Reserved
-
-Permission to use, copy, modify, and distribute this software and its 
-documentation for any purpose and without fee is hereby granted, 
-provided that the above copyright notice appear in all copies and that
-both that copyright notice and this permission notice appear in 
-supporting documentation, and that the name of Digital not be
-used in advertising or publicity pertaining to distribution of the
-software without specific, written prior permission.  
-
-DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
-ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
-DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
-ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
-WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
-ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
-SOFTWARE.
-
-******************************************************************/
-#ifdef HAVE_DIX_CONFIG_H
-#include <dix-config.h>
-#endif
-
-#include <math.h>
-#include <X11/X.h>
-#include "gcstruct.h"
-#include "windowstr.h"
-#include "pixmapstr.h"
-#include "mifpoly.h"
-
-static int GetFPolyYBounds(SppPointPtr pts, int n, double yFtrans,
-                           int *by, int *ty);
-
-/*
- *	Written by Todd Newman; April. 1987.
- *
- *	Fill a convex polygon.  If the given polygon
- *	is not convex, then the result is undefined.
- *	The algorithm is to order the edges from smallest
- *	y to largest by partitioning the array into a left
- *	edge list and a right edge list.  The algorithm used
- *	to traverse each edge is digital differencing analyzer
- *	line algorithm with y as the major axis. There's some funny linear
- *	interpolation involved because of the subpixel postioning.
- */
-void
-miFillSppPoly(DrawablePtr dst, GCPtr pgc, int count,    /* number of points */
-              SppPointPtr ptsIn,        /* the points */
-              int xTrans, int yTrans,   /* Translate each point by this */
-              double xFtrans, double yFtrans    /* translate before conversion
-                                                   by this amount.  This provides
-                                                   a mechanism to match rounding
-                                                   errors with any shape that must
-                                                   meet the polygon exactly.
-                                                 */
-    )
-{
-    double xl = 0.0, xr = 0.0,  /* x vals of left and right edges */
-        ml = 0.0,               /* left edge slope */
-        mr = 0.0,               /* right edge slope */
-        dy,                     /* delta y */
-        i;                      /* loop counter */
-    int y,                      /* current scanline */
-     j, imin,                   /* index of vertex with smallest y */
-     ymin,                      /* y-extents of polygon */
-     ymax, *width, *FirstWidth, /* output buffer */
-    *Marked;                    /* set if this vertex has been used */
-    int left, right,            /* indices to first endpoints */
-     nextleft, nextright;       /* indices to second endpoints */
-    DDXPointPtr ptsOut, FirstPoint;     /* output buffer */
-
-    if (pgc->miTranslate) {
-        xTrans += dst->x;
-        yTrans += dst->y;
-    }
-
-    imin = GetFPolyYBounds(ptsIn, count, yFtrans, &ymin, &ymax);
-
-    y = ymax - ymin + 1;
-    if ((count < 3) || (y <= 0))
-        return;
-    ptsOut = FirstPoint = malloc(sizeof(DDXPointRec) * y);
-    width = FirstWidth = malloc(sizeof(int) * y);
-    Marked = malloc(sizeof(int) * count);
-
-    if (!ptsOut || !width || !Marked) {
-        free(Marked);
-        free(width);
-        free(ptsOut);
-        return;
-    }
-
-    for (j = 0; j < count; j++)
-        Marked[j] = 0;
-    nextleft = nextright = imin;
-    Marked[imin] = -1;
-    y = ICEIL(ptsIn[nextleft].y + yFtrans);
-
-    /*
-     *  loop through all edges of the polygon
-     */
-    do {
-        /* add a left edge if we need to */
-        if ((y > (ptsIn[nextleft].y + yFtrans) ||
-             ISEQUAL(y, ptsIn[nextleft].y + yFtrans)) &&
-            Marked[nextleft] != 1) {
-            Marked[nextleft]++;
-            left = nextleft++;
-
-            /* find the next edge, considering the end conditions */
-            if (nextleft >= count)
-                nextleft = 0;
-
-            /* now compute the starting point and slope */
-            dy = ptsIn[nextleft].y - ptsIn[left].y;
-            if (dy != 0.0) {
-                ml = (ptsIn[nextleft].x - ptsIn[left].x) / dy;
-                dy = y - (ptsIn[left].y + yFtrans);
-                xl = (ptsIn[left].x + xFtrans) + ml * max(dy, 0);
-            }
-        }
-
-        /* add a right edge if we need to */
-        if ((y > ptsIn[nextright].y + yFtrans) ||
-            (ISEQUAL(y, ptsIn[nextright].y + yFtrans)
-             && Marked[nextright] != 1)) {
-            Marked[nextright]++;
-            right = nextright--;
-
-            /* find the next edge, considering the end conditions */
-            if (nextright < 0)
-                nextright = count - 1;
-
-            /* now compute the starting point and slope */
-            dy = ptsIn[nextright].y - ptsIn[right].y;
-            if (dy != 0.0) {
-                mr = (ptsIn[nextright].x - ptsIn[right].x) / dy;
-                dy = y - (ptsIn[right].y + yFtrans);
-                xr = (ptsIn[right].x + xFtrans) + mr * max(dy, 0);
-            }
-        }
-
-        /*
-         *  generate scans to fill while we still have
-         *  a right edge as well as a left edge.
-         */
-        i = (min(ptsIn[nextleft].y, ptsIn[nextright].y) + yFtrans) - y;
-
-        if (i < EPSILON) {
-            if (Marked[nextleft] && Marked[nextright]) {
-                /* Arrgh, we're trapped! (no more points) 
-                 * Out, we've got to get out of here before this decadence saps
-                 * our will completely! */
-                break;
-            }
-            continue;
-        }
-        else {
-            j = (int) i;
-            if (!j)
-                j++;
-        }
-        while (j > 0) {
-            int cxl, cxr;
-
-            ptsOut->y = (y) + yTrans;
-
-            cxl = ICEIL(xl);
-            cxr = ICEIL(xr);
-            /* reverse the edges if necessary */
-            if (xl < xr) {
-                *(width++) = cxr - cxl;
-                (ptsOut++)->x = cxl + xTrans;
-            }
-            else {
-                *(width++) = cxl - cxr;
-                (ptsOut++)->x = cxr + xTrans;
-            }
-            y++;
-
-            /* increment down the edges */
-            xl += ml;
-            xr += mr;
-            j--;
-        }
-    } while (y <= ymax);
-
-    /* Finally, fill the spans we've collected */
-    (*pgc->ops->FillSpans) (dst, pgc,
-                            ptsOut - FirstPoint, FirstPoint, FirstWidth, 1);
-    free(Marked);
-    free(FirstWidth);
-    free(FirstPoint);
-}
-
-/* Find the index of the point with the smallest y.also return the
- * smallest and largest y */
-static
-    int
-GetFPolyYBounds(SppPointPtr pts, int n, double yFtrans, int *by, int *ty)
-{
-    SppPointPtr ptMin;
-    double ymin, ymax;
-    SppPointPtr ptsStart = pts;
-
-    ptMin = pts;
-    ymin = ymax = (pts++)->y;
-
-    while (--n > 0) {
-        if (pts->y < ymin) {
-            ptMin = pts;
-            ymin = pts->y;
-        }
-        if (pts->y > ymax)
-            ymax = pts->y;
-
-        pts++;
-    }
-
-    *by = ICEIL(ymin + yFtrans);
-    *ty = ICEIL(ymax + yFtrans - 1);
-    return ptMin - ptsStart;
-}
commit f307ef10f4c33da4b5ae59800931741b0a431d75
Author: Adam Jackson <ajax at redhat.com>
Date:   Mon Jul 21 17:22:07 2014 -0400

    mi: Fold mispans.c into miwideline.c
    
    Reviewed-by: Keith Packard <keithp at keithp.com>
    Signed-off-by: Adam Jackson <ajax at redhat.com>

diff --git a/hw/xfree86/sdksyms.sh b/hw/xfree86/sdksyms.sh
index c2a1942..9c3c02f 100755
--- a/hw/xfree86/sdksyms.sh
+++ b/hw/xfree86/sdksyms.sh
@@ -216,7 +216,6 @@ cat > sdksyms.c << EOF
 #include "mizerarc.h"
 #include "micoord.h"
 #include "mifillarc.h"
-#include "mispans.h"
 #include "mistruct.h"
 #include "mifpoly.h"
 #include "mioverlay.h"
diff --git a/mi/Makefile.am b/mi/Makefile.am
index 4466f69..149dc06 100644
--- a/mi/Makefile.am
+++ b/mi/Makefile.am
@@ -47,8 +47,6 @@ libmi_la_SOURCES = 	\
 	mipushpxl.c	\
 	miscanfill.h	\
 	miscrinit.c	\
-	mispans.c	\
-	mispans.h	\
 	misprite.c	\
 	misprite.h	\
 	mistruct.h	\
diff --git a/mi/mispans.c b/mi/mispans.c
deleted file mode 100644
index 11c8a43..0000000
--- a/mi/mispans.c
+++ /dev/null
@@ -1,526 +0,0 @@
-/***********************************************************
-
-Copyright 1989, 1998  The Open Group
-
-Permission to use, copy, modify, distribute, and sell this software and its
-documentation for any purpose is hereby granted without fee, provided that
-the above copyright notice appear in all copies and that both that
-copyright notice and this permission notice appear in supporting
-documentation.
-
-The above copyright notice and this permission notice shall be included in
-all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
-OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
-AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
-CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-
-Except as contained in this notice, the name of The Open Group shall not be
-used in advertising or otherwise to promote the sale, use or other dealings
-in this Software without prior written authorization from The Open Group.
-
-Copyright 1989 by Digital Equipment Corporation, Maynard, Massachusetts.
-
-                        All Rights Reserved
-
-Permission to use, copy, modify, and distribute this software and its 
-documentation for any purpose and without fee is hereby granted, 
-provided that the above copyright notice appear in all copies and that
-both that copyright notice and this permission notice appear in 
-supporting documentation, and that the name of Digital not be
-used in advertising or publicity pertaining to distribution of the
-software without specific, written prior permission.  
-
-DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
-ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
-DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
-ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
-WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
-ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
-SOFTWARE.
-
-******************************************************************/
-
-#ifdef HAVE_DIX_CONFIG_H
-#include <dix-config.h>
-#endif
-
-#include "misc.h"
-#include "pixmapstr.h"
-#include "gcstruct.h"
-#include "mispans.h"
-
-/*
-
-These routines maintain lists of Spans, in order to implement the
-``touch-each-pixel-once'' rules of wide lines and arcs.
-
-Written by Joel McCormack, Summer 1989.
-
-*/
-
-void
-miInitSpanGroup(SpanGroup * spanGroup)
-{
-    spanGroup->size = 0;
-    spanGroup->count = 0;
-    spanGroup->group = NULL;
-    spanGroup->ymin = MAXSHORT;
-    spanGroup->ymax = MINSHORT;
-}                               /* InitSpanGroup */
-
-#define YMIN(spans) (spans->points[0].y)
-#define YMAX(spans)  (spans->points[spans->count-1].y)
-
-static void
-miSubtractSpans(SpanGroup * spanGroup, Spans * sub)
-{
-    int i, subCount, spansCount;
-    int ymin, ymax, xmin, xmax;
-    Spans *spans;
-    DDXPointPtr subPt, spansPt;
-    int *subWid, *spansWid;
-    int extra;
-
-    ymin = YMIN(sub);
-    ymax = YMAX(sub);
-    spans = spanGroup->group;
-    for (i = spanGroup->count; i; i--, spans++) {
-        if (YMIN(spans) <= ymax && ymin <= YMAX(spans)) {
-            subCount = sub->count;
-            subPt = sub->points;
-            subWid = sub->widths;
-            spansCount = spans->count;
-            spansPt = spans->points;
-            spansWid = spans->widths;
-            extra = 0;
-            for (;;) {
-                while (spansCount && spansPt->y < subPt->y) {
-                    spansPt++;
-                    spansWid++;
-                    spansCount--;
-                }
-                if (!spansCount)
-                    break;
-                while (subCount && subPt->y < spansPt->y) {
-                    subPt++;
-                    subWid++;
-                    subCount--;
-                }
-                if (!subCount)
-                    break;
-                if (subPt->y == spansPt->y) {
-                    xmin = subPt->x;
-                    xmax = xmin + *subWid;
-                    if (xmin >= spansPt->x + *spansWid || spansPt->x >= xmax) {
-                        ;
-                    }
-                    else if (xmin <= spansPt->x) {
-                        if (xmax >= spansPt->x + *spansWid) {
-                            memmove(spansPt, spansPt + 1,
-                                    sizeof *spansPt * (spansCount - 1));
-                            memmove(spansWid, spansWid + 1,
-                                    sizeof *spansWid * (spansCount - 1));
-                            spansPt--;
-                            spansWid--;
-                            spans->count--;
-                            extra++;
-                        }
-                        else {
-                            *spansWid = *spansWid - (xmax - spansPt->x);
-                            spansPt->x = xmax;
-                        }
-                    }
-                    else {
-                        if (xmax >= spansPt->x + *spansWid) {
-                            *spansWid = xmin - spansPt->x;
-                        }
-                        else {
-                            if (!extra) {
-                                DDXPointPtr newPt;
-                                int *newwid;
-
-#define EXTRA 8
-                                newPt =
-                                    (DDXPointPtr) realloc(spans->points,
-                                                          (spans->count +
-                                                           EXTRA) *
-                                                          sizeof(DDXPointRec));
-                                if (!newPt)
-                                    break;
-                                spansPt = newPt + (spansPt - spans->points);
-                                spans->points = newPt;
-                                newwid =
-                                    (int *) realloc(spans->widths,
-                                                    (spans->count +
-                                                     EXTRA) * sizeof(int));
-                                if (!newwid)
-                                    break;
-                                spansWid = newwid + (spansWid - spans->widths);
-                                spans->widths = newwid;
-                                extra = EXTRA;
-                            }
-                            memmove(spansPt + 1, spansPt,
-                                    sizeof *spansPt * (spansCount));
-                            memmove(spansWid + 1, spansWid,
-                                    sizeof *spansWid * (spansCount));
-                            spans->count++;
-                            extra--;
-                            *spansWid = xmin - spansPt->x;
-                            spansWid++;
-                            spansPt++;
-                            *spansWid = *spansWid - (xmax - spansPt->x);
-                            spansPt->x = xmax;
-                        }
-                    }
-                }
-                spansPt++;
-                spansWid++;
-                spansCount--;
-            }
-        }
-    }
-}
-
-void
-miAppendSpans(SpanGroup * spanGroup, SpanGroup * otherGroup, Spans * spans)
-{
-    int ymin, ymax;
-    int spansCount;
-
-    spansCount = spans->count;
-    if (spansCount > 0) {
-        if (spanGroup->size == spanGroup->count) {
-            spanGroup->size = (spanGroup->size + 8) * 2;
-            spanGroup->group = (Spans *)
-                realloc(spanGroup->group, sizeof(Spans) * spanGroup->size);
-        }
-
-        spanGroup->group[spanGroup->count] = *spans;
-        (spanGroup->count)++;
-        ymin = spans->points[0].y;
-        if (ymin < spanGroup->ymin)
-            spanGroup->ymin = ymin;
-        ymax = spans->points[spansCount - 1].y;
-        if (ymax > spanGroup->ymax)
-            spanGroup->ymax = ymax;
-        if (otherGroup && otherGroup->ymin < ymax && ymin < otherGroup->ymax) {
-            miSubtractSpans(otherGroup, spans);
-        }
-    }
-    else {
-        free(spans->points);
-        free(spans->widths);
-    }
-}                               /* AppendSpans */
-
-void
-miFreeSpanGroup(SpanGroup * spanGroup)
-{
-    free(spanGroup->group);
-}
-
-static void
-QuickSortSpansX(DDXPointRec points[], int widths[], int numSpans)
-{
-    int x;
-    int i, j, m;
-    DDXPointPtr r;
-
-/* Always called with numSpans > 1 */
-/* Sorts only by x, as all y should be the same */
-
-#define ExchangeSpans(a, b)				    \
-{							    \
-    DDXPointRec 	tpt;				    \
-    int    		tw;				    \
-							    \
-    tpt = points[a]; points[a] = points[b]; points[b] = tpt;    \
-    tw = widths[a]; widths[a] = widths[b]; widths[b] = tw;  \
-}
-
-    do {
-        if (numSpans < 9) {
-            /* Do insertion sort */
-            int xprev;
-
-            xprev = points[0].x;
-            i = 1;
-            do {                /* while i != numSpans */
-                x = points[i].x;
-                if (xprev > x) {
-                    /* points[i] is out of order.  Move into proper location. */
-                    DDXPointRec tpt;
-                    int tw, k;
-
-                    for (j = 0; x >= points[j].x; j++) {
-                    }
-                    tpt = points[i];
-                    tw = widths[i];
-                    for (k = i; k != j; k--) {
-                        points[k] = points[k - 1];
-                        widths[k] = widths[k - 1];
-                    }
-                    points[j] = tpt;
-                    widths[j] = tw;
-                    x = points[i].x;
-                }               /* if out of order */
-                xprev = x;
-                i++;
-            } while (i != numSpans);
-            return;
-        }
-
-        /* Choose partition element, stick in location 0 */
-        m = numSpans / 2;
-        if (points[m].x > points[0].x)
-            ExchangeSpans(m, 0);
-        if (points[m].x > points[numSpans - 1].x)
-            ExchangeSpans(m, numSpans - 1);
-        if (points[m].x > points[0].x)
-            ExchangeSpans(m, 0);
-        x = points[0].x;
-
-        /* Partition array */
-        i = 0;
-        j = numSpans;
-        do {
-            r = &(points[i]);
-            do {
-                r++;
-                i++;
-            } while (i != numSpans && r->x < x);
-            r = &(points[j]);
-            do {
-                r--;
-                j--;
-            } while (x < r->x);
-            if (i < j)
-                ExchangeSpans(i, j);
-        } while (i < j);
-
-        /* Move partition element back to middle */
-        ExchangeSpans(0, j);
-
-        /* Recurse */
-        if (numSpans - j - 1 > 1)
-            QuickSortSpansX(&points[j + 1], &widths[j + 1], numSpans - j - 1);
-        numSpans = j;
-    } while (numSpans > 1);
-}                               /* QuickSortSpans */
-
-static int
-UniquifySpansX(Spans * spans, DDXPointRec * newPoints, int *newWidths)
-{
-    int newx1, newx2, oldpt, i, y;
-    DDXPointRec *oldPoints;
-    int *oldWidths;
-    int *startNewWidths;
-
-/* Always called with numSpans > 1 */
-/* Uniquify the spans, and stash them into newPoints and newWidths.  Return the
-   number of unique spans. */
-
-    startNewWidths = newWidths;
-
-    oldPoints = spans->points;
-    oldWidths = spans->widths;
-
-    y = oldPoints->y;
-    newx1 = oldPoints->x;
-    newx2 = newx1 + *oldWidths;
-
-    for (i = spans->count - 1; i != 0; i--) {
-        oldPoints++;
-        oldWidths++;
-        oldpt = oldPoints->x;
-        if (oldpt > newx2) {
-            /* Write current span, start a new one */
-            newPoints->x = newx1;
-            newPoints->y = y;
-            *newWidths = newx2 - newx1;
-            newPoints++;
-            newWidths++;
-            newx1 = oldpt;
-            newx2 = oldpt + *oldWidths;
-        }
-        else {
-            /* extend current span, if old extends beyond new */
-            oldpt = oldpt + *oldWidths;
-            if (oldpt > newx2)
-                newx2 = oldpt;
-        }
-    }                           /* for */
-
-    /* Write final span */
-    newPoints->x = newx1;
-    *newWidths = newx2 - newx1;
-    newPoints->y = y;
-
-    return (newWidths - startNewWidths) + 1;
-}                               /* UniquifySpansX */
-
-static void
-miDisposeSpanGroup(SpanGroup * spanGroup)
-{
-    int i;
-    Spans *spans;
-
-    for (i = 0; i < spanGroup->count; i++) {
-        spans = spanGroup->group + i;
-        free(spans->points);
-        free(spans->widths);
-    }
-}
-
-void
-miFillUniqueSpanGroup(DrawablePtr pDraw, GCPtr pGC, SpanGroup * spanGroup)
-{
-    int i;
-    Spans *spans;
-    Spans *yspans;
-    int *ysizes;
-    int ymin, ylength;
-
-    /* Outgoing spans for one big call to FillSpans */
-    DDXPointPtr points;
-    int *widths;
-    int count;
-
-    if (spanGroup->count == 0)
-        return;
-
-    if (spanGroup->count == 1) {
-        /* Already should be sorted, unique */
-        spans = spanGroup->group;
-        (*pGC->ops->FillSpans)
-            (pDraw, pGC, spans->count, spans->points, spans->widths, TRUE);
-        free(spans->points);
-        free(spans->widths);
-    }
-    else {
-        /* Yuck.  Gross.  Radix sort into y buckets, then sort x and uniquify */
-        /* This seems to be the fastest thing to do.  I've tried sorting on
-           both x and y at the same time rather than creating into all those
-           y buckets, but it was somewhat slower. */
-
-        ymin = spanGroup->ymin;
-        ylength = spanGroup->ymax - ymin + 1;
-
-        /* Allocate Spans for y buckets */
-        yspans = malloc(ylength * sizeof(Spans));
-        ysizes = malloc(ylength * sizeof(int));
-
-        if (!yspans || !ysizes) {
-            free(yspans);
-            free(ysizes);
-            miDisposeSpanGroup(spanGroup);
-            return;
-        }
-
-        for (i = 0; i != ylength; i++) {
-            ysizes[i] = 0;
-            yspans[i].count = 0;
-            yspans[i].points = NULL;
-            yspans[i].widths = NULL;
-        }
-
-        /* Go through every single span and put it into the correct bucket */
-        count = 0;
-        for (i = 0, spans = spanGroup->group;
-             i != spanGroup->count; i++, spans++) {
-            int index;
-            int j;
-
-            for (j = 0, points = spans->points, widths = spans->widths;
-                 j != spans->count; j++, points++, widths++) {
-                index = points->y - ymin;
-                if (index >= 0 && index < ylength) {
-                    Spans *newspans = &(yspans[index]);
-
-                    if (newspans->count == ysizes[index]) {
-                        DDXPointPtr newpoints;
-                        int *newwidths;
-
-                        ysizes[index] = (ysizes[index] + 8) * 2;
-                        newpoints = (DDXPointPtr) realloc(newspans->points,
-                                                          ysizes[index] *
-                                                          sizeof(DDXPointRec));
-                        newwidths =
-                            (int *) realloc(newspans->widths,
-                                            ysizes[index] * sizeof(int));
-                        if (!newpoints || !newwidths) {
-                            for (i = 0; i < ylength; i++) {
-                                free(yspans[i].points);
-                                free(yspans[i].widths);
-                            }
-                            free(yspans);
-                            free(ysizes);
-                            free(newpoints);
-                            free(newwidths);
-                            miDisposeSpanGroup(spanGroup);
-                            return;
-                        }
-                        newspans->points = newpoints;
-                        newspans->widths = newwidths;
-                    }
-                    newspans->points[newspans->count] = *points;
-                    newspans->widths[newspans->count] = *widths;
-                    (newspans->count)++;
-                }               /* if y value of span in range */
-            }                   /* for j through spans */
-            count += spans->count;
-            free(spans->points);
-            spans->points = NULL;
-            free(spans->widths);
-            spans->widths = NULL;
-        }                       /* for i thorough Spans */
-
-        /* Now sort by x and uniquify each bucket into the final array */
-        points = malloc(count * sizeof(DDXPointRec));
-        widths = malloc(count * sizeof(int));
-        if (!points || !widths) {
-            for (i = 0; i < ylength; i++) {
-                free(yspans[i].points);
-                free(yspans[i].widths);
-            }
-            free(yspans);
-            free(ysizes);
-            free(points);
-            free(widths);
-            return;
-        }
-        count = 0;
-        for (i = 0; i != ylength; i++) {
-            int ycount = yspans[i].count;
-
-            if (ycount > 0) {
-                if (ycount > 1) {
-                    QuickSortSpansX(yspans[i].points, yspans[i].widths, ycount);
-                    count += UniquifySpansX
-                        (&(yspans[i]), &(points[count]), &(widths[count]));
-                }
-                else {
-                    points[count] = yspans[i].points[0];
-                    widths[count] = yspans[i].widths[0];
-                    count++;
-                }
-                free(yspans[i].points);
-                free(yspans[i].widths);
-            }
-        }
-
-        (*pGC->ops->FillSpans) (pDraw, pGC, count, points, widths, TRUE);
-        free(points);
-        free(widths);
-        free(yspans);
-        free(ysizes);           /* use (DE)xalloc for these? */
-    }
-
-    spanGroup->count = 0;
-    spanGroup->ymin = MAXSHORT;
-    spanGroup->ymax = MINSHORT;
-}
diff --git a/mi/mispans.h b/mi/mispans.h
deleted file mode 100644
index 7c3fcef..0000000
--- a/mi/mispans.h
+++ /dev/null
@@ -1,83 +0,0 @@
-/***********************************************************
-
-Copyright 1989, 1998  The Open Group
-
-Permission to use, copy, modify, distribute, and sell this software and its
-documentation for any purpose is hereby granted without fee, provided that
-the above copyright notice appear in all copies and that both that
-copyright notice and this permission notice appear in supporting
-documentation.
-
-The above copyright notice and this permission notice shall be included in
-all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
-OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
-AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
-CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-
-Except as contained in this notice, the name of The Open Group shall not be
-used in advertising or otherwise to promote the sale, use or other dealings
-in this Software without prior written authorization from The Open Group.
-
-Copyright 1989 by Digital Equipment Corporation, Maynard, Massachusetts.
-
-                        All Rights Reserved
-
-Permission to use, copy, modify, and distribute this software and its 
-documentation for any purpose and without fee is hereby granted, 
-provided that the above copyright notice appear in all copies and that
-both that copyright notice and this permission notice appear in 
-supporting documentation, and that the name of Digital not be
-used in advertising or publicity pertaining to distribution of the
-software without specific, written prior permission.  
-
-DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
-ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
-DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
-ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
-WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
-ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
-SOFTWARE.
-
-******************************************************************/
-
-#ifndef MISPANS_H
-#define MISPANS_H
-
-typedef struct {
-    int count;                  /* number of spans                  */
-    DDXPointPtr points;         /* pointer to list of start points  */
-    int *widths;                /* pointer to list of widths        */
-} Spans;
-
-typedef struct {
-    int size;                   /* Total number of *Spans allocated     */
-    int count;                  /* Number of *Spans actually in group   */
-    Spans *group;               /* List of Spans                        */
-    int ymin, ymax;             /* Min, max y values encountered        */
-} SpanGroup;
-
-/* Initialize SpanGroup.  MUST BE DONE before use. */
-extern void miInitSpanGroup(SpanGroup *       /*spanGroup */);
-
-/* Add a Spans to a SpanGroup. The spans MUST BE in y-sorted order */
-extern void miAppendSpans(SpanGroup * /*spanGroup */ ,
-                          SpanGroup * /*otherGroup */ ,
-                          Spans *     /*spans */);
-
-/* Paint a span group, insuring that each pixel is painted at most once */
-extern void miFillUniqueSpanGroup(DrawablePtr /*pDraw */ ,
-                                  GCPtr /*pGC */ ,
-                                  SpanGroup * /*spanGroup */);
-
-/* Free up data in a span group.  MUST BE DONE or you'll suffer memory leaks */
-extern void miFreeSpanGroup(SpanGroup *       /*spanGroup */);
-
-/* Rops which must use span groups */
-#define miSpansCarefulRop(rop)	(((rop) & 0xc) == 0x8 || ((rop) & 0x3) == 0x2)
-#define miSpansEasyRop(rop)	(!miSpansCarefulRop(rop))
-
-#endif                          /* MISPANS_H */
diff --git a/mi/miwideline.c b/mi/miwideline.c
index 295a05a..452d74f 100644
--- a/mi/miwideline.c
+++ b/mi/miwideline.c
@@ -24,6 +24,25 @@ not be used in advertising or otherwise to promote the sale, use or
 other dealings in this Software without prior written authorization
 from The Open Group.
 
+Copyright 1989 by Digital Equipment Corporation, Maynard, Massachusetts.
+
+                        All Rights Reserved
+
+Permission to use, copy, modify, and distribute this software and its
+documentation for any purpose and without fee is hereby granted,
+provided that the above copyright notice appear in all copies and that
+both that copyright notice and this permission notice appear in
+supporting documentation, and that the name of Digital not be
+used in advertising or publicity pertaining to distribution of the
+software without specific, written prior permission.
+
+DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
+ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
+DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
+ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
+WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
+ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+SOFTWARE.
 */
 
 /* Author:  Keith Packard, MIT X Consortium */
@@ -52,6 +71,505 @@ from The Open Group.
 #include "miwideline.h"
 #include "mi.h"
 
+#if 0
+#ifdef HAVE_DIX_CONFIG_H
+#include <dix-config.h>
+#endif
+
+#include "misc.h"
+#include "pixmapstr.h"
+#include "gcstruct.h"
+#endif
+
+typedef struct {
+    int count;                  /* number of spans                  */
+    DDXPointPtr points;         /* pointer to list of start points  */
+    int *widths;                /* pointer to list of widths        */
+} Spans;
+
+typedef struct {
+    int size;                   /* Total number of *Spans allocated     */
+    int count;                  /* Number of *Spans actually in group   */
+    Spans *group;               /* List of Spans                        */
+    int ymin, ymax;             /* Min, max y values encountered        */
+} SpanGroup;
+
+/* Rops which must use span groups */
+#define miSpansCarefulRop(rop)	(((rop) & 0xc) == 0x8 || ((rop) & 0x3) == 0x2)
+#define miSpansEasyRop(rop)	(!miSpansCarefulRop(rop))
+
+/*
+
+These routines maintain lists of Spans, in order to implement the
+``touch-each-pixel-once'' rules of wide lines and arcs.
+
+Written by Joel McCormack, Summer 1989.
+
+*/
+
+static void
+miInitSpanGroup(SpanGroup * spanGroup)
+{
+    spanGroup->size = 0;
+    spanGroup->count = 0;
+    spanGroup->group = NULL;
+    spanGroup->ymin = MAXSHORT;
+    spanGroup->ymax = MINSHORT;
+}                               /* InitSpanGroup */
+
+#define YMIN(spans) (spans->points[0].y)
+#define YMAX(spans)  (spans->points[spans->count-1].y)
+
+static void
+miSubtractSpans(SpanGroup * spanGroup, Spans * sub)
+{
+    int i, subCount, spansCount;
+    int ymin, ymax, xmin, xmax;
+    Spans *spans;
+    DDXPointPtr subPt, spansPt;
+    int *subWid, *spansWid;
+    int extra;
+
+    ymin = YMIN(sub);
+    ymax = YMAX(sub);
+    spans = spanGroup->group;
+    for (i = spanGroup->count; i; i--, spans++) {
+        if (YMIN(spans) <= ymax && ymin <= YMAX(spans)) {
+            subCount = sub->count;
+            subPt = sub->points;
+            subWid = sub->widths;
+            spansCount = spans->count;
+            spansPt = spans->points;
+            spansWid = spans->widths;
+            extra = 0;
+            for (;;) {
+                while (spansCount && spansPt->y < subPt->y) {
+                    spansPt++;
+                    spansWid++;
+                    spansCount--;
+                }
+                if (!spansCount)
+                    break;
+                while (subCount && subPt->y < spansPt->y) {
+                    subPt++;
+                    subWid++;
+                    subCount--;
+                }
+                if (!subCount)
+                    break;
+                if (subPt->y == spansPt->y) {
+                    xmin = subPt->x;
+                    xmax = xmin + *subWid;
+                    if (xmin >= spansPt->x + *spansWid || spansPt->x >= xmax) {
+                        ;
+                    }
+                    else if (xmin <= spansPt->x) {
+                        if (xmax >= spansPt->x + *spansWid) {
+                            memmove(spansPt, spansPt + 1,
+                                    sizeof *spansPt * (spansCount - 1));
+                            memmove(spansWid, spansWid + 1,
+                                    sizeof *spansWid * (spansCount - 1));
+                            spansPt--;
+                            spansWid--;
+                            spans->count--;
+                            extra++;
+                        }
+                        else {
+                            *spansWid = *spansWid - (xmax - spansPt->x);
+                            spansPt->x = xmax;
+                        }
+                    }
+                    else {
+                        if (xmax >= spansPt->x + *spansWid) {
+                            *spansWid = xmin - spansPt->x;
+                        }
+                        else {
+                            if (!extra) {
+                                DDXPointPtr newPt;
+                                int *newwid;
+
+#define EXTRA 8
+                                newPt =
+                                    (DDXPointPtr) realloc(spans->points,
+                                                          (spans->count +
+                                                           EXTRA) *
+                                                          sizeof(DDXPointRec));
+                                if (!newPt)
+                                    break;
+                                spansPt = newPt + (spansPt - spans->points);
+                                spans->points = newPt;
+                                newwid =
+                                    (int *) realloc(spans->widths,
+                                                    (spans->count +
+                                                     EXTRA) * sizeof(int));
+                                if (!newwid)
+                                    break;
+                                spansWid = newwid + (spansWid - spans->widths);
+                                spans->widths = newwid;
+                                extra = EXTRA;
+                            }
+                            memmove(spansPt + 1, spansPt,
+                                    sizeof *spansPt * (spansCount));
+                            memmove(spansWid + 1, spansWid,
+                                    sizeof *spansWid * (spansCount));
+                            spans->count++;
+                            extra--;
+                            *spansWid = xmin - spansPt->x;
+                            spansWid++;
+                            spansPt++;
+                            *spansWid = *spansWid - (xmax - spansPt->x);
+                            spansPt->x = xmax;
+                        }
+                    }
+                }
+                spansPt++;
+                spansWid++;
+                spansCount--;
+            }
+        }
+    }
+}
+
+static void
+miAppendSpans(SpanGroup * spanGroup, SpanGroup * otherGroup, Spans * spans)
+{
+    int ymin, ymax;
+    int spansCount;
+
+    spansCount = spans->count;
+    if (spansCount > 0) {
+        if (spanGroup->size == spanGroup->count) {
+            spanGroup->size = (spanGroup->size + 8) * 2;
+            spanGroup->group = (Spans *)
+                realloc(spanGroup->group, sizeof(Spans) * spanGroup->size);
+        }
+
+        spanGroup->group[spanGroup->count] = *spans;
+        (spanGroup->count)++;
+        ymin = spans->points[0].y;
+        if (ymin < spanGroup->ymin)
+            spanGroup->ymin = ymin;
+        ymax = spans->points[spansCount - 1].y;
+        if (ymax > spanGroup->ymax)
+            spanGroup->ymax = ymax;
+        if (otherGroup && otherGroup->ymin < ymax && ymin < otherGroup->ymax) {
+            miSubtractSpans(otherGroup, spans);
+        }
+    }
+    else {
+        free(spans->points);
+        free(spans->widths);
+    }
+}                               /* AppendSpans */
+
+static void
+miFreeSpanGroup(SpanGroup * spanGroup)
+{
+    free(spanGroup->group);
+}
+
+static void
+QuickSortSpansX(DDXPointRec points[], int widths[], int numSpans)
+{
+    int x;
+    int i, j, m;
+    DDXPointPtr r;
+
+/* Always called with numSpans > 1 */
+/* Sorts only by x, as all y should be the same */
+
+#define ExchangeSpans(a, b)				    \
+{							    \
+    DDXPointRec 	tpt;				    \
+    int    		tw;				    \
+							    \
+    tpt = points[a]; points[a] = points[b]; points[b] = tpt;    \
+    tw = widths[a]; widths[a] = widths[b]; widths[b] = tw;  \
+}
+
+    do {
+        if (numSpans < 9) {
+            /* Do insertion sort */
+            int xprev;
+
+            xprev = points[0].x;
+            i = 1;
+            do {                /* while i != numSpans */
+                x = points[i].x;
+                if (xprev > x) {
+                    /* points[i] is out of order.  Move into proper location. */
+                    DDXPointRec tpt;
+                    int tw, k;
+
+                    for (j = 0; x >= points[j].x; j++) {
+                    }
+                    tpt = points[i];
+                    tw = widths[i];
+                    for (k = i; k != j; k--) {
+                        points[k] = points[k - 1];
+                        widths[k] = widths[k - 1];
+                    }
+                    points[j] = tpt;
+                    widths[j] = tw;
+                    x = points[i].x;
+                }               /* if out of order */
+                xprev = x;
+                i++;
+            } while (i != numSpans);
+            return;
+        }
+
+        /* Choose partition element, stick in location 0 */
+        m = numSpans / 2;
+        if (points[m].x > points[0].x)
+            ExchangeSpans(m, 0);
+        if (points[m].x > points[numSpans - 1].x)
+            ExchangeSpans(m, numSpans - 1);
+        if (points[m].x > points[0].x)
+            ExchangeSpans(m, 0);
+        x = points[0].x;
+
+        /* Partition array */
+        i = 0;
+        j = numSpans;
+        do {
+            r = &(points[i]);
+            do {
+                r++;
+                i++;
+            } while (i != numSpans && r->x < x);
+            r = &(points[j]);
+            do {
+                r--;
+                j--;
+            } while (x < r->x);
+            if (i < j)
+                ExchangeSpans(i, j);
+        } while (i < j);
+
+        /* Move partition element back to middle */
+        ExchangeSpans(0, j);
+
+        /* Recurse */
+        if (numSpans - j - 1 > 1)
+            QuickSortSpansX(&points[j + 1], &widths[j + 1], numSpans - j - 1);
+        numSpans = j;
+    } while (numSpans > 1);
+}                               /* QuickSortSpans */
+
+static int
+UniquifySpansX(Spans * spans, DDXPointRec * newPoints, int *newWidths)
+{
+    int newx1, newx2, oldpt, i, y;
+    DDXPointRec *oldPoints;
+    int *oldWidths;
+    int *startNewWidths;
+
+/* Always called with numSpans > 1 */
+/* Uniquify the spans, and stash them into newPoints and newWidths.  Return the
+   number of unique spans. */
+
+    startNewWidths = newWidths;
+
+    oldPoints = spans->points;
+    oldWidths = spans->widths;
+
+    y = oldPoints->y;
+    newx1 = oldPoints->x;
+    newx2 = newx1 + *oldWidths;
+
+    for (i = spans->count - 1; i != 0; i--) {
+        oldPoints++;
+        oldWidths++;
+        oldpt = oldPoints->x;
+        if (oldpt > newx2) {
+            /* Write current span, start a new one */
+            newPoints->x = newx1;
+            newPoints->y = y;
+            *newWidths = newx2 - newx1;
+            newPoints++;
+            newWidths++;
+            newx1 = oldpt;
+            newx2 = oldpt + *oldWidths;
+        }
+        else {
+            /* extend current span, if old extends beyond new */
+            oldpt = oldpt + *oldWidths;
+            if (oldpt > newx2)
+                newx2 = oldpt;
+        }
+    }                           /* for */
+
+    /* Write final span */
+    newPoints->x = newx1;
+    *newWidths = newx2 - newx1;
+    newPoints->y = y;
+
+    return (newWidths - startNewWidths) + 1;
+}                               /* UniquifySpansX */
+
+static void
+miDisposeSpanGroup(SpanGroup * spanGroup)
+{
+    int i;
+    Spans *spans;
+
+    for (i = 0; i < spanGroup->count; i++) {
+        spans = spanGroup->group + i;
+        free(spans->points);
+        free(spans->widths);
+    }
+}
+
+static void
+miFillUniqueSpanGroup(DrawablePtr pDraw, GCPtr pGC, SpanGroup * spanGroup)
+{
+    int i;
+    Spans *spans;
+    Spans *yspans;
+    int *ysizes;
+    int ymin, ylength;
+
+    /* Outgoing spans for one big call to FillSpans */
+    DDXPointPtr points;
+    int *widths;
+    int count;
+
+    if (spanGroup->count == 0)
+        return;
+
+    if (spanGroup->count == 1) {
+        /* Already should be sorted, unique */
+        spans = spanGroup->group;
+        (*pGC->ops->FillSpans)
+            (pDraw, pGC, spans->count, spans->points, spans->widths, TRUE);
+        free(spans->points);
+        free(spans->widths);
+    }
+    else {
+        /* Yuck.  Gross.  Radix sort into y buckets, then sort x and uniquify */
+        /* This seems to be the fastest thing to do.  I've tried sorting on
+           both x and y at the same time rather than creating into all those
+           y buckets, but it was somewhat slower. */
+
+        ymin = spanGroup->ymin;
+        ylength = spanGroup->ymax - ymin + 1;
+
+        /* Allocate Spans for y buckets */
+        yspans = malloc(ylength * sizeof(Spans));
+        ysizes = malloc(ylength * sizeof(int));
+
+        if (!yspans || !ysizes) {
+            free(yspans);
+            free(ysizes);
+            miDisposeSpanGroup(spanGroup);
+            return;
+        }
+
+        for (i = 0; i != ylength; i++) {
+            ysizes[i] = 0;
+            yspans[i].count = 0;
+            yspans[i].points = NULL;
+            yspans[i].widths = NULL;
+        }
+
+        /* Go through every single span and put it into the correct bucket */
+        count = 0;
+        for (i = 0, spans = spanGroup->group;
+             i != spanGroup->count; i++, spans++) {
+            int index;
+            int j;
+
+            for (j = 0, points = spans->points, widths = spans->widths;
+                 j != spans->count; j++, points++, widths++) {
+                index = points->y - ymin;
+                if (index >= 0 && index < ylength) {
+                    Spans *newspans = &(yspans[index]);
+
+                    if (newspans->count == ysizes[index]) {
+                        DDXPointPtr newpoints;
+                        int *newwidths;
+
+                        ysizes[index] = (ysizes[index] + 8) * 2;
+                        newpoints = (DDXPointPtr) realloc(newspans->points,
+                                                          ysizes[index] *
+                                                          sizeof(DDXPointRec));
+                        newwidths =
+                            (int *) realloc(newspans->widths,
+                                            ysizes[index] * sizeof(int));
+                        if (!newpoints || !newwidths) {
+                            for (i = 0; i < ylength; i++) {
+                                free(yspans[i].points);
+                                free(yspans[i].widths);
+                            }
+                            free(yspans);
+                            free(ysizes);
+                            free(newpoints);
+                            free(newwidths);
+                            miDisposeSpanGroup(spanGroup);
+                            return;
+                        }
+                        newspans->points = newpoints;
+                        newspans->widths = newwidths;
+                    }
+                    newspans->points[newspans->count] = *points;
+                    newspans->widths[newspans->count] = *widths;
+                    (newspans->count)++;
+                }               /* if y value of span in range */
+            }                   /* for j through spans */
+            count += spans->count;
+            free(spans->points);
+            spans->points = NULL;
+            free(spans->widths);
+            spans->widths = NULL;
+        }                       /* for i thorough Spans */
+
+        /* Now sort by x and uniquify each bucket into the final array */
+        points = malloc(count * sizeof(DDXPointRec));
+        widths = malloc(count * sizeof(int));
+        if (!points || !widths) {
+            for (i = 0; i < ylength; i++) {
+                free(yspans[i].points);
+                free(yspans[i].widths);
+            }
+            free(yspans);
+            free(ysizes);
+            free(points);
+            free(widths);
+            return;
+        }
+        count = 0;
+        for (i = 0; i != ylength; i++) {
+            int ycount = yspans[i].count;
+
+            if (ycount > 0) {
+                if (ycount > 1) {
+                    QuickSortSpansX(yspans[i].points, yspans[i].widths, ycount);
+                    count += UniquifySpansX
+                        (&(yspans[i]), &(points[count]), &(widths[count]));
+                }
+                else {
+                    points[count] = yspans[i].points[0];
+                    widths[count] = yspans[i].widths[0];
+                    count++;
+                }
+                free(yspans[i].points);
+                free(yspans[i].widths);
+            }
+        }
+
+        (*pGC->ops->FillSpans) (pDraw, pGC, count, points, widths, TRUE);
+        free(points);
+        free(widths);
+        free(yspans);
+        free(ysizes);           /* use (DE)xalloc for these? */
+    }
+
+    spanGroup->count = 0;
+    spanGroup->ymin = MAXSHORT;
+    spanGroup->ymax = MINSHORT;
+}
+
 static Bool
 InitSpans(Spans * spans, size_t nspans)
 {
diff --git a/mi/miwideline.h b/mi/miwideline.h
index a9f2740..88bc3d6 100644
--- a/mi/miwideline.h
+++ b/mi/miwideline.h
@@ -28,7 +28,6 @@ from The Open Group.
 
 /* Author:  Keith Packard, MIT X Consortium */
 
-#include "mispans.h"
 #include "mifpoly.h"            /* for ICEIL */
 
 /*
commit 707965407a3c907058b89610e73e02989fd0b552
Author: Adam Jackson <ajax at redhat.com>
Date:   Fri May 23 12:10:29 2014 -0400

    mi: Unexport arc fill implementation details
    
    Reviewed-by: Keith Packard <keithp at keithp.com>
    Signed-off-by: Adam Jackson <ajax at redhat.com>

diff --git a/mi/Makefile.am b/mi/Makefile.am
index b243029..4466f69 100644
--- a/mi/Makefile.am
+++ b/mi/Makefile.am
@@ -2,7 +2,7 @@ noinst_LTLIBRARIES = libmi.la
 
 if XORG
 sdk_HEADERS = micmap.h miline.h mipointer.h mi.h \
-              migc.h mipointrst.h mizerarc.h micoord.h mifillarc.h \
+              migc.h mipointrst.h mizerarc.h micoord.h \
               mistruct.h mioverlay.h
 endif
 
diff --git a/mi/mifillarc.c b/mi/mifillarc.c
index 08484d7..9a5e785 100644
--- a/mi/mifillarc.c
+++ b/mi/mifillarc.c
@@ -51,7 +51,7 @@ Author:  Bob Scheifler, MIT X Consortium
 #define Dsin(d)	sin((double)d*(M_PI/11520.0))
 #define Dcos(d)	cos((double)d*(M_PI/11520.0))
 
-void
+static void
 miFillArcSetup(xArc * arc, miFillArcRec * info)
 {
     info->y = arc->height >> 1;
@@ -277,7 +277,7 @@ miGetPieEdge(xArc * arc, int angle, miSliceEdgePtr edge, Bool top, Bool left)
     miGetArcEdge(arc, edge, k, top, left);
 }
 
-void
+static void
 miFillArcSliceSetup(xArc * arc, miArcSliceRec * slice, GCPtr pGC)
 {
     int angle1, angle2;
diff --git a/mi/mifillarc.h b/mi/mifillarc.h
index 1478d18..61ab253 100644
--- a/mi/mifillarc.h
+++ b/mi/mifillarc.h
@@ -175,13 +175,4 @@ typedef struct _miArcSlice {
 #define miFillInArcLower(slw) (((iny + dy) != 0) && \
 			       ((slw > 1) || (ine != inxk)))
 
-extern _X_EXPORT void miFillArcSetup(xArc * /*arc */ ,
-                                     miFillArcRec *     /*info */
-    );
-
-extern _X_EXPORT void miFillArcSliceSetup(xArc * /*arc */ ,
-                                          miArcSliceRec * /*slice */ ,
-                                          GCPtr /*pGC */
-    );
-
 #endif                          /* __MIFILLARC_H__ */
commit ce8fff5cd681523088c14b97ce4fb6e4fb658321
Author: Adam Jackson <ajax at redhat.com>
Date:   Fri May 23 12:06:03 2014 -0400

    mi: Unexport subpixel polygon implementation details
    
    Reviewed-by: Keith Packard <keithp at keithp.com>
    Signed-off-by: Adam Jackson <ajax at redhat.com>

diff --git a/mi/Makefile.am b/mi/Makefile.am
index b93a8f9..b243029 100644
--- a/mi/Makefile.am
+++ b/mi/Makefile.am
@@ -3,7 +3,7 @@ noinst_LTLIBRARIES = libmi.la
 if XORG
 sdk_HEADERS = micmap.h miline.h mipointer.h mi.h \
               migc.h mipointrst.h mizerarc.h micoord.h mifillarc.h \
-              mistruct.h mifpoly.h mioverlay.h
+              mistruct.h mioverlay.h
 endif
 
 AM_CFLAGS = $(DIX_CFLAGS)
diff --git a/mi/mifpoly.h b/mi/mifpoly.h
index f853fb4..4b27d1c 100644
--- a/mi/mifpoly.h
+++ b/mi/mifpoly.h
@@ -89,14 +89,13 @@ typedef struct _SppArc {
 
 /* mifpolycon.c */
 
-extern _X_EXPORT void miFillSppPoly(DrawablePtr /*dst */ ,
-                                    GCPtr /*pgc */ ,
-                                    int /*count */ ,
-                                    SppPointPtr /*ptsIn */ ,
-                                    int /*xTrans */ ,
-                                    int /*yTrans */ ,
-                                    double /*xFtrans */ ,
-                                    double      /*yFtrans */
-    );
+extern void miFillSppPoly(DrawablePtr /*dst */ ,
+                          GCPtr /*pgc */ ,
+                          int /*count */ ,
+                          SppPointPtr /*ptsIn */ ,
+                          int /*xTrans */ ,
+                          int /*yTrans */ ,
+                          double /*xFtrans */ ,
+                          double      /*yFtrans */);
 
 #endif                          /* __MIFPOLY_H__ */
commit a085ba82bde375b5c884a40b410b563815c58a9e
Author: Adam Jackson <ajax at redhat.com>
Date:   Fri May 23 11:55:05 2014 -0400

    mi: Unexport span group implementation details
    
    Reviewed-by: Keith Packard <keithp at keithp.com>
    Signed-off-by: Adam Jackson <ajax at redhat.com>

diff --git a/mi/Makefile.am b/mi/Makefile.am
index 526f4bb..b93a8f9 100644
--- a/mi/Makefile.am
+++ b/mi/Makefile.am
@@ -3,7 +3,7 @@ noinst_LTLIBRARIES = libmi.la
 if XORG
 sdk_HEADERS = micmap.h miline.h mipointer.h mi.h \
               migc.h mipointrst.h mizerarc.h micoord.h mifillarc.h \
-              mispans.h mistruct.h mifpoly.h mioverlay.h
+              mistruct.h mifpoly.h mioverlay.h
 endif
 
 AM_CFLAGS = $(DIX_CFLAGS)
diff --git a/mi/mispans.h b/mi/mispans.h
index f3148ff..7c3fcef 100644
--- a/mi/mispans.h
+++ b/mi/mispans.h
@@ -61,24 +61,20 @@ typedef struct {
 } SpanGroup;
 
 /* Initialize SpanGroup.  MUST BE DONE before use. */
-extern _X_EXPORT void miInitSpanGroup(SpanGroup *       /*spanGroup */
-    );
+extern void miInitSpanGroup(SpanGroup *       /*spanGroup */);
 
 /* Add a Spans to a SpanGroup. The spans MUST BE in y-sorted order */
-extern _X_EXPORT void miAppendSpans(SpanGroup * /*spanGroup */ ,
-                                    SpanGroup * /*otherGroup */ ,
-                                    Spans *     /*spans */
-    );
+extern void miAppendSpans(SpanGroup * /*spanGroup */ ,
+                          SpanGroup * /*otherGroup */ ,
+                          Spans *     /*spans */);
 
 /* Paint a span group, insuring that each pixel is painted at most once */
-extern _X_EXPORT void miFillUniqueSpanGroup(DrawablePtr /*pDraw */ ,
-                                            GCPtr /*pGC */ ,
-                                            SpanGroup * /*spanGroup */
-    );
+extern void miFillUniqueSpanGroup(DrawablePtr /*pDraw */ ,
+                                  GCPtr /*pGC */ ,
+                                  SpanGroup * /*spanGroup */);
 
 /* Free up data in a span group.  MUST BE DONE or you'll suffer memory leaks */
-extern _X_EXPORT void miFreeSpanGroup(SpanGroup *       /*spanGroup */
-    );
+extern void miFreeSpanGroup(SpanGroup *       /*spanGroup */);
 
 /* Rops which must use span groups */
 #define miSpansCarefulRop(rop)	(((rop) & 0xc) == 0x8 || ((rop) & 0x3) == 0x2)
commit c15c886ee70f9144bc4603b918310f229312aadc
Author: Adam Jackson <ajax at redhat.com>
Date:   Fri May 23 11:50:07 2014 -0400

    mi: Unexport polygon edge table implementation details
    
    Reviewed-by: Keith Packard <keithp at keithp.com>
    Signed-off-by: Adam Jackson <ajax at redhat.com>

diff --git a/mi/mipoly.h b/mi/mipoly.h
index e37fb48..02fcfc8 100644
--- a/mi/mipoly.h
+++ b/mi/mipoly.h
@@ -174,20 +174,17 @@ typedef struct _ScanLineListBlock {
 
 /* mipolyutil.c */
 
-extern _X_EXPORT Bool miCreateETandAET(int /*count */ ,
-                                       DDXPointPtr /*pts */ ,
-                                       EdgeTable * /*ET*/,
-                                       EdgeTableEntry * /*AET*/,
-                                       EdgeTableEntry * /*pETEs */ ,
-                                       ScanLineListBlock *      /*pSLLBlock */
-    );
+extern Bool miCreateETandAET(int /*count */ ,
+                             DDXPointPtr /*pts */ ,
+                             EdgeTable * /*ET*/,
+                             EdgeTableEntry * /*AET*/,
+                             EdgeTableEntry * /*pETEs */ ,
+                             ScanLineListBlock *      /*pSLLBlock */);
 
-extern _X_EXPORT void miloadAET(EdgeTableEntry * /*AET*/, EdgeTableEntry *      /*ETEs */
-    );
+extern void miloadAET(EdgeTableEntry * /*AET*/, EdgeTableEntry * /*ETEs */);
 
-extern _X_EXPORT void micomputeWAET(EdgeTableEntry * /*AET*/);
+extern void micomputeWAET(EdgeTableEntry * /*AET*/);
 
-extern _X_EXPORT int miInsertionSort(EdgeTableEntry * /*AET*/);
+extern int miInsertionSort(EdgeTableEntry * /*AET*/);
 
-extern _X_EXPORT void miFreeStorage(ScanLineListBlock * /*pSLLBlock */
-    );
+extern void miFreeStorage(ScanLineListBlock * /*pSLLBlock */);
commit 9bdc9b0113915de3d536b2b3f025915379c2126f
Author: Adam Jackson <ajax at redhat.com>
Date:   Fri May 23 11:21:28 2014 -0400

    mi: Unexport wide line details
    
    XAA wanted these, once upon a time, but that's gone now.
    
    Reviewed-by: Keith Packard <keithp at keithp.com>
    Signed-off-by: Adam Jackson <ajax at redhat.com>

diff --git a/hw/xfree86/sdksyms.sh b/hw/xfree86/sdksyms.sh
index d9a4478..c2a1942 100755
--- a/hw/xfree86/sdksyms.sh
+++ b/hw/xfree86/sdksyms.sh
@@ -217,7 +217,6 @@ cat > sdksyms.c << EOF
 #include "micoord.h"
 #include "mifillarc.h"
 #include "mispans.h"
-#include "miwideline.h"
 #include "mistruct.h"
 #include "mifpoly.h"
 #include "mioverlay.h"
diff --git a/mi/Makefile.am b/mi/Makefile.am
index 0cef779..526f4bb 100644
--- a/mi/Makefile.am
+++ b/mi/Makefile.am
@@ -3,7 +3,7 @@ noinst_LTLIBRARIES = libmi.la
 if XORG
 sdk_HEADERS = micmap.h miline.h mipointer.h mi.h \
               migc.h mipointrst.h mizerarc.h micoord.h mifillarc.h \
-              mispans.h miwideline.h mistruct.h mifpoly.h mioverlay.h
+              mispans.h mistruct.h mifpoly.h mioverlay.h
 endif
 
 AM_CFLAGS = $(DIX_CFLAGS)
diff --git a/mi/miwideline.c b/mi/miwideline.c
index 29ba12c..295a05a 100644
--- a/mi/miwideline.c
+++ b/mi/miwideline.c
@@ -273,7 +273,7 @@ miFillRectPolyHelper(DrawablePtr pDrawable,
     }
 }
 
-/* static */ int
+static int
 miPolyBuildEdge(double x0, double y0, double k, /* x0 * dy - y0 * dx */
                 int dx, int dy, int xi, int yi, int left, PolyEdgePtr edge)
 {
@@ -325,7 +325,7 @@ miPolyBuildEdge(double x0, double y0, double k, /* x0 * dy - y0 * dx */
 
 #define StepAround(v, incr, max) (((v) + (incr) < 0) ? (max - 1) : ((v) + (incr) == max) ? 0 : ((v) + (incr)))
 
-/* static */ int
+static int
 miPolyBuildPoly(PolyVertexPtr vertices,
                 PolySlopePtr slopes,
                 int count,
@@ -865,7 +865,7 @@ miRoundJoinFace(LineFacePtr face, PolyEdgePtr edge, Bool *leftEdge)
     return y;
 }
 
-void
+static void
 miRoundJoinClip(LineFacePtr pLeft, LineFacePtr pRight,
                 PolyEdgePtr edge1, PolyEdgePtr edge2,
                 int *y1, int *y2, Bool *left1, Bool *left2)
@@ -886,7 +886,7 @@ miRoundJoinClip(LineFacePtr pLeft, LineFacePtr pRight,
     *y2 = miRoundJoinFace(pRight, edge2, left2);
 }
 
-int
+static int
 miRoundCapClip(LineFacePtr face, Bool isInt, PolyEdgePtr edge, Bool *leftEdge)
 {
     int y;
diff --git a/mi/miwideline.h b/mi/miwideline.h
index 1105411..a9f2740 100644
--- a/mi/miwideline.h
+++ b/mi/miwideline.h
@@ -92,28 +92,3 @@ typedef struct _LineFace {
 	ValidateGC (pDrawable, pGC); \
     } \
 }
-
-extern _X_EXPORT void miRoundJoinClip(LineFacePtr /*pLeft */ ,
-                                      LineFacePtr /*pRight */ ,
-                                      PolyEdgePtr /*edge1 */ ,
-                                      PolyEdgePtr /*edge2 */ ,
-                                      int * /*y1 */ ,
-                                      int * /*y2 */ ,
-                                      Bool * /*left1 */ ,
-                                      Bool *    /*left2 */
-    );
-
-extern _X_EXPORT int miRoundCapClip(LineFacePtr /*face */ ,
-                                    Bool /*isInt */ ,
-                                    PolyEdgePtr /*edge */ ,
-                                    Bool *      /*leftEdge */
-    );
-
-extern _X_EXPORT int miPolyBuildEdge(double x0, double y0, double k, int dx,
-                                     int dy, int xi, int yi, int left,
-                                     PolyEdgePtr edge);
-extern _X_EXPORT int miPolyBuildPoly(PolyVertexPtr vertices,
-                                     PolySlopePtr slopes, int count, int xi,
-                                     int yi, PolyEdgePtr left,
-                                     PolyEdgePtr right, int *pnleft,
-                                     int *pnright, int *h);
commit d181e52ceb9ae44e1faa8d5af8805f43328da6c2
Author: Keith Packard <keithp at keithp.com>
Date:   Fri Oct 24 11:56:23 2014 -0700

    glamor: Free converted bits in _glamor_upload_bits_to_pixmap_texture fast path
    
    When uploading bits to a texture which need reformatting to match a
    supported GL format, a temporary buffer is allocated to hold the
    reformatted bits. This gets freed in the general path, but is not
    freed in the fast path because that includes an early return before
    the call to free.
    
    This patch removes the early return and places the general case under
    an 'else' block, so that both paths reach the call to free.
    
    Signed-off-by: Keith Packard <keithp at keithp.com>
    Reviewed-by: Alex Deucher <alexander.deucher at amd.com>

diff --git a/glamor/glamor_pixmap.c b/glamor/glamor_pixmap.c
index 7c9bf26..947113e 100644
--- a/glamor/glamor_pixmap.c
+++ b/glamor/glamor_pixmap.c
@@ -808,45 +808,44 @@ _glamor_upload_bits_to_pixmap_texture(PixmapPtr pixmap, GLenum format,
                                           format, type,
                                           x + fbo_x_off, y + fbo_y_off, w, h,
                                           bits, pbo);
-        return TRUE;
+    } else {
+        ptexcoords = texcoords_inv;
+
+        pixmap_priv_get_dest_scale(pixmap_priv, &dst_xscale, &dst_yscale);
+        glamor_set_normalize_vcoords(pixmap_priv, dst_xscale,
+                                     dst_yscale,
+                                     x, y,
+                                     x + w, y + h,
+                                     vertices);
+        /* Slow path, we need to flip y or wire alpha to 1. */
+        glamor_make_current(glamor_priv);
+        glVertexAttribPointer(GLAMOR_VERTEX_POS, 2, GL_FLOAT,
+                              GL_FALSE, 2 * sizeof(float), vertices);
+        glEnableVertexAttribArray(GLAMOR_VERTEX_POS);
+        glVertexAttribPointer(GLAMOR_VERTEX_SOURCE, 2, GL_FLOAT,
+                              GL_FALSE, 2 * sizeof(float), ptexcoords);
+        glEnableVertexAttribArray(GLAMOR_VERTEX_SOURCE);
+
+        glamor_set_destination_pixmap_priv_nc(pixmap_priv);
+        __glamor_upload_pixmap_to_texture(pixmap, &tex,
+                                          format, type, 0, 0, w, h, bits, pbo);
+        glActiveTexture(GL_TEXTURE0);
+        glBindTexture(GL_TEXTURE_2D, tex);
+
+        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
+        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
+        glUseProgram(glamor_priv->finish_access_prog[no_alpha]);
+        glUniform1i(glamor_priv->finish_access_revert[no_alpha], revert);
+        glUniform1i(glamor_priv->finish_access_swap_rb[no_alpha], swap_rb);
+
+        glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
+
+        glDisableVertexAttribArray(GLAMOR_VERTEX_POS);
+        glDisableVertexAttribArray(GLAMOR_VERTEX_SOURCE);
+        glDeleteTextures(1, &tex);
+        glBindFramebuffer(GL_FRAMEBUFFER, 0);
     }
 
-    ptexcoords = texcoords_inv;
-
-    pixmap_priv_get_dest_scale(pixmap_priv, &dst_xscale, &dst_yscale);
-    glamor_set_normalize_vcoords(pixmap_priv, dst_xscale,
-                                 dst_yscale,
-                                 x, y,
-                                 x + w, y + h,
-                                 vertices);
-    /* Slow path, we need to flip y or wire alpha to 1. */
-    glamor_make_current(glamor_priv);
-    glVertexAttribPointer(GLAMOR_VERTEX_POS, 2, GL_FLOAT,
-                          GL_FALSE, 2 * sizeof(float), vertices);
-    glEnableVertexAttribArray(GLAMOR_VERTEX_POS);
-    glVertexAttribPointer(GLAMOR_VERTEX_SOURCE, 2, GL_FLOAT,
-                          GL_FALSE, 2 * sizeof(float), ptexcoords);
-    glEnableVertexAttribArray(GLAMOR_VERTEX_SOURCE);
-
-    glamor_set_destination_pixmap_priv_nc(pixmap_priv);
-    __glamor_upload_pixmap_to_texture(pixmap, &tex,
-                                      format, type, 0, 0, w, h, bits, pbo);
-    glActiveTexture(GL_TEXTURE0);
-    glBindTexture(GL_TEXTURE_2D, tex);
-
-    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
-    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
-    glUseProgram(glamor_priv->finish_access_prog[no_alpha]);
-    glUniform1i(glamor_priv->finish_access_revert[no_alpha], revert);
-    glUniform1i(glamor_priv->finish_access_swap_rb[no_alpha], swap_rb);
-
-    glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
-
-    glDisableVertexAttribArray(GLAMOR_VERTEX_POS);
-    glDisableVertexAttribArray(GLAMOR_VERTEX_SOURCE);
-    glDeleteTextures(1, &tex);
-    glBindFramebuffer(GL_FRAMEBUFFER, 0);
-
     if (need_free_bits)
         free(bits);
     return TRUE;
commit 55b27ed70cf9dfa9b9dffe46e9a3191bfda38f7c
Author: Andreas Hartmetz <ahartmetz at gmail.com>
Date:   Sat Oct 4 18:13:04 2014 +0200

    glamor: Don't free memory we are going to use.
    
    glamor_color_convert_to_bits() returns its second argument on
    success, NULL on error, and need_free_bits already makes sure that
    "bits" aliasing converted_bits is freed in the success case.
    Looks like the memory leak that was supposed to be fixed in
    6e50bfa706cd3ab884c933bf1f17c221a6208aa4 only occurred in the error
    case.
    
    Reviewed-by: Michel Dänzer <michel.daenzer at amd.com>
    Signed-off-by: Keith Packard <keithp at keithp.com>

diff --git a/glamor/glamor_pixmap.c b/glamor/glamor_pixmap.c
index 355fe4b..7c9bf26 100644
--- a/glamor/glamor_pixmap.c
+++ b/glamor/glamor_pixmap.c
@@ -774,8 +774,8 @@ _glamor_upload_bits_to_pixmap_texture(PixmapPtr pixmap, GLenum format,
             return FALSE;
         bits = glamor_color_convert_to_bits(bits, converted_bits, w, h,
                                             stride, no_alpha, revert, swap_rb);
-        free(converted_bits);
         if (bits == NULL) {
+            free(converted_bits);
             ErrorF("Failed to convert pixmap no_alpha %d,"
                    "revert mode %d, swap mode %d\n", no_alpha, revert, swap_rb);
             return FALSE;
commit 16a32c53f6e9ad1f3284d4596edfa33e9efb740e
Author: Alan Coopersmith <alan.coopersmith at oracle.com>
Date:   Thu Oct 9 05:42:09 2014 -0700

    If fork fails in System(), don't fallthrough to exec()
    
    In the unlikely event of a failure in creating processes, signal
    masks will fall from the panels above you.  Secure your mask before
    telling your child what to do, since it won't exist, and you will
    instead cause the server itself to be replaced by a shell running
    the target program.
    
    Found by Coverity #53397: Missing break in switch
    Execution falls through to the next case statement or default;
     this might indicate a common typo.
    In System: Missing break statement between cases in switch statement (CWE-484)
    
    Signed-off-by: Alan Coopersmith <alan.coopersmith at oracle.com>
    Reviewed-by: Matthieu Herrb <matthieu at herrb.eu>
    Signed-off-by: Keith Packard <keithp at keithp.com>

diff --git a/os/utils.c b/os/utils.c
index 80415c4..75769f1 100644
--- a/os/utils.c
+++ b/os/utils.c
@@ -1373,6 +1373,7 @@ System(const char *command)
     switch (pid = fork()) {
     case -1:                   /* error */
         p = -1;
+        break;
     case 0:                    /* child */
         if (setgid(getgid()) == -1)
             _exit(127);
commit 7e5bc49d1ed2c78c321da79bdbc99b90c5f95b38
Author: Alan Coopersmith <alan.coopersmith at oracle.com>
Date:   Thu Oct 9 05:42:08 2014 -0700

    Allocate enough room for both reset & flags attributes
    
    ctx_attribs had room for 3 pairs of attributes, but if both flags & reset
    attributes were being returned it was storing 4 pairs in the array.
    
    Found by Coverity #53442:  Out-of-bounds write
    This could cause an immediate crash or incorrect computations.
    In create_driver_context: Out-of-bounds write to a buffer (CWE-119)
    
    Signed-off-by: Alan Coopersmith <alan.coopersmith at oracle.com>
    Reviewed-by: Adam Jackson <ajax at redhat.com>
    Signed-off-by: Keith Packard <keithp at keithp.com>

diff --git a/glx/glxdri2.c b/glx/glxdri2.c
index c756bf5..5a8966f 100644
--- a/glx/glxdri2.c
+++ b/glx/glxdri2.c
@@ -475,7 +475,7 @@ create_driver_context(__GLXDRIcontext * context,
     context->driContext = NULL;
 
     if (screen->dri2->base.version >= 3) {
-        uint32_t ctx_attribs[3 * 2];
+        uint32_t ctx_attribs[4 * 2];
         unsigned num_ctx_attribs = 0;
         unsigned dri_err = 0;
         unsigned major_ver;
@@ -510,6 +510,8 @@ create_driver_context(__GLXDRIcontext * context,
                     __DRI_CTX_ATTRIB_RESET_STRATEGY;
                 ctx_attribs[num_ctx_attribs++] = reset;
             }
+
+            assert(num_ctx_attribs <= ARRAY_SIZE(ctx_attribs));
         }
 
         context->driContext =
commit cffd4e4a4ee615d8583eae78b35017e0d1bfa4f0
Author: Adam Jackson <ajax at redhat.com>
Date:   Thu Oct 9 09:58:06 2014 +0200

    mi: Mark the span blit routines as _X_COLD
    
    On gcc, __attribute__((cold)) means:
    
    - consider calls to the function to be unlikely for branch prediction
    - optimize the function for size
    - emit the function in a dedicated cold text section
    
    It's not worth deleting these routines even though there are no longer
    in-tree consumers, but we can at least keep them out of i$ at runtime.
    
    Signed-off-by: Adam Jackson <ajax at redhat.com>
    Reviewed-by: Keith Packard <keithp at keithp.com>
    Signed-off-by: Keith Packard <keithp at keithp.com>

diff --git a/mi/mibitblt.c b/mi/mibitblt.c
index 08bd1c5..114f72d 100644
--- a/mi/mibitblt.c
+++ b/mi/mibitblt.c
@@ -72,7 +72,7 @@ extern int ffs(int);
  *     set them in the destination with SetSpans
  * We let SetSpans worry about clipping to the destination.
  */
-RegionPtr
+_X_COLD RegionPtr
 miCopyArea(DrawablePtr pSrcDrawable,
            DrawablePtr pDstDrawable,
            GCPtr pGC,
@@ -261,8 +261,7 @@ miCopyArea(DrawablePtr pSrcDrawable,
  * This should be replaced with something more general.  mi shouldn't have to
  * care about such things as scanline padding et alia.
  */
-static
-MiBits *
+_X_COLD static MiBits *
 miGetPlane(DrawablePtr pDraw, int planeNum,     /* number of the bitPlane */
            int sx, int sy, int w, int h, MiBits * result)
 {
@@ -368,7 +367,7 @@ miGetPlane(DrawablePtr pDraw, int planeNum,     /* number of the bitPlane */
  * Note how the clipped out bits of the bitmap are always the background
  * color so that the stipple never causes FillRect to draw them.
  */
-static void
+_X_COLD static void
 miOpqStipDrawable(DrawablePtr pDraw, GCPtr pGC, RegionPtr prgnSrc,
                   MiBits * pbits, int srcx, int w, int h, int dstx, int dsty)
 {
@@ -510,7 +509,7 @@ miOpqStipDrawable(DrawablePtr pDraw, GCPtr pGC, RegionPtr prgnSrc,
  * build a source clip
  * Use the bitmap we've built up as a Stipple for the destination 
  */
-RegionPtr
+_X_COLD RegionPtr
 miCopyPlane(DrawablePtr pSrcDrawable,
             DrawablePtr pDstDrawable,
             GCPtr pGC,
@@ -599,7 +598,7 @@ miCopyPlane(DrawablePtr pSrcDrawable,
  * XY format:
  * get the single plane specified in planemask
  */
-void
+_X_COLD void
 miGetImage(DrawablePtr pDraw, int sx, int sy, int w, int h,
            unsigned int format, unsigned long planeMask, char *pDst)
 {
@@ -689,7 +688,7 @@ miGetImage(DrawablePtr pDraw, int sx, int sy, int w, int h,
  * ZPixmap format:
  *	This part is simple, just call SetSpans
  */
-void
+_X_COLD void
 miPutImage(DrawablePtr pDraw, GCPtr pGC, int depth,
            int x, int y, int w, int h, int leftPad, int format, char *pImage)
 {
diff --git a/mi/mifillrct.c b/mi/mifillrct.c
index 79c4057..faf6049 100644
--- a/mi/mifillrct.c
+++ b/mi/mifillrct.c
@@ -65,7 +65,7 @@ SOFTWARE.
  * then call FillSpans to fill each rectangle.  We let FillSpans worry about
  * clipping to the destination
  */
-void
+_X_COLD void
 miPolyFillRect(DrawablePtr pDrawable, GCPtr pGC, int nrectFill, /* number of rectangles to fill */
                xRectangle *prectInit    /* Pointer to first rectangle to fill */
     )
commit de55aafa8f6a9e0dec364bec920d6f91ef2b39f0
Merge: 462bf87 c79f824
Author: Keith Packard <keithp at keithp.com>
Date:   Thu Oct 23 17:28:24 2014 -0700

    Merge remote-tracking branch 'ajax/xwin'

commit 462bf87c4d1c2211dd49a5ce62d01ff84ff33970
Author: Adam Jackson <ajax at redhat.com>
Date:   Wed Oct 8 17:20:33 2014 +0200

    render: Always store client clip as a region
    
    This does have one semantic change.  FixesCreateRegionFromPicture used to
    throw BadImplementation if you tried to create a region from a picture
    with no client clip.  I changed that to BadMatch here since that more
    honestly describes what's going on.
    
    Signed-off-by: Adam Jackson <ajax at redhat.com>
    Reviewed-by: Keith Packard <keithp at keithp.com>
    Signed-off-by: Keith Packard <keithp at keithp.com>

diff --git a/fb/fbpict.c b/fb/fbpict.c
index 21baf89..f9c9917 100644
--- a/fb/fbpict.c
+++ b/fb/fbpict.c
@@ -326,7 +326,7 @@ create_bits_picture(PicturePtr pict, Bool has_clip, int *xoff, int *yoff)
      * only set the clip region for pictures with drawables
      */
     if (has_clip) {
-        if (pict->clientClipType != CT_NONE)
+        if (pict->clientClip)
             pixman_image_set_has_client_clip(image, TRUE);
 
         if (*xoff || *yoff)
diff --git a/render/mipict.c b/render/mipict.c
index 3959fc4..a725104 100644
--- a/render/mipict.c
+++ b/render/mipict.c
@@ -49,23 +49,9 @@ miDestroyPicture(PicturePtr pPicture)
 void
 miDestroyPictureClip(PicturePtr pPicture)
 {
-    switch (pPicture->clientClipType) {
-    case CT_NONE:
-        return;
-    case CT_PIXMAP:
-        (*pPicture->pDrawable->pScreen->
-         DestroyPixmap) ((PixmapPtr) (pPicture->clientClip));
-        break;
-    default:
-        /*
-         * we know we'll never have a list of rectangles, since ChangeClip
-         * immediately turns them into a region
-         */
+    if (pPicture->clientClip)
         RegionDestroy(pPicture->clientClip);
-        break;
-    }
     pPicture->clientClip = NULL;
-    pPicture->clientClipType = CT_NONE;
 }
 
 int
@@ -73,37 +59,31 @@ miChangePictureClip(PicturePtr pPicture, int type, void *value, int n)
 {
     ScreenPtr pScreen = pPicture->pDrawable->pScreen;
     PictureScreenPtr ps = GetPictureScreen(pScreen);
-    void *clientClip;
-    int clientClipType;
+    RegionPtr clientClip;
 
     switch (type) {
     case CT_PIXMAP:
         /* convert the pixmap to a region */
-        clientClip = (void *) BitmapToRegion(pScreen, (PixmapPtr) value);
+        clientClip = BitmapToRegion(pScreen, (PixmapPtr) value);
         if (!clientClip)
             return BadAlloc;
-        clientClipType = CT_REGION;
         (*pScreen->DestroyPixmap) ((PixmapPtr) value);
         break;
     case CT_REGION:
         clientClip = value;
-        clientClipType = CT_REGION;
         break;
     case CT_NONE:
         clientClip = 0;
-        clientClipType = CT_NONE;
         break;
     default:
-        clientClip = (void *) RegionFromRects(n, (xRectangle *) value, type);
+        clientClip = RegionFromRects(n, (xRectangle *) value, type);
         if (!clientClip)
             return BadAlloc;
-        clientClipType = CT_REGION;
         free(value);
         break;
     }
     (*ps->DestroyPictureClip) (pPicture);
     pPicture->clientClip = clientClip;
-    pPicture->clientClipType = clientClipType;
     pPicture->stateChanges |= CPClipMask;
     return Success;
 }
@@ -144,7 +124,7 @@ miValidatePicture(PicturePtr pPicture, Mask mask)
              * copying of regions.  (this wins especially if many clients clip
              * by children and have no client clip.)
              */
-            if (pPicture->clientClipType == CT_NONE) {
+            if (!pPicture->clientClip) {
                 if (freeCompClip)
                     RegionDestroy(pPicture->pCompositeClip);
                 pPicture->pCompositeClip = pregWin;
@@ -203,7 +183,7 @@ miValidatePicture(PicturePtr pPicture, Mask mask)
                 pPicture->pCompositeClip = RegionCreate(&pixbounds, 1);
             }
 
-            if (pPicture->clientClipType == CT_REGION) {
+            if (pPicture->clientClip) {
                 if (pDrawable->x || pDrawable->y) {
                     RegionTranslate(pPicture->clientClip,
                                     pDrawable->x + pPicture->clipOrigin.x,
@@ -284,7 +264,7 @@ miClipPictureReg(pixman_region16_t * pRegion,
 static inline Bool
 miClipPictureSrc(RegionPtr pRegion, PicturePtr pPicture, int dx, int dy)
 {
-    if (pPicture->clientClipType != CT_NONE) {
+    if (pPicture->clientClip) {
         Bool result;
 
         pixman_region_translate(pPicture->clientClip,
diff --git a/render/mirect.c b/render/mirect.c
index 4e76972..a36d1d6 100644
--- a/render/mirect.c
+++ b/render/mirect.c
@@ -54,7 +54,7 @@ miColorRects(PicturePtr pDst,
     tmpval[1].val = pixel;
     tmpval[2].val = pDst->subWindowMode;
     mask = GCFunction | GCForeground | GCSubwindowMode;
-    if (pClipPict->clientClipType == CT_REGION) {
+    if (pClipPict->clientClip) {
         tmpval[3].val = pDst->clipOrigin.x - xoff;
         tmpval[4].val = pDst->clipOrigin.y - yoff;
         mask |= GCClipXOrigin | GCClipYOrigin;
diff --git a/render/picture.c b/render/picture.c
index 58535d4..cd9bc74 100644
--- a/render/picture.c
+++ b/render/picture.c
@@ -731,7 +731,6 @@ SetPictureToDefaults(PicturePtr pPicture)
     pPicture->polyEdge = PolyEdgeSharp;
     pPicture->polyMode = PolyModePrecise;
     pPicture->freeCompClip = FALSE;
-    pPicture->clientClipType = CT_NONE;
     pPicture->componentAlpha = FALSE;
     pPicture->repeatType = RepeatNone;
 
diff --git a/render/picturestr.h b/render/picturestr.h
index 1278f62..177f87b 100644
--- a/render/picturestr.h
+++ b/render/picturestr.h
@@ -132,7 +132,6 @@ typedef struct _Picture {
     unsigned int polyEdge:1;
     unsigned int polyMode:1;
     unsigned int freeCompClip:1;
-    unsigned int clientClipType:2;
     unsigned int componentAlpha:1;
     unsigned int repeatType:2;
     unsigned int filter:3;
@@ -145,7 +144,7 @@ typedef struct _Picture {
     DDXPointRec alphaOrigin;
 
     DDXPointRec clipOrigin;
-    void *clientClip;
+    RegionPtr clientClip;
 
     unsigned long serialNumber;
 
diff --git a/xfixes/region.c b/xfixes/region.c
index f9de525..4cfeee1 100644
--- a/xfixes/region.c
+++ b/xfixes/region.c
@@ -272,20 +272,12 @@ ProcXFixesCreateRegionFromPicture(ClientPtr client)
     if (!pPicture->pDrawable)
         return RenderErrBase + BadPicture;
 
-    switch (pPicture->clientClipType) {
-    case CT_PIXMAP:
-        pRegion = BitmapToRegion(pPicture->pDrawable->pScreen,
-                                 (PixmapPtr) pPicture->clientClip);
-        if (!pRegion)
-            return BadAlloc;
-        break;
-    case CT_REGION:
+    if (pPicture->clientClip) {
         pRegion = XFixesRegionCopy((RegionPtr) pPicture->clientClip);
         if (!pRegion)
             return BadAlloc;
-        break;
-    default:
-        return BadImplementation;       /* assume sane server bits */
+    } else {
+        return BadMatch;
     }
 
     if (!AddResource(stuff->region, RegionResType, (void *) pRegion))
commit 3f4edd2e3ff84c38df563b09c2e8c32404db38f7
Author: Adam Jackson <ajax at redhat.com>
Date:   Wed Oct 8 17:18:32 2014 +0200

    xinerama: Fix access mode in GetImage's drawable lookup
    
    Signed-off-by: Adam Jackson <ajax at redhat.com>
    Reviewed-by: Julien Cristau <jcristau at debian.org>
    Signed-off-by: Keith Packard <keithp at keithp.com>

diff --git a/Xext/panoramiXprocs.c b/Xext/panoramiXprocs.c
index aa3859f..0122ff3 100644
--- a/Xext/panoramiXprocs.c
+++ b/Xext/panoramiXprocs.c
@@ -1908,7 +1908,7 @@ PanoramiXGetImage(ClientPtr client)
     }
 
     rc = dixLookupResourceByClass((void **) &draw, stuff->drawable,
-                                  XRC_DRAWABLE, client, DixWriteAccess);
+                                  XRC_DRAWABLE, client, DixReadAccess);
     if (rc != Success)
         return (rc == BadValue) ? BadDrawable : rc;
 
commit 942e18e17e334d7a25f8c1dcc6f5c3711eeb6a7d
Author: William ML Leslie <william.leslie.ttg at gmail.com>
Date:   Wed May 21 10:28:52 2014 +1000

    Xephyr: option to disable grabbing the host
    
    This patch makes it possible to use C-S key combinations
    within Xephyr without losing access to the host window manager's
    commands.
    
    Signed-off-by: Keith Packard <keithp at keithp.com>
    Reviewed-by: Eric Anholt <eric at anholt.net>

diff --git a/hw/kdrive/ephyr/ephyr.c b/hw/kdrive/ephyr/ephyr.c
index 8b88f3e..5761710 100644
--- a/hw/kdrive/ephyr/ephyr.c
+++ b/hw/kdrive/ephyr/ephyr.c
@@ -68,6 +68,7 @@ typedef struct _EphyrInputPrivate {
 
 Bool EphyrWantGrayScale = 0;
 Bool EphyrWantResize = 0;
+Bool EphyrWantNoHostGrab = 0;
 
 Bool
 host_has_extension(xcb_extension_t *extension)
@@ -649,7 +650,11 @@ ephyrInitScreen(ScreenPtr pScreen)
 
     EPHYR_LOG("pScreen->myNum:%d\n", pScreen->myNum);
     hostx_set_screen_number(screen, pScreen->myNum);
-    hostx_set_win_title(screen, "(ctrl+shift grabs mouse and keyboard)");
+    if (EphyrWantNoHostGrab) {
+        hostx_set_win_title(screen, "xephyr");
+    } else {
+        hostx_set_win_title(screen, "(ctrl+shift grabs mouse and keyboard)");
+    }
     pScreen->CreateColormap = ephyrCreateColormap;
 
 #ifdef XV
@@ -1092,12 +1097,13 @@ ephyrProcessKeyRelease(xcb_generic_event_t *xev)
     if (!keysyms)
         keysyms = xcb_key_symbols_alloc(conn);
 
-    if (((xcb_key_symbols_get_keysym(keysyms, key->detail, 0) == XK_Shift_L
+    if (!EphyrWantNoHostGrab &&
+        (((xcb_key_symbols_get_keysym(keysyms, key->detail, 0) == XK_Shift_L
           || xcb_key_symbols_get_keysym(keysyms, key->detail, 0) == XK_Shift_R)
          && (key->state & XCB_MOD_MASK_CONTROL)) ||
         ((xcb_key_symbols_get_keysym(keysyms, key->detail, 0) == XK_Control_L
           || xcb_key_symbols_get_keysym(keysyms, key->detail, 0) == XK_Control_R)
-         && (key->state & XCB_MOD_MASK_SHIFT))) {
+         && (key->state & XCB_MOD_MASK_SHIFT)))) {
         KdScreenInfo *screen = screen_from_window(key->event);
         EphyrScrPriv *scrpriv = screen->driver;
 
diff --git a/hw/kdrive/ephyr/ephyrinit.c b/hw/kdrive/ephyr/ephyrinit.c
index 3693531..bcfb750 100644
--- a/hw/kdrive/ephyr/ephyrinit.c
+++ b/hw/kdrive/ephyr/ephyrinit.c
@@ -33,6 +33,7 @@
 extern Window EphyrPreExistingHostWin;
 extern Bool EphyrWantGrayScale;
 extern Bool EphyrWantResize;
+extern Bool EphyrWantNoHostGrab;
 extern Bool kdHasPointer;
 extern Bool kdHasKbd;
 extern Bool ephyr_glamor, ephyr_glamor_gles2;
@@ -153,6 +154,7 @@ ddxUseMsg(void)
     ErrorF("-name [name]         define the name in the WM_CLASS property\n");
     ErrorF
         ("-title [title]       set the window title in the WM_NAME property\n");
+    ErrorF("-no-host-grab        Disable grabbing the keyboard and mouse.\n");
     ErrorF("\n");
 }
 
@@ -360,6 +362,10 @@ ddxProcessArgument(int argc, char **argv, int i)
         return 2;
     }
     /* end Xnest compat */
+    else if (!strcmp(argv[i], "-no-host-grab")) {
+        EphyrWantNoHostGrab = 1;
+        return 2;
+    }
 
     return KdProcessArgument(argc, argv, i);
 }
diff --git a/hw/kdrive/ephyr/man/Xephyr.man b/hw/kdrive/ephyr/man/Xephyr.man
index f14f6c8..c043790 100644
--- a/hw/kdrive/ephyr/man/Xephyr.man
+++ b/hw/kdrive/ephyr/man/Xephyr.man
@@ -63,6 +63,9 @@ improvement is negligible.
 .B -resizeable
 Allow the Xephyr window to be resized, even if not embedded into a parent
 window. By default, the Xephyr window has a fixed size.
+.TP 8
+.B -no-host-grab
+Disable grabbing the keyboard and mouse.
 .SH "SIGNALS"
 Send a SIGUSR1 to the server (e.g. pkill -USR1 Xephyr) to
 toggle the debugging mode.
commit 61a292adf45405641de1c522a04c148e0a152acd
Author: Keith Packard <keithp at keithp.com>
Date:   Thu Oct 9 15:17:17 2014 +0200

    glx: check return from __glXGetAnswerBuffer
    
    This function can return NULL; make sure every caller tests for that.
    
    Reviewed-by: Adam Jackson <ajax at redhat.com>
    Signed-off-by: Keith Packard <keithp at keithp.com>

diff --git a/glx/indirect_dispatch.c b/glx/indirect_dispatch.c
index 329b2e6..f6cabef 100644
--- a/glx/indirect_dispatch.c
+++ b/glx/indirect_dispatch.c
@@ -2464,6 +2464,9 @@ __glXDisp_AreTexturesResident(__GLXclientState * cl, GLbyte * pc)
         GLboolean answerBuffer[200];
         GLboolean *residences =
             __glXGetAnswerBuffer(cl, n, answerBuffer, sizeof(answerBuffer), 1);
+
+        if (residences == NULL)
+            return BadAlloc;
         retval =
             glAreTexturesResident(n, (const GLuint *) (pc + 4), residences);
         __glXSendReply(cl->client, residences, n, 1, GL_TRUE, retval);
@@ -2488,6 +2491,9 @@ __glXDisp_AreTexturesResidentEXT(__GLXclientState * cl, GLbyte * pc)
         GLboolean answerBuffer[200];
         GLboolean *residences =
             __glXGetAnswerBuffer(cl, n, answerBuffer, sizeof(answerBuffer), 1);
+
+        if (residences == NULL)
+            return BadAlloc;
         retval =
             glAreTexturesResident(n, (const GLuint *) (pc + 4), residences);
         __glXSendReply(cl->client, residences, n, 1, GL_TRUE, retval);
@@ -2593,6 +2599,9 @@ __glXDisp_GenTextures(__GLXclientState * cl, GLbyte * pc)
         GLuint *textures =
             __glXGetAnswerBuffer(cl, n * 4, answerBuffer, sizeof(answerBuffer),
                                  4);
+
+        if (textures == NULL)
+            return BadAlloc;
         glGenTextures(n, textures);
         __glXSendReply(cl->client, textures, n, 4, GL_TRUE, 0);
         error = Success;
@@ -2616,6 +2625,9 @@ __glXDisp_GenTexturesEXT(__GLXclientState * cl, GLbyte * pc)
         GLuint *textures =
             __glXGetAnswerBuffer(cl, n * 4, answerBuffer, sizeof(answerBuffer),
                                  4);
+
+        if (textures == NULL)
+            return BadAlloc;
         glGenTextures(n, textures);
         __glXSendReply(cl->client, textures, n, 4, GL_TRUE, 0);
         error = Success;
@@ -3883,6 +3895,9 @@ __glXDisp_GenQueries(__GLXclientState * cl, GLbyte * pc)
         GLuint *ids =
             __glXGetAnswerBuffer(cl, n * 4, answerBuffer, sizeof(answerBuffer),
                                  4);
+
+        if (ids == NULL)
+            return BadAlloc;
         GenQueries(n, ids);
         __glXSendReply(cl->client, ids, n, 4, GL_TRUE, 0);
         error = Success;
@@ -4253,6 +4268,9 @@ __glXDisp_GenProgramsARB(__GLXclientState * cl, GLbyte * pc)
         GLuint *programs =
             __glXGetAnswerBuffer(cl, n * 4, answerBuffer, sizeof(answerBuffer),
                                  4);
+
+        if (programs == NULL)
+            return BadAlloc;
         GenProgramsARB(n, programs);
         __glXSendReply(cl->client, programs, n, 4, GL_TRUE, 0);
         error = Success;
@@ -4630,6 +4648,10 @@ __glXDisp_GenFramebuffers(__GLXclientState * cl, GLbyte * pc)
         GLuint *framebuffers =
             __glXGetAnswerBuffer(cl, n * 4, answerBuffer, sizeof(answerBuffer),
                                  4);
+
+        if (framebuffers == NULL)
+            return BadAlloc;
+
         GenFramebuffers(n, framebuffers);
         __glXSendReply(cl->client, framebuffers, n, 4, GL_TRUE, 0);
         error = Success;
@@ -4655,6 +4677,9 @@ __glXDisp_GenRenderbuffers(__GLXclientState * cl, GLbyte * pc)
         GLuint *renderbuffers =
             __glXGetAnswerBuffer(cl, n * 4, answerBuffer, sizeof(answerBuffer),
                                  4);
+
+        if (renderbuffers == NULL)
+            return BadAlloc;
         GenRenderbuffers(n, renderbuffers);
         __glXSendReply(cl->client, renderbuffers, n, 4, GL_TRUE, 0);
         error = Success;
diff --git a/glx/indirect_dispatch_swap.c b/glx/indirect_dispatch_swap.c
index 647d0c9..c0bb64d 100644
--- a/glx/indirect_dispatch_swap.c
+++ b/glx/indirect_dispatch_swap.c
@@ -2731,6 +2731,9 @@ __glXDispSwap_AreTexturesResident(__GLXclientState * cl, GLbyte * pc)
         GLboolean answerBuffer[200];
         GLboolean *residences =
             __glXGetAnswerBuffer(cl, n, answerBuffer, sizeof(answerBuffer), 1);
+
+        if (residences == NULL)
+            return BadAlloc;
         retval =
             glAreTexturesResident(n,
                                   (const GLuint *)
@@ -2759,6 +2762,9 @@ __glXDispSwap_AreTexturesResidentEXT(__GLXclientState * cl, GLbyte * pc)
         GLboolean answerBuffer[200];
         GLboolean *residences =
             __glXGetAnswerBuffer(cl, n, answerBuffer, sizeof(answerBuffer), 1);
+
+        if (residences == NULL)
+            return BadAlloc;
         retval =
             glAreTexturesResident(n,
                                   (const GLuint *)
@@ -2878,6 +2884,9 @@ __glXDispSwap_GenTextures(__GLXclientState * cl, GLbyte * pc)
         GLuint *textures =
             __glXGetAnswerBuffer(cl, n * 4, answerBuffer, sizeof(answerBuffer),
                                  4);
+
+        if (textures == NULL)
+            return BadAlloc;
         glGenTextures(n, textures);
         (void) bswap_32_array((uint32_t *) textures, n);
         __glXSendReplySwap(cl->client, textures, n, 4, GL_TRUE, 0);
@@ -2903,6 +2912,9 @@ __glXDispSwap_GenTexturesEXT(__GLXclientState * cl, GLbyte * pc)
         GLuint *textures =
             __glXGetAnswerBuffer(cl, n * 4, answerBuffer, sizeof(answerBuffer),
                                  4);
+
+        if (textures == NULL)
+            return BadAlloc;
         glGenTextures(n, textures);
         (void) bswap_32_array((uint32_t *) textures, n);
         __glXSendReplySwap(cl->client, textures, n, 4, GL_TRUE, 0);
@@ -4290,6 +4302,9 @@ __glXDispSwap_GenQueries(__GLXclientState * cl, GLbyte * pc)
         GLuint *ids =
             __glXGetAnswerBuffer(cl, n * 4, answerBuffer, sizeof(answerBuffer),
                                  4);
+        if (ids == NULL)
+            return BadAlloc;
+
         GenQueries(n, ids);
         (void) bswap_32_array((uint32_t *) ids, n);
         __glXSendReplySwap(cl->client, ids, n, 4, GL_TRUE, 0);
@@ -4697,6 +4712,9 @@ __glXDispSwap_GenProgramsARB(__GLXclientState * cl, GLbyte * pc)
         GLuint *programs =
             __glXGetAnswerBuffer(cl, n * 4, answerBuffer, sizeof(answerBuffer),
                                  4);
+        if (programs == NULL)
+            return BadAlloc;
+
         GenProgramsARB(n, programs);
         (void) bswap_32_array((uint32_t *) programs, n);
         __glXSendReplySwap(cl->client, programs, n, 4, GL_TRUE, 0);
@@ -5122,6 +5140,10 @@ __glXDispSwap_GenFramebuffers(__GLXclientState * cl, GLbyte * pc)
         GLuint *framebuffers =
             __glXGetAnswerBuffer(cl, n * 4, answerBuffer, sizeof(answerBuffer),
                                  4);
+
+        if (framebuffers == NULL)
+            return BadAlloc;
+
         GenFramebuffers(n, framebuffers);
         (void) bswap_32_array((uint32_t *) framebuffers, n);
         __glXSendReplySwap(cl->client, framebuffers, n, 4, GL_TRUE, 0);
@@ -5149,6 +5171,10 @@ __glXDispSwap_GenRenderbuffers(__GLXclientState * cl, GLbyte * pc)
         GLuint *renderbuffers =
             __glXGetAnswerBuffer(cl, n * 4, answerBuffer, sizeof(answerBuffer),
                                  4);
+
+        if (renderbuffers == NULL)
+            return BadAlloc;
+
         GenRenderbuffers(n, renderbuffers);
         (void) bswap_32_array((uint32_t *) renderbuffers, n);
         __glXSendReplySwap(cl->client, renderbuffers, n, 4, GL_TRUE, 0);
commit d634ecdf82f244ff8ce75d351fc175792d254e5c
Merge: 6622f0c 7ebf480
Author: Keith Packard <keithp at keithp.com>
Date:   Thu Oct 9 15:08:31 2014 +0200

    Merge remote-tracking branch 'ajax/dead-code'

commit 6622f0cb1761501f3287ffa8d3cbca3fd30f9f0c
Merge: f12e7f4 5ecd786
Author: Keith Packard <keithp at keithp.com>
Date:   Thu Oct 9 15:05:26 2014 +0200

    Merge remote-tracking branch 'ajax/mi-cleanup'

commit f12e7f4980416b74988052a04d0f2487b2c4a7e9
Merge: da88772 aaf5e2d
Author: Keith Packard <keithp at keithp.com>
Date:   Thu Oct 9 14:21:19 2014 +0200

    Merge remote-tracking branch 'anholt/modesetting-glamor'

commit da887726eeaece0396962dd3912578d3372881b1
Author: Alan Coopersmith <alan.coopersmith at oracle.com>
Date:   Sun Sep 21 09:49:06 2014 -0700

    Use unique display name for each xi2 test program [v3]
    
    make -j 8 check was sporadically failing in different xi2 tests.
    After adding the asserts in the previous commit to catch xkb failure
    it became easier to catch the failures and see that multiple tests
    were running at once trying to write to /tmp/server-(null).xkm and
    then delete it, and interfering with each other.
    
    Putting a unique string into the display variable let them each write
    to their own file and not interfere with others.
    
    v2: Fix Linux bits:
    
      Add #include <errno.h> to get a declaration of
      program_invocation_name on Linux.
    
      Use only the last portion of the pathname so that the resulting
      display name doesn't contain any slashes.
    
    v3: use program_invocation_short_name on Linux
    
      This is the same as program_invocation_name, except is has
      stripped off any path prefix.
    
    Signed-off-by: Alan Coopersmith <alan.coopersmith at oracle.com>
    Reviewed-by: Peter Hutterer <peter.hutterer at who-t.net>
    Reviewed-by: Adam Jackson <ajax at redhat.com>
    Signed-off-by: Keith Packard <keithp at keithp.com>

diff --git a/configure.ac b/configure.ac
index 30c0c5c..c697188 100644
--- a/configure.ac
+++ b/configure.ac
@@ -217,10 +217,12 @@ AC_SUBST(DLOPEN_LIBS)
 
 dnl Checks for library functions.
 AC_CHECK_FUNCS([backtrace ffs geteuid getuid issetugid getresuid \
-	getdtablesize getifaddrs getpeereid getpeerucred getzoneid \
+	getdtablesize getifaddrs getpeereid getpeerucred getprogname getzoneid \
 	mmap seteuid shmctl64 strncasecmp vasprintf vsnprintf walkcontext])
 AC_REPLACE_FUNCS([strcasecmp strcasestr strlcat strlcpy strndup])
 
+AC_CHECK_DECLS([program_invocation_short_name], [], [], [[#include <errno.h>]])
+
 dnl Find the math libary, then check for cbrt function in it.
 AC_CHECK_LIB(m, sqrt)
 AC_CHECK_FUNCS([cbrt])
diff --git a/include/dix-config.h.in b/include/dix-config.h.in
index f170c1c..1aa77a5 100644
--- a/include/dix-config.h.in
+++ b/include/dix-config.h.in
@@ -72,6 +72,10 @@
 /* Define to 1 if you have the <dbm.h> header file. */
 #undef HAVE_DBM_H
 
+/* Define to 1 if you have the declaration of `program_invocation_short_name', and
+   to 0 if you don't. */
+#undef HAVE_DECL_PROGRAM_INVOCATION_SHORT_NAME
+
 /* Define to 1 if you have the <dirent.h> header file, and it defines `DIR'.
    */
 #undef HAVE_DIRENT_H
@@ -100,6 +104,9 @@
 /* Define to 1 if you have the `getpeerucred' function. */
 #undef HAVE_GETPEERUCRED
 
+/* Define to 1 if you have the `getprogname' function. */
+#undef HAVE_GETPROGNAME
+
 /* Define to 1 if you have the `getzoneid' function. */
 #undef HAVE_GETZONEID
 
diff --git a/test/xi2/protocol-common.c b/test/xi2/protocol-common.c
index 64a5777..9265ba3 100644
--- a/test/xi2/protocol-common.c
+++ b/test/xi2/protocol-common.c
@@ -25,6 +25,7 @@
 #include <dix-config.h>
 #endif
 
+#include <errno.h>
 #include <stdint.h>
 #include "extinit.h"            /* for XInputExtensionInit */
 #include "exglobals.h"
@@ -139,6 +140,17 @@ init_devices(void)
     struct devices local_devices;
     int ret;
 
+    /*
+     * Put a unique name in display pointer so that when tests are run in
+     * parallel, their xkbcomp outputs to /tmp/server-<display>.xkm don't
+     * stomp on each other.
+     */
+#ifdef HAVE_GETPROGNAME
+    display = getprogname();
+#elif HAVE_DECL_PROGRAM_INVOCATION_SHORT_NAME
+    display = program_invocation_short_name;
+#endif
+
     client = init_client(0, NULL);
 
     AllocDevicePair(&client, "Virtual core", &local_devices.vcp, &local_devices.vck,
commit 5ecd7866f7587d620f000e802a262c7cd4b9df33
Author: Adam Jackson <ajax at redhat.com>
Date:   Thu Sep 11 10:11:39 2014 -0400

    misc: Fold together some redundant conditionals
    
    Reviewed-by: Julien Cristau <jcristau at debian.org>
    Signed-off-by: Adam Jackson <ajax at redhat.com>

diff --git a/dix/window.c b/dix/window.c
index 7a2866a..d43ef03 100644
--- a/dix/window.c
+++ b/dix/window.c
@@ -2059,10 +2059,10 @@ ReflectStackChange(WindowPtr pWin, WindowPtr pSib, VTKind kind)
         if (anyMarked) {
             (*pScreen->ValidateTree) (pLayerWin->parent, pFirstChange, kind);
             (*pScreen->HandleExposures) (pLayerWin->parent);
+            if (pWin->drawable.pScreen->PostValidateTree)
+                (*pScreen->PostValidateTree) (pLayerWin->parent, pFirstChange,
+                                              kind);
         }
-        if (anyMarked && pWin->drawable.pScreen->PostValidateTree)
-            (*pScreen->PostValidateTree) (pLayerWin->parent, pFirstChange,
-                                          kind);
     }
     if (pWin->realized)
         WindowsRestructured();
@@ -2576,10 +2576,10 @@ MapWindow(WindowPtr pWin, ClientPtr client)
             if (anyMarked) {
                 (*pScreen->ValidateTree) (pLayerWin->parent, pLayerWin, VTMap);
                 (*pScreen->HandleExposures) (pLayerWin->parent);
+                if (pScreen->PostValidateTree)
+                    (*pScreen->PostValidateTree) (pLayerWin->parent, pLayerWin,
+                                                  VTMap);
             }
-            if (anyMarked && pScreen->PostValidateTree)
-                (*pScreen->PostValidateTree) (pLayerWin->parent, pLayerWin,
-                                              VTMap);
         }
         WindowsRestructured();
     }
@@ -2657,10 +2657,10 @@ MapSubwindows(WindowPtr pParent, ClientPtr client)
         if (anyMarked) {
             (*pScreen->ValidateTree) (pLayerWin->parent, pFirstMapped, VTMap);
             (*pScreen->HandleExposures) (pLayerWin->parent);
+            if (pScreen->PostValidateTree)
+                (*pScreen->PostValidateTree) (pLayerWin->parent, pFirstMapped,
+                                              VTMap);
         }
-        if (anyMarked && pScreen->PostValidateTree)
-            (*pScreen->PostValidateTree) (pLayerWin->parent, pFirstMapped,
-                                          VTMap);
         WindowsRestructured();
     }
 }
@@ -2754,9 +2754,9 @@ UnmapWindow(WindowPtr pWin, Bool fromConfigure)
         if (!fromConfigure) {
             (*pScreen->ValidateTree) (pLayerWin->parent, pWin, VTUnmap);
             (*pScreen->HandleExposures) (pLayerWin->parent);
+            if (pScreen->PostValidateTree)
+                (*pScreen->PostValidateTree) (pLayerWin->parent, pWin, VTUnmap);
         }
-        if (!fromConfigure && pScreen->PostValidateTree)
-            (*pScreen->PostValidateTree) (pLayerWin->parent, pWin, VTUnmap);
     }
     if (wasRealized && !fromConfigure) {
         WindowsRestructured();
@@ -2824,9 +2824,10 @@ UnmapSubwindows(WindowPtr pWin)
             }
             (*pScreen->ValidateTree) (pLayerWin->parent, pHead, VTUnmap);
             (*pScreen->HandleExposures) (pLayerWin->parent);
+            if (pScreen->PostValidateTree)
+                (*pScreen->PostValidateTree) (pLayerWin->parent, pHead,
+                                              VTUnmap);
         }
-        if (anyMarked && pScreen->PostValidateTree)
-            (*pScreen->PostValidateTree) (pLayerWin->parent, pHead, VTUnmap);
     }
     if (wasRealized) {
         WindowsRestructured();
@@ -3592,15 +3593,12 @@ SetRootClip(ScreenPtr pScreen, Bool enable)
             anyMarked = TRUE;
         }
 
-        if (anyMarked)
+        if (anyMarked) {
             (*pScreen->ValidateTree) (pWin, NullWindow, VTOther);
-    }
-
-    if (WasViewable) {
-        if (anyMarked)
             (*pScreen->HandleExposures) (pWin);
-        if (anyMarked && pScreen->PostValidateTree)
-            (*pScreen->PostValidateTree) (pWin, NullWindow, VTOther);
+            if (pScreen->PostValidateTree)
+                (*pScreen->PostValidateTree) (pWin, NullWindow, VTOther);
+        }
     }
     if (pWin->realized)
         WindowsRestructured();
diff --git a/mi/mioverlay.c b/mi/mioverlay.c
index 2ad6bc0..eb8dda1 100644
--- a/mi/mioverlay.c
+++ b/mi/mioverlay.c
@@ -1464,11 +1464,7 @@ miOverlaySetShape(WindowPtr pWin, int kind)
 
         if (WasViewable) {
             (*pScreen->MarkOverlappedWindows) (pWin, pWin, NULL);
-
             (*pScreen->ValidateTree) (pWin->parent, NullWindow, VTOther);
-        }
-
-        if (WasViewable) {
             (*pScreen->HandleExposures) (pWin->parent);
             if (pScreen->PostValidateTree)
                 (*pScreen->PostValidateTree) (pWin->parent, NullWindow,
diff --git a/mi/miwindow.c b/mi/miwindow.c
index cfe085a..0cf5046 100644
--- a/mi/miwindow.c
+++ b/mi/miwindow.c
@@ -292,9 +292,9 @@ miMoveWindow(WindowPtr pWin, int x, int y, WindowPtr pNextSib, VTKind kind)
             RegionDestroy(oldRegion);
             /* XXX need to retile border if ParentRelative origin */
             (*pScreen->HandleExposures) (pLayerWin->parent);
+            if (pScreen->PostValidateTree)
+                (*pScreen->PostValidateTree) (pLayerWin->parent, NULL, kind);
         }
-        if (anyMarked && pScreen->PostValidateTree)
-            (*pScreen->PostValidateTree) (pLayerWin->parent, NullWindow, kind);
     }
     if (pWin->realized)
         WindowsRestructured();
@@ -607,11 +607,12 @@ miResizeWindow(WindowPtr pWin, int x, int y, unsigned int w, unsigned int h,
         RegionDestroy(pRegion);
         if (destClip)
             RegionDestroy(destClip);
-        if (anyMarked)
+        if (anyMarked) {
             (*pScreen->HandleExposures) (pLayerWin->parent);
-        if (anyMarked && pScreen->PostValidateTree)
-            (*pScreen->PostValidateTree) (pLayerWin->parent, pFirstChange,
-                                          VTOther);
+            if (pScreen->PostValidateTree)
+                (*pScreen->PostValidateTree) (pLayerWin->parent, pFirstChange,
+                                              VTOther);
+        }
     }
     if (pWin->realized)
         WindowsRestructured();
@@ -663,17 +664,14 @@ miSetShape(WindowPtr pWin, int kind)
         if (WasViewable) {
             anyMarked |= (*pScreen->MarkOverlappedWindows) (pWin, pWin, NULL);
 
-            if (anyMarked)
+            if (anyMarked) {
                 (*pScreen->ValidateTree) (pLayerWin->parent, NullWindow,
                                           VTOther);
-        }
-
-        if (WasViewable) {
-            if (anyMarked)
                 (*pScreen->HandleExposures) (pLayerWin->parent);
-            if (anyMarked && pScreen->PostValidateTree)
-                (*pScreen->PostValidateTree) (pLayerWin->parent, NullWindow,
-                                              VTOther);
+                if (pScreen->PostValidateTree)
+                    (*pScreen->PostValidateTree) (pLayerWin->parent, NULL,
+                                                  VTOther);
+            }
         }
     }
     if (pWin->realized)
@@ -725,10 +723,10 @@ miChangeBorderWidth(WindowPtr pWin, unsigned int width)
         if (anyMarked) {
             (*pScreen->ValidateTree) (pLayerWin->parent, pLayerWin, VTOther);
             (*pScreen->HandleExposures) (pLayerWin->parent);
+            if (pScreen->PostValidateTree)
+                (*pScreen->PostValidateTree) (pLayerWin->parent, pLayerWin,
+                                              VTOther);
         }
-        if (anyMarked && pScreen->PostValidateTree)
-            (*pScreen->PostValidateTree) (pLayerWin->parent, pLayerWin,
-                                          VTOther);
     }
     if (pWin->realized)
         WindowsRestructured();
commit 5b07f1db6de9f08f757206454da03ee0ae872bfc
Author: Adam Jackson <ajax at redhat.com>
Date:   Thu Sep 18 16:05:40 2014 -0400

    fb: fb{Map,Unmap}Window -> fb{Realize,Unrealize}Window
    
    Make the function names match the screen slot name.
    
    Reviewed-by: Julien Cristau <jcristau at debian.org>
    Signed-off-by: Adam Jackson <ajax at redhat.com>

diff --git a/fb/fb.h b/fb/fb.h
index 9057767..d176bb3 100644
--- a/fb/fb.h
+++ b/fb/fb.h
@@ -1621,13 +1621,13 @@ extern _X_EXPORT Bool
  fbDestroyWindow(WindowPtr pWin);
 
 extern _X_EXPORT Bool
- fbMapWindow(WindowPtr pWindow);
+ fbRealizeWindow(WindowPtr pWindow);
 
 extern _X_EXPORT Bool
  fbPositionWindow(WindowPtr pWin, int x, int y);
 
 extern _X_EXPORT Bool
- fbUnmapWindow(WindowPtr pWindow);
+ fbUnrealizeWindow(WindowPtr pWindow);
 
 extern _X_EXPORT void
 
diff --git a/fb/fbscreen.c b/fb/fbscreen.c
index 0d4d87f..71bcc5d 100644
--- a/fb/fbscreen.c
+++ b/fb/fbscreen.c
@@ -110,8 +110,8 @@ fbSetupScreen(ScreenPtr pScreen, void *pbits, /* pointer to screen bitmap */
     pScreen->DestroyWindow = fbDestroyWindow;
     pScreen->PositionWindow = fbPositionWindow;
     pScreen->ChangeWindowAttributes = fbChangeWindowAttributes;
-    pScreen->RealizeWindow = fbMapWindow;
-    pScreen->UnrealizeWindow = fbUnmapWindow;
+    pScreen->RealizeWindow = fbRealizeWindow;
+    pScreen->UnrealizeWindow = fbUnrealizeWindow;
     pScreen->CopyWindow = fbCopyWindow;
     pScreen->CreatePixmap = fbCreatePixmap;
     pScreen->DestroyPixmap = fbDestroyPixmap;
diff --git a/fb/fbwindow.c b/fb/fbwindow.c
index c90175f..7a5fac8 100644
--- a/fb/fbwindow.c
+++ b/fb/fbwindow.c
@@ -46,7 +46,7 @@ fbDestroyWindow(WindowPtr pWin)
 }
 
 Bool
-fbMapWindow(WindowPtr pWindow)
+fbRealizeWindow(WindowPtr pWindow)
 {
     return TRUE;
 }
@@ -58,7 +58,7 @@ fbPositionWindow(WindowPtr pWin, int x, int y)
 }
 
 Bool
-fbUnmapWindow(WindowPtr pWindow)
+fbUnrealizeWindow(WindowPtr pWindow)
 {
     return TRUE;
 }
diff --git a/fb/wfbrename.h b/fb/wfbrename.h
index 54d00d0..749c6d0 100644
--- a/fb/wfbrename.h
+++ b/fb/wfbrename.h
@@ -88,7 +88,6 @@
 #define fbInstallColormap wfbInstallColormap
 #define fbLaneTable wfbLaneTable
 #define fbListInstalledColormaps wfbListInstalledColormaps
-#define fbMapWindow wfbMapWindow
 #define FbMergeRopBits wFbMergeRopBits
 #define fbOddStipple wfbOddStipple
 #define fbOddTile wfbOddTile
@@ -134,6 +133,7 @@
 #define fbQueryBestSize wfbQueryBestSize
 #define fbRasterizeTrapezoid wfbRasterizeTrapezoid
 #define fbRealizeFont wfbRealizeFont
+#define fbRealizeWindow wfbRealizeWindow
 #define fbReduceRasterOp wfbReduceRasterOp
 #define fbReplicatePixel wfbReplicatePixel
 #define fbResolveColor wfbResolveColor
@@ -160,7 +160,7 @@
 #define fbTrapezoids wfbTrapezoids
 #define fbTriangles wfbTriangles
 #define fbUninstallColormap wfbUninstallColormap
-#define fbUnmapWindow wfbUnmapWindow
+#define fbUnrealizeWindow wfbUnrealizeWindow
 #define fbUnrealizeFont wfbUnrealizeFont
 #define fbValidateGC wfbValidateGC
 #define fbWinPrivateKeyRec wfbWinPrivateKeyRec
commit 9ed83a694b6492c9db226b115ed282cb127e798e
Author: Adam Jackson <ajax at redhat.com>
Date:   Thu Sep 18 15:36:57 2014 -0400

    mi: miSlideAndSizeWindow -> miResizeWindow
    
    Make the function name match the screen slot name.
    
    Reviewed-by: Julien Cristau <jcristau at debian.org>
    Signed-off-by: Adam Jackson <ajax at redhat.com>

diff --git a/mi/mi.h b/mi/mi.h
index 8cb3ce7..5a455c9 100644
--- a/mi/mi.h
+++ b/mi/mi.h
@@ -470,12 +470,12 @@ extern _X_EXPORT void miMoveWindow(WindowPtr /*pWin */ ,
                                    VTKind       /*kind */
     );
 
-extern _X_EXPORT void miSlideAndSizeWindow(WindowPtr /*pWin */ ,
-                                           int /*x */ ,
-                                           int /*y */ ,
-                                           unsigned int /*w */ ,
-                                           unsigned int /*h */ ,
-                                           WindowPtr    /*pSib */
+extern _X_EXPORT void miResizeWindow(WindowPtr /*pWin */ ,
+                                     int /*x */ ,
+                                     int /*y */ ,
+                                     unsigned int /*w */ ,
+                                     unsigned int /*h */ ,
+                                     WindowPtr    /*pSib */
     );
 
 extern _X_EXPORT WindowPtr miGetLayerWindow(WindowPtr   /*pWin */
diff --git a/mi/miscrinit.c b/mi/miscrinit.c
index ec4d108..327bd15 100644
--- a/mi/miscrinit.c
+++ b/mi/miscrinit.c
@@ -264,7 +264,7 @@ miScreenInit(ScreenPtr pScreen, void *pbits,  /* pointer to screen bits */
     pScreen->MarkWindow = miMarkWindow;
     pScreen->MarkOverlappedWindows = miMarkOverlappedWindows;
     pScreen->MoveWindow = miMoveWindow;
-    pScreen->ResizeWindow = miSlideAndSizeWindow;
+    pScreen->ResizeWindow = miResizeWindow;
     pScreen->GetLayerWindow = miGetLayerWindow;
     pScreen->HandleExposures = miHandleValidateExposures;
     pScreen->ReparentWindow = (ReparentWindowProcPtr) 0;
diff --git a/mi/miwindow.c b/mi/miwindow.c
index ba4c9ed..cfe085a 100644
--- a/mi/miwindow.c
+++ b/mi/miwindow.c
@@ -337,9 +337,8 @@ miRecomputeExposures(WindowPtr pWin, void *value)
 }
 
 void
-miSlideAndSizeWindow(WindowPtr pWin,
-                     int x, int y,
-                     unsigned int w, unsigned int h, WindowPtr pSib)
+miResizeWindow(WindowPtr pWin, int x, int y, unsigned int w, unsigned int h,
+               WindowPtr pSib)
 {
     WindowPtr pParent;
     Bool WasViewable = (Bool) (pWin->viewable);
commit 939ca767c7603923a91fd37901175a42e802d40e
Author: Adam Jackson <ajax at redhat.com>
Date:   Thu Sep 18 14:50:28 2014 -0400

    dix: Remove an obfuscatory macro
    
    Reviewed-by: Julien Cristau <jcristau at debian.org>
    Signed-off-by: Adam Jackson <ajax at redhat.com>

diff --git a/dix/window.c b/dix/window.c
index 295038a..7a2866a 100644
--- a/dix/window.c
+++ b/dix/window.c
@@ -1812,8 +1812,6 @@ ResizeChildrenWinSize(WindowPtr pWin, int dx, int dy, int dw, int dh)
 
 #define ChangeMask ((Mask)(CWX | CWY | CWWidth | CWHeight))
 
-#define IllegalInputOnlyConfigureMask (CWBorderWidth)
-
 /*
  * IsSiblingAboveMe
  *     returns Above if pSib above pMe in stack or Below otherwise 
@@ -2091,8 +2089,7 @@ ConfigureWindow(WindowPtr pWin, Mask mask, XID *vlist, ClientPtr client)
         h = pWin->drawable.height, bw = pWin->borderWidth;
     int rc, action, smode = Above;
 
-    if ((pWin->drawable.class == InputOnly) &&
-        (mask & IllegalInputOnlyConfigureMask))
+    if ((pWin->drawable.class == InputOnly) && (mask & CWBorderWidth))
         return BadMatch;
 
     if ((mask & CWSibling) && !(mask & CWStackMode))
commit d138d9ccc62a9472925574089f346bf9aa3dab1f
Author: Adam Jackson <ajax at redhat.com>
Date:   Mon Sep 15 13:05:24 2014 -0400

    dix: Remove some pointless casting of NULL
    
    Reviewed-by: Julien Cristau <jcristau at debian.org>
    Signed-off-by: Adam Jackson <ajax at redhat.com>

diff --git a/dix/window.c b/dix/window.c
index e49670a..295038a 100644
--- a/dix/window.c
+++ b/dix/window.c
@@ -357,8 +357,8 @@ SetWindowToDefaults(WindowPtr pWin)
     pWin->firstChild = NullWindow;
     pWin->lastChild = NullWindow;
 
-    pWin->valdata = (ValidatePtr) NULL;
-    pWin->optional = (WindowOptPtr) NULL;
+    pWin->valdata = NULL;
+    pWin->optional = NULL;
     pWin->cursorIsNone = TRUE;
 
     pWin->backingStore = NotUseful;
@@ -1550,7 +1550,7 @@ MoveWindowInStack(WindowPtr pWin, WindowPtr pNextSib)
             if (pWin->prevSib)
                 pWin->prevSib->nextSib = pWin->nextSib;
             pWin->nextSib = pParent->firstChild;
-            pWin->prevSib = (WindowPtr) NULL;
+            pWin->prevSib = NULL;
             pNextSib->prevSib = pWin;
             pParent->firstChild = pWin;
         }
@@ -1847,7 +1847,7 @@ WindowExtents(WindowPtr pWin, BoxPtr pBox)
     return pBox;
 }
 
-#define IS_SHAPED(pWin)	(wBoundingShape (pWin) != (RegionPtr) NULL)
+#define IS_SHAPED(pWin)	(wBoundingShape (pWin) != NULL)
 
 static RegionPtr
 MakeBoundingRegion(WindowPtr pWin, BoxPtr pBox)
@@ -1953,7 +1953,7 @@ WhereDoIGoInTheStack(WindowPtr pWin,
     WindowPtr pHead, pFirst;
 
     if ((pWin == pWin->parent->firstChild) && (pWin == pWin->parent->lastChild))
-        return ((WindowPtr) NULL);
+        return NULL;
     pHead = RealChildHead(pWin->parent);
     pFirst = pHead ? pHead->nextSib : pWin->parent->firstChild;
     box.x1 = x;
@@ -2644,8 +2644,7 @@ MapSubwindows(WindowPtr pParent, ClientPtr client)
                 RealizeTree(pWin);
                 if (pWin->viewable) {
                     anyMarked |= (*pScreen->MarkOverlappedWindows) (pWin, pWin,
-                                                                    (WindowPtr
-                                                                     *) NULL);
+                                                                    NULL);
                 }
             }
         }
@@ -2655,8 +2654,7 @@ MapSubwindows(WindowPtr pParent, ClientPtr client)
         pLayerWin = (*pScreen->GetLayerWindow) (pParent);
         if (pLayerWin->parent != pParent) {
             anyMarked |= (*pScreen->MarkOverlappedWindows) (pLayerWin,
-                                                            pLayerWin,
-                                                            (WindowPtr *) NULL);
+                                                            pLayerWin, NULL);
             pFirstMapped = pLayerWin;
         }
         if (anyMarked) {
@@ -2815,8 +2813,7 @@ UnmapSubwindows(WindowPtr pWin)
             else {
                 WindowPtr ptmp;
 
-                (*pScreen->MarkOverlappedWindows) (pWin, pLayerWin,
-                                                   (WindowPtr *) NULL);
+                (*pScreen->MarkOverlappedWindows) (pWin, pLayerWin, NULL);
                 (*pScreen->MarkWindow) (pLayerWin->parent);
 
                 /* Windows between pWin and pLayerWin may not have been marked */
@@ -2875,7 +2872,7 @@ HandleSaveSet(ClientPtr client)
     }
     free(client->saveSet);
     client->numSaved = 0;
-    client->saveSet = (SaveSetElt *) NULL;
+    client->saveSet = NULL;
 }
 
 /**
@@ -3591,7 +3588,7 @@ SetRootClip(ScreenPtr pScreen, Bool enable)
         if (pWin->firstChild) {
             anyMarked |= (*pScreen->MarkOverlappedWindows) (pWin->firstChild,
                                                             pWin->firstChild,
-                                                            (WindowPtr *) NULL);
+                                                            NULL);
         }
         else {
             (*pScreen->MarkWindow) (pWin);
commit 277330075bfbd4343c4efdd136e0be716e1a491f
Author: Adam Jackson <ajax at redhat.com>
Date:   Mon Sep 15 12:30:44 2014 -0400

    dix: Remove an empty if
    
    Reviewed-by: Julien Cristau <jcristau at debian.org>
    Signed-off-by: Adam Jackson <ajax at redhat.com>

diff --git a/dix/window.c b/dix/window.c
index e1645c3..e49670a 100644
--- a/dix/window.c
+++ b/dix/window.c
@@ -2806,8 +2806,6 @@ UnmapSubwindows(WindowPtr pWin)
             pChild->mapped = FALSE;
             if (pChild->realized)
                 UnrealizeTree(pChild, FALSE);
-            if (wasViewable) {
-            }
         }
     }
     if (wasViewable) {
commit 81d76a835b2f647e3051b1d93606e59db7998d76
Author: Adam Jackson <ajax at redhat.com>
Date:   Mon Sep 15 12:10:55 2014 -0400

    dix: Lower backStorage to a bit instead of a pointer
    
    Reviewed-by: Julien Cristau <jcristau at debian.org>
    Signed-off-by: Adam Jackson <ajax at redhat.com>

diff --git a/composite/compinit.c b/composite/compinit.c
index 48e938f..111c16e 100644
--- a/composite/compinit.c
+++ b/composite/compinit.c
@@ -119,12 +119,12 @@ compChangeWindowAttributes(WindowPtr pWin, unsigned long mask)
         pScreen->backingStoreSupport != NotUseful) {
         if (pWin->backingStore != NotUseful && !pWin->backStorage) {
             compRedirectWindow(serverClient, pWin, CompositeRedirectAutomatic);
-            pWin->backStorage = (void *) (intptr_t) 1;
+            pWin->backStorage = TRUE;
         }
         else if (pWin->backingStore == NotUseful && pWin->backStorage) {
             compUnredirectWindow(serverClient, pWin,
                                  CompositeRedirectAutomatic);
-            pWin->backStorage = NULL;
+            pWin->backStorage = FALSE;
         }
     }
 
diff --git a/dix/window.c b/dix/window.c
index f227e4c..e1645c3 100644
--- a/dix/window.c
+++ b/dix/window.c
@@ -362,7 +362,7 @@ SetWindowToDefaults(WindowPtr pWin)
     pWin->cursorIsNone = TRUE;
 
     pWin->backingStore = NotUseful;
-    pWin->backStorage = (void *) NULL;
+    pWin->backStorage = 0;
 
     pWin->mapped = FALSE;       /* off */
     pWin->realized = FALSE;     /* off */
diff --git a/include/windowstr.h b/include/windowstr.h
index 81f5f8c..740f4a6 100644
--- a/include/windowstr.h
+++ b/include/windowstr.h
@@ -144,12 +144,12 @@ typedef struct _Window {
     Mask eventMask;             /* mask from the creating client */
     PixUnion background;
     PixUnion border;
-    void *backStorage;          /* null when BS disabled */
     WindowOptPtr optional;
     unsigned backgroundState:2; /* None, Relative, Pixel, Pixmap */
     unsigned borderIsPixel:1;
     unsigned cursorIsNone:1;    /* else real cursor (might inherit) */
     unsigned backingStore:2;
+    unsigned backStorage:1;     /* if bs is allocated */
     unsigned saveUnder:1;
     unsigned bitGravity:4;
     unsigned winGravity:4;
diff --git a/mi/miexpose.c b/mi/miexpose.c
index 555f3b2..de8ee6c 100644
--- a/mi/miexpose.c
+++ b/mi/miexpose.c
@@ -143,7 +143,7 @@ miHandleExposures(DrawablePtr pSrcDrawable, DrawablePtr pDstDrawable,
     if (!pGC->graphicsExposures &&
         (pDstDrawable->type == DRAWABLE_PIXMAP) &&
         ((pSrcDrawable->type == DRAWABLE_PIXMAP) ||
-         (((WindowPtr) pSrcDrawable)->backStorage == NULL)))
+         (((WindowPtr) pSrcDrawable)->backStorage == 0)))
         return NULL;
 
     srcBox.x1 = srcx;
commit 322ba42c23a3a107f7a62fb1c449792b616e5eba
Author: Adam Jackson <ajax at redhat.com>
Date:   Mon Sep 15 12:05:26 2014 -0400

    dix: Remove DIXsaveUnder bit from the Window
    
    Reviewed-by: Julien Cristau <jcristau at debian.org>
    Signed-off-by: Adam Jackson <ajax at redhat.com>

diff --git a/dix/window.c b/dix/window.c
index 52e69ef..f227e4c 100644
--- a/dix/window.c
+++ b/dix/window.c
@@ -362,7 +362,6 @@ SetWindowToDefaults(WindowPtr pWin)
     pWin->cursorIsNone = TRUE;
 
     pWin->backingStore = NotUseful;
-    pWin->DIXsaveUnder = FALSE;
     pWin->backStorage = (void *) NULL;
 
     pWin->mapped = FALSE;       /* off */
diff --git a/include/windowstr.h b/include/windowstr.h
index 6b79bbd..81f5f8c 100644
--- a/include/windowstr.h
+++ b/include/windowstr.h
@@ -151,7 +151,6 @@ typedef struct _Window {
     unsigned cursorIsNone:1;    /* else real cursor (might inherit) */
     unsigned backingStore:2;
     unsigned saveUnder:1;
-    unsigned DIXsaveUnder:1;
     unsigned bitGravity:4;
     unsigned winGravity:4;
     unsigned overrideRedirect:1;
commit 1e56b2dfc6377234ffdcdf206528d476b04d13af
Author: Adam Jackson <ajax at redhat.com>
Date:   Fri Sep 12 12:51:13 2014 -0400

    mi: Move pScreen->SendGraphicsExpose up to dix
    
    No DDX is overriding this and it's fairly absurd to expose it as a
    screen operation anyway.
    
    Reviewed-by: Julien Cristau <jcristau at debian.org>
    Signed-off-by: Adam Jackson <ajax at redhat.com>

diff --git a/Xext/panoramiXprocs.c b/Xext/panoramiXprocs.c
index 83a2e08..aa3859f 100644
--- a/Xext/panoramiXprocs.c
+++ b/Xext/panoramiXprocs.c
@@ -1193,9 +1193,8 @@ PanoramiXCopyArea(ClientPtr client)
             Bool overlap;
 
             RegionValidate(&totalReg, &overlap);
-            (*pDst->pScreen->SendGraphicsExpose) (client, &totalReg,
-                                                  stuff->dstDrawable,
-                                                  X_CopyArea, 0);
+            SendGraphicsExpose(client, &totalReg, stuff->dstDrawable,
+                               X_CopyArea, 0);
             RegionUninit(&totalReg);
         }
     }
@@ -1306,9 +1305,8 @@ PanoramiXCopyPlane(ClientPtr client)
         Bool overlap;
 
         RegionValidate(&totalReg, &overlap);
-        (*pdstDraw->pScreen->SendGraphicsExpose) (client, &totalReg,
-                                                  stuff->dstDrawable,
-                                                  X_CopyPlane, 0);
+        SendGraphicsExpose(client, &totalReg, stuff->dstDrawable,
+                           X_CopyPlane, 0);
         RegionUninit(&totalReg);
     }
 
diff --git a/dix/dispatch.c b/dix/dispatch.c
index f7a08f8..74abecd 100644
--- a/dix/dispatch.c
+++ b/dix/dispatch.c
@@ -1597,6 +1597,52 @@ ProcClearToBackground(ClientPtr client)
     return Success;
 }
 
+/* send GraphicsExpose events, or a NoExpose event, based on the region */
+void
+SendGraphicsExpose(ClientPtr client, RegionPtr pRgn, XID drawable,
+                     int major, int minor)
+{
+    if (pRgn && !RegionNil(pRgn)) {
+        xEvent *pEvent;
+        xEvent *pe;
+        BoxPtr pBox;
+        int i;
+        int numRects;
+
+        numRects = RegionNumRects(pRgn);
+        pBox = RegionRects(pRgn);
+        if (!(pEvent = calloc(numRects, sizeof(xEvent))))
+            return;
+        pe = pEvent;
+
+        for (i = 1; i <= numRects; i++, pe++, pBox++) {
+            pe->u.u.type = GraphicsExpose;
+            pe->u.graphicsExposure.drawable = drawable;
+            pe->u.graphicsExposure.x = pBox->x1;
+            pe->u.graphicsExposure.y = pBox->y1;
+            pe->u.graphicsExposure.width = pBox->x2 - pBox->x1;
+            pe->u.graphicsExposure.height = pBox->y2 - pBox->y1;
+            pe->u.graphicsExposure.count = numRects - i;
+            pe->u.graphicsExposure.majorEvent = major;
+            pe->u.graphicsExposure.minorEvent = minor;
+        }
+        /* GraphicsExpose is a "critical event", which TryClientEvents
+         * handles specially. */
+        TryClientEvents(client, NULL, pEvent, numRects,
+                        (Mask) 0, NoEventMask, NullGrab);
+        free(pEvent);
+    }
+    else {
+        xEvent event = {
+            .u.noExposure.drawable = drawable,
+            .u.noExposure.majorEvent = major,
+            .u.noExposure.minorEvent = minor
+        };
+        event.u.u.type = NoExpose;
+        WriteEventsToClient(client, 1, &event);
+    }
+}
+
 int
 ProcCopyArea(ClientPtr client)
 {
@@ -1628,8 +1674,7 @@ ProcCopyArea(ClientPtr client)
                                   stuff->width, stuff->height,
                                   stuff->dstX, stuff->dstY);
     if (pGC->graphicsExposures) {
-        (*pDst->pScreen->SendGraphicsExpose)
-            (client, pRgn, stuff->dstDrawable, X_CopyArea, 0);
+        SendGraphicsExpose(client, pRgn, stuff->dstDrawable, X_CopyArea, 0);
         if (pRgn)
             RegionDestroy(pRgn);
     }
@@ -1676,8 +1721,7 @@ ProcCopyPlane(ClientPtr client)
                                 stuff->srcY, stuff->width, stuff->height,
                                 stuff->dstX, stuff->dstY, stuff->bitPlane);
     if (pGC->graphicsExposures) {
-        (*pdstDraw->pScreen->SendGraphicsExpose)
-            (client, pRgn, stuff->dstDrawable, X_CopyPlane, 0);
+        SendGraphicsExpose(client, pRgn, stuff->dstDrawable, X_CopyPlane, 0);
         if (pRgn)
             RegionDestroy(pRgn);
     }
diff --git a/include/dix.h b/include/dix.h
index 61ecc8d..116da2e 100644
--- a/include/dix.h
+++ b/include/dix.h
@@ -254,6 +254,12 @@ extern _X_EXPORT void ClientWakeup(ClientPtr /*client */ );
 
 extern _X_EXPORT Bool ClientIsAsleep(ClientPtr /*client */ );
 
+extern _X_EXPORT void SendGraphicsExpose(ClientPtr /*client */ ,
+                                         RegionPtr /*pRgn */ ,
+                                         XID /*drawable */ ,
+                                         int /*major */ ,
+                                         int  /*minor */);
+
 /* atom.c */
 
 extern _X_EXPORT Atom MakeAtom(const char * /*string */ ,
diff --git a/include/scrnintstr.h b/include/scrnintstr.h
index 7331ec1..269ff5a 100644
--- a/include/scrnintstr.h
+++ b/include/scrnintstr.h
@@ -252,12 +252,6 @@ typedef void (*ResolveColorProcPtr) (unsigned short * /*pred */ ,
 
 typedef RegionPtr (*BitmapToRegionProcPtr) (PixmapPtr /*pPix */ );
 
-typedef void (*SendGraphicsExposeProcPtr) (ClientPtr /*client */ ,
-                                           RegionPtr /*pRgn */ ,
-                                           XID /*drawable */ ,
-                                           int /*major */ ,
-                                           int /*minor */ );
-
 typedef void (*ScreenBlockHandlerProcPtr) (ScreenPtr pScreen,
                                            void *pTimeout,
                                            void *pReadmask);
@@ -540,7 +534,6 @@ typedef struct _Screen {
     /* Region procedures */
 
     BitmapToRegionProcPtr BitmapToRegion;
-    SendGraphicsExposeProcPtr SendGraphicsExpose;
 
     /* os layer procedures */
 
diff --git a/mi/mi.h b/mi/mi.h
index 700bb11..8cb3ce7 100644
--- a/mi/mi.h
+++ b/mi/mi.h
@@ -232,13 +232,6 @@ extern _X_EXPORT RegionPtr miHandleExposures(DrawablePtr /*pSrcDrawable */ ,
                                              int /*dsty */
     );
 
-extern _X_EXPORT void miSendGraphicsExpose(ClientPtr /*client */ ,
-                                           RegionPtr /*pRgn */ ,
-                                           XID /*drawable */ ,
-                                           int /*major */ ,
-                                           int  /*minor */
-    );
-
 extern _X_EXPORT void miSendExposures(WindowPtr /*pWin */ ,
                                       RegionPtr /*pRgn */ ,
                                       int /*dx */ ,
diff --git a/mi/miexpose.c b/mi/miexpose.c
index 7a1c172..555f3b2 100644
--- a/mi/miexpose.c
+++ b/mi/miexpose.c
@@ -306,53 +306,6 @@ miHandleExposures(DrawablePtr pSrcDrawable, DrawablePtr pDstDrawable,
     }
 }
 
-/* send GraphicsExpose events, or a NoExpose event, based on the region */
-
-void
-miSendGraphicsExpose(ClientPtr client, RegionPtr pRgn, XID drawable,
-                     int major, int minor)
-{
-    if (pRgn && !RegionNil(pRgn)) {
-        xEvent *pEvent;
-        xEvent *pe;
-        BoxPtr pBox;
-        int i;
-        int numRects;
-
-        numRects = RegionNumRects(pRgn);
-        pBox = RegionRects(pRgn);
-        if (!(pEvent = calloc(numRects, sizeof(xEvent))))
-            return;
-        pe = pEvent;
-
-        for (i = 1; i <= numRects; i++, pe++, pBox++) {
-            pe->u.u.type = GraphicsExpose;
-            pe->u.graphicsExposure.drawable = drawable;
-            pe->u.graphicsExposure.x = pBox->x1;
-            pe->u.graphicsExposure.y = pBox->y1;
-            pe->u.graphicsExposure.width = pBox->x2 - pBox->x1;
-            pe->u.graphicsExposure.height = pBox->y2 - pBox->y1;
-            pe->u.graphicsExposure.count = numRects - i;
-            pe->u.graphicsExposure.majorEvent = major;
-            pe->u.graphicsExposure.minorEvent = minor;
-        }
-        /* GraphicsExpose is a "critical event", which TryClientEvents
-         * handles specially. */
-        TryClientEvents(client, NULL, pEvent, numRects,
-                        (Mask) 0, NoEventMask, NullGrab);
-        free(pEvent);
-    }
-    else {
-        xEvent event = {
-            .u.noExposure.drawable = drawable,
-            .u.noExposure.majorEvent = major,
-            .u.noExposure.minorEvent = minor
-        };
-        event.u.u.type = NoExpose;
-        WriteEventsToClient(client, 1, &event);
-    }
-}
-
 void
 miSendExposures(WindowPtr pWin, RegionPtr pRgn, int dx, int dy)
 {
diff --git a/mi/miscrinit.c b/mi/miscrinit.c
index 00c15f7..ec4d108 100644
--- a/mi/miscrinit.c
+++ b/mi/miscrinit.c
@@ -259,7 +259,6 @@ miScreenInit(ScreenPtr pScreen, void *pbits,  /* pointer to screen bits */
     /* CreateColormap, DestroyColormap, InstallColormap, UninstallColormap */
     /* ListInstalledColormaps, StoreColors, ResolveColor */
     /* BitmapToRegion */
-    pScreen->SendGraphicsExpose = miSendGraphicsExpose;
     pScreen->BlockHandler = (ScreenBlockHandlerProcPtr) NoopDDA;
     pScreen->WakeupHandler = (ScreenWakeupHandlerProcPtr) NoopDDA;
     pScreen->MarkWindow = miMarkWindow;
commit 5d3bd8a3dc6456ea1ccf7b5f71b972379d7565ec
Author: Adam Jackson <ajax at redhat.com>
Date:   Fri Sep 12 11:56:28 2014 -0400

    mi: Drop plane argument from miHandleExposures
    
    This existed to be passed to the bs recovery routine; since we back all
    planes, we don't care.
    
    Reviewed-by: Julien Cristau <jcristau at debian.org>
    Signed-off-by: Adam Jackson <ajax at redhat.com>

diff --git a/fb/fbcopy.c b/fb/fbcopy.c
index 541ef71..5bbabc3 100644
--- a/fb/fbcopy.c
+++ b/fb/fbcopy.c
@@ -271,5 +271,5 @@ fbCopyPlane(DrawablePtr pSrcDrawable,
     else
         return miHandleExposures(pSrcDrawable, pDstDrawable, pGC,
                                  xIn, yIn,
-                                 widthSrc, heightSrc, xOut, yOut, bitplane);
+                                 widthSrc, heightSrc, xOut, yOut);
 }
diff --git a/glamor/glamor_copy.c b/glamor/glamor_copy.c
index 6f422d4..3320935 100644
--- a/glamor/glamor_copy.c
+++ b/glamor/glamor_copy.c
@@ -677,8 +677,7 @@ glamor_copy_plane(DrawablePtr src, DrawablePtr dst, GCPtr gc,
 {
     if ((bitplane & FbFullMask(src->depth)) == 0)
         return miHandleExposures(src, dst, gc,
-                                 srcx, srcy, width, height, dstx, dsty,
-                                 bitplane);
+                                 srcx, srcy, width, height, dstx, dsty);
     return miDoCopy(src, dst, gc,
                     srcx, srcy, width, height,
                     dstx, dsty, glamor_copy, bitplane, NULL);
diff --git a/hw/dmx/dmxgcops.c b/hw/dmx/dmxgcops.c
index aa7c8eb..0ebd69a 100644
--- a/hw/dmx/dmxgcops.c
+++ b/hw/dmx/dmxgcops.c
@@ -179,7 +179,7 @@ dmxCopyArea(DrawablePtr pSrc, DrawablePtr pDst, GCPtr pGC,
 
     if (DMX_GCOPS_OFFSCREEN(pSrc) || DMX_GCOPS_OFFSCREEN(pDst))
         return miHandleExposures(pSrc, pDst, pGC, srcx, srcy, w, h,
-                                 dstx, dsty, 0L);
+                                 dstx, dsty);
 
     DMX_GCOPS_SET_DRAWABLE(pSrc, srcDraw);
     DMX_GCOPS_SET_DRAWABLE(pDst, dstDraw);
@@ -188,7 +188,7 @@ dmxCopyArea(DrawablePtr pSrc, DrawablePtr pDst, GCPtr pGC,
               srcx, srcy, w, h, dstx, dsty);
     dmxSync(dmxScreen, FALSE);
 
-    return miHandleExposures(pSrc, pDst, pGC, srcx, srcy, w, h, dstx, dsty, 0L);
+    return miHandleExposures(pSrc, pDst, pGC, srcx, srcy, w, h, dstx, dsty);
 }
 
 /** Copy plane number \a bitPlane from \a pSrc drawable to \a pDst
@@ -206,7 +206,7 @@ dmxCopyPlane(DrawablePtr pSrc, DrawablePtr pDst, GCPtr pGC,
 
     if (DMX_GCOPS_OFFSCREEN(pSrc) || DMX_GCOPS_OFFSCREEN(pDst))
         return miHandleExposures(pSrc, pDst, pGC, srcx, srcy, width, height,
-                                 dstx, dsty, bitPlane);
+                                 dstx, dsty);
 
     DMX_GCOPS_SET_DRAWABLE(pSrc, srcDraw);
     DMX_GCOPS_SET_DRAWABLE(pDst, dstDraw);
@@ -216,7 +216,7 @@ dmxCopyPlane(DrawablePtr pSrc, DrawablePtr pDst, GCPtr pGC,
     dmxSync(dmxScreen, FALSE);
 
     return miHandleExposures(pSrc, pDst, pGC, srcx, srcy, width, height,
-                             dstx, dsty, bitPlane);
+                             dstx, dsty);
 }
 
 /** Render list of points, \a pptInit in \a pDrawable on the back-end
diff --git a/mi/mi.h b/mi/mi.h
index a4a01b8..700bb11 100644
--- a/mi/mi.h
+++ b/mi/mi.h
@@ -229,8 +229,7 @@ extern _X_EXPORT RegionPtr miHandleExposures(DrawablePtr /*pSrcDrawable */ ,
                                              int /*width */ ,
                                              int /*height */ ,
                                              int /*dstx */ ,
-                                             int /*dsty */ ,
-                                             unsigned long      /*plane */
+                                             int /*dsty */
     );
 
 extern _X_EXPORT void miSendGraphicsExpose(ClientPtr /*client */ ,
diff --git a/mi/mibitblt.c b/mi/mibitblt.c
index 3ed4ed1..08bd1c5 100644
--- a/mi/mibitblt.c
+++ b/mi/mibitblt.c
@@ -242,8 +242,7 @@ miCopyArea(DrawablePtr pSrcDrawable,
         }
     }
     prgnExposed = miHandleExposures(pSrcDrawable, pDstDrawable, pGC, xIn, yIn,
-                                    widthSrc, heightSrc, xOut, yOut,
-                                    (unsigned long) 0);
+                                    widthSrc, heightSrc, xOut, yOut);
     if (realSrcClip)
         RegionDestroy(prgnSrcClip);
 
@@ -579,7 +578,7 @@ miCopyPlane(DrawablePtr pSrcDrawable,
         }
     }
     prgnExposed = miHandleExposures(pSrcDrawable, pDstDrawable, pGC, srcx, srcy,
-                                    width, height, dstx, dsty, bitPlane);
+                                    width, height, dstx, dsty);
     RegionDestroy(prgnSrc);
     return prgnExposed;
 }
diff --git a/mi/micopy.c b/mi/micopy.c
index 3079511..a52b0a7 100644
--- a/mi/micopy.c
+++ b/mi/micopy.c
@@ -304,8 +304,7 @@ miDoCopy(DrawablePtr pSrcDrawable,
                                         yIn - pSrcDrawable->y,
                                         widthSrc, heightSrc,
                                         xOut - pDstDrawable->x,
-                                        yOut - pDstDrawable->y,
-                                        (unsigned long) bitPlane);
+                                        yOut - pDstDrawable->y);
     RegionUninit(&rgnDst);
     if (freeSrcClip)
         RegionDestroy(prgnSrcClip);
diff --git a/mi/miexpose.c b/mi/miexpose.c
index de0e148..7a1c172 100644
--- a/mi/miexpose.c
+++ b/mi/miexpose.c
@@ -116,18 +116,12 @@ NOTE:
      this should generally be called, even if graphicsExposures is false,
 because this is where bits get recovered from backing store.
 
-NOTE:
-     added argument 'plane' is used to indicate how exposures from backing
-store should be accomplished. If plane is 0 (i.e. no bit plane), CopyArea
-should be used, else a CopyPlane of the indicated plane will be used. The
-exposing is done by the backing store's GraphicsExpose function, of course.
-
 */
 
 RegionPtr
 miHandleExposures(DrawablePtr pSrcDrawable, DrawablePtr pDstDrawable,
                   GCPtr pGC, int srcx, int srcy, int width, int height,
-                  int dstx, int dsty, unsigned long plane)
+                  int dstx, int dsty)
 {
     RegionPtr prgnSrcClip;      /* drawable-relative source clip */
     RegionRec rgnSrcRec;
commit 7eddc80bc4a6c1902746a9fbe79ab553f9fd5821
Author: Adam Jackson <ajax at redhat.com>
Date:   Tue Aug 5 14:07:17 2014 -0400

    mi: Simplify composite border clip redirection interface
    
    There's not really a good reason for mi to not just call the composite
    code directly.
    
    Reviewed-by: Keith Packard <keithp at keithp.com>
    Signed-off-by: Adam Jackson <ajax at redhat.com>

diff --git a/composite/compext.c b/composite/compext.c
index cadedbd..fcfc349 100644
--- a/composite/compext.c
+++ b/composite/compext.c
@@ -594,9 +594,6 @@ CompositeExtensionInit(void)
         return;
     CompositeReqCode = (CARD8) extEntry->base;
 
-    miRegisterRedirectBorderClipProc(compSetRedirectBorderClip,
-                                     compGetRedirectBorderClip);
-
     /* Initialization succeeded */
     noCompositeExtension = FALSE;
 }
diff --git a/mi/mi.h b/mi/mi.h
index 4b5e862..a4a01b8 100644
--- a/mi/mi.h
+++ b/mi/mi.h
@@ -425,17 +425,6 @@ extern _X_EXPORT int miShapedWindowIn(RegionPtr /*universe */ ,
                                       int       /*y */
     );
 
-typedef void
- (*SetRedirectBorderClipProcPtr) (WindowPtr pWindow, RegionPtr pRegion);
-
-typedef RegionPtr
- (*GetRedirectBorderClipProcPtr) (WindowPtr pWindow);
-
-extern _X_EXPORT void
-
-miRegisterRedirectBorderClipProc(SetRedirectBorderClipProcPtr setBorderClip,
-                                 GetRedirectBorderClipProcPtr getBorderClip);
-
 extern _X_EXPORT int miValidateTree(WindowPtr /*pParent */ ,
                                     WindowPtr /*pChild */ ,
                                     VTKind      /*kind */
diff --git a/mi/mivaltree.c b/mi/mivaltree.c
index c1cc431..8e4e9a9 100644
--- a/mi/mivaltree.c
+++ b/mi/mivaltree.c
@@ -99,8 +99,10 @@ Equipment Corporation.
 #include    "mi.h"
 #include    "regionstr.h"
 #include    "mivalidate.h"
-
 #include    "globals.h"
+#ifdef COMPOSITE
+#include    "compint.h"
+#endif
 
 /*
  * Compute the visibility of a shaped window
@@ -160,17 +162,6 @@ miShapedWindowIn(RegionPtr universe, RegionPtr bounding,
     return rgnOUT;
 }
 
-static GetRedirectBorderClipProcPtr miGetRedirectBorderClipProc;
-static SetRedirectBorderClipProcPtr miSetRedirectBorderClipProc;
-
-void
-miRegisterRedirectBorderClipProc(SetRedirectBorderClipProcPtr setBorderClip,
-                                 GetRedirectBorderClipProcPtr getBorderClip)
-{
-    miSetRedirectBorderClipProc = setBorderClip;
-    miGetRedirectBorderClipProc = getBorderClip;
-}
-
 /*
  * Manual redirected windows are treated as transparent; they do not obscure
  * siblings or parent windows
@@ -242,11 +233,9 @@ miComputeClips(WindowPtr pParent,
      * In redirected drawing case, reset universe to borderSize
      */
     if (pParent->redirectDraw != RedirectDrawNone) {
-        if (miSetRedirectBorderClipProc) {
-            if (TreatAsTransparent(pParent))
-                RegionEmpty(universe);
-            (*miSetRedirectBorderClipProc) (pParent, universe);
-        }
+        if (TreatAsTransparent(pParent))
+            RegionEmpty(universe);
+        compSetRedirectBorderClip (pParent, universe);
         RegionCopy(universe, &pParent->borderSize);
     }
 #endif
@@ -516,6 +505,17 @@ miTreeObscured(WindowPtr pParent)
     }
 }
 
+static RegionPtr
+getBorderClip(WindowPtr pWin)
+{
+#ifdef COMPOSITE
+    if (pWin->redirectDraw != RedirectDrawNone)
+        return compGetRedirectBorderClip(pWin);
+    else
+#endif
+        return &pWin->borderClip;
+}
+
 /*
  *-----------------------------------------------------------------------
  * miValidateTree --
@@ -609,14 +609,7 @@ miValidateTree(WindowPtr pParent,       /* Parent to validate */
             forward = TRUE;
             for (pWin = pChild; pWin; pWin = pWin->nextSib) {
                 if (pWin->valdata) {
-                    RegionPtr pBorderClip = &pWin->borderClip;
-
-#ifdef COMPOSITE
-                    if (pWin->redirectDraw != RedirectDrawNone &&
-                        miGetRedirectBorderClipProc)
-                        pBorderClip = (*miGetRedirectBorderClipProc) (pWin);
-#endif
-                    RegionAppend(&totalClip, pBorderClip);
+                    RegionAppend(&totalClip, getBorderClip(pWin));
                     if (pWin->viewable)
                         viewvals++;
                 }
@@ -627,14 +620,7 @@ miValidateTree(WindowPtr pParent,       /* Parent to validate */
             pWin = pParent->lastChild;
             while (1) {
                 if (pWin->valdata) {
-                    RegionPtr pBorderClip = &pWin->borderClip;
-
-#ifdef COMPOSITE
-                    if (pWin->redirectDraw != RedirectDrawNone &&
-                        miGetRedirectBorderClipProc)
-                        pBorderClip = (*miGetRedirectBorderClipProc) (pWin);
-#endif
-                    RegionAppend(&totalClip, pBorderClip);
+                    RegionAppend(&totalClip, getBorderClip(pWin));
                     if (pWin->viewable)
                         viewvals++;
                 }
commit 7b35dc9b1533d4b99a3f84f460ac66354a6fe347
Author: Adam Jackson <ajax at redhat.com>
Date:   Tue Sep 23 10:35:37 2014 -0400

    mi: Deobfuscate miOverlayWindowExposures
    
    Reviewed-by: Julien Cristau <jcristau at debian.org>
    Signed-off-by: Adam Jackson <ajax at redhat.com>

diff --git a/mi/mioverlay.c b/mi/mioverlay.c
index f894e2b..2ad6bc0 100644
--- a/mi/mioverlay.c
+++ b/mi/mioverlay.c
@@ -983,28 +983,19 @@ miOverlayWindowExposures(WindowPtr pWin, RegionPtr prgn)
 {
     RegionPtr exposures = prgn;
 
-    if ((prgn && !RegionNil(prgn)) || (exposures && !RegionNil(exposures))) {
+    if (prgn && !RegionNil(prgn)) {
         RegionRec expRec;
-        int clientInterested;
-
-        clientInterested = (pWin->eventMask | wOtherEventMasks(pWin)) &
-            ExposureMask;
-        if (clientInterested && exposures &&
-            (RegionNumRects(exposures) > RECTLIMIT)) {
+        int clientInterested =
+            (pWin->eventMask | wOtherEventMasks(pWin)) & ExposureMask;
+        if (clientInterested && (RegionNumRects(prgn) > RECTLIMIT)) {
             ScreenPtr pScreen = pWin->drawable.pScreen;
             miOverlayScreenPtr pPriv = MIOVERLAY_GET_SCREEN_PRIVATE(pScreen);
             BoxRec box;
 
-            box = *RegionExtents(exposures);
-            if (exposures == prgn) {
-                exposures = &expRec;
-                RegionInit(exposures, &box, 1);
-                RegionReset(prgn, &box);
-            }
-            else {
-                RegionReset(exposures, &box);
-                RegionUnion(prgn, prgn, exposures);
-            }
+            box = *RegionExtents(prgn);
+            exposures = &expRec;
+            RegionInit(exposures, &box, 1);
+            RegionReset(prgn, &box);
             /* This is the only reason why we are replacing mi's version
                of this file */
 
@@ -1016,21 +1007,14 @@ miOverlayWindowExposures(WindowPtr pWin, RegionPtr prgn)
             else
                 RegionIntersect(prgn, prgn, &pWin->clipList);
         }
-        if (prgn && !RegionNil(prgn))
-            miPaintWindow(pWin, prgn, PW_BACKGROUND);
-        if (clientInterested && exposures && !RegionNil(exposures))
+        miPaintWindow(pWin, prgn, PW_BACKGROUND);
+        if (clientInterested)
             miSendExposures(pWin, exposures,
                             pWin->drawable.x, pWin->drawable.y);
-        if (exposures == &expRec) {
+        if (exposures == &expRec)
             RegionUninit(exposures);
-        }
-        else if (exposures && exposures != prgn)
-            RegionDestroy(exposures);
-        if (prgn)
-            RegionEmpty(prgn);
+        RegionEmpty(prgn);
     }
-    else if (exposures && exposures != prgn)
-        RegionDestroy(exposures);
 }
 
 typedef struct {
commit fb34f273481b90a90a988f0f5c5a2d642a5661b8
Author: Adam Jackson <ajax at redhat.com>
Date:   Tue Sep 23 10:30:56 2014 -0400

    mi: Deobfuscate miWindowExposures
    
    Reviewed-by: Julien Cristau <jcristau at debian.org>
    Signed-off-by: Adam Jackson <ajax at redhat.com>

diff --git a/mi/miexpose.c b/mi/miexpose.c
index 23987fa..de0e148 100644
--- a/mi/miexpose.c
+++ b/mi/miexpose.c
@@ -425,17 +425,11 @@ miWindowExposures(WindowPtr pWin, RegionPtr prgn)
 {
     RegionPtr exposures = prgn;
 
-    if ((prgn && !RegionNil(prgn)) || (exposures && !RegionNil(exposures))) {
+    if (prgn && !RegionNil(prgn)) {
         RegionRec expRec;
-        int clientInterested;
-
-        /*
-         * Restore from backing-store FIRST.
-         */
-        clientInterested =
+        int clientInterested =
             (pWin->eventMask | wOtherEventMasks(pWin)) & ExposureMask;
-        if (clientInterested && exposures &&
-            (RegionNumRects(exposures) > RECTLIMIT)) {
+        if (clientInterested && (RegionNumRects(prgn) > RECTLIMIT)) {
             /*
              * If we have LOTS of rectangles, we decide to take the extents
              * and force an exposure on that.  This should require much less
@@ -444,34 +438,21 @@ miWindowExposures(WindowPtr pWin, RegionPtr prgn)
              */
             BoxRec box;
 
-            box = *RegionExtents(exposures);
-            if (exposures == prgn) {
-                exposures = &expRec;
-                RegionInit(exposures, &box, 1);
-                RegionReset(prgn, &box);
-            }
-            else {
-                RegionReset(exposures, &box);
-                RegionUnion(prgn, prgn, exposures);
-            }
+            box = *RegionExtents(prgn);
+            exposures = &expRec;
+            RegionInit(exposures, &box, 1);
+            RegionReset(prgn, &box);
             /* miPaintWindow doesn't clip, so we have to */
             RegionIntersect(prgn, prgn, &pWin->clipList);
         }
-        if (prgn && !RegionNil(prgn))
-            miPaintWindow(pWin, prgn, PW_BACKGROUND);
-        if (clientInterested && exposures && !RegionNil(exposures))
+        miPaintWindow(pWin, prgn, PW_BACKGROUND);
+        if (clientInterested)
             miSendExposures(pWin, exposures,
                             pWin->drawable.x, pWin->drawable.y);
-        if (exposures == &expRec) {
+        if (exposures == &expRec)
             RegionUninit(exposures);
-        }
-        else if (exposures && exposures != prgn)
-            RegionDestroy(exposures);
-        if (prgn)
-            RegionEmpty(prgn);
+        RegionEmpty(prgn);
     }
-    else if (exposures && exposures != prgn)
-        RegionDestroy(exposures);
 }
 
 #ifdef ROOTLESS
commit 0d30d44a8cdacfbc99d8193f76c133b803464622
Author: Adam Jackson <ajax at redhat.com>
Date:   Thu Sep 11 12:44:54 2014 -0400

    dix: Drop the third argument from WindowExposuresProcPtr
    
    A careful read shows that it was always NULL.  It hasn't always been; as
    the DDX spec indicates, it was the "occluded region that has backing
    store", but since that backing store code is long gone, we can nuke it.
    
    mi{,Overlay}WindowExposures get slightly simpler here, and will get even
    simpler in just a moment.
    
    Reviewed-by: Julien Cristau <jcristau at debian.org>
    Signed-off-by: Adam Jackson <ajax at redhat.com>

diff --git a/dix/window.c b/dix/window.c
index f4acdc8..52e69ef 100644
--- a/dix/window.c
+++ b/dix/window.c
@@ -2601,7 +2601,7 @@ MapWindow(WindowPtr pWin, ClientPtr client)
             (*pScreen->PostValidateTree) (NullWindow, pWin, VTMap);
         RegionNull(&temp);
         RegionCopy(&temp, &pWin->clipList);
-        (*pScreen->WindowExposures) (pWin, &temp, NullRegion);
+        (*pScreen->WindowExposures) (pWin, &temp);
         RegionUninit(&temp);
     }
 
diff --git a/fb/fboverlay.c b/fb/fboverlay.c
index 935bf1b..6a5f0f8 100644
--- a/fb/fboverlay.c
+++ b/fb/fboverlay.c
@@ -240,12 +240,11 @@ fbOverlayCopyWindow(WindowPtr pWin, DDXPointRec ptOldOrg, RegionPtr prgnSrc)
 }
 
 void
-fbOverlayWindowExposures(WindowPtr pWin,
-                         RegionPtr prgn, RegionPtr other_exposed)
+fbOverlayWindowExposures(WindowPtr pWin, RegionPtr prgn)
 {
     fbOverlayUpdateLayerRegion(pWin->drawable.pScreen,
                                fbOverlayWindowLayer(pWin), prgn);
-    miWindowExposures(pWin, prgn, other_exposed);
+    miWindowExposures(pWin, prgn);
 }
 
 Bool
diff --git a/fb/fboverlay.h b/fb/fboverlay.h
index 57c9873..47727e4 100644
--- a/fb/fboverlay.h
+++ b/fb/fboverlay.h
@@ -82,9 +82,7 @@ extern _X_EXPORT void
  fbOverlayCopyWindow(WindowPtr pWin, DDXPointRec ptOldOrg, RegionPtr prgnSrc);
 
 extern _X_EXPORT void
-
-fbOverlayWindowExposures(WindowPtr pWin,
-                         RegionPtr prgn, RegionPtr other_exposed);
+fbOverlayWindowExposures(WindowPtr pWin, RegionPtr prgn);
 
 extern _X_EXPORT Bool
 
diff --git a/hw/dmx/dmxwindow.c b/hw/dmx/dmxwindow.c
index 1c23527..c753735 100644
--- a/hw/dmx/dmxwindow.c
+++ b/hw/dmx/dmxwindow.c
@@ -772,7 +772,7 @@ dmxWindowExposurePredicate(Display * dpy, XEvent * ev, XPointer ptr)
  *  in DMX, the events that are generated by the back-end server are
  *  redundant, so we eat them here. */
 void
-dmxWindowExposures(WindowPtr pWindow, RegionPtr prgn, RegionPtr other_exposed)
+dmxWindowExposures(WindowPtr pWindow, RegionPtr prgn)
 {
     ScreenPtr pScreen = pWindow->drawable.pScreen;
     DMXScreenInfo *dmxScreen = &dmxScreens[pScreen->myNum];
@@ -799,7 +799,7 @@ dmxWindowExposures(WindowPtr pWindow, RegionPtr prgn, RegionPtr other_exposed)
 
 #if 1
     if (pScreen->WindowExposures)
-        pScreen->WindowExposures(pWindow, prgn, other_exposed);
+        pScreen->WindowExposures(pWindow, prgn);
 #endif
     DMX_WRAP(WindowExposures, dmxWindowExposures, dmxScreen, pScreen);
 }
diff --git a/hw/dmx/dmxwindow.h b/hw/dmx/dmxwindow.h
index c6b2efe..dda6538 100644
--- a/hw/dmx/dmxwindow.h
+++ b/hw/dmx/dmxwindow.h
@@ -73,8 +73,7 @@ extern Bool dmxChangeWindowAttributes(WindowPtr pWindow, unsigned long mask);
 extern Bool dmxRealizeWindow(WindowPtr pWindow);
 extern Bool dmxUnrealizeWindow(WindowPtr pWindow);
 extern void dmxRestackWindow(WindowPtr pWindow, WindowPtr pOldNextSib);
-extern void dmxWindowExposures(WindowPtr pWindow, RegionPtr prgn,
-                               RegionPtr other_exposed);
+extern void dmxWindowExposures(WindowPtr pWindow, RegionPtr prgn);
 extern void dmxCopyWindow(WindowPtr pWindow, DDXPointRec ptOldOrg,
                           RegionPtr prgnSrc);
 
diff --git a/hw/kdrive/ephyr/ephyr.c b/hw/kdrive/ephyr/ephyr.c
index 85d4193..8b88f3e 100644
--- a/hw/kdrive/ephyr/ephyr.c
+++ b/hw/kdrive/ephyr/ephyr.c
@@ -878,7 +878,7 @@ ephyrExposePairedWindow(int a_remote)
     screen = pair->local->drawable.pScreen;
     RegionNull(&reg);
     RegionCopy(&reg, &pair->local->clipList);
-    screen->WindowExposures(pair->local, &reg, NullRegion);
+    screen->WindowExposures(pair->local, &reg);
     RegionUninit(&reg);
 }
 #endif                          /* XF86DRI */
diff --git a/hw/kdrive/src/kxv.c b/hw/kdrive/src/kxv.c
index f979e1f..163d5c1 100644
--- a/hw/kdrive/src/kxv.c
+++ b/hw/kdrive/src/kxv.c
@@ -86,7 +86,7 @@ static int KdXVQueryImageAttributes(XvPortPtr, XvImagePtr,
 /* ScreenRec fields */
 
 static Bool KdXVDestroyWindow(WindowPtr pWin);
-static void KdXVWindowExposures(WindowPtr pWin, RegionPtr r1, RegionPtr r2);
+static void KdXVWindowExposures(WindowPtr pWin, RegionPtr r1);
 static void KdXVClipNotify(WindowPtr pWin, int dx, int dy);
 static Bool KdXVCloseScreen(ScreenPtr);
 
@@ -822,7 +822,7 @@ KdXVDestroyWindow(WindowPtr pWin)
 }
 
 static void
-KdXVWindowExposures(WindowPtr pWin, RegionPtr reg1, RegionPtr reg2)
+KdXVWindowExposures(WindowPtr pWin, RegionPtr reg1)
 {
     ScreenPtr pScreen = pWin->drawable.pScreen;
     KdXVScreenPtr ScreenPriv = GET_KDXV_SCREEN(pScreen);
@@ -834,7 +834,7 @@ KdXVWindowExposures(WindowPtr pWin, RegionPtr reg1, RegionPtr reg2)
     AreasExposed = (WinPriv && reg1 && RegionNotEmpty(reg1));
 
     pScreen->WindowExposures = ScreenPriv->WindowExposures;
-    (*pScreen->WindowExposures) (pWin, reg1, reg2);
+    (*pScreen->WindowExposures) (pWin, reg1);
     pScreen->WindowExposures = KdXVWindowExposures;
 
     /* filter out XClearWindow/Area */
diff --git a/hw/xfree86/common/xf86xv.c b/hw/xfree86/common/xf86xv.c
index 0e67690..5ef5de1 100644
--- a/hw/xfree86/common/xf86xv.c
+++ b/hw/xfree86/common/xf86xv.c
@@ -84,7 +84,7 @@ static int xf86XVQueryImageAttributes(XvPortPtr, XvImagePtr,
 /* ScreenRec fields */
 
 static Bool xf86XVDestroyWindow(WindowPtr pWin);
-static void xf86XVWindowExposures(WindowPtr pWin, RegionPtr r1, RegionPtr r2);
+static void xf86XVWindowExposures(WindowPtr pWin, RegionPtr r1);
 static void xf86XVPostValidateTree(WindowPtr pWin, WindowPtr pLayerWin,
                                    VTKind kind);
 static void xf86XVClipNotify(WindowPtr pWin, int dx, int dy);
@@ -1048,7 +1048,7 @@ xf86XVPostValidateTree(WindowPtr pWin, WindowPtr pLayerWin, VTKind kind)
 }
 
 static void
-xf86XVWindowExposures(WindowPtr pWin, RegionPtr reg1, RegionPtr reg2)
+xf86XVWindowExposures(WindowPtr pWin, RegionPtr reg1)
 {
     ScreenPtr pScreen = pWin->drawable.pScreen;
     XF86XVScreenPtr ScreenPriv = GET_XF86XV_SCREEN(pScreen);
@@ -1059,7 +1059,7 @@ xf86XVWindowExposures(WindowPtr pWin, RegionPtr reg1, RegionPtr reg2)
     AreasExposed = (WinPriv && reg1 && RegionNotEmpty(reg1));
 
     pScreen->WindowExposures = ScreenPriv->WindowExposures;
-    (*pScreen->WindowExposures) (pWin, reg1, reg2);
+    (*pScreen->WindowExposures) (pWin, reg1);
     pScreen->WindowExposures = xf86XVWindowExposures;
 
     /* filter out XClearWindow/Area */
diff --git a/hw/xfree86/dri/dri.c b/hw/xfree86/dri/dri.c
index 3f2f6a9..5077c7c 100644
--- a/hw/xfree86/dri/dri.c
+++ b/hw/xfree86/dri/dri.c
@@ -1828,7 +1828,7 @@ DRIGetContextStore(DRIContextPrivPtr context)
 }
 
 void
-DRIWindowExposures(WindowPtr pWin, RegionPtr prgn, RegionPtr bsreg)
+DRIWindowExposures(WindowPtr pWin, RegionPtr prgn)
 {
     ScreenPtr pScreen = pWin->drawable.pScreen;
     DRIScreenPrivPtr pDRIPriv = DRI_SCREEN_PRIV(pScreen);
@@ -1846,7 +1846,7 @@ DRIWindowExposures(WindowPtr pWin, RegionPtr prgn, RegionPtr bsreg)
         pScreen->WindowExposures = pDRIPriv->wrap.WindowExposures;
 
         /* call lower layers */
-        (*pScreen->WindowExposures) (pWin, prgn, bsreg);
+        (*pScreen->WindowExposures) (pWin, prgn);
 
         /* rewrap */
         pDRIPriv->wrap.WindowExposures = pScreen->WindowExposures;
diff --git a/hw/xfree86/dri/dri.h b/hw/xfree86/dri/dri.h
index dec6885..1ce0970 100644
--- a/hw/xfree86/dri/dri.h
+++ b/hw/xfree86/dri/dri.h
@@ -280,8 +280,7 @@ extern _X_EXPORT void DRISwapContext(int drmFD, void *oldctx, void *newctx);
 
 extern _X_EXPORT void *DRIGetContextStore(DRIContextPrivPtr context);
 
-extern _X_EXPORT void DRIWindowExposures(WindowPtr pWin,
-                                         RegionPtr prgn, RegionPtr bsreg);
+extern _X_EXPORT void DRIWindowExposures(WindowPtr pWin, RegionPtr prgn);
 
 extern _X_EXPORT Bool DRIDestroyWindow(WindowPtr pWin);
 
diff --git a/hw/xnest/Window.c b/hw/xnest/Window.c
index fc87e82..8d9c672 100644
--- a/hw/xnest/Window.c
+++ b/hw/xnest/Window.c
@@ -386,7 +386,7 @@ xnestWindowExposurePredicate(Display * dpy, XEvent * event, XPointer ptr)
 }
 
 void
-xnestWindowExposures(WindowPtr pWin, RegionPtr pRgn, RegionPtr other_exposed)
+xnestWindowExposures(WindowPtr pWin, RegionPtr pRgn)
 {
     XEvent event;
     Window window;
@@ -410,7 +410,7 @@ xnestWindowExposures(WindowPtr pWin, RegionPtr pRgn, RegionPtr other_exposed)
             XPutBackEvent(xnestDisplay, &event);
     }
 
-    miWindowExposures(pWin, pRgn, other_exposed);
+    miWindowExposures(pWin, pRgn);
 }
 
 void
diff --git a/hw/xnest/XNWindow.h b/hw/xnest/XNWindow.h
index 02b0f3f..6320ede 100644
--- a/hw/xnest/XNWindow.h
+++ b/hw/xnest/XNWindow.h
@@ -66,8 +66,7 @@ Bool xnestRealizeWindow(WindowPtr pWin);
 Bool xnestUnrealizeWindow(WindowPtr pWin);
 void xnestCopyWindow(WindowPtr pWin, xPoint oldOrigin, RegionPtr oldRegion);
 void xnestClipNotify(WindowPtr pWin, int dx, int dy);
-void xnestWindowExposures(WindowPtr pWin, RegionPtr pRgn,
-                          RegionPtr other_exposed);
+void xnestWindowExposures(WindowPtr pWin, RegionPtr pRgn);
 void xnestSetShape(WindowPtr pWin, int kind);
 void xnestShapeWindow(WindowPtr pWin);
 
diff --git a/include/scrnintstr.h b/include/scrnintstr.h
index 6955e77..7331ec1 100644
--- a/include/scrnintstr.h
+++ b/include/scrnintstr.h
@@ -155,8 +155,7 @@ typedef void (*PostValidateTreeProcPtr) (WindowPtr /*pParent */ ,
                                          VTKind /*kind */ );
 
 typedef void (*WindowExposuresProcPtr) (WindowPtr /*pWindow */ ,
-                                        RegionPtr /*prgn */ ,
-                                        RegionPtr /*other_exposed */ );
+                                        RegionPtr /*prgn */);
 
 typedef void (*CopyWindowProcPtr) (WindowPtr /*pWindow */ ,
                                    DDXPointRec /*ptOldOrg */ ,
diff --git a/mi/mi.h b/mi/mi.h
index d5a5ba3..4b5e862 100644
--- a/mi/mi.h
+++ b/mi/mi.h
@@ -247,9 +247,7 @@ extern _X_EXPORT void miSendExposures(WindowPtr /*pWin */ ,
     );
 
 extern _X_EXPORT void miWindowExposures(WindowPtr /*pWin */ ,
-                                        RegionPtr /*prgn */ ,
-                                        RegionPtr       /*other_exposed */
-    );
+                                        RegionPtr /*prgn */);
 
 extern _X_EXPORT void miPaintWindow(WindowPtr /*pWin */ ,
                                     RegionPtr /*prgn */ ,
diff --git a/mi/miexpose.c b/mi/miexpose.c
index 198c433..23987fa 100644
--- a/mi/miexpose.c
+++ b/mi/miexpose.c
@@ -421,12 +421,11 @@ miSendExposures(WindowPtr pWin, RegionPtr pRgn, int dx, int dy)
 }
 
 void
-miWindowExposures(WindowPtr pWin, RegionPtr prgn, RegionPtr other_exposed)
+miWindowExposures(WindowPtr pWin, RegionPtr prgn)
 {
     RegionPtr exposures = prgn;
 
-    if ((prgn && !RegionNil(prgn)) ||
-        (exposures && !RegionNil(exposures)) || other_exposed) {
+    if ((prgn && !RegionNil(prgn)) || (exposures && !RegionNil(exposures))) {
         RegionRec expRec;
         int clientInterested;
 
@@ -435,14 +434,6 @@ miWindowExposures(WindowPtr pWin, RegionPtr prgn, RegionPtr other_exposed)
          */
         clientInterested =
             (pWin->eventMask | wOtherEventMasks(pWin)) & ExposureMask;
-        if (other_exposed) {
-            if (exposures) {
-                RegionUnion(other_exposed, exposures, other_exposed);
-                if (exposures != prgn)
-                    RegionDestroy(exposures);
-            }
-            exposures = other_exposed;
-        }
         if (clientInterested && exposures &&
             (RegionNumRects(exposures) > RECTLIMIT)) {
             /*
@@ -474,7 +465,7 @@ miWindowExposures(WindowPtr pWin, RegionPtr prgn, RegionPtr other_exposed)
         if (exposures == &expRec) {
             RegionUninit(exposures);
         }
-        else if (exposures && exposures != prgn && exposures != other_exposed)
+        else if (exposures && exposures != prgn)
             RegionDestroy(exposures);
         if (prgn)
             RegionEmpty(prgn);
diff --git a/mi/mioverlay.c b/mi/mioverlay.c
index 7f502fa..f894e2b 100644
--- a/mi/mioverlay.c
+++ b/mi/mioverlay.c
@@ -79,7 +79,7 @@ static void miOverlayMarkUnrealizedWindow(WindowPtr, WindowPtr, Bool);
 static int miOverlayValidateTree(WindowPtr, WindowPtr, VTKind);
 static void miOverlayHandleExposures(WindowPtr);
 static void miOverlayMoveWindow(WindowPtr, int, int, WindowPtr, VTKind);
-static void miOverlayWindowExposures(WindowPtr, RegionPtr, RegionPtr);
+static void miOverlayWindowExposures(WindowPtr, RegionPtr);
 static void miOverlayResizeWindow(WindowPtr, int, int, unsigned int,
                                   unsigned int, WindowPtr);
 static void miOverlayClearToBackground(WindowPtr, int, int, int, int, Bool);
@@ -827,7 +827,7 @@ miOverlayHandleExposures(WindowPtr pWin)
     miOverlayScreenPtr pPriv = MIOVERLAY_GET_SCREEN_PRIVATE(pScreen);
     WindowPtr pChild;
     ValidatePtr val;
-    void (*WindowExposures) (WindowPtr, RegionPtr, RegionPtr);
+    WindowExposuresProcPtr WindowExposures;
 
     WindowExposures = pWin->drawable.pScreen->WindowExposures;
     if (pPriv->underlayMarked) {
@@ -849,8 +849,7 @@ miOverlayHandleExposures(WindowPtr pWin)
                     }
                     RegionUninit(&mival->borderExposed);
 
-                    (*WindowExposures) (pTree->pWin, &mival->exposed,
-                                        NullRegion);
+                    (*WindowExposures) (pTree->pWin, &mival->exposed);
                     RegionUninit(&mival->exposed);
                 }
                 free(mival);
@@ -886,7 +885,7 @@ miOverlayHandleExposures(WindowPtr pWin)
                 if (RegionNotEmpty(&val->after.borderExposed)) {
                     miPaintWindow(pChild, &val->after.borderExposed, PW_BORDER);
                 }
-                (*WindowExposures) (pChild, &val->after.exposed, NullRegion);
+                (*WindowExposures) (pChild, &val->after.exposed);
             }
             RegionUninit(&val->after.borderExposed);
             RegionUninit(&val->after.exposed);
@@ -980,26 +979,16 @@ miOverlayMoveWindow(WindowPtr pWin,
 #endif
 
 static void
-miOverlayWindowExposures(WindowPtr pWin,
-                         RegionPtr prgn, RegionPtr other_exposed)
+miOverlayWindowExposures(WindowPtr pWin, RegionPtr prgn)
 {
     RegionPtr exposures = prgn;
 
-    if ((prgn && !RegionNil(prgn)) ||
-        (exposures && !RegionNil(exposures)) || other_exposed) {
+    if ((prgn && !RegionNil(prgn)) || (exposures && !RegionNil(exposures))) {
         RegionRec expRec;
         int clientInterested;
 
         clientInterested = (pWin->eventMask | wOtherEventMasks(pWin)) &
             ExposureMask;
-        if (other_exposed) {
-            if (exposures) {
-                RegionUnion(other_exposed, exposures, other_exposed);
-                if (exposures != prgn)
-                    RegionDestroy(exposures);
-            }
-            exposures = other_exposed;
-        }
         if (clientInterested && exposures &&
             (RegionNumRects(exposures) > RECTLIMIT)) {
             ScreenPtr pScreen = pWin->drawable.pScreen;
@@ -1035,7 +1024,7 @@ miOverlayWindowExposures(WindowPtr pWin,
         if (exposures == &expRec) {
             RegionUninit(exposures);
         }
-        else if (exposures && exposures != prgn && exposures != other_exposed)
+        else if (exposures && exposures != prgn)
             RegionDestroy(exposures);
         if (prgn)
             RegionEmpty(prgn);
@@ -1592,7 +1581,6 @@ miOverlayClearToBackground(WindowPtr pWin,
     miOverlayTreePtr pTree = MIOVERLAY_GET_WINDOW_TREE(pWin);
     BoxRec box;
     RegionRec reg;
-    RegionPtr pBSReg = NullRegion;
     ScreenPtr pScreen = pWin->drawable.pScreen;
     miOverlayScreenPtr pScreenPriv = MIOVERLAY_GET_SCREEN_PRIVATE(pScreen);
     RegionPtr clipList;
@@ -1636,12 +1624,10 @@ miOverlayClearToBackground(WindowPtr pWin,
 
     RegionIntersect(&reg, &reg, clipList);
     if (generateExposures)
-        (*pScreen->WindowExposures) (pWin, &reg, pBSReg);
+        (*pScreen->WindowExposures) (pWin, &reg);
     else if (pWin->backgroundState != None)
         miPaintWindow(pWin, &reg, PW_BACKGROUND);
     RegionUninit(&reg);
-    if (pBSReg)
-        RegionDestroy(pBSReg);
 }
 
 /****************************************************************/
diff --git a/mi/miwindow.c b/mi/miwindow.c
index 82c3513..ba4c9ed 100644
--- a/mi/miwindow.c
+++ b/mi/miwindow.c
@@ -111,7 +111,7 @@ miClearToBackground(WindowPtr pWin,
 
     RegionIntersect(&reg, &reg, &pWin->clipList);
     if (generateExposures)
-        (*pWin->drawable.pScreen->WindowExposures) (pWin, &reg, NULL);
+        (*pWin->drawable.pScreen->WindowExposures) (pWin, &reg);
     else if (pWin->backgroundState != None)
         miPaintWindow(pWin, &reg, PW_BACKGROUND);
     RegionUninit(&reg);
@@ -221,7 +221,7 @@ miHandleValidateExposures(WindowPtr pWin)
             if (RegionNotEmpty(&val->after.borderExposed))
                 miPaintWindow(pChild, &val->after.borderExposed, PW_BORDER);
             RegionUninit(&val->after.borderExposed);
-            (*WindowExposures) (pChild, &val->after.exposed, NullRegion);
+            (*WindowExposures) (pChild, &val->after.exposed);
             RegionUninit(&val->after.exposed);
             free(val);
             pChild->valdata = NULL;
commit aaf5e2d643af590366b2d02ad1c2db05d1fc4131
Author: Eric Anholt <eric at anholt.net>
Date:   Sat Dec 28 11:32:10 2013 -0800

    modesetting: Add support for rendering using glamor.
    
    By default modesetting now tries to enable X acceleration using
    glamor, but falls back to normal shadowfb if GL fails to initialize.
    
    Signed-off-by: Eric Anholt <eric at anholt.net>
    Reviewed-by: Keith Packard <keithp at keithp.com>

diff --git a/hw/xfree86/drivers/modesetting/Makefile.am b/hw/xfree86/drivers/modesetting/Makefile.am
index ca3279e..e6834e2 100644
--- a/hw/xfree86/drivers/modesetting/Makefile.am
+++ b/hw/xfree86/drivers/modesetting/Makefile.am
@@ -28,6 +28,7 @@ AM_CFLAGS = $(DIX_CFLAGS) $(XORG_CFLAGS) $(LIBDRM_CFLAGS) $(UDEV_CFLAGS) $(CWARN
 
 AM_CPPFLAGS = \
 	$(XORG_INCS) \
+	-I$(top_srcdir)/glamor \
 	-I$(srcdir)/../../ddc \
 	-I$(srcdir)/../../i2c \
 	-I$(srcdir)/../../modes \
diff --git a/hw/xfree86/drivers/modesetting/driver.c b/hw/xfree86/drivers/modesetting/driver.c
index c713746..c62147a 100644
--- a/hw/xfree86/drivers/modesetting/driver.c
+++ b/hw/xfree86/drivers/modesetting/driver.c
@@ -61,6 +61,11 @@
 
 #include "driver.h"
 
+#ifdef GLAMOR
+#define GLAMOR_FOR_XORG 1
+#include "glamor.h"
+#endif
+
 static void AdjustFrame(ScrnInfoPtr pScrn, int x, int y);
 static Bool CloseScreen(ScreenPtr pScreen);
 static Bool EnterVT(ScrnInfoPtr pScrn);
@@ -122,12 +127,14 @@ typedef enum {
     OPTION_SW_CURSOR,
     OPTION_DEVICE_PATH,
     OPTION_SHADOW_FB,
+    OPTION_ACCEL_METHOD,
 } modesettingOpts;
 
 static const OptionInfoRec Options[] = {
     {OPTION_SW_CURSOR, "SWcursor", OPTV_BOOLEAN, {0}, FALSE},
     {OPTION_DEVICE_PATH, "kmsdev", OPTV_STRING, {0}, FALSE},
     {OPTION_SHADOW_FB, "ShadowFB", OPTV_BOOLEAN, {0}, FALSE},
+    {OPTION_ACCEL_METHOD, "AccelMethod", OPTV_STRING, {0}, FALSE},
     {-1, NULL, OPTV_NONE, {0}, FALSE}
 };
 
@@ -577,6 +584,43 @@ FreeRec(ScrnInfoPtr pScrn)
 
 }
 
+static void
+try_enable_glamor(ScrnInfoPtr pScrn)
+{
+    modesettingPtr ms = modesettingPTR(pScrn);
+    const char *accel_method_str = xf86GetOptValString(ms->Options,
+                                                       OPTION_ACCEL_METHOD);
+    Bool do_glamor = (!accel_method_str ||
+                      strcmp(accel_method_str, "glamor") == 0);
+
+    ms->glamor = FALSE;
+
+#ifdef GLAMOR
+    if (!do_glamor) {
+        xf86DrvMsg(pScrn->scrnIndex, X_CONFIG, "glamor disabled\n");
+        return;
+    }
+
+    if (xf86LoadSubModule(pScrn, GLAMOR_EGL_MODULE_NAME)) {
+        if (glamor_egl_init(pScrn, ms->fd)) {
+            xf86DrvMsg(pScrn->scrnIndex, X_INFO, "glamor initialized\n");
+            ms->glamor = TRUE;
+        } else {
+            xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
+                       "glamor initialization failed\n");
+        }
+    } else {
+        xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
+                   "Failed to load glamor module.\n");
+    }
+#else
+    if (do_glamor) {
+        xf86DrvMsg(pScrn->scrnIndex, X_INFO,
+                   "No glamor support in the X Server\n");
+    }
+#endif
+}
+
 #ifndef DRM_CAP_CURSOR_WIDTH
 #define DRM_CAP_CURSOR_WIDTH 0x8
 #endif
@@ -594,7 +638,6 @@ PreInit(ScrnInfoPtr pScrn, int flags)
     EntPtr msEnt = NULL;
     char *BusID = NULL;
     const char *devicename;
-    Bool prefer_shadow = TRUE;
     uint64_t value = 0;
     int ret;
     int bppflags;
@@ -732,11 +775,6 @@ PreInit(ScrnInfoPtr pScrn, int flags)
         ms->drmmode.sw_cursor = TRUE;
     }
 
-    ret = drmGetCap(ms->fd, DRM_CAP_DUMB_PREFER_SHADOW, &value);
-    if (!ret) {
-        prefer_shadow = ! !value;
-    }
-
     ms->cursor_width = 64;
     ms->cursor_height = 64;
     ret = drmGetCap(ms->fd, DRM_CAP_CURSOR_WIDTH, &value);
@@ -748,12 +786,26 @@ PreInit(ScrnInfoPtr pScrn, int flags)
         ms->cursor_height = value;
     }
 
-    ms->drmmode.shadow_enable =
-        xf86ReturnOptValBool(ms->Options, OPTION_SHADOW_FB, prefer_shadow);
+    try_enable_glamor(pScrn);
+
+    if (!ms->glamor) {
+        Bool prefer_shadow = TRUE;
+
+        ret = drmGetCap(ms->fd, DRM_CAP_DUMB_PREFER_SHADOW, &value);
+        if (!ret) {
+            prefer_shadow = !!value;
+        }
+
+        ms->drmmode.shadow_enable = xf86ReturnOptValBool(ms->Options,
+                                                         OPTION_SHADOW_FB,
+                                                         prefer_shadow);
+
+        xf86DrvMsg(pScrn->scrnIndex, X_INFO,
+                   "ShadowFB: preferred %s, enabled %s\n",
+                   prefer_shadow ? "YES" : "NO",
+                   ms->drmmode.shadow_enable ? "YES" : "NO");
+    }
 
-    xf86DrvMsg(pScrn->scrnIndex, X_INFO, "ShadowFB: preferred %s, enabled %s\n",
-               prefer_shadow ? "YES" : "NO",
-               ms->drmmode.shadow_enable ? "YES" : "NO");
     if (drmmode_pre_init(pScrn, &ms->drmmode, pScrn->bitsPerPixel / 8) == FALSE) {
         xf86DrvMsg(pScrn->scrnIndex, X_ERROR, "KMS setup failed\n");
         goto fail;
@@ -832,6 +884,20 @@ CreateScreenResources(ScreenPtr pScreen)
     if (!drmmode_set_desired_modes(pScrn, &ms->drmmode))
         return FALSE;
 
+#ifdef GLAMOR
+    if (ms->glamor) {
+        if (!glamor_egl_create_textured_screen_ext(pScreen,
+                                                   ms->drmmode.front_bo->handle,
+                                                   pScrn->displayWidth *
+                                                   pScrn->bitsPerPixel / 8,
+                                                   NULL)) {
+            xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
+                       "glamor_egl_create_textured_screen_ext() failed\n");
+            return FALSE;
+        }
+    }
+#endif
+
     drmmode_uevent_init(pScrn, &ms->drmmode);
 
     if (!ms->drmmode.sw_cursor)
@@ -984,6 +1050,19 @@ ScreenInit(ScreenPtr pScreen, int argc, char **argv)
 
     fbPictureInit(pScreen, NULL, 0);
 
+#ifdef GLAMOR
+    if (ms->glamor) {
+        if (!glamor_init(pScreen,
+                         GLAMOR_USE_EGL_SCREEN |
+                         GLAMOR_USE_SCREEN |
+                         GLAMOR_USE_PICTURE_SCREEN)) {
+            xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
+                       "Failed to initialize glamor at ScreenInit() time.\n");
+            return FALSE;
+        }
+    }
+#endif
+
     if (ms->drmmode.shadow_enable && !msShadowInit(pScreen)) {
         xf86DrvMsg(pScrn->scrnIndex, X_ERROR, "shadow fb init failed\n");
         return FALSE;
diff --git a/hw/xfree86/drivers/modesetting/driver.h b/hw/xfree86/drivers/modesetting/driver.h
index 8a920b9..35f2419 100644
--- a/hw/xfree86/drivers/modesetting/driver.h
+++ b/hw/xfree86/drivers/modesetting/driver.h
@@ -74,6 +74,7 @@ typedef struct _modesettingRec {
     Bool dirty_enabled;
 
     uint32_t cursor_width, cursor_height;
+    Bool glamor;
 } modesettingRec, *modesettingPtr;
 
 #define modesettingPTR(p) ((modesettingPtr)((p)->driverPrivate))
diff --git a/hw/xfree86/drivers/modesetting/modesetting.man b/hw/xfree86/drivers/modesetting/modesetting.man
index 34baa9c..9cb27d7 100644
--- a/hw/xfree86/drivers/modesetting/modesetting.man
+++ b/hw/xfree86/drivers/modesetting/modesetting.man
@@ -47,6 +47,9 @@ The framebuffer device to use. Default: /dev/dri/card0.
 .BI "Option \*qShadowFB\*q \*q" boolean \*q
 Enable or disable use of the shadow framebuffer layer.  Default: on.
 .TP
+.BI "Option \*qAccelMethod\*q \*q" string \*q
+One of \*qglamor\*q or \*qnone\*q.  Default: glamor
+.TP
 .SH "SEE ALSO"
 __xservername__(__appmansuffix__), __xconfigfile__(__filemansuffix__), Xserver(__appmansuffix__),
 X(__miscmansuffix__)
commit 6d41bdb23ca92803e3a51dc317d2b80cdb92f43a
Author: Eric Anholt <eric at anholt.net>
Date:   Tue Aug 26 16:59:37 2014 -0700

    modesetting: Deduplicate some scrn setup.
    
    Signed-off-by: Eric Anholt <eric at anholt.net>
    Reviewed-by: Keith Packard <keithp at keithp.com>

diff --git a/hw/xfree86/drivers/modesetting/driver.c b/hw/xfree86/drivers/modesetting/driver.c
index f509a19..c713746 100644
--- a/hw/xfree86/drivers/modesetting/driver.c
+++ b/hw/xfree86/drivers/modesetting/driver.c
@@ -306,6 +306,24 @@ ms_driver_func(ScrnInfoPtr scrn, xorgDriverFuncOp op, void *data)
     }
 }
 
+static void
+ms_setup_scrn_hooks(ScrnInfoPtr scrn)
+{
+    scrn->driverVersion = 1;
+    scrn->driverName = "modesetting";
+    scrn->name = "modeset";
+
+    scrn->Probe = NULL;
+    scrn->PreInit = PreInit;
+    scrn->ScreenInit = ScreenInit;
+    scrn->SwitchMode = SwitchMode;
+    scrn->AdjustFrame = AdjustFrame;
+    scrn->EnterVT = EnterVT;
+    scrn->LeaveVT = LeaveVT;
+    scrn->FreeScreen = FreeScreen;
+    scrn->ValidMode = ValidMode;
+}
+
 #if XSERVER_LIBPCIACCESS
 static Bool
 ms_pci_probe(DriverPtr driver,
@@ -322,18 +340,7 @@ ms_pci_probe(DriverPtr driver,
 
         devpath = xf86FindOptionValue(devSection->options, "kmsdev");
         if (probe_hw_pci(devpath, dev)) {
-            scrn->driverVersion = 1;
-            scrn->driverName = "modesetting";
-            scrn->name = "modeset";
-            scrn->Probe = NULL;
-            scrn->PreInit = PreInit;
-            scrn->ScreenInit = ScreenInit;
-            scrn->SwitchMode = SwitchMode;
-            scrn->AdjustFrame = AdjustFrame;
-            scrn->EnterVT = EnterVT;
-            scrn->LeaveVT = LeaveVT;
-            scrn->FreeScreen = FreeScreen;
-            scrn->ValidMode = ValidMode;
+            ms_setup_scrn_hooks(scrn);
 
             xf86DrvMsg(scrn->scrnIndex, X_CONFIG,
                        "claimed PCI slot %d@%d:%d:%d\n",
@@ -365,16 +372,8 @@ ms_platform_probe(DriverPtr driver,
         scrn = xf86AllocateScreen(driver, scr_flags);
         xf86AddEntityToScreen(scrn, entity_num);
 
-        scrn->driverName = "modesetting";
-        scrn->name = "modesetting";
-        scrn->PreInit = PreInit;
-        scrn->ScreenInit = ScreenInit;
-        scrn->SwitchMode = SwitchMode;
-        scrn->AdjustFrame = AdjustFrame;
-        scrn->EnterVT = EnterVT;
-        scrn->LeaveVT = LeaveVT;
-        scrn->FreeScreen = FreeScreen;
-        scrn->ValidMode = ValidMode;
+        ms_setup_scrn_hooks(scrn);
+
         xf86DrvMsg(scrn->scrnIndex, X_INFO,
                    "using drv %s\n", path ? path : "default device");
     }
@@ -416,18 +415,8 @@ Probe(DriverPtr drv, int flags)
 
         if (scrn) {
             foundScreen = TRUE;
-            scrn->driverVersion = 1;
-            scrn->driverName = "modesetting";
-            scrn->name = "modesetting";
+            ms_setup_scrn_hooks(scrn);
             scrn->Probe = Probe;
-            scrn->PreInit = PreInit;
-            scrn->ScreenInit = ScreenInit;
-            scrn->SwitchMode = SwitchMode;
-            scrn->AdjustFrame = AdjustFrame;
-            scrn->EnterVT = EnterVT;
-            scrn->LeaveVT = LeaveVT;
-            scrn->FreeScreen = FreeScreen;
-            scrn->ValidMode = ValidMode;
 
             xf86DrvMsg(scrn->scrnIndex, X_INFO,
                        "using %s\n", dev ? dev : "default device");
commit 20a3b482191711bc15be0410ccc3651924271349
Author: Eric Anholt <eric at anholt.net>
Date:   Wed Oct 8 00:41:13 2014 -0700

    modesetting: Fix some weird formatting after x-indent-all.sh.
    
    Signed-off-by: Eric Anholt <eric at anholt.net>
    Reviewed-by: Keith Packard <keithp at keithp.com>

diff --git a/hw/xfree86/drivers/modesetting/drmmode_display.c b/hw/xfree86/drivers/modesetting/drmmode_display.c
index ca02a4d..d959837 100644
--- a/hw/xfree86/drivers/modesetting/drmmode_display.c
+++ b/hw/xfree86/drivers/modesetting/drmmode_display.c
@@ -976,7 +976,9 @@ static const xf86OutputFuncsRec drmmode_output_funcs = {
     .destroy = drmmode_output_destroy
 };
 
-static int subpixel_conv_table[7] = { 0, SubPixelUnknown,
+static int subpixel_conv_table[7] = {
+    0,
+    SubPixelUnknown,
     SubPixelHorizontalRGB,
     SubPixelHorizontalBGR,
     SubPixelVerticalRGB,
@@ -984,7 +986,8 @@ static int subpixel_conv_table[7] = { 0, SubPixelUnknown,
     SubPixelNone
 };
 
-static const char *const output_names[] = { "None",
+static const char *const output_names[] = {
+    "None",
     "VGA",
     "DVI",
     "DVI",
commit 3119acdab9eecff90b8fd9a265e2a456e7bc8779
Author: Eric Anholt <eric at anholt.net>
Date:   Wed Oct 8 00:39:15 2014 -0700

    modesetting: Run x-indent-all.sh.
    
    As I was editing code, the top-level .dir-locals.el was making my new
    stuff conflict with the existing style.  Make it consistently use the
    xorg style, instead.
    
    Signed-off-by: Eric Anholt <eric at anholt.net>
    Reviewed-by: Keith Packard <keithp at keithp.com>

diff --git a/hw/xfree86/drivers/modesetting/driver.c b/hw/xfree86/drivers/modesetting/driver.c
index adfb69c..f509a19 100644
--- a/hw/xfree86/drivers/modesetting/driver.c
+++ b/hw/xfree86/drivers/modesetting/driver.c
@@ -66,8 +66,8 @@ static Bool CloseScreen(ScreenPtr pScreen);
 static Bool EnterVT(ScrnInfoPtr pScrn);
 static void Identify(int flags);
 static const OptionInfoRec *AvailableOptions(int chipid, int busid);
-static ModeStatus ValidMode(ScrnInfoPtr pScrn, DisplayModePtr mode, Bool verbose,
-			    int flags);
+static ModeStatus ValidMode(ScrnInfoPtr pScrn, DisplayModePtr mode,
+                            Bool verbose, int flags);
 static void FreeScreen(ScrnInfoPtr pScrn);
 static void LeaveVT(ScrnInfoPtr pScrn);
 static Bool SwitchMode(ScrnInfoPtr pScrn, DisplayModePtr mode);
@@ -76,26 +76,25 @@ static Bool PreInit(ScrnInfoPtr pScrn, int flags);
 
 static Bool Probe(DriverPtr drv, int flags);
 static Bool ms_pci_probe(DriverPtr driver,
-			 int entity_num, struct pci_device *device,
-			 intptr_t match_data);
-static Bool ms_driver_func(ScrnInfoPtr scrn, xorgDriverFuncOp op,
-			   void *data);
+                         int entity_num, struct pci_device *device,
+                         intptr_t match_data);
+static Bool ms_driver_func(ScrnInfoPtr scrn, xorgDriverFuncOp op, void *data);
 
 #ifdef XSERVER_LIBPCIACCESS
 static const struct pci_id_match ms_device_match[] = {
     {
-	PCI_MATCH_ANY, PCI_MATCH_ANY, PCI_MATCH_ANY, PCI_MATCH_ANY,
-	0x00030000, 0x00ff0000, 0
-    },
+     PCI_MATCH_ANY, PCI_MATCH_ANY, PCI_MATCH_ANY, PCI_MATCH_ANY,
+     0x00030000, 0x00ff0000, 0},
 
-    { 0, 0, 0 },
+    {0, 0, 0},
 };
 #endif
 
 #ifdef XSERVER_PLATFORM_BUS
 static Bool ms_platform_probe(DriverPtr driver,
-                          int entity_num, int flags, struct xf86_platform_device *device,
-			  intptr_t match_data);
+                              int entity_num, int flags,
+                              struct xf86_platform_device *device,
+                              intptr_t match_data);
 #endif
 
 _X_EXPORT DriverRec modesetting = {
@@ -115,12 +114,11 @@ _X_EXPORT DriverRec modesetting = {
 };
 
 static SymTabRec Chipsets[] = {
-    {0, "kms" },
+    {0, "kms"},
     {-1, NULL}
 };
 
-typedef enum
-{
+typedef enum {
     OPTION_SW_CURSOR,
     OPTION_DEVICE_PATH,
     OPTION_SHADOW_FB,
@@ -128,8 +126,8 @@ typedef enum
 
 static const OptionInfoRec Options[] = {
     {OPTION_SW_CURSOR, "SWcursor", OPTV_BOOLEAN, {0}, FALSE},
-    {OPTION_DEVICE_PATH, "kmsdev", OPTV_STRING, {0}, FALSE },
-    {OPTION_SHADOW_FB, "ShadowFB", OPTV_BOOLEAN, {0}, FALSE },
+    {OPTION_DEVICE_PATH, "kmsdev", OPTV_STRING, {0}, FALSE},
+    {OPTION_SHADOW_FB, "ShadowFB", OPTV_BOOLEAN, {0}, FALSE},
     {-1, NULL, OPTV_NONE, {0}, FALSE}
 };
 
@@ -155,25 +153,26 @@ static XF86ModuleVersionInfo VersRec = {
 _X_EXPORT XF86ModuleData modesettingModuleData = { &VersRec, Setup, NULL };
 
 static void *
-Setup(void * module, void * opts, int *errmaj, int *errmin)
+Setup(void *module, void *opts, int *errmaj, int *errmin)
 {
     static Bool setupDone = 0;
 
     /* This module should be loaded only once, but check to be sure.
      */
     if (!setupDone) {
-	setupDone = 1;
-	xf86AddDriver(&modesetting, module, HaveDriverFuncs);
-
-	/*
-	 * The return value must be non-NULL on success even though there
-	 * is no TearDownProc.
-	 */
-	return (void *) 1;
-    } else {
-	if (errmaj)
-	    *errmaj = LDR_ONCEONLY;
-	return NULL;
+        setupDone = 1;
+        xf86AddDriver(&modesetting, module, HaveDriverFuncs);
+
+        /*
+         * The return value must be non-NULL on success even though there
+         * is no TearDownProc.
+         */
+        return (void *) 1;
+    }
+    else {
+        if (errmaj)
+            *errmaj = LDR_ONCEONLY;
+        return NULL;
     }
 }
 
@@ -181,28 +180,31 @@ static void
 Identify(int flags)
 {
     xf86PrintChipsets("modesetting", "Driver for Modesetting Kernel Drivers",
-		      Chipsets);
+                      Chipsets);
 }
 
-static int open_hw(const char *dev)
+static int
+open_hw(const char *dev)
 {
     int fd;
+
     if (dev)
-	fd = open(dev, O_RDWR, 0);
+        fd = open(dev, O_RDWR, 0);
     else {
-	dev = getenv("KMSDEVICE");
-	if ((NULL == dev) || ((fd = open(dev, O_RDWR, 0)) == -1)) {
-	    dev = "/dev/dri/card0";
-	    fd = open(dev,O_RDWR, 0);
-	}
+        dev = getenv("KMSDEVICE");
+        if ((NULL == dev) || ((fd = open(dev, O_RDWR, 0)) == -1)) {
+            dev = "/dev/dri/card0";
+            fd = open(dev, O_RDWR, 0);
+        }
     }
     if (fd == -1)
-	xf86DrvMsg(-1, X_ERROR,"open %s: %s\n", dev, strerror(errno));
+        xf86DrvMsg(-1, X_ERROR, "open %s: %s\n", dev, strerror(errno));
 
     return fd;
 }
 
-static int check_outputs(int fd)
+static int
+check_outputs(int fd)
 {
     drmModeResPtr res = drmModeGetResources(fd);
     int ret;
@@ -214,7 +216,8 @@ static int check_outputs(int fd)
     return ret;
 }
 
-static Bool probe_hw(const char *dev, struct xf86_platform_device *platform_dev)
+static Bool
+probe_hw(const char *dev, struct xf86_platform_device *platform_dev)
 {
     int fd;
 
@@ -230,6 +233,7 @@ static Bool probe_hw(const char *dev, struct xf86_platform_device *platform_dev)
     fd = open_hw(dev);
     if (fd != -1) {
         int ret = check_outputs(fd);
+
         close(fd);
         return ret;
     }
@@ -248,15 +252,15 @@ ms_DRICreatePCIBusID(const struct pci_device *dev)
     return busID;
 }
 
-
-static Bool probe_hw_pci(const char *dev, struct pci_device *pdev)
+static Bool
+probe_hw_pci(const char *dev, struct pci_device *pdev)
 {
     int ret = FALSE, fd = open_hw(dev);
     char *id, *devid;
     drmSetVersion sv;
 
     if (fd == -1)
-	return FALSE;
+        return FALSE;
 
     sv.drm_di_major = 1;
     sv.drm_di_minor = 4;
@@ -267,7 +271,6 @@ static Bool probe_hw_pci(const char *dev, struct pci_device *pdev)
         return FALSE;
     }
 
-
     id = drmGetBusid(fd);
     devid = ms_DRICreatePCIBusID(pdev);
 
@@ -279,6 +282,7 @@ static Bool probe_hw_pci(const char *dev, struct pci_device *pdev)
     free(devid);
     return ret;
 }
+
 static const OptionInfoRec *
 AvailableOptions(int chipid, int busid)
 {
@@ -289,55 +293,56 @@ static Bool
 ms_driver_func(ScrnInfoPtr scrn, xorgDriverFuncOp op, void *data)
 {
     xorgHWFlags *flag;
-    
+
     switch (op) {
-	case GET_REQUIRED_HW_INTERFACES:
-	    flag = (CARD32 *)data;
-	    (*flag) = 0;
-	    return TRUE;
-        case SUPPORTS_SERVER_FDS:
-            return TRUE;
-	default:
-	    return FALSE;
+    case GET_REQUIRED_HW_INTERFACES:
+        flag = (CARD32 *) data;
+        (*flag) = 0;
+        return TRUE;
+    case SUPPORTS_SERVER_FDS:
+        return TRUE;
+    default:
+        return FALSE;
     }
 }
 
 #if XSERVER_LIBPCIACCESS
 static Bool
 ms_pci_probe(DriverPtr driver,
-	     int entity_num, struct pci_device *dev, intptr_t match_data)
+             int entity_num, struct pci_device *dev, intptr_t match_data)
 {
     ScrnInfoPtr scrn = NULL;
 
     scrn = xf86ConfigPciEntity(scrn, 0, entity_num, NULL,
-			       NULL, NULL, NULL, NULL, NULL);
+                               NULL, NULL, NULL, NULL, NULL);
     if (scrn) {
-	const char *devpath;
-	GDevPtr devSection = xf86GetDevFromEntity(scrn->entityList[0],
-						  scrn->entityInstanceList[0]);
-
-	devpath = xf86FindOptionValue(devSection->options, "kmsdev");
-	if (probe_hw_pci(devpath, dev)) {
-	    scrn->driverVersion = 1;
-	    scrn->driverName = "modesetting";
-	    scrn->name = "modeset";
-	    scrn->Probe = NULL;
-	    scrn->PreInit = PreInit;
-	    scrn->ScreenInit = ScreenInit;
-	    scrn->SwitchMode = SwitchMode;
-	    scrn->AdjustFrame = AdjustFrame;
-	    scrn->EnterVT = EnterVT;
-	    scrn->LeaveVT = LeaveVT;
-	    scrn->FreeScreen = FreeScreen;
-	    scrn->ValidMode = ValidMode;
-
-	    xf86DrvMsg(scrn->scrnIndex, X_CONFIG,
-		       "claimed PCI slot %d@%d:%d:%d\n", 
-		       dev->bus, dev->domain, dev->dev, dev->func);
-	    xf86DrvMsg(scrn->scrnIndex, X_INFO,
-		       "using %s\n", devpath ? devpath : "default device");
-	} else
-	    scrn = NULL;
+        const char *devpath;
+        GDevPtr devSection = xf86GetDevFromEntity(scrn->entityList[0],
+                                                  scrn->entityInstanceList[0]);
+
+        devpath = xf86FindOptionValue(devSection->options, "kmsdev");
+        if (probe_hw_pci(devpath, dev)) {
+            scrn->driverVersion = 1;
+            scrn->driverName = "modesetting";
+            scrn->name = "modeset";
+            scrn->Probe = NULL;
+            scrn->PreInit = PreInit;
+            scrn->ScreenInit = ScreenInit;
+            scrn->SwitchMode = SwitchMode;
+            scrn->AdjustFrame = AdjustFrame;
+            scrn->EnterVT = EnterVT;
+            scrn->LeaveVT = LeaveVT;
+            scrn->FreeScreen = FreeScreen;
+            scrn->ValidMode = ValidMode;
+
+            xf86DrvMsg(scrn->scrnIndex, X_CONFIG,
+                       "claimed PCI slot %d@%d:%d:%d\n",
+                       dev->bus, dev->domain, dev->dev, dev->func);
+            xf86DrvMsg(scrn->scrnIndex, X_INFO,
+                       "using %s\n", devpath ? devpath : "default device");
+        }
+        else
+            scrn = NULL;
     }
     return scrn != NULL;
 }
@@ -346,14 +351,15 @@ ms_pci_probe(DriverPtr driver,
 #ifdef XSERVER_PLATFORM_BUS
 static Bool
 ms_platform_probe(DriverPtr driver,
-              int entity_num, int flags, struct xf86_platform_device *dev, intptr_t match_data)
+                  int entity_num, int flags, struct xf86_platform_device *dev,
+                  intptr_t match_data)
 {
     ScrnInfoPtr scrn = NULL;
     const char *path = xf86_platform_device_odev_attributes(dev)->path;
     int scr_flags = 0;
 
     if (flags & PLATFORM_PROBE_GPU_SCREEN)
-            scr_flags = XF86_ALLOCATE_GPU_SCREEN;
+        scr_flags = XF86_ALLOCATE_GPU_SCREEN;
 
     if (probe_hw(path, dev)) {
         scrn = xf86AllocateScreen(driver, scr_flags);
@@ -388,44 +394,44 @@ Probe(DriverPtr drv, int flags)
 
     /* For now, just bail out for PROBE_DETECT. */
     if (flags & PROBE_DETECT)
-	return FALSE;
+        return FALSE;
 
     /*
      * Find the config file Device sections that match this
      * driver, and return if there are none.
      */
     if ((numDevSections = xf86MatchDevice("modesetting", &devSections)) <= 0) {
-	return FALSE;
+        return FALSE;
     }
 
     for (i = 0; i < numDevSections; i++) {
 
-	dev = xf86FindOptionValue(devSections[i]->options,"kmsdev");
-	if (probe_hw(dev, NULL)) {
-	    int entity;
-	    entity = xf86ClaimFbSlot(drv, 0, devSections[i], TRUE);
-	    scrn = xf86ConfigFbEntity(scrn, 0, entity,
-				  NULL, NULL, NULL, NULL);
-	}
-
-	if (scrn) {
-	    foundScreen = TRUE;
-	    scrn->driverVersion = 1;
-	    scrn->driverName = "modesetting";
-	    scrn->name = "modesetting";
-	    scrn->Probe = Probe;
-	    scrn->PreInit = PreInit;
-	    scrn->ScreenInit = ScreenInit;
-	    scrn->SwitchMode = SwitchMode;
-	    scrn->AdjustFrame = AdjustFrame;
-	    scrn->EnterVT = EnterVT;
-	    scrn->LeaveVT = LeaveVT;
-	    scrn->FreeScreen = FreeScreen;
-	    scrn->ValidMode = ValidMode;
-
-	    xf86DrvMsg(scrn->scrnIndex, X_INFO,
-			   "using %s\n", dev ? dev : "default device");
-	}
+        dev = xf86FindOptionValue(devSections[i]->options, "kmsdev");
+        if (probe_hw(dev, NULL)) {
+            int entity;
+
+            entity = xf86ClaimFbSlot(drv, 0, devSections[i], TRUE);
+            scrn = xf86ConfigFbEntity(scrn, 0, entity, NULL, NULL, NULL, NULL);
+        }
+
+        if (scrn) {
+            foundScreen = TRUE;
+            scrn->driverVersion = 1;
+            scrn->driverName = "modesetting";
+            scrn->name = "modesetting";
+            scrn->Probe = Probe;
+            scrn->PreInit = PreInit;
+            scrn->ScreenInit = ScreenInit;
+            scrn->SwitchMode = SwitchMode;
+            scrn->AdjustFrame = AdjustFrame;
+            scrn->EnterVT = EnterVT;
+            scrn->LeaveVT = LeaveVT;
+            scrn->FreeScreen = FreeScreen;
+            scrn->ValidMode = ValidMode;
+
+            xf86DrvMsg(scrn->scrnIndex, X_INFO,
+                       "using %s\n", dev ? dev : "default device");
+        }
     }
 
     free(devSections);
@@ -437,51 +443,51 @@ static Bool
 GetRec(ScrnInfoPtr pScrn)
 {
     if (pScrn->driverPrivate)
-	return TRUE;
+        return TRUE;
 
     pScrn->driverPrivate = xnfcalloc(sizeof(modesettingRec), 1);
 
     return TRUE;
 }
 
-static int dispatch_dirty_region(ScrnInfoPtr scrn,
-				 PixmapPtr pixmap,
-				 DamagePtr damage,
-				 int fb_id)
+static int
+dispatch_dirty_region(ScrnInfoPtr scrn,
+                      PixmapPtr pixmap, DamagePtr damage, int fb_id)
 {
     modesettingPtr ms = modesettingPTR(scrn);
     RegionPtr dirty = DamageRegion(damage);
     unsigned num_cliprects = REGION_NUM_RECTS(dirty);
 
     if (num_cliprects) {
-	drmModeClip *clip = malloc(num_cliprects * sizeof(drmModeClip));
-	BoxPtr rect = REGION_RECTS(dirty);
-	int i, ret;
-	    
-	if (!clip)
-	    return -ENOMEM;
-
-	/* XXX no need for copy? */
-	for (i = 0; i < num_cliprects; i++, rect++) {
-	    clip[i].x1 = rect->x1;
-	    clip[i].y1 = rect->y1;
-	    clip[i].x2 = rect->x2;
-	    clip[i].y2 = rect->y2;
-	}
-
-	/* TODO query connector property to see if this is needed */
-	ret = drmModeDirtyFB(ms->fd, fb_id, clip, num_cliprects);
-	free(clip);
-	DamageEmpty(damage);
-	if (ret) {
-	    if (ret == -EINVAL)
-		return ret;
-	}
+        drmModeClip *clip = malloc(num_cliprects * sizeof(drmModeClip));
+        BoxPtr rect = REGION_RECTS(dirty);
+        int i, ret;
+
+        if (!clip)
+            return -ENOMEM;
+
+        /* XXX no need for copy? */
+        for (i = 0; i < num_cliprects; i++, rect++) {
+            clip[i].x1 = rect->x1;
+            clip[i].y1 = rect->y1;
+            clip[i].x2 = rect->x2;
+            clip[i].y2 = rect->y2;
+        }
+
+        /* TODO query connector property to see if this is needed */
+        ret = drmModeDirtyFB(ms->fd, fb_id, clip, num_cliprects);
+        free(clip);
+        DamageEmpty(damage);
+        if (ret) {
+            if (ret == -EINVAL)
+                return ret;
+        }
     }
     return 0;
 }
 
-static void dispatch_dirty(ScreenPtr pScreen)
+static void
+dispatch_dirty(ScreenPtr pScreen)
 {
     ScrnInfoPtr scrn = xf86ScreenToScrn(pScreen);
     modesettingPtr ms = modesettingPTR(scrn);
@@ -491,16 +497,18 @@ static void dispatch_dirty(ScreenPtr pScreen)
 
     ret = dispatch_dirty_region(scrn, pixmap, ms->damage, fb_id);
     if (ret == -EINVAL || ret == -ENOSYS) {
-	ms->dirty_enabled = FALSE;
-	DamageUnregister(ms->damage);
-	DamageDestroy(ms->damage);
-	ms->damage = NULL;
-	xf86DrvMsg(scrn->scrnIndex, X_INFO, "Disabling kernel dirty updates, not required.\n");
-	return;
+        ms->dirty_enabled = FALSE;
+        DamageUnregister(ms->damage);
+        DamageDestroy(ms->damage);
+        ms->damage = NULL;
+        xf86DrvMsg(scrn->scrnIndex, X_INFO,
+                   "Disabling kernel dirty updates, not required.\n");
+        return;
     }
 }
 
-static void dispatch_dirty_crtc(ScrnInfoPtr scrn, xf86CrtcPtr crtc)
+static void
+dispatch_dirty_crtc(ScrnInfoPtr scrn, xf86CrtcPtr crtc)
 {
     modesettingPtr ms = modesettingPTR(scrn);
     PixmapPtr pixmap = crtc->randr_crtc->scanout_pixmap;
@@ -516,25 +524,27 @@ static void dispatch_dirty_crtc(ScrnInfoPtr scrn, xf86CrtcPtr crtc)
     }
 }
 
-static void dispatch_slave_dirty(ScreenPtr pScreen)
+static void
+dispatch_slave_dirty(ScreenPtr pScreen)
 {
     ScrnInfoPtr scrn = xf86ScreenToScrn(pScreen);
     xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(scrn);
     int c;
 
     for (c = 0; c < xf86_config->num_crtc; c++) {
-	xf86CrtcPtr crtc = xf86_config->crtc[c];
+        xf86CrtcPtr crtc = xf86_config->crtc[c];
 
-	if (!crtc->randr_crtc)
-	    continue;
-	if (!crtc->randr_crtc->scanout_pixmap)
-	    continue;
+        if (!crtc->randr_crtc)
+            continue;
+        if (!crtc->randr_crtc->scanout_pixmap)
+            continue;
 
-	dispatch_dirty_crtc(scrn, crtc);
+        dispatch_dirty_crtc(scrn, crtc);
     }
 }
 
-static void msBlockHandler(ScreenPtr pScreen, void *pTimeout, void *pReadmask)
+static void
+msBlockHandler(ScreenPtr pScreen, void *pTimeout, void *pReadmask)
 {
     modesettingPtr ms = modesettingPTR(xf86ScreenToScrn(pScreen));
 
@@ -568,7 +578,7 @@ FreeRec(ScrnInfoPtr pScrn)
         else
 #ifdef XF86_PDEV_SERVER_FD
         if (!(ms->pEnt->location.type == BUS_PLATFORM &&
-              (ms->pEnt->location.id.plat->flags & XF86_PDEV_SERVER_FD)))
+                  (ms->pEnt->location.id.plat->flags & XF86_PDEV_SERVER_FD)))
 #endif
             ret = close(ms->fd);
         (void) ret;
@@ -602,38 +612,40 @@ PreInit(ScrnInfoPtr pScrn, int flags)
     int defaultdepth, defaultbpp;
 
     if (pScrn->numEntities != 1)
-	return FALSE;
+        return FALSE;
 
     pEnt = xf86GetEntityInfo(pScrn->entityList[0]);
 
     if (flags & PROBE_DETECT) {
-	return FALSE;
+        return FALSE;
     }
 
     /* Allocate driverPrivate */
     if (!GetRec(pScrn))
-	return FALSE;
+        return FALSE;
 
     ms = modesettingPTR(pScrn);
     ms->SaveGeneration = -1;
     ms->pEnt = pEnt;
 
-    pScrn->displayWidth = 640;	       /* default it */
+    pScrn->displayWidth = 640;  /* default it */
 
     /* Allocate an entity private if necessary */
     if (xf86IsEntityShared(pScrn->entityList[0])) {
-	msEnt = xf86GetEntityPrivate(pScrn->entityList[0],
-				     modesettingEntityIndex)->ptr;
-	ms->entityPrivate = msEnt;
-    } else
-	ms->entityPrivate = NULL;
+        msEnt = xf86GetEntityPrivate(pScrn->entityList[0],
+                                     modesettingEntityIndex)->ptr;
+        ms->entityPrivate = msEnt;
+    }
+    else
+        ms->entityPrivate = NULL;
 
     if (xf86IsEntityShared(pScrn->entityList[0])) {
-	if (xf86IsPrimInitDone(pScrn->entityList[0])) {
-	    /* do something */
-	} else {
-	    xf86SetPrimInitDone(pScrn->entityList[0]);
-	}
+        if (xf86IsPrimInitDone(pScrn->entityList[0])) {
+            /* do something */
+        }
+        else {
+            xf86SetPrimInitDone(pScrn->entityList[0]);
+        }
     }
 
     pScrn->monitor = pScrn->confScreen->monitor;
@@ -644,15 +656,19 @@ PreInit(ScrnInfoPtr pScrn, int flags)
     if (pEnt->location.type == BUS_PLATFORM) {
 #ifdef XF86_PDEV_SERVER_FD
         if (pEnt->location.id.plat->flags & XF86_PDEV_SERVER_FD)
-            ms->fd = xf86_platform_device_odev_attributes(pEnt->location.id.plat)->fd;
+            ms->fd =
+                xf86_platform_device_odev_attributes(pEnt->location.id.plat)->
+                fd;
         else
 #endif
         {
-            char *path = xf86_platform_device_odev_attributes(pEnt->location.id.plat)->path;
+            char *path =
+                xf86_platform_device_odev_attributes(pEnt->location.id.plat)->
+                path;
             ms->fd = open_hw(path);
         }
     }
-    else 
+    else
 #endif
     if (pEnt->location.type == BUS_PCI) {
         ms->PciInfo = xf86GetPciInfoForEntity(ms->pEnt->index);
@@ -670,12 +686,13 @@ PreInit(ScrnInfoPtr pScrn, int flags)
                 );
         }
         ms->fd = drmOpen(NULL, BusID);
-    } else {
+    }
+    else {
         devicename = xf86FindOptionValue(ms->pEnt->device->options, "kmsdev");
         ms->fd = open_hw(devicename);
     }
     if (ms->fd < 0)
-	return FALSE;
+        return FALSE;
 
     ms->drmmode.fd = ms->fd;
 
@@ -689,81 +706,84 @@ PreInit(ScrnInfoPtr pScrn, int flags)
 #endif
     drmmode_get_default_bpp(pScrn, &ms->drmmode, &defaultdepth, &defaultbpp);
     if (defaultdepth == 24 && defaultbpp == 24)
-	    bppflags = SupportConvert32to24 | Support24bppFb;
+        bppflags = SupportConvert32to24 | Support24bppFb;
     else
-	    bppflags = PreferConvert24to32 | SupportConvert24to32 | Support32bppFb;
-    
+        bppflags = PreferConvert24to32 | SupportConvert24to32 | Support32bppFb;
+
     if (!xf86SetDepthBpp
-	(pScrn, defaultdepth, defaultdepth, defaultbpp, bppflags))
-	return FALSE;
+        (pScrn, defaultdepth, defaultdepth, defaultbpp, bppflags))
+        return FALSE;
 
     switch (pScrn->depth) {
     case 15:
     case 16:
     case 24:
-	break;
+        break;
     default:
-	xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
-		   "Given depth (%d) is not supported by the driver\n",
-		   pScrn->depth);
-	return FALSE;
+        xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
+                   "Given depth (%d) is not supported by the driver\n",
+                   pScrn->depth);
+        return FALSE;
     }
     xf86PrintDepthBpp(pScrn);
 
     /* Process the options */
     xf86CollectOptions(pScrn, NULL);
     if (!(ms->Options = malloc(sizeof(Options))))
-	return FALSE;
+        return FALSE;
     memcpy(ms->Options, Options, sizeof(Options));
     xf86ProcessOptions(pScrn->scrnIndex, pScrn->options, ms->Options);
 
     if (!xf86SetWeight(pScrn, defaultWeight, defaultWeight))
-	return FALSE;
+        return FALSE;
     if (!xf86SetDefaultVisual(pScrn, -1))
-	return FALSE;
+        return FALSE;
 
     if (xf86ReturnOptValBool(ms->Options, OPTION_SW_CURSOR, FALSE)) {
-	ms->drmmode.sw_cursor = TRUE;
+        ms->drmmode.sw_cursor = TRUE;
     }
 
     ret = drmGetCap(ms->fd, DRM_CAP_DUMB_PREFER_SHADOW, &value);
     if (!ret) {
-	prefer_shadow = !!value;
+        prefer_shadow = ! !value;
     }
 
     ms->cursor_width = 64;
     ms->cursor_height = 64;
     ret = drmGetCap(ms->fd, DRM_CAP_CURSOR_WIDTH, &value);
     if (!ret) {
-	ms->cursor_width = value;
+        ms->cursor_width = value;
     }
     ret = drmGetCap(ms->fd, DRM_CAP_CURSOR_HEIGHT, &value);
     if (!ret) {
-	ms->cursor_height = value;
+        ms->cursor_height = value;
     }
 
-    ms->drmmode.shadow_enable = xf86ReturnOptValBool(ms->Options, OPTION_SHADOW_FB, prefer_shadow);
+    ms->drmmode.shadow_enable =
+        xf86ReturnOptValBool(ms->Options, OPTION_SHADOW_FB, prefer_shadow);
 
-    xf86DrvMsg(pScrn->scrnIndex, X_INFO, "ShadowFB: preferred %s, enabled %s\n", prefer_shadow ? "YES" : "NO", ms->drmmode.shadow_enable ? "YES" : "NO");
+    xf86DrvMsg(pScrn->scrnIndex, X_INFO, "ShadowFB: preferred %s, enabled %s\n",
+               prefer_shadow ? "YES" : "NO",
+               ms->drmmode.shadow_enable ? "YES" : "NO");
     if (drmmode_pre_init(pScrn, &ms->drmmode, pScrn->bitsPerPixel / 8) == FALSE) {
-	xf86DrvMsg(pScrn->scrnIndex, X_ERROR, "KMS setup failed\n");
-	goto fail;
+        xf86DrvMsg(pScrn->scrnIndex, X_ERROR, "KMS setup failed\n");
+        goto fail;
     }
 
     /*
      * If the driver can do gamma correction, it should call xf86SetGamma() here.
      */
     {
-	Gamma zeros = { 0.0, 0.0, 0.0 };
+        Gamma zeros = { 0.0, 0.0, 0.0 };
 
-	if (!xf86SetGamma(pScrn, zeros)) {
-	    return FALSE;
-	}
+        if (!xf86SetGamma(pScrn, zeros)) {
+            return FALSE;
+        }
     }
 
     if (pScrn->modes == NULL) {
-	xf86DrvMsg(pScrn->scrnIndex, X_ERROR, "No modes.\n");
-	return FALSE;
+        xf86DrvMsg(pScrn->scrnIndex, X_ERROR, "No modes.\n");
+        return FALSE;
     }
 
     pScrn->currentMode = pScrn->modes;
@@ -773,23 +793,23 @@ PreInit(ScrnInfoPtr pScrn, int flags)
 
     /* Load the required sub modules */
     if (!xf86LoadSubModule(pScrn, "fb")) {
-	return FALSE;
+        return FALSE;
     }
 
     if (ms->drmmode.shadow_enable) {
-	if (!xf86LoadSubModule(pScrn, "shadow")) {
-	    return FALSE;
-	}
+        if (!xf86LoadSubModule(pScrn, "shadow")) {
+            return FALSE;
+        }
     }
 
     return TRUE;
-    fail:
+ fail:
     return FALSE;
 }
 
 static void *
 msShadowWindow(ScreenPtr screen, CARD32 row, CARD32 offset, int mode,
-	       CARD32 *size, void *closure)
+               CARD32 *size, void *closure)
 {
     ScrnInfoPtr pScrn = xf86ScreenToScrn(screen);
     modesettingPtr ms = modesettingPTR(pScrn);
@@ -798,7 +818,7 @@ msShadowWindow(ScreenPtr screen, CARD32 row, CARD32 offset, int mode,
     stride = (pScrn->displayWidth * pScrn->bitsPerPixel) / 8;
     *size = stride;
 
-    return ((uint8_t *)ms->drmmode.front_bo->ptr + row * stride + offset);
+    return ((uint8_t *) ms->drmmode.front_bo->ptr + row * stride + offset);
 }
 
 static void
@@ -815,12 +835,13 @@ CreateScreenResources(ScreenPtr pScreen)
     PixmapPtr rootPixmap;
     Bool ret;
     void *pixels;
+
     pScreen->CreateScreenResources = ms->createScreenResources;
     ret = pScreen->CreateScreenResources(pScreen);
     pScreen->CreateScreenResources = CreateScreenResources;
 
     if (!drmmode_set_desired_modes(pScrn, &ms->drmmode))
-      return FALSE;
+        return FALSE;
 
     drmmode_uevent_init(pScrn, &ms->drmmode);
 
@@ -828,33 +849,34 @@ CreateScreenResources(ScreenPtr pScreen)
         drmmode_map_cursor_bos(pScrn, &ms->drmmode);
     pixels = drmmode_map_front_bo(&ms->drmmode);
     if (!pixels)
-	return FALSE;
+        return FALSE;
 
     rootPixmap = pScreen->GetScreenPixmap(pScreen);
 
     if (ms->drmmode.shadow_enable)
-	pixels = ms->drmmode.shadow_fb;
-    
+        pixels = ms->drmmode.shadow_fb;
+
     if (!pScreen->ModifyPixmapHeader(rootPixmap, -1, -1, -1, -1, -1, pixels))
-	FatalError("Couldn't adjust screen pixmap\n");
+        FatalError("Couldn't adjust screen pixmap\n");
 
     if (ms->drmmode.shadow_enable) {
-	if (!shadowAdd(pScreen, rootPixmap, msUpdatePacked,
-		       msShadowWindow, 0, 0))
-	    return FALSE;
+        if (!shadowAdd(pScreen, rootPixmap, msUpdatePacked,
+                       msShadowWindow, 0, 0))
+            return FALSE;
     }
 
     ms->damage = DamageCreate(NULL, NULL, DamageReportNone, TRUE,
                               pScreen, rootPixmap);
 
     if (ms->damage) {
-	DamageRegister(&rootPixmap->drawable, ms->damage);
-	ms->dirty_enabled = TRUE;
-	xf86DrvMsg(pScrn->scrnIndex, X_INFO, "Damage tracking initialized\n");
-    } else {
-	xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
-		   "Failed to create screen damage record\n");
-	return FALSE;
+        DamageRegister(&rootPixmap->drawable, ms->damage);
+        ms->dirty_enabled = TRUE;
+        xf86DrvMsg(pScrn->scrnIndex, X_INFO, "Damage tracking initialized\n");
+    }
+    else {
+        xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
+                   "Failed to create screen damage record\n");
+        return FALSE;
     }
     return ret;
 }
@@ -863,7 +885,7 @@ static Bool
 msShadowInit(ScreenPtr pScreen)
 {
     if (!shadowSetup(pScreen)) {
-	return FALSE;
+        return FALSE;
     }
     return TRUE;
 }
@@ -876,11 +898,11 @@ msSetSharedPixmapBacking(PixmapPtr ppix, void *fd_handle)
     modesettingPtr ms = modesettingPTR(scrn);
     Bool ret;
     int size = ppix->devKind * ppix->drawable.height;
-    int ihandle = (int)(long)fd_handle;
+    int ihandle = (int) (long) fd_handle;
 
     ret = drmmode_SetSlaveBO(ppix, &ms->drmmode, ihandle, ppix->devKind, size);
     if (ret == FALSE)
-	    return ret;
+        return ret;
 
     return TRUE;
 }
@@ -893,7 +915,7 @@ SetMaster(ScrnInfoPtr pScrn)
 
 #ifdef XF86_PDEV_SERVER_FD
     if (ms->pEnt->location.type == BUS_PLATFORM &&
-            (ms->pEnt->location.id.plat->flags & XF86_PDEV_SERVER_FD))
+        (ms->pEnt->location.id.plat->flags & XF86_PDEV_SERVER_FD))
         return TRUE;
 #endif
 
@@ -920,62 +942,64 @@ ScreenInit(ScreenPtr pScreen, int argc, char **argv)
     /* HW dependent - FIXME */
     pScrn->displayWidth = pScrn->virtualX;
     if (!drmmode_create_initial_bos(pScrn, &ms->drmmode))
-	return FALSE;
+        return FALSE;
 
     if (ms->drmmode.shadow_enable) {
-	ms->drmmode.shadow_fb = calloc(1, pScrn->displayWidth * pScrn->virtualY *
-			       ((pScrn->bitsPerPixel + 7) >> 3));
-	if (!ms->drmmode.shadow_fb)
-	    ms->drmmode.shadow_enable = FALSE;
-    }	
-    
+        ms->drmmode.shadow_fb =
+            calloc(1,
+                   pScrn->displayWidth * pScrn->virtualY *
+                   ((pScrn->bitsPerPixel + 7) >> 3));
+        if (!ms->drmmode.shadow_fb)
+            ms->drmmode.shadow_enable = FALSE;
+    }
+
     miClearVisualTypes();
 
     if (!miSetVisualTypes(pScrn->depth,
-			  miGetDefaultVisualMask(pScrn->depth),
-			  pScrn->rgbBits, pScrn->defaultVisual))
-	return FALSE;
+                          miGetDefaultVisualMask(pScrn->depth),
+                          pScrn->rgbBits, pScrn->defaultVisual))
+        return FALSE;
 
     if (!miSetPixmapDepths())
-	return FALSE;
+        return FALSE;
 
-    if (!dixRegisterScreenSpecificPrivateKey(pScreen, &ms->drmmode.pixmapPrivateKeyRec,
-        PRIVATE_PIXMAP, sizeof(msPixmapPrivRec))) { 
-	return FALSE;
+    if (!dixRegisterScreenSpecificPrivateKey
+        (pScreen, &ms->drmmode.pixmapPrivateKeyRec, PRIVATE_PIXMAP,
+         sizeof(msPixmapPrivRec))) {
+        return FALSE;
     }
 
     pScrn->memPhysBase = 0;
     pScrn->fbOffset = 0;
 
     if (!fbScreenInit(pScreen, NULL,
-		      pScrn->virtualX, pScrn->virtualY,
-		      pScrn->xDpi, pScrn->yDpi,
-		      pScrn->displayWidth, pScrn->bitsPerPixel))
-	return FALSE;
+                      pScrn->virtualX, pScrn->virtualY,
+                      pScrn->xDpi, pScrn->yDpi,
+                      pScrn->displayWidth, pScrn->bitsPerPixel))
+        return FALSE;
 
     if (pScrn->bitsPerPixel > 8) {
-	/* Fixup RGB ordering */
-	visual = pScreen->visuals + pScreen->numVisuals;
-	while (--visual >= pScreen->visuals) {
-	    if ((visual->class | DynamicClass) == DirectColor) {
-		visual->offsetRed = pScrn->offset.red;
-		visual->offsetGreen = pScrn->offset.green;
-		visual->offsetBlue = pScrn->offset.blue;
-		visual->redMask = pScrn->mask.red;
-		visual->greenMask = pScrn->mask.green;
-		visual->blueMask = pScrn->mask.blue;
-	    }
-	}
+        /* Fixup RGB ordering */
+        visual = pScreen->visuals + pScreen->numVisuals;
+        while (--visual >= pScreen->visuals) {
+            if ((visual->class | DynamicClass) == DirectColor) {
+                visual->offsetRed = pScrn->offset.red;
+                visual->offsetGreen = pScrn->offset.green;
+                visual->offsetBlue = pScrn->offset.blue;
+                visual->redMask = pScrn->mask.red;
+                visual->greenMask = pScrn->mask.green;
+                visual->blueMask = pScrn->mask.blue;
+            }
+        }
     }
 
     fbPictureInit(pScreen, NULL, 0);
 
     if (ms->drmmode.shadow_enable && !msShadowInit(pScreen)) {
-	xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
-		   "shadow fb init failed\n");
-	return FALSE;
+        xf86DrvMsg(pScrn->scrnIndex, X_ERROR, "shadow fb init failed\n");
+        return FALSE;
     }
-  
+
     ms->createScreenResources = pScreen->CreateScreenResources;
     pScreen->CreateScreenResources = CreateScreenResources;
 
@@ -987,9 +1011,9 @@ ScreenInit(ScreenPtr pScreen, int argc, char **argv)
 
     /* Need to extend HWcursor support to handle mask interleave */
     if (!ms->drmmode.sw_cursor)
-	xf86_cursors_init(pScreen, ms->cursor_width, ms->cursor_height,
-			  HARDWARE_CURSOR_SOURCE_MASK_INTERLEAVE_64 |
-			  HARDWARE_CURSOR_ARGB);
+        xf86_cursors_init(pScreen, ms->cursor_width, ms->cursor_height,
+                          HARDWARE_CURSOR_SOURCE_MASK_INTERLEAVE_64 |
+                          HARDWARE_CURSOR_ARGB);
 
     /* Must force it before EnterVT, so we are in control of VT and
      * later memory should be bound when allocating, e.g rotate_mem */
@@ -1005,15 +1029,15 @@ ScreenInit(ScreenPtr pScreen, int argc, char **argv)
     pScreen->SetSharedPixmapBacking = msSetSharedPixmapBacking;
 
     if (!xf86CrtcScreenInit(pScreen))
-	return FALSE;
+        return FALSE;
 
     if (!miCreateDefColormap(pScreen))
-	return FALSE;
+        return FALSE;
 
     xf86DPMSInit(pScreen, xf86DPMSSet, 0);
 
     if (serverGeneration == 1)
-	xf86ShowUnusedOptions(pScrn->scrnIndex, pScrn->options);
+        xf86ShowUnusedOptions(pScrn->scrnIndex, pScrn->options);
 
     return EnterVT(pScrn);
 }
@@ -1036,13 +1060,14 @@ static void
 LeaveVT(ScrnInfoPtr pScrn)
 {
     modesettingPtr ms = modesettingPTR(pScrn);
+
     xf86_hide_cursors(pScrn);
 
     pScrn->vtSema = FALSE;
 
 #ifdef XF86_PDEV_SERVER_FD
     if (ms->pEnt->location.type == BUS_PLATFORM &&
-            (ms->pEnt->location.id.plat->flags & XF86_PDEV_SERVER_FD))
+        (ms->pEnt->location.id.plat->flags & XF86_PDEV_SERVER_FD))
         return;
 #endif
 
@@ -1062,7 +1087,7 @@ EnterVT(ScrnInfoPtr pScrn)
     SetMaster(pScrn);
 
     if (!drmmode_set_desired_modes(pScrn, &ms->drmmode))
-	return FALSE;
+        return FALSE;
 
     return TRUE;
 }
@@ -1080,15 +1105,15 @@ CloseScreen(ScreenPtr pScreen)
     modesettingPtr ms = modesettingPTR(pScrn);
 
     if (ms->damage) {
-	DamageUnregister(ms->damage);
-	DamageDestroy(ms->damage);
-	ms->damage = NULL;
+        DamageUnregister(ms->damage);
+        DamageDestroy(ms->damage);
+        ms->damage = NULL;
     }
 
     if (ms->drmmode.shadow_enable) {
-	shadowRemove(pScreen, pScreen->GetScreenPixmap(pScreen));
-	free(ms->drmmode.shadow_fb);
-	ms->drmmode.shadow_fb = NULL;
+        shadowRemove(pScreen, pScreen->GetScreenPixmap(pScreen));
+        free(ms->drmmode.shadow_fb);
+        ms->drmmode.shadow_fb = NULL;
     }
     drmmode_uevent_fini(pScrn, &ms->drmmode);
 
diff --git a/hw/xfree86/drivers/modesetting/driver.h b/hw/xfree86/drivers/modesetting/driver.h
index 450b29c..8a920b9 100644
--- a/hw/xfree86/drivers/modesetting/driver.h
+++ b/hw/xfree86/drivers/modesetting/driver.h
@@ -35,16 +35,14 @@
 #include "drmmode_display.h"
 #define DRV_ERROR(msg)	xf86DrvMsg(pScrn->scrnIndex, X_ERROR, msg);
 
-typedef struct
-{
+typedef struct {
     int lastInstance;
     int refCount;
     ScrnInfoPtr pScrn_1;
     ScrnInfoPtr pScrn_2;
 } EntRec, *EntPtr;
 
-typedef struct _modesettingRec
-{
+typedef struct _modesettingRec {
     int fd;
 
     EntPtr entityPrivate;
diff --git a/hw/xfree86/drivers/modesetting/drmmode_display.c b/hw/xfree86/drivers/modesetting/drmmode_display.c
index 9723ccd..ca02a4d 100644
--- a/hw/xfree86/drivers/modesetting/drmmode_display.c
+++ b/hw/xfree86/drivers/modesetting/drmmode_display.c
@@ -49,181 +49,183 @@
 
 #include "driver.h"
 
-static struct dumb_bo *dumb_bo_create(int fd,
-			  const unsigned width, const unsigned height,
-			  const unsigned bpp)
+static struct dumb_bo *
+dumb_bo_create(int fd,
+               const unsigned width, const unsigned height, const unsigned bpp)
 {
-	struct drm_mode_create_dumb arg;
-	struct dumb_bo *bo;
-	int ret;
-
-	bo = calloc(1, sizeof(*bo));
-	if (!bo)
-		return NULL;
-
-	memset(&arg, 0, sizeof(arg));
-	arg.width = width;
-	arg.height = height;
-	arg.bpp = bpp;
-	
-	ret = drmIoctl(fd, DRM_IOCTL_MODE_CREATE_DUMB, &arg);
-	if (ret)
-		goto err_free;
-
-	bo->handle = arg.handle;
-	bo->size = arg.size;
-	bo->pitch = arg.pitch;
-
-	return bo;
+    struct drm_mode_create_dumb arg;
+    struct dumb_bo *bo;
+    int ret;
+
+    bo = calloc(1, sizeof(*bo));
+    if (!bo)
+        return NULL;
+
+    memset(&arg, 0, sizeof(arg));
+    arg.width = width;
+    arg.height = height;
+    arg.bpp = bpp;
+
+    ret = drmIoctl(fd, DRM_IOCTL_MODE_CREATE_DUMB, &arg);
+    if (ret)
+        goto err_free;
+
+    bo->handle = arg.handle;
+    bo->size = arg.size;
+    bo->pitch = arg.pitch;
+
+    return bo;
  err_free:
-	free(bo);
-	return NULL;
+    free(bo);
+    return NULL;
 }
 
-static int dumb_bo_map(int fd, struct dumb_bo *bo)
+static int
+dumb_bo_map(int fd, struct dumb_bo *bo)
 {
-	struct drm_mode_map_dumb arg;
-	int ret;
-	void *map;
+    struct drm_mode_map_dumb arg;
+    int ret;
+    void *map;
 
-	if (bo->ptr) {
-		bo->map_count++;
-		return 0;
-	}
+    if (bo->ptr) {
+        bo->map_count++;
+        return 0;
+    }
 
-	memset(&arg, 0, sizeof(arg));
-	arg.handle = bo->handle;
+    memset(&arg, 0, sizeof(arg));
+    arg.handle = bo->handle;
 
-	ret = drmIoctl(fd, DRM_IOCTL_MODE_MAP_DUMB, &arg);
-	if (ret)
-		return ret;
+    ret = drmIoctl(fd, DRM_IOCTL_MODE_MAP_DUMB, &arg);
+    if (ret)
+        return ret;
 
-	map = mmap(0, bo->size, PROT_READ | PROT_WRITE, MAP_SHARED,
-		   fd, arg.offset);
-	if (map == MAP_FAILED)
-		return -errno;
+    map = mmap(0, bo->size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, arg.offset);
+    if (map == MAP_FAILED)
+        return -errno;
 
-	bo->ptr = map;
-	return 0;
+    bo->ptr = map;
+    return 0;
 }
 
 #if 0
-static int dumb_bo_unmap(int fd, struct dumb_bo *bo)
+static int
+dumb_bo_unmap(int fd, struct dumb_bo *bo)
 {
-	bo->map_count--;
-	return 0;
+    bo->map_count--;
+    return 0;
 }
 #endif
 
-static int dumb_bo_destroy(int fd, struct dumb_bo *bo)
+static int
+dumb_bo_destroy(int fd, struct dumb_bo *bo)
 {
-	struct drm_mode_destroy_dumb arg;
-	int ret;
-	
-	if (bo->ptr) {
-		munmap(bo->ptr, bo->size);
-		bo->ptr = NULL;
-	}
-
-	memset(&arg, 0, sizeof(arg));
-	arg.handle = bo->handle;
-	ret = drmIoctl(fd, DRM_IOCTL_MODE_DESTROY_DUMB, &arg);
-	if (ret)
-		return -errno;
-
-	free(bo);
-	return 0;
+    struct drm_mode_destroy_dumb arg;
+    int ret;
+
+    if (bo->ptr) {
+        munmap(bo->ptr, bo->size);
+        bo->ptr = NULL;
+    }
+
+    memset(&arg, 0, sizeof(arg));
+    arg.handle = bo->handle;
+    ret = drmIoctl(fd, DRM_IOCTL_MODE_DESTROY_DUMB, &arg);
+    if (ret)
+        return -errno;
+
+    free(bo);
+    return 0;
 }
 
-static struct dumb_bo *dumb_get_bo_from_handle(int fd, int handle, int pitch, int size)
+static struct dumb_bo *
+dumb_get_bo_from_handle(int fd, int handle, int pitch, int size)
 {
-  	struct dumb_bo *bo;
-	int ret;
-
-	bo = calloc(1, sizeof(*bo));
-	if (!bo)
-		return NULL;
-
-	ret = drmPrimeFDToHandle(fd, handle, &bo->handle);
-	if (ret) {
-		free(bo);
-		return NULL;
-	}
-	bo->pitch = pitch;
-	bo->size = size;
-	return bo;
+    struct dumb_bo *bo;
+    int ret;
+
+    bo = calloc(1, sizeof(*bo));
+    if (!bo)
+        return NULL;
+
+    ret = drmPrimeFDToHandle(fd, handle, &bo->handle);
+    if (ret) {
+        free(bo);
+        return NULL;
+    }
+    bo->pitch = pitch;
+    bo->size = size;
+    return bo;
 }
 
-Bool drmmode_SetSlaveBO(PixmapPtr ppix,
-			drmmode_ptr drmmode, 
-			int fd_handle, int pitch, int size)
+Bool
+drmmode_SetSlaveBO(PixmapPtr ppix,
+                   drmmode_ptr drmmode, int fd_handle, int pitch, int size)
 {
-    	msPixmapPrivPtr ppriv = msGetPixmapPriv(drmmode, ppix);
+    msPixmapPrivPtr ppriv = msGetPixmapPriv(drmmode, ppix);
 
-	ppriv->backing_bo = dumb_get_bo_from_handle(drmmode->fd, fd_handle, pitch, size);
-	if (!ppriv->backing_bo)
-		return FALSE;
+    ppriv->backing_bo =
+        dumb_get_bo_from_handle(drmmode->fd, fd_handle, pitch, size);
+    if (!ppriv->backing_bo)
+        return FALSE;
 
-	close(fd_handle);
-	return TRUE;
+    close(fd_handle);
+    return TRUE;
 }
 
 static void
-drmmode_ConvertFromKMode(ScrnInfoPtr	scrn,
-		     drmModeModeInfo *kmode,
-		     DisplayModePtr	mode)
+drmmode_ConvertFromKMode(ScrnInfoPtr scrn,
+                         drmModeModeInfo * kmode, DisplayModePtr mode)
 {
-	memset(mode, 0, sizeof(DisplayModeRec));
-	mode->status = MODE_OK;
-
-	mode->Clock = kmode->clock;
-
-	mode->HDisplay = kmode->hdisplay;
-	mode->HSyncStart = kmode->hsync_start;
-	mode->HSyncEnd = kmode->hsync_end;
-	mode->HTotal = kmode->htotal;
-	mode->HSkew = kmode->hskew;
-
-	mode->VDisplay = kmode->vdisplay;
-	mode->VSyncStart = kmode->vsync_start;
-	mode->VSyncEnd = kmode->vsync_end;
-	mode->VTotal = kmode->vtotal;
-	mode->VScan = kmode->vscan;
-
-	mode->Flags = kmode->flags; //& FLAG_BITS;
-	mode->name = strdup(kmode->name);
-
-	if (kmode->type & DRM_MODE_TYPE_DRIVER)
-		mode->type = M_T_DRIVER;
-	if (kmode->type & DRM_MODE_TYPE_PREFERRED)
-		mode->type |= M_T_PREFERRED;
-	xf86SetModeCrtc (mode, scrn->adjustFlags);
+    memset(mode, 0, sizeof(DisplayModeRec));
+    mode->status = MODE_OK;
+
+    mode->Clock = kmode->clock;
+
+    mode->HDisplay = kmode->hdisplay;
+    mode->HSyncStart = kmode->hsync_start;
+    mode->HSyncEnd = kmode->hsync_end;
+    mode->HTotal = kmode->htotal;
+    mode->HSkew = kmode->hskew;
+
+    mode->VDisplay = kmode->vdisplay;
+    mode->VSyncStart = kmode->vsync_start;
+    mode->VSyncEnd = kmode->vsync_end;
+    mode->VTotal = kmode->vtotal;
+    mode->VScan = kmode->vscan;
+
+    mode->Flags = kmode->flags; //& FLAG_BITS;
+    mode->name = strdup(kmode->name);
+
+    if (kmode->type & DRM_MODE_TYPE_DRIVER)
+        mode->type = M_T_DRIVER;
+    if (kmode->type & DRM_MODE_TYPE_PREFERRED)
+        mode->type |= M_T_PREFERRED;
+    xf86SetModeCrtc(mode, scrn->adjustFlags);
 }
 
 static void
-drmmode_ConvertToKMode(ScrnInfoPtr	scrn,
-		     drmModeModeInfo *kmode,
-		     DisplayModePtr	mode)
+drmmode_ConvertToKMode(ScrnInfoPtr scrn,
+                       drmModeModeInfo * kmode, DisplayModePtr mode)
 {
-	memset(kmode, 0, sizeof(*kmode));
-
-	kmode->clock = mode->Clock;
-	kmode->hdisplay = mode->HDisplay;
-	kmode->hsync_start = mode->HSyncStart;
-	kmode->hsync_end = mode->HSyncEnd;
-	kmode->htotal = mode->HTotal;
-	kmode->hskew = mode->HSkew;
-
-	kmode->vdisplay = mode->VDisplay;
-	kmode->vsync_start = mode->VSyncStart;
-	kmode->vsync_end = mode->VSyncEnd;
-	kmode->vtotal = mode->VTotal;
-	kmode->vscan = mode->VScan;
-
-	kmode->flags = mode->Flags; //& FLAG_BITS;
-	if (mode->name)
-		strncpy(kmode->name, mode->name, DRM_DISPLAY_MODE_LEN);
-	kmode->name[DRM_DISPLAY_MODE_LEN-1] = 0;
+    memset(kmode, 0, sizeof(*kmode));
+
+    kmode->clock = mode->Clock;
+    kmode->hdisplay = mode->HDisplay;
+    kmode->hsync_start = mode->HSyncStart;
+    kmode->hsync_end = mode->HSyncEnd;
+    kmode->htotal = mode->HTotal;
+    kmode->hskew = mode->HSkew;
+
+    kmode->vdisplay = mode->VDisplay;
+    kmode->vsync_start = mode->VSyncStart;
+    kmode->vsync_end = mode->VSyncEnd;
+    kmode->vtotal = mode->VTotal;
+    kmode->vscan = mode->VScan;
+
+    kmode->flags = mode->Flags; //& FLAG_BITS;
+    if (mode->name)
+        strncpy(kmode->name, mode->name, DRM_DISPLAY_MODE_LEN);
+    kmode->name[DRM_DISPLAY_MODE_LEN - 1] = 0;
 
 }
 
@@ -231,331 +233,337 @@ static void
 drmmode_crtc_dpms(xf86CrtcPtr crtc, int mode)
 {
 #if 0
-	xf86CrtcConfigPtr   xf86_config = XF86_CRTC_CONFIG_PTR(crtc->scrn);
-//	drmmode_crtc_private_ptr drmmode_crtc = crtc->driver_private;
-//	drmmode_ptr drmmode = drmmode_crtc->drmmode;
-
-	/* bonghits in the randr 1.2 - uses dpms to disable crtc - bad buzz */
-	if (mode == DPMSModeOff) {
-//		drmModeSetCrtc(drmmode->fd, drmmode_crtc->mode_crtc->crtc_id,
-//			       0, 0, 0, NULL, 0, NULL);
-	}
+    xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(crtc->scrn);
+
+//      drmmode_crtc_private_ptr drmmode_crtc = crtc->driver_private;
+//      drmmode_ptr drmmode = drmmode_crtc->drmmode;
+
+    /* bonghits in the randr 1.2 - uses dpms to disable crtc - bad buzz */
+    if (mode == DPMSModeOff) {
+//              drmModeSetCrtc(drmmode->fd, drmmode_crtc->mode_crtc->crtc_id,
+//                             0, 0, 0, NULL, 0, NULL);
+    }
 #endif
 }
 
 #if 0
 static PixmapPtr
-create_pixmap_for_fbcon(drmmode_ptr drmmode,
-			ScrnInfoPtr pScrn, int crtc_id)
+create_pixmap_for_fbcon(drmmode_ptr drmmode, ScrnInfoPtr pScrn, int crtc_id)
 {
-	xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(pScrn);
-	drmmode_crtc_private_ptr drmmode_crtc;
-	ScreenPtr pScreen = pScrn->pScreen;
-	PixmapPtr pixmap;
-	struct radeon_bo *bo;
-	drmModeFBPtr fbcon;
-	struct drm_gem_flink flink;
-
-	drmmode_crtc = xf86_config->crtc[crtc_id]->driver_private;
-
-	fbcon = drmModeGetFB(drmmode->fd, drmmode_crtc->mode_crtc->buffer_id);
-	if (fbcon == NULL)
-		return NULL;
-
-	flink.handle = fbcon->handle;
-	if (ioctl(drmmode->fd, DRM_IOCTL_GEM_FLINK, &flink) < 0) {
-		xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
-			   "Couldn't flink fbcon handle\n");
-		return NULL;
-	}
-
-	bo = radeon_bo_open(drmmode->bufmgr, flink.name, 0, 0, 0, 0);
-	if (bo == NULL) {
-		xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
-			   "Couldn't allocate bo for fbcon handle\n");
-		return NULL;
-	}
-
-	pixmap = drmmode_create_bo_pixmap(pScreen, fbcon->width, fbcon->height,
-					  fbcon->depth, fbcon->bpp,
-					  fbcon->pitch, bo);
-	if (!pixmap) 
-		return NULL;
-
-	radeon_bo_unref(bo);
-	drmModeFreeFB(fbcon);
-	return pixmap;
+    xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(pScrn);
+    drmmode_crtc_private_ptr drmmode_crtc;
+    ScreenPtr pScreen = pScrn->pScreen;
+    PixmapPtr pixmap;
+    struct radeon_bo *bo;
+    drmModeFBPtr fbcon;
+    struct drm_gem_flink flink;
+
+    drmmode_crtc = xf86_config->crtc[crtc_id]->driver_private;
+
+    fbcon = drmModeGetFB(drmmode->fd, drmmode_crtc->mode_crtc->buffer_id);
+    if (fbcon == NULL)
+        return NULL;
+
+    flink.handle = fbcon->handle;
+    if (ioctl(drmmode->fd, DRM_IOCTL_GEM_FLINK, &flink) < 0) {
+        xf86DrvMsg(pScrn->scrnIndex, X_ERROR, "Couldn't flink fbcon handle\n");
+        return NULL;
+    }
+
+    bo = radeon_bo_open(drmmode->bufmgr, flink.name, 0, 0, 0, 0);
+    if (bo == NULL) {
+        xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
+                   "Couldn't allocate bo for fbcon handle\n");
+        return NULL;
+    }
+
+    pixmap = drmmode_create_bo_pixmap(pScreen, fbcon->width, fbcon->height,
+                                      fbcon->depth, fbcon->bpp,
+                                      fbcon->pitch, bo);
+    if (!pixmap)
+        return NULL;
+
+    radeon_bo_unref(bo);
+    drmModeFreeFB(fbcon);
+    return pixmap;
 }
 
 #endif
 
 static Bool
 drmmode_set_mode_major(xf86CrtcPtr crtc, DisplayModePtr mode,
-		     Rotation rotation, int x, int y)
+                       Rotation rotation, int x, int y)
 {
-	ScrnInfoPtr pScrn = crtc->scrn;
-	xf86CrtcConfigPtr   xf86_config = XF86_CRTC_CONFIG_PTR(crtc->scrn);
-	drmmode_crtc_private_ptr drmmode_crtc = crtc->driver_private;
-	drmmode_ptr drmmode = drmmode_crtc->drmmode;
-	int saved_x, saved_y;
-	Rotation saved_rotation;
-	DisplayModeRec saved_mode;
-	uint32_t *output_ids;
-	int output_count = 0;
-	Bool ret = TRUE;
-	int i;
-	uint32_t fb_id;
-	drmModeModeInfo kmode;
-	int height;
-
-	height = pScrn->virtualY;
-
-	if (drmmode->fb_id == 0) {
-		ret = drmModeAddFB(drmmode->fd,
-				   pScrn->virtualX, height,
-                                   pScrn->depth, pScrn->bitsPerPixel,
-				   drmmode->front_bo->pitch,
-				   drmmode->front_bo->handle,
-                                   &drmmode->fb_id);
-                if (ret < 0) {
-                        ErrorF("failed to add fb %d\n", ret);
-                        return FALSE;
-                }
+    ScrnInfoPtr pScrn = crtc->scrn;
+    xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(crtc->scrn);
+    drmmode_crtc_private_ptr drmmode_crtc = crtc->driver_private;
+    drmmode_ptr drmmode = drmmode_crtc->drmmode;
+    int saved_x, saved_y;
+    Rotation saved_rotation;
+    DisplayModeRec saved_mode;
+    uint32_t *output_ids;
+    int output_count = 0;
+    Bool ret = TRUE;
+    int i;
+    uint32_t fb_id;
+    drmModeModeInfo kmode;
+    int height;
+
+    height = pScrn->virtualY;
+
+    if (drmmode->fb_id == 0) {
+        ret = drmModeAddFB(drmmode->fd,
+                           pScrn->virtualX, height,
+                           pScrn->depth, pScrn->bitsPerPixel,
+                           drmmode->front_bo->pitch,
+                           drmmode->front_bo->handle, &drmmode->fb_id);
+        if (ret < 0) {
+            ErrorF("failed to add fb %d\n", ret);
+            return FALSE;
+        }
+    }
+
+    saved_mode = crtc->mode;
+    saved_x = crtc->x;
+    saved_y = crtc->y;
+    saved_rotation = crtc->rotation;
+
+    if (mode) {
+        crtc->mode = *mode;
+        crtc->x = x;
+        crtc->y = y;
+        crtc->rotation = rotation;
+        crtc->transformPresent = FALSE;
+    }
+
+    output_ids = calloc(sizeof(uint32_t), xf86_config->num_output);
+    if (!output_ids) {
+        ret = FALSE;
+        goto done;
+    }
+
+    if (mode) {
+        for (i = 0; i < xf86_config->num_output; i++) {
+            xf86OutputPtr output = xf86_config->output[i];
+            drmmode_output_private_ptr drmmode_output;
+
+            if (output->crtc != crtc)
+                continue;
+
+            drmmode_output = output->driver_private;
+            output_ids[output_count] =
+                drmmode_output->mode_output->connector_id;
+            output_count++;
         }
 
-	saved_mode = crtc->mode;
-	saved_x = crtc->x;
-	saved_y = crtc->y;
-	saved_rotation = crtc->rotation;
-
-	if (mode) {
-		crtc->mode = *mode;
-		crtc->x = x;
-		crtc->y = y;
-		crtc->rotation = rotation;
-		crtc->transformPresent = FALSE;
-	}
-
-	output_ids = calloc(sizeof(uint32_t), xf86_config->num_output);
-	if (!output_ids) {
-		ret = FALSE;
-		goto done;
-	}
-
-	if (mode) {
-		for (i = 0; i < xf86_config->num_output; i++) {
-			xf86OutputPtr output = xf86_config->output[i];
-			drmmode_output_private_ptr drmmode_output;
-
-			if (output->crtc != crtc)
-				continue;
-
-			drmmode_output = output->driver_private;
-			output_ids[output_count] = drmmode_output->mode_output->connector_id;
-			output_count++;
-		}
-
-		if (!xf86CrtcRotate(crtc)) {
-			goto done;
-		}
-		crtc->funcs->gamma_set(crtc, crtc->gamma_red, crtc->gamma_green,
-				       crtc->gamma_blue, crtc->gamma_size);
-		
-		drmmode_ConvertToKMode(crtc->scrn, &kmode, mode);
-
-		fb_id = drmmode->fb_id;
-		if (crtc->randr_crtc->scanout_pixmap) {
-    			msPixmapPrivPtr ppriv = msGetPixmapPriv(drmmode, crtc->randr_crtc->scanout_pixmap);
-			fb_id = ppriv->fb_id;
-			x = y = 0;
-		} else if (drmmode_crtc->rotate_fb_id) {
-			fb_id = drmmode_crtc->rotate_fb_id;
-			x = y = 0;
-		}
-		ret = drmModeSetCrtc(drmmode->fd, drmmode_crtc->mode_crtc->crtc_id,
-				     fb_id, x, y, output_ids, output_count, &kmode);
-		if (ret)
-			xf86DrvMsg(crtc->scrn->scrnIndex, X_ERROR,
-				   "failed to set mode: %s", strerror(-ret));
-		else
-			ret = TRUE;
-
-		if (crtc->scrn->pScreen)
-			xf86CrtcSetScreenSubpixelOrder(crtc->scrn->pScreen);
-		/* go through all the outputs and force DPMS them back on? */
-		for (i = 0; i < xf86_config->num_output; i++) {
-			xf86OutputPtr output = xf86_config->output[i];
-
-			if (output->crtc != crtc)
-				continue;
-
-			output->funcs->dpms(output, DPMSModeOn);
-		}
-	}
+        if (!xf86CrtcRotate(crtc)) {
+            goto done;
+        }
+        crtc->funcs->gamma_set(crtc, crtc->gamma_red, crtc->gamma_green,
+                               crtc->gamma_blue, crtc->gamma_size);
+
+        drmmode_ConvertToKMode(crtc->scrn, &kmode, mode);
+
+        fb_id = drmmode->fb_id;
+        if (crtc->randr_crtc->scanout_pixmap) {
+            msPixmapPrivPtr ppriv =
+                msGetPixmapPriv(drmmode, crtc->randr_crtc->scanout_pixmap);
+            fb_id = ppriv->fb_id;
+            x = y = 0;
+        }
+        else if (drmmode_crtc->rotate_fb_id) {
+            fb_id = drmmode_crtc->rotate_fb_id;
+            x = y = 0;
+        }
+        ret = drmModeSetCrtc(drmmode->fd, drmmode_crtc->mode_crtc->crtc_id,
+                             fb_id, x, y, output_ids, output_count, &kmode);
+        if (ret)
+            xf86DrvMsg(crtc->scrn->scrnIndex, X_ERROR,
+                       "failed to set mode: %s", strerror(-ret));
+        else
+            ret = TRUE;
+
+        if (crtc->scrn->pScreen)
+            xf86CrtcSetScreenSubpixelOrder(crtc->scrn->pScreen);
+        /* go through all the outputs and force DPMS them back on? */
+        for (i = 0; i < xf86_config->num_output; i++) {
+            xf86OutputPtr output = xf86_config->output[i];
+
+            if (output->crtc != crtc)
+                continue;
+
+            output->funcs->dpms(output, DPMSModeOn);
+        }
+    }
 
 #if 0
-	if (pScrn->pScreen &&
-		!xf86ReturnOptValBool(info->Options, OPTION_SW_CURSOR, FALSE))
-		xf86_reload_cursors(pScrn->pScreen);
+    if (pScrn->pScreen &&
+        !xf86ReturnOptValBool(info->Options, OPTION_SW_CURSOR, FALSE))
+        xf86_reload_cursors(pScrn->pScreen);
 #endif
-done:
-	if (!ret) {
-		crtc->x = saved_x;
-		crtc->y = saved_y;
-		crtc->rotation = saved_rotation;
-		crtc->mode = saved_mode;
-	}
+ done:
+    if (!ret) {
+        crtc->x = saved_x;
+        crtc->y = saved_y;
+        crtc->rotation = saved_rotation;
+        crtc->mode = saved_mode;
+    }
 #if defined(XF86_CRTC_VERSION) && XF86_CRTC_VERSION >= 3
-	else
-		crtc->active = TRUE;
+    else
+        crtc->active = TRUE;
 #endif
 
-	return ret;
+    return ret;
 }
 
 static void
-drmmode_set_cursor_colors (xf86CrtcPtr crtc, int bg, int fg)
+drmmode_set_cursor_colors(xf86CrtcPtr crtc, int bg, int fg)
 {
 
 }
 
 static void
-drmmode_set_cursor_position (xf86CrtcPtr crtc, int x, int y)
+drmmode_set_cursor_position(xf86CrtcPtr crtc, int x, int y)
 {
-	drmmode_crtc_private_ptr drmmode_crtc = crtc->driver_private;
-	drmmode_ptr drmmode = drmmode_crtc->drmmode;
+    drmmode_crtc_private_ptr drmmode_crtc = crtc->driver_private;
+    drmmode_ptr drmmode = drmmode_crtc->drmmode;
 
-	drmModeMoveCursor(drmmode->fd, drmmode_crtc->mode_crtc->crtc_id, x, y);
+    drmModeMoveCursor(drmmode->fd, drmmode_crtc->mode_crtc->crtc_id, x, y);
 }
 
 static void
-drmmode_load_cursor_argb (xf86CrtcPtr crtc, CARD32 *image)
+drmmode_load_cursor_argb(xf86CrtcPtr crtc, CARD32 *image)
 {
-	modesettingPtr ms = modesettingPTR(crtc->scrn);
-	drmmode_crtc_private_ptr drmmode_crtc = crtc->driver_private;
-	int i;
-	uint32_t *ptr;
-	uint32_t handle = drmmode_crtc->cursor_bo->handle;
-	int ret;
-	/* cursor should be mapped already */
-	ptr = (uint32_t *)(drmmode_crtc->cursor_bo->ptr);
-
-	for (i = 0; i < ms->cursor_width * ms->cursor_height; i++)
-		ptr[i] = image[i];// cpu_to_le32(image[i]);
-
-	ret = drmModeSetCursor(drmmode_crtc->drmmode->fd, drmmode_crtc->mode_crtc->crtc_id, handle,
-			       ms->cursor_width, ms->cursor_height);
-	if (ret) {
-		xf86CrtcConfigPtr   xf86_config = XF86_CRTC_CONFIG_PTR(crtc->scrn);
-		xf86CursorInfoPtr	cursor_info = xf86_config->cursor_info;
-		
-		cursor_info->MaxWidth = cursor_info->MaxHeight = 0;
-		drmmode_crtc->drmmode->sw_cursor = TRUE;
-		/* fallback to swcursor */
-	}
+    modesettingPtr ms = modesettingPTR(crtc->scrn);
+    drmmode_crtc_private_ptr drmmode_crtc = crtc->driver_private;
+    int i;
+    uint32_t *ptr;
+    uint32_t handle = drmmode_crtc->cursor_bo->handle;
+    int ret;
+
+    /* cursor should be mapped already */
+    ptr = (uint32_t *) (drmmode_crtc->cursor_bo->ptr);
+
+    for (i = 0; i < ms->cursor_width * ms->cursor_height; i++)
+        ptr[i] = image[i];      // cpu_to_le32(image[i]);
+
+    ret =
+        drmModeSetCursor(drmmode_crtc->drmmode->fd,
+                         drmmode_crtc->mode_crtc->crtc_id, handle,
+                         ms->cursor_width, ms->cursor_height);
+    if (ret) {
+        xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(crtc->scrn);
+        xf86CursorInfoPtr cursor_info = xf86_config->cursor_info;
+
+        cursor_info->MaxWidth = cursor_info->MaxHeight = 0;
+        drmmode_crtc->drmmode->sw_cursor = TRUE;
+        /* fallback to swcursor */
+    }
 }
 
-
 static void
-drmmode_hide_cursor (xf86CrtcPtr crtc)
+drmmode_hide_cursor(xf86CrtcPtr crtc)
 {
-	modesettingPtr ms = modesettingPTR(crtc->scrn);
-	drmmode_crtc_private_ptr drmmode_crtc = crtc->driver_private;
-	drmmode_ptr drmmode = drmmode_crtc->drmmode;
+    modesettingPtr ms = modesettingPTR(crtc->scrn);
+    drmmode_crtc_private_ptr drmmode_crtc = crtc->driver_private;
+    drmmode_ptr drmmode = drmmode_crtc->drmmode;
 
-	drmModeSetCursor(drmmode->fd, drmmode_crtc->mode_crtc->crtc_id, 0,
-			 ms->cursor_width, ms->cursor_height);
+    drmModeSetCursor(drmmode->fd, drmmode_crtc->mode_crtc->crtc_id, 0,
+                     ms->cursor_width, ms->cursor_height);
 
 }
 
 static void
-drmmode_show_cursor (xf86CrtcPtr crtc)
+drmmode_show_cursor(xf86CrtcPtr crtc)
 {
-	modesettingPtr ms = modesettingPTR(crtc->scrn);
-	drmmode_crtc_private_ptr drmmode_crtc = crtc->driver_private;
-	drmmode_ptr drmmode = drmmode_crtc->drmmode;
-	uint32_t handle = drmmode_crtc->cursor_bo->handle;
-       static Bool use_set_cursor2 = TRUE;
-
-       if (use_set_cursor2) {
-               xf86CrtcConfigPtr   xf86_config = XF86_CRTC_CONFIG_PTR(crtc->scrn);
-               CursorPtr cursor = xf86_config->cursor;
-               int ret;
-               ret = drmModeSetCursor2(drmmode->fd, drmmode_crtc->mode_crtc->crtc_id, handle, ms->cursor_width, ms->cursor_height, cursor->bits->xhot, cursor->bits->yhot);
-               if (ret == -EINVAL)
-                       use_set_cursor2 = FALSE;
-               else
-                       return;
-       }
-
-	drmModeSetCursor(drmmode->fd, drmmode_crtc->mode_crtc->crtc_id, handle,
-			 ms->cursor_width, ms->cursor_height);
+    modesettingPtr ms = modesettingPTR(crtc->scrn);
+    drmmode_crtc_private_ptr drmmode_crtc = crtc->driver_private;
+    drmmode_ptr drmmode = drmmode_crtc->drmmode;
+    uint32_t handle = drmmode_crtc->cursor_bo->handle;
+    static Bool use_set_cursor2 = TRUE;
+
+    if (use_set_cursor2) {
+        xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(crtc->scrn);
+        CursorPtr cursor = xf86_config->cursor;
+        int ret;
+
+        ret =
+            drmModeSetCursor2(drmmode->fd, drmmode_crtc->mode_crtc->crtc_id,
+                              handle, ms->cursor_width, ms->cursor_height,
+                              cursor->bits->xhot, cursor->bits->yhot);
+        if (ret == -EINVAL)
+            use_set_cursor2 = FALSE;
+        else
+            return;
+    }
+
+    drmModeSetCursor(drmmode->fd, drmmode_crtc->mode_crtc->crtc_id, handle,
+                     ms->cursor_width, ms->cursor_height);
 }
 
 static void
-drmmode_crtc_gamma_set(xf86CrtcPtr crtc, uint16_t *red, uint16_t *green,
-                      uint16_t *blue, int size)
+drmmode_crtc_gamma_set(xf86CrtcPtr crtc, uint16_t * red, uint16_t * green,
+                       uint16_t * blue, int size)
 {
-	drmmode_crtc_private_ptr drmmode_crtc = crtc->driver_private;
-	drmmode_ptr drmmode = drmmode_crtc->drmmode;
+    drmmode_crtc_private_ptr drmmode_crtc = crtc->driver_private;
+    drmmode_ptr drmmode = drmmode_crtc->drmmode;
 
-	drmModeCrtcSetGamma(drmmode->fd, drmmode_crtc->mode_crtc->crtc_id,
-			    size, red, green, blue);
+    drmModeCrtcSetGamma(drmmode->fd, drmmode_crtc->mode_crtc->crtc_id,
+                        size, red, green, blue);
 }
 
 static Bool
 drmmode_set_scanout_pixmap(xf86CrtcPtr crtc, PixmapPtr ppix)
 {
-	drmmode_crtc_private_ptr drmmode_crtc = crtc->driver_private;
-	drmmode_ptr drmmode = drmmode_crtc->drmmode;
-	msPixmapPrivPtr ppriv;
-	void *ptr;
-
-	if (!ppix) {
-		if (crtc->randr_crtc->scanout_pixmap) {
-    			ppriv = msGetPixmapPriv(drmmode, crtc->randr_crtc->scanout_pixmap);
-			drmModeRmFB(drmmode->fd, ppriv->fb_id);
-		}
-		if (drmmode_crtc->slave_damage) {
-			DamageUnregister(drmmode_crtc->slave_damage);
-			drmmode_crtc->slave_damage = NULL;
-		}
-		return TRUE;
-	}
-
-	ppriv = msGetPixmapPriv(drmmode, ppix);
-	if (!drmmode_crtc->slave_damage) {
-		drmmode_crtc->slave_damage = DamageCreate(NULL, NULL,
-							  DamageReportNone,
-							  TRUE,
-							  crtc->randr_crtc->pScreen,
-							  NULL);
-	}
-	ptr = drmmode_map_slave_bo(drmmode, ppriv);
-	ppix->devPrivate.ptr = ptr;
-	DamageRegister(&ppix->drawable, drmmode_crtc->slave_damage);
-
-	if (ppriv->fb_id == 0) {
-                drmModeAddFB(drmmode->fd, ppix->drawable.width,
-                             ppix->drawable.height,
-                             ppix->drawable.depth,
-                             ppix->drawable.bitsPerPixel,
-                             ppix->devKind,
-                             ppriv->backing_bo->handle,
-                             &ppriv->fb_id);
-	}
-	return TRUE;
+    drmmode_crtc_private_ptr drmmode_crtc = crtc->driver_private;
+    drmmode_ptr drmmode = drmmode_crtc->drmmode;
+    msPixmapPrivPtr ppriv;
+    void *ptr;
+
+    if (!ppix) {
+        if (crtc->randr_crtc->scanout_pixmap) {
+            ppriv = msGetPixmapPriv(drmmode, crtc->randr_crtc->scanout_pixmap);
+            drmModeRmFB(drmmode->fd, ppriv->fb_id);
+        }
+        if (drmmode_crtc->slave_damage) {
+            DamageUnregister(drmmode_crtc->slave_damage);
+            drmmode_crtc->slave_damage = NULL;
+        }
+        return TRUE;
+    }
+
+    ppriv = msGetPixmapPriv(drmmode, ppix);
+    if (!drmmode_crtc->slave_damage) {
+        drmmode_crtc->slave_damage = DamageCreate(NULL, NULL,
+                                                  DamageReportNone,
+                                                  TRUE,
+                                                  crtc->randr_crtc->pScreen,
+                                                  NULL);
+    }
+    ptr = drmmode_map_slave_bo(drmmode, ppriv);
+    ppix->devPrivate.ptr = ptr;
+    DamageRegister(&ppix->drawable, drmmode_crtc->slave_damage);
+
+    if (ppriv->fb_id == 0) {
+        drmModeAddFB(drmmode->fd, ppix->drawable.width,
+                     ppix->drawable.height,
+                     ppix->drawable.depth,
+                     ppix->drawable.bitsPerPixel,
+                     ppix->devKind, ppriv->backing_bo->handle, &ppriv->fb_id);
+    }
+    return TRUE;
 }
 
-static void *drmmode_shadow_allocate(xf86CrtcPtr crtc, int width, int height)
+static void *
+drmmode_shadow_allocate(xf86CrtcPtr crtc, int width, int height)
 {
-	return NULL;
+    return NULL;
 }
 
-static PixmapPtr drmmode_shadow_create(xf86CrtcPtr crtc, void *data, int width,
-				       int height)
+static PixmapPtr
+drmmode_shadow_create(xf86CrtcPtr crtc, void *data, int width, int height)
 {
-	return NULL;
+    return NULL;
 }
 
 static const xf86CrtcFuncsRec drmmode_crtc_funcs = {
@@ -568,7 +576,7 @@ static const xf86CrtcFuncsRec drmmode_crtc_funcs = {
     .load_cursor_argb = drmmode_load_cursor_argb,
 
     .gamma_set = drmmode_crtc_gamma_set,
-    .destroy = NULL, /* XXX */
+    .destroy = NULL,            /* XXX */
     .set_scanout_pixmap = drmmode_set_scanout_pixmap,
     .shadow_allocate = drmmode_shadow_allocate,
     .shadow_create = drmmode_shadow_create,
@@ -577,222 +585,224 @@ static const xf86CrtcFuncsRec drmmode_crtc_funcs = {
 static void
 drmmode_crtc_init(ScrnInfoPtr pScrn, drmmode_ptr drmmode, int num)
 {
-	xf86CrtcPtr crtc;
-	drmmode_crtc_private_ptr drmmode_crtc;
-
-	crtc = xf86CrtcCreate(pScrn, &drmmode_crtc_funcs);
-	if (crtc == NULL)
-		return;
-
-	drmmode_crtc = xnfcalloc(sizeof(drmmode_crtc_private_rec), 1);
-	drmmode_crtc->mode_crtc = drmModeGetCrtc(drmmode->fd, drmmode->mode_res->crtcs[num]);
-	drmmode_crtc->drmmode = drmmode;
-	crtc->driver_private = drmmode_crtc;
+    xf86CrtcPtr crtc;
+    drmmode_crtc_private_ptr drmmode_crtc;
+
+    crtc = xf86CrtcCreate(pScrn, &drmmode_crtc_funcs);
+    if (crtc == NULL)
+        return;
+
+    drmmode_crtc = xnfcalloc(sizeof(drmmode_crtc_private_rec), 1);
+    drmmode_crtc->mode_crtc =
+        drmModeGetCrtc(drmmode->fd, drmmode->mode_res->crtcs[num]);
+    drmmode_crtc->drmmode = drmmode;
+    crtc->driver_private = drmmode_crtc;
 }
 
 static xf86OutputStatus
 drmmode_output_detect(xf86OutputPtr output)
 {
-	/* go to the hw and retrieve a new output struct */
-	drmmode_output_private_ptr drmmode_output = output->driver_private;
-	drmmode_ptr drmmode = drmmode_output->drmmode;
-	xf86OutputStatus status;
-	drmModeFreeConnector(drmmode_output->mode_output);
-
-	drmmode_output->mode_output = drmModeGetConnector(drmmode->fd, drmmode_output->output_id);
-	if (!drmmode_output->mode_output)
-		return XF86OutputStatusDisconnected;
-
-	switch (drmmode_output->mode_output->connection) {
-	case DRM_MODE_CONNECTED:
-		status = XF86OutputStatusConnected;
-		break;
-	case DRM_MODE_DISCONNECTED:
-		status = XF86OutputStatusDisconnected;
-		break;
-	default:
-	case DRM_MODE_UNKNOWNCONNECTION:
-		status = XF86OutputStatusUnknown;
-		break;
-	}
-	return status;
+    /* go to the hw and retrieve a new output struct */
+    drmmode_output_private_ptr drmmode_output = output->driver_private;
+    drmmode_ptr drmmode = drmmode_output->drmmode;
+    xf86OutputStatus status;
+
+    drmModeFreeConnector(drmmode_output->mode_output);
+
+    drmmode_output->mode_output =
+        drmModeGetConnector(drmmode->fd, drmmode_output->output_id);
+    if (!drmmode_output->mode_output)
+        return XF86OutputStatusDisconnected;
+
+    switch (drmmode_output->mode_output->connection) {
+    case DRM_MODE_CONNECTED:
+        status = XF86OutputStatusConnected;
+        break;
+    case DRM_MODE_DISCONNECTED:
+        status = XF86OutputStatusDisconnected;
+        break;
+    default:
+    case DRM_MODE_UNKNOWNCONNECTION:
+        status = XF86OutputStatusUnknown;
+        break;
+    }
+    return status;
 }
 
 static Bool
 drmmode_output_mode_valid(xf86OutputPtr output, DisplayModePtr pModes)
 {
-	return MODE_OK;
+    return MODE_OK;
 }
 
 static Bool
 has_panel_fitter(xf86OutputPtr output)
 {
-	drmmode_output_private_ptr drmmode_output = output->driver_private;
-	drmModeConnectorPtr koutput = drmmode_output->mode_output;
-	drmmode_ptr drmmode = drmmode_output->drmmode;
-	int i;
-
-	/* Presume that if the output supports scaling, then we have a
-	 * panel fitter capable of adjust any mode to suit.
-	 */
-	for (i = 0; i < koutput->count_props; i++) {
-		drmModePropertyPtr props;
-		Bool found = FALSE;
-
-		props = drmModeGetProperty(drmmode->fd, koutput->props[i]);
-		if (props) {
-			found = strcmp(props->name, "scaling mode") == 0;
-			drmModeFreeProperty(props);
-		}
-
-		if (found)
-			return TRUE;
-	}
-
-	return FALSE;
+    drmmode_output_private_ptr drmmode_output = output->driver_private;
+    drmModeConnectorPtr koutput = drmmode_output->mode_output;
+    drmmode_ptr drmmode = drmmode_output->drmmode;
+    int i;
+
+    /* Presume that if the output supports scaling, then we have a
+     * panel fitter capable of adjust any mode to suit.
+     */
+    for (i = 0; i < koutput->count_props; i++) {
+        drmModePropertyPtr props;
+        Bool found = FALSE;
+
+        props = drmModeGetProperty(drmmode->fd, koutput->props[i]);
+        if (props) {
+            found = strcmp(props->name, "scaling mode") == 0;
+            drmModeFreeProperty(props);
+        }
+
+        if (found)
+            return TRUE;
+    }
+
+    return FALSE;
 }
 
 static DisplayModePtr
-drmmode_output_add_gtf_modes(xf86OutputPtr output,
-			     DisplayModePtr Modes)
+drmmode_output_add_gtf_modes(xf86OutputPtr output, DisplayModePtr Modes)
 {
-	xf86MonPtr mon = output->MonInfo;
-	DisplayModePtr i, m, preferred = NULL;
-	int max_x = 0, max_y = 0;
-	float max_vrefresh = 0.0;
-
-	if (mon && GTF_SUPPORTED(mon->features.msc))
-		return Modes;
-
-	if (!has_panel_fitter(output))
-		return Modes;
-
-	for (m = Modes; m; m = m->next) {
-		if (m->type & M_T_PREFERRED)
-			preferred = m;
-		max_x = max(max_x, m->HDisplay);
-		max_y = max(max_y, m->VDisplay);
-		max_vrefresh = max(max_vrefresh, xf86ModeVRefresh(m));
-	}
-
-	max_vrefresh = max(max_vrefresh, 60.0);
-	max_vrefresh *= (1 + SYNC_TOLERANCE);
-
-	m = xf86GetDefaultModes();
-	xf86ValidateModesSize(output->scrn, m, max_x, max_y, 0);
-
-	for (i = m; i; i = i->next) {
-		if (xf86ModeVRefresh(i) > max_vrefresh)
-			i->status = MODE_VSYNC;
-		if (preferred &&
-		    i->HDisplay >= preferred->HDisplay &&
-		    i->VDisplay >= preferred->VDisplay &&
-		    xf86ModeVRefresh(i) >= xf86ModeVRefresh(preferred))
-			i->status = MODE_VSYNC;
-	}
-
-	xf86PruneInvalidModes(output->scrn, &m, FALSE);
-
-	return xf86ModesAdd(Modes, m);
+    xf86MonPtr mon = output->MonInfo;
+    DisplayModePtr i, m, preferred = NULL;
+    int max_x = 0, max_y = 0;
+    float max_vrefresh = 0.0;
+
+    if (mon && GTF_SUPPORTED(mon->features.msc))
+        return Modes;
+
+    if (!has_panel_fitter(output))
+        return Modes;
+
+    for (m = Modes; m; m = m->next) {
+        if (m->type & M_T_PREFERRED)
+            preferred = m;
+        max_x = max(max_x, m->HDisplay);
+        max_y = max(max_y, m->VDisplay);
+        max_vrefresh = max(max_vrefresh, xf86ModeVRefresh(m));
+    }
+
+    max_vrefresh = max(max_vrefresh, 60.0);
+    max_vrefresh *= (1 + SYNC_TOLERANCE);
+
+    m = xf86GetDefaultModes();
+    xf86ValidateModesSize(output->scrn, m, max_x, max_y, 0);
+
+    for (i = m; i; i = i->next) {
+        if (xf86ModeVRefresh(i) > max_vrefresh)
+            i->status = MODE_VSYNC;
+        if (preferred &&
+            i->HDisplay >= preferred->HDisplay &&
+            i->VDisplay >= preferred->VDisplay &&
+            xf86ModeVRefresh(i) >= xf86ModeVRefresh(preferred))
+            i->status = MODE_VSYNC;
+    }
+
+    xf86PruneInvalidModes(output->scrn, &m, FALSE);
+
+    return xf86ModesAdd(Modes, m);
 }
 
 static DisplayModePtr
 drmmode_output_get_modes(xf86OutputPtr output)
 {
-	drmmode_output_private_ptr drmmode_output = output->driver_private;
-	drmModeConnectorPtr koutput = drmmode_output->mode_output;
-	drmmode_ptr drmmode = drmmode_output->drmmode;
-	int i;
-	DisplayModePtr Modes = NULL, Mode;
-	drmModePropertyPtr props;
-	xf86MonPtr mon = NULL;
-
-	if (!koutput)
-		return NULL;
-
-	/* look for an EDID property */
-	for (i = 0; i < koutput->count_props; i++) {
-		props = drmModeGetProperty(drmmode->fd, koutput->props[i]);
-		if (props && (props->flags & DRM_MODE_PROP_BLOB)) {
-			if (!strcmp(props->name, "EDID")) {
-				if (drmmode_output->edid_blob)
-					drmModeFreePropertyBlob(drmmode_output->edid_blob);
-				drmmode_output->edid_blob = drmModeGetPropertyBlob(drmmode->fd, koutput->prop_values[i]);
-			}
-			drmModeFreeProperty(props);
-		}
-	}
-
-	if (drmmode_output->edid_blob) {
-		mon = xf86InterpretEDID(output->scrn->scrnIndex,
-					drmmode_output->edid_blob->data);
-		if (mon && drmmode_output->edid_blob->length > 128)
-			mon->flags |= MONITOR_EDID_COMPLETE_RAWDATA;
-	}
-	xf86OutputSetEDID(output, mon);
-
-	/* modes should already be available */
-	for (i = 0; i < koutput->count_modes; i++) {
-		Mode = xnfalloc(sizeof(DisplayModeRec));
-
-		drmmode_ConvertFromKMode(output->scrn, &koutput->modes[i], Mode);
-		Modes = xf86ModesAdd(Modes, Mode);
-
-	}
-
-	return drmmode_output_add_gtf_modes(output, Modes);
+    drmmode_output_private_ptr drmmode_output = output->driver_private;
+    drmModeConnectorPtr koutput = drmmode_output->mode_output;
+    drmmode_ptr drmmode = drmmode_output->drmmode;
+    int i;
+    DisplayModePtr Modes = NULL, Mode;
+    drmModePropertyPtr props;
+    xf86MonPtr mon = NULL;
+
+    if (!koutput)
+        return NULL;
+
+    /* look for an EDID property */
+    for (i = 0; i < koutput->count_props; i++) {
+        props = drmModeGetProperty(drmmode->fd, koutput->props[i]);
+        if (props && (props->flags & DRM_MODE_PROP_BLOB)) {
+            if (!strcmp(props->name, "EDID")) {
+                if (drmmode_output->edid_blob)
+                    drmModeFreePropertyBlob(drmmode_output->edid_blob);
+                drmmode_output->edid_blob =
+                    drmModeGetPropertyBlob(drmmode->fd,
+                                           koutput->prop_values[i]);
+            }
+            drmModeFreeProperty(props);
+        }
+    }
+
+    if (drmmode_output->edid_blob) {
+        mon = xf86InterpretEDID(output->scrn->scrnIndex,
+                                drmmode_output->edid_blob->data);
+        if (mon && drmmode_output->edid_blob->length > 128)
+            mon->flags |= MONITOR_EDID_COMPLETE_RAWDATA;
+    }
+    xf86OutputSetEDID(output, mon);
+
+    /* modes should already be available */
+    for (i = 0; i < koutput->count_modes; i++) {
+        Mode = xnfalloc(sizeof(DisplayModeRec));
+
+        drmmode_ConvertFromKMode(output->scrn, &koutput->modes[i], Mode);
+        Modes = xf86ModesAdd(Modes, Mode);
+
+    }
+
+    return drmmode_output_add_gtf_modes(output, Modes);
 }
 
 static void
 drmmode_output_destroy(xf86OutputPtr output)
 {
-	drmmode_output_private_ptr drmmode_output = output->driver_private;
-	int i;
-
-	if (drmmode_output->edid_blob)
-		drmModeFreePropertyBlob(drmmode_output->edid_blob);
-	for (i = 0; i < drmmode_output->num_props; i++) {
-		drmModeFreeProperty(drmmode_output->props[i].mode_prop);
-		free(drmmode_output->props[i].atoms);
-	}
-	free(drmmode_output->props);
-	for (i = 0; i < drmmode_output->mode_output->count_encoders; i++) {
-		drmModeFreeEncoder(drmmode_output->mode_encoders[i]);
-	}
-	free(drmmode_output->mode_encoders);
-	drmModeFreeConnector(drmmode_output->mode_output);
-	free(drmmode_output);
-	output->driver_private = NULL;
+    drmmode_output_private_ptr drmmode_output = output->driver_private;
+    int i;
+
+    if (drmmode_output->edid_blob)
+        drmModeFreePropertyBlob(drmmode_output->edid_blob);
+    for (i = 0; i < drmmode_output->num_props; i++) {
+        drmModeFreeProperty(drmmode_output->props[i].mode_prop);
+        free(drmmode_output->props[i].atoms);
+    }
+    free(drmmode_output->props);
+    for (i = 0; i < drmmode_output->mode_output->count_encoders; i++) {
+        drmModeFreeEncoder(drmmode_output->mode_encoders[i]);
+    }
+    free(drmmode_output->mode_encoders);
+    drmModeFreeConnector(drmmode_output->mode_output);
+    free(drmmode_output);
+    output->driver_private = NULL;
 }
 
 static void
 drmmode_output_dpms(xf86OutputPtr output, int mode)
 {
-	drmmode_output_private_ptr drmmode_output = output->driver_private;
-	drmModeConnectorPtr koutput = drmmode_output->mode_output;
-	drmmode_ptr drmmode = drmmode_output->drmmode;
+    drmmode_output_private_ptr drmmode_output = output->driver_private;
+    drmModeConnectorPtr koutput = drmmode_output->mode_output;
+    drmmode_ptr drmmode = drmmode_output->drmmode;
 
-	if (!koutput)
-		return;
+    if (!koutput)
+        return;
 
-	drmModeConnectorSetProperty(drmmode->fd, koutput->connector_id,
-				    drmmode_output->dpms_enum_id, mode);
-	return;
+    drmModeConnectorSetProperty(drmmode->fd, koutput->connector_id,
+                                drmmode_output->dpms_enum_id, mode);
+    return;
 }
 
-
 static Bool
 drmmode_property_ignore(drmModePropertyPtr prop)
 {
     if (!prop)
-	return TRUE;
+        return TRUE;
     /* ignore blob prop */
     if (prop->flags & DRM_MODE_PROP_BLOB)
-	return TRUE;
+        return TRUE;
     /* ignore standard property */
-    if (!strcmp(prop->name, "EDID") ||
-	    !strcmp(prop->name, "DPMS"))
-	return TRUE;
+    if (!strcmp(prop->name, "EDID") || !strcmp(prop->name, "DPMS"))
+        return TRUE;
 
     return FALSE;
 }
@@ -806,128 +816,143 @@ drmmode_output_create_resources(xf86OutputPtr output)
     drmModePropertyPtr drmmode_prop;
     int i, j, err;
 
-    drmmode_output->props = calloc(mode_output->count_props, sizeof(drmmode_prop_rec));
+    drmmode_output->props =
+        calloc(mode_output->count_props, sizeof(drmmode_prop_rec));
     if (!drmmode_output->props)
-	return;
-    
+        return;
+
     drmmode_output->num_props = 0;
     for (i = 0, j = 0; i < mode_output->count_props; i++) {
-	drmmode_prop = drmModeGetProperty(drmmode->fd, mode_output->props[i]);
-	if (drmmode_property_ignore(drmmode_prop)) {
-	    drmModeFreeProperty(drmmode_prop);
-	    continue;
-	}
-	drmmode_output->props[j].mode_prop = drmmode_prop;
-	drmmode_output->props[j].value = mode_output->prop_values[i];
-	drmmode_output->num_props++;
-	j++;
+        drmmode_prop = drmModeGetProperty(drmmode->fd, mode_output->props[i]);
+        if (drmmode_property_ignore(drmmode_prop)) {
+            drmModeFreeProperty(drmmode_prop);
+            continue;
+        }
+        drmmode_output->props[j].mode_prop = drmmode_prop;
+        drmmode_output->props[j].value = mode_output->prop_values[i];
+        drmmode_output->num_props++;
+        j++;
     }
 
     for (i = 0; i < drmmode_output->num_props; i++) {
-	drmmode_prop_ptr p = &drmmode_output->props[i];
-	drmmode_prop = p->mode_prop;
-
-	if (drmmode_prop->flags & DRM_MODE_PROP_RANGE) {
-	    INT32 prop_range[2];
-	    INT32 value = p->value;
-
-	    p->num_atoms = 1;
-	    p->atoms = calloc(p->num_atoms, sizeof(Atom));
-	    if (!p->atoms)
-		continue;
-	    p->atoms[0] = MakeAtom(drmmode_prop->name, strlen(drmmode_prop->name), TRUE);
-	    prop_range[0] = drmmode_prop->values[0];
-	    prop_range[1] = drmmode_prop->values[1];
-	    err = RRConfigureOutputProperty(output->randr_output, p->atoms[0],
-		    FALSE, TRUE,
-		    drmmode_prop->flags & DRM_MODE_PROP_IMMUTABLE ? TRUE : FALSE,
-		    2, prop_range);
-	    if (err != 0) {
-		xf86DrvMsg(output->scrn->scrnIndex, X_ERROR,
-			"RRConfigureOutputProperty error, %d\n", err);
-	    }
-	    err = RRChangeOutputProperty(output->randr_output, p->atoms[0],
-		    XA_INTEGER, 32, PropModeReplace, 1, &value, FALSE, TRUE);
-	    if (err != 0) {
-		xf86DrvMsg(output->scrn->scrnIndex, X_ERROR,
-			"RRChangeOutputProperty error, %d\n", err);
-	    }
-	} else if (drmmode_prop->flags & DRM_MODE_PROP_ENUM) {
-	    p->num_atoms = drmmode_prop->count_enums + 1;
-	    p->atoms = calloc(p->num_atoms, sizeof(Atom));
-	    if (!p->atoms)
-		continue;
-	    p->atoms[0] = MakeAtom(drmmode_prop->name, strlen(drmmode_prop->name), TRUE);
-	    for (j = 1; j <= drmmode_prop->count_enums; j++) {
-		struct drm_mode_property_enum *e = &drmmode_prop->enums[j-1];
-		p->atoms[j] = MakeAtom(e->name, strlen(e->name), TRUE);
-	    }
-	    err = RRConfigureOutputProperty(output->randr_output, p->atoms[0],
-		    FALSE, FALSE,
-		    drmmode_prop->flags & DRM_MODE_PROP_IMMUTABLE ? TRUE : FALSE,
-		    p->num_atoms - 1, (INT32 *)&p->atoms[1]);
-	    if (err != 0) {
-		xf86DrvMsg(output->scrn->scrnIndex, X_ERROR,
-			"RRConfigureOutputProperty error, %d\n", err);
-	    }
-	    for (j = 0; j < drmmode_prop->count_enums; j++)
-		if (drmmode_prop->enums[j].value == p->value)
-		    break;
-	    /* there's always a matching value */
-	    err = RRChangeOutputProperty(output->randr_output, p->atoms[0],
-		    XA_ATOM, 32, PropModeReplace, 1, &p->atoms[j+1], FALSE, TRUE);
-	    if (err != 0) {
-		xf86DrvMsg(output->scrn->scrnIndex, X_ERROR,
-			"RRChangeOutputProperty error, %d\n", err);
-	    }
-	}
+        drmmode_prop_ptr p = &drmmode_output->props[i];
+
+        drmmode_prop = p->mode_prop;
+
+        if (drmmode_prop->flags & DRM_MODE_PROP_RANGE) {
+            INT32 prop_range[2];
+            INT32 value = p->value;
+
+            p->num_atoms = 1;
+            p->atoms = calloc(p->num_atoms, sizeof(Atom));
+            if (!p->atoms)
+                continue;
+            p->atoms[0] =
+                MakeAtom(drmmode_prop->name, strlen(drmmode_prop->name), TRUE);
+            prop_range[0] = drmmode_prop->values[0];
+            prop_range[1] = drmmode_prop->values[1];
+            err = RRConfigureOutputProperty(output->randr_output, p->atoms[0],
+                                            FALSE, TRUE,
+                                            drmmode_prop->
+                                            flags & DRM_MODE_PROP_IMMUTABLE ?
+                                            TRUE : FALSE, 2, prop_range);
+            if (err != 0) {
+                xf86DrvMsg(output->scrn->scrnIndex, X_ERROR,
+                           "RRConfigureOutputProperty error, %d\n", err);
+            }
+            err = RRChangeOutputProperty(output->randr_output, p->atoms[0],
+                                         XA_INTEGER, 32, PropModeReplace, 1,
+                                         &value, FALSE, TRUE);
+            if (err != 0) {
+                xf86DrvMsg(output->scrn->scrnIndex, X_ERROR,
+                           "RRChangeOutputProperty error, %d\n", err);
+            }
+        }
+        else if (drmmode_prop->flags & DRM_MODE_PROP_ENUM) {
+            p->num_atoms = drmmode_prop->count_enums + 1;
+            p->atoms = calloc(p->num_atoms, sizeof(Atom));
+            if (!p->atoms)
+                continue;
+            p->atoms[0] =
+                MakeAtom(drmmode_prop->name, strlen(drmmode_prop->name), TRUE);
+            for (j = 1; j <= drmmode_prop->count_enums; j++) {
+                struct drm_mode_property_enum *e = &drmmode_prop->enums[j - 1];
+
+                p->atoms[j] = MakeAtom(e->name, strlen(e->name), TRUE);
+            }
+            err = RRConfigureOutputProperty(output->randr_output, p->atoms[0],
+                                            FALSE, FALSE,
+                                            drmmode_prop->
+                                            flags & DRM_MODE_PROP_IMMUTABLE ?
+                                            TRUE : FALSE, p->num_atoms - 1,
+                                            (INT32 *) &p->atoms[1]);
+            if (err != 0) {
+                xf86DrvMsg(output->scrn->scrnIndex, X_ERROR,
+                           "RRConfigureOutputProperty error, %d\n", err);
+            }
+            for (j = 0; j < drmmode_prop->count_enums; j++)
+                if (drmmode_prop->enums[j].value == p->value)
+                    break;
+            /* there's always a matching value */
+            err = RRChangeOutputProperty(output->randr_output, p->atoms[0],
+                                         XA_ATOM, 32, PropModeReplace, 1,
+                                         &p->atoms[j + 1], FALSE, TRUE);
+            if (err != 0) {
+                xf86DrvMsg(output->scrn->scrnIndex, X_ERROR,
+                           "RRChangeOutputProperty error, %d\n", err);
+            }
+        }
     }
 }
 
 static Bool
 drmmode_output_set_property(xf86OutputPtr output, Atom property,
-		RRPropertyValuePtr value)
+                            RRPropertyValuePtr value)
 {
     drmmode_output_private_ptr drmmode_output = output->driver_private;
     drmmode_ptr drmmode = drmmode_output->drmmode;
     int i;
 
     for (i = 0; i < drmmode_output->num_props; i++) {
-	drmmode_prop_ptr p = &drmmode_output->props[i];
-
-	if (p->atoms[0] != property)
-	    continue;
-
-	if (p->mode_prop->flags & DRM_MODE_PROP_RANGE) {
-	    uint32_t val;
-
-	    if (value->type != XA_INTEGER || value->format != 32 ||
-		    value->size != 1)
-		return FALSE;
-	    val = *(uint32_t *)value->data;
-
-	    drmModeConnectorSetProperty(drmmode->fd, drmmode_output->output_id,
-		    p->mode_prop->prop_id, (uint64_t)val);
-	    return TRUE;
-	} else if (p->mode_prop->flags & DRM_MODE_PROP_ENUM) {
-	    Atom	atom;
-	    const char	*name;
-	    int		j;
-
-	    if (value->type != XA_ATOM || value->format != 32 || value->size != 1)
-		return FALSE;
-	    memcpy(&atom, value->data, 4);
-	    name = NameForAtom(atom);
-
-	    /* search for matching name string, then set its value down */
-	    for (j = 0; j < p->mode_prop->count_enums; j++) {
-		if (!strcmp(p->mode_prop->enums[j].name, name)) {
-		    drmModeConnectorSetProperty(drmmode->fd, drmmode_output->output_id,
-			    p->mode_prop->prop_id, p->mode_prop->enums[j].value);
-		    return TRUE;
-		}
-	    }
-	}
+        drmmode_prop_ptr p = &drmmode_output->props[i];
+
+        if (p->atoms[0] != property)
+            continue;
+
+        if (p->mode_prop->flags & DRM_MODE_PROP_RANGE) {
+            uint32_t val;
+
+            if (value->type != XA_INTEGER || value->format != 32 ||
+                value->size != 1)
+                return FALSE;
+            val = *(uint32_t *) value->data;
+
+            drmModeConnectorSetProperty(drmmode->fd, drmmode_output->output_id,
+                                        p->mode_prop->prop_id, (uint64_t) val);
+            return TRUE;
+        }
+        else if (p->mode_prop->flags & DRM_MODE_PROP_ENUM) {
+            Atom atom;
+            const char *name;
+            int j;
+
+            if (value->type != XA_ATOM || value->format != 32 ||
+                value->size != 1)
+                return FALSE;
+            memcpy(&atom, value->data, 4);
+            name = NameForAtom(atom);
+
+            /* search for matching name string, then set its value down */
+            for (j = 0; j < p->mode_prop->count_enums; j++) {
+                if (!strcmp(p->mode_prop->enums[j].name, name)) {
+                    drmModeConnectorSetProperty(drmmode->fd,
+                                                drmmode_output->output_id,
+                                                p->mode_prop->prop_id,
+                                                p->mode_prop->enums[j].value);
+                    return TRUE;
+                }
+            }
+        }
     }
 
     return TRUE;
@@ -952,401 +977,416 @@ static const xf86OutputFuncsRec drmmode_output_funcs = {
 };
 
 static int subpixel_conv_table[7] = { 0, SubPixelUnknown,
-				      SubPixelHorizontalRGB,
-				      SubPixelHorizontalBGR,
-				      SubPixelVerticalRGB,
-				      SubPixelVerticalBGR,
-				      SubPixelNone };
-
-static const char * const output_names[] = { "None",
-					     "VGA",
-					     "DVI",
-					     "DVI",
-					     "DVI",
-					     "Composite",
-					     "S-video",
-					     "LVDS",
-					     "CTV",
-					     "DIN",
-					     "DisplayPort",
-					     "HDMI",
-					     "HDMI",
-					     "TV",
-					     "eDP",
-					     "Virtual",
-					     "DSI",
+    SubPixelHorizontalRGB,
+    SubPixelHorizontalBGR,
+    SubPixelVerticalRGB,
+    SubPixelVerticalBGR,
+    SubPixelNone
+};
+
+static const char *const output_names[] = { "None",
+    "VGA",
+    "DVI",
+    "DVI",
+    "DVI",
+    "Composite",
+    "S-video",
+    "LVDS",
+    "CTV",
+    "DIN",
+    "DisplayPort",
+    "HDMI",
+    "HDMI",
+    "TV",
+    "eDP",
+    "Virtual",
+    "DSI",
 };
 
 static void
-drmmode_output_init(ScrnInfoPtr pScrn, drmmode_ptr drmmode, int num, int *num_dvi, int *num_hdmi)
+drmmode_output_init(ScrnInfoPtr pScrn, drmmode_ptr drmmode, int num,
+                    int *num_dvi, int *num_hdmi)
 {
-	xf86OutputPtr output;
-	drmModeConnectorPtr koutput;
-	drmModeEncoderPtr *kencoders = NULL;
-	drmmode_output_private_ptr drmmode_output;
-	drmModePropertyPtr props;
-	char name[32];
-	int i;
-
-	koutput = drmModeGetConnector(drmmode->fd, drmmode->mode_res->connectors[num]);
-	if (!koutput)
-		return;
-
-	kencoders = calloc(sizeof(drmModeEncoderPtr), koutput->count_encoders);
-	if (!kencoders) {
-		goto out_free_encoders;
-	}
-
-	for (i = 0; i < koutput->count_encoders; i++) {
-		kencoders[i] = drmModeGetEncoder(drmmode->fd, koutput->encoders[i]);
-		if (!kencoders[i]) {
-			goto out_free_encoders;
-		}
-	}
-
-	/* need to do smart conversion here for compat with non-kms ATI driver */
-	if (koutput->connector_type >= MS_ARRAY_SIZE(output_names))
-		snprintf(name, 32, "Unknown-%d", koutput->connector_type_id - 1);
-	else if (pScrn->is_gpu)
-		snprintf(name, 32, "%s-%d-%d", output_names[koutput->connector_type], pScrn->scrnIndex - GPU_SCREEN_OFFSET + 1, koutput->connector_type_id - 1);
-	else
-		snprintf(name, 32, "%s-%d", output_names[koutput->connector_type], koutput->connector_type_id - 1);
-
-	output = xf86OutputCreate (pScrn, &drmmode_output_funcs, name);
-	if (!output) {
-		goto out_free_encoders;
-	}
-
-	drmmode_output = calloc(sizeof(drmmode_output_private_rec), 1);
-	if (!drmmode_output) {
-		xf86OutputDestroy(output);
-		goto out_free_encoders;
-	}
-
-	drmmode_output->output_id = drmmode->mode_res->connectors[num];
-	drmmode_output->mode_output = koutput;
-	drmmode_output->mode_encoders = kencoders;
-	drmmode_output->drmmode = drmmode;
-	output->mm_width = koutput->mmWidth;
-	output->mm_height = koutput->mmHeight;
-
-	output->subpixel_order = subpixel_conv_table[koutput->subpixel];
-	output->interlaceAllowed = TRUE;
-	output->doubleScanAllowed = TRUE;
-	output->driver_private = drmmode_output;
-	
-	output->possible_crtcs = 0x7f;
-	for (i = 0; i < koutput->count_encoders; i++) {
-		output->possible_crtcs &= kencoders[i]->possible_crtcs;
-	}
-	/* work out the possible clones later */
-	output->possible_clones = 0;
-
-	for (i = 0; i < koutput->count_props; i++) {
-		props = drmModeGetProperty(drmmode->fd, koutput->props[i]);
-		if (props && (props->flags & DRM_MODE_PROP_ENUM)) {
-			if (!strcmp(props->name, "DPMS")) {
-				drmmode_output->dpms_enum_id = koutput->props[i];
-				drmModeFreeProperty(props);
-				break;
-			}
-			drmModeFreeProperty(props);
-		}
-	}
-
-	return;
-out_free_encoders:
-	if (kencoders){
-		for (i = 0; i < koutput->count_encoders; i++)
-			drmModeFreeEncoder(kencoders[i]);
-		free(kencoders);
-	}
-	drmModeFreeConnector(koutput);
-	
+    xf86OutputPtr output;
+    drmModeConnectorPtr koutput;
+    drmModeEncoderPtr *kencoders = NULL;
+    drmmode_output_private_ptr drmmode_output;
+    drmModePropertyPtr props;
+    char name[32];
+    int i;
+
+    koutput =
+        drmModeGetConnector(drmmode->fd, drmmode->mode_res->connectors[num]);
+    if (!koutput)
+        return;
+
+    kencoders = calloc(sizeof(drmModeEncoderPtr), koutput->count_encoders);
+    if (!kencoders) {
+        goto out_free_encoders;
+    }
+
+    for (i = 0; i < koutput->count_encoders; i++) {
+        kencoders[i] = drmModeGetEncoder(drmmode->fd, koutput->encoders[i]);
+        if (!kencoders[i]) {
+            goto out_free_encoders;
+        }
+    }
+
+    /* need to do smart conversion here for compat with non-kms ATI driver */
+    if (koutput->connector_type >= MS_ARRAY_SIZE(output_names))
+        snprintf(name, 32, "Unknown-%d", koutput->connector_type_id - 1);
+    else if (pScrn->is_gpu)
+        snprintf(name, 32, "%s-%d-%d", output_names[koutput->connector_type],
+                 pScrn->scrnIndex - GPU_SCREEN_OFFSET + 1,
+                 koutput->connector_type_id - 1);
+    else
+        snprintf(name, 32, "%s-%d", output_names[koutput->connector_type],
+                 koutput->connector_type_id - 1);
+
+    output = xf86OutputCreate(pScrn, &drmmode_output_funcs, name);
+    if (!output) {
+        goto out_free_encoders;
+    }
+
+    drmmode_output = calloc(sizeof(drmmode_output_private_rec), 1);
+    if (!drmmode_output) {
+        xf86OutputDestroy(output);
+        goto out_free_encoders;
+    }
+
+    drmmode_output->output_id = drmmode->mode_res->connectors[num];
+    drmmode_output->mode_output = koutput;
+    drmmode_output->mode_encoders = kencoders;
+    drmmode_output->drmmode = drmmode;
+    output->mm_width = koutput->mmWidth;
+    output->mm_height = koutput->mmHeight;
+
+    output->subpixel_order = subpixel_conv_table[koutput->subpixel];
+    output->interlaceAllowed = TRUE;
+    output->doubleScanAllowed = TRUE;
+    output->driver_private = drmmode_output;
+
+    output->possible_crtcs = 0x7f;
+    for (i = 0; i < koutput->count_encoders; i++) {
+        output->possible_crtcs &= kencoders[i]->possible_crtcs;
+    }
+    /* work out the possible clones later */
+    output->possible_clones = 0;
+
+    for (i = 0; i < koutput->count_props; i++) {
+        props = drmModeGetProperty(drmmode->fd, koutput->props[i]);
+        if (props && (props->flags & DRM_MODE_PROP_ENUM)) {
+            if (!strcmp(props->name, "DPMS")) {
+                drmmode_output->dpms_enum_id = koutput->props[i];
+                drmModeFreeProperty(props);
+                break;
+            }
+            drmModeFreeProperty(props);
+        }
+    }
+
+    return;
+ out_free_encoders:
+    if (kencoders) {
+        for (i = 0; i < koutput->count_encoders; i++)
+            drmModeFreeEncoder(kencoders[i]);
+        free(kencoders);
+    }
+    drmModeFreeConnector(koutput);
+
 }
 
-static uint32_t find_clones(ScrnInfoPtr scrn, xf86OutputPtr output)
+static uint32_t
+find_clones(ScrnInfoPtr scrn, xf86OutputPtr output)
 {
-	drmmode_output_private_ptr drmmode_output = output->driver_private, clone_drmout;
-	int i;
-	xf86OutputPtr clone_output;
-	xf86CrtcConfigPtr   xf86_config = XF86_CRTC_CONFIG_PTR(scrn);
-	int index_mask = 0;
-
-	if (drmmode_output->enc_clone_mask == 0)
-		return index_mask;
-
-	for (i = 0; i < xf86_config->num_output; i++) {
-		clone_output = xf86_config->output[i];
-		clone_drmout = clone_output->driver_private;
-		if (output == clone_output)
-			continue;
-		
-		if (clone_drmout->enc_mask == 0)
-			continue;
-		if (drmmode_output->enc_clone_mask == clone_drmout->enc_mask)
-			index_mask |= (1 << i);
-	}
-	return index_mask;
+    drmmode_output_private_ptr drmmode_output =
+        output->driver_private, clone_drmout;
+    int i;
+    xf86OutputPtr clone_output;
+    xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(scrn);
+    int index_mask = 0;
+
+    if (drmmode_output->enc_clone_mask == 0)
+        return index_mask;
+
+    for (i = 0; i < xf86_config->num_output; i++) {
+        clone_output = xf86_config->output[i];
+        clone_drmout = clone_output->driver_private;
+        if (output == clone_output)
+            continue;
+
+        if (clone_drmout->enc_mask == 0)
+            continue;
+        if (drmmode_output->enc_clone_mask == clone_drmout->enc_mask)
+            index_mask |= (1 << i);
+    }
+    return index_mask;
 }
 
-
 static void
 drmmode_clones_init(ScrnInfoPtr scrn, drmmode_ptr drmmode)
 {
-	int i, j;
-	xf86CrtcConfigPtr   xf86_config = XF86_CRTC_CONFIG_PTR(scrn);
-
-	for (i = 0; i < xf86_config->num_output; i++) {
-		xf86OutputPtr output = xf86_config->output[i];
-		drmmode_output_private_ptr drmmode_output;
-
-		drmmode_output = output->driver_private;
-		drmmode_output->enc_clone_mask = 0xff;
-		/* and all the possible encoder clones for this output together */
-		for (j = 0; j < drmmode_output->mode_output->count_encoders; j++)
-		{
-			int k;
-			for (k = 0; k < drmmode->mode_res->count_encoders; k++) {
-				if (drmmode->mode_res->encoders[k] == drmmode_output->mode_encoders[j]->encoder_id)
-					drmmode_output->enc_mask |= (1 << k);
-			}
-
-			drmmode_output->enc_clone_mask &= drmmode_output->mode_encoders[j]->possible_clones;
-		}
-	}
-
-	for (i = 0; i < xf86_config->num_output; i++) {
-		xf86OutputPtr output = xf86_config->output[i];
-		output->possible_clones = find_clones(scrn, output);
-	}
+    int i, j;
+    xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(scrn);
+
+    for (i = 0; i < xf86_config->num_output; i++) {
+        xf86OutputPtr output = xf86_config->output[i];
+        drmmode_output_private_ptr drmmode_output;
+
+        drmmode_output = output->driver_private;
+        drmmode_output->enc_clone_mask = 0xff;
+        /* and all the possible encoder clones for this output together */
+        for (j = 0; j < drmmode_output->mode_output->count_encoders; j++) {
+            int k;
+
+            for (k = 0; k < drmmode->mode_res->count_encoders; k++) {
+                if (drmmode->mode_res->encoders[k] ==
+                    drmmode_output->mode_encoders[j]->encoder_id)
+                    drmmode_output->enc_mask |= (1 << k);
+            }
+
+            drmmode_output->enc_clone_mask &=
+                drmmode_output->mode_encoders[j]->possible_clones;
+        }
+    }
+
+    for (i = 0; i < xf86_config->num_output; i++) {
+        xf86OutputPtr output = xf86_config->output[i];
+
+        output->possible_clones = find_clones(scrn, output);
+    }
 }
 
 static Bool
-drmmode_xf86crtc_resize (ScrnInfoPtr scrn, int width, int height)
+drmmode_xf86crtc_resize(ScrnInfoPtr scrn, int width, int height)
 {
-	xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(scrn);
-	drmmode_crtc_private_ptr
-		    drmmode_crtc = xf86_config->crtc[0]->driver_private;
-	drmmode_ptr drmmode = drmmode_crtc->drmmode;
-	struct dumb_bo *old_front = NULL;
-	Bool	    ret;
-	ScreenPtr   screen = xf86ScrnToScreen(scrn);
-	uint32_t    old_fb_id;
-	int	    i, pitch, old_width, old_height, old_pitch;
-	int cpp = (scrn->bitsPerPixel + 7) / 8;
-	PixmapPtr ppix = screen->GetScreenPixmap(screen);
-	void *new_pixels;
-
-	if (scrn->virtualX == width && scrn->virtualY == height)
-		return TRUE;
-
-	xf86DrvMsg(scrn->scrnIndex, X_INFO,
-		   "Allocate new frame buffer %dx%d stride\n",
-		   width, height);
-
-	old_width = scrn->virtualX;
-	old_height = scrn->virtualY;
-	old_pitch = drmmode->front_bo->pitch;
-	old_fb_id = drmmode->fb_id;
-	old_front = drmmode->front_bo;
-
-	drmmode->front_bo = dumb_bo_create(drmmode->fd, width, height, scrn->bitsPerPixel);
-	if (!drmmode->front_bo)
-		goto fail;
-
-	pitch = drmmode->front_bo->pitch;
-
-	scrn->virtualX = width;
-	scrn->virtualY = height;
-	scrn->displayWidth = pitch / cpp;
-
-	ret = drmModeAddFB(drmmode->fd, width, height, scrn->depth,
-			   scrn->bitsPerPixel, pitch,
-			   drmmode->front_bo->handle,
-			   &drmmode->fb_id);
-	if (ret)
-		goto fail;
-	
-	new_pixels  = drmmode_map_front_bo(drmmode);
-	if (!new_pixels)
-		goto fail;
-
-	if (!drmmode->shadow_enable)
-		screen->ModifyPixmapHeader(ppix, width, height, -1, -1,
-					   pitch, new_pixels);
-	else {
-		void *new_shadow;
-		uint32_t size = scrn->displayWidth * scrn->virtualY *
-			((scrn->bitsPerPixel + 7) >> 3);
-		new_shadow = calloc(1, size);
-		if (new_shadow == NULL)
-			goto fail;
-		free(drmmode->shadow_fb);
-		drmmode->shadow_fb = new_shadow;
-		screen->ModifyPixmapHeader(ppix, width, height, -1, -1,
-					   pitch, drmmode->shadow_fb);
-	}
-
-	for (i = 0; i < xf86_config->num_crtc; i++) {
-		xf86CrtcPtr crtc = xf86_config->crtc[i];
-
-		if (!crtc->enabled)
-			continue;
-
-		drmmode_set_mode_major(crtc, &crtc->mode,
-				       crtc->rotation, crtc->x, crtc->y);
-	}
-
-	if (old_fb_id) {
-		drmModeRmFB(drmmode->fd, old_fb_id);
-		dumb_bo_destroy(drmmode->fd, old_front);
-	}
-
-	return TRUE;
+    xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(scrn);
+
+    drmmode_crtc_private_ptr
+        drmmode_crtc = xf86_config->crtc[0]->driver_private;
+    drmmode_ptr drmmode = drmmode_crtc->drmmode;
+    struct dumb_bo *old_front = NULL;
+    Bool ret;
+    ScreenPtr screen = xf86ScrnToScreen(scrn);
+    uint32_t old_fb_id;
+    int i, pitch, old_width, old_height, old_pitch;
+    int cpp = (scrn->bitsPerPixel + 7) / 8;
+    PixmapPtr ppix = screen->GetScreenPixmap(screen);
+    void *new_pixels;
+
+    if (scrn->virtualX == width && scrn->virtualY == height)
+        return TRUE;
+
+    xf86DrvMsg(scrn->scrnIndex, X_INFO,
+               "Allocate new frame buffer %dx%d stride\n", width, height);
+
+    old_width = scrn->virtualX;
+    old_height = scrn->virtualY;
+    old_pitch = drmmode->front_bo->pitch;
+    old_fb_id = drmmode->fb_id;
+    old_front = drmmode->front_bo;
+
+    drmmode->front_bo =
+        dumb_bo_create(drmmode->fd, width, height, scrn->bitsPerPixel);
+    if (!drmmode->front_bo)
+        goto fail;
+
+    pitch = drmmode->front_bo->pitch;
+
+    scrn->virtualX = width;
+    scrn->virtualY = height;
+    scrn->displayWidth = pitch / cpp;
+
+    ret = drmModeAddFB(drmmode->fd, width, height, scrn->depth,
+                       scrn->bitsPerPixel, pitch,
+                       drmmode->front_bo->handle, &drmmode->fb_id);
+    if (ret)
+        goto fail;
+
+    new_pixels = drmmode_map_front_bo(drmmode);
+    if (!new_pixels)
+        goto fail;
+
+    if (!drmmode->shadow_enable)
+        screen->ModifyPixmapHeader(ppix, width, height, -1, -1,
+                                   pitch, new_pixels);
+    else {
+        void *new_shadow;
+        uint32_t size = scrn->displayWidth * scrn->virtualY *
+            ((scrn->bitsPerPixel + 7) >> 3);
+        new_shadow = calloc(1, size);
+        if (new_shadow == NULL)
+            goto fail;
+        free(drmmode->shadow_fb);
+        drmmode->shadow_fb = new_shadow;
+        screen->ModifyPixmapHeader(ppix, width, height, -1, -1,
+                                   pitch, drmmode->shadow_fb);
+    }
+
+    for (i = 0; i < xf86_config->num_crtc; i++) {
+        xf86CrtcPtr crtc = xf86_config->crtc[i];
+
+        if (!crtc->enabled)
+            continue;
+
+        drmmode_set_mode_major(crtc, &crtc->mode,
+                               crtc->rotation, crtc->x, crtc->y);
+    }
+
+    if (old_fb_id) {
+        drmModeRmFB(drmmode->fd, old_fb_id);
+        dumb_bo_destroy(drmmode->fd, old_front);
+    }
+
+    return TRUE;
 
  fail:
-	if (drmmode->front_bo)
-		dumb_bo_destroy(drmmode->fd, drmmode->front_bo);
-	drmmode->front_bo = old_front;
-	scrn->virtualX = old_width;
-	scrn->virtualY = old_height;
-	scrn->displayWidth = old_pitch / cpp;
-	drmmode->fb_id = old_fb_id;
-
-	return FALSE;
+    if (drmmode->front_bo)
+        dumb_bo_destroy(drmmode->fd, drmmode->front_bo);
+    drmmode->front_bo = old_front;
+    scrn->virtualX = old_width;
+    scrn->virtualY = old_height;
+    scrn->displayWidth = old_pitch / cpp;
+    drmmode->fb_id = old_fb_id;
+
+    return FALSE;
 }
 
 static const xf86CrtcConfigFuncsRec drmmode_xf86crtc_config_funcs = {
-	drmmode_xf86crtc_resize
+    drmmode_xf86crtc_resize
 };
 
-Bool drmmode_pre_init(ScrnInfoPtr pScrn, drmmode_ptr drmmode, int cpp)
+Bool
+drmmode_pre_init(ScrnInfoPtr pScrn, drmmode_ptr drmmode, int cpp)
 {
-	int i, num_dvi = 0, num_hdmi = 0;
-	int ret;
-	uint64_t value = 0;
-
-	/* check for dumb capability */
-	ret = drmGetCap(drmmode->fd, DRM_CAP_DUMB_BUFFER, &value);
-	if (ret > 0 || value != 1) {
-		xf86DrvMsg(pScrn->scrnIndex, X_ERROR, "KMS doesn't support dumb interface\n");
-		return FALSE;
-	}
+    int i, num_dvi = 0, num_hdmi = 0;
+    int ret;
+    uint64_t value = 0;
+
+    /* check for dumb capability */
+    ret = drmGetCap(drmmode->fd, DRM_CAP_DUMB_BUFFER, &value);
+    if (ret > 0 || value != 1) {
+        xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
+                   "KMS doesn't support dumb interface\n");
+        return FALSE;
+    }
 
-	xf86CrtcConfigInit(pScrn, &drmmode_xf86crtc_config_funcs);
+    xf86CrtcConfigInit(pScrn, &drmmode_xf86crtc_config_funcs);
 
-	drmmode->scrn = pScrn;
-	drmmode->cpp = cpp;
-	drmmode->mode_res = drmModeGetResources(drmmode->fd);
-	if (!drmmode->mode_res)
-		return FALSE;
+    drmmode->scrn = pScrn;
+    drmmode->cpp = cpp;
+    drmmode->mode_res = drmModeGetResources(drmmode->fd);
+    if (!drmmode->mode_res)
+        return FALSE;
 
-	xf86CrtcSetSizeRange(pScrn, 320, 200, drmmode->mode_res->max_width, drmmode->mode_res->max_height);
-	for (i = 0; i < drmmode->mode_res->count_crtcs; i++)
-		if (!xf86IsEntityShared(pScrn->entityList[0]) || pScrn->confScreen->device->screen == i)
-			drmmode_crtc_init(pScrn, drmmode, i);
+    xf86CrtcSetSizeRange(pScrn, 320, 200, drmmode->mode_res->max_width,
+                         drmmode->mode_res->max_height);
+    for (i = 0; i < drmmode->mode_res->count_crtcs; i++)
+        if (!xf86IsEntityShared(pScrn->entityList[0]) ||
+            pScrn->confScreen->device->screen == i)
+            drmmode_crtc_init(pScrn, drmmode, i);
 
-	for (i = 0; i < drmmode->mode_res->count_connectors; i++)
-		drmmode_output_init(pScrn, drmmode, i, &num_dvi, &num_hdmi);
+    for (i = 0; i < drmmode->mode_res->count_connectors; i++)
+        drmmode_output_init(pScrn, drmmode, i, &num_dvi, &num_hdmi);
 
-	/* workout clones */
-	drmmode_clones_init(pScrn, drmmode);
+    /* workout clones */
+    drmmode_clones_init(pScrn, drmmode);
 
 #if XF86_CRTC_VERSION >= 5
-	xf86ProviderSetup(pScrn, NULL, "modesetting");
+    xf86ProviderSetup(pScrn, NULL, "modesetting");
 #endif
 
-	xf86InitialConfiguration(pScrn, TRUE);
+    xf86InitialConfiguration(pScrn, TRUE);
 
-	return TRUE;
+    return TRUE;
 }
 
-void drmmode_adjust_frame(ScrnInfoPtr pScrn, drmmode_ptr drmmode, int x, int y)
+void
+drmmode_adjust_frame(ScrnInfoPtr pScrn, drmmode_ptr drmmode, int x, int y)
 {
-	xf86CrtcConfigPtr	config = XF86_CRTC_CONFIG_PTR(pScrn);
-	xf86OutputPtr  output = config->output[config->compat_output];
-	xf86CrtcPtr	crtc = output->crtc;
-
-	if (crtc && crtc->enabled) {
-		drmmode_set_mode_major(crtc, &crtc->mode, crtc->rotation,
-				       x, y);
-	}
+    xf86CrtcConfigPtr config = XF86_CRTC_CONFIG_PTR(pScrn);
+    xf86OutputPtr output = config->output[config->compat_output];
+    xf86CrtcPtr crtc = output->crtc;
+
+    if (crtc && crtc->enabled) {
+        drmmode_set_mode_major(crtc, &crtc->mode, crtc->rotation, x, y);
+    }
 }
 
-Bool drmmode_set_desired_modes(ScrnInfoPtr pScrn, drmmode_ptr drmmode)
+Bool
+drmmode_set_desired_modes(ScrnInfoPtr pScrn, drmmode_ptr drmmode)
 {
-	xf86CrtcConfigPtr   config = XF86_CRTC_CONFIG_PTR(pScrn);
-	int c;
-
-	for (c = 0; c < config->num_crtc; c++) {
-		xf86CrtcPtr	crtc = config->crtc[c];
-		drmmode_crtc_private_ptr drmmode_crtc = crtc->driver_private;
-		xf86OutputPtr	output = NULL;
-		int		o;
-
-		/* Skip disabled CRTCs */
-		if (!crtc->enabled) {
-			drmModeSetCrtc(drmmode->fd, drmmode_crtc->mode_crtc->crtc_id,
-				       0, 0, 0, NULL, 0, NULL);
-			continue;
-		}
-
-		if (config->output[config->compat_output]->crtc == crtc)
-			output = config->output[config->compat_output];
-		else
-		{
-			for (o = 0; o < config->num_output; o++)
-				if (config->output[o]->crtc == crtc)
-				{
-					output = config->output[o];
-					break;
-				}
-		}
-		/* paranoia */
-		if (!output)
-			continue;
-
-		/* Mark that we'll need to re-set the mode for sure */
-		memset(&crtc->mode, 0, sizeof(crtc->mode));
-		if (!crtc->desiredMode.CrtcHDisplay)
-		{
-			DisplayModePtr  mode = xf86OutputFindClosestMode (output, pScrn->currentMode);
-
-			if (!mode)
-				return FALSE;
-			crtc->desiredMode = *mode;
-			crtc->desiredRotation = RR_Rotate_0;
-			crtc->desiredX = 0;
-			crtc->desiredY = 0;
-		}
-
-		if (!crtc->funcs->set_mode_major(crtc, &crtc->desiredMode, crtc->desiredRotation,
-						 crtc->desiredX, crtc->desiredY))
-			return FALSE;
-	}
-	return TRUE;
+    xf86CrtcConfigPtr config = XF86_CRTC_CONFIG_PTR(pScrn);
+    int c;
+
+    for (c = 0; c < config->num_crtc; c++) {
+        xf86CrtcPtr crtc = config->crtc[c];
+        drmmode_crtc_private_ptr drmmode_crtc = crtc->driver_private;
+        xf86OutputPtr output = NULL;
+        int o;
+
+        /* Skip disabled CRTCs */
+        if (!crtc->enabled) {
+            drmModeSetCrtc(drmmode->fd, drmmode_crtc->mode_crtc->crtc_id,
+                           0, 0, 0, NULL, 0, NULL);
+            continue;
+        }
+
+        if (config->output[config->compat_output]->crtc == crtc)
+            output = config->output[config->compat_output];
+        else {
+            for (o = 0; o < config->num_output; o++)
+                if (config->output[o]->crtc == crtc) {
+                    output = config->output[o];
+                    break;
+                }
+        }
+        /* paranoia */
+        if (!output)
+            continue;
+
+        /* Mark that we'll need to re-set the mode for sure */
+        memset(&crtc->mode, 0, sizeof(crtc->mode));
+        if (!crtc->desiredMode.CrtcHDisplay) {
+            DisplayModePtr mode =
+                xf86OutputFindClosestMode(output, pScrn->currentMode);
+
+            if (!mode)
+                return FALSE;
+            crtc->desiredMode = *mode;
+            crtc->desiredRotation = RR_Rotate_0;
+            crtc->desiredX = 0;
+            crtc->desiredY = 0;
+        }
+
+        if (!crtc->funcs->
+            set_mode_major(crtc, &crtc->desiredMode, crtc->desiredRotation,
+                           crtc->desiredX, crtc->desiredY))
+            return FALSE;
+    }
+    return TRUE;
 }
 
-static void drmmode_load_palette(ScrnInfoPtr pScrn, int numColors,
-                                 int *indices, LOCO *colors, VisualPtr pVisual)
+static void
+drmmode_load_palette(ScrnInfoPtr pScrn, int numColors,
+                     int *indices, LOCO * colors, VisualPtr pVisual)
 {
-    xf86CrtcConfigPtr   xf86_config = XF86_CRTC_CONFIG_PTR(pScrn);
-    uint16_t       lut_r[256], lut_g[256], lut_b[256];
+    xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(pScrn);
+    uint16_t lut_r[256], lut_g[256], lut_b[256];
     int index, j, i;
     int c;
 
     for (c = 0; c < xf86_config->num_crtc; c++) {
         xf86CrtcPtr crtc = xf86_config->crtc[c];
-	drmmode_crtc_private_ptr drmmode_crtc = crtc->driver_private;
+        drmmode_crtc_private_ptr drmmode_crtc = crtc->driver_private;
 
-        for (i = 0 ; i < 256; i++) {
+        for (i = 0; i < 256; i++) {
             lut_r[i] = drmmode_crtc->lut_r[i] << 6;
             lut_g[i] = drmmode_crtc->lut_g[i] << 6;
             lut_b[i] = drmmode_crtc->lut_b[i] << 6;
         }
 
-        switch(pScrn->depth) {
+        switch (pScrn->depth) {
         case 15:
             for (i = 0; i < numColors; i++) {
                 index = indices[i];
@@ -1356,56 +1396,55 @@ static void drmmode_load_palette(ScrnInfoPtr pScrn, int numColors,
                     lut_b[index * 8 + j] = colors[index].blue << 6;
                 }
             }
-         break;
-         case 16:
-             for (i = 0; i < numColors; i++) {
-                 index = indices[i];
-
-                  if (i <= 31) {
-                      for (j = 0; j < 8; j++) {
-                          lut_r[index * 8 + j] = colors[index].red << 6;
-                          lut_b[index * 8 + j] = colors[index].blue << 6;
-                      }
-                  }
-
-                  for (j = 0; j < 4; j++) {
-                      lut_g[index * 4 + j] = colors[index].green << 6;
-                  }
-              }
-	  break;
-          default:
-              for (i = 0; i < numColors; i++) {
-                  index = indices[i];
-                  lut_r[index] = colors[index].red << 6;
-                  lut_g[index] = colors[index].green << 6;
-                  lut_b[index] = colors[index].blue << 6;
-              }
-              break;
-          }
-
-    /* Make the change through RandR */
+            break;
+        case 16:
+            for (i = 0; i < numColors; i++) {
+                index = indices[i];
+
+                if (i <= 31) {
+                    for (j = 0; j < 8; j++) {
+                        lut_r[index * 8 + j] = colors[index].red << 6;
+                        lut_b[index * 8 + j] = colors[index].blue << 6;
+                    }
+                }
+
+                for (j = 0; j < 4; j++) {
+                    lut_g[index * 4 + j] = colors[index].green << 6;
+                }
+            }
+            break;
+        default:
+            for (i = 0; i < numColors; i++) {
+                index = indices[i];
+                lut_r[index] = colors[index].red << 6;
+                lut_g[index] = colors[index].green << 6;
+                lut_b[index] = colors[index].blue << 6;
+            }
+            break;
+        }
+
+        /* Make the change through RandR */
         if (crtc->randr_crtc)
             RRCrtcGammaSet(crtc->randr_crtc, lut_r, lut_g, lut_b);
         else
             crtc->funcs->gamma_set(crtc, lut_r, lut_g, lut_b, 256);
-     }
+    }
 }
 
-Bool drmmode_setup_colormap(ScreenPtr pScreen, ScrnInfoPtr pScrn)
+Bool
+drmmode_setup_colormap(ScreenPtr pScreen, ScrnInfoPtr pScrn)
 {
-    xf86DrvMsgVerb(pScrn->scrnIndex, X_INFO, 0,
-                  "Initializing kms color map\n");
+    xf86DrvMsgVerb(pScrn->scrnIndex, X_INFO, 0, "Initializing kms color map\n");
     if (!miCreateDefColormap(pScreen))
         return FALSE;
     /* all radeons support 10 bit CLUTs */
     if (!xf86HandleColormaps(pScreen, 256, 10,
-                             drmmode_load_palette, NULL,
-                             CMAP_PALETTED_TRUECOLOR
-#if 0 /* This option messes up text mode! (eich at suse.de) */
+                             drmmode_load_palette, NULL, CMAP_PALETTED_TRUECOLOR
+#if 0                           /* This option messes up text mode! (eich at suse.de) */
                              | CMAP_LOAD_EVEN_IF_OFFSCREEN
 #endif
                              | CMAP_RELOAD_ON_MODE_SWITCH))
-         return FALSE;
+        return FALSE;
     return TRUE;
 }
 
@@ -1413,204 +1452,220 @@ Bool drmmode_setup_colormap(ScreenPtr pScreen, ScrnInfoPtr pScrn)
 static void
 drmmode_handle_uevents(int fd, void *closure)
 {
-	drmmode_ptr drmmode = closure;
-	ScrnInfoPtr scrn = drmmode->scrn;
-	struct udev_device *dev;
-	dev = udev_monitor_receive_device(drmmode->uevent_monitor);
-	if (!dev)
-		return;
-
-	RRGetInfo(xf86ScrnToScreen(scrn), TRUE);
-	udev_device_unref(dev);
+    drmmode_ptr drmmode = closure;
+    ScrnInfoPtr scrn = drmmode->scrn;
+    struct udev_device *dev;
+
+    dev = udev_monitor_receive_device(drmmode->uevent_monitor);
+    if (!dev)
+        return;
+
+    RRGetInfo(xf86ScrnToScreen(scrn), TRUE);
+    udev_device_unref(dev);
 }
 #endif
 
-void drmmode_uevent_init(ScrnInfoPtr scrn, drmmode_ptr drmmode)
+void
+drmmode_uevent_init(ScrnInfoPtr scrn, drmmode_ptr drmmode)
 {
 #ifdef HAVE_UDEV
-	struct udev *u;
-	struct udev_monitor *mon;
-
-	u = udev_new();
-	if (!u)
-		return;
-	mon = udev_monitor_new_from_netlink(u, "udev");
-	if (!mon) {
-		udev_unref(u);
-		return;
-	}
-
-	if (udev_monitor_filter_add_match_subsystem_devtype(mon,
-							    "drm",
-							    "drm_minor") < 0 ||
-	    udev_monitor_enable_receiving(mon) < 0) {
-		udev_monitor_unref(mon);
-		udev_unref(u);
-		return;
-	}
-
-	drmmode->uevent_handler =
-		xf86AddGeneralHandler(udev_monitor_get_fd(mon),
-				      drmmode_handle_uevents,
-				      drmmode);
-
-	drmmode->uevent_monitor = mon;
+    struct udev *u;
+    struct udev_monitor *mon;
+
+    u = udev_new();
+    if (!u)
+        return;
+    mon = udev_monitor_new_from_netlink(u, "udev");
+    if (!mon) {
+        udev_unref(u);
+        return;
+    }
+
+    if (udev_monitor_filter_add_match_subsystem_devtype(mon,
+                                                        "drm",
+                                                        "drm_minor") < 0 ||
+        udev_monitor_enable_receiving(mon) < 0) {
+        udev_monitor_unref(mon);
+        udev_unref(u);
+        return;
+    }
+
+    drmmode->uevent_handler =
+        xf86AddGeneralHandler(udev_monitor_get_fd(mon),
+                              drmmode_handle_uevents, drmmode);
+
+    drmmode->uevent_monitor = mon;
 #endif
 }
 
-void drmmode_uevent_fini(ScrnInfoPtr scrn, drmmode_ptr drmmode)
+void
+drmmode_uevent_fini(ScrnInfoPtr scrn, drmmode_ptr drmmode)
 {
 #ifdef HAVE_UDEV
-	if (drmmode->uevent_handler) {
-		struct udev *u = udev_monitor_get_udev(drmmode->uevent_monitor);
-		xf86RemoveGeneralHandler(drmmode->uevent_handler);
+    if (drmmode->uevent_handler) {
+        struct udev *u = udev_monitor_get_udev(drmmode->uevent_monitor);
+
+        xf86RemoveGeneralHandler(drmmode->uevent_handler);
 
-		udev_monitor_unref(drmmode->uevent_monitor);
-		udev_unref(u);
-	}
+        udev_monitor_unref(drmmode->uevent_monitor);
+        udev_unref(u);
+    }
 #endif
 }
 
 /* create front and cursor BOs */
-Bool drmmode_create_initial_bos(ScrnInfoPtr pScrn, drmmode_ptr drmmode)
+Bool
+drmmode_create_initial_bos(ScrnInfoPtr pScrn, drmmode_ptr drmmode)
 {
-	modesettingPtr ms = modesettingPTR(pScrn);
-	xf86CrtcConfigPtr   xf86_config = XF86_CRTC_CONFIG_PTR(pScrn);
-	int width;
-	int height;
-	int bpp = pScrn->bitsPerPixel;
-	int i;
-	int cpp = (bpp + 7) / 8;
-
-	width = pScrn->virtualX;
-	height = pScrn->virtualY;
-
-	drmmode->front_bo = dumb_bo_create(drmmode->fd, width, height, bpp);
-	if (!drmmode->front_bo)
-		return FALSE;
-	pScrn->displayWidth = drmmode->front_bo->pitch / cpp;
-
-	width = ms->cursor_width;
-	height = ms->cursor_height;
-	bpp = 32;
-	for (i = 0; i < xf86_config->num_crtc; i++) {
-		xf86CrtcPtr crtc = xf86_config->crtc[i];
-		drmmode_crtc_private_ptr drmmode_crtc = crtc->driver_private;
-		drmmode_crtc->cursor_bo = dumb_bo_create(drmmode->fd, width, height, bpp);
-	}
-	return TRUE;
+    modesettingPtr ms = modesettingPTR(pScrn);
+    xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(pScrn);
+    int width;
+    int height;
+    int bpp = pScrn->bitsPerPixel;
+    int i;
+    int cpp = (bpp + 7) / 8;
+
+    width = pScrn->virtualX;
+    height = pScrn->virtualY;
+
+    drmmode->front_bo = dumb_bo_create(drmmode->fd, width, height, bpp);
+    if (!drmmode->front_bo)
+        return FALSE;
+    pScrn->displayWidth = drmmode->front_bo->pitch / cpp;
+
+    width = ms->cursor_width;
+    height = ms->cursor_height;
+    bpp = 32;
+    for (i = 0; i < xf86_config->num_crtc; i++) {
+        xf86CrtcPtr crtc = xf86_config->crtc[i];
+        drmmode_crtc_private_ptr drmmode_crtc = crtc->driver_private;
+
+        drmmode_crtc->cursor_bo =
+            dumb_bo_create(drmmode->fd, width, height, bpp);
+    }
+    return TRUE;
 }
 
-void *drmmode_map_front_bo(drmmode_ptr drmmode)
+void *
+drmmode_map_front_bo(drmmode_ptr drmmode)
 {
-	int ret;
+    int ret;
 
-	if (drmmode->front_bo->ptr)
-		return drmmode->front_bo->ptr;
+    if (drmmode->front_bo->ptr)
+        return drmmode->front_bo->ptr;
 
-	ret = dumb_bo_map(drmmode->fd, drmmode->front_bo);
-	if (ret)
-		return NULL;
+    ret = dumb_bo_map(drmmode->fd, drmmode->front_bo);
+    if (ret)
+        return NULL;
+
+    return drmmode->front_bo->ptr;
 
-	return drmmode->front_bo->ptr;
-	
 }
 
-void *drmmode_map_slave_bo(drmmode_ptr drmmode, msPixmapPrivPtr ppriv)
+void *
+drmmode_map_slave_bo(drmmode_ptr drmmode, msPixmapPrivPtr ppriv)
 {
-        int ret;
+    int ret;
 
-        if (ppriv->backing_bo->ptr)
-                return ppriv->backing_bo->ptr;
+    if (ppriv->backing_bo->ptr)
+        return ppriv->backing_bo->ptr;
 
-        ret = dumb_bo_map(drmmode->fd, ppriv->backing_bo);
-        if (ret)
-                return NULL;
+    ret = dumb_bo_map(drmmode->fd, ppriv->backing_bo);
+    if (ret)
+        return NULL;
 
-        return ppriv->backing_bo->ptr;  
+    return ppriv->backing_bo->ptr;
 }
 
-Bool drmmode_map_cursor_bos(ScrnInfoPtr pScrn, drmmode_ptr drmmode)
+Bool
+drmmode_map_cursor_bos(ScrnInfoPtr pScrn, drmmode_ptr drmmode)
 {
-	xf86CrtcConfigPtr   xf86_config = XF86_CRTC_CONFIG_PTR(pScrn);
-	int i, ret;
-	for (i = 0; i < xf86_config->num_crtc; i++) {
-		xf86CrtcPtr crtc = xf86_config->crtc[i];
-		drmmode_crtc_private_ptr drmmode_crtc = crtc->driver_private;
-		ret = dumb_bo_map(drmmode->fd, drmmode_crtc->cursor_bo);
-		if (ret)
-			return FALSE;
-	}
-	return TRUE;
+    xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(pScrn);
+    int i, ret;
+
+    for (i = 0; i < xf86_config->num_crtc; i++) {
+        xf86CrtcPtr crtc = xf86_config->crtc[i];
+        drmmode_crtc_private_ptr drmmode_crtc = crtc->driver_private;
+
+        ret = dumb_bo_map(drmmode->fd, drmmode_crtc->cursor_bo);
+        if (ret)
+            return FALSE;
+    }
+    return TRUE;
 }
 
-void drmmode_free_bos(ScrnInfoPtr pScrn, drmmode_ptr drmmode)
+void
+drmmode_free_bos(ScrnInfoPtr pScrn, drmmode_ptr drmmode)
 {
-	xf86CrtcConfigPtr   xf86_config = XF86_CRTC_CONFIG_PTR(pScrn);
-	int i;
-
-	if (drmmode->fb_id) {
-		drmModeRmFB(drmmode->fd, drmmode->fb_id);
-		drmmode->fb_id = 0;
-	}
-
-	dumb_bo_destroy(drmmode->fd, drmmode->front_bo);
-	drmmode->front_bo = NULL;
-
-	for (i = 0; i < xf86_config->num_crtc; i++) {
-		xf86CrtcPtr crtc = xf86_config->crtc[i];
-		drmmode_crtc_private_ptr drmmode_crtc = crtc->driver_private;
-		dumb_bo_destroy(drmmode->fd, drmmode_crtc->cursor_bo);
-	}
+    xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(pScrn);
+    int i;
+
+    if (drmmode->fb_id) {
+        drmModeRmFB(drmmode->fd, drmmode->fb_id);
+        drmmode->fb_id = 0;
+    }
+
+    dumb_bo_destroy(drmmode->fd, drmmode->front_bo);
+    drmmode->front_bo = NULL;
+
+    for (i = 0; i < xf86_config->num_crtc; i++) {
+        xf86CrtcPtr crtc = xf86_config->crtc[i];
+        drmmode_crtc_private_ptr drmmode_crtc = crtc->driver_private;
+
+        dumb_bo_destroy(drmmode->fd, drmmode_crtc->cursor_bo);
+    }
 }
 
 /* ugly workaround to see if we can create 32bpp */
-void drmmode_get_default_bpp(ScrnInfoPtr pScrn, drmmode_ptr drmmode, int *depth, int *bpp)
+void
+drmmode_get_default_bpp(ScrnInfoPtr pScrn, drmmode_ptr drmmode, int *depth,
+                        int *bpp)
 {
-	drmModeResPtr mode_res;
-	uint64_t value;
-	struct dumb_bo *bo;
-	uint32_t fb_id;
-	int ret;
-
-	/* 16 is fine */
-	ret = drmGetCap(drmmode->fd, DRM_CAP_DUMB_PREFERRED_DEPTH, &value);
-	if (!ret && (value == 16 || value == 8)) {
-		*depth = value;
-		*bpp = value;
-		return;
-	}
-
-	*depth = 24;
-	mode_res = drmModeGetResources(drmmode->fd);
-	if (!mode_res)
-		return;
-
-	if (mode_res->min_width == 0)
-		mode_res->min_width = 1;
-	if (mode_res->min_height == 0)
-		mode_res->min_height = 1;
-	/*create a bo */
-	bo = dumb_bo_create(drmmode->fd, mode_res->min_width, mode_res->min_height, 32);
-	if (!bo) {
-		*bpp = 24;
-		goto out;
-	}
-
-	ret = drmModeAddFB(drmmode->fd, mode_res->min_width, mode_res->min_height,
-			    24, 32, bo->pitch, bo->handle, &fb_id);
-
-	if (ret) {
-		*bpp = 24;
-		dumb_bo_destroy(drmmode->fd, bo);
-		goto out;
-	}
-
-	drmModeRmFB(drmmode->fd, fb_id);
-	*bpp = 32;
-
-	dumb_bo_destroy(drmmode->fd, bo);
-out:	
-	drmModeFreeResources(mode_res);
-	return;
+    drmModeResPtr mode_res;
+    uint64_t value;
+    struct dumb_bo *bo;
+    uint32_t fb_id;
+    int ret;
+
+    /* 16 is fine */
+    ret = drmGetCap(drmmode->fd, DRM_CAP_DUMB_PREFERRED_DEPTH, &value);
+    if (!ret && (value == 16 || value == 8)) {
+        *depth = value;
+        *bpp = value;
+        return;
+    }
+
+    *depth = 24;
+    mode_res = drmModeGetResources(drmmode->fd);
+    if (!mode_res)
+        return;
+
+    if (mode_res->min_width == 0)
+        mode_res->min_width = 1;
+    if (mode_res->min_height == 0)
+        mode_res->min_height = 1;
+    /*create a bo */
+    bo = dumb_bo_create(drmmode->fd, mode_res->min_width, mode_res->min_height,
+                        32);
+    if (!bo) {
+        *bpp = 24;
+        goto out;
+    }
+
+    ret = drmModeAddFB(drmmode->fd, mode_res->min_width, mode_res->min_height,
+                       24, 32, bo->pitch, bo->handle, &fb_id);
+
+    if (ret) {
+        *bpp = 24;
+        dumb_bo_destroy(drmmode->fd, bo);
+        goto out;
+    }
+
+    drmModeRmFB(drmmode->fd, fb_id);
+    *bpp = 32;
+
+    dumb_bo_destroy(drmmode->fd, bo);
+ out:
+    drmModeFreeResources(mode_res);
+    return;
 }
diff --git a/hw/xfree86/drivers/modesetting/drmmode_display.h b/hw/xfree86/drivers/modesetting/drmmode_display.h
index 7bfe885..438743b 100644
--- a/hw/xfree86/drivers/modesetting/drmmode_display.h
+++ b/hw/xfree86/drivers/modesetting/drmmode_display.h
@@ -74,11 +74,10 @@ typedef struct {
 typedef struct {
     drmModePropertyPtr mode_prop;
     uint64_t value;
-    int num_atoms; /* if range prop, num_atoms == 1; if enum prop, num_atoms == num_enums + 1 */
+    int num_atoms;              /* if range prop, num_atoms == 1; if enum prop, num_atoms == num_enums + 1 */
     Atom *atoms;
 } drmmode_prop_rec, *drmmode_prop_ptr;
 
-
 typedef struct {
     drmmode_ptr drmmode;
     int output_id;
@@ -97,16 +96,16 @@ typedef struct _msPixmapPriv {
     struct dumb_bo *backing_bo; /* if this pixmap is backed by a dumb bo */
 } msPixmapPrivRec, *msPixmapPrivPtr;
 
-
 extern DevPrivateKeyRec msPixmapPrivateKeyRec;
+
 #define msPixmapPrivateKey (&msPixmapPrivateKeyRec)
 
 #define msGetPixmapPriv(drmmode, p) ((msPixmapPrivPtr)dixGetPrivateAddr(&(p)->devPrivates, &(drmmode)->pixmapPrivateKeyRec))
 
 void *drmmode_map_slave_bo(drmmode_ptr drmmode, msPixmapPrivPtr ppriv);
 Bool drmmode_SetSlaveBO(PixmapPtr ppix,
-			drmmode_ptr drmmode,
-			int fd_handle, int pitch, int size);
+                        drmmode_ptr drmmode,
+                        int fd_handle, int pitch, int size);
 
 extern Bool drmmode_pre_init(ScrnInfoPtr pScrn, drmmode_ptr drmmode, int cpp);
 void drmmode_adjust_frame(ScrnInfoPtr pScrn, drmmode_ptr drmmode, int x, int y);
@@ -120,8 +119,8 @@ Bool drmmode_create_initial_bos(ScrnInfoPtr pScrn, drmmode_ptr drmmode);
 void *drmmode_map_front_bo(drmmode_ptr drmmode);
 Bool drmmode_map_cursor_bos(ScrnInfoPtr pScrn, drmmode_ptr drmmode);
 void drmmode_free_bos(ScrnInfoPtr pScrn, drmmode_ptr drmmode);
-void drmmode_get_default_bpp(ScrnInfoPtr pScrn, drmmode_ptr drmmmode, int *depth, int *bpp);
-
+void drmmode_get_default_bpp(ScrnInfoPtr pScrn, drmmode_ptr drmmmode,
+                             int *depth, int *bpp);
 
 #ifndef DRM_CAP_DUMB_PREFERRED_DEPTH
 #define DRM_CAP_DUMB_PREFERRED_DEPTH 3
@@ -132,5 +131,4 @@ void drmmode_get_default_bpp(ScrnInfoPtr pScrn, drmmode_ptr drmmmode, int *depth
 
 #define MS_ARRAY_SIZE(x) (sizeof(x)/sizeof(x[0]))
 
-
 #endif
commit c79f824bf6617816aaf10393beec8dddfa591f7b
Author: Adam Jackson <ajax at redhat.com>
Date:   Thu Sep 25 15:49:26 2014 -0400

    xwin: Remove primary DirectDraw engine
    
    Again, as the documentation says, "unsupported, obsolete".
    
    Reviewed-by: Jon TURNEY <jon.turney at dronecode.org.uk>
    Signed-off-by: Adam Jackson <ajax at redhat.com>

diff --git a/configure.ac b/configure.ac
index a12e9e2..3a72947 100644
--- a/configure.ac
+++ b/configure.ac
@@ -2206,7 +2206,6 @@ AM_CONDITIONAL(XWIN_MULTIWINDOW, [test "x$XWIN" = xyes])
 AM_CONDITIONAL(XWIN_MULTIWINDOWEXTWM, [test "x$XWIN" = xyes && test "x$WINDOWSWM" = xyes])
 AM_CONDITIONAL(XWIN_CLIPBOARD, [test "x$XWIN" = xyes])
 AM_CONDITIONAL(XWIN_GLX_WINDOWS, [test "x$XWIN" = xyes && test "x$AIGLX" = xyes])
-AM_CONDITIONAL(XWIN_PRIMARYFB, [test "x$XWIN" = xyes])
 AM_CONDITIONAL(XWIN_RANDR, [test "x$XWIN" = xyes])
 AM_CONDITIONAL(XWIN_XV, [test "x$XWIN" = xyes && test "x$XV" = xyes])
 
diff --git a/hw/xwin/InitOutput.c b/hw/xwin/InitOutput.c
index 96e1006..e867119 100644
--- a/hw/xwin/InitOutput.c
+++ b/hw/xwin/InitOutput.c
@@ -735,9 +735,6 @@ winUseMsg(void)
            "\t\t1 - Shadow GDI\n"
            "\t\t2 - Shadow DirectDraw\n"
            "\t\t4 - Shadow DirectDraw4 Non-Locking\n"
-#ifdef XWIN_PRIMARYFB
-           "\t\t8 - Primary DirectDraw - obsolete\n"
-#endif
         );
 
     ErrorF("-fullscreen\n" "\tRun the server in fullscreen mode.\n");
diff --git a/hw/xwin/Makefile.am b/hw/xwin/Makefile.am
index dea55b4..0ea8ba7 100644
--- a/hw/xwin/Makefile.am
+++ b/hw/xwin/Makefile.am
@@ -37,12 +37,6 @@ DEFS_MULTIWINDOWEXTWM = -DXWIN_MULTIWINDOWEXTWM
 MULTIWINDOWEXTWM_LIBS = $(top_builddir)/miext/rootless/librootless.la
 endif
 
-if XWIN_PRIMARYFB
-SRCS_PRIMARYFB = \
-	winpfbdd.c
-DEFS_PRIMARYFB = -DXWIN_PRIMARYFB
-endif
-
 if XWIN_RANDR
 SRCS_RANDR = \
 	winrandr.c
diff --git a/hw/xwin/man/XWin.man b/hw/xwin/man/XWin.man
index f3eca1e..a043ac2 100644
--- a/hw/xwin/man/XWin.man
+++ b/hw/xwin/man/XWin.man
@@ -261,8 +261,6 @@ Shadow GDI
 Shadow DirectDraw
 .IP 4 4
 Shadow DirectDraw Non-Locking
-.IP 8 4
-Primary DirectDraw (unsupported, obsolete)
 .RE
 
 .SH FULLSCREEN OPTIONS
diff --git a/hw/xwin/win.h b/hw/xwin/win.h
index 6b3e42a..ed1ad01 100644
--- a/hw/xwin/win.h
+++ b/hw/xwin/win.h
@@ -103,9 +103,6 @@
 #define WIN_SERVER_SHADOW_GDI	0x1L    /* 1 */
 #define WIN_SERVER_SHADOW_DD	0x2L    /* 2 */
 #define WIN_SERVER_SHADOW_DDNL	0x4L    /* 4 */
-#ifdef XWIN_PRIMARYFB
-#define WIN_SERVER_PRIMARY_DD	0x8L    /* 8 */
-#endif
 
 #define AltMapIndex		Mod1MapIndex
 #define NumLockMapIndex		Mod2MapIndex
@@ -913,15 +910,6 @@ winMouseButtonsHandle(ScreenPtr pScreen,
 void
  winEnqueueMotion(int x, int y);
 
-#ifdef XWIN_PRIMARYFB
-/*
- * winpfbddd.c
- */
-
-Bool
- winSetEngineFunctionsPrimaryDD(ScreenPtr pScreen);
-#endif
-
 /*
  * winscrinit.c
  */
diff --git a/hw/xwin/winengine.c b/hw/xwin/winengine.c
index 8aa9051..b473b3a 100644
--- a/hw/xwin/winengine.c
+++ b/hw/xwin/winengine.c
@@ -90,15 +90,6 @@ winDetectSupportedEngines(void)
             winErrorFVerb(2,
                           "winDetectSupportedEngines - DirectDraw installed, allowing ShadowDD\n");
             g_dwEnginesSupported |= WIN_SERVER_SHADOW_DD;
-
-#ifdef XWIN_PRIMARYFB
-            /* Allow PrimaryDD engine if NT */
-            if (osvi.dwPlatformId == VER_PLATFORM_WIN32_NT) {
-                g_dwEnginesSupported |= WIN_SERVER_PRIMARY_DD;
-                winErrorFVerb(2,
-                              "winDetectSupportedEngines - Windows NT, allowing PrimaryDD\n");
-            }
-#endif
         }
 
         /* Try to query for DirectDraw4 interface */
@@ -202,11 +193,6 @@ winSetEngine(ScreenPtr pScreen)
         case WIN_SERVER_SHADOW_DDNL:
             winSetEngineFunctionsShadowDDNL(pScreen);
             break;
-#ifdef XWIN_PRIMARYFB
-        case WIN_SERVER_PRIMARY_DD:
-            winSetEngineFunctionsPrimaryDD(pScreen);
-            break;
-#endif
         default:
             FatalError("winSetEngine - Invalid engine type\n");
         }
diff --git a/hw/xwin/winpfbdd.c b/hw/xwin/winpfbdd.c
deleted file mode 100644
index 0106161..0000000
--- a/hw/xwin/winpfbdd.c
+++ /dev/null
@@ -1,620 +0,0 @@
-/*
- *Copyright (C) 1994-2000 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, FITNESS 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.
- *
- * Authors:	Dakshinamurthy Karra
- *		Suhaib M Siddiqi
- *		Peter Busch
- *		Harold L Hunt II
- */
-
-#ifdef HAVE_XWIN_CONFIG_H
-#include <xwin-config.h>
-#endif
-#include "win.h"
-
-/*
- * Local function prototypes
- */
-
-static Bool
- winAllocateFBPrimaryDD(ScreenPtr pScreen);
-
-static Bool
- winCloseScreenPrimaryDD(ScreenPtr pScreen);
-
-static Bool
- winInitVisualsPrimaryDD(ScreenPtr pScreen);
-
-static Bool
- winAdjustVideoModePrimaryDD(ScreenPtr pScreen);
-
-static Bool
- winActivateAppPrimaryDD(ScreenPtr pScreen);
-
-static Bool
- winHotKeyAltTabPrimaryDD(ScreenPtr pScreen);
-
-/*
- * Create a DirectDraw primary surface 
- */
-
-static Bool
-winAllocateFBPrimaryDD(ScreenPtr pScreen)
-{
-    winScreenPriv(pScreen);
-    winScreenInfo *pScreenInfo = pScreenPriv->pScreenInfo;
-    HRESULT ddrval = DD_OK;
-    DDSURFACEDESC ddsd;
-    DDSURFACEDESC *pddsdPrimary = NULL;
-    DDSURFACEDESC *pddsdOffscreen = NULL;
-    RECT rcClient;
-
-    ErrorF("winAllocateFBPrimaryDD\n");
-
-    /* Get client area location in screen coords */
-    GetClientRect(pScreenPriv->hwndScreen, &rcClient);
-    MapWindowPoints(pScreenPriv->hwndScreen,
-                    HWND_DESKTOP, (LPPOINT) &rcClient, 2);
-
-    /* Create a DirectDraw object, store the address at lpdd */
-    ddrval = (*g_fpDirectDrawCreate) (NULL, &pScreenPriv->pdd, NULL);
-    if (ddrval != DD_OK)
-        FatalError("winAllocateFBPrimaryDD - Could not start DirectDraw\n");
-
-    /* Get a DirectDraw2 interface pointer */
-    ddrval = IDirectDraw_QueryInterface(pScreenPriv->pdd,
-                                        &IID_IDirectDraw2,
-                                        (LPVOID *) &pScreenPriv->pdd2);
-    if (FAILED(ddrval)) {
-        ErrorF("winAllocateFBShadowDD - Failed DD2 query: %08x\n",
-               (unsigned int) ddrval);
-        return FALSE;
-    }
-
-    ErrorF("winAllocateFBPrimaryDD - Created and initialized DD\n");
-
-    /* Are we windowed or fullscreen? */
-    if (pScreenInfo->fFullScreen) {
-        /* Full screen mode */
-        ddrval = IDirectDraw2_SetCooperativeLevel(pScreenPriv->pdd2,
-                                                  pScreenPriv->hwndScreen,
-                                                  DDSCL_FULLSCREEN
-                                                  | DDSCL_EXCLUSIVE);
-        if (FAILED(ddrval))
-            FatalError("winAllocateFBPrimaryDD - Could not set "
-                       "cooperative level\n");
-
-        /* Change the video mode to the mode requested */
-        ddrval = IDirectDraw2_SetDisplayMode(pScreenPriv->pdd2,
-                                             pScreenInfo->dwWidth,
-                                             pScreenInfo->dwHeight,
-                                             pScreenInfo->dwBPP,
-                                             pScreenInfo->dwRefreshRate, 0);
-        if (FAILED(ddrval))
-            FatalError("winAllocateFBPrimaryDD - Could not set "
-                       "full screen display mode\n");
-    }
-    else {
-        /* Windowed mode */
-        ddrval = IDirectDraw2_SetCooperativeLevel(pScreenPriv->pdd2,
-                                                  pScreenPriv->hwndScreen,
-                                                  DDSCL_NORMAL);
-        if (FAILED(ddrval))
-            FatalError("winAllocateFBPrimaryDD - Could not set "
-                       "cooperative level\n");
-    }
-
-    /* Describe the primary surface */
-    ZeroMemory(&ddsd, sizeof(ddsd));
-    ddsd.dwSize = sizeof(ddsd);
-    ddsd.dwFlags = DDSD_CAPS;
-    ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
-
-    /* Create the primary surface */
-    ddrval = IDirectDraw2_CreateSurface(pScreenPriv->pdd2,
-                                        &ddsd, &pScreenPriv->pddsPrimary, NULL);
-    if (FAILED(ddrval))
-        FatalError("winAllocateFBPrimaryDD - Could not create primary "
-                   "surface %08x\n", (unsigned int) ddrval);
-
-    ErrorF("winAllocateFBPrimaryDD - Created primary\n");
-
-    /* Allocate a DD surface description for our screen privates */
-    pddsdPrimary = pScreenPriv->pddsdPrimary = malloc(sizeof(DDSURFACEDESC));
-    if (pddsdPrimary == NULL)
-        FatalError("winAllocateFBPrimaryDD - Could not allocate surface "
-                   "description memory\n");
-    ZeroMemory(pddsdPrimary, sizeof(*pddsdPrimary));
-    pddsdPrimary->dwSize = sizeof(*pddsdPrimary);
-
-    /* Describe the offscreen surface to be created */
-    /*
-     * NOTE: Do not use a DDSCAPS_VIDEOMEMORY surface,
-     * as drawing, locking, and unlocking take forever
-     * with video memory surfaces.  In addition,
-     * video memory is a somewhat scarce resource,
-     * so you shouldn't be allocating video memory when
-     * you have the option of using system memory instead.
-     */
-    ZeroMemory(&ddsd, sizeof(ddsd));
-    ddsd.dwSize = sizeof(ddsd);
-    ddsd.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH;
-    ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | DDSCAPS_SYSTEMMEMORY;
-    ddsd.dwHeight = pScreenInfo->dwHeight;
-    ddsd.dwWidth = pScreenInfo->dwWidth;
-
-    /* Create the shadow surface */
-    ddrval = IDirectDraw2_CreateSurface(pScreenPriv->pdd2,
-                                        &ddsd,
-                                        &pScreenPriv->pddsOffscreen, NULL);
-    if (ddrval != DD_OK)
-        FatalError("winAllocateFBPrimaryDD - Could not create shadow "
-                   "surface\n");
-
-    ErrorF("winAllocateFBPrimaryDD - Created offscreen\n");
-
-    /* Allocate a DD surface description for our screen privates */
-    pddsdOffscreen = pScreenPriv->pddsdOffscreen
-        = malloc(sizeof(DDSURFACEDESC));
-    if (pddsdOffscreen == NULL)
-        FatalError("winAllocateFBPrimaryDD - Could not allocate surface "
-                   "description memory\n");
-    ZeroMemory(pddsdOffscreen, sizeof(*pddsdOffscreen));
-    pddsdOffscreen->dwSize = sizeof(*pddsdOffscreen);
-
-    ErrorF("winAllocateFBPrimaryDD - Locking primary\n");
-
-    /* Lock the primary surface */
-    ddrval = IDirectDrawSurface2_Lock(pScreenPriv->pddsPrimary,
-                                      pScreenInfo->
-                                      fFullScreen ? NULL : &rcClient,
-                                      pddsdPrimary, DDLOCK_WAIT, NULL);
-    if (ddrval != DD_OK || pddsdPrimary->lpSurface == NULL)
-        FatalError("winAllocateFBPrimaryDD - Could not lock "
-                   "primary surface\n");
-
-    ErrorF("winAllocateFBPrimaryDD - Locked primary\n");
-
-    /* We don't know how to deal with anything other than RGB */
-    if (!(pddsdPrimary->ddpfPixelFormat.dwFlags & DDPF_RGB))
-        FatalError("winAllocateFBPrimaryDD - Color format other than RGB\n");
-
-    /* Grab the pitch from the surface desc */
-    pScreenInfo->dwStride = (pddsdPrimary->u1.lPitch * 8)
-        / pScreenInfo->dwBPP;
-
-    /* Save the pointer to our surface memory */
-    pScreenInfo->pfb = pddsdPrimary->lpSurface;
-
-    /* Grab the color depth and masks from the surface description */
-    pScreenPriv->dwRedMask = pddsdPrimary->ddpfPixelFormat.u2.dwRBitMask;
-    pScreenPriv->dwGreenMask = pddsdPrimary->ddpfPixelFormat.u3.dwGBitMask;
-    pScreenPriv->dwBlueMask = pddsdPrimary->ddpfPixelFormat.u4.dwBBitMask;
-
-    ErrorF("winAllocateFBPrimaryDD - Returning\n");
-
-    return TRUE;
-}
-
-static void
-winFreeFBPrimaryDD(ScreenPtr pScreen)
-{
-    winScreenPriv(pScreen);
-    winScreenInfo *pScreenInfo = pScreenPriv->pScreenInfo;
-
-    /* Free the offscreen surface, if there is one */
-    if (pScreenPriv->pddsOffscreen) {
-        IDirectDrawSurface2_Unlock(pScreenPriv->pddsOffscreen, NULL);
-        IDirectDrawSurface2_Release(pScreenPriv->pddsOffscreen);
-        pScreenPriv->pddsOffscreen = NULL;
-    }
-
-    /* Release the primary surface, if there is one */
-    if (pScreenPriv->pddsPrimary) {
-        IDirectDrawSurface2_Unlock(pScreenPriv->pddsPrimary, NULL);
-        IDirectDrawSurface2_Release(pScreenPriv->pddsPrimary);
-        pScreenPriv->pddsPrimary = NULL;
-    }
-
-    /* Free the DirectDraw object, if there is one */
-    if (pScreenPriv->pdd) {
-        IDirectDraw2_RestoreDisplayMode(pScreenPriv->pdd);
-        IDirectDraw2_Release(pScreenPriv->pdd);
-        pScreenPriv->pdd = NULL;
-    }
-
-    /* Invalidate the ScreenInfo's fb pointer */
-    pScreenInfo->pfb = NULL;
-}
-
-static Bool
-winInitScreenPrimaryDD(ScreenPtr pScreen)
-{
-    return winAllocateFBPrimaryDD(pScreen);
-}
-
-/*
- * Call the wrapped CloseScreen function.
- * 
- * Free our resources and private structures.
- */
-
-static Bool
-winCloseScreenPrimaryDD(ScreenPtr pScreen)
-{
-    winScreenPriv(pScreen);
-    winScreenInfo *pScreenInfo = pScreenPriv->pScreenInfo;
-    Bool fReturn;
-
-    ErrorF("winCloseScreenPrimaryDD - Freeing screen resources\n");
-
-    /* Flag that the screen is closed */
-    pScreenPriv->fClosed = TRUE;
-    pScreenPriv->fActive = FALSE;
-
-    /* Call the wrapped CloseScreen procedure */
-    WIN_UNWRAP(CloseScreen);
-    if (pScreen->CloseScreen)
-        fReturn = (*pScreen->CloseScreen) (pScreen);
-
-    /* Delete the window property */
-    RemoveProp(pScreenPriv->hwndScreen, WIN_SCR_PROP);
-
-    winFreeFBPrimaryDD(pScreen);
-
-    /* Delete tray icon, if we have one */
-    if (!pScreenInfo->fNoTrayIcon)
-        winDeleteNotifyIcon(pScreenPriv);
-
-    /* Free the exit confirmation dialog box, if it exists */
-    if (g_hDlgExit != NULL) {
-        DestroyWindow(g_hDlgExit);
-        g_hDlgExit = NULL;
-    }
-
-    /* Kill our window */
-    if (pScreenPriv->hwndScreen) {
-        DestroyWindow(pScreenPriv->hwndScreen);
-        pScreenPriv->hwndScreen = NULL;
-    }
-
-    /* Kill our screeninfo's pointer to the screen */
-    pScreenInfo->pScreen = NULL;
-
-    /* Free the screen privates for this screen */
-    free((void *) pScreenPriv);
-
-    return fReturn;
-}
-
-/*
- * Tell mi what sort of visuals we need.
- * 
- * Generally we only need one visual, as our screen can only
- * handle one format at a time, I believe.  You may want
- * to verify that last sentence.
- */
-
-static Bool
-winInitVisualsPrimaryDD(ScreenPtr pScreen)
-{
-    winScreenPriv(pScreen);
-    winScreenInfo *pScreenInfo = pScreenPriv->pScreenInfo;
-    DWORD dwRedBits, dwGreenBits, dwBlueBits;
-
-    /* Count the number of ones in each color mask */
-    dwRedBits = winCountBits(pScreenPriv->dwRedMask);
-    dwGreenBits = winCountBits(pScreenPriv->dwGreenMask);
-    dwBlueBits = winCountBits(pScreenPriv->dwBlueMask);
-
-    /* Store the maximum number of ones in a color mask as the bitsPerRGB */
-    if (dwRedBits > dwGreenBits && dwRedBits > dwBlueBits)
-        pScreenPriv->dwBitsPerRGB = dwRedBits;
-    else if (dwGreenBits > dwRedBits && dwGreenBits > dwBlueBits)
-        pScreenPriv->dwBitsPerRGB = dwGreenBits;
-    else
-        pScreenPriv->dwBitsPerRGB = dwBlueBits;
-
-    ErrorF("winInitVisualsPrimaryDD - Masks: %08x %08x %08x bpRGB: %d\n",
-           (unsigned int) pScreenPriv->dwRedMask,
-           (unsigned int) pScreenPriv->dwGreenMask,
-           (unsigned int) pScreenPriv->dwBlueMask,
-           (int) pScreenPriv->dwBitsPerRGB);
-
-    /* Create a single visual according to the Windows screen depth */
-    switch (pScreenInfo->dwDepth) {
-    case 24:
-    case 16:
-    case 15:
-        if (!miSetVisualTypesAndMasks(pScreenInfo->dwDepth,
-                                      TrueColorMask,
-                                      pScreenPriv->dwBitsPerRGB,
-                                      TrueColor,
-                                      pScreenPriv->dwRedMask,
-                                      pScreenPriv->dwGreenMask,
-                                      pScreenPriv->dwBlueMask)) {
-            ErrorF("winInitVisualsPrimaryDD - "
-                   "miSetVisualTypesAndMasks failed\n");
-            return FALSE;
-        }
-        break;
-
-    case 8:
-#if CYGDEBUG
-        winDebug("winInitVisuals - Calling miSetVisualTypesAndMasks\n");
-#endif                          /* CYGDEBUG */
-        if (!miSetVisualTypesAndMasks(pScreenInfo->dwDepth,
-                                      PseudoColorMask,
-                                      pScreenPriv->dwBitsPerRGB,
-                                      PseudoColor,
-                                      pScreenPriv->dwRedMask,
-                                      pScreenPriv->dwGreenMask,
-                                      pScreenPriv->dwBlueMask)) {
-            ErrorF("winInitVisualsPrimaryDD - "
-                   "miSetVisualTypesAndMasks failed\n");
-            return FALSE;
-        }
-#if CYGDEBUG
-        winDebug("winInitVisualsPrimaryDD - Returned from "
-                 "miSetVisualTypesAndMasks\n");
-#endif                          /* CYGDEBUG */
-        break;
-
-    default:
-        ErrorF("winInitVisualsPrimaryDD - Unknown screen depth\n");
-        return FALSE;
-    }
-
-    ErrorF("winInitVisualsPrimaryDD - Returning\n");
-
-    return TRUE;
-}
-
-static Bool
-winAdjustVideoModePrimaryDD(ScreenPtr pScreen)
-{
-    winScreenPriv(pScreen);
-    winScreenInfo *pScreenInfo = pScreenPriv->pScreenInfo;
-    HDC hdc = NULL;
-    DWORD dwBPP;
-
-    /* We're in serious trouble if we can't get a DC */
-    hdc = GetDC(NULL);
-    if (hdc == NULL) {
-        ErrorF("winAdjustVideoModePrimaryDD - GetDC failed\n");
-        return FALSE;
-    }
-
-    /* Query GDI for current display depth */
-    dwBPP = GetDeviceCaps(hdc, BITSPIXEL);
-
-    /* DirectDraw can only change the depth in fullscreen mode */
-    if (!(pScreenInfo->fFullScreen && (pScreenInfo->dwBPP != WIN_DEFAULT_BPP))) {
-        /* Otherwise, We'll use GDI's depth */
-        pScreenInfo->dwBPP = dwBPP;
-    }
-
-    /* Release our DC */
-    ReleaseDC(NULL, hdc);
-
-    return TRUE;
-}
-
-/*
- * We need to blit our offscreen fb to
- * the screen when we are activated, and we need to point
- * the fb code back to the primary surface memory.
- */
-
-static Bool
-winActivateAppPrimaryDD(ScreenPtr pScreen)
-{
-    winScreenPriv(pScreen);
-    RECT rcSrc, rcClient;
-    HRESULT ddrval = DD_OK;
-
-    /* Check for errors */
-    if (pScreenPriv == NULL
-        || pScreenPriv->pScreenInfo == NULL
-        || pScreenPriv->pddsPrimary == NULL
-        || pScreenPriv->pddsOffscreen == NULL)
-        return FALSE;
-
-    /* Check for do-nothing */
-    if (!pScreenPriv->fActive)
-        return TRUE;
-
-    /* We are activating */
-    ddrval = IDirectDrawSurface2_IsLost(pScreenPriv->pddsOffscreen);
-    if (ddrval == DD_OK) {
-        IDirectDrawSurface2_Unlock(pScreenPriv->pddsOffscreen, NULL);
-        /*
-         * We don't check for an error from Unlock, because it
-         * doesn't matter if the Unlock failed.
-         */
-    }
-
-    /* Restore both surfaces, just cause I like it that way */
-    IDirectDrawSurface2_Restore(pScreenPriv->pddsOffscreen);
-    IDirectDrawSurface2_Restore(pScreenPriv->pddsPrimary);
-
-    /* Get client area in screen coords */
-    GetClientRect(pScreenPriv->hwndScreen, &rcClient);
-    MapWindowPoints(pScreenPriv->hwndScreen,
-                    HWND_DESKTOP, (LPPOINT) &rcClient, 2);
-
-    /* Setup a source rectangle */
-    rcSrc.left = 0;
-    rcSrc.top = 0;
-    rcSrc.right = pScreenPriv->pScreenInfo->dwWidth;
-    rcSrc.bottom = pScreenPriv->pScreenInfo->dwHeight;
-
-    ddrval = IDirectDrawSurface2_Blt(pScreenPriv->pddsPrimary,
-                                     &rcClient,
-                                     pScreenPriv->pddsOffscreen,
-                                     &rcSrc, DDBLT_WAIT, NULL);
-    if (ddrval != DD_OK)
-        FatalError("winActivateAppPrimaryDD () - Failed blitting offscreen "
-                   "surface to primary surface %08x\n", (unsigned int) ddrval);
-
-    /* Lock the primary surface */
-    ddrval = IDirectDrawSurface2_Lock(pScreenPriv->pddsPrimary,
-                                      &rcClient,
-                                      pScreenPriv->pddsdPrimary,
-                                      DDLOCK_WAIT, NULL);
-    if (ddrval != DD_OK || pScreenPriv->pddsdPrimary->lpSurface == NULL)
-        FatalError("winActivateAppPrimaryDD () - Could not lock "
-                   "primary surface\n");
-
-    /* Notify FB of the new memory pointer */
-    winUpdateFBPointer(pScreen, pScreenPriv->pddsdPrimary->lpSurface);
-
-    /*
-     * Register the Alt-Tab combo as a hotkey so we can copy
-     * the primary framebuffer before the display mode changes
-     */
-    RegisterHotKey(pScreenPriv->hwndScreen, 1, MOD_ALT, 9);
-
-    return TRUE;
-}
-
-/*
- * Handle the Alt+Tab hotkey.
- *
- * We need to save the primary fb to an offscreen fb when
- * we get deactivated, and point the fb code at the offscreen
- * fb for the duration of the deactivation.
- */
-
-static Bool
-winHotKeyAltTabPrimaryDD(ScreenPtr pScreen)
-{
-    winScreenPriv(pScreen);
-    HRESULT ddrval = DD_OK;
-
-    ErrorF("\nwinHotKeyAltTabPrimaryDD\n\n");
-
-    /* Alt+Tab was pressed, we will lose focus very soon */
-    pScreenPriv->fActive = FALSE;
-
-    /* Check for error conditions */
-    if (pScreenPriv->pddsPrimary == NULL || pScreenPriv->pddsOffscreen == NULL)
-        return FALSE;
-
-    /* Did we loose the primary surface? */
-    ddrval = IDirectDrawSurface2_IsLost(pScreenPriv->pddsPrimary);
-    if (ddrval == DD_OK) {
-        ddrval = IDirectDrawSurface2_Unlock(pScreenPriv->pddsPrimary, NULL);
-        if (FAILED(ddrval))
-            FatalError("winHotKeyAltTabPrimaryDD - Failed unlocking primary "
-                       "surface\n");
-    }
-
-    /* Blit the primary surface to the offscreen surface */
-    ddrval = IDirectDrawSurface2_Blt(pScreenPriv->pddsOffscreen, NULL,  /* should be rcDest */
-                                     pScreenPriv->pddsPrimary,
-                                     NULL, DDBLT_WAIT, NULL);
-    if (ddrval == DDERR_SURFACELOST) {
-        IDirectDrawSurface2_Restore(pScreenPriv->pddsOffscreen);
-        IDirectDrawSurface2_Restore(pScreenPriv->pddsPrimary);
-
-        /* Blit the primary surface to the offscreen surface */
-        ddrval = IDirectDrawSurface2_Blt(pScreenPriv->pddsOffscreen,
-                                         NULL,
-                                         pScreenPriv->pddsPrimary,
-                                         NULL, DDBLT_WAIT, NULL);
-        if (FAILED(ddrval))
-            FatalError("winHotKeyAltTabPrimaryDD - Failed blitting primary "
-                       "surface to offscreen surface: %08x\n",
-                       (unsigned int) ddrval);
-    }
-    else {
-        FatalError("winHotKeyAltTabPrimaryDD - Unknown error from "
-                   "Blt: %08dx\n", (unsigned int) ddrval);
-    }
-
-    /* Lock the offscreen surface */
-    ddrval = IDirectDrawSurface2_Lock(pScreenPriv->pddsOffscreen,
-                                      NULL,
-                                      pScreenPriv->pddsdOffscreen,
-                                      DDLOCK_WAIT, NULL);
-    if (ddrval != DD_OK || pScreenPriv->pddsdPrimary->lpSurface == NULL)
-        FatalError("winHotKeyAltTabPrimaryDD - Could not lock "
-                   "offscreen surface\n");
-
-    /* Notify FB of the new memory pointer */
-    winUpdateFBPointer(pScreen, pScreenPriv->pddsdOffscreen->lpSurface);
-
-    /* Unregister our hotkey */
-    UnregisterHotKey(pScreenPriv->hwndScreen, 1);
-
-    return TRUE;
-}
-
-/* Set engine specific functions */
-Bool
-winSetEngineFunctionsPrimaryDD(ScreenPtr pScreen)
-{
-    winScreenPriv(pScreen);
-    winScreenInfo *pScreenInfo = pScreenPriv->pScreenInfo;
-
-    /* Set our pointers */
-    pScreenPriv->pwinAllocateFB = winAllocateFBPrimaryDD;
-    pScreenPriv->pwinFreeFB = winFreeFBPrimaryDD;
-    pScreenPriv->pwinShadowUpdate =
-        (winShadowUpdateProcPtr) (void (*)(void)) NoopDDA;
-    pScreenPriv->pwinInitScreen = winInitScreenPrimaryDD;
-    pScreenPriv->pwinCloseScreen = winCloseScreenPrimaryDD;
-    pScreenPriv->pwinInitVisuals = winInitVisualsPrimaryDD;
-    pScreenPriv->pwinAdjustVideoMode = winAdjustVideoModePrimaryDD;
-    if (pScreenInfo->fFullScreen)
-        pScreenPriv->pwinCreateBoundingWindow =
-            winCreateBoundingWindowFullScreen;
-    else
-        pScreenPriv->pwinCreateBoundingWindow = winCreateBoundingWindowWindowed;
-    pScreenPriv->pwinFinishScreenInit = winFinishScreenInitFB;
-    pScreenPriv->pwinBltExposedRegions =
-        (winBltExposedRegionsProcPtr) (void (*)(void)) NoopDDA;
-    pScreenPriv->pwinActivateApp = winActivateAppPrimaryDD;
-    pScreenPriv->pwinRedrawScreen = NULL;
-    pScreenPriv->pwinRealizeInstalledPalette = NULL;
-    pScreenPriv->pwinInstallColormap = NULL;
-    pScreenPriv->pwinStoreColors = NULL;
-    pScreenPriv->pwinCreateColormap = NULL;
-    pScreenPriv->pwinDestroyColormap = NULL;
-    pScreenPriv->pwinHotKeyAltTab = winHotKeyAltTabPrimaryDD;
-    pScreenPriv->pwinCreatePrimarySurface =
-        (winCreatePrimarySurfaceProcPtr) (void (*)(void)) NoopDDA;
-    pScreenPriv->pwinReleasePrimarySurface =
-        (winReleasePrimarySurfaceProcPtr) (void (*)(void)) NoopDDA;
-#ifdef XWIN_MULTIWINDOW
-    pScreenPriv->pwinFinishCreateWindowsWindow =
-        (winFinishCreateWindowsWindowProcPtr) (void (*)(void)) NoopDDA;
-#endif
-
-    return TRUE;
-}
diff --git a/hw/xwin/winwndproc.c b/hw/xwin/winwndproc.c
index e3adb56..1b09921 100644
--- a/hw/xwin/winwndproc.c
+++ b/hw/xwin/winwndproc.c
@@ -163,11 +163,7 @@ winWindowProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
          */
         if (s_pScreenInfo->fFullScreen
             && (s_pScreenInfo->dwEngine == WIN_SERVER_SHADOW_DD
-                || s_pScreenInfo->dwEngine == WIN_SERVER_SHADOW_DDNL
-#ifdef XWIN_PRIMARYFB
-                || s_pScreenInfo->dwEngine == WIN_SERVER_PRIMARY_DD
-#endif
-            )) {
+                || s_pScreenInfo->dwEngine == WIN_SERVER_SHADOW_DDNL)) {
             break;
         }
 
@@ -191,11 +187,7 @@ winWindowProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
         if (s_pScreenInfo->dwBPP !=
             GetDeviceCaps(s_pScreenPriv->hdcScreen, BITSPIXEL)) {
             if ((s_pScreenInfo->dwEngine == WIN_SERVER_SHADOW_DD ||
-                 s_pScreenInfo->dwEngine == WIN_SERVER_SHADOW_DDNL
-#ifdef XWIN_PRIMARYFB
-                 || s_pScreenInfo->dwEngine == WIN_SERVER_PRIMARY_DD
-#endif
-                )) {
+                 s_pScreenInfo->dwEngine == WIN_SERVER_SHADOW_DDNL)) {
                 /* Cannot display the visual until the depth is restored */
                 ErrorF("winWindowProc - Disruptive change in depth\n");
 
commit 8465ee788fd541fa37681aa0a44103c7f944d437
Author: Adam Jackson <ajax at redhat.com>
Date:   Thu Sep 25 15:37:33 2014 -0400

    xwin: Remove native GDI engine (v2)
    
    As the man page says, "unsupported, experimental, and barely
    functional".  The last even minor updates to any of this were back in
    2004, presumably it's not getting better any time soon.
    
    This is also the only GC ops implementation in the tree that actually
    falls all the way down to the spans routines for everything, so that's
    pretty nice to be rid of.
    
    v2: Fix stray break statement (Jon)
    
    Reviewed-by: Jon TURNEY <jon.turney at dronecode.org.uk>
    Signed-off-by: Adam Jackson <ajax at redhat.com>

diff --git a/configure.ac b/configure.ac
index 30c0c5c..a12e9e2 100644
--- a/configure.ac
+++ b/configure.ac
@@ -2206,7 +2206,6 @@ AM_CONDITIONAL(XWIN_MULTIWINDOW, [test "x$XWIN" = xyes])
 AM_CONDITIONAL(XWIN_MULTIWINDOWEXTWM, [test "x$XWIN" = xyes && test "x$WINDOWSWM" = xyes])
 AM_CONDITIONAL(XWIN_CLIPBOARD, [test "x$XWIN" = xyes])
 AM_CONDITIONAL(XWIN_GLX_WINDOWS, [test "x$XWIN" = xyes && test "x$AIGLX" = xyes])
-AM_CONDITIONAL(XWIN_NATIVEGDI, [test "x$XWIN" = xyes])
 AM_CONDITIONAL(XWIN_PRIMARYFB, [test "x$XWIN" = xyes])
 AM_CONDITIONAL(XWIN_RANDR, [test "x$XWIN" = xyes])
 AM_CONDITIONAL(XWIN_XV, [test "x$XWIN" = xyes && test "x$XV" = xyes])
diff --git a/hw/xwin/InitOutput.c b/hw/xwin/InitOutput.c
index 88bc85a..96e1006 100644
--- a/hw/xwin/InitOutput.c
+++ b/hw/xwin/InitOutput.c
@@ -738,9 +738,6 @@ winUseMsg(void)
 #ifdef XWIN_PRIMARYFB
            "\t\t8 - Primary DirectDraw - obsolete\n"
 #endif
-#ifdef XWIN_NATIVEGDI
-           "\t\t16 - Native GDI - experimental\n"
-#endif
         );
 
     ErrorF("-fullscreen\n" "\tRun the server in fullscreen mode.\n");
diff --git a/hw/xwin/Makefile.am b/hw/xwin/Makefile.am
index 2c7fde3..dea55b4 100644
--- a/hw/xwin/Makefile.am
+++ b/hw/xwin/Makefile.am
@@ -37,21 +37,6 @@ DEFS_MULTIWINDOWEXTWM = -DXWIN_MULTIWINDOWEXTWM
 MULTIWINDOWEXTWM_LIBS = $(top_builddir)/miext/rootless/librootless.la
 endif
 
-if XWIN_NATIVEGDI
-SRCS_NATIVEGDI = \
-	winclip.c \
-	winfillsp.c \
-	winfont.c \
-	wingc.c \
-	wingetsp.c \
-	winnativegdi.c \
-	winpixmap.c \
-	winpolyline.c \
-	winrop.c \
-	winsetsp.c
-DEFS_NATIVEGDI = -DXWIN_NATIVEGDI
-endif
-
 if XWIN_PRIMARYFB
 SRCS_PRIMARYFB = \
 	winpfbdd.c
diff --git a/hw/xwin/man/XWin.man b/hw/xwin/man/XWin.man
index c71f6a1..f3eca1e 100644
--- a/hw/xwin/man/XWin.man
+++ b/hw/xwin/man/XWin.man
@@ -263,8 +263,6 @@ Shadow DirectDraw
 Shadow DirectDraw Non-Locking
 .IP 8 4
 Primary DirectDraw (unsupported, obsolete)
-.IP 16 4
-Native GDI (unsupported, experimental and barely functional)
 .RE
 
 .SH FULLSCREEN OPTIONS
diff --git a/hw/xwin/win.h b/hw/xwin/win.h
index 7af35e7..6b3e42a 100644
--- a/hw/xwin/win.h
+++ b/hw/xwin/win.h
@@ -106,9 +106,6 @@
 #ifdef XWIN_PRIMARYFB
 #define WIN_SERVER_PRIMARY_DD	0x8L    /* 8 */
 #endif
-#ifdef XWIN_NATIVEGDI
-#define WIN_SERVER_NATIVE_GDI	0x10L   /* 16 */
-#endif
 
 #define AltMapIndex		Mod1MapIndex
 #define NumLockMapIndex		Mod2MapIndex
@@ -304,12 +301,6 @@ typedef Bool (*winFinishCreateWindowsWindowProcPtr) (WindowPtr pWin);
 
 typedef Bool (*winCreateScreenResourcesProc) (ScreenPtr);
 
-#ifdef XWIN_NATIVEGDI
-/* Typedefs for native GDI wrappers */
-typedef Bool (*RealizeFontPtr) (ScreenPtr pScreen, FontPtr pFont);
-typedef Bool (*UnrealizeFontPtr) (ScreenPtr pScreen, FontPtr pFont);
-#endif
-
 /*
  * GC (graphics context) privates
  */
@@ -582,12 +573,6 @@ typedef struct _winPrivScreenRec {
     SetShapeProcPtr SetShape;
 
     winCursorRec cursor;
-
-#ifdef XWIN_NATIVEGDI
-    RealizeFontPtr RealizeFont;
-    UnrealizeFontPtr UnrealizeFont;
-#endif
-
 } winPrivScreenRec;
 
 #ifdef XWIN_MULTIWINDOWEXTWM
@@ -775,15 +760,6 @@ void
 winBlockHandler(ScreenPtr pScreen,
                 void *pTimeout, void *pReadMask);
 
-#ifdef XWIN_NATIVEGDI
-/*
- * winclip.c
- */
-
-RegionPtr
- winPixmapToRegionNativeGDI(PixmapPtr pPix);
-#endif
-
 #ifdef XWIN_CLIPBOARD
 /*
  * winclipboardinit.c
@@ -859,52 +835,6 @@ void
 winMessageBoxF(const char *pszError, UINT uType, ...)
 _X_ATTRIBUTE_PRINTF(1, 3);
 
-#ifdef XWIN_NATIVEGDI
-/*
- * winfillsp.c
- */
-
-void
-
-winFillSpansNativeGDI(DrawablePtr pDrawable,
-                      GCPtr pGC,
-                      int nSpans,
-                      DDXPointPtr pPoints, int *pWidths, int fSorted);
-#endif
-
-#ifdef XWIN_NATIVEGDI
-/*
- * winfont.c
- */
-
-Bool
- winRealizeFontNativeGDI(ScreenPtr pScreen, FontPtr pFont);
-
-Bool
- winUnrealizeFontNativeGDI(ScreenPtr pScreen, FontPtr pFont);
-#endif
-
-#ifdef XWIN_NATIVEGDI
-/*
- * wingc.c
- */
-
-Bool
- winCreateGCNativeGDI(GCPtr pGC);
-#endif
-
-#ifdef XWIN_NATIVEGDI
-/*
- * wingetsp.c
- */
-
-void
-
-winGetSpansNativeGDI(DrawablePtr pDrawable,
-                     int wMax,
-                     DDXPointPtr pPoints, int *pWidths, int nSpans, char *pDst);
-#endif
-
 /*
  * winglobals.c
  */
@@ -956,23 +886,12 @@ void
  * winmisc.c
  */
 
-#ifdef XWIN_NATIVEGDI
-void
-
-winQueryBestSizeNativeGDI(int class, unsigned short *pWidth,
-                          unsigned short *pHeight, ScreenPtr pScreen);
-#endif
-
 CARD8
  winCountBits(DWORD dw);
 
 Bool
  winUpdateFBPointer(ScreenPtr pScreen, void *pbits);
 
-#ifdef XWIN_NATIVEGDI
-BOOL winPaintBackground(HWND hwnd, COLORREF colorref);
-#endif
-
 /*
  * winmouse.c
  */
@@ -994,19 +913,6 @@ winMouseButtonsHandle(ScreenPtr pScreen,
 void
  winEnqueueMotion(int x, int y);
 
-#ifdef XWIN_NATIVEGDI
-/*
- * winnativegdi.c
- */
-
-HBITMAP
-winCreateDIBNativeGDI(int iWidth, int iHeight, int iDepth,
-                      BYTE ** ppbBits, BITMAPINFO ** ppbmi);
-
-Bool
- winSetEngineFunctionsNativeGDI(ScreenPtr pScreen);
-#endif
-
 #ifdef XWIN_PRIMARYFB
 /*
  * winpfbddd.c
@@ -1016,38 +922,6 @@ Bool
  winSetEngineFunctionsPrimaryDD(ScreenPtr pScreen);
 #endif
 
-#ifdef XWIN_NATIVEGDI
-/*
- * winpixmap.c
- */
-
-PixmapPtr
-
-winCreatePixmapNativeGDI(ScreenPtr pScreen, int width, int height, int depth,
-                         unsigned usage_hint);
-
-Bool
- winDestroyPixmapNativeGDI(PixmapPtr pPixmap);
-
-Bool
-
-winModifyPixmapHeaderNativeGDI(PixmapPtr pPixmap,
-                               int iWidth, int iHeight,
-                               int iDepth,
-                               int iBitsPerPixel,
-                               int devKind, void *pPixData);
-#endif
-
-#ifdef XWIN_NATIVEGDI
-/*
- * winpolyline.c
- */
-
-void
-
-winPolyLineNativeGDI(DrawablePtr pDrawable,
-                     GCPtr pGC, int mode, int npt, DDXPointPtr ppt);
-#endif
 /*
  * winscrinit.c
  */
@@ -1058,26 +932,6 @@ Bool
 Bool
  winFinishScreenInitFB(int i, ScreenPtr pScreen, int argc, char **argv);
 
-#if defined(XWIN_NATIVEGDI)
-Bool
-
-winFinishScreenInitNativeGDI(int i,
-                             ScreenPtr pScreen, int argc, char **argv);
-#endif
-
-#ifdef XWIN_NATIVEGDI
-/*
- * winsetsp.c
- */
-
-void
-
-winSetSpansNativeGDI(DrawablePtr pDrawable,
-                     GCPtr pGC,
-                     char *pSrc,
-                     DDXPointPtr pPoints, int *pWidth, int nSpans, int fSorted);
-#endif
-
 /*
  * winshaddd.c
  */
@@ -1112,30 +966,6 @@ winWakeupHandler(ScreenPtr pScreen,
  * winwindow.c
  */
 
-#ifdef XWIN_NATIVEGDI
-Bool
- winCreateWindowNativeGDI(WindowPtr pWin);
-
-Bool
- winDestroyWindowNativeGDI(WindowPtr pWin);
-
-Bool
- winPositionWindowNativeGDI(WindowPtr pWin, int x, int y);
-
-void
-
-winCopyWindowNativeGDI(WindowPtr pWin, DDXPointRec ptOldOrg, RegionPtr prgnSrc);
-
-Bool
- winChangeWindowAttributesNativeGDI(WindowPtr pWin, unsigned long mask);
-
-Bool
- winUnmapWindowNativeGDI(WindowPtr pWindow);
-
-Bool
- winMapWindowNativeGDI(WindowPtr pWindow);
-#endif
-
 Bool
  winCreateWindowRootless(WindowPtr pWindow);
 
diff --git a/hw/xwin/winclip.c b/hw/xwin/winclip.c
deleted file mode 100644
index 941e948..0000000
--- a/hw/xwin/winclip.c
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- *Copyright (C) 2001-2004 Harold L Hunt II 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, FITNESS FOR A PARTICULAR PURPOSE AND
- *NONINFRINGEMENT. IN NO EVENT SHALL HAROLD L HUNT II 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 Harold L Hunt II
- *shall not be used in advertising or otherwise to promote the sale, use
- *or other dealings in this Software without prior written authorization
- *from Harold L Hunt II.
- *
- * Authors:	Harold L Hunt II
- */
-
-#ifdef HAVE_XWIN_CONFIG_H
-#include <xwin-config.h>
-#endif
-#include "win.h"
-
-/* Look at mfb/mfbclip.c for sample implementation */
-RegionPtr
-winPixmapToRegionNativeGDI(PixmapPtr pPix)
-{
-    ErrorF("winPixmapToRegion()\n");
-    return NULL;
-}
diff --git a/hw/xwin/wincreatewnd.c b/hw/xwin/wincreatewnd.c
index 6732dcb..9f72016 100644
--- a/hw/xwin/wincreatewnd.c
+++ b/hw/xwin/wincreatewnd.c
@@ -110,20 +110,8 @@ winCreateBoundingWindowFullScreen(ScreenPtr pScreen)
                              GetModuleHandle(NULL),     /* Instance handle */
                              pScreenPriv);      /* ScreenPrivates */
 
-    /* Branch on the server engine */
-    switch (pScreenInfo->dwEngine) {
-#ifdef XWIN_NATIVEGDI
-    case WIN_SERVER_SHADOW_GDI:
-        /* Show the window */
-        ShowWindow(*phwnd, SW_SHOWMAXIMIZED);
-        break;
-#endif
-
-    default:
-        /* Hide the window */
-        ShowWindow(*phwnd, SW_SHOWNORMAL);
-        break;
-    }
+    /* Hide the window */
+    ShowWindow(*phwnd, SW_SHOWNORMAL);
 
     /* Send first paint message */
     UpdateWindow(*phwnd);
@@ -474,12 +462,6 @@ winCreateBoundingWindowWindowed(ScreenPtr pScreen)
         }
     }
 
-#ifdef XWIN_NATIVEGDI
-    /* Paint window background blue */
-    if (pScreenInfo->dwEngine == WIN_SERVER_NATIVE_GDI)
-        winPaintBackground(*phwnd, RGB(0x00, 0x00, 0xFF));
-#endif
-
     winDebug("winCreateBoundingWindowWindowed -  Returning\n");
 
     return TRUE;
diff --git a/hw/xwin/winengine.c b/hw/xwin/winengine.c
index 1f55ada..8aa9051 100644
--- a/hw/xwin/winengine.c
+++ b/hw/xwin/winengine.c
@@ -59,10 +59,6 @@ winDetectSupportedEngines(void)
     /* Initialize the engine support flags */
     g_dwEnginesSupported = WIN_SERVER_SHADOW_GDI;
 
-#ifdef XWIN_NATIVEGDI
-    g_dwEnginesSupported |= WIN_SERVER_NATIVE_GDI;
-#endif
-
     /* Get operating system version information */
     ZeroMemory(&osvi, sizeof(osvi));
     osvi.dwOSVersionInfoSize = sizeof(osvi);
@@ -211,11 +207,6 @@ winSetEngine(ScreenPtr pScreen)
             winSetEngineFunctionsPrimaryDD(pScreen);
             break;
 #endif
-#ifdef XWIN_NATIVEGDI
-        case WIN_SERVER_NATIVE_GDI:
-            winSetEngineFunctionsNativeGDI(pScreen);
-            break;
-#endif
         default:
             FatalError("winSetEngine - Invalid engine type\n");
         }
diff --git a/hw/xwin/winfillsp.c b/hw/xwin/winfillsp.c
deleted file mode 100644
index bd0a15e..0000000
--- a/hw/xwin/winfillsp.c
+++ /dev/null
@@ -1,842 +0,0 @@
-/*
- *Copyright (C) 1994-2000 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, FITNESS 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.
- *
- * Authors:	Harold L Hunt II
- * 		Alan Hourihane <alanh at fairlite.demon.co.uk>
- */
-
-#ifdef HAVE_XWIN_CONFIG_H
-#include <xwin-config.h>
-#endif
-#include "win.h"
-
-extern void ROP16(HDC hdc, int rop);
-
-#define TRANSLATE_COLOR(color)						\
-{									\
-  if (pDrawable->depth == 15)						\
-    color = ((color & 0x1F) << 19) | ((color & 0x03E0) << 6) |		\
-      ((color & 0xF800) >> 8);						\
-  else if (pDrawable->depth == 16)					\
-    color = ((color & 0x1F) << 19) | ((color & 0x07E0) << 5) |		\
-      ((color & 0xF800) >> 8);						\
-  else if (pDrawable->depth == 24 || pDrawable->depth == 32)		\
-    color = ((color & 0xFF) << 16) | (color & 0xFF00) |			\
-      ((color & 0xFF0000) >> 16);					\
-}
-
-/* See Porting Layer Definition - p. 54 */
-void
-winFillSpansNativeGDI(DrawablePtr pDrawable,
-                      GCPtr pGC,
-                      int iSpans,
-                      DDXPointPtr pPoints, int *piWidths, int fSorted)
-{
-    winGCPriv(pGC);
-    HBITMAP hbmpOrig = NULL, hbmpOrigStipple = NULL;
-    HBITMAP hPenOrig = NULL;
-    HBITMAP hBitmap = NULL;
-    PixmapPtr pPixmap = NULL;
-    winPrivPixmapPtr pPixmapPriv = NULL;
-    PixmapPtr pStipple = NULL;
-    winPrivPixmapPtr pStipplePriv = NULL;
-    PixmapPtr pTile = NULL;
-    winPrivPixmapPtr pTilePriv = NULL;
-    HDC hdcStipple = NULL, hdcTile = NULL;
-    HPEN hPen = NULL;
-    int iX;
-    int fg, bg;
-    RegionPtr pClip = pGC->pCompositeClip;
-    BoxPtr pextent, pbox;
-    int nbox;
-    int extentX1, extentX2, extentY1, extentY2;
-    int fullX1, fullX2, fullY1;
-    HRGN hrgn = NULL, combined = NULL;
-
-    nbox = RegionNumRects(pClip);
-    pbox = RegionRects(pClip);
-
-    if (!nbox)
-        return;
-
-    combined = CreateRectRgn(pbox->x1, pbox->y1, pbox->x2, pbox->y2);
-    nbox--;
-    pbox++;
-
-    while (nbox--) {
-        hrgn = CreateRectRgn(pbox->x1, pbox->y1, pbox->x2, pbox->y2);
-        CombineRgn(combined, combined, hrgn, RGN_OR);
-        DeleteObject(hrgn);
-        hrgn = NULL;
-        pbox++;
-    }
-
-    pextent = RegionExtents(pClip);
-    extentX1 = pextent->x1;
-    extentY1 = pextent->y1;
-    extentX2 = pextent->x2;
-    extentY2 = pextent->y2;
-
-    /* Branch on the type of drawable we have */
-    switch (pDrawable->type) {
-    case DRAWABLE_PIXMAP:
-
-        SelectClipRgn(pGCPriv->hdcMem, combined);
-        DeleteObject(combined);
-        combined = NULL;
-
-        /* Get a pixmap pointer from the drawable pointer, and fetch privates  */
-        pPixmap = (PixmapPtr) pDrawable;
-        pPixmapPriv = winGetPixmapPriv(pPixmap);
-
-        /* Select the drawable pixmap into memory hdc */
-        hbmpOrig = SelectObject(pGCPriv->hdcMem, pPixmapPriv->hBitmap);
-        if (hbmpOrig == NULL)
-            FatalError("winFillSpans - DRAWABLE_PIXMAP - "
-                       "SelectObject () failed on\n\tpPixmapPriv->hBitmap: "
-                       "%p\n", pPixmapPriv->hBitmap);
-
-        /* Branch on the fill type */
-        switch (pGC->fillStyle) {
-        case FillSolid:
-
-            ROP16(pGCPriv->hdcMem, pGC->alu);
-
-            if (pDrawable->depth == 1) {
-                if (pGC->fgPixel == 0)
-                    hPenOrig = SelectObject(pGCPriv->hdcMem,
-                                            GetStockObject(BLACK_PEN));
-                else
-                    hPenOrig = SelectObject(pGCPriv->hdcMem,
-                                            GetStockObject(WHITE_PEN));
-            }
-            else {
-                fg = pGC->fgPixel;
-                TRANSLATE_COLOR(fg);
-                hPen = CreatePen(PS_SOLID, 0, fg);
-                hPenOrig = SelectObject(pGCPriv->hdcMem, hPen);
-            }
-
-            while (iSpans--) {
-                fullX1 = pPoints->x;
-                fullY1 = pPoints->y;
-                fullX2 = fullX1 + (int) *piWidths;
-                pPoints++;
-                piWidths++;
-
-                if (fullY1 < extentY1 || extentY2 <= fullY1)
-                    continue;
-
-                if (fullX1 < extentX1)
-                    fullX1 = extentX1;
-                if (fullX2 > extentX2)
-                    fullX2 = extentX2;
-
-                if (fullX1 >= fullX2)
-                    continue;
-
-                MoveToEx(pGCPriv->hdcMem, fullX1, fullY1, NULL);
-                LineTo(pGCPriv->hdcMem, fullX2, fullY1);
-            }
-
-            SetROP2(pGCPriv->hdcMem, R2_COPYPEN);
-
-            /* Give back the Pen */
-            SelectObject(pGCPriv->hdcMem, hPenOrig);
-
-            if (pDrawable->depth != 1)
-                DeleteObject(hPen);
-            break;
-
-        case FillOpaqueStippled:
-
-            pStipple = pGC->stipple;
-            pStipplePriv = winGetPixmapPriv(pStipple);
-
-            /* Create a device-dependent bitmap for the stipple */
-            hBitmap = CreateDIBitmap(pGCPriv->hdcMem,
-                                     (BITMAPINFOHEADER *) pStipplePriv->pbmih,
-                                     CBM_INIT,
-                                     pStipplePriv->pbBits,
-                                     (BITMAPINFO *) pStipplePriv->pbmih,
-                                     DIB_RGB_COLORS);
-
-            /* Create a memory DC to hold the stipple */
-            hdcStipple = CreateCompatibleDC(pGCPriv->hdcMem);
-
-            /* Select the stipple bitmap into the stipple DC */
-            hbmpOrigStipple = SelectObject(hdcStipple, hBitmap);
-            if (hbmpOrigStipple == NULL)
-                FatalError("winFillSpans () - DRAWABLE_PIXMAP - FillStippled - "
-                           "SelectObject () failed on hbmpOrigStipple\n");
-
-            /* Make a temporary copy of the foreground and background colors */
-            bg = pGC->bgPixel;
-            fg = pGC->fgPixel;
-
-            /* Translate the depth-dependent colors to Win32 COLORREFs */
-            TRANSLATE_COLOR(fg);
-            TRANSLATE_COLOR(bg);
-            SetTextColor(pGCPriv->hdcMem, fg);
-            SetBkColor(pGCPriv->hdcMem, bg);
-
-            while (iSpans--) {
-                int width = pStipple->drawable.width;
-
-                fullX1 = pPoints->x;
-                fullY1 = pPoints->y;
-                fullX2 = fullX1 + (int) *piWidths;
-                pPoints++;
-                piWidths++;
-
-                if (fullY1 < extentY1 || extentY2 <= fullY1)
-                    continue;
-
-                if (fullX1 < extentX1)
-                    fullX1 = extentX1;
-                if (fullX2 > extentX2)
-                    fullX2 = extentX2;
-
-                if (fullX1 >= fullX2)
-                    continue;
-
-                for (iX = fullX1; iX < fullX2; iX += width) {
-                    int xoffset;
-
-                    if ((iX + pStipple->drawable.width) > fullX2)
-                        width = fullX2 - iX;
-                    else
-                        width = pStipple->drawable.width;
-
-                    if (iX == fullX1)
-                        xoffset =
-                            (fullX1 -
-                             (pDrawable->x +
-                              (pGC->patOrg.x % pStipple->drawable.width) -
-                              pStipple->drawable.width)) %
-                            pStipple->drawable.width;
-                    else
-                        xoffset = 0;
-
-                    if (xoffset + width > pStipple->drawable.width)
-                        width = pStipple->drawable.width - xoffset;
-
-                    BitBlt(pGCPriv->hdcMem,
-                           iX, fullY1,
-                           width, 1,
-                           hdcStipple,
-                           xoffset,
-                           (fullY1 -
-                            (pDrawable->y +
-                             (pGC->patOrg.y % pStipple->drawable.height) -
-                             pStipple->drawable.height)) %
-                           pStipple->drawable.height, g_copyROP[pGC->alu]);
-                }
-            }
-
-            /* Clear the stipple HDC */
-            SelectObject(hdcStipple, hbmpOrigStipple);
-            DeleteDC(hdcStipple);
-
-            /* Delete the device dependent stipple bitmap */
-            DeleteObject(hBitmap);
-
-            break;
-        case FillStippled:
-
-            pStipple = pGC->stipple;
-            pStipplePriv = winGetPixmapPriv(pStipple);
-
-            /* Create a device-dependent bitmap for the stipple */
-            hBitmap = CreateDIBitmap(pGCPriv->hdcMem,
-                                     (BITMAPINFOHEADER *) pStipplePriv->pbmih,
-                                     CBM_INIT,
-                                     pStipplePriv->pbBits,
-                                     (BITMAPINFO *) pStipplePriv->pbmih,
-                                     DIB_RGB_COLORS);
-
-            /* Create a memory DC to hold the stipple */
-            hdcStipple = CreateCompatibleDC(pGCPriv->hdcMem);
-
-            /* Select the stipple bitmap into the stipple DC */
-            hbmpOrigStipple = SelectObject(hdcStipple, hBitmap);
-            if (hbmpOrigStipple == NULL)
-                FatalError("winFillSpans () - DRAWABLE_PIXMAP - FillStippled - "
-                           "SelectObject () failed on hbmpOrigStipple\n");
-
-            /* Make a temporary copy of the foreground and background colors */
-            bg = pGC->bgPixel;
-            fg = pGC->fgPixel;
-
-            /* Translate the depth-dependent colors to Win32 COLORREFs */
-            TRANSLATE_COLOR(fg);
-            TRANSLATE_COLOR(bg);
-
-            /* this is fudgy, we should only invert on the last one
-             * We need to get the black/white pixels right in the
-             * colormap. But yeah ! it's working.. 
-             */
-            if (pGC->bgPixel != -1 && pGC->fgPixel != -1) {
-                SetTextColor(pGCPriv->hdcMem, fg);
-                SetBkColor(pGCPriv->hdcMem, bg);
-                BitBlt(hdcStipple,
-                       0, 0,
-                       pStipple->drawable.width, pStipple->drawable.height,
-                       hdcStipple, 0, 0, 0x330008);
-            }
-            else if (pGC->bgPixel == -1) {
-                SetTextColor(pGCPriv->hdcMem, fg);
-                SetBkMode(pGCPriv->hdcMem, TRANSPARENT);
-                BitBlt(hdcStipple,
-                       0, 0,
-                       pStipple->drawable.width, pStipple->drawable.height,
-                       hdcStipple, 0, 0, 0x330008);
-            }
-            else if (pGC->fgPixel == -1) {
-                SetTextColor(pGCPriv->hdcMem, bg);
-                SetBkMode(pGCPriv->hdcMem, TRANSPARENT);
-#if 0
-                BitBlt(hdcStipple,
-                       0, 0,
-                       pStipple->drawable.width, pStipple->drawable.height,
-                       hdcStipple, 0, 0, 0x330008);
-#endif
-            }
-
-            while (iSpans--) {
-                int width = pStipple->drawable.width;
-
-                fullX1 = pPoints->x;
-                fullY1 = pPoints->y;
-                fullX2 = fullX1 + (int) *piWidths;
-                pPoints++;
-                piWidths++;
-
-                if (fullY1 < extentY1 || extentY2 <= fullY1)
-                    continue;
-
-                if (fullX1 < extentX1)
-                    fullX1 = extentX1;
-                if (fullX2 > extentX2)
-                    fullX2 = extentX2;
-
-                if (fullX1 >= fullX2)
-                    continue;
-
-                for (iX = fullX1; iX < fullX2; iX += width) {
-                    int xoffset;
-
-                    if ((iX + pStipple->drawable.width) > fullX2)
-                        width = fullX2 - iX;
-                    else
-                        width = pStipple->drawable.width;
-
-                    if (iX == fullX1)
-                        xoffset =
-                            (fullX1 -
-                             (pDrawable->x +
-                              (pGC->patOrg.x % pStipple->drawable.width) -
-                              pStipple->drawable.width)) %
-                            pStipple->drawable.width;
-                    else
-                        xoffset = 0;
-
-                    if (xoffset + width > pStipple->drawable.width)
-                        width = pStipple->drawable.width - xoffset;
-
-                    BitBlt(pGCPriv->hdcMem,
-                           iX, fullY1,
-                           width, 1,
-                           hdcStipple,
-                           xoffset,
-                           (fullY1 -
-                            (pDrawable->y +
-                             (pGC->patOrg.y % pStipple->drawable.height) -
-                             pStipple->drawable.height)) %
-                           pStipple->drawable.height, g_copyROP[pGC->alu]);
-                }
-            }
-
-            /* Clear the stipple HDC */
-            SelectObject(hdcStipple, hbmpOrigStipple);
-            DeleteDC(hdcStipple);
-
-            /* Delete the device dependent stipple bitmap */
-            DeleteObject(hBitmap);
-
-            /* Restore the background mode */
-            SetBkMode(pGCPriv->hdcMem, OPAQUE);
-            break;
-
-        case FillTiled:
-
-            /* Get a pixmap pointer from the tile pointer, and fetch privates  */
-            pTile = (PixmapPtr) pGC->tile.pixmap;
-            pTilePriv = winGetPixmapPriv(pTile);
-
-            /* Create a memory DC to hold the tile */
-            hdcTile = CreateCompatibleDC(pGCPriv->hdcMem);
-
-            /* Select the tile into a DC */
-            hbmpOrig = SelectObject(hdcTile, pTilePriv->hBitmap);
-            if (hbmpOrig == NULL)
-                FatalError("winFillSpans - DRAWABLE_PIXMAP - FillTiled - "
-                           "SelectObject () failed on pTilePriv->hBitmap\n");
-
-            while (iSpans--) {
-                int width = pTile->drawable.width;
-
-                fullX1 = pPoints->x;
-                fullY1 = pPoints->y;
-                fullX2 = fullX1 + (int) *piWidths;
-                pPoints++;
-                piWidths++;
-
-                if (fullY1 < extentY1 || extentY2 <= fullY1)
-                    continue;
-
-                if (fullX1 < extentX1)
-                    fullX1 = extentX1;
-                if (fullX2 > extentX2)
-                    fullX2 = extentX2;
-
-                if (fullX1 >= fullX2)
-                    continue;
-
-                for (iX = fullX1; iX < fullX2; iX += width) {
-                    int xoffset;
-
-                    if ((iX + pTile->drawable.width) > fullX2)
-                        width = fullX2 - iX;
-                    else
-                        width = pTile->drawable.width;
-
-                    if (iX == fullX1)
-                        xoffset =
-                            (fullX1 -
-                             (pDrawable->x +
-                              (pGC->patOrg.x % pTile->drawable.width) -
-                              pTile->drawable.width)) % pTile->drawable.width;
-                    else
-                        xoffset = 0;
-
-                    if (xoffset + width > pTile->drawable.width)
-                        width = pTile->drawable.width - xoffset;
-
-                    BitBlt(pGCPriv->hdcMem,
-                           iX, fullY1,
-                           width, 1,
-                           hdcTile,
-                           xoffset,
-                           (fullY1 -
-                            (pDrawable->y +
-                             (pGC->patOrg.y % pTile->drawable.height) -
-                             pTile->drawable.height)) % pTile->drawable.height,
-                           g_copyROP[pGC->alu]);
-                }
-            }
-
-            /* Push the tile pixmap out of the memory HDC */
-            SelectObject(hdcTile, hbmpOrig);
-
-            /* Delete the tile */
-            DeleteDC(hdcTile);
-            break;
-
-        default:
-            ErrorF("winFillSpans - DRAWABLE_PIXMAP - Unknown fillStyle\n");
-            break;
-        }
-
-        /* Reset clip region */
-        SelectClipRgn(pGCPriv->hdcMem, NULL);
-
-        /* Push the drawable pixmap out of the GC HDC */
-        SelectObject(pGCPriv->hdcMem, hbmpOrig);
-        break;
-
-    case DRAWABLE_WINDOW:
-
-        SelectClipRgn(pGCPriv->hdc, combined);
-        DeleteObject(combined);
-        combined = NULL;
-
-        /* Branch on fill style */
-        switch (pGC->fillStyle) {
-        case FillSolid:
-
-            ROP16(pGCPriv->hdc, pGC->alu);
-
-            if (pDrawable->depth == 1) {
-                if (pGC->fgPixel == 0)
-                    hPenOrig = SelectObject(pGCPriv->hdc,
-                                            GetStockObject(BLACK_PEN));
-                else
-                    hPenOrig = SelectObject(pGCPriv->hdc,
-                                            GetStockObject(WHITE_PEN));
-            }
-            else {
-                fg = pGC->fgPixel;
-                TRANSLATE_COLOR(fg);
-                hPen = CreatePen(PS_SOLID, 0, fg);
-                hPenOrig = SelectObject(pGCPriv->hdc, hPen);
-            }
-
-            while (iSpans--) {
-                fullX1 = pPoints->x;
-                fullY1 = pPoints->y;
-                fullX2 = fullX1 + (int) *piWidths;
-                pPoints++;
-                piWidths++;
-
-                if (fullY1 < extentY1 || extentY2 <= fullY1)
-                    continue;
-
-                if (fullX1 < extentX1)
-                    fullX1 = extentX1;
-                if (fullX2 > extentX2)
-                    fullX2 = extentX2;
-
-                if (fullX1 >= fullX2)
-                    continue;
-
-                MoveToEx(pGCPriv->hdc, fullX1, fullY1, NULL);
-                LineTo(pGCPriv->hdc, fullX2, fullY1);
-            }
-
-            SetROP2(pGCPriv->hdc, R2_COPYPEN);
-
-            /* Give back the Brush */
-            SelectObject(pGCPriv->hdc, hPenOrig);
-
-            if (pDrawable->depth != 1)
-                DeleteObject(hPen);
-            break;
-
-        case FillOpaqueStippled:
-
-            pStipple = pGC->stipple;
-            pStipplePriv = winGetPixmapPriv(pStipple);
-
-            /* Create a device-dependent bitmap for the stipple */
-            hBitmap = CreateDIBitmap(pGCPriv->hdc,
-                                     (BITMAPINFOHEADER *) pStipplePriv->pbmih,
-                                     CBM_INIT,
-                                     pStipplePriv->pbBits,
-                                     (BITMAPINFO *) pStipplePriv->pbmih,
-                                     DIB_RGB_COLORS);
-
-            /* Create a memory DC to hold the stipple */
-            hdcStipple = CreateCompatibleDC(pGCPriv->hdc);
-
-            /* Select the stipple bitmap into the stipple DC */
-            hbmpOrigStipple = SelectObject(hdcStipple, hBitmap);
-            if (hbmpOrigStipple == NULL)
-                FatalError("winFillSpans () - DRAWABLE_PIXMAP - FillStippled - "
-                           "SelectObject () failed on hbmpOrigStipple\n");
-
-            /* Make a temporary copy of the foreground and background colors */
-            bg = pGC->bgPixel;
-            fg = pGC->fgPixel;
-
-            /* Translate the depth-dependent colors to Win32 COLORREFs */
-            TRANSLATE_COLOR(fg);
-            TRANSLATE_COLOR(bg);
-            SetTextColor(pGCPriv->hdc, fg);
-            SetBkColor(pGCPriv->hdc, bg);
-
-            while (iSpans--) {
-                int width = pStipple->drawable.width;
-
-                fullX1 = pPoints->x;
-                fullY1 = pPoints->y;
-                fullX2 = fullX1 + (int) *piWidths;
-                pPoints++;
-                piWidths++;
-
-                if (fullY1 < extentY1 || extentY2 <= fullY1)
-                    continue;
-
-                if (fullX1 < extentX1)
-                    fullX1 = extentX1;
-                if (fullX2 > extentX2)
-                    fullX2 = extentX2;
-
-                if (fullX1 >= fullX2)
-                    continue;
-
-                for (iX = fullX1; iX < fullX2; iX += width) {
-                    int xoffset;
-
-                    if ((iX + pStipple->drawable.width) > fullX2)
-                        width = fullX2 - iX;
-                    else
-                        width = pStipple->drawable.width;
-
-                    if (iX == fullX1)
-                        xoffset =
-                            (fullX1 -
-                             (pDrawable->x +
-                              (pGC->patOrg.x % pStipple->drawable.width) -
-                              pStipple->drawable.width)) %
-                            pStipple->drawable.width;
-                    else
-                        xoffset = 0;
-
-                    if (xoffset + width > pStipple->drawable.width)
-                        width = pStipple->drawable.width - xoffset;
-
-                    BitBlt(pGCPriv->hdc,
-                           iX, fullY1,
-                           width, 1,
-                           hdcStipple,
-                           xoffset,
-                           (fullY1 -
-                            (pDrawable->y +
-                             (pGC->patOrg.y % pStipple->drawable.height) -
-                             pStipple->drawable.height)) %
-                           pStipple->drawable.height, g_copyROP[pGC->alu]);
-                }
-            }
-
-            /* Clear the stipple HDC */
-            SelectObject(hdcStipple, hbmpOrigStipple);
-            DeleteDC(hdcStipple);
-
-            /* Delete the device dependent stipple bitmap */
-            DeleteObject(hBitmap);
-
-            break;
-
-        case FillStippled:
-            pStipple = pGC->stipple;
-            pStipplePriv = winGetPixmapPriv(pStipple);
-
-            /* Create a device-dependent bitmap for the stipple */
-            hBitmap = CreateDIBitmap(pGCPriv->hdcMem,
-                                     (BITMAPINFOHEADER *) pStipplePriv->pbmih,
-                                     CBM_INIT,
-                                     pStipplePriv->pbBits,
-                                     (BITMAPINFO *) pStipplePriv->pbmih,
-                                     DIB_RGB_COLORS);
-
-            /* Create a memory DC to hold the stipple */
-            hdcStipple = CreateCompatibleDC(pGCPriv->hdc);
-
-            /* Select the stipple bitmap into the stipple DC */
-            hbmpOrigStipple = SelectObject(hdcStipple, hBitmap);
-            if (hbmpOrigStipple == NULL)
-                FatalError("winFillSpans () - DRAWABLE_PIXMAP - FillStippled - "
-                           "SelectObject () failed on hbmpOrigStipple\n");
-
-            /* Make a temporary copy of the foreground and background colors */
-            bg = pGC->bgPixel;
-            fg = pGC->fgPixel;
-
-            /* Translate the depth-dependent colors to Win32 COLORREFs */
-            TRANSLATE_COLOR(fg);
-            TRANSLATE_COLOR(bg);
-
-            /* this is fudgy, we should only invert on the last one
-             * We need to get the black/white pixels right in the
-             * colormap. But yeah ! it's working.. 
-             */
-            if (pGC->bgPixel != -1 && pGC->fgPixel != -1) {
-                SetTextColor(pGCPriv->hdc, fg);
-                SetBkColor(pGCPriv->hdc, bg);
-                BitBlt(hdcStipple,
-                       0, 0,
-                       pStipple->drawable.width, pStipple->drawable.height,
-                       hdcStipple, 0, 0, 0x330008);
-            }
-            else if (pGC->bgPixel == -1) {
-                SetTextColor(pGCPriv->hdc, fg);
-                SetBkMode(pGCPriv->hdc, TRANSPARENT);
-                BitBlt(hdcStipple,
-                       0, 0,
-                       pStipple->drawable.width, pStipple->drawable.height,
-                       hdcStipple, 0, 0, 0x330008);
-            }
-            else if (pGC->fgPixel == -1) {
-                SetTextColor(pGCPriv->hdc, bg);
-                SetBkMode(pGCPriv->hdc, TRANSPARENT);
-#if 0
-                BitBlt(hdcStipple,
-                       0, 0,
-                       pStipple->drawable.width, pStipple->drawable.height,
-                       hdcStipple, 0, 0, 0x330008);
-#endif
-            }
-
-            while (iSpans--) {
-                int width = pStipple->drawable.width;
-
-                fullX1 = pPoints->x;
-                fullY1 = pPoints->y;
-                fullX2 = fullX1 + (int) *piWidths;
-                pPoints++;
-                piWidths++;
-
-                if (fullY1 < extentY1 || extentY2 <= fullY1)
-                    continue;
-
-                if (fullX1 < extentX1)
-                    fullX1 = extentX1;
-                if (fullX2 > extentX2)
-                    fullX2 = extentX2;
-
-                if (fullX1 >= fullX2)
-                    continue;
-
-                for (iX = fullX1; iX < fullX2; iX += width) {
-                    int xoffset;
-
-                    if ((iX + pStipple->drawable.width) > fullX2)
-                        width = fullX2 - iX;
-                    else
-                        width = pStipple->drawable.width;
-
-                    if (iX == fullX1)
-                        xoffset =
-                            (fullX1 -
-                             (pDrawable->x +
-                              (pGC->patOrg.x % pStipple->drawable.width) -
-                              pStipple->drawable.width)) %
-                            pStipple->drawable.width;
-                    else
-                        xoffset = 0;
-
-                    if (xoffset + width > pStipple->drawable.width)
-                        width = pStipple->drawable.width - xoffset;
-
-                    BitBlt(pGCPriv->hdc,
-                           iX, fullY1,
-                           width, 1,
-                           hdcStipple,
-                           xoffset,
-                           (fullY1 -
-                            (pDrawable->y +
-                             (pGC->patOrg.y % pStipple->drawable.height) -
-                             pStipple->drawable.height)) %
-                           pStipple->drawable.height, g_copyROP[pGC->alu]);
-                }
-            }
-
-            /* Clear the stipple HDC */
-            SelectObject(hdcStipple, hbmpOrigStipple);
-            DeleteDC(hdcStipple);
-
-            /* Delete the device dependent stipple bitmap */
-            DeleteObject(hBitmap);
-
-            /* Restore the background mode */
-            SetBkMode(pGCPriv->hdc, OPAQUE);
-            break;
-
-        case FillTiled:
-
-            /* Get a pixmap pointer from the tile pointer, and fetch privates  */
-            pTile = (PixmapPtr) pGC->tile.pixmap;
-            pTilePriv = winGetPixmapPriv(pTile);
-
-            /* Select the tile into a DC */
-            hbmpOrig = SelectObject(pGCPriv->hdcMem, pTilePriv->hBitmap);
-            if (hbmpOrig == NULL)
-                FatalError("winFillSpans - DRAWABLE_WINDOW - FillTiled - "
-                           "SelectObject () failed on pTilePriv->hBitmap\n");
-
-            while (iSpans--) {
-                int width = pTile->drawable.width;
-
-                fullX1 = pPoints->x;
-                fullY1 = pPoints->y;
-                fullX2 = fullX1 + (int) *piWidths;
-                pPoints++;
-                piWidths++;
-
-                if (fullY1 < extentY1 || extentY2 <= fullY1)
-                    continue;
-
-                if (fullX1 < extentX1)
-                    fullX1 = extentX1;
-                if (fullX2 > extentX2)
-                    fullX2 = extentX2;
-
-                if (fullX1 >= fullX2)
-                    continue;
-
-                for (iX = fullX1; iX < fullX2; iX += width) {
-                    int xoffset;
-
-                    if ((iX + pTile->drawable.width) > fullX2)
-                        width = fullX2 - iX;
-                    else
-                        width = pTile->drawable.width;
-
-                    if (iX == fullX1)
-                        xoffset =
-                            (fullX1 -
-                             (pDrawable->x +
-                              (pGC->patOrg.x % pTile->drawable.width) -
-                              pTile->drawable.width)) % pTile->drawable.width;
-                    else
-                        xoffset = 0;
-
-                    if (xoffset + width > pTile->drawable.width)
-                        width = pTile->drawable.width - xoffset;
-
-                    BitBlt(pGCPriv->hdc,
-                           iX, fullY1,
-                           width, 1,
-                           pGCPriv->hdcMem,
-                           xoffset,
-                           (fullY1 -
-                            (pDrawable->y +
-                             (pGC->patOrg.y % pTile->drawable.height) -
-                             pTile->drawable.height)) % pTile->drawable.height,
-                           g_copyROP[pGC->alu]);
-                }
-            }
-
-            /* Push the tile pixmap out of the memory HDC */
-            SelectObject(pGCPriv->hdcMem, hbmpOrig);
-            break;
-
-        default:
-            ErrorF("winFillSpans - DRAWABLE_WINDOW - Unknown fillStyle\n");
-            break;
-        }
-
-        /* Reset clip region */
-        SelectClipRgn(pGCPriv->hdc, NULL);
-        break;
-
-    default:
-        ErrorF("winFillSpans - Unknown drawable type\n");
-        break;
-    }
-}
diff --git a/hw/xwin/winfont.c b/hw/xwin/winfont.c
deleted file mode 100644
index 7bcbce1..0000000
--- a/hw/xwin/winfont.c
+++ /dev/null
@@ -1,82 +0,0 @@
-/*
- *Copyright (C) 2001-2004 Harold L Hunt II 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, FITNESS FOR A PARTICULAR PURPOSE AND
- *NONINFRINGEMENT. IN NO EVENT SHALL HAROLD L HUNT II 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 Harold L Hunt II
- *shall not be used in advertising or otherwise to promote the sale, use
- *or other dealings in this Software without prior written authorization
- *from Harold L Hunt II.
- *
- * Authors:	Harold L Hunt II
- */
-
-#ifdef HAVE_XWIN_CONFIG_H
-#include <xwin-config.h>
-#endif
-#include "win.h"
-
-#ifdef XWIN_NATIVEGDI
-/* See Porting Layer Definition - p. 32 */
-/* See mfb/mfbfont.c - mfbRealizeFont() - which is empty :) */
-Bool
-winRealizeFontNativeGDI(ScreenPtr pScreen, FontPtr pFont)
-{
-    BOOL fResult = TRUE;
-
-    winScreenPriv(pScreen);
-
-#if CYGDEBUG
-    winTrace("winRealizeFont (%p, %p)\n", pScreen, pFont);
-#endif
-
-    WIN_UNWRAP(RealizeFont);
-    if (pScreen->RealizeFont)
-        fResult = (*pScreen->RealizeFont) (pScreen, pFont);
-    WIN_WRAP(RealizeFont, winRealizeFontNativeGDI);
-
-    return fResult;
-}
-
-/* See Porting Layer Definition - p. 32 */
-/* See mfb/mfbfont.c - mfbUnrealizeFont() - which is empty :) */
-Bool
-winUnrealizeFontNativeGDI(ScreenPtr pScreen, FontPtr pFont)
-{
-    BOOL fResult = TRUE;
-
-    winScreenPriv(pScreen);
-
-#if CYGDEBUG
-    winTrace("winUnrealizeFont (%p, %p)\n", pScreen, pFont);
-#endif
-
-    WIN_UNWRAP(UnrealizeFont);
-    if (pScreen->UnrealizeFont)
-        fResult = (*pScreen->UnrealizeFont) (pScreen, pFont);
-    WIN_WRAP(UnrealizeFont, winUnrealizeFontNativeGDI);
-
-    return fResult;
-#if CYGDEBUG
-    winDebug("winUnrealizeFont()\n");
-#endif
-    return TRUE;
-}
-#endif
diff --git a/hw/xwin/wingc.c b/hw/xwin/wingc.c
deleted file mode 100644
index 5986e0a..0000000
--- a/hw/xwin/wingc.c
+++ /dev/null
@@ -1,235 +0,0 @@
-/*
- *Copyright (C) 2001-2004 Harold L Hunt II 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, FITNESS FOR A PARTICULAR PURPOSE AND
- *NONINFRINGEMENT. IN NO EVENT SHALL HAROLD L HUNT II 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 Harold L Hunt II
- *shall not be used in advertising or otherwise to promote the sale, use
- *or other dealings in this Software without prior written authorization
- *from Harold L Hunt II.
- *
- * Authors:	Harold L Hunt II
- */
-
-#ifdef HAVE_XWIN_CONFIG_H
-#include <xwin-config.h>
-#endif
-#include "win.h"
-
-/*
- * Local prototypes
- */
-
-#if 0
-static void
- winChangeGCNativeGDI(GCPtr pGC, unsigned long ulChanges);
-#endif
-
-static void
-
-winValidateGCNativeGDI(GCPtr pGC, unsigned long changes, DrawablePtr pDrawable);
-
-#if 0
-static void
- winCopyGCNativeGDI(GCPtr pGCsrc, unsigned long ulMask, GCPtr pGCdst);
-#endif
-
-static void
- winDestroyGCNativeGDI(GCPtr pGC);
-
-#if 0
-static void
- winChangeClipNativeGDI(GCPtr pGC, int nType, void *pValue, int nRects);
-
-static void
- winDestroyClipNativeGDI(GCPtr pGC);
-
-static void
- winCopyClipNativeGDI(GCPtr pGCdst, GCPtr pGCsrc);
-#endif
-
-#if 0
-/* GC Handling Routines */
-const GCFuncs winGCFuncs = {
-    winValidateGCNativeGDI,
-    winChangeGCNativeGDI,
-    winCopyGCNativeGDI,
-    winDestroyGCNativeGDI,
-    winChangeClipNativeGDI,
-    winDestroyClipNativeGDI,
-    winCopyClipNativeGDI,
-};
-#else
-const GCFuncs winGCFuncs = {
-    winValidateGCNativeGDI,
-    miChangeGC,
-    miCopyGC,
-    winDestroyGCNativeGDI,
-    miChangeClip,
-    miDestroyClip,
-    miCopyClip,
-};
-#endif
-
-/* Drawing Primitives */
-const GCOps winGCOps = {
-    winFillSpansNativeGDI,
-    winSetSpansNativeGDI,
-    miPutImage,
-    miCopyArea,
-    miCopyPlane,
-    miPolyPoint,
-    winPolyLineNativeGDI,
-    miPolySegment,
-    miPolyRectangle,
-    miPolyArc,
-    miFillPolygon,
-    miPolyFillRect,
-    miPolyFillArc,
-    miPolyText8,
-    miPolyText16,
-    miImageText8,
-    miImageText16,
-#if 0
-    winImageGlyphBltNativeGDI,
-    winPolyGlyphBltNativeGDI,
-#else
-    miImageGlyphBlt,
-    miPolyGlyphBlt,
-#endif
-    miPushPixels,
-};
-
-/* See Porting Layer Definition - p. 45 */
-/* See mfb/mfbgc.c - mfbCreateGC() */
-/* See Strategies for Porting - pp. 15, 16 */
-Bool
-winCreateGCNativeGDI(GCPtr pGC)
-{
-    winPrivGCPtr pGCPriv = NULL;
-    winPrivScreenPtr pScreenPriv = NULL;
-
-#if 0
-    ErrorF("winCreateGCNativeGDI - depth: %d\n", pGC->depth);
-#endif
-
-    pGC->ops = (GCOps *) &winGCOps;
-    pGC->funcs = (GCFuncs *) &winGCFuncs;
-
-    /* We want all coordinates passed to spans functions to be screen relative */
-    pGC->miTranslate = TRUE;
-
-    /* Allocate privates for this GC */
-    pGCPriv = winGetGCPriv(pGC);
-    if (pGCPriv == NULL) {
-        ErrorF("winCreateGCNativeGDI () - Privates pointer was NULL\n");
-        return FALSE;
-    }
-
-    /* Create a new screen DC for the display window */
-    pScreenPriv = winGetScreenPriv(pGC->pScreen);
-    pGCPriv->hdc = GetDC(pScreenPriv->hwndScreen);
-
-    /* Allocate a memory DC for the GC */
-    pGCPriv->hdcMem = CreateCompatibleDC(pGCPriv->hdc);
-
-    return TRUE;
-}
-
-#if 0
-/* See Porting Layer Definition - p. 45 */
-static void
-winChangeGCNativeGDI(GCPtr pGC, unsigned long ulChanges)
-{
-#if 0
-    ErrorF("winChangeGCNativeGDI () - Doing nothing\n");
-#endif
-}
-#endif
-
-static void
-winValidateGCNativeGDI(GCPtr pGC,
-                       unsigned long ulChanges, DrawablePtr pDrawable)
-{
-    if ((ulChanges &
-         (GCClipXOrigin | GCClipYOrigin | GCClipMask | GCSubwindowMode))
-        || (pDrawable->serialNumber !=
-            (pGC->serialNumber & DRAWABLE_SERIAL_BITS))) {
-        miComputeCompositeClip(pGC, pDrawable);
-    }
-}
-
-#if 0
-/* See Porting Layer Definition - p. 46 */
-static void
-winCopyGCNativeGDI(GCPtr pGCsrc, unsigned long ulMask, GCPtr pGCdst)
-{
-
-}
-#endif
-
-/* See Porting Layer Definition - p. 46 */
-static void
-winDestroyGCNativeGDI(GCPtr pGC)
-{
-    winGCPriv(pGC);
-    winScreenPriv(pGC->pScreen);
-
-    if (pGC->freeCompClip)
-        RegionDestroy(pGC->pCompositeClip);
-
-    /* Free the memory DC */
-    if (pGCPriv->hdcMem != NULL) {
-        DeleteDC(pGCPriv->hdcMem);
-        pGCPriv->hdcMem = NULL;
-    }
-
-    /* Release the screen DC for the display window */
-    if (pGCPriv->hdc != NULL) {
-        ReleaseDC(pScreenPriv->hwndScreen, pGCPriv->hdc);
-        pGCPriv->hdc = NULL;
-    }
-
-    /* Invalidate the GC privates pointer */
-    winSetGCPriv(pGC, NULL);
-}
-
-#if 0
-/* See Porting Layer Definition - p. 46 */
-static void
-winChangeClipNativeGDI(GCPtr pGC, int nType, void *pValue, int nRects)
-{
-
-}
-
-/* See Porting Layer Definition - p. 47 */
-static void
-winDestroyClipNativeGDI(GCPtr pGC)
-{
-
-}
-
-/* See Porting Layer Definition - p. 47 */
-static void
-winCopyClipNativeGDI(GCPtr pGCdst, GCPtr pGCsrc)
-{
-
-}
-#endif
diff --git a/hw/xwin/wingetsp.c b/hw/xwin/wingetsp.c
deleted file mode 100644
index 049e2c9..0000000
--- a/hw/xwin/wingetsp.c
+++ /dev/null
@@ -1,171 +0,0 @@
-/*
- *Copyright (C) 1994-2000 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, FITNESS 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.
- *
- * Authors:	Harold L Hunt II
- * 		Alan Hourihane <alanh at fairlite.demon.co.uk>
- */
-
-#ifdef HAVE_XWIN_CONFIG_H
-#include <xwin-config.h>
-#endif
-#include "win.h"
-
-/* See Porting Layer Definition - p. 55 */
-void
-winGetSpansNativeGDI(DrawablePtr pDrawable,
-                     int nMax,
-                     DDXPointPtr pPoints,
-                     int *piWidths, int iSpans, char *pDsts)
-{
-    PixmapPtr pPixmap = NULL;
-    winPrivPixmapPtr pPixmapPriv = NULL;
-    int iSpan;
-    DDXPointPtr pPoint = NULL;
-    int *piWidth = NULL;
-    char *pDst = pDsts;
-    HBITMAP hbmpWindow, hbmpOrig, hbmpOrig1;
-    BYTE *pbWindow = NULL;
-    HDC hdcMem, hdcMem1;
-    ScreenPtr pScreen = pDrawable->pScreen;
-
-    winScreenPriv(pScreen);
-
-    /* Branch on the drawable type */
-    switch (pDrawable->type) {
-    case DRAWABLE_PIXMAP:
-#if 0
-        ErrorF("winGetSpans - DRAWABLE_PIXMAP %08x\n", pDrawable);
-#endif
-
-        pPixmap = (PixmapPtr) pDrawable;
-        pPixmapPriv = winGetPixmapPriv(pPixmap);
-
-        /* Open a memory HDC */
-        hdcMem1 = CreateCompatibleDC(NULL);
-        hdcMem = CreateCompatibleDC(NULL);
-
-        /* Select the drawable pixmap into a DC */
-        hbmpOrig1 = SelectObject(hdcMem1, pPixmapPriv->hBitmap);
-
-        if (hbmpOrig1 == NULL)
-            FatalError("winGetSpans - DRAWABLE_PIXMAP - SelectObject () "
-                       "failed on pPixmapPriv->hBitmap\n");
-
-        /* Loop through spans */
-        for (iSpan = 0; iSpan < iSpans; ++iSpan) {
-            pPoint = pPoints + iSpan;
-            piWidth = piWidths + iSpan;
-
-            hbmpWindow = winCreateDIBNativeGDI(*piWidth, 1,
-                                               pDrawable->depth,
-                                               &pbWindow, NULL);
-
-            hbmpOrig = SelectObject(hdcMem, hbmpWindow);
-
-            /* Transfer the window bits to the window bitmap */
-            BitBlt(hdcMem,
-                   0, 0, *piWidth, 1, hdcMem1, pPoint->x, pPoint->y, SRCCOPY);
-
-            memcpy(pDst,
-                   (char *) pbWindow,
-                   PixmapBytePad(*piWidth, pDrawable->depth));
-
-            /* Pop the window bitmap out of the HDC and delete the bitmap */
-            SelectObject(hdcMem, hbmpOrig);
-            DeleteObject(hbmpWindow);
-
-#if 0
-            ErrorF("(%dx%dx%d) (%d,%d) w: %d\n",
-                   pDrawable->width, pDrawable->height, pDrawable->depth,
-                   pPoint->x, pPoint->y, *piWidth);
-#endif
-
-            /* Calculate offset of next bit destination */
-            pDst += PixmapBytePad(*piWidth, pDrawable->depth);
-        }
-
-        /* Pop the pixmap's bitmap out of the HDC */
-        SelectObject(hdcMem1, hbmpOrig1);
-
-        /* Delete the HDCs */
-        DeleteDC(hdcMem1);
-        DeleteDC(hdcMem);
-        break;
-
-    case DRAWABLE_WINDOW:
-#if 0
-        ErrorF("winGetSpans - DRAWABLE_WINDOW\n");
-#endif
-
-        /* Open a memory HDC */
-        hdcMem = CreateCompatibleDC(NULL);
-
-        /* Loop through spans */
-        for (iSpan = 0; iSpan < iSpans; ++iSpan) {
-            pPoint = pPoints + iSpan;
-            piWidth = piWidths + iSpan;
-
-            hbmpWindow = winCreateDIBNativeGDI(*piWidth, 1,
-                                               pDrawable->depth,
-                                               &pbWindow, NULL);
-
-            hbmpOrig = SelectObject(hdcMem, hbmpWindow);
-
-            /* Transfer the window bits to the window bitmap */
-            BitBlt(hdcMem,
-                   0, 0,
-                   *piWidth, 1,
-                   pScreenPriv->hdcScreen, pPoint->x, pPoint->y, SRCCOPY);
-
-            memcpy(pDst,
-                   (char *) pbWindow,
-                   PixmapBytePad(*piWidth, pDrawable->depth));
-
-            /* Pop the window bitmap out of the HDC */
-            SelectObject(hdcMem, hbmpOrig);
-
-            DeleteObject(hbmpWindow);
-
-#if 0
-            ErrorF("(%dx%dx%d) (%d,%d) w: %d\n",
-                   pDrawable->width, pDrawable->height, pDrawable->depth,
-                   pPoint->x, pPoint->y, *piWidth);
-#endif
-
-            /* Calculate offset of next bit destination */
-            pDst += PixmapBytePad(*piWidth, pDrawable->depth);
-        }
-
-        /* Delete the window bitmap */
-        DeleteDC(hdcMem);
-        break;
-
-    default:
-        FatalError("winGetSpans - Unknown drawable type\n");
-        break;
-    }
-}
diff --git a/hw/xwin/winmisc.c b/hw/xwin/winmisc.c
index 10f9732..bea6290 100644
--- a/hw/xwin/winmisc.c
+++ b/hw/xwin/winmisc.c
@@ -33,21 +33,6 @@
 #endif
 #include "win.h"
 
-#ifdef XWIN_NATIVEGDI
-/* See Porting Layer Definition - p. 33 */
-/*
- * Called by clients, returns the best size for a cursor, tile, or
- * stipple, specified by class (sometimes called kind)
- */
-
-void
-winQueryBestSizeNativeGDI(int class, unsigned short *pWidth,
-                          unsigned short *pHeight, ScreenPtr pScreen)
-{
-    ErrorF("winQueryBestSizeNativeGDI\n");
-}
-#endif
-
 /*
  * Count the number of one bits in a color mask.
  */
@@ -93,51 +78,3 @@ winUpdateFBPointer(ScreenPtr pScreen, void *pbits)
 
     return TRUE;
 }
-
-#ifdef XWIN_NATIVEGDI
-/*
- * Paint the window background with the specified color
- */
-
-BOOL
-winPaintBackground(HWND hwnd, COLORREF colorref)
-{
-    HDC hdc;
-    HBRUSH hbrush;
-    RECT rect;
-
-    /* Create an hdc */
-    hdc = GetDC(hwnd);
-    if (hdc == NULL) {
-        printf("gdiWindowProc - GetDC failed\n");
-        exit(1);
-    }
-
-    /* Create and select blue brush */
-    hbrush = CreateSolidBrush(colorref);
-    if (hbrush == NULL) {
-        printf("gdiWindowProc - CreateSolidBrush failed\n");
-        exit(1);
-    }
-
-    /* Get window extents */
-    if (GetClientRect(hwnd, &rect) == FALSE) {
-        printf("gdiWindowProc - GetClientRect failed\n");
-        exit(1);
-    }
-
-    /* Fill window with blue brush */
-    if (FillRect(hdc, &rect, hbrush) == 0) {
-        printf("gdiWindowProc - FillRect failed\n");
-        exit(1);
-    }
-
-    /* Delete blue brush */
-    DeleteObject(hbrush);
-
-    /* Release the hdc */
-    ReleaseDC(hwnd, hdc);
-
-    return TRUE;
-}
-#endif
diff --git a/hw/xwin/winnativegdi.c b/hw/xwin/winnativegdi.c
deleted file mode 100644
index 1859698..0000000
--- a/hw/xwin/winnativegdi.c
+++ /dev/null
@@ -1,491 +0,0 @@
-/*
- *Copyright (C) 1994-2000 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, FITNESS 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.
- *
- * Authors:	Harold L Hunt II
- */
-
-#ifdef HAVE_XWIN_CONFIG_H
-#include <xwin-config.h>
-#endif
-#include "win.h"
-
-/*
- * Local function prototypes
- */
-
-static Bool
- winAllocateFBNativeGDI(ScreenPtr pScreen);
-
-static void
- winShadowUpdateNativeGDI(ScreenPtr pScreen, shadowBufPtr pBuf);
-
-static Bool
- winCloseScreenNativeGDI(ScreenPtr pScreen);
-
-static Bool
- winInitVisualsNativeGDI(ScreenPtr pScreen);
-
-static Bool
- winAdjustVideoModeNativeGDI(ScreenPtr pScreen);
-
-#if 0
-static Bool
- winBltExposedRegionsNativeGDI(ScreenPtr pScreen);
-#endif
-
-static Bool
- winActivateAppNativeGDI(ScreenPtr pScreen);
-
-static Bool
- winRedrawScreenNativeGDI(ScreenPtr pScreen);
-
-static Bool
- winRealizeInstalledPaletteNativeGDI(ScreenPtr pScreen);
-
-static Bool
- winInstallColormapNativeGDI(ColormapPtr pColormap);
-
-static Bool
- winStoreColorsNativeGDI(ColormapPtr pmap, int ndef, xColorItem * pdefs);
-
-static Bool
- winCreateColormapNativeGDI(ColormapPtr pColormap);
-
-static Bool
- winDestroyColormapNativeGDI(ColormapPtr pColormap);
-
-static Bool
-winAllocateFBNativeGDI(ScreenPtr pScreen)
-{
-    FatalError("winAllocateFBNativeGDI\n");
-
-    return TRUE;
-}
-
-static void
-winFreeFBNativeGDI(ScreenPtr pScreen)
-{
-    FatalError("winFreeFBNativeGDI\n");
-}
-
-static Bool
-winInitScreenNativeGDI(ScreenPtr pScreen)
-{
-    FatalError("winInitScreenNativeGDI\n");
-}
-
-/*
- * We wrap whatever CloseScreen procedure was specified by fb;
- * a pointer to said procedure is stored in our privates.
- */
-
-static Bool
-winCloseScreenNativeGDI(ScreenPtr pScreen)
-{
-    winScreenPriv(pScreen);
-    winScreenInfo *pScreenInfo = pScreenPriv->pScreenInfo;
-
-    ErrorF("winCloseScreenNativeGDI - Freeing screen resources\n");
-
-    /* Flag that the screen is closed */
-    pScreenPriv->fClosed = TRUE;
-    pScreenPriv->fActive = FALSE;
-
-    /* 
-     * NOTE: mi doesn't use a CloseScreen procedure, so we do not
-     * need to call a wrapped procedure here.
-     */
-
-    /* Delete the window property */
-    RemoveProp(pScreenPriv->hwndScreen, WIN_SCR_PROP);
-
-    ErrorF("winCloseScreenNativeGDI - Destroying window\n");
-
-    /* Delete tray icon, if we have one */
-    if (!pScreenInfo->fNoTrayIcon)
-        winDeleteNotifyIcon(pScreenPriv);
-
-    /* Free the exit confirmation dialog box, if it exists */
-    if (g_hDlgExit != NULL) {
-        DestroyWindow(g_hDlgExit);
-        g_hDlgExit = NULL;
-    }
-
-    /* Kill our window */
-    if (pScreenPriv->hwndScreen) {
-        DestroyWindow(pScreenPriv->hwndScreen);
-        pScreenPriv->hwndScreen = NULL;
-    }
-
-    /* Invalidate our screeninfo's pointer to the screen */
-    pScreenInfo->pScreen = NULL;
-
-    /* Free the screen privates for this screen */
-    free(pScreenPriv);
-
-    ErrorF("winCloseScreenNativeGDI - Returning\n");
-
-    return TRUE;
-}
-
-static void
-winShadowUpdateNativeGDI(ScreenPtr pScreen, shadowBufPtr pBuf)
-{
-    FatalError("winShadowUpdateNativeGDI\n");
-    return;
-}
-
-static Bool
-winInitVisualsNativeGDI(ScreenPtr pScreen)
-{
-    winScreenPriv(pScreen);
-    winScreenInfo *pScreenInfo = pScreenPriv->pScreenInfo;
-
-    /* Set the bitsPerRGB and bit masks */
-    switch (pScreenInfo->dwDepth) {
-    case 24:
-        pScreenPriv->dwBitsPerRGB = 8;
-        pScreenPriv->dwRedMask = 0x00FF0000;
-        pScreenPriv->dwGreenMask = 0x0000FF00;
-        pScreenPriv->dwBlueMask = 0x000000FF;
-        break;
-
-    case 16:
-        pScreenPriv->dwBitsPerRGB = 6;
-        pScreenPriv->dwRedMask = 0xF800;
-        pScreenPriv->dwGreenMask = 0x07E0;
-        pScreenPriv->dwBlueMask = 0x001F;
-        break;
-
-    case 15:
-        pScreenPriv->dwBitsPerRGB = 5;
-        pScreenPriv->dwRedMask = 0x7C00;
-        pScreenPriv->dwGreenMask = 0x03E0;
-        pScreenPriv->dwBlueMask = 0x001F;
-        break;
-
-    case 8:
-        pScreenPriv->dwBitsPerRGB = 8;
-        pScreenPriv->dwRedMask = 0;
-        pScreenPriv->dwGreenMask = 0;
-        pScreenPriv->dwBlueMask = 0;
-        break;
-
-    default:
-        ErrorF("winInitVisualsNativeGDI - Unknown screen depth\n");
-        return FALSE;
-        break;
-    }
-
-    /* Tell the user how many bits per RGB we are using */
-    ErrorF("winInitVisualsNativeGDI - Using dwBitsPerRGB: %d\n",
-           (int) pScreenPriv->dwBitsPerRGB);
-
-    /* Create a single visual according to the Windows screen depth */
-    switch (pScreenInfo->dwDepth) {
-    case 24:
-    case 16:
-    case 15:
-        if (!miSetVisualTypesAndMasks(pScreenInfo->dwDepth,
-                                      TrueColorMask,
-                                      pScreenPriv->dwBitsPerRGB,
-                                      TrueColor,
-                                      pScreenPriv->dwRedMask,
-                                      pScreenPriv->dwGreenMask,
-                                      pScreenPriv->dwBlueMask)) {
-            ErrorF("winInitVisuals - miSetVisualTypesAndMasks failed\n");
-            return FALSE;
-        }
-        break;
-
-    case 8:
-        ErrorF("winInitVisuals - Calling miSetVisualTypesAndMasks\n");
-        if (!miSetVisualTypesAndMasks(pScreenInfo->dwDepth,
-                                      StaticColorMask,
-                                      pScreenPriv->dwBitsPerRGB,
-                                      StaticColor,
-                                      pScreenPriv->dwRedMask,
-                                      pScreenPriv->dwGreenMask,
-                                      pScreenPriv->dwBlueMask)) {
-            ErrorF("winInitVisuals - miSetVisualTypesAndMasks failed\n");
-            return FALSE;
-        }
-        break;
-
-    default:
-        ErrorF("winInitVisualsNativeGDI - Unknown screen depth\n");
-        return FALSE;
-    }
-
-#if 1
-    ErrorF("winInitVisualsNativeGDI - Returning\n");
-#endif
-
-    return TRUE;
-}
-
-/* Adjust the video mode */
-static Bool
-winAdjustVideoModeNativeGDI(ScreenPtr pScreen)
-{
-    winScreenPriv(pScreen);
-    winScreenInfo *pScreenInfo = pScreenPriv->pScreenInfo;
-    HDC hdc = NULL;
-    DWORD dwBPP;
-
-    hdc = GetDC(NULL);
-
-    /* We're in serious trouble if we can't get a DC */
-    if (hdc == NULL) {
-        ErrorF("winAdjustVideoModeNativeGDI - GetDC () failed\n");
-        return FALSE;
-    }
-
-    /* Query GDI for current display depth */
-    dwBPP = GetDeviceCaps(hdc, BITSPIXEL);
-    pScreenInfo->dwDepth = GetDeviceCaps(hdc, PLANES);
-
-    switch (pScreenInfo->dwDepth) {
-    case 24:
-    case 16:
-    case 15:
-    case 8:
-        break;
-    default:
-        if (dwBPP == 32)
-            pScreenInfo->dwDepth = 24;
-        else
-            pScreenInfo->dwDepth = dwBPP;
-        break;
-    }
-
-    /* GDI cannot change the screen depth, so we'll use GDI's depth */
-    pScreenInfo->dwBPP = dwBPP;
-
-    /* Release our DC */
-    ReleaseDC(NULL, hdc);
-
-    return TRUE;
-}
-
-static Bool
-winActivateAppNativeGDI(ScreenPtr pScreen)
-{
-    winScreenPriv(pScreen);
-
-    /*
-     * Are we active?
-     * Are we fullscreen?
-     */
-    if (pScreenPriv != NULL
-        && pScreenPriv->fActive
-        && pScreenPriv->pScreenInfo && pScreenPriv->pScreenInfo->fFullScreen) {
-        /*
-         * Activating, attempt to bring our window 
-         * to the top of the display
-         */
-        ShowWindow(pScreenPriv->hwndScreen, SW_RESTORE);
-    }
-
-    /*
-     * Are we inactive?
-     * Are we fullscreen?
-     */
-    if (pScreenPriv != NULL
-        && !pScreenPriv->fActive
-        && pScreenPriv->pScreenInfo && pScreenPriv->pScreenInfo->fFullScreen) {
-        /*
-         * Deactivating, stuff our window onto the
-         * task bar.
-         */
-        ShowWindow(pScreenPriv->hwndScreen, SW_MINIMIZE);
-    }
-
-    return TRUE;
-}
-
-HBITMAP
-winCreateDIBNativeGDI(int iWidth, int iHeight, int iDepth,
-                      BYTE ** ppbBits, BITMAPINFO ** ppbmi)
-{
-    BITMAPINFOHEADER *pbmih = NULL;
-    HBITMAP hBitmap = NULL;
-    BITMAPINFO *pbmi = NULL;
-
-    /* Don't create an invalid bitmap */
-    if (iWidth == 0 || iHeight == 0 || iDepth == 0) {
-        ErrorF("\nwinCreateDIBNativeGDI - Invalid specs w %d h %d d %d\n\n",
-               iWidth, iHeight, iDepth);
-        return NULL;
-    }
-
-    /* Allocate bitmap info header */
-    pbmih = malloc(sizeof(BITMAPINFOHEADER) + 256 * sizeof(RGBQUAD));
-    if (pbmih == NULL) {
-        ErrorF("winCreateDIBNativeGDI - malloc () failed\n");
-        return FALSE;
-    }
-    ZeroMemory(pbmih, sizeof(BITMAPINFOHEADER) + 256 * sizeof(RGBQUAD));
-
-    /* Describe bitmap to be created */
-    pbmih->biSize = sizeof(BITMAPINFOHEADER);
-    pbmih->biWidth = iWidth;
-    pbmih->biHeight = -iHeight;
-    pbmih->biPlanes = 1;
-    pbmih->biBitCount = iDepth;
-    pbmih->biCompression = BI_RGB;
-    pbmih->biSizeImage = 0;
-    pbmih->biXPelsPerMeter = 0;
-    pbmih->biYPelsPerMeter = 0;
-    pbmih->biClrUsed = 0;
-    pbmih->biClrImportant = 0;
-
-    /* Setup color table for mono DIBs */
-    if (iDepth == 1) {
-        pbmi = (BITMAPINFO *) pbmih;
-        pbmi->bmiColors[1].rgbBlue = 255;
-        pbmi->bmiColors[1].rgbGreen = 255;
-        pbmi->bmiColors[1].rgbRed = 255;
-    }
-
-    /* Create a DIB with a bit pointer */
-    hBitmap = CreateDIBSection(NULL,
-                               (BITMAPINFO *) pbmih,
-                               DIB_RGB_COLORS, (void **) ppbBits, NULL, 0);
-    if (hBitmap == NULL) {
-        ErrorF("winCreateDIBNativeGDI - CreateDIBSection () failed\n");
-        return NULL;
-    }
-
-    /* Free the bitmap info header memory */
-    if (ppbmi != NULL) {
-        /* Store the address of the BMIH in the ppbmih parameter */
-        *ppbmi = (BITMAPINFO *) pbmih;
-    }
-    else {
-        free(pbmih);
-        pbmih = NULL;
-    }
-
-    return hBitmap;
-}
-
-#if 0
-static Bool
-winBltExposedRegionsNativeGDI(ScreenPtr pScreen)
-{
-
-    return TRUE;
-}
-#endif
-
-static Bool
-winRedrawScreenNativeGDI(ScreenPtr pScreen)
-{
-    FatalError("winRedrawScreenNativeGDI\n");
-    return TRUE;
-}
-
-static Bool
-winRealizeInstalledPaletteNativeGDI(ScreenPtr pScreen)
-{
-    FatalError("winRealizeInstalledPaletteNativeGDI\n");
-    return TRUE;
-}
-
-static Bool
-winInstallColormapNativeGDI(ColormapPtr pColormap)
-{
-    FatalError("winInstallColormapNativeGDI\n");
-    return TRUE;
-}
-
-static Bool
-winStoreColorsNativeGDI(ColormapPtr pmap, int ndef, xColorItem * pdefs)
-{
-    FatalError("winStoreColorsNativeGDI\n");
-    return TRUE;
-}
-
-static Bool
-winCreateColormapNativeGDI(ColormapPtr pColormap)
-{
-    FatalError("winCreateColormapNativeGDI\n");
-    return TRUE;
-}
-
-static Bool
-winDestroyColormapNativeGDI(ColormapPtr pColormap)
-{
-    FatalError("winDestroyColormapNativeGDI\n");
-    return TRUE;
-}
-
-/* Set engine specific funtions */
-Bool
-winSetEngineFunctionsNativeGDI(ScreenPtr pScreen)
-{
-    winScreenPriv(pScreen);
-    winScreenInfo *pScreenInfo = pScreenPriv->pScreenInfo;
-
-    /* Set our pointers */
-    pScreenPriv->pwinAllocateFB = winAllocateFBNativeGDI;
-    pScreenPriv->pwinFreeFB = winFreeFBNativeGDI;
-    pScreenPriv->pwinShadowUpdate = winShadowUpdateNativeGDI;
-    pScreenPriv->pwinInitScreen = winInitScreenNativeGDI;
-    pScreenPriv->pwinCloseScreen = winCloseScreenNativeGDI;
-    pScreenPriv->pwinInitVisuals = winInitVisualsNativeGDI;
-    pScreenPriv->pwinAdjustVideoMode = winAdjustVideoModeNativeGDI;
-    if (pScreenInfo->fFullScreen)
-        pScreenPriv->pwinCreateBoundingWindow =
-            winCreateBoundingWindowFullScreen;
-    else
-        pScreenPriv->pwinCreateBoundingWindow = winCreateBoundingWindowWindowed;
-    pScreenPriv->pwinFinishScreenInit = winFinishScreenInitNativeGDI;
-    /*
-     * WARNING: Do not set the BltExposedRegions procedure pointer to anything
-     * other than NULL until a working painting procedure is in place.
-     * Else, winWindowProc will get stuck in an infinite loop because
-     * Windows expects the BeginPaint and EndPaint functions to be called
-     * before a WM_PAINT message can be removed from the queue.  We are
-     * using NULL here as a signal for winWindowProc that it should
-     * not signal that the WM_PAINT message has been processed.
-     */
-    pScreenPriv->pwinBltExposedRegions = NULL;
-    pScreenPriv->pwinActivateApp = winActivateAppNativeGDI;
-    pScreenPriv->pwinRedrawScreen = winRedrawScreenNativeGDI;
-    pScreenPriv->pwinRealizeInstalledPalette =
-        winRealizeInstalledPaletteNativeGDI;
-    pScreenPriv->pwinInstallColormap = winInstallColormapNativeGDI;
-    pScreenPriv->pwinStoreColors = winStoreColorsNativeGDI;
-    pScreenPriv->pwinCreateColormap = winCreateColormapNativeGDI;
-    pScreenPriv->pwinDestroyColormap = winDestroyColormapNativeGDI;
-    pScreenPriv->pwinHotKeyAltTab =
-        (winHotKeyAltTabProcPtr) (void (*)(void)) NoopDDA;
-
-    return TRUE;
-}
diff --git a/hw/xwin/winpixmap.c b/hw/xwin/winpixmap.c
deleted file mode 100644
index ef158c8..0000000
--- a/hw/xwin/winpixmap.c
+++ /dev/null
@@ -1,223 +0,0 @@
-/*
- *Copyright (C) 1994-2000 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, FITNESS 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.
- *
- * Authors:	drewry, september 1986
- *		Harold L Hunt II
- */
-
-#ifdef HAVE_XWIN_CONFIG_H
-#include <xwin-config.h>
-#endif
-#include "win.h"
-
-/*
- * Local prototypes
- */
-
-#if 0
-static void
- winXRotatePixmapNativeGDI(PixmapPtr pPix, int rw);
-
-static void
- winYRotatePixmapNativeGDI(PixmapPtr pPix, int rh);
-
-static void
-
-winCopyRotatePixmapNativeGDI(PixmapPtr psrcPix, PixmapPtr *ppdstPix,
-                             int xrot, int yrot);
-#endif
-
-/* See Porting Layer Definition - p. 34 */
-/* See mfb/mfbpixmap.c - mfbCreatePixmap() */
-PixmapPtr
-winCreatePixmapNativeGDI(ScreenPtr pScreen,
-                         int iWidth, int iHeight,
-                         int iDepth, unsigned usage_hint)
-{
-    winPrivPixmapPtr pPixmapPriv = NULL;
-    PixmapPtr pPixmap = NULL;
-
-    /* Allocate pixmap memory */
-    pPixmap = AllocatePixmap(pScreen, 0);
-    if (!pPixmap) {
-        ErrorF("winCreatePixmapNativeGDI () - Couldn't allocate a pixmap\n");
-        return NullPixmap;
-    }
-
-#if CYGDEBUG
-    winDebug("winCreatePixmap () - w %d h %d d %d uh %d bw %d\n",
-             iWidth, iHeight, iDepth, usage_hint,
-             PixmapBytePad(iWidth, iDepth));
-#endif
-
-    /* Setup pixmap values */
-    pPixmap->drawable.type = DRAWABLE_PIXMAP;
-    pPixmap->drawable.class = 0;
-    pPixmap->drawable.pScreen = pScreen;
-    pPixmap->drawable.depth = iDepth;
-    pPixmap->drawable.bitsPerPixel = BitsPerPixel(iDepth);
-    pPixmap->drawable.id = 0;
-    pPixmap->drawable.serialNumber = NEXT_SERIAL_NUMBER;
-    pPixmap->drawable.x = 0;
-    pPixmap->drawable.y = 0;
-    pPixmap->drawable.width = iWidth;
-    pPixmap->drawable.height = iHeight;
-    pPixmap->devKind = 0;
-    pPixmap->refcnt = 1;
-    pPixmap->devPrivate.ptr = NULL;
-    pPixmap->usage_hint = usage_hint;
-
-    /* Pixmap privates are allocated by AllocatePixmap */
-    pPixmapPriv = winGetPixmapPriv(pPixmap);
-
-    /* Initialize pixmap privates */
-    pPixmapPriv->hBitmap = NULL;
-    pPixmapPriv->hdcSelected = NULL;
-    pPixmapPriv->pbBits = NULL;
-    pPixmapPriv->dwScanlineBytes = PixmapBytePad(iWidth, iDepth);
-
-    /* Check for zero width or height pixmaps */
-    if (iWidth == 0 || iHeight == 0) {
-        /* Don't allocate a real pixmap, just set fields and return */
-        return pPixmap;
-    }
-
-    /* Create a DIB for the pixmap */
-    pPixmapPriv->hBitmap = winCreateDIBNativeGDI(iWidth, iHeight, iDepth,
-                                                 &pPixmapPriv->pbBits,
-                                                 (BITMAPINFO **) &pPixmapPriv->
-                                                 pbmih);
-
-#if CYGDEBUG
-    winDebug("winCreatePixmap () - Created a pixmap %08x, %dx%dx%d, for "
-             "screen: %08x\n",
-             pPixmapPriv->hBitmap, iWidth, iHeight, iDepth, pScreen);
-#endif
-
-    return pPixmap;
-}
-
-/* 
- * See Porting Layer Definition - p. 35
- *
- * See mfb/mfbpixmap.c - mfbDestroyPixmap()
- */
-
-Bool
-winDestroyPixmapNativeGDI(PixmapPtr pPixmap)
-{
-    winPrivPixmapPtr pPixmapPriv = NULL;
-
-#if CYGDEBUG
-    winDebug("winDestroyPixmapNativeGDI ()\n");
-#endif
-
-    /* Bail early if there is not a pixmap to destroy */
-    if (pPixmap == NULL) {
-        ErrorF("winDestroyPixmapNativeGDI () - No pixmap to destroy\n");
-        return TRUE;
-    }
-
-    /* Get a handle to the pixmap privates */
-    pPixmapPriv = winGetPixmapPriv(pPixmap);
-
-#if CYGDEBUG
-    winDebug("winDestroyPixmapNativeGDI - pPixmapPriv->hBitmap: %08x\n",
-             pPixmapPriv->hBitmap);
-#endif
-
-    /* Decrement reference count, return if nonzero */
-    --pPixmap->refcnt;
-    if (pPixmap->refcnt != 0)
-        return TRUE;
-
-    /* Free GDI bitmap */
-    if (pPixmapPriv->hBitmap)
-        DeleteObject(pPixmapPriv->hBitmap);
-
-    /* Free the bitmap info header memory */
-    free(pPixmapPriv->pbmih);
-    pPixmapPriv->pbmih = NULL;
-
-    /* Free the pixmap memory */
-    free(pPixmap);
-    pPixmap = NULL;
-
-    return TRUE;
-}
-
-/* 
- * Not used yet
- */
-
-Bool
-winModifyPixmapHeaderNativeGDI(PixmapPtr pPixmap,
-                               int iWidth, int iHeight,
-                               int iDepth,
-                               int iBitsPerPixel, int devKind, void *pPixData)
-{
-    FatalError("winModifyPixmapHeaderNativeGDI ()\n");
-    return TRUE;
-}
-
-#if 0
-/* 
- * Not used yet.
- * See cfb/cfbpixmap.c
- */
-
-static void
-winXRotatePixmapNativeGDI(PixmapPtr pPix, int rw)
-{
-    ErrorF("winXRotatePixmap()\n");
-    /* fill in this function, look at CFB */
-}
-
-/*
- * Not used yet.
- * See cfb/cfbpixmap.c
- */
-static void
-winYRotatePixmapNativeGDI(PixmapPtr pPix, int rh)
-{
-    ErrorF("winYRotatePixmap()\n");
-    /* fill in this function, look at CFB */
-}
-
-/* 
- * Not used yet.
- * See cfb/cfbpixmap.c
- */
-
-static void
-winCopyRotatePixmapNativeGDI(PixmapPtr psrcPix, PixmapPtr *ppdstPix,
-                             int xrot, int yrot)
-{
-    ErrorF("winCopyRotatePixmap()\n");
-    /* fill in this function, look at CFB */
-}
-#endif
diff --git a/hw/xwin/winpolyline.c b/hw/xwin/winpolyline.c
deleted file mode 100644
index 8b7e106..0000000
--- a/hw/xwin/winpolyline.c
+++ /dev/null
@@ -1,53 +0,0 @@
-/*
- *Copyright (C) 2001-2004 Harold L Hunt II 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, FITNESS FOR A PARTICULAR PURPOSE AND
- *NONINFRINGEMENT. IN NO EVENT SHALL HAROLD L HUNT II 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 Harold L Hunt II
- *shall not be used in advertising or otherwise to promote the sale, use
- *or other dealings in this Software without prior written authorization
- *from Harold L Hunt II.
- *
- * Authors:	Harold L Hunt II
- */
-
-#ifdef HAVE_XWIN_CONFIG_H
-#include <xwin-config.h>
-#endif
-#include "win.h"
-
-/* See Porting Layer Definition - p. 50 */
-void
-winPolyLineNativeGDI(DrawablePtr pDrawable,
-                     GCPtr pGC, int mode, int npt, DDXPointPtr ppt)
-{
-    switch (pGC->lineStyle) {
-    case LineSolid:
-        if (pGC->lineWidth == 0)
-            return miZeroLine(pDrawable, pGC, mode, npt, ppt);
-        else
-            miWideLine(pDrawable, pGC, mode, npt, ppt);
-        break;
-    case LineOnOffDash:
-    case LineDoubleDash:
-        miWideDash(pDrawable, pGC, mode, npt, ppt);
-        break;
-    }
-}
diff --git a/hw/xwin/winrop.c b/hw/xwin/winrop.c
deleted file mode 100644
index 1f9ff73..0000000
--- a/hw/xwin/winrop.c
+++ /dev/null
@@ -1,142 +0,0 @@
-/*
- *Copyright (C) 1994-2002 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, FITNESS 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.
- *
- * 	Authors:	Alan Hourihane <alanh at fairlite.demon.co.uk>
- */
-
-/*
- * Raster operations used by Windows translated to X's 16 rop codes...
- */
-#ifdef HAVE_XWIN_CONFIG_H
-#include <xwin-config.h>
-#endif
-#include "win.h"
-
-void
- ROP16(HDC hdc, int rop);
-
-int g_copyROP[16] = { 0xFF0062, /* GXclear            - 0 */
-    0x8800C6,                   /* GXand              - S & D */
-    0x440328,                   /* GXandReverse       - S & !D */
-    0xCC0020,                   /* GXcopy             - S */
-    0x220326,                   /* GXandInverted      - !S & D */
-    0xAA0029,                   /* GXnoop             - D */
-    0x660046,                   /* GXxor              - S ^ D */
-    0xEE0086,                   /* GXor               - S | D */
-    0x1100A6,                   /* GXnor              - !S & !D */
-    0x990126,                   /* GXequiv            - !S ^ D */
-    0x550009,                   /* GXinvert           - !D */
-    0xDD0228,                   /* GXorReverse        - S | !D */
-    0x330008,                   /* GXcopyInverted     - !S */
-    0xBB0226,                   /* GXorInverted       - !S | D */
-    0x7700C6,                   /* GXnand             - !S | !D */
-    0x000042                    /* GXset              - 1 */
-};
-
-int g_patternROP[16] = { 0xFF0062,      /* GXclear            - 0 */
-    0xA000C9,                   /* GXand              - P & D */
-    0xF50225,                   /* GXandReverse       - P & !D */
-    0xF00021,                   /* GXcopy             - P */
-    0x5F00E9,                   /* GXandInverted      - !P & D */
-    0xAA0029,                   /* GXnoop             - D */
-    0xA50065,                   /* GXxor              - P ^ D */
-    0xA000C9,                   /* GXor               - P | D */
-    0x5F00E9,                   /* GXnor              - !P & !D */
-    0x5A0049,                   /* GXequiv            - !P ^ D */
-    0x550009,                   /* GXinvert           - !D */
-    0x500325,                   /* GXorReverse        - P | !D */
-    0x0F0001,                   /* GXcopyInverted     - !P */
-    0x0A0329,                   /* GXorInverted       - !P | D */
-    0x0500A9,                   /* GXnand             - !P | !D */
-    0x000042                    /* GXset              - 1 */
-};
-
-void
-ROP16(HDC hdc, int rop)
-{
-    switch (rop) {
-    case GXclear:
-        SetROP2(hdc, R2_BLACK);
-        break;
-
-    case GXand:
-        SetROP2(hdc, R2_MASKPEN);
-        break;
-
-    case GXandReverse:
-        SetROP2(hdc, R2_MASKPENNOT);
-        break;
-
-    case GXcopy:
-        SetROP2(hdc, R2_COPYPEN);
-        break;
-
-    case GXnoop:
-        SetROP2(hdc, R2_NOP);
-        break;
-
-    case GXxor:
-        SetROP2(hdc, R2_XORPEN);
-        break;
-
-    case GXor:
-        SetROP2(hdc, R2_MERGEPEN);
-        break;
-
-    case GXnor:
-        SetROP2(hdc, R2_NOTMERGEPEN);
-        break;
-
-    case GXequiv:
-        SetROP2(hdc, R2_NOTXORPEN);
-        break;
-
-    case GXinvert:
-        SetROP2(hdc, R2_NOT);
-        break;
-
-    case GXorReverse:
-        SetROP2(hdc, R2_MERGEPENNOT);
-        break;
-
-    case GXcopyInverted:
-        SetROP2(hdc, R2_NOTCOPYPEN);
-        break;
-
-    case GXorInverted:
-        SetROP2(hdc, R2_MERGENOTPEN);
-        break;
-
-    case GXnand:
-        SetROP2(hdc, R2_NOTMASKPEN);
-        break;
-
-    case GXset:
-        SetROP2(hdc, R2_WHITE);
-        break;
-    }
-}
diff --git a/hw/xwin/winscrinit.c b/hw/xwin/winscrinit.c
index 23152cb..ed1773c 100644
--- a/hw/xwin/winscrinit.c
+++ b/hw/xwin/winscrinit.c
@@ -570,145 +570,6 @@ winFinishScreenInitFB(int i, ScreenPtr pScreen, int argc, char **argv)
     return TRUE;
 }
 
-#ifdef XWIN_NATIVEGDI
-/* See Porting Layer Definition - p. 20 */
-
-Bool
-winFinishScreenInitNativeGDI(int i,
-                             ScreenPtr pScreen, int argc, char **argv)
-{
-    winScreenPriv(pScreen);
-    winScreenInfoPtr pScreenInfo = &g_ScreenInfo[i];
-    VisualPtr pVisuals = NULL;
-    DepthPtr pDepths = NULL;
-    VisualID rootVisual = 0;
-    int nVisuals = 0, nDepths = 0, nRootDepth = 0;
-
-    /* Ignore user input (mouse, keyboard) */
-    pScreenInfo->fIgnoreInput = FALSE;
-
-    /* Get device contexts for the screen and shadow bitmap */
-    pScreenPriv->hdcScreen = GetDC(pScreenPriv->hwndScreen);
-    if (pScreenPriv->hdcScreen == NULL)
-        FatalError("winFinishScreenInitNativeGDI - Couldn't get a DC\n");
-
-    /* Init visuals */
-    if (!(*pScreenPriv->pwinInitVisuals) (pScreen)) {
-        ErrorF("winFinishScreenInitNativeGDI - pwinInitVisuals failed\n");
-        return FALSE;
-    }
-
-    /* Initialize the mi visuals */
-    if (!miInitVisuals(&pVisuals, &pDepths, &nVisuals, &nDepths, &nRootDepth,
-                       &rootVisual,
-                       ((unsigned long) 1 << (pScreenInfo->dwDepth - 1)), 8,
-                       TrueColor)) {
-        ErrorF("winFinishScreenInitNativeGDI - miInitVisuals () failed\n");
-        return FALSE;
-    }
-
-    /* Initialize the CloseScreen procedure pointer */
-    pScreen->CloseScreen = NULL;
-
-    /* Initialize the mi code */
-    if (!miScreenInit(pScreen, NULL,    /* No framebuffer */
-                      pScreenInfo->dwWidth, pScreenInfo->dwHeight,
-                      monitorResolution, monitorResolution,
-                      pScreenInfo->dwStride,
-                      nRootDepth, nDepths, pDepths, rootVisual,
-                      nVisuals, pVisuals)) {
-        ErrorF("winFinishScreenInitNativeGDI - miScreenInit failed\n");
-        return FALSE;
-    }
-
-    pScreen->defColormap = FakeClientID(0);
-
-    /*
-     * Register our block and wakeup handlers; these procedures
-     * process messages in our Windows message queue; specifically,
-     * they process mouse and keyboard input.
-     */
-    pScreen->BlockHandler = winBlockHandler;
-    pScreen->WakeupHandler = winWakeupHandler;
-
-    /* Place our save screen function */
-    pScreen->SaveScreen = winSaveScreen;
-
-    /* Pixmaps */
-    pScreen->CreatePixmap = winCreatePixmapNativeGDI;
-    pScreen->DestroyPixmap = winDestroyPixmapNativeGDI;
-
-    /* Other Screen Routines */
-    pScreen->QueryBestSize = winQueryBestSizeNativeGDI;
-    pScreen->SaveScreen = winSaveScreen;
-    pScreen->GetImage = miGetImage;
-    pScreen->GetSpans = winGetSpansNativeGDI;
-
-    /* Window Procedures */
-    pScreen->CreateWindow = winCreateWindowNativeGDI;
-    pScreen->DestroyWindow = winDestroyWindowNativeGDI;
-    pScreen->PositionWindow = winPositionWindowNativeGDI;
-    /*pScreen->ChangeWindowAttributes = winChangeWindowAttributesNativeGDI; */
-    pScreen->RealizeWindow = winMapWindowNativeGDI;
-    pScreen->UnrealizeWindow = winUnmapWindowNativeGDI;
-
-    /* Paint window */
-    pScreen->CopyWindow = winCopyWindowNativeGDI;
-
-    /* Fonts */
-    pScreen->RealizeFont = winRealizeFontNativeGDI;
-    pScreen->UnrealizeFont = winUnrealizeFontNativeGDI;
-
-    /* GC */
-    pScreen->CreateGC = winCreateGCNativeGDI;
-
-    /* Colormap Routines */
-    pScreen->CreateColormap = miInitializeColormap;
-    pScreen->DestroyColormap =
-        (DestroyColormapProcPtr) (void (*)(void)) NoopDDA;
-    pScreen->InstallColormap = miInstallColormap;
-    pScreen->UninstallColormap = miUninstallColormap;
-    pScreen->ListInstalledColormaps = miListInstalledColormaps;
-    pScreen->StoreColors = (StoreColorsProcPtr) (void (*)(void)) NoopDDA;
-    pScreen->ResolveColor = miResolveColor;
-
-    /* Bitmap */
-    pScreen->BitmapToRegion = winPixmapToRegionNativeGDI;
-
-    ErrorF("winFinishScreenInitNativeGDI - calling miDCInitialize\n");
-
-    /* Set the default white and black pixel positions */
-    pScreen->whitePixel = pScreen->blackPixel = (Pixel) 0;
-
-    /* Initialize the cursor */
-    if (!miDCInitialize(pScreen, &g_winPointerCursorFuncs)) {
-        ErrorF("winFinishScreenInitNativeGDI - miDCInitialize failed\n");
-        return FALSE;
-    }
-
-    /* Create a default colormap */
-    if (!miCreateDefColormap(pScreen)) {
-        ErrorF("winFinishScreenInitNativeGDI - miCreateDefColormap () "
-               "failed\n");
-        return FALSE;
-    }
-
-    ErrorF("winFinishScreenInitNativeGDI - miCreateDefColormap () "
-           "returned\n");
-
-    /* mi doesn't use a CloseScreen procedure, so no need to wrap */
-    pScreen->CloseScreen = pScreenPriv->pwinCloseScreen;
-
-    /* Tell the server that we are enabled */
-    pScreenPriv->fEnabled = TRUE;
-
-    ErrorF("winFinishScreenInitNativeGDI - Successful addition of "
-           "screen %p\n", pScreen);
-
-    return TRUE;
-}
-#endif
-
 /* See Porting Layer Definition - p. 33 */
 static Bool
 winSaveScreen(ScreenPtr pScreen, int on)
diff --git a/hw/xwin/winsetsp.c b/hw/xwin/winsetsp.c
deleted file mode 100644
index 11108cb..0000000
--- a/hw/xwin/winsetsp.c
+++ /dev/null
@@ -1,175 +0,0 @@
-/*
- *Copyright (C) 1994-2000 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, FITNESS 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.
- *
- * Authors:	Harold L Hunt II
- * 		Alan Hourihane <alanh at fairlite.demon.co.uk>
- */
-
-#ifdef HAVE_XWIN_CONFIG_H
-#include <xwin-config.h>
-#endif
-#include "win.h"
-
-/* See Porting Layer Definition - p. 55 */
-void
-winSetSpansNativeGDI(DrawablePtr pDrawable,
-                     GCPtr pGC,
-                     char *pSrcs,
-                     DDXPointPtr pPoints,
-                     int *piWidths, int iSpans, int fSorted)
-{
-    winGCPriv(pGC);
-    PixmapPtr pPixmap = NULL;
-    winPrivPixmapPtr pPixmapPriv = NULL;
-    HBITMAP hbmpOrig = NULL;
-    BITMAPINFO *pbmi;
-    HRGN hrgn = NULL, combined = NULL;
-    int nbox;
-    BoxPtr pbox;
-
-    nbox = RegionNumRects(pGC->pCompositeClip);
-    pbox = RegionRects(pGC->pCompositeClip);
-
-    if (!nbox)
-        return;
-
-    pbmi = malloc(sizeof(BITMAPINFO) + sizeof(RGBQUAD));
-
-    combined = CreateRectRgn(pbox->x1, pbox->y1, pbox->x2, pbox->y2);
-    nbox--;
-    pbox++;
-    while (nbox--) {
-        hrgn = CreateRectRgn(pbox->x1, pbox->y1, pbox->x2, pbox->y2);
-        CombineRgn(combined, combined, hrgn, RGN_OR);
-        DeleteObject(hrgn);
-        hrgn = NULL;
-        pbox++;
-    }
-
-    /* Branch on the drawable type */
-    switch (pDrawable->type) {
-    case DRAWABLE_PIXMAP:
-
-        SelectClipRgn(pGCPriv->hdcMem, combined);
-        DeleteObject(combined);
-        combined = NULL;
-
-        pPixmap = (PixmapPtr) pDrawable;
-        pPixmapPriv = winGetPixmapPriv(pPixmap);
-
-        /* Select the drawable pixmap into a DC */
-        hbmpOrig = SelectObject(pGCPriv->hdcMem, pPixmapPriv->hBitmap);
-        if (hbmpOrig == NULL)
-            FatalError("winSetSpans - DRAWABLE_PIXMAP - SelectObject () "
-                       "failed on pPixmapPriv->hBitmap\n");
-
-        while (iSpans--) {
-            ZeroMemory(pbmi, sizeof(BITMAPINFO));
-            pbmi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
-            pbmi->bmiHeader.biWidth = *piWidths;
-            pbmi->bmiHeader.biHeight = 1;
-            pbmi->bmiHeader.biPlanes = 1;
-            pbmi->bmiHeader.biBitCount = pDrawable->depth;
-            pbmi->bmiHeader.biCompression = BI_RGB;
-
-            /* Setup color table for mono DIBs */
-            if (pDrawable->depth == 1) {
-                RGBQUAD *bmiColors = &(pbmi->bmiColors[0]);
-                bmiColors[1].rgbBlue = 255;
-                bmiColors[1].rgbGreen = 255;
-                bmiColors[1].rgbRed = 255;
-            }
-
-            StretchDIBits(pGCPriv->hdcMem,
-                          pPoints->x, pPoints->y,
-                          *piWidths, 1,
-                          0, 0,
-                          *piWidths, 1,
-                          pSrcs,
-                          (BITMAPINFO *) pbmi,
-                          DIB_RGB_COLORS, g_copyROP[pGC->alu]);
-
-            pSrcs += PixmapBytePad(*piWidths, pDrawable->depth);
-            pPoints++;
-            piWidths++;
-        }
-
-        /* Reset the clip region */
-        SelectClipRgn(pGCPriv->hdcMem, NULL);
-
-        /* Push the drawable pixmap out of the GC HDC */
-        SelectObject(pGCPriv->hdcMem, hbmpOrig);
-        break;
-
-    case DRAWABLE_WINDOW:
-
-        SelectClipRgn(pGCPriv->hdc, combined);
-        DeleteObject(combined);
-        combined = NULL;
-
-        while (iSpans--) {
-            ZeroMemory(pbmi, sizeof(BITMAPINFO));
-            pbmi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
-            pbmi->bmiHeader.biWidth = *piWidths;
-            pbmi->bmiHeader.biHeight = 1;
-            pbmi->bmiHeader.biPlanes = 1;
-            pbmi->bmiHeader.biBitCount = pDrawable->depth;
-            pbmi->bmiHeader.biCompression = BI_RGB;
-
-            /* Setup color table for mono DIBs */
-            if (pDrawable->depth == 1) {
-                RGBQUAD *bmiColors = &(pbmi->bmiColors[0]);
-                bmiColors[1].rgbBlue = 255;
-                bmiColors[1].rgbGreen = 255;
-                bmiColors[1].rgbRed = 255;
-            }
-
-            StretchDIBits(pGCPriv->hdc,
-                          pPoints->x, pPoints->y,
-                          *piWidths, 1,
-                          0, 0,
-                          *piWidths, 1,
-                          pSrcs,
-                          (BITMAPINFO *) pbmi,
-                          DIB_RGB_COLORS, g_copyROP[pGC->alu]);
-
-            pSrcs += PixmapBytePad(*piWidths, pDrawable->depth);
-            pPoints++;
-            piWidths++;
-        }
-
-        /* Reset the clip region */
-        SelectClipRgn(pGCPriv->hdc, NULL);
-        break;
-
-    default:
-        FatalError("\nwinSetSpansNativeGDI - Unknown drawable type\n\n");
-        break;
-    }
-
-    free(pbmi);
-}
diff --git a/hw/xwin/winwindow.c b/hw/xwin/winwindow.c
index 8c1c28f..934f6d8 100644
--- a/hw/xwin/winwindow.c
+++ b/hw/xwin/winwindow.c
@@ -49,225 +49,6 @@ static
     void
  winReshapeRootless(WindowPtr pWin);
 
-#ifdef XWIN_NATIVEGDI
-/* See Porting Layer Definition - p. 37 */
-/* See mfb/mfbwindow.c - mfbCreateWindow() */
-
-Bool
-winCreateWindowNativeGDI(WindowPtr pWin)
-{
-    Bool fResult = TRUE;
-    ScreenPtr pScreen = pWin->drawable.pScreen;
-
-    winScreenPriv(pScreen);
-
-#if CYGDEBUG
-    winTrace("winCreateWindowNativeGDI (%p)\n", pWin);
-#endif
-
-    WIN_UNWRAP(CreateWindow);
-    fResult = (*pScreen->CreateWindow) (pWin);
-    WIN_WRAP(CreateWindow, winCreateWindowNativeGDI);
-
-    return fResult;
-}
-
-/* See Porting Layer Definition - p. 37 */
-/* See mfb/mfbwindow.c - mfbDestroyWindow() */
-
-Bool
-winDestroyWindowNativeGDI(WindowPtr pWin)
-{
-    Bool fResult = TRUE;
-    ScreenPtr pScreen = pWin->drawable.pScreen;
-
-    winScreenPriv(pScreen);
-
-#if CYGDEBUG
-    winTrace("winDestroyWindowNativeGDI (%p)\n", pWin);
-#endif
-
-    WIN_UNWRAP(DestroyWindow);
-    fResult = (*pScreen->DestroyWindow) (pWin);
-    WIN_WRAP(DestroyWindow, winDestroyWindowNativeGDI);
-
-    return fResult;
-}
-
-/* See Porting Layer Definition - p. 37 */
-/* See mfb/mfbwindow.c - mfbPositionWindow() */
-
-Bool
-winPositionWindowNativeGDI(WindowPtr pWin, int x, int y)
-{
-    Bool fResult = TRUE;
-    ScreenPtr pScreen = pWin->drawable.pScreen;
-
-    winScreenPriv(pScreen);
-
-#if CYGDEBUG
-    winTrace("winPositionWindowNativeGDI (%p)\n", pWin);
-#endif
-
-    WIN_UNWRAP(PositionWindow);
-    fResult = (*pScreen->PositionWindow) (pWin, x, y);
-    WIN_WRAP(PositionWindow, winPositionWindowNativeGDI);
-
-    return fResult;
-}
-
-/* See Porting Layer Definition - p. 39 */
-/* See mfb/mfbwindow.c - mfbCopyWindow() */
-
-void
-winCopyWindowNativeGDI(WindowPtr pWin, DDXPointRec ptOldOrg, RegionPtr prgnSrc)
-{
-    DDXPointPtr pptSrc;
-    DDXPointPtr ppt;
-    RegionPtr prgnDst;
-    BoxPtr pBox;
-    int dx, dy;
-    int i, nbox;
-    BoxPtr pBoxDst;
-    ScreenPtr pScreen = pWin->drawable.pScreen;
-
-    winScreenPriv(pScreen);
-
-#if 0
-    ErrorF("winCopyWindow\n");
-#endif
-
-    /* Create a region for the destination */
-    prgnDst = RegionCreate(NULL, 1);
-
-    /* Calculate the shift from the source to the destination */
-    dx = ptOldOrg.x - pWin->drawable.x;
-    dy = ptOldOrg.y - pWin->drawable.y;
-
-    /* Translate the region from the destination to the source? */
-    RegionTranslate(prgnSrc, -dx, -dy);
-    RegionIntersect(prgnDst, &pWin->borderClip, prgnSrc);
-
-    /* Get a pointer to the first box in the region to be copied */
-    pBox = RegionRects(prgnDst);
-
-    /* Get the number of boxes in the region */
-    nbox = RegionNumRects(prgnDst);
-
-    /* Allocate source points for each box */
-    if (!(pptSrc = malloc(nbox * sizeof(DDXPointRec))))
-        return;
-
-    /* Set an iterator pointer */
-    ppt = pptSrc;
-
-    /* Calculate the source point of each box? */
-    for (i = nbox; --i >= 0; ppt++, pBox++) {
-        ppt->x = pBox->x1 + dx;
-        ppt->y = pBox->y1 + dy;
-    }
-
-    /* Setup loop pointers again */
-    pBoxDst = RegionRects(prgnDst);
-    ppt = pptSrc;
-
-#if 0
-    ErrorF("winCopyWindow - x1\tx2\ty1\ty2\tx\ty\n");
-#endif
-
-    /* BitBlt each source to the destination point */
-    for (i = nbox; --i >= 0; pBoxDst++, ppt++) {
-#if 0
-        ErrorF("winCopyWindow - %d\t%d\t%d\t%d\t%d\t%d\n",
-               pBoxDst->x1, pBoxDst->x2, pBoxDst->y1, pBoxDst->y2,
-               ppt->x, ppt->y);
-#endif
-
-        BitBlt(pScreenPriv->hdcScreen,
-               pBoxDst->x1, pBoxDst->y1,
-               pBoxDst->x2 - pBoxDst->x1, pBoxDst->y2 - pBoxDst->y1,
-               pScreenPriv->hdcScreen, ppt->x, ppt->y, SRCCOPY);
-    }
-
-    /* Cleanup the regions, etc. */
-    free(pptSrc);
-    RegionDestroy(prgnDst);
-}
-
-/* See Porting Layer Definition - p. 37 */
-/* See mfb/mfbwindow.c - mfbChangeWindowAttributes() */
-
-Bool
-winChangeWindowAttributesNativeGDI(WindowPtr pWin, unsigned long mask)
-{
-    Bool fResult = TRUE;
-    ScreenPtr pScreen = pWin->drawable.pScreen;
-
-    winScreenPriv(pScreen);
-
-#if CYGDEBUG
-    winTrace("winChangeWindowAttributesNativeGDI (%p)\n", pWin);
-#endif
-
-    WIN_UNWRAP(ChangeWindowAttributes);
-    fResult = (*pScreen->ChangeWindowAttributes) (pWin, mask);
-    WIN_WRAP(ChangeWindowAttributes, winChangeWindowAttributesNativeGDI);
-
-    /*
-     * NOTE: We do not currently need to do anything here.
-     */
-
-    return fResult;
-}
-
-/* See Porting Layer Definition - p. 37
- * Also referred to as UnrealizeWindow
- */
-
-Bool
-winUnmapWindowNativeGDI(WindowPtr pWin)
-{
-    Bool fResult = TRUE;
-    ScreenPtr pScreen = pWin->drawable.pScreen;
-
-    winScreenPriv(pScreen);
-
-#if CYGDEBUG
-    winTrace("winUnmapWindowNativeGDI (%p)\n", pWin);
-#endif
-
-    WIN_UNWRAP(UnrealizeWindow);
-    fResult = (*pScreen->UnrealizeWindow) (pWin);
-    WIN_WRAP(UnrealizeWindow, winUnmapWindowNativeGDI);
-
-    return fResult;
-}
-
-/* See Porting Layer Definition - p. 37
- * Also referred to as RealizeWindow
- */
-
-Bool
-winMapWindowNativeGDI(WindowPtr pWin)
-{
-    Bool fResult = TRUE;
-    ScreenPtr pScreen = pWin->drawable.pScreen;
-
-    winScreenPriv(pScreen);
-
-#if CYGDEBUG
-    winTrace("winMapWindowNativeGDI (%p)\n", pWin);
-#endif
-
-    WIN_UNWRAP(RealizeWindow);
-    fResult = (*pScreen->RealizeWindow) (pWin);
-    WIN_WRAP(RealizeWindow, winMapWindowMultiWindow);
-
-    return fResult;
-
-}
-#endif
-
 /* See Porting Layer Definition - p. 37 */
 /* See mfb/mfbwindow.c - mfbCreateWindow() */
 
commit e2a3e91a56cb598f2c8257614d92ccd46b7fc094
Author: Adam Jackson <ajax at redhat.com>
Date:   Fri Jul 25 11:01:22 2014 -0400

    rootless: remove redundant RootlessShapedWindowIn
    
    miShapedWindowIn is identical.  Which you would expect, since neither
    one takes an actual WindowPtr argument, so they couldn't possibly make
    reference to rootlessness.
    
    Reviewed-by: Julien Cristau <jcristau at debian.org>
    Signed-off-by: Adam Jackson <ajax at redhat.com>

diff --git a/miext/rootless/rootlessValTree.c b/miext/rootless/rootlessValTree.c
index 730d291..c7c2c99 100644
--- a/miext/rootless/rootlessValTree.c
+++ b/miext/rootless/rootlessValTree.c
@@ -106,64 +106,6 @@ Equipment Corporation.
 
 int RootlessMiValidateTree(WindowPtr pRoot, WindowPtr pChild, VTKind kind);
 
-/*
- * Compute the visibility of a shaped window
- */
-static int
-RootlessShapedWindowIn(RegionPtr universe,
-                       RegionPtr bounding, BoxPtr rect, int x, int y)
-{
-    BoxRec box;
-    register BoxPtr boundBox;
-    int nbox;
-    Bool someIn, someOut;
-    register int t, x1, y1, x2, y2;
-
-    nbox = RegionNumRects(bounding);
-    boundBox = RegionRects(bounding);
-    someIn = someOut = FALSE;
-    x1 = rect->x1;
-    y1 = rect->y1;
-    x2 = rect->x2;
-    y2 = rect->y2;
-    while (nbox--) {
-        if ((t = boundBox->x1 + x) < x1)
-            t = x1;
-        box.x1 = t;
-        if ((t = boundBox->y1 + y) < y1)
-            t = y1;
-        box.y1 = t;
-        if ((t = boundBox->x2 + x) > x2)
-            t = x2;
-        box.x2 = t;
-        if ((t = boundBox->y2 + y) > y2)
-            t = y2;
-        box.y2 = t;
-        if (box.x1 > box.x2)
-            box.x2 = box.x1;
-        if (box.y1 > box.y2)
-            box.y2 = box.y1;
-        switch (RegionContainsRect(universe, &box)) {
-        case rgnIN:
-            if (someOut)
-                return rgnPART;
-            someIn = TRUE;
-            break;
-        case rgnOUT:
-            if (someIn)
-                return rgnPART;
-            someOut = TRUE;
-            break;
-        default:
-            return rgnPART;
-        }
-        boundBox++;
-    }
-    if (someIn)
-        return rgnIN;
-    return rgnOUT;
-}
-
 #define HasParentRelativeBorder(w) (!(w)->borderIsPixel && \
 				    HasBorder(w) && \
 				    (w)->backgroundState == ParentRelative)
@@ -229,10 +171,9 @@ RootlessComputeClips(WindowPtr pParent, ScreenPtr pScreen,
             RegionPtr pBounding;
 
             if ((pBounding = wBoundingShape(pParent))) {
-                switch (RootlessShapedWindowIn(universe,
-                                               pBounding, &borderSize,
-                                               pParent->drawable.x,
-                                               pParent->drawable.y)) {
+                switch (miShapedWindowIn(universe, pBounding, &borderSize,
+                                         pParent->drawable.x,
+                                         pParent->drawable.y)) {
                 case rgnIN:
                     newVis = VisibilityUnobscured;
                     break;
commit 7e8ac6dcd24d56e384ad09c7c23259cb3f4f8dc6
Author: Adam Jackson <ajax at redhat.com>
Date:   Thu Sep 11 12:30:15 2014 -0400

    xquartz: Remove useless DRIWindowExposures
    
    Reviewed-by: Keith Packard <keithp at keithp.com>
    Signed-off-by: Adam Jackson <ajax at redhat.com>

diff --git a/hw/xquartz/xpr/dri.c b/hw/xquartz/xpr/dri.c
index 0f19047..565d94f 100644
--- a/hw/xquartz/xpr/dri.c
+++ b/hw/xquartz/xpr/dri.c
@@ -138,9 +138,6 @@ DRIFinishScreenInit(ScreenPtr pScreen)
     DRIScreenPrivPtr pDRIPriv = DRI_SCREEN_PRIV(pScreen);
 
     /* Wrap DRI support */
-    pDRIPriv->wrap.WindowExposures = pScreen->WindowExposures;
-    pScreen->WindowExposures = DRIWindowExposures;
-
     pDRIPriv->wrap.CopyWindow = pScreen->CopyWindow;
     pScreen->CopyWindow = DRICopyWindow;
 
@@ -577,24 +574,6 @@ DRIDrawablePrivDelete(void *pResource, XID id)
 }
 
 void
-DRIWindowExposures(WindowPtr pWin, RegionPtr prgn, RegionPtr bsreg)
-{
-    ScreenPtr pScreen = pWin->drawable.pScreen;
-    DRIScreenPrivPtr pDRIPriv = DRI_SCREEN_PRIV(pScreen);
-    DRIDrawablePrivPtr pDRIDrawablePriv = DRI_DRAWABLE_PRIV_FROM_WINDOW(pWin);
-
-    if (pDRIDrawablePriv) {
-        /* FIXME: something? */
-    }
-
-    pScreen->WindowExposures = pDRIPriv->wrap.WindowExposures;
-
-    (*pScreen->WindowExposures)(pWin, prgn, bsreg);
-
-    pScreen->WindowExposures = DRIWindowExposures;
-}
-
-void
 DRICopyWindow(WindowPtr pWin, DDXPointRec ptOldOrg, RegionPtr prgnSrc)
 {
     ScreenPtr pScreen = pWin->drawable.pScreen;
diff --git a/hw/xquartz/xpr/dri.h b/hw/xquartz/xpr/dri.h
index 4476b06..a4400a2 100644
--- a/hw/xquartz/xpr/dri.h
+++ b/hw/xquartz/xpr/dri.h
@@ -51,7 +51,6 @@ typedef void (*ClipNotifyPtr)(WindowPtr, int, int);
  * overridden by the driver in its [driver]DRIScreenInit function.
  */
 typedef struct {
-    WindowExposuresProcPtr WindowExposures;
     CopyWindowProcPtr CopyWindow;
     ClipNotifyProcPtr ClipNotify;
 } DRIWrappedFuncsRec, *DRIWrappedFuncsPtr;
@@ -109,9 +108,6 @@ extern void
 DRIClipNotify(WindowPtr pWin, int dx, int dy);
 
 extern void
-DRIWindowExposures(WindowPtr pWin, RegionPtr prgn, RegionPtr bsreg);
-
-extern void
 DRISurfaceNotify(xp_surface_id id, int kind);
 
 extern void
commit a8c6fc46c088bedb36c6441b78c98ca4cb9761b4
Author: Adam Jackson <ajax at redhat.com>
Date:   Thu Sep 11 10:24:27 2014 -0400

    kdrive: Remove vestigial reference to fbInitValidateTree
    
    Reviewed-by: Keith Packard <keithp at keithp.com>
    Signed-off-by: Adam Jackson <ajax at redhat.com>

diff --git a/hw/kdrive/src/kdrive.c b/hw/kdrive/src/kdrive.c
index 5dbff3f..dddbe6e 100644
--- a/hw/kdrive/src/kdrive.c
+++ b/hw/kdrive/src/kdrive.c
@@ -909,10 +909,6 @@ KdScreenInit(ScreenPtr pScreen, int argc, char **argv)
         if (!(*card->cfuncs->finishInitScreen) (pScreen))
             return FALSE;
 
-#if 0
-    fbInitValidateTree(pScreen);
-#endif
-
     /*
      * Wrap CloseScreen, the order now is:
      *  KdCloseScreen
commit 7ebf480f5eb75e06271ec924769e51bdcbbdc69c
Author: Adam Jackson <ajax at redhat.com>
Date:   Fri Feb 28 12:34:49 2014 -0500

    xfree86: Remove some can't-happen printf from xf86CreateRootWindow
    
    Reviewed-by: Keith Packard <keithp at keithp.com>
    Signed-off-by: Adam Jackson <ajax at redhat.com>

diff --git a/hw/xfree86/common/xf86Init.c b/hw/xfree86/common/xf86Init.c
index 7686294..017dcb6 100644
--- a/hw/xfree86/common/xf86Init.c
+++ b/hw/xfree86/common/xf86Init.c
@@ -308,14 +308,6 @@ xf86CreateRootWindow(WindowPtr pWin)
 
     DebugF("xf86CreateRootWindow(%p)\n", pWin);
 
-    if (pScreen->CreateWindow != xf86CreateRootWindow) {
-        /* Can't find hook we are hung on */
-        xf86DrvMsg(pScreen->myNum, X_WARNING /* X_ERROR */ ,
-                   "xf86CreateRootWindow %p called when not in pScreen->CreateWindow %p n",
-                   (void *) xf86CreateRootWindow,
-                   (void *) pScreen->CreateWindow);
-    }
-
     /* Unhook this function ... */
     pScreen->CreateWindow = create_window;
     dixSetPrivate(&pScreen->devPrivates, xf86CreateRootWindowKey, NULL);
@@ -343,15 +335,8 @@ xf86CreateRootWindow(WindowPtr pWin)
             ret &= (err == Success);
 
         }
-        else {
-            xf86Msg(X_ERROR, "xf86CreateRootWindow unexpectedly called with "
-                    "non-root window %p (parent %p)\n",
-                    (void *) pWin, (void *) pWin->parent);
-            ret = FALSE;
-        }
     }
 
-    DebugF("xf86CreateRootWindow() returns %d\n", ret);
     return ret;
 }
 
commit 3689be96ac125c9bfca9d37de4878f05f4e2f584
Author: Adam Jackson <ajax at redhat.com>
Date:   Tue Jun 10 12:54:41 2014 -0400

    vfb: Don't reimplement micmap so much
    
    We know we're atop fb which is atop micmap, the only thing we need to
    hook is InstallColormap to handle the xwd colormap change.
    
    Reviewed-by: Keith Packard <keithp at keithp.com>
    Signed-off-by: Adam Jackson <ajax at redhat.com>

diff --git a/hw/vfb/InitOutput.c b/hw/vfb/InitOutput.c
index 9c49264..bcaaa85 100644
--- a/hw/vfb/InitOutput.c
+++ b/hw/vfb/InitOutput.c
@@ -380,26 +380,10 @@ ddxProcessArgument(int argc, char *argv[], int i)
     return 0;
 }
 
-static DevPrivateKeyRec cmapScrPrivateKeyRec;
-
-#define cmapScrPrivateKey (&cmapScrPrivateKeyRec)
-
-#define GetInstalledColormap(s) ((ColormapPtr) dixLookupPrivate(&(s)->devPrivates, cmapScrPrivateKey))
-#define SetInstalledColormap(s,c) (dixSetPrivate(&(s)->devPrivates, cmapScrPrivateKey, c))
-
-static int
-vfbListInstalledColormaps(ScreenPtr pScreen, Colormap * pmaps)
-{
-    /* By the time we are processing requests, we can guarantee that there
-     * is always a colormap installed */
-    *pmaps = GetInstalledColormap(pScreen)->mid;
-    return 1;
-}
-
 static void
 vfbInstallColormap(ColormapPtr pmap)
 {
-    ColormapPtr oldpmap = GetInstalledColormap(pmap->pScreen);
+    ColormapPtr oldpmap = GetInstalledmiColormap(pmap->pScreen);
 
     if (pmap != oldpmap) {
         int entries;
@@ -410,11 +394,7 @@ vfbInstallColormap(ColormapPtr pmap)
         xColorItem *defs;
         int i;
 
-        if (oldpmap != (ColormapPtr) None)
-            WalkTree(pmap->pScreen, TellLostMap, (char *) &oldpmap->mid);
-        /* Install pmap */
-        SetInstalledColormap(pmap->pScreen, pmap);
-        WalkTree(pmap->pScreen, TellGainedMap, (char *) &pmap->mid);
+        miInstallColormap(pmap);
 
         entries = pmap->pVisual->ColormapEntries;
         pXWDHeader = vfbScreens[pmap->pScreen->myNum].pXWDHeader;
@@ -452,28 +432,12 @@ vfbInstallColormap(ColormapPtr pmap)
 }
 
 static void
-vfbUninstallColormap(ColormapPtr pmap)
-{
-    ColormapPtr curpmap = GetInstalledColormap(pmap->pScreen);
-
-    if (pmap == curpmap) {
-        if (pmap->mid != pmap->pScreen->defColormap) {
-            dixLookupResourceByType((void **) &curpmap,
-                                    pmap->pScreen->defColormap,
-                                    RT_COLORMAP, serverClient,
-                                    DixInstallAccess);
-            (*pmap->pScreen->InstallColormap) (curpmap);
-        }
-    }
-}
-
-static void
 vfbStoreColors(ColormapPtr pmap, int ndef, xColorItem * pdefs)
 {
     XWDColor *pXWDCmap;
     int i;
 
-    if (pmap != GetInstalledColormap(pmap->pScreen)) {
+    if (pmap != GetInstalledmiColormap(pmap->pScreen)) {
         return;
     }
 
@@ -761,18 +725,10 @@ static Bool
 vfbCloseScreen(ScreenPtr pScreen)
 {
     vfbScreenInfoPtr pvfb = &vfbScreens[pScreen->myNum];
-    int i;
 
     pScreen->CloseScreen = pvfb->closeScreen;
 
     /*
-     * XXX probably lots of stuff to clean.  For now,
-     * clear installed colormaps so that server reset works correctly.
-     */
-    for (i = 0; i < screenInfo.numScreens; i++)
-        SetInstalledColormap(screenInfo.screens[i], NULL);
-
-    /*
      * fb overwrites miCloseScreen, so do this here
      */
     if (pScreen->devPrivate)
@@ -790,9 +746,6 @@ vfbScreenInit(ScreenPtr pScreen, int argc, char **argv)
     int ret;
     char *pbits;
 
-    if (!dixRegisterPrivateKey(&cmapScrPrivateKeyRec, PRIVATE_SCREEN, 0))
-        return FALSE;
-
     if (dpix == 0)
         dpix = 100;
 
@@ -859,8 +812,6 @@ vfbScreenInit(ScreenPtr pScreen, int argc, char **argv)
         return FALSE;
 
     pScreen->InstallColormap = vfbInstallColormap;
-    pScreen->UninstallColormap = vfbUninstallColormap;
-    pScreen->ListInstalledColormaps = vfbListInstalledColormaps;
 
     pScreen->SaveScreen = vfbSaveScreen;
     pScreen->StoreColors = vfbStoreColors;
commit 692676debbc2227054d67078c6442f1ab1811192
Author: Adam Jackson <ajax at redhat.com>
Date:   Mon Jun 16 12:35:28 2014 -0400

    loader: Remove some baklava code
    
    Reviewed-by: Keith Packard <keithp at keithp.com>
    Signed-off-by: Adam Jackson <ajax at redhat.com>

diff --git a/hw/xfree86/loader/loadmod.c b/hw/xfree86/loader/loadmod.c
index 21ccb1b..7021bdd 100644
--- a/hw/xfree86/loader/loadmod.c
+++ b/hw/xfree86/loader/loadmod.c
@@ -77,12 +77,8 @@ typedef struct _pattern {
 static char *FindModule(const char *, const char *, const char **, PatternPtr);
 static Bool CheckVersion(const char *, XF86ModuleVersionInfo *,
                          const XF86ModReqInfo *);
-static void UnloadModuleOrDriver(ModuleDescPtr mod);
 static char *LoaderGetCanonicalName(const char *, PatternPtr);
 static void RemoveChild(ModuleDescPtr);
-static ModuleDescPtr doLoadModule(const char *, const char *, const char **,
-                                  const char **, void *,
-                                  const XF86ModReqInfo *, int *, int *);
 
 const ModuleVersions LoaderVersionInfo = {
     XORG_VERSION_CURRENT,
@@ -754,8 +750,8 @@ LoadSubModule(void *_parent, const char *module,
         return NULL;
     }
 
-    submod = doLoadModule(module, NULL, subdirlist, patternlist, options,
-                          modreq, errmaj, errmin);
+    submod = LoadModule(module, NULL, subdirlist, patternlist, options,
+                        modreq, errmaj, errmin);
     if (submod && submod != (ModuleDescPtr) 1) {
         parent->child = AddSibling(parent->child, submod);
         submod->parent = parent;
@@ -818,10 +814,47 @@ static const char *compiled_in_modules[] = {
     NULL
 };
 
-static ModuleDescPtr
-doLoadModule(const char *module, const char *path, const char **subdirlist,
-             const char **patternlist, void *options,
-             const XF86ModReqInfo * modreq, int *errmaj, int *errmin)
+/*
+ * LoadModule: load a module
+ *
+ * module       The module name.  Normally this is not a filename but the
+ *              module's "canonical name.  A full pathname is, however,
+ *              also accepted.
+ * path         A comma separated list of module directories.
+ * subdirlist   A NULL terminated list of subdirectories to search.  When
+ *              NULL, the default "stdSubdirs" list is used.  The default
+ *              list is also substituted for entries with value DEFAULT_LIST.
+ * patternlist  A NULL terminated list of regular expressions used to find
+ *              module filenames.  Each regex should contain exactly one
+ *              subexpression that corresponds to the canonical module name.
+ *              When NULL, the default "stdPatterns" list is used.  The
+ *              default list is also substituted for entries with value
+ *              DEFAULT_LIST.
+ * options      A NULL terminated list of Options that are passed to the
+ *              module's SetupProc function.
+ * modreq       An optional XF86ModReqInfo* containing
+ *              version/ABI/vendor-ABI requirements to check for when
+ *              loading the module.  The following fields of the
+ *              XF86ModReqInfo struct are checked:
+ *                majorversion - must match the module's majorversion exactly
+ *                minorversion - the module's minorversion must be >= this
+ *                patchlevel   - the module's minorversion.patchlevel must be
+ *                               >= this.  Patchlevel is ignored when
+ *                               minorversion is not set.
+ *                abiclass     - (string) must match the module's abiclass
+ *                abiversion   - must be consistent with the module's
+ *                               abiversion (major equal, minor no older)
+ *                moduleclass  - string must match the module's moduleclass
+ *                               string
+ *              "don't care" values are ~0 for numbers, and NULL for strings
+ * errmaj       Major error return.
+ * errmin       Minor error return.
+ *
+ */
+ModuleDescPtr
+LoadModule(const char *module, const char *path, const char **subdirlist,
+           const char **patternlist, void *options,
+           const XF86ModReqInfo * modreq, int *errmaj, int *errmin)
 {
     XF86ModuleData *initdata = NULL;
     char **pathlist = NULL;
@@ -1009,61 +1042,11 @@ doLoadModule(const char *module, const char *path, const char **subdirlist,
     return ret;
 }
 
-/*
- * LoadModule: load a module
- *
- * module       The module name.  Normally this is not a filename but the
- *              module's "canonical name.  A full pathname is, however,
- *              also accepted.
- * path         A comma separated list of module directories.
- * subdirlist   A NULL terminated list of subdirectories to search.  When
- *              NULL, the default "stdSubdirs" list is used.  The default
- *              list is also substituted for entries with value DEFAULT_LIST.
- * patternlist  A NULL terminated list of regular expressions used to find
- *              module filenames.  Each regex should contain exactly one
- *              subexpression that corresponds to the canonical module name.
- *              When NULL, the default "stdPatterns" list is used.  The
- *              default list is also substituted for entries with value
- *              DEFAULT_LIST.
- * options      A NULL terminated list of Options that are passed to the
- *              module's SetupProc function.
- * modreq       An optional XF86ModReqInfo* containing
- *              version/ABI/vendor-ABI requirements to check for when
- *              loading the module.  The following fields of the
- *              XF86ModReqInfo struct are checked:
- *                majorversion - must match the module's majorversion exactly
- *                minorversion - the module's minorversion must be >= this
- *                patchlevel   - the module's minorversion.patchlevel must be
- *                               >= this.  Patchlevel is ignored when
- *                               minorversion is not set.
- *                abiclass     - (string) must match the module's abiclass
- *                abiversion   - must be consistent with the module's
- *                               abiversion (major equal, minor no older)
- *                moduleclass  - string must match the module's moduleclass
- *                               string
- *              "don't care" values are ~0 for numbers, and NULL for strings
- * errmaj       Major error return.
- * errmin       Minor error return.
- *
- */
-ModuleDescPtr
-LoadModule(const char *module, const char *path, const char **subdirlist,
-           const char **patternlist, void *options,
-           const XF86ModReqInfo * modreq, int *errmaj, int *errmin)
-{
-    return doLoadModule(module, path, subdirlist, patternlist, options,
-                        modreq, errmaj, errmin);
-}
-
 void
-UnloadModule(void *mod)
+UnloadModule(void *_mod)
 {
-    UnloadModuleOrDriver((ModuleDescPtr) mod);
-}
+    ModuleDescPtr mod = _mod;
 
-static void
-UnloadModuleOrDriver(ModuleDescPtr mod)
-{
     if (mod == (ModuleDescPtr) 1)
         return;
 
@@ -1083,9 +1066,9 @@ UnloadModuleOrDriver(ModuleDescPtr mod)
     }
 
     if (mod->child)
-        UnloadModuleOrDriver(mod->child);
+        UnloadModule(mod->child);
     if (mod->sib)
-        UnloadModuleOrDriver(mod->sib);
+        UnloadModule(mod->sib);
     free(mod->path);
     free(mod->name);
     free(mod);
@@ -1100,7 +1083,7 @@ UnloadSubModule(void *_mod)
     if (mod == (ModuleDescPtr) 1)
         return;
     RemoveChild(mod);
-    UnloadModuleOrDriver(mod);
+    UnloadModule(mod);
 }
 
 static void
commit c695a1430b80bac0b95e4d7f559e1bd223ecb1ef
Author: Adam Jackson <ajax at redhat.com>
Date:   Tue Jul 8 14:38:34 2014 -0400

    input: Remove unused SetKeySymsMap
    
    Reviewed-by: Daniel Stone <daniels at collabora.com>
    Signed-off-by: Adam Jackson <ajax at redhat.com>

diff --git a/dix/devices.c b/dix/devices.c
index f17a3ac..3fb7ca0 100644
--- a/dix/devices.c
+++ b/dix/devices.c
@@ -1214,63 +1214,6 @@ QueryMinMaxKeyCodes(KeyCode *minCode, KeyCode *maxCode)
     }
 }
 
-/* Notably, this function does not expand the destination's keycode range, or
- * notify clients. */
-Bool
-SetKeySymsMap(KeySymsPtr dst, KeySymsPtr src)
-{
-    int i, j;
-    KeySym *tmp;
-    int rowDif = src->minKeyCode - dst->minKeyCode;
-
-    /* if keysym map size changes, grow map first */
-    if (src->mapWidth < dst->mapWidth) {
-        for (i = src->minKeyCode; i <= src->maxKeyCode; i++) {
-#define SI(r, c) (((r - src->minKeyCode) * src->mapWidth) + (c))
-#define DI(r, c) (((r - dst->minKeyCode) * dst->mapWidth) + (c))
-            for (j = 0; j < src->mapWidth; j++)
-                dst->map[DI(i, j)] = src->map[SI(i, j)];
-            for (j = src->mapWidth; j < dst->mapWidth; j++)
-                dst->map[DI(i, j)] = NoSymbol;
-#undef SI
-#undef DI
-        }
-        return TRUE;
-    }
-    else if (src->mapWidth > dst->mapWidth) {
-        i = sizeof(KeySym) * src->mapWidth *
-            (dst->maxKeyCode - dst->minKeyCode + 1);
-        tmp = calloc(sizeof(KeySym), i);
-        if (!tmp)
-            return FALSE;
-
-        if (dst->map) {
-            for (i = 0; i <= dst->maxKeyCode - dst->minKeyCode; i++)
-                memmove(&tmp[i * src->mapWidth], &dst->map[i * dst->mapWidth],
-                        dst->mapWidth * sizeof(KeySym));
-            free(dst->map);
-        }
-        dst->mapWidth = src->mapWidth;
-        dst->map = tmp;
-    }
-    else if (!dst->map) {
-        i = sizeof(KeySym) * src->mapWidth *
-            (dst->maxKeyCode - dst->minKeyCode + 1);
-        tmp = calloc(sizeof(KeySym), i);
-        if (!tmp)
-            return FALSE;
-
-        dst->map = tmp;
-        dst->mapWidth = src->mapWidth;
-    }
-
-    memmove(&dst->map[rowDif * dst->mapWidth], src->map,
-            (src->maxKeyCode - src->minKeyCode + 1) *
-            dst->mapWidth * sizeof(KeySym));
-
-    return TRUE;
-}
-
 Bool
 InitButtonClassDeviceStruct(DeviceIntPtr dev, int numButtons, Atom *labels,
                             CARD8 *map)
diff --git a/include/input.h b/include/input.h
index 1b2102f..35ceafa 100644
--- a/include/input.h
+++ b/include/input.h
@@ -287,9 +287,6 @@ extern _X_EXPORT int dixLookupDevice(DeviceIntPtr * /* dev */ ,
 extern _X_EXPORT void QueryMinMaxKeyCodes(KeyCode * /*minCode */ ,
                                           KeyCode * /*maxCode */ );
 
-extern _X_EXPORT Bool SetKeySymsMap(KeySymsPtr /*dst */ ,
-                                    KeySymsPtr /*src */ );
-
 extern _X_EXPORT Bool InitButtonClassDeviceStruct(DeviceIntPtr /*device */ ,
                                                   int /*numButtons */ ,
                                                   Atom * /* labels */ ,
commit 645063cd9384a26353775e92a79ed8710c6ca66c
Author: Adam Jackson <ajax at redhat.com>
Date:   Tue Mar 4 12:51:49 2014 -0500

    exa, kdrive: Remove redundant BitsPerPixel macros
    
    We already get this from servermd.h
    
    Reviewed-by: Keith Packard <keithp at keithp.com>
    Signed-off-by: Adam Jackson <ajax at redhat.com>

diff --git a/exa/exa_priv.h b/exa/exa_priv.h
index 61a1f4c..88bfd37 100644
--- a/exa/exa_priv.h
+++ b/exa/exa_priv.h
@@ -214,18 +214,6 @@ typedef struct {
     DevPrivateKeyRec gcPrivateKeyRec;
 } ExaScreenPrivRec, *ExaScreenPrivPtr;
 
-/*
- * This is the only completely portable way to
- * compute this info.
- */
-#ifndef BitsPerPixel
-#define BitsPerPixel(d) (\
-    PixmapWidthPaddingInfo[d].notPower2 ? \
-    (PixmapWidthPaddingInfo[d].bytesPerPixel * 8) : \
-    ((1 << PixmapWidthPaddingInfo[d].padBytesLog2) * 8 / \
-    (PixmapWidthPaddingInfo[d].padRoundUp+1)))
-#endif
-
 extern DevPrivateKeyRec exaScreenPrivateKeyRec;
 
 #define exaScreenPrivateKey (&exaScreenPrivateKeyRec)
diff --git a/hw/kdrive/src/kdrive.h b/hw/kdrive/src/kdrive.h
index 066a134..e1d2b59 100644
--- a/hw/kdrive/src/kdrive.h
+++ b/hw/kdrive/src/kdrive.h
@@ -330,19 +330,6 @@ typedef struct _KdPointerMatrix {
     int matrix[2][3];
 } KdPointerMatrix;
 
-/*
- * This is the only completely portable way to
- * compute this info.
- */
-
-#ifndef BitsPerPixel
-#define BitsPerPixel(d) (\
-    PixmapWidthPaddingInfo[d].notPower2 ? \
-    (PixmapWidthPaddingInfo[d].bytesPerPixel * 8) : \
-    ((1 << PixmapWidthPaddingInfo[d].padBytesLog2) * 8 / \
-    (PixmapWidthPaddingInfo[d].padRoundUp+1)))
-#endif
-
 extern DevPrivateKeyRec kdScreenPrivateKeyRec;
 
 #define kdScreenPrivateKey (&kdScreenPrivateKeyRec)
commit cccba52d152a7d233c0b762a54844ecef831483e
Author: Alan Coopersmith <alan.coopersmith at oracle.com>
Date:   Sun Sep 21 09:49:05 2014 -0700

    Abort xi2 tests if ActivateDevice() fails
    
    I was getting segfaults in xi2 tests from trying to copy XKB keyboard
    state to NULL pointers with a stack of:
        key=key at entry=0) at xkbActions.c:1189
        sendevent=sendevent at entry=0 '\000') at devices.c:420
        at protocol-xiquerydevice.c:338
    
    which turned out to be due to xkbcomp failure, which was logged in the
    test logs as:
    XKB: Failed to compile keymap
    Keyboard initialization failed. This could be a missing or incorrect setup of xkeyboard-config.
    
    but which was overlooked because the ActivateDevice() return code wasn't
    checked and the tests went forward assuming the structures were all
    correctly initialized.   This catches the failure closer to the point of
    failure, to save debugging time.
    
    Signed-off-by: Alan Coopersmith <alan.coopersmith at oracle.com>
    Reviewed-by: Peter Hutterer <peter.hutterer at who-t.net>
    Signed-off-by: Keith Packard <keithp at keithp.com>

diff --git a/test/xi2/protocol-common.c b/test/xi2/protocol-common.c
index 9a429e4..64a5777 100644
--- a/test/xi2/protocol-common.c
+++ b/test/xi2/protocol-common.c
@@ -137,6 +137,7 @@ init_devices(void)
 {
     ClientRec client;
     struct devices local_devices;
+    int ret;
 
     client = init_client(0, NULL);
 
@@ -145,15 +146,20 @@ init_devices(void)
     inputInfo.pointer = local_devices.vcp;
 
     inputInfo.keyboard = local_devices.vck;
-    ActivateDevice(local_devices.vcp, FALSE);
-    ActivateDevice(local_devices.vck, FALSE);
+    ret = ActivateDevice(local_devices.vcp, FALSE);
+    assert(ret == Success);
+    /* This may fail if xkbcomp fails or xkb-config is not found. */
+    ret = ActivateDevice(local_devices.vck, FALSE);
+    assert(ret == Success);
     EnableDevice(local_devices.vcp, FALSE);
     EnableDevice(local_devices.vck, FALSE);
 
     AllocDevicePair(&client, "", &local_devices.mouse, &local_devices.kbd,
                     TestPointerProc, CoreKeyboardProc, FALSE);
-    ActivateDevice(local_devices.mouse, FALSE);
-    ActivateDevice(local_devices.kbd, FALSE);
+    ret = ActivateDevice(local_devices.mouse, FALSE);
+    assert(ret == Success);
+    ret = ActivateDevice(local_devices.kbd, FALSE);
+    assert(ret == Success);
     EnableDevice(local_devices.mouse, FALSE);
     EnableDevice(local_devices.kbd, FALSE);
 
commit 95a5b92e37f73f497d547fd91c543c16d2cc73de
Author: Keith Packard <keithp at keithp.com>
Date:   Thu Oct 2 10:26:53 2014 -0700

    xfree86: Remove remaining return FALSE from configServerFlags
    
    Remove the error return path from the FLAG_PIXMAP path and leave the
    default value in place. There's no point skipping the rest of this
    function.
    
    Signed-off-by: Keith Packard <keithp at keithp.com>

diff --git a/hw/xfree86/common/xf86Config.c b/hw/xfree86/common/xf86Config.c
index bca5b45..5b254ba 100644
--- a/hw/xfree86/common/xf86Config.c
+++ b/hw/xfree86/common/xf86Config.c
@@ -1011,7 +1011,7 @@ configServerFlags(XF86ConfFlagsPtr flagsconf, XF86OptionPtr layoutopts)
         break;
     default:
         ErrorF("Pixmap option's value (%d) must be 24 or 32\n", i);
-        return FALSE;
+        break;
     }
     if (xf86Pix24 != Pix24DontCare) {
         xf86Info.pixmap24 = xf86Pix24;
commit e9651e3dbc32650fcaf90888b4cbef81da77cfcd
Merge: 9bc01df 4433bc6
Author: Keith Packard <keithp at keithp.com>
Date:   Thu Oct 2 10:24:33 2014 -0700

    Merge remote-tracking branch 'ajax/dead-code'

commit 9bc01dfc7070a40f5948588895b3a11dd1636d0e
Author: Axel Davy <axel.davy at ens.fr>
Date:   Sat Sep 27 23:17:13 2014 +0200

    Fix present_pixmap when using present_notify_msc
    
    Calling present_notify_msc could cancel a pending pixmap presentation.
    
    Signed-off-by: Axel Davy <axel.davy at ens.fr>
    Reviewed-by: Keith Packard <keithp at keithp.com>
    Signed-off-by: Keith Packard <keithp at keithp.com>

diff --git a/present/present.c b/present/present.c
index e838da7..47566c7 100644
--- a/present/present.c
+++ b/present/present.c
@@ -767,7 +767,7 @@ present_pixmap(WindowPtr window,
      * in the same frame
      */
 
-    if (!update) {
+    if (!update && pixmap) {
         xorg_list_for_each_entry_safe(vblank, tmp, &window_priv->vblank, window_list) {
 
             if (!vblank->pixmap)
commit b3e9791fd375eb71b6150a77b8009b046b213004
Author: Daniel Martin <consume.noise at gmail.com>
Date:   Sat Sep 20 09:07:41 2014 +0200

    xfree86: Delete file modinit.h
    
    All references to modinit.h have been remove with:
    
        a1d41e3 Move extension initialisation prototypes into extinit.h
    
    Signed-off-by: Daniel Martin <consume.noise at gmail.com>
    Reviewed-by: Eric Anholt <eric at anholt.net>
    Signed-off-by: Keith Packard <keithp at keithp.com>

diff --git a/hw/xfree86/dixmods/extmod/modinit.h b/hw/xfree86/dixmods/extmod/modinit.h
deleted file mode 100644
index 4c9b6e3..0000000
--- a/hw/xfree86/dixmods/extmod/modinit.h
+++ /dev/null
@@ -1,80 +0,0 @@
-
-#ifdef HAVE_DIX_CONFIG_H
-#include <dix-config.h>
-#endif
-
-#include <X11/extensions/shapeproto.h>
-
-#ifdef XTEST
-extern void XTestExtensionInit(void);
-#include <X11/extensions/xtestproto.h>
-#endif
-
-#if 1
-extern void XTestExtension1Init(void);
-#endif
-
-#if 1
-extern void XCMiscExtensionInit(void);
-#endif
-
-#ifdef SCREENSAVER
-extern void ScreenSaverExtensionInit(void);
-#include <X11/extensions/saver.h>
-#endif
-
-#ifdef XF86VIDMODE
-extern void XFree86VidModeExtensionInit(void);
-#include <X11/extensions/xf86vmproto.h>
-#endif
-
-#ifdef XFreeXDGA
-extern void XFree86DGAExtensionInit(void);
-extern void XFree86DGARegister(void);
-#include <X11/extensions/xf86dgaproto.h>
-#endif
-
-#ifdef DPMSExtension
-extern void DPMSExtensionInit(void);
-#include <X11/extensions/dpmsconst.h>
-#endif
-
-#ifdef XV
-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(void);
-#include <X11/extensions/XResproto.h>
-#endif
-
-#ifdef SHM
-#include <X11/extensions/shmproto.h>
-extern void ShmExtensionInit(void);
-extern void ShmRegisterFuncs(ScreenPtr pScreen, ShmFuncsPtr funcs);
-#endif
-
-#ifdef XSELINUX
-extern void SELinuxExtensionInit(void);
-#include "xselinux.h"
-#endif
-
-#ifdef XEVIE
-extern void XevieExtensionInit(void);
-#endif
-
-#if 1
-extern void SecurityExtensionInit(void);
-#endif
-
-#if 1
-extern void PanoramiXExtensionInit(void);
-#endif
-
-#if 1
-extern void XkbExtensionInit(void);
-#endif
commit 2aeb9d8f8b22ceb1de883c231a0a75d4c75d3f4a
Author: Daniel Martin <consume.noise at gmail.com>
Date:   Sat Sep 20 09:07:40 2014 +0200

    security: Remove XpExtension from SecurityTrustedExtensions
    
    There's no XPrint extension (anymore).
    
    Signed-off-by: Daniel Martin <consume.noise at gmail.com>
    Reviewed-by: Keith Packard <keithp at keithp.com>
    Signed-off-by: Keith Packard <keithp at keithp.com>

diff --git a/Xext/security.c b/Xext/security.c
index 421b252..bf2ab2e 100644
--- a/Xext/security.c
+++ b/Xext/security.c
@@ -67,7 +67,6 @@ typedef struct {
 static const char *SecurityTrustedExtensions[] = {
     "XC-MISC",
     "BIG-REQUESTS",
-    "XpExtension",
     NULL
 };
 
commit 12c19bbff4b7b2d0b350a7b93b38ebbf69748534
Author: Daniel Martin <consume.noise at gmail.com>
Date:   Sat Sep 20 09:07:39 2014 +0200

    dix: Remove XpExtension leftovers from protocol.txt
    
    There's no XPrint extension (anymore).
    
    Signed-off-by: Daniel Martin <consume.noise at gmail.com>
    Reviewed-by: Keith Packard <keithp at keithp.com>
    Signed-off-by: Keith Packard <keithp at keithp.com>

diff --git a/dix/protocol.txt b/dix/protocol.txt
index f83f38c..c223795 100644
--- a/dix/protocol.txt
+++ b/dix/protocol.txt
@@ -1082,33 +1082,3 @@ R009 XVideo-MotionCompensation:GetDRInfo
 E000 XVideo-MotionCompensation:BadContext
 E001 XVideo-MotionCompensation:BadSurface
 E002 XVideo-MotionCompensation:BadSubpicture
-R000 XpExtension:QueryVersion
-R001 XpExtension:GetPrinterList
-R002 XpExtension:CreateContext
-R003 XpExtension:SetContext
-R004 XpExtension:GetContext
-R005 XpExtension:DestroyContext
-R006 XpExtension:GetContextScreen
-R007 XpExtension:StartJob
-R008 XpExtension:EndJob
-R009 XpExtension:StartDoc
-R010 XpExtension:EndDoc
-R011 XpExtension:PutDocumentData
-R012 XpExtension:GetDocumentData
-R013 XpExtension:StartPage
-R014 XpExtension:EndPage
-R015 XpExtension:SelectInput
-R016 XpExtension:InputSelected
-R017 XpExtension:GetAttributes
-R018 XpExtension:SetAttributes
-R019 XpExtension:GetOneAttribute
-R020 XpExtension:RehashPrinterList
-R021 XpExtension:GetPageDimensions
-R022 XpExtension:QueryScreens
-R023 XpExtension:SetImageResolution
-R024 XpExtension:GetImageResolution
-V000 XpExtension:PrintNotify
-V001 XpExtension:AttributeNotify
-E000 XpExtension:BadContext
-E001 XpExtension:BadSequence
-E002 XpExtension:BadResourceID
commit d3d845ca9e92f0a2ccde93f4242d7769cfe14164
Author: Michel Dänzer <michel.daenzer at amd.com>
Date:   Thu Sep 25 15:27:22 2014 +0900

    glamor: Use GL_STREAM_READ also for read/write access to a PBO
    
    Otherwise the CPU may end up reading from non-cacheable memory, which is
    very slow.
    
    Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=84178
    Signed-off-by: Michel Dänzer <michel.daenzer at amd.com>
    Reviewed-by: Markus Wick <markus at selfnet.de>
    Reviewed-by: Eric Anholt <eric at anholt.net>
    Signed-off-by: Keith Packard <keithp at keithp.com>

diff --git a/glamor/glamor_prepare.c b/glamor/glamor_prepare.c
index 561c55d..fb85d90 100644
--- a/glamor/glamor_prepare.c
+++ b/glamor/glamor_prepare.c
@@ -84,10 +84,7 @@ glamor_prep_pixmap_box(PixmapPtr pixmap, glamor_access_t access, BoxPtr box)
             if (priv->base.pbo == 0)
                 glGenBuffers(1, &priv->base.pbo);
 
-            if (access == GLAMOR_ACCESS_RW)
-                gl_usage = GL_DYNAMIC_DRAW;
-            else
-                gl_usage = GL_STREAM_READ;
+            gl_usage = GL_STREAM_READ;
 
             glBindBuffer(GL_PIXEL_PACK_BUFFER, priv->base.pbo);
             glBufferData(GL_PIXEL_PACK_BUFFER,
commit 78c27d12e1f4857bfcfc92afbb69d5dd989232b9
Merge: 6e50bfa 1d6334d
Author: Keith Packard <keithp at keithp.com>
Date:   Mon Sep 29 13:04:49 2014 -0700

    Merge remote-tracking branch 'jturney/xwin-clipboard-refactoring'

commit 6e50bfa706cd3ab884c933bf1f17c221a6208aa4
Author: Michel Dänzer <michel.daenzer at amd.com>
Date:   Wed Sep 24 16:48:10 2014 +0900

    glamor: Fix leak of converted_bits in _glamor_upload_bits_to_pixmap_texture
    
    ==9530== 808,575,600 bytes in 5,904 blocks are definitely lost in loss record 4,602 of 4,602
    ==9530==    at 0x4C28C20: malloc (vg_replace_malloc.c:296)
    ==9530==    by 0xAD29C98: _glamor_upload_bits_to_pixmap_texture (glamor_pixmap.c:771)
    ==9530==    by 0xAD2AE95: glamor_upload_sub_pixmap_to_texture (glamor_pixmap.c:1031)
    ==9530==    by 0xAD2BD55: glamor_upload_pixmap_to_texture (glamor_pixmap.c:1057)
    ==9530==    by 0xAD1C2E6: glamor_composite_choose_shader (glamor_render.c:1025)
    ==9530==    by 0xAD1C629: glamor_composite_with_shader (glamor_render.c:1174)
    ==9530==    by 0xAD1DA77: glamor_composite_clipped_region (glamor_render.c:1542)
    ==9530==    by 0xAD1E849: _glamor_composite (glamor_render.c:1689)
    ==9530==    by 0xAD1ED90: glamor_composite (glamor_render.c:1758)
    ==9530==    by 0x519FD6: damageComposite (damage.c:502)
    ==9530==    by 0xAD27AA3: glamor_trapezoids (glamor_trapezoid.c:147)
    ==9530==    by 0xAD27B51: glamor_trapezoids (glamor_trapezoid.c:101)
    
    Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=84176
    Signed-off-by: Michel Dänzer <michel.daenzer at amd.com>
    Reviewed-by: Eric Anholt <eric at anholt.net>
    Signed-off-by: Keith Packard <keithp at keithp.com>

diff --git a/glamor/glamor_pixmap.c b/glamor/glamor_pixmap.c
index 11e9ebb..355fe4b 100644
--- a/glamor/glamor_pixmap.c
+++ b/glamor/glamor_pixmap.c
@@ -774,6 +774,7 @@ _glamor_upload_bits_to_pixmap_texture(PixmapPtr pixmap, GLenum format,
             return FALSE;
         bits = glamor_color_convert_to_bits(bits, converted_bits, w, h,
                                             stride, no_alpha, revert, swap_rb);
+        free(converted_bits);
         if (bits == NULL) {
             ErrorF("Failed to convert pixmap no_alpha %d,"
                    "revert mode %d, swap mode %d\n", no_alpha, revert, swap_rb);
commit 4433bc6d53e651b3dc4112099a153c2574f30797
Author: Adam Jackson <ajax at redhat.com>
Date:   Thu May 1 12:48:15 2014 -0400

    x86emu: Undefine _NO_INLINE
    
    Never defined by the server.
    
    Reviewed-by: Eric Anholt <eric at anholt.net>
    Signed-off-by: Adam Jackson <ajax at redhat.com>

diff --git a/hw/xfree86/x86emu/x86emu/x86emui.h b/hw/xfree86/x86emu/x86emu/x86emui.h
index 5e20d97..01bd92a 100644
--- a/hw/xfree86/x86emu/x86emu/x86emui.h
+++ b/hw/xfree86/x86emu/x86emu/x86emui.h
@@ -46,7 +46,7 @@
  * dramatically in this case).
  */
 
-#if	defined(__cplusplus) && !defined(_NO_INLINE)
+#if defined(__cplusplus)
 #define	_INLINE	inline
 #else
 #define	_INLINE static
commit 1c3cb68d0cd15d29fd3aaa9eedbfa772ec8e3a47
Author: Adam Jackson <ajax at redhat.com>
Date:   Tue Jul 29 14:15:24 2014 -0400

    xfree86: Remove pointless xf86PrintMarkers
    
    Reviewed-by: Eric Anholt <eric at anholt.net>
    Signed-off-by: Adam Jackson <ajax at redhat.com>

diff --git a/hw/xfree86/common/xf86Init.c b/hw/xfree86/common/xf86Init.c
index b197c1c..7686294 100644
--- a/hw/xfree86/common/xf86Init.c
+++ b/hw/xfree86/common/xf86Init.c
@@ -233,12 +233,6 @@ xf86PrintBanner(void)
                    "\tto make sure that you have the latest version.\n");
 }
 
-static void
-xf86PrintMarkers(void)
-{
-    LogPrintMarkers();
-}
-
 Bool
 xf86PrivsElevated(void)
 {
@@ -421,7 +415,7 @@ InitOutput(ScreenInfo * pScreenInfo, int argc, char **argv)
             xf86ServerName = argv[0];
 
         xf86PrintBanner();
-        xf86PrintMarkers();
+        LogPrintMarkers();
         if (xf86LogFile) {
             time_t t;
             const char *ct;
commit 30fa6da6f140d713041942a81f5d6da6736e4f7f
Author: Adam Jackson <ajax at redhat.com>
Date:   Tue Jul 29 14:07:39 2014 -0400

    xfree86: configServerFlags never fails, make it return void
    
    Reviewed-by: Eric Anholt <eric at anholt.net>
    Signed-off-by: Adam Jackson <ajax at redhat.com>

diff --git a/hw/xfree86/common/xf86Config.c b/hw/xfree86/common/xf86Config.c
index 3eb7a0f..bca5b45 100644
--- a/hw/xfree86/common/xf86Config.c
+++ b/hw/xfree86/common/xf86Config.c
@@ -760,7 +760,7 @@ static OptionInfoRec FlagOptions[] = {
      {0}, FALSE},
 };
 
-static Bool
+static void
 configServerFlags(XF86ConfFlagsPtr flagsconf, XF86OptionPtr layoutopts)
 {
     XF86OptionPtr optp, tmp;
@@ -1046,8 +1046,6 @@ configServerFlags(XF86ConfFlagsPtr flagsconf, XF86OptionPtr layoutopts)
         xf86Info.dri2From = X_CONFIG;
     }
 #endif
-
-    return TRUE;
 }
 
 Bool
@@ -2474,11 +2472,7 @@ xf86HandleConfigFile(Bool autoconfig)
     }
 #endif
     /* Now process everything else */
-    if (!configServerFlags(xf86configptr->conf_flags, xf86ConfigLayout.options)) {
-        ErrorF("Problem when converting the config data structures\n");
-        return CONFIG_PARSE_ERROR;
-    }
-
+    configServerFlags(xf86configptr->conf_flags, xf86ConfigLayout.options);
     configFiles(xf86configptr->conf_files);
     configExtensions(xf86configptr->conf_extensions);
 #ifdef XF86DRI
commit 2bf9db1930528255a37f9787aeb82e2851f814c2
Author: Adam Jackson <ajax at redhat.com>
Date:   Tue Jul 29 14:02:01 2014 -0400

    xfree86: Remove unused xf86Info.useDefaultFontPathFrom
    
    Reviewed-by: Eric Anholt <eric at anholt.net>
    Signed-off-by: Adam Jackson <ajax at redhat.com>

diff --git a/hw/xfree86/common/xf86Config.c b/hw/xfree86/common/xf86Config.c
index 8f16be3..3eb7a0f 100644
--- a/hw/xfree86/common/xf86Config.c
+++ b/hw/xfree86/common/xf86Config.c
@@ -959,10 +959,8 @@ configServerFlags(XF86ConfFlagsPtr flagsconf, XF86OptionPtr layoutopts)
     XkbFreeRMLVOSet(&set, FALSE);
 
     xf86Info.useDefaultFontPath = TRUE;
-    xf86Info.useDefaultFontPathFrom = X_DEFAULT;
     if (xf86GetOptValBool(FlagOptions, FLAG_USE_DEFAULT_FONT_PATH, &value)) {
         xf86Info.useDefaultFontPath = value;
-        xf86Info.useDefaultFontPathFrom = X_CONFIG;
     }
 
 /* Make sure that timers don't overflow CARD32's after multiplying */
diff --git a/hw/xfree86/common/xf86Privstr.h b/hw/xfree86/common/xf86Privstr.h
index 7bb8889..cffa14d 100644
--- a/hw/xfree86/common/xf86Privstr.h
+++ b/hw/xfree86/common/xf86Privstr.h
@@ -93,7 +93,6 @@ typedef struct {
     MessageType glxVisualsFrom;
 
     Bool useDefaultFontPath;
-    MessageType useDefaultFontPathFrom;
     Bool ignoreABI;
 
     Bool forceInputDevices;     /* force xorg.conf or built-in input devices */
commit fffea07b4cb0992fed2cca33be08440ea94090d9
Author: Adam Jackson <ajax at redhat.com>
Date:   Tue Jul 29 13:48:10 2014 -0400

    xfree86: Remove xf86Info.log (v2)
    
    SUBCLASS ALL THE THINGS
    
    v2: Remove the enum too (anholt)
    
    Reviewed-by: Eric Anholt <eric at anholt.net>
    Signed-off-by: Adam Jackson <ajax at redhat.com>

diff --git a/hw/xfree86/common/xf86Config.c b/hw/xfree86/common/xf86Config.c
index 546055d..8f16be3 100644
--- a/hw/xfree86/common/xf86Config.c
+++ b/hw/xfree86/common/xf86Config.c
@@ -874,12 +874,10 @@ configServerFlags(XF86ConfFlagsPtr flagsconf, XF86OptionPtr layoutopts)
         if ((s = xf86GetOptValString(FlagOptions, FLAG_LOG))) {
             if (!xf86NameCmp(s, "flush")) {
                 xf86Msg(X_CONFIG, "Flushing logfile enabled\n");
-                xf86Info.log = LogFlush;
                 LogSetParameter(XLOG_FLUSH, TRUE);
             }
             else if (!xf86NameCmp(s, "sync")) {
                 xf86Msg(X_CONFIG, "Syncing logfile enabled\n");
-                xf86Info.log = LogSync;
                 LogSetParameter(XLOG_FLUSH, TRUE);
                 LogSetParameter(XLOG_SYNC, TRUE);
             }
diff --git a/hw/xfree86/common/xf86Globals.c b/hw/xfree86/common/xf86Globals.c
index 984c39b..93a35b8 100644
--- a/hw/xfree86/common/xf86Globals.c
+++ b/hw/xfree86/common/xf86Globals.c
@@ -120,7 +120,6 @@ xf86InfoRec xf86Info = {
     .pixmap24 = Pix24DontCare,
     .pix24From = X_DEFAULT,
     .pmFlag = TRUE,
-    .log = LogNone,
     .disableRandR = FALSE,
     .randRFrom = X_DEFAULT,
 #if defined(CONFIG_HAL) || defined(CONFIG_UDEV) || defined(CONFIG_WSCONS)
diff --git a/hw/xfree86/common/xf86Privstr.h b/hw/xfree86/common/xf86Privstr.h
index 410ef17..7bb8889 100644
--- a/hw/xfree86/common/xf86Privstr.h
+++ b/hw/xfree86/common/xf86Privstr.h
@@ -37,12 +37,6 @@
 #include "xf86str.h"
 
 typedef enum {
-    LogNone,
-    LogFlush,
-    LogSync
-} Log;
-
-typedef enum {
     XF86_GlxVisualsMinimal,
     XF86_GlxVisualsTypical,
     XF86_GlxVisualsAll,
@@ -91,7 +85,6 @@ typedef struct {
     Pix24Flags pixmap24;
     MessageType pix24From;
     Bool pmFlag;
-    Log log;
     Bool disableRandR;
     MessageType randRFrom;
     Bool aiglx;
commit 2f5cfbee5409b088156d4cd84a3376499e291631
Author: Adam Jackson <ajax at redhat.com>
Date:   Tue Jul 8 14:50:22 2014 -0400

    xfree86: Remove DisplayID support
    
    Not actually wired up so it's fairly useless.
    
    Reviewed-by: Eric Anholt <eric at anholt.net>
    Signed-off-by: Adam Jackson <ajax at redhat.com>

diff --git a/hw/xfree86/ddc/ddc.c b/hw/xfree86/ddc/ddc.c
index 04d1a09..15e4beb 100644
--- a/hw/xfree86/ddc/ddc.c
+++ b/hw/xfree86/ddc/ddc.c
@@ -468,61 +468,3 @@ xf86DoEDID_DDC2(ScrnInfoPtr pScrn, I2CBusPtr pBus)
 {
     return xf86DoEEDID(pScrn, pBus, FALSE);
 }
-
-/* XXX write me */
-static void *
-DDC2ReadDisplayID(void)
-{
-    return FALSE;
-}
-
-/**
- * Attempts to probe the monitor for DisplayID information, if NoDDC and
- * NoDDC2 are unset.  DisplayID blocks are interpreted and the results
- * returned in an xf86MonPtr.
- *
- * This function does not affect the list of modes used by drivers -- it is up
- * to the driver to decide policy on what to do with DisplayID information.
- *
- * @return pointer to a new xf86MonPtr containing the DisplayID information.
- * @return NULL if no monitor attached or failure to interpret the DisplayID.
- */
-xf86MonPtr
-xf86DoDisplayID(ScrnInfoPtr pScrn, I2CBusPtr pBus)
-{
-    unsigned char *did = NULL;
-    xf86MonPtr tmp = NULL;
-    I2CDevPtr dev = NULL;
-
-    /* Default DDC and DDC2 to enabled. */
-    Bool noddc = FALSE, noddc2 = FALSE;
-    OptionInfoPtr options;
-
-    options = malloc(sizeof(DDCOptions));
-    if (!options)
-        return NULL;
-    memcpy(options, DDCOptions, sizeof(DDCOptions));
-    xf86ProcessOptions(pScrn->scrnIndex, pScrn->options, options);
-
-    xf86GetOptValBool(options, DDCOPT_NODDC, &noddc);
-    xf86GetOptValBool(options, DDCOPT_NODDC2, &noddc2);
-    free(options);
-
-    if (noddc || noddc2)
-        return NULL;
-
-    if (!(dev = DDC2Init(pBus)))
-        return NULL;
-
-    if ((did = DDC2ReadDisplayID())) {
-        tmp = calloc(1, sizeof(*tmp));
-        if (!tmp)
-            return NULL;
-
-        tmp->scrnIndex = pScrn->scrnIndex;
-        tmp->flags |= MONITOR_DISPLAYID;
-        tmp->rawData = did;
-    }
-
-    return tmp;
-}
diff --git a/hw/xfree86/ddc/xf86DDC.h b/hw/xfree86/ddc/xf86DDC.h
index de8e718..727813f 100644
--- a/hw/xfree86/ddc/xf86DDC.h
+++ b/hw/xfree86/ddc/xf86DDC.h
@@ -48,11 +48,6 @@ extern _X_EXPORT Bool xf86SetDDCproperties(ScrnInfoPtr pScreen, xf86MonPtr DDC);
 extern _X_EXPORT Bool
  xf86MonitorIsHDMI(xf86MonPtr mon);
 
-extern _X_EXPORT xf86MonPtr xf86DoDisplayID(ScrnInfoPtr pScrn, I2CBusPtr pBus);
-
-extern _X_EXPORT void
- xf86DisplayIDMonitorSet(int scrnIndex, MonPtr mon, xf86MonPtr DDC);
-
 extern _X_EXPORT DisplayModePtr
 FindDMTMode(int hsize, int vsize, int refresh, Bool rb);
 
diff --git a/hw/xfree86/modes/Makefile.am b/hw/xfree86/modes/Makefile.am
index 220643f..6eb162a 100644
--- a/hw/xfree86/modes/Makefile.am
+++ b/hw/xfree86/modes/Makefile.am
@@ -10,7 +10,6 @@ libxf86modes_la_SOURCES = \
 	xf86Cursors.c \
 	xf86cvt.c \
 	xf86gtf.c \
-	xf86DisplayIDModes.c \
 	xf86EdidModes.c \
 	xf86Modes.c \
 	xf86Modes.h \
diff --git a/hw/xfree86/modes/xf86DisplayIDModes.c b/hw/xfree86/modes/xf86DisplayIDModes.c
deleted file mode 100644
index c2e7718..0000000
--- a/hw/xfree86/modes/xf86DisplayIDModes.c
+++ /dev/null
@@ -1,444 +0,0 @@
-/*
- * Copyright 2009 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
- * on the rights to use, copy, modify, merge, publish, distribute, sub
- * license, and/or sell copies of the Software, and to permit persons to whom
- * them 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 MERCHANTIBILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.  IN NO EVENT SHALL
- * THE AUTHORS 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:
- *	Adam Jackson <ajax at redhat.com>
- */
-
-#include "xorg-config.h"
-#include "xf86.h"
-#include "xf86Modes.h"
-#include "xf86str.h"
-#include "edid.h"
-#include "xf86DDC.h"
-
-typedef void (*did_proc) (int scrnIndex, unsigned char *data, void *closure);
-
-#define DID_PRODUCT_ID		    0x00
-#define DID_DISPLAY_PARAMETERS	    0x01
-#define DID_COLOR_INFO		    0x02
-#define DID_TIMING_1_DETAILED	    0x03
-#define DID_TIMING_2_DETAILED	    0x04
-#define DID_TIMING_3_SHORT	    0x05
-#define DID_TIMING_4_DMT	    0x06
-#define DID_TIMING_VESA		    0x07
-#define DID_TIMING_CEA		    0x08
-#define DID_TIMING_RANGE_LIMITS	    0x09
-#define DID_PRODUCT_SERIAL	    0x0A
-#define DID_ASCII_STRING	    0x0B
-#define DID_DISPLAY_DEVICE	    0x0C
-#define DID_POWER_SEQUENCING	    0x0D
-#define DID_TRANSFER_INFO	    0x0E
-#define DID_DISPLAY_INTERFACE	    0x0F
-#define DID_STEREO		    0x10
-#define DID_VENDOR		    0x7F
-
-#define extract_le16(x, i) ((x[i+1] << 8) + (x[i]))
-#define extract_le24(x, i) ((x[i+2] << 16) + (x[i+1] << 8) + (x[i]))
-
-static DisplayModePtr
-modeCalloc(void)
-{
-    return calloc(1, sizeof(DisplayModeRec));
-}
-
-/*
- * How awesome is it to have two detailed timing formats, neither of which
- * are compatible with the format in EDID?  So awesome.
- */
-
-static void
-didDetailedTiming1(int i, unsigned char *x, MonPtr mon)
-{
-    DisplayModePtr m = modeCalloc();
-
-    if (!m)
-        return;
-
-    m->Clock = extract_le24(x, 0);
-
-    m->HDisplay = extract_le16(x, 4);
-    m->HSyncStart = m->HDisplay + (extract_le16(x, 8) & 0x7f);
-    m->HSyncEnd = m->HSyncStart + extract_le16(x, 10);
-    m->HTotal = m->HDisplay + extract_le16(x, 6);
-    m->Flags |= (x[9] & 0x80) ? V_PHSYNC : V_NHSYNC;
-
-    m->VDisplay = extract_le16(x, 12);
-    m->VSyncStart = m->VDisplay + (extract_le16(x, 16) & 0x7f);
-    m->VSyncEnd = m->VSyncStart + extract_le16(x, 18);
-    m->VTotal = m->VDisplay + extract_le16(x, 14);
-    m->Flags |= (x[17] & 0x80) ? V_PVSYNC : V_NVSYNC;
-
-    m->type = M_T_DRIVER;
-    if (x[3] & 0x80)
-        m->type |= M_T_PREFERRED;
-
-    /* XXX double check handling of this */
-    if (x[3] & 0x10)
-        m->Flags |= V_INTERLACE;
-
-    mon->Modes = xf86ModesAdd(mon->Modes, m);
-}
-
-/* XXX no sync bits.  what to do? */
-static void
-didDetailedTiming2(int i, unsigned char *x, MonPtr mon)
-{
-    DisplayModePtr mode = modeCalloc();
-
-    if (!mode)
-        return;
-
-    mode->Clock = extract_le24(x, 0);
-
-    /* horiz sizes are in character cells, not pixels, hence * 8 */
-    mode->HDisplay = ((extract_le16(x, 4) & 0x01ff) + 1) * 8;
-    mode->HSyncStart = mode->HDisplay + (((x[6] & 0xf0) >> 4) + 1) * 8;
-    mode->HSyncEnd = mode->HSyncStart + ((x[6] & 0x0f) + 1) * 8;
-    mode->HTotal = mode->HDisplay + ((x[5] >> 1) + 1) * 8;
-
-    mode->VDisplay = extract_le16(x, 7) & 0x07ff;
-    mode->VSyncStart = mode->VDisplay + (x[10] >> 4) + 1;
-    mode->VSyncEnd = mode->VSyncStart + (x[10] & 0x0f) + 1;
-    mode->VTotal = mode->VDisplay + x[9];
-
-    mode->status = M_T_DRIVER;
-    if (x[3] & 0x80)
-        mode->status |= M_T_PREFERRED;
-
-    /* XXX double check handling of this */
-    if (x[3] & 0x10)
-        mode->Flags |= V_INTERLACE;
-
-    mon->Modes = xf86ModesAdd(mon->Modes, mode);
-}
-
-static void
-didShortTiming(int i, unsigned char *x, MonPtr mon)
-{
-    DisplayModePtr m;
-    int w, h, r;
-
-    w = (x[1] + 1) * 8;
-    switch (x[0] & 0x0f) {
-    case 0:
-        h = w;
-        break;
-    case 1:
-        h = (w * 4) / 5;
-        break;
-    case 2:
-        h = (w * 3) / 4;
-        break;
-    case 3:
-        h = (w * 9) / 15;
-        break;
-    case 4:
-        h = (w * 9) / 16;
-        break;
-    case 5:
-        h = (w * 10) / 16;
-        break;
-    default:
-        return;
-    }
-    r = (x[2] & 0x7f) + 1;
-
-    m = xf86CVTMode(w, h, r, ! !(x[0] & 0x10), ! !(x[2] & 0x80));
-
-    m->type = M_T_DRIVER;
-    if (x[0] & 0x80)
-        m->type |= M_T_PREFERRED;
-
-    mon->Modes = xf86ModesAdd(mon->Modes, m);
-}
-
-static void
-didDMTTiming(int i, unsigned char *x, void *closure)
-{
-    MonPtr mon = closure;
-
-    mon->Modes = xf86ModesAdd(mon->Modes, xf86DuplicateMode(DMTModes + *x));
-}
-
-#define RB 1
-#define INT 2
-static const struct did_dmt {
-    short w, h, r, f;
-} did_dmt[] = {
-    /* byte 3 */
-    {640, 350, 85, 0},
-    {640, 400, 85, 0},
-    {720, 400, 85, 0},
-    {640, 480, 60, 0},
-    {640, 480, 72, 0},
-    {640, 480, 75, 0},
-    {640, 480, 85, 0},
-    {800, 600, 56, 0},
-        /* byte 4 */
-    {800, 600, 60, 0},
-    {800, 600, 72, 0},
-    {800, 600, 75, 0},
-    {800, 600, 85, 0},
-    {800, 600, 120, RB},
-    {848, 480, 60, 0},
-    {1024, 768, 43, INT},
-    {1024, 768, 60, 0},
-        /* byte 5 */
-    {1024, 768, 70, 0},
-    {1024, 768, 75, 0},
-    {1024, 768, 85, 0},
-    {1024, 768, 120, RB},
-    {1152, 864, 75, 0},
-    {1280, 768, 60, RB},
-    {1280, 768, 60, 0},
-    {1280, 768, 75, 0},
-        /* byte 6 */
-    {1280, 768, 85, 0},
-    {1280, 768, 120, RB},
-    {1280, 800, 60, RB},
-    {1280, 800, 60, 0},
-    {1280, 800, 75, 0},
-    {1280, 800, 85, 0},
-    {1280, 800, 120, RB},
-    {1280, 960, 60, 0},
-        /* byte 7 */
-    {1280, 960, 85, 0},
-    {1280, 960, 120, RB},
-    {1280, 1024, 60, 0},
-    {1280, 1024, 75, 0},
-    {1280, 1024, 85, 0},
-    {1280, 1024, 120, RB},
-    {1360, 768, 60, 0},
-    {1360, 768, 120, RB},
-        /* byte 8 */
-    {1400, 1050, 60, RB},
-    {1400, 1050, 60, 0},
-    {1400, 1050, 75, 0},
-    {1400, 1050, 85, 0},
-    {1400, 1050, 120, RB},
-    {1440, 900, 60, RB},
-    {1440, 900, 60, 0},
-    {1440, 900, 75, 0},
-        /* byte 9 */
-    {1440, 900, 85, 0},
-    {1440, 900, 120, RB},
-    {1600, 1200, 60, 0},
-    {1600, 1200, 65, 0},
-    {1600, 1200, 70, 0},
-    {1600, 1200, 75, 0},
-    {1600, 1200, 85, 0},
-    {1600, 1200, 120, RB},
-        /* byte a */
-    {1680, 1050, 60, RB},
-    {1680, 1050, 60, 0},
-    {1680, 1050, 75, 0},
-    {1680, 1050, 85, 0},
-    {1680, 1050, 120, RB},
-    {1792, 1344, 60, 0},
-    {1792, 1344, 75, 0},
-    {1792, 1344, 120, RB},
-        /* byte b */
-    {1856, 1392, 60, 0},
-    {1856, 1392, 75, 0},
-    {1856, 1392, 120, RB},
-    {1920, 1200, 60, RB},
-    {1920, 1200, 60, 0},
-    {1920, 1200, 75, 0},
-    {1920, 1200, 85, 0},
-    {1920, 1200, 120, RB},
-        /* byte c */
-    {1920, 1440, 60, 0},
-    {1920, 1440, 75, 0},
-    {1920, 1440, 120, RB},
-    {2560, 1600, 60, RB},
-    {2560, 1600, 60, 0},
-    {2560, 1600, 75, 0},
-    {2560, 1600, 85, 0},
-    {2560, 1600, 120, RB},
-};
-
-static void
-didVesaTiming(int scrn, unsigned char *x, MonPtr mon)
-{
-    int i, j;
-
-    x += 3;
-
-    for (i = 0; i < 10; i++)
-        for (j = 0; j < 8; j++)
-            if (x[i] & (1 << j)) {
-                const struct did_dmt *d = &(did_dmt[i * 8 + j]);
-
-                if (d->f == INT)
-                    continue;
-                mon->Modes = xf86ModesAdd(mon->Modes,
-                                          FindDMTMode(d->w, d->h, d->r,
-                                                      d->f == RB));
-            }
-
-}
-
-static void
-handleDisplayIDBlock(int scrnIndex, unsigned char *x, void *closure)
-{
-    MonPtr mon = closure;
-
-    switch (x[0]) {
-    case DID_DISPLAY_PARAMETERS:
-        /* w/h are in decimillimeters */
-        mon->widthmm = (extract_le16(x, 3) + 5) / 10;
-        mon->heightmm = (extract_le16(x, 5) + 5) / 10;
-        /* XXX pixel count, feature flags, gamma, aspect, color depth */
-        break;
-
-    case DID_TIMING_RANGE_LIMITS:
-    {
-        int n;
-
-        mon->maxPixClock = max(mon->maxPixClock, extract_le24(x, 6) * 10);
-
-        n = mon->nHsync++;
-        if (n < MAX_HSYNC) {
-            mon->hsync[n].lo = x[9];
-            mon->hsync[n].hi = x[10];
-        }
-        else {
-            n = MAX_HSYNC;
-        }
-        n = mon->nVrefresh++;
-        if (n < MAX_VREFRESH) {
-            mon->vrefresh[n].lo = x[13];
-            mon->vrefresh[n].hi = x[14];
-        }
-        else {
-            n = MAX_VREFRESH;
-        }
-        break;
-    }
-
-    case DID_TIMING_1_DETAILED:
-    {
-        int i;
-
-        for (i = 0; i < x[2]; i += 20)
-            didDetailedTiming1(scrnIndex, x + i + 3, mon);
-        break;
-    }
-
-    case DID_TIMING_2_DETAILED:
-    {
-        int i;
-
-        for (i = 0; i < x[2]; i += 11)
-            didDetailedTiming2(scrnIndex, x + i + 3, mon);
-        break;
-    }
-
-    case DID_TIMING_3_SHORT:
-    {
-        int i;
-
-        for (i = 0; i < x[2]; i += 3)
-            didShortTiming(scrnIndex, x + i + 3, mon);
-        break;
-    }
-
-    case DID_TIMING_4_DMT:
-    {
-        int i;
-
-        for (i = 0; i < x[2]; i++)
-            didDMTTiming(scrnIndex, x + i + 3, mon);
-        break;
-    }
-
-    case DID_TIMING_VESA:
-        didVesaTiming(scrnIndex, x, mon);
-        break;
-
-        /* XXX pixel format, ar, orientation, subpixel, dot pitch, bit depth */
-    case DID_DISPLAY_DEVICE:
-
-        /* XXX interface, links, color encoding, ss, drm */
-    case DID_DISPLAY_INTERFACE:
-
-        /* XXX stereo */
-    case DID_STEREO:
-
-        /* nothing interesting in these */
-    case DID_COLOR_INFO:
-    case DID_PRODUCT_SERIAL:
-    case DID_ASCII_STRING:
-    case DID_POWER_SEQUENCING:
-    case DID_TRANSFER_INFO:
-    case DID_VENDOR:
-        break;
-
-        /* warn about anything else */
-    default:
-        xf86DrvMsg(scrnIndex, X_WARNING,
-                   "Unknown DisplayID block type %hx\n", x[0]);
-        break;
-    }
-}
-
-static void
-forEachDisplayIDBlock(int scrnIndex, unsigned char *did, did_proc proc,
-                      void *closure)
-{
-    int num_extensions = did[3];
-    int section_size = did[1];
-    unsigned char *block;
-
-    do {
-        if ((did[0] & 0xf0) != 0x10)    /* not 1.x, abort */
-            return;
-        /* XXX also, checksum */
-
-        block = did + 4;
-
-        while (section_size > 0) {
-            int block_size = (block[2] + 2);
-
-            proc(scrnIndex, block, closure);
-
-            section_size -= block_size;
-            block += block_size;
-        }
-
-        did += (did[1] + 5);
-    } while (num_extensions--);
-}
-
-/*
- * Fill out MonPtr with xf86MonPtr information.
- */
-void
-xf86DisplayIDMonitorSet(int scrnIndex, MonPtr mon, xf86MonPtr DDC)
-{
-    if (!mon || !DDC)
-        return;
-
-    mon->DDC = DDC;
-
-    forEachDisplayIDBlock(scrnIndex, DDC->rawData, handleDisplayIDBlock, mon);
-}
commit b56fcce761534d3e28b7ea19e2a13213c3157a1f
Author: Adam Jackson <ajax at redhat.com>
Date:   Tue Jun 17 10:36:44 2014 -0400

    xfree86: Remove useless back-pointer to pScrn from colormap code
    
    Reviewed-by: Eric Anholt <eric at anholt.net>
    Signed-off-by: Adam Jackson <ajax at redhat.com>

diff --git a/hw/xfree86/common/xf86cmap.c b/hw/xfree86/common/xf86cmap.c
index 3f9c880..c4bae56 100644
--- a/hw/xfree86/common/xf86cmap.c
+++ b/hw/xfree86/common/xf86cmap.c
@@ -74,7 +74,6 @@ typedef struct _CMapLink {
 } CMapLink, *CMapLinkPtr;
 
 typedef struct {
-    ScrnInfoPtr pScrn;
     CloseScreenProcPtr CloseScreen;
     CreateColormapProcPtr CreateColormap;
     DestroyColormapProcPtr DestroyColormap;
@@ -123,7 +122,7 @@ static int CMapSetDGAMode(ScrnInfoPtr, int, DGADevicePtr);
 #endif
 static int CMapChangeGamma(ScrnInfoPtr, Gamma);
 
-static void ComputeGamma(CMapScreenPtr);
+static void ComputeGamma(ScrnInfoPtr, CMapScreenPtr);
 static Bool CMapAllocateColormapPrivate(ColormapPtr);
 static void CMapRefreshColors(ColormapPtr, int, int *);
 static void CMapSetOverscan(ColormapPtr, int, int *);
@@ -194,7 +193,6 @@ xf86HandleColormaps(ScreenPtr pScreen,
     pScreen->InstallColormap = CMapInstallColormap;
     pScreen->StoreColors = CMapStoreColors;
 
-    pScreenPriv->pScrn = pScrn;
     pScrn->LoadPalette = loadPalette;
     pScrn->SetOverscan = setOverscan;
     pScreenPriv->maxColors = maxColors;
@@ -221,7 +219,7 @@ xf86HandleColormaps(ScreenPtr pScreen,
 #endif
     pScrn->ChangeGamma = CMapChangeGamma;
 
-    ComputeGamma(pScreenPriv);
+    ComputeGamma(pScrn, pScreenPriv);
 
     /* get the default map */
     dixLookupResourceByType((void **) &pDefMap, pScreen->defColormap,
@@ -660,8 +658,7 @@ CMapRefreshColors(ColormapPtr pmap, int defs, int *indices)
     }
 
     if (LOAD_PALETTE(pmap))
-        (*pScrn->LoadPalette) (pScreenPriv->pScrn, defs, indices,
-                               colors, pmap->pVisual);
+        (*pScrn->LoadPalette) (pScrn, defs, indices, colors, pmap->pVisual);
 
     if (pScrn->SetOverscan)
         CMapSetOverscan(pmap, defs, indices);
@@ -822,7 +819,7 @@ CMapSetOverscan(ColormapPtr pmap, int defs, int *indices)
 #ifdef DEBUGOVERSCAN
             ErrorF("SetOverscan() called from CmapSetOverscan\n");
 #endif
-            pScrn->SetOverscan(pScreenPriv->pScrn, overscan);
+            pScrn->SetOverscan(pScrn, overscan);
         }
     }
 }
@@ -851,7 +848,7 @@ CMapUnwrapScreen(ScreenPtr pScreen)
 }
 
 static void
-ComputeGamma(CMapScreenPtr priv)
+ComputeGamma(ScrnInfoPtr pScrn, CMapScreenPtr priv)
 {
     int elements = priv->gammaElements - 1;
     double RedGamma, GreenGamma, BlueGamma;
@@ -859,28 +856,25 @@ ComputeGamma(CMapScreenPtr priv)
 
 #ifndef DONT_CHECK_GAMMA
     /* This check is to catch drivers that are not initialising pScrn->gamma */
-    if (priv->pScrn->gamma.red < GAMMA_MIN ||
-        priv->pScrn->gamma.red > GAMMA_MAX ||
-        priv->pScrn->gamma.green < GAMMA_MIN ||
-        priv->pScrn->gamma.green > GAMMA_MAX ||
-        priv->pScrn->gamma.blue < GAMMA_MIN ||
-        priv->pScrn->gamma.blue > GAMMA_MAX) {
-
-        xf86DrvMsgVerb(priv->pScrn->scrnIndex, X_WARNING, 0,
+    if (pScrn->gamma.red < GAMMA_MIN || pScrn->gamma.red > GAMMA_MAX ||
+        pScrn->gamma.green < GAMMA_MIN || pScrn->gamma.green > GAMMA_MAX ||
+        pScrn->gamma.blue < GAMMA_MIN || pScrn->gamma.blue > GAMMA_MAX) {
+
+        xf86DrvMsgVerb(pScrn->scrnIndex, X_WARNING, 0,
                        "The %s driver didn't call xf86SetGamma() to initialise\n"
-                       "\tthe gamma values.\n", priv->pScrn->driverName);
-        xf86DrvMsgVerb(priv->pScrn->scrnIndex, X_WARNING, 0,
+                       "\tthe gamma values.\n", pScrn->driverName);
+        xf86DrvMsgVerb(pScrn->scrnIndex, X_WARNING, 0,
                        "PLEASE FIX THE `%s' DRIVER!\n",
-                       priv->pScrn->driverName);
-        priv->pScrn->gamma.red = 1.0;
-        priv->pScrn->gamma.green = 1.0;
-        priv->pScrn->gamma.blue = 1.0;
+                       pScrn->driverName);
+        pScrn->gamma.red = 1.0;
+        pScrn->gamma.green = 1.0;
+        pScrn->gamma.blue = 1.0;
     }
 #endif
 
-    RedGamma = 1.0 / (double) priv->pScrn->gamma.red;
-    GreenGamma = 1.0 / (double) priv->pScrn->gamma.green;
-    BlueGamma = 1.0 / (double) priv->pScrn->gamma.blue;
+    RedGamma = 1.0 / (double) pScrn->gamma.red;
+    GreenGamma = 1.0 / (double) pScrn->gamma.green;
+    BlueGamma = 1.0 / (double) pScrn->gamma.blue;
 
     for (i = 0; i <= elements; i++) {
         if (RedGamma == 1.0)
@@ -933,7 +927,7 @@ CMapChangeGamma(ScrnInfoPtr pScrn, Gamma gamma)
     pScrn->gamma.green = gamma.green;
     pScrn->gamma.blue = gamma.blue;
 
-    ComputeGamma(pScreenPriv);
+    ComputeGamma(pScrn, pScreenPriv);
 
     /* mark all colormaps on this screen */
     pLink = pScreenPriv->maps;
commit ef22655311efa0d5a5395ba2f19aa20d71a05a4f
Author: Adam Jackson <ajax at redhat.com>
Date:   Fri May 2 13:36:13 2014 -0400

    xfree86: Remove spurious xf86ConfigError
    
    READABLE.
    
    Reviewed-by: Eric Anholt <eric at anholt.net>
    Signed-off-by: Adam Jackson <ajax at redhat.com>

diff --git a/hw/xfree86/common/xf86Config.c b/hw/xfree86/common/xf86Config.c
index 53e61a0..546055d 100644
--- a/hw/xfree86/common/xf86Config.c
+++ b/hw/xfree86/common/xf86Config.c
@@ -571,25 +571,6 @@ xf86DriverlistFromCompile(void)
     return driverlist;
 }
 
-/*
- * xf86ConfigError --
- *      Print a READABLE ErrorMessage!!!  All information that is 
- *      available is printed.
- */
-static void
-_X_ATTRIBUTE_PRINTF(1, 2)
-xf86ConfigError(const char *msg, ...)
-{
-    va_list ap;
-
-    ErrorF("\nConfig Error:\n");
-    va_start(ap, msg);
-    VErrorF(msg, ap);
-    va_end(ap);
-    ErrorF("\n");
-    return;
-}
-
 static void
 configFiles(XF86ConfFilesPtr fileconf)
 {
@@ -994,9 +975,8 @@ configServerFlags(XF86ConfFlagsPtr flagsconf, XF86OptionPtr layoutopts)
     if ((i >= 0) && (i < MAX_TIME_IN_MIN))
         ScreenSaverTime = defaultScreenSaverTime = i * MILLI_PER_MIN;
     else if (i != -1)
-        xf86ConfigError
-            ("BlankTime value %d outside legal range of 0 - %d minutes", i,
-             MAX_TIME_IN_MIN);
+        ErrorF("BlankTime value %d outside legal range of 0 - %d minutes\n",
+               i, MAX_TIME_IN_MIN);
 
 #ifdef DPMSExtension
     i = -1;
@@ -1004,25 +984,22 @@ configServerFlags(XF86ConfFlagsPtr flagsconf, XF86OptionPtr layoutopts)
     if ((i >= 0) && (i < MAX_TIME_IN_MIN))
         DPMSStandbyTime = i * MILLI_PER_MIN;
     else if (i != -1)
-        xf86ConfigError
-            ("StandbyTime value %d outside legal range of 0 - %d minutes", i,
-             MAX_TIME_IN_MIN);
+        ErrorF("StandbyTime value %d outside legal range of 0 - %d minutes\n",
+               i, MAX_TIME_IN_MIN);
     i = -1;
     xf86GetOptValInteger(FlagOptions, FLAG_DPMS_SUSPENDTIME, &i);
     if ((i >= 0) && (i < MAX_TIME_IN_MIN))
         DPMSSuspendTime = i * MILLI_PER_MIN;
     else if (i != -1)
-        xf86ConfigError
-            ("SuspendTime value %d outside legal range of 0 - %d minutes", i,
-             MAX_TIME_IN_MIN);
+        ErrorF("SuspendTime value %d outside legal range of 0 - %d minutes\n",
+               i, MAX_TIME_IN_MIN);
     i = -1;
     xf86GetOptValInteger(FlagOptions, FLAG_DPMS_OFFTIME, &i);
     if ((i >= 0) && (i < MAX_TIME_IN_MIN))
         DPMSOffTime = i * MILLI_PER_MIN;
     else if (i != -1)
-        xf86ConfigError
-            ("OffTime value %d outside legal range of 0 - %d minutes", i,
-             MAX_TIME_IN_MIN);
+        ErrorF("OffTime value %d outside legal range of 0 - %d minutes\n",
+               i, MAX_TIME_IN_MIN);
 #endif
 
     i = -1;
@@ -1037,7 +1014,7 @@ configServerFlags(XF86ConfFlagsPtr flagsconf, XF86OptionPtr layoutopts)
     case -1:
         break;
     default:
-        xf86ConfigError("Pixmap option's value (%d) must be 24 or 32\n", i);
+        ErrorF("Pixmap option's value (%d) must be 24 or 32\n", i);
         return FALSE;
     }
     if (xf86Pix24 != Pix24DontCare) {
@@ -2049,8 +2026,8 @@ configMonitor(MonPtr monitorp, XF86ConfMonitorPtr conf_monitor)
         badgamma = monitorp->gamma.blue;
     }
     if (badgamma > GAMMA_ZERO) {
-        xf86ConfigError("Gamma value %.f is out of range (%.2f - %.1f)\n",
-                        badgamma, GAMMA_MIN, GAMMA_MAX);
+        ErrorF("Gamma value %.f is out of range (%.2f - %.1f)\n", badgamma,
+               GAMMA_MIN, GAMMA_MAX);
         return FALSE;
     }
 
@@ -2109,8 +2086,7 @@ configDisplay(DispPtr displayp, XF86ConfDisplayPtr conf_display)
     if (conf_display->disp_visual) {
         displayp->defaultVisual = lookupVisual(conf_display->disp_visual);
         if (displayp->defaultVisual == -1) {
-            xf86ConfigError("Invalid visual name: \"%s\"",
-                            conf_display->disp_visual);
+            ErrorF("Invalid visual name: \"%s\"\n", conf_display->disp_visual);
             return FALSE;
         }
     }
commit 35f0257360fa6e11b9ecc08e467163718e012bb1
Author: Adam Jackson <ajax at redhat.com>
Date:   Tue Mar 4 11:12:16 2014 -0500

    xfree86: Remove Option "TextClockFreq"
    
    No modern driver pays attention to this.  Presumably there existed
    hardware once where you couldn't just read the right values out of the
    CRTC.
    
    Reviewed-by: Eric Anholt <eric at anholt.net>
    Signed-off-by: Adam Jackson <ajax at redhat.com>

diff --git a/hw/xfree86/common/xf86Config.c b/hw/xfree86/common/xf86Config.c
index 779ba6f..53e61a0 100644
--- a/hw/xfree86/common/xf86Config.c
+++ b/hw/xfree86/common/xf86Config.c
@@ -2168,7 +2168,6 @@ configDevice(GDevPtr devicep, XF86ConfDevicePtr conf_device, Bool active)
     devicep->IOBase = conf_device->dev_io_base;
     devicep->clockchip = conf_device->dev_clockchip;
     devicep->busID = conf_device->dev_busid;
-    devicep->textClockFreq = conf_device->dev_textclockfreq;
     devicep->chipID = conf_device->dev_chipid;
     devicep->chipRev = conf_device->dev_chiprev;
     devicep->options = conf_device->dev_option_lst;
diff --git a/hw/xfree86/common/xf86Configure.c b/hw/xfree86/common/xf86Configure.c
index 967bfbc..8dbca3a 100644
--- a/hw/xfree86/common/xf86Configure.c
+++ b/hw/xfree86/common/xf86Configure.c
@@ -267,7 +267,6 @@ configureDeviceSection(int screennum)
     for (i = 0; (i < MAXDACSPEEDS) && (i < CONF_MAXDACSPEEDS); i++)
         ptr->dev_dacSpeeds[i] = DevToConfig[screennum].GDev.dacSpeeds[i];
     ptr->dev_videoram = DevToConfig[screennum].GDev.videoRam;
-    ptr->dev_textclockfreq = DevToConfig[screennum].GDev.textClockFreq;
     ptr->dev_bios_base = DevToConfig[screennum].GDev.BiosBase;
     ptr->dev_mem_base = DevToConfig[screennum].GDev.MemBase;
     ptr->dev_io_base = DevToConfig[screennum].GDev.IOBase;
diff --git a/hw/xfree86/common/xf86str.h b/hw/xfree86/common/xf86str.h
index a81e886..9ad1b90 100644
--- a/hw/xfree86/common/xf86str.h
+++ b/hw/xfree86/common/xf86str.h
@@ -403,7 +403,6 @@ typedef struct {
     Bool active;
     Bool inUse;
     int videoRam;
-    int textClockFreq;
     unsigned long BiosBase;     /* Base address of video BIOS */
     unsigned long MemBase;      /* Frame buffer base address */
     unsigned long IOBase;
@@ -753,7 +752,6 @@ typedef struct _ScrnInfoRec {
     unsigned long memPhysBase;  /* Physical address of FB */
     unsigned long fbOffset;     /* Offset of FB in the above */
     int memClk;                 /* memory clock */
-    int textClockFreq;          /* clock of text mode */
     Bool flipPixels;            /* swap default black/white */
     void *options;
 
diff --git a/hw/xfree86/man/xorg.conf.man b/hw/xfree86/man/xorg.conf.man
index 378f26b..d26c3cc 100644
--- a/hw/xfree86/man/xorg.conf.man
+++ b/hw/xfree86/man/xorg.conf.man
@@ -1449,12 +1449,6 @@ This optional entry specifies the chip revision number.
 This can be used to override the auto-detection, but that should only be done
 when the driver-specific documentation recommends it.
 .TP 7
-.BI "TextClockFreq  " "freq"
-This optional entry specifies the pixel clock frequency that is used
-for the regular text mode.
-The frequency is specified in MHz.
-This is rarely used.
-.TP 7
 .BI "MatchSeat  " "seat\-id"
 Only apply this
 .B Device
diff --git a/hw/xfree86/parser/Device.c b/hw/xfree86/parser/Device.c
index d3ac293..28c274d 100644
--- a/hw/xfree86/parser/Device.c
+++ b/hw/xfree86/parser/Device.c
@@ -83,7 +83,6 @@ xf86ConfigSymTabRec DeviceTab[] = {
     {CARD, "card"},
     {DRIVER, "driver"},
     {BUSID, "busid"},
-    {TEXTCLOCKFRQ, "textclockfreq"},
     {IRQ, "irq"},
     {SCREEN, "screen"},
     {-1, ""},
@@ -212,11 +211,6 @@ xf86parseDeviceSection(void)
             ptr->dev_clocks = i;
             xf86unGetToken(token);
             break;
-        case TEXTCLOCKFRQ:
-            if ((token = xf86getSubToken(&(ptr->dev_comment))) != NUMBER)
-                Error(NUMBER_MSG, "TextClockFreq");
-            ptr->dev_textclockfreq = (int) (xf86_lex_val.realnum * 1000.0 + 0.5);
-            break;
         case MATCHSEAT:
             if (xf86getSubToken(&(ptr->dev_comment)) != STRING)
                 Error(QUOTE_MSG, "MatchSeat");
@@ -312,10 +306,6 @@ xf86printDeviceSection(FILE * cf, XF86ConfDevicePtr ptr)
                 fprintf(cf, "%.1f ", (double) ptr->dev_clock[i] / 1000.0);
             fprintf(cf, "\n");
         }
-        if (ptr->dev_textclockfreq) {
-            fprintf(cf, "\tTextClockFreq %.1f\n",
-                    (double) ptr->dev_textclockfreq / 1000.0);
-        }
         if (ptr->dev_busid)
             fprintf(cf, "\tBusID       \"%s\"\n", ptr->dev_busid);
         if (ptr->dev_screen > 0)
diff --git a/hw/xfree86/parser/xf86Parser.h b/hw/xfree86/parser/xf86Parser.h
index 3fa5b71..73187f3 100644
--- a/hw/xfree86/parser/xf86Parser.h
+++ b/hw/xfree86/parser/xf86Parser.h
@@ -211,7 +211,6 @@ typedef struct {
     const char *dev_ramdac;
     int dev_dacSpeeds[CONF_MAXDACSPEEDS];
     int dev_videoram;
-    int dev_textclockfreq;
     unsigned long dev_bios_base;
     unsigned long dev_mem_base;
     unsigned long dev_io_base;
diff --git a/hw/xfree86/parser/xf86tokens.h b/hw/xfree86/parser/xf86tokens.h
index 5c01ce7..8e15f12 100644
--- a/hw/xfree86/parser/xf86tokens.h
+++ b/hw/xfree86/parser/xf86tokens.h
@@ -187,7 +187,6 @@ typedef enum {
     CHIPREV,
     CARD,
     BUSID,
-    TEXTCLOCKFRQ,
     IRQ,
 
     /* Keyboard tokens */
diff --git a/hw/xwin/winconfig.h b/hw/xwin/winconfig.h
index 798c779..f079368 100644
--- a/hw/xwin/winconfig.h
+++ b/hw/xwin/winconfig.h
@@ -57,7 +57,6 @@ typedef struct {
     Bool active;
     Bool inUse;
     int videoRam;
-    int textClockFreq;
     void *options;
     int screen;                 /* For multi-CRTC cards */
 } GDevRec, *GDevPtr;
commit 6755aa2c1244fee11846c1e0b274bd34900e3299
Author: Adam Jackson <ajax at redhat.com>
Date:   Fri Jul 25 12:31:54 2014 -0400

    xfree86: Remove xv clip notify driver hook
    
    Nothing's using it.
    
    Reviewed-by: Eric Anholt <eric at anholt.net>
    Signed-off-by: Adam Jackson <ajax at redhat.com>

diff --git a/hw/xfree86/common/xf86xv.c b/hw/xfree86/common/xf86xv.c
index d342bde..0e67690 100644
--- a/hw/xfree86/common/xf86xv.c
+++ b/hw/xfree86/common/xf86xv.c
@@ -1117,10 +1117,6 @@ xf86XVClipNotify(WindowPtr pWin, int dx, int dy)
 
         pPriv->pCompositeClip = NULL;
 
-        if (pPriv->AdaptorRec->ClipNotify)
-            (*pPriv->AdaptorRec->ClipNotify) (pPriv->pScrn, pPriv->DevPriv.ptr,
-                                              pWin, dx, dy);
-
         pPriv->clipChanged = TRUE;
 
         if (ScreenPriv->PostValidateTree == PostValidateTreeUndefined) {
diff --git a/hw/xfree86/common/xf86xv.h b/hw/xfree86/common/xf86xv.h
index c6455d7..6f8662c 100644
--- a/hw/xfree86/common/xf86xv.h
+++ b/hw/xfree86/common/xf86xv.h
@@ -95,8 +95,6 @@ typedef int (*QueryImageAttributesFuncPtr) (ScrnInfoPtr pScrn, int image,
                                             unsigned short *width,
                                             unsigned short *height,
                                             int *pitches, int *offsets);
-typedef void (*ClipNotifyFuncPtr) (ScrnInfoPtr pScrn, void *data,
-                                   WindowPtr window, int dx, int dy);
 
 typedef enum {
     XV_OFF,
@@ -145,7 +143,6 @@ typedef struct {
     PutImageFuncPtr PutImage;
     ReputImageFuncPtr ReputImage;       /* image/still */
     QueryImageAttributesFuncPtr QueryImageAttributes;
-    ClipNotifyFuncPtr ClipNotify;
 } XF86VideoAdaptorRec, *XF86VideoAdaptorPtr;
 
 typedef struct {
diff --git a/hw/xfree86/common/xf86xvpriv.h b/hw/xfree86/common/xf86xvpriv.h
index c0dff16..8fb22e6 100644
--- a/hw/xfree86/common/xf86xvpriv.h
+++ b/hw/xfree86/common/xf86xvpriv.h
@@ -61,7 +61,6 @@ typedef struct {
     PutImageFuncPtr PutImage;
     ReputImageFuncPtr ReputImage;
     QueryImageAttributesFuncPtr QueryImageAttributes;
-    ClipNotifyFuncPtr ClipNotify;
 } XvAdaptorRecPrivate, *XvAdaptorRecPrivatePtr;
 
 typedef struct {
commit e89ccacea9a1e4bc3693bb78e717343addd517e5
Author: Adam Jackson <ajax at redhat.com>
Date:   Thu Jan 23 10:27:58 2014 -0500

    mi: Remove Windows 8-bpp colormap compatibility
    
    Nice, but not something our Windows servers build, and not something
    that belongs in mi anyway.
    
    Reviewed-by: Eric Anholt <eric at anholt.net>
    Signed-off-by: Adam Jackson <ajax at redhat.com>

diff --git a/mi/micmap.c b/mi/micmap.c
index 4648b9a..1aeb359 100644
--- a/mi/micmap.c
+++ b/mi/micmap.c
@@ -235,42 +235,7 @@ miExpandDirectColors(ColormapPtr pmap, int ndef, xColorItem * indefs,
 Bool
 miCreateDefColormap(ScreenPtr pScreen)
 {
-/* 
- * In the following sources PC X server vendors may want to delete 
- * "_not_tog" from "#ifdef WIN32_not_tog"
- */
-#ifdef WIN32_not_tog
-    /*  
-     * these are the MS-Windows desktop colors, adjusted for X's 16-bit 
-     * color specifications.
-     */
-    static xColorItem citems[] = {
-        {0, 0, 0, 0, 0, 0},
-        {1, 0x8000, 0, 0, 0, 0},
-        {2, 0, 0x8000, 0, 0, 0},
-        {3, 0x8000, 0x8000, 0, 0, 0},
-        {4, 0, 0, 0x8000, 0, 0},
-        {5, 0x8000, 0, 0x8000, 0, 0},
-        {6, 0, 0x8000, 0x8000, 0, 0},
-        {7, 0xc000, 0xc000, 0xc000, 0, 0},
-        {8, 0xc000, 0xdc00, 0xc000, 0, 0},
-        {9, 0xa600, 0xca00, 0xf000, 0, 0},
-        {246, 0xff00, 0xfb00, 0xf000, 0, 0},
-        {247, 0xa000, 0xa000, 0xa400, 0, 0},
-        {248, 0x8000, 0x8000, 0x8000, 0, 0},
-        {249, 0xff00, 0, 0, 0, 0},
-        {250, 0, 0xff00, 0, 0, 0},
-        {251, 0xff00, 0xff00, 0, 0, 0},
-        {252, 0, 0, 0xff00, 0, 0},
-        {253, 0xff00, 0, 0xff00, 0, 0},
-        {254, 0, 0xff00, 0xff00, 0, 0},
-        {255, 0xff00, 0xff00, 0xff00, 0, 0}
-    };
-#define NUM_DESKTOP_COLORS sizeof citems / sizeof citems[0]
-    int i;
-#else
     unsigned short zero = 0, ones = 0xFFFF;
-#endif
     Pixel wp, bp;
     VisualPtr pVisual;
     ColormapPtr cmap;
@@ -294,21 +259,12 @@ miCreateDefColormap(ScreenPtr pScreen)
     if (pScreen->rootDepth > 1) {
         wp = pScreen->whitePixel;
         bp = pScreen->blackPixel;
-#ifdef WIN32_not_tog
-        for (i = 0; i < NUM_DESKTOP_COLORS; i++) {
-            if (AllocColor(cmap,
-                           &citems[i].red, &citems[i].green, &citems[i].blue,
-                           &citems[i].pixel, 0) != Success)
-                return FALSE;
-        }
-#else
         if ((AllocColor(cmap, &ones, &ones, &ones, &wp, 0) !=
              Success) ||
             (AllocColor(cmap, &zero, &zero, &zero, &bp, 0) != Success))
             return FALSE;
         pScreen->whitePixel = wp;
         pScreen->blackPixel = bp;
-#endif
     }
 
     (*pScreen->InstallColormap) (cmap);
commit 7cd192edc195c089c6df32e9f22e57da7467b6fd
Author: Adam Jackson <ajax at redhat.com>
Date:   Mon Jun 16 11:55:30 2014 -0400

    loader: Deobfuscate RTLD_* macro stuff
    
    POSIX requires that these be named correctly, no need to be clever.
    
    Reviewed-by: Mark Kettenis <kettenis at openbsd.org>
    Signed-off-by: Adam Jackson <ajax at redhat.com>

diff --git a/hw/xfree86/loader/loader.c b/hw/xfree86/loader/loader.c
index cc41dcb..3132984 100644
--- a/hw/xfree86/loader/loader.c
+++ b/hw/xfree86/loader/loader.c
@@ -71,24 +71,6 @@
 #include <dlfcn.h>
 #include <X11/Xos.h>
 
-#if defined(DL_LAZY)
-#define DLOPEN_LAZY DL_LAZY
-#elif defined(RTLD_LAZY)
-#define DLOPEN_LAZY RTLD_LAZY
-#elif defined(__FreeBSD__)
-#define DLOPEN_LAZY 1
-#else
-#define DLOPEN_LAZY 0
-#endif
-
-#if defined(LD_GLOBAL)
-#define DLOPEN_GLOBAL LD_GLOBAL
-#elif defined(RTLD_GLOBAL)
-#define DLOPEN_GLOBAL RTLD_GLOBAL
-#else
-#define DLOPEN_GLOBAL 0
-#endif
-
 #else
 #error i have no dynamic linker and i must scream
 #endif
@@ -128,7 +110,7 @@ LoaderOpen(const char *module, int *errmaj, int *errmin)
 
     xf86Msg(X_INFO, "Loading %s\n", module);
 
-    if (!(ret = dlopen(module, DLOPEN_LAZY | DLOPEN_GLOBAL))) {
+    if (!(ret = dlopen(module, RTLD_LAZY | RTLD_GLOBAL))) {
         xf86Msg(X_ERROR, "Failed to load %s: %s\n", module, dlerror());
         if (errmaj)
             *errmaj = LDR_NOLOAD;
@@ -151,7 +133,7 @@ LoaderSymbol(const char *name)
         return p;
 
     if (!global_scope)
-        global_scope = dlopen(NULL, DLOPEN_LAZY | DLOPEN_GLOBAL);
+        global_scope = dlopen(NULL, RTLD_LAZY | RTLD_GLOBAL);
 
     if (global_scope)
         return dlsym(global_scope, name);
commit cc59be38b7eff52a1d003b390f2994c73ee0b3e9
Author: Keith Packard <keithp at keithp.com>
Date:   Fri Sep 12 11:33:48 2014 -0700

    os: Don't listen to 'tcp' by default. Add '-listen' option. [v2]
    
    This disables the tcp listen socket by default. Then, it
    uses a new xtrans interface, TRANS(Listen), to provide a command line
    option to re-enable those if desired.
    
    v2: Leave unix socket enabled by default. Add configure options.
    
    Signed-off-by: Keith Packard <keithp at keithp.com>
    Reviewed-by: Hans de Goede <hdegoede at redhat.com>

diff --git a/configure.ac b/configure.ac
index 9066a6f..51e0f1f 100644
--- a/configure.ac
+++ b/configure.ac
@@ -461,6 +461,16 @@ AC_ARG_WITH(os-vendor,       AS_HELP_STRING([--with-os-vendor=OSVENDOR], [Name o
 AC_ARG_WITH(builderstring,   AS_HELP_STRING([--with-builderstring=BUILDERSTRING], [Additional builder string]),
 				[ BUILDERSTRING="$withval" ]
 				[ ])
+AC_ARG_ENABLE(listen-tcp,    AS_HELP_STRING([--enable-listen-tcp],
+                                            [Listen on TCP by default (default:disabled)]),
+                                [LISTEN_TCP=$enableval], [LISTEN_TCP=no])
+AC_ARG_ENABLE(listen-unix,   AS_HELP_STRING([--disable-listen-unix],
+                                            [Listen on Unix by default (default:enabled)]),
+                                [LISTEN_UNIX=$enableval], [LISTEN_UNIX=yes])
+
+AC_ARG_ENABLE(listen-local,  AS_HELP_STRING([--disable-listen-local],
+                                            [Listen on local by default (default:enabled)]),
+                                [LISTEN_LOCAL=$enableval], [LISTEN_LOCAL=yes])
 
 dnl Determine font path
 XORG_FONTROOTDIR
@@ -1053,6 +1063,16 @@ if test "x$RES" = xyes; then
 	SDK_REQUIRED_MODULES="$SDK_REQUIRED_MODULES $RESOURCEPROTO"
 fi
 
+if test "x$LISTEN_TCP" = xyes; then
+	AC_DEFINE(LISTEN_TCP, 1, [Listen on TCP socket])
+fi
+if test "x$LISTEN_UNIX" = xyes; then
+	AC_DEFINE(LISTEN_UNIX, 1, [Listen on Unix socket])
+fi
+if test "x$LISTEN_LOCAL" = xyes; then
+	AC_DEFINE(LISTEN_LOCAL, 1, [Listen on local socket])
+fi
+
 # The XRes extension may support client ID tracking only if it has
 # been specifically enabled. Client ID tracking is implicitly not
 # supported if XRes extension is disabled.
diff --git a/include/dix-config.h.in b/include/dix-config.h.in
index 4268b8f..f170c1c 100644
--- a/include/dix-config.h.in
+++ b/include/dix-config.h.in
@@ -493,4 +493,13 @@
 /* byte order */
 #undef X_BYTE_ORDER
 
+/* Listen on TCP socket */
+#undef LISTEN_TCP
+
+/* Listen on Unix socket */
+#undef LISTEN_UNIX
+
+/* Listen on local socket */
+#undef LISTEN_LOCAL
+
 #endif /* _DIX_CONFIG_H_ */
diff --git a/man/Xserver.man b/man/Xserver.man
index 7a74e85..c03830c 100644
--- a/man/Xserver.man
+++ b/man/Xserver.man
@@ -196,6 +196,13 @@ with
 This option may be issued multiple times to disable listening to different
 transport types.
 .TP 8
+.B \-listen \fItrans-type\fP
+enables a transport type.  For example, TCP/IP connections can be enabled
+with
+.BR "\-listen tcp" .
+This option may be issued multiple times to enable listening to different
+transport types.
+.TP 8
 .B \-noreset
 prevents a server reset when the last client connection is closed.  This
 overrides a previous
diff --git a/os/utils.c b/os/utils.c
index 2d02f92..80415c4 100644
--- a/os/utils.c
+++ b/os/utils.c
@@ -557,6 +557,7 @@ UseMsg(void)
     ErrorF("-nolock                disable the locking mechanism\n");
 #endif
     ErrorF("-nolisten string       don't listen on protocol\n");
+    ErrorF("-listen string         listen on protocol\n");
     ErrorF("-noreset               don't reset after last client exists\n");
     ErrorF("-background [none]     create root window with no background\n");
     ErrorF("-reset                 reset after last client exists\n");
@@ -646,6 +647,19 @@ VerifyDisplayName(const char *d)
     return 1;
 }
 
+static const char *defaultNoListenList[] = {
+#ifndef LISTEN_TCP
+    "tcp",
+#endif
+#ifndef LISTEN_UNIX
+    "unix",
+#endif
+#ifndef LISTEN_LOCAL
+    "local",
+#endif
+    NULL
+};
+
 /*
  * This function parses the command line. Handles device-independent fields
  * and allows ddx to handle additional fields.  It is not allowed to modify
@@ -664,6 +678,12 @@ ProcessCommandLine(int argc, char *argv[])
     PartialNetwork = TRUE;
 #endif
 
+    for (i = 0; defaultNoListenList[i] != NULL; i++) {
+        if (_XSERVTransNoListen(defaultNoListenList[i]))
+                    ErrorF("Failed to disable listen for %s transport",
+                           defaultNoListenList[i]);
+    }
+
     for (i = 1; i < argc; i++) {
         /* call ddx first, so it can peek/override if it wants */
         if ((skip = ddxProcessArgument(argc, argv, i))) {
@@ -849,6 +869,15 @@ ProcessCommandLine(int argc, char *argv[])
             else
                 UseMsg();
         }
+        else if (strcmp(argv[i], "-listen") == 0) {
+            if (++i < argc) {
+                if (_XSERVTransListen(argv[i]))
+                    ErrorF("Failed to enable listen for %s transport",
+                           argv[i]);
+            }
+            else
+                UseMsg();
+        }
         else if (strcmp(argv[i], "-noreset") == 0) {
             dispatchExceptionAtReset = 0;
         }
commit 8ada3fb32cd7dd8948eb55620de18ba03df6131d
Author: Keith Packard <keithp at keithp.com>
Date:   Sat Sep 20 10:04:11 2014 -0700

    Require xtrans 1.3.5 or newer
    
    This version of xtrans offers the TRANS(Listen) function.
    
    Signed-off-by: Keith Packard <keithp at keithp.com>

diff --git a/configure.ac b/configure.ac
index be8bff6..9066a6f 100644
--- a/configure.ac
+++ b/configure.ac
@@ -779,7 +779,7 @@ FIXESPROTO="fixesproto >= 5.0"
 DAMAGEPROTO="damageproto >= 1.1"
 XCMISCPROTO="xcmiscproto >= 1.2.0"
 BIGREQSPROTO="bigreqsproto >= 1.1.0"
-XTRANS="xtrans >= 1.3.3"
+XTRANS="xtrans >= 1.3.5"
 PRESENTPROTO="presentproto >= 1.0"
 
 dnl List of libraries that require a specific version
commit 18935b41e13b34571ffda84bde5257b8e84e6d1f
Author: Keith Packard <keithp at keithp.com>
Date:   Sat Sep 20 04:04:43 2014 -0700

    XSERVER_DTRACE needs request names from registry too
    
    The dtrace code in the server wants to log the name of each executed
    request, which it gets from the registry. Use that as an additional
    indication of when that portion of the registry should be included in
    the server build.
    
    See:
    
    http://tinderbox.x.org/builds/2014-09-19-0003/logs/xserver/#build
    
    Signed-off-by: Keith Packard <keithp at keithp.com>
    Reviewed-by: Dave Airlie <airlied at gmail.com>

diff --git a/include/registry.h b/include/registry.h
index 43c3db3..f50fa76 100644
--- a/include/registry.h
+++ b/include/registry.h
@@ -24,7 +24,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 #define X_REGISTRY_RESOURCE       1
 #endif
 
-#if defined(XSELINUX) || defined(XCSECURITY)
+#if defined(XSELINUX) || defined(XCSECURITY) || defined(XSERVER_DTRACE)
 #define X_REGISTRY_REQUEST        1
 #endif
 
commit 28337cb14e4347e1dd7936c5393a22e042866687
Author: Jon TURNEY <jon.turney at dronecode.org.uk>
Date:   Fri Sep 19 14:22:13 2014 +1000

    xserver: Move 'pragma GCC diagnostic' outside functions
    
    $ gcc --version
    gcc (Gentoo 4.4.3-r2 p1.2) 4.4.3
    
    /jhbuild/checkout/xorg/xserver/os/log.c: In function ‘LogInit’:
    /jhbuild/checkout/xorg/xserver/os/log.c:199: error: #pragma GCC diagnostic not allowed inside functions
    /jhbuild/checkout/xorg/xserver/os/log.c:201: warning: format not a string literal, argument types not checked
    /jhbuild/checkout/xorg/xserver/os/log.c:212: error: #pragma GCC diagnostic not allowed inside functions
    /jhbuild/checkout/xorg/xserver/os/log.c:214: warning: format not a string literal, argument types not checked
    
    etc.
    
    Reviewed-by: Dave Airlie <airlied at redhat.com>
    Signed-off-by: Jon TURNEY <jon.turney at dronecode.org.uk>
    Signed-off-by: Dave Airlie <airlied at redhat.com>
    Signed-off-by: Keith Packard <keithp at keithp.com>

diff --git a/hw/xfree86/os-support/linux/lnx_init.c b/hw/xfree86/os-support/linux/lnx_init.c
index 85709c6..9485307 100644
--- a/hw/xfree86/os-support/linux/lnx_init.c
+++ b/hw/xfree86/os-support/linux/lnx_init.c
@@ -76,6 +76,9 @@ switch_to(int vt, const char *from)
         FatalError("%s: VT_WAITACTIVE failed: %s\n", from, strerror(errno));
 }
 
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wformat-nonliteral"
+
 void
 xf86OpenConsole(void)
 {
@@ -166,7 +169,6 @@ xf86OpenConsole(void)
 
         i = 0;
         while (vcs[i] != NULL) {
-#pragma GCC diagnostic ignored "-Wformat-nonliteral"
             snprintf(vtname, sizeof(vtname), vcs[i], xf86Info.vtno);    /* /dev/tty1-64 */
             if ((xf86Info.consoleFd = open(vtname, O_RDWR | O_NDELAY, 0)) >= 0)
                 break;
@@ -272,6 +274,8 @@ xf86OpenConsole(void)
     }
 }
 
+#pragma GCC diagnostic pop
+
 void
 xf86CloseConsole(void)
 {
diff --git a/os/log.c b/os/log.c
index 629021e..7348ad4 100644
--- a/os/log.c
+++ b/os/log.c
@@ -189,15 +189,15 @@ strlen_sigsafe(const char *s)
  * string.
  */
 
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wformat-nonliteral"
+
 const char *
 LogInit(const char *fname, const char *backup)
 {
     char *logFileName = NULL;
 
     if (fname && *fname) {
-#if __GNUC__ > 4 || __GNUC__ == 4 && __GNUC_MINOR__ > 5
-#pragma GCC diagnostic ignored "-Wformat-nonliteral"
-#endif
         if (asprintf(&logFileName, fname, display) == -1)
             FatalError("Cannot allocate space for the log file name\n");
 
@@ -208,9 +208,6 @@ LogInit(const char *fname, const char *backup)
                 char *suffix;
                 char *oldLog;
 
-#if __GNUC__ > 4 || __GNUC__ == 4 && __GNUC_MINOR__ > 5
-#pragma GCC diagnostic ignored "-Wformat-nonliteral"
-#endif
                 if ((asprintf(&suffix, backup, display) == -1) ||
                     (asprintf(&oldLog, "%s%s", logFileName, suffix) == -1))
                     FatalError("Cannot allocate space for the log file name\n");
@@ -254,6 +251,7 @@ LogInit(const char *fname, const char *backup)
 
     return logFileName;
 }
+#pragma GCC diagnostic pop
 
 void
 LogClose(enum ExitCode error)
diff --git a/test/signal-logging.c b/test/signal-logging.c
index 4320121..3d2d048 100644
--- a/test/signal-logging.c
+++ b/test/signal-logging.c
@@ -113,12 +113,13 @@ double float_tests[] = { 0, 5, 0.1, 0.01, 5.2342, 10.2301,
                          -1, -2.00, -0.6023, -1203.30
                         };
 
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Woverflow"
+
 static void
 number_formatting(void)
 {
     int i;
-#pragma GCC diagnostic push
-#pragma GCC diagnostic ignored "-Woverflow"
     long unsigned int unsigned_tests[] = { 0,/* Zero */
                                            5, /* Single digit number */
                                            12, /* Two digit decimal number */
@@ -141,7 +142,6 @@ number_formatting(void)
                                 -0x15D027BF211B37A, /* Large > 32 bit number */
                                 -0x7FFFFFFFFFFFFFFF, /* Maximum 64-bit signed number */
     } ;
-#pragma GCC diagnostic pop
 
     for (i = 0; i < sizeof(unsigned_tests) / sizeof(unsigned_tests[0]); i++)
         assert(check_number_format_test(unsigned_tests[i]));
@@ -152,6 +152,7 @@ number_formatting(void)
     for (i = 0; i < sizeof(float_tests) / sizeof(float_tests[0]); i++)
         assert(check_float_format_test(float_tests[i]));
 }
+#pragma GCC diagnostic pop
 
 #pragma GCC diagnostic push
 #pragma GCC diagnostic ignored "-Wformat-security"
commit 7e6bd546846964fd9b8c2a06dea4782a552b62d7
Author: Keith Packard <keithp at keithp.com>
Date:   Wed Aug 6 12:58:38 2014 -0700

    glamor: Remove shader-based trapezoid implementation. Fixes Bug 76213.
    
    I can't find any performance benefit to using the GL path and the code
    renders this trapezoid incorrectly:
    
      		                 top: FIXED   29.50
    		              bottom: FIXED   30.00
    		            left top: POINT    0.00,   29.50
    		         left bottom: POINT    0.00,   30.50
    		           right top: POINT -127.50,   29.50
    		        right bottom: POINT   52.50,   30.00
    
    This should render a solid line from 0,30 to 52,30 but draws nothing.
    
    The code also uses an area computation for trapezoid coverage which
    does not conform to the Render specification which requires a specific
    point sampling technique.
    
    Signed-off-by: Keith Packard <keithp at keithp.com>
    Reviewed-by: Adam Jackson <ajax at redhat.com>

diff --git a/glamor/glamor.c b/glamor/glamor.c
index e582e50..fc24b1b 100644
--- a/glamor/glamor.c
+++ b/glamor/glamor.c
@@ -515,9 +515,6 @@ glamor_init(ScreenPtr screen, unsigned int flags)
 
     glamor_init_vbo(screen);
     glamor_init_pixmap_fbo(screen);
-#ifdef GLAMOR_TRAPEZOID_SHADER
-    glamor_init_trapezoid_shader(screen);
-#endif
     glamor_init_finish_access_shaders(screen);
 #ifdef GLAMOR_GRADIENT_SHADER
     glamor_init_gradient_shader(screen);
@@ -546,9 +543,6 @@ glamor_release_screen_priv(ScreenPtr screen)
 #endif
     glamor_fini_vbo(screen);
     glamor_fini_pixmap_fbo(screen);
-#ifdef GLAMOR_TRAPEZOID_SHADER
-    glamor_fini_trapezoid_shader(screen);
-#endif
     glamor_fini_finish_access_shaders(screen);
 #ifdef GLAMOR_GRADIENT_SHADER
     glamor_fini_gradient_shader(screen);
diff --git a/glamor/glamor_priv.h b/glamor/glamor_priv.h
index 51adeef..c089db8 100644
--- a/glamor/glamor_priv.h
+++ b/glamor/glamor_priv.h
@@ -306,9 +306,6 @@ typedef struct glamor_screen_private {
     int linear_max_nstops;
     int radial_max_nstops;
 
-    /* glamor trapezoid shader. */
-    GLint trapezoid_prog;
-
     PixmapPtr *back_pixmap;
     int screen_fbo;
     struct glamor_saved_procs saved_procs;
@@ -745,8 +742,6 @@ void glamor_composite_glyph_rects(CARD8 op,
 void glamor_composite_rects(CARD8 op,
                             PicturePtr pDst,
                             xRenderColor *color, int nRect, xRectangle *rects);
-void glamor_init_trapezoid_shader(ScreenPtr screen);
-void glamor_fini_trapezoid_shader(ScreenPtr screen);
 PicturePtr glamor_convert_gradient_picture(ScreenPtr screen,
                                            PicturePtr source,
                                            int x_source,
@@ -1089,7 +1084,6 @@ void glamor_xv_render(glamor_port_private *port_priv);
 
 #define GLAMOR_PIXMAP_DYNAMIC_UPLOAD
 #define GLAMOR_GRADIENT_SHADER
-#define GLAMOR_TRAPEZOID_SHADER
 #define GLAMOR_TEXTURED_LARGE_PIXMAP 1
 #define WALKAROUND_LARGE_TEXTURE_MAP
 #if 0
diff --git a/glamor/glamor_trapezoid.c b/glamor/glamor_trapezoid.c
index d61d11f..f8bf6c9 100644
--- a/glamor/glamor_trapezoid.c
+++ b/glamor/glamor_trapezoid.c
@@ -36,1522 +36,6 @@
 #include "mipict.h"
 #include "fbpict.h"
 
-static xFixed
-_glamor_linefixedX(xLineFixed *l, xFixed y, Bool ceil)
-{
-    xFixed dx = l->p2.x - l->p1.x;
-    xFixed_32_32 ex = (xFixed_32_32) (y - l->p1.y) * dx;
-    xFixed dy = l->p2.y - l->p1.y;
-
-    if (ceil)
-        ex += (dy - 1);
-    return l->p1.x + (xFixed) (ex / dy);
-}
-
-static xFixed
-_glamor_linefixedY(xLineFixed *l, xFixed x, Bool ceil)
-{
-    xFixed dy = l->p2.y - l->p1.y;
-    xFixed_32_32 ey = (xFixed_32_32) (x - l->p1.x) * dy;
-    xFixed dx = l->p2.x - l->p1.x;
-
-    if (ceil)
-        ey += (dx - 1);
-    return l->p1.y + (xFixed) (ey / dx);
-}
-
-#ifdef GLAMOR_TRAPEZOID_SHADER
-
-#define GLAMOR_VERTEX_TOP_BOTTOM  (GLAMOR_VERTEX_SOURCE + 1)
-#define GLAMOR_VERTEX_LEFT_PARAM  (GLAMOR_VERTEX_SOURCE + 2)
-#define GLAMOR_VERTEX_RIGHT_PARAM (GLAMOR_VERTEX_SOURCE + 3)
-
-#define DEBUG_CLIP_VTX 0
-
-#define POINT_INSIDE_CLIP_RECT(point, rect)	\
-    (point[0] >= IntToxFixed(rect->x1)		\
-     && point[0] <= IntToxFixed(rect->x2) 	\
-     && point[1] >= IntToxFixed(rect->y1)	\
-     && point[1] <= IntToxFixed(rect->y2))
-
-static xFixed
-_glamor_lines_crossfixedY(xLineFixed *l, xLineFixed *r)
-{
-    xFixed dx1 = l->p2.x - l->p1.x;
-    xFixed dx2 = r->p2.x - r->p1.x;
-    xFixed dy1 = l->p2.y - l->p1.y;
-    xFixed dy2 = r->p2.y - r->p1.y;
-    xFixed_32_32 tmp = (xFixed_32_32) dy2 * dy1;
-    xFixed_32_32 dividend1 = (tmp >> 32) * (l->p1.x - r->p1.x);
-    xFixed_32_32 dividend2;
-    xFixed_32_32 dividend3;
-    xFixed_32_32 divisor;
-
-    tmp = (xFixed_32_32) dx1 *dy2;
-
-    dividend2 = (tmp >> 32) * l->p1.y;
-    tmp = (xFixed_32_32) dy1 *dx2;
-
-    dividend3 = (tmp >> 32) * r->p1.y;
-    divisor = ((xFixed_32_32) dx1 * (xFixed_32_32) dy2
-               - (xFixed_32_32) dy1 * (xFixed_32_32) dx2) >> 32;
-
-    if (divisor)
-        return (xFixed) ((dividend2 - dividend1 - dividend3) / divisor);
-
-    return 0xFFFFFFFF;
-}
-
-static Bool
-point_inside_trapezoid(int point[2], xTrapezoid *trap, xFixed cut_y)
-{
-    int ret = TRUE;
-    int tmp;
-
-    if (point[1] > trap->bottom) {
-        ret = FALSE;
-        if (DEBUG_CLIP_VTX) {
-            ErrorF("Out of Trap bottom, point[1] = %d(0x%x)), "
-                   "bottom = %d(0x%x)\n",
-                   (unsigned int) xFixedToInt(point[1]), point[1],
-                   (unsigned int) xFixedToInt(trap->bottom),
-                   (unsigned int) trap->bottom);
-        }
-
-        return ret;
-    }
-
-    if (point[1] < trap->top) {
-        ret = FALSE;
-        if (DEBUG_CLIP_VTX) {
-            ErrorF("Out of Trap top, point[1] = %d(0x%x)), "
-                   "top = %d(0x%x)\n",
-                   (unsigned int) xFixedToInt(point[1]), point[1],
-                   (unsigned int) xFixedToInt(trap->top),
-                   (unsigned int) trap->top);
-        }
-
-        return ret;
-    }
-
-    tmp = _glamor_linefixedX(&trap->left, point[1], FALSE);
-    if (point[0] < tmp) {
-        ret = FALSE;
-
-        if (abs(cut_y - trap->top) < pixman_fixed_1_minus_e &&
-            abs(point[1] - trap->top) < pixman_fixed_1_minus_e &&
-            tmp - point[0] < pixman_fixed_1_minus_e) {
-            ret = TRUE;
-        }
-        else if (abs(cut_y - trap->bottom) < pixman_fixed_1_minus_e &&
-                 point[1] - trap->bottom < pixman_fixed_1_minus_e &&
-                 tmp - point[0] < pixman_fixed_1_minus_e) {
-            ret = TRUE;
-        }
-
-        if (DEBUG_CLIP_VTX && !ret) {
-            ErrorF("Out of Trap left, point[0] = %d(0x%x)), "
-                   "left = %d(0x%x)\n",
-                   (unsigned int) xFixedToInt(point[0]), point[0],
-                   (unsigned int) xFixedToInt(tmp), (unsigned int) tmp);
-        }
-
-        if (!ret)
-            return ret;
-    }
-
-    tmp = _glamor_linefixedX(&trap->right, point[1], TRUE);
-    if (point[0] > tmp) {
-        ret = FALSE;
-
-        if (abs(cut_y - trap->top) < pixman_fixed_1_minus_e &&
-            abs(point[1] - trap->top) < pixman_fixed_1_minus_e &&
-            point[0] - tmp < pixman_fixed_1_minus_e) {
-            ret = TRUE;
-        }
-        else if (abs(cut_y - trap->bottom) < pixman_fixed_1_minus_e &&
-                 abs(point[1] - trap->bottom) < pixman_fixed_1_minus_e &&
-                 point[0] - tmp < pixman_fixed_1_minus_e) {
-            ret = TRUE;
-        }
-
-        if (DEBUG_CLIP_VTX && !ret) {
-            ErrorF("Out of Trap right, point[0] = %d(0x%x)), "
-                   "right = %d(0x%x)\n",
-                   (unsigned int) xFixedToInt(point[0]), point[0],
-                   (unsigned int) xFixedToInt(tmp), (unsigned int) tmp);
-        }
-
-        if (!ret)
-            return ret;
-    }
-
-    return ret;
-}
-
-static void
-glamor_emit_composite_vert(ScreenPtr screen,
-                           float *vb,
-                           const float *src_coords,
-                           const float *mask_coords,
-                           const float *dst_coords, int i)
-{
-    glamor_screen_private *glamor_priv = glamor_get_screen_private(screen);
-    int j = 0;
-
-    vb += i * glamor_priv->vb_stride / sizeof(float);
-
-    vb[j++] = dst_coords[i * 2 + 0];
-    vb[j++] = dst_coords[i * 2 + 1];
-    if (glamor_priv->has_source_coords) {
-        vb[j++] = src_coords[i * 2 + 0];
-        vb[j++] = src_coords[i * 2 + 1];
-    }
-    if (glamor_priv->has_mask_coords) {
-        vb[j++] = mask_coords[i * 2 + 0];
-        vb[j++] = mask_coords[i * 2 + 1];
-    }
-
-    glamor_priv->render_nr_verts++;
-}
-
-static void
-glamor_emit_composite_triangle(ScreenPtr screen,
-                               float *vb,
-                               const float *src_coords,
-                               const float *mask_coords,
-                               const float *dst_coords)
-{
-    glamor_emit_composite_vert(screen, vb,
-                               src_coords, mask_coords, dst_coords, 0);
-    glamor_emit_composite_vert(screen, vb,
-                               src_coords, mask_coords, dst_coords, 1);
-    glamor_emit_composite_vert(screen, vb,
-                               src_coords, mask_coords, dst_coords, 2);
-}
-
-static void
-glamor_flush_composite_triangles(ScreenPtr screen)
-{
-    glamor_screen_private *glamor_priv = glamor_get_screen_private(screen);
-
-    glamor_make_current(glamor_priv);
-    glamor_put_vbo_space(screen);
-
-    if (!glamor_priv->render_nr_verts)
-        return;
-
-    glDrawArrays(GL_TRIANGLES, 0, glamor_priv->render_nr_verts);
-}
-
-static Bool
-_glamor_clip_trapezoid_vertex(xTrapezoid *trap, BoxPtr pbox,
-                              int vertex[6], int *num)
-{
-    xFixed edge_cross_y = 0xFFFFFFFF;
-    int tl[2];
-    int bl[2];
-    int tr[2];
-    int br[2];
-    int left_cut_top[2];
-    int left_cut_left[2];
-    int left_cut_right[2];
-    int left_cut_bottom[2];
-    int right_cut_top[2];
-    int right_cut_left[2];
-    int right_cut_right[2];
-    int right_cut_bottom[2];
-    int tmp[2];
-    int tmp_vtx[20 * 2];
-    float tmp_vtx_slope[20];
-    BoxRec trap_bound;
-    int i = 0;
-    int vertex_num = 0;
-
-    if (DEBUG_CLIP_VTX) {
-        ErrorF
-            ("The parameter of xTrapezoid is:\ntop: %d  0x%x\tbottom: %d  0x%x\n"
-             "left:  p1 (%d   0x%x, %d   0x%x)\tp2 (%d   0x%x, %d   0x%x)\n"
-             "right: p1 (%d   0x%x, %d   0x%x)\tp2 (%d   0x%x, %d   0x%x)\n",
-             xFixedToInt(trap->top), (unsigned int) trap->top,
-             xFixedToInt(trap->bottom), (unsigned int) trap->bottom,
-             xFixedToInt(trap->left.p1.x), (unsigned int) trap->left.p1.x,
-             xFixedToInt(trap->left.p1.y), (unsigned int) trap->left.p1.y,
-             xFixedToInt(trap->left.p2.x), (unsigned int) trap->left.p2.x,
-             xFixedToInt(trap->left.p2.y), (unsigned int) trap->left.p2.y,
-             xFixedToInt(trap->right.p1.x), (unsigned int) trap->right.p1.x,
-             xFixedToInt(trap->right.p1.y), (unsigned int) trap->right.p1.y,
-             xFixedToInt(trap->right.p2.x), (unsigned int) trap->right.p2.x,
-             xFixedToInt(trap->right.p2.y), (unsigned int) trap->right.p2.y);
-    }
-
-    miTrapezoidBounds(1, trap, &trap_bound);
-    if (DEBUG_CLIP_VTX)
-        ErrorF("The bounds for this traps is: bounds.x1 = %d, bounds.x2 = %d, "
-               "bounds.y1 = %d, bounds.y2 = %d\n", trap_bound.x1, trap_bound.x2,
-               trap_bound.y1, trap_bound.y2);
-
-    if (trap_bound.x1 > pbox->x2 || trap_bound.x2 < pbox->x1)
-        return FALSE;
-    if (trap_bound.y1 > pbox->y2 || trap_bound.y2 < pbox->y1)
-        return FALSE;
-
-#define IS_TRAP_EDGE_VERTICAL(edge)		\
-	(edge->p1.x == edge->p2.x)
-
-#define CACULATE_CUT_VERTEX(vtx, cal_x, ceil, vh_edge, edge)		\
-	do {								\
-	    if(cal_x) {							\
-		vtx[1] = (vh_edge);					\
-		vtx[0] = (_glamor_linefixedX(				\
-			      edge, vh_edge, ceil));			\
-		if(DEBUG_CLIP_VTX)					\
-		    ErrorF("The intersection point of line y=%d and "	\
-			   "line of p1:(%d,%d) -- p2 (%d,%d) "		\
-			   "is (%d, %d)\n",				\
-			   xFixedToInt(vh_edge),			\
-			   xFixedToInt(edge->p1.x),			\
-			   xFixedToInt(edge->p1.y),			\
-			   xFixedToInt(edge->p2.x),			\
-			   xFixedToInt(edge->p2.y),			\
-			   xFixedToInt(vtx[0]),				\
-			   xFixedToInt(vtx[1]));			\
-	    } else {							\
-		vtx[0] = (vh_edge);					\
-		vtx[1] = (_glamor_linefixedY(				\
-			      edge, vh_edge, ceil));			\
-		if(DEBUG_CLIP_VTX)					\
-		    ErrorF("The intersection point of line x=%d and "	\
-			   "line of p1:(%d,%d) -- p2 (%d,%d) "		\
-			   "is (%d, %d)\n",				\
-			   xFixedToInt(vh_edge),			\
-			   xFixedToInt(edge->p1.x),			\
-			   xFixedToInt(edge->p1.y),			\
-			   xFixedToInt(edge->p2.x),			\
-			   xFixedToInt(edge->p2.y),			\
-			   xFixedToInt(vtx[0]),				\
-			   xFixedToInt(vtx[1]));			\
-	    }								\
-	} while(0)
-
-#define ADD_VERTEX_IF_INSIDE(vtx)				\
-	if(POINT_INSIDE_CLIP_RECT(vtx, pbox)			\
-	   && point_inside_trapezoid(vtx, trap, edge_cross_y)){	\
-	    tmp_vtx[vertex_num] = xFixedToInt(vtx[0]);		\
-	    tmp_vtx[vertex_num + 1] = xFixedToInt(vtx[1]);	\
-	    vertex_num += 2;					\
-	    if(DEBUG_CLIP_VTX)					\
-		ErrorF("@ Point: (%d, %d) is inside "		\
-		       "the Rect and Trapezoid\n",		\
-		       xFixedToInt(vtx[0]),			\
-		       xFixedToInt(vtx[1]));			\
-	} else if(DEBUG_CLIP_VTX){				\
-	    ErrorF("X Point: (%d, %d) is outside "		\
-		   "the Rect and Trapezoid\t",			\
-		   xFixedToInt(vtx[0]),				\
-		   xFixedToInt(vtx[1]));			\
-	    if(POINT_INSIDE_CLIP_RECT(vtx, pbox))		\
-		ErrorF("The Point is outside "			\
-		       "the Trapezoid\n");			\
-	    else						\
-		ErrorF("The Point is outside "			\
-		       "the Rect\n");				\
-	}
-
-    /*Trap's right edge cut right edge. */
-    if ((!IS_TRAP_EDGE_VERTICAL((&trap->left))) ||
-        (!IS_TRAP_EDGE_VERTICAL((&trap->right)))) {
-        edge_cross_y = _glamor_lines_crossfixedY((&trap->left), (&trap->right));
-        if (DEBUG_CLIP_VTX) {
-            ErrorF("Trap's left edge cut right edge at %d(0x%x), "
-                   "trap_top = %x, trap_bottom = %x\n",
-                   xFixedToInt(edge_cross_y), edge_cross_y,
-                   (unsigned int) trap->top, (unsigned int) trap->bottom);
-        }
-    }
-
-    /*Trap's TopLeft, BottomLeft, TopRight and BottomRight. */
-    CACULATE_CUT_VERTEX(tl, 1, FALSE, trap->top, (&trap->left));
-    CACULATE_CUT_VERTEX(bl, 1, FALSE, trap->bottom, (&trap->left));
-    CACULATE_CUT_VERTEX(tr, 1, TRUE, trap->top, (&trap->right));
-    CACULATE_CUT_VERTEX(br, 1, TRUE, trap->bottom, (&trap->right));
-
-    if (DEBUG_CLIP_VTX)
-        ErrorF("Trap's TopLeft, BottomLeft, TopRight and BottomRight\n");
-    if (DEBUG_CLIP_VTX)
-        ErrorF("Caculate the vertex of trapezoid:\n"
-               "      (%3d, %3d)-------------------------(%3d, %3d)\n"
-               "              /                           \\       \n"
-               "             /                             \\      \n"
-               "            /                               \\     \n"
-               "  (%3d, %3d)---------------------------------(%3d, %3d)\n"
-               "Clip with rect:\n"
-               "  (%3d, %3d)------------------------(%3d, %3d)    \n"
-               "           |                        |             \n"
-               "           |                        |             \n"
-               "           |                        |             \n"
-               "  (%3d, %3d)------------------------(%3d, %3d)    \n",
-               xFixedToInt(tl[0]), xFixedToInt(tl[1]), xFixedToInt(tr[0]),
-               xFixedToInt(tr[1]), xFixedToInt(bl[0]), xFixedToInt(bl[1]),
-               xFixedToInt(br[0]), xFixedToInt(br[1]),
-               pbox->x1, pbox->y1, pbox->x2, pbox->y1, pbox->x1, pbox->y2,
-               pbox->x2, pbox->y2);
-
-    ADD_VERTEX_IF_INSIDE(tl);
-    ADD_VERTEX_IF_INSIDE(bl);
-    ADD_VERTEX_IF_INSIDE(tr);
-    ADD_VERTEX_IF_INSIDE(br);
-
-    /*Trap's left edge cut Rect. */
-    if (DEBUG_CLIP_VTX)
-        ErrorF("Trap's left edge cut Rect\n");
-    CACULATE_CUT_VERTEX(left_cut_top, 1, FALSE, IntToxFixed(pbox->y1),
-                        (&trap->left));
-    ADD_VERTEX_IF_INSIDE(left_cut_top);
-    if (!IS_TRAP_EDGE_VERTICAL((&trap->left))) {
-        CACULATE_CUT_VERTEX(left_cut_left, 0, FALSE, IntToxFixed(pbox->x1),
-                            (&trap->left));
-        ADD_VERTEX_IF_INSIDE(left_cut_left);
-    }
-    CACULATE_CUT_VERTEX(left_cut_bottom, 1, FALSE, IntToxFixed(pbox->y2),
-                        (&trap->left));
-    ADD_VERTEX_IF_INSIDE(left_cut_bottom);
-    if (!IS_TRAP_EDGE_VERTICAL((&trap->left))) {
-        CACULATE_CUT_VERTEX(left_cut_right, 0, FALSE, IntToxFixed(pbox->x2),
-                            (&trap->left));
-        ADD_VERTEX_IF_INSIDE(left_cut_right);
-    }
-
-    /*Trap's right edge cut Rect. */
-    if (DEBUG_CLIP_VTX)
-        ErrorF("Trap's right edge cut Rect\n");
-    CACULATE_CUT_VERTEX(right_cut_top, 1, TRUE, IntToxFixed(pbox->y1),
-                        (&trap->right));
-    ADD_VERTEX_IF_INSIDE(right_cut_top);
-    if (!IS_TRAP_EDGE_VERTICAL((&trap->right))) {
-        CACULATE_CUT_VERTEX(right_cut_left, 0, TRUE, IntToxFixed(pbox->x1),
-                            (&trap->right));
-        ADD_VERTEX_IF_INSIDE(right_cut_left);
-    }
-    CACULATE_CUT_VERTEX(right_cut_bottom, 1, TRUE, IntToxFixed(pbox->y2),
-                        (&trap->right));
-    ADD_VERTEX_IF_INSIDE(right_cut_bottom);
-    if (!IS_TRAP_EDGE_VERTICAL((&trap->right))) {
-        CACULATE_CUT_VERTEX(right_cut_right, 0, TRUE, IntToxFixed(pbox->x2),
-                            (&trap->right));
-        ADD_VERTEX_IF_INSIDE(right_cut_right);
-    }
-
-    /* Trap's top cut Left and Right of rect. */
-    if (DEBUG_CLIP_VTX)
-        ErrorF("Trap's top cut Left and Right of rect\n");
-    tmp[0] = IntToxFixed(pbox->x1);
-    tmp[1] = trap->top;
-    ADD_VERTEX_IF_INSIDE(tmp);
-    tmp[0] = IntToxFixed(pbox->x2);
-    tmp[1] = trap->top;
-    ADD_VERTEX_IF_INSIDE(tmp);
-
-    /* Trap's bottom cut Left and Right of rect. */
-    if (DEBUG_CLIP_VTX)
-        ErrorF("Trap's bottom cut Left and Right of rect\n");
-    tmp[0] = IntToxFixed(pbox->x1);
-    tmp[1] = trap->bottom;
-    ADD_VERTEX_IF_INSIDE(tmp);
-    tmp[0] = IntToxFixed(pbox->x2);
-    tmp[1] = trap->bottom;
-    ADD_VERTEX_IF_INSIDE(tmp);
-
-    /* The orginal 4 vertex of rect. */
-    if (DEBUG_CLIP_VTX)
-        ErrorF("The orginal 4 vertex of rect\n");
-    tmp[0] = IntToxFixed(pbox->x1);
-    tmp[1] = IntToxFixed(pbox->y1);
-    ADD_VERTEX_IF_INSIDE(tmp);
-    tmp[0] = IntToxFixed(pbox->x1);
-    tmp[1] = IntToxFixed(pbox->y2);
-    ADD_VERTEX_IF_INSIDE(tmp);
-    tmp[0] = IntToxFixed(pbox->x2);
-    tmp[1] = IntToxFixed(pbox->y2);
-    ADD_VERTEX_IF_INSIDE(tmp);
-    tmp[0] = IntToxFixed(pbox->x2);
-    tmp[1] = IntToxFixed(pbox->y1);
-    ADD_VERTEX_IF_INSIDE(tmp);
-
-    if (DEBUG_CLIP_VTX) {
-        ErrorF("\nThe candidate vertex number is %d\n", vertex_num / 2);
-        for (i = 0; i < vertex_num / 2; i++) {
-            ErrorF("(%d, %d) ", tmp_vtx[2 * i], tmp_vtx[2 * i + 1]);
-        }
-        ErrorF("\n");
-    }
-
-    /* Sort the vertex by X and then Y. */
-    for (i = 0; i < vertex_num / 2; i++) {
-        int j;
-
-        for (j = 0; j < vertex_num / 2 - i - 1; j++) {
-            if (tmp_vtx[2 * j] > tmp_vtx[2 * (j + 1)]
-                || (tmp_vtx[2 * j] == tmp_vtx[2 * (j + 1)]
-                    && tmp_vtx[2 * j + 1] > tmp_vtx[2 * (j + 1) + 1])) {
-                tmp[0] = tmp_vtx[2 * j];
-                tmp[1] = tmp_vtx[2 * j + 1];
-                tmp_vtx[2 * j] = tmp_vtx[2 * (j + 1)];
-                tmp_vtx[2 * j + 1] = tmp_vtx[2 * (j + 1) + 1];
-                tmp_vtx[2 * (j + 1)] = tmp[0];
-                tmp_vtx[2 * (j + 1) + 1] = tmp[1];
-            }
-        }
-
-    }
-
-    if (DEBUG_CLIP_VTX) {
-        ErrorF("\nAfter sort vertex number is:\n");
-        for (i = 0; i < vertex_num / 2; i++) {
-            ErrorF("(%d, %d) ", tmp_vtx[2 * i], tmp_vtx[2 * i + 1]);
-        }
-        ErrorF("\n");
-    }
-
-    memset(vertex, -1, 2 * 6);
-    *num = 0;
-
-    for (i = 0; i < vertex_num / 2; i++) {
-        if (*num > 0 && vertex[2 * (*num - 1)] == tmp_vtx[2 * i]
-            && vertex[2 * (*num - 1) + 1] == tmp_vtx[2 * i + 1]) {
-            /*same vertex. */
-            if (DEBUG_CLIP_VTX)
-                ErrorF("X Point:(%d, %d) discard\n",
-                       tmp_vtx[2 * i], tmp_vtx[2 * i + 1]);
-            continue;
-        }
-
-        (*num)++;
-        if (*num > 6) {
-            if (DEBUG_CLIP_VTX)
-                FatalError("Trapezoid clip with Rect can never have vtx"
-                           "number bigger than 6\n");
-            else {
-                ErrorF("Trapezoid clip with Rect can never have vtx"
-                       "number bigger than 6\n");
-                *num = 6;
-                break;
-            }
-        }
-
-        vertex[2 * (*num - 1)] = tmp_vtx[2 * i];
-        vertex[2 * (*num - 1) + 1] = tmp_vtx[2 * i + 1];
-        if (DEBUG_CLIP_VTX)
-            ErrorF("@ Point:(%d, %d) select, num now is %d\n",
-                   tmp_vtx[2 * i], tmp_vtx[2 * i + 1], *num);
-    }
-
-    /* Now we need to arrange the vtx in the polygon's counter-clockwise
-       order. We first select the left and top point as the start point and
-       sort every vtx by the slope from vtx to the start vtx. */
-    for (i = 1; i < *num; i++) {
-        tmp_vtx_slope[i] = (vertex[2 * i] != vertex[0] ?
-                            (float) (vertex[2 * i + 1] -
-                                     vertex[1]) / (float) (vertex[2 * i] -
-                                                           vertex[0])
-                            : (float) INT_MAX);
-    }
-
-    if (DEBUG_CLIP_VTX) {
-        ErrorF("\nvtx number: %d, VTX and slope:\n", *num);
-        for (i = 0; i < *num; i++) {
-            ErrorF("(%d, %d):%f ",
-                   vertex[2 * i], vertex[2 * i + 1], tmp_vtx_slope[i]);
-        }
-        ErrorF("\n");
-    }
-
-    /* Sort the vertex by slope. */
-    for (i = 0; i < *num - 1; i++) {
-        int j;
-        float tmp_slope;
-
-        for (j = 1; j < *num - i - 1; j++) {
-            if (tmp_vtx_slope[j] < tmp_vtx_slope[j + 1]) {
-                tmp_slope = tmp_vtx_slope[j];
-                tmp_vtx_slope[j] = tmp_vtx_slope[j + 1];
-                tmp_vtx_slope[j + 1] = tmp_slope;
-                tmp[0] = vertex[2 * j];
-                tmp[1] = vertex[2 * j + 1];
-                vertex[2 * j] = vertex[2 * (j + 1)];
-                vertex[2 * j + 1] = vertex[2 * (j + 1) + 1];
-                vertex[2 * (j + 1)] = tmp[0];
-                vertex[2 * (j + 1) + 1] = tmp[1];
-            }
-        }
-    }
-
-    if (DEBUG_CLIP_VTX) {
-        ErrorF("\nBefore return, vtx number: %d, VTX and slope:\n", *num);
-        for (i = 0; i < *num; i++) {
-            ErrorF("(%d, %d):%f ",
-                   vertex[2 * i], vertex[2 * i + 1], tmp_vtx_slope[i]);
-        }
-        ErrorF("\n");
-    }
-
-    return TRUE;
-}
-
-static void *
-glamor_setup_composite_vbo_for_trapezoid(ScreenPtr screen, int n_verts)
-{
-    glamor_screen_private *glamor_priv = glamor_get_screen_private(screen);
-    int stride;
-    int vert_size;
-    char *vbo_offset;
-    void *vb;
-
-    glamor_priv->render_nr_verts = 0;
-
-    /* For GLAMOR_VERTEX_POS */
-    glamor_priv->vb_stride = 2 * sizeof(float);
-
-    /* For GLAMOR_GLAMOR_VERTEX_SOURCE */
-    glamor_priv->vb_stride += 2 * sizeof(float);
-
-    /* For GLAMOR_VERTEX_TOP_BOTTOM */
-    glamor_priv->vb_stride += 2 * sizeof(float);
-
-    /* For GLAMOR_VERTEX_LEFT_PARAM */
-    glamor_priv->vb_stride += 4 * sizeof(float);
-
-    /* For GLAMOR_VERTEX_RIGHT_PARAM */
-    glamor_priv->vb_stride += 4 * sizeof(float);
-
-    vert_size = n_verts * glamor_priv->vb_stride;
-
-    glamor_make_current(glamor_priv);
-
-    glDisableVertexAttribArray(GLAMOR_VERTEX_POS);
-    glDisableVertexAttribArray(GLAMOR_VERTEX_SOURCE);
-    glDisableVertexAttribArray(GLAMOR_VERTEX_TOP_BOTTOM);
-    glDisableVertexAttribArray(GLAMOR_VERTEX_LEFT_PARAM);
-    glDisableVertexAttribArray(GLAMOR_VERTEX_RIGHT_PARAM);
-
-    vb = glamor_get_vbo_space(screen, vert_size, &vbo_offset);
-
-    /* Set the vertex pointer. */
-    glVertexAttribPointer(GLAMOR_VERTEX_POS, 2, GL_FLOAT,
-                          GL_FALSE, glamor_priv->vb_stride,
-                          vbo_offset);
-    glEnableVertexAttribArray(GLAMOR_VERTEX_POS);
-    stride = 2;
-
-    glVertexAttribPointer(GLAMOR_VERTEX_SOURCE, 2, GL_FLOAT,
-                          GL_FALSE, glamor_priv->vb_stride,
-                          vbo_offset + stride * sizeof(float));
-    glEnableVertexAttribArray(GLAMOR_VERTEX_SOURCE);
-    stride += 2;
-
-    glVertexAttribPointer(GLAMOR_VERTEX_TOP_BOTTOM, 2, GL_FLOAT,
-                          GL_FALSE, glamor_priv->vb_stride,
-                          vbo_offset + stride * sizeof(float));
-    glEnableVertexAttribArray(GLAMOR_VERTEX_TOP_BOTTOM);
-    stride += 2;
-
-    glVertexAttribPointer(GLAMOR_VERTEX_LEFT_PARAM, 4, GL_FLOAT,
-                          GL_FALSE, glamor_priv->vb_stride,
-                          vbo_offset + stride * sizeof(float));
-    glEnableVertexAttribArray(GLAMOR_VERTEX_LEFT_PARAM);
-    stride += 4;
-
-    glVertexAttribPointer(GLAMOR_VERTEX_RIGHT_PARAM, 4, GL_FLOAT,
-                          GL_FALSE, glamor_priv->vb_stride,
-                          vbo_offset + stride * sizeof(float));
-    glEnableVertexAttribArray(GLAMOR_VERTEX_RIGHT_PARAM);
-
-    return vb;
-}
-
-static Bool
-_glamor_trapezoids_with_shader(CARD8 op,
-                               PicturePtr src, PicturePtr dst,
-                               PictFormatPtr mask_format, INT16 x_src,
-                               INT16 y_src, int ntrap, xTrapezoid * traps)
-{
-    ScreenPtr screen = dst->pDrawable->pScreen;
-    glamor_screen_private *glamor_priv = glamor_get_screen_private(screen);
-    struct shader_key key;
-    glamor_composite_shader *shader = NULL;
-    struct blendinfo op_info;
-    PictFormatShort saved_source_format = 0;
-    PixmapPtr source_pixmap = NULL;
-    PixmapPtr dest_pixmap = NULL;
-    glamor_pixmap_private *source_pixmap_priv = NULL;
-    glamor_pixmap_private *dest_pixmap_priv = NULL;
-    glamor_pixmap_private *temp_src_priv = NULL;
-    int x_temp_src, y_temp_src;
-    int src_width, src_height;
-    int source_x_off, source_y_off;
-    GLfloat src_xscale = 1, src_yscale = 1;
-    int x_dst, y_dst;
-    int dest_x_off, dest_y_off;
-    GLfloat dst_xscale, dst_yscale;
-    BoxRec bounds;
-    PicturePtr temp_src = src;
-    int vert_stride = 3;
-    int ntriangle_per_loop;
-    int nclip_rect;
-    int mclip_rect;
-    int clip_processed;
-    int clipped_vtx[6 * 2];
-    RegionRec region;
-    BoxPtr box = NULL;
-    BoxPtr pbox = NULL;
-    int traps_count = 0;
-    int traps_not_completed = 0;
-    xTrapezoid *ptrap = NULL;
-    int nbox;
-    float src_matrix[9];
-    Bool ret = FALSE;
-
-    /* If a mask format wasn't provided, we get to choose, but behavior should
-     * be as if there was no temporary mask the traps were accumulated into.
-     */
-    if (!mask_format) {
-        if (dst->polyEdge == PolyEdgeSharp)
-            mask_format = PictureMatchFormat(screen, 1, PICT_a1);
-        else
-            mask_format = PictureMatchFormat(screen, 8, PICT_a8);
-        for (; ntrap; ntrap--, traps++)
-            glamor_trapezoids(op, src, dst, mask_format, x_src,
-                              y_src, 1, traps);
-        return TRUE;
-    }
-
-    miTrapezoidBounds(ntrap, traps, &bounds);
-    DEBUGF("The bounds for all traps is: bounds.x1 = %d, bounds.x2 = %d, "
-           "bounds.y1 = %d, bounds.y2 = %d\n", bounds.x1, bounds.x2,
-           bounds.y1, bounds.y2);
-
-    /* No area need to render. */
-    if (bounds.y1 >= bounds.y2 || bounds.x1 >= bounds.x2)
-        return TRUE;
-
-    dest_pixmap = glamor_get_drawable_pixmap(dst->pDrawable);
-    dest_pixmap_priv = glamor_get_pixmap_private(dest_pixmap);
-
-    if (!GLAMOR_PIXMAP_PRIV_HAS_FBO(dest_pixmap_priv)
-        || dest_pixmap_priv->type == GLAMOR_TEXTURE_LARGE) {
-        /* Currently. Always fallback to cpu if destination is in CPU memory. */
-        ret = FALSE;
-        DEBUGF("dst pixmap has no FBO.\n");
-        goto TRAPEZOID_OUT;
-    }
-
-    if (src->pDrawable) {
-        source_pixmap = glamor_get_drawable_pixmap(src->pDrawable);
-        source_pixmap_priv = glamor_get_pixmap_private(source_pixmap);
-        temp_src_priv = source_pixmap_priv;
-        if (source_pixmap_priv
-            && (source_pixmap_priv->type == GLAMOR_DRM_ONLY
-                || source_pixmap_priv->type == GLAMOR_TEXTURE_LARGE)) {
-            ret = FALSE;
-            goto TRAPEZOID_OUT;
-        }
-    }
-
-    x_dst = bounds.x1;
-    y_dst = bounds.y1;
-
-    src_width = bounds.x2 - bounds.x1;
-    src_height = bounds.y2 - bounds.y1;
-
-    x_temp_src = x_src + bounds.x1 - (traps[0].left.p1.x >> 16);
-    y_temp_src = y_src + bounds.y1 - (traps[0].left.p1.y >> 16);
-
-    if ((!src->pDrawable && (src->pSourcePict->type != SourcePictTypeSolidFill))        //1. The Gradient case.
-        /* 2. Has no fbo but can upload. */
-        || (src->pDrawable && !GLAMOR_PIXMAP_PRIV_HAS_FBO(source_pixmap_priv)
-            && ((src_width * src_height * 4 <
-                 source_pixmap->drawable.width * source_pixmap->drawable.height)
-                || !glamor_check_fbo_size(glamor_priv,
-                                          source_pixmap->drawable.width,
-                                          source_pixmap->drawable.height)))) {
-
-        if (!glamor_check_fbo_size(glamor_priv, src_width, src_height)) {
-            ret = FALSE;
-            goto TRAPEZOID_OUT;
-        }
-        temp_src = glamor_convert_gradient_picture(screen, src,
-                                                   x_src, y_src,
-                                                   src_width, src_height);
-        if (!temp_src) {
-            temp_src = src;
-            ret = FALSE;
-            DEBUGF("Convert gradient picture failed\n");
-            goto TRAPEZOID_OUT;
-        }
-        temp_src_priv =
-            glamor_get_pixmap_private((PixmapPtr) temp_src->pDrawable);
-        x_temp_src = y_temp_src = 0;
-    }
-
-    x_dst += dst->pDrawable->x;
-    y_dst += dst->pDrawable->y;
-    if (temp_src->pDrawable) {
-        x_temp_src += temp_src->pDrawable->x;
-        y_temp_src += temp_src->pDrawable->y;
-    }
-
-    if (!miComputeCompositeRegion(&region,
-                                  temp_src, NULL, dst,
-                                  x_temp_src, y_temp_src,
-                                  0, 0, x_dst, y_dst, src_width, src_height)) {
-        DEBUGF("All the regions are clipped out, do nothing\n");
-        goto TRAPEZOID_OUT;
-    }
-
-    glamor_make_current(glamor_priv);
-
-    box = REGION_RECTS(&region);
-    nbox = REGION_NUM_RECTS(&region);
-    pbox = box;
-
-    ret = glamor_composite_choose_shader(op, temp_src, NULL, dst,
-                                         temp_src_priv, NULL, dest_pixmap_priv,
-                                         &key, &shader, &op_info,
-                                         &saved_source_format);
-    if (ret == FALSE) {
-        DEBUGF("can not set the shader program for composite\n");
-        goto TRAPEZOID_RESET_GL;
-    }
-    glamor_set_destination_pixmap_priv_nc(dest_pixmap_priv);
-    glamor_composite_set_shader_blend(dest_pixmap_priv, &key, shader, &op_info);
-    glamor_priv->has_source_coords = key.source != SHADER_SOURCE_SOLID;
-    glamor_priv->has_mask_coords = (key.mask != SHADER_MASK_NONE &&
-                                    key.mask != SHADER_MASK_SOLID);
-
-    glamor_get_drawable_deltas(dst->pDrawable, dest_pixmap,
-                               &dest_x_off, &dest_y_off);
-
-    pixmap_priv_get_dest_scale(dest_pixmap_priv, &dst_xscale, &dst_yscale);
-
-    if (glamor_priv->has_source_coords) {
-        source_pixmap = glamor_get_drawable_pixmap(temp_src->pDrawable);
-        source_pixmap_priv = glamor_get_pixmap_private(source_pixmap);
-        glamor_get_drawable_deltas(temp_src->pDrawable,
-                                   source_pixmap, &source_x_off, &source_y_off);
-        pixmap_priv_get_scale(source_pixmap_priv, &src_xscale, &src_yscale);
-        glamor_picture_get_matrixf(temp_src, src_matrix);
-        vert_stride += 3;
-    }
-
-    if (glamor_priv->has_mask_coords) {
-        DEBUGF("Should never have mask coords here!\n");
-        ret = FALSE;
-        goto TRAPEZOID_RESET_GL;
-    }
-
-    /* A trapezoid clip with a rectangle will at most generate a hexagon,
-       which can be devided into 4 triangles to render. */
-    ntriangle_per_loop =
-        (vert_stride * nbox * ntrap * 4) >
-        GLAMOR_COMPOSITE_VBO_VERT_CNT ? (GLAMOR_COMPOSITE_VBO_VERT_CNT /
-                                         vert_stride) : nbox * ntrap * 4;
-    ntriangle_per_loop = (ntriangle_per_loop / 4) * 4;
-
-    nclip_rect = nbox;
-    while (nclip_rect) {
-        float *vb;
-
-        mclip_rect = (nclip_rect * ntrap * 4) > ntriangle_per_loop ?
-            (ntriangle_per_loop / (4 * ntrap)) : nclip_rect;
-
-        if (!mclip_rect) {      /* Maybe too many traps. */
-            mclip_rect = 1;
-            ptrap = traps;
-            traps_count = ntriangle_per_loop / 4;
-            traps_not_completed = ntrap - traps_count;
-        }
-        else {
-            traps_count = ntrap;
-            ptrap = traps;
-            traps_not_completed = 0;
-        }
-
- NTRAPS_LOOP_AGAIN:
-
-        vb = glamor_setup_composite_vbo(screen,
-                                        (mclip_rect * traps_count *
-                                         4 * vert_stride));
-        clip_processed = mclip_rect;
-
-        while (mclip_rect--) {
-            while (traps_count--) {
-                int vtx_num;
-                int i;
-                float vertices[3 * 2], source_texcoords[3 * 2];
-
-                DEBUGF
-                    ("In loop of render trapezoid, nclip_rect = %d, mclip_rect = %d, "
-                     "clip_processed = %d, traps_count = %d, traps_not_completed = %d\n",
-                     nclip_rect, mclip_rect, clip_processed, traps_count,
-                     traps_not_completed);
-
-                if (_glamor_clip_trapezoid_vertex
-                    (ptrap, pbox, clipped_vtx, &vtx_num)) {
-                    for (i = 0; i < vtx_num - 2; i++) {
-                        int clipped_vtx_tmp[3 * 2];
-
-                        clipped_vtx_tmp[0] = clipped_vtx[0];
-                        clipped_vtx_tmp[1] = clipped_vtx[1];
-                        clipped_vtx_tmp[2] = clipped_vtx[(i + 1) * 2];
-                        clipped_vtx_tmp[3] = clipped_vtx[(i + 1) * 2 + 1];
-                        clipped_vtx_tmp[4] = clipped_vtx[(i + 2) * 2];
-                        clipped_vtx_tmp[5] = clipped_vtx[(i + 2) * 2 + 1];
-                        glamor_set_normalize_tri_vcoords(dst_xscale, dst_yscale,
-                                                         clipped_vtx_tmp,
-                                                         vertices);
-                        DEBUGF("vertices of triangle: (%f X %f), (%f X %f), "
-                               "(%f X %f)\n", vertices[0], vertices[1],
-                               vertices[2], vertices[3], vertices[4],
-                               vertices[5]);
-
-                        if (key.source != SHADER_SOURCE_SOLID) {
-                            if (src->transform) {
-                                glamor_set_transformed_normalize_tri_tcoords
-                                    (source_pixmap_priv, src_matrix, src_xscale,
-                                     src_yscale, clipped_vtx_tmp,
-                                     source_texcoords);
-                            }
-                            else {
-                                glamor_set_normalize_tri_tcoords(src_xscale,
-                                                                 src_yscale,
-                                                                 clipped_vtx_tmp,
-                                                                 source_texcoords);
-                            }
-
-                            DEBUGF("source_texcoords of triangle: (%f X %f), "
-                                   "(%f X %f), (%f X %f)\n",
-                                   source_texcoords[0], source_texcoords[1],
-                                   source_texcoords[2], source_texcoords[3],
-                                   source_texcoords[4], source_texcoords[5]);
-                        }
-
-                        glamor_emit_composite_triangle(screen, vb,
-                                                       source_texcoords,
-                                                       NULL, vertices);
-                        vb += 3 * glamor_priv->vb_stride / sizeof(float);
-                    }
-                }
-
-                ptrap++;
-            }
-
-            if (traps_not_completed) {  /* one loop of ntraps not completed */
-                mclip_rect = 1;
-                traps_count = traps_not_completed > (ntriangle_per_loop / 4) ?
-                    (ntriangle_per_loop / 4) : traps_not_completed;
-                traps_not_completed -= traps_count;
-                glamor_flush_composite_triangles(screen);
-                goto NTRAPS_LOOP_AGAIN;
-            }
-            else {
-                ptrap = traps;
-                traps_count = ntrap;
-            }
-
-            pbox++;
-        }
-
-        glamor_flush_composite_triangles(screen);
-
-        nclip_rect -= clip_processed;
-    }
-
-    ret = TRUE;
-
- TRAPEZOID_RESET_GL:
-    glDisableVertexAttribArray(GLAMOR_VERTEX_POS);
-    glDisableVertexAttribArray(GLAMOR_VERTEX_SOURCE);
-    glDisableVertexAttribArray(GLAMOR_VERTEX_MASK);
-    glDisable(GL_BLEND);
-
- TRAPEZOID_OUT:
-    if (box) {
-        REGION_UNINIT(dst->pDrawable->pScreen, &region);
-    }
-
-    if (temp_src != src) {
-        FreePicture(temp_src, 0);
-    }
-    else {
-        if (saved_source_format) {
-            src->format = saved_source_format;
-        }
-    }
-
-    return ret;
-}
-
-void
-glamor_init_trapezoid_shader(ScreenPtr screen)
-{
-    glamor_screen_private *glamor_priv;
-    GLint fs_prog, vs_prog;
-
-    const char *trapezoid_vs =
-        GLAMOR_DEFAULT_PRECISION
-        "attribute vec4 v_position;\n"
-        "attribute vec2 v_texcoord;\n"
-        /* v_top_bottom, v_left_param and v_right_param contain the
-           constant value for all the vertex of one rect. Using uniform
-           is more suitable but we need to reset the uniform variables
-           for every rect rendering and can not use the vbo, which causes
-           performance loss. So we set these attributes to same value
-           for every vertex of one rect and so it is also a constant in FS */
-        "attribute vec2 v_top_bottom;\n"
-        "attribute vec4 v_left_param;\n"
-        "attribute vec4 v_right_param;\n"
-        "\n"
-        "varying vec2 source_texture;\n"
-        "varying float trap_top;\n"
-        "varying float trap_bottom;\n"
-        "varying float trap_left_x;\n"
-        "varying float trap_left_y;\n"
-        "varying float trap_left_slope;\n"
-        "varying float trap_left_vertical_f;\n"
-        "varying float trap_right_x;\n"
-        "varying float trap_right_y;\n"
-        "varying float trap_right_slope;\n"
-        "varying float trap_right_vertical_f;\n"
-        "\n"
-        "void main()\n"
-        "{\n"
-        "    gl_Position = v_position;\n"
-        "    source_texture = v_texcoord.xy;\n"
-        "    trap_top = v_top_bottom.x;\n"
-        "    trap_bottom = v_top_bottom.y;\n"
-        "    \n"
-        "    trap_left_x = v_left_param.x;\n"
-        "    trap_left_y = v_left_param.y;\n"
-        "    trap_left_slope = v_left_param.z;\n"
-        "    trap_left_vertical_f = v_left_param.w;\n"
-        "    \n"
-        "    trap_right_x = v_right_param.x;\n"
-        "    trap_right_y = v_right_param.y;\n"
-        "    trap_right_slope = v_right_param.z;\n"
-        "    trap_right_vertical_f = v_right_param.w;\n"
-        "}\n";
-
-    /*
-     * Because some GL fill function do not support the MultSample
-     * anti-alias, we need to do the MSAA here. This manner like
-     * pixman, will caculate the value of area in trapezoid dividing
-     * the totol area for each pixel, as follow:
-     |
-     ----+------------------------------------------------------>
-     |
-     |              -------------
-     |             /             \
-     |            /               \
-     |           /                 \
-     |          /              +----------------+
-     |         /               |.....\          |
-     |        /                |......\         |
-     |       /                 |.......\        |
-     |      /                  |........\       |
-     |     /-------------------+---------\      |
-     |                         |                |
-     |                         |                |
-     |                         +----------------+
-     |
-     \|/
-
-     */
-    const char *trapezoid_fs =
-        GLAMOR_DEFAULT_PRECISION
-        "varying vec2 source_texture;  \n"
-        "varying float trap_top;  \n"
-        "varying float trap_bottom;  \n"
-        "varying float trap_left_x;  \n"
-        "varying float trap_left_y;  \n"
-        "varying float trap_left_slope;  \n"
-        "varying float trap_left_vertical_f;  \n"
-        "varying float trap_right_x;  \n"
-        "varying float trap_right_y;  \n"
-        "varying float trap_right_slope;  \n"
-        "varying float trap_right_vertical_f;  \n"
-        "float x_per_pix = 1.0;"
-        "float y_per_pix = 1.0;"
-        "\n"
-        "float get_alpha_val() \n"
-        "{  \n"
-        "    float x_up_cut_left;  \n"
-        "    float x_bottom_cut_left;  \n"
-        "    float x_up_cut_right;  \n"
-        "    float x_bottom_cut_right;  \n"
-        "    bool trap_left_vertical;\n"
-        "    bool trap_right_vertical;\n"
-        "	 if (abs(trap_left_vertical_f - 1.0) <= 0.0001)\n"
-        "		trap_left_vertical = true;\n"
-        "	 else\n"
-        "		trap_left_vertical = false;\n"
-        "	 if (abs(trap_right_vertical_f - 1.0) <= 0.0001)\n"
-        "		trap_right_vertical = true;\n"
-        "	 else\n"
-        "		trap_right_vertical = false;\n"
-        "    \n"
-        "    if(trap_left_vertical == true) {  \n"
-        "        x_up_cut_left = trap_left_x;  \n"
-        "        x_bottom_cut_left = trap_left_x;  \n"
-        "    } else {  \n"
-        "        x_up_cut_left = trap_left_x  \n"
-        "            + (source_texture.y - y_per_pix/2.0 - trap_left_y)  \n"
-        "              / trap_left_slope;  \n"
-        "        x_bottom_cut_left = trap_left_x  \n"
-        "            + (source_texture.y + y_per_pix/2.0 - trap_left_y)  \n"
-        "              / trap_left_slope;  \n"
-        "    }  \n"
-        "    \n"
-        "    if(trap_right_vertical == true) {  \n"
-        "        x_up_cut_right = trap_right_x;  \n"
-        "        x_bottom_cut_right = trap_right_x;  \n"
-        "    } else {  \n"
-        "        x_up_cut_right = trap_right_x  \n"
-        "            + (source_texture.y - y_per_pix/2.0 - trap_right_y)  \n"
-        "              / trap_right_slope;  \n"
-        "        x_bottom_cut_right = trap_right_x  \n"
-        "            + (source_texture.y + y_per_pix/2.0 - trap_right_y)  \n"
-        "              / trap_right_slope;  \n"
-        "    }  \n"
-        "    \n"
-        "    if((x_up_cut_left <= source_texture.x - x_per_pix/2.0) &&  \n"
-        "          (x_bottom_cut_left <= source_texture.x - x_per_pix/2.0) &&  \n"
-        "          (x_up_cut_right >= source_texture.x + x_per_pix/2.0) &&  \n"
-        "          (x_bottom_cut_right >= source_texture.x + x_per_pix/2.0) &&  \n"
-        "          (trap_top <= source_texture.y - y_per_pix/2.0) &&  \n"
-        "          (trap_bottom >= source_texture.y + y_per_pix/2.0)) {  \n"
-        //       The complete inside case.
-        "        return 1.0;  \n"
-        "    } else if((trap_top > source_texture.y + y_per_pix/2.0) ||  \n"
-        "                (trap_bottom < source_texture.y - y_per_pix/2.0)) {  \n"
-        //       The complete outside. Above the top or Below the bottom.
-        "        return 0.0;  \n"
-        "    } else {  \n"
-        "        if((x_up_cut_right < source_texture.x - x_per_pix/2.0 &&  \n"
-        "                   x_bottom_cut_right < source_texture.x - x_per_pix/2.0)  \n"
-        "            || (x_up_cut_left > source_texture.x + x_per_pix/2.0  &&  \n"
-        "                   x_bottom_cut_left > source_texture.x + x_per_pix/2.0)) {  \n"
-        //            The complete outside. At Left or Right of the trapezoide.
-        "             return 0.0;  \n"
-        "        }  \n"
-        "    }  \n"
-        //   Get here, the pix is partly inside the trapezoid.
-        "    {  \n"
-        "        float percent = 0.0;  \n"
-        "        float up = (source_texture.y - y_per_pix/2.0) >= trap_top ?  \n"
-        "                       (source_texture.y - y_per_pix/2.0) : trap_top;  \n"
-        "        float bottom = (source_texture.y + y_per_pix/2.0) <= trap_bottom ?  \n"
-        "                       (source_texture.y + y_per_pix/2.0) : trap_bottom;  \n"
-        "        float left = source_texture.x - x_per_pix/2.0;  \n"
-        "        float right = source_texture.x + x_per_pix/2.0;  \n"
-        "        \n"
-        "        percent = (bottom - up) / y_per_pix;  \n"
-        "        \n"
-        "	     if(trap_left_vertical == true) {  \n"
-        "            if(trap_left_x > source_texture.x - x_per_pix/2.0 &&  \n"
-        "                     trap_left_x < source_texture.x + x_per_pix/2.0)  \n"
-        "                left = trap_left_x;  \n"
-        "        }  \n"
-        "	     if(trap_right_vertical == true) {  \n"
-        "            if(trap_right_x > source_texture.x - x_per_pix/2.0 &&  \n"
-        "                     trap_right_x < source_texture.x + x_per_pix/2.0)  \n"
-        "                right = trap_right_x;  \n"
-        "        }  \n"
-        "        if((up >= bottom) || (left >= right))  \n"
-        "            return 0.0;  \n"
-        "        \n"
-        "        percent = percent * ((right - left)/x_per_pix);  \n"
-        "        if(trap_left_vertical == true && trap_right_vertical == true)  \n"
-        "            return percent;  \n"
-        "        \n"
-        "        if(trap_left_vertical != true) {  \n"
-        "            float area;  \n"
-        //           the slope should never be 0.0 here
-        "            float up_x = trap_left_x + (up - trap_left_y)/trap_left_slope;  \n"
-        "            float bottom_x = trap_left_x + (bottom - trap_left_y)/trap_left_slope;  \n"
-        "            if(trap_left_slope < 0.0 && up_x > left) {  \n"
-        /*   case 1
-           |
-           ----+------------------------------------->
-           |                 /
-           |                /
-           |           +---/--------+
-           |           |  /.........|
-           |           | /..........|
-           |           |/...........|
-           |           /............|
-           |          /|............|
-           |           +------------+
-           |
-           \|/
-         */
-        "                float left_y = trap_left_y + trap_left_slope*(left - trap_left_x);  \n"
-        "                if((up_x > left) && (left_y > up)) {  \n"
-        "                    area = 0.5 * (up_x - left) * (left_y - up);  \n"
-        "                    if(up_x > right) {  \n"
-        "                        float right_y = trap_left_y  \n"
-        "                                  + trap_left_slope*(right - trap_left_x);  \n"
-        "                        area = area - 0.5 * (up_x - right) * (right_y - up);  \n"
-        "                    }  \n"
-        "                    if(left_y > bottom) {  \n"
-        "                        area = area - 0.5 * (bottom_x - left) * (left_y - bottom);  \n"
-        "                    }  \n"
-        "                } else {  \n"
-        "                    area = 0.0;  \n"
-        "                }  \n"
-        "                percent = percent * (1.0 - (area/((right-left)*(bottom-up))));  \n"
-        "            } else if(trap_left_slope > 0.0 && bottom_x > left) {  \n"
-        /*   case 2
-           |
-           ----+------------------------------------->
-           |          \
-           |           \
-           |           +\-----------+
-           |           | \..........|
-           |           |  \.........|
-           |           |   \........|
-           |           |    \.......|
-           |           |     \......|
-           |           +------\-----+
-           |                   \
-           |                    \
-           \|/
-         */
-        "                float right_y = trap_left_y + trap_left_slope*(right - trap_left_x);  \n"
-        "                if((up_x < right) && (right_y > up)) {  \n"
-        "                    area = 0.5 * (right - up_x) * (right_y - up);  \n"
-        "                    if(up_x < left) {  \n"
-        "                        float left_y = trap_left_y  \n"
-        "                                  + trap_left_slope*(left - trap_left_x);  \n"
-        "                        area = area - 0.5 * (left - up_x) * (left_y - up);  \n"
-        "                    }  \n"
-        "                    if(right_y > bottom) {  \n"
-        "                        area = area - 0.5 * (right - bottom_x) * (right_y - bottom);  \n"
-        "                    }  \n"
-        "                } else {  \n"
-        "                    area = 0.0;  \n"
-        "                }  \n"
-        "                percent = percent * (area/((right-left)*(bottom-up)));  \n"
-        "            }  \n"
-        "        }  \n"
-        "        \n"
-        "        if(trap_right_vertical != true) {  \n"
-        "            float area;  \n"
-        //           the slope should never be 0.0 here
-        "            float up_x = trap_right_x + (up - trap_right_y)/trap_right_slope;  \n"
-        "            float bottom_x = trap_right_x + (bottom - trap_right_y)/trap_right_slope;  \n"
-        "            if(trap_right_slope < 0.0 && bottom_x < right) {  \n"
-        /*   case 3
-           |
-           ----+------------------------------------->
-           |                     /
-           |           +--------/---+
-           |           |......./    |
-           |           |....../     |
-           |           |...../      |
-           |           |..../       |
-           |           |.../        |
-           |           +--/---------+
-           |             /
-           |
-           \|/
-         */
-        "                float left_y = trap_right_y + trap_right_slope*(left - trap_right_x);  \n"
-        "                if((up_x > left) && (left_y > up)) {  \n"
-        "                    area = 0.5 * (up_x - left) * (left_y - up);  \n"
-        "                    if(up_x > right) {  \n"
-        "                        float right_y = trap_right_y  \n"
-        "                                  + trap_right_slope*(right - trap_right_x);  \n"
-        "                        area = area - 0.5 * (up_x - right) * (right_y - up);  \n"
-        "                    }  \n"
-        "                    if(left_y > bottom) {  \n"
-        "                        area = area - 0.5 * (bottom_x - left) * (left_y - bottom);  \n"
-        "                    }  \n"
-        "                } else {  \n"
-        "                    area = 0.0;  \n"
-        "                }  \n"
-        "                percent = percent * (area/((right-left)*(bottom-up)));  \n"
-        "            } else if(trap_right_slope > 0.0 && up_x < right) {  \n"
-        /*   case 4
-           |
-           ----+------------------------------------->
-           |                   \
-           |           +--------\---+
-           |           |.........\  |
-           |           |..........\ |
-           |           |...........\|
-           |           |............\
-           |           |............|\
-           |           +------------+ \
-           |                           \
-           |
-           \|/
-         */
-        "                float right_y = trap_right_y + trap_right_slope*(right - trap_right_x);  \n"
-        "                if((up_x < right) && (right_y > up)) {  \n"
-        "                    area = 0.5 * (right - up_x) * (right_y - up);  \n"
-        "                    if(up_x < left) {  \n"
-        "                        float left_y = trap_right_y  \n"
-        "                                  + trap_right_slope*(left - trap_right_x);  \n"
-        "                        area = area - 0.5 * (left - up_x) * (left_y - up);  \n"
-        "                    }  \n"
-        "                    if(right_y > bottom) {  \n"
-        "                        area = area - 0.5 * (right - bottom_x) * (right_y - bottom);  \n"
-        "                    }  \n"
-        "                } else {  \n"
-        "                    area = 0.0;  \n"
-        "                }  \n"
-        "                percent = percent * (1.0 - (area/((right-left)*(bottom-up))));  \n"
-        "            }  \n"
-        "        }  \n"
-        "        \n"
-        "        return percent;  \n"
-        "    }  \n"
-        "}  \n"
-        "\n"
-        "void main()  \n"
-        "{  \n"
-        "    float alpha_val = get_alpha_val();  \n"
-        "    gl_FragColor = vec4(0.0, 0.0, 0.0, alpha_val);  \n"
-        "}\n";
-
-    glamor_priv = glamor_get_screen_private(screen);
-    glamor_make_current(glamor_priv);
-
-    glamor_priv->trapezoid_prog = glCreateProgram();
-
-    vs_prog = glamor_compile_glsl_prog(GL_VERTEX_SHADER, trapezoid_vs);
-    fs_prog = glamor_compile_glsl_prog(GL_FRAGMENT_SHADER, trapezoid_fs);
-
-    glAttachShader(glamor_priv->trapezoid_prog, vs_prog);
-    glAttachShader(glamor_priv->trapezoid_prog, fs_prog);
-
-    glBindAttribLocation(glamor_priv->trapezoid_prog,
-                         GLAMOR_VERTEX_POS, "v_positionsition");
-    glBindAttribLocation(glamor_priv->trapezoid_prog,
-                         GLAMOR_VERTEX_SOURCE, "v_texcoord");
-    glBindAttribLocation(glamor_priv->trapezoid_prog,
-                         GLAMOR_VERTEX_TOP_BOTTOM, "v_top_bottom");
-    glBindAttribLocation(glamor_priv->trapezoid_prog,
-                         GLAMOR_VERTEX_LEFT_PARAM, "v_left_param");
-    glBindAttribLocation(glamor_priv->trapezoid_prog,
-                         GLAMOR_VERTEX_RIGHT_PARAM, "v_right_param");
-
-    glamor_link_glsl_prog(screen, glamor_priv->trapezoid_prog, "trapezoid");
-}
-
-void
-glamor_fini_trapezoid_shader(ScreenPtr screen)
-{
-    glamor_screen_private *glamor_priv;
-
-    glamor_priv = glamor_get_screen_private(screen);
-    glamor_make_current(glamor_priv);
-    glDeleteProgram(glamor_priv->trapezoid_prog);
-}
-
-static Bool
-_glamor_generate_trapezoid_with_shader(ScreenPtr screen, PicturePtr picture,
-                                       xTrapezoid *traps, int ntrap,
-                                       BoxRec *bounds)
-{
-    glamor_screen_private *glamor_priv;
-    glamor_pixmap_private *pixmap_priv;
-    PixmapPtr pixmap = NULL;
-    GLint trapezoid_prog;
-    GLfloat xscale, yscale;
-    float left_slope, right_slope;
-    xTrapezoid *ptrap;
-    BoxRec one_trap_bound;
-    int nrect_max;
-    int i, j;
-    float params[4];
-
-    glamor_priv = glamor_get_screen_private(screen);
-    trapezoid_prog = glamor_priv->trapezoid_prog;
-
-    pixmap = glamor_get_drawable_pixmap(picture->pDrawable);
-    pixmap_priv = glamor_get_pixmap_private(pixmap);
-
-    if (!GLAMOR_PIXMAP_PRIV_HAS_FBO(pixmap_priv)
-        || pixmap_priv->type == GLAMOR_TEXTURE_LARGE) { /* should always have here. */
-        DEBUGF("GLAMOR_PIXMAP_PRIV_HAS_FBO check failed, fallback\n");
-        return FALSE;
-    }
-
-    /* First, clear all to zero */
-    glamor_solid(pixmap, 0, 0, pixmap_priv->base.pixmap->drawable.width,
-                 pixmap_priv->base.pixmap->drawable.height, 0);
-
-    glamor_make_current(glamor_priv);
-
-    glamor_set_destination_pixmap_priv_nc(pixmap_priv);
-
-    pixmap_priv_get_dest_scale(pixmap_priv, (&xscale), (&yscale));
-
-    /* Now draw the Trapezoid mask. */
-    glUseProgram(trapezoid_prog);
-
-    glEnable(GL_BLEND);
-    glBlendFunc(GL_ONE, GL_ONE);
-
-    nrect_max = GLAMOR_COMPOSITE_VBO_VERT_CNT / (4 * GLAMOR_VERTEX_RIGHT_PARAM);
-
-    for (i = 0; i < ntrap;) {
-        float *vertices;
-        int mrect;
-        int stride;
-
-        mrect = (ntrap - i) > nrect_max ? nrect_max : (ntrap - i);
-        vertices = glamor_setup_composite_vbo_for_trapezoid(screen, 4 * mrect);
-        stride = glamor_priv->vb_stride / sizeof(float);
-
-        for (j = 0; j < mrect; j++) {
-            ptrap = traps + i + j;
-
-            DEBUGF
-                ("--- The parameter of xTrapezoid is:\ntop: %d  0x%x\tbottom: %d  0x%x\n"
-                 "left:  p1 (%d   0x%x, %d   0x%x)\tp2 (%d   0x%x, %d   0x%x)\n"
-                 "right: p1 (%d   0x%x, %d   0x%x)\tp2 (%d   0x%x, %d   0x%x)\n",
-                 xFixedToInt(ptrap->top), ptrap->top,
-                 xFixedToInt(ptrap->bottom), ptrap->bottom,
-                 xFixedToInt(ptrap->left.p1.x), ptrap->left.p1.x,
-                 xFixedToInt(ptrap->left.p1.y), ptrap->left.p1.y,
-                 xFixedToInt(ptrap->left.p2.x), ptrap->left.p2.x,
-                 xFixedToInt(ptrap->left.p2.y), ptrap->left.p2.y,
-                 xFixedToInt(ptrap->right.p1.x), ptrap->right.p1.x,
-                 xFixedToInt(ptrap->right.p1.y), ptrap->right.p1.y,
-                 xFixedToInt(ptrap->right.p2.x), ptrap->right.p2.x,
-                 xFixedToInt(ptrap->right.p2.y), ptrap->right.p2.y);
-
-            miTrapezoidBounds(1, ptrap, &one_trap_bound);
-
-            vertices += 2;
-            glamor_set_tcoords_ext((one_trap_bound.x1), (one_trap_bound.y1),
-                                   (one_trap_bound.x2), (one_trap_bound.y2),
-                                   vertices, stride);
-            DEBUGF("tex_vertices --> leftup : %f X %f, rightup: %f X %f,"
-                   "rightbottom: %f X %f, leftbottom : %f X %f\n", vertices[0],
-                   vertices[1], vertices[1 * stride], vertices[1 * stride + 1],
-                   vertices[2 * stride], vertices[2 * stride + 1],
-                   vertices[3 * stride], vertices[3 * stride + 1]);
-
-            /* Need to rebase. */
-            one_trap_bound.x1 -= bounds->x1;
-            one_trap_bound.x2 -= bounds->x1;
-            one_trap_bound.y1 -= bounds->y1;
-            one_trap_bound.y2 -= bounds->y1;
-
-            vertices -= 2;
-
-            glamor_set_normalize_vcoords_ext(pixmap_priv, xscale, yscale,
-                                             one_trap_bound.x1,
-                                             one_trap_bound.y1,
-                                             one_trap_bound.x2,
-                                             one_trap_bound.y2,
-                                             vertices, stride);
-            DEBUGF("vertices --> leftup : %f X %f, rightup: %f X %f,"
-                   "rightbottom: %f X %f, leftbottom : %f X %f\n", vertices[0],
-                   vertices[1], vertices[1 * stride], vertices[1 * stride + 1],
-                   vertices[2 * stride], vertices[2 * stride + 1],
-                   vertices[3 * stride], vertices[3 * stride + 1]);
-            vertices += 4;
-
-            /* Set the top and bottom. */
-            params[0] = ((float) ptrap->top) / 65536;
-            params[1] = ((float) ptrap->bottom) / 65536;
-            glamor_set_const_ext(params, 2, vertices, 4, stride);
-            vertices += 2;
-
-            /* Set the left params. */
-            params[0] = ((float) ptrap->left.p1.x) / 65536;
-            params[1] = ((float) ptrap->left.p1.y) / 65536;
-
-            if (ptrap->left.p1.x == ptrap->left.p2.x) {
-                left_slope = 0.0;
-                params[3] = 1.0;
-            }
-            else {
-                left_slope = ((float) (ptrap->left.p1.y - ptrap->left.p2.y))
-                    / ((float) (ptrap->left.p1.x - ptrap->left.p2.x));
-                params[3] = 0.0;
-            }
-            params[2] = left_slope;
-            glamor_set_const_ext(params, 4, vertices, 4, stride);
-            vertices += 4;
-
-            /* Set the left params. */
-            params[0] = ((float) ptrap->right.p1.x) / 65536;
-            params[1] = ((float) ptrap->right.p1.y) / 65536;
-
-            if (ptrap->right.p1.x == ptrap->right.p2.x) {
-                right_slope = 0.0;
-                params[3] = 1.0;
-            }
-            else {
-                right_slope = ((float) (ptrap->right.p1.y - ptrap->right.p2.y))
-                    / ((float) (ptrap->right.p1.x - ptrap->right.p2.x));
-                params[3] = 0.0;
-            }
-            params[2] = right_slope;
-            glamor_set_const_ext(params, 4, vertices, 4, stride);
-            vertices += 4;
-
-            DEBUGF("trap_top = %f, trap_bottom = %f, "
-                   "trap_left_x = %f, trap_left_y = %f, left_slope = %f, "
-                   "trap_right_x = %f, trap_right_y = %f, right_slope = %f\n",
-                   ((float) ptrap->top) / 65536,
-                   ((float) ptrap->bottom) / 65536,
-                   ((float) ptrap->left.p1.x) / 65536,
-                   ((float) ptrap->left.p1.y) / 65536, left_slope,
-                   ((float) ptrap->right.p1.x) / 65536,
-                   ((float) ptrap->right.p1.y) / 65536, right_slope);
-
-            glamor_priv->render_nr_verts += 4;
-            vertices += 3 * stride;
-        }
-
-        i += mrect;
-
-        glamor_put_vbo_space(screen);
-
-        /* Now rendering. */
-        if (!glamor_priv->render_nr_verts)
-            continue;
-
-        if (glamor_priv->gl_flavor == GLAMOR_GL_DESKTOP) {
-            glDrawRangeElements(GL_TRIANGLES, 0,
-                                glamor_priv->render_nr_verts,
-                                (glamor_priv->render_nr_verts * 3) / 2,
-                                GL_UNSIGNED_SHORT, NULL);
-        } else {
-            glDrawElements(GL_TRIANGLES,
-                           (glamor_priv->render_nr_verts * 3) / 2,
-                           GL_UNSIGNED_SHORT, NULL);
-        }
-    }
-
-    glBlendFunc(GL_ONE, GL_ZERO);
-    glDisable(GL_BLEND);
-    glDisableVertexAttribArray(GLAMOR_VERTEX_POS);
-    glDisableVertexAttribArray(GLAMOR_VERTEX_SOURCE);
-    glDisableVertexAttribArray(GLAMOR_VERTEX_TOP_BOTTOM);
-    glDisableVertexAttribArray(GLAMOR_VERTEX_LEFT_PARAM);
-    glDisableVertexAttribArray(GLAMOR_VERTEX_RIGHT_PARAM);
-    return TRUE;
-}
-
-#endif                          /*GLAMOR_TRAPEZOID_SHADER */
-
 /**
  * Creates an appropriate picture for temp mask use.
  */
@@ -1559,7 +43,7 @@ static PicturePtr
 glamor_create_mask_picture(ScreenPtr screen,
                            PicturePtr dst,
                            PictFormatPtr pict_format,
-                           CARD16 width, CARD16 height, int gpu)
+                           CARD16 width, CARD16 height)
 {
     PixmapPtr pixmap;
     PicturePtr picture;
@@ -1574,15 +58,9 @@ glamor_create_mask_picture(ScreenPtr screen,
             return 0;
     }
 
-    if (gpu) {
-        pixmap = glamor_create_pixmap(screen, width, height,
-                                      pict_format->depth, 0);
-    }
-    else {
-        pixmap = glamor_create_pixmap(screen, 0, 0,
-                                      pict_format->depth,
-                                      GLAMOR_CREATE_PIXMAP_CPU);
-    }
+    pixmap = glamor_create_pixmap(screen, 0, 0,
+                                  pict_format->depth,
+                                  GLAMOR_CREATE_PIXMAP_CPU);
 
     if (!pixmap)
         return 0;
@@ -1592,61 +70,15 @@ glamor_create_mask_picture(ScreenPtr screen,
     return picture;
 }
 
-static int
-_glamor_trapezoid_bounds(int ntrap, xTrapezoid *traps, BoxPtr box)
-{
-    int has_large_trapezoid = 0;
-
-    box->y1 = MAXSHORT;
-    box->y2 = MINSHORT;
-    box->x1 = MAXSHORT;
-    box->x2 = MINSHORT;
-
-    for (; ntrap; ntrap--, traps++) {
-        INT16 x1, y1, x2, y2;
-
-        if (!xTrapezoidValid(traps))
-            continue;
-        y1 = xFixedToInt(traps->top);
-        if (y1 < box->y1)
-            box->y1 = y1;
-
-        y2 = xFixedToInt(xFixedCeil(traps->bottom));
-        if (y2 > box->y2)
-            box->y2 = y2;
-
-        x1 = xFixedToInt(min
-                         (_glamor_linefixedX(&traps->left, traps->top, FALSE),
-                          _glamor_linefixedX(&traps->left, traps->bottom,
-                                             FALSE)));
-        if (x1 < box->x1)
-            box->x1 = x1;
-
-        x2 = xFixedToInt(xFixedCeil
-                         (max
-                          (_glamor_linefixedX(&traps->right, traps->top, TRUE),
-                           _glamor_linefixedX(&traps->right, traps->bottom,
-                                              TRUE))));
-        if (x2 > box->x2)
-            box->x2 = x2;
-
-        if (!has_large_trapezoid && (x2 - x1) > 256 && (y2 - y1) > 32)
-            has_large_trapezoid = 1;
-    }
-
-    return has_large_trapezoid;
-}
-
 /**
- * glamor_trapezoids will first try to create a trapezoid mask using shader,
- * if failed, miTrapezoids will generate trapezoid mask accumulating in
+ * glamor_trapezoids will generate trapezoid mask accumulating in
  * system memory.
  */
-static Bool
-_glamor_trapezoids(CARD8 op,
-                   PicturePtr src, PicturePtr dst,
-                   PictFormatPtr mask_format, INT16 x_src, INT16 y_src,
-                   int ntrap, xTrapezoid *traps, Bool fallback)
+void
+glamor_trapezoids(CARD8 op,
+                  PicturePtr src, PicturePtr dst,
+                  PictFormatPtr mask_format, INT16 x_src, INT16 y_src,
+                  int ntrap, xTrapezoid *traps)
 {
     ScreenPtr screen = dst->pDrawable->pScreen;
     BoxRec bounds;
@@ -1656,8 +88,6 @@ _glamor_trapezoids(CARD8 op,
     int width, height, stride;
     PixmapPtr pixmap;
     pixman_image_t *image = NULL;
-    int ret = 0;
-    int has_large_trapezoid;
 
     /* If a mask format wasn't provided, we get to choose, but behavior should
      * be as if there was no temporary mask the traps were accumulated into.
@@ -1670,16 +100,13 @@ _glamor_trapezoids(CARD8 op,
         for (; ntrap; ntrap--, traps++)
             glamor_trapezoids(op, src, dst, mask_format, x_src,
                               y_src, 1, traps);
-        return TRUE;
+        return;
     }
 
-    has_large_trapezoid = _glamor_trapezoid_bounds(ntrap, traps, &bounds);
-    DEBUGF("The bounds for all traps is: bounds.x1 = %d, bounds.x2 = %d, "
-           "bounds.y1 = %d, bounds.y2 = %d, ---- ntrap = %d\n", bounds.x1,
-           bounds.x2, bounds.y1, bounds.y2, ntrap);
+    miTrapezoidBounds(ntrap, traps, &bounds);
 
     if (bounds.y1 >= bounds.y2 || bounds.x1 >= bounds.x2)
-        return TRUE;
+        return;
 
     x_dst = traps[0].left.p1.x >> 16;
     y_dst = traps[0].left.p1.y >> 16;
@@ -1688,85 +115,34 @@ _glamor_trapezoids(CARD8 op,
     height = bounds.y2 - bounds.y1;
     stride = PixmapBytePad(width, mask_format->depth);
 
-#ifdef GLAMOR_TRAPEZOID_SHADER
-    /* We seperate the render to two paths.
-       Some GL implemetation do not implement the Anti-Alias for triangles
-       and polygen's filling. So when the edge is not vertical or horizontal,
-       sawtooth will be obvious. The trapezoid is widely used to render wide
-       lines and circles. In these case, the line or circle will be divided
-       into a large number of small trapezoids to approximate it, so the sawtooth
-       at the edge will cause the result not be acceptable.
-       When the depth of the mask is 1, there is no Anti-Alias needed, so we
-       use the clip logic to generate the result directly(fast path).
-       When the depth is not 1, AA is needed and we use a shader to generate
-       a temp mask pixmap.
-     */
-    if (mask_format->depth == 1) {
-        ret = _glamor_trapezoids_with_shader(op, src, dst, mask_format,
-                                             x_src, y_src, ntrap, traps);
-        if (ret)
-            return TRUE;
-    }
-    else {
-        if (has_large_trapezoid || ntrap > 256) {
-            /* The shader speed is relative slower than pixman when generating big chunk
-               trapezoid mask. We fallback to pixman to improve the performance. */
-            ;
-        }
-        else if (dst->polyMode == PolyModeImprecise) {
-            /*  The precise mode is that we sample the trapezoid on the centre points of
-               an (2*n+1)x(2*n-1) subpixel grid. It is computationally expensive in shader
-               and we use inside area ratio to replace it if the polymode == Imprecise. */
-            picture = glamor_create_mask_picture(screen, dst, mask_format,
-                                                 width, height, 1);
-            if (!picture)
-                return TRUE;
-
-            ret =
-                _glamor_generate_trapezoid_with_shader(screen, picture, traps,
-                                                       ntrap, &bounds);
+    picture = glamor_create_mask_picture(screen, dst, mask_format,
+                                         width, height);
+    if (!picture)
+        return;
 
-            if (!ret)
-                FreePicture(picture, 0);
-        }
+    image = pixman_image_create_bits(picture->format,
+                                     width, height, NULL, stride);
+    if (!image) {
+        FreePicture(picture, 0);
+        return;
     }
-#endif
 
-    if (!ret) {
-        DEBUGF("Fallback to sw rasterize of trapezoid\n");
+    for (; ntrap; ntrap--, traps++)
+        pixman_rasterize_trapezoid(image,
+                                   (pixman_trapezoid_t *) traps,
+                                   -bounds.x1, -bounds.y1);
 
-        picture = glamor_create_mask_picture(screen, dst, mask_format,
-                                             width, height, 0);
-        if (!picture)
-            return TRUE;
-
-        image = pixman_image_create_bits(picture->format,
-                                         width, height, NULL, stride);
-        if (!image) {
-            FreePicture(picture, 0);
-            return TRUE;
-        }
-
-        for (; ntrap; ntrap--, traps++)
-            pixman_rasterize_trapezoid(image,
-                                       (pixman_trapezoid_t *) traps,
-                                       -bounds.x1, -bounds.y1);
+    pixmap = glamor_get_drawable_pixmap(picture->pDrawable);
 
-        pixmap = glamor_get_drawable_pixmap(picture->pDrawable);
-
-        screen->ModifyPixmapHeader(pixmap, width, height,
-                                   mask_format->depth,
-                                   BitsPerPixel(mask_format->depth),
-                                   PixmapBytePad(width,
-                                                 mask_format->depth),
-                                   pixman_image_get_data(image));
-    }
+    screen->ModifyPixmapHeader(pixmap, width, height,
+                               mask_format->depth,
+                               BitsPerPixel(mask_format->depth),
+                               PixmapBytePad(width,
+                                             mask_format->depth),
+                               pixman_image_get_data(image));
 
     x_rel = bounds.x1 + x_src - x_dst;
     y_rel = bounds.y1 + y_src - y_dst;
-    DEBUGF("x_src = %d, y_src = %d, x_dst = %d, y_dst = %d, "
-           "x_rel = %d, y_rel = %d\n", x_src, y_src, x_dst,
-           y_dst, x_rel, y_rel);
 
     CompositePicture(op, src, picture, dst,
                      x_rel, y_rel,
@@ -1778,19 +154,6 @@ _glamor_trapezoids(CARD8 op,
         pixman_image_unref(image);
 
     FreePicture(picture, 0);
-    return TRUE;
-}
-
-void
-glamor_trapezoids(CARD8 op,
-                  PicturePtr src, PicturePtr dst,
-                  PictFormatPtr mask_format, INT16 x_src, INT16 y_src,
-                  int ntrap, xTrapezoid *traps)
-{
-    DEBUGF("x_src = %d, y_src = %d, ntrap = %d\n", x_src, y_src, ntrap);
-
-    _glamor_trapezoids(op, src, dst, mask_format, x_src,
-                       y_src, ntrap, traps, TRUE);
 }
 
 Bool
@@ -1801,8 +164,9 @@ glamor_trapezoids_nf(CARD8 op,
 {
     DEBUGF("x_src = %d, y_src = %d, ntrap = %d\n", x_src, y_src, ntrap);
 
-    return _glamor_trapezoids(op, src, dst, mask_format, x_src,
-                              y_src, ntrap, traps, FALSE);
+    glamor_trapezoids(op, src, dst, mask_format, x_src,
+                      y_src, ntrap, traps);
+    return TRUE;
 }
 
 #endif                          /* RENDER */
commit b2452311bd1d67b4d78612570d4a25c685c78a0c
Author: Keith Packard <keithp at keithp.com>
Date:   Tue Aug 19 12:52:05 2014 -0700

    glamor: Check large pixmap users in glamor_largepixmap.c
    
    This enables the assertion that all users of the large pixmap member
    are restricted to pixmaps which are actually large.
    
    Signed-off-by: Keith Packard <keithp at keithp.com>
    Reviewed-by: Adam Jackson <ajax at redhat.com>

diff --git a/glamor/glamor_largepixmap.c b/glamor/glamor_largepixmap.c
index ce38809..9b24584 100644
--- a/glamor/glamor_largepixmap.c
+++ b/glamor/glamor_largepixmap.c
@@ -4,9 +4,7 @@
 
 static inline glamor_pixmap_private_large_t *
 __glamor_large(glamor_pixmap_private *pixmap_priv) {
-#if 0
     assert(pixmap_priv->type == GLAMOR_TEXTURE_LARGE);
-#endif
     return &pixmap_priv->large;
 }
 
commit 5fc3e99f537b10dd9c2adfd37cf2c4ba5ed4bd44
Author: Keith Packard <keithp at keithp.com>
Date:   Tue Aug 19 12:44:41 2014 -0700

    glamor: Handle compositing from large to small pixmaps
    
    glamor_composite_largepixmap_region is given the job of dealing with
    compositing between a mixture of large and small pixmaps. However, it
    was assuming that the destination pixmap was large and fetching
    members of the large structure even for small pixmaps.
    
    This manifested with assertion failures when compositing from a large
    pixmap to a small pixmap.
    
    Fixed by using the pixmap size for the destination block size for
    small pixmaps.
    
    Signed-off-by: Keith Packard <keithp at keithp.com>
    Reviewed-by: Adam Jackson <ajax at redhat.com>

diff --git a/glamor/glamor_largepixmap.c b/glamor/glamor_largepixmap.c
index ad6a090..ce38809 100644
--- a/glamor/glamor_largepixmap.c
+++ b/glamor/glamor_largepixmap.c
@@ -1041,6 +1041,7 @@ glamor_composite_largepixmap_region(CARD8 op,
     int is_normal_source_fbo = 0;
     int is_normal_mask_fbo = 0;
     int fixed_block_width, fixed_block_height;
+    int dest_block_width, dest_block_height;
     int null_source, null_mask;
     glamor_pixmap_private *need_free_source_pixmap_priv = NULL;
     glamor_pixmap_private *need_free_mask_pixmap_priv = NULL;
@@ -1057,8 +1058,16 @@ glamor_composite_largepixmap_region(CARD8 op,
     else
         mask_repeat_type = RepeatNone;
 
-    fixed_block_width = dest_pixmap_priv->large.block_w;
-    fixed_block_height = dest_pixmap_priv->large.block_h;
+    if (dest_pixmap_priv->type == GLAMOR_TEXTURE_LARGE) {
+        dest_block_width = __glamor_large(dest_pixmap_priv)->block_w;
+        dest_block_height = __glamor_large(dest_pixmap_priv)->block_h;
+    } else {
+        dest_block_width = dest_pixmap_priv->base.pixmap->drawable.width;
+        dest_block_height = dest_pixmap_priv->base.pixmap->drawable.height;
+    }
+    fixed_block_width = dest_block_width;
+    fixed_block_height = dest_block_height;
+
     /* If we got an totally out-of-box region for a source or mask
      * region without repeat, we need to set it as null_source and
      * give it a solid color (0,0,0,0). */
@@ -1124,8 +1133,8 @@ glamor_composite_largepixmap_region(CARD8 op,
 
     /*compute the correct block width and height whose transformed source/mask
      *region can fit into one texture.*/
-    if (force_clip || fixed_block_width < dest_pixmap_priv->large.block_w
-        || fixed_block_height < dest_pixmap_priv->large.block_h)
+    if (force_clip || fixed_block_width < dest_block_width
+        || fixed_block_height < dest_block_height)
         clipped_dest_regions =
             glamor_compute_clipped_regions_ext(dest_pixmap_priv, region,
                                                &n_dest_regions,
commit 6e78d7f5e6edf56180e2ecfd25300bb2523876ab
Author: Keith Packard <keithp at keithp.com>
Date:   Tue Aug 19 12:41:45 2014 -0700

    glamor: Don't abuse large_pixmap members for regular pixmaps
    
    glamor_compute_clipped_regions_ext wants to treat small and large
    pixmaps uniformly and did that by writing into the large pixmap
    union member in small pixmaps to construct something that looks like a
    one texture large pixmap.
    
    Instead of doing that, simply allocate the necessary elements locally
    on the stack and use them from there.
    
    Signed-off-by: Keith Packard <keithp at keithp.com>
    Reviewed-by: Adam Jackson <ajax at redhat.com>

diff --git a/glamor/glamor_largepixmap.c b/glamor/glamor_largepixmap.c
index e3a1e82..ad6a090 100644
--- a/glamor/glamor_largepixmap.c
+++ b/glamor/glamor_largepixmap.c
@@ -162,9 +162,9 @@ glamor_compute_clipped_regions_ext(glamor_pixmap_private *pixmap_priv,
         *result_regions;
     int i, j, x, y, k, inner_n_regions;
     int width, height;
-    glamor_pixmap_private_large_t *priv;
-
-    priv = &pixmap_priv->large;
+    BoxPtr box_array;
+    BoxRec small_box;
+    int block_w, block_h;
 
     DEBUGF("ext called \n");
 
@@ -178,14 +178,16 @@ glamor_compute_clipped_regions_ext(glamor_pixmap_private *pixmap_priv,
         clipped_regions[0].block_idx = 0;
         RegionCopy(clipped_regions[0].region, region);
         *n_region = 1;
-        priv->block_w = priv->base.pixmap->drawable.width;
-        priv->block_h = priv->base.pixmap->drawable.height;
-        priv->box_array = &priv->box;
-        priv->box.x1 = priv->box.y1 = 0;
-        priv->box.x2 = priv->block_w;
-        priv->box.y2 = priv->block_h;
+        block_w = pixmap_priv->base.pixmap->drawable.width;
+        block_h = pixmap_priv->base.pixmap->drawable.height;
+        box_array = &small_box;
+        small_box.x1 = small_box.y1 = 0;
+        small_box.x2 = block_w;
+        small_box.y2 = block_h;
     }
     else {
+        glamor_pixmap_private_large_t *priv = __glamor_large(pixmap_priv);
+
         clipped_regions = __glamor_compute_clipped_regions(priv->block_w,
                                                            priv->block_h,
                                                            priv->block_wcnt,
@@ -201,20 +203,23 @@ glamor_compute_clipped_regions_ext(glamor_pixmap_private *pixmap_priv,
             *n_region = 0;
             return NULL;
         }
+        block_w = priv->block_w;
+        block_h = priv->block_h;
+        box_array = priv->box_array;
     }
-    if (inner_block_w >= priv->block_w && inner_block_h >= priv->block_h)
+    if (inner_block_w >= block_w && inner_block_h >= block_h)
         return clipped_regions;
     result_regions = calloc(*n_region
-                            * ((priv->block_w + inner_block_w - 1) /
+                            * ((block_w + inner_block_w - 1) /
                                inner_block_w)
-                            * ((priv->block_h + inner_block_h - 1) /
+                            * ((block_h + inner_block_h - 1) /
                                inner_block_h), sizeof(*result_regions));
     k = 0;
     for (i = 0; i < *n_region; i++) {
-        x = priv->box_array[clipped_regions[i].block_idx].x1;
-        y = priv->box_array[clipped_regions[i].block_idx].y1;
-        width = priv->box_array[clipped_regions[i].block_idx].x2 - x;
-        height = priv->box_array[clipped_regions[i].block_idx].y2 - y;
+        x = box_array[clipped_regions[i].block_idx].x1;
+        y = box_array[clipped_regions[i].block_idx].y1;
+        width = box_array[clipped_regions[i].block_idx].x2 - x;
+        height = box_array[clipped_regions[i].block_idx].y2 - y;
         inner_regions = __glamor_compute_clipped_regions(inner_block_w,
                                                          inner_block_h,
                                                          0, x, y,
commit bab319763c9734da3cff7b91a582f54989dc4cbe
Author: Keith Packard <keithp at keithp.com>
Date:   Tue Aug 19 12:39:07 2014 -0700

    glamor: Add macro __glamor_large in glamor_largepixmap.c
    
    For now, this simply fetches the large member of the pixmap private.
    It will be changed to assert that the pixmap is large once bugs
    related to that have been fixed.
    
    Signed-off-by: Keith Packard <keithp at keithp.com>
    Reviewed-by: Adam Jackson <ajax at redhat.com>

diff --git a/glamor/glamor_largepixmap.c b/glamor/glamor_largepixmap.c
index 4c82a8d..e3a1e82 100644
--- a/glamor/glamor_largepixmap.c
+++ b/glamor/glamor_largepixmap.c
@@ -2,6 +2,14 @@
 
 #include "glamor_priv.h"
 
+static inline glamor_pixmap_private_large_t *
+__glamor_large(glamor_pixmap_private *pixmap_priv) {
+#if 0
+    assert(pixmap_priv->type == GLAMOR_TEXTURE_LARGE);
+#endif
+    return &pixmap_priv->large;
+}
+
 /**
  * Clip the boxes regards to each pixmap's block array.
  *
@@ -343,8 +351,6 @@ _glamor_compute_clipped_regions(glamor_pixmap_private *pixmap_priv,
     int x_center_shift = 0, y_center_shift = 0;
     glamor_pixmap_private_large_t *priv;
 
-    priv = &pixmap_priv->large;
-
     DEBUGRegionPrint(region);
     if (pixmap_priv->type != GLAMOR_TEXTURE_LARGE) {
         clipped_regions = calloc(1, sizeof(*clipped_regions));
@@ -355,6 +361,8 @@ _glamor_compute_clipped_regions(glamor_pixmap_private *pixmap_priv,
         return clipped_regions;
     }
 
+    priv = __glamor_large(pixmap_priv);
+
     pixmap_width = priv->base.pixmap->drawable.width;
     pixmap_height = priv->base.pixmap->drawable.height;
     if (repeat_type == 0 || repeat_type == RepeatPad) {
@@ -751,7 +759,7 @@ glamor_merge_clipped_regions(glamor_pixmap_private *pixmap_priv,
     int pixmap_width, pixmap_height;
     glamor_pixmap_private_large_t *priv;
 
-    priv = &pixmap_priv->large;
+    priv = __glamor_large(pixmap_priv);
     pixmap_width = priv->base.pixmap->drawable.width;
     pixmap_height = priv->base.pixmap->drawable.height;
 
@@ -985,15 +993,15 @@ _glamor_process_transformed_clipped_region(glamor_pixmap_private *priv,
             shift_y = (temp_box->y1 - rem) / priv->base.pixmap->drawable.height;
 
             if (shift_x != 0) {
-                priv->large.box.x1 +=
+                __glamor_large(priv)->box.x1 +=
                     shift_x * priv->base.pixmap->drawable.width;
-                priv->large.box.x2 +=
+                __glamor_large(priv)->box.x2 +=
                     shift_x * priv->base.pixmap->drawable.width;
             }
             if (shift_y != 0) {
-                priv->large.box.y1 +=
+                __glamor_large(priv)->box.y1 +=
                     shift_y * priv->base.pixmap->drawable.height;
-                priv->large.box.y2 +=
+                __glamor_large(priv)->box.y2 +=
                     shift_y * priv->base.pixmap->drawable.height;
             }
         }
@@ -1071,8 +1079,8 @@ glamor_composite_largepixmap_region(CARD8 op,
         int source_transformed_block_width, source_transformed_block_height;
 
         if (!glamor_get_transform_block_size(source->transform,
-                                             source_pixmap_priv->large.block_w,
-                                             source_pixmap_priv->large.block_h,
+                                             __glamor_large(source_pixmap_priv)->block_w,
+                                             __glamor_large(source_pixmap_priv)->block_h,
                                              &source_transformed_block_width,
                                              &source_transformed_block_height))
         {
@@ -1093,8 +1101,8 @@ glamor_composite_largepixmap_region(CARD8 op,
         int mask_transformed_block_width, mask_transformed_block_height;
 
         if (!glamor_get_transform_block_size(mask->transform,
-                                             mask_pixmap_priv->large.block_w,
-                                             mask_pixmap_priv->large.block_h,
+                                             __glamor_large(mask_pixmap_priv)->block_w,
+                                             __glamor_large(mask_pixmap_priv)->block_h,
                                              &mask_transformed_block_width,
                                              &mask_transformed_block_height)) {
             DEBUGF("mask block size less than 1, fallback.\n");
@@ -1271,8 +1279,8 @@ glamor_composite_largepixmap_region(CARD8 op,
                                                    clipped_mask_regions[k].
                                                    block_idx);
                             DEBUGF("mask fbo off %d %d \n",
-                                   mask_pixmap_priv->large.box.x1,
-                                   mask_pixmap_priv->large.box.y1);
+                                   __glamor_large(mask_pixmap_priv)->box.x1,
+                                   __glamor_large(mask_pixmap_priv)->box.y1);
                             DEBUGF("start composite mask hasn't transform.\n");
                             RegionTranslate(clipped_mask_regions[k].region,
                                             x_dest - x_mask +
commit 16e429f1f96f984b1ff575875a7a4d7d29b482e2
Author: Keith Packard <keithp at keithp.com>
Date:   Tue Aug 19 12:34:41 2014 -0700

    glamor: Change SET_PIXMAP_FBO_CURRENT from macro to static inline
    
    This is the last function-like macro in glamor_priv.h; change to
    static inline like all of the other functions there.
    
    Signed-off-by: Keith Packard <keithp at keithp.com>
    Reviewed-by: Adam Jackson <ajax at redhat.com>

diff --git a/glamor/glamor_largepixmap.c b/glamor/glamor_largepixmap.c
index 5a4bec5..4c82a8d 100644
--- a/glamor/glamor_largepixmap.c
+++ b/glamor/glamor_largepixmap.c
@@ -970,7 +970,7 @@ _glamor_process_transformed_clipped_region(glamor_pixmap_private *priv,
                                      need_clean_fbo);
     }
     else {
-        SET_PIXMAP_FBO_CURRENT(priv, clipped_regions[0].block_idx);
+        glamor_set_pixmap_fbo_current(priv, clipped_regions[0].block_idx);
         if (repeat_type == RepeatReflect || repeat_type == RepeatNormal) {
             /* The required source areas are in one region,
              * we need to shift the corresponding box's coords to proper position,
@@ -1140,7 +1140,7 @@ glamor_composite_largepixmap_region(CARD8 op,
         DEBUGF("dest region %d  idx %d\n", i,
                clipped_dest_regions[i].block_idx);
         DEBUGRegionPrint(clipped_dest_regions[i].region);
-        SET_PIXMAP_FBO_CURRENT(dest_pixmap_priv,
+        glamor_set_pixmap_fbo_current(dest_pixmap_priv,
                                clipped_dest_regions[i].block_idx);
         if (source_pixmap_priv &&
             source_pixmap_priv->type == GLAMOR_TEXTURE_LARGE) {
@@ -1180,7 +1180,7 @@ glamor_composite_largepixmap_region(CARD8 op,
             DEBUGF("source clipped result %d region: \n", n_source_regions);
             for (j = 0; j < n_source_regions; j++) {
                 if (is_normal_source_fbo)
-                    SET_PIXMAP_FBO_CURRENT(source_pixmap_priv,
+                    glamor_set_pixmap_fbo_current(source_pixmap_priv,
                                            clipped_source_regions[j].block_idx);
 
                 if (mask_pixmap_priv &&
@@ -1267,7 +1267,7 @@ glamor_composite_largepixmap_region(CARD8 op,
                                clipped_mask_regions[k].block_idx);
                         DEBUGRegionPrint(clipped_mask_regions[k].region);
                         if (is_normal_mask_fbo) {
-                            SET_PIXMAP_FBO_CURRENT(mask_pixmap_priv,
+                            glamor_set_pixmap_fbo_current(mask_pixmap_priv,
                                                    clipped_mask_regions[k].
                                                    block_idx);
                             DEBUGF("mask fbo off %d %d \n",
@@ -1378,7 +1378,7 @@ glamor_composite_largepixmap_region(CARD8 op,
                            clipped_mask_regions[k].block_idx);
                     DEBUGRegionPrint(clipped_mask_regions[k].region);
                     if (is_normal_mask_fbo) {
-                        SET_PIXMAP_FBO_CURRENT(mask_pixmap_priv,
+                        glamor_set_pixmap_fbo_current(mask_pixmap_priv,
                                                clipped_mask_regions[k].
                                                block_idx);
                         RegionTranslate(clipped_mask_regions[k].region,
diff --git a/glamor/glamor_pixmap.c b/glamor/glamor_pixmap.c
index ccb49f3..11e9ebb 100644
--- a/glamor/glamor_pixmap.c
+++ b/glamor/glamor_pixmap.c
@@ -985,7 +985,7 @@ glamor_upload_sub_pixmap_to_texture(PixmapPtr pixmap, int x, int y, int w,
 
             assert(pbo == 0);
 
-            SET_PIXMAP_FBO_CURRENT(pixmap_priv, clipped_regions[i].block_idx);
+            glamor_set_pixmap_fbo_current(pixmap_priv, clipped_regions[i].block_idx);
 
             boxes = RegionRects(clipped_regions[i].region);
             nbox = RegionNumRects(clipped_regions[i].region);
diff --git a/glamor/glamor_priv.h b/glamor/glamor_priv.h
index aa59e3b..51adeef 100644
--- a/glamor/glamor_priv.h
+++ b/glamor/glamor_priv.h
@@ -438,14 +438,6 @@ typedef struct glamor_pixmap_clipped_regions {
     RegionPtr region;
 } glamor_pixmap_clipped_regions;
 
-#define SET_PIXMAP_FBO_CURRENT(priv, idx) 				\
-  do {									\
-	if (priv->type == GLAMOR_TEXTURE_LARGE) {			\
-		(priv)->large.base.fbo = priv->large.fbo_array[idx]; 	\
-		(priv)->large.box = priv->large.box_array[idx]; 	\
-	}								\
-  } while(0)
-
 typedef struct glamor_pixmap_private_base {
     glamor_pixmap_type_t type;
     enum glamor_fbo_state gl_fbo;
@@ -518,6 +510,15 @@ typedef struct glamor_pixmap_private {
     };
 } glamor_pixmap_private;
 
+static inline void
+glamor_set_pixmap_fbo_current(glamor_pixmap_private *priv, int idx)
+{
+    if (priv->type == GLAMOR_TEXTURE_LARGE) {
+        priv->large.base.fbo = priv->large.fbo_array[idx];
+        priv->large.box = priv->large.box_array[idx];
+    }
+}
+
 static inline glamor_pixmap_fbo *
 glamor_pixmap_fbo_at(glamor_pixmap_private *priv, int x, int y)
 {
commit ea7357de90792cbceca6d8d9fdc144e7df8a0fba
Author: Keith Packard <keithp at keithp.com>
Date:   Wed Sep 10 14:01:59 2014 -0700

    present: Clear pending flip pixmaps at CloseScreen
    
    If a flip is active at server reset time, the associated window will
    get destroyed which will queue an unflip operation. If that isn't
    synchronous, then it won't have finished by the time CloseScreen is
    called.
    
    Calling present_flip_idle will signal the fence and remove the
    reference to the fence and pixmap, freeing these in the X server and
    allowing a DRM client to clean up as well.
    
    This also rewords other comments in present_flip_destroy, removing
    scary words about needing synchronous operation (everything in this
    function is synchronous now) and describing what effect we actually
    need from present_set_abort_flip.
    
    Signed-off-by: Keith Packard <keithp at keithp.com>
    Reviewed-by: Adam Jackson <ajax at redhat.com>

diff --git a/present/present.c b/present/present.c
index 9be690c..e838da7 100644
--- a/present/present.c
+++ b/present/present.c
@@ -938,11 +938,12 @@ present_flip_destroy(ScreenPtr screen)
 {
     present_screen_priv_ptr     screen_priv = present_screen_priv(screen);
 
-    /* XXX this needs to be synchronous for server reset */
-
-    /* Do the actual cleanup once the flip has been performed by the hardware */
+    /* Reset window pixmaps back to the screen pixmap */
     if (screen_priv->flip_pending)
         present_set_abort_flip(screen);
+
+    /* Drop reference to any pending flip or unflip pixmaps. */
+    present_flip_idle(screen);
 }
 
 void
commit 2051514652481a83bd7cf22e57cb0fcd40333f33
Author: Keith Packard <keithp at keithp.com>
Date:   Wed Sep 10 14:02:13 2014 -0700

    present: Support PresentOptionCopy
    
    We added this option to the present protocol before 1.0 but somehow
    never implemented it in the server. It's pretty simple; just don't
    ever do flips if the application specifies Copy.
    
    Signed-off-by: Keith Packard <keithp at keithp.com>
    Reviewed-by: Adam Jackson <ajax at redhat.com>

diff --git a/present/present.c b/present/present.c
index f488e21..9be690c 100644
--- a/present/present.c
+++ b/present/present.c
@@ -837,7 +837,10 @@ present_pixmap(WindowPtr window,
     if (!screen_priv->info || !(screen_priv->info->capabilities & PresentCapabilityAsync))
         vblank->sync_flip = TRUE;
 
-    if (pixmap && present_check_flip (target_crtc, window, pixmap, vblank->sync_flip, valid, x_off, y_off)) {
+    if (!(options & PresentOptionCopy) &&
+        pixmap != NULL &&
+        present_check_flip (target_crtc, window, pixmap, vblank->sync_flip, valid, x_off, y_off))
+    {
         vblank->flip = TRUE;
         if (vblank->sync_flip)
             target_msc--;
commit 69d8572ae4cd1bce17223ea8aff87916a974c861
Author: Keith Packard <keithp at keithp.com>
Date:   Wed Sep 10 15:21:32 2014 -0700

    Build required portions of registry.c automatically [v2]
    
    Instead of making the inclusion of the registry code a global
    conditional, split the registry into two pieces; the bits required by
    the X-Resource extension (the resource names) and the bits required by
    the XCSECURITY extension (the protocol names). Build each set of code
    if the related extension is being built.
    
    v2: Check for both XCSECURITY and XSELINUX.
    
    Signed-off-by: Keith Packard <keithp at keithp.com>
    Reviewed-by: Adam Jackson <ajax at redhat.com>

diff --git a/configure.ac b/configure.ac
index 140fb97..be8bff6 100644
--- a/configure.ac
+++ b/configure.ac
@@ -564,7 +564,6 @@ AC_ARG_WITH(khronos-spec-dir, AS_HELP_STRING([--with-khronos-spec-dir=PATH], [Pa
 				[KHRONOS_SPEC_DIR=auto])
 
 dnl Extensions.
-AC_ARG_ENABLE(registry,       AS_HELP_STRING([--disable-registry], [Build string registry module (default: enabled)]), [XREGISTRY=$enableval], [XREGISTRY=yes])
 AC_ARG_ENABLE(composite,      AS_HELP_STRING([--disable-composite], [Build Composite extension (default: enabled)]), [COMPOSITE=$enableval], [COMPOSITE=yes])
 AC_ARG_ENABLE(mitshm,         AS_HELP_STRING([--disable-mitshm], [Build SHM extension (default: auto)]), [MITSHM=$enableval], [MITSHM=auto])
 AC_ARG_ENABLE(xres,           AS_HELP_STRING([--disable-xres], [Build XRes extension (default: enabled)]), [RES=$enableval], [RES=yes])
@@ -1016,11 +1015,6 @@ if test "x$XVMC" = xyes; then
 	AC_DEFINE(XvMCExtension, 1, [Build XvMC extension])
 fi
 
-AM_CONDITIONAL(XREGISTRY, [test "x$XREGISTRY" = xyes])
-if test "x$XREGISTRY" = xyes; then
-	AC_DEFINE(XREGISTRY, 1, [Build registry module])
-fi
-
 AM_CONDITIONAL(COMPOSITE, [test "x$COMPOSITE" = xyes])
 if test "x$COMPOSITE" = xyes; then
 	AC_DEFINE(COMPOSITE, 1, [Support Composite Extension])
diff --git a/dix/extension.c b/dix/extension.c
index ede4bf5..e43291e 100644
--- a/dix/extension.c
+++ b/dix/extension.c
@@ -139,7 +139,9 @@ AddExtension(const char *name, int NumEvents, int NumErrors,
         ext->errorLast = 0;
     }
 
+#ifdef X_REGISTRY_REQUEST
     RegisterExtensionNames(ext);
+#endif
     return ext;
 }
 
diff --git a/dix/registry.c b/dix/registry.c
index 8b76d56..84d48b4 100644
--- a/dix/registry.c
+++ b/dix/registry.c
@@ -21,8 +21,6 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 #include <dix-config.h>
 #endif
 
-#ifdef XREGISTRY
-
 #include <stdlib.h>
 #include <string.h>
 #include <X11/X.h>
@@ -31,6 +29,8 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 #include "registry.h"
 
 #define BASE_SIZE 16
+
+#ifdef X_REGISTRY_REQUEST
 #define CORE "X11"
 #define FILENAME SERVER_MISC_CONFIG_PATH "/protocol.txt"
 
@@ -42,9 +42,15 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 static FILE *fh;
 
 static char ***requests, **events, **errors;
+static unsigned nmajor, *nminor, nevent, nerror;
+#endif
+
+#ifdef X_REGISTRY_RESOURCE
 static const char **resources;
-static unsigned nmajor, *nminor, nevent, nerror, nresource;
+static unsigned nresource;
+#endif
 
+#if defined(X_REGISTRY_RESOURCE) || defined(X_REGISTRY_REQUEST)
 /*
  * File parsing routines
  */
@@ -72,7 +78,12 @@ double_size(void *p, unsigned n, unsigned size)
     memset(*ptr + s, 0, f - s);
     return TRUE;
 }
+#endif
 
+#ifdef X_REGISTRY_REQUEST
+/*
+ * Request/event/error registry functions
+ */
 static void
 RegisterRequestName(unsigned major, unsigned minor, char *name)
 {
@@ -197,28 +208,6 @@ RegisterExtensionNames(ExtensionEntry * extEntry)
     }
 }
 
-/*
- * Registration functions
- */
-
-void
-RegisterResourceName(RESTYPE resource, const char *name)
-{
-    resource &= TypeMask;
-
-    while (resource >= nresource) {
-        if (!double_size(&resources, nresource, sizeof(char *)))
-            return;
-        nresource = nresource ? nresource * 2 : BASE_SIZE;
-    }
-
-    resources[resource] = name;
-}
-
-/*
- * Lookup functions
- */
-
 const char *
 LookupRequestName(int major, int minor)
 {
@@ -269,6 +258,26 @@ LookupErrorName(int error)
 
     return errors[error] ? errors[error] : XREGISTRY_UNKNOWN;
 }
+#endif /* X_REGISTRY_REQUEST */
+
+#ifdef X_REGISTRY_RESOURCE
+/*
+ * Resource registry functions
+ */
+
+void
+RegisterResourceName(RESTYPE resource, const char *name)
+{
+    resource &= TypeMask;
+
+    while (resource >= nresource) {
+        if (!double_size(&resources, nresource, sizeof(char *)))
+            return;
+        nresource = nresource ? nresource * 2 : BASE_SIZE;
+    }
+
+    resources[resource] = name;
+}
 
 const char *
 LookupResourceName(RESTYPE resource)
@@ -279,10 +288,12 @@ LookupResourceName(RESTYPE resource)
 
     return resources[resource] ? resources[resource] : XREGISTRY_UNKNOWN;
 }
+#endif /* X_REGISTRY_RESOURCE */
 
 void
 dixFreeRegistry(void)
 {
+#ifdef X_REGISTRY_REQUEST
     /* Free all memory */
     while (nmajor--) {
         while (nminor[nmajor])
@@ -299,25 +310,30 @@ dixFreeRegistry(void)
     while (nerror--)
         free(errors[nerror]);
     free(errors);
-
-    free(resources);
-
     requests = NULL;
     nminor = NULL;
     events = NULL;
     errors = NULL;
-    resources = NULL;
+    nmajor = nevent = nerror = 0;
+#endif
+
+#ifdef X_REGISTRY_RESOURCE
+    free(resources);
 
-    nmajor = nevent = nerror = nresource = 0;
+    resources = NULL;
+    nresource = 0;
+#endif
 }
 
 void
 dixCloseRegistry(void)
 {
+#ifdef X_REGISTRY_REQUEST
     if (fh) {
 	fclose(fh);
         fh = NULL;
     }
+#endif
 }
 
 /*
@@ -326,16 +342,24 @@ dixCloseRegistry(void)
 void
 dixResetRegistry(void)
 {
+#ifdef X_REGISTRY_REQUEST
     ExtensionEntry extEntry = { .name = CORE };
+#endif
 
     dixFreeRegistry();
 
+#ifdef X_REGISTRY_REQUEST
     /* Open the protocol file */
     fh = fopen(FILENAME, "r");
     if (!fh)
         LogMessage(X_WARNING,
                    "Failed to open protocol names file " FILENAME "\n");
 
+    /* Add the core protocol */
+    RegisterExtensionNames(&extEntry);
+#endif
+
+#ifdef X_REGISTRY_RESOURCE
     /* Add built-in resources */
     RegisterResourceName(RT_NONE, "NONE");
     RegisterResourceName(RT_WINDOW, "WINDOW");
@@ -347,9 +371,5 @@ dixResetRegistry(void)
     RegisterResourceName(RT_CMAPENTRY, "COLORMAP ENTRY");
     RegisterResourceName(RT_OTHERCLIENT, "OTHER CLIENT");
     RegisterResourceName(RT_PASSIVEGRAB, "PASSIVE GRAB");
-
-    /* Add the core protocol */
-    RegisterExtensionNames(&extEntry);
+#endif
 }
-
-#endif                          /* XREGISTRY */
diff --git a/dix/resource.c b/dix/resource.c
index 623d862..c254244 100644
--- a/dix/resource.c
+++ b/dix/resource.c
@@ -524,8 +524,10 @@ CreateNewResourceType(DeleteType deleteFunc, const char *name)
     resourceTypes[next].findSubResFunc = DefaultFindSubRes;
     resourceTypes[next].errorValue = BadValue;
 
+#if X_REGISTRY_RESOURCE
     /* Called even if name is NULL, to remove any previous entry */
     RegisterResourceName(next, name);
+#endif
 
     return next;
 }
diff --git a/include/registry.h b/include/registry.h
index 4e54bf6..43c3db3 100644
--- a/include/registry.h
+++ b/include/registry.h
@@ -17,18 +17,26 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  */
 #define XREGISTRY_UNKNOWN "<unknown>"
 
-#ifdef XREGISTRY
-
 #include "resource.h"
 #include "extnsionst.h"
 
+#if defined(XSELINUX) || defined(RES)
+#define X_REGISTRY_RESOURCE       1
+#endif
+
+#if defined(XSELINUX) || defined(XCSECURITY)
+#define X_REGISTRY_REQUEST        1
+#endif
+
 /* Internal string registry - for auditing, debugging, security, etc. */
 
-/*
- * Registration functions.  The name string is not copied, so it must
- * not be a stack variable.
- */
+#ifdef X_REGISTRY_RESOURCE
+/* Functions used by the X-Resource extension */
 extern _X_EXPORT void RegisterResourceName(RESTYPE type, const char *name);
+extern _X_EXPORT const char *LookupResourceName(RESTYPE rtype);
+#endif
+
+#ifdef X_REGISTRY_REQUEST
 extern _X_EXPORT void RegisterExtensionNames(ExtensionEntry * ext);
 
 /*
@@ -38,7 +46,7 @@ extern _X_EXPORT const char *LookupMajorName(int major);
 extern _X_EXPORT const char *LookupRequestName(int major, int minor);
 extern _X_EXPORT const char *LookupEventName(int event);
 extern _X_EXPORT const char *LookupErrorName(int error);
-extern _X_EXPORT const char *LookupResourceName(RESTYPE rtype);
+#endif
 
 /*
  * Setup and teardown
@@ -47,21 +55,4 @@ extern _X_EXPORT void dixResetRegistry(void);
 extern _X_EXPORT void dixFreeRegistry(void);
 extern _X_EXPORT void dixCloseRegistry(void);
 
-#else                           /* XREGISTRY */
-
-/* Define calls away when the registry is not being built. */
-
-#define RegisterResourceName(a, b) { ; }
-#define RegisterExtensionNames(a) { ; }
-
-#define LookupMajorName(a) XREGISTRY_UNKNOWN
-#define LookupRequestName(a, b) XREGISTRY_UNKNOWN
-#define LookupEventName(a) XREGISTRY_UNKNOWN
-#define LookupErrorName(a) XREGISTRY_UNKNOWN
-#define LookupResourceName(a) XREGISTRY_UNKNOWN
-
-#define dixResetRegistry() { ; }
-#define dixFreeRegistry() { ; }
-
-#endif                          /* XREGISTRY */
 #endif                          /* DIX_REGISTRY_H */
commit a11fc2493e85e4a532f4954805a7c6d1c601b08f
Author: Keith Packard <keithp at keithp.com>
Date:   Wed Sep 10 15:04:00 2014 -0700

    dix: Close protocol.txt after we're done loading extension names
    
    Don't leave this file open during the whole server execution process;
    close it once all of the extensions are initialized.
    
    Signed-off-by: Keith Packard <keithp at keithp.com>
    Reviewed-by: Adam Jackson <ajax at redhat.com>

diff --git a/dix/main.c b/dix/main.c
index 7427e08..930a85f 100644
--- a/dix/main.c
+++ b/dix/main.c
@@ -269,6 +269,8 @@ dix_main(int argc, char *argv[], char *envp[])
 
         dixSaveScreens(serverClient, SCREEN_SAVER_FORCER, ScreenSaverReset);
 
+        dixCloseRegistry();
+
 #ifdef PANORAMIX
         if (!noPanoramiXExtension) {
             if (!PanoramiXCreateConnectionBlock()) {
diff --git a/dix/registry.c b/dix/registry.c
index 82a3340..8b76d56 100644
--- a/dix/registry.c
+++ b/dix/registry.c
@@ -309,7 +309,11 @@ dixFreeRegistry(void)
     resources = NULL;
 
     nmajor = nevent = nerror = nresource = 0;
+}
 
+void
+dixCloseRegistry(void)
+{
     if (fh) {
 	fclose(fh);
         fh = NULL;
diff --git a/include/registry.h b/include/registry.h
index 96be87a..4e54bf6 100644
--- a/include/registry.h
+++ b/include/registry.h
@@ -45,6 +45,7 @@ extern _X_EXPORT const char *LookupResourceName(RESTYPE rtype);
  */
 extern _X_EXPORT void dixResetRegistry(void);
 extern _X_EXPORT void dixFreeRegistry(void);
+extern _X_EXPORT void dixCloseRegistry(void);
 
 #else                           /* XREGISTRY */
 
commit 9e07f3a3d28b01402beecb3280c94fc525bd8075
Author: Keith Packard <keithp at keithp.com>
Date:   Wed Sep 10 15:41:08 2014 -0700

    test: Only build hashtable tests if building X-Resource extension
    
    The hash table functions are only included in the server when the
    X-Resource extension is built, so don't try to build and test them
    unless the X-Resource extension is being built.
    
    Signed-off-by: Keith Packard <keithp at keithp.com>
    Reviewed-by: Adam Jackson <ajax at redhat.com>

diff --git a/test/Makefile.am b/test/Makefile.am
index 32edc7a..8344276 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -5,7 +5,10 @@ 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 os signal-logging touch
+noinst_PROGRAMS += xkb input xtest misc fixes xfree86 os signal-logging touch
+if RES
+noinst_PROGRAMS += hashtabletest
+endif
 endif
 check_LTLIBRARIES = libxservertest.la
 
commit 670ee0757febfb965d718fce2d5688717def667d
Author: Adam Jackson <ajax at redhat.com>
Date:   Tue Sep 16 11:10:58 2014 -0400

    ephyr: Properly implement hardware cursors (v3)
    
    When dix hands us a new cursor we proxy it through to the host server;
    since we keep the host XID on the cursor bits private we can switch
    among them with just ChangeWindowAttributes.
    
    v2:
    Use xcb-renderutil for argb format lookup (Uli, Keith)
    Fall back to core cursors for host RENDER < 0.5 (Keith)
    Drop useless ephyrEnableCursor
    Consistently create/destroy the cursor image GC on both paths
    Treat null cursor from dix as invisible
    
    v3:
    Initialize the invisible cursor's image (Keith)
    
    Signed-off-by: Adam Jackson <ajax at redhat.com>
    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 0d6c232..140fb97 100644
--- a/configure.ac
+++ b/configure.ac
@@ -2349,7 +2349,7 @@ if test "$KDRIVE" = yes; then
        AC_DEFINE(KDRIVE_MOUSE, 1, [Enable KDrive mouse driver])
     fi
 
-    XEPHYR_REQUIRED_LIBS="xau xdmcp xcb xcb-shape xcb-aux xcb-image xcb-icccm xcb-shm xcb-keysyms xcb-randr"
+    XEPHYR_REQUIRED_LIBS="xau xdmcp xcb xcb-shape xcb-render xcb-renderutil xcb-aux xcb-image xcb-icccm xcb-shm xcb-keysyms xcb-randr"
     if test "x$XV" = xyes; then
         XEPHYR_REQUIRED_LIBS="$XEPHYR_REQUIRED_LIBS xcb-xv"
     fi
diff --git a/hw/kdrive/ephyr/Makefile.am b/hw/kdrive/ephyr/Makefile.am
index 10c5917..155e11e 100644
--- a/hw/kdrive/ephyr/Makefile.am
+++ b/hw/kdrive/ephyr/Makefile.am
@@ -68,6 +68,7 @@ Xephyr_SOURCES = \
 	ephyr_draw.c \
 	os.c \
 	ephyrinit.c \
+	ephyrcursor.c \
 	hostx.c \
 	hostx.h \
 	$(XV_SRCS) \
diff --git a/hw/kdrive/ephyr/ephyr.h b/hw/kdrive/ephyr/ephyr.h
index 4e753f1..f3a3c8e 100644
--- a/hw/kdrive/ephyr/ephyr.h
+++ b/hw/kdrive/ephyr/ephyr.h
@@ -197,8 +197,6 @@ extern KdOsFuncs EphyrOsFuncs;
 
 extern Bool ephyrCursorInit(ScreenPtr pScreen);
 
-extern void ephyrCursorEnable(ScreenPtr pScreen);
-
 extern int ephyrBufferHeight(KdScreenInfo * screen);
 
 /* ephyr_draw.c */
diff --git a/hw/kdrive/ephyr/ephyrcursor.c b/hw/kdrive/ephyr/ephyrcursor.c
new file mode 100644
index 0000000..852be33
--- /dev/null
+++ b/hw/kdrive/ephyr/ephyrcursor.c
@@ -0,0 +1,262 @@
+/*
+ * Copyright © 2014 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.
+ *
+ * Author:
+ *      Adam Jackson <ajax at redhat.com>
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <kdrive-config.h>
+#endif
+#include "ephyr.h"
+#include "ephyrlog.h"
+#include "hostx.h"
+#include "cursorstr.h"
+#include <xcb/render.h>
+#include <xcb/xcb_renderutil.h>
+
+static DevPrivateKeyRec ephyrCursorPrivateKey;
+
+typedef struct _ephyrCursor {
+    xcb_cursor_t cursor;
+} ephyrCursorRec, *ephyrCursorPtr;
+
+static ephyrCursorPtr
+ephyrGetCursor(CursorPtr cursor)
+{
+    return dixGetPrivateAddr(&cursor->devPrivates, &ephyrCursorPrivateKey);
+}
+
+static void
+ephyrRealizeCoreCursor(EphyrScrPriv *scr, CursorPtr cursor)
+{
+    ephyrCursorPtr hw = ephyrGetCursor(cursor);
+    xcb_connection_t *conn = hostx_get_xcbconn();
+    xcb_pixmap_t source, mask;
+    xcb_image_t *image;
+    xcb_gcontext_t gc;
+    int w = cursor->bits->width, h = cursor->bits->height;
+    uint32_t gcmask = XCB_GC_FUNCTION |
+                      XCB_GC_PLANE_MASK |
+                      XCB_GC_FOREGROUND |
+                      XCB_GC_BACKGROUND |
+                      XCB_GC_CLIP_MASK;
+    uint32_t val[] = {
+        XCB_GX_COPY,    /* function */
+        ~0,             /* planemask */
+        1L,             /* foreground */
+        0L,             /* background */
+        None,           /* clipmask */
+    };
+
+    source = xcb_generate_id(conn);
+    mask = xcb_generate_id(conn);
+    xcb_create_pixmap(conn, 1, source, scr->win, w, h);
+    xcb_create_pixmap(conn, 1, mask, scr->win, w, h);
+
+    gc = xcb_generate_id(conn);
+    xcb_create_gc(conn, gc, source, gcmask, val);
+
+    image = xcb_image_create_native(conn, w, h, XCB_IMAGE_FORMAT_XY_BITMAP,
+                                    1, NULL, ~0, NULL);
+    image->data = cursor->bits->source;
+    xcb_image_put(conn, source, gc, image, 0, 0, 0);
+    xcb_image_destroy(image);
+
+    image = xcb_image_create_native(conn, w, h, XCB_IMAGE_FORMAT_XY_BITMAP,
+                                    1, NULL, ~0, NULL);
+    image->data = cursor->bits->mask;
+    xcb_image_put(conn, mask, gc, image, 0, 0, 0);
+    xcb_image_destroy(image);
+
+    xcb_free_gc(conn, gc);
+
+    hw->cursor = xcb_generate_id(conn);
+    xcb_create_cursor(conn, hw->cursor, source, mask,
+                      cursor->foreRed, cursor->foreGreen, cursor->foreBlue,
+                      cursor->backRed, cursor->backGreen, cursor->backBlue,
+                      cursor->bits->xhot, cursor->bits->yhot);
+
+    xcb_free_pixmap(conn, source);
+    xcb_free_pixmap(conn, mask);
+}
+
+#ifdef ARGB_CURSOR
+static xcb_render_pictformat_t
+get_argb_format(void)
+{
+    static xcb_render_pictformat_t format;
+    if (format == None) {
+        xcb_connection_t *conn = hostx_get_xcbconn();
+        xcb_render_query_pict_formats_cookie_t cookie;
+        xcb_render_query_pict_formats_reply_t *formats;
+
+        cookie = xcb_render_query_pict_formats(conn);
+        formats =
+            xcb_render_query_pict_formats_reply(conn, cookie, NULL);
+
+        format =
+            xcb_render_util_find_standard_format(formats,
+                                                 XCB_PICT_STANDARD_ARGB_32)->id;
+
+        free(formats);
+    }
+
+    return format;
+}
+
+static void
+ephyrRealizeARGBCursor(EphyrScrPriv *scr, CursorPtr cursor)
+{
+    ephyrCursorPtr hw = ephyrGetCursor(cursor);
+    xcb_connection_t *conn = hostx_get_xcbconn();
+    xcb_gcontext_t gc;
+    xcb_pixmap_t source;
+    xcb_render_picture_t picture;
+    xcb_image_t *image;
+    int w = cursor->bits->width, h = cursor->bits->height;
+
+    /* dix' storage is PICT_a8r8g8b8 */
+    source = xcb_generate_id(conn);
+    xcb_create_pixmap(conn, 32, source, scr->win, w, h);
+
+    gc = xcb_generate_id(conn);
+    xcb_create_gc(conn, gc, source, 0, NULL);
+    image = xcb_image_create_native(conn, w, h, XCB_IMAGE_FORMAT_Z_PIXMAP,
+                                    32, NULL, ~0, NULL);
+    image->data = (void *)cursor->bits->argb;
+    xcb_image_put(conn, source, gc, image, 0, 0, 0);
+    xcb_free_gc(conn, gc);
+    xcb_image_destroy(image);
+
+    picture = xcb_generate_id(conn);
+    xcb_render_create_picture(conn, picture, source, get_argb_format(),
+                              0, NULL);
+    xcb_free_pixmap(conn, source);
+
+    hw->cursor = xcb_generate_id(conn);
+    xcb_render_create_cursor(conn, hw->cursor, picture,
+                             cursor->bits->xhot, cursor->bits->yhot);
+
+    xcb_render_free_picture(conn, picture);
+}
+
+static Bool
+can_argb_cursor(void)
+{
+    static const xcb_render_query_version_reply_t *v;
+
+    if (!v)
+        v = xcb_render_util_query_version(hostx_get_xcbconn());
+
+    return v->major_version == 0 && v->minor_version >= 5;
+}
+#endif
+
+static Bool
+ephyrRealizeCursor(DeviceIntPtr dev, ScreenPtr screen, CursorPtr cursor)
+{
+    KdScreenPriv(screen);
+    KdScreenInfo *kscr = pScreenPriv->screen;
+    EphyrScrPriv *scr = kscr->driver;
+
+#ifdef ARGB_CURSOR
+    if (cursor->bits->argb && can_argb_cursor())
+        ephyrRealizeARGBCursor(scr, cursor);
+    else
+#endif
+    {
+        ephyrRealizeCoreCursor(scr, cursor);
+    }
+    return TRUE;
+}
+
+static Bool
+ephyrUnrealizeCursor(DeviceIntPtr dev, ScreenPtr screen, CursorPtr cursor)
+{
+    ephyrCursorPtr hw = ephyrGetCursor(cursor);
+
+    if (hw->cursor) {
+        xcb_free_cursor(hostx_get_xcbconn(), hw->cursor);
+        hw->cursor = None;
+    }
+
+    return TRUE;
+}
+
+static void
+ephyrSetCursor(DeviceIntPtr dev, ScreenPtr screen, CursorPtr cursor, int x,
+               int y)
+{
+    KdScreenPriv(screen);
+    KdScreenInfo *kscr = pScreenPriv->screen;
+    EphyrScrPriv *scr = kscr->driver;
+    uint32_t attr = None;
+
+    if (cursor)
+        attr = ephyrGetCursor(cursor)->cursor;
+    else
+        attr = hostx_get_empty_cursor();
+
+    xcb_change_window_attributes(hostx_get_xcbconn(), scr->win,
+                                 XCB_CW_CURSOR, &attr);
+    xcb_flush(hostx_get_xcbconn());
+}
+
+static void
+ephyrMoveCursor(DeviceIntPtr dev, ScreenPtr screen, int x, int y)
+{
+}
+
+static Bool
+ephyrDeviceCursorInitialize(DeviceIntPtr dev, ScreenPtr screen)
+{
+    return TRUE;
+}
+
+static void
+ephyrDeviceCursorCleanup(DeviceIntPtr dev, ScreenPtr screen)
+{
+}
+
+miPointerSpriteFuncRec EphyrPointerSpriteFuncs = {
+    ephyrRealizeCursor,
+    ephyrUnrealizeCursor,
+    ephyrSetCursor,
+    ephyrMoveCursor,
+    ephyrDeviceCursorInitialize,
+    ephyrDeviceCursorCleanup
+};
+
+Bool
+ephyrCursorInit(ScreenPtr screen)
+{
+    if (!dixRegisterPrivateKey(&ephyrCursorPrivateKey, PRIVATE_CURSOR_BITS,
+                               sizeof(ephyrCursorRec)))
+        return FALSE;
+
+    miPointerInitialize(screen,
+                        &EphyrPointerSpriteFuncs,
+                        &ephyrPointerScreenFuncs, FALSE);
+
+    return TRUE;
+}
diff --git a/hw/kdrive/ephyr/ephyrinit.c b/hw/kdrive/ephyr/ephyrinit.c
index 38acc52..3693531 100644
--- a/hw/kdrive/ephyr/ephyrinit.c
+++ b/hw/kdrive/ephyr/ephyrinit.c
@@ -369,77 +369,12 @@ OsVendorInit(void)
 {
     EPHYR_DBG("mark");
 
-    if (hostx_want_host_cursor()) {
+    if (hostx_want_host_cursor())
         ephyrFuncs.initCursor = &ephyrCursorInit;
-        ephyrFuncs.enableCursor = &ephyrCursorEnable;
-    }
 
     KdOsInit(&EphyrOsFuncs);
 }
 
-/* 'Fake' cursor stuff, could be improved */
-
-static Bool
-ephyrRealizeCursor(DeviceIntPtr pDev, ScreenPtr pScreen, CursorPtr pCursor)
-{
-    return TRUE;
-}
-
-static Bool
-ephyrUnrealizeCursor(DeviceIntPtr pDev, ScreenPtr pScreen, CursorPtr pCursor)
-{
-    return TRUE;
-}
-
-static void
-ephyrSetCursor(DeviceIntPtr pDev, ScreenPtr pScreen, CursorPtr pCursor, int x,
-               int y)
-{
-    ;
-}
-
-static void
-ephyrMoveCursor(DeviceIntPtr pDev, ScreenPtr pScreen, int x, int y)
-{
-    ;
-}
-
-static Bool
-ephyrDeviceCursorInitialize(DeviceIntPtr pDev, ScreenPtr pScreen)
-{
-    return TRUE;
-}
-
-static void
-ephyrDeviceCursorCleanup(DeviceIntPtr pDev, ScreenPtr pScreen)
-{
-}
-
-miPointerSpriteFuncRec EphyrPointerSpriteFuncs = {
-    ephyrRealizeCursor,
-    ephyrUnrealizeCursor,
-    ephyrSetCursor,
-    ephyrMoveCursor,
-    ephyrDeviceCursorInitialize,
-    ephyrDeviceCursorCleanup
-};
-
-Bool
-ephyrCursorInit(ScreenPtr pScreen)
-{
-    miPointerInitialize(pScreen,
-                        &EphyrPointerSpriteFuncs,
-                        &ephyrPointerScreenFuncs, FALSE);
-
-    return TRUE;
-}
-
-void
-ephyrCursorEnable(ScreenPtr pScreen)
-{
-    ;
-}
-
 KdCardFuncs ephyrFuncs = {
     ephyrCardInit,              /* cardinit */
     ephyrScreenInitialize,      /* scrinit */
diff --git a/hw/kdrive/ephyr/hostx.c b/hw/kdrive/ephyr/hostx.c
index 2161ad5..0562625 100644
--- a/hw/kdrive/ephyr/hostx.c
+++ b/hw/kdrive/ephyr/hostx.c
@@ -71,6 +71,8 @@ struct EphyrHostXVars {
     xcb_visualtype_t *visual;
     Window winroot;
     xcb_gcontext_t  gc;
+    xcb_render_pictformat_t argb_format;
+    xcb_cursor_t empty_cursor;
     int depth;
     Bool use_sw_cursor;
     Bool use_fullscreen;
@@ -202,6 +204,12 @@ hostx_use_sw_cursor(void)
     HostX.use_sw_cursor = TRUE;
 }
 
+xcb_cursor_t
+hostx_get_empty_cursor(void)
+{
+    return HostX.empty_cursor;
+}
+
 int
 hostx_want_preexisting_window(KdScreenInfo *screen)
 {
@@ -408,8 +416,8 @@ hostx_init(void)
 {
     uint32_t attrs[2];
     uint32_t attr_mask = 0;
-    xcb_cursor_t empty_cursor;
     xcb_pixmap_t cursor_pxm;
+    xcb_gcontext_t cursor_gc;
     uint16_t red, green, blue;
     uint32_t pixel;
     int index;
@@ -418,6 +426,7 @@ hostx_init(void)
     size_t class_len;
     const xcb_query_extension_reply_t *shm_rep;
     xcb_screen_t *xscreen;
+    xcb_rectangle_t rect = { 0, 0, 1, 1 };
 
     attrs[0] =
         XCB_EVENT_MASK_BUTTON_PRESS
@@ -594,18 +603,25 @@ hostx_init(void)
 
     xcb_change_gc(HostX.conn, HostX.gc, XCB_GC_FOREGROUND, &pixel);
 
+    cursor_pxm = xcb_generate_id(HostX.conn);
+    xcb_create_pixmap(HostX.conn, 1, cursor_pxm, HostX.winroot, 1, 1);
+    cursor_gc = xcb_generate_id(HostX.conn);
+    pixel = 0;
+    xcb_create_gc(HostX.conn, cursor_gc, cursor_pxm,
+                  XCB_GC_FOREGROUND, &pixel);
+    xcb_poly_fill_rectangle(HostX.conn, cursor_pxm, cursor_gc, 1, &rect);
+    xcb_free_gc(HostX.conn, cursor_gc);
+    HostX.empty_cursor = xcb_generate_id(HostX.conn);
+    xcb_create_cursor(HostX.conn,
+                      HostX.empty_cursor,
+                      cursor_pxm, cursor_pxm,
+                      0,0,0,
+                      0,0,0,
+                      1,1);
+    xcb_free_pixmap(HostX.conn, cursor_pxm);
     if (!hostx_want_host_cursor ()) {
         CursorVisible = TRUE;
         /* Ditch the cursor, we provide our 'own' */
-        cursor_pxm = xcb_generate_id(HostX.conn);
-        xcb_create_pixmap(HostX.conn, 1, cursor_pxm, HostX.winroot, 1, 1);
-        empty_cursor = xcb_generate_id(HostX.conn);
-        xcb_create_cursor(HostX.conn,
-                          empty_cursor,
-                          cursor_pxm, cursor_pxm,
-                          0,0,0,
-                          0,0,0,
-                          1,1);
         for (index = 0; index < HostX.n_screens; index++) {
             KdScreenInfo *screen = HostX.screens[index];
             EphyrScrPriv *scrpriv = screen->driver;
@@ -613,9 +629,8 @@ hostx_init(void)
             xcb_change_window_attributes(HostX.conn,
                                          scrpriv->win,
                                          XCB_CW_CURSOR,
-                                         &empty_cursor);
+                                         &HostX.empty_cursor);
         }
-        xcb_free_pixmap(HostX.conn, cursor_pxm);
     }
 
     /* Try to get share memory ximages for a little bit more speed */
diff --git a/hw/kdrive/ephyr/hostx.h b/hw/kdrive/ephyr/hostx.h
index 80894c8..229961e 100644
--- a/hw/kdrive/ephyr/hostx.h
+++ b/hw/kdrive/ephyr/hostx.h
@@ -29,6 +29,7 @@
 #include <X11/X.h>
 #include <X11/Xmd.h>
 #include <xcb/xcb.h>
+#include <xcb/render.h>
 #include "ephyr.h"
 
 #define EPHYR_WANT_DEBUG 0
@@ -82,6 +83,9 @@ int
 void
  hostx_use_sw_cursor(void);
 
+xcb_cursor_t
+ hostx_get_empty_cursor(void);
+
 void
  hostx_get_output_geometry(const char *output,
                            int *x, int *y,
commit f839caadd4e567bf89f893aa7e5ba1327b712b4b
Author: Adam Jackson <ajax at redhat.com>
Date:   Wed Sep 17 11:07:22 2014 -0400

    loader: Remove compatibility with ancient XFree86 version numbering
    
    Pretty sure I'm guilty of adding this.  I think I was thinking of trying
    to be compatible with some really old binary-only driver that I had
    vague aspirations of reverse-engineering, but since I haven't gotten
    around to it in the intervening decade...
    
    Signed-off-by: Adam Jackson <ajax at redhat.com>
    Reviewed-by: Eric Anholt <eric at anholt.net>
    Signed-off-by: Keith Packard <keithp at keithp.com>

diff --git a/hw/xfree86/loader/loadmod.c b/hw/xfree86/loader/loadmod.c
index f1f7c22..21ccb1b 100644
--- a/hw/xfree86/loader/loadmod.c
+++ b/hw/xfree86/loader/loadmod.c
@@ -584,7 +584,6 @@ CheckVersion(const char *module, XF86ModuleVersionInfo * data,
              const XF86ModReqInfo * req)
 {
     int vercode[4];
-    char verstr[4];
     long ver = data->xf86version;
     MessageType errtype;
 
@@ -592,42 +591,15 @@ CheckVersion(const char *module, XF86ModuleVersionInfo * data,
             data->modname ? data->modname : "UNKNOWN!",
             data->vendor ? data->vendor : "UNKNOWN!");
 
-    /* Check for the different scheme used in XFree86 4.0.x releases:
-     * ((((((((major << 7) | minor) << 7) | subminor) << 5) | beta) << 5) | alpha)
-     * Since it wasn't used in 4.1.0 or later, limit to versions in the 4.0.x
-     * range, which limits the overlap with the new version scheme to conflicts
-     * with 6.71.8.764 through 6.72.39.934.
-     */
-    if ((ver > (4 << 24)) && (ver < ((4 << 24) + (1 << 17)))) {
-        /* 4.0.x and earlier */
-        verstr[1] = verstr[3] = 0;
-        verstr[2] = (ver & 0x1f) ? (ver & 0x1f) + 'a' - 1 : 0;
-        ver >>= 5;
-        verstr[0] = (ver & 0x1f) ? (ver & 0x1f) + 'A' - 1 : 0;
-        ver >>= 5;
-        vercode[2] = ver & 0x7f;
-        ver >>= 7;
-        vercode[1] = ver & 0x7f;
-        ver >>= 7;
-        vercode[0] = ver;
-        xf86ErrorF("\tcompiled for %d.%d", vercode[0], vercode[1]);
-        if (vercode[2] != 0)
-            xf86ErrorF(".%d", vercode[2]);
-        xf86ErrorF("%s%s, module version = %d.%d.%d\n", verstr, verstr + 2,
-                   data->majorversion, data->minorversion, data->patchlevel);
-    }
-    else {
-        vercode[0] = ver / 10000000;
-        vercode[1] = (ver / 100000) % 100;
-        vercode[2] = (ver / 1000) % 100;
-        vercode[3] = ver % 1000;
-        xf86ErrorF("\tcompiled for %d.%d.%d", vercode[0], vercode[1],
-                   vercode[2]);
-        if (vercode[3] != 0)
-            xf86ErrorF(".%d", vercode[3]);
-        xf86ErrorF(", module version = %d.%d.%d\n", data->majorversion,
-                   data->minorversion, data->patchlevel);
-    }
+    vercode[0] = ver / 10000000;
+    vercode[1] = (ver / 100000) % 100;
+    vercode[2] = (ver / 1000) % 100;
+    vercode[3] = ver % 1000;
+    xf86ErrorF("\tcompiled for %d.%d.%d", vercode[0], vercode[1], vercode[2]);
+    if (vercode[3] != 0)
+        xf86ErrorF(".%d", vercode[3]);
+    xf86ErrorF(", module version = %d.%d.%d\n", data->majorversion,
+               data->minorversion, data->patchlevel);
 
     if (data->moduleclass)
         xf86ErrorFVerb(2, "\tModule class: %s\n", data->moduleclass);
commit af40913797e6595fb5466c2ff3110e9526a37b9f
Author: Julien Cristau <jcristau at debian.org>
Date:   Wed Sep 17 07:41:27 2014 +0200

    xwayland: always include drm.xml in tarballs
    
    Move drm.xml out of the automake conditional so make dist includes it
    even if glamor-egl is disabled.
    
    Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=83960
    
    Signed-off-by: Julien Cristau <jcristau at debian.org>
    Reviewed-by: Eric Anholt <eric at anholt.net>
    Signed-off-by: Keith Packard <keithp at keithp.com>

diff --git a/hw/xwayland/Makefile.am b/hw/xwayland/Makefile.am
index dc16b8b..4e0e1bb 100644
--- a/hw/xwayland/Makefile.am
+++ b/hw/xwayland/Makefile.am
@@ -39,8 +39,6 @@ nodist_Xwayland_SOURCES =			\
 
 CLEANFILES = $(nodist_Xwayland_SOURCES)
 
-EXTRA_DIST = drm.xml
-
 xwayland-glamor.c : $(nodist_Xwayland_SOURCES)
 
 glamor_lib = $(top_builddir)/glamor/libglamor.la
@@ -48,6 +46,8 @@ glamor_lib = $(top_builddir)/glamor/libglamor.la
 Xwayland_LDADD += $(GLAMOR_LIBS) $(GBM_LIBS) -lEGL -lGL
 endif
 
+EXTRA_DIST = drm.xml
+
 
 relink:
 	$(AM_V_at)rm -f Xwayland$(EXEEXT) && $(MAKE) Xwayland$(EXEEXT)
commit eaee6572beefca240c42791f9a3a6e547bedd410
Merge: e3aa13b b84d25f
Author: Keith Packard <keithp at keithp.com>
Date:   Wed Sep 17 15:49:24 2014 -0700

    Merge remote-tracking branch 'anholt/modesetting-import'

commit e3aa13b8d63ea2fba6eb47ddd0a7dde5a6d2b661
Author: Jon TURNEY <jon.turney at dronecode.org.uk>
Date:   Wed Sep 17 15:38:39 2014 -0700

    Update help text since -iglx is now the default
    
    This should have been part of d0da0e9c3bb8fe0cd4879ecb24d21715bfaa209b
    
    Signed-off-by: Jon TURNEY <jon.turney at dronecode.org.uk>
    Signed-off-by: Eric Anholt <eric at anholt.net>
    Reviewed-by: Eric Anholt <eric at anholt.net>
    Signed-off-by: Keith Packard <keithp at keithp.com>

diff --git a/os/utils.c b/os/utils.c
index c83f77d..2d02f92 100644
--- a/os/utils.c
+++ b/os/utils.c
@@ -541,8 +541,8 @@ UseMsg(void)
     ErrorF("-fn string             default font name\n");
     ErrorF("-fp string             default font path\n");
     ErrorF("-help                  prints message with these options\n");
-    ErrorF("+iglx                  Allow creating indirect GLX contexts (default)\n");
-    ErrorF("-iglx                  Prohibit creating indirect GLX contexts\n");
+    ErrorF("+iglx                  Allow creating indirect GLX contexts\n");
+    ErrorF("-iglx                  Prohibit creating indirect GLX contexts (default)\n");
     ErrorF("-I                     ignore all remaining arguments\n");
 #ifdef RLIMIT_DATA
     ErrorF("-ld int                limit data space to N Kb\n");
commit b84d25fd53e97105b99495af84abaacc4c901967
Author: Eric Anholt <eric at anholt.net>
Date:   Tue Aug 26 11:22:02 2014 -0700

    modesetting: Drop remaining old-xserver compatibility.
    
    Signed-off-by: Eric Anholt <eric at anholt.net>
    Reviewed-by: Keith Packard <keithp at keithp.com>

diff --git a/hw/xfree86/drivers/modesetting/driver.c b/hw/xfree86/drivers/modesetting/driver.c
index 35e73a3..adfb69c 100644
--- a/hw/xfree86/drivers/modesetting/driver.c
+++ b/hw/xfree86/drivers/modesetting/driver.c
@@ -295,10 +295,8 @@ ms_driver_func(ScrnInfoPtr scrn, xorgDriverFuncOp op, void *data)
 	    flag = (CARD32 *)data;
 	    (*flag) = 0;
 	    return TRUE;
-#if XORG_VERSION_CURRENT >= XORG_VERSION_NUMERIC(1,15,99,902,0)
         case SUPPORTS_SERVER_FDS:
             return TRUE;
-#endif
 	default:
 	    return FALSE;
     }
@@ -494,7 +492,7 @@ static void dispatch_dirty(ScreenPtr pScreen)
     ret = dispatch_dirty_region(scrn, pixmap, ms->damage, fb_id);
     if (ret == -EINVAL || ret == -ENOSYS) {
 	ms->dirty_enabled = FALSE;
-	DamageUnregister(&pScreen->GetScreenPixmap(pScreen)->drawable, ms->damage);
+	DamageUnregister(ms->damage);
 	DamageDestroy(ms->damage);
 	ms->damage = NULL;
 	xf86DrvMsg(scrn->scrnIndex, X_INFO, "Disabling kernel dirty updates, not required.\n");
@@ -1082,7 +1080,7 @@ CloseScreen(ScreenPtr pScreen)
     modesettingPtr ms = modesettingPTR(pScrn);
 
     if (ms->damage) {
-	DamageUnregister(&pScreen->GetScreenPixmap(pScreen)->drawable, ms->damage);
+	DamageUnregister(ms->damage);
 	DamageDestroy(ms->damage);
 	ms->damage = NULL;
     }
diff --git a/hw/xfree86/drivers/modesetting/drmmode_display.c b/hw/xfree86/drivers/modesetting/drmmode_display.c
index 88de97c..9723ccd 100644
--- a/hw/xfree86/drivers/modesetting/drmmode_display.c
+++ b/hw/xfree86/drivers/modesetting/drmmode_display.c
@@ -333,9 +333,7 @@ drmmode_set_mode_major(xf86CrtcPtr crtc, DisplayModePtr mode,
 		crtc->x = x;
 		crtc->y = y;
 		crtc->rotation = rotation;
-#if XORG_VERSION_CURRENT >= XORG_VERSION_NUMERIC(1,5,99,0,0)
 		crtc->transformPresent = FALSE;
-#endif
 	}
 
 	output_ids = calloc(sizeof(uint32_t), xf86_config->num_output);
@@ -360,10 +358,8 @@ drmmode_set_mode_major(xf86CrtcPtr crtc, DisplayModePtr mode,
 		if (!xf86CrtcRotate(crtc)) {
 			goto done;
 		}
-#if XORG_VERSION_CURRENT >= XORG_VERSION_NUMERIC(1,7,0,0,0)
 		crtc->funcs->gamma_set(crtc, crtc->gamma_red, crtc->gamma_green,
 				       crtc->gamma_blue, crtc->gamma_size);
-#endif
 		
 		drmmode_ConvertToKMode(crtc->scrn, &kmode, mode);
 
@@ -521,8 +517,7 @@ drmmode_set_scanout_pixmap(xf86CrtcPtr crtc, PixmapPtr ppix)
 			drmModeRmFB(drmmode->fd, ppriv->fb_id);
 		}
 		if (drmmode_crtc->slave_damage) {
-			DamageUnregister(&crtc->randr_crtc->scanout_pixmap->drawable,
-					 drmmode_crtc->slave_damage);
+			DamageUnregister(drmmode_crtc->slave_damage);
 			drmmode_crtc->slave_damage = NULL;
 		}
 		return TRUE;
@@ -947,10 +942,8 @@ drmmode_output_get_property(xf86OutputPtr output, Atom property)
 static const xf86OutputFuncsRec drmmode_output_funcs = {
     .dpms = drmmode_output_dpms,
     .create_resources = drmmode_output_create_resources,
-#ifdef RANDR_12_INTERFACE
     .set_property = drmmode_output_set_property,
     .get_property = drmmode_output_get_property,
-#endif
     .detect = drmmode_output_detect,
     .mode_valid = drmmode_output_mode_valid,
 
@@ -1195,10 +1188,6 @@ drmmode_xf86crtc_resize (ScrnInfoPtr scrn, int width, int height)
 					   pitch, drmmode->shadow_fb);
 	}
 
-#if XORG_VERSION_CURRENT < XORG_VERSION_NUMERIC(1,9,99,1,0)
-	scrn->pixmapPrivate.ptr = ppix->devPrivate.ptr;
-#endif
-
 	for (i = 0; i < xf86_config->num_crtc; i++) {
 		xf86CrtcPtr crtc = xf86_config->crtc[i];
 
@@ -1395,11 +1384,9 @@ static void drmmode_load_palette(ScrnInfoPtr pScrn, int numColors,
           }
 
     /* Make the change through RandR */
-#ifdef RANDR_12_INTERFACE
         if (crtc->randr_crtc)
             RRCrtcGammaSet(crtc->randr_crtc, lut_r, lut_g, lut_b);
         else
-#endif
             crtc->funcs->gamma_set(crtc, lut_r, lut_g, lut_b, 256);
      }
 }
diff --git a/hw/xfree86/drivers/modesetting/drmmode_display.h b/hw/xfree86/drivers/modesetting/drmmode_display.h
index 1954abf..7bfe885 100644
--- a/hw/xfree86/drivers/modesetting/drmmode_display.h
+++ b/hw/xfree86/drivers/modesetting/drmmode_display.h
@@ -32,10 +32,6 @@
 #include "libudev.h"
 #endif
 
-#if XORG_VERSION_CURRENT >= XORG_VERSION_NUMERIC(1,14,99,2,0)
-#define DamageUnregister(d, dd) DamageUnregister(dd)
-#endif
-
 struct dumb_bo {
     uint32_t handle;
     uint32_t size;
@@ -62,9 +58,7 @@ typedef struct {
     Bool shadow_enable;
     void *shadow_fb;
 
-#ifdef HAVE_SCREEN_SPECIFIC_PRIVATE_KEYS
     DevPrivateKeyRec pixmapPrivateKeyRec;
-#endif
 } drmmode_rec, *drmmode_ptr;
 
 typedef struct {
commit 7b0965a826612988dd721ddbd67cfbec392b67b5
Author: Eric Anholt <eric at anholt.net>
Date:   Tue Aug 26 11:37:46 2014 -0700

    modesetting: Drop use of compat-api.h
    
    Signed-off-by: Eric Anholt <eric at anholt.net>
    Reviewed-by: Keith Packard <keithp at keithp.com>

diff --git a/hw/xfree86/drivers/modesetting/Makefile.am b/hw/xfree86/drivers/modesetting/Makefile.am
index f6c6041..ca3279e 100644
--- a/hw/xfree86/drivers/modesetting/Makefile.am
+++ b/hw/xfree86/drivers/modesetting/Makefile.am
@@ -41,7 +41,6 @@ modesetting_drv_la_LIBADD = $(UDEV_LIBS) $(DRM_LIBS)
 modesetting_drv_ladir = @moduledir@/drivers
 
 modesetting_drv_la_SOURCES = \
-	 compat-api.h \
 	 driver.c \
 	 driver.h \
 	 drmmode_display.c \
diff --git a/hw/xfree86/drivers/modesetting/compat-api.h b/hw/xfree86/drivers/modesetting/compat-api.h
deleted file mode 100644
index bd7decc..0000000
--- a/hw/xfree86/drivers/modesetting/compat-api.h
+++ /dev/null
@@ -1,94 +0,0 @@
-/*
- * 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.
- *
- * Author: Dave Airlie <airlied at redhat.com>
- */
-
-/* this file provides API compat between server post 1.13 and pre it,
-   it should be reused inside as many drivers as possible */
-#ifndef COMPAT_API_H
-#define COMPAT_API_H
-
-#ifndef GLYPH_HAS_GLYPH_PICTURE_ACCESSOR
-#define GetGlyphPicture(g, s) GlyphPicture((g))[(s)->myNum]
-#define SetGlyphPicture(g, s, p) GlyphPicture((g))[(s)->myNum] = p
-#endif
-
-#ifndef XF86_HAS_SCRN_CONV
-#define xf86ScreenToScrn(s) xf86Screens[(s)->myNum]
-#define xf86ScrnToScreen(s) screenInfo.screens[(s)->scrnIndex]
-#endif
-
-#ifndef XF86_SCRN_INTERFACE
-
-#define SCRN_ARG_TYPE int
-#define SCRN_INFO_PTR(arg1) ScrnInfoPtr pScrn = xf86Screens[(arg1)]
-
-#define SCREEN_ARG_TYPE int
-#define SCREEN_PTR(arg1) ScreenPtr pScreen = screenInfo.screens[(arg1)]
-
-#define SCREEN_INIT_ARGS_DECL int i, ScreenPtr pScreen, int argc, char **argv
-
-#define BLOCKHANDLER_ARGS_DECL int arg, void * blockData, void * pTimeout, void * pReadmask
-#define BLOCKHANDLER_ARGS arg, blockData, pTimeout, pReadmask
-
-#define CLOSE_SCREEN_ARGS_DECL int scrnIndex, ScreenPtr pScreen
-#define CLOSE_SCREEN_ARGS scrnIndex, pScreen
-
-#define ADJUST_FRAME_ARGS_DECL int arg, int x, int y, int flags
-
-#define SWITCH_MODE_ARGS_DECL int arg, DisplayModePtr mode, int flags
-
-#define FREE_SCREEN_ARGS_DECL int arg, int flags
-
-#define VT_FUNC_ARGS_DECL int arg, int flags
-#define VT_FUNC_ARGS pScrn->scrnIndex, 0
-
-#define XF86_ENABLEDISABLEFB_ARG(x) ((x)->scrnIndex)
-#else
-#define SCRN_ARG_TYPE ScrnInfoPtr
-#define SCRN_INFO_PTR(arg1) ScrnInfoPtr pScrn = (arg1)
-
-#define SCREEN_ARG_TYPE ScreenPtr
-#define SCREEN_PTR(arg1) ScreenPtr pScreen = (arg1)
-
-#define SCREEN_INIT_ARGS_DECL ScreenPtr pScreen, int argc, char **argv
-
-#define BLOCKHANDLER_ARGS_DECL ScreenPtr arg, void * pTimeout, void * pReadmask
-#define BLOCKHANDLER_ARGS arg, pTimeout, pReadmask
-
-#define CLOSE_SCREEN_ARGS_DECL ScreenPtr pScreen
-#define CLOSE_SCREEN_ARGS pScreen
-
-#define ADJUST_FRAME_ARGS_DECL ScrnInfoPtr arg, int x, int y
-#define SWITCH_MODE_ARGS_DECL ScrnInfoPtr arg, DisplayModePtr mode
-
-#define FREE_SCREEN_ARGS_DECL ScrnInfoPtr arg
-
-#define VT_FUNC_ARGS_DECL ScrnInfoPtr arg
-#define VT_FUNC_ARGS pScrn
-
-#define XF86_ENABLEDISABLEFB_ARG(x) (x)
-
-#endif
-
-#endif
diff --git a/hw/xfree86/drivers/modesetting/driver.c b/hw/xfree86/drivers/modesetting/driver.c
index b30c32c..35e73a3 100644
--- a/hw/xfree86/drivers/modesetting/driver.c
+++ b/hw/xfree86/drivers/modesetting/driver.c
@@ -59,20 +59,19 @@
 #include <pciaccess.h>
 #endif
 
-#include "compat-api.h"
 #include "driver.h"
 
-static void AdjustFrame(ADJUST_FRAME_ARGS_DECL);
-static Bool CloseScreen(CLOSE_SCREEN_ARGS_DECL);
-static Bool EnterVT(VT_FUNC_ARGS_DECL);
+static void AdjustFrame(ScrnInfoPtr pScrn, int x, int y);
+static Bool CloseScreen(ScreenPtr pScreen);
+static Bool EnterVT(ScrnInfoPtr pScrn);
 static void Identify(int flags);
 static const OptionInfoRec *AvailableOptions(int chipid, int busid);
-static ModeStatus ValidMode(SCRN_ARG_TYPE arg, DisplayModePtr mode, Bool verbose,
+static ModeStatus ValidMode(ScrnInfoPtr pScrn, DisplayModePtr mode, Bool verbose,
 			    int flags);
-static void FreeScreen(FREE_SCREEN_ARGS_DECL);
-static void LeaveVT(VT_FUNC_ARGS_DECL);
-static Bool SwitchMode(SWITCH_MODE_ARGS_DECL);
-static Bool ScreenInit(SCREEN_INIT_ARGS_DECL);
+static void FreeScreen(ScrnInfoPtr pScrn);
+static void LeaveVT(ScrnInfoPtr pScrn);
+static Bool SwitchMode(ScrnInfoPtr pScrn, DisplayModePtr mode);
+static Bool ScreenInit(ScreenPtr pScreen, int argc, char **argv);
 static Bool PreInit(ScrnInfoPtr pScrn, int flags);
 
 static Bool Probe(DriverPtr drv, int flags);
@@ -537,13 +536,12 @@ static void dispatch_slave_dirty(ScreenPtr pScreen)
     }
 }
 
-static void msBlockHandler(BLOCKHANDLER_ARGS_DECL)
+static void msBlockHandler(ScreenPtr pScreen, void *pTimeout, void *pReadmask)
 {
-    SCREEN_PTR(arg);
     modesettingPtr ms = modesettingPTR(xf86ScreenToScrn(pScreen));
 
     pScreen->BlockHandler = ms->BlockHandler;
-    pScreen->BlockHandler(BLOCKHANDLER_ARGS);
+    pScreen->BlockHandler(pScreen, pTimeout, pReadmask);
     pScreen->BlockHandler = msBlockHandler;
     if (pScreen->isGPU)
         dispatch_slave_dirty(pScreen);
@@ -910,7 +908,7 @@ SetMaster(ScrnInfoPtr pScrn)
 }
 
 static Bool
-ScreenInit(SCREEN_INIT_ARGS_DECL)
+ScreenInit(ScreenPtr pScreen, int argc, char **argv)
 {
     ScrnInfoPtr pScrn = xf86ScreenToScrn(pScreen);
     modesettingPtr ms = modesettingPTR(pScrn);
@@ -1019,29 +1017,26 @@ ScreenInit(SCREEN_INIT_ARGS_DECL)
     if (serverGeneration == 1)
 	xf86ShowUnusedOptions(pScrn->scrnIndex, pScrn->options);
 
-    return EnterVT(VT_FUNC_ARGS);
+    return EnterVT(pScrn);
 }
 
 static void
-AdjustFrame(ADJUST_FRAME_ARGS_DECL)
+AdjustFrame(ScrnInfoPtr pScrn, int x, int y)
 {
-    SCRN_INFO_PTR(arg);
     modesettingPtr ms = modesettingPTR(pScrn);
 
     drmmode_adjust_frame(pScrn, &ms->drmmode, x, y);
 }
 
 static void
-FreeScreen(FREE_SCREEN_ARGS_DECL)
+FreeScreen(ScrnInfoPtr pScrn)
 {
-    SCRN_INFO_PTR(arg);
     FreeRec(pScrn);
 }
 
 static void
-LeaveVT(VT_FUNC_ARGS_DECL)
+LeaveVT(ScrnInfoPtr pScrn)
 {
-    SCRN_INFO_PTR(arg);
     modesettingPtr ms = modesettingPTR(pScrn);
     xf86_hide_cursors(pScrn);
 
@@ -1060,9 +1055,8 @@ LeaveVT(VT_FUNC_ARGS_DECL)
  * This gets called when gaining control of the VT, and from ScreenInit().
  */
 static Bool
-EnterVT(VT_FUNC_ARGS_DECL)
+EnterVT(ScrnInfoPtr pScrn)
 {
-    SCRN_INFO_PTR(arg);
     modesettingPtr ms = modesettingPTR(pScrn);
 
     pScrn->vtSema = TRUE;
@@ -1076,15 +1070,13 @@ EnterVT(VT_FUNC_ARGS_DECL)
 }
 
 static Bool
-SwitchMode(SWITCH_MODE_ARGS_DECL)
+SwitchMode(ScrnInfoPtr pScrn, DisplayModePtr mode)
 {
-    SCRN_INFO_PTR(arg);
-
     return xf86SetSingleMode(pScrn, mode, RR_Rotate_0);
 }
 
 static Bool
-CloseScreen(CLOSE_SCREEN_ARGS_DECL)
+CloseScreen(ScreenPtr pScreen)
 {
     ScrnInfoPtr pScrn = xf86ScreenToScrn(pScreen);
     modesettingPtr ms = modesettingPTR(pScrn);
@@ -1105,7 +1097,7 @@ CloseScreen(CLOSE_SCREEN_ARGS_DECL)
     drmmode_free_bos(pScrn, &ms->drmmode);
 
     if (pScrn->vtSema) {
-        LeaveVT(VT_FUNC_ARGS);
+        LeaveVT(pScrn);
     }
 
     pScreen->CreateScreenResources = ms->createScreenResources;
@@ -1113,11 +1105,11 @@ CloseScreen(CLOSE_SCREEN_ARGS_DECL)
 
     pScrn->vtSema = FALSE;
     pScreen->CloseScreen = ms->CloseScreen;
-    return (*pScreen->CloseScreen) (CLOSE_SCREEN_ARGS);
+    return (*pScreen->CloseScreen) (pScreen);
 }
 
 static ModeStatus
-ValidMode(SCRN_ARG_TYPE arg, DisplayModePtr mode, Bool verbose, int flags)
+ValidMode(ScrnInfoPtr arg, DisplayModePtr mode, Bool verbose, int flags)
 {
     return MODE_OK;
 }
diff --git a/hw/xfree86/drivers/modesetting/drmmode_display.c b/hw/xfree86/drivers/modesetting/drmmode_display.c
index d55157b..88de97c 100644
--- a/hw/xfree86/drivers/modesetting/drmmode_display.c
+++ b/hw/xfree86/drivers/modesetting/drmmode_display.c
@@ -46,7 +46,6 @@
 #include <cursorstr.h>
 
 #include <X11/extensions/dpmsconst.h>
-#include "compat-api.h"
 
 #include "driver.h"
 
commit 2feda3b6b58f46cef91ea41312aac9021a703777
Author: Eric Anholt <eric at anholt.net>
Date:   Tue Aug 26 11:06:23 2014 -0700

    modesetting: Connect the driver to the build.
    
    v2: Fix libdrm version check, and use XORG_VERSION_* instead of a
        static 1.0.0 version for the driver module.
    
    Signed-off-by: Eric Anholt <eric at anholt.net>
    Reviewed-by: Keith Packard <keithp at keithp.com>

diff --git a/configure.ac b/configure.ac
index cba7d24..ae3327d 100644
--- a/configure.ac
+++ b/configure.ac
@@ -863,6 +863,7 @@ fi
 PKG_CHECK_MODULES(UDEV, $LIBUDEV, [HAVE_LIBUDEV=yes], [HAVE_LIBUDEV=no])
 if test "x$CONFIG_UDEV" = xauto; then
 	CONFIG_UDEV="$HAVE_LIBUDEV"
+	AC_DEFINE(HAVE_LIBUDEV, 1, [Define to 1 if libudev is available.])
 fi
 AM_CONDITIONAL(CONFIG_UDEV, [test "x$CONFIG_UDEV" = xyes])
 if test "x$CONFIG_UDEV" = xyes; then
@@ -2039,6 +2040,12 @@ if test "x$XORG" = xyes; then
 	        XORG_SYS_LIBS="$XORG_SYS_LIBS $XORG_MODULES_LIBS"
 	fi
 
+	if test "x$DRM" = xyes; then
+		dnl 2.4.46 is required for cursor hotspot support.
+		PKG_CHECK_EXISTS(libdrm >= 2.4.46)
+		XORG_DRIVER_MODESETTING=yes
+	fi
+
 	AC_SUBST([XORG_LIBS])
 	AC_SUBST([XORG_SYS_LIBS])
 	AC_SUBST([XORG_INCS])
@@ -2109,6 +2116,7 @@ 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])
+AM_CONDITIONAL([XORG_DRIVER_MODESETTING], [test "x$XORG_DRIVER_MODESETTING" = xyes])
 
 dnl glamor
 AM_CONDITIONAL([GLAMOR], [test "x$GLAMOR" = xyes])
@@ -2554,6 +2562,8 @@ hw/xfree86/dixmods/Makefile
 hw/xfree86/doc/Makefile
 hw/xfree86/dri/Makefile
 hw/xfree86/dri2/Makefile
+hw/xfree86/drivers/Makefile
+hw/xfree86/drivers/modesetting/Makefile
 hw/xfree86/exa/Makefile
 hw/xfree86/exa/man/Makefile
 hw/xfree86/fbdevhw/Makefile
diff --git a/hw/xfree86/Makefile.am b/hw/xfree86/Makefile.am
index c5992c3..30f7c8f 100644
--- a/hw/xfree86/Makefile.am
+++ b/hw/xfree86/Makefile.am
@@ -38,7 +38,7 @@ SUBDIRS = common ddc x86emu $(INT10_SUBDIR) os-support parser \
 	  ramdac $(VGAHW_SUBDIR) loader modes $(DRI_SUBDIR) \
 	  $(DRI2_SUBDIR) . $(VBE_SUBDIR) i2c dixmods \
 	  fbdevhw shadowfb exa $(XF86UTILS_SUBDIR) doc man \
-	  $(GLAMOR_EGL_SUBDIR)
+	  $(GLAMOR_EGL_SUBDIR) drivers
 
 DIST_SUBDIRS = common ddc i2c x86emu int10 fbdevhw os-support \
                parser ramdac shadowfb vbe vgahw \
diff --git a/hw/xfree86/drivers/Makefile.am b/hw/xfree86/drivers/Makefile.am
new file mode 100644
index 0000000..04d787f
--- /dev/null
+++ b/hw/xfree86/drivers/Makefile.am
@@ -0,0 +1,5 @@
+SUBDIRS =
+
+if XORG_DRIVER_MODESETTING
+SUBDIRS += modesetting
+endif
diff --git a/hw/xfree86/drivers/modesetting/Makefile.am b/hw/xfree86/drivers/modesetting/Makefile.am
index 3cc4624..f6c6041 100644
--- a/hw/xfree86/drivers/modesetting/Makefile.am
+++ b/hw/xfree86/drivers/modesetting/Makefile.am
@@ -24,11 +24,20 @@
 # _ladir passes a dummy rpath to libtool so the thing will actually link
 # TODO: -nostdlib/-Bstatic/-lgcc platform magic, not installing the .a, etc.
 
-AM_CFLAGS = $(XORG_CFLAGS) $(DRM_CFLAGS) $(UDEV_CFLAGS) $(CWARNFLAGS)
+AM_CFLAGS = $(DIX_CFLAGS) $(XORG_CFLAGS) $(LIBDRM_CFLAGS) $(UDEV_CFLAGS) $(CWARNFLAGS)
+
+AM_CPPFLAGS = \
+	$(XORG_INCS) \
+	-I$(srcdir)/../../ddc \
+	-I$(srcdir)/../../i2c \
+	-I$(srcdir)/../../modes \
+	-I$(srcdir)/../../parser \
+	-I$(srcdir)/../../ramdac \
+	$(NULL)
 
 modesetting_drv_la_LTLIBRARIES = modesetting_drv.la
 modesetting_drv_la_LDFLAGS = -module -avoid-version
-modesetting_drv_la_LIBADD = @UDEV_LIBS@ @DRM_LIBS@
+modesetting_drv_la_LIBADD = $(UDEV_LIBS) $(DRM_LIBS)
 modesetting_drv_ladir = @moduledir@/drivers
 
 modesetting_drv_la_SOURCES = \
@@ -37,3 +46,17 @@ modesetting_drv_la_SOURCES = \
 	 driver.h \
 	 drmmode_display.c \
 	 drmmode_display.h
+
+drivermandir = $(DRIVER_MAN_DIR)
+driverman_PRE = modesetting.man
+driverman_DATA = $(driverman_PRE:man=@DRIVER_MAN_SUFFIX@)
+
+EXTRA_DIST = modesetting.man
+
+CLEANFILES = $(driverman_DATA)
+
+# String replacements in MAN_SUBSTS now come from xorg-macros.m4 via configure
+SUFFIXES = .$(DRIVER_MAN_SUFFIX) .man
+
+.man.$(DRIVER_MAN_SUFFIX):
+	$(AM_V_GEN)$(SED) $(MAN_SUBSTS) < $< > $@
diff --git a/hw/xfree86/drivers/modesetting/driver.c b/hw/xfree86/drivers/modesetting/driver.c
index eaa3a0f..b30c32c 100644
--- a/hw/xfree86/drivers/modesetting/driver.c
+++ b/hw/xfree86/drivers/modesetting/driver.c
@@ -29,8 +29,8 @@
  *
  */
 
-#ifdef HAVE_CONFIG_H
-#include "config.h"
+#ifdef HAVE_DIX_CONFIG_H
+#include "dix-config.h"
 #endif
 
 #include <unistd.h>
@@ -51,7 +51,7 @@
 #include "shadow.h"
 #include "xf86xv.h"
 #include <X11/extensions/Xv.h>
-#include <xorg-server.h>
+#include <xorg-config.h>
 #ifdef XSERVER_PLATFORM_BUS
 #include "xf86platformBus.h"
 #endif
@@ -144,7 +144,9 @@ static XF86ModuleVersionInfo VersRec = {
     MODINFOSTRING1,
     MODINFOSTRING2,
     XORG_VERSION_CURRENT,
-    PACKAGE_VERSION_MAJOR, PACKAGE_VERSION_MINOR, PACKAGE_VERSION_PATCHLEVEL,
+    XORG_VERSION_MAJOR,
+    XORG_VERSION_MINOR,
+    XORG_VERSION_PATCH,
     ABI_CLASS_VIDEODRV,
     ABI_VIDEODRV_VERSION,
     MOD_CLASS_VIDEODRV,
diff --git a/hw/xfree86/drivers/modesetting/drmmode_display.c b/hw/xfree86/drivers/modesetting/drmmode_display.c
index 31c39a2..d55157b 100644
--- a/hw/xfree86/drivers/modesetting/drmmode_display.c
+++ b/hw/xfree86/drivers/modesetting/drmmode_display.c
@@ -25,8 +25,8 @@
  *
  */
 
-#ifdef HAVE_CONFIG_H
-#include "config.h"
+#ifdef HAVE_DIX_CONFIG_H
+#include "dix-config.h"
 #endif
 
 #include <errno.h>
commit 30dcc10f6c9c4bacbc0e3652917c298ca9fb3898
Author: Adam Jackson <ajax at redhat.com>
Date:   Mon May 5 11:18:33 2014 -0400

    xfree86: Clean up some more alpha awareness
    
    Since the sparse stuff is gone none of these variables get used for
    anything, they're just dead side-effect-less execution.
    
    Reviewed-by: Eric Anholt <eric at anholt.net>
    Signed-off-by: Adam Jackson <ajax at redhat.com>

diff --git a/hw/xfree86/os-support/bsd/Makefile.am b/hw/xfree86/os-support/bsd/Makefile.am
index 7133c0f..b01ea5b 100644
--- a/hw/xfree86/os-support/bsd/Makefile.am
+++ b/hw/xfree86/os-support/bsd/Makefile.am
@@ -27,9 +27,7 @@ if ALPHA_VIDEO
 # Cheat here and piggyback other alpha bits on ALPHA_VIDEO.
 ARCH_SOURCES = \
 	alpha_video.c \
-	bsd_ev56.c \
-	bsd_axp.c \
-	$(srcdir)/../shared/xf86Axp.c
+	bsd_ev56.c
 endif
 
 if ARM_VIDEO
diff --git a/hw/xfree86/os-support/bsd/alpha_video.c b/hw/xfree86/os-support/bsd/alpha_video.c
index b65b762..236def6 100644
--- a/hw/xfree86/os-support/bsd/alpha_video.c
+++ b/hw/xfree86/os-support/bsd/alpha_video.c
@@ -36,8 +36,6 @@
 #include <sys/sysctl.h>
 #endif
 
-#include "xf86Axp.h"
-
 #include "xf86_OSlib.h"
 #include "xf86OSpriv.h"
 
@@ -47,43 +45,9 @@
 #define MAP_FLAGS (MAP_FILE | MAP_SHARED)
 #endif
 
-axpDevice bsdGetAXP(void);
-
 #ifndef __NetBSD__
 extern unsigned long dense_base(void);
-
-static int axpSystem = -1;
-static unsigned long hae_thresh;
-static unsigned long hae_mask;
-
-static int
-has_bwx(void)
-{
-    static int bwx = 0;
-    size_t len = sizeof(bwx);
-    int error;
-
-#ifdef __OpenBSD__
-    int mib[3];
-
-    mib[0] = CTL_MACHDEP;
-    mib[1] = CPU_CHIPSET;
-    mib[2] = CPU_CHIPSET_BWX;
-
-    if ((error = sysctl(mib, 3, &bwx, &len, NULL, 0)) < 0)
-        return FALSE;
-    else
-        return bwx;
-#else
-    if ((error = sysctlbyname("hw.chipset.bwx", &bwx, &len, 0, 0)) < 0)
-        return FALSE;
-    else
-        return bwx;
-#endif
-}
 #else                           /* __NetBSD__ */
-static unsigned long hae_thresh = (1UL << 24);
-static unsigned long hae_mask = 0xf8000000UL;   /* XXX - should use xf86AXP.c */
 static struct alpha_bus_window *abw;
 static int abw_count = -1;
 
@@ -97,16 +61,6 @@ init_abw(void)
     }
 }
 
-static int
-has_bwx(void)
-{
-    if (abw_count < 0)
-        init_abw();
-
-    xf86Msg(X_INFO, "has_bwx = %d\n", abw[0].abw_abst.abst_flags & ABST_BWX ? 1 : 0);   /* XXXX */
-    return abw[0].abw_abst.abst_flags & ABST_BWX;
-}
-
 static unsigned long
 dense_base(void)
 {
@@ -216,18 +170,6 @@ xf86OSInitVidMem(VidMemInfoPtr pVidMem)
 {
     checkDevMem(TRUE);
 
-    if (has_bwx()) {
-        xf86Msg(X_PROBED, "Machine type has 8/16 bit access\n");
-    }
-    else {
-        xf86Msg(X_PROBED, "Machine needs sparse mapping\n");
-#ifndef __NetBSD__
-        if (axpSystem == -1)
-            axpSystem = bsdGetAXP();
-        hae_thresh = xf86AXPParams[axpSystem].hae_thresh;
-        hae_mask = xf86AXPParams[axpSystem].hae_mask;
-#endif                          /* __NetBSD__ */
-    }
     pVidMem->initialised = TRUE;
 }
 
diff --git a/hw/xfree86/os-support/bsd/bsd_axp.c b/hw/xfree86/os-support/bsd/bsd_axp.c
deleted file mode 100644
index e7a36f8..0000000
--- a/hw/xfree86/os-support/bsd/bsd_axp.c
+++ /dev/null
@@ -1,71 +0,0 @@
-
-#ifdef HAVE_XORG_CONFIG_H
-#include <xorg-config.h>
-#endif
-
-#include <X11/X.h>
-#include "os.h"
-#include "xf86.h"
-#include "xf86Priv.h"
-#include "shared/xf86Axp.h"
-#include <sys/param.h>
-#include "xf86_OSlib.h"
-#include <stdio.h>
-#include <sys/sysctl.h>
-
-axpDevice bsdGetAXP(void);
-
-/*
- * BSD does a very nice job providing system information to
- * user space programs. Unfortunately it doesn't provide all
- * the information required. Therefore we just obtain the
- * system type and look up the rest from a list we maintain
- * ourselves.
- */
-
-typedef struct {
-    char *name;
-    int type;
-} _AXP;
-
-static _AXP axpList[] = {
-    {"apecs", APECS},
-    {"pyxis", PYXIS},
-    {"cia", CIA},
-    {"irongate", IRONGATE},
-    {"lca", LCA},
-    {"t2", T2},
-    {"tsunami", TSUNAMI},
-    {NULL, SYS_NONE}
-};
-
-axpDevice
-bsdGetAXP(void)
-{
-    int i;
-    char sysname[64];
-    size_t len = sizeof(sysname);
-
-#ifdef __OpenBSD__
-    int mib[3];
-    int error;
-
-    mib[0] = CTL_MACHDEP;
-    mib[1] = CPU_CHIPSET;
-    mib[2] = CPU_CHIPSET_TYPE;
-
-    if ((error = sysctl(mib, 3, &sysname, &len, NULL, 0)) < 0)
-#else
-    if ((sysctlbyname("hw.chipset.type", &sysname, &len, 0, 0)) < 0)
-#endif
-        FatalError("bsdGetAXP: can't find machine type\n");
-#ifdef DEBUG
-    xf86Msg(X_INFO, "AXP is a: %s\n", sysname);
-#endif
-    for (i = 0;; i++) {
-        if (axpList[i].name == NULL)
-            return SYS_NONE;
-        if (!strcmp(sysname, axpList[i].name))
-            return axpList[i].type;
-    }
-}
diff --git a/hw/xfree86/os-support/linux/Makefile.am b/hw/xfree86/os-support/linux/Makefile.am
index 6fd317a..50fcd1f 100644
--- a/hw/xfree86/os-support/linux/Makefile.am
+++ b/hw/xfree86/os-support/linux/Makefile.am
@@ -2,9 +2,6 @@ noinst_LTLIBRARIES = liblinux.la
 
 if LINUX_ALPHA
 noinst_LTLIBRARIES += liblinuxev56.la
-PLATFORM_PCI_SUPPORT = \
-       $(srcdir)/lnx_axp.c \
-       $(srcdir)/../shared/xf86Axp.c
 
 liblinuxev56_la_CFLAGS = $(AM_CFLAGS) -mcpu=ev56
 
@@ -34,16 +31,12 @@ liblinux_la_SOURCES = lnx_init.c lnx_video.c \
 		     $(srcdir)/../shared/sigio.c \
                      $(ACPI_SRCS) \
                      $(APM_SRCS) \
-                     $(LOGIND_SRCS) \
-                     $(PLATFORM_PCI_SUPPORT)
+                     $(LOGIND_SRCS)
 
 AM_CFLAGS = -DUSESTDRES -DHAVE_SYSV_IPC $(DIX_CFLAGS) $(XORG_CFLAGS) $(PLATFORM_DEFINES)
 
 AM_CPPFLAGS = $(XORG_INCS) $(PLATFORM_INCLUDES) $(LIBDRM_CFLAGS)
 
-EXTRA_DIST = \
-	$(srcdir)/../shared/xf86Axp.h
-
 if LINUX_ALPHA
 liblinux_la_LIBADD = liblinuxev56.la
 endif
diff --git a/hw/xfree86/os-support/linux/lnx_axp.c b/hw/xfree86/os-support/linux/lnx_axp.c
deleted file mode 100644
index d65a3a4..0000000
--- a/hw/xfree86/os-support/linux/lnx_axp.c
+++ /dev/null
@@ -1,103 +0,0 @@
-
-#ifdef HAVE_XORG_CONFIG_H
-#include <xorg-config.h>
-#endif
-
-#include <stdio.h>
-#include "xf86.h"
-#include "shared/xf86Axp.h"
-
-axpDevice lnxGetAXP(void);
-
-typedef struct {
-    char *sysName;
-    char *sysVari;
-    char *cpu;
-    axpDevice sys;
-} AXP;
-
-static AXP axpList[] = {
-    {"Tsunami", NULL, NULL, TSUNAMI},
-    {"Eiger", NULL, NULL, TSUNAMI},
-    {"Noname", NULL, NULL, LCA},
-    {"AlphaBook1", NULL, NULL, LCA},
-    {"EB66", NULL, NULL, LCA},
-    {"EB64+", NULL, NULL, APECS},
-    {"Noritake", NULL, "EV5", CIA},
-    {"Noritake", NULL, "EV56", CIA},
-    {"Noritake", NULL, NULL, APECS},
-    {"XL", NULL, NULL, APECS},
-    {"Avanti", NULL, NULL, APECS},
-    {"Mikasa", NULL, "EV5", CIA},
-    {"Mikasa", NULL, "EV56", CIA},
-    {"Mikasa", NULL, NULL, APECS},
-    {"EB164", "EB164", NULL, CIA},
-    {"EB164", "PC164", NULL, CIA},
-    {"EB164", "LX164", NULL, PYXIS},
-    {"EB164", "SX164", NULL, PYXIS},
-    {"EB164", "RX164", NULL, POLARIS},
-    {"Alcor", NULL, NULL, CIA},
-    {"Takara", NULL, NULL, CIA},
-    {"Sable", NULL, "EV5", T2_GAMMA},
-    {"Sable", NULL, "EV56", T2_GAMMA},
-    {"Sable", NULL, NULL, T2},
-    {"Rawhide", NULL, NULL, MCPCIA},
-    {"Jensen", NULL, NULL, JENSEN},
-    {"Miata", NULL, NULL, PYXIS_CIA},
-    {"Ruffian", NULL, NULL, PYXIS_CIA},
-    {"Nautilus", NULL, NULL, IRONGATE},
-    {NULL, NULL, NULL, SYS_NONE}
-};
-
-axpDevice
-lnxGetAXP(void)
-{
-    FILE *file;
-    int count = 0;
-    char res[256];
-    char cpu[255];
-    char systype[255];
-    char sysvari[255];
-
-    if (!(file = fopen("/proc/cpuinfo", "r")))
-        return SYS_NONE;
-    do {
-        if (!fgets(res, 0xff, file))
-            return SYS_NONE;
-        switch (count) {
-        case 1:
-            sscanf(res, "cpu model : %s", cpu);
-            DebugF("CPU %s\n", cpu);
-            break;
-        case 5:
-            sscanf(res, "system type : %s", systype);
-            DebugF("system type : %s\n", systype);
-            break;
-        case 6:
-            sscanf(res, "system variation : %s", sysvari);
-            DebugF("system variation: %s\n", sysvari);
-            break;
-        }
-        count++;
-    } while (count < 8);
-
-    fclose(file);
-
-    count = 0;
-
-    do {
-        if (!axpList[count].sysName || !strcmp(axpList[count].sysName, systype)) {
-            if (axpList[count].sysVari &&
-                strcmp(axpList[count].sysVari, sysvari)) {
-                count++;
-                continue;
-            };
-            if (axpList[count].cpu && strcmp(axpList[count].cpu, cpu)) {
-                count++;
-                continue;
-            }
-            return axpList[count].sys;
-        }
-        count++;
-    } while (1);
-}
diff --git a/hw/xfree86/os-support/linux/lnx_video.c b/hw/xfree86/os-support/linux/lnx_video.c
index 018d921..c09d719 100644
--- a/hw/xfree86/os-support/linux/lnx_video.c
+++ b/hw/xfree86/os-support/linux/lnx_video.c
@@ -38,9 +38,6 @@
 #include "xf86Priv.h"
 #include "xf86_OSlib.h"
 #include "xf86OSpriv.h"
-#ifdef __alpha__
-#include "shared/xf86Axp.h"
-#endif
 
 static Bool ExtendedEnabled = FALSE;
 
@@ -68,49 +65,13 @@ extern int iopl(int __level);
 
 #endif
 
-#ifdef __alpha__
-#define BUS_BASE bus_base
-#else
-#define BUS_BASE (0)
-#endif                          /*  __alpha__ */
-
 /***************************************************************************/
 /* Video Memory Mapping section                                            */
 /***************************************************************************/
 
-#if defined (__alpha__)
-extern void sethae(unsigned long hae);
-extern unsigned long _bus_base __P((void)) __attribute__ ((const));
-extern unsigned long _bus_base_sparse __P((void)) __attribute__ ((const));
-
-extern axpDevice lnxGetAXP(void);
-static axpDevice axpSystem = -1;
-static Bool needSparse;
-static unsigned long hae_thresh;
-static unsigned long hae_mask;
-static unsigned long bus_base;
-#endif
-
 void
 xf86OSInitVidMem(VidMemInfoPtr pVidMem)
 {
-#ifdef __alpha__
-    if (axpSystem == -1) {
-        axpSystem = lnxGetAXP();
-        if ((needSparse = (_bus_base_sparse() > 0))) {
-            hae_thresh = xf86AXPParams[axpSystem].hae_thresh;
-            hae_mask = xf86AXPParams[axpSystem].hae_mask;
-        }
-        bus_base = _bus_base();
-    }
-    if (needSparse) {
-        xf86Msg(X_INFO, "Machine needs sparse mapping\n");
-    }
-    else {
-        xf86Msg(X_INFO, "Machine type has 8/16 bit access\n");
-    }
-#endif                          /* __alpha__ */
-
     pVidMem->initialised = TRUE;
 }
 
diff --git a/hw/xfree86/os-support/shared/xf86Axp.c b/hw/xfree86/os-support/shared/xf86Axp.c
deleted file mode 100644
index 5f2f398..0000000
--- a/hw/xfree86/os-support/shared/xf86Axp.c
+++ /dev/null
@@ -1,60 +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).
- */
-
-#ifdef HAVE_XORG_CONFIG_H
-#include <xorg-config.h>
-#endif
-
-#include "xf86Axp.h"
-
-axpParams xf86AXPParams[] = {
-    {SYS_NONE, 0, 0, 0}
-    ,
-    {TSUNAMI, 0, 0, 0}
-    ,
-    {LCA, 1 << 24, 0xf8000000, 1UL << 32}
-    ,
-    {APECS, 1 << 24, 0xf8000000, 1UL << 32}
-    ,
-    {T2, 0, 0xFC000000, 1UL << 31}
-    ,
-    {T2_GAMMA, 0, 0xFC000000, 1UL << 31}
-    ,
-    {CIA, 0, 0xE0000000, 1UL << 34}
-    ,
-    {MCPCIA, 0, 0xf8000000, 1UL << 31}
-    ,
-    {JENSEN, 0, 0xE000000, 1UL << 32}
-    ,
-    {POLARIS, 0, 0, 0}
-    ,
-    {PYXIS, 0, 0, 0}
-    ,
-    {PYXIS_CIA, 0, 0xE0000000, 1UL << 34}
-    ,
-    {IRONGATE, 0, 0, 0}
-};
diff --git a/hw/xfree86/os-support/shared/xf86Axp.h b/hw/xfree86/os-support/shared/xf86Axp.h
deleted file mode 100644
index fded9d8..0000000
--- a/hw/xfree86/os-support/shared/xf86Axp.h
+++ /dev/null
@@ -1,33 +0,0 @@
-#ifdef HAVE_XORG_CONFIG_H
-#include <xorg-config.h>
-#endif
-
-#ifndef _XF86_AXP_H_
-#define _XF86_AXP_H_
-
-typedef enum {
-    SYS_NONE,
-    TSUNAMI,
-    LCA,
-    APECS,
-    T2,
-    T2_GAMMA,
-    CIA,
-    MCPCIA,
-    JENSEN,
-    POLARIS,
-    PYXIS,
-    PYXIS_CIA,
-    IRONGATE
-} axpDevice;
-
-typedef struct {
-    axpDevice id;
-    unsigned long hae_thresh;
-    unsigned long hae_mask;
-    unsigned long size;
-} axpParams;
-
-extern axpParams xf86AXPParams[];
-
-#endif
commit 2e21c081d34d52ee49ac00a294d2e74caf529818
Author: Adam Jackson <ajax at redhat.com>
Date:   Fri May 2 13:00:21 2014 -0400

    xfree86: Remove the memory of MTRR awareness
    
    pciaccess does this for us, and none of our internal hooks really
    remain.  This does remove a cleanup pass from the BSD code, but the case
    it's covering (a previous server leaving MTRRs around) can't happen
    anymore.
    
    Reviewed-by: Eric Anholt <eric at anholt.net>
    Signed-off-by: Adam Jackson <ajax at redhat.com>

diff --git a/configure.ac b/configure.ac
index cba7d24..b69caec 100644
--- a/configure.ac
+++ b/configure.ac
@@ -235,29 +235,6 @@ dnl fbdev header
 AC_CHECK_HEADERS([linux/fb.h], FBDEV=yes)
 AM_CONDITIONAL(FBDEVHW, [test "x$FBDEV" = xyes])
 
-dnl MTRR header
-AC_CHECK_HEADERS([asm/mtrr.h], ac_cv_asm_mtrr_h=yes)
-if test "x$ac_cv_asm_mtrr_h" = xyes; then
-	HAVE_MTRR=yes
-fi
-
-dnl BSD MTRR header
-AC_CHECK_HEADERS([sys/memrange.h], ac_cv_memrange_h=yes)
-if test "x$ac_cv_memrange_h" = xyes; then
-	HAVE_MTRR=yes
-fi
-
-if test "x$HAVE_MTRR" = xyes; then
-	AC_DEFINE(HAS_MTRR_SUPPORT, 1, [MTRR support available])
-fi
-
-dnl A NetBSD MTRR header
-AC_CHECK_HEADERS([machine/mtrr.h], ac_cv_machine_mtrr_h=yes)
-if test "x$ac_cv_machine_mtrr_h" = xyes; then
-	AC_DEFINE(HAS_MTRR_BUILTIN, 1, [Define to 1 if NetBSD built-in MTRR
-		support is available])
-fi
-
 dnl FreeBSD kldload support (sys/linker.h)
 AC_CHECK_HEADERS([sys/linker.h],
 	[ac_cv_sys_linker_h=yes],
diff --git a/hw/xfree86/doc/README.DRIcomp b/hw/xfree86/doc/README.DRIcomp
index 2d3ebf1..7388650 100644
--- a/hw/xfree86/doc/README.DRIcomp
+++ b/hw/xfree86/doc/README.DRIcomp
@@ -142,9 +142,6 @@ Here are the basic steps for kernel setup.
 
         o Enable all chipsets' support for AGP
 
-        o It's recommended that you turn on MTRRs under Processor type and
-          Features, but not required.
-
    o Configure the rest of the kernel as required for your system (i.e. Eth-
      ernet, SCSI, etc)
 
diff --git a/hw/xfree86/doc/Registry b/hw/xfree86/doc/Registry
index 48e24a2..ad5b9bf 100644
--- a/hw/xfree86/doc/Registry
+++ b/hw/xfree86/doc/Registry
@@ -231,7 +231,6 @@ DDC                       B     C    Enable/disable DDC
 DDC1                      B     C    Enable/disable DDC1
 DDC2                      B     C    Enable/disable DDC2
 DPMS                      O     C    Enable DPMS
-MTRR                      B     C    Enable/disable setting MTRRs
 
 BaudRate                  I     I    Serial port baud rate
 ButtonNumber              I     I    Button number (for touch screen?)
diff --git a/hw/xfree86/man/xorg.conf.man b/hw/xfree86/man/xorg.conf.man
index 1631212..378f26b 100644
--- a/hw/xfree86/man/xorg.conf.man
+++ b/hw/xfree86/man/xorg.conf.man
@@ -2023,12 +2023,6 @@ Default: false.
 Disables the Int10 module, a module that uses the int10 call to the BIOS
 of the graphics card to initialize it.
 Default: false.
-.TP 7
-.BI "Option \*qNoMTRR\*q"
-Disables MTRR (Memory Type Range Register) support, a feature of modern
-processors which can improve video performance by a factor of up to 2.5.
-Some hardware has buggy MTRR support, and some video drivers have been
-known to exhibit problems when MTRR's are used.
 .PP
 Each
 .B Screen
diff --git a/hw/xfree86/os-support/bsd/i386_video.c b/hw/xfree86/os-support/bsd/i386_video.c
index dae3555..6c3bbcb 100644
--- a/hw/xfree86/os-support/bsd/i386_video.c
+++ b/hw/xfree86/os-support/bsd/i386_video.c
@@ -34,27 +34,6 @@
 #include <errno.h>
 #include <sys/mman.h>
 
-#ifdef HAS_MTRR_SUPPORT
-#ifndef __NetBSD__
-#include <sys/types.h>
-#include <sys/memrange.h>
-#else
-#include "memrange.h"
-#endif
-#define X_MTRR_ID "XFree86"
-#endif
-
-#if defined(HAS_MTRR_BUILTIN) && defined(__NetBSD__)
-#include <machine/mtrr.h>
-#include <machine/sysarch.h>
-#include <sys/queue.h>
-#ifdef __x86_64__
-#define i386_set_mtrr x86_64_set_mtrr
-#define i386_get_mtrr x86_64_get_mtrr
-#define i386_iopl x86_64_iopl
-#endif
-#endif
-
 #include "xf86_OSlib.h"
 #include "xf86OSpriv.h"
 
@@ -85,10 +64,6 @@ static int devMemFd = -1;
 #define DEV_APERTURE "/dev/xf86"
 #endif
 
-#ifdef HAS_MTRR_SUPPORT
-static Bool cleanMTRR(void);
-#endif
-
 /*
  * Check if /dev/mem can be mmap'd.  If it can't print a warning when
  * "warn" is TRUE.
@@ -181,9 +156,6 @@ xf86OSInitVidMem(VidMemInfoPtr pVidMem)
 
     pci_system_init_dev_mem(devMemFd);
 
-#ifdef HAS_MTRR_SUPPORT
-    cleanMTRR();
-#endif
     pVidMem->initialised = TRUE;
 }
 
@@ -354,87 +326,3 @@ xf86SetRGBOut()
     return;
 }
 #endif
-
-#ifdef HAS_MTRR_SUPPORT
-/* memory range (MTRR) support for FreeBSD */
-
-/*
- * This code is experimental.  Some parts may be overkill, and other parts
- * may be incomplete.
- */
-
-/*
- * getAllRanges returns the full list of memory ranges with attributes set.
- */
-
-static struct mem_range_desc *
-getAllRanges(int *nmr)
-{
-    struct mem_range_desc *mrd;
-    struct mem_range_op mro;
-
-    /*
-     * Find how many ranges there are.  If this fails, then the kernel
-     * probably doesn't have MTRR support.
-     */
-    mro.mo_arg[0] = 0;
-    if (ioctl(devMemFd, MEMRANGE_GET, &mro))
-        return NULL;
-    *nmr = mro.mo_arg[0];
-    mrd = xnfalloc(*nmr * sizeof(struct mem_range_desc));
-    mro.mo_arg[0] = *nmr;
-    mro.mo_desc = mrd;
-    if (ioctl(devMemFd, MEMRANGE_GET, &mro)) {
-        free(mrd);
-        return NULL;
-    }
-    return mrd;
-}
-
-/*
- * cleanMTRR removes any memory attribute that may be left by a previous
- * X server.  Normally there won't be any, but this takes care of the
- * case where a server crashed without being able finish cleaning up.
- */
-
-static Bool
-cleanMTRR()
-{
-    struct mem_range_desc *mrd;
-    struct mem_range_op mro;
-    int nmr, i;
-
-    /* This shouldn't happen */
-    if (devMemFd < 0)
-        return FALSE;
-
-    if (!(mrd = getAllRanges(&nmr)))
-        return FALSE;
-
-    for (i = 0; i < nmr; i++) {
-        if (strcmp(mrd[i].mr_owner, X_MTRR_ID) == 0 &&
-            (mrd[i].mr_flags & MDF_ACTIVE)) {
-#ifdef DEBUG
-            ErrorF("Clean for (0x%lx,0x%lx)\n",
-                   (unsigned long) mrd[i].mr_base,
-                   (unsigned long) mrd[i].mr_len);
-#endif
-            if (mrd[i].mr_flags & MDF_FIXACTIVE) {
-                mro.mo_arg[0] = MEMRANGE_SET_UPDATE;
-                mrd[i].mr_flags = MDF_UNCACHEABLE;
-            }
-            else {
-                mro.mo_arg[0] = MEMRANGE_SET_REMOVE;
-            }
-            mro.mo_desc = mrd + i;
-            ioctl(devMemFd, MEMRANGE_SET, &mro);
-        }
-    }
-#ifdef DEBUG
-    sleep(10);
-#endif
-    free(mrd);
-    return TRUE;
-}
-
-#endif                          /* HAS_MTRR_SUPPORT */
diff --git a/include/dix-config.h.in b/include/dix-config.h.in
index 2203f82..4268b8f 100644
--- a/include/dix-config.h.in
+++ b/include/dix-config.h.in
@@ -57,9 +57,6 @@
 /* Support SHM */
 #undef HAS_SHM
 
-/* Define to 1 if you have the <asm/mtrr.h> header file. */
-#undef HAVE_ASM_MTRR_H
-
 /* Has backtrace support */
 #undef HAVE_BACKTRACE
 
diff --git a/include/xorg-config.h.in b/include/xorg-config.h.in
index 629ae40..7c03126 100644
--- a/include/xorg-config.h.in
+++ b/include/xorg-config.h.in
@@ -82,12 +82,6 @@
 /* Building vgahw module */
 #undef WITH_VGAHW
 
-/* Define to 1 if NetBSD built-in MTRR support is available */
-#undef HAS_MTRR_BUILTIN
-
-/* Define to 1 if BSD MTRR support is available */
-#undef HAS_MTRR_SUPPORT
-
 /* NetBSD PIO alpha IO */
 #undef USE_ALPHA_PIO
 
commit c42712ab4d8eec56704ad5422d8f54befeb1e886
Author: Adam Jackson <ajax at redhat.com>
Date:   Fri May 2 12:58:23 2014 -0400

    xfree86: Remove xf86CheckMTRR
    
    Die die die die die.
    
    Reviewed-by: Eric Anholt <eric at anholt.net>
    Signed-off-by: Adam Jackson <ajax at redhat.com>

diff --git a/hw/xfree86/os-support/shared/vidmem.c b/hw/xfree86/os-support/shared/vidmem.c
index 1d4f6a9..a6bf677 100644
--- a/hw/xfree86/os-support/shared/vidmem.c
+++ b/hw/xfree86/os-support/shared/vidmem.c
@@ -42,72 +42,7 @@
  * This file contains the common part of the video memory mapping functions
  */
 
-/*
- * Get a piece of the ScrnInfoRec.  At the moment, this is only used to hold
- * the MTRR option information, but it is likely to be expanded if we do
- * auto unmapping of memory at VT switch.
- *
- */
-
-typedef struct {
-    Bool mtrrEnabled;
-    MessageType mtrrFrom;
-    Bool mtrrOptChecked;
-    ScrnInfoPtr pScrn;
-} VidMapRec, *VidMapPtr;
-
-static int vidMapIndex = -1;
-
-#define VIDMAPPTR(p) ((VidMapPtr)((p)->privates[vidMapIndex].ptr))
-
 static VidMemInfo vidMemInfo = { FALSE, };
-static VidMapRec vidMapRec = { TRUE, X_DEFAULT, FALSE, NULL };
-
-static VidMapPtr
-getVidMapRec(int scrnIndex)
-{
-    VidMapPtr vp;
-    ScrnInfoPtr pScrn;
-
-    if ((scrnIndex < 0) || !(pScrn = xf86Screens[scrnIndex]))
-        return &vidMapRec;
-
-    if (vidMapIndex < 0)
-        vidMapIndex = xf86AllocateScrnInfoPrivateIndex();
-
-    if (VIDMAPPTR(pScrn) != NULL)
-        return VIDMAPPTR(pScrn);
-
-    vp = pScrn->privates[vidMapIndex].ptr = xnfcalloc(sizeof(VidMapRec), 1);
-    vp->mtrrEnabled = TRUE;     /* default to enabled */
-    vp->mtrrFrom = X_DEFAULT;
-    vp->mtrrOptChecked = FALSE;
-    vp->pScrn = pScrn;
-    return vp;
-}
-
-enum { OPTION_MTRR };
-
-static const OptionInfoRec opts[] = {
-    {OPTION_MTRR, "mtrr", OPTV_BOOLEAN, {0}, FALSE},
-    {-1, NULL, OPTV_NONE, {0}, FALSE}
-};
-
-static void
-checkMtrrOption(VidMapPtr vp)
-{
-    if (!vp->mtrrOptChecked && vp->pScrn && vp->pScrn->options != NULL) {
-        OptionInfoPtr options;
-
-        options = xnfalloc(sizeof(opts));
-        (void) memcpy(options, opts, sizeof(opts));
-        xf86ProcessOptions(vp->pScrn->scrnIndex, vp->pScrn->options, options);
-        if (xf86GetOptValBool(options, OPTION_MTRR, &vp->mtrrEnabled))
-            vp->mtrrFrom = X_CONFIG;
-        free(options);
-        vp->mtrrOptChecked = TRUE;
-    }
-}
 
 void
 xf86InitVidMem(void)
@@ -117,20 +52,3 @@ xf86InitVidMem(void)
         xf86OSInitVidMem(&vidMemInfo);
     }
 }
-
-Bool
-xf86CheckMTRR(int ScreenNum)
-{
-    VidMapPtr vp = getVidMapRec(ScreenNum);
-
-    /*
-     * Check the "mtrr" option even when MTRR isn't supported to avoid
-     * warnings about unrecognised options.
-     */
-    checkMtrrOption(vp);
-
-    if (vp->mtrrEnabled)
-        return TRUE;
-
-    return FALSE;
-}
diff --git a/hw/xfree86/os-support/xf86_OSproc.h b/hw/xfree86/os-support/xf86_OSproc.h
index 1c1cc5e..822bab2 100644
--- a/hw/xfree86/os-support/xf86_OSproc.h
+++ b/hw/xfree86/os-support/xf86_OSproc.h
@@ -112,7 +112,6 @@
 _XFUNCPROTOBEGIN
 
 /* public functions */
-extern _X_EXPORT _X_DEPRECATED Bool xf86CheckMTRR(int);
 extern _X_EXPORT Bool xf86EnableIO(void);
 extern _X_EXPORT void xf86DisableIO(void);
 
commit 8686463de7e1ef9814824d46526d8177a7a492a0
Author: Adam Jackson <ajax at redhat.com>
Date:   Fri May 2 12:55:37 2014 -0400

    xfree86: Remove xf86ReadBIOS
    
    Not being used externally or internally anymore.
    
    Reviewed-by: Eric Anholt <eric at anholt.net>
    Signed-off-by: Adam Jackson <ajax at redhat.com>

diff --git a/hw/xfree86/os-support/bsd/alpha_video.c b/hw/xfree86/os-support/bsd/alpha_video.c
index faa3a07..b65b762 100644
--- a/hw/xfree86/os-support/bsd/alpha_video.c
+++ b/hw/xfree86/os-support/bsd/alpha_video.c
@@ -231,50 +231,6 @@ xf86OSInitVidMem(VidMemInfoPtr pVidMem)
     pVidMem->initialised = TRUE;
 }
 
-/*
- * Read BIOS via mmap()ing DEV_MEM
- */
-
-int
-xf86ReadBIOS(unsigned long Base, unsigned long Offset, unsigned char *Buf,
-             int Len)
-{
-    unsigned char *ptr;
-    int psize;
-    int mlen;
-
-    checkDevMem(TRUE);
-    if (devMemFd == -1) {
-        return -1;
-    }
-
-    psize = getpagesize();
-    Offset += Base & (psize - 1);
-    Base &= ~(psize - 1);
-    mlen = (Offset + Len + psize - 1) & ~(psize - 1);
-    ptr = (unsigned char *) mmap((caddr_t) 0, mlen, PROT_READ,
-                                 MAP_SHARED, devMemFd, (off_t) Base + BUS_BASE);
-    if ((long) ptr == -1) {
-        xf86Msg(X_WARNING,
-                "xf86ReadBIOS: %s mmap[s=%x,a=%lx,o=%lx] failed (%s)\n",
-                DEV_MEM, Len, Base, Offset, strerror(errno));
-        return -1;
-    }
-#ifdef DEBUG
-    xf86MsgVerb(X_INFO, 3,
-                "xf86ReadBIOS: BIOS at 0x%08x has signature 0x%04x\n", Base,
-                ptr[0] | (ptr[1] << 8));
-#endif
-    (void) memcpy(Buf, (void *) (ptr + Offset), Len);
-    (void) munmap((caddr_t) ptr, mlen);
-#ifdef DEBUG
-    xf86MsgVerb(X_INFO, 3, "xf86ReadBIOS(%x, %x, Buf, %x)"
-                "-> %02x %02x %02x %02x...\n",
-                Base, Offset, Len, Buf[0], Buf[1], Buf[2], Buf[3]);
-#endif
-    return Len;
-}
-
 #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__OpenBSD__)
 
 extern int ioperm(unsigned long from, unsigned long num, int on);
diff --git a/hw/xfree86/os-support/bsd/arm_video.c b/hw/xfree86/os-support/bsd/arm_video.c
index 60f5bca..3a639b8 100644
--- a/hw/xfree86/os-support/bsd/arm_video.c
+++ b/hw/xfree86/os-support/bsd/arm_video.c
@@ -130,49 +130,6 @@ xf86OSInitVidMem(VidMemInfoPtr pVidMem)
     pVidMem->initialised = TRUE;
 }
 
-/*
- * Read BIOS via mmap()ing DEV_MEM
- */
-
-int
-xf86ReadBIOS(unsigned long Base, unsigned long Offset, unsigned char *Buf,
-             int Len)
-{
-    unsigned char *ptr;
-    int psize;
-    int mlen;
-
-    checkDevMem(TRUE);
-    if (devMemFd == -1) {
-        return -1;
-    }
-
-    psize = getpagesize();
-    Offset += Base & (psize - 1);
-    Base &= ~(psize - 1);
-    mlen = (Offset + Len + psize - 1) & ~(psize - 1);
-    ptr = (unsigned char *) mmap((caddr_t) 0, mlen, PROT_READ,
-                                 MAP_SHARED, devMemFd, (off_t) Base + BUS_BASE);
-    if ((long) ptr == -1) {
-        xf86Msg(X_WARNING,
-                "xf86ReadBIOS: %s mmap[s=%x,a=%x,o=%x] failed (%s)\n",
-                DEV_MEM, Len, Base, Offset, strerror(errno));
-        return -1;
-    }
-#ifdef DEBUG
-    ErrorF("xf86ReadBIOS: BIOS at 0x%08x has signature 0x%04x\n",
-           Base, ptr[0] | (ptr[1] << 8));
-#endif
-    (void) memcpy(Buf, (void *) (ptr + Offset), Len);
-    (void) munmap((caddr_t) ptr, mlen);
-#ifdef DEBUG
-    xf86MsgVerb(X_INFO, 3, "xf86ReadBIOS(%x, %x, Buf, %x)"
-                "-> %02x %02x %02x %02x...\n",
-                Base, Offset, Len, Buf[0], Buf[1], Buf[2], Buf[3]);
-#endif
-    return Len;
-}
-
 #ifdef USE_DEV_IO
 static int IoFd = -1;
 
diff --git a/hw/xfree86/os-support/bsd/i386_video.c b/hw/xfree86/os-support/bsd/i386_video.c
index 2b2c2a3..dae3555 100644
--- a/hw/xfree86/os-support/bsd/i386_video.c
+++ b/hw/xfree86/os-support/bsd/i386_video.c
@@ -187,54 +187,6 @@ xf86OSInitVidMem(VidMemInfoPtr pVidMem)
     pVidMem->initialised = TRUE;
 }
 
-/*
- * Read BIOS via mmap()ing DEV_MEM
- */
-
-int
-xf86ReadBIOS(unsigned long Base, unsigned long Offset, unsigned char *Buf,
-             int Len)
-{
-    unsigned char *ptr;
-    int psize;
-    int mlen;
-
-    checkDevMem(TRUE);
-    if (devMemFd == -1) {
-        return -1;
-    }
-
-    psize = getpagesize();
-    Offset += Base & (psize - 1);
-    Base &= ~(psize - 1);
-    mlen = (Offset + Len + psize - 1) & ~(psize - 1);
-    ptr = (unsigned char *) mmap((caddr_t) 0, mlen, PROT_READ,
-                                 MAP_SHARED, devMemFd, (off_t) Base);
-    if ((long) ptr == -1) {
-        xf86Msg(X_WARNING,
-                "xf86ReadBIOS: %s mmap[s=%x,a=%lx,o=%lx] failed (%s)\n",
-                DEV_MEM, Len, Base, Offset, strerror(errno));
-#ifdef __OpenBSD__
-        if (Base < 0xa0000) {
-            xf86Msg(X_WARNING, SYSCTL_MSG2);
-        }
-#endif
-        return -1;
-    }
-#ifdef DEBUG
-    ErrorF("xf86ReadBIOS: BIOS at 0x%08x has signature 0x%04x\n",
-           Base, ptr[0] | (ptr[1] << 8));
-#endif
-    (void) memcpy(Buf, (void *) (ptr + Offset), Len);
-    (void) munmap((caddr_t) ptr, mlen);
-#ifdef DEBUG
-    xf86MsgVerb(X_INFO, 3, "xf86ReadBIOS(%x, %x, Buf, %x)"
-                "-> %02x %02x %02x %02x...\n",
-                Base, Offset, Len, Buf[0], Buf[1], Buf[2], Buf[3]);
-#endif
-    return Len;
-}
-
 #ifdef USE_I386_IOPL
 /***************************************************************************/
 /* I/O Permissions section                                                 */
diff --git a/hw/xfree86/os-support/bsd/ppc_video.c b/hw/xfree86/os-support/bsd/ppc_video.c
index 0cecd48..b1cf7eb 100644
--- a/hw/xfree86/os-support/bsd/ppc_video.c
+++ b/hw/xfree86/os-support/bsd/ppc_video.c
@@ -56,30 +56,6 @@ xf86OSInitVidMem(VidMemInfoPtr pVidMem)
 
 volatile unsigned char *ioBase = MAP_FAILED;
 
-int
-xf86ReadBIOS(unsigned long Base, unsigned long Offset, unsigned char *Buf,
-             int Len)
-{
-    int rv;
-    static int kmem = -1;
-
-    if (kmem == -1) {
-        kmem = open(DEV_MEM, 2);
-        if (kmem == -1) {
-            FatalError("xf86ReadBIOS: open %s", DEV_MEM);
-        }
-    }
-
-#ifdef DEBUG
-    xf86MsgVerb(X_INFO, 3, "xf86ReadBIOS() %lx %lx, %x\n", Base, Offset, Len);
-#endif
-
-    lseek(kmem, Base + Offset, 0);
-    rv = read(kmem, Buf, Len);
-
-    return rv;
-}
-
 Bool
 xf86EnableIO()
 {
diff --git a/hw/xfree86/os-support/bsd/sparc64_video.c b/hw/xfree86/os-support/bsd/sparc64_video.c
index b87afc1..5bed017 100644
--- a/hw/xfree86/os-support/bsd/sparc64_video.c
+++ b/hw/xfree86/os-support/bsd/sparc64_video.c
@@ -43,11 +43,3 @@ xf86OSInitVidMem(VidMemInfoPtr pVidMem)
 {
     pVidMem->initialised = TRUE;
 }
-
-int
-xf86ReadBIOS(unsigned long Base, unsigned long Offset, unsigned char *Buf,
-             int Len)
-{
-
-    return 0;
-}
diff --git a/hw/xfree86/os-support/hurd/Makefile.am b/hw/xfree86/os-support/hurd/Makefile.am
index f228c1c..3866054 100644
--- a/hw/xfree86/os-support/hurd/Makefile.am
+++ b/hw/xfree86/os-support/hurd/Makefile.am
@@ -1,6 +1,6 @@
 noinst_LTLIBRARIES = libhurd.la
 
-libhurd_la_SOURCES = hurd_bell.c hurd_init.c hurd_mmap.c \
+libhurd_la_SOURCES = hurd_bell.c hurd_init.c \
 		hurd_video.c \
 		$(srcdir)/../shared/VTsw_noop.c \
 		$(srcdir)/../shared/posix_tty.c \
diff --git a/hw/xfree86/os-support/hurd/hurd_mmap.c b/hw/xfree86/os-support/hurd/hurd_mmap.c
deleted file mode 100644
index 8e089ca..0000000
--- a/hw/xfree86/os-support/hurd/hurd_mmap.c
+++ /dev/null
@@ -1,94 +0,0 @@
-/*
- * Copyright 1997 by UCHIYAMA Yasushi
- *
- * 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 UCHIYAMA Yasushi not be used in
- * advertising or publicity pertaining to distribution of the software without
- * specific, written prior permission.  UCHIYAMA Yasushi makes no representations
- * about the suitability of this software for any purpose.  It is provided
- * "as is" without express or implied warranty.
- *
- * UCHIYAMA YASUSHI DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
- * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
- * EVENT SHALL UCHIYAMA YASUSHI 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<mach.h>
-#include<device/device.h>
-#include<mach/machine/mach_i386.h>
-#include <hurd.h>
-
-#include <X11/X.h>
-
-#include "xf86.h"
-#include "xf86Priv.h"
-#include "xf86_OSlib.h"
-
-#define BIOS_SIZE 0x20000
-
-int
-xf86ReadBIOS(unsigned long Base, unsigned long Offset, unsigned char *Buf,
-             int Len)
-{
-    mach_port_t device, mem_dev;
-    memory_object_t mem_obj;
-    vm_address_t addr = (vm_address_t) 0;       /* serach starting address */
-    kern_return_t err;
-
-    err = get_privileged_ports(NULL, &device);
-    if (err) {
-        errno = err;
-        FatalError("xf86ReadBIOS() can't get_privileged_ports. (%s)\n",
-                   strerror(errno));
-    }
-    err = device_open(device, D_READ | D_WRITE, "mem", &mem_dev);
-    mach_port_deallocate(mach_task_self(), device);
-    if (err) {
-        errno = err;
-        FatalError("xf86ReadBIOS() can't device_open. (%s)\n", strerror(errno));
-    }
-    err =
-        device_map(mem_dev, VM_PROT_READ | VM_PROT_WRITE, Base, BIOS_SIZE,
-                   &mem_obj, 0);
-    if (err) {
-        errno = err;
-        FatalError("xf86ReadBIOS() can't device_map. (%s)\n", strerror(errno));
-    }
-    err = vm_map(mach_task_self(),
-                 &addr,
-                 BIOS_SIZE,
-                 0,
-                 TRUE,
-                 mem_obj,
-                 Base,
-                 FALSE,
-                 VM_PROT_READ | VM_PROT_WRITE,
-                 VM_PROT_READ | VM_PROT_WRITE, VM_INHERIT_SHARE);
-    mach_port_deallocate(mach_task_self(), mem_obj);
-    if (err) {
-        errno = err;
-        FatalError("xf86ReadBIOS() can't vm_map. (%s)\n", strerror(errno));
-    }
-
-    memcpy(Buf, (void *) ((int) addr + Offset), Len);
-
-    err = vm_deallocate(mach_task_self(), addr, BIOS_SIZE);
-    if (err) {
-        errno = err;
-        FatalError("xf86ReadBIOS() can't vm_deallocate. (%s)\n",
-                   strerror(errno));
-    }
-
-    return Len;
-}
diff --git a/hw/xfree86/os-support/linux/Makefile.am b/hw/xfree86/os-support/linux/Makefile.am
index 1686dc2..6fd317a 100644
--- a/hw/xfree86/os-support/linux/Makefile.am
+++ b/hw/xfree86/os-support/linux/Makefile.am
@@ -28,7 +28,6 @@ endif
 
 liblinux_la_SOURCES = lnx_init.c lnx_video.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 \
                      $(srcdir)/../shared/vidmem.c \
diff --git a/hw/xfree86/os-support/shared/bios_mmap.c b/hw/xfree86/os-support/shared/bios_mmap.c
deleted file mode 100644
index e000dc9..0000000
--- a/hw/xfree86/os-support/shared/bios_mmap.c
+++ /dev/null
@@ -1,135 +0,0 @@
-/*
- * Copyright 1993 by David Wexelblat <dwex at goblin.org>
- *
- * 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 David Wexelblat not be used in
- * advertising or publicity pertaining to distribution of the software without
- * specific, written prior permission.  David Wexelblat makes no representations
- * about the suitability of this software for any purpose.  It is provided
- * "as is" without express or implied warranty.
- *
- * DAVID WEXELBLAT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
- * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
- * EVENT SHALL DAVID WEXELBLAT 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 <X11/X.h>
-
-#include "xf86.h"
-#include "xf86Priv.h"
-#include "xf86_OSlib.h"
-
-/*
- * Read BIOS via mmap()ing DEV_MEM
- */
-
-#ifndef __alpha__
-int
-xf86ReadBIOS(unsigned long Base, unsigned long Offset, unsigned char *Buf,
-             int Len)
-{
-    int fd;
-    unsigned char *ptr;
-    int psize;
-    int mlen;
-
-    if ((fd = open(DEV_MEM, O_RDONLY)) < 0) {
-        xf86Msg(X_WARNING, "xf86ReadBIOS: Failed to open %s (%s)\n",
-                DEV_MEM, strerror(errno));
-        return -1;
-    }
-    psize = getpagesize();
-    Offset += Base & (psize - 1);
-    Base &= ~(psize - 1);
-    mlen = (Offset + Len + psize - 1) & ~(psize - 1);
-    ptr = (unsigned char *) mmap((caddr_t) 0, mlen, PROT_READ,
-                                 MAP_SHARED, fd, (off_t) Base);
-    if (ptr == MAP_FAILED) {
-        xf86Msg(X_WARNING, "xf86ReadBIOS: %s mmap failed (%s)\n",
-                DEV_MEM, strerror(errno));
-        close(fd);
-        return -1;
-    }
-    DebugF("xf86ReadBIOS: BIOS at 0x%08x has signature 0x%04x\n",
-           Base, ptr[0] | (ptr[1] << 8));
-    (void) memcpy(Buf, (void *) (ptr + Offset), Len);
-    (void) munmap((caddr_t) ptr, mlen);
-    (void) close(fd);
-    return Len;
-}
-
-#else                           /* __alpha__ */
-
-  /*
-   *  We trick "mmap" into mapping BUS memory for us via BUS_BASE,
-   *  which is the KSEG address of the start of the DENSE memory
-   *  area.
-   */
-
-  /*
-   * NOTE: there prolly ought to be more validity checks and all
-   *  re: boundaries and sizes and such...
-   */
-
-#ifdef linux
-
-extern unsigned long _bus_base(void);
-
-#define BUS_BASE _bus_base()
-
-#else
-
-extern u_int64_t dense_base(void);
-
-#define BUS_BASE dense_base()
-
-#endif
-
-int
-xf86ReadBIOS(unsigned long Base, unsigned long Offset, unsigned char *Buf,
-             int Len)
-{
-    caddr_t base;
-    int fd;
-    int psize;
-    int mlen;
-
-    if ((fd = open(DEV_MEM, O_RDONLY)) < 0) {
-        xf86Msg(X_WARNING, "xf86ReadBIOS: Failed to open %s (%s)\n",
-                DEV_MEM, strerror(errno));
-        return -1;
-    }
-
-    psize = getpagesize();
-    Offset += Base & (psize - 1);
-    Base &= ~(psize - 1);
-    mlen = (Offset + Len + psize - 1) & ~(psize - 1);
-    base = mmap((caddr_t) 0, mlen, PROT_READ,
-                MAP_SHARED, fd, (off_t) (Base + BUS_BASE));
-
-    if (base == MAP_FAILED) {
-        xf86Msg(X_WARNING, "xf86ReadBIOS: Failed to mmap %s (%s)\n",
-                DEV_MEM, strerror(errno));
-        return -1;
-    }
-
-    xf86SlowBCopyFromBus((unsigned char *) (base + Offset), Buf, Len);
-
-    munmap((caddr_t) base, mlen);
-    close(fd);
-    return Len;
-}
-
-#endif                          /* __alpha__ */
diff --git a/hw/xfree86/os-support/solaris/sun_vid.c b/hw/xfree86/os-support/solaris/sun_vid.c
index bab449d..25f7618 100644
--- a/hw/xfree86/os-support/solaris/sun_vid.c
+++ b/hw/xfree86/os-support/solaris/sun_vid.c
@@ -63,96 +63,12 @@
 /* Video Memory Mapping section 					   */
 /***************************************************************************/
 
-static char *apertureDevName = NULL;
-static int apertureDevFD_ro = -1;
-static int apertureDevFD_rw = -1;
-
-static Bool
-solOpenAperture(void)
-{
-    if (apertureDevName == NULL) {
-        apertureDevName = "/dev/xsvc";
-        if ((apertureDevFD_rw = open(apertureDevName, O_RDWR)) < 0) {
-            xf86MsgVerb(X_WARNING, 0,
-                        "solOpenAperture: failed to open %s (%s)\n",
-                        apertureDevName, strerror(errno));
-            apertureDevName = "/dev/fbs/aperture";
-            apertureDevFD_rw = open(apertureDevName, O_RDWR);
-        }
-        apertureDevFD_ro = open(apertureDevName, O_RDONLY);
-
-        if ((apertureDevFD_rw < 0) || (apertureDevFD_ro < 0)) {
-            xf86MsgVerb(X_WARNING, 0,
-                        "solOpenAperture: failed to open %s (%s)\n",
-                        apertureDevName, strerror(errno));
-            xf86MsgVerb(X_WARNING, 0,
-                        "solOpenAperture: either /dev/fbs/aperture"
-                        " or /dev/xsvc required\n");
-
-            apertureDevName = NULL;
-
-            if (apertureDevFD_rw >= 0) {
-                close(apertureDevFD_rw);
-            }
-            apertureDevFD_rw = -1;
-
-            if (apertureDevFD_ro >= 0) {
-                close(apertureDevFD_ro);
-            }
-            apertureDevFD_ro = -1;
-
-            return FALSE;
-        }
-    }
-    return TRUE;
-}
-
 _X_HIDDEN void
 xf86OSInitVidMem(VidMemInfoPtr pVidMem)
 {
     pVidMem->initialised = TRUE;
 }
 
-/*
- * Read BIOS via mmap()ing physical memory.
- */
-int
-xf86ReadBIOS(unsigned long Base, unsigned long Offset, unsigned char *Buf,
-             int Len)
-{
-    unsigned char *ptr;
-    int psize;
-    int mlen;
-
-    psize = getpagesize();
-    Offset += Base & (psize - 1);
-    Base &= ~(psize - 1);
-    mlen = (Offset + Len + psize - 1) & ~(psize - 1);
-
-    if (solOpenAperture() == FALSE) {
-        xf86Msg(X_WARNING,
-                "xf86ReadBIOS: Failed to open aperture to read BIOS\n");
-        return -1;
-    }
-
-    ptr = (unsigned char *) mmap(NULL, mlen, PROT_READ,
-                                 MAP_SHARED, apertureDevFD_ro, (off_t) Base);
-    if (ptr == MAP_FAILED) {
-        xf86Msg(X_WARNING, "xf86ReadBIOS: %s mmap failed [0x%08lx, 0x%04x]\n",
-                apertureDevName, Base, mlen);
-        return -1;
-    }
-
-    (void) memcpy(Buf, (void *) (ptr + Offset), Len);
-    if (munmap((caddr_t) ptr, mlen) != 0) {
-        xf86MsgVerb(X_WARNING, 0,
-                    "xf86ReadBIOS: failed to unmap %s (0x%p,0x%x) (%s)\n",
-                    apertureDevName, ptr, mlen, strerror(errno));
-    }
-
-    return Len;
-}
-
 /***************************************************************************/
 /* I/O Permissions section						   */
 /***************************************************************************/
diff --git a/hw/xfree86/os-support/stub/Makefile.am b/hw/xfree86/os-support/stub/Makefile.am
index a39e17d..19468c6 100644
--- a/hw/xfree86/os-support/stub/Makefile.am
+++ b/hw/xfree86/os-support/stub/Makefile.am
@@ -14,6 +14,5 @@ libstub_la_SOURCES = \
 	$(srcdir)/../shared/posix_tty.c \
 	$(srcdir)/../shared/sigio.c \
 	stub_bell.c \
-	stub_bios.c \
 	stub_init.c \
 	stub_video.c
diff --git a/hw/xfree86/os-support/stub/stub_bios.c b/hw/xfree86/os-support/stub/stub_bios.c
deleted file mode 100644
index dbc92fc..0000000
--- a/hw/xfree86/os-support/stub/stub_bios.c
+++ /dev/null
@@ -1,12 +0,0 @@
-#ifdef HAVE_XORG_CONFIG_H
-#include <xorg-config.h>
-#endif
-
-#include "xf86_OSlib.h"
-
-int
-xf86ReadBIOS(unsigned long Base, unsigned long Offset, unsigned char *Buf,
-             int Len)
-{
-    return -1;
-}
diff --git a/hw/xfree86/os-support/xf86_OSproc.h b/hw/xfree86/os-support/xf86_OSproc.h
index 5337d7b..1c1cc5e 100644
--- a/hw/xfree86/os-support/xf86_OSproc.h
+++ b/hw/xfree86/os-support/xf86_OSproc.h
@@ -113,8 +113,6 @@ _XFUNCPROTOBEGIN
 
 /* public functions */
 extern _X_EXPORT _X_DEPRECATED Bool xf86CheckMTRR(int);
-extern _X_EXPORT int xf86ReadBIOS(unsigned long, unsigned long, unsigned char *,
-                                  int);
 extern _X_EXPORT Bool xf86EnableIO(void);
 extern _X_EXPORT void xf86DisableIO(void);
 
commit 21b216ad6ce2e9c89359b95e4196e42d91bf9420
Author: Adam Jackson <ajax at redhat.com>
Date:   Fri May 2 12:46:45 2014 -0400

    int10: Port off xf86ReadBIOS
    
    If the linux vm86 backend changes look somewhat horrifying to you,
    that's because you have taste.
    
    Reviewed-by: Eric Anholt <eric at anholt.net>
    Signed-off-by: Adam Jackson <ajax at redhat.com>

diff --git a/hw/xfree86/int10/generic.c b/hw/xfree86/int10/generic.c
index 73a1e5e..012d194 100644
--- a/hw/xfree86/int10/generic.c
+++ b/hw/xfree86/int10/generic.c
@@ -99,6 +99,20 @@ static void UnmapVRam(xf86Int10InfoPtr pInt);
 
 static void *sysMem = NULL;
 
+static Bool
+readIntVec(struct pci_device *dev, unsigned char *buf, int len)
+{
+    void *map;
+
+    if (!pci_device_map_legacy(dev, 0, len, 0, &map))
+        return FALSE;
+
+    memcpy(buf, map, len);
+    pci_device_unmap_legacy(dev, map, len);
+
+    return TRUE;
+}
+
 xf86Int10InfoPtr
 xf86ExtendedInitInt10(int entityIndex, int Flags)
 {
@@ -144,7 +158,7 @@ xf86ExtendedInitInt10(int entityIndex, int Flags)
                               PCI_DEV_MAP_FLAG_WRITABLE, &sysMem);
     INTPriv(pInt)->sysMem = sysMem;
 
-    if (xf86ReadBIOS(0, 0, base, LOW_PAGE_SIZE) < 0) {
+    if (!readIntVec(pInt->dev, base, LOW_PAGE_SIZE)) {
         xf86DrvMsg(pScrn->scrnIndex, X_ERROR, "Cannot read int vect\n");
         goto error1;
     }
diff --git a/hw/xfree86/os-support/linux/int10/linux.c b/hw/xfree86/os-support/linux/int10/linux.c
index 6181eb9..79b9a88 100644
--- a/hw/xfree86/os-support/linux/int10/linux.c
+++ b/hw/xfree86/os-support/linux/int10/linux.c
@@ -70,6 +70,20 @@ static Int10LinuxSubModuleState int10LinuxLoadSubModule(ScrnInfoPtr pScrn);
 
 #endif                          /* DoSubModules */
 
+static Bool
+readLegacy(struct pci_device *dev, unsigned char *buf, int base, int len)
+{
+    void *map;
+
+    if (!pci_device_map_legacy(dev, base, len, 0, &map))
+        return FALSE;
+
+    memcpy(buf, map, len);
+    pci_device_unmap_legacy(dev, man, len);
+
+    return TRUE;
+}
+
 xf86Int10InfoPtr
 xf86ExtendedInitInt10(int entityIndex, int Flags)
 {
@@ -222,7 +236,8 @@ xf86ExtendedInitInt10(int entityIndex, int Flags)
     Int10Current = pInt;
 
     DebugF("Mapping int area\n");
-    if (xf86ReadBIOS(0, 0, (unsigned char *) 0, LOW_PAGE_SIZE) < 0) {
+    /* note: yes, we really are writing the 0 page here */
+    if (!readLegacy(pInt->dev, (unsigned char *) 0, 0, LOW_PAGE_SIZE)) {
         xf86DrvMsg(screen, X_ERROR, "Cannot read int vect\n");
         goto error3;
     }
@@ -236,7 +251,7 @@ xf86ExtendedInitInt10(int entityIndex, int Flags)
         memset((void *) V_BIOS, 0, SYS_BIOS - V_BIOS);
         DebugF("Reading BIOS\n");
         for (cs = V_BIOS; cs < SYS_BIOS; cs += V_BIOS_SIZE)
-            if (xf86ReadBIOS(cs, 0, (void *) cs, V_BIOS_SIZE) < V_BIOS_SIZE)
+            if (!readLegacy(pInt->dev, (void *)cs, cs, V_BIOS_SIZE))
                 xf86DrvMsg(screen, X_WARNING,
                            "Unable to retrieve all of segment 0x%06lX.\n",
                            (long) cs);
commit 96c0da812a563d8229dc1396ac801329b3bcba91
Author: Adam Jackson <ajax at redhat.com>
Date:   Fri May 2 12:39:01 2014 -0400

    xfree86: Remove xf86LinearVidMem
    
    The only driver even pretending to check the result is mach64 anyway.
    
    Reviewed-by: Eric Anholt <eric at anholt.net>
    Signed-off-by: Adam Jackson <ajax at redhat.com>

diff --git a/hw/xfree86/os-support/bsd/alpha_video.c b/hw/xfree86/os-support/bsd/alpha_video.c
index 3aeae58..faa3a07 100644
--- a/hw/xfree86/os-support/bsd/alpha_video.c
+++ b/hw/xfree86/os-support/bsd/alpha_video.c
@@ -132,7 +132,6 @@ dense_base(void)
                   "\trefer to xf86(4) for details"
 #endif
 
-static Bool useDevMem = FALSE;
 static int devMemFd = -1;
 
 #ifdef HAS_APERTURE_DRV
@@ -164,7 +163,6 @@ checkDevMem(Bool warn)
         if (base != MAP_FAILED) {
             munmap((caddr_t) base, 4096);
             devMemFd = fd;
-            useDevMem = TRUE;
             xf86Msg(X_INFO, "checkDevMem: using aperture driver %s\n",
                     DEV_APERTURE);
             return;
@@ -185,7 +183,6 @@ checkDevMem(Bool warn)
         if (base != MAP_FAILED) {
             munmap((caddr_t) base, 4096);
             devMemFd = fd;
-            useDevMem = TRUE;
             return;
         }
         else {
@@ -211,7 +208,6 @@ checkDevMem(Bool warn)
 #endif
         xf86ErrorF("\tlinear framebuffer access unavailable\n");
     }
-    useDevMem = FALSE;
     return;
 }
 
@@ -219,7 +215,6 @@ void
 xf86OSInitVidMem(VidMemInfoPtr pVidMem)
 {
     checkDevMem(TRUE);
-    pVidMem->linearSupported = useDevMem;
 
     if (has_bwx()) {
         xf86Msg(X_PROBED, "Machine type has 8/16 bit access\n");
diff --git a/hw/xfree86/os-support/bsd/arm_video.c b/hw/xfree86/os-support/bsd/arm_video.c
index 95f4017..60f5bca 100644
--- a/hw/xfree86/os-support/bsd/arm_video.c
+++ b/hw/xfree86/os-support/bsd/arm_video.c
@@ -79,7 +79,6 @@
 /* Video Memory Mapping section                                            */
 /***************************************************************************/
 
-static Bool useDevMem = FALSE;
 static int devMemFd = -1;
 
 /*
@@ -105,7 +104,6 @@ checkDevMem(Bool warn)
         if (base != MAP_FAILED) {
             munmap((caddr_t) base, 4096);
             devMemFd = fd;
-            useDevMem = TRUE;
             return;
         }
         else {
@@ -114,7 +112,6 @@ checkDevMem(Bool warn)
                 xf86Msg(X_WARNING, "checkDevMem: failed to mmap %s (%s)\n",
                         DEV_MEM, strerror(errno));
             }
-            useDevMem = FALSE;
             return;
         }
     }
@@ -122,16 +119,13 @@ checkDevMem(Bool warn)
         xf86Msg(X_WARNING, "checkDevMem: failed to open %s (%s)\n",
                 DEV_MEM, strerror(errno));
     }
-    useDevMem = FALSE;
     return;
 }
 
 void
 xf86OSInitVidMem(VidMemInfoPtr pVidMem)
 {
-
     checkDevMem(TRUE);
-    pVidMem->linearSupported = useDevMem;
 
     pVidMem->initialised = TRUE;
 }
diff --git a/hw/xfree86/os-support/bsd/i386_video.c b/hw/xfree86/os-support/bsd/i386_video.c
index 526cf8a..2b2c2a3 100644
--- a/hw/xfree86/os-support/bsd/i386_video.c
+++ b/hw/xfree86/os-support/bsd/i386_video.c
@@ -178,15 +178,11 @@ void
 xf86OSInitVidMem(VidMemInfoPtr pVidMem)
 {
     checkDevMem(TRUE);
-    pVidMem->linearSupported = useDevMem;
 
-    if (useDevMem)
-        pci_system_init_dev_mem(devMemFd);
+    pci_system_init_dev_mem(devMemFd);
 
 #ifdef HAS_MTRR_SUPPORT
-    if (useDevMem) {
-        cleanMTRR();
-    }
+    cleanMTRR();
 #endif
     pVidMem->initialised = TRUE;
 }
diff --git a/hw/xfree86/os-support/bsd/ppc_video.c b/hw/xfree86/os-support/bsd/ppc_video.c
index a624d4d..0cecd48 100644
--- a/hw/xfree86/os-support/bsd/ppc_video.c
+++ b/hw/xfree86/os-support/bsd/ppc_video.c
@@ -50,7 +50,6 @@ void xf86DisableIO(void);
 void
 xf86OSInitVidMem(VidMemInfoPtr pVidMem)
 {
-    pVidMem->linearSupported = TRUE;
     pVidMem->initialised = TRUE;
     xf86EnableIO();
 }
diff --git a/hw/xfree86/os-support/bsd/sparc64_video.c b/hw/xfree86/os-support/bsd/sparc64_video.c
index 3fd0315..b87afc1 100644
--- a/hw/xfree86/os-support/bsd/sparc64_video.c
+++ b/hw/xfree86/os-support/bsd/sparc64_video.c
@@ -41,7 +41,6 @@
 void
 xf86OSInitVidMem(VidMemInfoPtr pVidMem)
 {
-    pVidMem->linearSupported = TRUE;
     pVidMem->initialised = TRUE;
 }
 
diff --git a/hw/xfree86/os-support/hurd/hurd_video.c b/hw/xfree86/os-support/hurd/hurd_video.c
index 6485917..2a96393 100644
--- a/hw/xfree86/os-support/hurd/hurd_video.c
+++ b/hw/xfree86/os-support/hurd/hurd_video.c
@@ -84,6 +84,5 @@ xf86DisableIO()
 void
 xf86OSInitVidMem(VidMemInfoPtr pVidMem)
 {
-    pVidMem->linearSupported = TRUE;
     pVidMem->initialised = TRUE;
 }
diff --git a/hw/xfree86/os-support/linux/lnx_video.c b/hw/xfree86/os-support/linux/lnx_video.c
index 2efc9fd..018d921 100644
--- a/hw/xfree86/os-support/linux/lnx_video.c
+++ b/hw/xfree86/os-support/linux/lnx_video.c
@@ -94,7 +94,6 @@ static unsigned long bus_base;
 void
 xf86OSInitVidMem(VidMemInfoPtr pVidMem)
 {
-    pVidMem->linearSupported = TRUE;
 #ifdef __alpha__
     if (axpSystem == -1) {
         axpSystem = lnxGetAXP();
diff --git a/hw/xfree86/os-support/shared/vidmem.c b/hw/xfree86/os-support/shared/vidmem.c
index 0135867..1d4f6a9 100644
--- a/hw/xfree86/os-support/shared/vidmem.c
+++ b/hw/xfree86/os-support/shared/vidmem.c
@@ -134,10 +134,3 @@ xf86CheckMTRR(int ScreenNum)
 
     return FALSE;
 }
-
-Bool
-xf86LinearVidMem(void)
-{
-    xf86InitVidMem();
-    return vidMemInfo.linearSupported;
-}
diff --git a/hw/xfree86/os-support/solaris/sun_vid.c b/hw/xfree86/os-support/solaris/sun_vid.c
index 1526ae7..bab449d 100644
--- a/hw/xfree86/os-support/solaris/sun_vid.c
+++ b/hw/xfree86/os-support/solaris/sun_vid.c
@@ -110,11 +110,6 @@ solOpenAperture(void)
 _X_HIDDEN void
 xf86OSInitVidMem(VidMemInfoPtr pVidMem)
 {
-    pVidMem->linearSupported = solOpenAperture();
-    if (!pVidMem->linearSupported) {
-        xf86MsgVerb(X_WARNING, 0,
-                    "xf86OSInitVidMem: linear memory access disabled\n");
-    }
     pVidMem->initialised = TRUE;
 }
 
diff --git a/hw/xfree86/os-support/xf86OSpriv.h b/hw/xfree86/os-support/xf86OSpriv.h
index 7240f14..ce1ec33 100644
--- a/hw/xfree86/os-support/xf86OSpriv.h
+++ b/hw/xfree86/os-support/xf86OSpriv.h
@@ -34,7 +34,6 @@
 
 typedef struct {
     Bool initialised;
-    Bool linearSupported;
 } VidMemInfo, *VidMemInfoPtr;
 
 void xf86OSInitVidMem(VidMemInfoPtr);
diff --git a/hw/xfree86/os-support/xf86_OSproc.h b/hw/xfree86/os-support/xf86_OSproc.h
index 747803c..5337d7b 100644
--- a/hw/xfree86/os-support/xf86_OSproc.h
+++ b/hw/xfree86/os-support/xf86_OSproc.h
@@ -112,7 +112,6 @@
 _XFUNCPROTOBEGIN
 
 /* public functions */
-extern _X_EXPORT Bool xf86LinearVidMem(void);
 extern _X_EXPORT _X_DEPRECATED Bool xf86CheckMTRR(int);
 extern _X_EXPORT int xf86ReadBIOS(unsigned long, unsigned long, unsigned char *,
                                   int);
commit ec0e29ed5bc71516de7feb226b548ce45cb9ffdf
Author: Adam Jackson <ajax at redhat.com>
Date:   Fri May 2 12:32:02 2014 -0400

    xfree86: Remove {set,undo}WC from VidMemInfo
    
    Now that mapMem is gone this can never actually get called.
    
    Reviewed-by: Eric Anholt <eric at anholt.net>
    Signed-off-by: Adam Jackson <ajax at redhat.com>

diff --git a/hw/xfree86/os-support/bsd/i386_video.c b/hw/xfree86/os-support/bsd/i386_video.c
index cc84f44..526cf8a 100644
--- a/hw/xfree86/os-support/bsd/i386_video.c
+++ b/hw/xfree86/os-support/bsd/i386_video.c
@@ -86,15 +86,8 @@ static int devMemFd = -1;
 #endif
 
 #ifdef HAS_MTRR_SUPPORT
-static void *setWC(int, unsigned long, unsigned long, Bool, MessageType);
-static void undoWC(int, void *);
 static Bool cleanMTRR(void);
 #endif
-#if defined(HAS_MTRR_BUILTIN) && defined(__NetBSD__)
-static void *NetBSDsetWC(int, unsigned long, unsigned long, Bool,
-                           MessageType);
-static void NetBSDundoWC(int, void *);
-#endif
 
 /*
  * Check if /dev/mem can be mmap'd.  If it can't print a warning when
@@ -192,16 +185,9 @@ xf86OSInitVidMem(VidMemInfoPtr pVidMem)
 
 #ifdef HAS_MTRR_SUPPORT
     if (useDevMem) {
-        if (cleanMTRR()) {
-            pVidMem->setWC = setWC;
-            pVidMem->undoWC = undoWC;
-        }
+        cleanMTRR();
     }
 #endif
-#if defined(HAS_MTRR_BUILTIN) && defined(__NetBSD__)
-    pVidMem->setWC = NetBSDsetWC;
-    pVidMem->undoWC = NetBSDundoWC;
-#endif
     pVidMem->initialised = TRUE;
 }
 
@@ -503,334 +489,4 @@ cleanMTRR()
     return TRUE;
 }
 
-typedef struct x_RangeRec {
-    struct mem_range_desc mrd;
-    Bool wasWC;
-    struct x_RangeRec *next;
-} RangeRec, *RangePtr;
-
-static void
-freeRangeList(RangePtr range)
-{
-    RangePtr rp;
-
-    while (range) {
-        rp = range;
-        range = rp->next;
-        free(rp);
-    }
-}
-
-static RangePtr
-dupRangeList(RangePtr list)
-{
-    RangePtr new = NULL, rp, p;
-
-    rp = list;
-    while (rp) {
-        p = xnfalloc(sizeof(RangeRec));
-        *p = *rp;
-        p->next = new;
-        new = p;
-        rp = rp->next;
-    }
-    return new;
-}
-
-static RangePtr
-sortRangeList(RangePtr list)
-{
-    RangePtr rp1, rp2, copy, sorted = NULL, minp, prev, minprev;
-    unsigned long minBase;
-
-    /* Sort by base address */
-    rp1 = copy = dupRangeList(list);
-    while (rp1) {
-        minBase = rp1->mrd.mr_base;
-        minp = rp1;
-        minprev = NULL;
-        prev = rp1;
-        rp2 = rp1->next;
-        while (rp2) {
-            if (rp2->mrd.mr_base < minBase) {
-                minBase = rp2->mrd.mr_base;
-                minp = rp2;
-                minprev = prev;
-            }
-            prev = rp2;
-            rp2 = rp2->next;
-        }
-        if (minprev) {
-            minprev->next = minp->next;
-            rp1 = copy;
-        }
-        else {
-            rp1 = minp->next;
-        }
-        minp->next = sorted;
-        sorted = minp;
-    }
-    return sorted;
-}
-
-/*
- * findRanges returns a list of ranges that overlap the specified range.
- */
-
-static void
-findRanges(unsigned long base, unsigned long size, RangePtr * ucp,
-           RangePtr * wcp)
-{
-    struct mem_range_desc *mrd;
-    int nmr, i;
-    RangePtr rp, *p;
-
-    if (!(mrd = getAllRanges(&nmr)))
-        return;
-
-    for (i = 0; i < nmr; i++) {
-        if ((mrd[i].mr_flags & MDF_ACTIVE) &&
-            mrd[i].mr_base < base + size &&
-            mrd[i].mr_base + mrd[i].mr_len > base) {
-            if (mrd[i].mr_flags & MDF_WRITECOMBINE)
-                p = wcp;
-            else if (mrd[i].mr_flags & MDF_UNCACHEABLE)
-                p = ucp;
-            else
-                continue;
-            rp = xnfalloc(sizeof(RangeRec));
-            rp->mrd = mrd[i];
-            rp->next = *p;
-            *p = rp;
-        }
-    }
-    free(mrd);
-}
-
-/*
- * This checks if the existing overlapping ranges fully cover the requested
- * range.  Is this overkill?
- */
-
-static Bool
-fullCoverage(unsigned long base, unsigned long size, RangePtr overlap)
-{
-    RangePtr rp1, sorted = NULL;
-    unsigned long end;
-
-    sorted = sortRangeList(overlap);
-    /* Look for gaps */
-    rp1 = sorted;
-    end = base + size;
-    while (rp1) {
-        if (rp1->mrd.mr_base > base) {
-            freeRangeList(sorted);
-            return FALSE;
-        }
-        else {
-            base = rp1->mrd.mr_base + rp1->mrd.mr_len;
-        }
-        if (base >= end) {
-            freeRangeList(sorted);
-            return TRUE;
-        }
-        rp1 = rp1->next;
-    }
-    freeRangeList(sorted);
-    return FALSE;
-}
-
-static void *
-addWC(int screenNum, unsigned long base, unsigned long size, MessageType from)
-{
-    RangePtr uc = NULL, wc = NULL, retlist = NULL;
-    struct mem_range_desc mrd;
-    struct mem_range_op mro;
-
-    findRanges(base, size, &uc, &wc);
-
-    /* See of the full range is already WC */
-    if (!uc && fullCoverage(base, size, wc)) {
-        xf86DrvMsg(screenNum, from,
-                   "Write-combining range (0x%lx,0x%lx) was already set\n",
-                   base, size);
-        return NULL;
-    }
-
-    /* Otherwise, try to add the new range */
-    mrd.mr_base = base;
-    mrd.mr_len = size;
-    strcpy(mrd.mr_owner, X_MTRR_ID);
-    mrd.mr_flags = MDF_WRITECOMBINE;
-    mro.mo_desc = &mrd;
-    mro.mo_arg[0] = MEMRANGE_SET_UPDATE;
-    if (ioctl(devMemFd, MEMRANGE_SET, &mro)) {
-        xf86DrvMsg(screenNum, X_WARNING,
-                   "Failed to set write-combining range "
-                   "(0x%lx,0x%lx)\n", base, size);
-        return NULL;
-    }
-    else {
-        xf86DrvMsg(screenNum, from,
-                   "Write-combining range (0x%lx,0x%lx)\n", base, size);
-        retlist = xnfalloc(sizeof(RangeRec));
-        retlist->mrd = mrd;
-        retlist->wasWC = FALSE;
-        retlist->next = NULL;
-        return retlist;
-    }
-}
-
-static void *
-delWC(int screenNum, unsigned long base, unsigned long size, MessageType from)
-{
-    RangePtr uc = NULL, wc = NULL, retlist = NULL;
-    struct mem_range_desc mrd;
-    struct mem_range_op mro;
-
-    findRanges(base, size, &uc, &wc);
-
-    /*
-     * See of the full range is already not WC, or if there is full
-     * coverage from UC ranges.
-     */
-    if (!wc || fullCoverage(base, size, uc)) {
-        xf86DrvMsg(screenNum, from,
-                   "Write-combining range (0x%lx,0x%lx) was already clear\n",
-                   base, size);
-        return NULL;
-    }
-
-    /* Otherwise, try to add the new range */
-    mrd.mr_base = base;
-    mrd.mr_len = size;
-    strcpy(mrd.mr_owner, X_MTRR_ID);
-    mrd.mr_flags = MDF_UNCACHEABLE;
-    mro.mo_desc = &mrd;
-    mro.mo_arg[0] = MEMRANGE_SET_UPDATE;
-    if (ioctl(devMemFd, MEMRANGE_SET, &mro)) {
-        xf86DrvMsg(screenNum, X_WARNING,
-                   "Failed to remove write-combining range "
-                   "(0x%lx,0x%lx)\n", base, size);
-        /* XXX Should then remove all of the overlapping WC ranges */
-        return NULL;
-    }
-    else {
-        xf86DrvMsg(screenNum, from,
-                   "Removed Write-combining range (0x%lx,0x%lx)\n", base, size);
-        retlist = xnfalloc(sizeof(RangeRec));
-        retlist->mrd = mrd;
-        retlist->wasWC = TRUE;
-        retlist->next = NULL;
-        return retlist;
-    }
-}
-
-static void *
-setWC(int screenNum, unsigned long base, unsigned long size, Bool enable,
-      MessageType from)
-{
-    if (enable)
-        return addWC(screenNum, base, size, from);
-    else
-        return delWC(screenNum, base, size, from);
-}
-
-static void
-undoWC(int screenNum, void *list)
-{
-    RangePtr rp;
-    struct mem_range_op mro;
-    Bool failed;
-
-    rp = list;
-    while (rp) {
-#ifdef DEBUG
-        ErrorF("Undo for (0x%lx,0x%lx), %d\n",
-               (unsigned long) rp->mrd.mr_base,
-               (unsigned long) rp->mrd.mr_len, rp->wasWC);
-#endif
-        failed = FALSE;
-        if (rp->wasWC) {
-            mro.mo_arg[0] = MEMRANGE_SET_UPDATE;
-            rp->mrd.mr_flags = MDF_WRITECOMBINE;
-            strcpy(rp->mrd.mr_owner, "unknown");
-        }
-        else {
-            mro.mo_arg[0] = MEMRANGE_SET_REMOVE;
-        }
-        mro.mo_desc = &rp->mrd;
-
-        if (ioctl(devMemFd, MEMRANGE_SET, &mro)) {
-            if (!rp->wasWC) {
-                mro.mo_arg[0] = MEMRANGE_SET_UPDATE;
-                rp->mrd.mr_flags = MDF_UNCACHEABLE;
-                strcpy(rp->mrd.mr_owner, "unknown");
-                if (ioctl(devMemFd, MEMRANGE_SET, &mro))
-                    failed = TRUE;
-            }
-            else
-                failed = TRUE;
-        }
-        if (failed) {
-            xf86DrvMsg(screenNum, X_WARNING,
-                       "Failed to restore MTRR range (0x%lx,0x%lx)\n",
-                       (unsigned long) rp->mrd.mr_base,
-                       (unsigned long) rp->mrd.mr_len);
-        }
-        rp = rp->next;
-    }
-}
-
 #endif                          /* HAS_MTRR_SUPPORT */
-
-#if defined(HAS_MTRR_BUILTIN) && defined(__NetBSD__)
-static void *
-NetBSDsetWC(int screenNum, unsigned long base, unsigned long size, Bool enable,
-            MessageType from)
-{
-    struct mtrr *mtrrp;
-    int n;
-
-    xf86DrvMsg(screenNum, X_WARNING,
-               "%s MTRR %lx - %lx\n", enable ? "set" : "remove",
-               base, (base + size));
-
-    mtrrp = xnfalloc(sizeof(struct mtrr));
-    mtrrp->base = base;
-    mtrrp->len = size;
-    mtrrp->type = MTRR_TYPE_WC;
-
-    /*
-     * MTRR_PRIVATE will make this MTRR get reset automatically
-     * if this process exits, so we have no need for an explicit
-     * cleanup operation when starting a new server.
-     */
-
-    if (enable)
-        mtrrp->flags = MTRR_VALID | MTRR_PRIVATE;
-    else
-        mtrrp->flags = 0;
-    n = 1;
-
-    if (i386_set_mtrr(mtrrp, &n) < 0) {
-        free(mtrrp);
-        return NULL;
-    }
-    return mtrrp;
-}
-
-static void
-NetBSDundoWC(int screenNum, void *list)
-{
-    struct mtrr *mtrrp = (struct mtrr *) list;
-    int n;
-
-    if (mtrrp == NULL)
-        return;
-    n = 1;
-    mtrrp->flags &= ~MTRR_VALID;
-    i386_set_mtrr(mtrrp, &n);
-    free(mtrrp);
-}
-#endif
diff --git a/hw/xfree86/os-support/linux/lnx_video.c b/hw/xfree86/os-support/linux/lnx_video.c
index 7389d48..2efc9fd 100644
--- a/hw/xfree86/os-support/linux/lnx_video.c
+++ b/hw/xfree86/os-support/linux/lnx_video.c
@@ -42,10 +42,6 @@
 #include "shared/xf86Axp.h"
 #endif
 
-#ifdef HAS_MTRR_SUPPORT
-#include <asm/mtrr.h>
-#endif
-
 static Bool ExtendedEnabled = FALSE;
 
 #ifdef __ia64__
@@ -95,265 +91,6 @@ static unsigned long hae_mask;
 static unsigned long bus_base;
 #endif
 
-#ifdef HAS_MTRR_SUPPORT
-
-#define SPLIT_WC_REGIONS 1
-
-static void *setWC(int, unsigned long, unsigned long, Bool, MessageType);
-static void undoWC(int, void *);
-
-/* The file desc for /proc/mtrr. Once opened, left opened, and the mtrr
-   driver will clean up when we exit. */
-#define MTRR_FD_UNOPENED (-1)   /* We have yet to open /proc/mtrr */
-#define MTRR_FD_PROBLEM (-2)    /* We tried to open /proc/mtrr, but had
-                                   a problem. */
-static int mtrr_fd = MTRR_FD_UNOPENED;
-
-/* Open /proc/mtrr. FALSE on failure. Will always fail on Linux 2.0, 
-   and will fail on Linux 2.2 with MTRR support configured out,
-   so verbosity should be chosen appropriately. */
-static Bool
-mtrr_open(int verbosity)
-{
-    /* Only report absence of /proc/mtrr once. */
-    static Bool warned = FALSE;
-
-    if (mtrr_fd == MTRR_FD_UNOPENED) {
-        mtrr_fd = open("/proc/mtrr", O_WRONLY);
-
-        if (mtrr_fd < 0)
-            mtrr_fd = MTRR_FD_PROBLEM;
-    }
-
-    if (mtrr_fd == MTRR_FD_PROBLEM) {
-        /* To make sure we only ever warn once, need to check
-           verbosity outside xf86MsgVerb */
-        if (!warned && verbosity <= xf86GetVerbosity()) {
-            xf86MsgVerb(X_WARNING, verbosity,
-                        "System lacks support for changing MTRRs\n");
-            warned = TRUE;
-        }
-
-        return FALSE;
-    }
-    else
-        return TRUE;
-}
-
-/*
- * We maintain a list of WC regions for each physical mapping so they can
- * be undone when unmapping.
- */
-
-struct mtrr_wc_region {
-    struct mtrr_sentry sentry;
-    Bool added;                 /* added WC or removed it */
-    struct mtrr_wc_region *next;
-};
-
-static struct mtrr_wc_region *
-mtrr_cull_wc_region(int screenNum, unsigned long base, unsigned long size,
-                    MessageType from)
-{
-    /* Some BIOS writers thought that setting wc over the mmio
-       region of a graphics devices was a good idea. Try to fix
-       it. */
-
-    struct mtrr_gentry gent;
-    struct mtrr_wc_region *wcreturn = NULL, *wcr;
-    int count, ret = 0;
-
-    /* Linux 2.0 users should not get a warning without -verbose */
-    if (!mtrr_open(2))
-        return NULL;
-
-    for (gent.regnum = 0;
-         ioctl(mtrr_fd, MTRRIOC_GET_ENTRY, &gent) >= 0; gent.regnum++) {
-        if (gent.type != MTRR_TYPE_WRCOMB
-            || gent.base + gent.size <= base || base + size <= gent.base)
-            continue;
-
-        /* Found an overlapping region. Delete it. */
-
-        wcr = malloc(sizeof(*wcr));
-        if (!wcr)
-            return NULL;
-        wcr->sentry.base = gent.base;
-        wcr->sentry.size = gent.size;
-        wcr->sentry.type = MTRR_TYPE_WRCOMB;
-        wcr->added = FALSE;
-
-        count = 3;
-        while (count-- &&
-               (ret = ioctl(mtrr_fd, MTRRIOC_KILL_ENTRY, &(wcr->sentry))) < 0);
-
-        if (ret >= 0) {
-            xf86DrvMsg(screenNum, from,
-                       "Removed MMIO write-combining range "
-                       "(0x%lx,0x%lx)\n",
-                       (unsigned long) gent.base, (unsigned long) gent.size);
-            wcr->next = wcreturn;
-            wcreturn = wcr;
-            gent.regnum--;
-        }
-        else {
-            free(wcr);
-            xf86DrvMsgVerb(screenNum, X_WARNING, 0,
-                           "Failed to remove MMIO "
-                           "write-combining range (0x%lx,0x%lx)\n",
-                           (unsigned long)gent.base, (unsigned long) gent.size);
-        }
-    }
-    return wcreturn;
-}
-
-static struct mtrr_wc_region *
-mtrr_remove_offending(int screenNum, unsigned long base, unsigned long size,
-                      MessageType from)
-{
-    struct mtrr_gentry gent;
-    struct mtrr_wc_region *wcreturn = NULL, **wcr;
-
-    if (!mtrr_open(2))
-        return NULL;
-
-    wcr = &wcreturn;
-    for (gent.regnum = 0;
-         ioctl(mtrr_fd, MTRRIOC_GET_ENTRY, &gent) >= 0; gent.regnum++) {
-        if (gent.type == MTRR_TYPE_WRCOMB
-            && ((gent.base >= base && gent.base + gent.size < base + size) ||
-                (gent.base > base && gent.base + gent.size <= base + size))) {
-            *wcr = mtrr_cull_wc_region(screenNum, gent.base, gent.size, from);
-            if (*wcr)
-                gent.regnum--;
-            while (*wcr) {
-                wcr = &((*wcr)->next);
-            }
-        }
-    }
-    return wcreturn;
-}
-
-static struct mtrr_wc_region *
-mtrr_add_wc_region(int screenNum, unsigned long base, unsigned long size,
-                   MessageType from)
-{
-    struct mtrr_wc_region **wcr, *wcreturn, *curwcr;
-
-    /*
-     * There can be only one....
-     */
-
-    wcreturn = mtrr_remove_offending(screenNum, base, size, from);
-    wcr = &wcreturn;
-    while (*wcr) {
-        wcr = &((*wcr)->next);
-    }
-
-    /* Linux 2.0 should not warn, unless the user explicitly asks for
-       WC. */
-
-    if (!mtrr_open(from == X_CONFIG ? 0 : 2))
-        return wcreturn;
-
-    *wcr = curwcr = malloc(sizeof(**wcr));
-    if (!curwcr)
-        return wcreturn;
-
-    curwcr->sentry.base = base;
-    curwcr->sentry.size = size;
-    curwcr->sentry.type = MTRR_TYPE_WRCOMB;
-    curwcr->added = TRUE;
-    curwcr->next = NULL;
-
-#if SPLIT_WC_REGIONS
-    /*
-     * Splits up the write-combining region if it is not aligned on a
-     * size boundary.
-     */
-
-    {
-        unsigned long lbase, d_size = 1;
-        unsigned long n_size = size;
-        unsigned long n_base = base;
-
-        for (lbase = n_base, d_size = 1; !(lbase & 1);
-             lbase = lbase >> 1, d_size <<= 1);
-        while (d_size > n_size)
-            d_size = d_size >> 1;
-        DebugF("WC_BASE: 0x%lx WC_END: 0x%lx\n", base, base + d_size - 1);
-        n_base += d_size;
-        n_size -= d_size;
-        if (n_size) {
-            xf86DrvMsgVerb(screenNum, X_INFO, 3, "Splitting WC range: "
-                           "base: 0x%lx, size: 0x%lx\n", base, size);
-            curwcr->next = mtrr_add_wc_region(screenNum, n_base, n_size, from);
-        }
-        curwcr->sentry.size = d_size;
-    }
-
-        /*****************************************************************/
-#endif                          /* SPLIT_WC_REGIONS */
-
-    if (ioctl(mtrr_fd, MTRRIOC_ADD_ENTRY, &curwcr->sentry) >= 0) {
-        /* Avoid printing on every VT switch */
-        if (xf86ServerIsInitialising()) {
-            xf86DrvMsg(screenNum, from,
-                       "Write-combining range (0x%lx,0x%lx)\n", base, size);
-        }
-        return wcreturn;
-    }
-    else {
-        *wcr = curwcr->next;
-        free(curwcr);
-
-        /* Don't complain about the VGA region: MTRR fixed
-           regions aren't currently supported, but might be in
-           the future. */
-        if ((unsigned long) base >= 0x100000) {
-            xf86DrvMsgVerb(screenNum, X_WARNING, 0,
-                           "Failed to set up write-combining range "
-                           "(0x%lx,0x%lx)\n", base, size);
-        }
-        return wcreturn;
-    }
-}
-
-static void
-mtrr_undo_wc_region(int screenNum, struct mtrr_wc_region *wcr)
-{
-    struct mtrr_wc_region *p, *prev;
-
-    if (mtrr_fd >= 0) {
-        p = wcr;
-        while (p) {
-            if (p->added)
-                ioctl(mtrr_fd, MTRRIOC_DEL_ENTRY, &p->sentry);
-            prev = p;
-            p = p->next;
-            free(prev);
-        }
-    }
-}
-
-static void *
-setWC(int screenNum, unsigned long base, unsigned long size, Bool enable,
-      MessageType from)
-{
-    if (enable)
-        return mtrr_add_wc_region(screenNum, base, size, from);
-    else
-        return mtrr_cull_wc_region(screenNum, base, size, from);
-}
-
-static void
-undoWC(int screenNum, void *regioninfo)
-{
-    mtrr_undo_wc_region(screenNum, regioninfo);
-}
-
-#endif                          /* HAS_MTRR_SUPPORT */
-
 void
 xf86OSInitVidMem(VidMemInfoPtr pVidMem)
 {
@@ -375,10 +112,6 @@ xf86OSInitVidMem(VidMemInfoPtr pVidMem)
     }
 #endif                          /* __alpha__ */
 
-#ifdef HAS_MTRR_SUPPORT
-    pVidMem->setWC = setWC;
-    pVidMem->undoWC = undoWC;
-#endif
     pVidMem->initialised = TRUE;
 }
 
diff --git a/hw/xfree86/os-support/shared/vidmem.c b/hw/xfree86/os-support/shared/vidmem.c
index 1c695fe..0135867 100644
--- a/hw/xfree86/os-support/shared/vidmem.c
+++ b/hw/xfree86/os-support/shared/vidmem.c
@@ -129,7 +129,7 @@ xf86CheckMTRR(int ScreenNum)
      */
     checkMtrrOption(vp);
 
-    if (vp->mtrrEnabled && vidMemInfo.setWC)
+    if (vp->mtrrEnabled)
         return TRUE;
 
     return FALSE;
diff --git a/hw/xfree86/os-support/xf86OSpriv.h b/hw/xfree86/os-support/xf86OSpriv.h
index c586c7a..7240f14 100644
--- a/hw/xfree86/os-support/xf86OSpriv.h
+++ b/hw/xfree86/os-support/xf86OSpriv.h
@@ -32,14 +32,8 @@
 #ifndef _XF86OSPRIV_H
 #define _XF86OSPRIV_H
 
-typedef void *(*SetWCProcPtr) (int, unsigned long, unsigned long, Bool,
-                                 MessageType);
-typedef void (*UndoWCProcPtr) (int, void *);
-
 typedef struct {
     Bool initialised;
-    SetWCProcPtr setWC;
-    UndoWCProcPtr undoWC;
     Bool linearSupported;
 } VidMemInfo, *VidMemInfoPtr;
 
commit 9db2af6f757ef9680c70eb731698b7c9f9aca203
Author: Adam Jackson <ajax at redhat.com>
Date:   Fri May 2 12:14:10 2014 -0400

    xfree86: Remove xf86{Map,Unmap}VidMem
    
    This API sucks.  Fortunately it's mostly unused at this point.  geode,
    sis, and xgi need minor patches to use the corresponding pciaccess code,
    neomagic will (more explicitly) lose its non-PCI support, and newport
    will need to be ported to /dev/mem or the platform bus or something.
    
    This should also make it pretty clear that alpha's sparse memory support
    was basically not a thing anymore, very few tears shed.
    
    Reviewed-by: Eric Anholt <eric at anholt.net>
    Signed-off-by: Adam Jackson <ajax at redhat.com>

diff --git a/hw/xfree86/os-support/bsd/alpha_video.c b/hw/xfree86/os-support/bsd/alpha_video.c
index f656f55..3aeae58 100644
--- a/hw/xfree86/os-support/bsd/alpha_video.c
+++ b/hw/xfree86/os-support/bsd/alpha_video.c
@@ -35,9 +35,6 @@
 #ifndef __NetBSD__
 #include <sys/sysctl.h>
 #endif
-#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__NetBSD__)
-#include <machine/sysarch.h>
-#endif
 
 #include "xf86Axp.h"
 
@@ -59,32 +56,6 @@ static int axpSystem = -1;
 static unsigned long hae_thresh;
 static unsigned long hae_mask;
 
-static unsigned long
-memory_base(void)
-{
-    static unsigned long base = 0;
-
-    if (base == 0) {
-        size_t len = sizeof(base);
-        int error;
-
-#ifdef __OpenBSD__
-        int mib[3];
-
-        mib[0] = CTL_MACHDEP;
-        mib[1] = CPU_CHIPSET;
-        mib[2] = CPU_CHIPSET_MEM;
-
-        if ((error = sysctl(mib, 3, &base, &len, NULL, 0)) < 0)
-#else
-        if ((error = sysctlbyname("hw.chipset.memory", &base, &len, 0, 0)) < 0)
-#endif
-            FatalError("xf86MapVidMem: can't find memory\n");
-    }
-
-    return base;
-}
-
 static int
 has_bwx(void)
 {
@@ -147,30 +118,9 @@ dense_base(void)
     return abw[0].abw_abst.abst_sys_start;
 }
 
-static unsigned long
-memory_base(void)
-{
-    if (abw_count < 0)
-        init_abw();
-
-    if (abw_count > 1) {
-        xf86Msg(X_INFO, "memory base = %#lx\n", abw[1].abw_abst.abst_sys_start);        /* XXXX */
-        return abw[1].abw_abst.abst_sys_start;
-    }
-    else if (abw_count == 1) {
-        /* assume memory_base == dense_base */
-        xf86Msg(X_INFO, "memory base = %#lx\n", abw[0].abw_abst.abst_sys_start);        /* XXXX */
-        return abw[0].abw_abst.abst_sys_start;
-    }
-    else {
-        xf86Msg(X_INFO, "no memory base\n");    /* XXXX */
-        return 0;
-    }
-}
 #endif                          /* __NetBSD__ */
 
 #define BUS_BASE	dense_base()
-#define BUS_BASE_BWX	memory_base()
 
 /***************************************************************************/
 /* Video Memory Mapping section                                            */
@@ -189,11 +139,6 @@ static int devMemFd = -1;
 #define DEV_APERTURE "/dev/xf86"
 #endif
 
-static void *mapVidMem(int, unsigned long, unsigned long, int);
-static void unmapVidMem(int, void *, unsigned long);
-static void *mapVidMemSparse(int, unsigned long, unsigned long, int);
-static void unmapVidMemSparse(int, void *, unsigned long);
-
 /*
  * Check if /dev/mem can be mmap'd.  If it can't print a warning when
  * "warn" is TRUE.
@@ -278,13 +223,9 @@ xf86OSInitVidMem(VidMemInfoPtr pVidMem)
 
     if (has_bwx()) {
         xf86Msg(X_PROBED, "Machine type has 8/16 bit access\n");
-        pVidMem->mapMem = mapVidMem;
-        pVidMem->unmapMem = unmapVidMem;
     }
     else {
         xf86Msg(X_PROBED, "Machine needs sparse mapping\n");
-        pVidMem->mapMem = mapVidMemSparse;
-        pVidMem->unmapMem = unmapVidMemSparse;
 #ifndef __NetBSD__
         if (axpSystem == -1)
             axpSystem = bsdGetAXP();
@@ -295,52 +236,6 @@ xf86OSInitVidMem(VidMemInfoPtr pVidMem)
     pVidMem->initialised = TRUE;
 }
 
-static void *
-mapVidMem(int ScreenNum, unsigned long Base, unsigned long Size, int flags)
-{
-    void *base;
-
-    checkDevMem(FALSE);
-    Base = Base & ((1L << 32) - 1);
-
-    if (useDevMem) {
-        if (devMemFd < 0) {
-            FatalError("xf86MapVidMem: failed to open %s (%s)\n",
-                       DEV_MEM, strerror(errno));
-        }
-        base = mmap((caddr_t) 0, Size,
-                    (flags & VIDMEM_READONLY) ?
-                    PROT_READ : (PROT_READ | PROT_WRITE),
-                    MAP_FLAGS, devMemFd, (off_t) Base + BUS_BASE_BWX);
-        if (base == MAP_FAILED) {
-            FatalError("%s: could not mmap %s [s=%lx,a=%lx] (%s)\n",
-                       "xf86MapVidMem", DEV_MEM, Size, Base, strerror(errno));
-        }
-        return base;
-    }
-
-    /* else, mmap /dev/vga */
-    if ((unsigned long) Base < 0xA0000 || (unsigned long) Base >= 0xC0000) {
-        FatalError("%s: Address 0x%lx outside allowable range\n",
-                   "xf86MapVidMem", Base);
-    }
-    base = mmap(0, Size,
-                (flags & VIDMEM_READONLY) ?
-                PROT_READ : (PROT_READ | PROT_WRITE),
-                MAP_FLAGS, xf86Info.consoleFd, (unsigned long) Base + BUS_BASE);
-    if (base == MAP_FAILED) {
-        FatalError("xf86MapVidMem: Could not mmap /dev/vga (%s)\n",
-                   strerror(errno));
-    }
-    return base;
-}
-
-static void
-unmapVidMem(int ScreenNum, void *Base, unsigned long Size)
-{
-    munmap((caddr_t) Base, Size);
-}
-
 /*
  * Read BIOS via mmap()ing DEV_MEM
  */
@@ -422,11 +317,6 @@ xf86DisableIO()
 
 #endif                          /* USE_ALPHA_PIO */
 
-#define vuip    volatile unsigned int *
-
-static void *memSBase = 0;
-static void *memBase = 0;
-
 extern int readDense8(void *Base, register unsigned long Offset);
 extern int readDense16(void *Base, register unsigned long Offset);
 extern int readDense32(void *Base, register unsigned long Offset);
@@ -437,223 +327,6 @@ extern void
 extern void
  writeDense32(int Value, void *Base, register unsigned long Offset);
 
-static int readSparse8(void *Base, register unsigned long Offset);
-static int readSparse16(void *Base, register unsigned long Offset);
-static int readSparse32(void *Base, register unsigned long Offset);
-static void
- writeSparseNB8(int Value, void *Base, register unsigned long Offset);
-static void
- writeSparseNB16(int Value, void *Base, register unsigned long Offset);
-static void
- writeSparseNB32(int Value, void *Base, register unsigned long Offset);
-static void
- writeSparse8(int Value, void *Base, register unsigned long Offset);
-static void
- writeSparse16(int Value, void *Base, register unsigned long Offset);
-static void
- writeSparse32(int Value, void *Base, register unsigned long Offset);
-
-#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
-extern int sysarch(int, void *);
-
-struct parms {
-    u_int64_t hae;
-};
-
-static void
-sethae(u_int64_t hae)
-{
-#ifndef ALPHA_SETHAE
-#define ALPHA_SETHAE 0
-#endif
-    static struct parms p;
-
-    if (p.hae != hae) {
-        p.hae = hae;
-        sysarch(ALPHA_SETHAE, (char *) &p);
-    }
-}
-#endif
-
-static void *
-mapVidMemSparse(int ScreenNum, unsigned long Base, unsigned long Size,
-                int flags)
-{
-    static Bool was_here = FALSE;
-
-    if (!was_here) {
-        was_here = TRUE;
-
-        checkDevMem(FALSE);
-
-        xf86WriteMmio8 = writeSparse8;
-        xf86WriteMmio16 = writeSparse16;
-        xf86WriteMmio32 = writeSparse32;
-        xf86WriteMmioNB8 = writeSparseNB8;
-        xf86WriteMmioNB16 = writeSparseNB16;
-        xf86WriteMmioNB32 = writeSparseNB32;
-        xf86ReadMmio8 = readSparse8;
-        xf86ReadMmio16 = readSparse16;
-        xf86ReadMmio32 = readSparse32;
-
-        memBase = mmap((caddr_t) 0, 0x100000000,
-                       PROT_READ | PROT_WRITE,
-                       MAP_SHARED, devMemFd, (off_t) BUS_BASE);
-        memSBase = mmap((caddr_t) 0, 0x100000000,
-                        PROT_READ | PROT_WRITE,
-                        MAP_SHARED, devMemFd, (off_t) BUS_BASE_BWX);
-
-        if (memSBase == MAP_FAILED || memBase == MAP_FAILED) {
-            FatalError("xf86MapVidMem: Could not mmap framebuffer (%s)\n",
-                       strerror(errno));
-        }
-    }
-    return (void *) ((unsigned long) memBase + Base);
-}
-
-static void
-unmapVidMemSparse(int ScreenNum, void *Base, unsigned long Size)
-{
-}
-
-static int
-readSparse8(void *Base, register unsigned long Offset)
-{
-    register unsigned long result, shift;
-    register unsigned long msb;
-
-    mem_barrier();
-    Offset += (unsigned long) Base - (unsigned long) memBase;
-    shift = (Offset & 0x3) << 3;
-    if (Offset >= (hae_thresh)) {
-        msb = Offset & hae_mask;
-        Offset -= msb;
-#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
-        sethae(msb);
-#endif
-    }
-    result = *(vuip) ((unsigned long) memSBase + (Offset << 5));
-    result >>= shift;
-    return 0xffUL & result;
-}
-
-static int
-readSparse16(void *Base, register unsigned long Offset)
-{
-    register unsigned long result, shift;
-    register unsigned long msb;
-
-    mem_barrier();
-    Offset += (unsigned long) Base - (unsigned long) memBase;
-    shift = (Offset & 0x2) << 3;
-    if (Offset >= (hae_thresh)) {
-        msb = Offset & hae_mask;
-        Offset -= msb;
-#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
-        sethae(msb);
-#endif
-    }
-    result =
-        *(vuip) ((unsigned long) memSBase + (Offset << 5) + (1 << (5 - 2)));
-    result >>= shift;
-    return 0xffffUL & result;
-}
-
-static int
-readSparse32(void *Base, register unsigned long Offset)
-{
-    mem_barrier();
-    return *(vuip) ((unsigned long) Base + (Offset));
-}
-
-static void
-writeSparse8(int Value, void *Base, register unsigned long Offset)
-{
-    register unsigned long msb;
-    register unsigned int b = Value & 0xffU;
-
-    write_mem_barrier();
-    Offset += (unsigned long) Base - (unsigned long) memBase;
-    if (Offset >= (hae_thresh)) {
-        msb = Offset & hae_mask;
-        Offset -= msb;
-#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
-        sethae(msb);
-#endif
-    }
-    *(vuip) ((unsigned long) memSBase + (Offset << 5)) = b * 0x01010101;
-}
-
-static void
-writeSparse16(int Value, void *Base, register unsigned long Offset)
-{
-    register unsigned long msb;
-    register unsigned int w = Value & 0xffffU;
-
-    write_mem_barrier();
-    Offset += (unsigned long) Base - (unsigned long) memBase;
-    if (Offset >= (hae_thresh)) {
-        msb = Offset & hae_mask;
-        Offset -= msb;
-#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
-        sethae(msb);
-#endif
-    }
-    *(vuip) ((unsigned long) memSBase + (Offset << 5) + (1 << (5 - 2))) =
-        w * 0x00010001;
-
-}
-
-static void
-writeSparse32(int Value, void *Base, register unsigned long Offset)
-{
-    write_mem_barrier();
-    *(vuip) ((unsigned long) Base + (Offset)) = Value;
-    return;
-}
-
-static void
-writeSparseNB8(int Value, void *Base, register unsigned long Offset)
-{
-    register unsigned long msb;
-    register unsigned int b = Value & 0xffU;
-
-    Offset += (unsigned long) Base - (unsigned long) memBase;
-    if (Offset >= (hae_thresh)) {
-        msb = Offset & hae_mask;
-        Offset -= msb;
-#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
-        sethae(msb);
-#endif
-    }
-    *(vuip) ((unsigned long) memSBase + (Offset << 5)) = b * 0x01010101;
-}
-
-static void
-writeSparseNB16(int Value, void *Base, register unsigned long Offset)
-{
-    register unsigned long msb;
-    register unsigned int w = Value & 0xffffU;
-
-    Offset += (unsigned long) Base - (unsigned long) memBase;
-    if (Offset >= (hae_thresh)) {
-        msb = Offset & hae_mask;
-        Offset -= msb;
-#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
-        sethae(msb);
-#endif
-    }
-    *(vuip) ((unsigned long) memSBase + (Offset << 5) + (1 << (5 - 2))) =
-        w * 0x00010001;
-}
-
-static void
-writeSparseNB32(int Value, void *Base, register unsigned long Offset)
-{
-    *(vuip) ((unsigned long) Base + (Offset)) = Value;
-    return;
-}
-
 void (*xf86WriteMmio8) (int Value, void *Base, unsigned long Offset)
     = writeDense8;
 void (*xf86WriteMmio16) (int Value, void *Base, unsigned long Offset)
diff --git a/hw/xfree86/os-support/bsd/arm_video.c b/hw/xfree86/os-support/bsd/arm_video.c
index e295c92..95f4017 100644
--- a/hw/xfree86/os-support/bsd/arm_video.c
+++ b/hw/xfree86/os-support/bsd/arm_video.c
@@ -66,35 +66,6 @@
 #include "xf86_OSlib.h"
 #include "xf86OSpriv.h"
 
-#ifdef __arm32__
-#include "machine/devmap.h"
-struct memAccess {
-    int ioctl;
-    struct map_info memInfo;
-    void *regionVirtBase;
-    Bool Checked;
-    Bool OK;
-};
-
-static void *xf86MapInfoMap();
-static void xf86MapInfoUnmap();
-static struct memAccess *checkMapInfo();
-extern int vgaPhysLinearBase;
-
-/* A memAccess structure is needed for each possible region */
-struct memAccess vgaMemInfo = { CONSOLE_GET_MEM_INFO, NULL, NULL,
-    FALSE, FALSE
-};
-
-struct memAccess linearMemInfo = { CONSOLE_GET_LINEAR_INFO, NULL, NULL,
-    FALSE, FALSE
-};
-
-struct memAccess ioMemInfo = { CONSOLE_GET_IO_INFO, NULL, NULL,
-    FALSE, FALSE
-};
-#endif                          /* __arm32__ */
-
 #if defined(__NetBSD__) && !defined(MAP_FILE)
 #define MAP_FLAGS MAP_SHARED
 #else
@@ -111,9 +82,6 @@ struct memAccess ioMemInfo = { CONSOLE_GET_IO_INFO, NULL, NULL,
 static Bool useDevMem = FALSE;
 static int devMemFd = -1;
 
-static void *mapVidMem(int, unsigned long, unsigned long, int);
-static void unmapVidMem(int, void *, unsigned long);
-
 /*
  * Check if /dev/mem can be mmap'd.  If it can't print a warning when
  * "warn" is TRUE.
@@ -164,57 +132,10 @@ xf86OSInitVidMem(VidMemInfoPtr pVidMem)
 
     checkDevMem(TRUE);
     pVidMem->linearSupported = useDevMem;
-    pVidMem->mapMem = armMapVidMem;
-    pVidMem->unmapVidMem = armUnmapVidMem;
 
     pVidMem->initialised = TRUE;
 }
 
-static void *
-mapVidMem(int ScreenNum, unsigned long Base, unsigned long Size, int flags)
-{
-    void *base;
-
-    checkDevMem(FALSE);
-
-    if (useDevMem) {
-        if (devMemFd < 0) {
-            FatalError("xf86MapVidMem: failed to open %s (%s)\n",
-                       DEV_MEM, strerror(errno));
-        }
-        base = mmap((caddr_t) 0, Size,
-                    (flags & VIDMEM_READONLY) ?
-                    PROT_READ : (PROT_READ | PROT_WRITE),
-                    MAP_FLAGS, devMemFd, (off_t) Base + BUS_BASE_BWX);
-        if (base == MAP_FAILED) {
-            FatalError("%s: could not mmap %s [s=%x,a=%x] (%s)\n",
-                       "xf86MapVidMem", DEV_MEM, Size, Base, strerror(errno));
-        }
-        return base;
-    }
-
-    /* else, mmap /dev/vga */
-    if ((unsigned long) Base < 0xA0000 || (unsigned long) Base >= 0xC0000) {
-        FatalError("%s: Address 0x%x outside allowable range\n",
-                   "xf86MapVidMem", Base);
-    }
-    base = mmap(0, Size,
-                (flags & VIDMEM_READONLY) ?
-                PROT_READ : (PROT_READ | PROT_WRITE),
-                MAP_FLAGS, xf86Info.consoleFd, (unsigned long) Base - 0xA0000);
-    if (base == MAP_FAILED) {
-        FatalError("xf86MapVidMem: Could not mmap /dev/vga (%s)\n",
-                   strerror(errno));
-    }
-    return base;
-}
-
-static void
-unmapVidMem(int ScreenNum, void *Base, unsigned long Size)
-{
-    munmap((caddr_t) Base, Size);
-}
-
 /*
  * Read BIOS via mmap()ing DEV_MEM
  */
@@ -258,162 +179,6 @@ xf86ReadBIOS(unsigned long Base, unsigned long Offset, unsigned char *Buf,
     return Len;
 }
 
-/* XXX This needs to be updated for the ND */
-
-/*
-** Find out whether the console driver provides memory mapping information 
-** for the specified region and return the map_info pointer. Print a warning if required.
-*/
-static struct memAccess *
-checkMapInfo(Bool warn, int Region)
-{
-    struct memAccess *memAccP;
-
-    switch (Region) {
-    case VGA_REGION:
-        memAccP = &vgaMemInfo;
-        break;
-
-    case LINEAR_REGION:
-        memAccP = &linearMemInfo;
-        break;
-
-    case MMIO_REGION:
-        memAccP = &ioMemInfo;
-        break;
-
-    default:
-        return NULL;
-        break;
-    }
-
-    if (!memAccP->Checked) {
-        if (ioctl(xf86Info.consoleFd, memAccP->ioctl, &(memAccP->memInfo)) ==
-            -1) {
-            if (warn) {
-                xf86Msg(X_WARNING,
-                        "checkMapInfo: failed to get map info for region %d\n\t(%s)\n",
-                        Region, strerror(errno));
-            }
-        }
-        else {
-            if (memAccP->memInfo.u.map_info_mmap.map_offset != MAP_INFO_UNKNOWN)
-                memAccP->OK = TRUE;
-        }
-        memAccP->Checked = TRUE;
-    }
-    if (memAccP->OK) {
-        return memAccP;
-    }
-    else {
-        return NULL;
-    }
-}
-
-static void *
-xf86MapInfoMap(struct memAccess *memInfoP, void *Base, unsigned long Size)
-{
-    struct map_info *mapInfoP = &(memInfoP->memInfo);
-
-    if (mapInfoP->u.map_info_mmap.map_size == MAP_INFO_UNKNOWN) {
-        Size = (unsigned long) Base + Size;
-    }
-    else {
-        Size = mapInfoP->u.map_info_mmap.map_size;
-    }
-
-    switch (mapInfoP->method) {
-    case MAP_MMAP:
-        /* Need to remap if size is unknown because we may not have
-           mapped the whole region initially */
-        if (memInfoP->regionVirtBase == NULL ||
-            mapInfoP->u.map_info_mmap.map_size == MAP_INFO_UNKNOWN) {
-            if ((memInfoP->regionVirtBase =
-                 mmap((caddr_t) 0,
-                      Size,
-                      PROT_READ | PROT_WRITE,
-                      MAP_SHARED,
-                      xf86Info.consoleFd,
-                      (unsigned long) mapInfoP->u.map_info_mmap.map_offset))
-                == (void *) -1) {
-                FatalError
-                    ("xf86MapInfoMap: Failed to map memory at 0x%x\n\t%s\n",
-                     mapInfoP->u.map_info_mmap.map_offset, strerror(errno));
-            }
-            if (mapInfoP->u.map_info_mmap.internal_offset > 0)
-                memInfoP->regionVirtBase +=
-                    mapInfoP->u.map_info_mmap.internal_offset;
-        }
-        break;
-
-    default:
-        FatalError("xf86MapInfoMap: Unsuported mapping method\n");
-        break;
-    }
-
-    return (void *) ((int) memInfoP->regionVirtBase + (int) Base);
-}
-
-static void
-xf86MapInfoUnmap(struct memAccess *memInfoP, unsigned long Size)
-{
-    struct map_info *mapInfoP = &(memInfoP->memInfo);
-
-    switch (mapInfoP->method) {
-    case MAP_MMAP:
-        if (memInfoP->regionVirtBase != NULL) {
-            if (mapInfoP->u.map_info_mmap.map_size != MAP_INFO_UNKNOWN)
-                Size = mapInfoP->u.map_info_mmap.map_size;
-            munmap((caddr_t) memInfoP->regionVirtBase, Size);
-            memInfoP->regionVirtBase = NULL;
-        }
-        break;
-    default:
-        FatalError("xf86MapInfoMap: Unsuported mapping method\n");
-        break;
-    }
-}
-
-static void *
-armMapVidMem(int ScreenNum, unsigned long Base, unsigned long Size, int flags)
-{
-    struct memAccess *memInfoP;
-
-    if ((memInfoP = checkMapInfo(FALSE, Region)) != NULL) {
-        /*
-         ** xf86 passes in a physical address offset from the start
-         ** of physical memory, but xf86MapInfoMap expects an 
-         ** offset from the start of the specified region - it gets 
-         ** the physical address of the region from the display driver.
-         */
-        switch (Region) {
-        case LINEAR_REGION:
-            if (vgaPhysLinearBase) {
-                Base -= vgaPhysLinearBase;
-            }
-            break;
-        case VGA_REGION:
-            Base -= 0xA0000;
-            break;
-        }
-
-        base = xf86MapInfoMap(memInfoP, Base, Size);
-        return base;
-    }
-    return mapVidMem(ScreenNum, Base, Size, flags);
-}
-
-static void
-armUnmapVidMem(int ScreenNum, void *Base, unsigned long Size)
-{
-    struct memAccess *memInfoP;
-
-    if ((memInfoP = checkMapInfo(FALSE, Region)) != NULL) {
-        xf86MapInfoUnmap(memInfoP, Base, Size);
-    }
-    unmapVidMem(ScreenNum, Base, Size);
-}
-
 #ifdef USE_DEV_IO
 static int IoFd = -1;
 
diff --git a/hw/xfree86/os-support/bsd/i386_video.c b/hw/xfree86/os-support/bsd/i386_video.c
index 7453190..cc84f44 100644
--- a/hw/xfree86/os-support/bsd/i386_video.c
+++ b/hw/xfree86/os-support/bsd/i386_video.c
@@ -85,9 +85,6 @@ static int devMemFd = -1;
 #define DEV_APERTURE "/dev/xf86"
 #endif
 
-static void *mapVidMem(int, unsigned long, unsigned long, int);
-static void unmapVidMem(int, void *, unsigned long);
-
 #ifdef HAS_MTRR_SUPPORT
 static void *setWC(int, unsigned long, unsigned long, Bool, MessageType);
 static void undoWC(int, void *);
@@ -189,8 +186,6 @@ xf86OSInitVidMem(VidMemInfoPtr pVidMem)
 {
     checkDevMem(TRUE);
     pVidMem->linearSupported = useDevMem;
-    pVidMem->mapMem = mapVidMem;
-    pVidMem->unmapMem = unmapVidMem;
 
     if (useDevMem)
         pci_system_init_dev_mem(devMemFd);
@@ -210,51 +205,6 @@ xf86OSInitVidMem(VidMemInfoPtr pVidMem)
     pVidMem->initialised = TRUE;
 }
 
-static void *
-mapVidMem(int ScreenNum, unsigned long Base, unsigned long Size, int flags)
-{
-    void *base;
-
-    checkDevMem(FALSE);
-
-    if (useDevMem) {
-        if (devMemFd < 0) {
-            FatalError("xf86MapVidMem: failed to open %s (%s)",
-                       DEV_MEM, strerror(errno));
-        }
-        base = mmap((caddr_t) 0, Size,
-                    (flags & VIDMEM_READONLY) ?
-                    PROT_READ : (PROT_READ | PROT_WRITE),
-                    MAP_FLAGS, devMemFd, (off_t) Base);
-        if (base == MAP_FAILED) {
-            FatalError("%s: could not mmap %s [s=%lx,a=%lx] (%s)",
-                       "xf86MapVidMem", DEV_MEM, Size, Base, strerror(errno));
-        }
-        return base;
-    }
-
-    /* else, mmap /dev/vga */
-    if ((unsigned long) Base < 0xA0000 || (unsigned long) Base >= 0xC0000) {
-        FatalError("%s: Address 0x%lx outside allowable range",
-                   "xf86MapVidMem", Base);
-    }
-    base = mmap(0, Size,
-                (flags & VIDMEM_READONLY) ?
-                PROT_READ : (PROT_READ | PROT_WRITE),
-                MAP_FLAGS, xf86Info.consoleFd, (unsigned long) Base - 0xA0000);
-    if (base == MAP_FAILED) {
-        FatalError("xf86MapVidMem: Could not mmap /dev/vga (%s)",
-                   strerror(errno));
-    }
-    return base;
-}
-
-static void
-unmapVidMem(int ScreenNum, void *Base, unsigned long Size)
-{
-    munmap((caddr_t) Base, Size);
-}
-
 /*
  * Read BIOS via mmap()ing DEV_MEM
  */
diff --git a/hw/xfree86/os-support/bsd/ppc_video.c b/hw/xfree86/os-support/bsd/ppc_video.c
index 3fd28c3..a624d4d 100644
--- a/hw/xfree86/os-support/bsd/ppc_video.c
+++ b/hw/xfree86/os-support/bsd/ppc_video.c
@@ -44,9 +44,6 @@
 #define DEV_MEM "/dev/xf86"
 #endif
 
-static void *ppcMapVidMem(int, unsigned long, unsigned long, int flags);
-static void ppcUnmapVidMem(int, void *, unsigned long);
-
 Bool xf86EnableIO(void);
 void xf86DisableIO(void);
 
@@ -54,40 +51,12 @@ void
 xf86OSInitVidMem(VidMemInfoPtr pVidMem)
 {
     pVidMem->linearSupported = TRUE;
-    pVidMem->mapMem = ppcMapVidMem;
-    pVidMem->unmapMem = ppcUnmapVidMem;
     pVidMem->initialised = TRUE;
     xf86EnableIO();
 }
 
 volatile unsigned char *ioBase = MAP_FAILED;
 
-static void *
-ppcMapVidMem(int ScreenNum, unsigned long Base, unsigned long Size, int flags)
-{
-    int fd = xf86Info.consoleFd;
-    void *base;
-
-#ifdef DEBUG
-    xf86MsgVerb(X_INFO, 3, "mapVidMem %lx, %lx, fd = %d", Base, Size, fd);
-#endif
-
-    base = mmap(0, Size,
-                (flags & VIDMEM_READONLY) ?
-                PROT_READ : (PROT_READ | PROT_WRITE), MAP_SHARED, fd, Base);
-    if (base == MAP_FAILED)
-        FatalError("%s: could not mmap screen [s=%lx,a=%lx] (%s)",
-                   "xf86MapVidMem", Size, Base, strerror(errno));
-
-    return base;
-}
-
-static void
-ppcUnmapVidMem(int ScreenNum, void *Base, unsigned long Size)
-{
-    munmap(Base, Size);
-}
-
 int
 xf86ReadBIOS(unsigned long Base, unsigned long Offset, unsigned char *Buf,
              int Len)
diff --git a/hw/xfree86/os-support/bsd/sparc64_video.c b/hw/xfree86/os-support/bsd/sparc64_video.c
index 02951d6..3fd0315 100644
--- a/hw/xfree86/os-support/bsd/sparc64_video.c
+++ b/hw/xfree86/os-support/bsd/sparc64_video.c
@@ -38,44 +38,13 @@
 /* Video Memory Mapping section                                            */
 /***************************************************************************/
 
-static void *sparc64MapVidMem(int, unsigned long, unsigned long, int);
-static void sparc64UnmapVidMem(int, void *, unsigned long);
-
 void
 xf86OSInitVidMem(VidMemInfoPtr pVidMem)
 {
     pVidMem->linearSupported = TRUE;
-    pVidMem->mapMem = sparc64MapVidMem;
-    pVidMem->unmapMem = sparc64UnmapVidMem;
     pVidMem->initialised = TRUE;
 }
 
-static void *
-sparc64MapVidMem(int ScreenNum, unsigned long Base, unsigned long Size,
-                 int flags)
-{
-    int fd = xf86Info.consoleFd;
-    void *base;
-
-#ifdef DEBUG
-    xf86MsgVerb(X_INFO, 3, "mapVidMem %lx, %lx, fd = %d", Base, Size, fd);
-#endif
-
-    base = mmap(0, Size,
-                (flags & VIDMEM_READONLY) ?
-                PROT_READ : (PROT_READ | PROT_WRITE), MAP_SHARED, fd, Base);
-    if (base == MAP_FAILED)
-        FatalError("%s: could not mmap screen [s=%x,a=%x] (%s)",
-                   "xf86MapVidMem", Size, Base, strerror(errno));
-    return base;
-}
-
-static void
-sparc64UnmapVidMem(int ScreenNum, void *Base, unsigned long Size)
-{
-    munmap(Base, Size);
-}
-
 int
 xf86ReadBIOS(unsigned long Base, unsigned long Offset, unsigned char *Buf,
              int Len)
diff --git a/hw/xfree86/os-support/hurd/hurd_video.c b/hw/xfree86/os-support/hurd/hurd_video.c
index dc1a8e6..6485917 100644
--- a/hw/xfree86/os-support/hurd/hurd_video.c
+++ b/hw/xfree86/os-support/hurd/hurd_video.c
@@ -42,68 +42,6 @@
 /**************************************************************************
  * Video Memory Mapping section                                            
  ***************************************************************************/
-static void *
-mapVidMem(int ScreenNum, unsigned long Base, unsigned long Size, int Flags)
-{
-    mach_port_t device, mem_dev;
-    memory_object_t mem_obj;
-    kern_return_t err;
-    vm_address_t addr = (vm_address_t) 0;
-
-    err = get_privileged_ports(NULL, &device);
-    if (err) {
-        errno = err;
-        FatalError("xf86MapVidMem() can't get_privileged_ports. (%s)\n",
-                   strerror(errno));
-    }
-    err = device_open(device, D_READ | D_WRITE, "mem", &mem_dev);
-    mach_port_deallocate(mach_task_self(), device);
-    if (err) {
-        errno = err;
-        FatalError("xf86MapVidMem() can't device_open. (%s)\n",
-                   strerror(errno));
-    }
-
-    err =
-        device_map(mem_dev, VM_PROT_READ | VM_PROT_WRITE, Base, Size, &mem_obj,
-                   0);
-    if (err) {
-        errno = err;
-        FatalError("xf86MapVidMem() can't device_map. (%s)\n", strerror(errno));
-    }
-    err = vm_map(mach_task_self(), &addr, Size, 0,      /* mask */
-                 TRUE,          /* anywhere */
-                 mem_obj, (vm_offset_t) Base, FALSE,    /* copy on write */
-                 VM_PROT_READ | VM_PROT_WRITE,
-                 VM_PROT_READ | VM_PROT_WRITE, VM_INHERIT_SHARE);
-    mach_port_deallocate(mach_task_self(), mem_obj);
-    if (err) {
-        errno = err;
-        FatalError("xf86MapVidMem() can't vm_map.(mem_obj) (%s)\n",
-                   strerror(errno));
-    }
-    mach_port_deallocate(mach_task_self(), mem_dev);
-    if (err) {
-        errno = err;
-        FatalError
-            ("xf86MapVidMem() can't mach_port_deallocate.(mem_dev) (%s)\n",
-             strerror(errno));
-    }
-    return (void *) addr;
-}
-
-static void
-unmapVidMem(int ScreenNum, void *Base, unsigned long Size)
-{
-    kern_return_t err = vm_deallocate(mach_task_self(), (int) Base, Size);
-
-    if (err) {
-        errno = err;
-        ErrorF("xf86UnMapVidMem: can't dealloc framebuffer space (%s)\n",
-               strerror(errno));
-    }
-    return;
-}
 
 /**************************************************************************
  * I/O Permissions section                                                 
@@ -147,7 +85,5 @@ void
 xf86OSInitVidMem(VidMemInfoPtr pVidMem)
 {
     pVidMem->linearSupported = TRUE;
-    pVidMem->mapMem = mapVidMem;
-    pVidMem->unmapMem = unmapVidMem;
     pVidMem->initialised = TRUE;
 }
diff --git a/hw/xfree86/os-support/linux/lnx_video.c b/hw/xfree86/os-support/linux/lnx_video.c
index ffffc81..7389d48 100644
--- a/hw/xfree86/os-support/linux/lnx_video.c
+++ b/hw/xfree86/os-support/linux/lnx_video.c
@@ -82,17 +82,12 @@ extern int iopl(int __level);
 /* Video Memory Mapping section                                            */
 /***************************************************************************/
 
-static void *mapVidMem(int, unsigned long, unsigned long, int);
-static void unmapVidMem(int, void *, unsigned long);
-
 #if defined (__alpha__)
 extern void sethae(unsigned long hae);
 extern unsigned long _bus_base __P((void)) __attribute__ ((const));
 extern unsigned long _bus_base_sparse __P((void)) __attribute__ ((const));
 
-static void *mapVidMemSparse(int, unsigned long, unsigned long, int);
 extern axpDevice lnxGetAXP(void);
-static void unmapVidMemSparse(int, void *, unsigned long);
 static axpDevice axpSystem = -1;
 static Bool needSparse;
 static unsigned long hae_thresh;
@@ -374,17 +369,10 @@ xf86OSInitVidMem(VidMemInfoPtr pVidMem)
     }
     if (needSparse) {
         xf86Msg(X_INFO, "Machine needs sparse mapping\n");
-        pVidMem->mapMem = mapVidMemSparse;
-        pVidMem->unmapMem = unmapVidMemSparse;
     }
     else {
         xf86Msg(X_INFO, "Machine type has 8/16 bit access\n");
-        pVidMem->mapMem = mapVidMem;
-        pVidMem->unmapMem = unmapVidMem;
     }
-#else
-    pVidMem->mapMem = mapVidMem;
-    pVidMem->unmapMem = unmapVidMem;
 #endif                          /* __alpha__ */
 
 #ifdef HAS_MTRR_SUPPORT
@@ -394,83 +382,6 @@ xf86OSInitVidMem(VidMemInfoPtr pVidMem)
     pVidMem->initialised = TRUE;
 }
 
-#ifdef __sparc__
-/* Basically, you simply cannot do this on Sparc.  You have to do something portable
- * like use /dev/fb* or mmap() on /proc/bus/pci/X/Y nodes. -DaveM
- */
-static void *
-mapVidMem(int ScreenNum, unsigned long Base, unsigned long Size, int flags)
-{
-    return NULL;
-}
-#else
-static void *
-mapVidMem(int ScreenNum, unsigned long Base, unsigned long Size, int flags)
-{
-    void *base;
-    int fd;
-    int mapflags = MAP_SHARED;
-    int prot;
-    memType realBase, alignOff;
-
-    realBase = Base & ~(getpagesize() - 1);
-    alignOff = Base - realBase;
-    DebugF("base: %lx, realBase: %lx, alignOff: %lx \n",
-           Base, realBase, alignOff);
-
-#if defined(__ia64__) || defined(__arm__) || defined(__s390__)
-#ifndef MAP_WRITECOMBINED
-#define MAP_WRITECOMBINED 0x00010000
-#endif
-#ifndef MAP_NONCACHED
-#define MAP_NONCACHED 0x00020000
-#endif
-    if (flags & VIDMEM_FRAMEBUFFER)
-        mapflags |= MAP_WRITECOMBINED;
-    else
-        mapflags |= MAP_NONCACHED;
-#endif
-
-#if 0
-    /* this will disappear when people upgrade their kernels */
-    fd = open(DEV_MEM,
-              ((flags & VIDMEM_READONLY) ? O_RDONLY : O_RDWR) | O_SYNC);
-#else
-    fd = open(DEV_MEM, (flags & VIDMEM_READONLY) ? O_RDONLY : O_RDWR);
-#endif
-    if (fd < 0) {
-        FatalError("xf86MapVidMem: failed to open " DEV_MEM " (%s)\n",
-                   strerror(errno));
-    }
-
-    if (flags & VIDMEM_READONLY)
-        prot = PROT_READ;
-    else
-        prot = PROT_READ | PROT_WRITE;
-
-    /* This requires linux-0.99.pl10 or above */
-    base = mmap((caddr_t) 0, Size + alignOff, prot, mapflags, fd,
-                (off_t) realBase + BUS_BASE);
-    close(fd);
-    if (base == MAP_FAILED) {
-        FatalError("xf86MapVidMem: Could not mmap framebuffer"
-                   " (0x%08lx,0x%lx) (%s)\n", Base, Size, strerror(errno));
-    }
-    DebugF("base: %lx aligned base: %lx\n", base, (char *) base + alignOff);
-    return (char *) base + alignOff;
-}
-#endif                          /* !(__sparc__) */
-
-static void
-unmapVidMem(int ScreenNum, void *Base, unsigned long Size)
-{
-    uintptr_t alignOff = (uintptr_t) Base
-        - ((uintptr_t) Base & ~(getpagesize() - 1));
-
-    DebugF("alignment offset: %lx\n", (unsigned long) alignOff);
-    munmap((void *) ((uintptr_t) Base - alignOff), (Size + alignOff));
-}
-
 /***************************************************************************/
 /* I/O Permissions section                                                 */
 /***************************************************************************/
@@ -565,8 +476,6 @@ xf86DisableIO(void)
 
 #if defined (__alpha__)
 
-#define vuip    volatile unsigned int *
-
 extern int readDense8(void *Base, register unsigned long Offset);
 extern int readDense16(void *Base, register unsigned long Offset);
 extern int readDense32(void *Base, register unsigned long Offset);
@@ -577,284 +486,6 @@ extern void
 extern void
  writeDense32(int Value, void *Base, register unsigned long Offset);
 
-static int readSparse8(void *Base, register unsigned long Offset);
-static int readSparse16(void *Base, register unsigned long Offset);
-static int readSparse32(void *Base, register unsigned long Offset);
-static void
- writeSparseNB8(int Value, void *Base, register unsigned long Offset);
-static void
- writeSparseNB16(int Value, void *Base, register unsigned long Offset);
-static void
- writeSparseNB32(int Value, void *Base, register unsigned long Offset);
-static void
- writeSparse8(int Value, void *Base, register unsigned long Offset);
-static void
- writeSparse16(int Value, void *Base, register unsigned long Offset);
-static void
- writeSparse32(int Value, void *Base, register unsigned long Offset);
-
-#define DENSE_BASE	0x2ff00000000UL
-#define SPARSE_BASE	0x30000000000UL
-
-static unsigned long msb_set = 0;
-
-static void *
-mapVidMemSparse(int ScreenNum, unsigned long Base, unsigned long Size,
-                int flags)
-{
-    int fd, prot;
-    unsigned long ret, rets = 0;
-
-    static Bool was_here = FALSE;
-
-    if (!was_here) {
-        was_here = TRUE;
-
-        xf86WriteMmio8 = writeSparse8;
-        xf86WriteMmio16 = writeSparse16;
-        xf86WriteMmio32 = writeSparse32;
-        xf86WriteMmioNB8 = writeSparseNB8;
-        xf86WriteMmioNB16 = writeSparseNB16;
-        xf86WriteMmioNB32 = writeSparseNB32;
-        xf86ReadMmio8 = readSparse8;
-        xf86ReadMmio16 = readSparse16;
-        xf86ReadMmio32 = readSparse32;
-    }
-
-    fd = open(DEV_MEM, (flags & VIDMEM_READONLY) ? O_RDONLY : O_RDWR);
-    if (fd < 0) {
-        FatalError("xf86MapVidMem: failed to open " DEV_MEM " (%s)\n",
-                   strerror(errno));
-    }
-
-#if 0
-    xf86Msg(X_INFO, "mapVidMemSparse: try Base 0x%lx size 0x%lx flags 0x%x\n",
-            Base, Size, flags);
-#endif
-
-    if (flags & VIDMEM_READONLY)
-        prot = PROT_READ;
-    else
-        prot = PROT_READ | PROT_WRITE;
-
-    /* This requirers linux-0.99.pl10 or above */
-
-    /*
-     * Always do DENSE mmap, since read32/write32 currently require it.
-     */
-    ret = (unsigned long) mmap((caddr_t) (DENSE_BASE + Base), Size,
-                               prot, MAP_SHARED, fd, (off_t) (bus_base + Base));
-
-    /*
-     * Do SPARSE mmap only when MMIO and not MMIO_32BIT, or FRAMEBUFFER
-     * and SPARSE (which should require the use of read/write macros).
-     *
-     * By not SPARSE mmapping an 8MB framebuffer, we can save approx. 256K
-     * bytes worth of pagetable (32 pages).
-     */
-    if (((flags & VIDMEM_MMIO) && !(flags & VIDMEM_MMIO_32BIT)) ||
-        ((flags & VIDMEM_FRAMEBUFFER) && (flags & VIDMEM_SPARSE))) {
-        rets = (unsigned long) mmap((caddr_t) (SPARSE_BASE + (Base << 5)),
-                                    Size << 5, prot, MAP_SHARED, fd,
-                                    (off_t) _bus_base_sparse() + (Base << 5));
-    }
-
-    close(fd);
-
-    if (ret == (unsigned long) MAP_FAILED) {
-        FatalError("xf86MapVidMemSparse: Could not (dense) mmap fb (%s)\n",
-                   strerror(errno));
-    }
-
-    if (((flags & VIDMEM_MMIO) && !(flags & VIDMEM_MMIO_32BIT)) ||
-        ((flags & VIDMEM_FRAMEBUFFER) && (flags & VIDMEM_SPARSE))) {
-        if (rets == (unsigned long) MAP_FAILED ||
-            rets != (SPARSE_BASE + (Base << 5))) {
-            FatalError("mapVidMemSparse: Could not (sparse) mmap fb (%s)\n",
-                       strerror(errno));
-        }
-    }
-
-#if 1
-    if (rets)
-        xf86Msg(X_INFO, "mapVidMemSparse: mapped Base 0x%lx size 0x%lx"
-                " to DENSE at 0x%lx and SPARSE at 0x%lx\n",
-                Base, Size, ret, rets);
-    else
-        xf86Msg(X_INFO, "mapVidMemSparse: mapped Base 0x%lx size 0x%lx"
-                " to DENSE only at 0x%lx\n", Base, Size, ret);
-
-#endif
-    return (void *) ret;
-}
-
-static void
-unmapVidMemSparse(int ScreenNum, void *Base, unsigned long Size)
-{
-    unsigned long Offset = (unsigned long) Base - DENSE_BASE;
-
-#if 1
-    xf86Msg(X_INFO, "unmapVidMemSparse: unmapping Base 0x%lx Size 0x%lx\n",
-            Base, Size);
-#endif
-    /* Unmap DENSE always. */
-    munmap((caddr_t) Base, Size);
-
-    /* Unmap SPARSE always, and ignore error in case we did not map it. */
-    munmap((caddr_t) (SPARSE_BASE + (Offset << 5)), Size << 5);
-}
-
-static int
-readSparse8(void *Base, register unsigned long Offset)
-{
-    register unsigned long result, shift;
-    register unsigned long msb;
-
-    mem_barrier();
-    Offset += (unsigned long) Base - DENSE_BASE;
-    shift = (Offset & 0x3) << 3;
-    if (Offset >= (hae_thresh)) {
-        msb = Offset & hae_mask;
-        Offset -= msb;
-        if (msb_set != msb) {
-            sethae(msb);
-            msb_set = msb;
-        }
-    }
-
-    mem_barrier();
-    result = *(vuip) (SPARSE_BASE + (Offset << 5));
-    result >>= shift;
-    return 0xffUL & result;
-}
-
-static int
-readSparse16(void *Base, register unsigned long Offset)
-{
-    register unsigned long result, shift;
-    register unsigned long msb;
-
-    mem_barrier();
-    Offset += (unsigned long) Base - DENSE_BASE;
-    shift = (Offset & 0x2) << 3;
-    if (Offset >= hae_thresh) {
-        msb = Offset & hae_mask;
-        Offset -= msb;
-        if (msb_set != msb) {
-            sethae(msb);
-            msb_set = msb;
-        }
-    }
-
-    mem_barrier();
-    result = *(vuip) (SPARSE_BASE + (Offset << 5) + (1 << (5 - 2)));
-    result >>= shift;
-    return 0xffffUL & result;
-}
-
-static int
-readSparse32(void *Base, register unsigned long Offset)
-{
-    /* NOTE: this is really using DENSE. */
-    mem_barrier();
-    return *(vuip) ((unsigned long) Base + (Offset));
-}
-
-static void
-writeSparse8(int Value, void *Base, register unsigned long Offset)
-{
-    register unsigned long msb;
-    register unsigned int b = Value & 0xffU;
-
-    write_mem_barrier();
-    Offset += (unsigned long) Base - DENSE_BASE;
-    if (Offset >= hae_thresh) {
-        msb = Offset & hae_mask;
-        Offset -= msb;
-        if (msb_set != msb) {
-            sethae(msb);
-            msb_set = msb;
-        }
-    }
-
-    write_mem_barrier();
-    *(vuip) (SPARSE_BASE + (Offset << 5)) = b * 0x01010101;
-}
-
-static void
-writeSparse16(int Value, void *Base, register unsigned long Offset)
-{
-    register unsigned long msb;
-    register unsigned int w = Value & 0xffffU;
-
-    write_mem_barrier();
-    Offset += (unsigned long) Base - DENSE_BASE;
-    if (Offset >= hae_thresh) {
-        msb = Offset & hae_mask;
-        Offset -= msb;
-        if (msb_set != msb) {
-            sethae(msb);
-            msb_set = msb;
-        }
-    }
-
-    write_mem_barrier();
-    *(vuip) (SPARSE_BASE + (Offset << 5) + (1 << (5 - 2))) = w * 0x00010001;
-}
-
-static void
-writeSparse32(int Value, void *Base, register unsigned long Offset)
-{
-    /* NOTE: this is really using DENSE. */
-    write_mem_barrier();
-    *(vuip) ((unsigned long) Base + (Offset)) = Value;
-    return;
-}
-
-static void
-writeSparseNB8(int Value, void *Base, register unsigned long Offset)
-{
-    register unsigned long msb;
-    register unsigned int b = Value & 0xffU;
-
-    Offset += (unsigned long) Base - DENSE_BASE;
-    if (Offset >= hae_thresh) {
-        msb = Offset & hae_mask;
-        Offset -= msb;
-        if (msb_set != msb) {
-            sethae(msb);
-            msb_set = msb;
-        }
-    }
-    *(vuip) (SPARSE_BASE + (Offset << 5)) = b * 0x01010101;
-}
-
-static void
-writeSparseNB16(int Value, void *Base, register unsigned long Offset)
-{
-    register unsigned long msb;
-    register unsigned int w = Value & 0xffffU;
-
-    Offset += (unsigned long) Base - DENSE_BASE;
-    if (Offset >= hae_thresh) {
-        msb = Offset & hae_mask;
-        Offset -= msb;
-        if (msb_set != msb) {
-            sethae(msb);
-            msb_set = msb;
-        }
-    }
-    *(vuip) (SPARSE_BASE + (Offset << 5) + (1 << (5 - 2))) = w * 0x00010001;
-}
-
-static void
-writeSparseNB32(int Value, void *Base, register unsigned long Offset)
-{
-    /* NOTE: this is really using DENSE. */
-    *(vuip) ((unsigned long) Base + (Offset)) = Value;
-    return;
-}
-
 void (*xf86WriteMmio8) (int Value, void *Base, unsigned long Offset)
     = writeDense8;
 void (*xf86WriteMmio16) (int Value, void *Base, unsigned long Offset)
diff --git a/hw/xfree86/os-support/shared/vidmem.c b/hw/xfree86/os-support/shared/vidmem.c
index f473293..1c695fe 100644
--- a/hw/xfree86/os-support/shared/vidmem.c
+++ b/hw/xfree86/os-support/shared/vidmem.c
@@ -50,14 +50,6 @@
  */
 
 typedef struct {
-    unsigned long size;
-    void *virtBase;
-    void *mtrrInfo;
-} MappingRec, *MappingPtr;
-
-typedef struct {
-    int numMappings;
-    MappingPtr *mappings;
     Bool mtrrEnabled;
     MessageType mtrrFrom;
     Bool mtrrOptChecked;
@@ -69,7 +61,7 @@ static int vidMapIndex = -1;
 #define VIDMAPPTR(p) ((VidMapPtr)((p)->privates[vidMapIndex].ptr))
 
 static VidMemInfo vidMemInfo = { FALSE, };
-static VidMapRec vidMapRec = { 0, NULL, TRUE, X_DEFAULT, FALSE, NULL };
+static VidMapRec vidMapRec = { TRUE, X_DEFAULT, FALSE, NULL };
 
 static VidMapPtr
 getVidMapRec(int scrnIndex)
@@ -94,45 +86,6 @@ getVidMapRec(int scrnIndex)
     return vp;
 }
 
-static MappingPtr
-newMapping(VidMapPtr vp)
-{
-    vp->mappings = xnfrealloc(vp->mappings, sizeof(MappingPtr) *
-                              (vp->numMappings + 1));
-    vp->mappings[vp->numMappings] = xnfcalloc(sizeof(MappingRec), 1);
-    return vp->mappings[vp->numMappings++];
-}
-
-static MappingPtr
-findMapping(VidMapPtr vp, void *vbase, unsigned long size)
-{
-    int i;
-
-    for (i = 0; i < vp->numMappings; i++) {
-        if (vp->mappings[i]->virtBase == vbase && vp->mappings[i]->size == size)
-            return vp->mappings[i];
-    }
-    return NULL;
-}
-
-static void
-removeMapping(VidMapPtr vp, MappingPtr mp)
-{
-    int i, found = 0;
-
-    for (i = 0; i < vp->numMappings; i++) {
-        if (vp->mappings[i] == mp) {
-            found = 1;
-            free(vp->mappings[i]);
-        }
-        else if (found) {
-            vp->mappings[i - 1] = vp->mappings[i];
-        }
-    }
-    vp->numMappings--;
-    vp->mappings[vp->numMappings] = NULL;
-}
-
 enum { OPTION_MTRR };
 
 static const OptionInfoRec opts[] = {
@@ -165,75 +118,6 @@ xf86InitVidMem(void)
     }
 }
 
-void *
-xf86MapVidMem(int ScreenNum, int Flags, unsigned long Base, unsigned long Size)
-{
-    void *vbase = NULL;
-    VidMapPtr vp;
-    MappingPtr mp;
-
-    if (((Flags & VIDMEM_FRAMEBUFFER) &&
-         (Flags & (VIDMEM_MMIO | VIDMEM_MMIO_32BIT))))
-        FatalError("Mapping memory with more than one type\n");
-
-    xf86InitVidMem();
-    if (!vidMemInfo.initialised || !vidMemInfo.mapMem)
-        return NULL;
-
-    vbase = vidMemInfo.mapMem(ScreenNum, Base, Size, Flags);
-
-    if (!vbase || vbase == (void *) -1)
-        return NULL;
-
-    vp = getVidMapRec(ScreenNum);
-    mp = newMapping(vp);
-    mp->size = Size;
-    mp->virtBase = vbase;
-
-    /*
-     * Check the "mtrr" option even when MTRR isn't supported to avoid
-     * warnings about unrecognised options.
-     */
-    checkMtrrOption(vp);
-
-    if (vp->mtrrEnabled && vidMemInfo.setWC) {
-        if (Flags & (VIDMEM_MMIO | VIDMEM_MMIO_32BIT))
-            mp->mtrrInfo =
-                vidMemInfo.setWC(ScreenNum, Base, Size, FALSE, vp->mtrrFrom);
-        else if (Flags & VIDMEM_FRAMEBUFFER)
-            mp->mtrrInfo =
-                vidMemInfo.setWC(ScreenNum, Base, Size, TRUE, vp->mtrrFrom);
-    }
-    return vbase;
-}
-
-void
-xf86UnMapVidMem(int ScreenNum, void *Base, unsigned long Size)
-{
-    VidMapPtr vp;
-    MappingPtr mp;
-
-    if (!vidMemInfo.initialised || !vidMemInfo.unmapMem) {
-        xf86DrvMsg(ScreenNum, X_WARNING,
-                   "xf86UnMapVidMem() called before xf86MapVidMem()\n");
-        return;
-    }
-
-    vp = getVidMapRec(ScreenNum);
-    mp = findMapping(vp, Base, Size);
-    if (!mp) {
-        xf86DrvMsg(ScreenNum, X_WARNING,
-                   "xf86UnMapVidMem: cannot find region for [%p,0x%lx]\n",
-                   Base, Size);
-        return;
-    }
-    if (vp->mtrrEnabled && vidMemInfo.undoWC && mp)
-        vidMemInfo.undoWC(ScreenNum, mp->mtrrInfo);
-
-    vidMemInfo.unmapMem(ScreenNum, Base, Size);
-    removeMapping(vp, mp);
-}
-
 Bool
 xf86CheckMTRR(int ScreenNum)
 {
diff --git a/hw/xfree86/os-support/solaris/sun_vid.c b/hw/xfree86/os-support/solaris/sun_vid.c
index fc46487..1526ae7 100644
--- a/hw/xfree86/os-support/solaris/sun_vid.c
+++ b/hw/xfree86/os-support/solaris/sun_vid.c
@@ -107,62 +107,11 @@ solOpenAperture(void)
     return TRUE;
 }
 
-static void *
-solMapVidMem(int ScreenNum, unsigned long Base, unsigned long Size, int Flags)
-{
-    void *base;
-    int fd;
-    int prot;
-
-    if (Flags & VIDMEM_READONLY) {
-        fd = apertureDevFD_ro;
-        prot = PROT_READ;
-    }
-    else {
-        fd = apertureDevFD_rw;
-        prot = PROT_READ | PROT_WRITE;
-    }
-
-    if (fd < 0) {
-        xf86DrvMsg(ScreenNum, X_ERROR,
-                   "solMapVidMem: failed to open %s (%s)\n",
-                   apertureDevName, strerror(errno));
-        return NULL;
-    }
-
-    base = mmap(NULL, Size, prot, MAP_SHARED, fd, (off_t) Base);
-
-    if (base == MAP_FAILED) {
-        xf86DrvMsg(ScreenNum, X_ERROR,
-                   "solMapVidMem: failed to mmap %s (0x%08lx,0x%lx) (%s)\n",
-                   apertureDevName, Base, Size, strerror(errno));
-        return NULL;
-    }
-
-    return base;
-}
-
-/* ARGSUSED */
-static void
-solUnMapVidMem(int ScreenNum, void *Base, unsigned long Size)
-{
-    if (munmap(Base, Size) != 0) {
-        xf86DrvMsgVerb(ScreenNum, X_WARNING, 0,
-                       "solUnMapVidMem: failed to unmap %s"
-                       " (0x%p,0x%lx) (%s)\n",
-                       apertureDevName, Base, Size, strerror(errno));
-    }
-}
-
 _X_HIDDEN void
 xf86OSInitVidMem(VidMemInfoPtr pVidMem)
 {
     pVidMem->linearSupported = solOpenAperture();
-    if (pVidMem->linearSupported) {
-        pVidMem->mapMem = solMapVidMem;
-        pVidMem->unmapMem = solUnMapVidMem;
-    }
-    else {
+    if (!pVidMem->linearSupported) {
         xf86MsgVerb(X_WARNING, 0,
                     "xf86OSInitVidMem: linear memory access disabled\n");
     }
diff --git a/hw/xfree86/os-support/xf86OSpriv.h b/hw/xfree86/os-support/xf86OSpriv.h
index b56f45a..c586c7a 100644
--- a/hw/xfree86/os-support/xf86OSpriv.h
+++ b/hw/xfree86/os-support/xf86OSpriv.h
@@ -32,16 +32,12 @@
 #ifndef _XF86OSPRIV_H
 #define _XF86OSPRIV_H
 
-typedef void *(*MapMemProcPtr) (int, unsigned long, unsigned long, int);
-typedef void (*UnmapMemProcPtr) (int, void *, unsigned long);
 typedef void *(*SetWCProcPtr) (int, unsigned long, unsigned long, Bool,
                                  MessageType);
 typedef void (*UndoWCProcPtr) (int, void *);
 
 typedef struct {
     Bool initialised;
-    MapMemProcPtr mapMem;
-    UnmapMemProcPtr unmapMem;
     SetWCProcPtr setWC;
     UndoWCProcPtr undoWC;
     Bool linearSupported;
diff --git a/hw/xfree86/os-support/xf86_OSproc.h b/hw/xfree86/os-support/xf86_OSproc.h
index 8d27e8b..747803c 100644
--- a/hw/xfree86/os-support/xf86_OSproc.h
+++ b/hw/xfree86/os-support/xf86_OSproc.h
@@ -74,24 +74,6 @@
  */
 
 /*
- * Flags for xf86MapVidMem().  Multiple flags can be or'd together.  The
- * flags may be used as hints.  For example it would be permissible to
- * enable write combining for memory marked only for framebuffer use.
- */
-
-#define VIDMEM_FRAMEBUFFER	0x01    /* memory for framebuffer use */
-#define VIDMEM_MMIO		0x02    /* memory for I/O use */
-#define VIDMEM_MMIO_32BIT	0x04    /* memory accesses >= 32bit */
-#define VIDMEM_READSIDEEFFECT	0x08    /* reads can have side-effects */
-#define VIDMEM_SPARSE		0x10    /* sparse mapping required
-                                         * assumed when VIDMEM_MMIO is
-                                         * set. May be used with
-                                         * VIDMEM_FRAMEBUFFER) */
-#define VIDMEM_READONLY		0x20    /* read-only mapping
-                                         * used when reading BIOS images
-                                         * through xf86MapVidMem() */
-
-/*
  * OS-independent modem state flags for xf86SetSerialModemState() and
  * xf86GetSerialModemState().
  */
@@ -132,10 +114,6 @@ _XFUNCPROTOBEGIN
 /* public functions */
 extern _X_EXPORT Bool xf86LinearVidMem(void);
 extern _X_EXPORT _X_DEPRECATED Bool xf86CheckMTRR(int);
-extern _X_EXPORT _X_DEPRECATED void *xf86MapVidMem(int, int, unsigned long,
-                                                     unsigned long);
-extern _X_EXPORT _X_DEPRECATED void xf86UnMapVidMem(int, void *,
-                                                    unsigned long);
 extern _X_EXPORT int xf86ReadBIOS(unsigned long, unsigned long, unsigned char *,
                                   int);
 extern _X_EXPORT Bool xf86EnableIO(void);
commit 6d6aa8ab6b6d62d65f1354b4cd9af0bf4f2e81d7
Author: Eric Anholt <eric at anholt.net>
Date:   Tue Aug 26 11:43:54 2014 -0700

    modesetting: Update for the platform device API change.
    
    Signed-off-by: Eric Anholt <eric at anholt.net>
    Reviewed-by: Keith Packard <keithp at keithp.com>

diff --git a/hw/xfree86/drivers/modesetting/driver.c b/hw/xfree86/drivers/modesetting/driver.c
index 5158c46..eaa3a0f 100644
--- a/hw/xfree86/drivers/modesetting/driver.c
+++ b/hw/xfree86/drivers/modesetting/driver.c
@@ -219,7 +219,7 @@ static Bool probe_hw(const char *dev, struct xf86_platform_device *platform_dev)
 
 #if XF86_PDEV_SERVER_FD
     if (platform_dev && (platform_dev->flags & XF86_PDEV_SERVER_FD)) {
-        fd = xf86_get_platform_device_int_attrib(platform_dev, ODEV_ATTRIB_FD, -1);
+        fd = xf86_platform_device_odev_attributes(platform_dev)->fd;
         if (fd == -1)
             return FALSE;
         return check_outputs(fd);
@@ -350,7 +350,7 @@ ms_platform_probe(DriverPtr driver,
               int entity_num, int flags, struct xf86_platform_device *dev, intptr_t match_data)
 {
     ScrnInfoPtr scrn = NULL;
-    const char *path = xf86_get_platform_device_attrib(dev, ODEV_ATTRIB_PATH);
+    const char *path = xf86_platform_device_odev_attributes(dev)->path;
     int scr_flags = 0;
 
     if (flags & PLATFORM_PROBE_GPU_SCREEN)
@@ -646,11 +646,11 @@ PreInit(ScrnInfoPtr pScrn, int flags)
     if (pEnt->location.type == BUS_PLATFORM) {
 #ifdef XF86_PDEV_SERVER_FD
         if (pEnt->location.id.plat->flags & XF86_PDEV_SERVER_FD)
-            ms->fd = xf86_get_platform_device_int_attrib(pEnt->location.id.plat, ODEV_ATTRIB_FD, -1);
+            ms->fd = xf86_platform_device_odev_attributes(pEnt->location.id.plat)->fd;
         else
 #endif
         {
-            char *path = xf86_get_platform_device_attrib(pEnt->location.id.plat, ODEV_ATTRIB_PATH);
+            char *path = xf86_platform_device_odev_attributes(pEnt->location.id.plat)->path;
             ms->fd = open_hw(path);
         }
     }
commit 9c080f44960d2338c7a59eee132a02d45186bfb0
Author: Eric Anholt <eric at anholt.net>
Date:   Tue Aug 26 11:41:46 2014 -0700

    modesetting: Drop use of "pointer" for "void *"
    
    The xserver doesn't have that typedef.
    
    Signed-off-by: Eric Anholt <eric at anholt.net>
    Reviewed-by: Keith Packard <keithp at keithp.com>

diff --git a/hw/xfree86/drivers/modesetting/compat-api.h b/hw/xfree86/drivers/modesetting/compat-api.h
index df783a8..bd7decc 100644
--- a/hw/xfree86/drivers/modesetting/compat-api.h
+++ b/hw/xfree86/drivers/modesetting/compat-api.h
@@ -48,7 +48,7 @@
 
 #define SCREEN_INIT_ARGS_DECL int i, ScreenPtr pScreen, int argc, char **argv
 
-#define BLOCKHANDLER_ARGS_DECL int arg, pointer blockData, pointer pTimeout, pointer pReadmask
+#define BLOCKHANDLER_ARGS_DECL int arg, void * blockData, void * pTimeout, void * pReadmask
 #define BLOCKHANDLER_ARGS arg, blockData, pTimeout, pReadmask
 
 #define CLOSE_SCREEN_ARGS_DECL int scrnIndex, ScreenPtr pScreen
@@ -73,7 +73,7 @@
 
 #define SCREEN_INIT_ARGS_DECL ScreenPtr pScreen, int argc, char **argv
 
-#define BLOCKHANDLER_ARGS_DECL ScreenPtr arg, pointer pTimeout, pointer pReadmask
+#define BLOCKHANDLER_ARGS_DECL ScreenPtr arg, void * pTimeout, void * pReadmask
 #define BLOCKHANDLER_ARGS arg, pTimeout, pReadmask
 
 #define CLOSE_SCREEN_ARGS_DECL ScreenPtr pScreen
diff --git a/hw/xfree86/drivers/modesetting/driver.c b/hw/xfree86/drivers/modesetting/driver.c
index 44abdb3..5158c46 100644
--- a/hw/xfree86/drivers/modesetting/driver.c
+++ b/hw/xfree86/drivers/modesetting/driver.c
@@ -153,8 +153,8 @@ static XF86ModuleVersionInfo VersRec = {
 
 _X_EXPORT XF86ModuleData modesettingModuleData = { &VersRec, Setup, NULL };
 
-static pointer
-Setup(pointer module, pointer opts, int *errmaj, int *errmin)
+static void *
+Setup(void * module, void * opts, int *errmaj, int *errmin)
 {
     static Bool setupDone = 0;
 
@@ -168,7 +168,7 @@ Setup(pointer module, pointer opts, int *errmaj, int *errmin)
 	 * The return value must be non-NULL on success even though there
 	 * is no TearDownProc.
 	 */
-	return (pointer) 1;
+	return (void *) 1;
     } else {
 	if (errmaj)
 	    *errmaj = LDR_ONCEONLY;
commit a10ea01475c6d0795b1a00cfd8be9912f4b54235
Author: Eric Anholt <eric at anholt.net>
Date:   Tue Aug 26 11:24:31 2014 -0700

    modesetting: xserver already checks XEXTPROTO >= 7.2.99.901.
    
    Signed-off-by: Eric Anholt <eric at anholt.net>
    Reviewed-by: Keith Packard <keithp at keithp.com>

diff --git a/hw/xfree86/drivers/modesetting/drmmode_display.c b/hw/xfree86/drivers/modesetting/drmmode_display.c
index 6964e93..31c39a2 100644
--- a/hw/xfree86/drivers/modesetting/drmmode_display.c
+++ b/hw/xfree86/drivers/modesetting/drmmode_display.c
@@ -45,13 +45,7 @@
 
 #include <cursorstr.h>
 
-/* DPMS */
-#ifdef HAVE_XEXTPROTO_71
 #include <X11/extensions/dpmsconst.h>
-#else
-#define DPMS_SERVER
-#include <X11/extensions/dpms.h>
-#endif
 #include "compat-api.h"
 
 #include "driver.h"
commit c7e8d4a6ee9542f56cd241cf7a960fb8223a6b22
Author: Eric Anholt <eric at anholt.net>
Date:   Tue Aug 26 11:21:24 2014 -0700

    modesetting: unifdef MODESETTING_OUTPUT_SLAVE_SUPPORT
    
    The server will always have it.
    
    v2: Clean up some weird formatting from the unifdeffing.
    
    Signed-off-by: Eric Anholt <eric at anholt.net>
    Reviewed-by: Keith Packard <keithp at keithp.com>

diff --git a/hw/xfree86/drivers/modesetting/driver.c b/hw/xfree86/drivers/modesetting/driver.c
index d99b027..44abdb3 100644
--- a/hw/xfree86/drivers/modesetting/driver.c
+++ b/hw/xfree86/drivers/modesetting/driver.c
@@ -501,7 +501,6 @@ static void dispatch_dirty(ScreenPtr pScreen)
     }
 }
 
-#ifdef MODESETTING_OUTPUT_SLAVE_SUPPORT
 static void dispatch_dirty_crtc(ScrnInfoPtr scrn, xf86CrtcPtr crtc)
 {
     modesettingPtr ms = modesettingPTR(scrn);
@@ -535,7 +534,6 @@ static void dispatch_slave_dirty(ScreenPtr pScreen)
 	dispatch_dirty_crtc(scrn, crtc);
     }
 }
-#endif
 
 static void msBlockHandler(BLOCKHANDLER_ARGS_DECL)
 {
@@ -545,12 +543,9 @@ static void msBlockHandler(BLOCKHANDLER_ARGS_DECL)
     pScreen->BlockHandler = ms->BlockHandler;
     pScreen->BlockHandler(BLOCKHANDLER_ARGS);
     pScreen->BlockHandler = msBlockHandler;
-#ifdef MODESETTING_OUTPUT_SLAVE_SUPPORT
     if (pScreen->isGPU)
         dispatch_slave_dirty(pScreen);
-    else
-#endif
-    if (ms->dirty_enabled)
+    else if (ms->dirty_enabled)
         dispatch_dirty(pScreen);
 }
 
@@ -686,7 +681,6 @@ PreInit(ScrnInfoPtr pScrn, int flags)
 
     ms->drmmode.fd = ms->fd;
 
-#ifdef MODESETTING_OUTPUT_SLAVE_SUPPORT
     pScrn->capabilities = 0;
 #ifdef DRM_CAP_PRIME
     ret = drmGetCap(ms->fd, DRM_CAP_PRIME, &value);
@@ -695,7 +689,6 @@ PreInit(ScrnInfoPtr pScrn, int flags)
             pScrn->capabilities |= RR_Capability_SinkOutput;
     }
 #endif
-#endif
     drmmode_get_default_bpp(pScrn, &ms->drmmode, &defaultdepth, &defaultbpp);
     if (defaultdepth == 24 && defaultbpp == 24)
 	    bppflags = SupportConvert32to24 | Support24bppFb;
@@ -877,7 +870,6 @@ msShadowInit(ScreenPtr pScreen)
     return TRUE;
 }
 
-#ifdef MODESETTING_OUTPUT_SLAVE_SUPPORT
 static Bool
 msSetSharedPixmapBacking(PixmapPtr ppix, void *fd_handle)
 {
@@ -894,7 +886,6 @@ msSetSharedPixmapBacking(PixmapPtr ppix, void *fd_handle)
 
     return TRUE;
 }
-#endif
 
 static Bool
 SetMaster(ScrnInfoPtr pScrn)
@@ -950,12 +941,10 @@ ScreenInit(SCREEN_INIT_ARGS_DECL)
     if (!miSetPixmapDepths())
 	return FALSE;
 
-#ifdef MODESETTING_OUTPUT_SLAVE_SUPPORT
     if (!dixRegisterScreenSpecificPrivateKey(pScreen, &ms->drmmode.pixmapPrivateKeyRec,
         PRIVATE_PIXMAP, sizeof(msPixmapPrivRec))) { 
 	return FALSE;
     }
-#endif
 
     pScrn->memPhysBase = 0;
     pScrn->fbOffset = 0;
@@ -1015,9 +1004,7 @@ ScreenInit(SCREEN_INIT_ARGS_DECL)
     ms->BlockHandler = pScreen->BlockHandler;
     pScreen->BlockHandler = msBlockHandler;
 
-#ifdef MODESETTING_OUTPUT_SLAVE_SUPPORT
     pScreen->SetSharedPixmapBacking = msSetSharedPixmapBacking;
-#endif
 
     if (!xf86CrtcScreenInit(pScreen))
 	return FALSE;
diff --git a/hw/xfree86/drivers/modesetting/drmmode_display.c b/hw/xfree86/drivers/modesetting/drmmode_display.c
index c533324..6964e93 100644
--- a/hw/xfree86/drivers/modesetting/drmmode_display.c
+++ b/hw/xfree86/drivers/modesetting/drmmode_display.c
@@ -142,7 +142,6 @@ static int dumb_bo_destroy(int fd, struct dumb_bo *bo)
 	return 0;
 }
 
-#ifdef MODESETTING_OUTPUT_SLAVE_SUPPORT
 static struct dumb_bo *dumb_get_bo_from_handle(int fd, int handle, int pitch, int size)
 {
   	struct dumb_bo *bo;
@@ -161,9 +160,7 @@ static struct dumb_bo *dumb_get_bo_from_handle(int fd, int handle, int pitch, in
 	bo->size = size;
 	return bo;
 }
-#endif
 
-#ifdef MODESETTING_OUTPUT_SLAVE_SUPPORT
 Bool drmmode_SetSlaveBO(PixmapPtr ppix,
 			drmmode_ptr drmmode, 
 			int fd_handle, int pitch, int size)
@@ -177,7 +174,6 @@ Bool drmmode_SetSlaveBO(PixmapPtr ppix,
 	close(fd_handle);
 	return TRUE;
 }
-#endif
 
 static void
 drmmode_ConvertFromKMode(ScrnInfoPtr	scrn,
@@ -379,14 +375,11 @@ drmmode_set_mode_major(xf86CrtcPtr crtc, DisplayModePtr mode,
 		drmmode_ConvertToKMode(crtc->scrn, &kmode, mode);
 
 		fb_id = drmmode->fb_id;
-#ifdef MODESETTING_OUTPUT_SLAVE_SUPPORT
 		if (crtc->randr_crtc->scanout_pixmap) {
     			msPixmapPrivPtr ppriv = msGetPixmapPriv(drmmode, crtc->randr_crtc->scanout_pixmap);
 			fb_id = ppriv->fb_id;
 			x = y = 0;
-		} else 
-#endif
-		if (drmmode_crtc->rotate_fb_id) {
+		} else if (drmmode_crtc->rotate_fb_id) {
 			fb_id = drmmode_crtc->rotate_fb_id;
 			x = y = 0;
 		}
@@ -521,7 +514,6 @@ drmmode_crtc_gamma_set(xf86CrtcPtr crtc, uint16_t *red, uint16_t *green,
 			    size, red, green, blue);
 }
 
-#ifdef MODESETTING_OUTPUT_SLAVE_SUPPORT
 static Bool
 drmmode_set_scanout_pixmap(xf86CrtcPtr crtc, PixmapPtr ppix)
 {
@@ -566,7 +558,6 @@ drmmode_set_scanout_pixmap(xf86CrtcPtr crtc, PixmapPtr ppix)
 	}
 	return TRUE;
 }
-#endif
 
 static void *drmmode_shadow_allocate(xf86CrtcPtr crtc, int width, int height)
 {
@@ -590,9 +581,7 @@ static const xf86CrtcFuncsRec drmmode_crtc_funcs = {
 
     .gamma_set = drmmode_crtc_gamma_set,
     .destroy = NULL, /* XXX */
-#ifdef MODESETTING_OUTPUT_SLAVE_SUPPORT
     .set_scanout_pixmap = drmmode_set_scanout_pixmap,
-#endif
     .shadow_allocate = drmmode_shadow_allocate,
     .shadow_create = drmmode_shadow_create,
 };
@@ -1032,10 +1021,8 @@ drmmode_output_init(ScrnInfoPtr pScrn, drmmode_ptr drmmode, int num, int *num_dv
 	/* need to do smart conversion here for compat with non-kms ATI driver */
 	if (koutput->connector_type >= MS_ARRAY_SIZE(output_names))
 		snprintf(name, 32, "Unknown-%d", koutput->connector_type_id - 1);
-#ifdef MODESETTING_OUTPUT_SLAVE_SUPPORT
 	else if (pScrn->is_gpu)
 		snprintf(name, 32, "%s-%d-%d", output_names[koutput->connector_type], pScrn->scrnIndex - GPU_SCREEN_OFFSET + 1, koutput->connector_type_id - 1);
-#endif
 	else
 		snprintf(name, 32, "%s-%d", output_names[koutput->connector_type], koutput->connector_type_id - 1);
 
@@ -1549,7 +1536,6 @@ void *drmmode_map_front_bo(drmmode_ptr drmmode)
 	
 }
 
-#ifdef MODESETTING_OUTPUT_SLAVE_SUPPORT
 void *drmmode_map_slave_bo(drmmode_ptr drmmode, msPixmapPrivPtr ppriv)
 {
         int ret;
@@ -1563,7 +1549,6 @@ void *drmmode_map_slave_bo(drmmode_ptr drmmode, msPixmapPrivPtr ppriv)
 
         return ppriv->backing_bo->ptr;  
 }
-#endif
 
 Bool drmmode_map_cursor_bos(ScrnInfoPtr pScrn, drmmode_ptr drmmode)
 {
diff --git a/hw/xfree86/drivers/modesetting/drmmode_display.h b/hw/xfree86/drivers/modesetting/drmmode_display.h
index 745c484..1954abf 100644
--- a/hw/xfree86/drivers/modesetting/drmmode_display.h
+++ b/hw/xfree86/drivers/modesetting/drmmode_display.h
@@ -32,11 +32,6 @@
 #include "libudev.h"
 #endif
 
-/* the perfect storm */
-#if XF86_CRTC_VERSION >= 5 && defined(HAVE_DRMPRIMEFDTOHANDLE) && HAVE_SCREEN_SPECIFIC_PRIVATE_KEYS
-#define MODESETTING_OUTPUT_SLAVE_SUPPORT 1
-#endif
-
 #if XORG_VERSION_CURRENT >= XORG_VERSION_NUMERIC(1,14,99,2,0)
 #define DamageUnregister(d, dd) DamageUnregister(dd)
 #endif
@@ -103,7 +98,6 @@ typedef struct {
     int enc_clone_mask;
 } drmmode_output_private_rec, *drmmode_output_private_ptr;
 
-#ifdef MODESETTING_OUTPUT_SLAVE_SUPPORT
 typedef struct _msPixmapPriv {
     uint32_t fb_id;
     struct dumb_bo *backing_bo; /* if this pixmap is backed by a dumb bo */
@@ -119,7 +113,6 @@ void *drmmode_map_slave_bo(drmmode_ptr drmmode, msPixmapPrivPtr ppriv);
 Bool drmmode_SetSlaveBO(PixmapPtr ppix,
 			drmmode_ptr drmmode,
 			int fd_handle, int pitch, int size);
-#endif
 
 extern Bool drmmode_pre_init(ScrnInfoPtr pScrn, drmmode_ptr drmmode, int cpp);
 void drmmode_adjust_frame(ScrnInfoPtr pScrn, drmmode_ptr drmmode, int x, int y);
commit 0c07bfb38e61a8a6ad511dc8827e2dd20d68665d
Author: Eric Anholt <eric at anholt.net>
Date:   Mon Aug 25 15:42:45 2014 -0700

    modesetting: Merge modesetting's COPYING into the xserver's.
    
    Signed-off-by: Eric Anholt <eric at anholt.net>
    Reviewed-by: Keith Packard <keithp at keithp.com>

diff --git a/COPYING b/COPYING
index cc52a32..abf13c2 100644
--- a/COPYING
+++ b/COPYING
@@ -8,6 +8,7 @@ possible, and insert their name to this list.  Please sort by surname
 for people, and by the full name for other entities (e.g.  Juliusz
 Chroboczek sorts before Intel Corporation sorts before Daniel Stone).
 
+Copyright © 2011 Dave Airlie
 Copyright © 2000-2001 Juliusz Chroboczek
 Copyright © 1998 Egbert Eich
 Copyright © 2006-2007 Intel Corporation
@@ -145,6 +146,29 @@ used in advertising or otherwise to promote the sale, use or other dealings
 in this Software without prior written authorization from the X Consortium.
 
 
+Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas.
+
+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 TUNGSTEN GRAPHICS 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.
+
+
 Copyright © 1999-2000 SuSE, Inc.
 Copyright © 2007 Red Hat, Inc.
 
diff --git a/hw/xfree86/drivers/modesetting/COPYING b/hw/xfree86/drivers/modesetting/COPYING
deleted file mode 100644
index 9508e25..0000000
--- a/hw/xfree86/drivers/modesetting/COPYING
+++ /dev/null
@@ -1,44 +0,0 @@
-Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas.
-Copyright 2011 Dave Airlie
-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 TUNGSTEN GRAPHICS 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.
-
-Copyright © 2007 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.
commit 1d6334dd0ca99923b6b55c5c047ef6b5c325f66c
Author: Jon TURNEY <jon.turney at dronecode.org.uk>
Date:   Wed Jun 19 13:09:35 2013 +0100

    hw/xwin: Undefine _XSERVER64 in hw/xwin/winclipboard
    
    Including any server header might define the macro _XSERVER64 on 64 bit
    machines. That macro must _NOT_ be defined for Xlib client code, otherwise bad
    things happen. So let's undef that macro if necessary.
    
    Remove server directories from include path to ensure no server includes are
    included
    
    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/winclipboard/Makefile.am b/hw/xwin/winclipboard/Makefile.am
index 614e7ec..b1c95f4 100644
--- a/hw/xwin/winclipboard/Makefile.am
+++ b/hw/xwin/winclipboard/Makefile.am
@@ -9,8 +9,7 @@ libXWinclipboard_la_SOURCES = \
 
 libXWinclipboard_la_CFLAGS = -DHAVE_XWIN_CONFIG_H \
 			     $(DIX_CFLAGS) \
-			     $(XWINMODULES_CFLAGS) \
-		             -I$(top_srcdir) -I$(top_srcdir)/miext/rootless -I$(srcdir)/..
+			     $(XWINMODULES_CFLAGS)
 
 libXWinclipboard_la_LDFLAGS = -static -no-undefined
 
diff --git a/hw/xwin/winclipboard/textconv.c b/hw/xwin/winclipboard/textconv.c
index 4262d98..9c9cb35 100644
--- a/hw/xwin/winclipboard/textconv.c
+++ b/hw/xwin/winclipboard/textconv.c
@@ -31,6 +31,16 @@
 #ifdef HAVE_XWIN_CONFIG_H
 #include <xwin-config.h>
 #endif
+
+/*
+ * Including any server header might define the macro _XSERVER64 on 64 bit machines.
+ * That macro must _NOT_ be defined for Xlib client code, otherwise bad things happen.
+ * So let's undef that macro if necessary.
+ */
+#ifdef _XSERVER64
+#undef _XSERVER64
+#endif
+
 #include <stdlib.h>
 #include "internal.h"
 
diff --git a/hw/xwin/winclipboard/thread.c b/hw/xwin/winclipboard/thread.c
index a124e3e..c179e3f 100644
--- a/hw/xwin/winclipboard/thread.c
+++ b/hw/xwin/winclipboard/thread.c
@@ -36,6 +36,15 @@
 #define HAS_WINSOCK 1
 #endif
 
+/*
+ * Including any server header might define the macro _XSERVER64 on 64 bit machines.
+ * That macro must _NOT_ be defined for Xlib client code, otherwise bad things happen.
+ * So let's undef that macro if necessary.
+ */
+#ifdef _XSERVER64
+#undef _XSERVER64
+#endif
+
 #include <assert.h>
 #include <unistd.h>
 #include <fcntl.h>
diff --git a/hw/xwin/winclipboard/wndproc.c b/hw/xwin/winclipboard/wndproc.c
index 973f948..165ff55 100644
--- a/hw/xwin/winclipboard/wndproc.c
+++ b/hw/xwin/winclipboard/wndproc.c
@@ -34,6 +34,15 @@
 #include <xwin-config.h>
 #endif
 
+/*
+ * Including any server header might define the macro _XSERVER64 on 64 bit machines.
+ * That macro must _NOT_ be defined for Xlib client code, otherwise bad things happen.
+ * So let's undef that macro if necessary.
+ */
+#ifdef _XSERVER64
+#undef _XSERVER64
+#endif
+
 #include <sys/types.h>
 #include <sys/time.h>
 
diff --git a/hw/xwin/winclipboard/xevents.c b/hw/xwin/winclipboard/xevents.c
index 8a75bc4..d0077b8 100644
--- a/hw/xwin/winclipboard/xevents.c
+++ b/hw/xwin/winclipboard/xevents.c
@@ -34,6 +34,15 @@
 #include <xwin-config.h>
 #endif
 
+/*
+ * Including any server header might define the macro _XSERVER64 on 64 bit machines.
+ * That macro must _NOT_ be defined for Xlib client code, otherwise bad things happen.
+ * So let's undef that macro if necessary.
+ */
+#ifdef _XSERVER64
+#undef _XSERVER64
+#endif
+
 #include "internal.h"
 #include <X11/Xutil.h>
 #include <X11/Xatom.h>
diff --git a/hw/xwin/winclipboard/xwinclip.c b/hw/xwin/winclipboard/xwinclip.c
index 7b45770..3677974 100644
--- a/hw/xwin/winclipboard/xwinclip.c
+++ b/hw/xwin/winclipboard/xwinclip.c
@@ -35,6 +35,15 @@
 #include <xwin-config.h>
 #endif
 
+/*
+ * Including any server header might define the macro _XSERVER64 on 64 bit machines.
+ * That macro must _NOT_ be defined for Xlib client code, otherwise bad things happen.
+ * So let's undef that macro if necessary.
+ */
+#ifdef _XSERVER64
+#undef _XSERVER64
+#endif
+
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
commit 7ca93301940647219dbed2d14fcd3f37e49fb477
Author: Jon TURNEY <jon.turney at dronecode.org.uk>
Date:   Tue Jun 18 19:53:52 2013 +0100

    hw/xwin: Only add to XSetIOErrorHandler() handler chain once
    
    Only use XSetIOErrorHandler() to add to the global XSetIOErrorHandler() chain
    once.  If we do it every restart, then we make a loop in the handler chain, and
    we end up with a thread spinning in that loop when the server shuts down...
    
    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/winclipboard/thread.c b/hw/xwin/winclipboard/thread.c
index 31986f6..a124e3e 100644
--- a/hw/xwin/winclipboard/thread.c
+++ b/hw/xwin/winclipboard/thread.c
@@ -113,6 +113,7 @@ winClipboardProc(Bool fUseUnicode, char *szDisplay)
     Window iWindow = None;
     int iSelectError;
     Bool fShutdown = FALSE;
+    static Bool fErrorHandlerSet = FALSE;
 
     winDebug("winClipboardProc - Hello\n");
 
@@ -127,11 +128,15 @@ winClipboardProc(Bool fUseUnicode, char *szDisplay)
         ErrorF("winClipboardProc - Warning: Locale not supported by X.\n");
     }
 
-    /* Set error handler */
-    XSetErrorHandler(winClipboardErrorHandler);
     g_winClipboardProcThread = pthread_self();
-    g_winClipboardOldIOErrorHandler =
-        XSetIOErrorHandler(winClipboardIOErrorHandler);
+
+    /* Set error handler */
+    if (!fErrorHandlerSet) {
+      XSetErrorHandler(winClipboardErrorHandler);
+      g_winClipboardOldIOErrorHandler =
+         XSetIOErrorHandler(winClipboardIOErrorHandler);
+      fErrorHandlerSet = TRUE;
+    }
 
     /* Set jump point for Error exits */
     if (setjmp(g_jmpEntry)) {
commit 5819a02d461349dbfc86317c742406d2217f7f0c
Author: Jon TURNEY <jon.turney at dronecode.org.uk>
Date:   Tue Jun 18 19:35:20 2013 +0100

    hw/xwin: Add a basic manpage for xwinclip
    
    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/winclipboard/Makefile.am b/hw/xwin/winclipboard/Makefile.am
index b52e0e7..614e7ec 100644
--- a/hw/xwin/winclipboard/Makefile.am
+++ b/hw/xwin/winclipboard/Makefile.am
@@ -21,3 +21,6 @@ xwinclip_SOURCES = xwinclip.c debug.c
 xwinclip_CFLAGS = $(XWINMODULES_CFLAGS)
 
 xwinclip_LDADD = libXWinclipboard.la $(XWINMODULES_LIBS) -lgdi32
+
+include $(top_srcdir)/manpages.am
+appman_PRE = xwinclip.man
diff --git a/hw/xwin/winclipboard/xwinclip.man b/hw/xwin/winclipboard/xwinclip.man
new file mode 100644
index 0000000..822db91
--- /dev/null
+++ b/hw/xwin/winclipboard/xwinclip.man
@@ -0,0 +1,61 @@
+.TH xwinclip 1 __xorgversion__
+.SH NAME
+xwinclip - An X11 and Windows clipboard integration tool
+
+.SH SYNOPSIS
+.B xwinclip [OPTION]...
+
+.SH DESCRIPTION
+\fIxwinclip\fP is a tool for copying and pasting text between the Windows and X11 clipboard systems.
+
+\fIxwinclip\fP watches for updates to either clipboard and copies data between them when either one is updated.
+
+\fIxwinclip\fP monitors the X PRIMARY and CLIBPOARD selections for changes in ownership, and makes
+the contents of the most recent one to change available to paste from the Windows clipboard.
+
+It also monitors the contents of the Windows clipboard for changes, taking ownership of the PRIMARY and
+CLIPBOARD selections, and making the contents of the Windows clipboard available in them.
+
+.B Note well:
+The \fIXWin(1)\fP X server has internal clipboard integration that is enabled by default.
+Do \fINOT\fP run \fIxwinclip\fP unless \fIXWin(1)\fP has been started with the -noclipboard option.
+
+.SH OPTIONS
+\fIxwinclip\fP accepts the following optional command line switches:
+
+.TP 8
+.B \-display [display]
+Specifies the X server display to connect to.
+.TP 8
+.B \-nounicodeclipboard
+Do not use unicode text on the clipboard.
+
+.SH "SEE ALSO"
+XWin(1)
+
+.SH BUGS
+Only text clipboard contents are supported.
+
+The INCR (Incrememntal transfer) clipboard protocol for clipboard contents larger than the maximum size of an
+X request is not supported.
+
+Some X clients, notably ones written in Tcl/Tk, do not re-assert ownership of the PRIMARY selection or update
+it's timestamp when it's contents change, which currently prevents \fIxwinclip\fP from correctly noticing that
+the PRIMARY selection's contents have changed.
+
+Windows clipboard rendering is synchronous in the WM_RENDER*FORMAT message (that is, we must have placed the
+contents onto the clipboard by the time we return from processing this message), but we must wait for the X
+client which owns the selection to convert the selection to our requested format.  This is currently achieved
+using a fixed timeout of one second.
+
+The XWin(1) server should indicate somehow (by placing an atom on the root window?) that it is running with it's
+internal clipboard integration enabled, and xwinclip should notice this and exit with an appropriate error.
+
+Probably many other bugs.
+
+.SH "CONFORMING TO"
+ICCCM (Inter-Client Communication Conventions Manual) 2.0
+
+.SH AUTHORS
+Contributors to xwinclip include Benjamin Riefenstahl, Roland Cassard, Brian Genisio, Colin Harrison,
+Harold L Hunt II, Matsuzaki Kensuke, Jon Turney, Chris Twiner and Jeremy Wilkins.
commit 492c924c8531b013d50637e29213da287b9a7fa2
Author: Jon TURNEY <jon.turney at dronecode.org.uk>
Date:   Tue Jun 18 19:28:53 2013 +0100

    hw/xwin: In clipboard function prototypes, use Window type, not int 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/winclipboard/internal.h b/hw/xwin/winclipboard/internal.h
index 4b3531a..94956f8 100644
--- a/hw/xwin/winclipboard/internal.h
+++ b/hw/xwin/winclipboard/internal.h
@@ -97,7 +97,7 @@ typedef struct
 
 int
 winClipboardFlushXEvents(HWND hwnd,
-                         int iWindow, Display * pDisplay, Bool fUnicodeSupport, ClipboardAtoms *atom);
+                         Window iWindow, Display * pDisplay, Bool fUnicodeSupport, ClipboardAtoms *atom);
 
 
 Atom
diff --git a/hw/xwin/winclipboard/wndproc.c b/hw/xwin/winclipboard/wndproc.c
index fa84894..973f948 100644
--- a/hw/xwin/winclipboard/wndproc.c
+++ b/hw/xwin/winclipboard/wndproc.c
@@ -54,7 +54,7 @@
  */
 
 static int
-winProcessXEventsTimeout(HWND hwnd, int iWindow, Display * pDisplay,
+winProcessXEventsTimeout(HWND hwnd, Window iWindow, Display * pDisplay,
                          Bool fUseUnicode, ClipboardAtoms *atoms, int iTimeoutSec)
 {
     int iConnNumber;
diff --git a/hw/xwin/winclipboard/xevents.c b/hw/xwin/winclipboard/xevents.c
index d1e7df4..8a75bc4 100644
--- a/hw/xwin/winclipboard/xevents.c
+++ b/hw/xwin/winclipboard/xevents.c
@@ -129,7 +129,7 @@ winClipboardInitMonitoredSelections(void)
 
 int
 winClipboardFlushXEvents(HWND hwnd,
-                         int iWindow, Display * pDisplay, Bool fUseUnicode, ClipboardAtoms *atoms)
+                         Window iWindow, Display * pDisplay, Bool fUseUnicode, ClipboardAtoms *atoms)
 {
     Atom atomClipboard = atoms->atomClipboard;
     Atom atomLocalProperty = atoms->atomLocalProperty;
commit 4a38c3bda2b0a868d7611f9423d8a0f304b435aa
Author: Jon TURNEY <jon.turney at dronecode.org.uk>
Date:   Tue Jun 18 19:18:08 2013 +0100

    hw/xwin: Remove XOpenDisplay() retry code
    
    Remove XOpenDisplay() retry code.  This isn't a sensible thing for the
    application to be doing, and XWin server needs to retry much more than just
    XOpenDisplay().
    
    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/winclipboard/thread.c b/hw/xwin/winclipboard/thread.c
index 53e28c4..31986f6 100644
--- a/hw/xwin/winclipboard/thread.c
+++ b/hw/xwin/winclipboard/thread.c
@@ -111,7 +111,6 @@ winClipboardProc(Bool fUseUnicode, char *szDisplay)
     int iMaxDescriptor;
     Display *pDisplay = NULL;
     Window iWindow = None;
-    int iRetries;
     int iSelectError;
     Bool fShutdown = FALSE;
 
@@ -140,26 +139,8 @@ winClipboardProc(Bool fUseUnicode, char *szDisplay)
         goto winClipboardProc_Done;
     }
 
-    /* Initialize retry count */
-    iRetries = 0;
-
-
-    /* Open the X display */
-    do {
-        pDisplay = XOpenDisplay(szDisplay);
-        if (pDisplay == NULL) {
-            ErrorF("winClipboardProc - Could not open display, "
-                   "try: %d, sleeping: %d\n", iRetries + 1, WIN_CONNECT_DELAY);
-            ++iRetries;
-            sleep(WIN_CONNECT_DELAY);
-            continue;
-        }
-        else
-            break;
-    }
-    while (pDisplay == NULL && iRetries < WIN_CONNECT_RETRIES);
-
     /* Make sure that the display opened */
+    pDisplay = XOpenDisplay(szDisplay);
     if (pDisplay == NULL) {
         ErrorF("winClipboardProc - Failed opening the display, giving up\n");
         goto winClipboardProc_Done;
commit 4fc62aef8079266f8878cb355e6eb894000d8b8b
Author: Jon TURNEY <jon.turney at dronecode.org.uk>
Date:   Wed Jun 19 14:00:28 2013 +0100

    hw/xwin: Improve comment about why we can't XCloseDisplay()
    
    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/winclipboard/thread.c b/hw/xwin/winclipboard/thread.c
index 8f0ede5..53e28c4 100644
--- a/hw/xwin/winclipboard/thread.c
+++ b/hw/xwin/winclipboard/thread.c
@@ -370,8 +370,11 @@ winClipboardProc(Bool fUseUnicode, char *szDisplay)
 
 #if 0
     /*
-     * FIXME: XCloseDisplay hangs if we call it, as of 2004/03/26.  The
-     * XSync and XSelectInput calls did not help.
+     * FIXME: XCloseDisplay hangs if we call it
+     *
+     * XCloseDisplay() calls XSync(), so any outstanding errors are reported.
+     * If we are built into the server, this can deadlock if the server is
+     * in the process of exiting and waiting for this thread to exit.
      */
 
     /* Discard any remaining events */
commit 89eb7bdcad092821b61a48832e1db82975a2252b
Author: Jon TURNEY <jon.turney at dronecode.org.uk>
Date:   Wed Jun 19 13:59:40 2013 +0100

    hw/xwin: Remove setjmp()/longjmp() error constants
    
    Check specially that setjmp() returned a value which we don't pass to longjmp()
    seems a bit over-complex.
    
    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/winclipboard/internal.h b/hw/xwin/winclipboard/internal.h
index 34563e1..4b3531a 100644
--- a/hw/xwin/winclipboard/internal.h
+++ b/hw/xwin/winclipboard/internal.h
@@ -38,8 +38,6 @@
 /* Windows headers */
 #include <X11/Xwindows.h>
 
-#define WIN_JMP_OKAY				0
-#define WIN_JMP_ERROR_IO			2
 #define WIN_XEVENTS_SUCCESS			0
 #define WIN_XEVENTS_CONVERT			2
 #define WIN_XEVENTS_NOTIFY			3
diff --git a/hw/xwin/winclipboard/thread.c b/hw/xwin/winclipboard/thread.c
index 72d56d5..8f0ede5 100644
--- a/hw/xwin/winclipboard/thread.c
+++ b/hw/xwin/winclipboard/thread.c
@@ -135,16 +135,7 @@ winClipboardProc(Bool fUseUnicode, char *szDisplay)
         XSetIOErrorHandler(winClipboardIOErrorHandler);
 
     /* Set jump point for Error exits */
-    iReturn = setjmp(g_jmpEntry);
-
-    /* Check if we should continue operations */
-    if (iReturn != WIN_JMP_ERROR_IO && iReturn != WIN_JMP_OKAY) {
-        /* setjmp returned an unknown value, exit */
-        ErrorF("winClipboardProc - setjmp returned: %d exiting\n", iReturn);
-        goto winClipboardProc_Exit;
-    }
-    else if (iReturn == WIN_JMP_ERROR_IO) {
-        /* TODO: Cleanup the Win32 window and free any allocated memory */
+    if (setjmp(g_jmpEntry)) {
         ErrorF("winClipboardProc - setjmp returned for IO Error Handler.\n");
         goto winClipboardProc_Done;
     }
@@ -483,7 +474,7 @@ winClipboardIOErrorHandler(Display * pDisplay)
 
     if (pthread_equal(pthread_self(), g_winClipboardProcThread)) {
         /* Restart at the main entry point */
-        longjmp(g_jmpEntry, WIN_JMP_ERROR_IO);
+        longjmp(g_jmpEntry, 2);
     }
 
     if (g_winClipboardOldIOErrorHandler)
commit d0353bbe57aab910a6ef7da8778023a9d39c37df
Author: Jon TURNEY <jon.turney at dronecode.org.uk>
Date:   Thu Jun 20 00:04:16 2013 +0100

    hw/xwin: Move WIN_MSG_QUEUE_FNAME to where it's used
    
    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/winclipboard/internal.h b/hw/xwin/winclipboard/internal.h
index e517123..34563e1 100644
--- a/hw/xwin/winclipboard/internal.h
+++ b/hw/xwin/winclipboard/internal.h
@@ -38,13 +38,8 @@
 /* Windows headers */
 #include <X11/Xwindows.h>
 
-/* Clipboard module constants */
-#ifdef HAS_DEVWINDOWS
-#define WIN_MSG_QUEUE_FNAME			"/dev/windows"
-#endif
 #define WIN_JMP_OKAY				0
 #define WIN_JMP_ERROR_IO			2
-
 #define WIN_XEVENTS_SUCCESS			0
 #define WIN_XEVENTS_CONVERT			2
 #define WIN_XEVENTS_NOTIFY			3
diff --git a/hw/xwin/winclipboard/thread.c b/hw/xwin/winclipboard/thread.c
index 289bbb3..72d56d5 100644
--- a/hw/xwin/winclipboard/thread.c
+++ b/hw/xwin/winclipboard/thread.c
@@ -59,6 +59,9 @@
 
 #define WIN_CLIPBOARD_WINDOW_CLASS		"xwinclip"
 #define WIN_CLIPBOARD_WINDOW_TITLE		"xwinclip"
+#ifdef HAS_DEVWINDOWS
+#define WIN_MSG_QUEUE_FNAME "/dev/windows"
+#endif
 
 /*
  * Global variables
commit fa0da5a020c2ea9366568375b7f35d3f2ddad680
Author: Jon TURNEY <jon.turney at dronecode.org.uk>
Date:   Thu Jun 20 13:04:35 2013 +0100

    hw/xwin: Use header for prototypes in textconv.c
    
    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/winclipboard/textconv.c b/hw/xwin/winclipboard/textconv.c
index fd405a0..4262d98 100644
--- a/hw/xwin/winclipboard/textconv.c
+++ b/hw/xwin/winclipboard/textconv.c
@@ -31,14 +31,8 @@
 #ifdef HAVE_XWIN_CONFIG_H
 #include <xwin-config.h>
 #endif
-#include "win.h"
-#include <stdio.h>
 #include <stdlib.h>
-
-void
- winClipboardDOStoUNIX(char *pszSrc, int iLength);
-void
- winClipboardUNIXtoDOS(char **ppszData, int iLength);
+#include "internal.h"
 
 /*
  * Convert \r\n to \n
commit cbe133752d1e817246b532a274fda3f7d74ebca1
Author: Jon TURNEY <jon.turney at dronecode.org.uk>
Date:   Thu Jun 20 12:50:18 2013 +0100

    hw/xwin: Remove unused X includes from internal.h and add them where needed
    
    Also removing server headers we might clash with and no longer need.  Make
    a few adjustments to allow for this change:
    
    - provide a prototype of ErrorF()
    - use the MAX() macro provided by sys/param.h, not the max() macro provided by misc.h
    - use the X 'Bool' type rather than the unwrapped Windows 'BOOL' 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/winclipboard/internal.h b/hw/xwin/winclipboard/internal.h
index 0f9a656..e517123 100644
--- a/hw/xwin/winclipboard/internal.h
+++ b/hw/xwin/winclipboard/internal.h
@@ -33,10 +33,7 @@
 #define WINCLIPBOARD_INTERNAL_H
 
 /* X headers */
-#include <X11/X.h>
-#include <X11/Xatom.h>
-#include <X11/Xproto.h>
-#include <X11/Xutil.h>
+#include <X11/Xlib.h>
 
 /* Windows headers */
 #include <X11/Xwindows.h>
@@ -59,7 +56,7 @@
  */
 
 extern void winDebug(const char *format, ...);
-extern void winErrorFVerb(int verb, const char *format, ...);
+extern void ErrorF(const char *format, ...);
 
 /*
  * winclipboardtextconv.c
@@ -89,7 +86,7 @@ typedef struct
  * winclipboardwndproc.c
  */
 
-BOOL winClipboardFlushWindowsMessageQueue(HWND hwnd);
+Bool winClipboardFlushWindowsMessageQueue(HWND hwnd);
 
 LRESULT CALLBACK
 winClipboardWindowProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam);
diff --git a/hw/xwin/winclipboard/thread.c b/hw/xwin/winclipboard/thread.c
index ea0ef42..289bbb3 100644
--- a/hw/xwin/winclipboard/thread.c
+++ b/hw/xwin/winclipboard/thread.c
@@ -41,6 +41,7 @@
 #include <fcntl.h>
 #include <setjmp.h>
 #include <pthread.h>
+#include <sys/param.h> // for MAX() macro
 
 #ifdef HAS_WINSOCK
 #include <X11/Xwinsock.h>
@@ -48,7 +49,7 @@
 #include <errno.h>
 #endif
 
-#include "misc.h"
+#include <X11/Xatom.h>
 #include <X11/extensions/Xfixes.h>
 #include "winclipboard.h"
 #include "internal.h"
@@ -185,7 +186,7 @@ winClipboardProc(Bool fUseUnicode, char *szDisplay)
     }
 
     /* Find max of our file descriptors */
-    iMaxDescriptor = max(fdMessageQueue, iConnectionNumber) + 1;
+    iMaxDescriptor = MAX(fdMessageQueue, iConnectionNumber) + 1;
 #else
     iMaxDescriptor = iConnectionNumber + 1;
 #endif
diff --git a/hw/xwin/winclipboard/wndproc.c b/hw/xwin/winclipboard/wndproc.c
index 28e7ade..fa84894 100644
--- a/hw/xwin/winclipboard/wndproc.c
+++ b/hw/xwin/winclipboard/wndproc.c
@@ -37,8 +37,9 @@
 #include <sys/types.h>
 #include <sys/time.h>
 
+#include <X11/Xatom.h>
+
 #include "internal.h"
-#include "misc.h"
 #include "winclipboard.h"
 
 /*
@@ -499,7 +500,7 @@ winClipboardWindowProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
  * Process any pending Windows messages
  */
 
-BOOL
+Bool
 winClipboardFlushWindowsMessageQueue(HWND hwnd)
 {
     MSG msg;
diff --git a/hw/xwin/winclipboard/xevents.c b/hw/xwin/winclipboard/xevents.c
index 7275552..d1e7df4 100644
--- a/hw/xwin/winclipboard/xevents.c
+++ b/hw/xwin/winclipboard/xevents.c
@@ -35,7 +35,8 @@
 #endif
 
 #include "internal.h"
-#include "misc.h"
+#include <X11/Xutil.h>
+#include <X11/Xatom.h>
 #include <X11/extensions/Xfixes.h>
 
 /*
commit 52f3cf3c612b2f33e39fd6f985b840a0d7192a50
Author: Jon TURNEY <jon.turney at dronecode.org.uk>
Date:   Wed Jun 19 18:09:07 2013 +0100

    hw/xwin: Remove standard includes from internal.h and add them where needed
    
    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/winclipboard/internal.h b/hw/xwin/winclipboard/internal.h
index e31db54..0f9a656 100644
--- a/hw/xwin/winclipboard/internal.h
+++ b/hw/xwin/winclipboard/internal.h
@@ -32,20 +32,6 @@
 #ifndef WINCLIPBOARD_INTERNAL_H
 #define WINCLIPBOARD_INTERNAL_H
 
-/* Standard library headers */
-#include <assert.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#ifdef __CYGWIN__
-#include <sys/select.h>
-#else
-#include <X11/Xwinsock.h>
-#endif
-#include <fcntl.h>
-#include <setjmp.h>
-#include <pthread.h>
-
 /* X headers */
 #include <X11/X.h>
 #include <X11/Xatom.h>
diff --git a/hw/xwin/winclipboard/thread.c b/hw/xwin/winclipboard/thread.c
index 0d64cce..ea0ef42 100644
--- a/hw/xwin/winclipboard/thread.c
+++ b/hw/xwin/winclipboard/thread.c
@@ -36,10 +36,15 @@
 #define HAS_WINSOCK 1
 #endif
 
-#include <sys/types.h>
-#include <signal.h>
-#include "windisplay.h"
-#ifdef __CYGWIN__
+#include <assert.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <setjmp.h>
+#include <pthread.h>
+
+#ifdef HAS_WINSOCK
+#include <X11/Xwinsock.h>
+#else
 #include <errno.h>
 #endif
 
commit 5992550c4cf8818d1c47c1e474c3d8c3383983fa
Author: Jon TURNEY <jon.turney at dronecode.org.uk>
Date:   Mon Jun 17 19:01:19 2013 +0100

    hw/xwin: Add xwinclip test client
    
    Add xwinclip test client, which includes stubs for winDebug(), ErrorF()
    
    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/winclipboard/Makefile.am b/hw/xwin/winclipboard/Makefile.am
index 91cc116..b52e0e7 100644
--- a/hw/xwin/winclipboard/Makefile.am
+++ b/hw/xwin/winclipboard/Makefile.am
@@ -13,3 +13,11 @@ libXWinclipboard_la_CFLAGS = -DHAVE_XWIN_CONFIG_H \
 		             -I$(top_srcdir) -I$(top_srcdir)/miext/rootless -I$(srcdir)/..
 
 libXWinclipboard_la_LDFLAGS = -static -no-undefined
+
+bin_PROGRAMS = xwinclip
+
+xwinclip_SOURCES = xwinclip.c debug.c
+
+xwinclip_CFLAGS = $(XWINMODULES_CFLAGS)
+
+xwinclip_LDADD = libXWinclipboard.la $(XWINMODULES_LIBS) -lgdi32
diff --git a/hw/xwin/winclipboard/debug.c b/hw/xwin/winclipboard/debug.c
new file mode 100644
index 0000000..78ab6d9
--- /dev/null
+++ b/hw/xwin/winclipboard/debug.c
@@ -0,0 +1,52 @@
+//
+// Copyright © Jon TURNEY 2013
+//
+// This file is part of xwinclip.
+//
+// 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.
+//
+
+#include <stdarg.h>
+#include <stdio.h>
+
+#if 1
+int
+winDebug(const char *format, ...)
+{
+  int count;
+  va_list ap;
+  va_start(ap, format);
+  count = fprintf(stderr, "xwinclip: ");
+  count += vfprintf(stderr, format, ap);
+  va_end(ap);
+  return count;
+}
+#endif
+
+int
+ErrorF(const char *format, ...)
+{
+  int count;
+  va_list ap;
+  va_start(ap, format);
+  count = vfprintf(stderr, format, ap);
+  va_end(ap);
+  return count;
+}
diff --git a/hw/xwin/winclipboard/xwinclip.c b/hw/xwin/winclipboard/xwinclip.c
new file mode 100644
index 0000000..7b45770
--- /dev/null
+++ b/hw/xwin/winclipboard/xwinclip.c
@@ -0,0 +1,118 @@
+/*
+ *Copyright (C) 1994-2000 The XFree86 Project, Inc. All Rights Reserved.
+ *Copyright (C) 2003-2004 Harold L Hunt II All Rights Reserved.
+ *Copyright (C) Colin Harrison 2005-2008
+ *
+ *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.
+ *
+ *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).
+ *
+ * Authors:	Harold L Hunt II
+ *              Colin Harrison
+ */
+
+#ifdef HAVE_XWIN_CONFIG_H
+#include <xwin-config.h>
+#endif
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+/* X headers */
+#include <X11/Xlib.h>
+#ifdef X_LOCALE
+#include <X11/Xlocale.h>
+#else /* X_LOCALE */
+#include <locale.h>
+#endif /* X_LOCALE */
+
+#include "winclipboard.h"
+
+/*
+ * Main function
+ */
+
+int
+main (int argc, char *argv[])
+{
+  int			i;
+  char			*pszDisplay = NULL;
+  int			fUnicodeClipboard = 1;
+
+  /* Parse command-line parameters */
+  for (i = 1; i < argc; ++i)
+    {
+      /* Look for -display "display_name" or --display "display_name" */
+      if (i < argc - 1
+	  && (!strcmp (argv[i], "-display")
+	      || !strcmp (argv[i], "--display")))
+	{
+	  /* Grab a pointer to the display parameter */
+	  pszDisplay = argv[i + 1];
+
+	  /* Skip the display argument */
+	  i++;
+	  continue;
+	}
+
+      /* Look for -nounicodeclipboard */
+      if (!strcmp (argv[i], "-nounicodeclipboard"))
+	{
+	  fUnicodeClipboard = 0;
+	  continue;
+	}
+
+      /* Yack when we find a parameter that we don't know about */
+      printf ("Unknown parameter: %s\nExiting.\n", argv[i]);
+      exit (1);
+    }
+
+  /* Do we have Unicode support? */
+  if (fUnicodeClipboard)
+    {
+      printf ("Unicode clipboard I/O\n");
+    }
+  else
+    {
+      printf ("Non Unicode clipboard I/O\n");
+    }
+
+  /* Apply locale specified in the LANG environment variable */
+  if (!setlocale (LC_ALL, ""))
+    {
+      printf ("setlocale() error\n");
+      exit (1);
+    }
+
+  /* See if X supports the current locale */
+  if (XSupportsLocale () == False)
+    {
+      printf ("Locale not supported by X, falling back to 'C' locale.\n");
+      setlocale(LC_ALL, "C");
+    }
+
+  winClipboardProc(fUnicodeClipboard, pszDisplay);
+
+  return 0;
+}
commit 5ae674ae6d6c0b02fd86c5e7b23b8c38b19f180a
Author: Jon TURNEY <jon.turney at dronecode.org.uk>
Date:   Mon Jun 17 20:03:04 2013 +0100

    hw/xwin: Changes in error logging to make libwinclipboard more useful as a library
    
    Consistently use ErrorF() rather than winErrorFVerb()
    
    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/winclipboard/wndproc.c b/hw/xwin/winclipboard/wndproc.c
index affedf0..28e7ade 100644
--- a/hw/xwin/winclipboard/wndproc.c
+++ b/hw/xwin/winclipboard/wndproc.c
@@ -189,8 +189,8 @@ winClipboardWindowProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
             s_hwndNextViewer = (HWND) lParam;
             if (s_hwndNextViewer == hwnd) {
                 s_hwndNextViewer = NULL;
-                winErrorFVerb(1, "winClipboardWindowProc - WM_CHANGECBCHAIN: "
-                              "attempted to set next window to ourselves.");
+                ErrorF("winClipboardWindowProc - WM_CHANGECBCHAIN: "
+                       "attempted to set next window to ourselves.");
             }
         }
         else if (s_hwndNextViewer)
@@ -262,8 +262,8 @@ winClipboardWindowProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
             s_fCBCInitialized = FALSE;
             ChangeClipboardChain(hwnd, s_hwndNextViewer);
             winFixClipboardChain();
-            winErrorFVerb(1, "winClipboardWindowProc - WM_DRAWCLIPBOARD - "
-                          "Nested calls detected.  Re-initing.\n");
+            ErrorF("winClipboardWindowProc - WM_DRAWCLIPBOARD - "
+                   "Nested calls detected.  Re-initing.\n");
             winDebug("winClipboardWindowProc - WM_DRAWCLIPBOARD: Exit\n");
             s_fProcessingDrawClipboard = FALSE;
             return 0;
@@ -325,9 +325,9 @@ winClipboardWindowProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
                 XSetSelectionOwner(pDisplay, XA_PRIMARY, None, CurrentTime);
             }
             else if (BadWindow == iReturn || BadAtom == iReturn)
-                winErrorFVerb(1, "winClipboardWindowProc - WM_DRAWCLIPBOARD - "
-                              "XGetSelection failed for PRIMARY: %d\n",
-                              iReturn);
+                ErrorF("winClipboardWindowProc - WM_DRAWCLIPBOARD - "
+                       "XGetSelectionOwner failed for PRIMARY: %d\n",
+                       iReturn);
 
             /* Release CLIPBOARD selection if owned */
             iReturn = XGetSelectionOwner(pDisplay, atoms->atomClipboard);
@@ -337,9 +337,9 @@ winClipboardWindowProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
                 XSetSelectionOwner(pDisplay, atoms->atomClipboard, None, CurrentTime);
             }
             else if (BadWindow == iReturn || BadAtom == iReturn)
-                winErrorFVerb(1, "winClipboardWindowProc - WM_DRAWCLIPBOARD - "
-                              "XGetSelection failed for CLIPBOARD: %d\n",
-                              iReturn);
+                ErrorF("winClipboardWindowProc - WM_DRAWCLIPBOARD - "
+                       "XGetSelectionOwner failed for CLIPBOARD: %d\n",
+                       iReturn);
 
             winDebug("winClipboardWindowProc - WM_DRAWCLIPBOARD: Exit\n");
             s_fProcessingDrawClipboard = FALSE;
@@ -353,8 +353,8 @@ winClipboardWindowProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
                                      XA_PRIMARY, iWindow, CurrentTime);
         if (iReturn == BadAtom || iReturn == BadWindow ||
             XGetSelectionOwner(pDisplay, XA_PRIMARY) != iWindow) {
-            winErrorFVerb(1, "winClipboardWindowProc - WM_DRAWCLIPBOARD - "
-                          "Could not reassert ownership of PRIMARY\n");
+            ErrorF("winClipboardWindowProc - WM_DRAWCLIPBOARD - "
+                   "Could not reassert ownership of PRIMARY\n");
         }
         else {
             winDebug("winClipboardWindowProc - WM_DRAWCLIPBOARD - "
@@ -367,8 +367,8 @@ winClipboardWindowProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
 
         if (iReturn == BadAtom || iReturn == BadWindow ||
             XGetSelectionOwner(pDisplay, atoms->atomClipboard) != iWindow) {
-            winErrorFVerb(1, "winClipboardWindowProc - WM_DRAWCLIPBOARD - "
-                          "Could not reassert ownership of CLIPBOARD\n");
+            ErrorF("winClipboardWindowProc - WM_DRAWCLIPBOARD - "
+                    "Could not reassert ownership of CLIPBOARD\n");
         }
         else {
             winDebug("winClipboardWindowProc - WM_DRAWCLIPBOARD - "
@@ -421,8 +421,8 @@ winClipboardWindowProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
                                     atoms->atomLocalProperty,
                                     iWindow, CurrentTime);
         if (iReturn == BadAtom || iReturn == BadWindow) {
-            winErrorFVerb(1, "winClipboardWindowProc - WM_RENDER*FORMAT - "
-                          "XConvertSelection () failed\n");
+            ErrorF("winClipboardWindowProc - WM_RENDER*FORMAT - "
+                   "XConvertSelection () failed\n");
             break;
         }
 
@@ -436,16 +436,16 @@ winClipboardWindowProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
             }
 
             if (!OpenClipboard(hwnd)) {
-                winErrorFVerb(1, "winClipboardWindowProc - WM_RENDER*FORMATS - "
-                              "OpenClipboard () failed: %08x\n",
-                              GetLastError());
+                ErrorF("winClipboardWindowProc - WM_RENDER*FORMATS - "
+                       "OpenClipboard () failed: %08x\n",
+                       GetLastError());
                 break;
             }
 
             if (!EmptyClipboard()) {
-                winErrorFVerb(1, "winClipboardWindowProc - WM_RENDER*FORMATS - "
-                              "EmptyClipboard () failed: %08x\n",
-                              GetLastError());
+                ErrorF("winClipboardWindowProc - WM_RENDER*FORMATS - "
+                       "EmptyClipboard () failed: %08x\n",
+                       GetLastError());
                 break;
             }
         }
@@ -479,10 +479,9 @@ winClipboardWindowProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
             /* We must close the clipboard */
 
             if (!CloseClipboard()) {
-                winErrorFVerb(1,
-                              "winClipboardWindowProc - WM_RENDERALLFORMATS - "
-                              "CloseClipboard () failed: %08x\n",
-                              GetLastError());
+                ErrorF("winClipboardWindowProc - WM_RENDERALLFORMATS - "
+                       "CloseClipboard () failed: %08x\n",
+                       GetLastError());
                 break;
             }
         }
commit e1cf2b47bea9ff3e64c0ef1e4d0744d9df4bc1b7
Author: Jon TURNEY <jon.turney at dronecode.org.uk>
Date:   Mon Jun 17 19:58:20 2013 +0100

    hw/xwin: Look up atoms in winClipboardProc()
    
    Look up all atoms of interest in clipboard code in winClipboardProc() and pass
    them down.
    
    This avoids the need to check serverGeneration to notice when we need to
    invalidate cached atom values.
    
    Also consistently use cached atom values everywhere, rather than sometimes just
    doing XInternAtom() again.
    
    Remove WIN_LOCAL_PROPERTY as unused now, as we only refer to CYGX_CUT_BUFFER
    once and do that directly.
    
    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/winclipboard/internal.h b/hw/xwin/winclipboard/internal.h
index 89f0c39..e31db54 100644
--- a/hw/xwin/winclipboard/internal.h
+++ b/hw/xwin/winclipboard/internal.h
@@ -61,7 +61,7 @@
 #endif
 #define WIN_JMP_OKAY				0
 #define WIN_JMP_ERROR_IO			2
-#define WIN_LOCAL_PROPERTY			"CYGX_CUT_BUFFER"
+
 #define WIN_XEVENTS_SUCCESS			0
 #define WIN_XEVENTS_CONVERT			2
 #define WIN_XEVENTS_NOTIFY			3
@@ -90,6 +90,15 @@ void
  */
 
 
+typedef struct
+{
+    Atom atomClipboard;
+    Atom atomLocalProperty;
+    Atom atomUTF8String;
+    Atom atomCompoundText;
+    Atom atomTargets;
+} ClipboardAtoms;
+
 /*
  * winclipboardwndproc.c
  */
@@ -103,6 +112,7 @@ typedef struct
 {
   Display *pClipboardDisplay;
   Window iClipboardWindow;
+  ClipboardAtoms *atoms;
 } ClipboardWindowCreationParams;
 
 /*
@@ -111,11 +121,11 @@ typedef struct
 
 int
 winClipboardFlushXEvents(HWND hwnd,
-                         int iWindow, Display * pDisplay, Bool fUnicodeSupport);
+                         int iWindow, Display * pDisplay, Bool fUnicodeSupport, ClipboardAtoms *atom);
 
 
 Atom
-winClipboardGetLastOwnedSelectionAtom(void);
+winClipboardGetLastOwnedSelectionAtom(ClipboardAtoms *atoms);
 
 void
 winClipboardInitMonitoredSelections(void);
diff --git a/hw/xwin/winclipboard/thread.c b/hw/xwin/winclipboard/thread.c
index a9565fe..0d64cce 100644
--- a/hw/xwin/winclipboard/thread.c
+++ b/hw/xwin/winclipboard/thread.c
@@ -71,7 +71,7 @@ int xfixes_error_base;
  */
 
 static HWND
-winClipboardCreateMessagingWindow(Display *pDisplay, Window iWindow);
+winClipboardCreateMessagingWindow(Display *pDisplay, Window iWindow, ClipboardAtoms *atoms);
 
 static int
  winClipboardErrorHandler(Display * pDisplay, XErrorEvent * pErr);
@@ -88,7 +88,7 @@ static int
 Bool
 winClipboardProc(Bool fUseUnicode, char *szDisplay)
 {
-    Atom atomClipboard;
+    ClipboardAtoms atoms;
     int iReturn;
     HWND hwnd = NULL;
     int iConnectionNumber = 0;
@@ -188,8 +188,12 @@ winClipboardProc(Bool fUseUnicode, char *szDisplay)
     if (!XFixesQueryExtension(pDisplay, &xfixes_event_base, &xfixes_error_base))
       ErrorF ("winClipboardProc - XFixes extension not present\n");
 
-    /* Create atom */
-    atomClipboard = XInternAtom(pDisplay, "CLIPBOARD", False);
+    /* Create atoms */
+    atoms.atomClipboard = XInternAtom(pDisplay, "CLIPBOARD", False);
+    atoms.atomLocalProperty = XInternAtom (pDisplay, "CYGX_CUT_BUFFER", False);
+    atoms.atomUTF8String = XInternAtom (pDisplay, "UTF8_STRING", False);
+    atoms.atomCompoundText = XInternAtom (pDisplay, "COMPOUND_TEXT", False);
+    atoms.atomTargets = XInternAtom (pDisplay, "TARGETS", False);
 
     /* Create a messaging window */
     iWindow = XCreateSimpleWindow(pDisplay,
@@ -220,7 +224,7 @@ winClipboardProc(Bool fUseUnicode, char *szDisplay)
 
     XFixesSelectSelectionInput (pDisplay,
                                 iWindow,
-                                XInternAtom (pDisplay, "CLIPBOARD", False),
+                                atoms.atomClipboard,
                                 XFixesSetSelectionOwnerNotifyMask |
                                 XFixesSelectionWindowDestroyNotifyMask |
                                 XFixesSelectionClientCloseNotifyMask);
@@ -229,7 +233,7 @@ winClipboardProc(Bool fUseUnicode, char *szDisplay)
     /* Initialize monitored selection state */
     winClipboardInitMonitoredSelections();
     /* Create Windows messaging window */
-    hwnd = winClipboardCreateMessagingWindow(pDisplay, iWindow);
+    hwnd = winClipboardCreateMessagingWindow(pDisplay, iWindow, &atoms);
 
     /* Save copy of HWND */
     g_hwndClipboard = hwnd;
@@ -246,10 +250,10 @@ winClipboardProc(Bool fUseUnicode, char *szDisplay)
         }
 
         /* CLIPBOARD */
-        iReturn = XSetSelectionOwner(pDisplay, atomClipboard,
+        iReturn = XSetSelectionOwner(pDisplay, atoms.atomClipboard,
                                      iWindow, CurrentTime);
         if (iReturn == BadAtom || iReturn == BadWindow ||
-            XGetSelectionOwner(pDisplay, atomClipboard) != iWindow) {
+            XGetSelectionOwner(pDisplay, atoms.atomClipboard) != iWindow) {
             ErrorF("winClipboardProc - Could not set CLIPBOARD owner\n");
             goto winClipboardProc_Done;
         }
@@ -261,7 +265,7 @@ winClipboardProc(Bool fUseUnicode, char *szDisplay)
      *       because there may be events in local data structures
      *       already.
      */
-    winClipboardFlushXEvents(hwnd, iWindow, pDisplay, fUseUnicode);
+    winClipboardFlushXEvents(hwnd, iWindow, pDisplay, fUseUnicode, &atoms);
 
     /* Pre-flush Windows messages */
     if (!winClipboardFlushWindowsMessageQueue(hwnd)) {
@@ -319,7 +323,7 @@ winClipboardProc(Bool fUseUnicode, char *szDisplay)
         /* Branch on which descriptor became active */
         if (FD_ISSET(iConnectionNumber, &fdsRead)) {
             /* Process X events */
-            winClipboardFlushXEvents(hwnd, iWindow, pDisplay, fUseUnicode);
+            winClipboardFlushXEvents(hwnd, iWindow, pDisplay, fUseUnicode, &atoms);
         }
 
 #ifdef HAS_DEVWINDOWS
@@ -393,7 +397,7 @@ winClipboardProc(Bool fUseUnicode, char *szDisplay)
  */
 
 static HWND
-winClipboardCreateMessagingWindow(Display *pDisplay, Window iWindow)
+winClipboardCreateMessagingWindow(Display *pDisplay, Window iWindow, ClipboardAtoms *atoms)
 {
     WNDCLASSEX wc;
     ClipboardWindowCreationParams cwcp;
@@ -417,6 +421,7 @@ winClipboardCreateMessagingWindow(Display *pDisplay, Window iWindow)
     /* Information to be passed to WM_CREATE */
     cwcp.pClipboardDisplay = pDisplay;
     cwcp.iClipboardWindow = iWindow;
+    cwcp.atoms = atoms;
 
     /* Create the window */
     hwnd = CreateWindowExA(0,   /* Extended styles */
diff --git a/hw/xwin/winclipboard/wndproc.c b/hw/xwin/winclipboard/wndproc.c
index 769422b..affedf0 100644
--- a/hw/xwin/winclipboard/wndproc.c
+++ b/hw/xwin/winclipboard/wndproc.c
@@ -54,7 +54,7 @@
 
 static int
 winProcessXEventsTimeout(HWND hwnd, int iWindow, Display * pDisplay,
-                         Bool fUseUnicode, int iTimeoutSec)
+                         Bool fUseUnicode, ClipboardAtoms *atoms, int iTimeoutSec)
 {
     int iConnNumber;
     struct timeval tv;
@@ -107,7 +107,7 @@ winProcessXEventsTimeout(HWND hwnd, int iWindow, Display * pDisplay,
             /* Process X events */
             /* Exit when we see that server is shutting down */
             iReturn = winClipboardFlushXEvents(hwnd,
-                                               iWindow, pDisplay, fUseUnicode);
+                                               iWindow, pDisplay, fUseUnicode, atoms);
 
             winDebug
                 ("winProcessXEventsTimeout () - winClipboardFlushXEvents returned %d\n",
@@ -137,6 +137,7 @@ winClipboardWindowProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
     static Bool s_fCBCInitialized;
     static Display *pDisplay;
     static Window iWindow;
+    static ClipboardAtoms *atoms;
 
     /* Branch on message type */
     switch (message) {
@@ -163,6 +164,7 @@ winClipboardWindowProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
 
         pDisplay = cwcp->pClipboardDisplay;
         iWindow = cwcp->iClipboardWindow;
+        atoms = cwcp->atoms;
 
         first = GetClipboardViewer();   /* Get handle to first viewer in chain. */
         if (first == hwnd)
@@ -243,18 +245,11 @@ winClipboardWindowProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
 
     case WM_DRAWCLIPBOARD:
     {
-        static Atom atomClipboard;
-        static int generation;
         static Bool s_fProcessingDrawClipboard = FALSE;
         int iReturn;
 
         winDebug("winClipboardWindowProc - WM_DRAWCLIPBOARD: Enter\n");
 
-        if (generation != serverGeneration) {
-            generation = serverGeneration;
-            atomClipboard = XInternAtom(pDisplay, "CLIPBOARD", False);
-        }
-
         /*
          * We've occasionally seen a loop in the clipboard chain.
          * Try and fix it on the first hint of recursion.
@@ -335,11 +330,11 @@ winClipboardWindowProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
                               iReturn);
 
             /* Release CLIPBOARD selection if owned */
-            iReturn = XGetSelectionOwner(pDisplay, atomClipboard);
+            iReturn = XGetSelectionOwner(pDisplay, atoms->atomClipboard);
             if (iReturn == iWindow) {
                 winDebug("winClipboardWindowProc - WM_DRAWCLIPBOARD - "
-                         "CLIPBOARD selection is owned by us.\n");
-                XSetSelectionOwner(pDisplay, atomClipboard, None, CurrentTime);
+                         "CLIPBOARD selection is owned by us, releasing\n");
+                XSetSelectionOwner(pDisplay, atoms->atomClipboard, None, CurrentTime);
             }
             else if (BadWindow == iReturn || BadAtom == iReturn)
                 winErrorFVerb(1, "winClipboardWindowProc - WM_DRAWCLIPBOARD - "
@@ -368,10 +363,10 @@ winClipboardWindowProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
 
         /* Reassert ownership of the CLIPBOARD */
         iReturn = XSetSelectionOwner(pDisplay,
-                                     atomClipboard, iWindow, CurrentTime);
+                                     atoms->atomClipboard, iWindow, CurrentTime);
 
         if (iReturn == BadAtom || iReturn == BadWindow ||
-            XGetSelectionOwner(pDisplay, atomClipboard) != iWindow) {
+            XGetSelectionOwner(pDisplay, atoms->atomClipboard) != iWindow) {
             winErrorFVerb(1, "winClipboardWindowProc - WM_DRAWCLIPBOARD - "
                           "Could not reassert ownership of CLIPBOARD\n");
         }
@@ -421,11 +416,9 @@ winClipboardWindowProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
 
         /* Request the selection contents */
         iReturn = XConvertSelection(pDisplay,
-                                    winClipboardGetLastOwnedSelectionAtom(),
-                                    XInternAtom(pDisplay,
-                                                "COMPOUND_TEXT", False),
-                                    XInternAtom(pDisplay,
-                                                "CYGX_CUT_BUFFER", False),
+                                    winClipboardGetLastOwnedSelectionAtom(atoms),
+                                    atoms->atomCompoundText,
+                                    atoms->atomLocalProperty,
                                     iWindow, CurrentTime);
         if (iReturn == BadAtom || iReturn == BadWindow) {
             winErrorFVerb(1, "winClipboardWindowProc - WM_RENDER*FORMAT - "
@@ -461,7 +454,9 @@ winClipboardWindowProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
         iReturn = winProcessXEventsTimeout(hwnd,
                                            iWindow,
                                            pDisplay,
-                                           fConvertToUnicode, WIN_POLL_TIMEOUT);
+                                           fConvertToUnicode,
+                                           atoms,
+                                           WIN_POLL_TIMEOUT);
 
         /*
          * The last call to winProcessXEventsTimeout
diff --git a/hw/xwin/winclipboard/xevents.c b/hw/xwin/winclipboard/xevents.c
index 3fcf6e3..7275552 100644
--- a/hw/xwin/winclipboard/xevents.c
+++ b/hw/xwin/winclipboard/xevents.c
@@ -62,7 +62,6 @@ static const char *szSelectionNames[CLIP_NUM_SELECTIONS] =
     { "PRIMARY", "CLIPBOARD" };
 
 static unsigned int lastOwnedSelectionIndex = CLIP_OWN_NONE;
-static Atom atomClipboard = None;
 
 static void
 MonitorSelection(XFixesSelectionNotifyEvent * e, unsigned int i)
@@ -98,7 +97,7 @@ MonitorSelection(XFixesSelectionNotifyEvent * e, unsigned int i)
 }
 
 Atom
-winClipboardGetLastOwnedSelectionAtom(void)
+winClipboardGetLastOwnedSelectionAtom(ClipboardAtoms *atoms)
 {
     if (lastOwnedSelectionIndex == CLIP_OWN_NONE)
         return None;
@@ -107,7 +106,7 @@ winClipboardGetLastOwnedSelectionAtom(void)
         return XA_PRIMARY;
 
     if (lastOwnedSelectionIndex == CLIP_OWN_CLIPBOARD)
-        return atomClipboard;
+        return atoms->atomClipboard;
 
     return None;
 }
@@ -129,22 +128,13 @@ winClipboardInitMonitoredSelections(void)
 
 int
 winClipboardFlushXEvents(HWND hwnd,
-                         int iWindow, Display * pDisplay, Bool fUseUnicode)
+                         int iWindow, Display * pDisplay, Bool fUseUnicode, ClipboardAtoms *atoms)
 {
-    static Atom atomLocalProperty;
-    static Atom atomCompoundText;
-    static Atom atomUTF8String;
-    static Atom atomTargets;
-    static int generation;
-
-    if (generation != serverGeneration) {
-        generation = serverGeneration;
-        atomClipboard = XInternAtom(pDisplay, "CLIPBOARD", False);
-        atomLocalProperty = XInternAtom(pDisplay, WIN_LOCAL_PROPERTY, False);
-        atomUTF8String = XInternAtom(pDisplay, "UTF8_STRING", False);
-        atomCompoundText = XInternAtom(pDisplay, "COMPOUND_TEXT", False);
-        atomTargets = XInternAtom(pDisplay, "TARGETS", False);
-    }
+    Atom atomClipboard = atoms->atomClipboard;
+    Atom atomLocalProperty = atoms->atomLocalProperty;
+    Atom atomUTF8String = atoms->atomUTF8String;
+    Atom atomCompoundText = atoms->atomCompoundText;
+    Atom atomTargets = atoms->atomTargets;
 
     /* Process all pending events */
     while (XPending(pDisplay)) {
commit be61a1fc7e25a380f8d506e13b22017492a71913
Author: Jon TURNEY <jon.turney at dronecode.org.uk>
Date:   Mon Jun 17 19:07:05 2013 +0100

    hw/xwin: Add fUseUnicode as parameter to winClipboardProc()
    
    Add fUseUnicode as parameter to winClipboardProc()
    Access g_fUseUnicode global when calling it
    
    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/winclipboard/thread.c b/hw/xwin/winclipboard/thread.c
index 36a1b4e..a9565fe 100644
--- a/hw/xwin/winclipboard/thread.c
+++ b/hw/xwin/winclipboard/thread.c
@@ -55,12 +55,6 @@
 #define WIN_CLIPBOARD_WINDOW_TITLE		"xwinclip"
 
 /*
- * References to external symbols
- */
-
-extern Bool g_fUnicodeClipboard;
-
-/*
  * Global variables
  */
 
@@ -69,7 +63,6 @@ static jmp_buf g_jmpEntry;
 static XIOErrorHandler g_winClipboardOldIOErrorHandler;
 static pthread_t g_winClipboardProcThread;
 
-Bool g_fUseUnicode = FALSE;
 int xfixes_event_base;
 int xfixes_error_base;
 
@@ -93,7 +86,7 @@ static int
  */
 
 Bool
-winClipboardProc(char *szDisplay)
+winClipboardProc(Bool fUseUnicode, char *szDisplay)
 {
     Atom atomClipboard;
     int iReturn;
@@ -110,18 +103,11 @@ winClipboardProc(char *szDisplay)
     Display *pDisplay = NULL;
     Window iWindow = None;
     int iRetries;
-    Bool fUseUnicode;
     int iSelectError;
     Bool fShutdown = FALSE;
 
     winDebug("winClipboardProc - Hello\n");
 
-    /* Do we use Unicode clipboard? */
-    fUseUnicode = g_fUnicodeClipboard;
-
-    /* Save the Unicode support flag in a global */
-    g_fUseUnicode = fUseUnicode;
-
     /* Allow multiple threads to access Xlib */
     if (XInitThreads() == 0) {
         ErrorF("winClipboardProc - XInitThreads failed.\n");
diff --git a/hw/xwin/winclipboard/winclipboard.h b/hw/xwin/winclipboard/winclipboard.h
index 7aaa341..5248130 100644
--- a/hw/xwin/winclipboard/winclipboard.h
+++ b/hw/xwin/winclipboard/winclipboard.h
@@ -27,7 +27,7 @@
 #ifndef WINCLIPBOARD_H
 #define WINCLIPBOARD_H
 
-Bool winClipboardProc(char *szDisplay);
+Bool winClipboardProc(Bool fUseUnicode, char *szDisplay);
 
 void winFixClipboardChain(void);
 
diff --git a/hw/xwin/winclipboardinit.c b/hw/xwin/winclipboardinit.c
index 3324661..8aef8fe 100644
--- a/hw/xwin/winclipboardinit.c
+++ b/hw/xwin/winclipboardinit.c
@@ -82,7 +82,7 @@ winClipboardThreadProc(void *arg)
       /* Flag that clipboard client has been launched */
       g_fClipboardStarted = TRUE;
 
-      fShutdown = winClipboardProc(szDisplay);
+      fShutdown = winClipboardProc(g_fUnicodeClipboard, szDisplay);
 
       /* Flag that clipboard client has stopped */
       g_fClipboardStarted = FALSE;
commit 126c1cfaa5b5978026d44a1f8b044d367056965b
Author: Jon TURNEY <jon.turney at dronecode.org.uk>
Date:   Mon Jun 17 18:27:56 2013 +0100

    hw/xwin: Separate libwinclipboard interface and internal header files
    
    Rename the libwinclipboard internal header from winclipboard.h to internal.h
    
    Put libwinclipboard's public interface into winclipboard.h
    
    This lets winclipboardinit.c partake of that public interface, and all X server
    headers without clashes
    
    winInitClipboard() prototype belongs in a server header
    
    v2: Remove duplicate declaration of winClipboardWindowDestroy()
    
    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/win.h b/hw/xwin/win.h
index 1a882f4..7af35e7 100644
--- a/hw/xwin/win.h
+++ b/hw/xwin/win.h
@@ -793,9 +793,6 @@ Bool
  winInitClipboard(void);
 
 void
- winFixClipboardChain(void);
-
-void
  winClipboardShutdown(void);
 #endif
 
diff --git a/hw/xwin/winclipboard/internal.h b/hw/xwin/winclipboard/internal.h
new file mode 100644
index 0000000..89f0c39
--- /dev/null
+++ b/hw/xwin/winclipboard/internal.h
@@ -0,0 +1,123 @@
+
+/*
+ *Copyright (C) 2003-2004 Harold L Hunt II 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, FITNESS FOR A PARTICULAR PURPOSE AND
+ *NONINFRINGEMENT. IN NO EVENT SHALL HAROLD L HUNT II 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 Harold L Hunt II
+ *shall not be used in advertising or otherwise to promote the sale, use
+ *or other dealings in this Software without prior written authorization
+ *from Harold L Hunt II.
+ *
+ * Authors:	Harold L Hunt II
+ */
+
+#ifndef WINCLIPBOARD_INTERNAL_H
+#define WINCLIPBOARD_INTERNAL_H
+
+/* Standard library headers */
+#include <assert.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#ifdef __CYGWIN__
+#include <sys/select.h>
+#else
+#include <X11/Xwinsock.h>
+#endif
+#include <fcntl.h>
+#include <setjmp.h>
+#include <pthread.h>
+
+/* X headers */
+#include <X11/X.h>
+#include <X11/Xatom.h>
+#include <X11/Xproto.h>
+#include <X11/Xutil.h>
+
+/* Windows headers */
+#include <X11/Xwindows.h>
+
+/* Clipboard module constants */
+#ifdef HAS_DEVWINDOWS
+#define WIN_MSG_QUEUE_FNAME			"/dev/windows"
+#endif
+#define WIN_JMP_OKAY				0
+#define WIN_JMP_ERROR_IO			2
+#define WIN_LOCAL_PROPERTY			"CYGX_CUT_BUFFER"
+#define WIN_XEVENTS_SUCCESS			0
+#define WIN_XEVENTS_CONVERT			2
+#define WIN_XEVENTS_NOTIFY			3
+
+#define WM_WM_REINIT                           (WM_USER + 1)
+
+/*
+ * References to external symbols
+ */
+
+extern void winDebug(const char *format, ...);
+extern void winErrorFVerb(int verb, const char *format, ...);
+
+/*
+ * winclipboardtextconv.c
+ */
+
+void
+ winClipboardDOStoUNIX(char *pszData, int iLength);
+
+void
+ winClipboardUNIXtoDOS(char **ppszData, int iLength);
+
+/*
+ * winclipboardthread.c
+ */
+
+
+/*
+ * winclipboardwndproc.c
+ */
+
+BOOL winClipboardFlushWindowsMessageQueue(HWND hwnd);
+
+LRESULT CALLBACK
+winClipboardWindowProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam);
+
+typedef struct
+{
+  Display *pClipboardDisplay;
+  Window iClipboardWindow;
+} ClipboardWindowCreationParams;
+
+/*
+ * winclipboardxevents.c
+ */
+
+int
+winClipboardFlushXEvents(HWND hwnd,
+                         int iWindow, Display * pDisplay, Bool fUnicodeSupport);
+
+
+Atom
+winClipboardGetLastOwnedSelectionAtom(void);
+
+void
+winClipboardInitMonitoredSelections(void);
+
+#endif
diff --git a/hw/xwin/winclipboard/thread.c b/hw/xwin/winclipboard/thread.c
index bbb3a21..36a1b4e 100644
--- a/hw/xwin/winclipboard/thread.c
+++ b/hw/xwin/winclipboard/thread.c
@@ -35,15 +35,18 @@
 #else
 #define HAS_WINSOCK 1
 #endif
+
 #include <sys/types.h>
 #include <signal.h>
-#include "winclipboard.h"
 #include "windisplay.h"
 #ifdef __CYGWIN__
 #include <errno.h>
 #endif
+
 #include "misc.h"
 #include <X11/extensions/Xfixes.h>
+#include "winclipboard.h"
+#include "internal.h"
 
 #define WIN_CONNECT_RETRIES			40
 #define WIN_CONNECT_DELAY			4
diff --git a/hw/xwin/winclipboard/winclipboard.h b/hw/xwin/winclipboard/winclipboard.h
index 95b18a6..7aaa341 100644
--- a/hw/xwin/winclipboard/winclipboard.h
+++ b/hw/xwin/winclipboard/winclipboard.h
@@ -1,134 +1,36 @@
-/*
- *Copyright (C) 2003-2004 Harold L Hunt II 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, FITNESS FOR A PARTICULAR PURPOSE AND
- *NONINFRINGEMENT. IN NO EVENT SHALL HAROLD L HUNT II 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 Harold L Hunt II
- *shall not be used in advertising or otherwise to promote the sale, use
- *or other dealings in this Software without prior written authorization
- *from Harold L Hunt II.
- *
- * Authors:	Harold L Hunt II
- */
-
-#ifndef _WINCLIPBOARD_H_
-#define _WINCLIPBOARD_H_
-
-/* Standard library headers */
-#include <assert.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#ifdef __CYGWIN__
-#include <sys/select.h>
-#else
-#include <X11/Xwinsock.h>
-#endif
-#include <fcntl.h>
-#include <setjmp.h>
-#include <pthread.h>
-
-/* X headers */
-#include <X11/X.h>
-#include <X11/Xatom.h>
-#include <X11/Xproto.h>
-#include <X11/Xutil.h>
-#include <X11/Xlocale.h>
-
-/* Windows headers */
-#include <X11/Xwindows.h>
-
-/* Clipboard module constants */
-#ifdef HAS_DEVWINDOWS
-#define WIN_MSG_QUEUE_FNAME			"/dev/windows"
-#endif
-#define WIN_JMP_OKAY				0
-#define WIN_JMP_ERROR_IO			2
-#define WIN_LOCAL_PROPERTY			"CYGX_CUT_BUFFER"
-#define WIN_XEVENTS_SUCCESS			0
-#define WIN_XEVENTS_CONVERT			2
-#define WIN_XEVENTS_NOTIFY			3
-
-#define WM_WM_REINIT                           (WM_USER + 1)
-
-/*
- * References to external symbols
- */
-
-extern void winDebug(const char *format, ...);
-extern void winErrorFVerb(int verb, const char *format, ...);
-
-/*
- * winclipboardinit.c
- */
-
-Bool
- winInitClipboard(void);
-
-/*
- * winclipboardtextconv.c
- */
-
-void
- winClipboardDOStoUNIX(char *pszData, int iLength);
-
-void
- winClipboardUNIXtoDOS(char **ppszData, int iLength);
-
-/*
- * winclipboardthread.c
- */
+//
+// Copyright © Jon TURNEY 2013
+//
+// 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.
+//
+// File: winclipboard.h
+// Purpose: public interface to winclipboard library
+//
+
+#ifndef WINCLIPBOARD_H
+#define WINCLIPBOARD_H
 
 Bool winClipboardProc(char *szDisplay);
 
-void
-winClipboardWindowDestroy(void);
-
-/*
- * winclipboardwndproc.c
- */
-
-BOOL winClipboardFlushWindowsMessageQueue(HWND hwnd);
-
-LRESULT CALLBACK
-winClipboardWindowProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam);
-
-typedef struct
-{
-  Display *pClipboardDisplay;
-  Window iClipboardWindow;
-} ClipboardWindowCreationParams;
-
-/*
- * winclipboardxevents.c
- */
-
-int
-winClipboardFlushXEvents(HWND hwnd,
-                         int iWindow, Display * pDisplay, Bool fUnicodeSupport);
-
-
-Atom
-winClipboardGetLastOwnedSelectionAtom(void);
+void winFixClipboardChain(void);
 
-void
-winClipboardInitMonitoredSelections(void);
+void winClipboardWindowDestroy(void);
 
 #endif
diff --git a/hw/xwin/winclipboard/wndproc.c b/hw/xwin/winclipboard/wndproc.c
index 459170f..769422b 100644
--- a/hw/xwin/winclipboard/wndproc.c
+++ b/hw/xwin/winclipboard/wndproc.c
@@ -33,10 +33,13 @@
 #ifdef HAVE_XWIN_CONFIG_H
 #include <xwin-config.h>
 #endif
+
 #include <sys/types.h>
 #include <sys/time.h>
-#include "winclipboard.h"
+
+#include "internal.h"
 #include "misc.h"
+#include "winclipboard.h"
 
 /*
  * Constants
diff --git a/hw/xwin/winclipboard/xevents.c b/hw/xwin/winclipboard/xevents.c
index a792467..3fcf6e3 100644
--- a/hw/xwin/winclipboard/xevents.c
+++ b/hw/xwin/winclipboard/xevents.c
@@ -34,7 +34,7 @@
 #include <xwin-config.h>
 #endif
 
-#include "winclipboard.h"
+#include "internal.h"
 #include "misc.h"
 #include <X11/extensions/Xfixes.h>
 
diff --git a/hw/xwin/winclipboardinit.c b/hw/xwin/winclipboardinit.c
index 25790d0..3324661 100644
--- a/hw/xwin/winclipboardinit.c
+++ b/hw/xwin/winclipboardinit.c
@@ -35,22 +35,13 @@
 #include <unistd.h>
 #include <pthread.h>
 
-#include "os.h"
+#include "win.h"
 #include "winclipboard/winclipboard.h"
 #include "windisplay.h"
 
 #define WIN_CLIPBOARD_RETRIES			40
 #define WIN_CLIPBOARD_DELAY			1
 
-extern void winSetAuthorization(void);
-
-/*
- * References to external symbols
- */
-
-extern Bool g_fClipboard;
-extern Bool g_fClipboardStarted;
-
 /*
  * Local variables
  */
diff --git a/hw/xwin/winwndproc.c b/hw/xwin/winwndproc.c
index bee223d..e3adb56 100644
--- a/hw/xwin/winwndproc.c
+++ b/hw/xwin/winwndproc.c
@@ -42,6 +42,9 @@
 #include "winmsg.h"
 #include "winmonitors.h"
 #include "inputstr.h"
+#ifdef XWIN_CLIPBOARD
+#include "winclipboard/winclipboard.h"
+#endif
 
 /*
  * Global variables
commit 30c535219ef2c251d90a1a1d3d07c8a7ec936da9
Author: Jon TURNEY <jon.turney at dronecode.org.uk>
Date:   Tue Jun 18 00:32:53 2013 +0100

    hw/xwin: Return a shutdown flag from winClipboardProc() if we should stop trying
    
    Return a shutdown flag from winClipboardProc(), and use it in
    winClipboardThreadProc() to determine if we should stop.
    
    Currently this is set if the clipboard messaging window received a WM_QUIT.
    
    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/winclipboard/thread.c b/hw/xwin/winclipboard/thread.c
index 9ec61f8..bbb3a21 100644
--- a/hw/xwin/winclipboard/thread.c
+++ b/hw/xwin/winclipboard/thread.c
@@ -56,7 +56,6 @@
  */
 
 extern Bool g_fUnicodeClipboard;
-extern Bool g_fClipboard;
 
 /*
  * Global variables
@@ -85,10 +84,12 @@ static int
  winClipboardIOErrorHandler(Display * pDisplay);
 
 /*
- * Main thread function
+ * Create X11 and Win32 messaging windows, and run message processing loop
+ *
+ * returns TRUE if shutdown was signalled to loop, FALSE if some error occurred
  */
 
-void *
+Bool
 winClipboardProc(char *szDisplay)
 {
     Atom atomClipboard;
@@ -108,6 +109,7 @@ winClipboardProc(char *szDisplay)
     int iRetries;
     Bool fUseUnicode;
     int iSelectError;
+    Bool fShutdown = FALSE;
 
     winDebug("winClipboardProc - Hello\n");
 
@@ -349,8 +351,8 @@ winClipboardProc(char *szDisplay)
     }
 
  winClipboardProc_Exit:
-    /* disable the clipboard, which means the thread will die */
-    g_fClipboard = FALSE;
+    /* broke out of while loop on a shutdown message */
+    fShutdown = TRUE;
 
  winClipboardProc_Done:
     /* Close our Windows window */
@@ -394,7 +396,7 @@ winClipboardProc(char *szDisplay)
     /* global clipboard variable reset */
     g_hwndClipboard = NULL;
 
-    return NULL;
+    return fShutdown;
 }
 
 /*
diff --git a/hw/xwin/winclipboard/winclipboard.h b/hw/xwin/winclipboard/winclipboard.h
index 58e35dc..95b18a6 100644
--- a/hw/xwin/winclipboard/winclipboard.h
+++ b/hw/xwin/winclipboard/winclipboard.h
@@ -96,7 +96,7 @@ void
  * winclipboardthread.c
  */
 
-void *winClipboardProc(char *szDisplay);
+Bool winClipboardProc(char *szDisplay);
 
 void
 winClipboardWindowDestroy(void);
diff --git a/hw/xwin/winclipboardinit.c b/hw/xwin/winclipboardinit.c
index 2e400f6..25790d0 100644
--- a/hw/xwin/winclipboardinit.c
+++ b/hw/xwin/winclipboardinit.c
@@ -68,6 +68,8 @@ winClipboardThreadProc(void *arg)
 
   while (1)
     {
+      Bool fShutdown;
+
       ++clipboardRestarts;
 
       /* Use our generated cookie for authentication */
@@ -89,11 +91,14 @@ winClipboardThreadProc(void *arg)
       /* Flag that clipboard client has been launched */
       g_fClipboardStarted = TRUE;
 
-      winClipboardProc(szDisplay);
+      fShutdown = winClipboardProc(szDisplay);
 
       /* Flag that clipboard client has stopped */
       g_fClipboardStarted = FALSE;
 
+      if (fShutdown)
+        break;
+
       /* checking if we need to restart */
       if (clipboardRestarts >= WIN_CLIPBOARD_RETRIES) {
         /* terminates clipboard thread but the main server still lives */
commit 88d44597046086953032fec7e035fc036596e255
Author: Jon TURNEY <jon.turney at dronecode.org.uk>
Date:   Mon Jun 17 00:38:47 2013 +0100

    hw/xwin: Move clipboard integration code down to a subdirectory
    
    Move clipboard integration code down to a subdirectory and build as a
    convenience library
    
    Signed-off-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 8dc7198..93e8895 100644
--- a/configure.ac
+++ b/configure.ac
@@ -2599,6 +2599,7 @@ hw/xnest/man/Makefile
 hw/xwin/Makefile
 hw/xwin/glx/Makefile
 hw/xwin/man/Makefile
+hw/xwin/winclipboard/Makefile
 hw/xquartz/Makefile
 hw/xquartz/GL/Makefile
 hw/xquartz/bundle/Makefile
diff --git a/hw/xwin/Makefile.am b/hw/xwin/Makefile.am
index 326ffa0..2c7fde3 100644
--- a/hw/xwin/Makefile.am
+++ b/hw/xwin/Makefile.am
@@ -3,12 +3,9 @@ bin_PROGRAMS = XWin
 if XWIN_CLIPBOARD
 SRCS_CLIPBOARD = \
 	winclipboardinit.c \
-	winclipboardtextconv.c \
-	winclipboardthread.c \
-	winclipboardwndproc.c \
-	winclipboardwrappers.c \
-	winclipboardxevents.c
+	winclipboardwrappers.c
 DEFS_CLIPBOARD = -DXWIN_CLIPBOARD
+CLIPBOARD_LIBS = $(top_builddir)/hw/xwin/winclipboard/libXWinclipboard.la
 endif
 
 if XWIN_GLX_WINDOWS
@@ -110,7 +107,6 @@ SRCS =	InitInput.c \
 	winwindow.c \
 	winwndproc.c \
 	ddraw.h \
-	winclipboard.h \
 	winconfig.h \
 	win.h \
 	winglobals.h \
@@ -162,12 +158,15 @@ XWin_DEPENDENCIES = \
 	$(MULTIWINDOWEXTWM_LIBS) \
 	$(XWIN_GLX_LIBS) \
 	$(XWIN_LIBS) \
+	$(CLIPBOARD_LIBS) \
 	$(XSERVER_LIBS)
 
+
 XWin_LDADD = \
 	$(MULTIWINDOWEXTWM_LIBS) \
 	$(XWIN_GLX_LIBS) \
 	$(XWIN_LIBS) \
+	$(CLIPBOARD_LIBS) \
 	$(XSERVER_LIBS) \
 	$(XWIN_GLX_SYS_LIBS) \
 	$(XSERVER_SYS_LIBS) \
@@ -210,5 +209,5 @@ EXTRA_DIST = \
 relink:
 	$(AM_V_at)rm -f XWin$(EXEEXT) && $(MAKE) XWin$(EXEEXT)
 
-SUBDIRS = man $(GLX_DIR) .
-DIST_SUBDIRS = man glx .
+SUBDIRS = man $(GLX_DIR) winclipboard .
+DIST_SUBDIRS = man glx winclipboard .
diff --git a/hw/xwin/winclipboard.h b/hw/xwin/winclipboard.h
deleted file mode 100644
index 41c0a53..0000000
--- a/hw/xwin/winclipboard.h
+++ /dev/null
@@ -1,133 +0,0 @@
-#ifndef _WINCLIPBOARD_H_
-#define _WINCLIPBOARD_H_
-/*
- *Copyright (C) 2003-2004 Harold L Hunt II 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, FITNESS FOR A PARTICULAR PURPOSE AND
- *NONINFRINGEMENT. IN NO EVENT SHALL HAROLD L HUNT II 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 Harold L Hunt II
- *shall not be used in advertising or otherwise to promote the sale, use
- *or other dealings in this Software without prior written authorization
- *from Harold L Hunt II.
- *
- * Authors:	Harold L Hunt II
- */
-
-/* Standard library headers */
-#include <assert.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#ifdef __CYGWIN__
-#include <sys/select.h>
-#else
-#include <X11/Xwinsock.h>
-#endif
-#include <fcntl.h>
-#include <setjmp.h>
-#include <pthread.h>
-
-/* X headers */
-#include <X11/X.h>
-#include <X11/Xatom.h>
-#include <X11/Xproto.h>
-#include <X11/Xutil.h>
-#include <X11/Xlocale.h>
-
-/* Windows headers */
-#include <X11/Xwindows.h>
-
-/* Clipboard module constants */
-#ifdef HAS_DEVWINDOWS
-#define WIN_MSG_QUEUE_FNAME			"/dev/windows"
-#endif
-#define WIN_JMP_OKAY				0
-#define WIN_JMP_ERROR_IO			2
-#define WIN_LOCAL_PROPERTY			"CYGX_CUT_BUFFER"
-#define WIN_XEVENTS_SUCCESS			0
-#define WIN_XEVENTS_CONVERT			2
-#define WIN_XEVENTS_NOTIFY			3
-
-#define WM_WM_REINIT                           (WM_USER + 1)
-
-/*
- * References to external symbols
- */
-
-extern void winDebug(const char *format, ...);
-extern void winErrorFVerb(int verb, const char *format, ...);
-
-/*
- * winclipboardinit.c
- */
-
-Bool
- winInitClipboard(void);
-
-/*
- * winclipboardtextconv.c
- */
-
-void
- winClipboardDOStoUNIX(char *pszData, int iLength);
-
-void
- winClipboardUNIXtoDOS(char **ppszData, int iLength);
-
-/*
- * winclipboardthread.c
- */
-
-void *winClipboardProc(char *szDisplay);
-
-void
-winClipboardWindowDestroy(void);
-
-/*
- * winclipboardwndproc.c
- */
-
-BOOL winClipboardFlushWindowsMessageQueue(HWND hwnd);
-
-LRESULT CALLBACK
-winClipboardWindowProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam);
-
-typedef struct
-{
-  Display *pClipboardDisplay;
-  Window iClipboardWindow;
-} ClipboardWindowCreationParams;
-
-/*
- * winclipboardxevents.c
- */
-
-int
-winClipboardFlushXEvents(HWND hwnd,
-                         int iWindow, Display * pDisplay, Bool fUnicodeSupport);
-
-
-Atom
-winClipboardGetLastOwnedSelectionAtom(void);
-
-void
-winClipboardInitMonitoredSelections(void);
-
-#endif
diff --git a/hw/xwin/winclipboard/Makefile.am b/hw/xwin/winclipboard/Makefile.am
new file mode 100644
index 0000000..91cc116
--- /dev/null
+++ b/hw/xwin/winclipboard/Makefile.am
@@ -0,0 +1,15 @@
+noinst_LTLIBRARIES = libXWinclipboard.la
+
+libXWinclipboard_la_SOURCES = \
+	winclipboard.h \
+	textconv.c \
+	thread.c \
+	wndproc.c \
+	xevents.c
+
+libXWinclipboard_la_CFLAGS = -DHAVE_XWIN_CONFIG_H \
+			     $(DIX_CFLAGS) \
+			     $(XWINMODULES_CFLAGS) \
+		             -I$(top_srcdir) -I$(top_srcdir)/miext/rootless -I$(srcdir)/..
+
+libXWinclipboard_la_LDFLAGS = -static -no-undefined
diff --git a/hw/xwin/winclipboard/textconv.c b/hw/xwin/winclipboard/textconv.c
new file mode 100644
index 0000000..fd405a0
--- /dev/null
+++ b/hw/xwin/winclipboard/textconv.c
@@ -0,0 +1,147 @@
+/*
+ *Copyright (C) 2003-2004 Harold L Hunt II 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, FITNESS FOR A PARTICULAR PURPOSE AND
+ *NONINFRINGEMENT. IN NO EVENT SHALL HAROLD L HUNT II 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 Harold L Hunt II
+ *shall not be used in advertising or otherwise to promote the sale, use
+ *or other dealings in this Software without prior written authorization
+ *from Harold L Hunt II.
+ *
+ * Authors:	Harold L Hunt II
+ */
+
+#ifdef HAVE_XWIN_CONFIG_H
+#include <xwin-config.h>
+#endif
+#include "win.h"
+#include <stdio.h>
+#include <stdlib.h>
+
+void
+ winClipboardDOStoUNIX(char *pszSrc, int iLength);
+void
+ winClipboardUNIXtoDOS(char **ppszData, int iLength);
+
+/*
+ * Convert \r\n to \n
+ *
+ * NOTE: This was heavily inspired by, Cygwin's
+ * winsup/cygwin/fhandler.cc/fhandler_base::read ()
+ */
+
+void
+winClipboardDOStoUNIX(char *pszSrc, int iLength)
+{
+    char *pszDest = pszSrc;
+    char *pszEnd = pszSrc + iLength;
+
+    /* Loop until the last character */
+    while (pszSrc < pszEnd) {
+        /* Copy the current source character to current destination character */
+        *pszDest = *pszSrc;
+
+        /* Advance to the next source character */
+        pszSrc++;
+
+        /* Don't advance the destination character if we need to drop an \r */
+        if (*pszDest != '\r' || *pszSrc != '\n')
+            pszDest++;
+    }
+
+    /* Move the terminating null */
+    *pszDest = '\0';
+}
+
+/*
+ * Convert \n to \r\n
+ */
+
+void
+winClipboardUNIXtoDOS(char **ppszData, int iLength)
+{
+    int iNewlineCount = 0;
+    char *pszSrc = *ppszData;
+    char *pszEnd = pszSrc + iLength;
+    char *pszDest = NULL, *pszDestBegin = NULL;
+
+    winDebug("UNIXtoDOS () - Original data:'%s'\n", *ppszData);
+
+    /* Count \n characters without leading \r */
+    while (pszSrc < pszEnd) {
+        /* Skip ahead two character if found set of \r\n */
+        if (*pszSrc == '\r' && pszSrc + 1 < pszEnd && *(pszSrc + 1) == '\n') {
+            pszSrc += 2;
+            continue;
+        }
+
+        /* Increment the count if found naked \n */
+        if (*pszSrc == '\n') {
+            iNewlineCount++;
+        }
+
+        pszSrc++;
+    }
+
+    /* Return if no naked \n's */
+    if (iNewlineCount == 0)
+        return;
+
+    /* Allocate a new string */
+    pszDestBegin = pszDest = malloc(iLength + iNewlineCount + 1);
+
+    /* Set source pointer to beginning of data string */
+    pszSrc = *ppszData;
+
+    /* Loop through all characters in source string */
+    while (pszSrc < pszEnd) {
+        /* Copy line endings that are already valid */
+        if (*pszSrc == '\r' && pszSrc + 1 < pszEnd && *(pszSrc + 1) == '\n') {
+            *pszDest = *pszSrc;
+            *(pszDest + 1) = *(pszSrc + 1);
+            pszDest += 2;
+            pszSrc += 2;
+            continue;
+        }
+
+        /* Add \r to naked \n's */
+        if (*pszSrc == '\n') {
+            *pszDest = '\r';
+            *(pszDest + 1) = *pszSrc;
+            pszDest += 2;
+            pszSrc += 1;
+            continue;
+        }
+
+        /* Copy normal characters */
+        *pszDest = *pszSrc;
+        pszSrc++;
+        pszDest++;
+    }
+
+    /* Put terminating null at end of new string */
+    *pszDest = '\0';
+
+    /* Swap string pointers */
+    free(*ppszData);
+    *ppszData = pszDestBegin;
+
+    winDebug("UNIXtoDOS () - Final string:'%s'\n", pszDestBegin);
+}
diff --git a/hw/xwin/winclipboard/thread.c b/hw/xwin/winclipboard/thread.c
new file mode 100644
index 0000000..9ec61f8
--- /dev/null
+++ b/hw/xwin/winclipboard/thread.c
@@ -0,0 +1,504 @@
+/*
+ *Copyright (C) 2003-2004 Harold L Hunt II All Rights Reserved.
+ *Copyright (C) Colin Harrison 2005-2008
+ *
+ *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 HAROLD L HUNT II 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).
+ *
+ * Authors:	Harold L Hunt II
+ *              Colin Harrison
+ */
+
+#ifdef HAVE_XWIN_CONFIG_H
+#include <xwin-config.h>
+#else
+#define HAS_WINSOCK 1
+#endif
+#include <sys/types.h>
+#include <signal.h>
+#include "winclipboard.h"
+#include "windisplay.h"
+#ifdef __CYGWIN__
+#include <errno.h>
+#endif
+#include "misc.h"
+#include <X11/extensions/Xfixes.h>
+
+#define WIN_CONNECT_RETRIES			40
+#define WIN_CONNECT_DELAY			4
+
+#define WIN_CLIPBOARD_WINDOW_CLASS		"xwinclip"
+#define WIN_CLIPBOARD_WINDOW_TITLE		"xwinclip"
+
+/*
+ * References to external symbols
+ */
+
+extern Bool g_fUnicodeClipboard;
+extern Bool g_fClipboard;
+
+/*
+ * Global variables
+ */
+
+static HWND g_hwndClipboard = NULL;
+static jmp_buf g_jmpEntry;
+static XIOErrorHandler g_winClipboardOldIOErrorHandler;
+static pthread_t g_winClipboardProcThread;
+
+Bool g_fUseUnicode = FALSE;
+int xfixes_event_base;
+int xfixes_error_base;
+
+/*
+ * Local function prototypes
+ */
+
+static HWND
+winClipboardCreateMessagingWindow(Display *pDisplay, Window iWindow);
+
+static int
+ winClipboardErrorHandler(Display * pDisplay, XErrorEvent * pErr);
+
+static int
+ winClipboardIOErrorHandler(Display * pDisplay);
+
+/*
+ * Main thread function
+ */
+
+void *
+winClipboardProc(char *szDisplay)
+{
+    Atom atomClipboard;
+    int iReturn;
+    HWND hwnd = NULL;
+    int iConnectionNumber = 0;
+
+#ifdef HAS_DEVWINDOWS
+    int fdMessageQueue = 0;
+#else
+    struct timeval tvTimeout;
+#endif
+    fd_set fdsRead;
+    int iMaxDescriptor;
+    Display *pDisplay = NULL;
+    Window iWindow = None;
+    int iRetries;
+    Bool fUseUnicode;
+    int iSelectError;
+
+    winDebug("winClipboardProc - Hello\n");
+
+    /* Do we use Unicode clipboard? */
+    fUseUnicode = g_fUnicodeClipboard;
+
+    /* Save the Unicode support flag in a global */
+    g_fUseUnicode = fUseUnicode;
+
+    /* Allow multiple threads to access Xlib */
+    if (XInitThreads() == 0) {
+        ErrorF("winClipboardProc - XInitThreads failed.\n");
+        goto winClipboardProc_Exit;
+    }
+
+    /* See if X supports the current locale */
+    if (XSupportsLocale() == False) {
+        ErrorF("winClipboardProc - Warning: Locale not supported by X.\n");
+    }
+
+    /* Set error handler */
+    XSetErrorHandler(winClipboardErrorHandler);
+    g_winClipboardProcThread = pthread_self();
+    g_winClipboardOldIOErrorHandler =
+        XSetIOErrorHandler(winClipboardIOErrorHandler);
+
+    /* Set jump point for Error exits */
+    iReturn = setjmp(g_jmpEntry);
+
+    /* Check if we should continue operations */
+    if (iReturn != WIN_JMP_ERROR_IO && iReturn != WIN_JMP_OKAY) {
+        /* setjmp returned an unknown value, exit */
+        ErrorF("winClipboardProc - setjmp returned: %d exiting\n", iReturn);
+        goto winClipboardProc_Exit;
+    }
+    else if (iReturn == WIN_JMP_ERROR_IO) {
+        /* TODO: Cleanup the Win32 window and free any allocated memory */
+        ErrorF("winClipboardProc - setjmp returned for IO Error Handler.\n");
+        goto winClipboardProc_Done;
+    }
+
+    /* Initialize retry count */
+    iRetries = 0;
+
+
+    /* Open the X display */
+    do {
+        pDisplay = XOpenDisplay(szDisplay);
+        if (pDisplay == NULL) {
+            ErrorF("winClipboardProc - Could not open display, "
+                   "try: %d, sleeping: %d\n", iRetries + 1, WIN_CONNECT_DELAY);
+            ++iRetries;
+            sleep(WIN_CONNECT_DELAY);
+            continue;
+        }
+        else
+            break;
+    }
+    while (pDisplay == NULL && iRetries < WIN_CONNECT_RETRIES);
+
+    /* Make sure that the display opened */
+    if (pDisplay == NULL) {
+        ErrorF("winClipboardProc - Failed opening the display, giving up\n");
+        goto winClipboardProc_Done;
+    }
+
+    ErrorF("winClipboardProc - XOpenDisplay () returned and "
+           "successfully opened the display.\n");
+
+    /* Get our connection number */
+    iConnectionNumber = ConnectionNumber(pDisplay);
+
+#ifdef HAS_DEVWINDOWS
+    /* Open a file descriptor for the windows message queue */
+    fdMessageQueue = open(WIN_MSG_QUEUE_FNAME, O_RDONLY);
+    if (fdMessageQueue == -1) {
+        ErrorF("winClipboardProc - Failed opening %s\n", WIN_MSG_QUEUE_FNAME);
+        goto winClipboardProc_Done;
+    }
+
+    /* Find max of our file descriptors */
+    iMaxDescriptor = max(fdMessageQueue, iConnectionNumber) + 1;
+#else
+    iMaxDescriptor = iConnectionNumber + 1;
+#endif
+
+    if (!XFixesQueryExtension(pDisplay, &xfixes_event_base, &xfixes_error_base))
+      ErrorF ("winClipboardProc - XFixes extension not present\n");
+
+    /* Create atom */
+    atomClipboard = XInternAtom(pDisplay, "CLIPBOARD", False);
+
+    /* Create a messaging window */
+    iWindow = XCreateSimpleWindow(pDisplay,
+                                  DefaultRootWindow(pDisplay),
+                                  1, 1,
+                                  500, 500,
+                                  0,
+                                  BlackPixel(pDisplay, 0),
+                                  BlackPixel(pDisplay, 0));
+    if (iWindow == 0) {
+        ErrorF("winClipboardProc - Could not create an X window.\n");
+        goto winClipboardProc_Done;
+    }
+
+    XStoreName(pDisplay, iWindow, "xwinclip");
+
+    /* Select event types to watch */
+    if (XSelectInput(pDisplay, iWindow, PropertyChangeMask) == BadWindow)
+        ErrorF("winClipboardProc - XSelectInput generated BadWindow "
+               "on messaging window\n");
+
+    XFixesSelectSelectionInput (pDisplay,
+                                iWindow,
+                                XA_PRIMARY,
+                                XFixesSetSelectionOwnerNotifyMask |
+                                XFixesSelectionWindowDestroyNotifyMask |
+                                XFixesSelectionClientCloseNotifyMask);
+
+    XFixesSelectSelectionInput (pDisplay,
+                                iWindow,
+                                XInternAtom (pDisplay, "CLIPBOARD", False),
+                                XFixesSetSelectionOwnerNotifyMask |
+                                XFixesSelectionWindowDestroyNotifyMask |
+                                XFixesSelectionClientCloseNotifyMask);
+
+
+    /* Initialize monitored selection state */
+    winClipboardInitMonitoredSelections();
+    /* Create Windows messaging window */
+    hwnd = winClipboardCreateMessagingWindow(pDisplay, iWindow);
+
+    /* Save copy of HWND */
+    g_hwndClipboard = hwnd;
+
+    /* Assert ownership of selections if Win32 clipboard is owned */
+    if (NULL != GetClipboardOwner()) {
+        /* PRIMARY */
+        iReturn = XSetSelectionOwner(pDisplay, XA_PRIMARY,
+                                     iWindow, CurrentTime);
+        if (iReturn == BadAtom || iReturn == BadWindow ||
+            XGetSelectionOwner(pDisplay, XA_PRIMARY) != iWindow) {
+            ErrorF("winClipboardProc - Could not set PRIMARY owner\n");
+            goto winClipboardProc_Done;
+        }
+
+        /* CLIPBOARD */
+        iReturn = XSetSelectionOwner(pDisplay, atomClipboard,
+                                     iWindow, CurrentTime);
+        if (iReturn == BadAtom || iReturn == BadWindow ||
+            XGetSelectionOwner(pDisplay, atomClipboard) != iWindow) {
+            ErrorF("winClipboardProc - Could not set CLIPBOARD owner\n");
+            goto winClipboardProc_Done;
+        }
+    }
+
+    /* Pre-flush X events */
+    /*
+     * NOTE: Apparently you'll freeze if you don't do this,
+     *       because there may be events in local data structures
+     *       already.
+     */
+    winClipboardFlushXEvents(hwnd, iWindow, pDisplay, fUseUnicode);
+
+    /* Pre-flush Windows messages */
+    if (!winClipboardFlushWindowsMessageQueue(hwnd)) {
+        ErrorF("winClipboardProc - winClipboardFlushWindowsMessageQueue failed\n");
+    }
+
+    /* Loop for X events */
+    while (1) {
+        /* Setup the file descriptor set */
+        /*
+         * NOTE: You have to do this before every call to select
+         *       because select modifies the mask to indicate
+         *       which descriptors are ready.
+         */
+        FD_ZERO(&fdsRead);
+        FD_SET(iConnectionNumber, &fdsRead);
+#ifdef HAS_DEVWINDOWS
+        FD_SET(fdMessageQueue, &fdsRead);
+#else
+        tvTimeout.tv_sec = 0;
+        tvTimeout.tv_usec = 100;
+#endif
+
+        /* Wait for a Windows event or an X event */
+        iReturn = select(iMaxDescriptor,        /* Highest fds number */
+                         &fdsRead,      /* Read mask */
+                         NULL,  /* No write mask */
+                         NULL,  /* No exception mask */
+#ifdef HAS_DEVWINDOWS
+                         NULL   /* No timeout */
+#else
+                         &tvTimeout     /* Set timeout */
+#endif
+            );
+
+#ifndef HAS_WINSOCK
+        iSelectError = errno;
+#else
+        iSelectError = WSAGetLastError();
+#endif
+
+        if (iReturn < 0) {
+#ifndef HAS_WINSOCK
+            if (iSelectError == EINTR)
+#else
+            if (iSelectError == WSAEINTR)
+#endif
+                continue;
+
+            ErrorF("winClipboardProc - Call to select () failed: %d.  "
+                   "Bailing.\n", iReturn);
+            break;
+        }
+
+        /* Branch on which descriptor became active */
+        if (FD_ISSET(iConnectionNumber, &fdsRead)) {
+            /* Process X events */
+            winClipboardFlushXEvents(hwnd, iWindow, pDisplay, fUseUnicode);
+        }
+
+#ifdef HAS_DEVWINDOWS
+        /* Check for Windows event ready */
+        if (FD_ISSET(fdMessageQueue, &fdsRead))
+#else
+        if (1)
+#endif
+        {
+            /* Process Windows messages */
+            if (!winClipboardFlushWindowsMessageQueue(hwnd)) {
+                ErrorF("winClipboardProc - "
+                       "winClipboardFlushWindowsMessageQueue trapped "
+                       "WM_QUIT message, exiting main loop.\n");
+                break;
+            }
+        }
+    }
+
+ winClipboardProc_Exit:
+    /* disable the clipboard, which means the thread will die */
+    g_fClipboard = FALSE;
+
+ winClipboardProc_Done:
+    /* Close our Windows window */
+    if (g_hwndClipboard) {
+        winClipboardWindowDestroy();
+    }
+
+    /* Close our X window */
+    if (pDisplay && iWindow) {
+        iReturn = XDestroyWindow(pDisplay, iWindow);
+        if (iReturn == BadWindow)
+            ErrorF("winClipboardProc - XDestroyWindow returned BadWindow.\n");
+        else
+            ErrorF("winClipboardProc - XDestroyWindow succeeded.\n");
+    }
+
+#ifdef HAS_DEVWINDOWS
+    /* Close our Win32 message handle */
+    if (fdMessageQueue)
+        close(fdMessageQueue);
+#endif
+
+#if 0
+    /*
+     * FIXME: XCloseDisplay hangs if we call it, as of 2004/03/26.  The
+     * XSync and XSelectInput calls did not help.
+     */
+
+    /* Discard any remaining events */
+    XSync(pDisplay, TRUE);
+
+    /* Select event types to watch */
+    XSelectInput(pDisplay, DefaultRootWindow(pDisplay), None);
+
+    /* Close our X display */
+    if (pDisplay) {
+        XCloseDisplay(pDisplay);
+    }
+#endif
+
+    /* global clipboard variable reset */
+    g_hwndClipboard = NULL;
+
+    return NULL;
+}
+
+/*
+ * Create the Windows window that we use to receive Windows messages
+ */
+
+static HWND
+winClipboardCreateMessagingWindow(Display *pDisplay, Window iWindow)
+{
+    WNDCLASSEX wc;
+    ClipboardWindowCreationParams cwcp;
+    HWND hwnd;
+
+    /* Setup our window class */
+    wc.cbSize = sizeof(WNDCLASSEX);
+    wc.style = CS_HREDRAW | CS_VREDRAW;
+    wc.lpfnWndProc = winClipboardWindowProc;
+    wc.cbClsExtra = 0;
+    wc.cbWndExtra = 0;
+    wc.hInstance = GetModuleHandle(NULL);
+    wc.hIcon = 0;
+    wc.hCursor = 0;
+    wc.hbrBackground = (HBRUSH) GetStockObject(WHITE_BRUSH);
+    wc.lpszMenuName = NULL;
+    wc.lpszClassName = WIN_CLIPBOARD_WINDOW_CLASS;
+    wc.hIconSm = 0;
+    RegisterClassEx(&wc);
+
+    /* Information to be passed to WM_CREATE */
+    cwcp.pClipboardDisplay = pDisplay;
+    cwcp.iClipboardWindow = iWindow;
+
+    /* Create the window */
+    hwnd = CreateWindowExA(0,   /* Extended styles */
+                           WIN_CLIPBOARD_WINDOW_CLASS,  /* Class name */
+                           WIN_CLIPBOARD_WINDOW_TITLE,  /* Window name */
+                           WS_OVERLAPPED,       /* Not visible anyway */
+                           CW_USEDEFAULT,       /* Horizontal position */
+                           CW_USEDEFAULT,       /* Vertical position */
+                           CW_USEDEFAULT,       /* Right edge */
+                           CW_USEDEFAULT,       /* Bottom edge */
+                           (HWND) NULL, /* No parent or owner window */
+                           (HMENU) NULL,        /* No menu */
+                           GetModuleHandle(NULL),       /* Instance handle */
+                           &cwcp);       /* Creation data */
+    assert(hwnd != NULL);
+
+    /* I'm not sure, but we may need to call this to start message processing */
+    ShowWindow(hwnd, SW_HIDE);
+
+    /* Similarly, we may need a call to this even though we don't paint */
+    UpdateWindow(hwnd);
+
+    return hwnd;
+}
+
+/*
+ * winClipboardErrorHandler - Our application specific error handler
+ */
+
+static int
+winClipboardErrorHandler(Display * pDisplay, XErrorEvent * pErr)
+{
+    char pszErrorMsg[100];
+
+    XGetErrorText(pDisplay, pErr->error_code, pszErrorMsg, sizeof(pszErrorMsg));
+    ErrorF("winClipboardErrorHandler - ERROR: \n\t%s\n"
+           "\tSerial: %lu, Request Code: %d, Minor Code: %d\n",
+           pszErrorMsg, pErr->serial, pErr->request_code, pErr->minor_code);
+    return 0;
+}
+
+/*
+ * winClipboardIOErrorHandler - Our application specific IO error handler
+ */
+
+static int
+winClipboardIOErrorHandler(Display * pDisplay)
+{
+    ErrorF("winClipboardIOErrorHandler!\n");
+
+    if (pthread_equal(pthread_self(), g_winClipboardProcThread)) {
+        /* Restart at the main entry point */
+        longjmp(g_jmpEntry, WIN_JMP_ERROR_IO);
+    }
+
+    if (g_winClipboardOldIOErrorHandler)
+        g_winClipboardOldIOErrorHandler(pDisplay);
+
+    return 0;
+}
+
+void
+winClipboardWindowDestroy(void)
+{
+  if (g_hwndClipboard) {
+    SendMessage(g_hwndClipboard, WM_DESTROY, 0, 0);
+  }
+}
+
+void
+winFixClipboardChain(void)
+{
+  if (g_hwndClipboard) {
+    PostMessage(g_hwndClipboard, WM_WM_REINIT, 0, 0);
+  }
+}
diff --git a/hw/xwin/winclipboard/winclipboard.h b/hw/xwin/winclipboard/winclipboard.h
new file mode 100644
index 0000000..58e35dc
--- /dev/null
+++ b/hw/xwin/winclipboard/winclipboard.h
@@ -0,0 +1,134 @@
+/*
+ *Copyright (C) 2003-2004 Harold L Hunt II 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, FITNESS FOR A PARTICULAR PURPOSE AND
+ *NONINFRINGEMENT. IN NO EVENT SHALL HAROLD L HUNT II 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 Harold L Hunt II
+ *shall not be used in advertising or otherwise to promote the sale, use
+ *or other dealings in this Software without prior written authorization
+ *from Harold L Hunt II.
+ *
+ * Authors:	Harold L Hunt II
+ */
+
+#ifndef _WINCLIPBOARD_H_
+#define _WINCLIPBOARD_H_
+
+/* Standard library headers */
+#include <assert.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#ifdef __CYGWIN__
+#include <sys/select.h>
+#else
+#include <X11/Xwinsock.h>
+#endif
+#include <fcntl.h>
+#include <setjmp.h>
+#include <pthread.h>
+
+/* X headers */
+#include <X11/X.h>
+#include <X11/Xatom.h>
+#include <X11/Xproto.h>
+#include <X11/Xutil.h>
+#include <X11/Xlocale.h>
+
+/* Windows headers */
+#include <X11/Xwindows.h>
+
+/* Clipboard module constants */
+#ifdef HAS_DEVWINDOWS
+#define WIN_MSG_QUEUE_FNAME			"/dev/windows"
+#endif
+#define WIN_JMP_OKAY				0
+#define WIN_JMP_ERROR_IO			2
+#define WIN_LOCAL_PROPERTY			"CYGX_CUT_BUFFER"
+#define WIN_XEVENTS_SUCCESS			0
+#define WIN_XEVENTS_CONVERT			2
+#define WIN_XEVENTS_NOTIFY			3
+
+#define WM_WM_REINIT                           (WM_USER + 1)
+
+/*
+ * References to external symbols
+ */
+
+extern void winDebug(const char *format, ...);
+extern void winErrorFVerb(int verb, const char *format, ...);
+
+/*
+ * winclipboardinit.c
+ */
+
+Bool
+ winInitClipboard(void);
+
+/*
+ * winclipboardtextconv.c
+ */
+
+void
+ winClipboardDOStoUNIX(char *pszData, int iLength);
+
+void
+ winClipboardUNIXtoDOS(char **ppszData, int iLength);
+
+/*
+ * winclipboardthread.c
+ */
+
+void *winClipboardProc(char *szDisplay);
+
+void
+winClipboardWindowDestroy(void);
+
+/*
+ * winclipboardwndproc.c
+ */
+
+BOOL winClipboardFlushWindowsMessageQueue(HWND hwnd);
+
+LRESULT CALLBACK
+winClipboardWindowProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam);
+
+typedef struct
+{
+  Display *pClipboardDisplay;
+  Window iClipboardWindow;
+} ClipboardWindowCreationParams;
+
+/*
+ * winclipboardxevents.c
+ */
+
+int
+winClipboardFlushXEvents(HWND hwnd,
+                         int iWindow, Display * pDisplay, Bool fUnicodeSupport);
+
+
+Atom
+winClipboardGetLastOwnedSelectionAtom(void);
+
+void
+winClipboardInitMonitoredSelections(void);
+
+#endif
diff --git a/hw/xwin/winclipboard/wndproc.c b/hw/xwin/winclipboard/wndproc.c
new file mode 100644
index 0000000..459170f
--- /dev/null
+++ b/hw/xwin/winclipboard/wndproc.c
@@ -0,0 +1,524 @@
+/*
+ *Copyright (C) 2003-2004 Harold L Hunt II All Rights Reserved.
+ *Copyright (C) Colin Harrison 2005-2008
+ *
+ *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 HAROLD L HUNT II 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).
+ *
+ * Authors:	Harold L Hunt II
+ *              Colin Harrison
+ */
+
+#ifdef HAVE_XWIN_CONFIG_H
+#include <xwin-config.h>
+#endif
+#include <sys/types.h>
+#include <sys/time.h>
+#include "winclipboard.h"
+#include "misc.h"
+
+/*
+ * Constants
+ */
+
+#define WIN_POLL_TIMEOUT	1
+
+
+/*
+ * Process X events up to specified timeout
+ */
+
+static int
+winProcessXEventsTimeout(HWND hwnd, int iWindow, Display * pDisplay,
+                         Bool fUseUnicode, int iTimeoutSec)
+{
+    int iConnNumber;
+    struct timeval tv;
+    int iReturn;
+    DWORD dwStopTime = GetTickCount() + iTimeoutSec * 1000;
+
+    winDebug("winProcessXEventsTimeout () - pumping X events for %d seconds\n",
+             iTimeoutSec);
+
+    /* Get our connection number */
+    iConnNumber = ConnectionNumber(pDisplay);
+
+    /* Loop for X events */
+    while (1) {
+        fd_set fdsRead;
+        long remainingTime;
+
+        /* We need to ensure that all pending events are processed */
+        XSync(pDisplay, FALSE);
+
+        /* Setup the file descriptor set */
+        FD_ZERO(&fdsRead);
+        FD_SET(iConnNumber, &fdsRead);
+
+        /* Adjust timeout */
+        remainingTime = dwStopTime - GetTickCount();
+        tv.tv_sec = remainingTime / 1000;
+        tv.tv_usec = (remainingTime % 1000) * 1000;
+        winDebug("winProcessXEventsTimeout () - %d milliseconds left\n",
+                 remainingTime);
+
+        /* Break out if no time left */
+        if (remainingTime <= 0)
+            return WIN_XEVENTS_SUCCESS;
+
+        /* Wait for an X event */
+        iReturn = select(iConnNumber + 1,       /* Highest fds number */
+                         &fdsRead,      /* Read mask */
+                         NULL,  /* No write mask */
+                         NULL,  /* No exception mask */
+                         &tv);  /* Timeout */
+        if (iReturn < 0) {
+            ErrorF("winProcessXEventsTimeout - Call to select () failed: %d.  "
+                   "Bailing.\n", iReturn);
+            break;
+        }
+
+        /* Branch on which descriptor became active */
+        if (FD_ISSET(iConnNumber, &fdsRead)) {
+            /* Process X events */
+            /* Exit when we see that server is shutting down */
+            iReturn = winClipboardFlushXEvents(hwnd,
+                                               iWindow, pDisplay, fUseUnicode);
+
+            winDebug
+                ("winProcessXEventsTimeout () - winClipboardFlushXEvents returned %d\n",
+                 iReturn);
+
+            if (WIN_XEVENTS_NOTIFY == iReturn) {
+                /* Bail out if notify processed */
+                return iReturn;
+            }
+        }
+        else {
+            winDebug("winProcessXEventsTimeout - Spurious wake\n");
+        }
+    }
+
+    return WIN_XEVENTS_SUCCESS;
+}
+
+/*
+ * Process a given Windows message
+ */
+
+LRESULT CALLBACK
+winClipboardWindowProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
+{
+    static HWND s_hwndNextViewer;
+    static Bool s_fCBCInitialized;
+    static Display *pDisplay;
+    static Window iWindow;
+
+    /* Branch on message type */
+    switch (message) {
+    case WM_DESTROY:
+    {
+        winDebug("winClipboardWindowProc - WM_DESTROY\n");
+
+        /* Remove ourselves from the clipboard chain */
+        ChangeClipboardChain(hwnd, s_hwndNextViewer);
+
+        s_hwndNextViewer = NULL;
+
+        PostQuitMessage(0);
+    }
+        return 0;
+
+    case WM_CREATE:
+    {
+        HWND first, next;
+        DWORD error_code = 0;
+        ClipboardWindowCreationParams *cwcp = (ClipboardWindowCreationParams *)((CREATESTRUCT *)lParam)->lpCreateParams;
+
+        winDebug("winClipboardWindowProc - WM_CREATE\n");
+
+        pDisplay = cwcp->pClipboardDisplay;
+        iWindow = cwcp->iClipboardWindow;
+
+        first = GetClipboardViewer();   /* Get handle to first viewer in chain. */
+        if (first == hwnd)
+            return 0;           /* Make sure it's not us! */
+        /* Add ourselves to the clipboard viewer chain */
+        next = SetClipboardViewer(hwnd);
+        error_code = GetLastError();
+        if (SUCCEEDED(error_code) && (next == first))   /* SetClipboardViewer must have succeeded, and the handle */
+            s_hwndNextViewer = next;    /* it returned must have been the first window in the chain */
+        else
+            s_fCBCInitialized = FALSE;
+    }
+        return 0;
+
+    case WM_CHANGECBCHAIN:
+    {
+        winDebug("winClipboardWindowProc - WM_CHANGECBCHAIN: wParam(%x) "
+                 "lParam(%x) s_hwndNextViewer(%x)\n",
+                 wParam, lParam, s_hwndNextViewer);
+
+        if ((HWND) wParam == s_hwndNextViewer) {
+            s_hwndNextViewer = (HWND) lParam;
+            if (s_hwndNextViewer == hwnd) {
+                s_hwndNextViewer = NULL;
+                winErrorFVerb(1, "winClipboardWindowProc - WM_CHANGECBCHAIN: "
+                              "attempted to set next window to ourselves.");
+            }
+        }
+        else if (s_hwndNextViewer)
+            SendMessage(s_hwndNextViewer, message, wParam, lParam);
+
+    }
+        winDebug("winClipboardWindowProc - WM_CHANGECBCHAIN: Exit\n");
+        return 0;
+
+    case WM_WM_REINIT:
+    {
+        /* Ensure that we're in the clipboard chain.  Some apps,
+         * WinXP's remote desktop for one, don't play nice with the
+         * chain.  This message is called whenever we receive a
+         * WM_ACTIVATEAPP message to ensure that we continue to
+         * receive clipboard messages.
+         *
+         * It might be possible to detect if we're still in the chain
+         * by calling SendMessage (GetClipboardViewer(),
+         * WM_DRAWCLIPBOARD, 0, 0); and then seeing if we get the
+         * WM_DRAWCLIPBOARD message.  That, however, might be more
+         * expensive than just putting ourselves back into the chain.
+         */
+
+        HWND first, next;
+        DWORD error_code = 0;
+
+        winDebug("winClipboardWindowProc - WM_WM_REINIT: Enter\n");
+
+        first = GetClipboardViewer();   /* Get handle to first viewer in chain. */
+        if (first == hwnd)
+            return 0;           /* Make sure it's not us! */
+        winDebug("  WM_WM_REINIT: Replacing us(%x) with %x at head "
+                 "of chain\n", hwnd, s_hwndNextViewer);
+        s_fCBCInitialized = FALSE;
+        ChangeClipboardChain(hwnd, s_hwndNextViewer);
+        s_hwndNextViewer = NULL;
+        s_fCBCInitialized = FALSE;
+        winDebug("  WM_WM_REINIT: Putting us back at head of chain.\n");
+        first = GetClipboardViewer();   /* Get handle to first viewer in chain. */
+        if (first == hwnd)
+            return 0;           /* Make sure it's not us! */
+        next = SetClipboardViewer(hwnd);
+        error_code = GetLastError();
+        if (SUCCEEDED(error_code) && (next == first))   /* SetClipboardViewer must have succeeded, and the handle */
+            s_hwndNextViewer = next;    /* it returned must have been the first window in the chain */
+        else
+            s_fCBCInitialized = FALSE;
+    }
+        winDebug("winClipboardWindowProc - WM_WM_REINIT: Exit\n");
+        return 0;
+
+    case WM_DRAWCLIPBOARD:
+    {
+        static Atom atomClipboard;
+        static int generation;
+        static Bool s_fProcessingDrawClipboard = FALSE;
+        int iReturn;
+
+        winDebug("winClipboardWindowProc - WM_DRAWCLIPBOARD: Enter\n");
+
+        if (generation != serverGeneration) {
+            generation = serverGeneration;
+            atomClipboard = XInternAtom(pDisplay, "CLIPBOARD", False);
+        }
+
+        /*
+         * We've occasionally seen a loop in the clipboard chain.
+         * Try and fix it on the first hint of recursion.
+         */
+        if (!s_fProcessingDrawClipboard) {
+            s_fProcessingDrawClipboard = TRUE;
+        }
+        else {
+            /* Attempt to break the nesting by getting out of the chain, twice?, and then fix and bail */
+            s_fCBCInitialized = FALSE;
+            ChangeClipboardChain(hwnd, s_hwndNextViewer);
+            winFixClipboardChain();
+            winErrorFVerb(1, "winClipboardWindowProc - WM_DRAWCLIPBOARD - "
+                          "Nested calls detected.  Re-initing.\n");
+            winDebug("winClipboardWindowProc - WM_DRAWCLIPBOARD: Exit\n");
+            s_fProcessingDrawClipboard = FALSE;
+            return 0;
+        }
+
+        /* Bail on first message */
+        if (!s_fCBCInitialized) {
+            s_fCBCInitialized = TRUE;
+            s_fProcessingDrawClipboard = FALSE;
+            winDebug("winClipboardWindowProc - WM_DRAWCLIPBOARD: Exit\n");
+            return 0;
+        }
+
+        /*
+         * NOTE: We cannot bail out when NULL == GetClipboardOwner ()
+         * because some applications deal with the clipboard in a manner
+         * that causes the clipboard owner to be NULL when they are in
+         * fact taking ownership.  One example of this is the Win32
+         * native compile of emacs.
+         */
+
+        /* Bail when we still own the clipboard */
+        if (hwnd == GetClipboardOwner()) {
+
+            winDebug("winClipboardWindowProc - WM_DRAWCLIPBOARD - "
+                     "We own the clipboard, returning.\n");
+            winDebug("winClipboardWindowProc - WM_DRAWCLIPBOARD: Exit\n");
+            s_fProcessingDrawClipboard = FALSE;
+            if (s_hwndNextViewer)
+                SendMessage(s_hwndNextViewer, message, wParam, lParam);
+            return 0;
+        }
+
+        /*
+         * Do not take ownership of the X11 selections when something
+         * other than CF_TEXT or CF_UNICODETEXT has been copied
+         * into the Win32 clipboard.
+         */
+        if (!IsClipboardFormatAvailable(CF_TEXT)
+            && !IsClipboardFormatAvailable(CF_UNICODETEXT)) {
+
+            winDebug("winClipboardWindowProc - WM_DRAWCLIPBOARD - "
+                     "Clipboard does not contain CF_TEXT nor "
+                     "CF_UNICODETEXT.\n");
+
+            /*
+             * We need to make sure that the X Server has processed
+             * previous XSetSelectionOwner messages.
+             */
+            XSync(pDisplay, FALSE);
+
+            winDebug("winClipboardWindowProc - XSync done.\n");
+
+            /* Release PRIMARY selection if owned */
+            iReturn = XGetSelectionOwner(pDisplay, XA_PRIMARY);
+            if (iReturn == iWindow) {
+                winDebug("winClipboardWindowProc - WM_DRAWCLIPBOARD - "
+                         "PRIMARY selection is owned by us.\n");
+                XSetSelectionOwner(pDisplay, XA_PRIMARY, None, CurrentTime);
+            }
+            else if (BadWindow == iReturn || BadAtom == iReturn)
+                winErrorFVerb(1, "winClipboardWindowProc - WM_DRAWCLIPBOARD - "
+                              "XGetSelection failed for PRIMARY: %d\n",
+                              iReturn);
+
+            /* Release CLIPBOARD selection if owned */
+            iReturn = XGetSelectionOwner(pDisplay, atomClipboard);
+            if (iReturn == iWindow) {
+                winDebug("winClipboardWindowProc - WM_DRAWCLIPBOARD - "
+                         "CLIPBOARD selection is owned by us.\n");
+                XSetSelectionOwner(pDisplay, atomClipboard, None, CurrentTime);
+            }
+            else if (BadWindow == iReturn || BadAtom == iReturn)
+                winErrorFVerb(1, "winClipboardWindowProc - WM_DRAWCLIPBOARD - "
+                              "XGetSelection failed for CLIPBOARD: %d\n",
+                              iReturn);
+
+            winDebug("winClipboardWindowProc - WM_DRAWCLIPBOARD: Exit\n");
+            s_fProcessingDrawClipboard = FALSE;
+            if (s_hwndNextViewer)
+                SendMessage(s_hwndNextViewer, message, wParam, lParam);
+            return 0;
+        }
+
+        /* Reassert ownership of PRIMARY */
+        iReturn = XSetSelectionOwner(pDisplay,
+                                     XA_PRIMARY, iWindow, CurrentTime);
+        if (iReturn == BadAtom || iReturn == BadWindow ||
+            XGetSelectionOwner(pDisplay, XA_PRIMARY) != iWindow) {
+            winErrorFVerb(1, "winClipboardWindowProc - WM_DRAWCLIPBOARD - "
+                          "Could not reassert ownership of PRIMARY\n");
+        }
+        else {
+            winDebug("winClipboardWindowProc - WM_DRAWCLIPBOARD - "
+                     "Reasserted ownership of PRIMARY\n");
+        }
+
+        /* Reassert ownership of the CLIPBOARD */
+        iReturn = XSetSelectionOwner(pDisplay,
+                                     atomClipboard, iWindow, CurrentTime);
+
+        if (iReturn == BadAtom || iReturn == BadWindow ||
+            XGetSelectionOwner(pDisplay, atomClipboard) != iWindow) {
+            winErrorFVerb(1, "winClipboardWindowProc - WM_DRAWCLIPBOARD - "
+                          "Could not reassert ownership of CLIPBOARD\n");
+        }
+        else {
+            winDebug("winClipboardWindowProc - WM_DRAWCLIPBOARD - "
+                     "Reasserted ownership of CLIPBOARD\n");
+        }
+
+        /* Flush the pending SetSelectionOwner event now */
+        XFlush(pDisplay);
+
+        s_fProcessingDrawClipboard = FALSE;
+    }
+        winDebug("winClipboardWindowProc - WM_DRAWCLIPBOARD: Exit\n");
+        /* Pass the message on the next window in the clipboard viewer chain */
+        if (s_hwndNextViewer)
+            SendMessage(s_hwndNextViewer, message, wParam, lParam);
+        return 0;
+
+    case WM_DESTROYCLIPBOARD:
+        /*
+         * NOTE: Intentionally do nothing.
+         * Changes in the Win32 clipboard are handled by WM_DRAWCLIPBOARD
+         * above.  We only process this message to conform to the specs
+         * for delayed clipboard rendering in Win32.  You might think
+         * that we need to release ownership of the X11 selections, but
+         * we do not, because a WM_DRAWCLIPBOARD message will closely
+         * follow this message and reassert ownership of the X11
+         * selections, handling the issue for us.
+         */
+        winDebug("winClipboardWindowProc - WM_DESTROYCLIPBOARD - Ignored.\n");
+        return 0;
+
+    case WM_RENDERFORMAT:
+    case WM_RENDERALLFORMATS:
+    {
+        int iReturn;
+        Bool fConvertToUnicode;
+
+        winDebug("winClipboardWindowProc - WM_RENDER*FORMAT - Hello.\n");
+
+        /* Flag whether to convert to Unicode or not */
+        if (message == WM_RENDERALLFORMATS)
+            fConvertToUnicode = FALSE;
+        else
+            fConvertToUnicode = (CF_UNICODETEXT == wParam);
+
+        /* Request the selection contents */
+        iReturn = XConvertSelection(pDisplay,
+                                    winClipboardGetLastOwnedSelectionAtom(),
+                                    XInternAtom(pDisplay,
+                                                "COMPOUND_TEXT", False),
+                                    XInternAtom(pDisplay,
+                                                "CYGX_CUT_BUFFER", False),
+                                    iWindow, CurrentTime);
+        if (iReturn == BadAtom || iReturn == BadWindow) {
+            winErrorFVerb(1, "winClipboardWindowProc - WM_RENDER*FORMAT - "
+                          "XConvertSelection () failed\n");
+            break;
+        }
+
+        /* Special handling for WM_RENDERALLFORMATS */
+        if (message == WM_RENDERALLFORMATS) {
+            /* We must open and empty the clipboard */
+
+            /* Close clipboard if we have it open already */
+            if (GetOpenClipboardWindow() == hwnd) {
+                CloseClipboard();
+            }
+
+            if (!OpenClipboard(hwnd)) {
+                winErrorFVerb(1, "winClipboardWindowProc - WM_RENDER*FORMATS - "
+                              "OpenClipboard () failed: %08x\n",
+                              GetLastError());
+                break;
+            }
+
+            if (!EmptyClipboard()) {
+                winErrorFVerb(1, "winClipboardWindowProc - WM_RENDER*FORMATS - "
+                              "EmptyClipboard () failed: %08x\n",
+                              GetLastError());
+                break;
+            }
+        }
+
+        /* Process the SelectionNotify event */
+        iReturn = winProcessXEventsTimeout(hwnd,
+                                           iWindow,
+                                           pDisplay,
+                                           fConvertToUnicode, WIN_POLL_TIMEOUT);
+
+        /*
+         * The last call to winProcessXEventsTimeout
+         * from above had better have seen a notify event, or else we
+         * are dealing with a buggy or old X11 app.  In these cases we
+         * have to paste some fake data to the Win32 clipboard to
+         * satisfy the requirement that we write something to it.
+         */
+        if (WIN_XEVENTS_NOTIFY != iReturn) {
+            /* Paste no data, to satisfy required call to SetClipboardData */
+            SetClipboardData(CF_UNICODETEXT, NULL);
+            SetClipboardData(CF_TEXT, NULL);
+
+            ErrorF
+                ("winClipboardWindowProc - timed out waiting for WIN_XEVENTS_NOTIFY\n");
+        }
+
+        /* Special handling for WM_RENDERALLFORMATS */
+        if (message == WM_RENDERALLFORMATS) {
+            /* We must close the clipboard */
+
+            if (!CloseClipboard()) {
+                winErrorFVerb(1,
+                              "winClipboardWindowProc - WM_RENDERALLFORMATS - "
+                              "CloseClipboard () failed: %08x\n",
+                              GetLastError());
+                break;
+            }
+        }
+
+        winDebug("winClipboardWindowProc - WM_RENDER*FORMAT - Returning.\n");
+        return 0;
+    }
+    }
+
+    /* Let Windows perform default processing for unhandled messages */
+    return DefWindowProc(hwnd, message, wParam, lParam);
+}
+
+/*
+ * Process any pending Windows messages
+ */
+
+BOOL
+winClipboardFlushWindowsMessageQueue(HWND hwnd)
+{
+    MSG msg;
+
+    /* Flush the messaging window queue */
+    /* NOTE: Do not pass the hwnd of our messaging window to PeekMessage,
+     * as this will filter out many non-window-specific messages that
+     * are sent to our thread, such as WM_QUIT.
+     */
+    while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) {
+        /* Dispatch the message if not WM_QUIT */
+        if (msg.message == WM_QUIT)
+            return FALSE;
+        else
+            DispatchMessage(&msg);
+    }
+
+    return TRUE;
+}
diff --git a/hw/xwin/winclipboard/xevents.c b/hw/xwin/winclipboard/xevents.c
new file mode 100644
index 0000000..a792467
--- /dev/null
+++ b/hw/xwin/winclipboard/xevents.c
@@ -0,0 +1,862 @@
+/*
+ *Copyright (C) 2003-2004 Harold L Hunt II All Rights Reserved.
+ *Copyright (C) Colin Harrison 2005-2008
+ *
+ *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 HAROLD L HUNT II 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).
+ *
+ * Authors:	Harold L Hunt II
+ *              Colin Harrison
+ */
+
+#ifdef HAVE_XWIN_CONFIG_H
+#include <xwin-config.h>
+#endif
+
+#include "winclipboard.h"
+#include "misc.h"
+#include <X11/extensions/Xfixes.h>
+
+/*
+ * Constants
+ */
+
+#define CLIP_NUM_SELECTIONS		2
+#define CLIP_OWN_NONE     		-1
+#define CLIP_OWN_PRIMARY		0
+#define CLIP_OWN_CLIPBOARD		1
+
+/*
+ * Global variables
+ */
+
+extern int xfixes_event_base;
+
+/*
+ * Local variables
+ */
+
+static Window s_iOwners[CLIP_NUM_SELECTIONS] = { None, None };
+static const char *szSelectionNames[CLIP_NUM_SELECTIONS] =
+    { "PRIMARY", "CLIPBOARD" };
+
+static unsigned int lastOwnedSelectionIndex = CLIP_OWN_NONE;
+static Atom atomClipboard = None;
+
+static void
+MonitorSelection(XFixesSelectionNotifyEvent * e, unsigned int i)
+{
+    /* Look for owned -> not owned transition */
+    if (None == e->owner && None != s_iOwners[i]) {
+        unsigned int other_index;
+
+        winDebug("MonitorSelection - %s - Going from owned to not owned.\n",
+                 szSelectionNames[i]);
+
+        /* If this selection is not owned, the other monitored selection must be the most
+           recently owned, if it is owned at all */
+        if (i == CLIP_OWN_PRIMARY)
+            other_index = CLIP_OWN_CLIPBOARD;
+        if (i == CLIP_OWN_CLIPBOARD)
+            other_index = CLIP_OWN_PRIMARY;
+        if (None != s_iOwners[other_index])
+            lastOwnedSelectionIndex = other_index;
+        else
+            lastOwnedSelectionIndex = CLIP_OWN_NONE;
+    }
+
+    /* Save last owned selection */
+    if (None != e->owner) {
+        lastOwnedSelectionIndex = i;
+    }
+
+    /* Save new selection owner or None */
+    s_iOwners[i] = e->owner;
+    winDebug("MonitorSelection - %s - Now owned by XID %x\n",
+             szSelectionNames[i], e->owner);
+}
+
+Atom
+winClipboardGetLastOwnedSelectionAtom(void)
+{
+    if (lastOwnedSelectionIndex == CLIP_OWN_NONE)
+        return None;
+
+    if (lastOwnedSelectionIndex == CLIP_OWN_PRIMARY)
+        return XA_PRIMARY;
+
+    if (lastOwnedSelectionIndex == CLIP_OWN_CLIPBOARD)
+        return atomClipboard;
+
+    return None;
+}
+
+
+void
+winClipboardInitMonitoredSelections(void)
+{
+    /* Initialize static variables */
+    for (int i = 0; i < CLIP_NUM_SELECTIONS; ++i)
+      s_iOwners[i] = None;
+
+    lastOwnedSelectionIndex = CLIP_OWN_NONE;
+}
+
+/*
+ * Process any pending X events
+ */
+
+int
+winClipboardFlushXEvents(HWND hwnd,
+                         int iWindow, Display * pDisplay, Bool fUseUnicode)
+{
+    static Atom atomLocalProperty;
+    static Atom atomCompoundText;
+    static Atom atomUTF8String;
+    static Atom atomTargets;
+    static int generation;
+
+    if (generation != serverGeneration) {
+        generation = serverGeneration;
+        atomClipboard = XInternAtom(pDisplay, "CLIPBOARD", False);
+        atomLocalProperty = XInternAtom(pDisplay, WIN_LOCAL_PROPERTY, False);
+        atomUTF8String = XInternAtom(pDisplay, "UTF8_STRING", False);
+        atomCompoundText = XInternAtom(pDisplay, "COMPOUND_TEXT", False);
+        atomTargets = XInternAtom(pDisplay, "TARGETS", False);
+    }
+
+    /* Process all pending events */
+    while (XPending(pDisplay)) {
+        XTextProperty xtpText = { 0 };
+        XEvent event;
+        XSelectionEvent eventSelection;
+        unsigned long ulReturnBytesLeft;
+        char *pszReturnData = NULL;
+        char *pszGlobalData = NULL;
+        int iReturn;
+        HGLOBAL hGlobal = NULL;
+        XICCEncodingStyle xiccesStyle;
+        int iConvertDataLen = 0;
+        char *pszConvertData = NULL;
+        char *pszTextList[2] = { NULL };
+        int iCount;
+        char **ppszTextList = NULL;
+        wchar_t *pwszUnicodeStr = NULL;
+        int iUnicodeLen = 0;
+        int iReturnDataLen = 0;
+        Bool fAbort = FALSE;
+        Bool fCloseClipboard = FALSE;
+        Bool fSetClipboardData = TRUE;
+
+        /* Get the next event - will not block because one is ready */
+        XNextEvent(pDisplay, &event);
+
+        /* Branch on the event type */
+        switch (event.type) {
+            /*
+             * SelectionRequest
+             */
+
+        case SelectionRequest:
+        {
+            char *pszAtomName = NULL;
+
+            winDebug("SelectionRequest - target %d\n",
+                     event.xselectionrequest.target);
+
+            pszAtomName = XGetAtomName(pDisplay,
+                                       event.xselectionrequest.target);
+            winDebug("SelectionRequest - Target atom name %s\n", pszAtomName);
+            XFree(pszAtomName);
+            pszAtomName = NULL;
+        }
+
+            /* Abort if invalid target type */
+            if (event.xselectionrequest.target != XA_STRING
+                && event.xselectionrequest.target != atomUTF8String
+                && event.xselectionrequest.target != atomCompoundText
+                && event.xselectionrequest.target != atomTargets) {
+                /* Abort */
+                fAbort = TRUE;
+                goto winClipboardFlushXEvents_SelectionRequest_Done;
+            }
+
+            /* Handle targets type of request */
+            if (event.xselectionrequest.target == atomTargets) {
+                Atom atomTargetArr[] = { atomTargets,
+                    atomCompoundText,
+                    atomUTF8String,
+                    XA_STRING
+                };
+
+                /* Try to change the property */
+                iReturn = XChangeProperty(pDisplay,
+                                          event.xselectionrequest.requestor,
+                                          event.xselectionrequest.property,
+                                          XA_ATOM,
+                                          32,
+                                          PropModeReplace,
+                                          (unsigned char *) atomTargetArr,
+                                          (sizeof(atomTargetArr)
+                                           / sizeof(atomTargetArr[0])));
+                if (iReturn == BadAlloc
+                    || iReturn == BadAtom
+                    || iReturn == BadMatch
+                    || iReturn == BadValue || iReturn == BadWindow) {
+                    ErrorF("winClipboardFlushXEvents - SelectionRequest - "
+                           "XChangeProperty failed: %d\n", iReturn);
+                }
+
+                /* Setup selection notify xevent */
+                eventSelection.type = SelectionNotify;
+                eventSelection.send_event = True;
+                eventSelection.display = pDisplay;
+                eventSelection.requestor = event.xselectionrequest.requestor;
+                eventSelection.selection = event.xselectionrequest.selection;
+                eventSelection.target = event.xselectionrequest.target;
+                eventSelection.property = event.xselectionrequest.property;
+                eventSelection.time = event.xselectionrequest.time;
+
+                /*
+                 * Notify the requesting window that
+                 * the operation has completed
+                 */
+                iReturn = XSendEvent(pDisplay,
+                                     eventSelection.requestor,
+                                     False, 0L, (XEvent *) &eventSelection);
+                if (iReturn == BadValue || iReturn == BadWindow) {
+                    ErrorF("winClipboardFlushXEvents - SelectionRequest - "
+                           "XSendEvent () failed\n");
+                }
+                break;
+            }
+
+            /* Close clipboard if we have it open already */
+            if (GetOpenClipboardWindow() == hwnd) {
+                CloseClipboard();
+            }
+
+            /* Access the clipboard */
+            if (!OpenClipboard(hwnd)) {
+                ErrorF("winClipboardFlushXEvents - SelectionRequest - "
+                       "OpenClipboard () failed: %08lx\n", GetLastError());
+
+                /* Abort */
+                fAbort = TRUE;
+                goto winClipboardFlushXEvents_SelectionRequest_Done;
+            }
+
+            /* Indicate that clipboard was opened */
+            fCloseClipboard = TRUE;
+
+            /* Check that clipboard format is available */
+            if (fUseUnicode && !IsClipboardFormatAvailable(CF_UNICODETEXT)) {
+                static int count;       /* Hack to stop acroread spamming the log */
+                static HWND lasthwnd;   /* I've not seen any other client get here repeatedly? */
+
+                if (hwnd != lasthwnd)
+                    count = 0;
+                count++;
+                if (count < 6)
+                    ErrorF("winClipboardFlushXEvents - CF_UNICODETEXT is not "
+                           "available from Win32 clipboard.  Aborting %d.\n",
+                           count);
+                lasthwnd = hwnd;
+
+                /* Abort */
+                fAbort = TRUE;
+                goto winClipboardFlushXEvents_SelectionRequest_Done;
+            }
+            else if (!fUseUnicode && !IsClipboardFormatAvailable(CF_TEXT)) {
+                ErrorF("winClipboardFlushXEvents - CF_TEXT is not "
+                       "available from Win32 clipboard.  Aborting.\n");
+
+                /* Abort */
+                fAbort = TRUE;
+                goto winClipboardFlushXEvents_SelectionRequest_Done;
+            }
+
+            /* Setup the string style */
+            if (event.xselectionrequest.target == XA_STRING)
+                xiccesStyle = XStringStyle;
+#ifdef X_HAVE_UTF8_STRING
+            else if (event.xselectionrequest.target == atomUTF8String)
+                xiccesStyle = XUTF8StringStyle;
+#endif
+            else if (event.xselectionrequest.target == atomCompoundText)
+                xiccesStyle = XCompoundTextStyle;
+            else
+                xiccesStyle = XStringStyle;
+
+            /* Get a pointer to the clipboard text, in desired format */
+            if (fUseUnicode) {
+                /* Retrieve clipboard data */
+                hGlobal = GetClipboardData(CF_UNICODETEXT);
+            }
+            else {
+                /* Retrieve clipboard data */
+                hGlobal = GetClipboardData(CF_TEXT);
+            }
+            if (!hGlobal) {
+                ErrorF("winClipboardFlushXEvents - SelectionRequest - "
+                       "GetClipboardData () failed: %08lx\n", GetLastError());
+
+                /* Abort */
+                fAbort = TRUE;
+                goto winClipboardFlushXEvents_SelectionRequest_Done;
+            }
+            pszGlobalData = (char *) GlobalLock(hGlobal);
+
+            /* Convert the Unicode string to UTF8 (MBCS) */
+            if (fUseUnicode) {
+                iConvertDataLen = WideCharToMultiByte(CP_UTF8,
+                                                      0,
+                                                      (LPCWSTR) pszGlobalData,
+                                                      -1, NULL, 0, NULL, NULL);
+                /* NOTE: iConvertDataLen includes space for null terminator */
+                pszConvertData = malloc(iConvertDataLen);
+                WideCharToMultiByte(CP_UTF8,
+                                    0,
+                                    (LPCWSTR) pszGlobalData,
+                                    -1,
+                                    pszConvertData,
+                                    iConvertDataLen, NULL, NULL);
+            }
+            else {
+                pszConvertData = strdup(pszGlobalData);
+                iConvertDataLen = strlen(pszConvertData) + 1;
+            }
+
+            /* Convert DOS string to UNIX string */
+            winClipboardDOStoUNIX(pszConvertData, strlen(pszConvertData));
+
+            /* Setup our text list */
+            pszTextList[0] = pszConvertData;
+            pszTextList[1] = NULL;
+
+            /* Initialize the text property */
+            xtpText.value = NULL;
+            xtpText.nitems = 0;
+
+            /* Create the text property from the text list */
+            if (fUseUnicode) {
+#ifdef X_HAVE_UTF8_STRING
+                iReturn = Xutf8TextListToTextProperty(pDisplay,
+                                                      pszTextList,
+                                                      1, xiccesStyle, &xtpText);
+#endif
+            }
+            else {
+                iReturn = XmbTextListToTextProperty(pDisplay,
+                                                    pszTextList,
+                                                    1, xiccesStyle, &xtpText);
+            }
+            if (iReturn == XNoMemory || iReturn == XLocaleNotSupported) {
+                ErrorF("winClipboardFlushXEvents - SelectionRequest - "
+                       "X*TextListToTextProperty failed: %d\n", iReturn);
+
+                /* Abort */
+                fAbort = TRUE;
+                goto winClipboardFlushXEvents_SelectionRequest_Done;
+            }
+
+            /* Free the converted string */
+            free(pszConvertData);
+            pszConvertData = NULL;
+
+            /* Copy the clipboard text to the requesting window */
+            iReturn = XChangeProperty(pDisplay,
+                                      event.xselectionrequest.requestor,
+                                      event.xselectionrequest.property,
+                                      event.xselectionrequest.target,
+                                      8,
+                                      PropModeReplace,
+                                      xtpText.value, xtpText.nitems);
+            if (iReturn == BadAlloc || iReturn == BadAtom
+                || iReturn == BadMatch || iReturn == BadValue
+                || iReturn == BadWindow) {
+                ErrorF("winClipboardFlushXEvents - SelectionRequest - "
+                       "XChangeProperty failed: %d\n", iReturn);
+
+                /* Abort */
+                fAbort = TRUE;
+                goto winClipboardFlushXEvents_SelectionRequest_Done;
+            }
+
+            /* Release the clipboard data */
+            GlobalUnlock(hGlobal);
+            pszGlobalData = NULL;
+            fCloseClipboard = FALSE;
+            CloseClipboard();
+
+            /* Clean up */
+            XFree(xtpText.value);
+            xtpText.value = NULL;
+            xtpText.nitems = 0;
+
+            /* Setup selection notify event */
+            eventSelection.type = SelectionNotify;
+            eventSelection.send_event = True;
+            eventSelection.display = pDisplay;
+            eventSelection.requestor = event.xselectionrequest.requestor;
+            eventSelection.selection = event.xselectionrequest.selection;
+            eventSelection.target = event.xselectionrequest.target;
+            eventSelection.property = event.xselectionrequest.property;
+            eventSelection.time = event.xselectionrequest.time;
+
+            /* Notify the requesting window that the operation has completed */
+            iReturn = XSendEvent(pDisplay,
+                                 eventSelection.requestor,
+                                 False, 0L, (XEvent *) &eventSelection);
+            if (iReturn == BadValue || iReturn == BadWindow) {
+                ErrorF("winClipboardFlushXEvents - SelectionRequest - "
+                       "XSendEvent () failed\n");
+
+                /* Abort */
+                fAbort = TRUE;
+                goto winClipboardFlushXEvents_SelectionRequest_Done;
+            }
+
+ winClipboardFlushXEvents_SelectionRequest_Done:
+            /* Free allocated resources */
+            if (xtpText.value) {
+                XFree(xtpText.value);
+                xtpText.value = NULL;
+                xtpText.nitems = 0;
+            }
+            free(pszConvertData);
+            if (hGlobal && pszGlobalData)
+                GlobalUnlock(hGlobal);
+
+            /*
+             * Send a SelectionNotify event to the requesting
+             * client when we abort.
+             */
+            if (fAbort) {
+                /* Setup selection notify event */
+                eventSelection.type = SelectionNotify;
+                eventSelection.send_event = True;
+                eventSelection.display = pDisplay;
+                eventSelection.requestor = event.xselectionrequest.requestor;
+                eventSelection.selection = event.xselectionrequest.selection;
+                eventSelection.target = event.xselectionrequest.target;
+                eventSelection.property = None;
+                eventSelection.time = event.xselectionrequest.time;
+
+                /* Notify the requesting window that the operation is complete */
+                iReturn = XSendEvent(pDisplay,
+                                     eventSelection.requestor,
+                                     False, 0L, (XEvent *) &eventSelection);
+                if (iReturn == BadValue || iReturn == BadWindow) {
+                    /*
+                     * Should not be a problem if XSendEvent fails because
+                     * the client may simply have exited.
+                     */
+                    ErrorF("winClipboardFlushXEvents - SelectionRequest - "
+                           "XSendEvent () failed for abort event.\n");
+                }
+            }
+
+            /* Close clipboard if it was opened */
+            if (fCloseClipboard) {
+                fCloseClipboard = FALSE;
+                CloseClipboard();
+            }
+            break;
+
+            /*
+             * SelectionNotify
+             */
+
+        case SelectionNotify:
+
+            winDebug("winClipboardFlushXEvents - SelectionNotify\n");
+            {
+                char *pszAtomName;
+
+                pszAtomName = XGetAtomName(pDisplay,
+                                           event.xselection.selection);
+
+                winDebug
+                    ("winClipboardFlushXEvents - SelectionNotify - ATOM: %s\n",
+                     pszAtomName);
+                XFree(pszAtomName);
+            }
+
+            /*
+             * Request conversion of UTF8 and CompoundText targets.
+             */
+            if (event.xselection.property == None) {
+                if (event.xselection.target == XA_STRING) {
+                    winDebug("winClipboardFlushXEvents - SelectionNotify - "
+                             "XA_STRING\n");
+
+                    return WIN_XEVENTS_CONVERT;
+                }
+                else if (event.xselection.target == atomUTF8String) {
+                    winDebug("winClipboardFlushXEvents - SelectionNotify - "
+                             "Requesting conversion of UTF8 target.\n");
+
+                    XConvertSelection(pDisplay,
+                                      event.xselection.selection,
+                                      XA_STRING,
+                                      atomLocalProperty, iWindow, CurrentTime);
+
+                    /* Process the ConvertSelection event */
+                    XFlush(pDisplay);
+                    return WIN_XEVENTS_CONVERT;
+                }
+#ifdef X_HAVE_UTF8_STRING
+                else if (event.xselection.target == atomCompoundText) {
+                    winDebug("winClipboardFlushXEvents - SelectionNotify - "
+                             "Requesting conversion of CompoundText target.\n");
+
+                    XConvertSelection(pDisplay,
+                                      event.xselection.selection,
+                                      atomUTF8String,
+                                      atomLocalProperty, iWindow, CurrentTime);
+
+                    /* Process the ConvertSelection event */
+                    XFlush(pDisplay);
+                    return WIN_XEVENTS_CONVERT;
+                }
+#endif
+                else {
+                    ErrorF("winClipboardFlushXEvents - SelectionNotify - "
+                           "Unknown format.  Cannot request conversion, "
+                           "aborting.\n");
+                    break;
+                }
+            }
+
+            /* Retrieve the size of the stored data */
+            iReturn = XGetWindowProperty(pDisplay, iWindow, atomLocalProperty, 0, 0,    /* Don't get data, just size */
+                                         False,
+                                         AnyPropertyType,
+                                         &xtpText.encoding,
+                                         &xtpText.format,
+                                         &xtpText.nitems,
+                                         &ulReturnBytesLeft, &xtpText.value);
+            if (iReturn != Success) {
+                ErrorF("winClipboardFlushXEvents - SelectionNotify - "
+                       "XGetWindowProperty () failed, aborting: %d\n", iReturn);
+                break;
+            }
+
+            winDebug("SelectionNotify - returned data %d left %d\n",
+                     xtpText.nitems, ulReturnBytesLeft);
+
+            /* Request the selection data */
+            iReturn = XGetWindowProperty(pDisplay,
+                                         iWindow,
+                                         atomLocalProperty,
+                                         0,
+                                         ulReturnBytesLeft,
+                                         False,
+                                         AnyPropertyType,
+                                         &xtpText.encoding,
+                                         &xtpText.format,
+                                         &xtpText.nitems,
+                                         &ulReturnBytesLeft, &xtpText.value);
+            if (iReturn != Success) {
+                ErrorF("winClipboardFlushXEvents - SelectionNotify - "
+                       "XGetWindowProperty () failed, aborting: %d\n", iReturn);
+                break;
+            }
+
+            {
+                char *pszAtomName = NULL;
+
+                winDebug("SelectionNotify - returned data %d left %d\n",
+                         xtpText.nitems, ulReturnBytesLeft);
+                pszAtomName = XGetAtomName(pDisplay, xtpText.encoding);
+                winDebug("Notify atom name %s\n", pszAtomName);
+                XFree(pszAtomName);
+                pszAtomName = NULL;
+            }
+
+            if (fUseUnicode) {
+#ifdef X_HAVE_UTF8_STRING
+                /* Convert the text property to a text list */
+                iReturn = Xutf8TextPropertyToTextList(pDisplay,
+                                                      &xtpText,
+                                                      &ppszTextList, &iCount);
+#endif
+            }
+            else {
+                iReturn = XmbTextPropertyToTextList(pDisplay,
+                                                    &xtpText,
+                                                    &ppszTextList, &iCount);
+            }
+            if (iReturn == Success || iReturn > 0) {
+                /* Conversion succeeded or some unconvertible characters */
+                if (ppszTextList != NULL) {
+                    int i;
+
+                    iReturnDataLen = 0;
+                    for (i = 0; i < iCount; i++) {
+                        iReturnDataLen += strlen(ppszTextList[i]);
+                    }
+                    pszReturnData = malloc(iReturnDataLen + 1);
+                    pszReturnData[0] = '\0';
+                    for (i = 0; i < iCount; i++) {
+                        strcat(pszReturnData, ppszTextList[i]);
+                    }
+                }
+                else {
+                    ErrorF("winClipboardFlushXEvents - SelectionNotify - "
+                           "X*TextPropertyToTextList list_return is NULL.\n");
+                    pszReturnData = malloc(1);
+                    pszReturnData[0] = '\0';
+                }
+            }
+            else {
+                ErrorF("winClipboardFlushXEvents - SelectionNotify - "
+                       "X*TextPropertyToTextList returned: ");
+                switch (iReturn) {
+                case XNoMemory:
+                    ErrorF("XNoMemory\n");
+                    break;
+                case XLocaleNotSupported:
+                    ErrorF("XLocaleNotSupported\n");
+                    break;
+                case XConverterNotFound:
+                    ErrorF("XConverterNotFound\n");
+                    break;
+                default:
+                    ErrorF("%d\n", iReturn);
+                    break;
+                }
+                pszReturnData = malloc(1);
+                pszReturnData[0] = '\0';
+            }
+
+            /* Free the data returned from XGetWindowProperty */
+            if (ppszTextList)
+                XFreeStringList(ppszTextList);
+            ppszTextList = NULL;
+            XFree(xtpText.value);
+            xtpText.value = NULL;
+            xtpText.nitems = 0;
+
+            /* Convert the X clipboard string to DOS format */
+            winClipboardUNIXtoDOS(&pszReturnData, strlen(pszReturnData));
+
+            if (fUseUnicode) {
+                /* Find out how much space needed to convert MBCS to Unicode */
+                iUnicodeLen = MultiByteToWideChar(CP_UTF8,
+                                                  0,
+                                                  pszReturnData, -1, NULL, 0);
+
+                /* Allocate memory for the Unicode string */
+                pwszUnicodeStr = malloc(sizeof(wchar_t) * (iUnicodeLen + 1));
+                if (!pwszUnicodeStr) {
+                    ErrorF("winClipboardFlushXEvents - SelectionNotify "
+                           "malloc failed for pwszUnicodeStr, aborting.\n");
+
+                    /* Abort */
+                    fAbort = TRUE;
+                    goto winClipboardFlushXEvents_SelectionNotify_Done;
+                }
+
+                /* Do the actual conversion */
+                MultiByteToWideChar(CP_UTF8,
+                                    0,
+                                    pszReturnData,
+                                    -1, pwszUnicodeStr, iUnicodeLen);
+
+                /* Allocate global memory for the X clipboard data */
+                hGlobal = GlobalAlloc(GMEM_MOVEABLE,
+                                      sizeof(wchar_t) * (iUnicodeLen + 1));
+            }
+            else {
+                pszConvertData = strdup(pszReturnData);
+                iConvertDataLen = strlen(pszConvertData) + 1;
+
+                /* Allocate global memory for the X clipboard data */
+                hGlobal = GlobalAlloc(GMEM_MOVEABLE, iConvertDataLen);
+            }
+
+            free(pszReturnData);
+
+            /* Check that global memory was allocated */
+            if (!hGlobal) {
+                ErrorF("winClipboardFlushXEvents - SelectionNotify "
+                       "GlobalAlloc failed, aborting: %ld\n", GetLastError());
+
+                /* Abort */
+                fAbort = TRUE;
+                goto winClipboardFlushXEvents_SelectionNotify_Done;
+            }
+
+            /* Obtain a pointer to the global memory */
+            pszGlobalData = GlobalLock(hGlobal);
+            if (pszGlobalData == NULL) {
+                ErrorF("winClipboardFlushXEvents - Could not lock global "
+                       "memory for clipboard transfer\n");
+
+                /* Abort */
+                fAbort = TRUE;
+                goto winClipboardFlushXEvents_SelectionNotify_Done;
+            }
+
+            /* Copy the returned string into the global memory */
+            if (fUseUnicode) {
+                memcpy(pszGlobalData,
+                       pwszUnicodeStr, sizeof(wchar_t) * (iUnicodeLen + 1));
+                free(pwszUnicodeStr);
+                pwszUnicodeStr = NULL;
+            }
+            else {
+                strcpy(pszGlobalData, pszConvertData);
+                free(pszConvertData);
+                pszConvertData = NULL;
+            }
+
+            /* Release the pointer to the global memory */
+            GlobalUnlock(hGlobal);
+            pszGlobalData = NULL;
+
+            /* Push the selection data to the Windows clipboard */
+            if (fUseUnicode)
+                SetClipboardData(CF_UNICODETEXT, hGlobal);
+            else
+                SetClipboardData(CF_TEXT, hGlobal);
+
+            /* Flag that SetClipboardData has been called */
+            fSetClipboardData = FALSE;
+
+            /*
+             * NOTE: Do not try to free pszGlobalData, it is owned by
+             * Windows after the call to SetClipboardData ().
+             */
+
+ winClipboardFlushXEvents_SelectionNotify_Done:
+            /* Free allocated resources */
+            if (ppszTextList)
+                XFreeStringList(ppszTextList);
+            if (xtpText.value) {
+                XFree(xtpText.value);
+                xtpText.value = NULL;
+                xtpText.nitems = 0;
+            }
+            free(pszConvertData);
+            free(pwszUnicodeStr);
+            if (hGlobal && pszGlobalData)
+                GlobalUnlock(hGlobal);
+            if (fSetClipboardData) {
+                SetClipboardData(CF_UNICODETEXT, NULL);
+                SetClipboardData(CF_TEXT, NULL);
+            }
+            return WIN_XEVENTS_NOTIFY;
+
+        case SelectionClear:
+            winDebug("SelectionClear - doing nothing\n");
+            break;
+
+        case PropertyNotify:
+            break;
+
+        case MappingNotify:
+            break;
+
+        default:
+            if (event.type == XFixesSetSelectionOwnerNotify + xfixes_event_base) {
+                XFixesSelectionNotifyEvent *e =
+                    (XFixesSelectionNotifyEvent *) & event;
+
+                winDebug("winClipboardFlushXEvents - XFixesSetSelectionOwnerNotify\n");
+
+                /* Save selection owners for monitored selections, ignore other selections */
+                if (e->selection == XA_PRIMARY) {
+                    MonitorSelection(e, CLIP_OWN_PRIMARY);
+                }
+                else if (e->selection == atomClipboard) {
+                    MonitorSelection(e, CLIP_OWN_CLIPBOARD);
+                }
+                else
+                    break;
+
+                /* Selection is being disowned */
+                if (e->owner == None) {
+                    winDebug
+                        ("winClipboardFlushXEvents - No window, returning.\n");
+                    break;
+                }
+
+                /*
+                   XXX: there are all kinds of wacky edge cases we might need here:
+                   - we own windows clipboard, but neither PRIMARY nor CLIPBOARD have an owner, so we should disown it?
+                   - root window is taking ownership?
+                 */
+
+                /* If we are the owner of the most recently owned selection, don't go all recursive :) */
+                if ((lastOwnedSelectionIndex != CLIP_OWN_NONE) &&
+                    (s_iOwners[lastOwnedSelectionIndex] == iWindow)) {
+                    winDebug("winClipboardFlushXEvents - Ownership changed to us, aborting.\n");
+                    break;
+                }
+
+                /* Close clipboard if we have it open already (possible? correct??) */
+                if (GetOpenClipboardWindow() == hwnd) {
+                    CloseClipboard();
+                }
+
+                /* Access the Windows clipboard */
+                if (!OpenClipboard(hwnd)) {
+                    ErrorF("winClipboardFlushXEvents - OpenClipboard () failed: %08x\n",
+                           (int) GetLastError());
+                    break;
+                }
+
+                /* Take ownership of the Windows clipboard */
+                if (!EmptyClipboard()) {
+                    ErrorF("winClipboardFlushXEvents - EmptyClipboard () failed: %08x\n",
+                           (int) GetLastError());
+                    break;
+                }
+
+                /* Advertise regular text and unicode */
+                SetClipboardData(CF_UNICODETEXT, NULL);
+                SetClipboardData(CF_TEXT, NULL);
+
+                /* Release the clipboard */
+                if (!CloseClipboard()) {
+                    ErrorF("winClipboardFlushXEvents - CloseClipboard () failed: %08x\n",
+                           (int) GetLastError());
+                    break;
+                }
+            }
+            /* XFixesSelectionWindowDestroyNotifyMask */
+            /* XFixesSelectionClientCloseNotifyMask */
+            else {
+                ErrorF("winClipboardFlushXEvents - unexpected event type %d\n",
+                       event.type);
+            }
+            break;
+        }
+    }
+
+    return WIN_XEVENTS_SUCCESS;
+}
diff --git a/hw/xwin/winclipboardinit.c b/hw/xwin/winclipboardinit.c
index d16c121..2e400f6 100644
--- a/hw/xwin/winclipboardinit.c
+++ b/hw/xwin/winclipboardinit.c
@@ -36,7 +36,7 @@
 #include <pthread.h>
 
 #include "os.h"
-#include "winclipboard.h"
+#include "winclipboard/winclipboard.h"
 #include "windisplay.h"
 
 #define WIN_CLIPBOARD_RETRIES			40
diff --git a/hw/xwin/winclipboardtextconv.c b/hw/xwin/winclipboardtextconv.c
deleted file mode 100644
index fd405a0..0000000
--- a/hw/xwin/winclipboardtextconv.c
+++ /dev/null
@@ -1,147 +0,0 @@
-/*
- *Copyright (C) 2003-2004 Harold L Hunt II 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, FITNESS FOR A PARTICULAR PURPOSE AND
- *NONINFRINGEMENT. IN NO EVENT SHALL HAROLD L HUNT II 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 Harold L Hunt II
- *shall not be used in advertising or otherwise to promote the sale, use
- *or other dealings in this Software without prior written authorization
- *from Harold L Hunt II.
- *
- * Authors:	Harold L Hunt II
- */
-
-#ifdef HAVE_XWIN_CONFIG_H
-#include <xwin-config.h>
-#endif
-#include "win.h"
-#include <stdio.h>
-#include <stdlib.h>
-
-void
- winClipboardDOStoUNIX(char *pszSrc, int iLength);
-void
- winClipboardUNIXtoDOS(char **ppszData, int iLength);
-
-/*
- * Convert \r\n to \n
- *
- * NOTE: This was heavily inspired by, Cygwin's
- * winsup/cygwin/fhandler.cc/fhandler_base::read ()
- */
-
-void
-winClipboardDOStoUNIX(char *pszSrc, int iLength)
-{
-    char *pszDest = pszSrc;
-    char *pszEnd = pszSrc + iLength;
-
-    /* Loop until the last character */
-    while (pszSrc < pszEnd) {
-        /* Copy the current source character to current destination character */
-        *pszDest = *pszSrc;
-
-        /* Advance to the next source character */
-        pszSrc++;
-
-        /* Don't advance the destination character if we need to drop an \r */
-        if (*pszDest != '\r' || *pszSrc != '\n')
-            pszDest++;
-    }
-
-    /* Move the terminating null */
-    *pszDest = '\0';
-}
-
-/*
- * Convert \n to \r\n
- */
-
-void
-winClipboardUNIXtoDOS(char **ppszData, int iLength)
-{
-    int iNewlineCount = 0;
-    char *pszSrc = *ppszData;
-    char *pszEnd = pszSrc + iLength;
-    char *pszDest = NULL, *pszDestBegin = NULL;
-
-    winDebug("UNIXtoDOS () - Original data:'%s'\n", *ppszData);
-
-    /* Count \n characters without leading \r */
-    while (pszSrc < pszEnd) {
-        /* Skip ahead two character if found set of \r\n */
-        if (*pszSrc == '\r' && pszSrc + 1 < pszEnd && *(pszSrc + 1) == '\n') {
-            pszSrc += 2;
-            continue;
-        }
-
-        /* Increment the count if found naked \n */
-        if (*pszSrc == '\n') {
-            iNewlineCount++;
-        }
-
-        pszSrc++;
-    }
-
-    /* Return if no naked \n's */
-    if (iNewlineCount == 0)
-        return;
-
-    /* Allocate a new string */
-    pszDestBegin = pszDest = malloc(iLength + iNewlineCount + 1);
-
-    /* Set source pointer to beginning of data string */
-    pszSrc = *ppszData;
-
-    /* Loop through all characters in source string */
-    while (pszSrc < pszEnd) {
-        /* Copy line endings that are already valid */
-        if (*pszSrc == '\r' && pszSrc + 1 < pszEnd && *(pszSrc + 1) == '\n') {
-            *pszDest = *pszSrc;
-            *(pszDest + 1) = *(pszSrc + 1);
-            pszDest += 2;
-            pszSrc += 2;
-            continue;
-        }
-
-        /* Add \r to naked \n's */
-        if (*pszSrc == '\n') {
-            *pszDest = '\r';
-            *(pszDest + 1) = *pszSrc;
-            pszDest += 2;
-            pszSrc += 1;
-            continue;
-        }
-
-        /* Copy normal characters */
-        *pszDest = *pszSrc;
-        pszSrc++;
-        pszDest++;
-    }
-
-    /* Put terminating null at end of new string */
-    *pszDest = '\0';
-
-    /* Swap string pointers */
-    free(*ppszData);
-    *ppszData = pszDestBegin;
-
-    winDebug("UNIXtoDOS () - Final string:'%s'\n", pszDestBegin);
-}
diff --git a/hw/xwin/winclipboardthread.c b/hw/xwin/winclipboardthread.c
deleted file mode 100644
index 2641e20..0000000
--- a/hw/xwin/winclipboardthread.c
+++ /dev/null
@@ -1,504 +0,0 @@
-/*
- *Copyright (C) 2003-2004 Harold L Hunt II All Rights Reserved.
- *Copyright (C) Colin Harrison 2005-2008
- *
- *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 HAROLD L HUNT II 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).
- *
- * Authors:	Harold L Hunt II
- *              Colin Harrison
- */
-
-#ifdef HAVE_XWIN_CONFIG_H
-#include <xwin-config.h>
-#else
-#define HAS_WINSOCK 1
-#endif
-#include <sys/types.h>
-#include <signal.h>
-#include "winclipboard.h"
-#include "windisplay.h"
-#ifdef __CYGWIN__
-#include <errno.h>
-#endif
-#include "misc.h"
-#include <X11/extensions/Xfixes.h>
-
-#define WIN_CONNECT_RETRIES			40
-#define WIN_CONNECT_DELAY			4
-
-#define WIN_CLIPBOARD_WINDOW_CLASS		"xwinclip"
-#define WIN_CLIPBOARD_WINDOW_TITLE		"xwinclip"
-
-/*
- * References to external symbols
- */
-
-extern Bool g_fUnicodeClipboard;
-extern Bool g_fClipboard;
-
-/*
- * Global variables
- */
-
-static HWND g_hwndClipboard = NULL;
-static jmp_buf g_jmpEntry;
-static XIOErrorHandler g_winClipboardOldIOErrorHandler;
-static pthread_t g_winClipboardProcThread;
-
-Bool g_fUseUnicode = FALSE;
-int xfixes_event_base;
-int xfixes_error_base;
-
-/*
- * Local function prototypes
- */
-
-static HWND
-winClipboardCreateMessagingWindow(Display *pDisplay, Window iWindow);
-
-static int
- winClipboardErrorHandler(Display * pDisplay, XErrorEvent * pErr);
-
-static int
- winClipboardIOErrorHandler(Display * pDisplay);
-
-/*
- * Main thread function
- */
-
-void *
-winClipboardProc(char *szDisplay)
-{
-    Atom atomClipboard;
-    int iReturn;
-    HWND hwnd = NULL;
-    int iConnectionNumber = 0;
-
-#ifdef HAS_DEVWINDOWS
-    int fdMessageQueue = 0;
-#else
-    struct timeval tvTimeout;
-#endif
-    fd_set fdsRead;
-    int iMaxDescriptor;
-    Display *pDisplay = NULL;
-    Window iWindow = None;
-    int iRetries;
-    Bool fUseUnicode;
-    int iSelectError;
-
-    winDebug("winClipboardProc - Hello\n");
-
-    /* Do we use Unicode clipboard? */
-    fUseUnicode = g_fUnicodeClipboard;
-
-    /* Save the Unicode support flag in a global */
-    g_fUseUnicode = fUseUnicode;
-
-    /* Allow multiple threads to access Xlib */
-    if (XInitThreads() == 0) {
-        ErrorF("winClipboardProc - XInitThreads failed.\n");
-        goto winClipboardProc_Exit;
-    }
-
-    /* See if X supports the current locale */
-    if (XSupportsLocale() == False) {
-        ErrorF("winClipboardProc - Warning: Locale not supported by X.\n");
-    }
-
-    /* Set error handler */
-    XSetErrorHandler(winClipboardErrorHandler);
-    g_winClipboardProcThread = pthread_self();
-    g_winClipboardOldIOErrorHandler =
-        XSetIOErrorHandler(winClipboardIOErrorHandler);
-
-    /* Set jump point for Error exits */
-    iReturn = setjmp(g_jmpEntry);
-
-    /* Check if we should continue operations */
-    if (iReturn != WIN_JMP_ERROR_IO && iReturn != WIN_JMP_OKAY) {
-        /* setjmp returned an unknown value, exit */
-        ErrorF("winClipboardProc - setjmp returned: %d exiting\n", iReturn);
-        goto winClipboardProc_Exit;
-    }
-    else if (iReturn == WIN_JMP_ERROR_IO) {
-        /* TODO: Cleanup the Win32 window and free any allocated memory */
-        ErrorF("winClipboardProc - setjmp returned for IO Error Handler.\n");
-        goto winClipboardProc_Done;
-    }
-
-    /* Initialize retry count */
-    iRetries = 0;
-
-
-    /* Open the X display */
-    do {
-        pDisplay = XOpenDisplay(szDisplay);
-        if (pDisplay == NULL) {
-            ErrorF("winClipboardProc - Could not open display, "
-                   "try: %d, sleeping: %d\n", iRetries + 1, WIN_CONNECT_DELAY);
-            ++iRetries;
-            sleep(WIN_CONNECT_DELAY);
-            continue;
-        }
-        else
-            break;
-    }
-    while (pDisplay == NULL && iRetries < WIN_CONNECT_RETRIES);
-
-    /* Make sure that the display opened */
-    if (pDisplay == NULL) {
-        ErrorF("winClipboardProc - Failed opening the display, giving up\n");
-        goto winClipboardProc_Done;
-    }
-
-    ErrorF("winClipboardProc - XOpenDisplay () returned and "
-           "successfully opened the display.\n");
-
-    /* Get our connection number */
-    iConnectionNumber = ConnectionNumber(pDisplay);
-
-#ifdef HAS_DEVWINDOWS
-    /* Open a file descriptor for the windows message queue */
-    fdMessageQueue = open(WIN_MSG_QUEUE_FNAME, O_RDONLY);
-    if (fdMessageQueue == -1) {
-        ErrorF("winClipboardProc - Failed opening %s\n", WIN_MSG_QUEUE_FNAME);
-        goto winClipboardProc_Done;
-    }
-
-    /* Find max of our file descriptors */
-    iMaxDescriptor = max(fdMessageQueue, iConnectionNumber) + 1;
-#else
-    iMaxDescriptor = iConnectionNumber + 1;
-#endif
-
-    if (!XFixesQueryExtension(pDisplay, &xfixes_event_base, &xfixes_error_base))
-      ErrorF ("winClipboardProc - XFixes extension not present\n");
-
-    /* Create atom */
-    atomClipboard = XInternAtom(pDisplay, "CLIPBOARD", False);
-
-    /* Create a messaging window */
-    iWindow = XCreateSimpleWindow(pDisplay,
-                                  DefaultRootWindow(pDisplay),
-                                  1, 1,
-                                  500, 500,
-                                  0,
-                                  BlackPixel(pDisplay, 0),
-                                  BlackPixel(pDisplay, 0));
-    if (iWindow == 0) {
-        ErrorF("winClipboardProc - Could not create an X window.\n");
-        goto winClipboardProc_Done;
-    }
-
-    XStoreName(pDisplay, iWindow, "xwinclip");
-
-    /* Select event types to watch */
-    if (XSelectInput(pDisplay, iWindow, PropertyChangeMask) == BadWindow)
-        ErrorF("winClipboardProc - XSelectInput generated BadWindow "
-               "on messaging window\n");
-
-    XFixesSelectSelectionInput (pDisplay,
-                                iWindow,
-                                XA_PRIMARY,
-                                XFixesSetSelectionOwnerNotifyMask |
-                                XFixesSelectionWindowDestroyNotifyMask |
-                                XFixesSelectionClientCloseNotifyMask);
-
-    XFixesSelectSelectionInput (pDisplay,
-                                iWindow,
-                                XInternAtom (pDisplay, "CLIPBOARD", False),
-                                XFixesSetSelectionOwnerNotifyMask |
-                                XFixesSelectionWindowDestroyNotifyMask |
-                                XFixesSelectionClientCloseNotifyMask);
-
-
-    /* Initialize monitored selection state */
-    winClipboardInitMonitoredSelections();
-    /* Create Windows messaging window */
-    hwnd = winClipboardCreateMessagingWindow(pDisplay, iWindow);
-
-    /* Save copy of HWND */
-    g_hwndClipboard = hwnd;
-
-    /* Assert ownership of selections if Win32 clipboard is owned */
-    if (NULL != GetClipboardOwner()) {
-        /* PRIMARY */
-        iReturn = XSetSelectionOwner(pDisplay, XA_PRIMARY,
-                                     iWindow, CurrentTime);
-        if (iReturn == BadAtom || iReturn == BadWindow ||
-            XGetSelectionOwner(pDisplay, XA_PRIMARY) != iWindow) {
-            ErrorF("winClipboardProc - Could not set PRIMARY owner\n");
-            goto winClipboardProc_Done;
-        }
-
-        /* CLIPBOARD */
-        iReturn = XSetSelectionOwner(pDisplay, atomClipboard,
-                                     iWindow, CurrentTime);
-        if (iReturn == BadAtom || iReturn == BadWindow ||
-            XGetSelectionOwner(pDisplay, atomClipboard) != iWindow) {
-            ErrorF("winClipboardProc - Could not set CLIPBOARD owner\n");
-            goto winClipboardProc_Done;
-        }
-    }
-
-    /* Pre-flush X events */
-    /* 
-     * NOTE: Apparently you'll freeze if you don't do this,
-     *       because there may be events in local data structures
-     *       already.
-     */
-    winClipboardFlushXEvents(hwnd, iWindow, pDisplay, fUseUnicode);
-
-    /* Pre-flush Windows messages */
-    if (!winClipboardFlushWindowsMessageQueue(hwnd)) {
-        ErrorF("winClipboardProc - winClipboardFlushWindowsMessageQueue failed\n");
-    }
-
-    /* Loop for X events */
-    while (1) {
-        /* Setup the file descriptor set */
-        /*
-         * NOTE: You have to do this before every call to select
-         *       because select modifies the mask to indicate
-         *       which descriptors are ready.
-         */
-        FD_ZERO(&fdsRead);
-        FD_SET(iConnectionNumber, &fdsRead);
-#ifdef HAS_DEVWINDOWS
-        FD_SET(fdMessageQueue, &fdsRead);
-#else
-        tvTimeout.tv_sec = 0;
-        tvTimeout.tv_usec = 100;
-#endif
-
-        /* Wait for a Windows event or an X event */
-        iReturn = select(iMaxDescriptor,        /* Highest fds number */
-                         &fdsRead,      /* Read mask */
-                         NULL,  /* No write mask */
-                         NULL,  /* No exception mask */
-#ifdef HAS_DEVWINDOWS
-                         NULL   /* No timeout */
-#else
-                         &tvTimeout     /* Set timeout */
-#endif
-            );
-
-#ifndef HAS_WINSOCK
-        iSelectError = errno;
-#else
-        iSelectError = WSAGetLastError();
-#endif
-
-        if (iReturn < 0) {
-#ifndef HAS_WINSOCK
-            if (iSelectError == EINTR)
-#else
-            if (iSelectError == WSAEINTR)
-#endif
-                continue;
-
-            ErrorF("winClipboardProc - Call to select () failed: %d.  "
-                   "Bailing.\n", iReturn);
-            break;
-        }
-
-        /* Branch on which descriptor became active */
-        if (FD_ISSET(iConnectionNumber, &fdsRead)) {
-            /* Process X events */
-            winClipboardFlushXEvents(hwnd, iWindow, pDisplay, fUseUnicode);
-        }
-
-#ifdef HAS_DEVWINDOWS
-        /* Check for Windows event ready */
-        if (FD_ISSET(fdMessageQueue, &fdsRead))
-#else
-        if (1)
-#endif
-        {
-            /* Process Windows messages */
-            if (!winClipboardFlushWindowsMessageQueue(hwnd)) {
-                ErrorF("winClipboardProc - "
-                       "winClipboardFlushWindowsMessageQueue trapped "
-                       "WM_QUIT message, exiting main loop.\n");
-                break;
-            }
-        }
-    }
-
- winClipboardProc_Exit:
-    /* disable the clipboard, which means the thread will die */
-    g_fClipboard = FALSE;
-
- winClipboardProc_Done:
-    /* Close our Windows window */
-    if (g_hwndClipboard) {
-        winClipboardWindowDestroy();
-    }
-
-    /* Close our X window */
-    if (pDisplay && iWindow) {
-        iReturn = XDestroyWindow(pDisplay, iWindow);
-        if (iReturn == BadWindow)
-            ErrorF("winClipboardProc - XDestroyWindow returned BadWindow.\n");
-        else
-            ErrorF("winClipboardProc - XDestroyWindow succeeded.\n");
-    }
-
-#ifdef HAS_DEVWINDOWS
-    /* Close our Win32 message handle */
-    if (fdMessageQueue)
-        close(fdMessageQueue);
-#endif
-
-#if 0
-    /*
-     * FIXME: XCloseDisplay hangs if we call it, as of 2004/03/26.  The
-     * XSync and XSelectInput calls did not help.
-     */
-
-    /* Discard any remaining events */
-    XSync(pDisplay, TRUE);
-
-    /* Select event types to watch */
-    XSelectInput(pDisplay, DefaultRootWindow(pDisplay), None);
-
-    /* Close our X display */
-    if (pDisplay) {
-        XCloseDisplay(pDisplay);
-    }
-#endif
-
-    /* global clipboard variable reset */
-    g_hwndClipboard = NULL;
-
-    return NULL;
-}
-
-/*
- * Create the Windows window that we use to receive Windows messages
- */
-
-static HWND
-winClipboardCreateMessagingWindow(Display *pDisplay, Window iWindow)
-{
-    WNDCLASSEX wc;
-    ClipboardWindowCreationParams cwcp;
-    HWND hwnd;
-
-    /* Setup our window class */
-    wc.cbSize = sizeof(WNDCLASSEX);
-    wc.style = CS_HREDRAW | CS_VREDRAW;
-    wc.lpfnWndProc = winClipboardWindowProc;
-    wc.cbClsExtra = 0;
-    wc.cbWndExtra = 0;
-    wc.hInstance = GetModuleHandle(NULL);
-    wc.hIcon = 0;
-    wc.hCursor = 0;
-    wc.hbrBackground = (HBRUSH) GetStockObject(WHITE_BRUSH);
-    wc.lpszMenuName = NULL;
-    wc.lpszClassName = WIN_CLIPBOARD_WINDOW_CLASS;
-    wc.hIconSm = 0;
-    RegisterClassEx(&wc);
-
-    /* Information to be passed to WM_CREATE */
-    cwcp.pClipboardDisplay = pDisplay;
-    cwcp.iClipboardWindow = iWindow;
-
-    /* Create the window */
-    hwnd = CreateWindowExA(0,   /* Extended styles */
-                           WIN_CLIPBOARD_WINDOW_CLASS,  /* Class name */
-                           WIN_CLIPBOARD_WINDOW_TITLE,  /* Window name */
-                           WS_OVERLAPPED,       /* Not visible anyway */
-                           CW_USEDEFAULT,       /* Horizontal position */
-                           CW_USEDEFAULT,       /* Vertical position */
-                           CW_USEDEFAULT,       /* Right edge */
-                           CW_USEDEFAULT,       /* Bottom edge */
-                           (HWND) NULL, /* No parent or owner window */
-                           (HMENU) NULL,        /* No menu */
-                           GetModuleHandle(NULL),       /* Instance handle */
-                           &cwcp);       /* Creation data */
-    assert(hwnd != NULL);
-
-    /* I'm not sure, but we may need to call this to start message processing */
-    ShowWindow(hwnd, SW_HIDE);
-
-    /* Similarly, we may need a call to this even though we don't paint */
-    UpdateWindow(hwnd);
-
-    return hwnd;
-}
-
-/*
- * winClipboardErrorHandler - Our application specific error handler
- */
-
-static int
-winClipboardErrorHandler(Display * pDisplay, XErrorEvent * pErr)
-{
-    char pszErrorMsg[100];
-
-    XGetErrorText(pDisplay, pErr->error_code, pszErrorMsg, sizeof(pszErrorMsg));
-    ErrorF("winClipboardErrorHandler - ERROR: \n\t%s\n"
-           "\tSerial: %lu, Request Code: %d, Minor Code: %d\n",
-           pszErrorMsg, pErr->serial, pErr->request_code, pErr->minor_code);
-    return 0;
-}
-
-/*
- * winClipboardIOErrorHandler - Our application specific IO error handler
- */
-
-static int
-winClipboardIOErrorHandler(Display * pDisplay)
-{
-    ErrorF("winClipboardIOErrorHandler!\n");
-
-    if (pthread_equal(pthread_self(), g_winClipboardProcThread)) {
-        /* Restart at the main entry point */
-        longjmp(g_jmpEntry, WIN_JMP_ERROR_IO);
-    }
-
-    if (g_winClipboardOldIOErrorHandler)
-        g_winClipboardOldIOErrorHandler(pDisplay);
-
-    return 0;
-}
-
-void
-winClipboardWindowDestroy(void)
-{
-  if (g_hwndClipboard) {
-    SendMessage(g_hwndClipboard, WM_DESTROY, 0, 0);
-  }
-}
-
-void
-winFixClipboardChain(void)
-{
-  if (g_hwndClipboard) {
-    PostMessage(g_hwndClipboard, WM_WM_REINIT, 0, 0);
-  }
-}
diff --git a/hw/xwin/winclipboardwndproc.c b/hw/xwin/winclipboardwndproc.c
deleted file mode 100644
index 459170f..0000000
--- a/hw/xwin/winclipboardwndproc.c
+++ /dev/null
@@ -1,524 +0,0 @@
-/*
- *Copyright (C) 2003-2004 Harold L Hunt II All Rights Reserved.
- *Copyright (C) Colin Harrison 2005-2008
- *
- *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 HAROLD L HUNT II 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).
- *
- * Authors:	Harold L Hunt II
- *              Colin Harrison
- */
-
-#ifdef HAVE_XWIN_CONFIG_H
-#include <xwin-config.h>
-#endif
-#include <sys/types.h>
-#include <sys/time.h>
-#include "winclipboard.h"
-#include "misc.h"
-
-/*
- * Constants
- */
-
-#define WIN_POLL_TIMEOUT	1
-
-
-/*
- * Process X events up to specified timeout
- */
-
-static int
-winProcessXEventsTimeout(HWND hwnd, int iWindow, Display * pDisplay,
-                         Bool fUseUnicode, int iTimeoutSec)
-{
-    int iConnNumber;
-    struct timeval tv;
-    int iReturn;
-    DWORD dwStopTime = GetTickCount() + iTimeoutSec * 1000;
-
-    winDebug("winProcessXEventsTimeout () - pumping X events for %d seconds\n",
-             iTimeoutSec);
-
-    /* Get our connection number */
-    iConnNumber = ConnectionNumber(pDisplay);
-
-    /* Loop for X events */
-    while (1) {
-        fd_set fdsRead;
-        long remainingTime;
-
-        /* We need to ensure that all pending events are processed */
-        XSync(pDisplay, FALSE);
-
-        /* Setup the file descriptor set */
-        FD_ZERO(&fdsRead);
-        FD_SET(iConnNumber, &fdsRead);
-
-        /* Adjust timeout */
-        remainingTime = dwStopTime - GetTickCount();
-        tv.tv_sec = remainingTime / 1000;
-        tv.tv_usec = (remainingTime % 1000) * 1000;
-        winDebug("winProcessXEventsTimeout () - %d milliseconds left\n",
-                 remainingTime);
-
-        /* Break out if no time left */
-        if (remainingTime <= 0)
-            return WIN_XEVENTS_SUCCESS;
-
-        /* Wait for an X event */
-        iReturn = select(iConnNumber + 1,       /* Highest fds number */
-                         &fdsRead,      /* Read mask */
-                         NULL,  /* No write mask */
-                         NULL,  /* No exception mask */
-                         &tv);  /* Timeout */
-        if (iReturn < 0) {
-            ErrorF("winProcessXEventsTimeout - Call to select () failed: %d.  "
-                   "Bailing.\n", iReturn);
-            break;
-        }
-
-        /* Branch on which descriptor became active */
-        if (FD_ISSET(iConnNumber, &fdsRead)) {
-            /* Process X events */
-            /* Exit when we see that server is shutting down */
-            iReturn = winClipboardFlushXEvents(hwnd,
-                                               iWindow, pDisplay, fUseUnicode);
-
-            winDebug
-                ("winProcessXEventsTimeout () - winClipboardFlushXEvents returned %d\n",
-                 iReturn);
-
-            if (WIN_XEVENTS_NOTIFY == iReturn) {
-                /* Bail out if notify processed */
-                return iReturn;
-            }
-        }
-        else {
-            winDebug("winProcessXEventsTimeout - Spurious wake\n");
-        }
-    }
-
-    return WIN_XEVENTS_SUCCESS;
-}
-
-/*
- * Process a given Windows message
- */
-
-LRESULT CALLBACK
-winClipboardWindowProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
-{
-    static HWND s_hwndNextViewer;
-    static Bool s_fCBCInitialized;
-    static Display *pDisplay;
-    static Window iWindow;
-
-    /* Branch on message type */
-    switch (message) {
-    case WM_DESTROY:
-    {
-        winDebug("winClipboardWindowProc - WM_DESTROY\n");
-
-        /* Remove ourselves from the clipboard chain */
-        ChangeClipboardChain(hwnd, s_hwndNextViewer);
-
-        s_hwndNextViewer = NULL;
-
-        PostQuitMessage(0);
-    }
-        return 0;
-
-    case WM_CREATE:
-    {
-        HWND first, next;
-        DWORD error_code = 0;
-        ClipboardWindowCreationParams *cwcp = (ClipboardWindowCreationParams *)((CREATESTRUCT *)lParam)->lpCreateParams;
-
-        winDebug("winClipboardWindowProc - WM_CREATE\n");
-
-        pDisplay = cwcp->pClipboardDisplay;
-        iWindow = cwcp->iClipboardWindow;
-
-        first = GetClipboardViewer();   /* Get handle to first viewer in chain. */
-        if (first == hwnd)
-            return 0;           /* Make sure it's not us! */
-        /* Add ourselves to the clipboard viewer chain */
-        next = SetClipboardViewer(hwnd);
-        error_code = GetLastError();
-        if (SUCCEEDED(error_code) && (next == first))   /* SetClipboardViewer must have succeeded, and the handle */
-            s_hwndNextViewer = next;    /* it returned must have been the first window in the chain */
-        else
-            s_fCBCInitialized = FALSE;
-    }
-        return 0;
-
-    case WM_CHANGECBCHAIN:
-    {
-        winDebug("winClipboardWindowProc - WM_CHANGECBCHAIN: wParam(%x) "
-                 "lParam(%x) s_hwndNextViewer(%x)\n",
-                 wParam, lParam, s_hwndNextViewer);
-
-        if ((HWND) wParam == s_hwndNextViewer) {
-            s_hwndNextViewer = (HWND) lParam;
-            if (s_hwndNextViewer == hwnd) {
-                s_hwndNextViewer = NULL;
-                winErrorFVerb(1, "winClipboardWindowProc - WM_CHANGECBCHAIN: "
-                              "attempted to set next window to ourselves.");
-            }
-        }
-        else if (s_hwndNextViewer)
-            SendMessage(s_hwndNextViewer, message, wParam, lParam);
-
-    }
-        winDebug("winClipboardWindowProc - WM_CHANGECBCHAIN: Exit\n");
-        return 0;
-
-    case WM_WM_REINIT:
-    {
-        /* Ensure that we're in the clipboard chain.  Some apps,
-         * WinXP's remote desktop for one, don't play nice with the
-         * chain.  This message is called whenever we receive a
-         * WM_ACTIVATEAPP message to ensure that we continue to
-         * receive clipboard messages.
-         *
-         * It might be possible to detect if we're still in the chain
-         * by calling SendMessage (GetClipboardViewer(),
-         * WM_DRAWCLIPBOARD, 0, 0); and then seeing if we get the
-         * WM_DRAWCLIPBOARD message.  That, however, might be more
-         * expensive than just putting ourselves back into the chain.
-         */
-
-        HWND first, next;
-        DWORD error_code = 0;
-
-        winDebug("winClipboardWindowProc - WM_WM_REINIT: Enter\n");
-
-        first = GetClipboardViewer();   /* Get handle to first viewer in chain. */
-        if (first == hwnd)
-            return 0;           /* Make sure it's not us! */
-        winDebug("  WM_WM_REINIT: Replacing us(%x) with %x at head "
-                 "of chain\n", hwnd, s_hwndNextViewer);
-        s_fCBCInitialized = FALSE;
-        ChangeClipboardChain(hwnd, s_hwndNextViewer);
-        s_hwndNextViewer = NULL;
-        s_fCBCInitialized = FALSE;
-        winDebug("  WM_WM_REINIT: Putting us back at head of chain.\n");
-        first = GetClipboardViewer();   /* Get handle to first viewer in chain. */
-        if (first == hwnd)
-            return 0;           /* Make sure it's not us! */
-        next = SetClipboardViewer(hwnd);
-        error_code = GetLastError();
-        if (SUCCEEDED(error_code) && (next == first))   /* SetClipboardViewer must have succeeded, and the handle */
-            s_hwndNextViewer = next;    /* it returned must have been the first window in the chain */
-        else
-            s_fCBCInitialized = FALSE;
-    }
-        winDebug("winClipboardWindowProc - WM_WM_REINIT: Exit\n");
-        return 0;
-
-    case WM_DRAWCLIPBOARD:
-    {
-        static Atom atomClipboard;
-        static int generation;
-        static Bool s_fProcessingDrawClipboard = FALSE;
-        int iReturn;
-
-        winDebug("winClipboardWindowProc - WM_DRAWCLIPBOARD: Enter\n");
-
-        if (generation != serverGeneration) {
-            generation = serverGeneration;
-            atomClipboard = XInternAtom(pDisplay, "CLIPBOARD", False);
-        }
-
-        /*
-         * We've occasionally seen a loop in the clipboard chain.
-         * Try and fix it on the first hint of recursion.
-         */
-        if (!s_fProcessingDrawClipboard) {
-            s_fProcessingDrawClipboard = TRUE;
-        }
-        else {
-            /* Attempt to break the nesting by getting out of the chain, twice?, and then fix and bail */
-            s_fCBCInitialized = FALSE;
-            ChangeClipboardChain(hwnd, s_hwndNextViewer);
-            winFixClipboardChain();
-            winErrorFVerb(1, "winClipboardWindowProc - WM_DRAWCLIPBOARD - "
-                          "Nested calls detected.  Re-initing.\n");
-            winDebug("winClipboardWindowProc - WM_DRAWCLIPBOARD: Exit\n");
-            s_fProcessingDrawClipboard = FALSE;
-            return 0;
-        }
-
-        /* Bail on first message */
-        if (!s_fCBCInitialized) {
-            s_fCBCInitialized = TRUE;
-            s_fProcessingDrawClipboard = FALSE;
-            winDebug("winClipboardWindowProc - WM_DRAWCLIPBOARD: Exit\n");
-            return 0;
-        }
-
-        /*
-         * NOTE: We cannot bail out when NULL == GetClipboardOwner ()
-         * because some applications deal with the clipboard in a manner
-         * that causes the clipboard owner to be NULL when they are in
-         * fact taking ownership.  One example of this is the Win32
-         * native compile of emacs.
-         */
-
-        /* Bail when we still own the clipboard */
-        if (hwnd == GetClipboardOwner()) {
-
-            winDebug("winClipboardWindowProc - WM_DRAWCLIPBOARD - "
-                     "We own the clipboard, returning.\n");
-            winDebug("winClipboardWindowProc - WM_DRAWCLIPBOARD: Exit\n");
-            s_fProcessingDrawClipboard = FALSE;
-            if (s_hwndNextViewer)
-                SendMessage(s_hwndNextViewer, message, wParam, lParam);
-            return 0;
-        }
-
-        /*
-         * Do not take ownership of the X11 selections when something
-         * other than CF_TEXT or CF_UNICODETEXT has been copied
-         * into the Win32 clipboard.
-         */
-        if (!IsClipboardFormatAvailable(CF_TEXT)
-            && !IsClipboardFormatAvailable(CF_UNICODETEXT)) {
-
-            winDebug("winClipboardWindowProc - WM_DRAWCLIPBOARD - "
-                     "Clipboard does not contain CF_TEXT nor "
-                     "CF_UNICODETEXT.\n");
-
-            /*
-             * We need to make sure that the X Server has processed
-             * previous XSetSelectionOwner messages.
-             */
-            XSync(pDisplay, FALSE);
-
-            winDebug("winClipboardWindowProc - XSync done.\n");
-
-            /* Release PRIMARY selection if owned */
-            iReturn = XGetSelectionOwner(pDisplay, XA_PRIMARY);
-            if (iReturn == iWindow) {
-                winDebug("winClipboardWindowProc - WM_DRAWCLIPBOARD - "
-                         "PRIMARY selection is owned by us.\n");
-                XSetSelectionOwner(pDisplay, XA_PRIMARY, None, CurrentTime);
-            }
-            else if (BadWindow == iReturn || BadAtom == iReturn)
-                winErrorFVerb(1, "winClipboardWindowProc - WM_DRAWCLIPBOARD - "
-                              "XGetSelection failed for PRIMARY: %d\n",
-                              iReturn);
-
-            /* Release CLIPBOARD selection if owned */
-            iReturn = XGetSelectionOwner(pDisplay, atomClipboard);
-            if (iReturn == iWindow) {
-                winDebug("winClipboardWindowProc - WM_DRAWCLIPBOARD - "
-                         "CLIPBOARD selection is owned by us.\n");
-                XSetSelectionOwner(pDisplay, atomClipboard, None, CurrentTime);
-            }
-            else if (BadWindow == iReturn || BadAtom == iReturn)
-                winErrorFVerb(1, "winClipboardWindowProc - WM_DRAWCLIPBOARD - "
-                              "XGetSelection failed for CLIPBOARD: %d\n",
-                              iReturn);
-
-            winDebug("winClipboardWindowProc - WM_DRAWCLIPBOARD: Exit\n");
-            s_fProcessingDrawClipboard = FALSE;
-            if (s_hwndNextViewer)
-                SendMessage(s_hwndNextViewer, message, wParam, lParam);
-            return 0;
-        }
-
-        /* Reassert ownership of PRIMARY */
-        iReturn = XSetSelectionOwner(pDisplay,
-                                     XA_PRIMARY, iWindow, CurrentTime);
-        if (iReturn == BadAtom || iReturn == BadWindow ||
-            XGetSelectionOwner(pDisplay, XA_PRIMARY) != iWindow) {
-            winErrorFVerb(1, "winClipboardWindowProc - WM_DRAWCLIPBOARD - "
-                          "Could not reassert ownership of PRIMARY\n");
-        }
-        else {
-            winDebug("winClipboardWindowProc - WM_DRAWCLIPBOARD - "
-                     "Reasserted ownership of PRIMARY\n");
-        }
-
-        /* Reassert ownership of the CLIPBOARD */
-        iReturn = XSetSelectionOwner(pDisplay,
-                                     atomClipboard, iWindow, CurrentTime);
-
-        if (iReturn == BadAtom || iReturn == BadWindow ||
-            XGetSelectionOwner(pDisplay, atomClipboard) != iWindow) {
-            winErrorFVerb(1, "winClipboardWindowProc - WM_DRAWCLIPBOARD - "
-                          "Could not reassert ownership of CLIPBOARD\n");
-        }
-        else {
-            winDebug("winClipboardWindowProc - WM_DRAWCLIPBOARD - "
-                     "Reasserted ownership of CLIPBOARD\n");
-        }
-
-        /* Flush the pending SetSelectionOwner event now */
-        XFlush(pDisplay);
-
-        s_fProcessingDrawClipboard = FALSE;
-    }
-        winDebug("winClipboardWindowProc - WM_DRAWCLIPBOARD: Exit\n");
-        /* Pass the message on the next window in the clipboard viewer chain */
-        if (s_hwndNextViewer)
-            SendMessage(s_hwndNextViewer, message, wParam, lParam);
-        return 0;
-
-    case WM_DESTROYCLIPBOARD:
-        /*
-         * NOTE: Intentionally do nothing.
-         * Changes in the Win32 clipboard are handled by WM_DRAWCLIPBOARD
-         * above.  We only process this message to conform to the specs
-         * for delayed clipboard rendering in Win32.  You might think
-         * that we need to release ownership of the X11 selections, but
-         * we do not, because a WM_DRAWCLIPBOARD message will closely
-         * follow this message and reassert ownership of the X11
-         * selections, handling the issue for us.
-         */
-        winDebug("winClipboardWindowProc - WM_DESTROYCLIPBOARD - Ignored.\n");
-        return 0;
-
-    case WM_RENDERFORMAT:
-    case WM_RENDERALLFORMATS:
-    {
-        int iReturn;
-        Bool fConvertToUnicode;
-
-        winDebug("winClipboardWindowProc - WM_RENDER*FORMAT - Hello.\n");
-
-        /* Flag whether to convert to Unicode or not */
-        if (message == WM_RENDERALLFORMATS)
-            fConvertToUnicode = FALSE;
-        else
-            fConvertToUnicode = (CF_UNICODETEXT == wParam);
-
-        /* Request the selection contents */
-        iReturn = XConvertSelection(pDisplay,
-                                    winClipboardGetLastOwnedSelectionAtom(),
-                                    XInternAtom(pDisplay,
-                                                "COMPOUND_TEXT", False),
-                                    XInternAtom(pDisplay,
-                                                "CYGX_CUT_BUFFER", False),
-                                    iWindow, CurrentTime);
-        if (iReturn == BadAtom || iReturn == BadWindow) {
-            winErrorFVerb(1, "winClipboardWindowProc - WM_RENDER*FORMAT - "
-                          "XConvertSelection () failed\n");
-            break;
-        }
-
-        /* Special handling for WM_RENDERALLFORMATS */
-        if (message == WM_RENDERALLFORMATS) {
-            /* We must open and empty the clipboard */
-
-            /* Close clipboard if we have it open already */
-            if (GetOpenClipboardWindow() == hwnd) {
-                CloseClipboard();
-            }
-
-            if (!OpenClipboard(hwnd)) {
-                winErrorFVerb(1, "winClipboardWindowProc - WM_RENDER*FORMATS - "
-                              "OpenClipboard () failed: %08x\n",
-                              GetLastError());
-                break;
-            }
-
-            if (!EmptyClipboard()) {
-                winErrorFVerb(1, "winClipboardWindowProc - WM_RENDER*FORMATS - "
-                              "EmptyClipboard () failed: %08x\n",
-                              GetLastError());
-                break;
-            }
-        }
-
-        /* Process the SelectionNotify event */
-        iReturn = winProcessXEventsTimeout(hwnd,
-                                           iWindow,
-                                           pDisplay,
-                                           fConvertToUnicode, WIN_POLL_TIMEOUT);
-
-        /*
-         * The last call to winProcessXEventsTimeout
-         * from above had better have seen a notify event, or else we
-         * are dealing with a buggy or old X11 app.  In these cases we
-         * have to paste some fake data to the Win32 clipboard to
-         * satisfy the requirement that we write something to it.
-         */
-        if (WIN_XEVENTS_NOTIFY != iReturn) {
-            /* Paste no data, to satisfy required call to SetClipboardData */
-            SetClipboardData(CF_UNICODETEXT, NULL);
-            SetClipboardData(CF_TEXT, NULL);
-
-            ErrorF
-                ("winClipboardWindowProc - timed out waiting for WIN_XEVENTS_NOTIFY\n");
-        }
-
-        /* Special handling for WM_RENDERALLFORMATS */
-        if (message == WM_RENDERALLFORMATS) {
-            /* We must close the clipboard */
-
-            if (!CloseClipboard()) {
-                winErrorFVerb(1,
-                              "winClipboardWindowProc - WM_RENDERALLFORMATS - "
-                              "CloseClipboard () failed: %08x\n",
-                              GetLastError());
-                break;
-            }
-        }
-
-        winDebug("winClipboardWindowProc - WM_RENDER*FORMAT - Returning.\n");
-        return 0;
-    }
-    }
-
-    /* Let Windows perform default processing for unhandled messages */
-    return DefWindowProc(hwnd, message, wParam, lParam);
-}
-
-/*
- * Process any pending Windows messages
- */
-
-BOOL
-winClipboardFlushWindowsMessageQueue(HWND hwnd)
-{
-    MSG msg;
-
-    /* Flush the messaging window queue */
-    /* NOTE: Do not pass the hwnd of our messaging window to PeekMessage,
-     * as this will filter out many non-window-specific messages that
-     * are sent to our thread, such as WM_QUIT.
-     */
-    while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) {
-        /* Dispatch the message if not WM_QUIT */
-        if (msg.message == WM_QUIT)
-            return FALSE;
-        else
-            DispatchMessage(&msg);
-    }
-
-    return TRUE;
-}
diff --git a/hw/xwin/winclipboardxevents.c b/hw/xwin/winclipboardxevents.c
deleted file mode 100644
index a792467..0000000
--- a/hw/xwin/winclipboardxevents.c
+++ /dev/null
@@ -1,862 +0,0 @@
-/*
- *Copyright (C) 2003-2004 Harold L Hunt II All Rights Reserved.
- *Copyright (C) Colin Harrison 2005-2008
- *
- *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 HAROLD L HUNT II 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).
- *
- * Authors:	Harold L Hunt II
- *              Colin Harrison
- */
-
-#ifdef HAVE_XWIN_CONFIG_H
-#include <xwin-config.h>
-#endif
-
-#include "winclipboard.h"
-#include "misc.h"
-#include <X11/extensions/Xfixes.h>
-
-/*
- * Constants
- */
-
-#define CLIP_NUM_SELECTIONS		2
-#define CLIP_OWN_NONE     		-1
-#define CLIP_OWN_PRIMARY		0
-#define CLIP_OWN_CLIPBOARD		1
-
-/*
- * Global variables
- */
-
-extern int xfixes_event_base;
-
-/*
- * Local variables
- */
-
-static Window s_iOwners[CLIP_NUM_SELECTIONS] = { None, None };
-static const char *szSelectionNames[CLIP_NUM_SELECTIONS] =
-    { "PRIMARY", "CLIPBOARD" };
-
-static unsigned int lastOwnedSelectionIndex = CLIP_OWN_NONE;
-static Atom atomClipboard = None;
-
-static void
-MonitorSelection(XFixesSelectionNotifyEvent * e, unsigned int i)
-{
-    /* Look for owned -> not owned transition */
-    if (None == e->owner && None != s_iOwners[i]) {
-        unsigned int other_index;
-
-        winDebug("MonitorSelection - %s - Going from owned to not owned.\n",
-                 szSelectionNames[i]);
-
-        /* If this selection is not owned, the other monitored selection must be the most
-           recently owned, if it is owned at all */
-        if (i == CLIP_OWN_PRIMARY)
-            other_index = CLIP_OWN_CLIPBOARD;
-        if (i == CLIP_OWN_CLIPBOARD)
-            other_index = CLIP_OWN_PRIMARY;
-        if (None != s_iOwners[other_index])
-            lastOwnedSelectionIndex = other_index;
-        else
-            lastOwnedSelectionIndex = CLIP_OWN_NONE;
-    }
-
-    /* Save last owned selection */
-    if (None != e->owner) {
-        lastOwnedSelectionIndex = i;
-    }
-
-    /* Save new selection owner or None */
-    s_iOwners[i] = e->owner;
-    winDebug("MonitorSelection - %s - Now owned by XID %x\n",
-             szSelectionNames[i], e->owner);
-}
-
-Atom
-winClipboardGetLastOwnedSelectionAtom(void)
-{
-    if (lastOwnedSelectionIndex == CLIP_OWN_NONE)
-        return None;
-
-    if (lastOwnedSelectionIndex == CLIP_OWN_PRIMARY)
-        return XA_PRIMARY;
-
-    if (lastOwnedSelectionIndex == CLIP_OWN_CLIPBOARD)
-        return atomClipboard;
-
-    return None;
-}
-
-
-void
-winClipboardInitMonitoredSelections(void)
-{
-    /* Initialize static variables */
-    for (int i = 0; i < CLIP_NUM_SELECTIONS; ++i)
-      s_iOwners[i] = None;
-
-    lastOwnedSelectionIndex = CLIP_OWN_NONE;
-}
-
-/*
- * Process any pending X events
- */
-
-int
-winClipboardFlushXEvents(HWND hwnd,
-                         int iWindow, Display * pDisplay, Bool fUseUnicode)
-{
-    static Atom atomLocalProperty;
-    static Atom atomCompoundText;
-    static Atom atomUTF8String;
-    static Atom atomTargets;
-    static int generation;
-
-    if (generation != serverGeneration) {
-        generation = serverGeneration;
-        atomClipboard = XInternAtom(pDisplay, "CLIPBOARD", False);
-        atomLocalProperty = XInternAtom(pDisplay, WIN_LOCAL_PROPERTY, False);
-        atomUTF8String = XInternAtom(pDisplay, "UTF8_STRING", False);
-        atomCompoundText = XInternAtom(pDisplay, "COMPOUND_TEXT", False);
-        atomTargets = XInternAtom(pDisplay, "TARGETS", False);
-    }
-
-    /* Process all pending events */
-    while (XPending(pDisplay)) {
-        XTextProperty xtpText = { 0 };
-        XEvent event;
-        XSelectionEvent eventSelection;
-        unsigned long ulReturnBytesLeft;
-        char *pszReturnData = NULL;
-        char *pszGlobalData = NULL;
-        int iReturn;
-        HGLOBAL hGlobal = NULL;
-        XICCEncodingStyle xiccesStyle;
-        int iConvertDataLen = 0;
-        char *pszConvertData = NULL;
-        char *pszTextList[2] = { NULL };
-        int iCount;
-        char **ppszTextList = NULL;
-        wchar_t *pwszUnicodeStr = NULL;
-        int iUnicodeLen = 0;
-        int iReturnDataLen = 0;
-        Bool fAbort = FALSE;
-        Bool fCloseClipboard = FALSE;
-        Bool fSetClipboardData = TRUE;
-
-        /* Get the next event - will not block because one is ready */
-        XNextEvent(pDisplay, &event);
-
-        /* Branch on the event type */
-        switch (event.type) {
-            /*
-             * SelectionRequest
-             */
-
-        case SelectionRequest:
-        {
-            char *pszAtomName = NULL;
-
-            winDebug("SelectionRequest - target %d\n",
-                     event.xselectionrequest.target);
-
-            pszAtomName = XGetAtomName(pDisplay,
-                                       event.xselectionrequest.target);
-            winDebug("SelectionRequest - Target atom name %s\n", pszAtomName);
-            XFree(pszAtomName);
-            pszAtomName = NULL;
-        }
-
-            /* Abort if invalid target type */
-            if (event.xselectionrequest.target != XA_STRING
-                && event.xselectionrequest.target != atomUTF8String
-                && event.xselectionrequest.target != atomCompoundText
-                && event.xselectionrequest.target != atomTargets) {
-                /* Abort */
-                fAbort = TRUE;
-                goto winClipboardFlushXEvents_SelectionRequest_Done;
-            }
-
-            /* Handle targets type of request */
-            if (event.xselectionrequest.target == atomTargets) {
-                Atom atomTargetArr[] = { atomTargets,
-                    atomCompoundText,
-                    atomUTF8String,
-                    XA_STRING
-                };
-
-                /* Try to change the property */
-                iReturn = XChangeProperty(pDisplay,
-                                          event.xselectionrequest.requestor,
-                                          event.xselectionrequest.property,
-                                          XA_ATOM,
-                                          32,
-                                          PropModeReplace,
-                                          (unsigned char *) atomTargetArr,
-                                          (sizeof(atomTargetArr)
-                                           / sizeof(atomTargetArr[0])));
-                if (iReturn == BadAlloc
-                    || iReturn == BadAtom
-                    || iReturn == BadMatch
-                    || iReturn == BadValue || iReturn == BadWindow) {
-                    ErrorF("winClipboardFlushXEvents - SelectionRequest - "
-                           "XChangeProperty failed: %d\n", iReturn);
-                }
-
-                /* Setup selection notify xevent */
-                eventSelection.type = SelectionNotify;
-                eventSelection.send_event = True;
-                eventSelection.display = pDisplay;
-                eventSelection.requestor = event.xselectionrequest.requestor;
-                eventSelection.selection = event.xselectionrequest.selection;
-                eventSelection.target = event.xselectionrequest.target;
-                eventSelection.property = event.xselectionrequest.property;
-                eventSelection.time = event.xselectionrequest.time;
-
-                /*
-                 * Notify the requesting window that
-                 * the operation has completed
-                 */
-                iReturn = XSendEvent(pDisplay,
-                                     eventSelection.requestor,
-                                     False, 0L, (XEvent *) &eventSelection);
-                if (iReturn == BadValue || iReturn == BadWindow) {
-                    ErrorF("winClipboardFlushXEvents - SelectionRequest - "
-                           "XSendEvent () failed\n");
-                }
-                break;
-            }
-
-            /* Close clipboard if we have it open already */
-            if (GetOpenClipboardWindow() == hwnd) {
-                CloseClipboard();
-            }
-
-            /* Access the clipboard */
-            if (!OpenClipboard(hwnd)) {
-                ErrorF("winClipboardFlushXEvents - SelectionRequest - "
-                       "OpenClipboard () failed: %08lx\n", GetLastError());
-
-                /* Abort */
-                fAbort = TRUE;
-                goto winClipboardFlushXEvents_SelectionRequest_Done;
-            }
-
-            /* Indicate that clipboard was opened */
-            fCloseClipboard = TRUE;
-
-            /* Check that clipboard format is available */
-            if (fUseUnicode && !IsClipboardFormatAvailable(CF_UNICODETEXT)) {
-                static int count;       /* Hack to stop acroread spamming the log */
-                static HWND lasthwnd;   /* I've not seen any other client get here repeatedly? */
-
-                if (hwnd != lasthwnd)
-                    count = 0;
-                count++;
-                if (count < 6)
-                    ErrorF("winClipboardFlushXEvents - CF_UNICODETEXT is not "
-                           "available from Win32 clipboard.  Aborting %d.\n",
-                           count);
-                lasthwnd = hwnd;
-
-                /* Abort */
-                fAbort = TRUE;
-                goto winClipboardFlushXEvents_SelectionRequest_Done;
-            }
-            else if (!fUseUnicode && !IsClipboardFormatAvailable(CF_TEXT)) {
-                ErrorF("winClipboardFlushXEvents - CF_TEXT is not "
-                       "available from Win32 clipboard.  Aborting.\n");
-
-                /* Abort */
-                fAbort = TRUE;
-                goto winClipboardFlushXEvents_SelectionRequest_Done;
-            }
-
-            /* Setup the string style */
-            if (event.xselectionrequest.target == XA_STRING)
-                xiccesStyle = XStringStyle;
-#ifdef X_HAVE_UTF8_STRING
-            else if (event.xselectionrequest.target == atomUTF8String)
-                xiccesStyle = XUTF8StringStyle;
-#endif
-            else if (event.xselectionrequest.target == atomCompoundText)
-                xiccesStyle = XCompoundTextStyle;
-            else
-                xiccesStyle = XStringStyle;
-
-            /* Get a pointer to the clipboard text, in desired format */
-            if (fUseUnicode) {
-                /* Retrieve clipboard data */
-                hGlobal = GetClipboardData(CF_UNICODETEXT);
-            }
-            else {
-                /* Retrieve clipboard data */
-                hGlobal = GetClipboardData(CF_TEXT);
-            }
-            if (!hGlobal) {
-                ErrorF("winClipboardFlushXEvents - SelectionRequest - "
-                       "GetClipboardData () failed: %08lx\n", GetLastError());
-
-                /* Abort */
-                fAbort = TRUE;
-                goto winClipboardFlushXEvents_SelectionRequest_Done;
-            }
-            pszGlobalData = (char *) GlobalLock(hGlobal);
-
-            /* Convert the Unicode string to UTF8 (MBCS) */
-            if (fUseUnicode) {
-                iConvertDataLen = WideCharToMultiByte(CP_UTF8,
-                                                      0,
-                                                      (LPCWSTR) pszGlobalData,
-                                                      -1, NULL, 0, NULL, NULL);
-                /* NOTE: iConvertDataLen includes space for null terminator */
-                pszConvertData = malloc(iConvertDataLen);
-                WideCharToMultiByte(CP_UTF8,
-                                    0,
-                                    (LPCWSTR) pszGlobalData,
-                                    -1,
-                                    pszConvertData,
-                                    iConvertDataLen, NULL, NULL);
-            }
-            else {
-                pszConvertData = strdup(pszGlobalData);
-                iConvertDataLen = strlen(pszConvertData) + 1;
-            }
-
-            /* Convert DOS string to UNIX string */
-            winClipboardDOStoUNIX(pszConvertData, strlen(pszConvertData));
-
-            /* Setup our text list */
-            pszTextList[0] = pszConvertData;
-            pszTextList[1] = NULL;
-
-            /* Initialize the text property */
-            xtpText.value = NULL;
-            xtpText.nitems = 0;
-
-            /* Create the text property from the text list */
-            if (fUseUnicode) {
-#ifdef X_HAVE_UTF8_STRING
-                iReturn = Xutf8TextListToTextProperty(pDisplay,
-                                                      pszTextList,
-                                                      1, xiccesStyle, &xtpText);
-#endif
-            }
-            else {
-                iReturn = XmbTextListToTextProperty(pDisplay,
-                                                    pszTextList,
-                                                    1, xiccesStyle, &xtpText);
-            }
-            if (iReturn == XNoMemory || iReturn == XLocaleNotSupported) {
-                ErrorF("winClipboardFlushXEvents - SelectionRequest - "
-                       "X*TextListToTextProperty failed: %d\n", iReturn);
-
-                /* Abort */
-                fAbort = TRUE;
-                goto winClipboardFlushXEvents_SelectionRequest_Done;
-            }
-
-            /* Free the converted string */
-            free(pszConvertData);
-            pszConvertData = NULL;
-
-            /* Copy the clipboard text to the requesting window */
-            iReturn = XChangeProperty(pDisplay,
-                                      event.xselectionrequest.requestor,
-                                      event.xselectionrequest.property,
-                                      event.xselectionrequest.target,
-                                      8,
-                                      PropModeReplace,
-                                      xtpText.value, xtpText.nitems);
-            if (iReturn == BadAlloc || iReturn == BadAtom
-                || iReturn == BadMatch || iReturn == BadValue
-                || iReturn == BadWindow) {
-                ErrorF("winClipboardFlushXEvents - SelectionRequest - "
-                       "XChangeProperty failed: %d\n", iReturn);
-
-                /* Abort */
-                fAbort = TRUE;
-                goto winClipboardFlushXEvents_SelectionRequest_Done;
-            }
-
-            /* Release the clipboard data */
-            GlobalUnlock(hGlobal);
-            pszGlobalData = NULL;
-            fCloseClipboard = FALSE;
-            CloseClipboard();
-
-            /* Clean up */
-            XFree(xtpText.value);
-            xtpText.value = NULL;
-            xtpText.nitems = 0;
-
-            /* Setup selection notify event */
-            eventSelection.type = SelectionNotify;
-            eventSelection.send_event = True;
-            eventSelection.display = pDisplay;
-            eventSelection.requestor = event.xselectionrequest.requestor;
-            eventSelection.selection = event.xselectionrequest.selection;
-            eventSelection.target = event.xselectionrequest.target;
-            eventSelection.property = event.xselectionrequest.property;
-            eventSelection.time = event.xselectionrequest.time;
-
-            /* Notify the requesting window that the operation has completed */
-            iReturn = XSendEvent(pDisplay,
-                                 eventSelection.requestor,
-                                 False, 0L, (XEvent *) &eventSelection);
-            if (iReturn == BadValue || iReturn == BadWindow) {
-                ErrorF("winClipboardFlushXEvents - SelectionRequest - "
-                       "XSendEvent () failed\n");
-
-                /* Abort */
-                fAbort = TRUE;
-                goto winClipboardFlushXEvents_SelectionRequest_Done;
-            }
-
- winClipboardFlushXEvents_SelectionRequest_Done:
-            /* Free allocated resources */
-            if (xtpText.value) {
-                XFree(xtpText.value);
-                xtpText.value = NULL;
-                xtpText.nitems = 0;
-            }
-            free(pszConvertData);
-            if (hGlobal && pszGlobalData)
-                GlobalUnlock(hGlobal);
-
-            /*
-             * Send a SelectionNotify event to the requesting
-             * client when we abort.
-             */
-            if (fAbort) {
-                /* Setup selection notify event */
-                eventSelection.type = SelectionNotify;
-                eventSelection.send_event = True;
-                eventSelection.display = pDisplay;
-                eventSelection.requestor = event.xselectionrequest.requestor;
-                eventSelection.selection = event.xselectionrequest.selection;
-                eventSelection.target = event.xselectionrequest.target;
-                eventSelection.property = None;
-                eventSelection.time = event.xselectionrequest.time;
-
-                /* Notify the requesting window that the operation is complete */
-                iReturn = XSendEvent(pDisplay,
-                                     eventSelection.requestor,
-                                     False, 0L, (XEvent *) &eventSelection);
-                if (iReturn == BadValue || iReturn == BadWindow) {
-                    /*
-                     * Should not be a problem if XSendEvent fails because
-                     * the client may simply have exited.
-                     */
-                    ErrorF("winClipboardFlushXEvents - SelectionRequest - "
-                           "XSendEvent () failed for abort event.\n");
-                }
-            }
-
-            /* Close clipboard if it was opened */
-            if (fCloseClipboard) {
-                fCloseClipboard = FALSE;
-                CloseClipboard();
-            }
-            break;
-
-            /*
-             * SelectionNotify
-             */
-
-        case SelectionNotify:
-
-            winDebug("winClipboardFlushXEvents - SelectionNotify\n");
-            {
-                char *pszAtomName;
-
-                pszAtomName = XGetAtomName(pDisplay,
-                                           event.xselection.selection);
-
-                winDebug
-                    ("winClipboardFlushXEvents - SelectionNotify - ATOM: %s\n",
-                     pszAtomName);
-                XFree(pszAtomName);
-            }
-
-            /*
-             * Request conversion of UTF8 and CompoundText targets.
-             */
-            if (event.xselection.property == None) {
-                if (event.xselection.target == XA_STRING) {
-                    winDebug("winClipboardFlushXEvents - SelectionNotify - "
-                             "XA_STRING\n");
-
-                    return WIN_XEVENTS_CONVERT;
-                }
-                else if (event.xselection.target == atomUTF8String) {
-                    winDebug("winClipboardFlushXEvents - SelectionNotify - "
-                             "Requesting conversion of UTF8 target.\n");
-
-                    XConvertSelection(pDisplay,
-                                      event.xselection.selection,
-                                      XA_STRING,
-                                      atomLocalProperty, iWindow, CurrentTime);
-
-                    /* Process the ConvertSelection event */
-                    XFlush(pDisplay);
-                    return WIN_XEVENTS_CONVERT;
-                }
-#ifdef X_HAVE_UTF8_STRING
-                else if (event.xselection.target == atomCompoundText) {
-                    winDebug("winClipboardFlushXEvents - SelectionNotify - "
-                             "Requesting conversion of CompoundText target.\n");
-
-                    XConvertSelection(pDisplay,
-                                      event.xselection.selection,
-                                      atomUTF8String,
-                                      atomLocalProperty, iWindow, CurrentTime);
-
-                    /* Process the ConvertSelection event */
-                    XFlush(pDisplay);
-                    return WIN_XEVENTS_CONVERT;
-                }
-#endif
-                else {
-                    ErrorF("winClipboardFlushXEvents - SelectionNotify - "
-                           "Unknown format.  Cannot request conversion, "
-                           "aborting.\n");
-                    break;
-                }
-            }
-
-            /* Retrieve the size of the stored data */
-            iReturn = XGetWindowProperty(pDisplay, iWindow, atomLocalProperty, 0, 0,    /* Don't get data, just size */
-                                         False,
-                                         AnyPropertyType,
-                                         &xtpText.encoding,
-                                         &xtpText.format,
-                                         &xtpText.nitems,
-                                         &ulReturnBytesLeft, &xtpText.value);
-            if (iReturn != Success) {
-                ErrorF("winClipboardFlushXEvents - SelectionNotify - "
-                       "XGetWindowProperty () failed, aborting: %d\n", iReturn);
-                break;
-            }
-
-            winDebug("SelectionNotify - returned data %d left %d\n",
-                     xtpText.nitems, ulReturnBytesLeft);
-
-            /* Request the selection data */
-            iReturn = XGetWindowProperty(pDisplay,
-                                         iWindow,
-                                         atomLocalProperty,
-                                         0,
-                                         ulReturnBytesLeft,
-                                         False,
-                                         AnyPropertyType,
-                                         &xtpText.encoding,
-                                         &xtpText.format,
-                                         &xtpText.nitems,
-                                         &ulReturnBytesLeft, &xtpText.value);
-            if (iReturn != Success) {
-                ErrorF("winClipboardFlushXEvents - SelectionNotify - "
-                       "XGetWindowProperty () failed, aborting: %d\n", iReturn);
-                break;
-            }
-
-            {
-                char *pszAtomName = NULL;
-
-                winDebug("SelectionNotify - returned data %d left %d\n",
-                         xtpText.nitems, ulReturnBytesLeft);
-                pszAtomName = XGetAtomName(pDisplay, xtpText.encoding);
-                winDebug("Notify atom name %s\n", pszAtomName);
-                XFree(pszAtomName);
-                pszAtomName = NULL;
-            }
-
-            if (fUseUnicode) {
-#ifdef X_HAVE_UTF8_STRING
-                /* Convert the text property to a text list */
-                iReturn = Xutf8TextPropertyToTextList(pDisplay,
-                                                      &xtpText,
-                                                      &ppszTextList, &iCount);
-#endif
-            }
-            else {
-                iReturn = XmbTextPropertyToTextList(pDisplay,
-                                                    &xtpText,
-                                                    &ppszTextList, &iCount);
-            }
-            if (iReturn == Success || iReturn > 0) {
-                /* Conversion succeeded or some unconvertible characters */
-                if (ppszTextList != NULL) {
-                    int i;
-
-                    iReturnDataLen = 0;
-                    for (i = 0; i < iCount; i++) {
-                        iReturnDataLen += strlen(ppszTextList[i]);
-                    }
-                    pszReturnData = malloc(iReturnDataLen + 1);
-                    pszReturnData[0] = '\0';
-                    for (i = 0; i < iCount; i++) {
-                        strcat(pszReturnData, ppszTextList[i]);
-                    }
-                }
-                else {
-                    ErrorF("winClipboardFlushXEvents - SelectionNotify - "
-                           "X*TextPropertyToTextList list_return is NULL.\n");
-                    pszReturnData = malloc(1);
-                    pszReturnData[0] = '\0';
-                }
-            }
-            else {
-                ErrorF("winClipboardFlushXEvents - SelectionNotify - "
-                       "X*TextPropertyToTextList returned: ");
-                switch (iReturn) {
-                case XNoMemory:
-                    ErrorF("XNoMemory\n");
-                    break;
-                case XLocaleNotSupported:
-                    ErrorF("XLocaleNotSupported\n");
-                    break;
-                case XConverterNotFound:
-                    ErrorF("XConverterNotFound\n");
-                    break;
-                default:
-                    ErrorF("%d\n", iReturn);
-                    break;
-                }
-                pszReturnData = malloc(1);
-                pszReturnData[0] = '\0';
-            }
-
-            /* Free the data returned from XGetWindowProperty */
-            if (ppszTextList)
-                XFreeStringList(ppszTextList);
-            ppszTextList = NULL;
-            XFree(xtpText.value);
-            xtpText.value = NULL;
-            xtpText.nitems = 0;
-
-            /* Convert the X clipboard string to DOS format */
-            winClipboardUNIXtoDOS(&pszReturnData, strlen(pszReturnData));
-
-            if (fUseUnicode) {
-                /* Find out how much space needed to convert MBCS to Unicode */
-                iUnicodeLen = MultiByteToWideChar(CP_UTF8,
-                                                  0,
-                                                  pszReturnData, -1, NULL, 0);
-
-                /* Allocate memory for the Unicode string */
-                pwszUnicodeStr = malloc(sizeof(wchar_t) * (iUnicodeLen + 1));
-                if (!pwszUnicodeStr) {
-                    ErrorF("winClipboardFlushXEvents - SelectionNotify "
-                           "malloc failed for pwszUnicodeStr, aborting.\n");
-
-                    /* Abort */
-                    fAbort = TRUE;
-                    goto winClipboardFlushXEvents_SelectionNotify_Done;
-                }
-
-                /* Do the actual conversion */
-                MultiByteToWideChar(CP_UTF8,
-                                    0,
-                                    pszReturnData,
-                                    -1, pwszUnicodeStr, iUnicodeLen);
-
-                /* Allocate global memory for the X clipboard data */
-                hGlobal = GlobalAlloc(GMEM_MOVEABLE,
-                                      sizeof(wchar_t) * (iUnicodeLen + 1));
-            }
-            else {
-                pszConvertData = strdup(pszReturnData);
-                iConvertDataLen = strlen(pszConvertData) + 1;
-
-                /* Allocate global memory for the X clipboard data */
-                hGlobal = GlobalAlloc(GMEM_MOVEABLE, iConvertDataLen);
-            }
-
-            free(pszReturnData);
-
-            /* Check that global memory was allocated */
-            if (!hGlobal) {
-                ErrorF("winClipboardFlushXEvents - SelectionNotify "
-                       "GlobalAlloc failed, aborting: %ld\n", GetLastError());
-
-                /* Abort */
-                fAbort = TRUE;
-                goto winClipboardFlushXEvents_SelectionNotify_Done;
-            }
-
-            /* Obtain a pointer to the global memory */
-            pszGlobalData = GlobalLock(hGlobal);
-            if (pszGlobalData == NULL) {
-                ErrorF("winClipboardFlushXEvents - Could not lock global "
-                       "memory for clipboard transfer\n");
-
-                /* Abort */
-                fAbort = TRUE;
-                goto winClipboardFlushXEvents_SelectionNotify_Done;
-            }
-
-            /* Copy the returned string into the global memory */
-            if (fUseUnicode) {
-                memcpy(pszGlobalData,
-                       pwszUnicodeStr, sizeof(wchar_t) * (iUnicodeLen + 1));
-                free(pwszUnicodeStr);
-                pwszUnicodeStr = NULL;
-            }
-            else {
-                strcpy(pszGlobalData, pszConvertData);
-                free(pszConvertData);
-                pszConvertData = NULL;
-            }
-
-            /* Release the pointer to the global memory */
-            GlobalUnlock(hGlobal);
-            pszGlobalData = NULL;
-
-            /* Push the selection data to the Windows clipboard */
-            if (fUseUnicode)
-                SetClipboardData(CF_UNICODETEXT, hGlobal);
-            else
-                SetClipboardData(CF_TEXT, hGlobal);
-
-            /* Flag that SetClipboardData has been called */
-            fSetClipboardData = FALSE;
-
-            /*
-             * NOTE: Do not try to free pszGlobalData, it is owned by
-             * Windows after the call to SetClipboardData ().
-             */
-
- winClipboardFlushXEvents_SelectionNotify_Done:
-            /* Free allocated resources */
-            if (ppszTextList)
-                XFreeStringList(ppszTextList);
-            if (xtpText.value) {
-                XFree(xtpText.value);
-                xtpText.value = NULL;
-                xtpText.nitems = 0;
-            }
-            free(pszConvertData);
-            free(pwszUnicodeStr);
-            if (hGlobal && pszGlobalData)
-                GlobalUnlock(hGlobal);
-            if (fSetClipboardData) {
-                SetClipboardData(CF_UNICODETEXT, NULL);
-                SetClipboardData(CF_TEXT, NULL);
-            }
-            return WIN_XEVENTS_NOTIFY;
-
-        case SelectionClear:
-            winDebug("SelectionClear - doing nothing\n");
-            break;
-
-        case PropertyNotify:
-            break;
-
-        case MappingNotify:
-            break;
-
-        default:
-            if (event.type == XFixesSetSelectionOwnerNotify + xfixes_event_base) {
-                XFixesSelectionNotifyEvent *e =
-                    (XFixesSelectionNotifyEvent *) & event;
-
-                winDebug("winClipboardFlushXEvents - XFixesSetSelectionOwnerNotify\n");
-
-                /* Save selection owners for monitored selections, ignore other selections */
-                if (e->selection == XA_PRIMARY) {
-                    MonitorSelection(e, CLIP_OWN_PRIMARY);
-                }
-                else if (e->selection == atomClipboard) {
-                    MonitorSelection(e, CLIP_OWN_CLIPBOARD);
-                }
-                else
-                    break;
-
-                /* Selection is being disowned */
-                if (e->owner == None) {
-                    winDebug
-                        ("winClipboardFlushXEvents - No window, returning.\n");
-                    break;
-                }
-
-                /*
-                   XXX: there are all kinds of wacky edge cases we might need here:
-                   - we own windows clipboard, but neither PRIMARY nor CLIPBOARD have an owner, so we should disown it?
-                   - root window is taking ownership?
-                 */
-
-                /* If we are the owner of the most recently owned selection, don't go all recursive :) */
-                if ((lastOwnedSelectionIndex != CLIP_OWN_NONE) &&
-                    (s_iOwners[lastOwnedSelectionIndex] == iWindow)) {
-                    winDebug("winClipboardFlushXEvents - Ownership changed to us, aborting.\n");
-                    break;
-                }
-
-                /* Close clipboard if we have it open already (possible? correct??) */
-                if (GetOpenClipboardWindow() == hwnd) {
-                    CloseClipboard();
-                }
-
-                /* Access the Windows clipboard */
-                if (!OpenClipboard(hwnd)) {
-                    ErrorF("winClipboardFlushXEvents - OpenClipboard () failed: %08x\n",
-                           (int) GetLastError());
-                    break;
-                }
-
-                /* Take ownership of the Windows clipboard */
-                if (!EmptyClipboard()) {
-                    ErrorF("winClipboardFlushXEvents - EmptyClipboard () failed: %08x\n",
-                           (int) GetLastError());
-                    break;
-                }
-
-                /* Advertise regular text and unicode */
-                SetClipboardData(CF_UNICODETEXT, NULL);
-                SetClipboardData(CF_TEXT, NULL);
-
-                /* Release the clipboard */
-                if (!CloseClipboard()) {
-                    ErrorF("winClipboardFlushXEvents - CloseClipboard () failed: %08x\n",
-                           (int) GetLastError());
-                    break;
-                }
-            }
-            /* XFixesSelectionWindowDestroyNotifyMask */
-            /* XFixesSelectionClientCloseNotifyMask */
-            else {
-                ErrorF("winClipboardFlushXEvents - unexpected event type %d\n",
-                       event.type);
-            }
-            break;
-        }
-    }
-
-    return WIN_XEVENTS_SUCCESS;
-}
commit e965001a732a6b573c374f6a3503e172df01e8ec
Author: Jon TURNEY <jon.turney at dronecode.org.uk>
Date:   Mon Jun 17 13:18:16 2013 +0100

    hw/xwin: Make g_hwndClipboard static
    
    Move winFixClipboardChain() into winclipboardthread.c
    Add winCLipboardWindowDestroy() function to access it for WM_DESTROY
    
    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/winclipboard.h b/hw/xwin/winclipboard.h
index fa32c62..41c0a53 100644
--- a/hw/xwin/winclipboard.h
+++ b/hw/xwin/winclipboard.h
@@ -97,6 +97,9 @@ void
 
 void *winClipboardProc(char *szDisplay);
 
+void
+winClipboardWindowDestroy(void);
+
 /*
  * winclipboardwndproc.c
  */
diff --git a/hw/xwin/winclipboardinit.c b/hw/xwin/winclipboardinit.c
index 335e379..d16c121 100644
--- a/hw/xwin/winclipboardinit.c
+++ b/hw/xwin/winclipboardinit.c
@@ -49,7 +49,6 @@ extern void winSetAuthorization(void);
  */
 
 extern Bool g_fClipboard;
-extern HWND g_hwndClipboard;
 extern Bool g_fClipboardStarted;
 
 /*
@@ -135,12 +134,7 @@ winClipboardShutdown(void)
   /* Close down clipboard resources */
   if (g_fClipboard && g_fClipboardStarted) {
     /* Synchronously destroy the clipboard window */
-    if (g_hwndClipboard != NULL) {
-      SendMessage(g_hwndClipboard, WM_DESTROY, 0, 0);
-      /* NOTE: g_hwndClipboard is set to NULL in winclipboardthread.c */
-    }
-    else
-      return;
+    winClipboardWindowDestroy();
 
     /* Wait for the clipboard thread to exit */
     pthread_join(g_ptClipboardProc, NULL);
@@ -150,11 +144,3 @@ winClipboardShutdown(void)
     winDebug("winClipboardShutdown - Clipboard thread has exited.\n");
   }
 }
-
-void
-winFixClipboardChain(void)
-{
-    if (g_fClipboard && g_hwndClipboard) {
-        PostMessage(g_hwndClipboard, WM_WM_REINIT, 0, 0);
-    }
-}
diff --git a/hw/xwin/winclipboardthread.c b/hw/xwin/winclipboardthread.c
index 3d49606..2641e20 100644
--- a/hw/xwin/winclipboardthread.c
+++ b/hw/xwin/winclipboardthread.c
@@ -57,12 +57,12 @@
 
 extern Bool g_fUnicodeClipboard;
 extern Bool g_fClipboard;
-extern HWND g_hwndClipboard;
 
 /*
  * Global variables
  */
 
+static HWND g_hwndClipboard = NULL;
 static jmp_buf g_jmpEntry;
 static XIOErrorHandler g_winClipboardOldIOErrorHandler;
 static pthread_t g_winClipboardProcThread;
@@ -240,7 +240,7 @@ winClipboardProc(char *szDisplay)
     /* Create Windows messaging window */
     hwnd = winClipboardCreateMessagingWindow(pDisplay, iWindow);
 
-    /* Save copy of HWND in screen privates */
+    /* Save copy of HWND */
     g_hwndClipboard = hwnd;
 
     /* Assert ownership of selections if Win32 clipboard is owned */
@@ -355,10 +355,7 @@ winClipboardProc(char *szDisplay)
  winClipboardProc_Done:
     /* Close our Windows window */
     if (g_hwndClipboard) {
-        /* Destroy the Window window (hwnd) */
-        winDebug("winClipboardProc - Destroy Windows window\n");
-        PostMessage(g_hwndClipboard, WM_DESTROY, 0, 0);
-        winClipboardFlushWindowsMessageQueue(g_hwndClipboard);
+        winClipboardWindowDestroy();
     }
 
     /* Close our X window */
@@ -489,3 +486,19 @@ winClipboardIOErrorHandler(Display * pDisplay)
 
     return 0;
 }
+
+void
+winClipboardWindowDestroy(void)
+{
+  if (g_hwndClipboard) {
+    SendMessage(g_hwndClipboard, WM_DESTROY, 0, 0);
+  }
+}
+
+void
+winFixClipboardChain(void)
+{
+  if (g_hwndClipboard) {
+    PostMessage(g_hwndClipboard, WM_WM_REINIT, 0, 0);
+  }
+}
diff --git a/hw/xwin/winglobals.c b/hw/xwin/winglobals.c
index 8eaaf38..ad82b83 100644
--- a/hw/xwin/winglobals.c
+++ b/hw/xwin/winglobals.c
@@ -94,7 +94,6 @@ winDispatchProcPtr winProcEstablishConnectionOrig = NULL;
 Bool g_fUnicodeClipboard = TRUE;
 Bool g_fClipboard = TRUE;
 Bool g_fClipboardStarted = FALSE;
-HWND g_hwndClipboard = NULL;
 #endif
 
 /*
@@ -106,7 +105,4 @@ void
 winInitializeGlobals(void)
 {
     g_dwCurrentThreadID = GetCurrentThreadId();
-#ifdef XWIN_CLIPBOARD
-    g_hwndClipboard = NULL;
-#endif
 }
commit 03a59e7f787a160c6cc07c7a37df64a793242ef2
Author: Jon TURNEY <jon.turney at dronecode.org.uk>
Date:   Mon Jun 17 02:01:39 2013 +0100

    hw/xwin: Add remaining clipboard globals to winglobals.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/windialogs.c b/hw/xwin/windialogs.c
index c9af0e2..61f7fe0 100644
--- a/hw/xwin/windialogs.c
+++ b/hw/xwin/windialogs.c
@@ -37,13 +37,6 @@
 #include "winprefs.h"
 
 /*
- * References to external globals
- */
-
-#ifdef XWIN_CLIPBOARD
-extern Bool g_fClipboardStarted;
-#endif
-/*
  * Local function prototypes
  */
 
diff --git a/hw/xwin/winglobals.h b/hw/xwin/winglobals.h
index 5d8e7a0..d7b813d 100644
--- a/hw/xwin/winglobals.h
+++ b/hw/xwin/winglobals.h
@@ -73,6 +73,9 @@ typedef int (*winDispatchProcPtr) (ClientPtr);
  */
 extern winDispatchProcPtr winProcEstablishConnectionOrig;
 #endif
+extern Bool g_fUnicodeClipboard;
+extern Bool g_fClipboard;
+extern Bool g_fClipboardStarted;
 
 /* The global X default icons */
 #if defined(XWIN_MULTIWINDOW)
commit 8f9fba5bc1499804a6c4a3287d99fe7dab8d6b8f
Author: Jon TURNEY <jon.turney at dronecode.org.uk>
Date:   Mon Jun 17 02:01:27 2013 +0100

    hw/xwin: Hoist use of winSetAuthorization() and winGetDisplayName() up one level
    
    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/winclipboard.h b/hw/xwin/winclipboard.h
index fcda6bf..fa32c62 100644
--- a/hw/xwin/winclipboard.h
+++ b/hw/xwin/winclipboard.h
@@ -71,7 +71,6 @@
  * References to external symbols
  */
 
-extern char *display;
 extern void winDebug(const char *format, ...);
 extern void winErrorFVerb(int verb, const char *format, ...);
 
@@ -96,7 +95,7 @@ void
  * winclipboardthread.c
  */
 
-void *winClipboardProc(void *);
+void *winClipboardProc(char *szDisplay);
 
 /*
  * winclipboardwndproc.c
diff --git a/hw/xwin/winclipboardinit.c b/hw/xwin/winclipboardinit.c
index 07e57ee..335e379 100644
--- a/hw/xwin/winclipboardinit.c
+++ b/hw/xwin/winclipboardinit.c
@@ -37,10 +37,13 @@
 
 #include "os.h"
 #include "winclipboard.h"
+#include "windisplay.h"
 
 #define WIN_CLIPBOARD_RETRIES			40
 #define WIN_CLIPBOARD_DELAY			1
 
+extern void winSetAuthorization(void);
+
 /*
  * References to external symbols
  */
@@ -61,16 +64,33 @@ static pthread_t g_ptClipboardProc;
 static void *
 winClipboardThreadProc(void *arg)
 {
+  char szDisplay[512];
   int clipboardRestarts = 0;
 
   while (1)
     {
       ++clipboardRestarts;
 
+      /* Use our generated cookie for authentication */
+      winSetAuthorization();
+
+      /* Setup the display connection string */
+      /*
+       * NOTE: Always connect to screen 0 since we require that screen
+       * numbers start at 0 and increase without gaps.  We only need
+       * to connect to one screen on the display to get events
+       * for all screens on the display.  That is why there is only
+       * one clipboard client thread.
+      */
+      winGetDisplayName(szDisplay, 0);
+
+      /* Print the display connection string */
+      ErrorF("winClipboardThreadProc - DISPLAY=%s\n", szDisplay);
+
       /* Flag that clipboard client has been launched */
       g_fClipboardStarted = TRUE;
 
-      winClipboardProc(arg);
+      winClipboardProc(szDisplay);
 
       /* Flag that clipboard client has stopped */
       g_fClipboardStarted = FALSE;
diff --git a/hw/xwin/winclipboardthread.c b/hw/xwin/winclipboardthread.c
index f9089ff..3d49606 100644
--- a/hw/xwin/winclipboardthread.c
+++ b/hw/xwin/winclipboardthread.c
@@ -89,7 +89,7 @@ static int
  */
 
 void *
-winClipboardProc(void *pvNotUsed)
+winClipboardProc(char *szDisplay)
 {
     Atom atomClipboard;
     int iReturn;
@@ -107,7 +107,6 @@ winClipboardProc(void *pvNotUsed)
     Window iWindow = None;
     int iRetries;
     Bool fUseUnicode;
-    char szDisplay[512];
     int iSelectError;
 
     winDebug("winClipboardProc - Hello\n");
@@ -150,24 +149,9 @@ winClipboardProc(void *pvNotUsed)
         goto winClipboardProc_Done;
     }
 
-    /* Use our generated cookie for authentication */
-    winSetAuthorization();
-
     /* Initialize retry count */
     iRetries = 0;
 
-    /* Setup the display connection string x */
-    /*
-     * NOTE: Always connect to screen 0 since we require that screen
-     * numbers start at 0 and increase without gaps.  We only need
-     * to connect to one screen on the display to get events
-     * for all screens on the display.  That is why there is only
-     * one clipboard client thread.
-     */
-    winGetDisplayName(szDisplay, 0);
-
-    /* Print the display connection string */
-    ErrorF("winClipboardProc - DISPLAY=%s\n", szDisplay);
 
     /* Open the X display */
     do {
commit a3c1e405cb78df9ef18a1158dcaed3c27b3cbffe
Author: Jon TURNEY <jon.turney at dronecode.org.uk>
Date:   Sun Jun 16 22:35:22 2013 +0100

    hw/xwin: Eliminate g_pClipboardDisplay and g_iClipboardWindow globals
    
    Eliminate the g_pClipboardDisplay and g_iClipboardWindow globals used to make
    those values available to the clipboard wndproc, by passing them in via the
    WM_CREATE message instead.
    
    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/winclipboard.h b/hw/xwin/winclipboard.h
index 2d1b508..fcda6bf 100644
--- a/hw/xwin/winclipboard.h
+++ b/hw/xwin/winclipboard.h
@@ -107,6 +107,12 @@ BOOL winClipboardFlushWindowsMessageQueue(HWND hwnd);
 LRESULT CALLBACK
 winClipboardWindowProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam);
 
+typedef struct
+{
+  Display *pClipboardDisplay;
+  Window iClipboardWindow;
+} ClipboardWindowCreationParams;
+
 /*
  * winclipboardxevents.c
  */
diff --git a/hw/xwin/winclipboardthread.c b/hw/xwin/winclipboardthread.c
index 0bffd44..f9089ff 100644
--- a/hw/xwin/winclipboardthread.c
+++ b/hw/xwin/winclipboardthread.c
@@ -58,8 +58,6 @@
 extern Bool g_fUnicodeClipboard;
 extern Bool g_fClipboard;
 extern HWND g_hwndClipboard;
-extern void *g_pClipboardDisplay;
-extern Window g_iClipboardWindow;
 
 /*
  * Global variables
@@ -78,7 +76,7 @@ int xfixes_error_base;
  */
 
 static HWND
-winClipboardCreateMessagingWindow(void);
+winClipboardCreateMessagingWindow(Display *pDisplay, Window iWindow);
 
 static int
  winClipboardErrorHandler(Display * pDisplay, XErrorEvent * pErr);
@@ -192,9 +190,6 @@ winClipboardProc(void *pvNotUsed)
         goto winClipboardProc_Done;
     }
 
-    /* Save the display in a global used by the wndproc */
-    g_pClipboardDisplay = pDisplay;
-
     ErrorF("winClipboardProc - XOpenDisplay () returned and "
            "successfully opened the display.\n");
 
@@ -255,14 +250,11 @@ winClipboardProc(void *pvNotUsed)
                                 XFixesSelectionWindowDestroyNotifyMask |
                                 XFixesSelectionClientCloseNotifyMask);
 
-    /* Save the window in the screen privates */
-    g_iClipboardWindow = iWindow;
 
     /* Initialize monitored selection state */
     winClipboardInitMonitoredSelections();
-
     /* Create Windows messaging window */
-    hwnd = winClipboardCreateMessagingWindow();
+    hwnd = winClipboardCreateMessagingWindow(pDisplay, iWindow);
 
     /* Save copy of HWND in screen privates */
     g_hwndClipboard = hwnd;
@@ -419,8 +411,6 @@ winClipboardProc(void *pvNotUsed)
 #endif
 
     /* global clipboard variable reset */
-    g_iClipboardWindow = None;
-    g_pClipboardDisplay = NULL;
     g_hwndClipboard = NULL;
 
     return NULL;
@@ -431,9 +421,10 @@ winClipboardProc(void *pvNotUsed)
  */
 
 static HWND
-winClipboardCreateMessagingWindow(void)
+winClipboardCreateMessagingWindow(Display *pDisplay, Window iWindow)
 {
     WNDCLASSEX wc;
+    ClipboardWindowCreationParams cwcp;
     HWND hwnd;
 
     /* Setup our window class */
@@ -451,6 +442,10 @@ winClipboardCreateMessagingWindow(void)
     wc.hIconSm = 0;
     RegisterClassEx(&wc);
 
+    /* Information to be passed to WM_CREATE */
+    cwcp.pClipboardDisplay = pDisplay;
+    cwcp.iClipboardWindow = iWindow;
+
     /* Create the window */
     hwnd = CreateWindowExA(0,   /* Extended styles */
                            WIN_CLIPBOARD_WINDOW_CLASS,  /* Class name */
@@ -463,7 +458,7 @@ winClipboardCreateMessagingWindow(void)
                            (HWND) NULL, /* No parent or owner window */
                            (HMENU) NULL,        /* No menu */
                            GetModuleHandle(NULL),       /* Instance handle */
-                           NULL);       /* Creation data */
+                           &cwcp);       /* Creation data */
     assert(hwnd != NULL);
 
     /* I'm not sure, but we may need to call this to start message processing */
diff --git a/hw/xwin/winclipboardwndproc.c b/hw/xwin/winclipboardwndproc.c
index d73c2db..459170f 100644
--- a/hw/xwin/winclipboardwndproc.c
+++ b/hw/xwin/winclipboardwndproc.c
@@ -44,12 +44,6 @@
 
 #define WIN_POLL_TIMEOUT	1
 
-/*
- * References to external symbols
- */
-
-extern void *g_pClipboardDisplay;
-extern Window g_iClipboardWindow;
 
 /*
  * Process X events up to specified timeout
@@ -138,6 +132,8 @@ winClipboardWindowProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
 {
     static HWND s_hwndNextViewer;
     static Bool s_fCBCInitialized;
+    static Display *pDisplay;
+    static Window iWindow;
 
     /* Branch on message type */
     switch (message) {
@@ -158,9 +154,13 @@ winClipboardWindowProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
     {
         HWND first, next;
         DWORD error_code = 0;
+        ClipboardWindowCreationParams *cwcp = (ClipboardWindowCreationParams *)((CREATESTRUCT *)lParam)->lpCreateParams;
 
         winDebug("winClipboardWindowProc - WM_CREATE\n");
 
+        pDisplay = cwcp->pClipboardDisplay;
+        iWindow = cwcp->iClipboardWindow;
+
         first = GetClipboardViewer();   /* Get handle to first viewer in chain. */
         if (first == hwnd)
             return 0;           /* Make sure it's not us! */
@@ -243,8 +243,6 @@ winClipboardWindowProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
         static Atom atomClipboard;
         static int generation;
         static Bool s_fProcessingDrawClipboard = FALSE;
-        Display *pDisplay = g_pClipboardDisplay;
-        Window iWindow = g_iClipboardWindow;
         int iReturn;
 
         winDebug("winClipboardWindowProc - WM_DRAWCLIPBOARD: Enter\n");
@@ -323,7 +321,7 @@ winClipboardWindowProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
 
             /* Release PRIMARY selection if owned */
             iReturn = XGetSelectionOwner(pDisplay, XA_PRIMARY);
-            if (iReturn == g_iClipboardWindow) {
+            if (iReturn == iWindow) {
                 winDebug("winClipboardWindowProc - WM_DRAWCLIPBOARD - "
                          "PRIMARY selection is owned by us.\n");
                 XSetSelectionOwner(pDisplay, XA_PRIMARY, None, CurrentTime);
@@ -335,7 +333,7 @@ winClipboardWindowProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
 
             /* Release CLIPBOARD selection if owned */
             iReturn = XGetSelectionOwner(pDisplay, atomClipboard);
-            if (iReturn == g_iClipboardWindow) {
+            if (iReturn == iWindow) {
                 winDebug("winClipboardWindowProc - WM_DRAWCLIPBOARD - "
                          "CLIPBOARD selection is owned by us.\n");
                 XSetSelectionOwner(pDisplay, atomClipboard, None, CurrentTime);
@@ -408,8 +406,6 @@ winClipboardWindowProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
     case WM_RENDERALLFORMATS:
     {
         int iReturn;
-        Display *pDisplay = g_pClipboardDisplay;
-        Window iWindow = g_iClipboardWindow;
         Bool fConvertToUnicode;
 
         winDebug("winClipboardWindowProc - WM_RENDER*FORMAT - Hello.\n");
diff --git a/hw/xwin/winglobals.c b/hw/xwin/winglobals.c
index b3f18ae..8eaaf38 100644
--- a/hw/xwin/winglobals.c
+++ b/hw/xwin/winglobals.c
@@ -95,8 +95,6 @@ Bool g_fUnicodeClipboard = TRUE;
 Bool g_fClipboard = TRUE;
 Bool g_fClipboardStarted = FALSE;
 HWND g_hwndClipboard = NULL;
-void *g_pClipboardDisplay = NULL;
-Window g_iClipboardWindow = None;
 #endif
 
 /*
@@ -109,8 +107,6 @@ winInitializeGlobals(void)
 {
     g_dwCurrentThreadID = GetCurrentThreadId();
 #ifdef XWIN_CLIPBOARD
-    g_iClipboardWindow = None;
-    g_pClipboardDisplay = NULL;
     g_hwndClipboard = NULL;
 #endif
 }
commit 229a0a83a44c94ce76eb937d58dc1773a38baa3e
Author: Jon TURNEY <jon.turney at dronecode.org.uk>
Date:   Sun Jun 16 22:13:26 2013 +0100

    hw/xwin: Move winClipboardCreateMessagingWindow() to winclipboardthread.c
    
    Move winClipboardCreateMessagingWindow() from winclipboardinit.c to
    winclipboardthread.c, the only place that uses it, and make it static.
    
    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/winclipboard.h b/hw/xwin/winclipboard.h
index 503d6ac..2d1b508 100644
--- a/hw/xwin/winclipboard.h
+++ b/hw/xwin/winclipboard.h
@@ -55,8 +55,6 @@
 #include <X11/Xwindows.h>
 
 /* Clipboard module constants */
-#define WIN_CLIPBOARD_WINDOW_CLASS		"xwinclip"
-#define WIN_CLIPBOARD_WINDOW_TITLE		"xwinclip"
 #ifdef HAS_DEVWINDOWS
 #define WIN_MSG_QUEUE_FNAME			"/dev/windows"
 #endif
@@ -84,8 +82,6 @@ extern void winErrorFVerb(int verb, const char *format, ...);
 Bool
  winInitClipboard(void);
 
-HWND winClipboardCreateMessagingWindow(void);
-
 /*
  * winclipboardtextconv.c
  */
diff --git a/hw/xwin/winclipboardinit.c b/hw/xwin/winclipboardinit.c
index e74e2b2..07e57ee 100644
--- a/hw/xwin/winclipboardinit.c
+++ b/hw/xwin/winclipboardinit.c
@@ -131,55 +131,6 @@ winClipboardShutdown(void)
   }
 }
 
-/*
- * Create the Windows window that we use to receive Windows messages
- */
-
-HWND
-winClipboardCreateMessagingWindow(void)
-{
-    WNDCLASSEX wc;
-    HWND hwnd;
-
-    /* Setup our window class */
-    wc.cbSize = sizeof(WNDCLASSEX);
-    wc.style = CS_HREDRAW | CS_VREDRAW;
-    wc.lpfnWndProc = winClipboardWindowProc;
-    wc.cbClsExtra = 0;
-    wc.cbWndExtra = 0;
-    wc.hInstance = GetModuleHandle(NULL);
-    wc.hIcon = 0;
-    wc.hCursor = 0;
-    wc.hbrBackground = (HBRUSH) GetStockObject(WHITE_BRUSH);
-    wc.lpszMenuName = NULL;
-    wc.lpszClassName = WIN_CLIPBOARD_WINDOW_CLASS;
-    wc.hIconSm = 0;
-    RegisterClassEx(&wc);
-
-    /* Create the window */
-    hwnd = CreateWindowExA(0,   /* Extended styles */
-                           WIN_CLIPBOARD_WINDOW_CLASS,  /* Class name */
-                           WIN_CLIPBOARD_WINDOW_TITLE,  /* Window name */
-                           WS_OVERLAPPED,       /* Not visible anyway */
-                           CW_USEDEFAULT,       /* Horizontal position */
-                           CW_USEDEFAULT,       /* Vertical position */
-                           CW_USEDEFAULT,       /* Right edge */
-                           CW_USEDEFAULT,       /* Bottom edge */
-                           (HWND) NULL, /* No parent or owner window */
-                           (HMENU) NULL,        /* No menu */
-                           GetModuleHandle(NULL),       /* Instance handle */
-                           NULL);       /* Creation data */
-    assert(hwnd != NULL);
-
-    /* I'm not sure, but we may need to call this to start message processing */
-    ShowWindow(hwnd, SW_HIDE);
-
-    /* Similarly, we may need a call to this even though we don't paint */
-    UpdateWindow(hwnd);
-
-    return hwnd;
-}
-
 void
 winFixClipboardChain(void)
 {
diff --git a/hw/xwin/winclipboardthread.c b/hw/xwin/winclipboardthread.c
index 04ab24f..0bffd44 100644
--- a/hw/xwin/winclipboardthread.c
+++ b/hw/xwin/winclipboardthread.c
@@ -48,6 +48,9 @@
 #define WIN_CONNECT_RETRIES			40
 #define WIN_CONNECT_DELAY			4
 
+#define WIN_CLIPBOARD_WINDOW_CLASS		"xwinclip"
+#define WIN_CLIPBOARD_WINDOW_TITLE		"xwinclip"
+
 /*
  * References to external symbols
  */
@@ -74,6 +77,9 @@ int xfixes_error_base;
  * Local function prototypes
  */
 
+static HWND
+winClipboardCreateMessagingWindow(void);
+
 static int
  winClipboardErrorHandler(Display * pDisplay, XErrorEvent * pErr);
 
@@ -421,6 +427,55 @@ winClipboardProc(void *pvNotUsed)
 }
 
 /*
+ * Create the Windows window that we use to receive Windows messages
+ */
+
+static HWND
+winClipboardCreateMessagingWindow(void)
+{
+    WNDCLASSEX wc;
+    HWND hwnd;
+
+    /* Setup our window class */
+    wc.cbSize = sizeof(WNDCLASSEX);
+    wc.style = CS_HREDRAW | CS_VREDRAW;
+    wc.lpfnWndProc = winClipboardWindowProc;
+    wc.cbClsExtra = 0;
+    wc.cbWndExtra = 0;
+    wc.hInstance = GetModuleHandle(NULL);
+    wc.hIcon = 0;
+    wc.hCursor = 0;
+    wc.hbrBackground = (HBRUSH) GetStockObject(WHITE_BRUSH);
+    wc.lpszMenuName = NULL;
+    wc.lpszClassName = WIN_CLIPBOARD_WINDOW_CLASS;
+    wc.hIconSm = 0;
+    RegisterClassEx(&wc);
+
+    /* Create the window */
+    hwnd = CreateWindowExA(0,   /* Extended styles */
+                           WIN_CLIPBOARD_WINDOW_CLASS,  /* Class name */
+                           WIN_CLIPBOARD_WINDOW_TITLE,  /* Window name */
+                           WS_OVERLAPPED,       /* Not visible anyway */
+                           CW_USEDEFAULT,       /* Horizontal position */
+                           CW_USEDEFAULT,       /* Vertical position */
+                           CW_USEDEFAULT,       /* Right edge */
+                           CW_USEDEFAULT,       /* Bottom edge */
+                           (HWND) NULL, /* No parent or owner window */
+                           (HMENU) NULL,        /* No menu */
+                           GetModuleHandle(NULL),       /* Instance handle */
+                           NULL);       /* Creation data */
+    assert(hwnd != NULL);
+
+    /* I'm not sure, but we may need to call this to start message processing */
+    ShowWindow(hwnd, SW_HIDE);
+
+    /* Similarly, we may need a call to this even though we don't paint */
+    UpdateWindow(hwnd);
+
+    return hwnd;
+}
+
+/*
  * winClipboardErrorHandler - Our application specific error handler
  */
 
commit a70c2384a2689cc0346868bb27366c008c01758d
Author: Jon TURNEY <jon.turney at dronecode.org.uk>
Date:   Mon Feb 13 19:58:37 2012 +0000

    hw/xwin: Remove SetSelectionOwner wrapper, use XFixesSetSelectionOwnerNotify event instead
    
    Use the XFixesSetSelectionNotify event instead of a SetSelectionOwner wrapper,
    the completely equivalent client-side mechanism.
    
    Signed-off-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 cba7d24..8dc7198 100644
--- a/configure.ac
+++ b/configure.ac
@@ -2143,7 +2143,7 @@ if test "x$XWIN" = xyes; then
 	AC_DEFINE_UNQUOTED(__VENDORDWEBSUPPORT__, ["$VENDOR_WEB"], [Vendor web address for support])
 	AC_CHECK_TOOL(WINDRES, windres)
 
-	PKG_CHECK_MODULES([XWINMODULES],[x11 xdmcp xau])
+	PKG_CHECK_MODULES([XWINMODULES],[x11 xdmcp xau xfixes])
 
 	if test "x$WINDOWSWM" = xauto; then
 		PKG_CHECK_EXISTS($WINDOWSWMPROTO, [WINDOWSWM=yes], [WINDOWSWM=no])
diff --git a/hw/xwin/InitInput.c b/hw/xwin/InitInput.c
index 38203c9..3e9ee41 100644
--- a/hw/xwin/InitInput.c
+++ b/hw/xwin/InitInput.c
@@ -39,7 +39,6 @@
 
 #ifdef XWIN_CLIPBOARD
 int winProcEstablishConnection(ClientPtr /* client */ );
-int winProcSetSelectionOwner(ClientPtr /* client */ );
 #endif
 
 /*
diff --git a/hw/xwin/winclipboard.h b/hw/xwin/winclipboard.h
index 63dce73..503d6ac 100644
--- a/hw/xwin/winclipboard.h
+++ b/hw/xwin/winclipboard.h
@@ -116,7 +116,14 @@ winClipboardWindowProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam);
  */
 
 int
-
 winClipboardFlushXEvents(HWND hwnd,
                          int iWindow, Display * pDisplay, Bool fUnicodeSupport);
+
+
+Atom
+winClipboardGetLastOwnedSelectionAtom(void);
+
+void
+winClipboardInitMonitoredSelections(void);
+
 #endif
diff --git a/hw/xwin/winclipboardinit.c b/hw/xwin/winclipboardinit.c
index 4912b2e..e74e2b2 100644
--- a/hw/xwin/winclipboardinit.c
+++ b/hw/xwin/winclipboardinit.c
@@ -35,25 +35,16 @@
 #include <unistd.h>
 #include <pthread.h>
 
-#include "dixstruct.h"
+#include "os.h"
 #include "winclipboard.h"
 
 #define WIN_CLIPBOARD_RETRIES			40
 #define WIN_CLIPBOARD_DELAY			1
 
 /*
- * Local typedefs
- */
-
-typedef int (*winDispatchProcPtr) (ClientPtr);
-
-int winProcSetSelectionOwner(ClientPtr /* client */ );
-
-/*
  * References to external symbols
  */
 
-extern winDispatchProcPtr winProcSetSelectionOwnerOrig;
 extern Bool g_fClipboard;
 extern HWND g_hwndClipboard;
 extern Bool g_fClipboardStarted;
@@ -108,12 +99,6 @@ winInitClipboard(void)
 {
     winDebug("winInitClipboard ()\n");
 
-    /* Wrap some internal server functions */
-    if (ProcVector[X_SetSelectionOwner] != winProcSetSelectionOwner) {
-        winProcSetSelectionOwnerOrig = ProcVector[X_SetSelectionOwner];
-        ProcVector[X_SetSelectionOwner] = winProcSetSelectionOwner;
-    }
-
     /* Spawn a thread for the Clipboard module */
     if (pthread_create(&g_ptClipboardProc, NULL, winClipboardThreadProc, NULL)) {
         /* Bail if thread creation failed */
diff --git a/hw/xwin/winclipboardthread.c b/hw/xwin/winclipboardthread.c
index 2ef73bd..04ab24f 100644
--- a/hw/xwin/winclipboardthread.c
+++ b/hw/xwin/winclipboardthread.c
@@ -43,6 +43,7 @@
 #include <errno.h>
 #endif
 #include "misc.h"
+#include <X11/extensions/Xfixes.h>
 
 #define WIN_CONNECT_RETRIES			40
 #define WIN_CONNECT_DELAY			4
@@ -66,6 +67,8 @@ static XIOErrorHandler g_winClipboardOldIOErrorHandler;
 static pthread_t g_winClipboardProcThread;
 
 Bool g_fUseUnicode = FALSE;
+int xfixes_event_base;
+int xfixes_error_base;
 
 /*
  * Local function prototypes
@@ -206,6 +209,9 @@ winClipboardProc(void *pvNotUsed)
     iMaxDescriptor = iConnectionNumber + 1;
 #endif
 
+    if (!XFixesQueryExtension(pDisplay, &xfixes_event_base, &xfixes_error_base))
+      ErrorF ("winClipboardProc - XFixes extension not present\n");
+
     /* Create atom */
     atomClipboard = XInternAtom(pDisplay, "CLIPBOARD", False);
 
@@ -229,9 +235,26 @@ winClipboardProc(void *pvNotUsed)
         ErrorF("winClipboardProc - XSelectInput generated BadWindow "
                "on messaging window\n");
 
+    XFixesSelectSelectionInput (pDisplay,
+                                iWindow,
+                                XA_PRIMARY,
+                                XFixesSetSelectionOwnerNotifyMask |
+                                XFixesSelectionWindowDestroyNotifyMask |
+                                XFixesSelectionClientCloseNotifyMask);
+
+    XFixesSelectSelectionInput (pDisplay,
+                                iWindow,
+                                XInternAtom (pDisplay, "CLIPBOARD", False),
+                                XFixesSetSelectionOwnerNotifyMask |
+                                XFixesSelectionWindowDestroyNotifyMask |
+                                XFixesSelectionClientCloseNotifyMask);
+
     /* Save the window in the screen privates */
     g_iClipboardWindow = iWindow;
 
+    /* Initialize monitored selection state */
+    winClipboardInitMonitoredSelections();
+
     /* Create Windows messaging window */
     hwnd = winClipboardCreateMessagingWindow();
 
diff --git a/hw/xwin/winclipboardwndproc.c b/hw/xwin/winclipboardwndproc.c
index 90dc9e0..d73c2db 100644
--- a/hw/xwin/winclipboardwndproc.c
+++ b/hw/xwin/winclipboardwndproc.c
@@ -50,7 +50,6 @@
 
 extern void *g_pClipboardDisplay;
 extern Window g_iClipboardWindow;
-extern Atom g_atomLastOwnedSelection;
 
 /*
  * Process X events up to specified timeout
@@ -423,7 +422,7 @@ winClipboardWindowProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
 
         /* Request the selection contents */
         iReturn = XConvertSelection(pDisplay,
-                                    g_atomLastOwnedSelection,
+                                    winClipboardGetLastOwnedSelectionAtom(),
                                     XInternAtom(pDisplay,
                                                 "COMPOUND_TEXT", False),
                                     XInternAtom(pDisplay,
diff --git a/hw/xwin/winclipboardwrappers.c b/hw/xwin/winclipboardwrappers.c
index 99dfc5b..2679f4f 100644
--- a/hw/xwin/winclipboardwrappers.c
+++ b/hw/xwin/winclipboardwrappers.c
@@ -33,35 +33,21 @@
 #ifdef HAVE_XWIN_CONFIG_H
 #include <xwin-config.h>
 #endif
+
 #include "win.h"
 #include "dixstruct.h"
-#include <X11/Xatom.h>
-
-/*
- * Constants
- */
-
-#define CLIP_NUM_SELECTIONS		2
-#define CLIP_OWN_PRIMARY		0
-#define CLIP_OWN_CLIPBOARD		1
 
 /*
  * Local function prototypes
  */
 
 DISPATCH_PROC(winProcEstablishConnection);
-DISPATCH_PROC(winProcSetSelectionOwner);
 
 /*
  * References to external symbols
  */
 
-extern Bool g_fClipboardStarted;
 extern Bool g_fClipboard;
-extern Window g_iClipboardWindow;
-extern Atom g_atomLastOwnedSelection;
-extern HWND g_hwndClipboard;
-
 
 /*
  * Wrapper for internal EstablishConnection function.
@@ -157,202 +143,3 @@ winProcEstablishConnection(ClientPtr client)
 
     return iReturn;
 }
-
-/*
- * Wrapper for internal SetSelectionOwner function.
- * Grabs ownership of Windows clipboard when X11 clipboard owner changes.
- */
-
-int
-winProcSetSelectionOwner(ClientPtr client)
-{
-    int i;
-    DrawablePtr pDrawable;
-    WindowPtr pWindow = None;
-    Bool fOwnedToNotOwned = FALSE;
-    static Window s_iOwners[CLIP_NUM_SELECTIONS] = { None };
-    static unsigned long s_ulServerGeneration = 0;
-
-    REQUEST(xSetSelectionOwnerReq);
-
-    REQUEST_SIZE_MATCH(xSetSelectionOwnerReq);
-
-    winDebug("winProcSetSelectionOwner - Hello.\n");
-
-    /* Watch for server reset */
-    if (s_ulServerGeneration != serverGeneration) {
-        /* Save new generation number */
-        s_ulServerGeneration = serverGeneration;
-
-        /* Initialize static variables */
-        for (i = 0; i < CLIP_NUM_SELECTIONS; ++i)
-            s_iOwners[i] = None;
-    }
-
-    /* Abort if clipboard not completely initialized yet */
-    if (!g_fClipboardStarted) {
-        /* ErrorF ("winProcSetSelectionOwner - Clipboard not yet started, "
-           "aborting.\n"); */
-        goto winProcSetSelectionOwner_Done;
-    }
-
-    /* Grab window if we have one */
-    if (None != stuff->window) {
-        /* Grab the Window from the request */
-        int rc =
-            dixLookupWindow(&pWindow, stuff->window, client, DixReadAccess);
-        if (rc != Success) {
-            ErrorF("winProcSetSelectionOwner - Found BadWindow, aborting.\n");
-            goto winProcSetSelectionOwner_Done;
-        }
-    }
-
-    /* Now we either have a valid window or None */
-
-    /* Save selection owners for monitored selections, ignore other selections */
-    if (XA_PRIMARY == stuff->selection) {
-        /* Look for owned -> not owned transition */
-        if (None == stuff->window && None != s_iOwners[CLIP_OWN_PRIMARY]) {
-            fOwnedToNotOwned = TRUE;
-
-            winDebug("winProcSetSelectionOwner - PRIMARY - Going from "
-                     "owned to not owned.\n");
-
-            /* Adjust last owned selection */
-            if (None != s_iOwners[CLIP_OWN_CLIPBOARD])
-                g_atomLastOwnedSelection = MakeAtom("CLIPBOARD", 9, TRUE);
-            else
-                g_atomLastOwnedSelection = None;
-        }
-
-        /* Save new selection owner or None */
-        s_iOwners[CLIP_OWN_PRIMARY] = stuff->window;
-
-        winDebug("winProcSetSelectionOwner - PRIMARY - Now owned by: %d\n",
-                 stuff->window);
-    }
-    else if (MakeAtom("CLIPBOARD", 9, TRUE) == stuff->selection) {
-        /* Look for owned -> not owned transition */
-        if (None == stuff->window && None != s_iOwners[CLIP_OWN_CLIPBOARD]) {
-            fOwnedToNotOwned = TRUE;
-
-            winDebug("winProcSetSelectionOwner - CLIPBOARD - Going from "
-                     "owned to not owned.\n");
-
-            /* Adjust last owned selection */
-            if (None != s_iOwners[CLIP_OWN_PRIMARY])
-                g_atomLastOwnedSelection = XA_PRIMARY;
-            else
-                g_atomLastOwnedSelection = None;
-        }
-
-        /* Save new selection owner or None */
-        s_iOwners[CLIP_OWN_CLIPBOARD] = stuff->window;
-
-        winDebug("winProcSetSelectionOwner - CLIPBOARD - Now owned by: %d\n",
-                 stuff->window);
-
-    }
-    else
-        goto winProcSetSelectionOwner_Done;
-
-    /*
-     * At this point, if one of the selections is still owned by the 
-     * clipboard manager then it should be marked as unowned since
-     * we will be taking ownership of the Win32 clipboard.
-     */
-    if (g_iClipboardWindow == s_iOwners[CLIP_OWN_PRIMARY])
-        s_iOwners[CLIP_OWN_PRIMARY] = None;
-    if (g_iClipboardWindow == s_iOwners[CLIP_OWN_CLIPBOARD])
-        s_iOwners[CLIP_OWN_CLIPBOARD] = None;
-
-    /*
-     * Handle case when selection is being disowned,
-     * WM_DRAWCLIPBOARD did not do the disowning,
-     * both monitored selections are no longer owned,
-     * an owned to not owned transition was detected,
-     * and we currently own the Win32 clipboard.
-     */
-    if (stuff->window == None
-        && s_iOwners[CLIP_OWN_PRIMARY] == None
-        && s_iOwners[CLIP_OWN_CLIPBOARD] == None
-        && fOwnedToNotOwned
-        && g_hwndClipboard != NULL && g_hwndClipboard == GetClipboardOwner()) {
-        winDebug("winProcSetSelectionOwner - We currently own the "
-                 "clipboard and neither the PRIMARY nor the CLIPBOARD "
-                 "selections are owned, releasing ownership of Win32 "
-                 "clipboard.\n");
-
-        /* Release ownership of the Windows clipboard */
-        OpenClipboard(NULL);
-        EmptyClipboard();
-        CloseClipboard();
-
-        goto winProcSetSelectionOwner_Done;
-    }
-
-    /* Abort if no window at this point */
-    if (None == stuff->window) {
-        winDebug("winProcSetSelectionOwner - No window, returning.\n");
-        goto winProcSetSelectionOwner_Done;
-    }
-
-    /* Abort if invalid selection */
-    if (!ValidAtom(stuff->selection)) {
-        ErrorF("winProcSetSelectionOwner - Found BadAtom, aborting.\n");
-        goto winProcSetSelectionOwner_Done;
-    }
-
-    /* Cast Window to Drawable */
-    pDrawable = (DrawablePtr) pWindow;
-
-    /* Abort if clipboard manager is owning the selection */
-    if (pDrawable->id == g_iClipboardWindow) {
-        winDebug("winProcSetSelectionOwner - We changed ownership, "
-                 "aborting.\n");
-        goto winProcSetSelectionOwner_Done;
-    }
-
-    /* Abort if root window is taking ownership */
-    if (pDrawable->id == 0) {
-        ErrorF("winProcSetSelectionOwner - Root window taking ownership, "
-               "aborting\n");
-        goto winProcSetSelectionOwner_Done;
-    }
-
-    /* Close clipboard if we have it open already */
-    if (GetOpenClipboardWindow() == g_hwndClipboard) {
-        CloseClipboard();
-    }
-
-    /* Access the Windows clipboard */
-    if (!OpenClipboard(g_hwndClipboard)) {
-        ErrorF("winProcSetSelectionOwner - OpenClipboard () failed: %08x\n",
-               (int) GetLastError());
-        goto winProcSetSelectionOwner_Done;
-    }
-
-    /* Take ownership of the Windows clipboard */
-    if (!EmptyClipboard()) {
-        ErrorF("winProcSetSelectionOwner - EmptyClipboard () failed: %08x\n",
-               (int) GetLastError());
-        goto winProcSetSelectionOwner_Done;
-    }
-
-    /* Advertise regular text and unicode */
-    SetClipboardData(CF_UNICODETEXT, NULL);
-    SetClipboardData(CF_TEXT, NULL);
-
-    /* Save handle to last owned selection */
-    g_atomLastOwnedSelection = stuff->selection;
-
-    /* Release the clipboard */
-    if (!CloseClipboard()) {
-        ErrorF("winProcSetSelectionOwner - CloseClipboard () failed: "
-               "%08x\n", (int) GetLastError());
-        goto winProcSetSelectionOwner_Done;
-    }
-
- winProcSetSelectionOwner_Done:
-    return (*winProcSetSelectionOwnerOrig) (client);
-}
diff --git a/hw/xwin/winclipboardxevents.c b/hw/xwin/winclipboardxevents.c
index 7d3c30e..a792467 100644
--- a/hw/xwin/winclipboardxevents.c
+++ b/hw/xwin/winclipboardxevents.c
@@ -33,8 +33,95 @@
 #ifdef HAVE_XWIN_CONFIG_H
 #include <xwin-config.h>
 #endif
+
 #include "winclipboard.h"
 #include "misc.h"
+#include <X11/extensions/Xfixes.h>
+
+/*
+ * Constants
+ */
+
+#define CLIP_NUM_SELECTIONS		2
+#define CLIP_OWN_NONE     		-1
+#define CLIP_OWN_PRIMARY		0
+#define CLIP_OWN_CLIPBOARD		1
+
+/*
+ * Global variables
+ */
+
+extern int xfixes_event_base;
+
+/*
+ * Local variables
+ */
+
+static Window s_iOwners[CLIP_NUM_SELECTIONS] = { None, None };
+static const char *szSelectionNames[CLIP_NUM_SELECTIONS] =
+    { "PRIMARY", "CLIPBOARD" };
+
+static unsigned int lastOwnedSelectionIndex = CLIP_OWN_NONE;
+static Atom atomClipboard = None;
+
+static void
+MonitorSelection(XFixesSelectionNotifyEvent * e, unsigned int i)
+{
+    /* Look for owned -> not owned transition */
+    if (None == e->owner && None != s_iOwners[i]) {
+        unsigned int other_index;
+
+        winDebug("MonitorSelection - %s - Going from owned to not owned.\n",
+                 szSelectionNames[i]);
+
+        /* If this selection is not owned, the other monitored selection must be the most
+           recently owned, if it is owned at all */
+        if (i == CLIP_OWN_PRIMARY)
+            other_index = CLIP_OWN_CLIPBOARD;
+        if (i == CLIP_OWN_CLIPBOARD)
+            other_index = CLIP_OWN_PRIMARY;
+        if (None != s_iOwners[other_index])
+            lastOwnedSelectionIndex = other_index;
+        else
+            lastOwnedSelectionIndex = CLIP_OWN_NONE;
+    }
+
+    /* Save last owned selection */
+    if (None != e->owner) {
+        lastOwnedSelectionIndex = i;
+    }
+
+    /* Save new selection owner or None */
+    s_iOwners[i] = e->owner;
+    winDebug("MonitorSelection - %s - Now owned by XID %x\n",
+             szSelectionNames[i], e->owner);
+}
+
+Atom
+winClipboardGetLastOwnedSelectionAtom(void)
+{
+    if (lastOwnedSelectionIndex == CLIP_OWN_NONE)
+        return None;
+
+    if (lastOwnedSelectionIndex == CLIP_OWN_PRIMARY)
+        return XA_PRIMARY;
+
+    if (lastOwnedSelectionIndex == CLIP_OWN_CLIPBOARD)
+        return atomClipboard;
+
+    return None;
+}
+
+
+void
+winClipboardInitMonitoredSelections(void)
+{
+    /* Initialize static variables */
+    for (int i = 0; i < CLIP_NUM_SELECTIONS; ++i)
+      s_iOwners[i] = None;
+
+    lastOwnedSelectionIndex = CLIP_OWN_NONE;
+}
 
 /*
  * Process any pending X events
@@ -52,6 +139,7 @@ winClipboardFlushXEvents(HWND hwnd,
 
     if (generation != serverGeneration) {
         generation = serverGeneration;
+        atomClipboard = XInternAtom(pDisplay, "CLIPBOARD", False);
         atomLocalProperty = XInternAtom(pDisplay, WIN_LOCAL_PROPERTY, False);
         atomUTF8String = XInternAtom(pDisplay, "UTF8_STRING", False);
         atomCompoundText = XInternAtom(pDisplay, "COMPOUND_TEXT", False);
@@ -77,7 +165,6 @@ winClipboardFlushXEvents(HWND hwnd,
         wchar_t *pwszUnicodeStr = NULL;
         int iUnicodeLen = 0;
         int iReturnDataLen = 0;
-        int i;
         Bool fAbort = FALSE;
         Bool fCloseClipboard = FALSE;
         Bool fSetClipboardData = TRUE;
@@ -525,6 +612,8 @@ winClipboardFlushXEvents(HWND hwnd,
             if (iReturn == Success || iReturn > 0) {
                 /* Conversion succeeded or some unconvertible characters */
                 if (ppszTextList != NULL) {
+                    int i;
+
                     iReturnDataLen = 0;
                     for (i = 0; i < iCount; i++) {
                         iReturnDataLen += strlen(ppszTextList[i]);
@@ -693,8 +782,78 @@ winClipboardFlushXEvents(HWND hwnd,
             break;
 
         default:
-            ErrorF("winClipboardFlushXEvents - unexpected event type %d\n",
-                   event.type);
+            if (event.type == XFixesSetSelectionOwnerNotify + xfixes_event_base) {
+                XFixesSelectionNotifyEvent *e =
+                    (XFixesSelectionNotifyEvent *) & event;
+
+                winDebug("winClipboardFlushXEvents - XFixesSetSelectionOwnerNotify\n");
+
+                /* Save selection owners for monitored selections, ignore other selections */
+                if (e->selection == XA_PRIMARY) {
+                    MonitorSelection(e, CLIP_OWN_PRIMARY);
+                }
+                else if (e->selection == atomClipboard) {
+                    MonitorSelection(e, CLIP_OWN_CLIPBOARD);
+                }
+                else
+                    break;
+
+                /* Selection is being disowned */
+                if (e->owner == None) {
+                    winDebug
+                        ("winClipboardFlushXEvents - No window, returning.\n");
+                    break;
+                }
+
+                /*
+                   XXX: there are all kinds of wacky edge cases we might need here:
+                   - we own windows clipboard, but neither PRIMARY nor CLIPBOARD have an owner, so we should disown it?
+                   - root window is taking ownership?
+                 */
+
+                /* If we are the owner of the most recently owned selection, don't go all recursive :) */
+                if ((lastOwnedSelectionIndex != CLIP_OWN_NONE) &&
+                    (s_iOwners[lastOwnedSelectionIndex] == iWindow)) {
+                    winDebug("winClipboardFlushXEvents - Ownership changed to us, aborting.\n");
+                    break;
+                }
+
+                /* Close clipboard if we have it open already (possible? correct??) */
+                if (GetOpenClipboardWindow() == hwnd) {
+                    CloseClipboard();
+                }
+
+                /* Access the Windows clipboard */
+                if (!OpenClipboard(hwnd)) {
+                    ErrorF("winClipboardFlushXEvents - OpenClipboard () failed: %08x\n",
+                           (int) GetLastError());
+                    break;
+                }
+
+                /* Take ownership of the Windows clipboard */
+                if (!EmptyClipboard()) {
+                    ErrorF("winClipboardFlushXEvents - EmptyClipboard () failed: %08x\n",
+                           (int) GetLastError());
+                    break;
+                }
+
+                /* Advertise regular text and unicode */
+                SetClipboardData(CF_UNICODETEXT, NULL);
+                SetClipboardData(CF_TEXT, NULL);
+
+                /* Release the clipboard */
+                if (!CloseClipboard()) {
+                    ErrorF("winClipboardFlushXEvents - CloseClipboard () failed: %08x\n",
+                           (int) GetLastError());
+                    break;
+                }
+            }
+            /* XFixesSelectionWindowDestroyNotifyMask */
+            /* XFixesSelectionClientCloseNotifyMask */
+            else {
+                ErrorF("winClipboardFlushXEvents - unexpected event type %d\n",
+                       event.type);
+            }
             break;
         }
     }
diff --git a/hw/xwin/winglobals.c b/hw/xwin/winglobals.c
index 095ecff..b3f18ae 100644
--- a/hw/xwin/winglobals.c
+++ b/hw/xwin/winglobals.c
@@ -86,7 +86,6 @@ pthread_mutex_t g_pmTerminating = PTHREAD_MUTEX_INITIALIZER;
  * Wrapped DIX functions
  */
 winDispatchProcPtr winProcEstablishConnectionOrig = NULL;
-winDispatchProcPtr winProcSetSelectionOwnerOrig = NULL;
 
 /*
  * Clipboard variables
@@ -98,7 +97,6 @@ Bool g_fClipboardStarted = FALSE;
 HWND g_hwndClipboard = NULL;
 void *g_pClipboardDisplay = NULL;
 Window g_iClipboardWindow = None;
-Atom g_atomLastOwnedSelection = None;
 #endif
 
 /*
@@ -113,7 +111,6 @@ winInitializeGlobals(void)
 #ifdef XWIN_CLIPBOARD
     g_iClipboardWindow = None;
     g_pClipboardDisplay = NULL;
-    g_atomLastOwnedSelection = None;
     g_hwndClipboard = NULL;
 #endif
 }
diff --git a/hw/xwin/winglobals.h b/hw/xwin/winglobals.h
index 60c00da..5d8e7a0 100644
--- a/hw/xwin/winglobals.h
+++ b/hw/xwin/winglobals.h
@@ -72,7 +72,6 @@ typedef int (*winDispatchProcPtr) (ClientPtr);
  * Wrapped DIX functions
  */
 extern winDispatchProcPtr winProcEstablishConnectionOrig;
-extern winDispatchProcPtr winProcSetSelectionOwnerOrig;
 #endif
 
 /* The global X default icons */
commit ab55746c1b179172a82b7a89ec6429b268a1f166
Author: Jon TURNEY <jon.turney at dronecode.org.uk>
Date:   Mon Jun 17 01:55:46 2013 +0100

    hw/xwin: Remove g_fClipboardLaunched, it's value is identical to g_fClipboardStarted
    
    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/winclipboardinit.c b/hw/xwin/winclipboardinit.c
index 0b895cb..4912b2e 100644
--- a/hw/xwin/winclipboardinit.c
+++ b/hw/xwin/winclipboardinit.c
@@ -56,7 +56,6 @@ int winProcSetSelectionOwner(ClientPtr /* client */ );
 extern winDispatchProcPtr winProcSetSelectionOwnerOrig;
 extern Bool g_fClipboard;
 extern HWND g_hwndClipboard;
-extern Bool g_fClipboardLaunched;
 extern Bool g_fClipboardStarted;
 
 /*
@@ -78,13 +77,11 @@ winClipboardThreadProc(void *arg)
       ++clipboardRestarts;
 
       /* Flag that clipboard client has been launched */
-      g_fClipboardLaunched = TRUE;
       g_fClipboardStarted = TRUE;
 
       winClipboardProc(arg);
 
       /* Flag that clipboard client has stopped */
-      g_fClipboardLaunched = FALSE;
       g_fClipboardStarted = FALSE;
 
       /* checking if we need to restart */
@@ -131,7 +128,7 @@ void
 winClipboardShutdown(void)
 {
   /* Close down clipboard resources */
-  if (g_fClipboard && g_fClipboardLaunched && g_fClipboardStarted) {
+  if (g_fClipboard && g_fClipboardStarted) {
     /* Synchronously destroy the clipboard window */
     if (g_hwndClipboard != NULL) {
       SendMessage(g_hwndClipboard, WM_DESTROY, 0, 0);
@@ -143,7 +140,6 @@ winClipboardShutdown(void)
     /* Wait for the clipboard thread to exit */
     pthread_join(g_ptClipboardProc, NULL);
 
-    g_fClipboardLaunched = FALSE;
     g_fClipboardStarted = FALSE;
 
     winDebug("winClipboardShutdown - Clipboard thread has exited.\n");
diff --git a/hw/xwin/winglobals.c b/hw/xwin/winglobals.c
index b0d6ffc..095ecff 100644
--- a/hw/xwin/winglobals.c
+++ b/hw/xwin/winglobals.c
@@ -94,7 +94,6 @@ winDispatchProcPtr winProcSetSelectionOwnerOrig = NULL;
 
 Bool g_fUnicodeClipboard = TRUE;
 Bool g_fClipboard = TRUE;
-Bool g_fClipboardLaunched = FALSE;
 Bool g_fClipboardStarted = FALSE;
 HWND g_hwndClipboard = NULL;
 void *g_pClipboardDisplay = NULL;
commit 42d13810822f6b48771d77b09c0ef7cc2356ede5
Author: Jon TURNEY <jon.turney at dronecode.org.uk>
Date:   Mon Jun 17 01:30:09 2013 +0100

    hw/xwin: Hoist setting of g_fClipboardStarted flag up one level
    
    Hoist the setting of g_fClipboardStarted flag up one level.
    
    Also move up the clearing of the g_fClipboardLaunched at the end of clipboard
    function.
    
    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/winclipboardinit.c b/hw/xwin/winclipboardinit.c
index a3c1261..0b895cb 100644
--- a/hw/xwin/winclipboardinit.c
+++ b/hw/xwin/winclipboardinit.c
@@ -79,9 +79,14 @@ winClipboardThreadProc(void *arg)
 
       /* Flag that clipboard client has been launched */
       g_fClipboardLaunched = TRUE;
+      g_fClipboardStarted = TRUE;
 
       winClipboardProc(arg);
 
+      /* Flag that clipboard client has stopped */
+      g_fClipboardLaunched = FALSE;
+      g_fClipboardStarted = FALSE;
+
       /* checking if we need to restart */
       if (clipboardRestarts >= WIN_CLIPBOARD_RETRIES) {
         /* terminates clipboard thread but the main server still lives */
diff --git a/hw/xwin/winclipboardthread.c b/hw/xwin/winclipboardthread.c
index fd1fc07..2ef73bd 100644
--- a/hw/xwin/winclipboardthread.c
+++ b/hw/xwin/winclipboardthread.c
@@ -52,8 +52,6 @@
  */
 
 extern Bool g_fUnicodeClipboard;
-extern Bool g_fClipboardStarted;
-extern Bool g_fClipboardLaunched;
 extern Bool g_fClipboard;
 extern HWND g_hwndClipboard;
 extern void *g_pClipboardDisplay;
@@ -274,9 +272,6 @@ winClipboardProc(void *pvNotUsed)
         ErrorF("winClipboardProc - winClipboardFlushWindowsMessageQueue failed\n");
     }
 
-    /* Signal that the clipboard client has started */
-    g_fClipboardStarted = TRUE;
-
     /* Loop for X events */
     while (1) {
         /* Setup the file descriptor set */
@@ -395,8 +390,6 @@ winClipboardProc(void *pvNotUsed)
 #endif
 
     /* global clipboard variable reset */
-    g_fClipboardLaunched = FALSE;
-    g_fClipboardStarted = FALSE;
     g_iClipboardWindow = None;
     g_pClipboardDisplay = NULL;
     g_hwndClipboard = NULL;
commit 290dbff0753ddf60f04da92d5a408c567a2ee3e0
Author: Jon TURNEY <jon.turney at dronecode.org.uk>
Date:   Mon Jun 17 01:55:03 2013 +0100

    hw/xwin: winProcEstablishConnection doesn't need to check if clipboard started
    
    winProcEstablishConnection doesn't need to check if clipboard has already been
    started.
    
    It should be clear that we start the thread only once when the wrapper tells us
    to, as the wrapper unhooks itself thereafter.
    
    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/winclipboardwrappers.c b/hw/xwin/winclipboardwrappers.c
index 05a8a28..99dfc5b 100644
--- a/hw/xwin/winclipboardwrappers.c
+++ b/hw/xwin/winclipboardwrappers.c
@@ -56,7 +56,6 @@ DISPATCH_PROC(winProcSetSelectionOwner);
  * References to external symbols
  */
 
-extern Bool g_fClipboardLaunched;
 extern Bool g_fClipboardStarted;
 extern Bool g_fClipboard;
 extern Window g_iClipboardWindow;
@@ -127,13 +126,6 @@ winProcEstablishConnection(ClientPtr client)
     /* Clear original function pointer */
     winProcEstablishConnectionOrig = NULL;
 
-    /* If the clipboard client has already been started, abort */
-    if (g_fClipboardLaunched) {
-        ErrorF("winProcEstablishConnection - Clipboard client already "
-               "launched, returning.\n");
-        return iReturn;
-    }
-
     /* Startup the clipboard client if clipboard mode is being used */
     if (g_fClipboard) {
         /*
commit 91e55691ef07735bb866c0f4d3c1a6e2ca167992
Author: Jon TURNEY <jon.turney at dronecode.org.uk>
Date:   Sun Jun 16 23:57:17 2013 +0100

    hw/xwin: Hoist clipboard thread restart up one level
    
    Hoist clipboard thread restart up one level.
    
    Note that currently g_fClipboardLaunched is set the first time in the
    winProcEstablishConnection wrapper, and subsequent times when the clipboard
    thread restarts itself.
    
    Try to clarify this and just set g_fClipboardLaunched before starting the
    thread.
    
    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/winclipboard.h b/hw/xwin/winclipboard.h
index cb77695..63dce73 100644
--- a/hw/xwin/winclipboard.h
+++ b/hw/xwin/winclipboard.h
@@ -60,16 +60,12 @@
 #ifdef HAS_DEVWINDOWS
 #define WIN_MSG_QUEUE_FNAME			"/dev/windows"
 #endif
-#define WIN_CONNECT_RETRIES			40
-#define WIN_CONNECT_DELAY			4
 #define WIN_JMP_OKAY				0
 #define WIN_JMP_ERROR_IO			2
 #define WIN_LOCAL_PROPERTY			"CYGX_CUT_BUFFER"
 #define WIN_XEVENTS_SUCCESS			0
 #define WIN_XEVENTS_CONVERT			2
 #define WIN_XEVENTS_NOTIFY			3
-#define WIN_CLIPBOARD_RETRIES			40
-#define WIN_CLIPBOARD_DELAY			1
 
 #define WM_WM_REINIT                           (WM_USER + 1)
 
diff --git a/hw/xwin/winclipboardinit.c b/hw/xwin/winclipboardinit.c
index e6bbf17..a3c1261 100644
--- a/hw/xwin/winclipboardinit.c
+++ b/hw/xwin/winclipboardinit.c
@@ -31,9 +31,16 @@
 #ifdef HAVE_XWIN_CONFIG_H
 #include <xwin-config.h>
 #endif
+
+#include <unistd.h>
+#include <pthread.h>
+
 #include "dixstruct.h"
 #include "winclipboard.h"
 
+#define WIN_CLIPBOARD_RETRIES			40
+#define WIN_CLIPBOARD_DELAY			1
+
 /*
  * Local typedefs
  */
@@ -59,6 +66,38 @@ extern Bool g_fClipboardStarted;
 static pthread_t g_ptClipboardProc;
 
 /*
+ *
+ */
+static void *
+winClipboardThreadProc(void *arg)
+{
+  int clipboardRestarts = 0;
+
+  while (1)
+    {
+      ++clipboardRestarts;
+
+      /* Flag that clipboard client has been launched */
+      g_fClipboardLaunched = TRUE;
+
+      winClipboardProc(arg);
+
+      /* checking if we need to restart */
+      if (clipboardRestarts >= WIN_CLIPBOARD_RETRIES) {
+        /* terminates clipboard thread but the main server still lives */
+        ErrorF("winClipboardProc - the clipboard thread has restarted %d times and seems to be unstable, disabling clipboard integration\n", clipboardRestarts);
+        g_fClipboard = FALSE;
+        break;
+      }
+
+      sleep(WIN_CLIPBOARD_DELAY);
+      ErrorF("winClipboardProc - trying to restart clipboard thread \n");
+    }
+
+  return NULL;
+}
+
+/*
  * Intialize the Clipboard module
  */
 
@@ -74,7 +113,7 @@ winInitClipboard(void)
     }
 
     /* Spawn a thread for the Clipboard module */
-    if (pthread_create(&g_ptClipboardProc, NULL, winClipboardProc, NULL)) {
+    if (pthread_create(&g_ptClipboardProc, NULL, winClipboardThreadProc, NULL)) {
         /* Bail if thread creation failed */
         ErrorF("winInitClipboard - pthread_create failed.\n");
         return FALSE;
diff --git a/hw/xwin/winclipboardthread.c b/hw/xwin/winclipboardthread.c
index 4a9eb4c..fd1fc07 100644
--- a/hw/xwin/winclipboardthread.c
+++ b/hw/xwin/winclipboardthread.c
@@ -44,6 +44,9 @@
 #endif
 #include "misc.h"
 
+#define WIN_CONNECT_RETRIES			40
+#define WIN_CONNECT_DELAY			4
+
 /*
  * References to external symbols
  */
@@ -61,7 +64,6 @@ extern Window g_iClipboardWindow;
  */
 
 static jmp_buf g_jmpEntry;
-static int clipboardRestarts = 0;
 static XIOErrorHandler g_winClipboardOldIOErrorHandler;
 static pthread_t g_winClipboardProcThread;
 
@@ -104,7 +106,6 @@ winClipboardProc(void *pvNotUsed)
     int iSelectError;
 
     winDebug("winClipboardProc - Hello\n");
-    ++clipboardRestarts;
 
     /* Do we use Unicode clipboard? */
     fUseUnicode = g_fUnicodeClipboard;
@@ -400,35 +401,6 @@ winClipboardProc(void *pvNotUsed)
     g_pClipboardDisplay = NULL;
     g_hwndClipboard = NULL;
 
-    /* checking if we need to restart */
-    if (clipboardRestarts >= WIN_CLIPBOARD_RETRIES) {
-        /* terminates clipboard thread but the main server still lives */
-        ErrorF
-            ("winClipboardProc - the clipboard thread has restarted %d times and seems to be unstable, disabling clipboard integration\n",
-             clipboardRestarts);
-        g_fClipboard = FALSE;
-        return NULL;
-    }
-
-    if (g_fClipboard) {
-        sleep(WIN_CLIPBOARD_DELAY);
-        ErrorF("winClipboardProc - trying to restart clipboard thread \n");
-        /* Create the clipboard client thread */
-        if (!winInitClipboard()) {
-            ErrorF("winClipboardProc - winClipboardInit failed.\n");
-            return NULL;
-        }
-
-        winDebug("winClipboardProc - winInitClipboard returned.\n");
-        /* Flag that clipboard client has been launched */
-        g_fClipboardLaunched = TRUE;
-    }
-    else {
-        ErrorF("winClipboardProc - Clipboard disabled  - Exit from server \n");
-        /* clipboard thread has exited, stop server as well */
-        raise(SIGTERM);
-    }
-
     return NULL;
 }
 
diff --git a/hw/xwin/winclipboardwrappers.c b/hw/xwin/winclipboardwrappers.c
index bfd6bff..05a8a28 100644
--- a/hw/xwin/winclipboardwrappers.c
+++ b/hw/xwin/winclipboardwrappers.c
@@ -163,9 +163,6 @@ winProcEstablishConnection(ClientPtr client)
         ErrorF("winProcEstablishConnection - winInitClipboard returned.\n");
     }
 
-    /* Flag that clipboard client has been launched */
-    g_fClipboardLaunched = TRUE;
-
     return iReturn;
 }
 
commit 0bb6eae4e34634abb2679004ace94504a4d65964
Author: Jon TURNEY <jon.turney at dronecode.org.uk>
Date:   Mon Jun 17 00:07:01 2013 +0100

    hw/xwin: Push winClipboardShutdown() into winclipboardinit.c
    
    Push winClipboardShutdown() into winclipboardinit.c
    This lets us make g_ptClipboardProc static
    
    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/InitOutput.c b/hw/xwin/InitOutput.c
index 6b5c38d..88bc85a 100644
--- a/hw/xwin/InitOutput.c
+++ b/hw/xwin/InitOutput.c
@@ -66,24 +66,11 @@ typedef WINAPI HRESULT(*SHGETFOLDERPATHPROC) (HWND hwndOwner,
 /*
  * References to external symbols
  */
-#ifdef XWIN_CLIPBOARD
-extern Bool g_fUnicodeClipboard;
-extern Bool g_fClipboardLaunched;
-extern Bool g_fClipboardStarted;
-extern pthread_t g_ptClipboardProc;
-extern HWND g_hwndClipboard;
-extern Bool g_fClipboard;
-#endif
 
 /*
  * Function prototypes
  */
 
-#ifdef XWIN_CLIPBOARD
-static void
- winClipboardShutdown(void);
-#endif
-
 static Bool
  winCheckDisplayNumber(void);
 
@@ -125,31 +112,6 @@ static PixmapFormatRec g_PixmapFormats[] = {
 
 const int NUMFORMATS = sizeof(g_PixmapFormats) / sizeof(g_PixmapFormats[0]);
 
-#ifdef XWIN_CLIPBOARD
-static void
-winClipboardShutdown(void)
-{
-    /* Close down clipboard resources */
-    if (g_fClipboard && g_fClipboardLaunched && g_fClipboardStarted) {
-        /* Synchronously destroy the clipboard window */
-        if (g_hwndClipboard != NULL) {
-            SendMessage(g_hwndClipboard, WM_DESTROY, 0, 0);
-            /* NOTE: g_hwndClipboard is set to NULL in winclipboardthread.c */
-        }
-        else
-            return;
-
-        /* Wait for the clipboard thread to exit */
-        pthread_join(g_ptClipboardProc, NULL);
-
-        g_fClipboardLaunched = FALSE;
-        g_fClipboardStarted = FALSE;
-
-        winDebug("winClipboardShutdown - Clipboard thread has exited.\n");
-    }
-}
-#endif
-
 static const ExtensionModule xwinExtensions[] = {
 #ifdef GLXEXT
   { GlxExtensionInit, "GLX", &noGlxExtension },
diff --git a/hw/xwin/win.h b/hw/xwin/win.h
index a738a59..1a882f4 100644
--- a/hw/xwin/win.h
+++ b/hw/xwin/win.h
@@ -794,6 +794,9 @@ Bool
 
 void
  winFixClipboardChain(void);
+
+void
+ winClipboardShutdown(void);
 #endif
 
 /*
diff --git a/hw/xwin/winclipboardinit.c b/hw/xwin/winclipboardinit.c
index 157006d..e6bbf17 100644
--- a/hw/xwin/winclipboardinit.c
+++ b/hw/xwin/winclipboardinit.c
@@ -46,10 +46,17 @@ int winProcSetSelectionOwner(ClientPtr /* client */ );
  * References to external symbols
  */
 
-extern pthread_t g_ptClipboardProc;
 extern winDispatchProcPtr winProcSetSelectionOwnerOrig;
 extern Bool g_fClipboard;
 extern HWND g_hwndClipboard;
+extern Bool g_fClipboardLaunched;
+extern Bool g_fClipboardStarted;
+
+/*
+ * Local variables
+ */
+
+static pthread_t g_ptClipboardProc;
 
 /*
  * Intialize the Clipboard module
@@ -76,6 +83,29 @@ winInitClipboard(void)
     return TRUE;
 }
 
+void
+winClipboardShutdown(void)
+{
+  /* Close down clipboard resources */
+  if (g_fClipboard && g_fClipboardLaunched && g_fClipboardStarted) {
+    /* Synchronously destroy the clipboard window */
+    if (g_hwndClipboard != NULL) {
+      SendMessage(g_hwndClipboard, WM_DESTROY, 0, 0);
+      /* NOTE: g_hwndClipboard is set to NULL in winclipboardthread.c */
+    }
+    else
+      return;
+
+    /* Wait for the clipboard thread to exit */
+    pthread_join(g_ptClipboardProc, NULL);
+
+    g_fClipboardLaunched = FALSE;
+    g_fClipboardStarted = FALSE;
+
+    winDebug("winClipboardShutdown - Clipboard thread has exited.\n");
+  }
+}
+
 /*
  * Create the Windows window that we use to receive Windows messages
  */
diff --git a/hw/xwin/winglobals.c b/hw/xwin/winglobals.c
index b9ad294..b0d6ffc 100644
--- a/hw/xwin/winglobals.c
+++ b/hw/xwin/winglobals.c
@@ -96,7 +96,6 @@ Bool g_fUnicodeClipboard = TRUE;
 Bool g_fClipboard = TRUE;
 Bool g_fClipboardLaunched = FALSE;
 Bool g_fClipboardStarted = FALSE;
-pthread_t g_ptClipboardProc;
 HWND g_hwndClipboard = NULL;
 void *g_pClipboardDisplay = NULL;
 Window g_iClipboardWindow = None;
commit 6343b531d786dd4a9bb52050c9ef267a04374b57
Author: Jon TURNEY <jon.turney at dronecode.org.uk>
Date:   Wed Jan 1 17:54:48 2014 +0000

    hw/xwin: Remove left-over pthread_exit() in clipboard code
    
    Commit c1bf3baa44fbd8af33a2b3ce045324485b85a7a7 removed all but one of the
    pthread_exit() calls which used to call winClipboardThreadExit()
    
    Fix the final remaining one to exit via done label on IOError instead.
    
    Also fix a comment and report pre-flush failure to log, but do not exit
    
    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/winclipboardthread.c b/hw/xwin/winclipboardthread.c
index e708960..4a9eb4c 100644
--- a/hw/xwin/winclipboardthread.c
+++ b/hw/xwin/winclipboardthread.c
@@ -141,7 +141,7 @@ winClipboardProc(void *pvNotUsed)
     else if (iReturn == WIN_JMP_ERROR_IO) {
         /* TODO: Cleanup the Win32 window and free any allocated memory */
         ErrorF("winClipboardProc - setjmp returned for IO Error Handler.\n");
-        pthread_exit(NULL);
+        goto winClipboardProc_Done;
     }
 
     /* Use our generated cookie for authentication */
@@ -184,7 +184,7 @@ winClipboardProc(void *pvNotUsed)
         goto winClipboardProc_Done;
     }
 
-    /* Save the display in the screen privates */
+    /* Save the display in a global used by the wndproc */
     g_pClipboardDisplay = pDisplay;
 
     ErrorF("winClipboardProc - XOpenDisplay () returned and "
@@ -269,8 +269,9 @@ winClipboardProc(void *pvNotUsed)
     winClipboardFlushXEvents(hwnd, iWindow, pDisplay, fUseUnicode);
 
     /* Pre-flush Windows messages */
-    if (!winClipboardFlushWindowsMessageQueue(hwnd))
-        return 0;
+    if (!winClipboardFlushWindowsMessageQueue(hwnd)) {
+        ErrorF("winClipboardProc - winClipboardFlushWindowsMessageQueue failed\n");
+    }
 
     /* Signal that the clipboard client has started */
     g_fClipboardStarted = TRUE;
commit d3427717f2c6a473dc3d20631dff653e4e37228e
Author: Adam Jackson <ajax at redhat.com>
Date:   Wed Jul 2 12:09:52 2014 -0400

    xwayland: Snap damage reports to the bounding box
    
    Instead of sending every little rect.  Lets x11perf run to completion,
    makes 'while true; do gtkperf -a; done' take longer to crash.
    
    This is effectively a resend of the same logic against the old
    xfree86+xwayland branch:
    
    http://lists.x.org/archives/xorg-devel/2013-October/038453.html
    
    Reviewed-by: Daniel Stone <daniel at fooishbar.org>
    Reviewed-by: Kristian Høgsberg <krh at bitplanet.net>
    Signed-off-by: Adam Jackson <ajax at redhat.com>

diff --git a/hw/xwayland/xwayland.c b/hw/xwayland/xwayland.c
index e0ae2a9..9132969 100644
--- a/hw/xwayland/xwayland.c
+++ b/hw/xwayland/xwayland.c
@@ -342,7 +342,6 @@ xwl_screen_post_damage(struct xwl_screen *xwl_screen)
     struct xwl_window *xwl_window, *next_xwl_window;
     RegionPtr region;
     BoxPtr box;
-    int count, i;
     struct wl_buffer *buffer;
     PixmapPtr pixmap;
 
@@ -354,8 +353,6 @@ xwl_screen_post_damage(struct xwl_screen *xwl_screen)
             continue;
 
         region = DamageRegion(xwl_window->damage);
-        count = RegionNumRects(region);
-
         pixmap = (*xwl_screen->screen->GetWindowPixmap) (xwl_window->window);
 
 #if GLAMOR_HAS_GBM
@@ -366,12 +363,10 @@ xwl_screen_post_damage(struct xwl_screen *xwl_screen)
             buffer = xwl_shm_pixmap_get_wl_buffer(pixmap);
 
         wl_surface_attach(xwl_window->surface, buffer, 0, 0);
-        for (i = 0; i < count; i++) {
-            box = &RegionRects(region)[i];
-            wl_surface_damage(xwl_window->surface,
-                              box->x1, box->y1,
-                              box->x2 - box->x1, box->y2 - box->y1);
-        }
+
+        box = RegionExtents(region);
+        wl_surface_damage(xwl_window->surface, box->x1, box->y1,
+                          box->x2 - box->x1, box->y2 - box->y1);
 
         xwl_window->frame_callback = wl_surface_frame(xwl_window->surface);
         wl_callback_add_listener(xwl_window->frame_callback, &frame_listener, xwl_window);
commit 5ecc0315a2b9bea44ace886f5706a7a3f5cbc4f6
Author: Jasper St. Pierre <jstpierre at mecheye.net>
Date:   Mon Jun 30 13:53:50 2014 -0400

    xwayland: Implement throttling for surfaces based on the frame event
    
    This implements simple throttling that keeps us to one attach per
    frame. There isn't really an active performance benefit, since the
    buffers will be redrawn only once per frame anyway, but it does cut down
    on the chatty network traffic. Since the Wayland sockets might fill
    up as well, the cut down on the volume of data we send out also provides
    us with a big stability benefit.
    
    Namely, mutter is a lot more stable running gtkperf, a fairly intensive
    X11 application, after this change.
    
    Reviewed-by: Daniel Stone <daniel at fooishbar.org>
    Signed-off-by: Jasper St. Pierre <jstpierre at mecheye.net>

diff --git a/hw/xwayland/xwayland.c b/hw/xwayland/xwayland.c
index 17b7bf7..e0ae2a9 100644
--- a/hw/xwayland/xwayland.c
+++ b/hw/xwayland/xwayland.c
@@ -308,6 +308,9 @@ xwl_unrealize_window(WindowPtr window)
         xorg_list_del(&xwl_window->link_damage);
     DamageUnregister(xwl_window->damage);
     DamageDestroy(xwl_window->damage);
+    if (xwl_window->frame_callback)
+        wl_callback_destroy(xwl_window->frame_callback);
+
     free(xwl_window);
     dixSetPrivate(&window->devPrivates, &xwl_window_private_key, NULL);
 
@@ -321,17 +324,35 @@ xwl_save_screen(ScreenPtr pScreen, int on)
 }
 
 static void
+frame_callback(void *data,
+               struct wl_callback *callback,
+               uint32_t time)
+{
+    struct xwl_window *xwl_window = data;
+    xwl_window->frame_callback = NULL;
+}
+
+static const struct wl_callback_listener frame_listener = {
+    frame_callback
+};
+
+static void
 xwl_screen_post_damage(struct xwl_screen *xwl_screen)
 {
-    struct xwl_window *xwl_window;
+    struct xwl_window *xwl_window, *next_xwl_window;
     RegionPtr region;
     BoxPtr box;
     int count, i;
     struct wl_buffer *buffer;
     PixmapPtr pixmap;
 
-    xorg_list_for_each_entry(xwl_window, &xwl_screen->damage_window_list,
-                             link_damage) {
+    xorg_list_for_each_entry_safe(xwl_window, next_xwl_window,
+                                  &xwl_screen->damage_window_list, link_damage) {
+        /* If we're waiting on a frame callback from the server,
+         * don't attach a new buffer. */
+        if (xwl_window->frame_callback)
+            continue;
+
         region = DamageRegion(xwl_window->damage);
         count = RegionNumRects(region);
 
@@ -351,11 +372,15 @@ xwl_screen_post_damage(struct xwl_screen *xwl_screen)
                               box->x1, box->y1,
                               box->x2 - box->x1, box->y2 - box->y1);
         }
+
+        xwl_window->frame_callback = wl_surface_frame(xwl_window->surface);
+        wl_callback_add_listener(xwl_window->frame_callback, &frame_listener, xwl_window);
+
         wl_surface_commit(xwl_window->surface);
         DamageEmpty(xwl_window->damage);
-    }
 
-    xorg_list_init(&xwl_screen->damage_window_list);
+        xorg_list_del(&xwl_window->link_damage);
+    }
 }
 
 static void
diff --git a/hw/xwayland/xwayland.h b/hw/xwayland/xwayland.h
index 60b0c29..bfffa71 100644
--- a/hw/xwayland/xwayland.h
+++ b/hw/xwayland/xwayland.h
@@ -102,6 +102,7 @@ struct xwl_window {
     WindowPtr window;
     DamagePtr damage;
     struct xorg_list link_damage;
+    struct wl_callback *frame_callback;
 };
 
 #define MODIFIER_META 0x01
commit 6c442fc4f7d84508665dfdee8a75ec91f50395dc
Author: Jasper St. Pierre <jstpierre at mecheye.net>
Date:   Mon Jun 30 15:28:16 2014 -0400

    xwayland-input: Fix a crasher for a race with the Wayland compositor
    
    If something quickly maps and unmaps a window, then we'll immediately
    create and destroy the Wayland surface that cooresponds to that
    window. If our mouse pointer is over the window when the surface is
    created, we'll receive a enter on the window.
    
    Since resource creation and destruction is not synchronous, that
    means that the compositor will queue up an event for a resource that's
    eventually destroyed. On the client-side, when we receive this message,
    we note that the resource isn't allocated, and get a NULL surface in our
    enter handler. We immediately try to dereference this, and then crash.
    
    This was caused by running gtkperf while moving the window a lot.
    
    Reviewed-by: Daniel Stone <daniel at fooishbar.org>
    Signed-off-by: Jasper St. Pierre <jstpierre at mecheye.net>

diff --git a/hw/xwayland/xwayland-input.c b/hw/xwayland/xwayland-input.c
index cc5f7df..b8c543c 100644
--- a/hw/xwayland/xwayland-input.c
+++ b/hw/xwayland/xwayland-input.c
@@ -152,6 +152,15 @@ pointer_handle_enter(void *data, struct wl_pointer *pointer,
     ScreenPtr pScreen = xwl_seat->xwl_screen->screen;
     ValuatorMask mask;
 
+    /* There's a race here where if we create and then immediately
+     * destroy a surface, we might end up in a state where the Wayland
+     * compositor sends us an event for a surface that doesn't exist.
+     *
+     * Don't process enter events in this case.
+     */
+    if (surface == NULL)
+        return;
+
     xwl_seat->xwl_screen->serial = serial;
     xwl_seat->pointer_enter_serial = serial;
 
commit 1d32004ed5a3a20b2d5879867e213122dced69d0
Author: Michel Dänzer <michel.daenzer at amd.com>
Date:   Wed Sep 10 16:20:48 2014 +0900

    glamor: Make glyph mask cache per-screen
    
    It references a pixmap, which is a per-screen resource.
    
    Fixes broken text rendering in xfwm4-tweak-settings in Zaphod mode.
    
    Signed-off-by: Michel Dänzer <michel.daenzer at amd.com>
    Reviewed-by: Alex Deucher <alexander.deucher at amd.com>
    Signed-off-by: Keith Packard <keithp at keithp.com>

diff --git a/glamor/glamor_glyphs.c b/glamor/glamor_glyphs.c
index 686260c..1f13624 100644
--- a/glamor/glamor_glyphs.c
+++ b/glamor/glamor_glyphs.c
@@ -62,14 +62,6 @@
  */
 #define GLYPH_BUFFER_SIZE 1024
 
-#define CACHE_PICTURE_SIZE 1024
-#define GLYPH_MIN_SIZE 8
-#define GLYPH_MAX_SIZE	64
-#define GLYPH_CACHE_SIZE ((CACHE_PICTURE_SIZE) * CACHE_PICTURE_SIZE / (GLYPH_MIN_SIZE * GLYPH_MIN_SIZE))
-#define MASK_CACHE_MAX_SIZE 32
-#define MASK_CACHE_WIDTH (CACHE_PICTURE_SIZE / MASK_CACHE_MAX_SIZE)
-#define MASK_CACHE_MASK ((1LL << (MASK_CACHE_WIDTH)) - 1)
-
 typedef struct {
     PicturePtr source;
     glamor_composite_rect_t rects[GLYPH_BUFFER_SIZE + 4];
@@ -123,24 +115,8 @@ glamor_glyph_get_private(ScreenPtr screen, GlyphPtr glyph)
  * gain.
  */
 
-struct glamor_glyph_mask_cache_entry {
-    int idx;
-    int width;
-    int height;
-    int x;
-    int y;
-};
-
-static struct glamor_glyph_mask_cache {
-    PixmapPtr pixmap;
-    struct glamor_glyph_mask_cache_entry mcache[MASK_CACHE_WIDTH];
-    unsigned int free_bitmap;
-    unsigned int cleared_bitmap;
-} *mask_cache[GLAMOR_NUM_GLYPH_CACHE_FORMATS] = {
-NULL};
-
 static void
-clear_mask_cache_bitmap(struct glamor_glyph_mask_cache *maskcache,
+clear_mask_cache_bitmap(glamor_glyph_mask_cache_t *maskcache,
                         unsigned int clear_mask_bits)
 {
     unsigned int i = 0;
@@ -162,7 +138,7 @@ clear_mask_cache_bitmap(struct glamor_glyph_mask_cache *maskcache,
 }
 
 static void
-clear_mask_cache(struct glamor_glyph_mask_cache *maskcache)
+clear_mask_cache(glamor_glyph_mask_cache_t *maskcache)
 {
     int x = 0;
     int cnt = MASK_CACHE_WIDTH;
@@ -224,7 +200,7 @@ find_continuous_bits(unsigned int bits, int bits_cnt, unsigned int *pbits_mask)
 }
 
 static struct glamor_glyph_mask_cache_entry *
-get_mask_cache(struct glamor_glyph_mask_cache *maskcache, int blocks)
+get_mask_cache(glamor_glyph_mask_cache_t *maskcache, int blocks)
 {
     int free_cleared_bit, idx = -1;
     int retry_cnt = 0;
@@ -257,7 +233,7 @@ get_mask_cache(struct glamor_glyph_mask_cache *maskcache, int blocks)
 }
 
 static void
-put_mask_cache_bitmap(struct glamor_glyph_mask_cache *maskcache,
+put_mask_cache_bitmap(glamor_glyph_mask_cache_t *maskcache,
                       unsigned int bitmap)
 {
     maskcache->free_bitmap |= bitmap;
@@ -283,8 +259,8 @@ glamor_unrealize_glyph_caches(ScreenPtr pScreen)
         if (cache->glyphs)
             free(cache->glyphs);
 
-        if (mask_cache[i])
-            free(mask_cache[i]);
+        if (glamor->mask_cache[i])
+            free(glamor->mask_cache[i]);
     }
     glamor->glyph_caches_realized = FALSE;
 }
@@ -358,9 +334,9 @@ glamor_realize_glyph_caches(ScreenPtr pScreen)
             goto bail;
 
         cache->evict = rand() % GLYPH_CACHE_SIZE;
-        mask_cache[i] = calloc(1, sizeof(*mask_cache[i]));
-        mask_cache[i]->pixmap = pixmap;
-        clear_mask_cache(mask_cache[i]);
+        glamor->mask_cache[i] = calloc(1, sizeof(*glamor->mask_cache[i]));
+        glamor->mask_cache[i]->pixmap = pixmap;
+        clear_mask_cache(glamor->mask_cache[i]);
     }
     assert(i == GLAMOR_NUM_GLYPH_CACHE_FORMATS);
 
@@ -1182,7 +1158,7 @@ unsigned long long dst_glyphs_cnt = 0;
 struct glyphs_flush_mask_arg {
     PicturePtr mask;
     glamor_glyph_buffer_t *buffer;
-    struct glamor_glyph_mask_cache *maskcache;
+    glamor_glyph_mask_cache_t *maskcache;
     unsigned int used_bitmap;
 };
 
@@ -1398,7 +1374,7 @@ glamor_glyphs_via_mask(CARD8 op,
     glamor_glyph_buffer_t *pmask_buffer;
     struct glyphs_flush_mask_arg *pmask_arg;
     struct glamor_glyph_mask_cache_entry *mce = NULL;
-    struct glamor_glyph_mask_cache *maskcache;
+    glamor_glyph_mask_cache_t *maskcache;
     glamor_glyph_cache_t *cache;
     int glyphs_dst_mode;
 
@@ -1419,7 +1395,7 @@ glamor_glyphs_via_mask(CARD8 op,
 
     cache = &glamor_priv->glyphCaches
         [PICT_FORMAT_RGB(mask_format->format) != 0];
-    maskcache = mask_cache[PICT_FORMAT_RGB(mask_format->format) != 0];
+    maskcache = glamor_priv->mask_cache[PICT_FORMAT_RGB(mask_format->format) != 0];
 
     x = -extents.x1;
     y = -extents.y1;
diff --git a/glamor/glamor_priv.h b/glamor/glamor_priv.h
index 6ebb7b3..aa59e3b 100644
--- a/glamor/glamor_priv.h
+++ b/glamor/glamor_priv.h
@@ -167,6 +167,30 @@ typedef struct {
     uint16_t evict;
 } glamor_glyph_cache_t;
 
+#define CACHE_PICTURE_SIZE 1024
+#define GLYPH_MIN_SIZE 8
+#define GLYPH_MAX_SIZE	64
+#define GLYPH_CACHE_SIZE ((CACHE_PICTURE_SIZE) * CACHE_PICTURE_SIZE / (GLYPH_MIN_SIZE * GLYPH_MIN_SIZE))
+
+#define MASK_CACHE_MAX_SIZE 32
+#define MASK_CACHE_WIDTH (CACHE_PICTURE_SIZE / MASK_CACHE_MAX_SIZE)
+#define MASK_CACHE_MASK ((1LL << (MASK_CACHE_WIDTH)) - 1)
+
+struct glamor_glyph_mask_cache_entry {
+    int idx;
+    int width;
+    int height;
+    int x;
+    int y;
+};
+
+typedef struct {
+    PixmapPtr pixmap;
+    struct glamor_glyph_mask_cache_entry mcache[MASK_CACHE_WIDTH];
+    unsigned int free_bitmap;
+    unsigned int cleared_bitmap;
+} glamor_glyph_mask_cache_t;
+
 struct glamor_saved_procs {
     CloseScreenProcPtr close_screen;
     CreateScreenResourcesProcPtr create_screen_resources;
@@ -268,6 +292,7 @@ typedef struct glamor_screen_private {
         [SHADER_MASK_COUNT]
         [SHADER_IN_COUNT];
     glamor_glyph_cache_t glyphCaches[GLAMOR_NUM_GLYPH_CACHE_FORMATS];
+    glamor_glyph_mask_cache_t *mask_cache[GLAMOR_NUM_GLYPH_CACHE_FORMATS];
     Bool glyph_caches_realized;
 
     /* shaders to restore a texture to another texture. */
commit 710d314ad16cf1eaca3b97b1736ff0ca43e598c4
Author: Michel Dänzer <michel.daenzer at amd.com>
Date:   Wed Sep 10 16:20:47 2014 +0900

    glamor: Track glyph caching information per screen
    
    This is necessary because the glyph caches are per screen.
    
    Fixes broken menu text in gnome-terminal in Zaphod mode.
    
    Signed-off-by: Michel Dänzer <michel.daenzer at amd.com>
    Reviewed-by: Alex Deucher <alexander.deucher at amd.com>
    Signed-off-by: Keith Packard <keithp at keithp.com>

diff --git a/glamor/glamor_glyphs.c b/glamor/glamor_glyphs.c
index b491768..686260c 100644
--- a/glamor/glamor_glyphs.c
+++ b/glamor/glamor_glyphs.c
@@ -96,9 +96,11 @@ typedef enum {
 static DevPrivateKeyRec glamor_glyph_key;
 
 static inline struct glamor_glyph *
-glamor_glyph_get_private(GlyphPtr glyph)
+glamor_glyph_get_private(ScreenPtr screen, GlyphPtr glyph)
 {
-    return (struct glamor_glyph *) glyph->devPrivates;
+    struct glamor_glyph *privates = (struct glamor_glyph*)glyph->devPrivates;
+
+    return &privates[screen->myNum];
 }
 
 /*
@@ -380,7 +382,8 @@ Bool
 glamor_glyphs_init(ScreenPtr pScreen)
 {
     if (!dixRegisterPrivateKey(&glamor_glyph_key,
-                               PRIVATE_GLYPH, sizeof(struct glamor_glyph)))
+                               PRIVATE_GLYPH,
+                               screenInfo.numScreens * sizeof(struct glamor_glyph)))
         return FALSE;
 
     return TRUE;
@@ -460,7 +463,7 @@ glamor_glyph_unrealize(ScreenPtr screen, GlyphPtr glyph)
     struct glamor_glyph *priv;
 
     /* Use Lookup in case we have not attached to this glyph. */
-    priv = glamor_glyph_get_private(glyph);
+    priv = glamor_glyph_get_private(screen, glyph);
 
     if (priv->cached)
         priv->cache->glyphs[priv->pos] = NULL;
@@ -791,7 +794,7 @@ glamor_glyphs_intersect(int nlist, GlyphListPtr list, GlyphPtr *glyphs,
             if (y1 < MINSHORT)
                 y1 = MINSHORT;
             if (check_fake_overlap)
-                priv = glamor_glyph_get_private(glyph);
+                priv = glamor_glyph_get_private(screen, glyph);
 
             x2 = x1 + glyph->info.width;
             y2 = y1 + glyph->info.height;
@@ -1079,7 +1082,7 @@ glamor_glyph_cache(glamor_screen_private *glamor, GlyphPtr glyph, int *out_x,
     mask = glamor_glyph_count_to_mask(s);
     pos = (cache->count + s - 1) & mask;
 
-    priv = glamor_glyph_get_private(glyph);
+    priv = glamor_glyph_get_private(screen, glyph);
     if (pos < GLYPH_CACHE_SIZE) {
         cache->count = pos + s;
     }
@@ -1091,7 +1094,7 @@ glamor_glyph_cache(glamor_screen_private *glamor, GlyphPtr glyph, int *out_x,
             if (evicted == NULL)
                 continue;
 
-            evicted_priv = glamor_glyph_get_private(evicted);
+            evicted_priv = glamor_glyph_get_private(screen, evicted);
             assert(evicted_priv->pos == i);
             if (evicted_priv->size >= s) {
                 cache->glyphs[i] = NULL;
@@ -1112,7 +1115,7 @@ glamor_glyph_cache(glamor_screen_private *glamor, GlyphPtr glyph, int *out_x,
 
                 if (evicted != NULL) {
 
-                    evicted_priv = glamor_glyph_get_private(evicted);
+                    evicted_priv = glamor_glyph_get_private(screen, evicted);
 
                     assert(evicted_priv->pos == pos + s);
                     evicted_priv->cached = FALSE;
@@ -1239,7 +1242,7 @@ glamor_buffer_glyph(glamor_screen_private *glamor_priv,
     glamor_glyph_cache_t *cache;
 
     if (glyphs_dst_mode != GLYPHS_DST_MODE_MASK_TO_DST)
-        priv = glamor_glyph_get_private(glyph);
+        priv = glamor_glyph_get_private(screen, glyph);
 
     if (PICT_FORMAT_BPP(format) == 1)
         format = PICT_a8;
@@ -1297,7 +1300,7 @@ glamor_buffer_glyph(glamor_screen_private *glamor_priv,
             rect->x_src = 0 + dx;
             rect->y_src = 0 + dy;
         }
-        priv = glamor_glyph_get_private(glyph);
+        priv = glamor_glyph_get_private(screen, glyph);
     }
 
     rect->x_dst = x_glyph;
commit a4e8e6dff9a0c26944a325e4017faa68d93ae5b8
Author: Michel Dänzer <michel.daenzer at amd.com>
Date:   Wed Sep 10 16:20:46 2014 +0900

    glamor: Move 'glyph caches realized' check to glamor_realize_glyph_caches
    
    And rename the boolean to reflect what it's about.
    
    Signed-off-by: Michel Dänzer <michel.daenzer at amd.com>
    Reviewed-by: Alex Deucher <alexander.deucher at amd.com>
    Signed-off-by: Keith Packard <keithp at keithp.com>

diff --git a/glamor/glamor_glyphs.c b/glamor/glamor_glyphs.c
index f570d75..b491768 100644
--- a/glamor/glamor_glyphs.c
+++ b/glamor/glamor_glyphs.c
@@ -269,7 +269,7 @@ glamor_unrealize_glyph_caches(ScreenPtr pScreen)
     glamor_screen_private *glamor = glamor_get_screen_private(pScreen);
     int i;
 
-    if (!glamor->glyph_cache_initialized)
+    if (!glamor->glyph_caches_realized)
         return;
 
     for (i = 0; i < GLAMOR_NUM_GLYPH_CACHE_FORMATS; i++) {
@@ -284,7 +284,7 @@ glamor_unrealize_glyph_caches(ScreenPtr pScreen)
         if (mask_cache[i])
             free(mask_cache[i]);
     }
-    glamor->glyph_cache_initialized = FALSE;
+    glamor->glyph_caches_realized = FALSE;
 }
 
 void
@@ -314,6 +314,9 @@ glamor_realize_glyph_caches(ScreenPtr pScreen)
     };
     int i;
 
+    if (glamor->glyph_caches_realized)
+        return TRUE;
+
     memset(glamor->glyphCaches, 0, sizeof(glamor->glyphCaches));
 
     for (i = 0; i < sizeof(formats) / sizeof(formats[0]); i++) {
@@ -359,6 +362,7 @@ glamor_realize_glyph_caches(ScreenPtr pScreen)
     }
     assert(i == GLAMOR_NUM_GLYPH_CACHE_FORMATS);
 
+    glamor->glyph_caches_realized = TRUE;
     return TRUE;
 
  bail:
@@ -375,17 +379,10 @@ glamor_realize_glyph_caches(ScreenPtr pScreen)
 Bool
 glamor_glyphs_init(ScreenPtr pScreen)
 {
-    glamor_screen_private *glamor = glamor_get_screen_private(pScreen);
-
-    if (glamor->glyph_cache_initialized)
-        return TRUE;
-
     if (!dixRegisterPrivateKey(&glamor_glyph_key,
                                PRIVATE_GLYPH, sizeof(struct glamor_glyph)))
         return FALSE;
 
-    glamor->glyph_cache_initialized = TRUE;
-
     return TRUE;
 }
 
diff --git a/glamor/glamor_priv.h b/glamor/glamor_priv.h
index 385c027..6ebb7b3 100644
--- a/glamor/glamor_priv.h
+++ b/glamor/glamor_priv.h
@@ -268,7 +268,7 @@ typedef struct glamor_screen_private {
         [SHADER_MASK_COUNT]
         [SHADER_IN_COUNT];
     glamor_glyph_cache_t glyphCaches[GLAMOR_NUM_GLYPH_CACHE_FORMATS];
-    Bool glyph_cache_initialized;
+    Bool glyph_caches_realized;
 
     /* shaders to restore a texture to another texture. */
     GLint finish_access_prog[2];
commit 0acff6e4374340dc391014f396f190daf73d579c
Author: Michel Dänzer <michel.daenzer at amd.com>
Date:   Wed Sep 10 16:20:45 2014 +0900

    glamor: Call glamor_glyphs_init from glamor_create_screen_resources
    
    The comment above glamor_glyphs_init was already saying so.
    
    Signed-off-by: Michel Dänzer <michel.daenzer at amd.com>
    Reviewed-by: Alex Deucher <alexander.deucher at amd.com>
    Signed-off-by: Keith Packard <keithp at keithp.com>

diff --git a/glamor/glamor.c b/glamor/glamor.c
index 521bc25..e582e50 100644
--- a/glamor/glamor.c
+++ b/glamor/glamor.c
@@ -296,6 +296,11 @@ glamor_create_screen_resources(ScreenPtr screen)
         ret = screen->CreateScreenResources(screen);
     screen->CreateScreenResources = glamor_create_screen_resources;
 
+    if (!glamor_glyphs_init(screen)) {
+        ErrorF("Failed to initialize glyphs\n");
+        ret = FALSE;
+    }
+
     if (!glamor_realize_glyph_caches(screen)) {
         ErrorF("Failed to initialize glyph cache\n");
         ret = FALSE;
@@ -518,7 +523,6 @@ glamor_init(ScreenPtr screen, unsigned int flags)
     glamor_init_gradient_shader(screen);
 #endif
     glamor_pixmap_init(screen);
-    glamor_glyphs_init(screen);
     glamor_sync_init(screen);
 
     glamor_priv->screen = screen;
commit 54a1d4db825be90fb7be138e3267a15922d62f03
Merge: 8f8dcfe f92df22
Author: Keith Packard <keithp at keithp.com>
Date:   Thu Sep 11 18:27:41 2014 -0700

    Merge remote-tracking branch 'jturney/master'

commit 8f8dcfee2085ba82107a8bf3872a0bb241493409
Author: Alan Coopersmith <alan.coopersmith at oracle.com>
Date:   Thu Sep 4 23:18:03 2014 -0700

    Make list tests actually test lists
    
    Coverity scan detected that asserts were setting values, not checking them:
    
    CID 53252: Side effect in assertion (ASSERT_SIDE_EFFECT)
      assignment_where_comparison_intended: Assignment item->b = i * 2
      has a side effect. This code will work differently in a non-debug build.
      Did you intend to use a comparison ("==") instead?
    
    CID 53259: Side effect in assertion (ASSERT_SIDE_EFFECT)
      assignment_where_comparison_intended: Assignment item->a = i
      has a side effect. This code will work differently in a non-debug build.
      Did you intend to use a comparison ("==") instead?
    
    CID 53260: Side effect in assertion (ASSERT_SIDE_EFFECT)
      assignment_where_comparison_intended: Assignment item->a = i
      has a side effect. This code will work differently in a non-debug build.
      Did you intend to use a comparison ("==") instead?
    
    CID 53261: Side effect in assertion (ASSERT_SIDE_EFFECT)
      assignment_where_comparison_intended: Assignment item->b = i * 2
      has a side effect. This code will work differently in a non-debug build.
      Did you intend to use a comparison ("==") instead?
    
    Fixing those to be == caused test_nt_list_insert to start failing as
    part assumed append order, part assumed insert order, so it had to be
    fixed to use consistent ordering.
    
    Signed-off-by: Alan Coopersmith <alan.coopersmith at oracle.com>
    Reviewed-by: Peter Hutterer <peter.hutterer at who-t.net>
    Signed-off-by: Keith Packard <keithp at keithp.com>

diff --git a/test/list.c b/test/list.c
index f9f54ee..28d9609 100644
--- a/test/list.c
+++ b/test/list.c
@@ -249,15 +249,15 @@ test_nt_list_append(void)
 
     /* Test using nt_list_next */
     for (item = foo, i = 1; i <= 10; i++, item = nt_list_next(item, next)) {
-        assert(item->a = i);
-        assert(item->b = i * 2);
+        assert(item->a == i);
+        assert(item->b == i * 2);
     }
 
     /* Test using nt_list_for_each_entry */
     i = 1;
     nt_list_for_each_entry(item, foo, next) {
-        assert(item->a = i);
-        assert(item->b = i * 2);
+        assert(item->a == i);
+        assert(item->b == i * 2);
         i++;
     }
     assert(i == 11);
@@ -270,11 +270,11 @@ test_nt_list_insert(void)
     struct foo *foo = calloc(10, sizeof(struct foo));
     struct foo *item;
 
-    foo->a = 10;
-    foo->b = 20;
+    foo->a = 1;
+    foo->b = 2;
     nt_list_init(foo, next);
 
-    for (item = &foo[1], i = 9; i > 0; i--, item++) {
+    for (item = &foo[1], i = 10; i > 1; i--, item++) {
         item->a = i;
         item->b = i * 2;
         nt_list_init(item, next);
@@ -282,16 +282,16 @@ test_nt_list_insert(void)
     }
 
     /* Test using nt_list_next */
-    for (item = foo, i = 10; i > 0; i--, item = nt_list_next(item, next)) {
-        assert(item->a = i);
-        assert(item->b = i * 2);
+    for (item = foo, i = 1; i <= 10; i++, item = nt_list_next(item, next)) {
+        assert(item->a == i);
+        assert(item->b == i * 2);
     }
 
     /* Test using nt_list_for_each_entry */
     i = 1;
     nt_list_for_each_entry(item, foo, next) {
-        assert(item->a = i);
-        assert(item->b = i * 2);
+        assert(item->a == i);
+        assert(item->b == i * 2);
         i++;
     }
     assert(i == 11);
commit d0da0e9c3bb8fe0cd4879ecb24d21715bfaa209b
Author: Eric Anholt <eric at anholt.net>
Date:   Thu Sep 4 10:59:40 2014 -0700

    glx: Disable indirect GLX contexts by default.
    
    Almost every situation of someone running indirect GLX is a mistake
    that results in X Server crashes.  Indirect GLX is the cause of
    regular security vulnerabilities, and rarely provides any capability
    to the user.  Just disable it unless someone wants to enable it for
    their special use case (using +iglx on the command line).
    
    Signed-off-by: Eric Anholt <eric at anholt.net>
    Acked-by:  Keith Packard <keithp at keithp.com>
    Signed-off-by: Keith Packard <keithp at keithp.com>

diff --git a/os/utils.c b/os/utils.c
index f319743..c83f77d 100644
--- a/os/utils.c
+++ b/os/utils.c
@@ -194,7 +194,7 @@ Bool noGEExtension = FALSE;
 
 Bool CoreDump;
 
-Bool enableIndirectGLX = TRUE;
+Bool enableIndirectGLX = FALSE;
 
 #ifdef PANORAMIX
 Bool PanoramiXExtensionDisabledHack = FALSE;
commit bf338efc678258d2d366dff2ed873752f98f0bfc
Author: Keith Packard <keithp at keithp.com>
Date:   Thu Sep 4 08:36:07 2014 -0700

    glx/present: Only send GLX_BufferSwapComplete for PresentCompleteKindPixmap
    
    Present didn't provide the 'kind' argument to the
    present_complete_notify hook that GLX uses to construct
    GLX_BufferSwapComplete events, so GLX was reporting events for
    PresentCompleteKindMSC notifications, which resulted in duplicate
    GLX_BufferSwapComplete events and crashes in clutter.
    
    See the gnome bug: https://bugzilla.gnome.org/show_bug.cgi?id=733282
    
    Signed-off-by: Keith Packard <keithp at keithp.com>
    Reviewed-by: Eric Anholt <eric at anholt.net>

diff --git a/glx/glxcmds.c b/glx/glxcmds.c
index 2fc3f4c..d11c667 100644
--- a/glx/glxcmds.c
+++ b/glx/glxcmds.c
@@ -2508,13 +2508,16 @@ __glXsendSwapEvent(__GLXdrawable *drawable, int type, CARD64 ust,
 
 #if PRESENT
 static void
-__glXpresentCompleteNotify(WindowPtr window, CARD8 present_mode, CARD32 serial,
-                           uint64_t ust, uint64_t msc)
+__glXpresentCompleteNotify(WindowPtr window, CARD8 present_kind, CARD8 present_mode,
+                           CARD32 serial, uint64_t ust, uint64_t msc)
 {
     __GLXdrawable *drawable;
     int glx_type;
     int rc;
 
+    if (present_kind != PresentCompleteKindPixmap)
+        return;
+
     rc = dixLookupResourceByType((void **) &drawable, window->drawable.id,
                                  __glXDrawableRes, serverClient, DixGetAttrAccess);
 
diff --git a/present/present.h b/present/present.h
index 0e3bdc0..aab2e16 100644
--- a/present/present.h
+++ b/present/present.h
@@ -116,6 +116,7 @@ extern _X_EXPORT Bool
 present_screen_init(ScreenPtr screen, present_screen_info_ptr info);
 
 typedef void (*present_complete_notify_proc)(WindowPtr window,
+                                             CARD8 kind,
                                              CARD8 mode,
                                              CARD32 serial,
                                              uint64_t ust,
diff --git a/present/present_event.c b/present/present_event.c
index ff57eba..d3a59ea 100644
--- a/present/present_event.c
+++ b/present/present_event.c
@@ -174,7 +174,7 @@ present_send_complete_notify(WindowPtr window, CARD8 kind, CARD8 mode, CARD32 se
         }
     }
     if (complete_notify)
-        (*complete_notify)(window, mode, serial, ust, msc);
+        (*complete_notify)(window, kind, mode, serial, ust, msc);
 }
 
 void
commit 7a0c79c8c478bf22ee71c1ea35886a6f555ef2bb
Author: Thomas Petazzoni <thomas.petazzoni at free-electrons.com>
Date:   Tue Sep 2 22:03:14 2014 +0200

    os/log: adjust gcc version conditions for #pragma
    
    In commit e67f2d7e0f9189beb2907fa06cff5ecc7f35f922 ("gcc 4.2.1 doesn't
    support #pragma GCC diagnostic ignored"), some compile time
    conditionals were added around the #pragma usage. Those conditionals
    ensure that the #pragma are not used on gcc <= 4.2.
    
    However, the usage of #pragma diagnostic inside functions was only
    added in gcc 4.6, and a build failure is therefore experienced with
    gcc 4.5:
    
    log.c: In function 'LogInit':
    log.c:199:9: error: #pragma GCC diagnostic not allowed inside functions
    log.c:201:9: warning: format not a string literal, argument types not checked
    log.c:212:9: error: #pragma GCC diagnostic not allowed inside functions
    log.c:214:17: warning: format not a string literal, argument types not checked
    
    $ ./host/usr/bin/powerpc-linux-gnu-gcc -v
    [...]
    gcc version 4.5.2 (Sourcery G++ Lite 2011.03-38)
    
    This patch therefore adjusts the compile time conditionals to make
    sure the #pragma is not used on gcc <= 4.5, and only used on gcc >=
    4.6.
    
    Signed-off-by: Thomas Petazzoni <thomas.petazzoni at free-electrons.com>
    Acked-by:  Keith Packard <keithp at keithp.com>
    Signed-off-by: Keith Packard <keithp at keithp.com>

diff --git a/os/log.c b/os/log.c
index 2a721b9..629021e 100644
--- a/os/log.c
+++ b/os/log.c
@@ -195,7 +195,7 @@ LogInit(const char *fname, const char *backup)
     char *logFileName = NULL;
 
     if (fname && *fname) {
-#if __GNUC__ > 4 || __GNUC__ == 4 && __GNUC_MINOR__ > 2
+#if __GNUC__ > 4 || __GNUC__ == 4 && __GNUC_MINOR__ > 5
 #pragma GCC diagnostic ignored "-Wformat-nonliteral"
 #endif
         if (asprintf(&logFileName, fname, display) == -1)
@@ -208,7 +208,7 @@ LogInit(const char *fname, const char *backup)
                 char *suffix;
                 char *oldLog;
 
-#if __GNUC__ > 4 || __GNUC__ == 4 && __GNUC_MINOR__ > 2
+#if __GNUC__ > 4 || __GNUC__ == 4 && __GNUC_MINOR__ > 5
 #pragma GCC diagnostic ignored "-Wformat-nonliteral"
 #endif
                 if ((asprintf(&suffix, backup, display) == -1) ||
commit da4bad620a6f1a58978f5279fda74da3c1c1d443
Author: Dave Airlie <airlied at gmail.com>
Date:   Tue Jul 30 13:50:48 2013 +1000

    pixmap: fix reverse optimus support with multiple heads
    
    For doing reverese optimus to multiple outputs on a secondary GPU
    the GPU can store the blits into a large screen pixmap, unfortunately
    this means we need a destination offset into the dirty code, so
    add a new API that just adds this interface.
    
    Signed-off-by: Dave Airlie <airlied at redhat.com>
    Reviewed-by: Chris Wilson <chris at chris-wilson.co.uk>
    Signed-off-by: Keith Packard <keithp at keithp.com>

diff --git a/dix/pixmap.c b/dix/pixmap.c
index 4b880af..00e298f 100644
--- a/dix/pixmap.c
+++ b/dix/pixmap.c
@@ -164,9 +164,9 @@ PixmapPtr PixmapShareToSlave(PixmapPtr pixmap, ScreenPtr slave)
 }
 
 Bool
-PixmapStartDirtyTracking(PixmapPtr src,
-                         PixmapPtr slave_dst,
-                         int x, int y)
+PixmapStartDirtyTracking2(PixmapPtr src,
+			  PixmapPtr slave_dst,
+			  int x, int y, int dst_x, int dst_y)
 {
     ScreenPtr screen = src->drawable.pScreen;
     PixmapDirtyUpdatePtr dirty_update;
@@ -179,6 +179,8 @@ PixmapStartDirtyTracking(PixmapPtr src,
     dirty_update->slave_dst = slave_dst;
     dirty_update->x = x;
     dirty_update->y = y;
+    dirty_update->dst_x = dst_x;
+    dirty_update->dst_y = dst_y;
 
     dirty_update->damage = DamageCreate(NULL, NULL,
                                         DamageReportNone,
@@ -195,6 +197,14 @@ PixmapStartDirtyTracking(PixmapPtr src,
 }
 
 Bool
+PixmapStartDirtyTracking(PixmapPtr src,
+			 PixmapPtr slave_dst,
+			 int x, int y)
+{
+   return PixmapStartDirtyTracking2(src, slave_dst, x, y, 0, 0);
+}
+
+Bool
 PixmapStopDirtyTracking(PixmapPtr src, PixmapPtr slave_dst)
 {
     ScreenPtr screen = src->drawable.pScreen;
@@ -261,7 +271,7 @@ Bool PixmapSyncDirtyHelper(PixmapDirtyUpdatePtr dirty, RegionPtr dirty_region)
         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);
+                           dirty->x + dst_box.x1, dirty->y + dst_box.y1, w, h, dirty->dst_x + dst_box.x1, dirty->dst_y + dst_box.y1);
         b++;
     }
     FreeScratchGC(pGC);
diff --git a/include/pixmap.h b/include/pixmap.h
index f3c2c60..4b8fc24 100644
--- a/include/pixmap.h
+++ b/include/pixmap.h
@@ -120,6 +120,12 @@ PixmapStartDirtyTracking(PixmapPtr src,
                          PixmapPtr slave_dst,
                          int x, int y);
 
+#define HAS_DIRTYTRACKING2 1
+extern _X_EXPORT Bool
+PixmapStartDirtyTracking2(PixmapPtr src,
+			  PixmapPtr slave_dst,
+			  int x, int y, int dst_x, int dst_y);
+
 extern _X_EXPORT Bool
 PixmapStopDirtyTracking(PixmapPtr src, PixmapPtr slave_dst);
 
diff --git a/include/pixmapstr.h b/include/pixmapstr.h
index 2a1ef9b..2bdff98 100644
--- a/include/pixmapstr.h
+++ b/include/pixmapstr.h
@@ -90,6 +90,7 @@ typedef struct _PixmapDirtyUpdate {
     int x, y;
     DamagePtr damage;
     struct xorg_list ent;
+    int dst_x, dst_y;
 } PixmapDirtyUpdateRec;
 
 static inline void
commit e1cc0d3df1fdb6c4393ac455ca038e1e0680bb22
Author: Maks Naumov <maksqwe1 at ukr.net>
Date:   Thu Aug 21 12:58:16 2014 -0700

    glx: Fix 'y ' value in swrastGetDrawableInfo()
    
    Signed-off-by: Maks Naumov <maksqwe1 at ukr.net>
    Reviewed-by: Eric Anholt <eric at anholt.net>
    Signed-off-by: Keith Packard <keithp at keithp.com>

diff --git a/glx/glxdriswrast.c b/glx/glxdriswrast.c
index c30ce9a..5d9aa04 100644
--- a/glx/glxdriswrast.c
+++ b/glx/glxdriswrast.c
@@ -325,7 +325,7 @@ swrastGetDrawableInfo(__DRIdrawable * draw,
     DrawablePtr pDraw = drawable->base.pDraw;
 
     *x = pDraw->x;
-    *y = pDraw->x;
+    *y = pDraw->y;
     *w = pDraw->width;
     *h = pDraw->height;
 }
commit f92df22a037cb8b672dab2e7aef18a22275f5660
Author: Jon TURNEY <jon.turney at dronecode.org.uk>
Date:   Fri Jul 18 15:08:17 2014 +0100

    hw/xwin/glx: Remove an incorrect assertion in glxWinDrawableSwapBuffers
    
    The piglit test glx_make_current triggers this assertion, by making the context
    current on a different drawable before issuing a glXSwapBuffers()
    
    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 70b9156..93cdb29 100644
--- a/hw/xwin/glx/indirect.c
+++ b/hw/xwin/glx/indirect.c
@@ -890,13 +890,6 @@ glxWinDrawableSwapBuffers(ClientPtr client, __GLXdrawable * base)
         ("glxWinSwapBuffers on drawable %p, last context %p (native ctx %p)",
          base, draw->drawContext, draw->drawContext->ctx);
 
-    /*
-       draw->drawContext->base.drawPriv will not be set if the context is not current anymore,
-       but if it is, it should point to this drawable....
-     */
-    assert((draw->drawContext->base.drawPriv == NULL) ||
-           (draw->drawContext->base.drawPriv == base));
-
     dc = glxWinMakeDC(draw->drawContext, draw, &dc, &hwnd);
     if (dc == NULL)
         return GL_FALSE;
commit b21321e515fc778f87077b7ce47922c43a4ba103
Author: Jon TURNEY <jon.turney at dronecode.org.uk>
Date:   Mon Jul 14 19:41:25 2014 +0100

    hw/xwin/glx: Downgrade "forcing window to exist" message to debug
    
    It happens whenever a GLX client uses GL on a window before it's been mapped, so
    don't log it like an error.
    
    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/winpriv.c b/hw/xwin/glx/winpriv.c
index 4f6e4ff..9b4baf3 100644
--- a/hw/xwin/glx/winpriv.c
+++ b/hw/xwin/glx/winpriv.c
@@ -51,7 +51,7 @@ winGetWindowInfo(WindowPtr pWin)
 
             if (pWinPriv->hWnd == NULL) {
                 winCreateWindowsWindow(pWin);
-                ErrorF("winGetWindowInfo: forcing window to exist...\n");
+                winDebug("winGetWindowInfo: forcing window to exist\n");
             }
 
             if (pWinPriv->hWnd != NULL) {
commit 31d089633683ea2a2716651c3c48e1456cc595bf
Author: Jon TURNEY <jon.turney at dronecode.org.uk>
Date:   Wed Jul 16 13:44:33 2014 +0100

    hw/xwin/glx: Fix a couple of typo bugs in indirect.c
    
    fbConfigToPixelFormatIndex()'s drawableTypeOverride parameter is a drawable
    type bitmask, not a drawable type enum value
    
    WGL_SWAP_COPY_ARB is a value of the WGL_SWAP_METHOD_ARB attribute for
    wglChoosePixelFormatARB(), not an attribute itself
    
    also remove duplicate error reporting for wglChoosePixelFormat() and fix a
    comment
    
    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 6c03033..70b9156 100644
--- a/hw/xwin/glx/indirect.c
+++ b/hw/xwin/glx/indirect.c
@@ -1120,7 +1120,6 @@ glxWinSetPixelFormat(__GLXWinContext * gc, HDC hdc, int bppOverride,
             fbConfigToPixelFormatIndex(hdc, gc->base.config,
                                        drawableTypeOverride, winScreen);
         if (pixelFormat == 0) {
-            ErrorF("wglChoosePixelFormat error: %s\n", glxWinErrorMessage());
             return FALSE;
         }
 
@@ -1303,7 +1302,7 @@ glxWinDeferredCreateContext(__GLXWinContext * gc, __GLXWinDrawable * draw)
             glxWinScreen *winScreen;
             int pixelFormat;
 
-            // XXX: which DC are supposed to use???
+            // XXX: which DC are we supposed to use???
             HDC screenDC = GetDC(NULL);
 
             if (!(gc->base.config->drawableType & GLX_PBUFFER_BIT)) {
@@ -1316,10 +1315,8 @@ glxWinDeferredCreateContext(__GLXWinContext * gc, __GLXWinDrawable * draw)
 
             pixelFormat =
                 fbConfigToPixelFormatIndex(screenDC, gc->base.config,
-                                           GLX_DRAWABLE_PBUFFER, winScreen);
+                                           GLX_PBUFFER_BIT, winScreen);
             if (pixelFormat == 0) {
-                ErrorF("wglChoosePixelFormat error: %s\n",
-                       glxWinErrorMessage());
                 return;
             }
 
@@ -1758,7 +1755,7 @@ fbConfigToPixelFormatIndex(HDC hdc, __GLXconfig * mode,
         SET_ATTR_VALUE(WGL_SWAP_METHOD_ARB, WGL_SWAP_EXCHANGE_ARB);
 
     if (mode->swapMethod == GLX_SWAP_COPY_OML)
-        SET_ATTR_VALUE(WGL_SWAP_COPY_ARB, TRUE);
+        SET_ATTR_VALUE(WGL_SWAP_METHOD_ARB, WGL_SWAP_COPY_ARB);
 
     // XXX: this should probably be the other way around, but that messes up drawableTypeOverride
     if (mode->visualRating == GLX_SLOW_VISUAL_EXT)
commit b1ea714cdce8444c6ad7778dae04e35c6bcc1750
Author: Jon TURNEY <jon.turney at dronecode.org.uk>
Date:   Sun Apr 27 22:10:31 2014 +0100

    hw/xwin/glx: Update .gitignore
    
    Update to align with rewrite of wrapper generation script in commit
    583a1146233f16d861706926706e5feec3baffba
    
    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/.gitignore b/hw/xwin/glx/.gitignore
index 062fd85..9684410 100644
--- a/hw/xwin/glx/.gitignore
+++ b/hw/xwin/glx/.gitignore
@@ -1,3 +1,6 @@
 # ignore generated files
-generated_gl_wrappers.c
+diag.txt
+generated_gl_shim.c
+generated_gl_thunks.c
+generated_gl_thunks.def
 generated_wgl_wrappers.c
commit d1d3bd359670a8f55c9350fd905af32ba6e67d33
Author: Jon TURNEY <jon.turney at dronecode.org.uk>
Date:   Sun Mar 30 20:51:36 2014 +0100

    hw/xwin/glx: Don't override the server supported GL extensions string.
    
    Don't override the server supported GL extensions string.
    
    The string reported to the client is the intersection of client, server and GL
    implementation extensions.
    
    Overriding the server supported GL extensions string like this causes extensions
    which are supported by the client and implementation, but not by the server, to
    be erroneously reported, so don't change it.
    
    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 9bfaac0..6c03033 100644
--- a/hw/xwin/glx/indirect.c
+++ b/hw/xwin/glx/indirect.c
@@ -738,9 +738,6 @@ glxWinScreenProbe(ScreenPtr pScreen)
 
         __glXScreenInit(&screen->base, pScreen);
 
-        // Override the GL extensions string set by __glXScreenInit()
-        screen->base.GLextensions = strdup(gl_extensions);
-
         // Generate the GLX extensions string (overrides that set by __glXScreenInit())
         {
             unsigned int buffer_size =
commit c99cd058a89bbfc9ceab3c91b93451f70351ddce
Author: Jon TURNEY <jon.turney at dronecode.org.uk>
Date:   Tue Mar 4 22:37:13 2014 +0000

    hw/xwin: Add an idempotency guard to glwindows.h
    
    Add an idempotency guard to glwindows.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/glwindows.h b/hw/xwin/glx/glwindows.h
index 4f859b4..34ff24c 100644
--- a/hw/xwin/glx/glwindows.h
+++ b/hw/xwin/glx/glwindows.h
@@ -28,6 +28,9 @@
  * DEALINGS IN THE SOFTWARE.
  */
 
+#ifndef GLWINDOWS_H
+#define GLWINDOWS_H
+
 #include <GL/gl.h>
 
 typedef struct {
@@ -53,3 +56,5 @@ int glWinSelectImplementation(int native);
 #define GLWIN_TRACE_MSG(a, ...)
 #define GLWIN_DEBUG_MSG(a, ...)
 #endif
+
+#endif
commit 1c34e774eff6c5a22501833444a10440cf3f915a
Author: Jon TURNEY <jon.turney at dronecode.org.uk>
Date:   Mon Nov 11 15:09:18 2013 +0000

    hw/xwin: Fix a potential crash in winRedrawScreenShadowDDNL()
    
    Seen during shutdown when using '-fullscreen' and '-depth 8'
    
    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/winshadddnl.c b/hw/xwin/winshadddnl.c
index 55af5c3..cb326dc 100644
--- a/hw/xwin/winshadddnl.c
+++ b/hw/xwin/winshadddnl.c
@@ -986,6 +986,10 @@ winRedrawScreenShadowDDNL(ScreenPtr pScreen)
     RECT rcSrc, rcDest;
     POINT ptOrigin;
 
+    /* Return immediately if we didn't get needed surfaces */
+    if (!pScreenPriv->pddsPrimary4 || !pScreenPriv->pddsShadow4)
+        return;
+
     /* Get the origin of the window in the screen coords */
     ptOrigin.x = pScreenInfo->dwXOffset;
     ptOrigin.y = pScreenInfo->dwYOffset;
commit 16d9da08861fe504de4be8c31708592e30687156
Author: Jon TURNEY <jon.turney at dronecode.org.uk>
Date:   Thu Feb 18 23:36:27 2010 -0600

    hw/xwin: Improve choice of display name used by internal clients
    
    Choose the display name used to connect to internal clients and exported into
    environment of processes started from the traymenu so that it uses a transport
    we know is working
    
    This should mean the server can start correctly with -multiwindow and/or
    -clipboard and any two of -nolisten inet6, -nolisten inet and -nolisten unix
    (the server will correctly refuse to start if all 3 are used, as it must be
    listening on at least one socket)
    
    v2:
    Place prototype for winGetDisplayName() in windisplay.h, and include it where
    needed.
    
    v3:
    Include xwin-config.h, so that _XSERVER64 is defined, just in case anything
    relies on that.
    
    v4:
    Replace grovelling around in the server's list of listeners with new Xtrans
    TransIsListening() interface, added in Xtrans 1.3.3
    
    See also [1]
    
    [1] https://sourceware.org/bugzilla/show_bug.cgi?id=10725
    
    Signed-off-by: Jon TURNEY <jon.turney at dronecode.org.uk>
    Reviewed-by: Yaakov Selkowitz <yselkowitz at users.sourceforge.net>
    Reviewed-by: Colin Harrison <colin.harrison at virgin.net>

diff --git a/hw/xwin/Makefile.am b/hw/xwin/Makefile.am
index 5908dfc..326ffa0 100644
--- a/hw/xwin/Makefile.am
+++ b/hw/xwin/Makefile.am
@@ -126,6 +126,8 @@ SRCS =	InitInput.c \
 	winprefs.h \
 	winresource.h \
 	winwindow.h \
+	windisplay.c \
+	windisplay.h \
 	XWin.rc \
 	$(top_srcdir)/mi/miinitext.c \
 	$(SRCS_CLIPBOARD) \
diff --git a/hw/xwin/winclipboardthread.c b/hw/xwin/winclipboardthread.c
index 33595be..e708960 100644
--- a/hw/xwin/winclipboardthread.c
+++ b/hw/xwin/winclipboardthread.c
@@ -38,6 +38,7 @@
 #include <sys/types.h>
 #include <signal.h>
 #include "winclipboard.h"
+#include "windisplay.h"
 #ifdef __CYGWIN__
 #include <errno.h>
 #endif
@@ -157,7 +158,7 @@ winClipboardProc(void *pvNotUsed)
      * for all screens on the display.  That is why there is only
      * one clipboard client thread.
      */
-    snprintf(szDisplay, 512, "127.0.0.1:%s.0", display);
+    winGetDisplayName(szDisplay, 0);
 
     /* Print the display connection string */
     ErrorF("winClipboardProc - DISPLAY=%s\n", szDisplay);
diff --git a/hw/xwin/windisplay.c b/hw/xwin/windisplay.c
new file mode 100644
index 0000000..17f0c77
--- /dev/null
+++ b/hw/xwin/windisplay.c
@@ -0,0 +1,64 @@
+/*
+ * File: windisplay.c
+ * Purpose: Retrieve server display name
+ *
+ * Copyright (C) Jon TURNEY 2009
+ *
+ * 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_XWIN_CONFIG_H
+#include <xwin-config.h>
+#endif
+
+#include <opaque.h>             // for display
+#include "windisplay.h"
+#include "winmsg.h"
+
+#define XSERV_t
+#define TRANS_SERVER
+#include <X11/Xtrans/Xtrans.h>
+
+/*
+  Generate a display name string referring to the display of this server,
+  using a transport we know is enabled
+*/
+
+void
+winGetDisplayName(char *szDisplay, unsigned int screen)
+{
+    if (_XSERVTransIsListening("local")) {
+        snprintf(szDisplay, 512, ":%s.%d", display, screen);
+    }
+    else if (_XSERVTransIsListening("inet")) {
+        snprintf(szDisplay, 512, "127.0.0.1:%s.%d", display, screen);
+    }
+    else if (_XSERVTransIsListening("inet6")) {
+        snprintf(szDisplay, 512, "::1:%s.%d", display, screen);
+    }
+    else {
+        // this can't happen!
+        ErrorF("winGetDisplay: Don't know what to use for DISPLAY\n");
+        snprintf(szDisplay, 512, "localhost:%s.%d", display, screen);
+    }
+
+    winDebug("winGetDisplay: DISPLAY=%s\n", szDisplay);
+}
diff --git a/hw/xwin/windisplay.h b/hw/xwin/windisplay.h
new file mode 100644
index 0000000..d1d4549
--- /dev/null
+++ b/hw/xwin/windisplay.h
@@ -0,0 +1,34 @@
+/*
+ * File: windisplay.h
+ * Purpose: Interface to retrieve server display name
+ *
+ * Copyright (C) Jon TURNEY 2009
+ *
+ * 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.
+ *
+ */
+
+#ifndef WINDISPLAY_H
+#define WINDISPLAY_H
+
+void
+winGetDisplayName(char *szDisplay, unsigned int screen);
+
+#endif /* !WINDISPLAY_H */
diff --git a/hw/xwin/winmsg.h b/hw/xwin/winmsg.h
index b638f2c..6c96c40 100644
--- a/hw/xwin/winmsg.h
+++ b/hw/xwin/winmsg.h
@@ -30,6 +30,8 @@
  * Authors: Alexander Gottwald	
  */
 
+#include <X11/Xwindows.h>
+
 /*
  * Function prototypes
  */
diff --git a/hw/xwin/winmultiwindowwm.c b/hw/xwin/winmultiwindowwm.c
index 618e381..e17a950 100644
--- a/hw/xwin/winmultiwindowwm.c
+++ b/hw/xwin/winmultiwindowwm.c
@@ -61,6 +61,7 @@
 #include "pixmapstr.h"
 #include "windowstr.h"
 #include "winglobals.h"
+#include "windisplay.h"
 
 #ifdef XWIN_MULTIWINDOWEXTWM
 #include <X11/extensions/windowswmstr.h>
@@ -1053,8 +1054,7 @@ winMultiWindowXMsgProc(void *pArg)
     }
 
     /* Setup the display connection string x */
-    snprintf(pszDisplay,
-             512, "127.0.0.1:%s.%d", display, (int) pProcArg->dwScreen);
+    winGetDisplayName(pszDisplay, (int) pProcArg->dwScreen);
 
     /* Print the display connection string */
     ErrorF("winMultiWindowXMsgProc - DISPLAY=%s\n", pszDisplay);
@@ -1446,8 +1446,7 @@ winInitMultiWindowWM(WMInfoPtr pWMInfo, WMProcArgPtr pProcArg)
     }
 
     /* Setup the display connection string x */
-    snprintf(pszDisplay,
-             512, "127.0.0.1:%s.%d", display, (int) pProcArg->dwScreen);
+    winGetDisplayName(pszDisplay, (int) pProcArg->dwScreen);
 
     /* Print the display connection string */
     ErrorF("winInitMultiWindowWM - DISPLAY=%s\n", pszDisplay);
diff --git a/hw/xwin/winprefs.c b/hw/xwin/winprefs.c
index f386fac..53abc16 100644
--- a/hw/xwin/winprefs.c
+++ b/hw/xwin/winprefs.c
@@ -44,6 +44,7 @@
 #include <shellapi.h>
 
 #include "winprefs.h"
+#include "windisplay.h"
 #include "winmultiwindowclass.h"
 
 /* Where will the custom menu commands start counting from? */
@@ -712,15 +713,14 @@ LoadPreferences(void)
 
     /* Setup a DISPLAY environment variable, need to allocate on heap */
     /* because putenv doesn't copy the argument... */
-    snprintf(szDisplay, 512, "DISPLAY=127.0.0.1:%s.0", display);
-    szEnvDisplay = (char *) (malloc(strlen(szDisplay) + 1));
+    winGetDisplayName(szDisplay, 0);
+    szEnvDisplay = (char *) (malloc(strlen(szDisplay) + strlen("DISPLAY=") + 1));
     if (szEnvDisplay) {
-        strcpy(szEnvDisplay, szDisplay);
+        snprintf(szEnvDisplay, 512, "DISPLAY=%s", szDisplay);
         putenv(szEnvDisplay);
     }
 
     /* Replace any "%display%" in menu commands with display string */
-    snprintf(szDisplay, 512, "127.0.0.1:%s.0", display);
     for (i = 0; i < pref.menuItems; i++) {
         for (j = 0; j < pref.menu[i].menuItems; j++) {
             if (pref.menu[i].menuItem[j].cmd == CMD_EXEC) {
commit 95357539c1178a97d8a167461806a280d2803ec4
Author: Jon TURNEY <jon.turney at dronecode.org.uk>
Date:   Wed Jan 1 20:34:36 2014 +0000

    hw/xwin: Makefile.am cleanup
    
    - Rename XWIN_GLX_LINK_FLAGS -> XWIN_GLX_SYS_LIBS for consistency
    - Rename MULTIWINDOW_LIBS -> MULTIWINDOW_SYS_LIBS for consistency
    - Don't link with XWin with $(MAIN_LIB), it provides it's own main()
    - Put one library per line for more intelligible diffs when one is added
    
    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/Makefile.am b/hw/xwin/Makefile.am
index 4ee9632..5908dfc 100644
--- a/hw/xwin/Makefile.am
+++ b/hw/xwin/Makefile.am
@@ -15,7 +15,7 @@ if XWIN_GLX_WINDOWS
 GLX_DIR = glx
 DEFS_GLX_WINDOWS = -DXWIN_GLX_WINDOWS
 XWIN_GLX_LIBS = $(top_builddir)/hw/xwin/glx/libXwinGLX.la
-XWIN_GLX_LINK_FLAGS = -lopengl32
+XWIN_GLX_SYS_LIBS = -lopengl32
 endif
 
 if XWIN_MULTIWINDOW
@@ -27,7 +27,7 @@ SRCS_MULTIWINDOW = \
 	propertystore.h \
 	winSetAppUserModelID.c
 DEFS_MULTIWINDOW = -DXWIN_MULTIWINDOW
-MULTIWINDOW_LIBS = -lshlwapi -lole32
+MULTIWINDOW_SYS_LIBS = -lshlwapi -lole32
 endif
 
 if XWIN_MULTIWINDOWEXTWM
@@ -150,11 +150,28 @@ XWin_SOURCES = $(SRCS)
 AM_CPPFLAGS = -I$(top_srcdir)/miext/rootless
 
 XWIN_SYS_LIBS += -ldxguid
-XWIN_LIBS += 	$(top_builddir)/pseudoramiX/libPseudoramiX.la \
-                $(top_builddir)/Xext/libXextdpmsstubs.la \
-                $(top_builddir)/Xi/libXistubs.la
-XWin_DEPENDENCIES = $(MULTIWINDOWEXTWM_LIBS) $(XWIN_GLX_LIBS) $(XWIN_LIBS) $(XSERVER_LIBS)
-XWin_LDADD = $(MULTIWINDOW_LIBS) $(MULTIWINDOWEXTWM_LIBS) $(XWIN_GLX_LIBS) $(XWIN_GLX_LINK_FLAGS) $(XWIN_LIBS) $(MAIN_LIB) $(XSERVER_LIBS) $(XSERVER_SYS_LIBS) $(XWIN_SYS_LIBS)
+
+XWIN_LIBS += \
+	$(top_builddir)/pseudoramiX/libPseudoramiX.la \
+	$(top_builddir)/Xext/libXextdpmsstubs.la \
+	$(top_builddir)/Xi/libXistubs.la
+
+XWin_DEPENDENCIES = \
+	$(MULTIWINDOWEXTWM_LIBS) \
+	$(XWIN_GLX_LIBS) \
+	$(XWIN_LIBS) \
+	$(XSERVER_LIBS)
+
+XWin_LDADD = \
+	$(MULTIWINDOWEXTWM_LIBS) \
+	$(XWIN_GLX_LIBS) \
+	$(XWIN_LIBS) \
+	$(XSERVER_LIBS) \
+	$(XWIN_GLX_SYS_LIBS) \
+	$(XSERVER_SYS_LIBS) \
+	$(XWIN_SYS_LIBS) \
+	$(MULTIWINDOW_SYS_LIBS)
+
 XWin_LDFLAGS = -mwindows -Wl,--disable-stdcall-fixup $(LD_EXPORT_SYMBOLS_FLAG)
 
 
commit aa40d0c07173209a2c13b332f1168e0df499a19e
Author: Jon TURNEY <jon.turney at dronecode.org.uk>
Date:   Fri Jun 13 16:16:51 2014 +0100

    hw/xwin/glx: When generating shims, limit the considered features to GL version <=1.2
    
    This fixes a problem when using Khronos registry data since the change of
    2013-08-16 removed glBlend(Color|Equation) from GL1.2 and added them to
    GL_ARB_imaging.
    
    If shim generation considers all features, no shims are generated for
    glBlend(Color|Equation) as they are first emitted for GL 1.4 (which we ignore as
    shims are only generated for GL version <=1.2), then emission for GL_ARB_imaging
    is skipped as they have already been emitted.
    
    Also improve feature name matching so it is exact, not on an initial substring,
    so 'GL_ARB_texture_compression_bptc' and 'GL_ARB_texture_compression_rgtc'
    aren't matched by 'GL_ARB_texture_compression'.
    
    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 cdbba63..69ab1ef 100755
--- a/hw/xwin/glx/gen_gl_wrappers.py
+++ b/hw/xwin/glx/gen_gl_wrappers.py
@@ -100,13 +100,16 @@ reg = Registry()
 tree = etree.parse(regFilename)
 reg.loadElementTree(tree)
 
-allVersions = '.*'
+if shim:
+    versions = '1\.[012]'
+else:
+    versions = '.*'
 
 genOpts = CGeneratorOptions(
         apiname           = prefix,
         profile           = 'compatibility',
-        versions          = allVersions,
-        emitversions      = allVersions,
+        versions          = versions,
+        emitversions      = versions,
         defaultExtensions = prefix,                   # Default extensions for GL
         protectFile       = protect,
         protectFeature    = protect,
@@ -257,7 +260,7 @@ class ThunkOutputGenerator(OutputGenerator):
         pass
     def beginFeature(self, interface, emit):
         OutputGenerator.beginFeature(self, interface, emit)
-        self.OldVersion = self.featureName.startswith('GL_VERSION_1_0') or self.featureName.startswith('GL_VERSION_1_1')
+        self.OldVersion = (self.featureName in ['GL_VERSION_1_0', 'GL_VERSION_1_1'])
     def endFeature(self):
         OutputGenerator.endFeature(self)
     def genType(self, typeinfo, name):
@@ -355,7 +358,7 @@ class ShimOutputGenerator(OutputGenerator):
         pass
     def beginFeature(self, interface, emit):
         OutputGenerator.beginFeature(self, interface, emit)
-        self.OldVersion = self.featureName.startswith('GL_VERSION_1_0') or self.featureName.startswith('GL_VERSION_1_1') or self.featureName.startswith('GL_VERSION_1_2') or self.featureName.startswith('GL_ARB_imaging') or self.featureName.startswith('GL_ARB_multitexture') or self.featureName.startswith('GL_ARB_texture_compression')
+        self.OldVersion = (self.featureName in ['GL_VERSION_1_0', 'GL_VERSION_1_1', 'GL_VERSION_1_2', 'GL_ARB_imaging', 'GL_ARB_multitexture', 'GL_ARB_texture_compression'])
     def endFeature(self):
         OutputGenerator.endFeature(self)
     def genType(self, typeinfo, name):
commit 35dc7c75150733dbcef8a18b6796f49a7c48ebee
Merge: 3a51418 5f3485b
Author: Eric Anholt <eric at anholt.net>
Date:   Mon Aug 25 15:52:58 2014 -0700

    Merge branch 'modesetting-import' into master
    
    This reintroduces a "hardware" driver to the xfree86 directory.
    Unlike the drivers that xorg used to include in the source tree, that
    needed independent release schedules to get hardware support out the
    door, the modesetting driver shouldn't change much as new hardware
    gets released.  A lot of what this driver needs to do is just keep up
    with server ABI changes.
    
    This import was done by taking xf86-video-modesetting-0.9.0, and
    running this script with 'git-filter-branch -f --tree-filter
    ~/bin/modesetting-filter':
    
    mkdir -p hw/xfree86/drivers/modesetting
    
    rm -f README autogen.sh configure.ac Makefile.am .gitignore
    rm -f man/Makefile.am
    
    mv man/modesetting.man hw/xfree86/drivers/modesetting/
    mv COPYING hw/xfree86/drivers/modesetting/
    mv src/* hw/xfree86/drivers/modesetting/

commit 3a51418b2db353519a1779cf3cebbcc9afba2520
Author: Laércio de Sousa <laerciosousa at sme-mogidascruzes.sp.gov.br>
Date:   Mon Aug 18 08:45:43 2014 -0300

    ephyr: set screen size & origin from host X server output's CRTC geometry
    
    If a given output is passed via new -output option, Xephyr will query
    host X server for its info. If the following conditions are met:
    
     a. RandR extension is enabled in host X server;
     b. supported RandR version in host X server is 1.2 or newer;
     c. the given output name is valid;
     d. the given output is connected;
    
    then Xephyr will get output's CRTC geometry and use it to set its own
    screen size and origin. It's just like starting Xephyr in fullscreen mode,
    but restricted to the given output's CRTC geometry (fake "Zaphod mode").
    
    This is the main feature needed for Xephyr-based single-card multiseat
    setups where we don't have separate screens to start Xephyr in fullscreen
    mode safely.
    
    Signed-off-by: Laércio de Sousa <laerciosousa at sme-mogidascruzes.sp.gov.br>
    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 f3d9654..cba7d24 100644
--- a/configure.ac
+++ b/configure.ac
@@ -2364,7 +2364,7 @@ if test "$KDRIVE" = yes; then
        AC_DEFINE(KDRIVE_MOUSE, 1, [Enable KDrive mouse driver])
     fi
 
-    XEPHYR_REQUIRED_LIBS="xau xdmcp xcb xcb-shape xcb-aux xcb-image xcb-icccm xcb-shm xcb-keysyms"
+    XEPHYR_REQUIRED_LIBS="xau xdmcp xcb xcb-shape xcb-aux xcb-image xcb-icccm xcb-shm xcb-keysyms xcb-randr"
     if test "x$XV" = xyes; then
         XEPHYR_REQUIRED_LIBS="$XEPHYR_REQUIRED_LIBS xcb-xv"
     fi
diff --git a/hw/kdrive/ephyr/ephyr.c b/hw/kdrive/ephyr/ephyr.c
index b039c68..85d4193 100644
--- a/hw/kdrive/ephyr/ephyr.c
+++ b/hw/kdrive/ephyr/ephyr.c
@@ -111,13 +111,16 @@ Bool
 ephyrScreenInitialize(KdScreenInfo *screen)
 {
     EphyrScrPriv *scrpriv = screen->driver;
+    int x = 0, y = 0;
     int width = 640, height = 480;
     CARD32 redMask, greenMask, blueMask;
 
-    if (hostx_want_screen_size(screen, &width, &height)
+    if (hostx_want_screen_geometry(screen, &width, &height, &x, &y)
         || !screen->width || !screen->height) {
         screen->width = width;
         screen->height = height;
+        screen->x = x;
+        screen->y = y;
     }
 
     if (EphyrWantGrayScale)
diff --git a/hw/kdrive/ephyr/ephyr.h b/hw/kdrive/ephyr/ephyr.h
index 5c4936b..4e753f1 100644
--- a/hw/kdrive/ephyr/ephyr.h
+++ b/hw/kdrive/ephyr/ephyr.h
@@ -74,8 +74,10 @@ typedef struct _ephyrScrPriv {
     xcb_window_t peer_win;            /* Used for GL; should be at most one */
     xcb_image_t *ximg;
     Bool win_explicit_position;
+    int win_x, win_y;
     int win_width, win_height;
     int server_depth;
+    const char *output;         /* Set via -output option */
     unsigned char *fb_data;     /* only used when host bpp != server bpp */
     xcb_shm_segment_info_t shminfo;
 
diff --git a/hw/kdrive/ephyr/ephyrinit.c b/hw/kdrive/ephyr/ephyrinit.c
index e04c8dc..38acc52 100644
--- a/hw/kdrive/ephyr/ephyrinit.c
+++ b/hw/kdrive/ephyr/ephyrinit.c
@@ -47,6 +47,8 @@ extern KdPointerDriver LinuxEvdevMouseDriver;
 extern KdKeyboardDriver LinuxEvdevKeyboardDriver;
 #endif
 
+void processScreenOrOutputArg(const char *screen_size, const char *output, char *parent_id);
+void processOutputArg(const char *output, char *parent_id);
 void processScreenArg(const char *screen_size, char *parent_id);
 
 void
@@ -134,6 +136,7 @@ ddxUseMsg(void)
     ErrorF("-parent <XID>        Use existing window as Xephyr root win\n");
     ErrorF("-sw-cursor           Render cursors in software in Xephyr\n");
     ErrorF("-fullscreen          Attempt to run Xephyr fullscreen\n");
+    ErrorF("-output <NAME>       Attempt to run Xephyr fullscreen (restricted to given output geometry)\n");
     ErrorF("-grayscale           Simulate 8bit grayscale\n");
     ErrorF("-resizeable          Make Xephyr windows resizeable\n");
 #ifdef GLAMOR
@@ -154,7 +157,7 @@ ddxUseMsg(void)
 }
 
 void
-processScreenArg(const char *screen_size, char *parent_id)
+processScreenOrOutputArg(const char *screen_size, const char *output, char *parent_id)
 {
     KdCardInfo *card;
 
@@ -178,13 +181,25 @@ processScreenArg(const char *screen_size, char *parent_id)
 
         use_geometry = (strchr(screen_size, '+') != NULL);
         EPHYR_DBG("screen number:%d\n", screen->mynum);
-        hostx_add_screen(screen, p_id, screen->mynum, use_geometry);
+        hostx_add_screen(screen, p_id, screen->mynum, use_geometry, output);
     }
     else {
         ErrorF("No matching card found!\n");
     }
 }
 
+void
+processScreenArg(const char *screen_size, char *parent_id)
+{
+    processScreenOrOutputArg(screen_size, NULL, parent_id);
+}
+
+void
+processOutputArg(const char *output, char *parent_id)
+{
+    processScreenOrOutputArg("100x100+0+0", output, parent_id);
+}
+
 int
 ddxProcessArgument(int argc, char **argv, int i)
 {
@@ -226,6 +241,15 @@ ddxProcessArgument(int argc, char **argv, int i)
         UseMsg();
         exit(1);
     }
+    else if (!strcmp(argv[i], "-output")) {
+        if (i + 1 < argc) {
+            processOutputArg(argv[i + 1], NULL);
+            return 2;
+        }
+
+        UseMsg();
+        exit(1);
+    }
     else if (!strcmp(argv[i], "-sw-cursor")) {
         hostx_use_sw_cursor();
         return 1;
diff --git a/hw/kdrive/ephyr/hostx.c b/hw/kdrive/ephyr/hostx.c
index 92a8ada..2161ad5 100644
--- a/hw/kdrive/ephyr/hostx.c
+++ b/hw/kdrive/ephyr/hostx.c
@@ -51,6 +51,7 @@
 #include <xcb/xcb_image.h>
 #include <xcb/shape.h>
 #include <xcb/xcb_keysyms.h>
+#include <xcb/randr.h>
 #ifdef XF86DRI
 #include <xcb/xf86dri.h>
 #include <xcb/glx.h>
@@ -104,12 +105,15 @@ static void
 #define host_depth_matches_server(_vars) (HostX.depth == (_vars)->server_depth)
 
 int
-hostx_want_screen_size(KdScreenInfo *screen, int *width, int *height)
+hostx_want_screen_geometry(KdScreenInfo *screen, int *width, int *height, int *x, int *y)
 {
     EphyrScrPriv *scrpriv = screen->driver;
 
     if (scrpriv && (scrpriv->win_pre_existing != None ||
+                    scrpriv->output != NULL ||
                     HostX.use_fullscreen == TRUE)) {
+        *x = scrpriv->win_x;
+        *y = scrpriv->win_y;
         *width = scrpriv->win_width;
         *height = scrpriv->win_height;
         return 1;
@@ -119,7 +123,7 @@ hostx_want_screen_size(KdScreenInfo *screen, int *width, int *height)
 }
 
 void
-hostx_add_screen(KdScreenInfo *screen, unsigned long win_id, int screen_num, Bool use_geometry)
+hostx_add_screen(KdScreenInfo *screen, unsigned long win_id, int screen_num, Bool use_geometry, const char *output)
 {
     EphyrScrPriv *scrpriv = screen->driver;
     int index = HostX.n_screens;
@@ -132,6 +136,7 @@ hostx_add_screen(KdScreenInfo *screen, unsigned long win_id, int screen_num, Boo
     scrpriv->screen = screen;
     scrpriv->win_pre_existing = win_id;
     scrpriv->win_explicit_position = use_geometry;
+    scrpriv->output = output;
 }
 
 void
@@ -211,6 +216,119 @@ hostx_want_preexisting_window(KdScreenInfo *screen)
 }
 
 void
+hostx_get_output_geometry(const char *output,
+                          int *x, int *y,
+                          int *width, int *height)
+{
+    int i, name_len = 0, output_found = FALSE;
+    char *name = NULL;
+    xcb_generic_error_t *error;
+    xcb_randr_query_version_cookie_t version_c;
+    xcb_randr_query_version_reply_t *version_r;
+    xcb_randr_get_screen_resources_cookie_t screen_resources_c;
+    xcb_randr_get_screen_resources_reply_t *screen_resources_r;
+    xcb_randr_output_t *randr_outputs;
+    xcb_randr_get_output_info_cookie_t output_info_c;
+    xcb_randr_get_output_info_reply_t *output_info_r;
+    xcb_randr_get_crtc_info_cookie_t crtc_info_c;
+    xcb_randr_get_crtc_info_reply_t *crtc_info_r;
+
+    /* First of all, check for extension */
+    if (!xcb_get_extension_data(HostX.conn, &xcb_randr_id)->present)
+    {
+        fprintf(stderr, "\nHost X server does not support RANDR extension (or it's disabled).\n");
+        exit(1);
+    }
+
+    /* Check RandR version */
+    version_c = xcb_randr_query_version(HostX.conn, 1, 2);
+    version_r = xcb_randr_query_version_reply(HostX.conn,
+                                              version_c,
+                                              &error);
+
+    if (error != NULL || version_r == NULL)
+    {
+        fprintf(stderr, "\nFailed to get RandR version supported by host X server.\n");
+        exit(1);
+    }
+    else if (version_r->major_version < 1 || version_r->minor_version < 2)
+    {
+        free(version_r);
+        fprintf(stderr, "\nHost X server doesn't support RandR 1.2, needed for -output usage.\n");
+        exit(1);
+    }
+
+    free(version_r);
+
+    /* Get list of outputs from screen resources */
+    screen_resources_c = xcb_randr_get_screen_resources(HostX.conn,
+                                                        HostX.winroot);
+    screen_resources_r = xcb_randr_get_screen_resources_reply(HostX.conn,
+                                                              screen_resources_c,
+                                                              NULL);
+    randr_outputs = xcb_randr_get_screen_resources_outputs(screen_resources_r);
+
+    for (i = 0; !output_found && i < screen_resources_r->num_outputs; i++)
+    {
+        /* Get info on the output */
+        output_info_c = xcb_randr_get_output_info(HostX.conn,
+                                                  randr_outputs[i],
+                                                  XCB_CURRENT_TIME);
+        output_info_r = xcb_randr_get_output_info_reply(HostX.conn,
+                                                        output_info_c,
+                                                        NULL);
+
+        /* Get output name */
+        name_len = xcb_randr_get_output_info_name_length(output_info_r);
+        name = malloc(name_len + 1);
+        strncpy(name, (char*)xcb_randr_get_output_info_name(output_info_r), name_len);
+        name[name_len] = '\0';
+
+        if (!strcmp(name, output))
+        {
+            output_found = TRUE;
+
+            /* Check if output is connected */
+            if (output_info_r->crtc == XCB_NONE)
+            {
+                free(name);
+                free(output_info_r);
+                free(screen_resources_r);
+                fprintf(stderr, "\nOutput %s is currently disabled (or not connected).\n", output);
+                exit(1);
+            }
+
+            /* Get CRTC from output info */
+            crtc_info_c = xcb_randr_get_crtc_info(HostX.conn,
+                                                  output_info_r->crtc,
+                                                  XCB_CURRENT_TIME);
+            crtc_info_r = xcb_randr_get_crtc_info_reply(HostX.conn,
+                                                        crtc_info_c,
+                                                        NULL);
+
+            /* Get CRTC geometry */
+            *x = crtc_info_r->x;
+            *y = crtc_info_r->y;
+            *width = crtc_info_r->width;
+            *height = crtc_info_r->height;
+
+            free(crtc_info_r);
+        }
+
+        free(name);
+        free(output_info_r);
+    }
+
+    free(screen_resources_r);
+
+    if (!output_found)
+    {
+        fprintf(stderr, "\nOutput %s not available in host X server.\n", output);
+        exit(1);
+    }
+}
+
+void
 hostx_use_fullscreen(void)
 {
     HostX.use_fullscreen = TRUE;
@@ -359,6 +477,8 @@ hostx_init(void)
         scrpriv->win = xcb_generate_id(HostX.conn);
         scrpriv->server_depth = HostX.depth;
         scrpriv->ximg = NULL;
+        scrpriv->win_x = 0;
+        scrpriv->win_y = 0;
 
         if (scrpriv->win_pre_existing != XCB_WINDOW_NONE) {
             xcb_get_geometry_reply_t *prewin_geom;
@@ -416,6 +536,17 @@ hostx_init(void)
 
                 hostx_set_fullscreen_hint();
             }
+            else if (scrpriv->output) {
+                hostx_get_output_geometry(scrpriv->output,
+                                          &scrpriv->win_x,
+                                          &scrpriv->win_y,
+                                          &scrpriv->win_width,
+                                          &scrpriv->win_height);
+
+                HostX.use_fullscreen = TRUE;
+                hostx_set_fullscreen_hint();
+            }
+
 
             tmpstr = getenv("RESOURCE_NAME");
             if (tmpstr && (!ephyrResNameFromCmd))
@@ -759,6 +890,8 @@ hostx_screen_init(KdScreenInfo *screen,
 
     scrpriv->win_width = width;
     scrpriv->win_height = height;
+    scrpriv->win_x = x;
+    scrpriv->win_y = y;
 
 #ifdef GLAMOR
     if (ephyr_glamor) {
diff --git a/hw/kdrive/ephyr/hostx.h b/hw/kdrive/ephyr/hostx.h
index c554ca3..80894c8 100644
--- a/hw/kdrive/ephyr/hostx.h
+++ b/hw/kdrive/ephyr/hostx.h
@@ -74,7 +74,7 @@ typedef struct {
 } EphyrRect;
 
 int
-hostx_want_screen_size(KdScreenInfo *screen, int *width, int *height);
+hostx_want_screen_geometry(KdScreenInfo *screen, int *width, int *height, int *x, int *y);
 
 int
  hostx_want_host_cursor(void);
@@ -83,6 +83,11 @@ void
  hostx_use_sw_cursor(void);
 
 void
+ hostx_get_output_geometry(const char *output,
+                           int *x, int *y,
+                           int *width, int *height);
+
+void
  hostx_use_fullscreen(void);
 
 int
@@ -107,7 +112,7 @@ int
  hostx_init(void);
 
 void
-hostx_add_screen(KdScreenInfo *screen, unsigned long win_id, int screen_num, Bool use_geometry);
+hostx_add_screen(KdScreenInfo *screen, unsigned long win_id, int screen_num, Bool use_geometry, const char *output);
 
 void
  hostx_set_display_name(char *name);
commit 84b02469ef97e6f85d074d220a517d752180045f
Author: Laércio de Sousa <laerciosousa at sme-mogidascruzes.sp.gov.br>
Date:   Mon Aug 18 08:45:42 2014 -0300

    ephyr: enable screen window placement following kdrive -screen option extended syntax
    
    With this patch, one can launch Xephyr with option "-screen WxH+X+Y"
    to place its window origin at (X,Y). This patch relies on a previous
    one that extends kdrive -screen option syntax to parse +X+Y substring
    as expected.
    
    If +X+Y is not passed in -screen argument string, let the WM place
    the window for us, as before.
    
    Signed-off-by: Laércio de Sousa <laerciosousa at sme-mogidascruzes.sp.gov.br>
    Reviewed-by: Keith Packard <keithp at keithp.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 d57e9f3..b039c68 100644
--- a/hw/kdrive/ephyr/ephyr.c
+++ b/hw/kdrive/ephyr/ephyr.c
@@ -242,7 +242,8 @@ ephyrMapFramebuffer(KdScreenInfo * screen)
     buffer_height = ephyrBufferHeight(screen);
 
     priv->base =
-        hostx_screen_init(screen, screen->width, screen->height, buffer_height,
+        hostx_screen_init(screen, screen->x, screen->y,
+                          screen->width, screen->height, buffer_height,
                           &priv->bytes_per_line, &screen->fb.bitsPerPixel);
 
     if ((scrpriv->randr & RR_Rotate_0) && !(scrpriv->randr & RR_Reflect_All)) {
diff --git a/hw/kdrive/ephyr/ephyr.h b/hw/kdrive/ephyr/ephyr.h
index dfd93c9..5c4936b 100644
--- a/hw/kdrive/ephyr/ephyr.h
+++ b/hw/kdrive/ephyr/ephyr.h
@@ -73,6 +73,7 @@ typedef struct _ephyrScrPriv {
     xcb_window_t win_pre_existing;    /* Set via -parent option like xnest */
     xcb_window_t peer_win;            /* Used for GL; should be at most one */
     xcb_image_t *ximg;
+    Bool win_explicit_position;
     int win_width, win_height;
     int server_depth;
     unsigned char *fb_data;     /* only used when host bpp != server bpp */
diff --git a/hw/kdrive/ephyr/ephyrinit.c b/hw/kdrive/ephyr/ephyrinit.c
index fc00010..e04c8dc 100644
--- a/hw/kdrive/ephyr/ephyrinit.c
+++ b/hw/kdrive/ephyr/ephyrinit.c
@@ -164,6 +164,7 @@ processScreenArg(const char *screen_size, char *parent_id)
     if (card) {
         KdScreenInfo *screen;
         unsigned long p_id = 0;
+        Bool use_geometry;
 
         screen = KdScreenInfoAdd(card);
         KdParseScreen(screen, screen_size);
@@ -174,8 +175,10 @@ processScreenArg(const char *screen_size, char *parent_id)
         if (parent_id) {
             p_id = strtol(parent_id, NULL, 0);
         }
+
+        use_geometry = (strchr(screen_size, '+') != NULL);
         EPHYR_DBG("screen number:%d\n", screen->mynum);
-        hostx_add_screen(screen, p_id, screen->mynum);
+        hostx_add_screen(screen, p_id, screen->mynum, use_geometry);
     }
     else {
         ErrorF("No matching card found!\n");
diff --git a/hw/kdrive/ephyr/hostx.c b/hw/kdrive/ephyr/hostx.c
index 1c75974..92a8ada 100644
--- a/hw/kdrive/ephyr/hostx.c
+++ b/hw/kdrive/ephyr/hostx.c
@@ -119,7 +119,7 @@ hostx_want_screen_size(KdScreenInfo *screen, int *width, int *height)
 }
 
 void
-hostx_add_screen(KdScreenInfo *screen, unsigned long win_id, int screen_num)
+hostx_add_screen(KdScreenInfo *screen, unsigned long win_id, int screen_num, Bool use_geometry)
 {
     EphyrScrPriv *scrpriv = screen->driver;
     int index = HostX.n_screens;
@@ -131,6 +131,7 @@ hostx_add_screen(KdScreenInfo *screen, unsigned long win_id, int screen_num)
 
     scrpriv->screen = screen;
     scrpriv->win_pre_existing = win_id;
+    scrpriv->win_explicit_position = use_geometry;
 }
 
 void
@@ -637,6 +638,7 @@ hostx_set_cmap_entry(unsigned char idx,
  */
 void *
 hostx_screen_init(KdScreenInfo *screen,
+                  int x, int y,
                   int width, int height, int buffer_height,
                   int *bytes_per_line, int *bits_per_pixel)
 {
@@ -648,8 +650,8 @@ hostx_screen_init(KdScreenInfo *screen,
         exit(1);
     }
 
-    EPHYR_DBG("host_screen=%p wxh=%dx%d, buffer_height=%d",
-              host_screen, width, height, buffer_height);
+    EPHYR_DBG("host_screen=%p x=%d, y=%d, wxh=%dx%d, buffer_height=%d",
+              host_screen, x, y, width, height, buffer_height);
 
     if (scrpriv->ximg != NULL) {
         /* Free up the image data if previously used
@@ -740,6 +742,19 @@ hostx_screen_init(KdScreenInfo *screen,
 
     xcb_map_window(HostX.conn, scrpriv->win);
 
+    /* Set explicit window position if it was informed in
+     * -screen option (WxH+X or WxH+X+Y). Otherwise, accept the
+     * position set by WM.
+     * The trick here is putting this code after xcb_map_window() call,
+     * so these values won't be overriden by WM. */
+    if (scrpriv->win_explicit_position)
+    {
+        uint32_t mask = XCB_CONFIG_WINDOW_X | XCB_CONFIG_WINDOW_Y;
+        uint32_t values[2] = {x, y};
+        xcb_configure_window(HostX.conn, scrpriv->win, mask, values);
+    }
+
+
     xcb_aux_sync(HostX.conn);
 
     scrpriv->win_width = width;
diff --git a/hw/kdrive/ephyr/hostx.h b/hw/kdrive/ephyr/hostx.h
index e83323a..c554ca3 100644
--- a/hw/kdrive/ephyr/hostx.h
+++ b/hw/kdrive/ephyr/hostx.h
@@ -107,7 +107,7 @@ int
  hostx_init(void);
 
 void
-hostx_add_screen(KdScreenInfo *screen, unsigned long win_id, int screen_num);
+hostx_add_screen(KdScreenInfo *screen, unsigned long win_id, int screen_num, Bool use_geometry);
 
 void
  hostx_set_display_name(char *name);
@@ -136,6 +136,7 @@ hostx_set_cmap_entry(unsigned char idx,
                      unsigned char r, unsigned char g, unsigned char b);
 
 void *hostx_screen_init(KdScreenInfo *screen,
+                        int x, int y,
                         int width, int height, int buffer_height,
                         int *bytes_per_line, int *bits_per_pixel);
 
commit 376f4de8ae927748417046390c24afbda24b0583
Author: Laércio de Sousa <laerciosousa at sme-mogidascruzes.sp.gov.br>
Date:   Mon Aug 18 08:45:41 2014 -0300

    kdrive: add support to +X+Y syntax in -screen option parsing
    
    This patch enhances current -screen option parsing for kdrive-based
    applications. It can parse strings like
    <WIDTH>x<HEIGHT>+<XOFFSET>+<YOFFSET>, storing X and Y offsets
    in KdScreenInfo instances.
    
    For negative values, this patch supports +-X+-Y (not -X-Y) syntax.
    
    It will allow e.g. proper Xephyr window placement for multiseat
    purposes.
    
    Signed-off-by: Laércio de Sousa <laerciosousa at sme-mogidascruzes.sp.gov.br>
    Reviewed-by: Keith Packard <keithp at keithp.com>
    Signed-off-by: Keith Packard <keithp at keithp.com>

diff --git a/hw/kdrive/src/kdrive.c b/hw/kdrive/src/kdrive.c
index b5b91c0..5dbff3f 100644
--- a/hw/kdrive/src/kdrive.c
+++ b/hw/kdrive/src/kdrive.c
@@ -300,6 +300,8 @@ KdParseScreen(KdScreenInfo * screen, const char *arg)
     screen->softCursor = kdSoftCursor;
     screen->origin = kdOrigin;
     screen->randr = RR_Rotate_0;
+    screen->x = 0;
+    screen->y = 0;
     screen->width = 0;
     screen->height = 0;
     screen->width_mm = 0;
@@ -313,7 +315,7 @@ KdParseScreen(KdScreenInfo * screen, const char *arg)
         return;
 
     for (i = 0; i < 2; i++) {
-        arg = KdParseFindNext(arg, "x/@XY", save, &delim);
+        arg = KdParseFindNext(arg, "x/+ at XY", save, &delim);
         if (!save[0])
             return;
 
@@ -321,7 +323,7 @@ KdParseScreen(KdScreenInfo * screen, const char *arg)
         mm = 0;
 
         if (delim == '/') {
-            arg = KdParseFindNext(arg, "x at XY", save, &delim);
+            arg = KdParseFindNext(arg, "x+ at XY", save, &delim);
             if (!save[0])
                 return;
             mm = atoi(save);
@@ -335,7 +337,8 @@ KdParseScreen(KdScreenInfo * screen, const char *arg)
             screen->height = pixels;
             screen->height_mm = mm;
         }
-        if (delim != 'x' && delim != '@' && delim != 'X' && delim != 'Y' &&
+        if (delim != 'x' && delim != '+' && delim != '@' &&
+            delim != 'X' && delim != 'Y' &&
             (delim != '\0' || i == 0))
             return;
     }
@@ -346,6 +349,18 @@ KdParseScreen(KdScreenInfo * screen, const char *arg)
     kdSoftCursor = FALSE;
     kdSubpixelOrder = SubPixelUnknown;
 
+    if (delim == '+') {
+        arg = KdParseFindNext(arg, "+ at xXY", save, &delim);
+        if (save[0])
+            screen->x = atoi(save);
+    }
+
+    if (delim == '+') {
+        arg = KdParseFindNext(arg, "@xXY", save, &delim);
+        if (save[0])
+            screen->y = atoi(save);
+    }
+
     if (delim == '@') {
         arg = KdParseFindNext(arg, "xXY", save, &delim);
         if (save[0]) {
@@ -425,7 +440,7 @@ KdUseMsg(void)
 {
     ErrorF("\nTinyX Device Dependent Usage:\n");
     ErrorF
-        ("-screen WIDTH[/WIDTHMM]xHEIGHT[/HEIGHTMM][@ROTATION][X][Y][xDEPTH/BPP[xFREQ]]  Specify screen characteristics\n");
+        ("-screen WIDTH[/WIDTHMM]xHEIGHT[/HEIGHTMM][+[-]XOFFSET][+[-]YOFFSET][@ROTATION][X][Y][xDEPTH/BPP[xFREQ]]  Specify screen characteristics\n");
     ErrorF
         ("-rgba rgb/bgr/vrgb/vbgr/none   Specify subpixel ordering for LCD panels\n");
     ErrorF
diff --git a/hw/kdrive/src/kdrive.h b/hw/kdrive/src/kdrive.h
index 08b1681..066a134 100644
--- a/hw/kdrive/src/kdrive.h
+++ b/hw/kdrive/src/kdrive.h
@@ -89,6 +89,8 @@ typedef struct _KdScreenInfo {
     ScreenPtr pScreen;
     void *driver;
     Rotation randr;             /* rotation and reflection */
+    int x;
+    int y;
     int width;
     int height;
     int rate;
commit fe5018e0564118a7a8198fa286186fdb9ed818c7
Author: Takashi Iwai <tiwai at suse.de>
Date:   Tue Aug 19 15:57:22 2014 -0500

    fb: Fix invalid bpp for 24bit depth window
    
    We have a hack in fb layer for a 24bpp screen to use 32bpp images, and
    fbCreateWindow() replaces its drawable.bitsPerPixel field
    appropriately.  But, the problem is that it always replaces when 32bpp
    is passed.  If the depth is 32, this results in bpp < depth, which is
    actually invalid.
    
    Meanwhile, fbCreatePixmap() has a more check and it creates with 24bpp
    only when the passed depth <= 24 for avoiding such a problem.
    
    This oneliner patch just adds the similar check in fbCreateWindow().
    This (hopefully) fixes the long-standing broken graphics mess of
    cirrus KMS with 24bpp.
    
    Signed-off-by: Takashi Iwai <tiwai at suse.de>
    Reviewed-by: Keith Packard <keithp at keithp.com>

diff --git a/fb/fbwindow.c b/fb/fbwindow.c
index 368c4b8..c90175f 100644
--- a/fb/fbwindow.c
+++ b/fb/fbwindow.c
@@ -33,7 +33,7 @@ fbCreateWindow(WindowPtr pWin)
 {
     dixSetPrivate(&pWin->devPrivates, fbGetWinPrivateKey(pWin),
                   fbGetScreenPixmap(pWin->drawable.pScreen));
-    if (pWin->drawable.bitsPerPixel == 32)
+    if (pWin->drawable.bitsPerPixel == 32 && pWin->drawable.depth <= 24)
         pWin->drawable.bitsPerPixel =
             fbGetScreenPrivate(pWin->drawable.pScreen)->win32bpp;
     return TRUE;
commit 5d133276de9c50146e80ffc69edd429c2afe98e6
Author: Thierry Reding <treding at nvidia.com>
Date:   Thu Feb 13 13:36:12 2014 +0100

    xfree86: Allow non-PCI devices as primary
    
    On platforms that don't support PCI or have no GPU attached to the PCI
    bus, there can still be a primary device on a non-PCI bus.
    
    Signed-off-by: Thierry Reding <treding at nvidia.com>
    Reviewed-by: Rob Clark <robdclark at gmail.com>
    Tested-by: Rob Clark <robdclark at gmail.com>
    Signed-off-by: Keith Packard <keithp at keithp.com>

diff --git a/hw/xfree86/common/xf86platformBus.c b/hw/xfree86/common/xf86platformBus.c
index 1bacc49..5ad9b70 100644
--- a/hw/xfree86/common/xf86platformBus.c
+++ b/hw/xfree86/common/xf86platformBus.c
@@ -435,10 +435,9 @@ xf86platformProbeDev(DriverPtr drvp)
                 /* for non-seat0 servers assume first device is the master */
                 if (ServerIsNotSeat0())
                     break;
-                if (xf86_platform_devices[j].pdev) {
-                    if (xf86IsPrimaryPlatform(&xf86_platform_devices[j]))
-                        break;
-                }
+
+                if (xf86IsPrimaryPlatform(&xf86_platform_devices[j]))
+                    break;
             }
         }
 
commit 2f0183222b4279266e6ef60b923738ff55f0afba
Author: Thierry Reding <treding at nvidia.com>
Date:   Thu Feb 13 13:31:31 2014 +0100

    xfree86: Fallback to first platform device as primary
    
    When neither of the various bus implementations was able to find a
    primary bus and device, fallback to using the platform bus as primary
    bus and the first platform device as primary device.
    
    Signed-off-by: Thierry Reding <treding at nvidia.com>
    Reviewed-by: Rob Clark <robdclark at gmail.com>
    Tested-by: Rob Clark <robdclark at gmail.com>
    Signed-off-by: Keith Packard <keithp at keithp.com>

diff --git a/hw/xfree86/common/xf86Bus.c b/hw/xfree86/common/xf86Bus.c
index b3b3f8c..bd3e4e3 100644
--- a/hw/xfree86/common/xf86Bus.c
+++ b/hw/xfree86/common/xf86Bus.c
@@ -210,6 +210,9 @@ xf86BusProbe(void)
 #if (defined(__sparc__) || defined(__sparc)) && !defined(__OpenBSD__)
     xf86SbusProbe();
 #endif
+#ifdef XSERVER_PLATFORM_BUS
+    xf86platformPrimary();
+#endif
 }
 
 /*
diff --git a/hw/xfree86/common/xf86platformBus.c b/hw/xfree86/common/xf86platformBus.c
index 9460399..1bacc49 100644
--- a/hw/xfree86/common/xf86platformBus.c
+++ b/hw/xfree86/common/xf86platformBus.c
@@ -594,4 +594,19 @@ void xf86platformVTProbe(void)
         xf86PlatformReprobeDevice(i, xf86_platform_devices[i].attribs);
     }
 }
+
+void xf86platformPrimary(void)
+{
+    /* use the first platform device as a fallback */
+    if (primaryBus.type == BUS_NONE) {
+        xf86Msg(X_INFO, "no primary bus or device found\n");
+
+        if (xf86_num_platform_devices > 0) {
+            primaryBus.id.plat = &xf86_platform_devices[0];
+            primaryBus.type = BUS_PLATFORM;
+
+            xf86Msg(X_NONE, "\tfalling back to %s\n", primaryBus.id.plat->attribs->syspath);
+        }
+    }
+}
 #endif
diff --git a/hw/xfree86/common/xf86platformBus.h b/hw/xfree86/common/xf86platformBus.h
index 317dd24..a7335b9 100644
--- a/hw/xfree86/common/xf86platformBus.h
+++ b/hw/xfree86/common/xf86platformBus.h
@@ -155,6 +155,7 @@ extern _X_EXPORT int
 xf86PlatformMatchDriver(char *matches[], int nmatches);
 
 extern void xf86platformVTProbe(void);
+extern void xf86platformPrimary(void);
 #endif
 
 #endif
commit 33aeec8a11bc75a06d32956bbdd9efb216790a02
Author: Keith Packard <keithp at keithp.com>
Date:   Thu Jan 30 16:24:35 2014 -0800

    dri3: Don't enable the DRI3 extension unless some screen supports it
    
    There's no reason to advertise this extension unless one of the
    hardware drivers actually supports it. Not listing it means it's
    slightly easier for users to tell what's going on.
    
    On the other hand, not listing it means we may have applications that
    only check for the extension and not for appropriate per-screen
    support. I don't think that's a real risk as DRI3 is only useful for
    systems with deep knowledge of the hardware.
    
    Signed-off-by: Keith Packard <keithp at keithp.com>
    Reviewed-by: Eric Anholt <eric at anholt.net>

diff --git a/dri3/dri3.c b/dri3/dri3.c
index 76e07b4..385862a 100644
--- a/dri3/dri3.c
+++ b/dri3/dri3.c
@@ -30,6 +30,8 @@ int dri3_request;
 DevPrivateKeyRec dri3_screen_private_key;
 DevPrivateKeyRec dri3_window_private_key;
 
+static int dri3_screen_generation;
+
 static Bool
 dri3_close_screen(ScreenPtr screen)
 {
@@ -44,6 +46,8 @@ dri3_close_screen(ScreenPtr screen)
 Bool
 dri3_screen_init(ScreenPtr screen, dri3_screen_info_ptr info)
 {
+    dri3_screen_generation = serverGeneration;
+
     if (!dixRegisterPrivateKey(&dri3_screen_private_key, PRIVATE_SCREEN, 0))
         return FALSE;
 
@@ -68,6 +72,12 @@ dri3_extension_init(void)
     ExtensionEntry *extension;
     int i;
 
+    /* If no screens support DRI3, there's no point offering the
+     * extension at all
+     */
+    if (dri3_screen_generation != serverGeneration)
+        return;
+
 #ifdef PANORAMIX
     if (!noPanoramiXExtension)
         return;
commit 0d7306ffe2e069f0091c4f174f138127100abb43
Author: Michel Dänzer <michel.daenzer at amd.com>
Date:   Wed Aug 13 17:10:21 2014 +0900

    glamor: Don't call glamor_copy_fbo_cpu() for GLAMOR_DRM_ONLY pixmaps
    
    It results in a crash.
    
    Signed-off-by: Michel Dänzer <michel.daenzer at amd.com>
    Reviewed-by: Eric Anholt <eric at anholt.net>
    Signed-off-by: Keith Packard <keithp at keithp.com>

diff --git a/glamor/glamor_copy.c b/glamor/glamor_copy.c
index b84fcf2..6f422d4 100644
--- a/glamor/glamor_copy.c
+++ b/glamor/glamor_copy.c
@@ -635,6 +635,7 @@ glamor_copy_gl(DrawablePtr src,
             return glamor_copy_cpu_fbo(src, dst, gc, box, nbox, dx, dy,
                                        reverse, upsidedown, bitplane, closure);
     } else if (GLAMOR_PIXMAP_PRIV_HAS_FBO(src_priv) &&
+               dst_priv->type != GLAMOR_DRM_ONLY &&
                bitplane == 0) {
             return glamor_copy_fbo_cpu(src, dst, gc, box, nbox, dx, dy,
                                        reverse, upsidedown, bitplane, closure);
commit c2548d71f7a754251d89696ae49aab2fe07446df
Author: Joerg Sonnenberger <joerg at NetBSD.org>
Date:   Mon Aug 11 10:36:01 2014 +0200

    Fix format string.
    
    Reviewed-by: Keith Packard <keithp at keithp.com>
    Signed-off-by: Thomas Klausner <wiz at NetBSD.org>
    Signed-off-by: Keith Packard <keithp at keithp.com>

diff --git a/hw/xfree86/os-support/bsd/ppc_video.c b/hw/xfree86/os-support/bsd/ppc_video.c
index 947a686..3fd28c3 100644
--- a/hw/xfree86/os-support/bsd/ppc_video.c
+++ b/hw/xfree86/os-support/bsd/ppc_video.c
@@ -76,7 +76,7 @@ ppcMapVidMem(int ScreenNum, unsigned long Base, unsigned long Size, int flags)
                 (flags & VIDMEM_READONLY) ?
                 PROT_READ : (PROT_READ | PROT_WRITE), MAP_SHARED, fd, Base);
     if (base == MAP_FAILED)
-        FatalError("%s: could not mmap screen [s=%x,a=%x] (%s)",
+        FatalError("%s: could not mmap screen [s=%lx,a=%lx] (%s)",
                    "xf86MapVidMem", Size, Base, strerror(errno));
 
     return base;
commit d4111239e698f0126123830429d74da7d24910ed
Author: Keith Packard <keithp at keithp.com>
Date:   Wed Aug 13 11:30:11 2014 -0700

    glamor: Free Xv put image data immediately after use
    
    The Xv StopVideo callback is not invoked on textured video ports, so
    the temporary pixmaps allocated for the video planes are never freed.
    
    Freeing the storage immediately after use is a simple solution to this
    problem which doesn't appear to have any visible performance impact.
    
    Signed-off-by: Keith Packard <keithp at keithp.com>
    Reviewed-by: Eric Anholt <eric at anholt.net>

diff --git a/glamor/glamor_xv.c b/glamor/glamor_xv.c
index 3f3e064..26bdef6 100644
--- a/glamor/glamor_xv.c
+++ b/glamor/glamor_xv.c
@@ -136,6 +136,11 @@ glamor_init_xv_shader(ScreenPtr screen)
 void
 glamor_xv_stop_video(glamor_port_private *port_priv)
 {
+}
+
+static void
+glamor_xv_free_port_data(glamor_port_private *port_priv)
+{
     int i;
 
     for (i = 0; i < 3; i++) {
@@ -144,6 +149,8 @@ glamor_xv_stop_video(glamor_port_private *port_priv)
             port_priv->src_pix[i] = NULL;
         }
     }
+    RegionUninit(&port_priv->clip);
+    RegionNull(&port_priv->clip);
 }
 
 int
@@ -381,6 +388,8 @@ glamor_xv_render(glamor_port_private *port_priv)
     glDisableVertexAttribArray(GLAMOR_VERTEX_SOURCE);
 
     DamageDamageRegion(port_priv->pDraw, &port_priv->clip);
+
+    glamor_xv_free_port_data(port_priv);
 }
 
 int
@@ -468,9 +477,7 @@ glamor_xv_put_image(glamor_port_private *port_priv,
     else
         port_priv->pPixmap = (PixmapPtr) pDrawable;
 
-    if (!RegionEqual(&port_priv->clip, clipBoxes)) {
-        RegionCopy(&port_priv->clip, clipBoxes);
-    }
+    RegionCopy(&port_priv->clip, clipBoxes);
 
     port_priv->src_x = src_x;
     port_priv->src_y = src_y;
commit c47ee880e742e15fdbd5f5ac3eba64db6228c09f
Author: Eric Anholt <eric at anholt.net>
Date:   Mon Aug 11 15:23:02 2014 -0700

    glamor: Don't try to set up core fonts textures when we won't use them.
    
    This happens to avoid GL errors on hardware without
    EXT_texture_integer (which implies < GLSL 130, and thus glamor_text.c
    programs not compiling anyway).
    
    Signed-off-by: Eric Anholt <eric at anholt.net>
    Reviewed-by: Alex Deucher <alexander.deucher at amd.com>
    Signed-off-by: Keith Packard <keithp at keithp.com>

diff --git a/glamor/glamor_font.c b/glamor/glamor_font.c
index 57c607d..0ca91fa 100644
--- a/glamor/glamor_font.c
+++ b/glamor/glamor_font.c
@@ -46,6 +46,8 @@ glamor_font_get(ScreenPtr screen, FontPtr font)
     CharInfoPtr         glyph;
     unsigned long       count;
 
+    if (glamor_priv->glsl_version < 130)
+        return NULL;
 
     privates = FontGetPrivate(font, glamor_font_private_index);
     if (!privates) {
@@ -167,6 +169,11 @@ glamor_unrealize_font(ScreenPtr screen, FontPtr font)
 Bool
 glamor_font_init(ScreenPtr screen)
 {
+    glamor_screen_private *glamor_priv = glamor_get_screen_private(screen);
+
+    if (glamor_priv->glsl_version < 130)
+        return TRUE;
+
     if (glamor_font_generation != serverGeneration) {
         glamor_font_private_index = AllocateFontPrivateIndex();
         if (glamor_font_private_index == -1)
commit d09c9ddb866dea31e2adf82be329d5d3489718f5
Merge: 606b701 ab32ee3
Author: Keith Packard <keithp at keithp.com>
Date:   Tue Aug 12 16:34:24 2014 -0700

    Merge remote-tracking branch 'jeremyhu/master'

commit 606b701c563c10f01dec147e061fa00cda784a9d
Author: Michel Dänzer <michel.daenzer at amd.com>
Date:   Wed Aug 6 10:30:25 2014 +0900

    glamor: Add glamor_copy_fbo_cpu() for CopyArea to non-GPU destination
    
    This provides a speedup e.g. when the destination is an SHM pixmap.
    
    Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=76285
    Signed-off-by: Michel Dänzer <michel.daenzer at amd.com>
    Reviewed-by: Eric Anholt <eric at anholt.net>
    Signed-off-by: Keith Packard <keithp at keithp.com>

diff --git a/glamor/glamor_copy.c b/glamor/glamor_copy.c
index bfcde43..b84fcf2 100644
--- a/glamor/glamor_copy.c
+++ b/glamor/glamor_copy.c
@@ -233,6 +233,56 @@ bail:
     return FALSE;
 }
 
+/**
+ * Implements CopyArea from the GPU to the CPU using glReadPixels from the
+ * source FBO.
+ */
+static Bool
+glamor_copy_fbo_cpu(DrawablePtr src,
+                    DrawablePtr dst,
+                    GCPtr gc,
+                    BoxPtr box,
+                    int nbox,
+                    int dx,
+                    int dy,
+                    Bool reverse,
+                    Bool upsidedown,
+                    Pixel bitplane,
+                    void *closure)
+{
+    ScreenPtr screen = dst->pScreen;
+    glamor_screen_private *glamor_priv = glamor_get_screen_private(screen);
+    PixmapPtr src_pixmap = glamor_get_drawable_pixmap(src);
+    FbBits *dst_bits;
+    FbStride dst_stride;
+    int dst_bpp;
+    int src_xoff, src_yoff;
+    int dst_xoff, dst_yoff;
+
+    if (gc && gc->alu != GXcopy)
+        goto bail;
+
+    if (gc && !glamor_pm_is_solid(dst, gc->planemask))
+        goto bail;
+
+    glamor_make_current(glamor_priv);
+    glamor_prepare_access(dst, GLAMOR_ACCESS_RW);
+
+    glamor_get_drawable_deltas(src, src_pixmap, &src_xoff, &src_yoff);
+
+    fbGetDrawable(dst, dst_bits, dst_stride, dst_bpp, dst_xoff, dst_yoff);
+
+    glamor_download_boxes(src_pixmap, box, nbox, src_xoff + dx, src_yoff + dy,
+                          dst_xoff, dst_yoff,
+                          (uint8_t *) dst_bits, dst_stride * sizeof (FbBits));
+    glamor_finish_access(dst);
+
+    return TRUE;
+
+bail:
+    return FALSE;
+}
+
 /*
  * Copy from GPU to GPU by using the source
  * as a texture and painting that into the destination
@@ -584,6 +634,10 @@ glamor_copy_gl(DrawablePtr src,
         if (bitplane == 0)
             return glamor_copy_cpu_fbo(src, dst, gc, box, nbox, dx, dy,
                                        reverse, upsidedown, bitplane, closure);
+    } else if (GLAMOR_PIXMAP_PRIV_HAS_FBO(src_priv) &&
+               bitplane == 0) {
+            return glamor_copy_fbo_cpu(src, dst, gc, box, nbox, dx, dy,
+                                       reverse, upsidedown, bitplane, closure);
     }
     return FALSE;
 }
commit 1e30fc1b99bda040038e4fd56d1b27c686b44c75
Author: Peter Hutterer <peter.hutterer at who-t.net>
Date:   Mon Aug 4 10:47:03 2014 +1000

    xkb: ignore floating slave devices when updating from master (#81885)
    
    Introduced in 45fb3a934dc0db51584aba37c2f9d73deff9191d. When a device is
    enabled, the master's locked state is pushed to the slave. If the device is
    floating, no master exists and we triggered a NULL-pointer dereference
    in XkbPushLockedStateToSlaves.
    
    X.Org Bug 81885 <http://bugs.freedesktop.org/show_bug.cgi?id=81885>
    
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
    Reviewed-by: Daniel Stone <daniel at fooishbar.org>
    Signed-off-by: Keith Packard <keithp at keithp.com>

diff --git a/dix/devices.c b/dix/devices.c
index 5d26fae..f17a3ac 100644
--- a/dix/devices.c
+++ b/dix/devices.c
@@ -416,7 +416,7 @@ EnableDevice(DeviceIntPtr dev, BOOL sendevent)
         XISendDeviceHierarchyEvent(flags);
     }
 
-    if (!IsMaster(dev))
+    if (!IsMaster(dev) && !IsFloating(dev))
         XkbPushLockedStateToSlaves(GetMaster(dev, MASTER_KEYBOARD), 0, 0);
     RecalculateMasterButtons(dev);
 
commit 4599a4492ca6a1c87cd9c537c54fbda11f13c15c
Author: Daphne Pfister <daphnediane at mac.com>
Date:   Wed Jul 23 21:51:57 2014 -0400

    os: Regenerate os/oscolor.c from app/rgb #52289
    
    Regenerate os/oscolor.c from rgb.txt. This adds the following
    colors: aqua, lime, fuchsia, crimson, indigo, olive, rebecca
    purple, silver and teal. It also adds versions of gray, grey,
    green, maroon and purple prefixed with web and x11 for the
    colors that are different between X11 and HTML/CSS web colors.
    
    Fixes: https://bugs.freedesktop.org/show_bug.cgi?id=52289
    Related: https://bugs.freedesktop.org/show_bug.cgi?id=80371
    
    Signed-off-by: nobody
    Tested-by: Keith Packard <keithp at keithp.com>
    Signed-off-by: Keith Packard <keithp at keithp.com>

diff --git a/os/oscolor.c b/os/oscolor.c
index a7573d2..a44ed3f 100644
--- a/os/oscolor.c
+++ b/os/oscolor.c
@@ -67,6 +67,7 @@ static const char BuiltinColorNames[] = {
         "AntiqueWhite2\0"
         "AntiqueWhite3\0"
         "AntiqueWhite4\0"
+        "aqua\0"
         "aquamarine\0"
         "aquamarine1\0"
         "aquamarine2\0"
@@ -131,6 +132,7 @@ static const char BuiltinColorNames[] = {
         "cornsilk2\0"
         "cornsilk3\0"
         "cornsilk4\0"
+        "crimson\0"
         "cyan\0"
         "cyan1\0"
         "cyan2\0"
@@ -229,6 +231,7 @@ static const char BuiltinColorNames[] = {
         "FloralWhite\0"
         "forest green\0"
         "ForestGreen\0"
+        "fuchsia\0"
         "gainsboro\0"
         "ghost white\0"
         "GhostWhite\0"
@@ -470,6 +473,7 @@ static const char BuiltinColorNames[] = {
         "IndianRed2\0"
         "IndianRed3\0"
         "IndianRed4\0"
+        "indigo\0"
         "ivory\0"
         "ivory1\0"
         "ivory2\0"
@@ -561,6 +565,7 @@ static const char BuiltinColorNames[] = {
         "LightYellow2\0"
         "LightYellow3\0"
         "LightYellow4\0"
+        "lime\0"
         "lime green\0"
         "LimeGreen\0"
         "linen\0"
@@ -622,6 +627,7 @@ static const char BuiltinColorNames[] = {
         "NavyBlue\0"
         "old lace\0"
         "OldLace\0"
+        "olive\0"
         "olive drab\0"
         "OliveDrab\0"
         "OliveDrab1\0"
@@ -690,6 +696,8 @@ static const char BuiltinColorNames[] = {
         "purple2\0"
         "purple3\0"
         "purple4\0"
+        "rebecca purple\0"
+        "RebeccaPurple\0"
         "red\0"
         "red1\0"
         "red2\0"
@@ -732,6 +740,7 @@ static const char BuiltinColorNames[] = {
         "sienna2\0"
         "sienna3\0"
         "sienna4\0"
+        "silver\0"
         "sky blue\0"
         "SkyBlue\0"
         "SkyBlue1\0"
@@ -774,6 +783,7 @@ static const char BuiltinColorNames[] = {
         "tan2\0"
         "tan3\0"
         "tan4\0"
+        "teal\0"
         "thistle\0"
         "thistle1\0"
         "thistle2\0"
@@ -796,6 +806,16 @@ static const char BuiltinColorNames[] = {
         "VioletRed2\0"
         "VioletRed3\0"
         "VioletRed4\0"
+        "web gray\0"
+        "web green\0"
+        "web grey\0"
+        "web maroon\0"
+        "web purple\0"
+        "WebGray\0"
+        "WebGreen\0"
+        "WebGrey\0"
+        "WebMaroon\0"
+        "WebPurple\0"
         "wheat\0"
         "wheat1\0"
         "wheat2\0"
@@ -804,9 +824,23 @@ static const char BuiltinColorNames[] = {
         "white\0"
         "white smoke\0"
         "WhiteSmoke\0"
+        "x11 gray\0"
+        "x11 green\0"
+        "x11 grey\0"
+        "x11 maroon\0"
+        "x11 purple\0"
+        "X11Gray\0"
+        "X11Green\0"
+        "X11Grey\0"
+        "X11Maroon\0"
+        "X11Purple\0"
         "yellow\0"
         "yellow green\0"
-        "yellow1\0" "yellow2\0" "yellow3\0" "yellow4\0" "YellowGreen\0"
+        "yellow1\0"
+        "yellow2\0"
+        "yellow3\0"
+        "yellow4\0"
+        "YellowGreen\0"
 };
 
 static const BuiltinColor BuiltinColors[] = {
@@ -818,750 +852,780 @@ static const BuiltinColor BuiltinColors[] = {
     {238, 223, 204, 62},        /* AntiqueWhite2 */
     {205, 192, 176, 76},        /* AntiqueWhite3 */
     {139, 131, 120, 90},        /* AntiqueWhite4 */
-    {127, 255, 212, 104},       /* aquamarine */
-    {127, 255, 212, 115},       /* aquamarine1 */
-    {118, 238, 198, 127},       /* aquamarine2 */
-    {102, 205, 170, 139},       /* aquamarine3 */
-    {69, 139, 116, 151},        /* aquamarine4 */
-    {240, 255, 255, 163},       /* azure */
-    {240, 255, 255, 169},       /* azure1 */
-    {224, 238, 238, 176},       /* azure2 */
-    {193, 205, 205, 183},       /* azure3 */
-    {131, 139, 139, 190},       /* azure4 */
-    {245, 245, 220, 197},       /* beige */
-    {255, 228, 196, 203},       /* bisque */
-    {255, 228, 196, 210},       /* bisque1 */
-    {238, 213, 183, 218},       /* bisque2 */
-    {205, 183, 158, 226},       /* bisque3 */
-    {139, 125, 107, 234},       /* bisque4 */
-    {0, 0, 0, 242},             /* black */
-    {255, 235, 205, 248},       /* blanched almond */
-    {255, 235, 205, 264},       /* BlanchedAlmond */
-    {0, 0, 255, 279},           /* blue */
-    {138, 43, 226, 284},        /* blue violet */
-    {0, 0, 255, 296},           /* blue1 */
-    {0, 0, 238, 302},           /* blue2 */
-    {0, 0, 205, 308},           /* blue3 */
-    {0, 0, 139, 314},           /* blue4 */
-    {138, 43, 226, 320},        /* BlueViolet */
-    {165, 42, 42, 331},         /* brown */
-    {255, 64, 64, 337},         /* brown1 */
-    {238, 59, 59, 344},         /* brown2 */
-    {205, 51, 51, 351},         /* brown3 */
-    {139, 35, 35, 358},         /* brown4 */
-    {222, 184, 135, 365},       /* burlywood */
-    {255, 211, 155, 375},       /* burlywood1 */
-    {238, 197, 145, 386},       /* burlywood2 */
-    {205, 170, 125, 397},       /* burlywood3 */
-    {139, 115, 85, 408},        /* burlywood4 */
-    {95, 158, 160, 419},        /* cadet blue */
-    {95, 158, 160, 430},        /* CadetBlue */
-    {152, 245, 255, 440},       /* CadetBlue1 */
-    {142, 229, 238, 451},       /* CadetBlue2 */
-    {122, 197, 205, 462},       /* CadetBlue3 */
-    {83, 134, 139, 473},        /* CadetBlue4 */
-    {127, 255, 0, 484},         /* chartreuse */
-    {127, 255, 0, 495},         /* chartreuse1 */
-    {118, 238, 0, 507},         /* chartreuse2 */
-    {102, 205, 0, 519},         /* chartreuse3 */
-    {69, 139, 0, 531},          /* chartreuse4 */
-    {210, 105, 30, 543},        /* chocolate */
-    {255, 127, 36, 553},        /* chocolate1 */
-    {238, 118, 33, 564},        /* chocolate2 */
-    {205, 102, 29, 575},        /* chocolate3 */
-    {139, 69, 19, 586},         /* chocolate4 */
-    {255, 127, 80, 597},        /* coral */
-    {255, 114, 86, 603},        /* coral1 */
-    {238, 106, 80, 610},        /* coral2 */
-    {205, 91, 69, 617},         /* coral3 */
-    {139, 62, 47, 624},         /* coral4 */
-    {100, 149, 237, 631},       /* cornflower blue */
-    {100, 149, 237, 647},       /* CornflowerBlue */
-    {255, 248, 220, 662},       /* cornsilk */
-    {255, 248, 220, 671},       /* cornsilk1 */
-    {238, 232, 205, 681},       /* cornsilk2 */
-    {205, 200, 177, 691},       /* cornsilk3 */
-    {139, 136, 120, 701},       /* cornsilk4 */
-    {0, 255, 255, 711},         /* cyan */
-    {0, 255, 255, 716},         /* cyan1 */
-    {0, 238, 238, 722},         /* cyan2 */
-    {0, 205, 205, 728},         /* cyan3 */
-    {0, 139, 139, 734},         /* cyan4 */
-    {0, 0, 139, 740},           /* dark blue */
-    {0, 139, 139, 750},         /* dark cyan */
-    {184, 134, 11, 760},        /* dark goldenrod */
-    {169, 169, 169, 775},       /* dark gray */
-    {0, 100, 0, 785},           /* dark green */
-    {169, 169, 169, 796},       /* dark grey */
-    {189, 183, 107, 806},       /* dark khaki */
-    {139, 0, 139, 817},         /* dark magenta */
-    {85, 107, 47, 830},         /* dark olive green */
-    {255, 140, 0, 847},         /* dark orange */
-    {153, 50, 204, 859},        /* dark orchid */
-    {139, 0, 0, 871},           /* dark red */
-    {233, 150, 122, 880},       /* dark salmon */
-    {143, 188, 143, 892},       /* dark sea green */
-    {72, 61, 139, 907},         /* dark slate blue */
-    {47, 79, 79, 923},          /* dark slate gray */
-    {47, 79, 79, 939},          /* dark slate grey */
-    {0, 206, 209, 955},         /* dark turquoise */
-    {148, 0, 211, 970},         /* dark violet */
-    {0, 0, 139, 982},           /* DarkBlue */
-    {0, 139, 139, 991},         /* DarkCyan */
-    {184, 134, 11, 1000},       /* DarkGoldenrod */
-    {255, 185, 15, 1014},       /* DarkGoldenrod1 */
-    {238, 173, 14, 1029},       /* DarkGoldenrod2 */
-    {205, 149, 12, 1044},       /* DarkGoldenrod3 */
-    {139, 101, 8, 1059},        /* DarkGoldenrod4 */
-    {169, 169, 169, 1074},      /* DarkGray */
-    {0, 100, 0, 1083},          /* DarkGreen */
-    {169, 169, 169, 1093},      /* DarkGrey */
-    {189, 183, 107, 1102},      /* DarkKhaki */
-    {139, 0, 139, 1112},        /* DarkMagenta */
-    {85, 107, 47, 1124},        /* DarkOliveGreen */
-    {202, 255, 112, 1139},      /* DarkOliveGreen1 */
-    {188, 238, 104, 1155},      /* DarkOliveGreen2 */
-    {162, 205, 90, 1171},       /* DarkOliveGreen3 */
-    {110, 139, 61, 1187},       /* DarkOliveGreen4 */
-    {255, 140, 0, 1203},        /* DarkOrange */
-    {255, 127, 0, 1214},        /* DarkOrange1 */
-    {238, 118, 0, 1226},        /* DarkOrange2 */
-    {205, 102, 0, 1238},        /* DarkOrange3 */
-    {139, 69, 0, 1250},         /* DarkOrange4 */
-    {153, 50, 204, 1262},       /* DarkOrchid */
-    {191, 62, 255, 1273},       /* DarkOrchid1 */
-    {178, 58, 238, 1285},       /* DarkOrchid2 */
-    {154, 50, 205, 1297},       /* DarkOrchid3 */
-    {104, 34, 139, 1309},       /* DarkOrchid4 */
-    {139, 0, 0, 1321},          /* DarkRed */
-    {233, 150, 122, 1329},      /* DarkSalmon */
-    {143, 188, 143, 1340},      /* DarkSeaGreen */
-    {193, 255, 193, 1353},      /* DarkSeaGreen1 */
-    {180, 238, 180, 1367},      /* DarkSeaGreen2 */
-    {155, 205, 155, 1381},      /* DarkSeaGreen3 */
-    {105, 139, 105, 1395},      /* DarkSeaGreen4 */
-    {72, 61, 139, 1409},        /* DarkSlateBlue */
-    {47, 79, 79, 1423},         /* DarkSlateGray */
-    {151, 255, 255, 1437},      /* DarkSlateGray1 */
-    {141, 238, 238, 1452},      /* DarkSlateGray2 */
-    {121, 205, 205, 1467},      /* DarkSlateGray3 */
-    {82, 139, 139, 1482},       /* DarkSlateGray4 */
-    {47, 79, 79, 1497},         /* DarkSlateGrey */
-    {0, 206, 209, 1511},        /* DarkTurquoise */
-    {148, 0, 211, 1525},        /* DarkViolet */
-    {255, 20, 147, 1536},       /* deep pink */
-    {0, 191, 255, 1546},        /* deep sky blue */
-    {255, 20, 147, 1560},       /* DeepPink */
-    {255, 20, 147, 1569},       /* DeepPink1 */
-    {238, 18, 137, 1579},       /* DeepPink2 */
-    {205, 16, 118, 1589},       /* DeepPink3 */
-    {139, 10, 80, 1599},        /* DeepPink4 */
-    {0, 191, 255, 1609},        /* DeepSkyBlue */
-    {0, 191, 255, 1621},        /* DeepSkyBlue1 */
-    {0, 178, 238, 1634},        /* DeepSkyBlue2 */
-    {0, 154, 205, 1647},        /* DeepSkyBlue3 */
-    {0, 104, 139, 1660},        /* DeepSkyBlue4 */
-    {105, 105, 105, 1673},      /* dim gray */
-    {105, 105, 105, 1682},      /* dim grey */
-    {105, 105, 105, 1691},      /* DimGray */
-    {105, 105, 105, 1699},      /* DimGrey */
-    {30, 144, 255, 1707},       /* dodger blue */
-    {30, 144, 255, 1719},       /* DodgerBlue */
-    {30, 144, 255, 1730},       /* DodgerBlue1 */
-    {28, 134, 238, 1742},       /* DodgerBlue2 */
-    {24, 116, 205, 1754},       /* DodgerBlue3 */
-    {16, 78, 139, 1766},        /* DodgerBlue4 */
-    {178, 34, 34, 1778},        /* firebrick */
-    {255, 48, 48, 1788},        /* firebrick1 */
-    {238, 44, 44, 1799},        /* firebrick2 */
-    {205, 38, 38, 1810},        /* firebrick3 */
-    {139, 26, 26, 1821},        /* firebrick4 */
-    {255, 250, 240, 1832},      /* floral white */
-    {255, 250, 240, 1845},      /* FloralWhite */
-    {34, 139, 34, 1857},        /* forest green */
-    {34, 139, 34, 1870},        /* ForestGreen */
-    {220, 220, 220, 1882},      /* gainsboro */
-    {248, 248, 255, 1892},      /* ghost white */
-    {248, 248, 255, 1904},      /* GhostWhite */
-    {255, 215, 0, 1915},        /* gold */
-    {255, 215, 0, 1920},        /* gold1 */
-    {238, 201, 0, 1926},        /* gold2 */
-    {205, 173, 0, 1932},        /* gold3 */
-    {139, 117, 0, 1938},        /* gold4 */
-    {218, 165, 32, 1944},       /* goldenrod */
-    {255, 193, 37, 1954},       /* goldenrod1 */
-    {238, 180, 34, 1965},       /* goldenrod2 */
-    {205, 155, 29, 1976},       /* goldenrod3 */
-    {139, 105, 20, 1987},       /* goldenrod4 */
-    {190, 190, 190, 1998},      /* gray */
-    {0, 0, 0, 2003},            /* gray0 */
-    {3, 3, 3, 2009},            /* gray1 */
-    {26, 26, 26, 2015},         /* gray10 */
-    {255, 255, 255, 2022},      /* gray100 */
-    {28, 28, 28, 2030},         /* gray11 */
-    {31, 31, 31, 2037},         /* gray12 */
-    {33, 33, 33, 2044},         /* gray13 */
-    {36, 36, 36, 2051},         /* gray14 */
-    {38, 38, 38, 2058},         /* gray15 */
-    {41, 41, 41, 2065},         /* gray16 */
-    {43, 43, 43, 2072},         /* gray17 */
-    {46, 46, 46, 2079},         /* gray18 */
-    {48, 48, 48, 2086},         /* gray19 */
-    {5, 5, 5, 2093},            /* gray2 */
-    {51, 51, 51, 2099},         /* gray20 */
-    {54, 54, 54, 2106},         /* gray21 */
-    {56, 56, 56, 2113},         /* gray22 */
-    {59, 59, 59, 2120},         /* gray23 */
-    {61, 61, 61, 2127},         /* gray24 */
-    {64, 64, 64, 2134},         /* gray25 */
-    {66, 66, 66, 2141},         /* gray26 */
-    {69, 69, 69, 2148},         /* gray27 */
-    {71, 71, 71, 2155},         /* gray28 */
-    {74, 74, 74, 2162},         /* gray29 */
-    {8, 8, 8, 2169},            /* gray3 */
-    {77, 77, 77, 2175},         /* gray30 */
-    {79, 79, 79, 2182},         /* gray31 */
-    {82, 82, 82, 2189},         /* gray32 */
-    {84, 84, 84, 2196},         /* gray33 */
-    {87, 87, 87, 2203},         /* gray34 */
-    {89, 89, 89, 2210},         /* gray35 */
-    {92, 92, 92, 2217},         /* gray36 */
-    {94, 94, 94, 2224},         /* gray37 */
-    {97, 97, 97, 2231},         /* gray38 */
-    {99, 99, 99, 2238},         /* gray39 */
-    {10, 10, 10, 2245},         /* gray4 */
-    {102, 102, 102, 2251},      /* gray40 */
-    {105, 105, 105, 2258},      /* gray41 */
-    {107, 107, 107, 2265},      /* gray42 */
-    {110, 110, 110, 2272},      /* gray43 */
-    {112, 112, 112, 2279},      /* gray44 */
-    {115, 115, 115, 2286},      /* gray45 */
-    {117, 117, 117, 2293},      /* gray46 */
-    {120, 120, 120, 2300},      /* gray47 */
-    {122, 122, 122, 2307},      /* gray48 */
-    {125, 125, 125, 2314},      /* gray49 */
-    {13, 13, 13, 2321},         /* gray5 */
-    {127, 127, 127, 2327},      /* gray50 */
-    {130, 130, 130, 2334},      /* gray51 */
-    {133, 133, 133, 2341},      /* gray52 */
-    {135, 135, 135, 2348},      /* gray53 */
-    {138, 138, 138, 2355},      /* gray54 */
-    {140, 140, 140, 2362},      /* gray55 */
-    {143, 143, 143, 2369},      /* gray56 */
-    {145, 145, 145, 2376},      /* gray57 */
-    {148, 148, 148, 2383},      /* gray58 */
-    {150, 150, 150, 2390},      /* gray59 */
-    {15, 15, 15, 2397},         /* gray6 */
-    {153, 153, 153, 2403},      /* gray60 */
-    {156, 156, 156, 2410},      /* gray61 */
-    {158, 158, 158, 2417},      /* gray62 */
-    {161, 161, 161, 2424},      /* gray63 */
-    {163, 163, 163, 2431},      /* gray64 */
-    {166, 166, 166, 2438},      /* gray65 */
-    {168, 168, 168, 2445},      /* gray66 */
-    {171, 171, 171, 2452},      /* gray67 */
-    {173, 173, 173, 2459},      /* gray68 */
-    {176, 176, 176, 2466},      /* gray69 */
-    {18, 18, 18, 2473},         /* gray7 */
-    {179, 179, 179, 2479},      /* gray70 */
-    {181, 181, 181, 2486},      /* gray71 */
-    {184, 184, 184, 2493},      /* gray72 */
-    {186, 186, 186, 2500},      /* gray73 */
-    {189, 189, 189, 2507},      /* gray74 */
-    {191, 191, 191, 2514},      /* gray75 */
-    {194, 194, 194, 2521},      /* gray76 */
-    {196, 196, 196, 2528},      /* gray77 */
-    {199, 199, 199, 2535},      /* gray78 */
-    {201, 201, 201, 2542},      /* gray79 */
-    {20, 20, 20, 2549},         /* gray8 */
-    {204, 204, 204, 2555},      /* gray80 */
-    {207, 207, 207, 2562},      /* gray81 */
-    {209, 209, 209, 2569},      /* gray82 */
-    {212, 212, 212, 2576},      /* gray83 */
-    {214, 214, 214, 2583},      /* gray84 */
-    {217, 217, 217, 2590},      /* gray85 */
-    {219, 219, 219, 2597},      /* gray86 */
-    {222, 222, 222, 2604},      /* gray87 */
-    {224, 224, 224, 2611},      /* gray88 */
-    {227, 227, 227, 2618},      /* gray89 */
-    {23, 23, 23, 2625},         /* gray9 */
-    {229, 229, 229, 2631},      /* gray90 */
-    {232, 232, 232, 2638},      /* gray91 */
-    {235, 235, 235, 2645},      /* gray92 */
-    {237, 237, 237, 2652},      /* gray93 */
-    {240, 240, 240, 2659},      /* gray94 */
-    {242, 242, 242, 2666},      /* gray95 */
-    {245, 245, 245, 2673},      /* gray96 */
-    {247, 247, 247, 2680},      /* gray97 */
-    {250, 250, 250, 2687},      /* gray98 */
-    {252, 252, 252, 2694},      /* gray99 */
-    {0, 255, 0, 2701},          /* green */
-    {173, 255, 47, 2707},       /* green yellow */
-    {0, 255, 0, 2720},          /* green1 */
-    {0, 238, 0, 2727},          /* green2 */
-    {0, 205, 0, 2734},          /* green3 */
-    {0, 139, 0, 2741},          /* green4 */
-    {173, 255, 47, 2748},       /* GreenYellow */
-    {190, 190, 190, 2760},      /* grey */
-    {0, 0, 0, 2765},            /* grey0 */
-    {3, 3, 3, 2771},            /* grey1 */
-    {26, 26, 26, 2777},         /* grey10 */
-    {255, 255, 255, 2784},      /* grey100 */
-    {28, 28, 28, 2792},         /* grey11 */
-    {31, 31, 31, 2799},         /* grey12 */
-    {33, 33, 33, 2806},         /* grey13 */
-    {36, 36, 36, 2813},         /* grey14 */
-    {38, 38, 38, 2820},         /* grey15 */
-    {41, 41, 41, 2827},         /* grey16 */
-    {43, 43, 43, 2834},         /* grey17 */
-    {46, 46, 46, 2841},         /* grey18 */
-    {48, 48, 48, 2848},         /* grey19 */
-    {5, 5, 5, 2855},            /* grey2 */
-    {51, 51, 51, 2861},         /* grey20 */
-    {54, 54, 54, 2868},         /* grey21 */
-    {56, 56, 56, 2875},         /* grey22 */
-    {59, 59, 59, 2882},         /* grey23 */
-    {61, 61, 61, 2889},         /* grey24 */
-    {64, 64, 64, 2896},         /* grey25 */
-    {66, 66, 66, 2903},         /* grey26 */
-    {69, 69, 69, 2910},         /* grey27 */
-    {71, 71, 71, 2917},         /* grey28 */
-    {74, 74, 74, 2924},         /* grey29 */
-    {8, 8, 8, 2931},            /* grey3 */
-    {77, 77, 77, 2937},         /* grey30 */
-    {79, 79, 79, 2944},         /* grey31 */
-    {82, 82, 82, 2951},         /* grey32 */
-    {84, 84, 84, 2958},         /* grey33 */
-    {87, 87, 87, 2965},         /* grey34 */
-    {89, 89, 89, 2972},         /* grey35 */
-    {92, 92, 92, 2979},         /* grey36 */
-    {94, 94, 94, 2986},         /* grey37 */
-    {97, 97, 97, 2993},         /* grey38 */
-    {99, 99, 99, 3000},         /* grey39 */
-    {10, 10, 10, 3007},         /* grey4 */
-    {102, 102, 102, 3013},      /* grey40 */
-    {105, 105, 105, 3020},      /* grey41 */
-    {107, 107, 107, 3027},      /* grey42 */
-    {110, 110, 110, 3034},      /* grey43 */
-    {112, 112, 112, 3041},      /* grey44 */
-    {115, 115, 115, 3048},      /* grey45 */
-    {117, 117, 117, 3055},      /* grey46 */
-    {120, 120, 120, 3062},      /* grey47 */
-    {122, 122, 122, 3069},      /* grey48 */
-    {125, 125, 125, 3076},      /* grey49 */
-    {13, 13, 13, 3083},         /* grey5 */
-    {127, 127, 127, 3089},      /* grey50 */
-    {130, 130, 130, 3096},      /* grey51 */
-    {133, 133, 133, 3103},      /* grey52 */
-    {135, 135, 135, 3110},      /* grey53 */
-    {138, 138, 138, 3117},      /* grey54 */
-    {140, 140, 140, 3124},      /* grey55 */
-    {143, 143, 143, 3131},      /* grey56 */
-    {145, 145, 145, 3138},      /* grey57 */
-    {148, 148, 148, 3145},      /* grey58 */
-    {150, 150, 150, 3152},      /* grey59 */
-    {15, 15, 15, 3159},         /* grey6 */
-    {153, 153, 153, 3165},      /* grey60 */
-    {156, 156, 156, 3172},      /* grey61 */
-    {158, 158, 158, 3179},      /* grey62 */
-    {161, 161, 161, 3186},      /* grey63 */
-    {163, 163, 163, 3193},      /* grey64 */
-    {166, 166, 166, 3200},      /* grey65 */
-    {168, 168, 168, 3207},      /* grey66 */
-    {171, 171, 171, 3214},      /* grey67 */
-    {173, 173, 173, 3221},      /* grey68 */
-    {176, 176, 176, 3228},      /* grey69 */
-    {18, 18, 18, 3235},         /* grey7 */
-    {179, 179, 179, 3241},      /* grey70 */
-    {181, 181, 181, 3248},      /* grey71 */
-    {184, 184, 184, 3255},      /* grey72 */
-    {186, 186, 186, 3262},      /* grey73 */
-    {189, 189, 189, 3269},      /* grey74 */
-    {191, 191, 191, 3276},      /* grey75 */
-    {194, 194, 194, 3283},      /* grey76 */
-    {196, 196, 196, 3290},      /* grey77 */
-    {199, 199, 199, 3297},      /* grey78 */
-    {201, 201, 201, 3304},      /* grey79 */
-    {20, 20, 20, 3311},         /* grey8 */
-    {204, 204, 204, 3317},      /* grey80 */
-    {207, 207, 207, 3324},      /* grey81 */
-    {209, 209, 209, 3331},      /* grey82 */
-    {212, 212, 212, 3338},      /* grey83 */
-    {214, 214, 214, 3345},      /* grey84 */
-    {217, 217, 217, 3352},      /* grey85 */
-    {219, 219, 219, 3359},      /* grey86 */
-    {222, 222, 222, 3366},      /* grey87 */
-    {224, 224, 224, 3373},      /* grey88 */
-    {227, 227, 227, 3380},      /* grey89 */
-    {23, 23, 23, 3387},         /* grey9 */
-    {229, 229, 229, 3393},      /* grey90 */
-    {232, 232, 232, 3400},      /* grey91 */
-    {235, 235, 235, 3407},      /* grey92 */
-    {237, 237, 237, 3414},      /* grey93 */
-    {240, 240, 240, 3421},      /* grey94 */
-    {242, 242, 242, 3428},      /* grey95 */
-    {245, 245, 245, 3435},      /* grey96 */
-    {247, 247, 247, 3442},      /* grey97 */
-    {250, 250, 250, 3449},      /* grey98 */
-    {252, 252, 252, 3456},      /* grey99 */
-    {240, 255, 240, 3463},      /* honeydew */
-    {240, 255, 240, 3472},      /* honeydew1 */
-    {224, 238, 224, 3482},      /* honeydew2 */
-    {193, 205, 193, 3492},      /* honeydew3 */
-    {131, 139, 131, 3502},      /* honeydew4 */
-    {255, 105, 180, 3512},      /* hot pink */
-    {255, 105, 180, 3521},      /* HotPink */
-    {255, 110, 180, 3529},      /* HotPink1 */
-    {238, 106, 167, 3538},      /* HotPink2 */
-    {205, 96, 144, 3547},       /* HotPink3 */
-    {139, 58, 98, 3556},        /* HotPink4 */
-    {205, 92, 92, 3565},        /* indian red */
-    {205, 92, 92, 3576},        /* IndianRed */
-    {255, 106, 106, 3586},      /* IndianRed1 */
-    {238, 99, 99, 3597},        /* IndianRed2 */
-    {205, 85, 85, 3608},        /* IndianRed3 */
-    {139, 58, 58, 3619},        /* IndianRed4 */
-    {255, 255, 240, 3630},      /* ivory */
-    {255, 255, 240, 3636},      /* ivory1 */
-    {238, 238, 224, 3643},      /* ivory2 */
-    {205, 205, 193, 3650},      /* ivory3 */
-    {139, 139, 131, 3657},      /* ivory4 */
-    {240, 230, 140, 3664},      /* khaki */
-    {255, 246, 143, 3670},      /* khaki1 */
-    {238, 230, 133, 3677},      /* khaki2 */
-    {205, 198, 115, 3684},      /* khaki3 */
-    {139, 134, 78, 3691},       /* khaki4 */
-    {230, 230, 250, 3698},      /* lavender */
-    {255, 240, 245, 3707},      /* lavender blush */
-    {255, 240, 245, 3722},      /* LavenderBlush */
-    {255, 240, 245, 3736},      /* LavenderBlush1 */
-    {238, 224, 229, 3751},      /* LavenderBlush2 */
-    {205, 193, 197, 3766},      /* LavenderBlush3 */
-    {139, 131, 134, 3781},      /* LavenderBlush4 */
-    {124, 252, 0, 3796},        /* lawn green */
-    {124, 252, 0, 3807},        /* LawnGreen */
-    {255, 250, 205, 3817},      /* lemon chiffon */
-    {255, 250, 205, 3831},      /* LemonChiffon */
-    {255, 250, 205, 3844},      /* LemonChiffon1 */
-    {238, 233, 191, 3858},      /* LemonChiffon2 */
-    {205, 201, 165, 3872},      /* LemonChiffon3 */
-    {139, 137, 112, 3886},      /* LemonChiffon4 */
-    {173, 216, 230, 3900},      /* light blue */
-    {240, 128, 128, 3911},      /* light coral */
-    {224, 255, 255, 3923},      /* light cyan */
-    {238, 221, 130, 3934},      /* light goldenrod */
-    {250, 250, 210, 3950},      /* light goldenrod yellow */
-    {211, 211, 211, 3973},      /* light gray */
-    {144, 238, 144, 3984},      /* light green */
-    {211, 211, 211, 3996},      /* light grey */
-    {255, 182, 193, 4007},      /* light pink */
-    {255, 160, 122, 4018},      /* light salmon */
-    {32, 178, 170, 4031},       /* light sea green */
-    {135, 206, 250, 4047},      /* light sky blue */
-    {132, 112, 255, 4062},      /* light slate blue */
-    {119, 136, 153, 4079},      /* light slate gray */
-    {119, 136, 153, 4096},      /* light slate grey */
-    {176, 196, 222, 4113},      /* light steel blue */
-    {255, 255, 224, 4130},      /* light yellow */
-    {173, 216, 230, 4143},      /* LightBlue */
-    {191, 239, 255, 4153},      /* LightBlue1 */
-    {178, 223, 238, 4164},      /* LightBlue2 */
-    {154, 192, 205, 4175},      /* LightBlue3 */
-    {104, 131, 139, 4186},      /* LightBlue4 */
-    {240, 128, 128, 4197},      /* LightCoral */
-    {224, 255, 255, 4208},      /* LightCyan */
-    {224, 255, 255, 4218},      /* LightCyan1 */
-    {209, 238, 238, 4229},      /* LightCyan2 */
-    {180, 205, 205, 4240},      /* LightCyan3 */
-    {122, 139, 139, 4251},      /* LightCyan4 */
-    {238, 221, 130, 4262},      /* LightGoldenrod */
-    {255, 236, 139, 4277},      /* LightGoldenrod1 */
-    {238, 220, 130, 4293},      /* LightGoldenrod2 */
-    {205, 190, 112, 4309},      /* LightGoldenrod3 */
-    {139, 129, 76, 4325},       /* LightGoldenrod4 */
-    {250, 250, 210, 4341},      /* LightGoldenrodYellow */
-    {211, 211, 211, 4362},      /* LightGray */
-    {144, 238, 144, 4372},      /* LightGreen */
-    {211, 211, 211, 4383},      /* LightGrey */
-    {255, 182, 193, 4393},      /* LightPink */
-    {255, 174, 185, 4403},      /* LightPink1 */
-    {238, 162, 173, 4414},      /* LightPink2 */
-    {205, 140, 149, 4425},      /* LightPink3 */
-    {139, 95, 101, 4436},       /* LightPink4 */
-    {255, 160, 122, 4447},      /* LightSalmon */
-    {255, 160, 122, 4459},      /* LightSalmon1 */
-    {238, 149, 114, 4472},      /* LightSalmon2 */
-    {205, 129, 98, 4485},       /* LightSalmon3 */
-    {139, 87, 66, 4498},        /* LightSalmon4 */
-    {32, 178, 170, 4511},       /* LightSeaGreen */
-    {135, 206, 250, 4525},      /* LightSkyBlue */
-    {176, 226, 255, 4538},      /* LightSkyBlue1 */
-    {164, 211, 238, 4552},      /* LightSkyBlue2 */
-    {141, 182, 205, 4566},      /* LightSkyBlue3 */
-    {96, 123, 139, 4580},       /* LightSkyBlue4 */
-    {132, 112, 255, 4594},      /* LightSlateBlue */
-    {119, 136, 153, 4609},      /* LightSlateGray */
-    {119, 136, 153, 4624},      /* LightSlateGrey */
-    {176, 196, 222, 4639},      /* LightSteelBlue */
-    {202, 225, 255, 4654},      /* LightSteelBlue1 */
-    {188, 210, 238, 4670},      /* LightSteelBlue2 */
-    {162, 181, 205, 4686},      /* LightSteelBlue3 */
-    {110, 123, 139, 4702},      /* LightSteelBlue4 */
-    {255, 255, 224, 4718},      /* LightYellow */
-    {255, 255, 224, 4730},      /* LightYellow1 */
-    {238, 238, 209, 4743},      /* LightYellow2 */
-    {205, 205, 180, 4756},      /* LightYellow3 */
-    {139, 139, 122, 4769},      /* LightYellow4 */
-    {50, 205, 50, 4782},        /* lime green */
-    {50, 205, 50, 4793},        /* LimeGreen */
-    {250, 240, 230, 4803},      /* linen */
-    {255, 0, 255, 4809},        /* magenta */
-    {255, 0, 255, 4817},        /* magenta1 */
-    {238, 0, 238, 4826},        /* magenta2 */
-    {205, 0, 205, 4835},        /* magenta3 */
-    {139, 0, 139, 4844},        /* magenta4 */
-    {176, 48, 96, 4853},        /* maroon */
-    {255, 52, 179, 4860},       /* maroon1 */
-    {238, 48, 167, 4868},       /* maroon2 */
-    {205, 41, 144, 4876},       /* maroon3 */
-    {139, 28, 98, 4884},        /* maroon4 */
-    {102, 205, 170, 4892},      /* medium aquamarine */
-    {0, 0, 205, 4910},          /* medium blue */
-    {186, 85, 211, 4922},       /* medium orchid */
-    {147, 112, 219, 4936},      /* medium purple */
-    {60, 179, 113, 4950},       /* medium sea green */
-    {123, 104, 238, 4967},      /* medium slate blue */
-    {0, 250, 154, 4985},        /* medium spring green */
-    {72, 209, 204, 5005},       /* medium turquoise */
-    {199, 21, 133, 5022},       /* medium violet red */
-    {102, 205, 170, 5040},      /* MediumAquamarine */
-    {0, 0, 205, 5057},          /* MediumBlue */
-    {186, 85, 211, 5068},       /* MediumOrchid */
-    {224, 102, 255, 5081},      /* MediumOrchid1 */
-    {209, 95, 238, 5095},       /* MediumOrchid2 */
-    {180, 82, 205, 5109},       /* MediumOrchid3 */
-    {122, 55, 139, 5123},       /* MediumOrchid4 */
-    {147, 112, 219, 5137},      /* MediumPurple */
-    {171, 130, 255, 5150},      /* MediumPurple1 */
-    {159, 121, 238, 5164},      /* MediumPurple2 */
-    {137, 104, 205, 5178},      /* MediumPurple3 */
-    {93, 71, 139, 5192},        /* MediumPurple4 */
-    {60, 179, 113, 5206},       /* MediumSeaGreen */
-    {123, 104, 238, 5221},      /* MediumSlateBlue */
-    {0, 250, 154, 5237},        /* MediumSpringGreen */
-    {72, 209, 204, 5255},       /* MediumTurquoise */
-    {199, 21, 133, 5271},       /* MediumVioletRed */
-    {25, 25, 112, 5287},        /* midnight blue */
-    {25, 25, 112, 5301},        /* MidnightBlue */
-    {245, 255, 250, 5314},      /* mint cream */
-    {245, 255, 250, 5325},      /* MintCream */
-    {255, 228, 225, 5335},      /* misty rose */
-    {255, 228, 225, 5346},      /* MistyRose */
-    {255, 228, 225, 5356},      /* MistyRose1 */
-    {238, 213, 210, 5367},      /* MistyRose2 */
-    {205, 183, 181, 5378},      /* MistyRose3 */
-    {139, 125, 123, 5389},      /* MistyRose4 */
-    {255, 228, 181, 5400},      /* moccasin */
-    {255, 222, 173, 5409},      /* navajo white */
-    {255, 222, 173, 5422},      /* NavajoWhite */
-    {255, 222, 173, 5434},      /* NavajoWhite1 */
-    {238, 207, 161, 5447},      /* NavajoWhite2 */
-    {205, 179, 139, 5460},      /* NavajoWhite3 */
-    {139, 121, 94, 5473},       /* NavajoWhite4 */
-    {0, 0, 128, 5486},          /* navy */
-    {0, 0, 128, 5491},          /* navy blue */
-    {0, 0, 128, 5501},          /* NavyBlue */
-    {253, 245, 230, 5510},      /* old lace */
-    {253, 245, 230, 5519},      /* OldLace */
-    {107, 142, 35, 5527},       /* olive drab */
-    {107, 142, 35, 5538},       /* OliveDrab */
-    {192, 255, 62, 5548},       /* OliveDrab1 */
-    {179, 238, 58, 5559},       /* OliveDrab2 */
-    {154, 205, 50, 5570},       /* OliveDrab3 */
-    {105, 139, 34, 5581},       /* OliveDrab4 */
-    {255, 165, 0, 5592},        /* orange */
-    {255, 69, 0, 5599},         /* orange red */
-    {255, 165, 0, 5610},        /* orange1 */
-    {238, 154, 0, 5618},        /* orange2 */
-    {205, 133, 0, 5626},        /* orange3 */
-    {139, 90, 0, 5634},         /* orange4 */
-    {255, 69, 0, 5642},         /* OrangeRed */
-    {255, 69, 0, 5652},         /* OrangeRed1 */
-    {238, 64, 0, 5663},         /* OrangeRed2 */
-    {205, 55, 0, 5674},         /* OrangeRed3 */
-    {139, 37, 0, 5685},         /* OrangeRed4 */
-    {218, 112, 214, 5696},      /* orchid */
-    {255, 131, 250, 5703},      /* orchid1 */
-    {238, 122, 233, 5711},      /* orchid2 */
-    {205, 105, 201, 5719},      /* orchid3 */
-    {139, 71, 137, 5727},       /* orchid4 */
-    {238, 232, 170, 5735},      /* pale goldenrod */
-    {152, 251, 152, 5750},      /* pale green */
-    {175, 238, 238, 5761},      /* pale turquoise */
-    {219, 112, 147, 5776},      /* pale violet red */
-    {238, 232, 170, 5792},      /* PaleGoldenrod */
-    {152, 251, 152, 5806},      /* PaleGreen */
-    {154, 255, 154, 5816},      /* PaleGreen1 */
-    {144, 238, 144, 5827},      /* PaleGreen2 */
-    {124, 205, 124, 5838},      /* PaleGreen3 */
-    {84, 139, 84, 5849},        /* PaleGreen4 */
-    {175, 238, 238, 5860},      /* PaleTurquoise */
-    {187, 255, 255, 5874},      /* PaleTurquoise1 */
-    {174, 238, 238, 5889},      /* PaleTurquoise2 */
-    {150, 205, 205, 5904},      /* PaleTurquoise3 */
-    {102, 139, 139, 5919},      /* PaleTurquoise4 */
-    {219, 112, 147, 5934},      /* PaleVioletRed */
-    {255, 130, 171, 5948},      /* PaleVioletRed1 */
-    {238, 121, 159, 5963},      /* PaleVioletRed2 */
-    {205, 104, 137, 5978},      /* PaleVioletRed3 */
-    {139, 71, 93, 5993},        /* PaleVioletRed4 */
-    {255, 239, 213, 6008},      /* papaya whip */
-    {255, 239, 213, 6020},      /* PapayaWhip */
-    {255, 218, 185, 6031},      /* peach puff */
-    {255, 218, 185, 6042},      /* PeachPuff */
-    {255, 218, 185, 6052},      /* PeachPuff1 */
-    {238, 203, 173, 6063},      /* PeachPuff2 */
-    {205, 175, 149, 6074},      /* PeachPuff3 */
-    {139, 119, 101, 6085},      /* PeachPuff4 */
-    {205, 133, 63, 6096},       /* peru */
-    {255, 192, 203, 6101},      /* pink */
-    {255, 181, 197, 6106},      /* pink1 */
-    {238, 169, 184, 6112},      /* pink2 */
-    {205, 145, 158, 6118},      /* pink3 */
-    {139, 99, 108, 6124},       /* pink4 */
-    {221, 160, 221, 6130},      /* plum */
-    {255, 187, 255, 6135},      /* plum1 */
-    {238, 174, 238, 6141},      /* plum2 */
-    {205, 150, 205, 6147},      /* plum3 */
-    {139, 102, 139, 6153},      /* plum4 */
-    {176, 224, 230, 6159},      /* powder blue */
-    {176, 224, 230, 6171},      /* PowderBlue */
-    {160, 32, 240, 6182},       /* purple */
-    {155, 48, 255, 6189},       /* purple1 */
-    {145, 44, 238, 6197},       /* purple2 */
-    {125, 38, 205, 6205},       /* purple3 */
-    {85, 26, 139, 6213},        /* purple4 */
-    {255, 0, 0, 6221},          /* red */
-    {255, 0, 0, 6225},          /* red1 */
-    {238, 0, 0, 6230},          /* red2 */
-    {205, 0, 0, 6235},          /* red3 */
-    {139, 0, 0, 6240},          /* red4 */
-    {188, 143, 143, 6245},      /* rosy brown */
-    {188, 143, 143, 6256},      /* RosyBrown */
-    {255, 193, 193, 6266},      /* RosyBrown1 */
-    {238, 180, 180, 6277},      /* RosyBrown2 */
-    {205, 155, 155, 6288},      /* RosyBrown3 */
-    {139, 105, 105, 6299},      /* RosyBrown4 */
-    {65, 105, 225, 6310},       /* royal blue */
-    {65, 105, 225, 6321},       /* RoyalBlue */
-    {72, 118, 255, 6331},       /* RoyalBlue1 */
-    {67, 110, 238, 6342},       /* RoyalBlue2 */
-    {58, 95, 205, 6353},        /* RoyalBlue3 */
-    {39, 64, 139, 6364},        /* RoyalBlue4 */
-    {139, 69, 19, 6375},        /* saddle brown */
-    {139, 69, 19, 6388},        /* SaddleBrown */
-    {250, 128, 114, 6400},      /* salmon */
-    {255, 140, 105, 6407},      /* salmon1 */
-    {238, 130, 98, 6415},       /* salmon2 */
-    {205, 112, 84, 6423},       /* salmon3 */
-    {139, 76, 57, 6431},        /* salmon4 */
-    {244, 164, 96, 6439},       /* sandy brown */
-    {244, 164, 96, 6451},       /* SandyBrown */
-    {46, 139, 87, 6462},        /* sea green */
-    {46, 139, 87, 6472},        /* SeaGreen */
-    {84, 255, 159, 6481},       /* SeaGreen1 */
-    {78, 238, 148, 6491},       /* SeaGreen2 */
-    {67, 205, 128, 6501},       /* SeaGreen3 */
-    {46, 139, 87, 6511},        /* SeaGreen4 */
-    {255, 245, 238, 6521},      /* seashell */
-    {255, 245, 238, 6530},      /* seashell1 */
-    {238, 229, 222, 6540},      /* seashell2 */
-    {205, 197, 191, 6550},      /* seashell3 */
-    {139, 134, 130, 6560},      /* seashell4 */
-    {160, 82, 45, 6570},        /* sienna */
-    {255, 130, 71, 6577},       /* sienna1 */
-    {238, 121, 66, 6585},       /* sienna2 */
-    {205, 104, 57, 6593},       /* sienna3 */
-    {139, 71, 38, 6601},        /* sienna4 */
-    {135, 206, 235, 6609},      /* sky blue */
-    {135, 206, 235, 6618},      /* SkyBlue */
-    {135, 206, 255, 6626},      /* SkyBlue1 */
-    {126, 192, 238, 6635},      /* SkyBlue2 */
-    {108, 166, 205, 6644},      /* SkyBlue3 */
-    {74, 112, 139, 6653},       /* SkyBlue4 */
-    {106, 90, 205, 6662},       /* slate blue */
-    {112, 128, 144, 6673},      /* slate gray */
-    {112, 128, 144, 6684},      /* slate grey */
-    {106, 90, 205, 6695},       /* SlateBlue */
-    {131, 111, 255, 6705},      /* SlateBlue1 */
-    {122, 103, 238, 6716},      /* SlateBlue2 */
-    {105, 89, 205, 6727},       /* SlateBlue3 */
-    {71, 60, 139, 6738},        /* SlateBlue4 */
-    {112, 128, 144, 6749},      /* SlateGray */
-    {198, 226, 255, 6759},      /* SlateGray1 */
-    {185, 211, 238, 6770},      /* SlateGray2 */
-    {159, 182, 205, 6781},      /* SlateGray3 */
-    {108, 123, 139, 6792},      /* SlateGray4 */
-    {112, 128, 144, 6803},      /* SlateGrey */
-    {255, 250, 250, 6813},      /* snow */
-    {255, 250, 250, 6818},      /* snow1 */
-    {238, 233, 233, 6824},      /* snow2 */
-    {205, 201, 201, 6830},      /* snow3 */
-    {139, 137, 137, 6836},      /* snow4 */
-    {0, 255, 127, 6842},        /* spring green */
-    {0, 255, 127, 6855},        /* SpringGreen */
-    {0, 255, 127, 6867},        /* SpringGreen1 */
-    {0, 238, 118, 6880},        /* SpringGreen2 */
-    {0, 205, 102, 6893},        /* SpringGreen3 */
-    {0, 139, 69, 6906},         /* SpringGreen4 */
-    {70, 130, 180, 6919},       /* steel blue */
-    {70, 130, 180, 6930},       /* SteelBlue */
-    {99, 184, 255, 6940},       /* SteelBlue1 */
-    {92, 172, 238, 6951},       /* SteelBlue2 */
-    {79, 148, 205, 6962},       /* SteelBlue3 */
-    {54, 100, 139, 6973},       /* SteelBlue4 */
-    {210, 180, 140, 6984},      /* tan */
-    {255, 165, 79, 6988},       /* tan1 */
-    {238, 154, 73, 6993},       /* tan2 */
-    {205, 133, 63, 6998},       /* tan3 */
-    {139, 90, 43, 7003},        /* tan4 */
-    {216, 191, 216, 7008},      /* thistle */
-    {255, 225, 255, 7016},      /* thistle1 */
-    {238, 210, 238, 7025},      /* thistle2 */
-    {205, 181, 205, 7034},      /* thistle3 */
-    {139, 123, 139, 7043},      /* thistle4 */
-    {255, 99, 71, 7052},        /* tomato */
-    {255, 99, 71, 7059},        /* tomato1 */
-    {238, 92, 66, 7067},        /* tomato2 */
-    {205, 79, 57, 7075},        /* tomato3 */
-    {139, 54, 38, 7083},        /* tomato4 */
-    {64, 224, 208, 7091},       /* turquoise */
-    {0, 245, 255, 7101},        /* turquoise1 */
-    {0, 229, 238, 7112},        /* turquoise2 */
-    {0, 197, 205, 7123},        /* turquoise3 */
-    {0, 134, 139, 7134},        /* turquoise4 */
-    {238, 130, 238, 7145},      /* violet */
-    {208, 32, 144, 7152},       /* violet red */
-    {208, 32, 144, 7163},       /* VioletRed */
-    {255, 62, 150, 7173},       /* VioletRed1 */
-    {238, 58, 140, 7184},       /* VioletRed2 */
-    {205, 50, 120, 7195},       /* VioletRed3 */
-    {139, 34, 82, 7206},        /* VioletRed4 */
-    {245, 222, 179, 7217},      /* wheat */
-    {255, 231, 186, 7223},      /* wheat1 */
-    {238, 216, 174, 7230},      /* wheat2 */
-    {205, 186, 150, 7237},      /* wheat3 */
-    {139, 126, 102, 7244},      /* wheat4 */
-    {255, 255, 255, 7251},      /* white */
-    {245, 245, 245, 7257},      /* white smoke */
-    {245, 245, 245, 7269},      /* WhiteSmoke */
-    {255, 255, 0, 7280},        /* yellow */
-    {154, 205, 50, 7287},       /* yellow green */
-    {255, 255, 0, 7300},        /* yellow1 */
-    {238, 238, 0, 7308},        /* yellow2 */
-    {205, 205, 0, 7316},        /* yellow3 */
-    {139, 139, 0, 7324},        /* yellow4 */
-    {154, 205, 50, 7332},       /* YellowGreen */
+    {0, 255, 255, 104},         /* aqua */
+    {127, 255, 212, 109},       /* aquamarine */
+    {127, 255, 212, 120},       /* aquamarine1 */
+    {118, 238, 198, 132},       /* aquamarine2 */
+    {102, 205, 170, 144},       /* aquamarine3 */
+    {69, 139, 116, 156},        /* aquamarine4 */
+    {240, 255, 255, 168},       /* azure */
+    {240, 255, 255, 174},       /* azure1 */
+    {224, 238, 238, 181},       /* azure2 */
+    {193, 205, 205, 188},       /* azure3 */
+    {131, 139, 139, 195},       /* azure4 */
+    {245, 245, 220, 202},       /* beige */
+    {255, 228, 196, 208},       /* bisque */
+    {255, 228, 196, 215},       /* bisque1 */
+    {238, 213, 183, 223},       /* bisque2 */
+    {205, 183, 158, 231},       /* bisque3 */
+    {139, 125, 107, 239},       /* bisque4 */
+    {0, 0, 0, 247},             /* black */
+    {255, 235, 205, 253},       /* blanched almond */
+    {255, 235, 205, 269},       /* BlanchedAlmond */
+    {0, 0, 255, 284},           /* blue */
+    {138, 43, 226, 289},        /* blue violet */
+    {0, 0, 255, 301},           /* blue1 */
+    {0, 0, 238, 307},           /* blue2 */
+    {0, 0, 205, 313},           /* blue3 */
+    {0, 0, 139, 319},           /* blue4 */
+    {138, 43, 226, 325},        /* BlueViolet */
+    {165, 42, 42, 336},         /* brown */
+    {255, 64, 64, 342},         /* brown1 */
+    {238, 59, 59, 349},         /* brown2 */
+    {205, 51, 51, 356},         /* brown3 */
+    {139, 35, 35, 363},         /* brown4 */
+    {222, 184, 135, 370},       /* burlywood */
+    {255, 211, 155, 380},       /* burlywood1 */
+    {238, 197, 145, 391},       /* burlywood2 */
+    {205, 170, 125, 402},       /* burlywood3 */
+    {139, 115, 85, 413},        /* burlywood4 */
+    {95, 158, 160, 424},        /* cadet blue */
+    {95, 158, 160, 435},        /* CadetBlue */
+    {152, 245, 255, 445},       /* CadetBlue1 */
+    {142, 229, 238, 456},       /* CadetBlue2 */
+    {122, 197, 205, 467},       /* CadetBlue3 */
+    {83, 134, 139, 478},        /* CadetBlue4 */
+    {127, 255, 0, 489},         /* chartreuse */
+    {127, 255, 0, 500},         /* chartreuse1 */
+    {118, 238, 0, 512},         /* chartreuse2 */
+    {102, 205, 0, 524},         /* chartreuse3 */
+    {69, 139, 0, 536},          /* chartreuse4 */
+    {210, 105, 30, 548},        /* chocolate */
+    {255, 127, 36, 558},        /* chocolate1 */
+    {238, 118, 33, 569},        /* chocolate2 */
+    {205, 102, 29, 580},        /* chocolate3 */
+    {139, 69, 19, 591},         /* chocolate4 */
+    {255, 127, 80, 602},        /* coral */
+    {255, 114, 86, 608},        /* coral1 */
+    {238, 106, 80, 615},        /* coral2 */
+    {205, 91, 69, 622},         /* coral3 */
+    {139, 62, 47, 629},         /* coral4 */
+    {100, 149, 237, 636},       /* cornflower blue */
+    {100, 149, 237, 652},       /* CornflowerBlue */
+    {255, 248, 220, 667},       /* cornsilk */
+    {255, 248, 220, 676},       /* cornsilk1 */
+    {238, 232, 205, 686},       /* cornsilk2 */
+    {205, 200, 177, 696},       /* cornsilk3 */
+    {139, 136, 120, 706},       /* cornsilk4 */
+    {220, 20, 60, 716},         /* crimson */
+    {0, 255, 255, 724},         /* cyan */
+    {0, 255, 255, 729},         /* cyan1 */
+    {0, 238, 238, 735},         /* cyan2 */
+    {0, 205, 205, 741},         /* cyan3 */
+    {0, 139, 139, 747},         /* cyan4 */
+    {0, 0, 139, 753},           /* dark blue */
+    {0, 139, 139, 763},         /* dark cyan */
+    {184, 134, 11, 773},        /* dark goldenrod */
+    {169, 169, 169, 788},       /* dark gray */
+    {0, 100, 0, 798},           /* dark green */
+    {169, 169, 169, 809},       /* dark grey */
+    {189, 183, 107, 819},       /* dark khaki */
+    {139, 0, 139, 830},         /* dark magenta */
+    {85, 107, 47, 843},         /* dark olive green */
+    {255, 140, 0, 860},         /* dark orange */
+    {153, 50, 204, 872},        /* dark orchid */
+    {139, 0, 0, 884},           /* dark red */
+    {233, 150, 122, 893},       /* dark salmon */
+    {143, 188, 143, 905},       /* dark sea green */
+    {72, 61, 139, 920},         /* dark slate blue */
+    {47, 79, 79, 936},          /* dark slate gray */
+    {47, 79, 79, 952},          /* dark slate grey */
+    {0, 206, 209, 968},         /* dark turquoise */
+    {148, 0, 211, 983},         /* dark violet */
+    {0, 0, 139, 995},           /* DarkBlue */
+    {0, 139, 139, 1004},        /* DarkCyan */
+    {184, 134, 11, 1013},       /* DarkGoldenrod */
+    {255, 185, 15, 1027},       /* DarkGoldenrod1 */
+    {238, 173, 14, 1042},       /* DarkGoldenrod2 */
+    {205, 149, 12, 1057},       /* DarkGoldenrod3 */
+    {139, 101, 8, 1072},        /* DarkGoldenrod4 */
+    {169, 169, 169, 1087},      /* DarkGray */
+    {0, 100, 0, 1096},          /* DarkGreen */
+    {169, 169, 169, 1106},      /* DarkGrey */
+    {189, 183, 107, 1115},      /* DarkKhaki */
+    {139, 0, 139, 1125},        /* DarkMagenta */
+    {85, 107, 47, 1137},        /* DarkOliveGreen */
+    {202, 255, 112, 1152},      /* DarkOliveGreen1 */
+    {188, 238, 104, 1168},      /* DarkOliveGreen2 */
+    {162, 205, 90, 1184},       /* DarkOliveGreen3 */
+    {110, 139, 61, 1200},       /* DarkOliveGreen4 */
+    {255, 140, 0, 1216},        /* DarkOrange */
+    {255, 127, 0, 1227},        /* DarkOrange1 */
+    {238, 118, 0, 1239},        /* DarkOrange2 */
+    {205, 102, 0, 1251},        /* DarkOrange3 */
+    {139, 69, 0, 1263},         /* DarkOrange4 */
+    {153, 50, 204, 1275},       /* DarkOrchid */
+    {191, 62, 255, 1286},       /* DarkOrchid1 */
+    {178, 58, 238, 1298},       /* DarkOrchid2 */
+    {154, 50, 205, 1310},       /* DarkOrchid3 */
+    {104, 34, 139, 1322},       /* DarkOrchid4 */
+    {139, 0, 0, 1334},          /* DarkRed */
+    {233, 150, 122, 1342},      /* DarkSalmon */
+    {143, 188, 143, 1353},      /* DarkSeaGreen */
+    {193, 255, 193, 1366},      /* DarkSeaGreen1 */
+    {180, 238, 180, 1380},      /* DarkSeaGreen2 */
+    {155, 205, 155, 1394},      /* DarkSeaGreen3 */
+    {105, 139, 105, 1408},      /* DarkSeaGreen4 */
+    {72, 61, 139, 1422},        /* DarkSlateBlue */
+    {47, 79, 79, 1436},         /* DarkSlateGray */
+    {151, 255, 255, 1450},      /* DarkSlateGray1 */
+    {141, 238, 238, 1465},      /* DarkSlateGray2 */
+    {121, 205, 205, 1480},      /* DarkSlateGray3 */
+    {82, 139, 139, 1495},       /* DarkSlateGray4 */
+    {47, 79, 79, 1510},         /* DarkSlateGrey */
+    {0, 206, 209, 1524},        /* DarkTurquoise */
+    {148, 0, 211, 1538},        /* DarkViolet */
+    {255, 20, 147, 1549},       /* deep pink */
+    {0, 191, 255, 1559},        /* deep sky blue */
+    {255, 20, 147, 1573},       /* DeepPink */
+    {255, 20, 147, 1582},       /* DeepPink1 */
+    {238, 18, 137, 1592},       /* DeepPink2 */
+    {205, 16, 118, 1602},       /* DeepPink3 */
+    {139, 10, 80, 1612},        /* DeepPink4 */
+    {0, 191, 255, 1622},        /* DeepSkyBlue */
+    {0, 191, 255, 1634},        /* DeepSkyBlue1 */
+    {0, 178, 238, 1647},        /* DeepSkyBlue2 */
+    {0, 154, 205, 1660},        /* DeepSkyBlue3 */
+    {0, 104, 139, 1673},        /* DeepSkyBlue4 */
+    {105, 105, 105, 1686},      /* dim gray */
+    {105, 105, 105, 1695},      /* dim grey */
+    {105, 105, 105, 1704},      /* DimGray */
+    {105, 105, 105, 1712},      /* DimGrey */
+    {30, 144, 255, 1720},       /* dodger blue */
+    {30, 144, 255, 1732},       /* DodgerBlue */
+    {30, 144, 255, 1743},       /* DodgerBlue1 */
+    {28, 134, 238, 1755},       /* DodgerBlue2 */
+    {24, 116, 205, 1767},       /* DodgerBlue3 */
+    {16, 78, 139, 1779},        /* DodgerBlue4 */
+    {178, 34, 34, 1791},        /* firebrick */
+    {255, 48, 48, 1801},        /* firebrick1 */
+    {238, 44, 44, 1812},        /* firebrick2 */
+    {205, 38, 38, 1823},        /* firebrick3 */
+    {139, 26, 26, 1834},        /* firebrick4 */
+    {255, 250, 240, 1845},      /* floral white */
+    {255, 250, 240, 1858},      /* FloralWhite */
+    {34, 139, 34, 1870},        /* forest green */
+    {34, 139, 34, 1883},        /* ForestGreen */
+    {255, 0, 255, 1895},        /* fuchsia */
+    {220, 220, 220, 1903},      /* gainsboro */
+    {248, 248, 255, 1913},      /* ghost white */
+    {248, 248, 255, 1925},      /* GhostWhite */
+    {255, 215, 0, 1936},        /* gold */
+    {255, 215, 0, 1941},        /* gold1 */
+    {238, 201, 0, 1947},        /* gold2 */
+    {205, 173, 0, 1953},        /* gold3 */
+    {139, 117, 0, 1959},        /* gold4 */
+    {218, 165, 32, 1965},       /* goldenrod */
+    {255, 193, 37, 1975},       /* goldenrod1 */
+    {238, 180, 34, 1986},       /* goldenrod2 */
+    {205, 155, 29, 1997},       /* goldenrod3 */
+    {139, 105, 20, 2008},       /* goldenrod4 */
+    {190, 190, 190, 2019},      /* gray */
+    {0, 0, 0, 2024},            /* gray0 */
+    {3, 3, 3, 2030},            /* gray1 */
+    {26, 26, 26, 2036},         /* gray10 */
+    {255, 255, 255, 2043},      /* gray100 */
+    {28, 28, 28, 2051},         /* gray11 */
+    {31, 31, 31, 2058},         /* gray12 */
+    {33, 33, 33, 2065},         /* gray13 */
+    {36, 36, 36, 2072},         /* gray14 */
+    {38, 38, 38, 2079},         /* gray15 */
+    {41, 41, 41, 2086},         /* gray16 */
+    {43, 43, 43, 2093},         /* gray17 */
+    {46, 46, 46, 2100},         /* gray18 */
+    {48, 48, 48, 2107},         /* gray19 */
+    {5, 5, 5, 2114},            /* gray2 */
+    {51, 51, 51, 2120},         /* gray20 */
+    {54, 54, 54, 2127},         /* gray21 */
+    {56, 56, 56, 2134},         /* gray22 */
+    {59, 59, 59, 2141},         /* gray23 */
+    {61, 61, 61, 2148},         /* gray24 */
+    {64, 64, 64, 2155},         /* gray25 */
+    {66, 66, 66, 2162},         /* gray26 */
+    {69, 69, 69, 2169},         /* gray27 */
+    {71, 71, 71, 2176},         /* gray28 */
+    {74, 74, 74, 2183},         /* gray29 */
+    {8, 8, 8, 2190},            /* gray3 */
+    {77, 77, 77, 2196},         /* gray30 */
+    {79, 79, 79, 2203},         /* gray31 */
+    {82, 82, 82, 2210},         /* gray32 */
+    {84, 84, 84, 2217},         /* gray33 */
+    {87, 87, 87, 2224},         /* gray34 */
+    {89, 89, 89, 2231},         /* gray35 */
+    {92, 92, 92, 2238},         /* gray36 */
+    {94, 94, 94, 2245},         /* gray37 */
+    {97, 97, 97, 2252},         /* gray38 */
+    {99, 99, 99, 2259},         /* gray39 */
+    {10, 10, 10, 2266},         /* gray4 */
+    {102, 102, 102, 2272},      /* gray40 */
+    {105, 105, 105, 2279},      /* gray41 */
+    {107, 107, 107, 2286},      /* gray42 */
+    {110, 110, 110, 2293},      /* gray43 */
+    {112, 112, 112, 2300},      /* gray44 */
+    {115, 115, 115, 2307},      /* gray45 */
+    {117, 117, 117, 2314},      /* gray46 */
+    {120, 120, 120, 2321},      /* gray47 */
+    {122, 122, 122, 2328},      /* gray48 */
+    {125, 125, 125, 2335},      /* gray49 */
+    {13, 13, 13, 2342},         /* gray5 */
+    {127, 127, 127, 2348},      /* gray50 */
+    {130, 130, 130, 2355},      /* gray51 */
+    {133, 133, 133, 2362},      /* gray52 */
+    {135, 135, 135, 2369},      /* gray53 */
+    {138, 138, 138, 2376},      /* gray54 */
+    {140, 140, 140, 2383},      /* gray55 */
+    {143, 143, 143, 2390},      /* gray56 */
+    {145, 145, 145, 2397},      /* gray57 */
+    {148, 148, 148, 2404},      /* gray58 */
+    {150, 150, 150, 2411},      /* gray59 */
+    {15, 15, 15, 2418},         /* gray6 */
+    {153, 153, 153, 2424},      /* gray60 */
+    {156, 156, 156, 2431},      /* gray61 */
+    {158, 158, 158, 2438},      /* gray62 */
+    {161, 161, 161, 2445},      /* gray63 */
+    {163, 163, 163, 2452},      /* gray64 */
+    {166, 166, 166, 2459},      /* gray65 */
+    {168, 168, 168, 2466},      /* gray66 */
+    {171, 171, 171, 2473},      /* gray67 */
+    {173, 173, 173, 2480},      /* gray68 */
+    {176, 176, 176, 2487},      /* gray69 */
+    {18, 18, 18, 2494},         /* gray7 */
+    {179, 179, 179, 2500},      /* gray70 */
+    {181, 181, 181, 2507},      /* gray71 */
+    {184, 184, 184, 2514},      /* gray72 */
+    {186, 186, 186, 2521},      /* gray73 */
+    {189, 189, 189, 2528},      /* gray74 */
+    {191, 191, 191, 2535},      /* gray75 */
+    {194, 194, 194, 2542},      /* gray76 */
+    {196, 196, 196, 2549},      /* gray77 */
+    {199, 199, 199, 2556},      /* gray78 */
+    {201, 201, 201, 2563},      /* gray79 */
+    {20, 20, 20, 2570},         /* gray8 */
+    {204, 204, 204, 2576},      /* gray80 */
+    {207, 207, 207, 2583},      /* gray81 */
+    {209, 209, 209, 2590},      /* gray82 */
+    {212, 212, 212, 2597},      /* gray83 */
+    {214, 214, 214, 2604},      /* gray84 */
+    {217, 217, 217, 2611},      /* gray85 */
+    {219, 219, 219, 2618},      /* gray86 */
+    {222, 222, 222, 2625},      /* gray87 */
+    {224, 224, 224, 2632},      /* gray88 */
+    {227, 227, 227, 2639},      /* gray89 */
+    {23, 23, 23, 2646},         /* gray9 */
+    {229, 229, 229, 2652},      /* gray90 */
+    {232, 232, 232, 2659},      /* gray91 */
+    {235, 235, 235, 2666},      /* gray92 */
+    {237, 237, 237, 2673},      /* gray93 */
+    {240, 240, 240, 2680},      /* gray94 */
+    {242, 242, 242, 2687},      /* gray95 */
+    {245, 245, 245, 2694},      /* gray96 */
+    {247, 247, 247, 2701},      /* gray97 */
+    {250, 250, 250, 2708},      /* gray98 */
+    {252, 252, 252, 2715},      /* gray99 */
+    {0, 255, 0, 2722},          /* green */
+    {173, 255, 47, 2728},       /* green yellow */
+    {0, 255, 0, 2741},          /* green1 */
+    {0, 238, 0, 2748},          /* green2 */
+    {0, 205, 0, 2755},          /* green3 */
+    {0, 139, 0, 2762},          /* green4 */
+    {173, 255, 47, 2769},       /* GreenYellow */
+    {190, 190, 190, 2781},      /* grey */
+    {0, 0, 0, 2786},            /* grey0 */
+    {3, 3, 3, 2792},            /* grey1 */
+    {26, 26, 26, 2798},         /* grey10 */
+    {255, 255, 255, 2805},      /* grey100 */
+    {28, 28, 28, 2813},         /* grey11 */
+    {31, 31, 31, 2820},         /* grey12 */
+    {33, 33, 33, 2827},         /* grey13 */
+    {36, 36, 36, 2834},         /* grey14 */
+    {38, 38, 38, 2841},         /* grey15 */
+    {41, 41, 41, 2848},         /* grey16 */
+    {43, 43, 43, 2855},         /* grey17 */
+    {46, 46, 46, 2862},         /* grey18 */
+    {48, 48, 48, 2869},         /* grey19 */
+    {5, 5, 5, 2876},            /* grey2 */
+    {51, 51, 51, 2882},         /* grey20 */
+    {54, 54, 54, 2889},         /* grey21 */
+    {56, 56, 56, 2896},         /* grey22 */
+    {59, 59, 59, 2903},         /* grey23 */
+    {61, 61, 61, 2910},         /* grey24 */
+    {64, 64, 64, 2917},         /* grey25 */
+    {66, 66, 66, 2924},         /* grey26 */
+    {69, 69, 69, 2931},         /* grey27 */
+    {71, 71, 71, 2938},         /* grey28 */
+    {74, 74, 74, 2945},         /* grey29 */
+    {8, 8, 8, 2952},            /* grey3 */
+    {77, 77, 77, 2958},         /* grey30 */
+    {79, 79, 79, 2965},         /* grey31 */
+    {82, 82, 82, 2972},         /* grey32 */
+    {84, 84, 84, 2979},         /* grey33 */
+    {87, 87, 87, 2986},         /* grey34 */
+    {89, 89, 89, 2993},         /* grey35 */
+    {92, 92, 92, 3000},         /* grey36 */
+    {94, 94, 94, 3007},         /* grey37 */
+    {97, 97, 97, 3014},         /* grey38 */
+    {99, 99, 99, 3021},         /* grey39 */
+    {10, 10, 10, 3028},         /* grey4 */
+    {102, 102, 102, 3034},      /* grey40 */
+    {105, 105, 105, 3041},      /* grey41 */
+    {107, 107, 107, 3048},      /* grey42 */
+    {110, 110, 110, 3055},      /* grey43 */
+    {112, 112, 112, 3062},      /* grey44 */
+    {115, 115, 115, 3069},      /* grey45 */
+    {117, 117, 117, 3076},      /* grey46 */
+    {120, 120, 120, 3083},      /* grey47 */
+    {122, 122, 122, 3090},      /* grey48 */
+    {125, 125, 125, 3097},      /* grey49 */
+    {13, 13, 13, 3104},         /* grey5 */
+    {127, 127, 127, 3110},      /* grey50 */
+    {130, 130, 130, 3117},      /* grey51 */
+    {133, 133, 133, 3124},      /* grey52 */
+    {135, 135, 135, 3131},      /* grey53 */
+    {138, 138, 138, 3138},      /* grey54 */
+    {140, 140, 140, 3145},      /* grey55 */
+    {143, 143, 143, 3152},      /* grey56 */
+    {145, 145, 145, 3159},      /* grey57 */
+    {148, 148, 148, 3166},      /* grey58 */
+    {150, 150, 150, 3173},      /* grey59 */
+    {15, 15, 15, 3180},         /* grey6 */
+    {153, 153, 153, 3186},      /* grey60 */
+    {156, 156, 156, 3193},      /* grey61 */
+    {158, 158, 158, 3200},      /* grey62 */
+    {161, 161, 161, 3207},      /* grey63 */
+    {163, 163, 163, 3214},      /* grey64 */
+    {166, 166, 166, 3221},      /* grey65 */
+    {168, 168, 168, 3228},      /* grey66 */
+    {171, 171, 171, 3235},      /* grey67 */
+    {173, 173, 173, 3242},      /* grey68 */
+    {176, 176, 176, 3249},      /* grey69 */
+    {18, 18, 18, 3256},         /* grey7 */
+    {179, 179, 179, 3262},      /* grey70 */
+    {181, 181, 181, 3269},      /* grey71 */
+    {184, 184, 184, 3276},      /* grey72 */
+    {186, 186, 186, 3283},      /* grey73 */
+    {189, 189, 189, 3290},      /* grey74 */
+    {191, 191, 191, 3297},      /* grey75 */
+    {194, 194, 194, 3304},      /* grey76 */
+    {196, 196, 196, 3311},      /* grey77 */
+    {199, 199, 199, 3318},      /* grey78 */
+    {201, 201, 201, 3325},      /* grey79 */
+    {20, 20, 20, 3332},         /* grey8 */
+    {204, 204, 204, 3338},      /* grey80 */
+    {207, 207, 207, 3345},      /* grey81 */
+    {209, 209, 209, 3352},      /* grey82 */
+    {212, 212, 212, 3359},      /* grey83 */
+    {214, 214, 214, 3366},      /* grey84 */
+    {217, 217, 217, 3373},      /* grey85 */
+    {219, 219, 219, 3380},      /* grey86 */
+    {222, 222, 222, 3387},      /* grey87 */
+    {224, 224, 224, 3394},      /* grey88 */
+    {227, 227, 227, 3401},      /* grey89 */
+    {23, 23, 23, 3408},         /* grey9 */
+    {229, 229, 229, 3414},      /* grey90 */
+    {232, 232, 232, 3421},      /* grey91 */
+    {235, 235, 235, 3428},      /* grey92 */
+    {237, 237, 237, 3435},      /* grey93 */
+    {240, 240, 240, 3442},      /* grey94 */
+    {242, 242, 242, 3449},      /* grey95 */
+    {245, 245, 245, 3456},      /* grey96 */
+    {247, 247, 247, 3463},      /* grey97 */
+    {250, 250, 250, 3470},      /* grey98 */
+    {252, 252, 252, 3477},      /* grey99 */
+    {240, 255, 240, 3484},      /* honeydew */
+    {240, 255, 240, 3493},      /* honeydew1 */
+    {224, 238, 224, 3503},      /* honeydew2 */
+    {193, 205, 193, 3513},      /* honeydew3 */
+    {131, 139, 131, 3523},      /* honeydew4 */
+    {255, 105, 180, 3533},      /* hot pink */
+    {255, 105, 180, 3542},      /* HotPink */
+    {255, 110, 180, 3550},      /* HotPink1 */
+    {238, 106, 167, 3559},      /* HotPink2 */
+    {205, 96, 144, 3568},       /* HotPink3 */
+    {139, 58, 98, 3577},        /* HotPink4 */
+    {205, 92, 92, 3586},        /* indian red */
+    {205, 92, 92, 3597},        /* IndianRed */
+    {255, 106, 106, 3607},      /* IndianRed1 */
+    {238, 99, 99, 3618},        /* IndianRed2 */
+    {205, 85, 85, 3629},        /* IndianRed3 */
+    {139, 58, 58, 3640},        /* IndianRed4 */
+    {75, 0, 130, 3651},         /* indigo */
+    {255, 255, 240, 3658},      /* ivory */
+    {255, 255, 240, 3664},      /* ivory1 */
+    {238, 238, 224, 3671},      /* ivory2 */
+    {205, 205, 193, 3678},      /* ivory3 */
+    {139, 139, 131, 3685},      /* ivory4 */
+    {240, 230, 140, 3692},      /* khaki */
+    {255, 246, 143, 3698},      /* khaki1 */
+    {238, 230, 133, 3705},      /* khaki2 */
+    {205, 198, 115, 3712},      /* khaki3 */
+    {139, 134, 78, 3719},       /* khaki4 */
+    {230, 230, 250, 3726},      /* lavender */
+    {255, 240, 245, 3735},      /* lavender blush */
+    {255, 240, 245, 3750},      /* LavenderBlush */
+    {255, 240, 245, 3764},      /* LavenderBlush1 */
+    {238, 224, 229, 3779},      /* LavenderBlush2 */
+    {205, 193, 197, 3794},      /* LavenderBlush3 */
+    {139, 131, 134, 3809},      /* LavenderBlush4 */
+    {124, 252, 0, 3824},        /* lawn green */
+    {124, 252, 0, 3835},        /* LawnGreen */
+    {255, 250, 205, 3845},      /* lemon chiffon */
+    {255, 250, 205, 3859},      /* LemonChiffon */
+    {255, 250, 205, 3872},      /* LemonChiffon1 */
+    {238, 233, 191, 3886},      /* LemonChiffon2 */
+    {205, 201, 165, 3900},      /* LemonChiffon3 */
+    {139, 137, 112, 3914},      /* LemonChiffon4 */
+    {173, 216, 230, 3928},      /* light blue */
+    {240, 128, 128, 3939},      /* light coral */
+    {224, 255, 255, 3951},      /* light cyan */
+    {238, 221, 130, 3962},      /* light goldenrod */
+    {250, 250, 210, 3978},      /* light goldenrod yellow */
+    {211, 211, 211, 4001},      /* light gray */
+    {144, 238, 144, 4012},      /* light green */
+    {211, 211, 211, 4024},      /* light grey */
+    {255, 182, 193, 4035},      /* light pink */
+    {255, 160, 122, 4046},      /* light salmon */
+    {32, 178, 170, 4059},       /* light sea green */
+    {135, 206, 250, 4075},      /* light sky blue */
+    {132, 112, 255, 4090},      /* light slate blue */
+    {119, 136, 153, 4107},      /* light slate gray */
+    {119, 136, 153, 4124},      /* light slate grey */
+    {176, 196, 222, 4141},      /* light steel blue */
+    {255, 255, 224, 4158},      /* light yellow */
+    {173, 216, 230, 4171},      /* LightBlue */
+    {191, 239, 255, 4181},      /* LightBlue1 */
+    {178, 223, 238, 4192},      /* LightBlue2 */
+    {154, 192, 205, 4203},      /* LightBlue3 */
+    {104, 131, 139, 4214},      /* LightBlue4 */
+    {240, 128, 128, 4225},      /* LightCoral */
+    {224, 255, 255, 4236},      /* LightCyan */
+    {224, 255, 255, 4246},      /* LightCyan1 */
+    {209, 238, 238, 4257},      /* LightCyan2 */
+    {180, 205, 205, 4268},      /* LightCyan3 */
+    {122, 139, 139, 4279},      /* LightCyan4 */
+    {238, 221, 130, 4290},      /* LightGoldenrod */
+    {255, 236, 139, 4305},      /* LightGoldenrod1 */
+    {238, 220, 130, 4321},      /* LightGoldenrod2 */
+    {205, 190, 112, 4337},      /* LightGoldenrod3 */
+    {139, 129, 76, 4353},       /* LightGoldenrod4 */
+    {250, 250, 210, 4369},      /* LightGoldenrodYellow */
+    {211, 211, 211, 4390},      /* LightGray */
+    {144, 238, 144, 4400},      /* LightGreen */
+    {211, 211, 211, 4411},      /* LightGrey */
+    {255, 182, 193, 4421},      /* LightPink */
+    {255, 174, 185, 4431},      /* LightPink1 */
+    {238, 162, 173, 4442},      /* LightPink2 */
+    {205, 140, 149, 4453},      /* LightPink3 */
+    {139, 95, 101, 4464},       /* LightPink4 */
+    {255, 160, 122, 4475},      /* LightSalmon */
+    {255, 160, 122, 4487},      /* LightSalmon1 */
+    {238, 149, 114, 4500},      /* LightSalmon2 */
+    {205, 129, 98, 4513},       /* LightSalmon3 */
+    {139, 87, 66, 4526},        /* LightSalmon4 */
+    {32, 178, 170, 4539},       /* LightSeaGreen */
+    {135, 206, 250, 4553},      /* LightSkyBlue */
+    {176, 226, 255, 4566},      /* LightSkyBlue1 */
+    {164, 211, 238, 4580},      /* LightSkyBlue2 */
+    {141, 182, 205, 4594},      /* LightSkyBlue3 */
+    {96, 123, 139, 4608},       /* LightSkyBlue4 */
+    {132, 112, 255, 4622},      /* LightSlateBlue */
+    {119, 136, 153, 4637},      /* LightSlateGray */
+    {119, 136, 153, 4652},      /* LightSlateGrey */
+    {176, 196, 222, 4667},      /* LightSteelBlue */
+    {202, 225, 255, 4682},      /* LightSteelBlue1 */
+    {188, 210, 238, 4698},      /* LightSteelBlue2 */
+    {162, 181, 205, 4714},      /* LightSteelBlue3 */
+    {110, 123, 139, 4730},      /* LightSteelBlue4 */
+    {255, 255, 224, 4746},      /* LightYellow */
+    {255, 255, 224, 4758},      /* LightYellow1 */
+    {238, 238, 209, 4771},      /* LightYellow2 */
+    {205, 205, 180, 4784},      /* LightYellow3 */
+    {139, 139, 122, 4797},      /* LightYellow4 */
+    {0, 255, 0, 4810},          /* lime */
+    {50, 205, 50, 4815},        /* lime green */
+    {50, 205, 50, 4826},        /* LimeGreen */
+    {250, 240, 230, 4836},      /* linen */
+    {255, 0, 255, 4842},        /* magenta */
+    {255, 0, 255, 4850},        /* magenta1 */
+    {238, 0, 238, 4859},        /* magenta2 */
+    {205, 0, 205, 4868},        /* magenta3 */
+    {139, 0, 139, 4877},        /* magenta4 */
+    {176, 48, 96, 4886},        /* maroon */
+    {255, 52, 179, 4893},       /* maroon1 */
+    {238, 48, 167, 4901},       /* maroon2 */
+    {205, 41, 144, 4909},       /* maroon3 */
+    {139, 28, 98, 4917},        /* maroon4 */
+    {102, 205, 170, 4925},      /* medium aquamarine */
+    {0, 0, 205, 4943},          /* medium blue */
+    {186, 85, 211, 4955},       /* medium orchid */
+    {147, 112, 219, 4969},      /* medium purple */
+    {60, 179, 113, 4983},       /* medium sea green */
+    {123, 104, 238, 5000},      /* medium slate blue */
+    {0, 250, 154, 5018},        /* medium spring green */
+    {72, 209, 204, 5038},       /* medium turquoise */
+    {199, 21, 133, 5055},       /* medium violet red */
+    {102, 205, 170, 5073},      /* MediumAquamarine */
+    {0, 0, 205, 5090},          /* MediumBlue */
+    {186, 85, 211, 5101},       /* MediumOrchid */
+    {224, 102, 255, 5114},      /* MediumOrchid1 */
+    {209, 95, 238, 5128},       /* MediumOrchid2 */
+    {180, 82, 205, 5142},       /* MediumOrchid3 */
+    {122, 55, 139, 5156},       /* MediumOrchid4 */
+    {147, 112, 219, 5170},      /* MediumPurple */
+    {171, 130, 255, 5183},      /* MediumPurple1 */
+    {159, 121, 238, 5197},      /* MediumPurple2 */
+    {137, 104, 205, 5211},      /* MediumPurple3 */
+    {93, 71, 139, 5225},        /* MediumPurple4 */
+    {60, 179, 113, 5239},       /* MediumSeaGreen */
+    {123, 104, 238, 5254},      /* MediumSlateBlue */
+    {0, 250, 154, 5270},        /* MediumSpringGreen */
+    {72, 209, 204, 5288},       /* MediumTurquoise */
+    {199, 21, 133, 5304},       /* MediumVioletRed */
+    {25, 25, 112, 5320},        /* midnight blue */
+    {25, 25, 112, 5334},        /* MidnightBlue */
+    {245, 255, 250, 5347},      /* mint cream */
+    {245, 255, 250, 5358},      /* MintCream */
+    {255, 228, 225, 5368},      /* misty rose */
+    {255, 228, 225, 5379},      /* MistyRose */
+    {255, 228, 225, 5389},      /* MistyRose1 */
+    {238, 213, 210, 5400},      /* MistyRose2 */
+    {205, 183, 181, 5411},      /* MistyRose3 */
+    {139, 125, 123, 5422},      /* MistyRose4 */
+    {255, 228, 181, 5433},      /* moccasin */
+    {255, 222, 173, 5442},      /* navajo white */
+    {255, 222, 173, 5455},      /* NavajoWhite */
+    {255, 222, 173, 5467},      /* NavajoWhite1 */
+    {238, 207, 161, 5480},      /* NavajoWhite2 */
+    {205, 179, 139, 5493},      /* NavajoWhite3 */
+    {139, 121, 94, 5506},       /* NavajoWhite4 */
+    {0, 0, 128, 5519},          /* navy */
+    {0, 0, 128, 5524},          /* navy blue */
+    {0, 0, 128, 5534},          /* NavyBlue */
+    {253, 245, 230, 5543},      /* old lace */
+    {253, 245, 230, 5552},      /* OldLace */
+    {128, 128, 0, 5560},        /* olive */
+    {107, 142, 35, 5566},       /* olive drab */
+    {107, 142, 35, 5577},       /* OliveDrab */
+    {192, 255, 62, 5587},       /* OliveDrab1 */
+    {179, 238, 58, 5598},       /* OliveDrab2 */
+    {154, 205, 50, 5609},       /* OliveDrab3 */
+    {105, 139, 34, 5620},       /* OliveDrab4 */
+    {255, 165, 0, 5631},        /* orange */
+    {255, 69, 0, 5638},         /* orange red */
+    {255, 165, 0, 5649},        /* orange1 */
+    {238, 154, 0, 5657},        /* orange2 */
+    {205, 133, 0, 5665},        /* orange3 */
+    {139, 90, 0, 5673},         /* orange4 */
+    {255, 69, 0, 5681},         /* OrangeRed */
+    {255, 69, 0, 5691},         /* OrangeRed1 */
+    {238, 64, 0, 5702},         /* OrangeRed2 */
+    {205, 55, 0, 5713},         /* OrangeRed3 */
+    {139, 37, 0, 5724},         /* OrangeRed4 */
+    {218, 112, 214, 5735},      /* orchid */
+    {255, 131, 250, 5742},      /* orchid1 */
+    {238, 122, 233, 5750},      /* orchid2 */
+    {205, 105, 201, 5758},      /* orchid3 */
+    {139, 71, 137, 5766},       /* orchid4 */
+    {238, 232, 170, 5774},      /* pale goldenrod */
+    {152, 251, 152, 5789},      /* pale green */
+    {175, 238, 238, 5800},      /* pale turquoise */
+    {219, 112, 147, 5815},      /* pale violet red */
+    {238, 232, 170, 5831},      /* PaleGoldenrod */
+    {152, 251, 152, 5845},      /* PaleGreen */
+    {154, 255, 154, 5855},      /* PaleGreen1 */
+    {144, 238, 144, 5866},      /* PaleGreen2 */
+    {124, 205, 124, 5877},      /* PaleGreen3 */
+    {84, 139, 84, 5888},        /* PaleGreen4 */
+    {175, 238, 238, 5899},      /* PaleTurquoise */
+    {187, 255, 255, 5913},      /* PaleTurquoise1 */
+    {174, 238, 238, 5928},      /* PaleTurquoise2 */
+    {150, 205, 205, 5943},      /* PaleTurquoise3 */
+    {102, 139, 139, 5958},      /* PaleTurquoise4 */
+    {219, 112, 147, 5973},      /* PaleVioletRed */
+    {255, 130, 171, 5987},      /* PaleVioletRed1 */
+    {238, 121, 159, 6002},      /* PaleVioletRed2 */
+    {205, 104, 137, 6017},      /* PaleVioletRed3 */
+    {139, 71, 93, 6032},        /* PaleVioletRed4 */
+    {255, 239, 213, 6047},      /* papaya whip */
+    {255, 239, 213, 6059},      /* PapayaWhip */
+    {255, 218, 185, 6070},      /* peach puff */
+    {255, 218, 185, 6081},      /* PeachPuff */
+    {255, 218, 185, 6091},      /* PeachPuff1 */
+    {238, 203, 173, 6102},      /* PeachPuff2 */
+    {205, 175, 149, 6113},      /* PeachPuff3 */
+    {139, 119, 101, 6124},      /* PeachPuff4 */
+    {205, 133, 63, 6135},       /* peru */
+    {255, 192, 203, 6140},      /* pink */
+    {255, 181, 197, 6145},      /* pink1 */
+    {238, 169, 184, 6151},      /* pink2 */
+    {205, 145, 158, 6157},      /* pink3 */
+    {139, 99, 108, 6163},       /* pink4 */
+    {221, 160, 221, 6169},      /* plum */
+    {255, 187, 255, 6174},      /* plum1 */
+    {238, 174, 238, 6180},      /* plum2 */
+    {205, 150, 205, 6186},      /* plum3 */
+    {139, 102, 139, 6192},      /* plum4 */
+    {176, 224, 230, 6198},      /* powder blue */
+    {176, 224, 230, 6210},      /* PowderBlue */
+    {160, 32, 240, 6221},       /* purple */
+    {155, 48, 255, 6228},       /* purple1 */
+    {145, 44, 238, 6236},       /* purple2 */
+    {125, 38, 205, 6244},       /* purple3 */
+    {85, 26, 139, 6252},        /* purple4 */
+    {102, 51, 153, 6260},       /* rebecca purple */
+    {102, 51, 153, 6275},       /* RebeccaPurple */
+    {255, 0, 0, 6289},          /* red */
+    {255, 0, 0, 6293},          /* red1 */
+    {238, 0, 0, 6298},          /* red2 */
+    {205, 0, 0, 6303},          /* red3 */
+    {139, 0, 0, 6308},          /* red4 */
+    {188, 143, 143, 6313},      /* rosy brown */
+    {188, 143, 143, 6324},      /* RosyBrown */
+    {255, 193, 193, 6334},      /* RosyBrown1 */
+    {238, 180, 180, 6345},      /* RosyBrown2 */
+    {205, 155, 155, 6356},      /* RosyBrown3 */
+    {139, 105, 105, 6367},      /* RosyBrown4 */
+    {65, 105, 225, 6378},       /* royal blue */
+    {65, 105, 225, 6389},       /* RoyalBlue */
+    {72, 118, 255, 6399},       /* RoyalBlue1 */
+    {67, 110, 238, 6410},       /* RoyalBlue2 */
+    {58, 95, 205, 6421},        /* RoyalBlue3 */
+    {39, 64, 139, 6432},        /* RoyalBlue4 */
+    {139, 69, 19, 6443},        /* saddle brown */
+    {139, 69, 19, 6456},        /* SaddleBrown */
+    {250, 128, 114, 6468},      /* salmon */
+    {255, 140, 105, 6475},      /* salmon1 */
+    {238, 130, 98, 6483},       /* salmon2 */
+    {205, 112, 84, 6491},       /* salmon3 */
+    {139, 76, 57, 6499},        /* salmon4 */
+    {244, 164, 96, 6507},       /* sandy brown */
+    {244, 164, 96, 6519},       /* SandyBrown */
+    {46, 139, 87, 6530},        /* sea green */
+    {46, 139, 87, 6540},        /* SeaGreen */
+    {84, 255, 159, 6549},       /* SeaGreen1 */
+    {78, 238, 148, 6559},       /* SeaGreen2 */
+    {67, 205, 128, 6569},       /* SeaGreen3 */
+    {46, 139, 87, 6579},        /* SeaGreen4 */
+    {255, 245, 238, 6589},      /* seashell */
+    {255, 245, 238, 6598},      /* seashell1 */
+    {238, 229, 222, 6608},      /* seashell2 */
+    {205, 197, 191, 6618},      /* seashell3 */
+    {139, 134, 130, 6628},      /* seashell4 */
+    {160, 82, 45, 6638},        /* sienna */
+    {255, 130, 71, 6645},       /* sienna1 */
+    {238, 121, 66, 6653},       /* sienna2 */
+    {205, 104, 57, 6661},       /* sienna3 */
+    {139, 71, 38, 6669},        /* sienna4 */
+    {192, 192, 192, 6677},      /* silver */
+    {135, 206, 235, 6684},      /* sky blue */
+    {135, 206, 235, 6693},      /* SkyBlue */
+    {135, 206, 255, 6701},      /* SkyBlue1 */
+    {126, 192, 238, 6710},      /* SkyBlue2 */
+    {108, 166, 205, 6719},      /* SkyBlue3 */
+    {74, 112, 139, 6728},       /* SkyBlue4 */
+    {106, 90, 205, 6737},       /* slate blue */
+    {112, 128, 144, 6748},      /* slate gray */
+    {112, 128, 144, 6759},      /* slate grey */
+    {106, 90, 205, 6770},       /* SlateBlue */
+    {131, 111, 255, 6780},      /* SlateBlue1 */
+    {122, 103, 238, 6791},      /* SlateBlue2 */
+    {105, 89, 205, 6802},       /* SlateBlue3 */
+    {71, 60, 139, 6813},        /* SlateBlue4 */
+    {112, 128, 144, 6824},      /* SlateGray */
+    {198, 226, 255, 6834},      /* SlateGray1 */
+    {185, 211, 238, 6845},      /* SlateGray2 */
+    {159, 182, 205, 6856},      /* SlateGray3 */
+    {108, 123, 139, 6867},      /* SlateGray4 */
+    {112, 128, 144, 6878},      /* SlateGrey */
+    {255, 250, 250, 6888},      /* snow */
+    {255, 250, 250, 6893},      /* snow1 */
+    {238, 233, 233, 6899},      /* snow2 */
+    {205, 201, 201, 6905},      /* snow3 */
+    {139, 137, 137, 6911},      /* snow4 */
+    {0, 255, 127, 6917},        /* spring green */
+    {0, 255, 127, 6930},        /* SpringGreen */
+    {0, 255, 127, 6942},        /* SpringGreen1 */
+    {0, 238, 118, 6955},        /* SpringGreen2 */
+    {0, 205, 102, 6968},        /* SpringGreen3 */
+    {0, 139, 69, 6981},         /* SpringGreen4 */
+    {70, 130, 180, 6994},       /* steel blue */
+    {70, 130, 180, 7005},       /* SteelBlue */
+    {99, 184, 255, 7015},       /* SteelBlue1 */
+    {92, 172, 238, 7026},       /* SteelBlue2 */
+    {79, 148, 205, 7037},       /* SteelBlue3 */
+    {54, 100, 139, 7048},       /* SteelBlue4 */
+    {210, 180, 140, 7059},      /* tan */
+    {255, 165, 79, 7063},       /* tan1 */
+    {238, 154, 73, 7068},       /* tan2 */
+    {205, 133, 63, 7073},       /* tan3 */
+    {139, 90, 43, 7078},        /* tan4 */
+    {0, 128, 128, 7083},        /* teal */
+    {216, 191, 216, 7088},      /* thistle */
+    {255, 225, 255, 7096},      /* thistle1 */
+    {238, 210, 238, 7105},      /* thistle2 */
+    {205, 181, 205, 7114},      /* thistle3 */
+    {139, 123, 139, 7123},      /* thistle4 */
+    {255, 99, 71, 7132},        /* tomato */
+    {255, 99, 71, 7139},        /* tomato1 */
+    {238, 92, 66, 7147},        /* tomato2 */
+    {205, 79, 57, 7155},        /* tomato3 */
+    {139, 54, 38, 7163},        /* tomato4 */
+    {64, 224, 208, 7171},       /* turquoise */
+    {0, 245, 255, 7181},        /* turquoise1 */
+    {0, 229, 238, 7192},        /* turquoise2 */
+    {0, 197, 205, 7203},        /* turquoise3 */
+    {0, 134, 139, 7214},        /* turquoise4 */
+    {238, 130, 238, 7225},      /* violet */
+    {208, 32, 144, 7232},       /* violet red */
+    {208, 32, 144, 7243},       /* VioletRed */
+    {255, 62, 150, 7253},       /* VioletRed1 */
+    {238, 58, 140, 7264},       /* VioletRed2 */
+    {205, 50, 120, 7275},       /* VioletRed3 */
+    {139, 34, 82, 7286},        /* VioletRed4 */
+    {128, 128, 128, 7297},      /* web gray */
+    {0, 128, 0, 7306},          /* web green */
+    {128, 128, 128, 7316},      /* web grey */
+    {128, 0, 0, 7325},          /* web maroon */
+    {128, 0, 128, 7336},        /* web purple */
+    {128, 128, 128, 7347},      /* WebGray */
+    {0, 128, 0, 7355},          /* WebGreen */
+    {128, 128, 128, 7364},      /* WebGrey */
+    {128, 0, 0, 7372},          /* WebMaroon */
+    {128, 0, 128, 7382},        /* WebPurple */
+    {245, 222, 179, 7392},      /* wheat */
+    {255, 231, 186, 7398},      /* wheat1 */
+    {238, 216, 174, 7405},      /* wheat2 */
+    {205, 186, 150, 7412},      /* wheat3 */
+    {139, 126, 102, 7419},      /* wheat4 */
+    {255, 255, 255, 7426},      /* white */
+    {245, 245, 245, 7432},      /* white smoke */
+    {245, 245, 245, 7444},      /* WhiteSmoke */
+    {190, 190, 190, 7455},      /* x11 gray */
+    {0, 255, 0, 7464},          /* x11 green */
+    {190, 190, 190, 7474},      /* x11 grey */
+    {176, 48, 96, 7483},        /* x11 maroon */
+    {160, 32, 240, 7494},       /* x11 purple */
+    {190, 190, 190, 7505},      /* X11Gray */
+    {0, 255, 0, 7513},          /* X11Green */
+    {190, 190, 190, 7522},      /* X11Grey */
+    {176, 48, 96, 7530},        /* X11Maroon */
+    {160, 32, 240, 7540},       /* X11Purple */
+    {255, 255, 0, 7550},        /* yellow */
+    {154, 205, 50, 7557},       /* yellow green */
+    {255, 255, 0, 7570},        /* yellow1 */
+    {238, 238, 0, 7578},        /* yellow2 */
+    {205, 205, 0, 7586},        /* yellow3 */
+    {139, 139, 0, 7594},        /* yellow4 */
+    {154, 205, 50, 7602},       /* YellowGreen */
 };
 
 #define NUM_BUILTIN_COLORS  (sizeof (BuiltinColors) / sizeof (BuiltinColors[0]))
commit ee9f766abf6fbe0cc36234bfe727aba924e9b5fd
Author: Keith Packard <keithp at keithp.com>
Date:   Mon Jul 28 12:09:51 2014 -0700

    xfree86: [v2] Remove duplicate InputInfoPtr typedef from xf86Xinput.h
    
    GCC 4.2 doesn't accept 2 typedef declarations of the same type, so
    remove the extra one from xf86Xinput.h and have xf86Xinput.h #include
    xf86.h to make sure everyone using just that file gets the typedef.
    
    Signed-off-by: Keith Packard <keithp at keithp.com>
    Reviewed-by: Peter Hutterer <peter.hutterer at who-t.net>
    Reviewed-by: Matthieu Herrb <matthieu at herrb.eu>

diff --git a/hw/xfree86/common/xf86Xinput.h b/hw/xfree86/common/xf86Xinput.h
index 9fe8c87..66a64fb 100644
--- a/hw/xfree86/common/xf86Xinput.h
+++ b/hw/xfree86/common/xf86Xinput.h
@@ -51,6 +51,7 @@
 #ifndef _xf86Xinput_h
 #define _xf86Xinput_h
 
+#include "xf86.h"
 #include "xf86str.h"
 #include "inputstr.h"
 #include <X11/extensions/XI.h>
@@ -85,7 +86,7 @@ typedef struct _InputDriverRec {
 
 /* This is to input devices what the ScrnInfoRec is to screens. */
 
-typedef struct _InputInfoRec {
+struct _InputInfoRec {
     struct _InputInfoRec *next;
     char *name;
     char *driver;
@@ -110,7 +111,7 @@ typedef struct _InputInfoRec {
     void *module;
     XF86OptionPtr options;
     InputAttributes *attrs;
-} *InputInfoPtr;
+};
 
 /* xf86Globals.c */
 extern InputInfoPtr xf86InputDevs;
commit ab32ee35890be51137b56525826ffe219b63eb88
Author: Jeremy Huddleston Sequoia <jeremyhu at apple.com>
Date:   Mon Aug 11 13:15:24 2014 -0700

    XQuartz: Better support turning off "Displays have separate Spaces" on OS X Mavericks
    
    http://xquartz.macosforge.org/trac/ticket/1876
    
    Follow-up to: 1c10b37380d228b35db8a8616a6312ac54f5e59b
    
    Signed-off-by: Jeremy Huddleston Sequoia <jeremyhu at apple.com>

diff --git a/hw/xquartz/xpr/xprScreen.c b/hw/xquartz/xpr/xprScreen.c
index 7aa1ae1..d0a525f 100644
--- a/hw/xquartz/xpr/xprScreen.c
+++ b/hw/xquartz/xpr/xprScreen.c
@@ -169,14 +169,25 @@ displayScreenBounds(CGDirectDisplayID id)
               (int)frame.size.width, (int)frame.size.height,
               (int)frame.origin.x, (int)frame.origin.y);
 
-    /* Remove menubar to help standard X11 window managers.
-     * On Mavericks and later, the menu bar is on all displays.
-     */
-    if (XQuartzIsRootless
+    Boolean spacePerDisplay = false;
 #if MAC_OS_X_VERSION_MIN_REQUIRED < 1090
-        && (NSAppKitVersionNumber >= 1265 || (frame.origin.x == 0 && frame.origin.y == 0))
+    if (NSAppKitVersionNumber >= 1265)
 #endif
-        ) {
+    {
+        Boolean ok;
+        (void)CFPreferencesAppSynchronize(CFSTR("com.apple.spaces"));
+        spacePerDisplay = ! CFPreferencesGetAppBooleanValue(CFSTR("spans-displays"),
+                                                            CFSTR("com.apple.spaces"),
+                                                            &ok);
+        if (!ok)
+            spacePerDisplay = true;
+    }
+
+    /* Remove menubar to help standard X11 window managers.
+     * On Mavericks and later, the menu bar is on all displays when spans-displays is false or unset.
+     */
+    if (XQuartzIsRootless &&
+        (spacePerDisplay || (frame.origin.x == 0 && frame.origin.y == 0))) {
         frame.origin.y += aquaMenuBarHeight;
         frame.size.height -= aquaMenuBarHeight;
     }
commit dfbc6a1a78ff3192baae6f7f2af98b6e51422f75
Author: Jeremy Huddleston Sequoia <jeremyhu at apple.com>
Date:   Wed Jul 23 11:53:33 2014 -0700

    ListenOnOpenFD: Remove Resets since this is intended to be for hotplugging connections
    
    pharris says that the resets should not be done in the hotplugging case.
    
    This may fix a crash reported against XQuartz:
    http://xquartz.macosforge.org/trac/ticket/869
    
    Signed-off-by: Jeremy Huddleston Sequoia <jeremyhu at apple.com>
    Reviewed-by: Peter Harris <pharris at opentext.com>

diff --git a/os/connection.c b/os/connection.c
index 40d9ff3..f915e12 100644
--- a/os/connection.c
+++ b/os/connection.c
@@ -1307,13 +1307,6 @@ ListenOnOpenFD(int fd, int noxauth)
 
     /* Increment the count */
     ListenTransCount++;
-
-    /* This *might* not be needed... /shrug */
-    ResetAuthorization();
-    ResetHosts(display);
-#ifdef XDMCP
-    XdmcpReset();
-#endif
 }
 
 /* based on TRANS(SocketUNIXAccept) (XtransConnInfo ciptr, int *status) */
commit 3714f5401690b288045090c4bcd9cb01c6e4860e
Author: Eric Anholt <eric at anholt.net>
Date:   Sun Apr 6 07:57:44 2014 +0100

    kdrive: Remove a dead struct.
    
    It's never been used in the history of the tree.
    
    Signed-off-by: Eric Anholt <eric at anholt.net>
    Reviewed-by: Keith Packard <keithp at keithp.com>

diff --git a/hw/kdrive/src/kxv.h b/hw/kdrive/src/kxv.h
index 4eb4054..b997299 100644
--- a/hw/kdrive/src/kxv.h
+++ b/hw/kdrive/src/kxv.h
@@ -54,15 +54,6 @@ of the copyright holder.
 #define VIDEO_OVERLAID_STILLS			0x00000008
 #define VIDEO_CLIP_TO_VIEWPORT			0x00000010
 
-typedef struct {
-    KdScreenInfo *screen;
-    int id;
-    unsigned short width, height;
-    int *pitches;               /* bytes */
-    int *offsets;               /* in bytes from start of framebuffer */
-    DevUnion devPrivate;
-} KdSurfaceRec, *KdSurfacePtr;
-
 typedef int (*PutVideoFuncPtr) (KdScreenInfo * screen, DrawablePtr pDraw,
                                 short vid_x, short vid_y, short drw_x,
                                 short drw_y, short vid_w, short vid_h,
commit ef258fa4fd0c215b1327fb3d94b37e75af9fae6b
Author: Eric Anholt <eric at anholt.net>
Date:   Wed Jul 30 21:11:51 2014 -0700

    xv: Drop the ClientPtr from the interface to the DDX.
    
    Nobody was using it.
    
    v2: Merge the hunk that was accidentally in the previous commit into
        this one.
    
    Signed-off-by: Eric Anholt <eric at anholt.net>
    Reviewed-by: Keith Packard <keithp at keithp.com>

diff --git a/Xext/xvdisp.c b/Xext/xvdisp.c
index 58c7203..0bdfed3 100644
--- a/Xext/xvdisp.c
+++ b/Xext/xvdisp.c
@@ -746,7 +746,7 @@ ProcXvQueryBestSize(ClientPtr client)
 
     VALIDATE_XV_PORT(stuff->port, pPort, DixReadAccess);
 
-    (*pPort->pAdaptor->ddQueryBestSize) (client, pPort, stuff->motion,
+    (*pPort->pAdaptor->ddQueryBestSize) (pPort, stuff->motion,
                                          stuff->vid_w, stuff->vid_h,
                                          stuff->drw_w, stuff->drw_h,
                                          &actual_width, &actual_height);
@@ -851,8 +851,7 @@ ProcXvPutImage(ClientPtr client)
 
     width = stuff->width;
     height = stuff->height;
-    size = (*pPort->pAdaptor->ddQueryImageAttributes) (client,
-                                                       pPort, pImage, &width,
+    size = (*pPort->pAdaptor->ddQueryImageAttributes) (pPort, pImage, &width,
                                                        &height, NULL, NULL);
     size += sizeof(xvPutImageReq);
     size = bytes_to_int32(size);
@@ -917,8 +916,7 @@ ProcXvShmPutImage(ClientPtr client)
 
     width = stuff->width;
     height = stuff->height;
-    size_needed = (*pPort->pAdaptor->ddQueryImageAttributes) (client,
-                                                              pPort, pImage,
+    size_needed = (*pPort->pAdaptor->ddQueryImageAttributes) (pPort, pImage,
                                                               &width, &height,
                                                               NULL, NULL);
     if ((size_needed + stuff->offset) > shmdesc->size)
@@ -1002,7 +1000,7 @@ ProcXvQueryImageAttributes(ClientPtr client)
     width = stuff->width;
     height = stuff->height;
 
-    size = (*pPort->pAdaptor->ddQueryImageAttributes) (client, pPort, pImage,
+    size = (*pPort->pAdaptor->ddQueryImageAttributes) (pPort, pImage,
                                                        &width, &height, offsets,
                                                        pitches);
 
diff --git a/Xext/xvdix.h b/Xext/xvdix.h
index 9bbfcde..e67a3c7 100644
--- a/Xext/xvdix.h
+++ b/Xext/xvdix.h
@@ -157,29 +157,29 @@ typedef struct {
     int nPorts;
     struct _XvPortRec *pPorts;
     ScreenPtr pScreen;
-    int (*ddPutVideo) (ClientPtr, DrawablePtr, struct _XvPortRec *, GCPtr,
+    int (*ddPutVideo) (DrawablePtr, struct _XvPortRec *, GCPtr,
                        INT16, INT16, CARD16, CARD16,
                        INT16, INT16, CARD16, CARD16);
-    int (*ddPutStill) (ClientPtr, DrawablePtr, struct _XvPortRec *, GCPtr,
+    int (*ddPutStill) (DrawablePtr, struct _XvPortRec *, GCPtr,
                        INT16, INT16, CARD16, CARD16,
                        INT16, INT16, CARD16, CARD16);
-    int (*ddGetVideo) (ClientPtr, DrawablePtr, struct _XvPortRec *, GCPtr,
+    int (*ddGetVideo) (DrawablePtr, struct _XvPortRec *, GCPtr,
                        INT16, INT16, CARD16, CARD16,
                        INT16, INT16, CARD16, CARD16);
-    int (*ddGetStill) (ClientPtr, DrawablePtr, struct _XvPortRec *, GCPtr,
+    int (*ddGetStill) (DrawablePtr, struct _XvPortRec *, GCPtr,
                        INT16, INT16, CARD16, CARD16,
                        INT16, INT16, CARD16, CARD16);
-    int (*ddStopVideo) (ClientPtr, struct _XvPortRec *, DrawablePtr);
-    int (*ddSetPortAttribute) (ClientPtr, struct _XvPortRec *, Atom, INT32);
-    int (*ddGetPortAttribute) (ClientPtr, struct _XvPortRec *, Atom, INT32 *);
-    int (*ddQueryBestSize) (ClientPtr, struct _XvPortRec *, CARD8,
+    int (*ddStopVideo) (struct _XvPortRec *, DrawablePtr);
+    int (*ddSetPortAttribute) (struct _XvPortRec *, Atom, INT32);
+    int (*ddGetPortAttribute) (struct _XvPortRec *, Atom, INT32 *);
+    int (*ddQueryBestSize) (struct _XvPortRec *, CARD8,
                             CARD16, CARD16, CARD16, CARD16,
                             unsigned int *, unsigned int *);
-    int (*ddPutImage) (ClientPtr, DrawablePtr, struct _XvPortRec *, GCPtr,
+    int (*ddPutImage) (DrawablePtr, struct _XvPortRec *, GCPtr,
                        INT16, INT16, CARD16, CARD16,
                        INT16, INT16, CARD16, CARD16,
                        XvImagePtr, unsigned char *, Bool, CARD16, CARD16);
-    int (*ddQueryImageAttributes) (ClientPtr, struct _XvPortRec *, XvImagePtr,
+    int (*ddQueryImageAttributes) (struct _XvPortRec *, XvImagePtr,
                                    CARD16 *, CARD16 *, int *, int *);
     DevUnion devPriv;
 } XvAdaptorRec, *XvAdaptorPtr;
diff --git a/Xext/xvmain.c b/Xext/xvmain.c
index b8294fe..bc176c8 100644
--- a/Xext/xvmain.c
+++ b/Xext/xvmain.c
@@ -356,7 +356,7 @@ XvDestroyPixmap(PixmapPtr pPix)
             if (pp->pDraw == (DrawablePtr) pPix) {
                 XvdiSendVideoNotify(pp, pp->pDraw, XvPreempted);
 
-                (void) (*pp->pAdaptor->ddStopVideo) (NULL, pp, pp->pDraw);
+                (void) (*pp->pAdaptor->ddStopVideo) (pp, pp->pDraw);
 
                 pp->pDraw = NULL;
                 pp->client = NULL;
@@ -404,7 +404,7 @@ XvDestroyWindow(WindowPtr pWin)
             if (pp->pDraw == (DrawablePtr) pWin) {
                 XvdiSendVideoNotify(pp, pp->pDraw, XvPreempted);
 
-                (void) (*pp->pAdaptor->ddStopVideo) (NULL, pp, pp->pDraw);
+                (void) (*pp->pAdaptor->ddStopVideo) (pp, pp->pDraw);
 
                 pp->pDraw = NULL;
                 pp->client = NULL;
@@ -566,7 +566,7 @@ XvdiPutVideo(ClientPtr client,
         XvdiSendVideoNotify(pPort, pPort->pDraw, XvPreempted);
     }
 
-    (void) (*pPort->pAdaptor->ddPutVideo) (client, pDraw, pPort, pGC,
+    (void) (*pPort->pAdaptor->ddPutVideo) (pDraw, pPort, pGC,
                                            vid_x, vid_y, vid_w, vid_h,
                                            drw_x, drw_y, drw_w, drw_h);
 
@@ -608,7 +608,7 @@ XvdiPutStill(ClientPtr client,
 
     pPort->time = currentTime;
 
-    status = (*pPort->pAdaptor->ddPutStill) (client, pDraw, pPort, pGC,
+    status = (*pPort->pAdaptor->ddPutStill) (pDraw, pPort, pGC,
                                              vid_x, vid_y, vid_w, vid_h,
                                              drw_x, drw_y, drw_w, drw_h);
 
@@ -644,7 +644,7 @@ XvdiPutImage(ClientPtr client,
 
     pPort->time = currentTime;
 
-    return (*pPort->pAdaptor->ddPutImage) (client, pDraw, pPort, pGC,
+    return (*pPort->pAdaptor->ddPutImage) (pDraw, pPort, pGC,
                                            src_x, src_y, src_w, src_h,
                                            drw_x, drw_y, drw_w, drw_h,
                                            image, data, sync, width, height);
@@ -683,7 +683,7 @@ XvdiGetVideo(ClientPtr client,
         XvdiSendVideoNotify(pPort, pPort->pDraw, XvPreempted);
     }
 
-    (void) (*pPort->pAdaptor->ddGetVideo) (client, pDraw, pPort, pGC,
+    (void) (*pPort->pAdaptor->ddGetVideo) (pDraw, pPort, pGC,
                                            vid_x, vid_y, vid_w, vid_h,
                                            drw_x, drw_y, drw_w, drw_h);
 
@@ -723,7 +723,7 @@ XvdiGetStill(ClientPtr client,
         return Success;
     }
 
-    status = (*pPort->pAdaptor->ddGetStill) (client, pDraw, pPort, pGC,
+    status = (*pPort->pAdaptor->ddGetStill) (pDraw, pPort, pGC,
                                              vid_x, vid_y, vid_w, vid_h,
                                              drw_x, drw_y, drw_w, drw_h);
 
@@ -955,7 +955,7 @@ XvdiStopVideo(ClientPtr client, XvPortPtr pPort, DrawablePtr pDraw)
 
     XvdiSendVideoNotify(pPort, pDraw, XvStopped);
 
-    status = (*pPort->pAdaptor->ddStopVideo) (client, pPort, pDraw);
+    status = (*pPort->pAdaptor->ddStopVideo) (pPort, pDraw);
 
     pPort->pDraw = NULL;
     pPort->client = (ClientPtr) client;
@@ -998,7 +998,7 @@ XvdiSetPortAttribute(ClientPtr client,
     int status;
 
     status =
-        (*pPort->pAdaptor->ddSetPortAttribute) (client, pPort, attribute,
+        (*pPort->pAdaptor->ddSetPortAttribute) (pPort, attribute,
                                                 value);
     if (status == Success)
         XvdiSendPortNotify(pPort, attribute, value);
@@ -1012,7 +1012,7 @@ XvdiGetPortAttribute(ClientPtr client,
 {
 
     return
-        (*pPort->pAdaptor->ddGetPortAttribute) (client, pPort, attribute,
+        (*pPort->pAdaptor->ddGetPortAttribute) (pPort, attribute,
                                                 p_value);
 
 }
diff --git a/hw/kdrive/src/kxv.c b/hw/kdrive/src/kxv.c
index f9c18d6..f979e1f 100644
--- a/hw/kdrive/src/kxv.c
+++ b/hw/kdrive/src/kxv.c
@@ -58,29 +58,29 @@ of the copyright holder.
 
 /* XvAdaptorRec fields */
 
-static int KdXVPutVideo(ClientPtr, DrawablePtr, XvPortPtr, GCPtr,
+static int KdXVPutVideo(DrawablePtr, XvPortPtr, GCPtr,
                         INT16, INT16, CARD16, CARD16,
                         INT16, INT16, CARD16, CARD16);
-static int KdXVPutStill(ClientPtr, DrawablePtr, XvPortPtr, GCPtr,
+static int KdXVPutStill(DrawablePtr, XvPortPtr, GCPtr,
                         INT16, INT16, CARD16, CARD16,
                         INT16, INT16, CARD16, CARD16);
-static int KdXVGetVideo(ClientPtr, DrawablePtr, XvPortPtr, GCPtr,
+static int KdXVGetVideo(DrawablePtr, XvPortPtr, GCPtr,
                         INT16, INT16, CARD16, CARD16,
                         INT16, INT16, CARD16, CARD16);
-static int KdXVGetStill(ClientPtr, DrawablePtr, XvPortPtr, GCPtr,
+static int KdXVGetStill(DrawablePtr, XvPortPtr, GCPtr,
                         INT16, INT16, CARD16, CARD16,
                         INT16, INT16, CARD16, CARD16);
-static int KdXVStopVideo(ClientPtr, XvPortPtr, DrawablePtr);
-static int KdXVSetPortAttribute(ClientPtr, XvPortPtr, Atom, INT32);
-static int KdXVGetPortAttribute(ClientPtr, XvPortPtr, Atom, INT32 *);
-static int KdXVQueryBestSize(ClientPtr, XvPortPtr, CARD8,
+static int KdXVStopVideo(XvPortPtr, DrawablePtr);
+static int KdXVSetPortAttribute(XvPortPtr, Atom, INT32);
+static int KdXVGetPortAttribute(XvPortPtr, Atom, INT32 *);
+static int KdXVQueryBestSize(XvPortPtr, CARD8,
                              CARD16, CARD16, CARD16, CARD16,
                              unsigned int *, unsigned int *);
-static int KdXVPutImage(ClientPtr, DrawablePtr, XvPortPtr, GCPtr,
+static int KdXVPutImage(DrawablePtr, XvPortPtr, GCPtr,
                         INT16, INT16, CARD16, CARD16,
                         INT16, INT16, CARD16, CARD16,
                         XvImagePtr, unsigned char *, Bool, CARD16, CARD16);
-static int KdXVQueryImageAttributes(ClientPtr, XvPortPtr, XvImagePtr,
+static int KdXVQueryImageAttributes(XvPortPtr, XvImagePtr,
                                     CARD16 *, CARD16 *, int *, int *);
 
 /* ScreenRec fields */
@@ -1028,8 +1028,7 @@ KdXVDisable(ScreenPtr pScreen)
 /**** XvAdaptorRec fields ****/
 
 static int
-KdXVPutVideo(ClientPtr client,
-             DrawablePtr pDraw,
+KdXVPutVideo(DrawablePtr pDraw,
              XvPortPtr pPort,
              GCPtr pGC,
              INT16 vid_x, INT16 vid_y,
@@ -1082,8 +1081,7 @@ KdXVPutVideo(ClientPtr client,
 }
 
 static int
-KdXVPutStill(ClientPtr client,
-             DrawablePtr pDraw,
+KdXVPutStill(DrawablePtr pDraw,
              XvPortPtr pPort,
              GCPtr pGC,
              INT16 vid_x, INT16 vid_y,
@@ -1175,8 +1173,7 @@ KdXVPutStill(ClientPtr client,
 }
 
 static int
-KdXVGetVideo(ClientPtr client,
-             DrawablePtr pDraw,
+KdXVGetVideo(DrawablePtr pDraw,
              XvPortPtr pPort,
              GCPtr pGC,
              INT16 vid_x, INT16 vid_y,
@@ -1229,8 +1226,7 @@ KdXVGetVideo(ClientPtr client,
 }
 
 static int
-KdXVGetStill(ClientPtr client,
-             DrawablePtr pDraw,
+KdXVGetStill(DrawablePtr pDraw,
              XvPortPtr pPort,
              GCPtr pGC,
              INT16 vid_x, INT16 vid_y,
@@ -1292,7 +1288,7 @@ KdXVGetStill(ClientPtr client,
 }
 
 static int
-KdXVStopVideo(ClientPtr client, XvPortPtr pPort, DrawablePtr pDraw)
+KdXVStopVideo(XvPortPtr pPort, DrawablePtr pDraw)
 {
     XvPortRecPrivatePtr portPriv = (XvPortRecPrivatePtr) (pPort->devPriv.ptr);
 
@@ -1318,8 +1314,7 @@ KdXVStopVideo(ClientPtr client, XvPortPtr pPort, DrawablePtr pDraw)
 }
 
 static int
-KdXVSetPortAttribute(ClientPtr client,
-                     XvPortPtr pPort, Atom attribute, INT32 value)
+KdXVSetPortAttribute(XvPortPtr pPort, Atom attribute, INT32 value)
 {
     XvPortRecPrivatePtr portPriv = (XvPortRecPrivatePtr) (pPort->devPriv.ptr);
 
@@ -1329,8 +1324,7 @@ KdXVSetPortAttribute(ClientPtr client,
 }
 
 static int
-KdXVGetPortAttribute(ClientPtr client,
-                     XvPortPtr pPort, Atom attribute, INT32 *p_value)
+KdXVGetPortAttribute(XvPortPtr pPort, Atom attribute, INT32 *p_value)
 {
     XvPortRecPrivatePtr portPriv = (XvPortRecPrivatePtr) (pPort->devPriv.ptr);
 
@@ -1341,8 +1335,7 @@ KdXVGetPortAttribute(ClientPtr client,
 }
 
 static int
-KdXVQueryBestSize(ClientPtr client,
-                  XvPortPtr pPort,
+KdXVQueryBestSize(XvPortPtr pPort,
                   CARD8 motion,
                   CARD16 vid_w, CARD16 vid_h,
                   CARD16 drw_w, CARD16 drw_h,
@@ -1359,8 +1352,7 @@ KdXVQueryBestSize(ClientPtr client,
 }
 
 static int
-KdXVPutImage(ClientPtr client,
-             DrawablePtr pDraw,
+KdXVPutImage(DrawablePtr pDraw,
              XvPortPtr pPort,
              GCPtr pGC,
              INT16 src_x, INT16 src_y,
@@ -1455,8 +1447,7 @@ KdXVPutImage(ClientPtr client,
 }
 
 static int
-KdXVQueryImageAttributes(ClientPtr client,
-                         XvPortPtr pPort,
+KdXVQueryImageAttributes(XvPortPtr pPort,
                          XvImagePtr format,
                          CARD16 *width,
                          CARD16 *height, int *pitches, int *offsets)
diff --git a/hw/xfree86/common/xf86xv.c b/hw/xfree86/common/xf86xv.c
index 141a4ed..d342bde 100644
--- a/hw/xfree86/common/xf86xv.c
+++ b/hw/xfree86/common/xf86xv.c
@@ -56,29 +56,29 @@
 
 /* XvAdaptorRec fields */
 
-static int xf86XVPutVideo(ClientPtr, DrawablePtr, XvPortPtr, GCPtr,
+static int xf86XVPutVideo(DrawablePtr, XvPortPtr, GCPtr,
                           INT16, INT16, CARD16, CARD16,
                           INT16, INT16, CARD16, CARD16);
-static int xf86XVPutStill(ClientPtr, DrawablePtr, XvPortPtr, GCPtr,
+static int xf86XVPutStill(DrawablePtr, XvPortPtr, GCPtr,
                           INT16, INT16, CARD16, CARD16,
                           INT16, INT16, CARD16, CARD16);
-static int xf86XVGetVideo(ClientPtr, DrawablePtr, XvPortPtr, GCPtr,
+static int xf86XVGetVideo(DrawablePtr, XvPortPtr, GCPtr,
                           INT16, INT16, CARD16, CARD16,
                           INT16, INT16, CARD16, CARD16);
-static int xf86XVGetStill(ClientPtr, DrawablePtr, XvPortPtr, GCPtr,
+static int xf86XVGetStill(DrawablePtr, XvPortPtr, GCPtr,
                           INT16, INT16, CARD16, CARD16,
                           INT16, INT16, CARD16, CARD16);
-static int xf86XVStopVideo(ClientPtr, XvPortPtr, DrawablePtr);
-static int xf86XVSetPortAttribute(ClientPtr, XvPortPtr, Atom, INT32);
-static int xf86XVGetPortAttribute(ClientPtr, XvPortPtr, Atom, INT32 *);
-static int xf86XVQueryBestSize(ClientPtr, XvPortPtr, CARD8,
+static int xf86XVStopVideo(XvPortPtr, DrawablePtr);
+static int xf86XVSetPortAttribute(XvPortPtr, Atom, INT32);
+static int xf86XVGetPortAttribute(XvPortPtr, Atom, INT32 *);
+static int xf86XVQueryBestSize(XvPortPtr, CARD8,
                                CARD16, CARD16, CARD16, CARD16,
                                unsigned int *, unsigned int *);
-static int xf86XVPutImage(ClientPtr, DrawablePtr, XvPortPtr, GCPtr,
+static int xf86XVPutImage(DrawablePtr, XvPortPtr, GCPtr,
                           INT16, INT16, CARD16, CARD16,
                           INT16, INT16, CARD16, CARD16,
                           XvImagePtr, unsigned char *, Bool, CARD16, CARD16);
-static int xf86XVQueryImageAttributes(ClientPtr, XvPortPtr, XvImagePtr,
+static int xf86XVQueryImageAttributes(XvPortPtr, XvImagePtr,
                                       CARD16 *, CARD16 *, int *, int *);
 
 /* ScreenRec fields */
@@ -1271,8 +1271,7 @@ xf86XVModeSet(ScrnInfoPtr pScrn)
 /**** XvAdaptorRec fields ****/
 
 static int
-xf86XVPutVideo(ClientPtr client,
-               DrawablePtr pDraw,
+xf86XVPutVideo(DrawablePtr pDraw,
                XvPortPtr pPort,
                GCPtr pGC,
                INT16 vid_x, INT16 vid_y,
@@ -1322,8 +1321,7 @@ xf86XVPutVideo(ClientPtr client,
 }
 
 static int
-xf86XVPutStill(ClientPtr client,
-               DrawablePtr pDraw,
+xf86XVPutStill(DrawablePtr pDraw,
                XvPortPtr pPort,
                GCPtr pGC,
                INT16 vid_x, INT16 vid_y,
@@ -1420,8 +1418,7 @@ xf86XVPutStill(ClientPtr client,
 }
 
 static int
-xf86XVGetVideo(ClientPtr client,
-               DrawablePtr pDraw,
+xf86XVGetVideo(DrawablePtr pDraw,
                XvPortPtr pPort,
                GCPtr pGC,
                INT16 vid_x, INT16 vid_y,
@@ -1471,8 +1468,7 @@ xf86XVGetVideo(ClientPtr client,
 }
 
 static int
-xf86XVGetStill(ClientPtr client,
-               DrawablePtr pDraw,
+xf86XVGetStill(DrawablePtr pDraw,
                XvPortPtr pPort,
                GCPtr pGC,
                INT16 vid_x, INT16 vid_y,
@@ -1531,7 +1527,7 @@ xf86XVGetStill(ClientPtr client,
 }
 
 static int
-xf86XVStopVideo(ClientPtr client, XvPortPtr pPort, DrawablePtr pDraw)
+xf86XVStopVideo(XvPortPtr pPort, DrawablePtr pDraw)
 {
     XvPortRecPrivatePtr portPriv = (XvPortRecPrivatePtr) (pPort->devPriv.ptr);
 
@@ -1555,8 +1551,7 @@ xf86XVStopVideo(ClientPtr client, XvPortPtr pPort, DrawablePtr pDraw)
 }
 
 static int
-xf86XVSetPortAttribute(ClientPtr client,
-                       XvPortPtr pPort, Atom attribute, INT32 value)
+xf86XVSetPortAttribute(XvPortPtr pPort, Atom attribute, INT32 value)
 {
     XvPortRecPrivatePtr portPriv = (XvPortRecPrivatePtr) (pPort->devPriv.ptr);
 
@@ -1566,8 +1561,7 @@ xf86XVSetPortAttribute(ClientPtr client,
 }
 
 static int
-xf86XVGetPortAttribute(ClientPtr client,
-                       XvPortPtr pPort, Atom attribute, INT32 *p_value)
+xf86XVGetPortAttribute(XvPortPtr pPort, Atom attribute, INT32 *p_value)
 {
     XvPortRecPrivatePtr portPriv = (XvPortRecPrivatePtr) (pPort->devPriv.ptr);
 
@@ -1577,8 +1571,7 @@ xf86XVGetPortAttribute(ClientPtr client,
 }
 
 static int
-xf86XVQueryBestSize(ClientPtr client,
-                    XvPortPtr pPort,
+xf86XVQueryBestSize(XvPortPtr pPort,
                     CARD8 motion,
                     CARD16 vid_w, CARD16 vid_h,
                     CARD16 drw_w, CARD16 drw_h,
@@ -1595,8 +1588,7 @@ xf86XVQueryBestSize(ClientPtr client,
 }
 
 static int
-xf86XVPutImage(ClientPtr client,
-               DrawablePtr pDraw,
+xf86XVPutImage(DrawablePtr pDraw,
                XvPortPtr pPort,
                GCPtr pGC,
                INT16 src_x, INT16 src_y,
@@ -1701,8 +1693,7 @@ xf86XVPutImage(ClientPtr client,
 }
 
 static int
-xf86XVQueryImageAttributes(ClientPtr client,
-                           XvPortPtr pPort,
+xf86XVQueryImageAttributes(XvPortPtr pPort,
                            XvImagePtr format,
                            CARD16 *width,
                            CARD16 *height, int *pitches, int *offsets)
commit 850b268e2b9e49445a22e041a356d8ff26ae2147
Author: Eric Anholt <eric at anholt.net>
Date:   Sat Apr 5 10:55:45 2014 +0100

    xv: Remove the no-op AllocatePort/FreePort interfaces.
    
    v2: Fix accidentally squashed-in change for dropping client from the
        arguments, which should have been in the next commit.
    
    Signed-off-by: Eric Anholt <eric at anholt.net>
    Reviewed-by: Keith Packard <keithp at keithp.com> (v2)

diff --git a/Xext/xvdisp.c b/Xext/xvdisp.c
index 71192b3..58c7203 100644
--- a/Xext/xvdisp.c
+++ b/Xext/xvdisp.c
@@ -297,9 +297,6 @@ SWriteListImageFormatsReply(ClientPtr client, xvListImageFormatsReply * rep)
   if ((_c)->swapped) SWriteImageFormatInfo(_c, _d); \
   else WriteToClient(_c, sz_xvImageFormatInfo, _d)
 
-#define _AllocatePort(_i,_p) \
-  ((_p)->id != _i) ? (* (_p)->pAdaptor->ddAllocatePort)(_i,_p,&_p) : Success
-
 static int
 ProcXvQueryExtension(ClientPtr client)
 {
@@ -420,18 +417,12 @@ ProcXvQueryEncodings(ClientPtr client)
     XvPortPtr pPort;
     int ne;
     XvEncodingPtr pe;
-    int status;
 
     REQUEST(xvQueryEncodingsReq);
     REQUEST_SIZE_MATCH(xvQueryEncodingsReq);
 
     VALIDATE_XV_PORT(stuff->port, pPort, DixReadAccess);
 
-    if ((status = _AllocatePort(stuff->port, pPort)) != Success) {
-        client->errorValue = stuff->port;
-        return status;
-    }
-
     rep = (xvQueryEncodingsReply) {
         .type = X_Reply,
         .sequenceNumber = client->sequence,
@@ -483,11 +474,6 @@ ProcXvPutVideo(ClientPtr client)
     VALIDATE_DRAWABLE_AND_GC(stuff->drawable, pDraw, DixWriteAccess);
     VALIDATE_XV_PORT(stuff->port, pPort, DixReadAccess);
 
-    if ((status = _AllocatePort(stuff->port, pPort)) != Success) {
-        client->errorValue = stuff->port;
-        return status;
-    }
-
     if (!(pPort->pAdaptor->type & XvInputMask) ||
         !(pPort->pAdaptor->type & XvVideoMask)) {
         client->errorValue = stuff->port;
@@ -518,11 +504,6 @@ ProcXvPutStill(ClientPtr client)
     VALIDATE_DRAWABLE_AND_GC(stuff->drawable, pDraw, DixWriteAccess);
     VALIDATE_XV_PORT(stuff->port, pPort, DixReadAccess);
 
-    if ((status = _AllocatePort(stuff->port, pPort)) != Success) {
-        client->errorValue = stuff->port;
-        return status;
-    }
-
     if (!(pPort->pAdaptor->type & XvInputMask) ||
         !(pPort->pAdaptor->type & XvStillMask)) {
         client->errorValue = stuff->port;
@@ -553,11 +534,6 @@ ProcXvGetVideo(ClientPtr client)
     VALIDATE_DRAWABLE_AND_GC(stuff->drawable, pDraw, DixReadAccess);
     VALIDATE_XV_PORT(stuff->port, pPort, DixReadAccess);
 
-    if ((status = _AllocatePort(stuff->port, pPort)) != Success) {
-        client->errorValue = stuff->port;
-        return status;
-    }
-
     if (!(pPort->pAdaptor->type & XvOutputMask) ||
         !(pPort->pAdaptor->type & XvVideoMask)) {
         client->errorValue = stuff->port;
@@ -588,11 +564,6 @@ ProcXvGetStill(ClientPtr client)
     VALIDATE_DRAWABLE_AND_GC(stuff->drawable, pDraw, DixReadAccess);
     VALIDATE_XV_PORT(stuff->port, pPort, DixReadAccess);
 
-    if ((status = _AllocatePort(stuff->port, pPort)) != Success) {
-        client->errorValue = stuff->port;
-        return status;
-    }
-
     if (!(pPort->pAdaptor->type & XvOutputMask) ||
         !(pPort->pAdaptor->type & XvStillMask)) {
         client->errorValue = stuff->port;
@@ -629,7 +600,6 @@ ProcXvSelectVideoNotify(ClientPtr client)
 static int
 ProcXvSelectPortNotify(ClientPtr client)
 {
-    int status;
     XvPortPtr pPort;
 
     REQUEST(xvSelectPortNotifyReq);
@@ -637,11 +607,6 @@ ProcXvSelectPortNotify(ClientPtr client)
 
     VALIDATE_XV_PORT(stuff->port, pPort, DixReadAccess);
 
-    if ((status = _AllocatePort(stuff->port, pPort)) != Success) {
-        client->errorValue = stuff->port;
-        return status;
-    }
-
     return XvdiSelectPortNotify(client, pPort, stuff->onoff);
 }
 
@@ -657,11 +622,6 @@ ProcXvGrabPort(ClientPtr client)
 
     VALIDATE_XV_PORT(stuff->port, pPort, DixReadAccess);
 
-    if ((status = _AllocatePort(stuff->port, pPort)) != Success) {
-        client->errorValue = stuff->port;
-        return status;
-    }
-
     status = XvdiGrabPort(client, pPort, stuff->time, &result);
 
     if (status != Success) {
@@ -682,7 +642,6 @@ ProcXvGrabPort(ClientPtr client)
 static int
 ProcXvUngrabPort(ClientPtr client)
 {
-    int status;
     XvPortPtr pPort;
 
     REQUEST(xvGrabPortReq);
@@ -690,18 +649,13 @@ ProcXvUngrabPort(ClientPtr client)
 
     VALIDATE_XV_PORT(stuff->port, pPort, DixReadAccess);
 
-    if ((status = _AllocatePort(stuff->port, pPort)) != Success) {
-        client->errorValue = stuff->port;
-        return status;
-    }
-
     return XvdiUngrabPort(client, pPort, stuff->time);
 }
 
 static int
 ProcXvStopVideo(ClientPtr client)
 {
-    int status, ret;
+    int ret;
     DrawablePtr pDraw;
     XvPortPtr pPort;
 
@@ -710,11 +664,6 @@ ProcXvStopVideo(ClientPtr client)
 
     VALIDATE_XV_PORT(stuff->port, pPort, DixReadAccess);
 
-    if ((status = _AllocatePort(stuff->port, pPort)) != Success) {
-        client->errorValue = stuff->port;
-        return status;
-    }
-
     ret = dixLookupDrawable(&pDraw, stuff->drawable, client, 0, DixWriteAccess);
     if (ret != Success)
         return ret;
@@ -733,11 +682,6 @@ ProcXvSetPortAttribute(ClientPtr client)
 
     VALIDATE_XV_PORT(stuff->port, pPort, DixSetAttrAccess);
 
-    if ((status = _AllocatePort(stuff->port, pPort)) != Success) {
-        client->errorValue = stuff->port;
-        return status;
-    }
-
     if (!ValidAtom(stuff->attribute)) {
         client->errorValue = stuff->attribute;
         return BadAtom;
@@ -767,11 +711,6 @@ ProcXvGetPortAttribute(ClientPtr client)
 
     VALIDATE_XV_PORT(stuff->port, pPort, DixGetAttrAccess);
 
-    if ((status = _AllocatePort(stuff->port, pPort)) != Success) {
-        client->errorValue = stuff->port;
-        return status;
-    }
-
     if (!ValidAtom(stuff->attribute)) {
         client->errorValue = stuff->attribute;
         return BadAtom;
@@ -798,7 +737,6 @@ ProcXvGetPortAttribute(ClientPtr client)
 static int
 ProcXvQueryBestSize(ClientPtr client)
 {
-    int status;
     unsigned int actual_width, actual_height;
     XvPortPtr pPort;
     xvQueryBestSizeReply rep;
@@ -808,11 +746,6 @@ ProcXvQueryBestSize(ClientPtr client)
 
     VALIDATE_XV_PORT(stuff->port, pPort, DixReadAccess);
 
-    if ((status = _AllocatePort(stuff->port, pPort)) != Success) {
-        client->errorValue = stuff->port;
-        return status;
-    }
-
     (*pPort->pAdaptor->ddQueryBestSize) (client, pPort, stuff->motion,
                                          stuff->vid_w, stuff->vid_h,
                                          stuff->drw_w, stuff->drw_h,
@@ -834,7 +767,7 @@ ProcXvQueryBestSize(ClientPtr client)
 static int
 ProcXvQueryPortAttributes(ClientPtr client)
 {
-    int status, size, i;
+    int size, i;
     XvPortPtr pPort;
     XvAttributePtr pAtt;
     xvQueryPortAttributesReply rep;
@@ -845,11 +778,6 @@ ProcXvQueryPortAttributes(ClientPtr client)
 
     VALIDATE_XV_PORT(stuff->port, pPort, DixGetAttrAccess);
 
-    if ((status = _AllocatePort(stuff->port, pPort)) != Success) {
-        client->errorValue = stuff->port;
-        return status;
-    }
-
     rep = (xvQueryPortAttributesReply) {
         .type = X_Reply,
         .sequenceNumber = client->sequence,
@@ -900,11 +828,6 @@ ProcXvPutImage(ClientPtr client)
     VALIDATE_DRAWABLE_AND_GC(stuff->drawable, pDraw, DixWriteAccess);
     VALIDATE_XV_PORT(stuff->port, pPort, DixReadAccess);
 
-    if ((status = _AllocatePort(stuff->port, pPort)) != Success) {
-        client->errorValue = stuff->port;
-        return status;
-    }
-
     if (!(pPort->pAdaptor->type & XvImageMask) ||
         !(pPort->pAdaptor->type & XvInputMask)) {
         client->errorValue = stuff->port;
@@ -966,11 +889,6 @@ ProcXvShmPutImage(ClientPtr client)
     VALIDATE_DRAWABLE_AND_GC(stuff->drawable, pDraw, DixWriteAccess);
     VALIDATE_XV_PORT(stuff->port, pPort, DixReadAccess);
 
-    if ((status = _AllocatePort(stuff->port, pPort)) != Success) {
-        client->errorValue = stuff->port;
-        return status;
-    }
-
     if (!(pPort->pAdaptor->type & XvImageMask) ||
         !(pPort->pAdaptor->type & XvInputMask)) {
         client->errorValue = stuff->port;
diff --git a/Xext/xvdix.h b/Xext/xvdix.h
index 828f67c..9bbfcde 100644
--- a/Xext/xvdix.h
+++ b/Xext/xvdix.h
@@ -157,9 +157,6 @@ typedef struct {
     int nPorts;
     struct _XvPortRec *pPorts;
     ScreenPtr pScreen;
-    int (*ddAllocatePort) (unsigned long, struct _XvPortRec *,
-                           struct _XvPortRec **);
-    int (*ddFreePort) (struct _XvPortRec *);
     int (*ddPutVideo) (ClientPtr, DrawablePtr, struct _XvPortRec *, GCPtr,
                        INT16, INT16, CARD16, CARD16,
                        INT16, INT16, CARD16, CARD16);
diff --git a/Xext/xvmain.c b/Xext/xvmain.c
index 389be0d..b8294fe 100644
--- a/Xext/xvmain.c
+++ b/Xext/xvmain.c
@@ -426,7 +426,7 @@ XvDestroyWindow(WindowPtr pWin)
 static int
 XvdiDestroyPort(void *pPort, XID id)
 {
-    return (*((XvPortPtr) pPort)->pAdaptor->ddFreePort) (pPort);
+    return Success;
 }
 
 static int
diff --git a/hw/kdrive/src/kxv.c b/hw/kdrive/src/kxv.c
index 0b4335a..f9c18d6 100644
--- a/hw/kdrive/src/kxv.c
+++ b/hw/kdrive/src/kxv.c
@@ -58,8 +58,6 @@ of the copyright holder.
 
 /* XvAdaptorRec fields */
 
-static int KdXVAllocatePort(unsigned long, XvPortPtr, XvPortPtr *);
-static int KdXVFreePort(XvPortPtr);
 static int KdXVPutVideo(ClientPtr, DrawablePtr, XvPortPtr, GCPtr,
                         INT16, INT16, CARD16, CARD16,
                         INT16, INT16, CARD16, CARD16);
@@ -260,8 +258,6 @@ KdXVInitAdaptors(ScreenPtr pScreen, KdVideoAdaptorPtr infoPtr, int number)
             continue;
 
         pa->pScreen = pScreen;
-        pa->ddAllocatePort = KdXVAllocatePort;
-        pa->ddFreePort = KdXVFreePort;
         pa->ddPutVideo = KdXVPutVideo;
         pa->ddPutStill = KdXVPutStill;
         pa->ddGetVideo = KdXVGetVideo;
@@ -1032,19 +1028,6 @@ KdXVDisable(ScreenPtr pScreen)
 /**** XvAdaptorRec fields ****/
 
 static int
-KdXVAllocatePort(unsigned long port, XvPortPtr pPort, XvPortPtr * ppPort)
-{
-    *ppPort = pPort;
-    return Success;
-}
-
-static int
-KdXVFreePort(XvPortPtr pPort)
-{
-    return Success;
-}
-
-static int
 KdXVPutVideo(ClientPtr client,
              DrawablePtr pDraw,
              XvPortPtr pPort,
diff --git a/hw/xfree86/common/xf86xv.c b/hw/xfree86/common/xf86xv.c
index 1c250b3..141a4ed 100644
--- a/hw/xfree86/common/xf86xv.c
+++ b/hw/xfree86/common/xf86xv.c
@@ -56,8 +56,6 @@
 
 /* XvAdaptorRec fields */
 
-static int xf86XVAllocatePort(unsigned long, XvPortPtr, XvPortPtr *);
-static int xf86XVFreePort(XvPortPtr);
 static int xf86XVPutVideo(ClientPtr, DrawablePtr, XvPortPtr, GCPtr,
                           INT16, INT16, CARD16, CARD16,
                           INT16, INT16, CARD16, CARD16);
@@ -369,8 +367,6 @@ xf86XVInitAdaptors(ScreenPtr pScreen, XF86VideoAdaptorPtr * infoPtr, int number)
             continue;
 
         pa->pScreen = pScreen;
-        pa->ddAllocatePort = xf86XVAllocatePort;
-        pa->ddFreePort = xf86XVFreePort;
         pa->ddPutVideo = xf86XVPutVideo;
         pa->ddPutStill = xf86XVPutStill;
         pa->ddGetVideo = xf86XVGetVideo;
@@ -1275,19 +1271,6 @@ xf86XVModeSet(ScrnInfoPtr pScrn)
 /**** XvAdaptorRec fields ****/
 
 static int
-xf86XVAllocatePort(unsigned long port, XvPortPtr pPort, XvPortPtr * ppPort)
-{
-    *ppPort = pPort;
-    return Success;
-}
-
-static int
-xf86XVFreePort(XvPortPtr pPort)
-{
-    return Success;
-}
-
-static int
 xf86XVPutVideo(ClientPtr client,
                DrawablePtr pDraw,
                XvPortPtr pPort,
commit 41d4a626c6ceb15d5b008dca00c6f5032ddd9556
Author: Eric Anholt <eric at anholt.net>
Date:   Sat Apr 5 10:35:52 2014 +0100

    kdrive: Don't bother explicitly clearing new window privates to NULL.
    
    Privates are initially cleared to zero by dixInitPrivates().
    
    Signed-off-by: Eric Anholt <eric at anholt.net>
    Reviewed-by: Keith Packard <keithp at keithp.com>

diff --git a/hw/kdrive/src/kxv.c b/hw/kdrive/src/kxv.c
index c916af4..0b4335a 100644
--- a/hw/kdrive/src/kxv.c
+++ b/hw/kdrive/src/kxv.c
@@ -87,7 +87,6 @@ static int KdXVQueryImageAttributes(ClientPtr, XvPortPtr, XvImagePtr,
 
 /* ScreenRec fields */
 
-static Bool KdXVCreateWindow(WindowPtr pWin);
 static Bool KdXVDestroyWindow(WindowPtr pWin);
 static void KdXVWindowExposures(WindowPtr pWin, RegionPtr r1, RegionPtr r2);
 static void KdXVClipNotify(WindowPtr pWin, int dx, int dy);
@@ -155,7 +154,6 @@ KdXVScreenInit(ScreenPtr pScreen, KdVideoAdaptorPtr adaptors, int num)
     if (!ScreenPriv)
         return FALSE;
 
-    ScreenPriv->CreateWindow = pScreen->CreateWindow;
     ScreenPriv->DestroyWindow = pScreen->DestroyWindow;
     ScreenPriv->WindowExposures = pScreen->WindowExposures;
     ScreenPriv->ClipNotify = pScreen->ClipNotify;
@@ -163,7 +161,6 @@ KdXVScreenInit(ScreenPtr pScreen, KdVideoAdaptorPtr adaptors, int num)
 
 /*   fprintf(stderr,"XV: Wrapping screen funcs\n"); */
 
-    pScreen->CreateWindow = KdXVCreateWindow;
     pScreen->DestroyWindow = KdXVDestroyWindow;
     pScreen->WindowExposures = KdXVWindowExposures;
     pScreen->ClipNotify = KdXVClipNotify;
@@ -797,23 +794,6 @@ KdXVRemovePortFromWindow(WindowPtr pWin, XvPortRecPrivatePtr portPriv)
 /****  ScreenRec fields ****/
 
 static Bool
-KdXVCreateWindow(WindowPtr pWin)
-{
-    ScreenPtr pScreen = pWin->drawable.pScreen;
-    KdXVScreenPtr ScreenPriv = GET_KDXV_SCREEN(pScreen);
-    int ret;
-
-    pScreen->CreateWindow = ScreenPriv->CreateWindow;
-    ret = (*pScreen->CreateWindow) (pWin);
-    pScreen->CreateWindow = KdXVCreateWindow;
-
-    if (ret)
-        dixSetPrivate(&pWin->devPrivates, KdXVWindowKey, NULL);
-
-    return ret;
-}
-
-static Bool
 KdXVDestroyWindow(WindowPtr pWin)
 {
     ScreenPtr pScreen = pWin->drawable.pScreen;
@@ -977,7 +957,6 @@ KdXVCloseScreen(ScreenPtr pScreen)
     if (!ScreenPriv)
         return TRUE;
 
-    pScreen->CreateWindow = ScreenPriv->CreateWindow;
     pScreen->DestroyWindow = ScreenPriv->DestroyWindow;
     pScreen->WindowExposures = ScreenPriv->WindowExposures;
     pScreen->ClipNotify = ScreenPriv->ClipNotify;
diff --git a/hw/kdrive/src/kxv.h b/hw/kdrive/src/kxv.h
index 190b326..4eb4054 100644
--- a/hw/kdrive/src/kxv.h
+++ b/hw/kdrive/src/kxv.h
@@ -181,7 +181,6 @@ void KdXVDisable(ScreenPtr);
 /*** These are DDX layer privates ***/
 
 typedef struct {
-    CreateWindowProcPtr CreateWindow;
     DestroyWindowProcPtr DestroyWindow;
     ClipNotifyProcPtr ClipNotify;
     WindowExposuresProcPtr WindowExposures;
commit e311318b35ef4f82996c6e277137569005893b44
Author: Eric Anholt <eric at anholt.net>
Date:   Sat Apr 5 09:11:03 2014 +0100

    kdrive: Remove dead KXVPaintRegion().
    
    It's been unused since mach64 was deleted, and now there's a helper in
    core XV.
    
    Signed-off-by: Eric Anholt <eric at anholt.net>
    Reviewed-by: Keith Packard <keithp at keithp.com>

diff --git a/hw/kdrive/src/kxv.c b/hw/kdrive/src/kxv.c
index 47e1357..c916af4 100644
--- a/hw/kdrive/src/kxv.c
+++ b/hw/kdrive/src/kxv.c
@@ -1650,44 +1650,3 @@ KdXVCopyPlanarData(KdScreenInfo * screen, CARD8 *src, CARD8 *dst, int randr,
         }
     }
 }
-
-void
-KXVPaintRegion(DrawablePtr pDraw, RegionPtr pRgn, Pixel fg)
-{
-    GCPtr pGC;
-    ChangeGCVal val[2];
-    xRectangle *rects, *r;
-    BoxPtr pBox = RegionRects(pRgn);
-    int nBox = RegionNumRects(pRgn);
-
-    rects = malloc(nBox * sizeof(xRectangle));
-    if (!rects)
-        goto bail0;
-    r = rects;
-    while (nBox--) {
-        r->x = pBox->x1 - pDraw->x;
-        r->y = pBox->y1 - pDraw->y;
-        r->width = pBox->x2 - pBox->x1;
-        r->height = pBox->y2 - pBox->y1;
-        r++;
-        pBox++;
-    }
-
-    pGC = GetScratchGC(pDraw->depth, pDraw->pScreen);
-    if (!pGC)
-        goto bail1;
-
-    val[0].val = fg;
-    val[1].val = IncludeInferiors;
-    ChangeGC(NullClient, pGC, GCForeground | GCSubwindowMode, val);
-
-    ValidateGC(pDraw, pGC);
-
-    (*pGC->ops->PolyFillRect) (pDraw, pGC, RegionNumRects(pRgn), rects);
-
-    FreeScratchGC(pGC);
- bail1:
-    free(rects);
- bail0:
-    ;
-}
diff --git a/hw/kdrive/src/kxv.h b/hw/kdrive/src/kxv.h
index 451d3fa..190b326 100644
--- a/hw/kdrive/src/kxv.h
+++ b/hw/kdrive/src/kxv.h
@@ -170,9 +170,6 @@ KdXVCopyPlanarData(KdScreenInfo * screen, CARD8 *src, CARD8 *dst, int randr,
                    int srcH, int height, int top, int left, int h, int w,
                    int id);
 
-void
- KXVPaintRegion(DrawablePtr pDraw, RegionPtr pRgn, Pixel fg);
-
 KdVideoAdaptorPtr KdXVAllocateVideoAdaptorRec(KdScreenInfo * screen);
 
 void KdXVFreeVideoAdaptorRec(KdVideoAdaptorPtr ptr);
commit 7eac142fb6e8abb011ce59feda3c2d7b04f2b225
Author: Eric Anholt <eric at anholt.net>
Date:   Sat Apr 5 09:09:17 2014 +0100

    xv: Fix malloc-failure cases in the fill color key helper.
    
    Signed-off-by: Eric Anholt <eric at anholt.net>
    Reviewed-by: Alex Deucher <alexander.deucher at amd.com>

diff --git a/Xext/xvmain.c b/Xext/xvmain.c
index d932dfd..389be0d 100644
--- a/Xext/xvmain.c
+++ b/Xext/xvmain.c
@@ -1094,22 +1094,26 @@ XvFillColorKey(DrawablePtr pDraw, CARD32 key, RegionPtr region)
     GCPtr gc;
 
     gc = GetScratchGC(pDraw->depth, pScreen);
+    if (!gc)
+        return;
+
     pval[0].val = key;
     pval[1].val = IncludeInferiors;
     (void) ChangeGC(NullClient, gc, GCForeground | GCSubwindowMode, pval);
     ValidateGC(pDraw, gc);
 
     rects = malloc(nbox * sizeof(xRectangle));
+    if (rects) {
+        for (i = 0; i < nbox; i++, pbox++) {
+            rects[i].x = pbox->x1 - pDraw->x;
+            rects[i].y = pbox->y1 - pDraw->y;
+            rects[i].width = pbox->x2 - pbox->x1;
+            rects[i].height = pbox->y2 - pbox->y1;
+        }
 
-    for (i = 0; i < nbox; i++, pbox++) {
-        rects[i].x = pbox->x1 - pDraw->x;
-        rects[i].y = pbox->y1 - pDraw->y;
-        rects[i].width = pbox->x2 - pbox->x1;
-        rects[i].height = pbox->y2 - pbox->y1;
-    }
-
-    (*gc->ops->PolyFillRect) (pDraw, gc, nbox, rects);
+        (*gc->ops->PolyFillRect) (pDraw, gc, nbox, rects);
 
-    free(rects);
+        free(rects);
+    }
     FreeScratchGC(gc);
 }
commit ea3f3b0786d58b2ba6a9bbf0a32e734670f54b73
Author: Eric Anholt <eric at anholt.net>
Date:   Sat Apr 5 09:07:18 2014 +0100

    xv: Move xf86 XV color key helper to core.
    
    Color key overlay implementations want to reuse this code, and XF86's
    had bugs (to be fixed in the next commit).
    
    Signed-off-by: Eric Anholt <eric at anholt.net>
    Reviewed-by: Keith Packard <keithp at keithp.com>

diff --git a/Xext/xvdix.h b/Xext/xvdix.h
index 534e7d3..828f67c 100644
--- a/Xext/xvdix.h
+++ b/Xext/xvdix.h
@@ -233,6 +233,8 @@ extern _X_EXPORT int XvScreenInit(ScreenPtr);
 extern _X_EXPORT DevPrivateKey XvGetScreenKey(void);
 extern _X_EXPORT unsigned long XvGetRTPort(void);
 extern _X_EXPORT void XvFreeAdaptor(XvAdaptorPtr pAdaptor);
+extern void _X_EXPORT XvFillColorKey(DrawablePtr pDraw, CARD32 key,
+                                     RegionPtr region);
 extern _X_EXPORT int XvdiSendPortNotify(XvPortPtr, Atom, INT32);
 
 extern _X_EXPORT int XvdiPutVideo(ClientPtr, DrawablePtr, XvPortPtr, GCPtr,
diff --git a/Xext/xvmain.c b/Xext/xvmain.c
index 4a439e3..d932dfd 100644
--- a/Xext/xvmain.c
+++ b/Xext/xvmain.c
@@ -1082,3 +1082,34 @@ XvFreeAdaptor(XvAdaptorPtr pAdaptor)
     free(pAdaptor->devPriv.ptr);
     pAdaptor->devPriv.ptr = NULL;
 }
+
+void
+XvFillColorKey(DrawablePtr pDraw, CARD32 key, RegionPtr region)
+{
+    ScreenPtr pScreen = pDraw->pScreen;
+    ChangeGCVal pval[2];
+    BoxPtr pbox = RegionRects(region);
+    int i, nbox = RegionNumRects(region);
+    xRectangle *rects;
+    GCPtr gc;
+
+    gc = GetScratchGC(pDraw->depth, pScreen);
+    pval[0].val = key;
+    pval[1].val = IncludeInferiors;
+    (void) ChangeGC(NullClient, gc, GCForeground | GCSubwindowMode, pval);
+    ValidateGC(pDraw, gc);
+
+    rects = malloc(nbox * sizeof(xRectangle));
+
+    for (i = 0; i < nbox; i++, pbox++) {
+        rects[i].x = pbox->x1 - pDraw->x;
+        rects[i].y = pbox->y1 - pDraw->y;
+        rects[i].width = pbox->x2 - pbox->x1;
+        rects[i].height = pbox->y2 - pbox->y1;
+    }
+
+    (*gc->ops->PolyFillRect) (pDraw, gc, nbox, rects);
+
+    free(rects);
+    FreeScratchGC(gc);
+}
diff --git a/hw/xfree86/common/xf86xv.c b/hw/xfree86/common/xf86xv.c
index 3e31046..1c250b3 100644
--- a/hw/xfree86/common/xf86xv.c
+++ b/hw/xfree86/common/xf86xv.c
@@ -1736,34 +1736,11 @@ void
 xf86XVFillKeyHelperDrawable(DrawablePtr pDraw, CARD32 key, RegionPtr fillboxes)
 {
     ScreenPtr pScreen = pDraw->pScreen;
-    ChangeGCVal pval[2];
-    BoxPtr pbox = RegionRects(fillboxes);
-    int i, nbox = RegionNumRects(fillboxes);
-    xRectangle *rects;
-    GCPtr gc;
 
     if (!xf86ScreenToScrn(pScreen)->vtSema)
         return;
 
-    gc = GetScratchGC(pDraw->depth, pScreen);
-    pval[0].val = key;
-    pval[1].val = IncludeInferiors;
-    (void) ChangeGC(NullClient, gc, GCForeground | GCSubwindowMode, pval);
-    ValidateGC(pDraw, gc);
-
-    rects = malloc(nbox * sizeof(xRectangle));
-
-    for (i = 0; i < nbox; i++, pbox++) {
-        rects[i].x = pbox->x1 - pDraw->x;
-        rects[i].y = pbox->y1 - pDraw->y;
-        rects[i].width = pbox->x2 - pbox->x1;
-        rects[i].height = pbox->y2 - pbox->y1;
-    }
-
-    (*gc->ops->PolyFillRect) (pDraw, gc, nbox, rects);
-
-    free(rects);
-    FreeScratchGC(gc);
+    XvFillColorKey(pDraw, key, fillboxes);
 }
 
 void
commit b01cfe5f23766b9c13ed6bd889263d5d7a8a351d
Author: Eric Anholt <eric at anholt.net>
Date:   Fri Apr 4 22:58:37 2014 +0100

    xv: Move CloseScreen setup from a DIX hook to normal wrapping.
    
    Signed-off-by: Eric Anholt <eric at anholt.net>
    Reviewed-by: Keith Packard <keithp at keithp.com>

diff --git a/Xext/xvdix.h b/Xext/xvdix.h
index b61659c..534e7d3 100644
--- a/Xext/xvdix.h
+++ b/Xext/xvdix.h
@@ -213,7 +213,6 @@ typedef struct {
     DestroyWindowProcPtr DestroyWindow;
     DestroyPixmapProcPtr DestroyPixmap;
     CloseScreenProcPtr CloseScreen;
-    Bool (*ddCloseScreen) (ScreenPtr);
 } XvScreenRec, *XvScreenPtr;
 
 #define SCREEN_PROLOGUE(pScreen, field) ((pScreen)->field = ((XvScreenPtr) \
diff --git a/Xext/xvmain.c b/Xext/xvmain.c
index 2046b9d..4a439e3 100644
--- a/Xext/xvmain.c
+++ b/Xext/xvmain.c
@@ -302,8 +302,6 @@ XvCloseScreen(ScreenPtr pScreen)
     pScreen->DestroyWindow = pxvs->DestroyWindow;
     pScreen->CloseScreen = pxvs->CloseScreen;
 
-    (*pxvs->ddCloseScreen) (pScreen);
-
     free(pxvs);
 
     dixSetPrivate(&pScreen->devPrivates, XvScreenKey, NULL);
diff --git a/hw/kdrive/src/kxv.c b/hw/kdrive/src/kxv.c
index ad51cf9..47e1357 100644
--- a/hw/kdrive/src/kxv.c
+++ b/hw/kdrive/src/kxv.c
@@ -56,10 +56,6 @@ of the copyright holder.
 #include "kxv.h"
 #include "fourcc.h"
 
-/* XvScreenRec fields */
-
-static Bool KdXVCloseScreen(ScreenPtr);
-
 /* XvAdaptorRec fields */
 
 static int KdXVAllocatePort(unsigned long, XvPortPtr, XvPortPtr *);
@@ -95,6 +91,7 @@ static Bool KdXVCreateWindow(WindowPtr pWin);
 static Bool KdXVDestroyWindow(WindowPtr pWin);
 static void KdXVWindowExposures(WindowPtr pWin, RegionPtr r1, RegionPtr r2);
 static void KdXVClipNotify(WindowPtr pWin, int dx, int dy);
+static Bool KdXVCloseScreen(ScreenPtr);
 
 /* misc */
 static Bool KdXVInitAdaptors(ScreenPtr, KdVideoAdaptorPtr, int);
@@ -132,7 +129,6 @@ Bool
 KdXVScreenInit(ScreenPtr pScreen, KdVideoAdaptorPtr adaptors, int num)
 {
     KdXVScreenPtr ScreenPriv;
-    XvScreenPtr pxvs;
 
 /*   fprintf(stderr,"KdXVScreenInit initializing %d adaptors\n",num); */
 
@@ -153,13 +149,6 @@ KdXVScreenInit(ScreenPtr pScreen, KdVideoAdaptorPtr adaptors, int num)
     KdXvScreenKey = XvGetScreenKey();
     PortResource = XvGetRTPort();
 
-    pxvs = GET_XV_SCREEN(pScreen);
-
-    /* Anyone initializing the Xv layer must provide this.
-       The Xv di layer calls it without even checking if it exists! */
-
-    pxvs->ddCloseScreen = KdXVCloseScreen;
-
     ScreenPriv = malloc(sizeof(KdXVScreenRec));
     dixSetPrivate(&pScreen->devPrivates, &KdXVScreenPrivateKey, ScreenPriv);
 
@@ -170,6 +159,7 @@ KdXVScreenInit(ScreenPtr pScreen, KdVideoAdaptorPtr adaptors, int num)
     ScreenPriv->DestroyWindow = pScreen->DestroyWindow;
     ScreenPriv->WindowExposures = pScreen->WindowExposures;
     ScreenPriv->ClipNotify = pScreen->ClipNotify;
+    ScreenPriv->CloseScreen = pScreen->CloseScreen;
 
 /*   fprintf(stderr,"XV: Wrapping screen funcs\n"); */
 
@@ -177,6 +167,7 @@ KdXVScreenInit(ScreenPtr pScreen, KdVideoAdaptorPtr adaptors, int num)
     pScreen->DestroyWindow = KdXVDestroyWindow;
     pScreen->WindowExposures = KdXVWindowExposures;
     pScreen->ClipNotify = KdXVClipNotify;
+    pScreen->CloseScreen = KdXVCloseScreen;
 
     if (!KdXVInitAdaptors(pScreen, adaptors, num))
         return FALSE;
@@ -990,6 +981,7 @@ KdXVCloseScreen(ScreenPtr pScreen)
     pScreen->DestroyWindow = ScreenPriv->DestroyWindow;
     pScreen->WindowExposures = ScreenPriv->WindowExposures;
     pScreen->ClipNotify = ScreenPriv->ClipNotify;
+    pScreen->CloseScreen = ScreenPriv->CloseScreen;
 
 /*   fprintf(stderr,"XV: Unwrapping screen funcs\n"); */
 
@@ -1000,7 +992,7 @@ KdXVCloseScreen(ScreenPtr pScreen)
     free(pxvs->pAdaptors);
     free(ScreenPriv);
 
-    return TRUE;
+    return pScreen->CloseScreen(pScreen);
 }
 
 static Bool
diff --git a/hw/kdrive/src/kxv.h b/hw/kdrive/src/kxv.h
index fe467a9..451d3fa 100644
--- a/hw/kdrive/src/kxv.h
+++ b/hw/kdrive/src/kxv.h
@@ -188,6 +188,7 @@ typedef struct {
     DestroyWindowProcPtr DestroyWindow;
     ClipNotifyProcPtr ClipNotify;
     WindowExposuresProcPtr WindowExposures;
+    CloseScreenProcPtr CloseScreen;
 } KdXVScreenRec, *KdXVScreenPtr;
 
 typedef struct {
diff --git a/hw/xfree86/common/xf86xv.c b/hw/xfree86/common/xf86xv.c
index 0f3b09b..3e31046 100644
--- a/hw/xfree86/common/xf86xv.c
+++ b/hw/xfree86/common/xf86xv.c
@@ -54,10 +54,6 @@
 
 #include "xf86xvpriv.h"
 
-/* XvScreenRec fields */
-
-static Bool xf86XVCloseScreen(ScreenPtr);
-
 /* XvAdaptorRec fields */
 
 static int xf86XVAllocatePort(unsigned long, XvPortPtr, XvPortPtr *);
@@ -94,6 +90,7 @@ static void xf86XVWindowExposures(WindowPtr pWin, RegionPtr r1, RegionPtr r2);
 static void xf86XVPostValidateTree(WindowPtr pWin, WindowPtr pLayerWin,
                                    VTKind kind);
 static void xf86XVClipNotify(WindowPtr pWin, int dx, int dy);
+static Bool xf86XVCloseScreen(ScreenPtr);
 
 #define PostValidateTreeUndefined ((PostValidateTreeProcPtr)-1)
 
@@ -234,7 +231,6 @@ xf86XVScreenInit(ScreenPtr pScreen, XF86VideoAdaptorPtr * adaptors, int num)
 {
     ScrnInfoPtr pScrn;
     XF86XVScreenPtr ScreenPriv;
-    XvScreenPtr pxvs;
 
     if (num <= 0 || noXvExtension)
         return FALSE;
@@ -251,13 +247,6 @@ xf86XVScreenInit(ScreenPtr pScreen, XF86VideoAdaptorPtr * adaptors, int num)
 
     PortResource = XvGetRTPort();
 
-    pxvs = GET_XV_SCREEN(pScreen);
-
-    /* Anyone initializing the Xv layer must provide this.
-       The Xv di layer calls it without even checking if it exists! */
-
-    pxvs->ddCloseScreen = xf86XVCloseScreen;
-
     ScreenPriv = malloc(sizeof(XF86XVScreenRec));
     dixSetPrivate(&pScreen->devPrivates, &XF86XVScreenPrivateKey, ScreenPriv);
 
@@ -270,6 +259,7 @@ xf86XVScreenInit(ScreenPtr pScreen, XF86VideoAdaptorPtr * adaptors, int num)
     ScreenPriv->WindowExposures = pScreen->WindowExposures;
     ScreenPriv->PostValidateTree = PostValidateTreeUndefined;
     ScreenPriv->ClipNotify = pScreen->ClipNotify;
+    ScreenPriv->CloseScreen = pScreen->CloseScreen;
     ScreenPriv->EnterVT = pScrn->EnterVT;
     ScreenPriv->LeaveVT = pScrn->LeaveVT;
     ScreenPriv->AdjustFrame = pScrn->AdjustFrame;
@@ -278,6 +268,7 @@ xf86XVScreenInit(ScreenPtr pScreen, XF86VideoAdaptorPtr * adaptors, int num)
     pScreen->DestroyWindow = xf86XVDestroyWindow;
     pScreen->WindowExposures = xf86XVWindowExposures;
     pScreen->ClipNotify = xf86XVClipNotify;
+    pScreen->CloseScreen = xf86XVCloseScreen;
     pScrn->EnterVT = xf86XVEnterVT;
     pScrn->LeaveVT = xf86XVLeaveVT;
     if (pScrn->AdjustFrame)
@@ -1168,6 +1159,7 @@ xf86XVCloseScreen(ScreenPtr pScreen)
     pScreen->DestroyWindow = ScreenPriv->DestroyWindow;
     pScreen->WindowExposures = ScreenPriv->WindowExposures;
     pScreen->ClipNotify = ScreenPriv->ClipNotify;
+    pScreen->CloseScreen = ScreenPriv->CloseScreen;
 
     pScrn->EnterVT = ScreenPriv->EnterVT;
     pScrn->LeaveVT = ScreenPriv->LeaveVT;
@@ -1180,7 +1172,8 @@ xf86XVCloseScreen(ScreenPtr pScreen)
 
     free(pxvs->pAdaptors);
     free(ScreenPriv);
-    return TRUE;
+
+    return pScreen->CloseScreen(pScreen);
 }
 
 /**** ScrnInfoRec fields ****/
diff --git a/hw/xfree86/common/xf86xvpriv.h b/hw/xfree86/common/xf86xvpriv.h
index e95f959..c0dff16 100644
--- a/hw/xfree86/common/xf86xvpriv.h
+++ b/hw/xfree86/common/xf86xvpriv.h
@@ -45,6 +45,7 @@ typedef struct {
     Bool (*EnterVT) (ScrnInfoPtr);
     void (*LeaveVT) (ScrnInfoPtr);
     xf86ModeSetProc *ModeSet;
+    CloseScreenProcPtr CloseScreen;
 } XF86XVScreenRec, *XF86XVScreenPtr;
 
 typedef struct {
commit 6a71ee79aabe6b611cae443a49786824a0322313
Author: Eric Anholt <eric at anholt.net>
Date:   Fri Apr 4 18:02:14 2014 +0100

    xv: Drop unused XvdiVideoStopped().
    
    Signed-off-by: Eric Anholt <eric at anholt.net>
    Reviewed-by: Keith Packard <keithp at keithp.com>

diff --git a/Xext/xvdix.h b/Xext/xvdix.h
index ddd8abb..b61659c 100644
--- a/Xext/xvdix.h
+++ b/Xext/xvdix.h
@@ -235,7 +235,6 @@ extern _X_EXPORT DevPrivateKey XvGetScreenKey(void);
 extern _X_EXPORT unsigned long XvGetRTPort(void);
 extern _X_EXPORT void XvFreeAdaptor(XvAdaptorPtr pAdaptor);
 extern _X_EXPORT int XvdiSendPortNotify(XvPortPtr, Atom, INT32);
-extern _X_EXPORT int XvdiVideoStopped(XvPortPtr, int);
 
 extern _X_EXPORT int XvdiPutVideo(ClientPtr, DrawablePtr, XvPortPtr, GCPtr,
                                   INT16, INT16, CARD16, CARD16,
diff --git a/Xext/xvmain.c b/Xext/xvmain.c
index ea3771f..2046b9d 100644
--- a/Xext/xvmain.c
+++ b/Xext/xvmain.c
@@ -425,30 +425,6 @@ XvDestroyWindow(WindowPtr pWin)
 
 }
 
-/* The XvdiVideoStopped procedure is a hook for the device dependent layer.
-   It provides a way for the dd layer to inform the di layer that video has
-   stopped in a port for reasons that the di layer had no control over; note
-   that it doesn't call back into the dd layer */
-
-int
-XvdiVideoStopped(XvPortPtr pPort, int reason)
-{
-
-    /* IF PORT ISN'T ACTIVE THEN WE'RE DONE */
-
-    if (!pPort->pDraw)
-        return Success;
-
-    XvdiSendVideoNotify(pPort, pPort->pDraw, reason);
-
-    pPort->pDraw = NULL;
-    pPort->client = NULL;
-    pPort->time = currentTime;
-
-    return Success;
-
-}
-
 static int
 XvdiDestroyPort(void *pPort, XID id)
 {
commit 4a095902a37cb98d7954d0873dcf1376cbab54b8
Author: Eric Anholt <eric at anholt.net>
Date:   Fri Apr 4 18:01:07 2014 +0100

    xv: Drop unused XvdiPreemptVideo().
    
    Signed-off-by: Eric Anholt <eric at anholt.net>
    Reviewed-by: Keith Packard <keithp at keithp.com>

diff --git a/Xext/xvdix.h b/Xext/xvdix.h
index 2437eb4..ddd8abb 100644
--- a/Xext/xvdix.h
+++ b/Xext/xvdix.h
@@ -259,7 +259,6 @@ extern _X_EXPORT int XvdiSelectPortNotify(ClientPtr, XvPortPtr, BOOL);
 extern _X_EXPORT int XvdiSetPortAttribute(ClientPtr, XvPortPtr, Atom, INT32);
 extern _X_EXPORT int XvdiGetPortAttribute(ClientPtr, XvPortPtr, Atom, INT32 *);
 extern _X_EXPORT int XvdiStopVideo(ClientPtr, XvPortPtr, DrawablePtr);
-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);
diff --git a/Xext/xvmain.c b/Xext/xvmain.c
index 9084e40..ea3771f 100644
--- a/Xext/xvmain.c
+++ b/Xext/xvmain.c
@@ -992,28 +992,6 @@ XvdiStopVideo(ClientPtr client, XvPortPtr pPort, DrawablePtr pDraw)
 }
 
 int
-XvdiPreemptVideo(ClientPtr client, XvPortPtr pPort, DrawablePtr pDraw)
-{
-    int status;
-
-    /* IF PORT ISN'T ACTIVE THEN WE'RE DONE */
-
-    if (!pPort->pDraw || (pPort->pDraw != pDraw))
-        return Success;
-
-    XvdiSendVideoNotify(pPort, pPort->pDraw, XvPreempted);
-
-    status = (*pPort->pAdaptor->ddStopVideo) (client, pPort, pPort->pDraw);
-
-    pPort->pDraw = NULL;
-    pPort->client = (ClientPtr) client;
-    pPort->time = currentTime;
-
-    return status;
-
-}
-
-int
 XvdiMatchPort(XvPortPtr pPort, DrawablePtr pDraw)
 {
 
commit e7dde86f2343832c52ef74f5c4fe44a72054c79b
Author: Eric Anholt <eric at anholt.net>
Date:   Fri Apr 4 17:54:58 2014 +0100

    xv: Move the DDX XV screen private allocation into the DDXes.
    
    XV was going against convention by having the core infrastructure
    allocate the private on behalf of the DDX.  I was interested in this
    because I was trying to make multiple pieces of DDX be able to
    allocate adaptors, and that wasn't going to work if DDX-specific code
    was hung off of a single global screen private.
    
    Signed-off-by: Eric Anholt <eric at anholt.net>
    Reviewed-by: Keith Packard <keithp at keithp.com>

diff --git a/Xext/xvdix.h b/Xext/xvdix.h
index 7afa88a..2437eb4 100644
--- a/Xext/xvdix.h
+++ b/Xext/xvdix.h
@@ -214,7 +214,6 @@ typedef struct {
     DestroyPixmapProcPtr DestroyPixmap;
     CloseScreenProcPtr CloseScreen;
     Bool (*ddCloseScreen) (ScreenPtr);
-    DevUnion devPriv;
 } XvScreenRec, *XvScreenPtr;
 
 #define SCREEN_PROLOGUE(pScreen, field) ((pScreen)->field = ((XvScreenPtr) \
diff --git a/hw/kdrive/src/kxv.c b/hw/kdrive/src/kxv.c
index 0896c81..ad51cf9 100644
--- a/hw/kdrive/src/kxv.c
+++ b/hw/kdrive/src/kxv.c
@@ -103,6 +103,7 @@ static DevPrivateKeyRec KdXVWindowKeyRec;
 
 #define KdXVWindowKey (&KdXVWindowKeyRec)
 static DevPrivateKey KdXvScreenKey;
+static DevPrivateKeyRec KdXVScreenPrivateKey;
 static unsigned long KdXVGeneration = 0;
 static unsigned long PortResource = 0;
 
@@ -110,7 +111,7 @@ static unsigned long PortResource = 0;
     dixLookupPrivate(&(pScreen)->devPrivates, KdXvScreenKey))
 
 #define GET_KDXV_SCREEN(pScreen) \
-  	((KdXVScreenPtr)(GET_XV_SCREEN(pScreen)->devPriv.ptr))
+    ((KdXVScreenPtr)(dixGetPrivate(&pScreen->devPrivates, &KdXVScreenPrivateKey)))
 
 #define GET_KDXV_WINDOW(pWin) ((KdXVWindowPtr) \
     dixLookupPrivate(&(pWin)->devPrivates, KdXVWindowKey))
@@ -143,6 +144,8 @@ KdXVScreenInit(ScreenPtr pScreen, KdVideoAdaptorPtr adaptors, int num)
 
     if (!dixRegisterPrivateKey(&KdXVWindowKeyRec, PRIVATE_WINDOW, 0))
         return FALSE;
+    if (!dixRegisterPrivateKey(&KdXVScreenPrivateKey, PRIVATE_SCREEN, 0))
+        return FALSE;
 
     if (Success != XvScreenInit(pScreen))
         return FALSE;
@@ -157,13 +160,8 @@ KdXVScreenInit(ScreenPtr pScreen, KdVideoAdaptorPtr adaptors, int num)
 
     pxvs->ddCloseScreen = KdXVCloseScreen;
 
-    /* The Xv di layer provides us with a private hook so that we don't
-       have to allocate our own screen private.  They also provide
-       a CloseScreen hook so that we don't have to wrap it.  I'm not
-       sure that I appreciate that.  */
-
     ScreenPriv = malloc(sizeof(KdXVScreenRec));
-    pxvs->devPriv.ptr = (void *) ScreenPriv;
+    dixSetPrivate(&pScreen->devPrivates, &KdXVScreenPrivateKey, ScreenPriv);
 
     if (!ScreenPriv)
         return FALSE;
diff --git a/hw/xfree86/common/xf86xv.c b/hw/xfree86/common/xf86xv.c
index 35dd664..0f3b09b 100644
--- a/hw/xfree86/common/xf86xv.c
+++ b/hw/xfree86/common/xf86xv.c
@@ -112,7 +112,10 @@ static DevPrivateKeyRec XF86XVWindowKeyRec;
 
 #define XF86XVWindowKey (&XF86XVWindowKeyRec)
 
+/* dixmain.c XvScreenPtr screen private */
 DevPrivateKey XF86XvScreenKey;
+/** xf86xv.c XF86XVScreenPtr screen private */
+static DevPrivateKeyRec XF86XVScreenPrivateKey;
 
 static unsigned long PortResource = 0;
 
@@ -120,7 +123,7 @@ static unsigned long PortResource = 0;
     ((XvScreenPtr)dixLookupPrivate(&(pScreen)->devPrivates, XF86XvScreenKey))
 
 #define GET_XF86XV_SCREEN(pScreen) \
-    ((XF86XVScreenPtr)(GET_XV_SCREEN(pScreen)->devPriv.ptr))
+    ((XF86XVScreenPtr)(dixGetPrivate(&pScreen->devPrivates, &XF86XVScreenPrivateKey)))
 
 #define GET_XF86XV_WINDOW(pWin) \
     ((XF86XVWindowPtr)dixLookupPrivate(&(pWin)->devPrivates, XF86XVWindowKey))
@@ -241,6 +244,8 @@ xf86XVScreenInit(ScreenPtr pScreen, XF86VideoAdaptorPtr * adaptors, int num)
 
     if (!dixRegisterPrivateKey(&XF86XVWindowKeyRec, PRIVATE_WINDOW, 0))
         return FALSE;
+    if (!dixRegisterPrivateKey(&XF86XVScreenPrivateKey, PRIVATE_SCREEN, 0))
+        return FALSE;
 
     XF86XvScreenKey = XvGetScreenKey();
 
@@ -253,13 +258,8 @@ xf86XVScreenInit(ScreenPtr pScreen, XF86VideoAdaptorPtr * adaptors, int num)
 
     pxvs->ddCloseScreen = xf86XVCloseScreen;
 
-    /* The Xv di layer provides us with a private hook so that we don't
-       have to allocate our own screen private.  They also provide
-       a CloseScreen hook so that we don't have to wrap it.  I'm not
-       sure that I appreciate that.  */
-
     ScreenPriv = malloc(sizeof(XF86XVScreenRec));
-    pxvs->devPriv.ptr = (void *) ScreenPriv;
+    dixSetPrivate(&pScreen->devPrivates, &XF86XVScreenPrivateKey, ScreenPriv);
 
     if (!ScreenPriv)
         return FALSE;
commit a146c6d4212ed199002e40419b4aa22da8f49e3a
Author: Eric Anholt <eric at anholt.net>
Date:   Fri Apr 4 13:12:34 2014 +0100

    xv: Drop the ddQueryAdaptors() interface.
    
    The core was passing pointers to pxvs's nAdaptors and pAdaptors, and
    the two hardware implementations were copying pxvs's nAdaptors and
    pAdaptors into those pointers.
    
    Signed-off-by: Eric Anholt <eric at anholt.net>
    Reviewed-by: Keith Packard <keithp at keithp.com>

diff --git a/Xext/xvdisp.c b/Xext/xvdisp.c
index f2d49a2..71192b3 100644
--- a/Xext/xvdisp.c
+++ b/Xext/xvdisp.c
@@ -356,8 +356,6 @@ ProcXvQueryAdaptors(ClientPtr client)
         return Success;
     }
 
-    (*pxvs->ddQueryAdaptors) (pScreen, &pxvs->pAdaptors, &pxvs->nAdaptors);
-
     rep = (xvQueryAdaptorsReply) {
         .type = X_Reply,
         .sequenceNumber = client->sequence,
diff --git a/Xext/xvdix.h b/Xext/xvdix.h
index f62adf8..7afa88a 100644
--- a/Xext/xvdix.h
+++ b/Xext/xvdix.h
@@ -214,7 +214,6 @@ typedef struct {
     DestroyPixmapProcPtr DestroyPixmap;
     CloseScreenProcPtr CloseScreen;
     Bool (*ddCloseScreen) (ScreenPtr);
-    int (*ddQueryAdaptors) (ScreenPtr, XvAdaptorPtr *, int *);
     DevUnion devPriv;
 } XvScreenRec, *XvScreenPtr;
 
diff --git a/hw/kdrive/src/kxv.c b/hw/kdrive/src/kxv.c
index 5aae8f7..0896c81 100644
--- a/hw/kdrive/src/kxv.c
+++ b/hw/kdrive/src/kxv.c
@@ -59,7 +59,6 @@ of the copyright holder.
 /* XvScreenRec fields */
 
 static Bool KdXVCloseScreen(ScreenPtr);
-static int KdXVQueryAdaptors(ScreenPtr, XvAdaptorPtr *, int *);
 
 /* XvAdaptorRec fields */
 
@@ -153,11 +152,10 @@ KdXVScreenInit(ScreenPtr pScreen, KdVideoAdaptorPtr adaptors, int num)
 
     pxvs = GET_XV_SCREEN(pScreen);
 
-    /* Anyone initializing the Xv layer must provide these two.
-       The Xv di layer calls them without even checking if they exist! */
+    /* Anyone initializing the Xv layer must provide this.
+       The Xv di layer calls it without even checking if it exists! */
 
     pxvs->ddCloseScreen = KdXVCloseScreen;
-    pxvs->ddQueryAdaptors = KdXVQueryAdaptors;
 
     /* The Xv di layer provides us with a private hook so that we don't
        have to allocate our own screen private.  They also provide
@@ -1007,18 +1005,6 @@ KdXVCloseScreen(ScreenPtr pScreen)
     return TRUE;
 }
 
-static int
-KdXVQueryAdaptors(ScreenPtr pScreen,
-                  XvAdaptorPtr * p_pAdaptors, int *p_nAdaptors)
-{
-    XvScreenPtr pxvs = GET_XV_SCREEN(pScreen);
-
-    *p_nAdaptors = pxvs->nAdaptors;
-    *p_pAdaptors = pxvs->pAdaptors;
-
-    return Success;
-}
-
 static Bool
 KdXVRunning(ScreenPtr pScreen)
 {
diff --git a/hw/xfree86/common/xf86xv.c b/hw/xfree86/common/xf86xv.c
index ae20b58..35dd664 100644
--- a/hw/xfree86/common/xf86xv.c
+++ b/hw/xfree86/common/xf86xv.c
@@ -57,7 +57,6 @@
 /* XvScreenRec fields */
 
 static Bool xf86XVCloseScreen(ScreenPtr);
-static int xf86XVQueryAdaptors(ScreenPtr, XvAdaptorPtr *, int *);
 
 /* XvAdaptorRec fields */
 
@@ -249,11 +248,10 @@ xf86XVScreenInit(ScreenPtr pScreen, XF86VideoAdaptorPtr * adaptors, int num)
 
     pxvs = GET_XV_SCREEN(pScreen);
 
-    /* Anyone initializing the Xv layer must provide these two.
-       The Xv di layer calls them without even checking if they exist! */
+    /* Anyone initializing the Xv layer must provide this.
+       The Xv di layer calls it without even checking if it exists! */
 
     pxvs->ddCloseScreen = xf86XVCloseScreen;
-    pxvs->ddQueryAdaptors = xf86XVQueryAdaptors;
 
     /* The Xv di layer provides us with a private hook so that we don't
        have to allocate our own screen private.  They also provide
@@ -1185,18 +1183,6 @@ xf86XVCloseScreen(ScreenPtr pScreen)
     return TRUE;
 }
 
-static int
-xf86XVQueryAdaptors(ScreenPtr pScreen,
-                    XvAdaptorPtr * p_pAdaptors, int *p_nAdaptors)
-{
-    XvScreenPtr pxvs = GET_XV_SCREEN(pScreen);
-
-    *p_nAdaptors = pxvs->nAdaptors;
-    *p_pAdaptors = pxvs->pAdaptors;
-
-    return Success;
-}
-
 /**** ScrnInfoRec fields ****/
 
 static Bool
commit cb42805c6675bbb9f0b37609fe2ffecc07f46290
Author: Eric Anholt <eric at anholt.net>
Date:   Fri Dec 27 21:54:26 2013 -0800

    xv: Move common code for adaptor cleanup to xvmain.c
    
    Since any DDX XV screen cleanup would need this same code for freeing
    the tree of pointers for xv adaptors, move it to the dix.
    
    v2: Unconditionalize the pPorts freeing, to match the block above it.
    
    Signed-off-by: Eric Anholt <eric at anholt.net>
    Reviewed-by: Keith Packard <keithp at keithp.com> (v1)

diff --git a/Xext/xvdix.h b/Xext/xvdix.h
index bb08cf4..f62adf8 100644
--- a/Xext/xvdix.h
+++ b/Xext/xvdix.h
@@ -235,6 +235,7 @@ extern _X_EXPORT int SProcXvDispatch(ClientPtr);
 extern _X_EXPORT int XvScreenInit(ScreenPtr);
 extern _X_EXPORT DevPrivateKey XvGetScreenKey(void);
 extern _X_EXPORT unsigned long XvGetRTPort(void);
+extern _X_EXPORT void XvFreeAdaptor(XvAdaptorPtr pAdaptor);
 extern _X_EXPORT int XvdiSendPortNotify(XvPortPtr, Atom, INT32);
 extern _X_EXPORT int XvdiVideoStopped(XvPortPtr, int);
 
diff --git a/Xext/xvmain.c b/Xext/xvmain.c
index 00b5179..9084e40 100644
--- a/Xext/xvmain.c
+++ b/Xext/xvmain.c
@@ -1091,3 +1091,42 @@ WriteSwappedPortNotifyEvent(xvEvent * from, xvEvent * to)
     cpswapl(from->u.portNotify.value, to->u.portNotify.value);
 
 }
+
+void
+XvFreeAdaptor(XvAdaptorPtr pAdaptor)
+{
+    int i;
+
+    free(pAdaptor->name);
+    pAdaptor->name = NULL;
+
+    if (pAdaptor->pEncodings) {
+        XvEncodingPtr pEncode = pAdaptor->pEncodings;
+
+        for (i = 0; i < pAdaptor->nEncodings; i++, pEncode++)
+            free(pEncode->name);
+        free(pAdaptor->pEncodings);
+        pAdaptor->pEncodings = NULL;
+    }
+
+    free(pAdaptor->pFormats);
+    pAdaptor->pFormats = NULL;
+
+    free(pAdaptor->pPorts);
+    pAdaptor->pPorts = NULL;
+
+    if (pAdaptor->pAttributes) {
+        XvAttributePtr pAttribute = pAdaptor->pAttributes;
+
+        for (i = 0; i < pAdaptor->nAttributes; i++, pAttribute++)
+            free(pAttribute->name);
+        free(pAdaptor->pAttributes);
+        pAdaptor->pAttributes = NULL;
+    }
+
+    free(pAdaptor->pImages);
+    pAdaptor->pImages = NULL;
+
+    free(pAdaptor->devPriv.ptr);
+    pAdaptor->devPriv.ptr = NULL;
+}
diff --git a/hw/kdrive/src/kxv.c b/hw/kdrive/src/kxv.c
index 3d63304..5aae8f7 100644
--- a/hw/kdrive/src/kxv.c
+++ b/hw/kdrive/src/kxv.c
@@ -193,19 +193,6 @@ KdXVFreeAdaptor(XvAdaptorPtr pAdaptor)
 {
     int i;
 
-    free(pAdaptor->name);
-
-    if (pAdaptor->pEncodings) {
-        XvEncodingPtr pEncode = pAdaptor->pEncodings;
-
-        for (i = 0; i < pAdaptor->nEncodings; i++, pEncode++) {
-            free(pEncode->name);
-        }
-        free(pAdaptor->pEncodings);
-    }
-
-    free(pAdaptor->pFormats);
-
     if (pAdaptor->pPorts) {
         XvPortPtr pPort = pAdaptor->pPorts;
         XvPortRecPrivatePtr pPriv;
@@ -220,22 +207,9 @@ KdXVFreeAdaptor(XvAdaptorPtr pAdaptor)
                 free(pPriv);
             }
         }
-        free(pAdaptor->pPorts);
     }
 
-    if (pAdaptor->nAttributes) {
-        XvAttributePtr pAttribute = pAdaptor->pAttributes;
-
-        for (i = 0; i < pAdaptor->nAttributes; i++, pAttribute++) {
-            free(pAttribute->name);
-        }
-
-        free(pAdaptor->pAttributes);
-    }
-
-    free(pAdaptor->pImages);
-
-    free(pAdaptor->devPriv.ptr);
+    XvFreeAdaptor(pAdaptor);
 }
 
 static Bool
diff --git a/hw/xfree86/common/xf86xv.c b/hw/xfree86/common/xf86xv.c
index 6302b8d..ae20b58 100644
--- a/hw/xfree86/common/xf86xv.c
+++ b/hw/xfree86/common/xf86xv.c
@@ -297,21 +297,6 @@ xf86XVFreeAdaptor(XvAdaptorPtr pAdaptor)
 {
     int i;
 
-    free(pAdaptor->name);
-    pAdaptor->name = NULL;
-
-    if (pAdaptor->pEncodings) {
-        XvEncodingPtr pEncode = pAdaptor->pEncodings;
-
-        for (i = 0; i < pAdaptor->nEncodings; i++, pEncode++)
-            free(pEncode->name);
-        free(pAdaptor->pEncodings);
-        pAdaptor->pEncodings = NULL;
-    }
-
-    free(pAdaptor->pFormats);
-    pAdaptor->pFormats = NULL;
-
     if (pAdaptor->pPorts) {
         XvPortPtr pPort = pAdaptor->pPorts;
         XvPortRecPrivatePtr pPriv;
@@ -328,23 +313,9 @@ xf86XVFreeAdaptor(XvAdaptorPtr pAdaptor)
                 free(pPriv);
             }
         }
-        free(pAdaptor->pPorts);
-        pAdaptor->pPorts = NULL;
-    }
-
-    if (pAdaptor->pAttributes) {
-        XvAttributePtr pAttribute = pAdaptor->pAttributes;
-
-        for (i = 0; i < pAdaptor->nAttributes; i++, pAttribute++)
-            free(pAttribute->name);
-        free(pAdaptor->pAttributes);
-        pAdaptor->pAttributes = NULL;
     }
 
-    free(pAdaptor->pImages);
-    free(pAdaptor->devPriv.ptr);
-    pAdaptor->pImages = NULL;
-    pAdaptor->devPriv.ptr = NULL;
+    XvFreeAdaptor(pAdaptor);
 }
 
 static Bool
commit 8cb0da29404d3fed13c1cbedb5c6164e4733ea82
Author: Eric Anholt <eric at anholt.net>
Date:   Fri Dec 27 20:59:12 2013 -0800

    xv: Remove dead VIDEO_NO_CLIPPING from the xorg and kdrive DDXes.
    
    As far as I can see, nothing has ever used this flag except possibly
    the i.mx6 xorg ddx debug during bringup.
    
    Signed-off-by: Eric Anholt <eric at anholt.net>
    Reviewed-by: Keith Packard <keithp at keithp.com>

diff --git a/hw/kdrive/src/kxv.c b/hw/kdrive/src/kxv.c
index f808fb0..3d63304 100644
--- a/hw/kdrive/src/kxv.c
+++ b/hw/kdrive/src/kxv.c
@@ -664,18 +664,6 @@ KdXVReputVideo(XvPortRecPrivatePtr portPriv)
         goto CLIP_VIDEO_BAILOUT;
     }
 
-    /* bailout if we have to clip but the hardware doesn't support it */
-    if (portPriv->AdaptorRec->flags & VIDEO_NO_CLIPPING) {
-        BoxPtr clipBox = RegionRects(&ClipRegion);
-
-        if ((RegionNumRects(&ClipRegion) != 1) ||
-            (clipBox->x1 != WinBox.x1) || (clipBox->x2 != WinBox.x2) ||
-            (clipBox->y1 != WinBox.y1) || (clipBox->y2 != WinBox.y2)) {
-            clippedAway = TRUE;
-            goto CLIP_VIDEO_BAILOUT;
-        }
-    }
-
     ret = (*portPriv->AdaptorRec->PutVideo) (portPriv->screen, portPriv->pDraw,
                                              portPriv->vid_x, portPriv->vid_y,
                                              WinBox.x1, WinBox.y1,
@@ -752,18 +740,6 @@ KdXVReputImage(XvPortRecPrivatePtr portPriv)
         goto CLIP_VIDEO_BAILOUT;
     }
 
-    /* bailout if we have to clip but the hardware doesn't support it */
-    if (portPriv->AdaptorRec->flags & VIDEO_NO_CLIPPING) {
-        BoxPtr clipBox = RegionRects(&ClipRegion);
-
-        if ((RegionNumRects(&ClipRegion) != 1) ||
-            (clipBox->x1 != WinBox.x1) || (clipBox->x2 != WinBox.x2) ||
-            (clipBox->y1 != WinBox.y1) || (clipBox->y2 != WinBox.y2)) {
-            clippedAway = TRUE;
-            goto CLIP_VIDEO_BAILOUT;
-        }
-    }
-
     ret =
         (*portPriv->AdaptorRec->ReputImage) (portPriv->screen, portPriv->pDraw,
                                              WinBox.x1, WinBox.y1, &ClipRegion,
@@ -1251,17 +1227,6 @@ KdXVPutStill(ClientPtr client,
         goto PUT_STILL_BAILOUT;
     }
 
-    if (portPriv->AdaptorRec->flags & VIDEO_NO_CLIPPING) {
-        BoxPtr clipBox = RegionRects(&ClipRegion);
-
-        if ((RegionNumRects(&ClipRegion) != 1) ||
-            (clipBox->x1 != WinBox.x1) || (clipBox->x2 != WinBox.x2) ||
-            (clipBox->y1 != WinBox.y1) || (clipBox->y2 != WinBox.y2)) {
-            clippedAway = TRUE;
-            goto PUT_STILL_BAILOUT;
-        }
-    }
-
     ret = (*portPriv->AdaptorRec->PutStill) (portPriv->screen, pDraw,
                                              vid_x, vid_y, WinBox.x1, WinBox.y1,
                                              vid_w, vid_h, drw_w, drw_h,
@@ -1541,17 +1506,6 @@ KdXVPutImage(ClientPtr client,
         goto PUT_IMAGE_BAILOUT;
     }
 
-    if (portPriv->AdaptorRec->flags & VIDEO_NO_CLIPPING) {
-        BoxPtr clipBox = RegionRects(&ClipRegion);
-
-        if ((RegionNumRects(&ClipRegion) != 1) ||
-            (clipBox->x1 != WinBox.x1) || (clipBox->x2 != WinBox.x2) ||
-            (clipBox->y1 != WinBox.y1) || (clipBox->y2 != WinBox.y2)) {
-            clippedAway = TRUE;
-            goto PUT_IMAGE_BAILOUT;
-        }
-    }
-
     ret = (*portPriv->AdaptorRec->PutImage) (portPriv->screen, pDraw,
                                              src_x, src_y, WinBox.x1, WinBox.y1,
                                              src_w, src_h, drw_w, drw_h,
diff --git a/hw/kdrive/src/kxv.h b/hw/kdrive/src/kxv.h
index adedbda..fe467a9 100644
--- a/hw/kdrive/src/kxv.h
+++ b/hw/kdrive/src/kxv.h
@@ -50,7 +50,6 @@ of the copyright holder.
 
 #include "../../Xext/xvdix.h"
 
-#define VIDEO_NO_CLIPPING			0x00000001
 #define VIDEO_OVERLAID_IMAGES			0x00000004
 #define VIDEO_OVERLAID_STILLS			0x00000008
 #define VIDEO_CLIP_TO_VIEWPORT			0x00000010
diff --git a/hw/xfree86/common/xf86xv.c b/hw/xfree86/common/xf86xv.c
index bb91758..6302b8d 100644
--- a/hw/xfree86/common/xf86xv.c
+++ b/hw/xfree86/common/xf86xv.c
@@ -784,18 +784,6 @@ xf86XVReputVideo(XvPortRecPrivatePtr portPriv)
         goto CLIP_VIDEO_BAILOUT;
     }
 
-    /* bailout if we have to clip but the hardware doesn't support it */
-    if (portPriv->AdaptorRec->flags & VIDEO_NO_CLIPPING) {
-        BoxPtr clipBox = RegionRects(&ClipRegion);
-
-        if ((RegionNumRects(&ClipRegion) != 1) ||
-            (clipBox->x1 != WinBox.x1) || (clipBox->x2 != WinBox.x2) ||
-            (clipBox->y1 != WinBox.y1) || (clipBox->y2 != WinBox.y2)) {
-            clippedAway = TRUE;
-            goto CLIP_VIDEO_BAILOUT;
-        }
-    }
-
     ret = (*portPriv->AdaptorRec->PutVideo) (portPriv->pScrn,
                                              portPriv->vid_x, portPriv->vid_y,
                                              WinBox.x1, WinBox.y1,
@@ -874,18 +862,6 @@ xf86XVReputImage(XvPortRecPrivatePtr portPriv)
         goto CLIP_VIDEO_BAILOUT;
     }
 
-    /* bailout if we have to clip but the hardware doesn't support it */
-    if (portPriv->AdaptorRec->flags & VIDEO_NO_CLIPPING) {
-        BoxPtr clipBox = RegionRects(&ClipRegion);
-
-        if ((RegionNumRects(&ClipRegion) != 1) ||
-            (clipBox->x1 != WinBox.x1) || (clipBox->x2 != WinBox.x2) ||
-            (clipBox->y1 != WinBox.y1) || (clipBox->y2 != WinBox.y2)) {
-            clippedAway = TRUE;
-            goto CLIP_VIDEO_BAILOUT;
-        }
-    }
-
     ret = (*portPriv->AdaptorRec->ReputImage) (portPriv->pScrn,
                                                portPriv->vid_x, portPriv->vid_y,
                                                WinBox.x1, WinBox.y1,
@@ -1468,17 +1444,6 @@ xf86XVPutStill(ClientPtr client,
         goto PUT_STILL_BAILOUT;
     }
 
-    if (portPriv->AdaptorRec->flags & VIDEO_NO_CLIPPING) {
-        BoxPtr clipBox = RegionRects(&ClipRegion);
-
-        if ((RegionNumRects(&ClipRegion) != 1) ||
-            (clipBox->x1 != WinBox.x1) || (clipBox->x2 != WinBox.x2) ||
-            (clipBox->y1 != WinBox.y1) || (clipBox->y2 != WinBox.y2)) {
-            clippedAway = TRUE;
-            goto PUT_STILL_BAILOUT;
-        }
-    }
-
     ret = (*portPriv->AdaptorRec->PutStill) (portPriv->pScrn,
                                              vid_x, vid_y, WinBox.x1, WinBox.y1,
                                              vid_w, vid_h, drw_w, drw_h,
@@ -1760,17 +1725,6 @@ xf86XVPutImage(ClientPtr client,
         goto PUT_IMAGE_BAILOUT;
     }
 
-    if (portPriv->AdaptorRec->flags & VIDEO_NO_CLIPPING) {
-        BoxPtr clipBox = RegionRects(&ClipRegion);
-
-        if ((RegionNumRects(&ClipRegion) != 1) ||
-            (clipBox->x1 != WinBox.x1) || (clipBox->x2 != WinBox.x2) ||
-            (clipBox->y1 != WinBox.y1) || (clipBox->y2 != WinBox.y2)) {
-            clippedAway = TRUE;
-            goto PUT_IMAGE_BAILOUT;
-        }
-    }
-
     ret = (*portPriv->AdaptorRec->PutImage) (portPriv->pScrn,
                                              src_x, src_y, WinBox.x1, WinBox.y1,
                                              src_w, src_h, drw_w, drw_h,
diff --git a/hw/xfree86/common/xf86xv.h b/hw/xfree86/common/xf86xv.h
index fc6cf5d..c6455d7 100644
--- a/hw/xfree86/common/xf86xv.h
+++ b/hw/xfree86/common/xf86xv.h
@@ -32,7 +32,6 @@
 #include "xvdix.h"
 #include "xf86str.h"
 
-#define VIDEO_NO_CLIPPING			0x00000001
 #define VIDEO_OVERLAID_IMAGES			0x00000004
 #define VIDEO_OVERLAID_STILLS			0x00000008
 /*
diff --git a/hw/xfree86/doc/ddxDesign.xml b/hw/xfree86/doc/ddxDesign.xml
index 969fb0f..6a9de9e 100644
--- a/hw/xfree86/doc/ddxDesign.xml
+++ b/hw/xfree86/doc/ddxDesign.xml
@@ -4543,21 +4543,6 @@ as follows:
 
 	      <variablelist>
 		<varlistentry>
-		  <term><constant>VIDEO_NO_CLIPPING</constant></term>
-		  <listitem><para>
-	   This indicates that the video adaptor does not support
-	   clipping.  The driver will never receive <quote>Put</quote> requests
-	   where less than the entire area determined by
-	   <parameter>drw_x</parameter>, <parameter>drw_y</parameter>,
-	   <parameter>drw_w</parameter> and <parameter>drw_h</parameter> is visible.
-	   This flag does not apply to <quote>Get</quote> requests.  Hardware
-	   that is incapable of clipping <quote>Gets</quote> may punt or get
-	   the extents of the clipping region passed to it.
-		    </para></listitem>
-
-		</varlistentry>
-
-		<varlistentry>
 		  <term><constant>VIDEO_OVERLAID_STILLS</constant></term>
 		  <listitem><para>
 	   Implementing PutStill for hardware that does video as an
@@ -4714,9 +4699,7 @@ as follows:
 	    </para>
 
 	    <para>
-	If the <constant>VIDEO_NO_CLIPPING</constant>
-	flag is set, the <literal remap="tt">clipBoxes</literal> may be ignored by
-	the driver.  <literal remap="tt">ClipBoxes</literal> is an <literal remap="tt">X-Y</literal>
+	<literal remap="tt">ClipBoxes</literal> is an <literal remap="tt">X-Y</literal>
 	banded region identical to those used throughout the server.
 	The clipBoxes represent the visible portions of the area determined
 	by <literal remap="tt">drw_x</literal>, <literal remap="tt">drw_y</literal>,
commit a6ec7d5278405d69e60cca2964006fb7ce32c556
Author: Eric Anholt <eric at anholt.net>
Date:   Fri Dec 27 20:53:00 2013 -0800

    xv: Remove dead VIDEO_INVERT_CLIPLIST from the xorg and kdrive DDXes.
    
    As far as I can see (looking at trees on my disk, plus googling for
    the term), nothing has ever used this flag
    
    Signed-off-by: Eric Anholt <eric at anholt.net>
    Reviewed-by: Keith Packard <keithp at keithp.com>

diff --git a/hw/kdrive/src/kxv.c b/hw/kdrive/src/kxv.c
index 60a8345..f808fb0 100644
--- a/hw/kdrive/src/kxv.c
+++ b/hw/kdrive/src/kxv.c
@@ -588,10 +588,6 @@ KdXVRegetVideo(XvPortRecPrivatePtr portPriv)
         goto CLIP_VIDEO_BAILOUT;
     }
 
-    if (portPriv->AdaptorRec->flags & VIDEO_INVERT_CLIPLIST) {
-        RegionSubtract(&ClipRegion, &WinRegion, &ClipRegion);
-    }
-
     ret = (*portPriv->AdaptorRec->GetVideo) (portPriv->screen, portPriv->pDraw,
                                              portPriv->vid_x, portPriv->vid_y,
                                              WinBox.x1, WinBox.y1,
@@ -680,10 +676,6 @@ KdXVReputVideo(XvPortRecPrivatePtr portPriv)
         }
     }
 
-    if (portPriv->AdaptorRec->flags & VIDEO_INVERT_CLIPLIST) {
-        RegionSubtract(&ClipRegion, &WinRegion, &ClipRegion);
-    }
-
     ret = (*portPriv->AdaptorRec->PutVideo) (portPriv->screen, portPriv->pDraw,
                                              portPriv->vid_x, portPriv->vid_y,
                                              WinBox.x1, WinBox.y1,
@@ -772,10 +764,6 @@ KdXVReputImage(XvPortRecPrivatePtr portPriv)
         }
     }
 
-    if (portPriv->AdaptorRec->flags & VIDEO_INVERT_CLIPLIST) {
-        RegionSubtract(&ClipRegion, &WinRegion, &ClipRegion);
-    }
-
     ret =
         (*portPriv->AdaptorRec->ReputImage) (portPriv->screen, portPriv->pDraw,
                                              WinBox.x1, WinBox.y1, &ClipRegion,
@@ -1274,10 +1262,6 @@ KdXVPutStill(ClientPtr client,
         }
     }
 
-    if (portPriv->AdaptorRec->flags & VIDEO_INVERT_CLIPLIST) {
-        RegionSubtract(&ClipRegion, &WinRegion, &ClipRegion);
-    }
-
     ret = (*portPriv->AdaptorRec->PutStill) (portPriv->screen, pDraw,
                                              vid_x, vid_y, WinBox.x1, WinBox.y1,
                                              vid_w, vid_h, drw_w, drw_h,
@@ -1410,10 +1394,6 @@ KdXVGetStill(ClientPtr client,
         goto GET_STILL_BAILOUT;
     }
 
-    if (portPriv->AdaptorRec->flags & VIDEO_INVERT_CLIPLIST) {
-        RegionSubtract(&ClipRegion, &WinRegion, &ClipRegion);
-    }
-
     ret = (*portPriv->AdaptorRec->GetStill) (portPriv->screen, pDraw,
                                              vid_x, vid_y, WinBox.x1, WinBox.y1,
                                              vid_w, vid_h, drw_w, drw_h,
@@ -1572,10 +1552,6 @@ KdXVPutImage(ClientPtr client,
         }
     }
 
-    if (portPriv->AdaptorRec->flags & VIDEO_INVERT_CLIPLIST) {
-        RegionSubtract(&ClipRegion, &WinRegion, &ClipRegion);
-    }
-
     ret = (*portPriv->AdaptorRec->PutImage) (portPriv->screen, pDraw,
                                              src_x, src_y, WinBox.x1, WinBox.y1,
                                              src_w, src_h, drw_w, drw_h,
diff --git a/hw/kdrive/src/kxv.h b/hw/kdrive/src/kxv.h
index 3a49a65..adedbda 100644
--- a/hw/kdrive/src/kxv.h
+++ b/hw/kdrive/src/kxv.h
@@ -51,7 +51,6 @@ of the copyright holder.
 #include "../../Xext/xvdix.h"
 
 #define VIDEO_NO_CLIPPING			0x00000001
-#define VIDEO_INVERT_CLIPLIST			0x00000002
 #define VIDEO_OVERLAID_IMAGES			0x00000004
 #define VIDEO_OVERLAID_STILLS			0x00000008
 #define VIDEO_CLIP_TO_VIEWPORT			0x00000010
diff --git a/hw/xfree86/common/xf86xv.c b/hw/xfree86/common/xf86xv.c
index e212a73..bb91758 100644
--- a/hw/xfree86/common/xf86xv.c
+++ b/hw/xfree86/common/xf86xv.c
@@ -712,10 +712,6 @@ xf86XVRegetVideo(XvPortRecPrivatePtr portPriv)
         goto CLIP_VIDEO_BAILOUT;
     }
 
-    if (portPriv->AdaptorRec->flags & VIDEO_INVERT_CLIPLIST) {
-        RegionSubtract(&ClipRegion, &WinRegion, &ClipRegion);
-    }
-
     ret = (*portPriv->AdaptorRec->GetVideo) (portPriv->pScrn,
                                              portPriv->vid_x, portPriv->vid_y,
                                              WinBox.x1, WinBox.y1,
@@ -800,10 +796,6 @@ xf86XVReputVideo(XvPortRecPrivatePtr portPriv)
         }
     }
 
-    if (portPriv->AdaptorRec->flags & VIDEO_INVERT_CLIPLIST) {
-        RegionSubtract(&ClipRegion, &WinRegion, &ClipRegion);
-    }
-
     ret = (*portPriv->AdaptorRec->PutVideo) (portPriv->pScrn,
                                              portPriv->vid_x, portPriv->vid_y,
                                              WinBox.x1, WinBox.y1,
@@ -894,10 +886,6 @@ xf86XVReputImage(XvPortRecPrivatePtr portPriv)
         }
     }
 
-    if (portPriv->AdaptorRec->flags & VIDEO_INVERT_CLIPLIST) {
-        RegionSubtract(&ClipRegion, &WinRegion, &ClipRegion);
-    }
-
     ret = (*portPriv->AdaptorRec->ReputImage) (portPriv->pScrn,
                                                portPriv->vid_x, portPriv->vid_y,
                                                WinBox.x1, WinBox.y1,
@@ -1491,10 +1479,6 @@ xf86XVPutStill(ClientPtr client,
         }
     }
 
-    if (portPriv->AdaptorRec->flags & VIDEO_INVERT_CLIPLIST) {
-        RegionSubtract(&ClipRegion, &WinRegion, &ClipRegion);
-    }
-
     ret = (*portPriv->AdaptorRec->PutStill) (portPriv->pScrn,
                                              vid_x, vid_y, WinBox.x1, WinBox.y1,
                                              vid_w, vid_h, drw_w, drw_h,
@@ -1628,10 +1612,6 @@ xf86XVGetStill(ClientPtr client,
         goto GET_STILL_BAILOUT;
     }
 
-    if (portPriv->AdaptorRec->flags & VIDEO_INVERT_CLIPLIST) {
-        RegionSubtract(&ClipRegion, &WinRegion, &ClipRegion);
-    }
-
     ret = (*portPriv->AdaptorRec->GetStill) (portPriv->pScrn,
                                              vid_x, vid_y, WinBox.x1, WinBox.y1,
                                              vid_w, vid_h, drw_w, drw_h,
@@ -1791,10 +1771,6 @@ xf86XVPutImage(ClientPtr client,
         }
     }
 
-    if (portPriv->AdaptorRec->flags & VIDEO_INVERT_CLIPLIST) {
-        RegionSubtract(&ClipRegion, &WinRegion, &ClipRegion);
-    }
-
     ret = (*portPriv->AdaptorRec->PutImage) (portPriv->pScrn,
                                              src_x, src_y, WinBox.x1, WinBox.y1,
                                              src_w, src_h, drw_w, drw_h,
diff --git a/hw/xfree86/common/xf86xv.h b/hw/xfree86/common/xf86xv.h
index de17eb1..fc6cf5d 100644
--- a/hw/xfree86/common/xf86xv.h
+++ b/hw/xfree86/common/xf86xv.h
@@ -33,7 +33,6 @@
 #include "xf86str.h"
 
 #define VIDEO_NO_CLIPPING			0x00000001
-#define VIDEO_INVERT_CLIPLIST			0x00000002
 #define VIDEO_OVERLAID_IMAGES			0x00000004
 #define VIDEO_OVERLAID_STILLS			0x00000008
 /*
diff --git a/hw/xfree86/doc/ddxDesign.xml b/hw/xfree86/doc/ddxDesign.xml
index fcf2228..969fb0f 100644
--- a/hw/xfree86/doc/ddxDesign.xml
+++ b/hw/xfree86/doc/ddxDesign.xml
@@ -4558,16 +4558,6 @@ as follows:
 		</varlistentry>
 
 		<varlistentry>
-		  <term><constant>VIDEO_INVERT_CLIPLIST</constant></term>
-		  <listitem><para>
-	   This indicates that the video driver requires the clip
-	   list to contain the regions which are obscured rather
-	   than the regions which are are visible.
-		    </para></listitem>
-
-		</varlistentry>
-
-		<varlistentry>
 		  <term><constant>VIDEO_OVERLAID_STILLS</constant></term>
 		  <listitem><para>
 	   Implementing PutStill for hardware that does video as an
@@ -4733,9 +4723,6 @@ as follows:
 	<literal remap="tt">drw_w</literal> and <literal remap="tt">drw_h</literal> in the Get/Put
 	function.  The boxes are in screen coordinates, are guaranteed
 	not to overlap and an empty region will never be passed.
-	If the driver has specified <constant>VIDEO_INVERT_CLIPLIST</constant>,
-	<literal remap="tt">clipBoxes</literal> will indicate the areas of the primitive
-	which are obscured rather than the areas visible.
 
 	    </para></listitem></varlistentry>
       </variablelist>
commit e6c8c7e46c79b2837a7d0b12079a47734eff1eb7
Author: Egbert Eich <eich at freedesktop.org>
Date:   Mon Aug 4 19:16:30 2014 +0200

    BellProc: Send bell event on core protocol bell when requested
    
    XKB allows to override the BellProc() ringing the 'keyboard bell':
    instead an event is sent to an X client which can perform an
    appropriate action.
    In most cases this effectively prevents the core protocol bell
    from ringing: if no BellProc() is set for the device, no attempt
    is made to ring a bell.
    This patch ensures that an XKB bell event is sent also when
    the core protocol bell is rung end thus an appropriate action
    can be taken by a client.
    
    Signed-off-by: Egbert Eich <eich at freedesktop.org>
    Acked-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 7f079ff..5d26fae 100644
--- a/dix/devices.c
+++ b/dix/devices.c
@@ -2257,7 +2257,7 @@ ProcBell(ClientPtr client)
     for (dev = inputInfo.devices; dev; dev = dev->next) {
         if ((dev == keybd ||
              (!IsMaster(dev) && GetMaster(dev, MASTER_KEYBOARD) == keybd)) &&
-            dev->kbdfeed && dev->kbdfeed->BellProc) {
+            ((dev->kbdfeed && dev->kbdfeed->BellProc) || dev->xkb_interest)) {
 
             rc = XaceHook(XACE_DEVICE_ACCESS, client, dev, DixBellAccess);
             if (rc != Success)
commit e8373e4b6a793b48487b1a82d798d97b5c9a10a3
Author: Keith Packard <keithp at keithp.com>
Date:   Thu Jul 31 19:57:53 2014 -0700

    Add X_BYTE_ORDER to xorg-server.h
    
    Drivers don't get to use dix-config.h, they use xorg-server.h
    instead. Add X_BYTE_ORDER to that file so drivers can see the value.
    
    Signed-off-by: Keith Packard <keithp at keithp.com>
    Reviewed-by: Michel Dänzer <michel.daenzer at amd.com>

diff --git a/include/xorg-server.h.in b/include/xorg-server.h.in
index 09b79b6..4cb9487 100644
--- a/include/xorg-server.h.in
+++ b/include/xorg-server.h.in
@@ -231,4 +231,7 @@
 /* Ask fontsproto to make font path element names const */
 #define FONT_PATH_ELEMENT_NAME_CONST    1
 
+/* byte order */
+#undef X_BYTE_ORDER
+
 #endif /* _XORG_SERVER_H_ */
commit e31564e1a21e73f4d20d6471da4fc7a9b63e4062
Author: Michel Dänzer <michel at daenzer.net>
Date:   Thu Jul 31 08:35:13 2014 -0700

    Check for dix-config.h or xorg-server.h before using X_BYTE_ORDER
    
    Now that servermd.h depends on X_BYTE_ORDER being defined in
    dix-config.h or xorg-server.h, check to make sure one of those has
    been included before using the value.
    
    Reviewed-by: Keith Packard <keithp at keithp.com>
    Signed-off-by: Keith Packard <keithp at keithp.com>

diff --git a/include/servermd.h b/include/servermd.h
index 0132d67..c88a542 100644
--- a/include/servermd.h
+++ b/include/servermd.h
@@ -47,7 +47,10 @@ SOFTWARE.
 #ifndef SERVERMD_H
 #define SERVERMD_H 1
 
-#include "dix-config.h"
+#if !defined(_DIX_CONFIG_H_) && !defined(_XORG_SERVER_H_)
+#error Drivers must include xorg-server.h before any other xserver headers
+#error xserver code must include dix-config.h before any other headers
+#endif
 
 #if X_BYTE_ORDER == X_LITTLE_ENDIAN
 #define IMAGE_BYTE_ORDER        LSBFirst
commit 61afe950e6a1a640ad9c5368549914ea32b90d48
Author: Keith Packard <keithp at keithp.com>
Date:   Mon Jul 21 19:27:20 2014 -0700

    xfree86/modes: rotation damage is automatically destroyed on close
    
    Don't try to destroy rotation_damage in the xf86RotateCloseScreen; it
    will have been destroyed when the screen pixmap was destroyed.
    
    Signed-off-by: Keith Packard <keithp at keithp.com>
    Reviewed-by: Eric Anholt <eric at anholt.net>

diff --git a/hw/xfree86/modes/xf86Rotate.c b/hw/xfree86/modes/xf86Rotate.c
index 54cbf2e..9c00a44 100644
--- a/hw/xfree86/modes/xf86Rotate.c
+++ b/hw/xfree86/modes/xf86Rotate.c
@@ -309,6 +309,8 @@ xf86RotateCloseScreen(ScreenPtr screen)
     xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(scrn);
     int c;
 
+    /* This has already been destroyed when the root window was destroyed */
+    xf86_config->rotation_damage = NULL;
     for (c = 0; c < xf86_config->num_crtc; c++)
         xf86RotateDestroy(xf86_config->crtc[c]);
 }
commit 40dc81154ad38514793f2181447d597b57d39e80
Author: Keith Packard <keithp at keithp.com>
Date:   Sun Jul 20 18:57:42 2014 -0700

    present: Avoid crash at server shutdown
    
    When a present flip operation is still in process during server reset,
    the call to present_set_abort_flip may not happen until the screen is
    being closed, at which point there is no root window to set pixmaps
    for. Check to make sure there's a window before resetting window pixmaps.
    
    Signed-off-by: Keith Packard <keithp at keithp.com>
    Reviewed-by: Eric Anholt <eric at anholt.net>

diff --git a/present/present.c b/present/present.c
index f624e5b..f488e21 100644
--- a/present/present.c
+++ b/present/present.c
@@ -399,7 +399,8 @@ present_set_abort_flip(ScreenPtr screen)
         present_set_tree_pixmap(screen_priv->flip_window,
                                   (*screen->GetScreenPixmap)(screen));
 
-    present_set_tree_pixmap(screen->root, (*screen->GetScreenPixmap)(screen));
+    if (screen->root)
+        present_set_tree_pixmap(screen->root, (*screen->GetScreenPixmap)(screen));
 
     screen_priv->flip_pending->abort_flip = TRUE;
 }
commit 627bce80894647c681b146a709aad4c390b4374e
Author: Keith Packard <keithp at keithp.com>
Date:   Sun Jul 20 18:53:52 2014 -0700

    present: Make window MSC offset 0 initially
    
    The MSC offset used by a window is adjusted as the window moves
    between screens, and between shown/unshown. The value shouldn't
    matter, but it's helpful for debugging to have window MSC values be
    the same as the CRTC MSC at first.
    
    This patch introduces a unique CRTC value so that Present can detect
    the first time a window is a PresentPixmap destination and set the MSC
    offset to zero, rather than using the fake MSC value as the previous
    window MSC.
    
    Signed-off-by: Keith Packard <keithp at keithp.com>
    Reviewed-by: Eric Anholt <eric at anholt.net>

diff --git a/present/present.c b/present/present.c
index 3aea0d7..f624e5b 100644
--- a/present/present.c
+++ b/present/present.c
@@ -291,14 +291,18 @@ present_window_to_crtc_msc(WindowPtr window, RRCrtcPtr crtc, uint64_t window_msc
     if (crtc != window_priv->crtc) {
         uint64_t        old_ust, old_msc;
 
-        /* The old CRTC may have been turned off, in which case
-         * we'll just use whatever previous MSC we'd seen from this CRTC
-         */
+        if (window_priv->crtc == PresentCrtcNeverSet) {
+            window_priv->msc_offset = 0;
+        } else {
+            /* The old CRTC may have been turned off, in which case
+             * we'll just use whatever previous MSC we'd seen from this CRTC
+             */
 
-        if (present_get_ust_msc(window->drawable.pScreen, window_priv->crtc, &old_ust, &old_msc) != Success)
-            old_msc = window_priv->msc;
+            if (present_get_ust_msc(window->drawable.pScreen, window_priv->crtc, &old_ust, &old_msc) != Success)
+                old_msc = window_priv->msc;
 
-        window_priv->msc_offset += new_msc - old_msc;
+            window_priv->msc_offset += new_msc - old_msc;
+        }
         window_priv->crtc = crtc;
     }
 
@@ -725,7 +729,7 @@ present_pixmap(WindowPtr window,
         if (!pixmap)
             target_crtc = window_priv->crtc;
 
-        if (!target_crtc)
+        if (!target_crtc || target_crtc == PresentCrtcNeverSet)
             target_crtc = present_get_crtc(window);
     }
 
diff --git a/present/present_priv.h b/present/present_priv.h
index d8569a2..f5c1652 100644
--- a/present/present_priv.h
+++ b/present/present_priv.h
@@ -134,6 +134,8 @@ typedef struct present_window_priv {
     struct xorg_list       notifies;
 } present_window_priv_rec, *present_window_priv_ptr;
 
+#define PresentCrtcNeverSet     ((RRCrtcPtr) 1)
+
 extern DevPrivateKeyRec present_window_private_key;
 
 static inline present_window_priv_ptr
diff --git a/present/present_screen.c b/present/present_screen.c
index 25ef681..2f91ac7 100644
--- a/present/present_screen.c
+++ b/present/present_screen.c
@@ -45,6 +45,7 @@ present_get_window_priv(WindowPtr window, Bool create)
         return NULL;
     xorg_list_init(&window_priv->vblank);
     xorg_list_init(&window_priv->notifies);
+    window_priv->crtc = PresentCrtcNeverSet;
     dixSetPrivate(&window->devPrivates, &present_window_private_key, window_priv);
     return window_priv;
 }
commit bd4198b01f2baf2284e61ea7ebf4600f554800e9
Author: Keith Packard <keithp at keithp.com>
Date:   Fri Jul 18 11:19:01 2014 -0700

    xfree86: Avoid compiler warning for unused vars without systemd
    
    When systemd isn't being used, systemd_logind_release_fd is defined
    as an empty macro, leaving the arguments unused. Fix the compiler
    warnings by simply removing the local variables and referencing the
    structure within the macro call.
    
    Signed-off-by: Keith Packard <keithp at keithp.com>
    Reviewed-by: Eric Anholt <eric at anholt.net>

diff --git a/hw/xfree86/common/xf86platformBus.c b/hw/xfree86/common/xf86platformBus.c
index 22e4603..9460399 100644
--- a/hw/xfree86/common/xf86platformBus.c
+++ b/hw/xfree86/common/xf86platformBus.c
@@ -348,7 +348,7 @@ static Bool doPlatformProbe(struct xf86_platform_device *dev, DriverPtr drvp,
                             GDevPtr gdev, int flags, intptr_t match_data)
 {
     Bool foundScreen = FALSE;
-    int entity, fd, major, minor;
+    int entity;
 
     if (gdev && gdev->screen == 0 && !xf86_check_platform_slot(dev))
         return FALSE;
@@ -374,10 +374,7 @@ static Bool doPlatformProbe(struct xf86_platform_device *dev, DriverPtr drvp,
     if (entity != -1) {
         if ((dev->flags & XF86_PDEV_SERVER_FD) && (!drvp->driverFunc ||
                 !drvp->driverFunc(NULL, SUPPORTS_SERVER_FDS, NULL))) {
-            fd = dev->attribs->fd;
-            major = dev->attribs->major;
-            minor = dev->attribs->minor;
-            systemd_logind_release_fd(major, minor, fd);
+            systemd_logind_release_fd(dev->attribs->major, dev->attribs->minor, dev->attribs->fd);
             dev->attribs->fd = -1;
             dev->flags &= ~XF86_PDEV_SERVER_FD;
         }
commit b063a185ab9d2c54669fb6e036fdbae3707c9e4b
Author: David Ung <davidu at nvidia.com>
Date:   Tue Jul 29 15:01:39 2014 -0700

    randr: Fix logic in RRPointerToNearestCrtc
    
    RRPointerToNearestCrtc is suppose to snap to the nearest Crtc,
    but best_x and best_y is always positive, hence when calling
    SetCursorPosition it will make the cursor even further away.
    Correct delta x/y to allow negative values and also use
    "width/height -1" in the calculation.  Also choose the closest
    Crtc by setting the "best" value.
    
    Signed-off-by: David Ung <davidu at nvidia.com>
    Reviewed-by: Keith Packard <keithp at keithp.com>
    Signed-off-by: Keith Packard <keithp at keithp.com>

diff --git a/randr/rrpointer.c b/randr/rrpointer.c
index eb6b677..b301d05 100644
--- a/randr/rrpointer.c
+++ b/randr/rrpointer.c
@@ -77,21 +77,22 @@ RRPointerToNearestCrtc(DeviceIntPtr pDev, ScreenPtr pScreen, int x, int y,
 
         if (x < crtc->x)
             dx = crtc->x - x;
-        else if (x > crtc->x + scan_width)
-            dx = x - (crtc->x + scan_width);
+        else if (x > crtc->x + scan_width - 1)
+            dx = crtc->x + (scan_width - 1) - x;
         else
             dx = 0;
         if (y < crtc->y)
             dy = crtc->y - y;
-        else if (y > crtc->y + scan_height)
-            dy = y - (crtc->y + scan_height);
+        else if (y > crtc->y + scan_height - 1)
+            dy = crtc->y + (scan_height - 1) - y;
         else
             dy = 0;
-        dist = dx + dy;
+        dist = dx * dx + dy * dy;
         if (!nearest || dist < best) {
             nearest = crtc;
             best_dx = dx;
             best_dy = dy;
+            best = dist;
         }
     }
     if (best_dx || best_dy)
commit 90803042bcbb9dc6261b5d112acf5613829d9f70
Author: Keith Packard <keithp at keithp.com>
Date:   Wed Jul 30 10:13:53 2014 -0700

    Fix files including xorg-server.h by mistake
    
    A few files in the server are including xorg-server.h, which is only
    for use by Xorg server drivers. This fixes those errors and then adds
    a check to make sure it doesn't happen again.
    
    Signed-off-by: Keith Packard <keithp at keithp.com>
    Reviewed-by: Adam Jackson <ajax at redhat.com>

diff --git a/dri3/dri3.h b/dri3/dri3.h
index edc7fa2..7562352 100644
--- a/dri3/dri3.h
+++ b/dri3/dri3.h
@@ -23,8 +23,6 @@
 #ifndef _DRI3_H_
 #define _DRI3_H_
 
-#include <xorg-server.h>
-
 #ifdef DRI3
 
 #include <X11/extensions/dri3proto.h>
diff --git a/glamor/glamor_egl.c b/glamor/glamor_egl.c
index 54af275..182e2e8 100644
--- a/glamor/glamor_egl.c
+++ b/glamor/glamor_egl.c
@@ -30,7 +30,6 @@
 #include "dix-config.h"
 
 #define GLAMOR_FOR_XORG
-#include <xorg-server.h>
 #include <unistd.h>
 #include <fcntl.h>
 #include <sys/ioctl.h>
diff --git a/glamor/glamor_eglmodule.c b/glamor/glamor_eglmodule.c
index d7e1836..dd4664b 100644
--- a/glamor/glamor_eglmodule.c
+++ b/glamor/glamor_eglmodule.c
@@ -29,7 +29,6 @@
 
 #include "dix-config.h"
 
-#include <xorg-server.h>
 #include <xf86.h>
 #define GLAMOR_FOR_XORG
 #include <xf86Module.h>
diff --git a/glamor/glamor_priv.h b/glamor/glamor_priv.h
index 57a4687..385c027 100644
--- a/glamor/glamor_priv.h
+++ b/glamor/glamor_priv.h
@@ -29,7 +29,6 @@
 
 #include "dix-config.h"
 
-#include <xorg-server.h>
 #include "glamor.h"
 #include "xvdix.h"
 
diff --git a/hw/xwayland/xwayland.h b/hw/xwayland/xwayland.h
index fc68550..60b0c29 100644
--- a/hw/xwayland/xwayland.h
+++ b/hw/xwayland/xwayland.h
@@ -27,7 +27,6 @@
 #define XWAYLAND_H
 
 #include <dix-config.h>
-#include <xorg-server.h>
 
 #include <stdio.h>
 #include <unistd.h>
diff --git a/include/xorg-server.h.in b/include/xorg-server.h.in
index 8bf9d38..09b79b6 100644
--- a/include/xorg-server.h.in
+++ b/include/xorg-server.h.in
@@ -16,6 +16,10 @@
 #ifndef _XORG_SERVER_H_
 #define _XORG_SERVER_H_
 
+#ifdef HAVE_XORG_CONFIG_H
+#error Include xorg-config.h when building the X server
+#endif
+
 /* Support BigRequests extension */
 #undef BIGREQS
 
commit a08e7a098aa37351294a25fe62b7ff6e95622e64
Author: Adam Jackson <ajax at redhat.com>
Date:   Tue Jun 24 14:21:57 2014 -0400

    dri1: Remove unused DRI{,Post}ValidateTree
    
    i810, mga, savage, and tdfx do reference these slots, but only to set
    them to NULL, so while this does have API impact it's not actually used.
    
    Reviewed-by: Keith Packard <keithp at keithp.com>
    Signed-off-by: Adam Jackson <ajax at redhat.com>

diff --git a/hw/xfree86/dri/dri.c b/hw/xfree86/dri/dri.c
index 95828bb..3f2f6a9 100644
--- a/hw/xfree86/dri/dri.c
+++ b/hw/xfree86/dri/dri.c
@@ -595,14 +595,6 @@ DRIFinishScreenInit(ScreenPtr pScreen)
     DRIInfoPtr pDRIInfo = pDRIPriv->pDriverInfo;
 
     /* Wrap DRI support */
-    if (pDRIInfo->wrap.ValidateTree) {
-        pDRIPriv->wrap.ValidateTree = pScreen->ValidateTree;
-        pScreen->ValidateTree = pDRIInfo->wrap.ValidateTree;
-    }
-    if (pDRIInfo->wrap.PostValidateTree) {
-        pDRIPriv->wrap.PostValidateTree = pScreen->PostValidateTree;
-        pScreen->PostValidateTree = pDRIInfo->wrap.PostValidateTree;
-    }
     if (pDRIInfo->wrap.WindowExposures) {
         pDRIPriv->wrap.WindowExposures = pScreen->WindowExposures;
         pScreen->WindowExposures = pDRIInfo->wrap.WindowExposures;
@@ -652,14 +644,6 @@ DRICloseScreen(ScreenPtr pScreen)
 
         if (pDRIPriv->wrapped) {
             /* Unwrap DRI Functions */
-            if (pDRIInfo->wrap.ValidateTree) {
-                pScreen->ValidateTree = pDRIPriv->wrap.ValidateTree;
-                pDRIPriv->wrap.ValidateTree = NULL;
-            }
-            if (pDRIInfo->wrap.PostValidateTree) {
-                pScreen->PostValidateTree = pDRIPriv->wrap.PostValidateTree;
-                pDRIPriv->wrap.PostValidateTree = NULL;
-            }
             if (pDRIInfo->wrap.WindowExposures) {
                 pScreen->WindowExposures = pDRIPriv->wrap.WindowExposures;
                 pDRIPriv->wrap.WindowExposures = NULL;
@@ -1601,8 +1585,6 @@ DRICreateInfoRec(void)
     inforec->wrap.BlockHandler = DRIDoBlockHandler;
     inforec->wrap.WindowExposures = DRIWindowExposures;
     inforec->wrap.CopyWindow = DRICopyWindow;
-    inforec->wrap.ValidateTree = DRIValidateTree;
-    inforec->wrap.PostValidateTree = DRIPostValidateTree;
     inforec->wrap.ClipNotify = DRIClipNotify;
     inforec->wrap.AdjustFrame = DRIAdjustFrame;
 
@@ -2064,61 +2046,6 @@ DRILockTree(ScreenPtr pScreen)
     }
 }
 
-int
-DRIValidateTree(WindowPtr pParent, WindowPtr pChild, VTKind kind)
-{
-    ScreenPtr pScreen = pParent->drawable.pScreen;
-    DRIScreenPrivPtr pDRIPriv = DRI_SCREEN_PRIV(pScreen);
-
-    int returnValue = 1;        /* always return 1, not checked by dix/window.c */
-
-    if (!pDRIPriv)
-        return returnValue;
-
-    /* call lower wrapped functions */
-    if (pDRIPriv->wrap.ValidateTree) {
-        /* unwrap */
-        pScreen->ValidateTree = pDRIPriv->wrap.ValidateTree;
-
-        /* call lower layers */
-        returnValue = (*pScreen->ValidateTree) (pParent, pChild, kind);
-
-        /* rewrap */
-        pDRIPriv->wrap.ValidateTree = pScreen->ValidateTree;
-        pScreen->ValidateTree = DRIValidateTree;
-    }
-
-    return returnValue;
-}
-
-void
-DRIPostValidateTree(WindowPtr pParent, WindowPtr pChild, VTKind kind)
-{
-    ScreenPtr pScreen;
-    DRIScreenPrivPtr pDRIPriv;
-
-    if (pParent) {
-        pScreen = pParent->drawable.pScreen;
-    }
-    else {
-        pScreen = pChild->drawable.pScreen;
-    }
-    if (!(pDRIPriv = DRI_SCREEN_PRIV(pScreen)))
-        return;
-
-    if (pDRIPriv->wrap.PostValidateTree) {
-        /* unwrap */
-        pScreen->PostValidateTree = pDRIPriv->wrap.PostValidateTree;
-
-        /* call lower layers */
-        (*pScreen->PostValidateTree) (pParent, pChild, kind);
-
-        /* rewrap */
-        pDRIPriv->wrap.PostValidateTree = pScreen->PostValidateTree;
-        pScreen->PostValidateTree = DRIPostValidateTree;
-    }
-}
-
 void
 DRIClipNotify(WindowPtr pWin, int dx, int dy)
 {
diff --git a/hw/xfree86/dri/dri.h b/hw/xfree86/dri/dri.h
index 64cd7c9..dec6885 100644
--- a/hw/xfree86/dri/dri.h
+++ b/hw/xfree86/dri/dri.h
@@ -85,8 +85,6 @@ typedef struct {
     ScreenBlockHandlerProcPtr BlockHandler;
     WindowExposuresProcPtr WindowExposures;
     CopyWindowProcPtr CopyWindow;
-    ValidateTreeProcPtr ValidateTree;
-    PostValidateTreeProcPtr PostValidateTree;
     ClipNotifyProcPtr ClipNotify;
     AdjustFramePtr AdjustFrame;
 } DRIWrappedFuncsRec, *DRIWrappedFuncsPtr;
@@ -290,12 +288,6 @@ extern _X_EXPORT Bool DRIDestroyWindow(WindowPtr pWin);
 extern _X_EXPORT void DRICopyWindow(WindowPtr pWin,
                                     DDXPointRec ptOldOrg, RegionPtr prgnSrc);
 
-extern _X_EXPORT int DRIValidateTree(WindowPtr pParent,
-                                     WindowPtr pChild, VTKind kind);
-
-extern _X_EXPORT void DRIPostValidateTree(WindowPtr pParent,
-                                          WindowPtr pChild, VTKind kind);
-
 extern _X_EXPORT void DRIClipNotify(WindowPtr pWin, int dx, int dy);
 
 extern _X_EXPORT CARD32 DRIGetDrawableIndex(WindowPtr pWin);
commit 5486c834fa3eebd79a4811143e513d6a92b7e504
Author: Adam Jackson <ajax at redhat.com>
Date:   Tue Jun 24 14:16:55 2014 -0400

    xquartz: Remove unused DRI{,Post}ValidateTree
    
    Cargo-culted from DRI1, not actually used for anything.
    
    Reviewed-by: Jeremy Huddleston Sequoia <jeremyhu at apple.com>
    Reviewed-by: Keith Packard <keithp at keithp.com>
    Signed-off-by: Adam Jackson <ajax at redhat.com>

diff --git a/hw/xquartz/xpr/dri.c b/hw/xquartz/xpr/dri.c
index 014709b..0f19047 100644
--- a/hw/xquartz/xpr/dri.c
+++ b/hw/xquartz/xpr/dri.c
@@ -138,12 +138,6 @@ DRIFinishScreenInit(ScreenPtr pScreen)
     DRIScreenPrivPtr pDRIPriv = DRI_SCREEN_PRIV(pScreen);
 
     /* Wrap DRI support */
-    pDRIPriv->wrap.ValidateTree = pScreen->ValidateTree;
-    pScreen->ValidateTree = DRIValidateTree;
-
-    pDRIPriv->wrap.PostValidateTree = pScreen->PostValidateTree;
-    pScreen->PostValidateTree = DRIPostValidateTree;
-
     pDRIPriv->wrap.WindowExposures = pScreen->WindowExposures;
     pScreen->WindowExposures = DRIWindowExposures;
 
@@ -624,51 +618,6 @@ DRICopyWindow(WindowPtr pWin, DDXPointRec ptOldOrg, RegionPtr prgnSrc)
     pScreen->CopyWindow = DRICopyWindow;
 }
 
-int
-DRIValidateTree(WindowPtr pParent, WindowPtr pChild, VTKind kind)
-{
-    ScreenPtr pScreen = pParent->drawable.pScreen;
-    DRIScreenPrivPtr pDRIPriv = DRI_SCREEN_PRIV(pScreen);
-    int returnValue;
-
-    /* unwrap */
-    pScreen->ValidateTree = pDRIPriv->wrap.ValidateTree;
-
-    /* call lower layers */
-    returnValue = (*pScreen->ValidateTree)(pParent, pChild, kind);
-
-    /* rewrap */
-    pScreen->ValidateTree = DRIValidateTree;
-
-    return returnValue;
-}
-
-void
-DRIPostValidateTree(WindowPtr pParent, WindowPtr pChild, VTKind kind)
-{
-    ScreenPtr pScreen;
-    DRIScreenPrivPtr pDRIPriv;
-
-    if (pParent) {
-        pScreen = pParent->drawable.pScreen;
-    }
-    else {
-        pScreen = pChild->drawable.pScreen;
-    }
-    pDRIPriv = DRI_SCREEN_PRIV(pScreen);
-
-    if (pDRIPriv->wrap.PostValidateTree) {
-        /* unwrap */
-        pScreen->PostValidateTree = pDRIPriv->wrap.PostValidateTree;
-
-        /* call lower layers */
-        (*pScreen->PostValidateTree)(pParent, pChild, kind);
-
-        /* rewrap */
-        pScreen->PostValidateTree = DRIPostValidateTree;
-    }
-}
-
 void
 DRIClipNotify(WindowPtr pWin, int dx, int dy)
 {
diff --git a/hw/xquartz/xpr/dri.h b/hw/xquartz/xpr/dri.h
index 70cb8b6..4476b06 100644
--- a/hw/xquartz/xpr/dri.h
+++ b/hw/xquartz/xpr/dri.h
@@ -53,8 +53,6 @@ typedef void (*ClipNotifyPtr)(WindowPtr, int, int);
 typedef struct {
     WindowExposuresProcPtr WindowExposures;
     CopyWindowProcPtr CopyWindow;
-    ValidateTreeProcPtr ValidateTree;
-    PostValidateTreeProcPtr PostValidateTree;
     ClipNotifyProcPtr ClipNotify;
 } DRIWrappedFuncsRec, *DRIWrappedFuncsPtr;
 
@@ -107,12 +105,6 @@ DRIGetWrappedFuncs(ScreenPtr pScreen);
 extern void
 DRICopyWindow(WindowPtr pWin, DDXPointRec ptOldOrg, RegionPtr prgnSrc);
 
-extern int
-DRIValidateTree(WindowPtr pParent, WindowPtr pChild, VTKind kind);
-
-extern void
-DRIPostValidateTree(WindowPtr pParent, WindowPtr pChild, VTKind kind);
-
 extern void
 DRIClipNotify(WindowPtr pWin, int dx, int dy);
 
commit a5e7701058c676231d2bc3f9a0c7c0fa9da7ad45
Author: Adam Jackson <ajax at redhat.com>
Date:   Wed May 28 14:48:14 2014 -0400

    xkb: Remove some fascinating paranoia from event emission
    
    XkbInterestPtrs are created by clients that already exist, meaning,
    clients that have already had ProcVector installed as something other
    than InitialProcVector.
    
    Reviewed-by: Daniel Stone <daniel at fooishbar.org>
    Signed-off-by: Adam Jackson <ajax at redhat.com>

diff --git a/xkb/xkbEvents.c b/xkb/xkbEvents.c
index 210d8eb..cc9a535 100644
--- a/xkb/xkbEvents.c
+++ b/xkb/xkbEvents.c
@@ -237,7 +237,6 @@ XkbSendStateNotify(DeviceIntPtr kbd, xkbStateNotify * pSN)
 
     while (interest) {
         if ((!interest->client->clientGone) &&
-            (interest->client->requestVector != InitialVector) &&
             (interest->client->xkbClientFlags & _XkbClientInitialized) &&
             (interest->stateNotifyMask & changed)) {
             pSN->sequenceNumber = interest->client->sequence;
@@ -400,7 +399,6 @@ XkbSendControlsNotify(DeviceIntPtr kbd, xkbControlsNotify * pCN)
     pCN->numGroups = xkbi->desc->ctrls->num_groups;
     while (interest) {
         if ((!interest->client->clientGone) &&
-            (interest->client->requestVector != InitialVector) &&
             (interest->client->xkbClientFlags & _XkbClientInitialized) &&
             (interest->ctrlsNotifyMask & changedControls)) {
             if (!initialized) {
@@ -447,7 +445,6 @@ XkbSendIndicatorNotify(DeviceIntPtr kbd, int xkbType, xkbIndicatorNotify * pEv)
     changed = pEv->changed;
     while (interest) {
         if ((!interest->client->clientGone) &&
-            (interest->client->requestVector != InitialVector) &&
             (interest->client->xkbClientFlags & _XkbClientInitialized) &&
             (((xkbType == XkbIndicatorStateNotify) &&
               (interest->iStateNotifyMask & changed)) ||
@@ -528,7 +525,6 @@ XkbHandleBell(BOOL force,
     initialized = 0;
     while (interest) {
         if ((!interest->client->clientGone) &&
-            (interest->client->requestVector != InitialVector) &&
             (interest->client->xkbClientFlags & _XkbClientInitialized) &&
             (interest->bellNotifyMask)) {
             if (!initialized) {
@@ -581,7 +577,6 @@ XkbSendAccessXNotify(DeviceIntPtr kbd, xkbAccessXNotify * pEv)
     db_delay = pEv->debounceDelay;
     while (interest) {
         if ((!interest->client->clientGone) &&
-            (interest->client->requestVector != InitialVector) &&
             (interest->client->xkbClientFlags & _XkbClientInitialized) &&
             (interest->accessXNotifyMask & (1 << pEv->detail))) {
             if (!initialized) {
@@ -627,7 +622,6 @@ XkbSendNamesNotify(DeviceIntPtr kbd, xkbNamesNotify * pEv)
     changedVirtualMods = pEv->changedVirtualMods;
     while (interest) {
         if ((!interest->client->clientGone) &&
-            (interest->client->requestVector != InitialVector) &&
             (interest->client->xkbClientFlags & _XkbClientInitialized) &&
             (interest->namesNotifyMask & pEv->changed)) {
             if (!initialized) {
@@ -671,7 +665,6 @@ XkbSendCompatMapNotify(DeviceIntPtr kbd, xkbCompatMapNotify * pEv)
     initialized = 0;
     while (interest) {
         if ((!interest->client->clientGone) &&
-            (interest->client->requestVector != InitialVector) &&
             (interest->client->xkbClientFlags & _XkbClientInitialized) &&
             (interest->compatNotifyMask)) {
             if (!initialized) {
@@ -722,7 +715,6 @@ XkbSendActionMessage(DeviceIntPtr kbd, xkbActionMessage * pEv)
     pEv->group = xkbi->state.group;
     while (interest) {
         if ((!interest->client->clientGone) &&
-            (interest->client->requestVector != InitialVector) &&
             (interest->client->xkbClientFlags & _XkbClientInitialized) &&
             (interest->actionMessageMask)) {
             if (!initialized) {
@@ -766,7 +758,6 @@ XkbSendExtensionDeviceNotify(DeviceIntPtr dev,
     state = pEv->ledState;
     while (interest) {
         if ((!interest->client->clientGone) &&
-            (interest->client->requestVector != InitialVector) &&
             (interest->client->xkbClientFlags & _XkbClientInitialized) &&
             (interest->extDevNotifyMask & reason)) {
             if (!initialized) {
commit ac3af4bd21394291ef6dd9cfcdd8ce6fceefec40
Author: Adam Jackson <ajax at redhat.com>
Date:   Tue Jun 17 12:58:41 2014 -0400

    xfree86: Remove unused HardEdges
    
    Reviewed-by: Alex Deucher <alexander.deucher at amd.com>
    Signed-off-by: Adam Jackson <ajax at redhat.com>

diff --git a/hw/xfree86/common/xf86Cursor.c b/hw/xfree86/common/xf86Cursor.c
index c6abf12..92c08af 100644
--- a/hw/xfree86/common/xf86Cursor.c
+++ b/hw/xfree86/common/xf86Cursor.c
@@ -74,8 +74,6 @@ static miPointerScreenFuncRec xf86PointerScreenFuncs = {
 
 static xf86ScreenLayoutRec xf86ScreenLayout[MAXSCREENS];
 
-static Bool HardEdges;
-
 /*
  * xf86InitViewport --
  *      Initialize paning & zooming parameters, so that a driver must only
@@ -429,16 +427,6 @@ xf86CursorOffScreen(ScreenPtr *pScreen, int *x, int *y)
         }
     }
 
-#if 0
-    /* This presents problems for overlapping screens when
-       HardEdges is used.  Have to think about the logic more */
-    if ((*x < 0) || (*x >= (*pScreen)->width) ||
-        (*y < 0) || (*y >= (*pScreen)->height)) {
-        /* We may have crossed more than one screen */
-        xf86CursorOffScreen(pScreen, x, y);
-    }
-#endif
-
     return TRUE;
 }
 
@@ -582,9 +570,6 @@ xf86InitOrigins(void)
     xf86ScreenLayoutPtr pLayout;
     Bool OldStyleConfig = FALSE;
 
-    /* need to have this set up with a config file option */
-    HardEdges = FALSE;
-
     memset(xf86ScreenLayout, 0, MAXSCREENS * sizeof(xf86ScreenLayoutRec));
 
     screensLeft = prevScreensLeft = (1 << xf86NumScreens) - 1;
@@ -836,7 +821,7 @@ xf86InitOrigins(void)
         }
     }
 
-    if (!HardEdges && !OldStyleConfig) {
+    if (!OldStyleConfig) {
         for (i = 0; i < xf86NumScreens; i++) {
             pLayout = &xf86ScreenLayout[i];
             pScreen = xf86Screens[i]->pScreen;
commit 4100687ea667970733c3aa69f704be0e3747f9fd
Author: Adam Jackson <ajax at redhat.com>
Date:   Mon Jun 23 15:42:23 2014 -0400

    xfree86: Remove useless #include "fb.h"
    
    Reviewed-by: Alex Deucher <alexander.deucher at amd.com>
    Signed-off-by: Adam Jackson <ajax at redhat.com>

diff --git a/hw/xfree86/modes/xf86Rotate.c b/hw/xfree86/modes/xf86Rotate.c
index 1627e61..54cbf2e 100644
--- a/hw/xfree86/modes/xf86Rotate.c
+++ b/hw/xfree86/modes/xf86Rotate.c
@@ -35,7 +35,6 @@
 
 #include "xf86.h"
 #include "xf86DDC.h"
-#include "fb.h"
 #include "windowstr.h"
 #include "xf86Crtc.h"
 #include "xf86Modes.h"
commit 2d451c5cdc7f81ea0c94c3542fab45027f829736
Author: Adam Jackson <ajax at redhat.com>
Date:   Thu May 22 14:04:16 2014 -0400

    xfree86: Remove pointless xf86RandRCreateScreenResources
    
    Given the #if 0 this was wrapping for no effect.
    
    Reviewed-by: Keith Packard <keithp at keithp.com>
    Signed-off-by: Adam Jackson <ajax at redhat.com>

diff --git a/hw/xfree86/common/xf86RandR.c b/hw/xfree86/common/xf86RandR.c
index 2418731..08f656b 100644
--- a/hw/xfree86/common/xf86RandR.c
+++ b/hw/xfree86/common/xf86RandR.c
@@ -37,7 +37,6 @@
 #include "inputstr.h"
 
 typedef struct _xf86RandRInfo {
-    CreateScreenResourcesProcPtr CreateScreenResources;
     CloseScreenProcPtr CloseScreen;
     int virtualX;
     int virtualY;
@@ -336,34 +335,6 @@ xf86RandRSetConfig(ScreenPtr pScreen,
 }
 
 /*
- * Wait until the screen is initialized before whacking the
- * sizes around; otherwise the screen pixmap will be allocated
- * at the current mode size rather than the maximum size
- */
-static Bool
-xf86RandRCreateScreenResources(ScreenPtr pScreen)
-{
-    XF86RandRInfoPtr randrp = XF86RANDRINFO(pScreen);
-
-#if 0
-    ScrnInfoPtr scrp = xf86ScreenToScrn(pScreen);
-    DisplayModePtr mode;
-#endif
-
-    pScreen->CreateScreenResources = randrp->CreateScreenResources;
-    if (!(*pScreen->CreateScreenResources) (pScreen))
-        return FALSE;
-
-#if 0
-    mode = scrp->currentMode;
-    if (mode)
-        xf86RandRSetMode(pScreen, mode, TRUE);
-#endif
-
-    return TRUE;
-}
-
-/*
  * Reset size back to original
  */
 static Bool
@@ -463,9 +434,6 @@ xf86RandRInit(ScreenPtr pScreen)
     randrp->mmWidth = pScreen->mmWidth;
     randrp->mmHeight = pScreen->mmHeight;
 
-    randrp->CreateScreenResources = pScreen->CreateScreenResources;
-    pScreen->CreateScreenResources = xf86RandRCreateScreenResources;
-
     randrp->CloseScreen = pScreen->CloseScreen;
     pScreen->CloseScreen = xf86RandRCloseScreen;
 
commit a8cca7bd5ad7ea36a9585f4927ed53cfa6db1daf
Author: Adam Jackson <ajax at redhat.com>
Date:   Fri May 2 11:43:14 2014 -0400

    xfree86: Remove protectMem from VidMemInfo
    
    Never filled in.
    
    Reviewed-by: Keith Packard <keithp at keithp.com>
    Signed-off-by: Adam Jackson <ajax at redhat.com>

diff --git a/hw/xfree86/os-support/xf86OSpriv.h b/hw/xfree86/os-support/xf86OSpriv.h
index 7f003e8..b56f45a 100644
--- a/hw/xfree86/os-support/xf86OSpriv.h
+++ b/hw/xfree86/os-support/xf86OSpriv.h
@@ -36,14 +36,12 @@ typedef void *(*MapMemProcPtr) (int, unsigned long, unsigned long, int);
 typedef void (*UnmapMemProcPtr) (int, void *, unsigned long);
 typedef void *(*SetWCProcPtr) (int, unsigned long, unsigned long, Bool,
                                  MessageType);
-typedef void (*ProtectMemProcPtr) (int, void *, unsigned long, Bool);
 typedef void (*UndoWCProcPtr) (int, void *);
 
 typedef struct {
     Bool initialised;
     MapMemProcPtr mapMem;
     UnmapMemProcPtr unmapMem;
-    ProtectMemProcPtr protectMem;
     SetWCProcPtr setWC;
     UndoWCProcPtr undoWC;
     Bool linearSupported;
commit e4cf1e58f5745dd39a9dd5eb29acd1cb28710094
Author: Adam Jackson <ajax at redhat.com>
Date:   Fri May 2 11:11:14 2014 -0400

    xfree86: Remove unused xf86{Map,Unmap}LegacyIO
    
    I ported these to pciaccess in:
    
        commit 858fbbb40d7c69540cd1fb5315cebf811c6e7b3f
        Author: Adam Jackson <ajax at redhat.com>
        Date:   Fri Sep 16 13:33:04 2011 -0400
    
            pci: Port xf86MapLegacyIO to pciaccess
    
    As of yet there are still no drivers using them, and there's not a lot
    of value in having the wrappers when they just trivially call pciaccess
    anyway.  Nuke 'em.
    
    Reviewed-by: Keith Packard <keithp at keithp.com>
    Signed-off-by: Adam Jackson <ajax at redhat.com>

diff --git a/hw/xfree86/common/xf86pciBus.c b/hw/xfree86/common/xf86pciBus.c
index 33fbd7f..e86ecb9 100644
--- a/hw/xfree86/common/xf86pciBus.c
+++ b/hw/xfree86/common/xf86pciBus.c
@@ -1473,15 +1473,3 @@ xf86PciConfigureNewDev(void *busData, struct pci_device *pVideo,
     if (*chipset < 0)
         *chipset = (pVideo->vendor_id << 16) | pVideo->device_id;
 }
-
-struct pci_io_handle *
-xf86MapLegacyIO(struct pci_device *dev)
-{
-    return pci_legacy_open_io(dev, 0, 64 * 1024);
-}
-
-void
-xf86UnmapLegacyIO(struct pci_device *dev, struct pci_io_handle *handle)
-{
-    pci_device_close_io(dev, handle);
-}
diff --git a/hw/xfree86/os-support/bus/xf86Pci.h b/hw/xfree86/os-support/bus/xf86Pci.h
index 5b34310..210ab3d 100644
--- a/hw/xfree86/os-support/bus/xf86Pci.h
+++ b/hw/xfree86/os-support/bus/xf86Pci.h
@@ -235,9 +235,4 @@
 /* Public PCI access functions */
 extern _X_EXPORT Bool xf86scanpci(void);
 
-/* Domain access functions.  Some of these probably shouldn't be public */
-extern _X_EXPORT struct pci_io_handle *xf86MapLegacyIO(struct pci_device *dev);
-extern _X_EXPORT void xf86UnmapLegacyIO(struct pci_device *,
-                                        struct pci_io_handle *);
-
 #endif                          /* _XF86PCI_H */
commit 96206cf47752af3fc8ca14dc1e03c59ed482167f
Author: Adam Jackson <ajax at redhat.com>
Date:   Tue Jul 8 13:19:08 2014 -0400

    xfree86: Remove deprecated PCI types
    
    Reviewed-by: Keith Packard <keithp at keithp.com>
    Signed-off-by: Adam Jackson <ajax at redhat.com>

diff --git a/hw/xfree86/os-support/bus/xf86Pci.h b/hw/xfree86/os-support/bus/xf86Pci.h
index 0397796..5b34310 100644
--- a/hw/xfree86/os-support/bus/xf86Pci.h
+++ b/hw/xfree86/os-support/bus/xf86Pci.h
@@ -232,10 +232,6 @@
  * Typedefs, etc...
  */
 
-/* Primitive Types */
-typedef unsigned long IOADDRESS _X_DEPRECATED;  /* Must be large enough for a pointer */
-typedef CARD32 PCITAG _X_DEPRECATED;
-
 /* Public PCI access functions */
 extern _X_EXPORT Bool xf86scanpci(void);
 
commit 46fd5a28ef7191b5ad0244f849c756dd2c5f43b6
Author: Adam Jackson <ajax at redhat.com>
Date:   Fri May 2 11:09:53 2014 -0400

    xfree86: Remove some unused pre-pciaccess types
    
    Reviewed-by: Keith Packard <keithp at keithp.com>
    Signed-off-by: Adam Jackson <ajax at redhat.com>

diff --git a/hw/xfree86/os-support/bus/xf86Pci.h b/hw/xfree86/os-support/bus/xf86Pci.h
index f69e55b..0397796 100644
--- a/hw/xfree86/os-support/bus/xf86Pci.h
+++ b/hw/xfree86/os-support/bus/xf86Pci.h
@@ -233,21 +233,9 @@
  */
 
 /* Primitive Types */
-typedef unsigned long ADDRESS;  /* Memory/PCI address */
 typedef unsigned long IOADDRESS _X_DEPRECATED;  /* Must be large enough for a pointer */
 typedef CARD32 PCITAG _X_DEPRECATED;
 
-typedef enum {
-    PCI_MEM,
-    PCI_MEM_SIZE,
-    PCI_MEM_SPARSE_BASE,
-    PCI_MEM_SPARSE_MASK,
-    PCI_IO,
-    PCI_IO_SIZE,
-    PCI_IO_SPARSE_BASE,
-    PCI_IO_SPARSE_MASK
-} PciAddrType;
-
 /* Public PCI access functions */
 extern _X_EXPORT Bool xf86scanpci(void);
 
commit 3bb9f9862b5bea3720ba7922714af729cab38776
Author: Adam Jackson <ajax at redhat.com>
Date:   Fri Feb 28 13:31:08 2014 -0500

    xfree86: Remove xf86ConfigActivePciEntity
    
    The giant OBSOLETE DO NOT USE comment has been there since 2000,
    probably it's safe to nuke by now.
    
    Reviewed-by: Alex Deucher <alexander.deucher at amd.com>
    Signed-off-by: Adam Jackson <ajax at redhat.com>

diff --git a/hw/xfree86/common/xf86.h b/hw/xfree86/common/xf86.h
index cec3135..49ff35b 100644
--- a/hw/xfree86/common/xf86.h
+++ b/hw/xfree86/common/xf86.h
@@ -129,14 +129,6 @@ extern _X_EXPORT ScrnInfoPtr xf86ConfigPciEntity(ScrnInfoPtr pScrn,
                                                  EntityProc enter,
                                                  EntityProc leave,
                                                  void *private);
-/* Obsolete! don't use */
-extern _X_EXPORT Bool xf86ConfigActivePciEntity(ScrnInfoPtr pScrn,
-                                                int entityIndex,
-                                                PciChipsets * p_chip,
-                                                void *dummy, EntityProc init,
-                                                EntityProc enter,
-                                                EntityProc leave,
-                                                void *private);
 #else
 #define xf86VGAarbiterInit() do {} while (0)
 #define xf86VGAarbiterFini() do {} while (0)
diff --git a/hw/xfree86/common/xf86pciBus.c b/hw/xfree86/common/xf86pciBus.c
index c06b040..33fbd7f 100644
--- a/hw/xfree86/common/xf86pciBus.c
+++ b/hw/xfree86/common/xf86pciBus.c
@@ -1061,33 +1061,6 @@ xf86ConfigPciEntity(ScrnInfoPtr pScrn, int scrnFlag, int entityIndex,
     return pScrn;
 }
 
-/*
- *  OBSOLETE ! xf86ConfigActivePciEntity() is an obsolete function.
- *             It is likely to be removed. Don't use!
- */
-Bool
-xf86ConfigActivePciEntity(ScrnInfoPtr pScrn, int entityIndex,
-                          PciChipsets * p_chip, void *dummy, EntityProc init,
-                          EntityProc enter, EntityProc leave, void *private)
-{
-    EntityInfoPtr pEnt = xf86GetEntityInfo(entityIndex);
-
-    if (!pEnt)
-        return FALSE;
-
-    if (!pEnt->active || !(pEnt->location.type == BUS_PCI)) {
-        free(pEnt);
-        return FALSE;
-    }
-    xf86AddEntityToScreen(pScrn, entityIndex);
-
-    free(pEnt);
-    if (!xf86SetEntityFuncs(entityIndex, init, enter, leave, private))
-        return FALSE;
-
-    return TRUE;
-}
-
 int
 xf86VideoPtrToDriverList(struct pci_device *dev,
                      char *returnList[], int returnListMax)
commit 51531a67179e342f6ad798de21accf014748a04f
Author: Adam Jackson <ajax at redhat.com>
Date:   Tue Jun 10 13:10:28 2014 -0400

    vgahw: Nuke unused vgaCmap.c
    
    Never been built since m12n, can't be needed.
    
    Reviewed-by: Keith Packard <keithp at keithp.com>
    Signed-off-by: Adam Jackson <ajax at redhat.com>

diff --git a/hw/xfree86/doc/ddxDesign.xml b/hw/xfree86/doc/ddxDesign.xml
index d1fd9af..fcf2228 100644
--- a/hw/xfree86/doc/ddxDesign.xml
+++ b/hw/xfree86/doc/ddxDesign.xml
@@ -9094,8 +9094,7 @@ ZZZScreenInit(ScreenPtr pScreen, int argc, char **argv)
     xf86SetBlackWhitePixels(pScreen);
 
     /*
-     * Install colourmap functions.  If using the vgahw module,
-     * vgaHandleColormaps would usually be called here.
+     * Install colourmap functions.
      */
 
     ...
diff --git a/hw/xfree86/vgahw/Makefile.am b/hw/xfree86/vgahw/Makefile.am
index 4b718b4..b8196a6 100644
--- a/hw/xfree86/vgahw/Makefile.am
+++ b/hw/xfree86/vgahw/Makefile.am
@@ -6,5 +6,3 @@ AM_CPPFLAGS = $(XORG_INCS) -I$(srcdir)/../ddc -I$(srcdir)/../i2c
 AM_CFLAGS = $(DIX_CFLAGS) $(XORG_CFLAGS)
 
 sdk_HEADERS = vgaHW.h
-
-EXTRA_DIST = vgaCmap.c
diff --git a/hw/xfree86/vgahw/vgaCmap.c b/hw/xfree86/vgahw/vgaCmap.c
deleted file mode 100644
index bf61225..0000000
--- a/hw/xfree86/vgahw/vgaCmap.c
+++ /dev/null
@@ -1,275 +0,0 @@
-/*
- * Copyright 1990,91 by Thomas Roell, Dinkelscherben, Germany.
- *
- * 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 Thomas Roell not be used in
- * advertising or publicity pertaining to distribution of the software without
- * specific, written prior permission.  Thomas Roell makes no representations
- * about the suitability of this software for any purpose.  It is provided
- * "as is" without express or implied warranty.
- *
- * THOMAS ROELL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
- * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
- * EVENT SHALL THOMAS ROELL 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 <X11/X.h>
-#include <X11/Xproto.h>
-#include "windowstr.h"
-#include "mipointer.h"
-#include "micmap.h"
-
-#include "xf86.h"
-#include "vgaHW.h"
-
-#include <X11/extensions/xf86dgaproto.h>
-#include "dgaproc.h"
-
-#define NOMAPYET        (ColormapPtr) 0
-
-int
-vgaListInstalledColormaps(pScreen, pmaps)
-ScreenPtr pScreen;
-Colormap *pmaps;
-{
-    /* By the time we are processing requests, we can guarantee that there
-     * is always a colormap installed */
-
-    *pmaps = GetInstalledmiColormap(pScreen)->mid;
-    return 1;
-}
-
-int
-vgaGetInstalledColormaps(pScreen, pmaps)
-ScreenPtr pScreen;
-ColormapPtr *pmaps;
-{
-    /* By the time we are processing requests, we can guarantee that there
-     * is always a colormap installed */
-
-    *pmaps = GetInstalledmiColormap(pScreen);
-    return 1;
-}
-
-int
-vgaCheckColorMap(ColormapPtr pmap)
-{
-    return (pmap != GetInstalledmiColormap(pmap->pScreen));
-}
-
-void
-vgaStoreColors(pmap, ndef, pdefs)
-ColormapPtr pmap;
-int ndef;
-xColorItem *pdefs;
-{
-    int i;
-    unsigned char *cmap, *tmp = NULL;
-    xColorItem directDefs[256];
-    Bool new_overscan = FALSE;
-    Bool writeColormap;
-    int scrnIndex = pmap->pScreen->myNum;
-    ScrnInfoPtr scrninfp = xf86ScreenToScrn(pmap->pScreen);
-    vgaHWPtr hwp = VGAHWPTR(scrninfp);
-
-    unsigned char overscan = hwp->ModeReg.Attribute[OVERSCAN];
-    unsigned char tmp_overscan = 0;
-
-    if (vgaCheckColorMap(pmap))
-        return;
-
-    if ((pmap->pVisual->class | DynamicClass) == DirectColor) {
-        ndef = miExpandDirectColors(pmap, ndef, pdefs, directDefs);
-        pdefs = directDefs;
-    }
-
-    writeColormap = scrninfp->vtSema;
-    if (DGAScreenAvailable(pmap->pScreen)) {
-        writeColormap = writeColormap ||
-            (DGAGetDirectMode(scrnIndex) &&
-             !(DGAGetFlags(scrnIndex) & XF86DGADirectColormap)) ||
-            (DGAGetFlags(scrnIndex) & XF86DGAHasColormap);
-    }
-
-    if (writeColormap)
-        hwp->enablePalette(hwp);
-
-    for (i = 0; i < ndef; i++) {
-        if (pdefs[i].pixel == overscan) {
-            new_overscan = TRUE;
-        }
-        cmap = &(hwp->ModeReg.DAC[pdefs[i].pixel * 3]);
-        if (scrninfp->rgbBits == 8) {
-            cmap[0] = pdefs[i].red >> 8;
-            cmap[1] = pdefs[i].green >> 8;
-            cmap[2] = pdefs[i].blue >> 8;
-        }
-        else {
-            cmap[0] = pdefs[i].red >> 10;
-            cmap[1] = pdefs[i].green >> 10;
-            cmap[2] = pdefs[i].blue >> 10;
-        }
-#if 0
-        if (clgd6225Lcd) {
-            /* The LCD doesn't like white */
-            if (cmap[0] == 63)
-                cmap[0] = 62;
-            if (cmap[1] == 63)
-                cmap[1] = 62;
-            if (cmap[2] == 63)
-                cmap[2] = 62;
-        }
-#endif
-
-        if (writeColormap) {
-            if (hwp->ShowOverscan && i == 255)
-                continue;
-            hwp->writeDacWriteAddr(hwp, pdefs[i].pixel);
-            DACDelay(hwp);
-            hwp->writeDacData(hwp, cmap[0]);
-            DACDelay(hwp);
-            hwp->writeDacData(hwp, cmap[1]);
-            DACDelay(hwp);
-            hwp->writeDacData(hwp, cmap[2]);
-            DACDelay(hwp);
-        }
-    }
-    if (new_overscan && !hwp->ShowOverscan) {
-        new_overscan = FALSE;
-        for (i = 0; i < ndef; i++) {
-            if (pdefs[i].pixel == overscan) {
-                if ((pdefs[i].red != 0) ||
-                    (pdefs[i].green != 0) || (pdefs[i].blue != 0)) {
-                    new_overscan = TRUE;
-                    tmp_overscan = overscan;
-                    tmp = &(hwp->ModeReg.DAC[pdefs[i].pixel * 3]);
-                }
-                break;
-            }
-        }
-        if (new_overscan) {
-            /*
-             * Find a black pixel, or the nearest match.
-             */
-            for (i = 255; i >= 0; i--) {
-                cmap = &(hwp->ModeReg.DAC[i * 3]);
-                if ((cmap[0] == 0) && (cmap[1] == 0) && (cmap[2] == 0)) {
-                    overscan = i;
-                    break;
-                }
-                else {
-                    if ((cmap[0] < tmp[0]) &&
-                        (cmap[1] < tmp[1]) && (cmap[2] < tmp[2])) {
-                        tmp = cmap;
-                        tmp_overscan = i;
-                    }
-                }
-            }
-            if (i < 0) {
-                overscan = tmp_overscan;
-            }
-            hwp->ModeReg.Attribute[OVERSCAN] = overscan;
-            if (writeColormap) {
-                hwp->writeAttr(hwp, OVERSCAN, overscan);
-            }
-        }
-    }
-
-    if (writeColormap)
-        hwp->disablePalette(hwp);
-}
-
-void
-vgaInstallColormap(pmap)
-ColormapPtr pmap;
-{
-    ColormapPtr oldmap = GetInstalledmiColormap(pmap->pScreen);
-    int entries;
-    Pixel *ppix;
-    xrgb *prgb;
-    xColorItem *defs;
-    int i;
-
-    if (pmap == oldmap)
-        return;
-
-    if ((pmap->pVisual->class | DynamicClass) == DirectColor)
-        entries = (pmap->pVisual->redMask |
-                   pmap->pVisual->greenMask | pmap->pVisual->blueMask) + 1;
-    else
-        entries = pmap->pVisual->ColormapEntries;
-
-    ppix = (Pixel *) malloc(entries * sizeof(Pixel));
-    prgb = (xrgb *) malloc(entries * sizeof(xrgb));
-    defs = (xColorItem *) malloc(entries * sizeof(xColorItem));
-
-    if (oldmap != NOMAPYET)
-        WalkTree(pmap->pScreen, TellLostMap, &oldmap->mid);
-
-    SetInstalledmiColormap(pmap->pScreen, pmap);
-
-    for (i = 0; i < entries; i++)
-        ppix[i] = i;
-
-    QueryColors(pmap, entries, ppix, prgb, serverClient);
-
-    for (i = 0; i < entries; i++) {     /* convert xrgbs to xColorItems */
-        defs[i].pixel = ppix[i];
-        defs[i].red = prgb[i].red;
-        defs[i].green = prgb[i].green;
-        defs[i].blue = prgb[i].blue;
-        defs[i].flags = DoRed | DoGreen | DoBlue;
-    }
-    pmap->pScreen->StoreColors(pmap, entries, defs);
-
-    WalkTree(pmap->pScreen, TellGainedMap, &pmap->mid);
-
-    free(ppix);
-    free(prgb);
-    free(defs);
-}
-
-void
-vgaUninstallColormap(pmap)
-ColormapPtr pmap;
-{
-
-    ColormapPtr defColormap;
-
-    if (pmap != GetInstalledmiColormap(pmap->pScreen))
-        return;
-
-    dixLookupResourceByType((void **) &defColormap,
-                            pmap->pScreen->defColormap, RT_COLORMAP,
-                            serverClient, DixInstallAccess);
-
-    if (defColormap == GetInstalledmiColormap(pmap->pScreen))
-        return;
-
-    (*pmap->pScreen->InstallColormap) (defColormap);
-}
-
-void
-vgaHandleColormaps(ScreenPtr pScreen, ScrnInfoPtr scrnp)
-{
-    if (scrnp->bitsPerPixel > 1) {
-        if (scrnp->bitsPerPixel <= 8) { /* For 8bpp SVGA and VGA16 */
-            pScreen->InstallColormap = vgaInstallColormap;
-            pScreen->UninstallColormap = vgaUninstallColormap;
-            pScreen->ListInstalledColormaps = vgaListInstalledColormaps;
-            pScreen->StoreColors = vgaStoreColors;
-        }
-    }
-}
commit 2db71b232c4756773562182cadb7ccdf5194a62d
Author: Adam Jackson <ajax at redhat.com>
Date:   Tue Jun 10 13:00:11 2014 -0400

    saver: Don't open-code IsMapInstalled
    
    Reviewed-by: Keith Packard <keithp at keithp.com>
    Signed-off-by: Adam Jackson <ajax at redhat.com>

diff --git a/Xext/saver.c b/Xext/saver.c
index 8e92fdf..2c14ea0 100644
--- a/Xext/saver.c
+++ b/Xext/saver.c
@@ -467,9 +467,6 @@ CreateSaverWindow(ScreenPtr pScreen)
     WindowPtr pWin;
     int result;
     unsigned long mask;
-    Colormap *installedMaps;
-    int numInstalled;
-    int i;
     Colormap wantMap;
     ColormapPtr pCmap;
 
@@ -545,18 +542,7 @@ CreateSaverWindow(ScreenPtr pScreen)
 
     /* check and install our own colormap if it isn't installed now */
     wantMap = wColormap(pWin);
-    if (wantMap == None)
-        return TRUE;
-    installedMaps = malloc(pScreen->maxInstalledCmaps * sizeof(Colormap));
-    numInstalled = (*pWin->drawable.pScreen->ListInstalledColormaps)
-        (pScreen, installedMaps);
-    for (i = 0; i < numInstalled; i++)
-        if (installedMaps[i] == wantMap)
-            break;
-
-    free((char *) installedMaps);
-
-    if (i < numInstalled)
+    if (wantMap == None || IsMapInstalled(wantMap, pWin))
         return TRUE;
 
     result = dixLookupResourceByType((void **) &pCmap, wantMap, RT_COLORMAP,
commit dd0e8491f75afbd72bea17172a042aa45ff7e30b
Author: Adam Jackson <ajax at redhat.com>
Date:   Fri Jun 20 12:36:10 2014 -0400

    render: Remove unused CopyPicture
    
    Arguably this would be useful API, but it's never called, and a careful
    reading of the CPClipMask path reveals that callers would be fairly
    disappointed.
    
    Reviewed-by: Keith Packard <keithp at keithp.com>
    Signed-off-by: Adam Jackson <ajax at redhat.com>

diff --git a/render/picture.c b/render/picture.c
index 7da9310..58535d4 100644
--- a/render/picture.c
+++ b/render/picture.c
@@ -1332,87 +1332,6 @@ SetPictureTransform(PicturePtr pPicture, PictTransform * transform)
     return Success;
 }
 
-void
-CopyPicture(PicturePtr pSrc, Mask mask, PicturePtr pDst)
-{
-    PictureScreenPtr ps = GetPictureScreen(pSrc->pDrawable->pScreen);
-    Mask origMask = mask;
-
-    pDst->serialNumber |= GC_CHANGE_SERIAL_BIT;
-    pDst->stateChanges |= mask;
-
-    while (mask) {
-        Mask bit = lowbit(mask);
-
-        switch (bit) {
-        case CPRepeat:
-            pDst->repeat = pSrc->repeat;
-            pDst->repeatType = pSrc->repeatType;
-            break;
-        case CPAlphaMap:
-            if (pSrc->alphaMap &&
-                pSrc->alphaMap->pDrawable->type == DRAWABLE_PIXMAP)
-                pSrc->alphaMap->refcnt++;
-            if (pDst->alphaMap)
-                FreePicture((void *) pDst->alphaMap, (XID) 0);
-            pDst->alphaMap = pSrc->alphaMap;
-            break;
-        case CPAlphaXOrigin:
-            pDst->alphaOrigin.x = pSrc->alphaOrigin.x;
-            break;
-        case CPAlphaYOrigin:
-            pDst->alphaOrigin.y = pSrc->alphaOrigin.y;
-            break;
-        case CPClipXOrigin:
-            pDst->clipOrigin.x = pSrc->clipOrigin.x;
-            break;
-        case CPClipYOrigin:
-            pDst->clipOrigin.y = pSrc->clipOrigin.y;
-            break;
-        case CPClipMask:
-            switch (pSrc->clientClipType) {
-            case CT_NONE:
-                (*ps->ChangePictureClip) (pDst, CT_NONE, NULL, 0);
-                break;
-            case CT_REGION:
-                if (!pSrc->clientClip) {
-                    (*ps->ChangePictureClip) (pDst, CT_NONE, NULL, 0);
-                }
-                else {
-                    RegionPtr clientClip;
-                    RegionPtr srcClientClip = (RegionPtr) pSrc->clientClip;
-
-                    clientClip = RegionCreate(RegionExtents(srcClientClip),
-                                              RegionNumRects(srcClientClip));
-                    (*ps->ChangePictureClip) (pDst, CT_REGION, clientClip, 0);
-                }
-                break;
-            default:
-                /* XXX: CT_PIXMAP unimplemented */
-                break;
-            }
-            break;
-        case CPGraphicsExposure:
-            pDst->graphicsExposures = pSrc->graphicsExposures;
-            break;
-        case CPPolyEdge:
-            pDst->polyEdge = pSrc->polyEdge;
-            break;
-        case CPPolyMode:
-            pDst->polyMode = pSrc->polyMode;
-            break;
-        case CPDither:
-            break;
-        case CPComponentAlpha:
-            pDst->componentAlpha = pSrc->componentAlpha;
-            break;
-        }
-        mask &= ~bit;
-    }
-
-    (*ps->ChangePicture) (pDst, origMask);
-}
-
 static void
 ValidateOnePicture(PicturePtr pPicture)
 {
diff --git a/render/picturestr.h b/render/picturestr.h
index 8c8100d..1278f62 100644
--- a/render/picturestr.h
+++ b/render/picturestr.h
@@ -476,9 +476,6 @@ extern _X_EXPORT int
  SetPictureTransform(PicturePtr pPicture, PictTransform * transform);
 
 extern _X_EXPORT void
- CopyPicture(PicturePtr pSrc, Mask mask, PicturePtr pDst);
-
-extern _X_EXPORT void
  ValidatePicture(PicturePtr pPicture);
 
 extern _X_EXPORT int
commit 578026fcd58d12dd0be4c0976ee5ecf95a9d61f0
Author: Adam Jackson <ajax at redhat.com>
Date:   Tue May 20 12:43:59 2014 -0400

    os: Remove LocalClientCred
    
    The comment lies, shm hasn't used this code since:
    
        commit fdef7be5c8d5989e0aa453d0a5b86d0a6952e960
        Author: Alan Coopersmith <alan.coopersmith at sun.com>
        Date:   Tue Oct 9 18:44:04 2007 -0700
    
            Sun bug 6589829: include zoneid of shm segment in access [...]
    
    Reviewed-by: Alan Coopersmith <alan.coopersmith at oracle.com>
    Signed-off-by: Adam Jackson <ajax at redhat.com>

diff --git a/include/os.h b/include/os.h
index 9982c9b..e4ec4b1 100644
--- a/include/os.h
+++ b/include/os.h
@@ -380,9 +380,6 @@ typedef struct sockaddr *sockaddrPtr;
 extern _X_EXPORT int
 InvalidHost(sockaddrPtr /*saddr */ , int /*len */ , ClientPtr client);
 
-extern _X_EXPORT int
-LocalClientCred(ClientPtr, int *, int *);
-
 #define LCC_UID_SET	(1 << 0)
 #define LCC_GID_SET	(1 << 1)
 #define LCC_PID_SET	(1 << 2)
diff --git a/os/access.c b/os/access.c
index 9fcf99a..125f35f 100644
--- a/os/access.c
+++ b/os/access.c
@@ -1008,33 +1008,6 @@ ComputeLocalClient(ClientPtr client)
 }
 
 /*
- * Return the uid and gid of a connected local client
- * 
- * Used by XShm to test access rights to shared memory segments
- */
-int
-LocalClientCred(ClientPtr client, int *pUid, int *pGid)
-{
-    LocalClientCredRec *lcc;
-    int ret = GetLocalClientCreds(client, &lcc);
-
-    if (ret == 0) {
-#ifdef HAVE_GETZONEID           /* only local if in the same zone */
-        if ((lcc->fieldsSet & LCC_ZID_SET) && (lcc->zoneid != getzoneid())) {
-            FreeLocalClientCreds(lcc);
-            return -1;
-        }
-#endif
-        if ((lcc->fieldsSet & LCC_UID_SET) && (pUid != NULL))
-            *pUid = lcc->euid;
-        if ((lcc->fieldsSet & LCC_GID_SET) && (pGid != NULL))
-            *pGid = lcc->egid;
-        FreeLocalClientCreds(lcc);
-    }
-    return ret;
-}
-
-/*
  * Return the uid and all gids of a connected local client
  * Allocates a LocalClientCredRec - caller must call FreeLocalClientCreds
  * 
commit cad9b053d52f62432dfd70e42e0240de77027cae
Author: Adam Jackson <ajax at redhat.com>
Date:   Tue Jul 8 13:24:25 2014 -0400

    os: Remove deprecated malloc/free wrappers
    
    Reviewed-by: Alex Deucher <alexander.deucher at amd.com>
    Signed-off-by: Adam Jackson <ajax at redhat.com>

diff --git a/doc/Xserver-spec.xml b/doc/Xserver-spec.xml
index cd1a9d0..4c34419 100644
--- a/doc/Xserver-spec.xml
+++ b/doc/Xserver-spec.xml
@@ -1217,11 +1217,9 @@ library is contained in dix/dixfonts.c
 <section>
   <title>Memory Management</title>
 <para>
-Memory management is based on functions in the C runtime library.
-Xalloc(), Xrealloc(), and Xfree() are deprecated aliases for malloc(),
+Memory management is based on functions in the C runtime library, malloc(),
 realloc(), and free(), and you should simply call the C library functions
-directly.  Consult a C runtime library reference
-manual for more details.
+directly.  Consult a C runtime library reference manual for more details.
 </para>
 <para>
 Treat memory allocation carefully in your implementation.  Memory
diff --git a/include/os.h b/include/os.h
index 0cbb928..9982c9b 100644
--- a/include/os.h
+++ b/include/os.h
@@ -67,15 +67,11 @@ SOFTWARE.
 typedef struct _FontPathRec *FontPathPtr;
 typedef struct _NewClientRec *NewClientPtr;
 
-#ifndef xalloc
+#ifndef xnfalloc
 #define xnfalloc(size) XNFalloc((unsigned long)(size))
 #define xnfcalloc(_num, _size) XNFcalloc((unsigned long)(_num)*(unsigned long)(_size))
 #define xnfrealloc(ptr, size) XNFrealloc((void *)(ptr), (unsigned long)(size))
 
-#define xalloc(size) Xalloc((unsigned long)(size))
-#define xcalloc(_num, _size) Xcalloc((unsigned long)(_num)*(unsigned long)(_size))
-#define xrealloc(ptr, size) Xrealloc((void *)(ptr), (unsigned long)(size))
-#define xfree(ptr) Xfree((void *)(ptr))
 #define xstrdup(s) Xstrdup(s)
 #define xnfstrdup(s) XNFstrdup(s)
 #endif
@@ -214,37 +210,6 @@ extern _X_EXPORT int set_font_authorizations(char **authorizations,
                                              int *authlen,
                                              void *client);
 
-#ifndef _HAVE_XALLOC_DECLS
-#define _HAVE_XALLOC_DECLS
-
-/*
- * Use malloc(3) instead.
- */
-extern _X_EXPORT void *
-Xalloc(unsigned long /*amount */ ) _X_DEPRECATED;
-
-/*
- * Use calloc(3) instead
- */
-extern _X_EXPORT void *
-Xcalloc(unsigned long /*amount */ ) _X_DEPRECATED;
-
-/*
- * Use realloc(3) instead
- */
-extern _X_EXPORT void *
-Xrealloc(void * /*ptr */ , unsigned long /*amount */ )
- _X_DEPRECATED;
-
-/*
- * Use free(3) instead
- */
-extern _X_EXPORT void
-Xfree(void * /*ptr */ )
-    _X_DEPRECATED;
-
-#endif
-
 /*
  * This function malloc(3)s buffer, terminating the server if there is not
  * enough memory.
diff --git a/os/utils.c b/os/utils.c
index ed7581e..f319743 100644
--- a/os/utils.c
+++ b/os/utils.c
@@ -1090,24 +1090,6 @@ set_font_authorizations(char **authorizations, int *authlen, void *client)
 }
 
 void *
-Xalloc(unsigned long amount)
-{
-    /*
-     * Xalloc used to return NULL when large amount of memory is requested. In
-     * order to catch the buggy callers this warning has been added, slated to
-     * removal by anyone who touches this code (or just looks at it) in 2011.
-     *
-     * -- Mikhail Gusarov
-     */
-    if ((long) amount <= 0)
-        ErrorF("Warning: Xalloc: "
-               "requesting unpleasantly large amount of memory: %lu bytes.\n",
-               amount);
-
-    return malloc(amount);
-}
-
-void *
 XNFalloc(unsigned long amount)
 {
     void *ptr = malloc(amount);
@@ -1118,12 +1100,6 @@ XNFalloc(unsigned long amount)
 }
 
 void *
-Xcalloc(unsigned long amount)
-{
-    return calloc(1, amount);
-}
-
-void *
 XNFcalloc(unsigned long amount)
 {
     void *ret = calloc(1, amount);
@@ -1134,24 +1110,6 @@ XNFcalloc(unsigned long amount)
 }
 
 void *
-Xrealloc(void *ptr, unsigned long amount)
-{
-    /*
-     * Xrealloc used to return NULL when large amount of memory is requested. In
-     * order to catch the buggy callers this warning has been added, slated to
-     * removal by anyone who touches this code (or just looks at it) in 2011.
-     *
-     * -- Mikhail Gusarov
-     */
-    if ((long) amount <= 0)
-        ErrorF("Warning: Xrealloc: "
-               "requesting unpleasantly large amount of memory: %lu bytes.\n",
-               amount);
-
-    return realloc(ptr, amount);
-}
-
-void *
 XNFrealloc(void *ptr, unsigned long amount)
 {
     void *ret = realloc(ptr, amount);
@@ -1161,12 +1119,6 @@ XNFrealloc(void *ptr, unsigned long amount)
     return ret;
 }
 
-void
-Xfree(void *ptr)
-{
-    free(ptr);
-}
-
 char *
 Xstrdup(const char *s)
 {
commit d5b279977236c4f80a8ba81db1f81a314484facf
Author: Adam Jackson <ajax at redhat.com>
Date:   Thu May 22 13:58:45 2014 -0400

    miext/shadow: Remove shadowInit
    
    This code is nonsensical.  You end up creating a screen-sized pixmap
    that's totally detached from everything else, which you then listen for
    damage on, which means you'll never hear any damage, which means your
    shadow update hooks will never get called.  Any driver using this would
    be sorely disappointed.
    
    Reviewed-by: Keith Packard <keithp at keithp.com>
    Signed-off-by: Adam Jackson <ajax at redhat.com>

diff --git a/miext/shadow/shadow.c b/miext/shadow/shadow.c
index 6690f70..0dd3604a 100644
--- a/miext/shadow/shadow.c
+++ b/miext/shadow/shadow.c
@@ -196,23 +196,3 @@ shadowRemove(ScreenPtr pScreen, PixmapPtr pPixmap)
     RemoveBlockAndWakeupHandlers(shadowBlockHandler, shadowWakeupHandler,
                                  (void *) pScreen);
 }
-
-Bool
-shadowInit(ScreenPtr pScreen, ShadowUpdateProc update, ShadowWindowProc window)
-{
-    PixmapPtr pPixmap;
-
-    pPixmap = pScreen->CreatePixmap(pScreen, pScreen->width, pScreen->height,
-                                    pScreen->rootDepth, 0);
-    if (!pPixmap)
-        return FALSE;
-
-    if (!shadowSetup(pScreen)) {
-        pScreen->DestroyPixmap(pPixmap);
-        return FALSE;
-    }
-
-    shadowAdd(pScreen, pPixmap, update, window, SHADOW_ROTATE_0, 0);
-
-    return TRUE;
-}
diff --git a/miext/shadow/shadow.h b/miext/shadow/shadow.h
index 9c5f991..86fa944 100644
--- a/miext/shadow/shadow.h
+++ b/miext/shadow/shadow.h
@@ -87,10 +87,6 @@ shadowAdd(ScreenPtr pScreen,
 extern _X_EXPORT void
  shadowRemove(ScreenPtr pScreen, PixmapPtr pPixmap);
 
-extern _X_EXPORT Bool
-
-shadowInit(ScreenPtr pScreen, ShadowUpdateProc update, ShadowWindowProc window);
-
 extern _X_EXPORT void *shadowAlloc(int width, int height, int bpp);
 
 extern _X_EXPORT void
commit cf4793d99ecee4dfd6094e02b1ccb89eb744d313
Author: Adam Jackson <ajax at redhat.com>
Date:   Fri Feb 28 15:36:31 2014 -0500

    miext/shadow: Remove ancient backwards-compatibility hack
    
    Here's a trip down memory lane.  Back when we merged kdrive we adopted
    kdrive's version of shadow, which used damage directly instead of
    hand-rolling it.  However a couple of Xorg drivers referred to the
    accumulated damage region in the shadow private directly, so I added a
    hack to copy the damage region around.
    
    That was 9148d8700b7c5afc2644e5820c57c509378f93ce, back in early 2006.
    Eight years is unusually patient for me.  The neomagic and trident drivers
    were still relying on this, but they've been modified to ask the damage
    code for the region instead.
    
    Reviewed-by: Keith Packard <keithp at keithp.com>
    Signed-off-by: Adam Jackson <ajax at redhat.com>

diff --git a/miext/shadow/shadow.c b/miext/shadow/shadow.c
index 522e21b..6690f70 100644
--- a/miext/shadow/shadow.c
+++ b/miext/shadow/shadow.c
@@ -93,8 +93,6 @@ shadowGetImage(DrawablePtr pDrawable, int sx, int sy, int w, int h,
     wrap(pBuf, pScreen, GetImage);
 }
 
-#define BACKWARDS_COMPATIBILITY
-
 static Bool
 shadowCloseScreen(ScreenPtr pScreen)
 {
@@ -104,35 +102,12 @@ shadowCloseScreen(ScreenPtr pScreen)
     unwrap(pBuf, pScreen, CloseScreen);
     shadowRemove(pScreen, pBuf->pPixmap);
     DamageDestroy(pBuf->pDamage);
-#ifdef BACKWARDS_COMPATIBILITY
-    RegionUninit(&pBuf->damage);        /* bc */
-#endif
     if (pBuf->pPixmap)
         pScreen->DestroyPixmap(pBuf->pPixmap);
     free(pBuf);
     return pScreen->CloseScreen(pScreen);
 }
 
-#ifdef BACKWARDS_COMPATIBILITY
-static void
-shadowReportFunc(DamagePtr pDamage, RegionPtr pRegion, void *closure)
-{
-    ScreenPtr pScreen = closure;
-    shadowBufPtr pBuf = (shadowBufPtr)
-        dixLookupPrivate(&pScreen->devPrivates, shadowScrPrivateKey);
-
-    /* Register the damaged region, use DamageReportNone below when we
-     * want to break BC below... */
-    RegionUnion(&pDamage->damage, &pDamage->damage, pRegion);
-
-    /*
-     * BC hack.  In 7.0 and earlier several drivers would inspect the
-     * 'damage' member directly, so we have to keep it existing.
-     */
-    RegionCopy(&pBuf->damage, pRegion);
-}
-#endif
-
 Bool
 shadowSetup(ScreenPtr pScreen)
 {
@@ -147,15 +122,9 @@ shadowSetup(ScreenPtr pScreen)
     pBuf = malloc(sizeof(shadowBufRec));
     if (!pBuf)
         return FALSE;
-#ifdef BACKWARDS_COMPATIBILITY
-    pBuf->pDamage = DamageCreate((DamageReportFunc) shadowReportFunc,
-                                 (DamageDestroyFunc) NULL,
-                                 DamageReportRawRegion, TRUE, pScreen, pScreen);
-#else
     pBuf->pDamage = DamageCreate((DamageReportFunc) NULL,
                                  (DamageDestroyFunc) NULL,
                                  DamageReportNone, TRUE, pScreen, pScreen);
-#endif
     if (!pBuf->pDamage) {
         free(pBuf);
         return FALSE;
@@ -168,9 +137,6 @@ shadowSetup(ScreenPtr pScreen)
     pBuf->pPixmap = 0;
     pBuf->closure = 0;
     pBuf->randr = 0;
-#ifdef BACKWARDS_COMPATIBILITY
-    RegionNull(&pBuf->damage);  /* bc */
-#endif
 
     dixSetPrivate(&pScreen->devPrivates, shadowScrPrivateKey, pBuf);
     return TRUE;
diff --git a/miext/shadow/shadow.h b/miext/shadow/shadow.h
index 421ae96..9c5f991 100644
--- a/miext/shadow/shadow.h
+++ b/miext/shadow/shadow.h
@@ -43,12 +43,10 @@ typedef void *(*ShadowWindowProc) (ScreenPtr pScreen,
                                    CARD32 offset,
                                    int mode, CARD32 *size, void *closure);
 
-/* BC hack: do not move the damage member.  see shadow.c for explanation. */
 typedef struct _shadowBuf {
     DamagePtr pDamage;
     ShadowUpdateProc update;
     ShadowWindowProc window;
-    RegionRec damage;
     PixmapPtr pPixmap;
     void *closure;
     int randr;
commit 35eabf2e5272e17e6765027d4baea43b34c66933
Author: Adam Jackson <ajax at redhat.com>
Date:   Tue Jul 8 14:11:22 2014 -0400

    mi: Remove apparently unused miSegregateChildren
    
    This came in between XFree86 4.3 and 4.4, I'm not entirely sure what it
    was meant to do.
    
    Reviewed-by: Keith Packard <keithp at keithp.com>
    Signed-off-by: Adam Jackson <ajax at redhat.com>

diff --git a/mi/mi.h b/mi/mi.h
index feba5cb..d5a5ba3 100644
--- a/mi/mi.h
+++ b/mi/mi.h
@@ -515,9 +515,6 @@ extern _X_EXPORT void miMarkUnrealizedWindow(WindowPtr /*pChild */ ,
                                              Bool       /*fromConfigure */
     );
 
-extern _X_EXPORT void miSegregateChildren(WindowPtr pWin, RegionPtr pReg,
-                                          int depth);
-
 extern _X_EXPORT WindowPtr miSpriteTrace(SpritePtr pSprite, int x, int y);
 
 extern _X_EXPORT WindowPtr miXYToWindow(ScreenPtr pScreen, SpritePtr pSprite, int x, int y);
diff --git a/mi/miwindow.c b/mi/miwindow.c
index 57de91b..82c3513 100644
--- a/mi/miwindow.c
+++ b/mi/miwindow.c
@@ -746,20 +746,6 @@ miMarkUnrealizedWindow(WindowPtr pChild, WindowPtr pWin, Bool fromConfigure)
     }
 }
 
-void
-miSegregateChildren(WindowPtr pWin, RegionPtr pReg, int depth)
-{
-    WindowPtr pChild;
-
-    for (pChild = pWin->firstChild; pChild; pChild = pChild->nextSib) {
-        if (pChild->drawable.depth == depth)
-            RegionUnion(pReg, pReg, &pChild->borderClip);
-
-        if (pChild->firstChild)
-            miSegregateChildren(pChild, pReg, depth);
-    }
-}
-
 WindowPtr
 miSpriteTrace(SpritePtr pSprite, int x, int y)
 {
commit 150acef3af9bb43cb60cbcc558ef3ad4a710e624
Author: Adam Jackson <ajax at redhat.com>
Date:   Mon May 19 13:46:12 2014 -0400

    kdrive: Remove some dead bits of the man page
    
    Reviewed-by: Keith Packard <keithp at keithp.com>
    Signed-off-by: Adam Jackson <ajax at redhat.com>

diff --git a/hw/kdrive/Xkdrive.man b/hw/kdrive/Xkdrive.man
index b37f9f1..c3e2089 100644
--- a/hw/kdrive/Xkdrive.man
+++ b/hw/kdrive/Xkdrive.man
@@ -4,10 +4,6 @@
 .SH NAME
 Xkdrive \- tiny X server
 .SH SYNOPSIS
-.B Xvesa
-.RI [ :display ]
-.RI [ option ...]
-
 .B Xfbdev
 .RI [ :display ]
 .RI [ option ...]
@@ -24,9 +20,6 @@ Xserver(1)), all the
 .B Xkdrive
 servers accept the following options:
 .TP 8
-.B -card \fIpcmcia\fP
-use pcmcia card as additional screen.
-.TP 8
 .B -dumb
 disable hardware acceleration.
 .TP 8
commit 71ef49062ee33ac49033fbcd67bab88120882668
Author: Adam Jackson <ajax at redhat.com>
Date:   Fri Feb 28 14:05:25 2014 -0500

    dix: Make some LBX-era code more obvious
    
    isItTimeToYield in the conditional effectively didn't do anything here.
    Take it out, and remove the comment since LBX proxies aren't a thing for
    us anymore.
    
    Reviewed-by: Keith Packard <keithp at keithp.com>
    Signed-off-by: Adam Jackson <ajax at redhat.com>

diff --git a/dix/dispatch.c b/dix/dispatch.c
index 4f830f7..f7a08f8 100644
--- a/dix/dispatch.c
+++ b/dix/dispatch.c
@@ -3188,13 +3188,11 @@ ProcKillClient(ClientPtr client)
     rc = dixLookupClient(&killclient, stuff->id, client, DixDestroyAccess);
     if (rc == Success) {
         CloseDownClient(killclient);
-        /* if an LBX proxy gets killed, isItTimeToYield will be set */
-        if (isItTimeToYield || (client == killclient)) {
+        if (client == killclient) {
             /* force yield and return Success, so that Dispatch()
              * doesn't try to touch client
              */
             isItTimeToYield = TRUE;
-            return Success;
         }
         return Success;
     }
commit a317e0a974c1597d55fe05a38b4a495c4e4e8d71
Author: Adam Jackson <ajax at redhat.com>
Date:   Fri May 2 11:50:17 2014 -0400

    bsd: Remove some reference arm code behind #if 0
    
    git history is reference enough, thanks.
    
    Reviewed-by: Alex Deucher <alexander.deucher at amd.com>
    Signed-off-by: Adam Jackson <ajax at redhat.com>

diff --git a/hw/xfree86/os-support/bsd/arm_video.c b/hw/xfree86/os-support/bsd/arm_video.c
index 6a977c2..e295c92 100644
--- a/hw/xfree86/os-support/bsd/arm_video.c
+++ b/hw/xfree86/os-support/bsd/arm_video.c
@@ -487,142 +487,3 @@ xf86DisableIO()
 }
 
 #endif                          /* USE_ARC_MMAP */
-
-#if 0
-/*
- * XXX This is here for reference.  It needs to be handled differently for the
- * ND.
- */
-#if defined(USE_ARC_MMAP) || defined(__arm32__)
-
-#ifdef USE_ARM32_MMAP
-#define	DEV_MEM_IOBASE	0x43000000
-#endif
-
-static Bool ScreenEnabled[MAXSCREENS];
-static Bool ExtendedEnabled = FALSE;
-static Bool InitDone = FALSE;
-
-Bool
-xf86EnableIOPorts(ScreenNum)
-int ScreenNum;
-{
-    int i;
-    int fd;
-    void *base;
-
-#ifdef __arm32__
-    struct memAccess *memInfoP;
-    int *Size;
-#endif
-
-    ScreenEnabled[ScreenNum] = TRUE;
-
-    if (ExtendedEnabled)
-        return TRUE;
-
-#ifdef USE_ARC_MMAP
-    if ((fd = open("/dev/ttyC0", O_RDWR)) >= 0) {
-        /* Try to map a page at the pccons I/O space */
-        base = (void *) mmap((caddr_t) 0, 65536, PROT_READ | PROT_WRITE,
-                             MAP_FLAGS, fd, (off_t) 0x0000);
-
-        if (base != (void *) -1) {
-            IOPortBase = base;
-        }
-        else {
-            xf86Msg(X_ERROR,
-                    "EnableIOPorts: failed to mmap %s (%s)\n",
-                    "/dev/ttyC0", strerror(errno));
-        }
-    }
-    else {
-        xf86Msg(X_ERROR, "EnableIOPorts: failed to open %s (%s)\n",
-                "/dev/ttyC0", strerror(errno));
-    }
-#endif
-
-#ifdef __arm32__
-    IOPortBase = (unsigned int) -1;
-
-    if ((memInfoP = checkMapInfo(TRUE, MMIO_REGION)) != NULL) {
-        /* 
-         * xf86MapInfoMap maps an offset from the start of video IO
-         * space (e.g. 0x3B0), but IOPortBase is expected to map to
-         * physical address 0x000, so subtract the start of video I/O
-         * space from the result.  This is safe for now becase we
-         * actually mmap the start of the page, then the start of video
-         * I/O space is added as an internal offset.
-         */
-        IOPortBase = (unsigned int) xf86MapInfoMap(memInfoP, (caddr_t) 0x0, 0L)
-            - memInfoP->memInfo.u.map_info_mmap.internal_offset;
-        ExtendedEnabled = TRUE;
-        return TRUE;
-    }
-#ifdef USE_ARM32_MMAP
-    checkDevMem(TRUE);
-
-    if (devMemFd >= 0 && useDevMem) {
-        base = (void *) mmap((caddr_t) 0, 0x400, PROT_READ | PROT_WRITE,
-                              MAP_FLAGS, devMemFd, (off_t) DEV_MEM_IOBASE);
-
-        if (base != (void *) -1)
-            IOPortBase = (unsigned int) base;
-    }
-
-    if (IOPortBase == (unsigned int) -1) {
-        xf86Msg(X_WARNING,
-                "xf86EnableIOPorts: failed to open mem device or map IO base. \n\
-Make sure you have the Aperture Driver installed, or a kernel built with the INSECURE option\n");
-        return FALSE;
-    }
-#else
-    /* We don't have the IOBASE, so we can't map the address */
-    xf86Msg(X_WARNING,
-            "xf86EnableIOPorts: failed to open mem device or map IO base. \n\
-Try building the server with USE_ARM32_MMAP defined\n");
-    return FALSE;
-#endif
-#endif
-
-    ExtendedEnabled = TRUE;
-
-    return TRUE;
-}
-
-void
-xf86DisableIOPorts(ScreenNum)
-int ScreenNum;
-{
-    int i;
-
-#ifdef __arm32__
-    struct memAccess *memInfoP;
-#endif
-
-    ScreenEnabled[ScreenNum] = FALSE;
-
-#ifdef __arm32__
-    if ((memInfoP = checkMapInfo(FALSE, MMIO_REGION)) != NULL) {
-        xf86MapInfoUnmap(memInfoP, 0);
-    }
-#endif
-
-#ifdef USE_ARM32_MMAP
-    if (!ExtendedEnabled)
-        return;
-
-    for (i = 0; i < MAXSCREENS; i++)
-        if (ScreenEnabled[i])
-            return;
-
-    munmap((caddr_t) IOPortBase, 0x400);
-    IOPortBase = (unsigned int) -1;
-    ExtendedEnabled = FALSE;
-#endif
-
-    return;
-}
-
-#endif                          /* USE_ARC_MMAP || USE_ARM32_MMAP */
-#endif
commit 8a60d1c3f4a62675cad005107f56413f946ecd77
Author: Keith Packard <keithp at keithp.com>
Date:   Mon Jul 28 11:10:15 2014 -0700

    glamor: Eliminate diagonal tearing in xv
    
    This uses a single large triangle and a scissor to draw the video
    instead of two triangles.
    
    Signed-off-by: Keith Packard <keithp at keithp.com>
    Reviewed-by: Alex Deucher <alexander.deucher at amd.com>

diff --git a/glamor/glamor_xv.c b/glamor/glamor_xv.c
index 68a06a4..3f3e064 100644
--- a/glamor/glamor_xv.c
+++ b/glamor/glamor_xv.c
@@ -336,6 +336,7 @@ glamor_xv_render(glamor_port_private *port_priv)
                           GL_FALSE, 2 * sizeof(float), vertices);
 
     glEnableVertexAttribArray(GLAMOR_VERTEX_POS);
+    glEnable(GL_SCISSOR_TEST);
     for (i = 0; i < nBox; i++) {
         float off_x = box[i].x1 - port_priv->drw_x;
         float off_y = box[i].y1 - port_priv->drw_y;
@@ -356,23 +357,25 @@ glamor_xv_render(glamor_port_private *port_priv)
 
         glamor_set_normalize_vcoords(pixmap_priv,
                                      dst_xscale, dst_yscale,
-                                     dstx,
+                                     dstx - dstw,
                                      dsty,
                                      dstx + dstw,
-                                     dsty + dsth,
+                                     dsty + dsth * 2,
                                      vertices);
 
         glamor_set_normalize_tcoords(src_pixmap_priv[0],
                                      src_xscale[0],
                                      src_yscale[0],
-                                     srcx,
+                                     srcx - srcw,
                                      srcy,
                                      srcx + srcw,
-                                     srcy + srch,
+                                     srcy + srch * 2,
                                      texcoords);
 
-        glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
+        glScissor(dstx, dsty, dstw, dsth);
+        glDrawArrays(GL_TRIANGLE_FAN, 0, 3);
     }
+    glDisable(GL_SCISSOR_TEST);
 
     glDisableVertexAttribArray(GLAMOR_VERTEX_POS);
     glDisableVertexAttribArray(GLAMOR_VERTEX_SOURCE);
commit 29eaa61cb210e0c67004bc567af0c15d48aad626
Author: Adam Jackson <ajax at redhat.com>
Date:   Tue Jul 22 11:05:32 2014 -0400

    mi: Remove semi-arbitrary arch awareness in packed coordinate macros
    
    The majority of arches end up on the right-shift path here.  I can't
    think of any arch where that'd be slower than a divide, and semantically
    it makes more sense to think of this as a shift operation anyway.
    
    Signed-off-by: Adam Jackson <ajax at redhat.com>
    Reviewed-by: Keith Packard <keithp at keithp.com>
    Signed-off-by: Keith Packard <keithp at keithp.com>

diff --git a/mi/micoord.h b/mi/micoord.h
index 481e418..c83bffd 100644
--- a/mi/micoord.h
+++ b/mi/micoord.h
@@ -32,27 +32,7 @@
 
 /* Macros which handle a coordinate in a single register */
 
-/*
- * Most compilers will convert divisions by 65536 into shifts, if signed
- * shifts exist.  If your machine does arithmetic shifts and your compiler
- * can't get it right, add to this line.
- */
-
-/*
- * mips compiler - what a joke - it CSEs the 65536 constant into a reg
- * forcing as to use div instead of shift.  Let's be explicit.
- */
-
-#if defined(mips) || \
-    defined(sparc) || defined(__sparc64__) || \
-    defined(__alpha) || defined(__alpha__) || \
-    defined(__i386__) || defined(__i386) || defined(__ia64__) || \
-    defined(__s390x__) || defined(__s390__) || \
-    defined(__amd64__) || defined(amd64) || defined(__amd64)
 #define GetHighWord(x) (((int) (x)) >> 16)
-#else
-#define GetHighWord(x) (((int) (x)) / 65536)
-#endif
 
 #if IMAGE_BYTE_ORDER == MSBFirst
 #define intToCoord(i,x,y)   (((x) = GetHighWord(i)), ((y) = (int) ((short) (i))))
commit 6ddd164508f81e9582b66061b385bd34ac1ccb7e
Author: Adam Jackson <ajax at redhat.com>
Date:   Tue Jul 22 10:59:13 2014 -0400

    xfree86: Unify the ppc/sparc mmio-swap-or-not conditionals
    
    Map SPARC_MMIO_IS_BE and PPC_MMIO_IS_BE to MMIO_IS_BE and use the same
    macros for both since they're identical.
    
    Reviewed-by: Julien Cristau <jcristau at debian.org>
    Signed-off-by: Adam Jackson <ajax at redhat.com>
    Signed-off-by: Keith Packard <keithp at keithp.com>

diff --git a/hw/xfree86/common/compiler.h b/hw/xfree86/common/compiler.h
index a94a388..5325129 100644
--- a/hw/xfree86/common/compiler.h
+++ b/hw/xfree86/common/compiler.h
@@ -1027,6 +1027,11 @@ inl(unsigned short port)
 #endif
 #endif                          /* __GNUC__ */
 
+#if !defined(MMIO_IS_BE) && \
+    (defined(SPARC_MMIO_IS_BE) || defined(PPC_MMIO_IS_BE))
+#define MMIO_IS_BE
+#endif
+
 #ifdef __alpha__
 /* entry points for Mmio memory access routines */
 extern _X_EXPORT int (*xf86ReadMmio8) (void *, unsigned long);
@@ -1071,17 +1076,17 @@ extern _X_EXPORT void xf86SlowBCopyToBus(unsigned char *, unsigned char *, int);
 #define MMIO_OUT16(base, offset, val) \
     (*xf86WriteMmio16)((CARD16)(val), base, offset)
 
-#elif defined(__powerpc__)
+#elif defined(__powerpc__) || defined(__sparc__)
  /* 
   * we provide byteswapping and no byteswapping functions here
   * with byteswapping as default, 
-  * drivers that don't need byteswapping should define PPC_MMIO_IS_BE 
+  * drivers that don't need byteswapping should define MMIO_IS_BE
   */
 #define MMIO_IN8(base, offset) xf86ReadMmio8(base, offset)
 #define MMIO_OUT8(base, offset, val) \
     xf86WriteMmio8(base, offset, (CARD8)(val))
 
-#if defined(PPC_MMIO_IS_BE)     /* No byteswapping */
+#if defined(MMIO_IS_BE)     /* No byteswapping */
 #define MMIO_IN16(base, offset) xf86ReadMmio16Be(base, offset)
 #define MMIO_IN32(base, offset) xf86ReadMmio32Be(base, offset)
 #define MMIO_OUT16(base, offset, val) \
@@ -1097,34 +1102,6 @@ extern _X_EXPORT void xf86SlowBCopyToBus(unsigned char *, unsigned char *, int);
      xf86WriteMmio32Le(base, offset, (CARD32)(val))
 #endif
 
-#elif defined(__sparc__)
- /*
-  * Like powerpc, we provide byteswapping and no byteswapping functions
-  * here with byteswapping as default, drivers that don't need byteswapping
-  * should define SPARC_MMIO_IS_BE (perhaps create a generic macro so that we
-  * do not need to use PPC_MMIO_IS_BE and the sparc one in all the same places
-  * of drivers?).
-  */
-#define MMIO_IN8(base, offset) xf86ReadMmio8(base, offset)
-#define MMIO_OUT8(base, offset, val) \
-    xf86WriteMmio8(base, offset, (CARD8)(val))
-
-#if defined(SPARC_MMIO_IS_BE)   /* No byteswapping */
-#define MMIO_IN16(base, offset) xf86ReadMmio16Be(base, offset)
-#define MMIO_IN32(base, offset) xf86ReadMmio32Be(base, offset)
-#define MMIO_OUT16(base, offset, val) \
-     xf86WriteMmio16Be(base, offset, (CARD16)(val))
-#define MMIO_OUT32(base, offset, val) \
-     xf86WriteMmio32Be(base, offset, (CARD32)(val))
-#else                           /* byteswapping is the default */
-#define MMIO_IN16(base, offset) xf86ReadMmio16Le(base, offset)
-#define MMIO_IN32(base, offset) xf86ReadMmio32Le(base, offset)
-#define MMIO_OUT16(base, offset, val) \
-     xf86WriteMmio16Le(base, offset, (CARD16)(val))
-#define MMIO_OUT32(base, offset, val) \
-     xf86WriteMmio32Le(base, offset, (CARD32)(val))
-#endif
-
 #elif defined(__nds32__)
  /*
   * we provide byteswapping and no byteswapping functions here
commit 8ffd1c066ab1e993d8964aef12a7c585329c677c
Author: Adam Jackson <ajax at redhat.com>
Date:   Tue Jul 22 10:59:12 2014 -0400

    xfree86: Clean up some silly __sparc macro usage
    
    The top of this file already defines __sparc__ if __sparc is defined.
    
    Reviewed-by: Julien Cristau <jcristau at debian.org>
    Signed-off-by: Adam Jackson <ajax at redhat.com>
    Signed-off-by: Keith Packard <keithp at keithp.com>

diff --git a/hw/xfree86/common/compiler.h b/hw/xfree86/common/compiler.h
index b1fd0d8..a94a388 100644
--- a/hw/xfree86/common/compiler.h
+++ b/hw/xfree86/common/compiler.h
@@ -97,7 +97,7 @@
 
 #if defined(DO_PROTOTYPES)
 #if !defined(__arm__)
-#if !defined(__sparc__) && !defined(__sparc) && !defined(__arm32__) && !defined(__nds32__) \
+#if !defined(__sparc__) && !defined(__arm32__) && !defined(__nds32__) \
       && !(defined(__alpha__) && defined(linux)) \
       && !(defined(__ia64__) && defined(linux)) \
       && !(defined(__mips64) && defined(linux)) \
@@ -1097,7 +1097,7 @@ extern _X_EXPORT void xf86SlowBCopyToBus(unsigned char *, unsigned char *, int);
      xf86WriteMmio32Le(base, offset, (CARD32)(val))
 #endif
 
-#elif defined(__sparc__) || defined(sparc) || defined(__sparc)
+#elif defined(__sparc__)
  /*
   * Like powerpc, we provide byteswapping and no byteswapping functions
   * here with byteswapping as default, drivers that don't need byteswapping
commit 1c1711b57f2c278c0df03bf9e7e9a1776a546968
Author: Adam Jackson <ajax at redhat.com>
Date:   Tue Jul 22 10:59:11 2014 -0400

    xfree86: Pull generic barrier() definition up to top level
    
    And remove the redundant redecl from the nds32 section.
    
    Reviewed-by: Julien Cristau <jcristau at debian.org>
    Signed-off-by: Adam Jackson <ajax at redhat.com>
    Signed-off-by: Keith Packard <keithp at keithp.com>

diff --git a/hw/xfree86/common/compiler.h b/hw/xfree86/common/compiler.h
index e408441..b1fd0d8 100644
--- a/hw/xfree86/common/compiler.h
+++ b/hw/xfree86/common/compiler.h
@@ -94,6 +94,7 @@
 #if !defined(__GNUC__) && !defined(__FUNCTION__)
 #define __FUNCTION__ __func__   /* C99 */
 #endif
+
 #if defined(DO_PROTOTYPES)
 #if !defined(__arm__)
 #if !defined(__sparc__) && !defined(__sparc) && !defined(__arm32__) && !defined(__nds32__) \
@@ -199,6 +200,10 @@ extern _X_EXPORT void xf86WriteMmio32Le (void *, unsigned long, unsigned int);
 #endif
 #endif                          /* __GNUC__ */
 
+#ifndef barrier
+#define barrier()
+#endif
+
 #ifndef mem_barrier
 #define mem_barrier()           /* NOP */
 #endif
@@ -790,8 +795,6 @@ xf_outl(unsigned short port, unsigned int val)
  * if there is unaligned port access.
  */
 
-#define barrier()               /* no barrier */
-
 #define PORT_SIZE long
 
 static __inline__ unsigned char
@@ -964,9 +967,6 @@ inl(unsigned PORT_SIZE port)
 
 #endif                          /* NDS32_MMIO_SWAP */
 
-#define mem_barrier()           /* XXX: nop for now */
-#define write_mem_barrier()     /* XXX: nop for now */
-
 #elif defined(__i386__) || defined(__ia64__)
 
 static __inline__ void
commit c73929bbfc14ba80397c53ca98d3b503c807ae78
Author: Adam Jackson <ajax at redhat.com>
Date:   Tue Jul 22 10:59:10 2014 -0400

    xfree86: Remove MMIO_ONB* and friends
    
    Non-barrier-emitting MMIO writes.  They appear to be utterly unused,
    burn it all down.
    
    Reviewed-by: Julien Cristau <jcristau at debian.org>
    Signed-off-by: Adam Jackson <ajax at redhat.com>
    Signed-off-by: Keith Packard <keithp at keithp.com>

diff --git a/hw/xfree86/common/compiler.h b/hw/xfree86/common/compiler.h
index 3430585..e408441 100644
--- a/hw/xfree86/common/compiler.h
+++ b/hw/xfree86/common/compiler.h
@@ -127,11 +127,6 @@ 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__ */
@@ -518,56 +513,6 @@ xf86WriteMmio32Le(__volatile__ void *base, const unsigned long offset,
     barrier();
 }
 
-static __inline__ void
-xf86WriteMmio8NB(__volatile__ void *base, const unsigned long offset,
-                 const unsigned int val)
-{
-    unsigned long addr = ((unsigned long) base) + offset;
-
-    __asm__ __volatile__("stba %0, [%1] %2":    /* No outputs */
-                         :"r"(val), "r"(addr), "i"(ASI_PL));
-}
-
-static __inline__ void
-xf86WriteMmio16BeNB(__volatile__ void *base, const unsigned long offset,
-                    const unsigned int val)
-{
-    unsigned long addr = ((unsigned long) base) + offset;
-
-    __asm__ __volatile__("sth %0, [%1]":        /* No outputs */
-                         :"r"(val), "r"(addr));
-}
-
-static __inline__ void
-xf86WriteMmio16LeNB(__volatile__ void *base, const unsigned long offset,
-                    const unsigned int val)
-{
-    unsigned long addr = ((unsigned long) base) + offset;
-
-    __asm__ __volatile__("stha %0, [%1] %2":    /* No outputs */
-                         :"r"(val), "r"(addr), "i"(ASI_PL));
-}
-
-static __inline__ void
-xf86WriteMmio32BeNB(__volatile__ void *base, const unsigned long offset,
-                    const unsigned int val)
-{
-    unsigned long addr = ((unsigned long) base) + offset;
-
-    __asm__ __volatile__("st %0, [%1]": /* No outputs */
-                         :"r"(val), "r"(addr));
-}
-
-static __inline__ void
-xf86WriteMmio32LeNB(__volatile__ void *base, const unsigned long offset,
-                    const unsigned int val)
-{
-    unsigned long addr = ((unsigned long) base) + offset;
-
-    __asm__ __volatile__("sta %0, [%1] %2":     /* No outputs */
-                         :"r"(val), "r"(addr), "i"(ASI_PL));
-}
-
 #elif defined(__mips__) || (defined(__arm32__) && !defined(__linux__))
 #if defined(__arm32__) || defined(__mips64)
 #define PORT_SIZE long
@@ -706,92 +651,57 @@ xf86ReadMmio32Le(__volatile__ void *base, const unsigned long offset)
 }
 
 static __inline__ void
-xf86WriteMmioNB8(__volatile__ void *base, const unsigned long offset,
-                 const unsigned char val)
+xf86WriteMmio8(__volatile__ void *base, const unsigned long offset,
+               const unsigned char val)
 {
     __asm__
         __volatile__("stbx %1,%2,%3\n\t":"=m"
                      (*((volatile unsigned char *) base + offset))
                      :"r"(val), "b"(base), "r"(offset));
+    eieio();
 }
 
 static __inline__ void
-xf86WriteMmioNB16Le(__volatile__ void *base, const unsigned long offset,
-                    const unsigned short val)
+xf86WriteMmio16Le(__volatile__ void *base, const unsigned long offset,
+                  const unsigned short val)
 {
     __asm__
         __volatile__("sthbrx %1,%2,%3\n\t":"=m"
                      (*((volatile unsigned char *) base + offset))
                      :"r"(val), "b"(base), "r"(offset));
+    eieio();
 }
 
 static __inline__ void
-xf86WriteMmioNB16Be(__volatile__ void *base, const unsigned long offset,
-                    const unsigned short val)
+xf86WriteMmio16Be(__volatile__ void *base, const unsigned long offset,
+                  const unsigned short val)
 {
     __asm__
         __volatile__("sthx %1,%2,%3\n\t":"=m"
                      (*((volatile unsigned char *) base + offset))
                      :"r"(val), "b"(base), "r"(offset));
+    eieio();
 }
 
 static __inline__ void
-xf86WriteMmioNB32Le(__volatile__ void *base, const unsigned long offset,
-                    const unsigned int val)
+xf86WriteMmio32Le(__volatile__ void *base, const unsigned long offset,
+                  const unsigned int val)
 {
     __asm__
         __volatile__("stwbrx %1,%2,%3\n\t":"=m"
                      (*((volatile unsigned char *) base + offset))
                      :"r"(val), "b"(base), "r"(offset));
+    eieio();
 }
 
 static __inline__ void
-xf86WriteMmioNB32Be(__volatile__ void *base, const unsigned long offset,
-                    const unsigned int val)
+xf86WriteMmio32Be(__volatile__ void *base, const unsigned long offset,
+                  const unsigned int val)
 {
     __asm__
         __volatile__("stwx %1,%2,%3\n\t":"=m"
                      (*((volatile unsigned char *) base + offset))
                      :"r"(val), "b"(base), "r"(offset));
-}
-
-static __inline__ void
-xf86WriteMmio8(__volatile__ void *base, const unsigned long offset,
-               const unsigned char val)
-{
-    xf86WriteMmioNB8(base, offset, val);
-    eieio();
-}
-
-static __inline__ void
-xf86WriteMmio16Le(__volatile__ void *base, const unsigned long offset,
-                  const unsigned short val)
-{
-    xf86WriteMmioNB16Le(base, offset, val);
-    eieio();
-}
-
-static __inline__ void
-xf86WriteMmio16Be(__volatile__ void *base, const unsigned long offset,
-                  const unsigned short val)
-{
-    xf86WriteMmioNB16Be(base, offset, val);
-    eieio();
-}
-
-static __inline__ void
-xf86WriteMmio32Le(__volatile__ void *base, const unsigned long offset,
-                  const unsigned int val)
-{
-    xf86WriteMmioNB32Le(base, offset, val);
-    eieio();
-}
-
-static __inline__ void
-xf86WriteMmio32Be(__volatile__ void *base, const unsigned long offset,
-                  const unsigned int val)
-{
-    xf86WriteMmioNB32Be(base, offset, val);
     eieio();
 }
 
@@ -898,13 +808,6 @@ xf86WriteMmio8(__volatile__ void *base, const unsigned long offset,
     barrier();
 }
 
-static __inline__ void
-xf86WriteMmio8NB(__volatile__ void *base, const unsigned long offset,
-                 const unsigned int val)
-{
-    *(volatile unsigned char *) ((unsigned char *) base + offset) = val;
-}
-
 static __inline__ unsigned short
 xf86ReadMmio16Swap(__volatile__ void *base, const unsigned long offset)
 {
@@ -943,23 +846,6 @@ xf86WriteMmio16(__volatile__ void *base, const unsigned long offset,
     barrier();
 }
 
-static __inline__ void
-xf86WriteMmio16SwapNB(__volatile__ void *base, const unsigned long offset,
-                      const unsigned int val)
-{
-    unsigned long addr = ((unsigned long) base) + offset;
-
-    __asm__ __volatile__("wsbh %0, %0;\n\t" "shi %0, [%1];\n\t":        /* No outputs */
-                         :"r"(val), "r"(addr));
-}
-
-static __inline__ void
-xf86WriteMmio16NB(__volatile__ void *base, const unsigned long offset,
-                  const unsigned int val)
-{
-    *(volatile unsigned short *) ((unsigned char *) base + offset) = val;
-}
-
 static __inline__ unsigned int
 xf86ReadMmio32Swap(__volatile__ void *base, const unsigned long offset)
 {
@@ -999,23 +885,6 @@ xf86WriteMmio32(__volatile__ void *base, const unsigned long offset,
     barrier();
 }
 
-static __inline__ void
-xf86WriteMmio32SwapNB(__volatile__ void *base, const unsigned long offset,
-                      const unsigned int val)
-{
-    unsigned long addr = ((unsigned long) base) + offset;
-
-    __asm__ __volatile__("wsbh %0, %0;\n\t" "rotri %0, %0, 16;\n\t" "swi %0, [%1];\n\t":        /* No outputs */
-                         :"r"(val), "r"(addr));
-}
-
-static __inline__ void
-xf86WriteMmio32NB(__volatile__ void *base, const unsigned long offset,
-                  const unsigned int val)
-{
-    *(volatile unsigned int *) ((unsigned char *) base + offset) = val;
-}
-
 #if defined(NDS32_MMIO_SWAP)
 static __inline__ void
 outb(unsigned PORT_SIZE port, unsigned char val)
@@ -1177,9 +1046,6 @@ xf86ReadMmio32(void *Base, unsigned long Offset)
 extern _X_EXPORT void (*xf86WriteMmio8) (int, void *, unsigned long);
 extern _X_EXPORT void (*xf86WriteMmio16) (int, void *, unsigned long);
 extern _X_EXPORT void (*xf86WriteMmio32) (int, void *, unsigned long);
-extern _X_EXPORT void (*xf86WriteMmioNB8) (int, void *, unsigned long);
-extern _X_EXPORT void (*xf86WriteMmioNB16) (int, void *, unsigned long);
-extern _X_EXPORT void (*xf86WriteMmioNB32) (int, void *, unsigned long);
 extern _X_EXPORT void xf86SlowBCopyFromBus(unsigned char *, unsigned char *,
                                            int);
 extern _X_EXPORT void xf86SlowBCopyToBus(unsigned char *, unsigned char *, int);
@@ -1199,17 +1065,11 @@ extern _X_EXPORT void xf86SlowBCopyToBus(unsigned char *, unsigned char *, int);
 	write_mem_barrier(); \
 	*(volatile CARD32 *)(void *)(((CARD8*)(base)) + (offset)) = (val); \
     } while (0)
-#define MMIO_ONB32(base, offset, val) \
-	*(volatile CARD32 *)(void *)(((CARD8*)(base)) + (offset)) = (val)
 
 #define MMIO_OUT8(base, offset, val) \
     (*xf86WriteMmio8)((CARD8)(val), base, offset)
 #define MMIO_OUT16(base, offset, val) \
     (*xf86WriteMmio16)((CARD16)(val), base, offset)
-#define MMIO_ONB8(base, offset, val) \
-    (*xf86WriteMmioNB8)((CARD8)(val), base, offset)
-#define MMIO_ONB16(base, offset, val) \
-    (*xf86WriteMmioNB16)((CARD16)(val), base, offset)
 
 #elif defined(__powerpc__)
  /* 
@@ -1220,8 +1080,6 @@ extern _X_EXPORT void xf86SlowBCopyToBus(unsigned char *, unsigned char *, int);
 #define MMIO_IN8(base, offset) xf86ReadMmio8(base, offset)
 #define MMIO_OUT8(base, offset, val) \
     xf86WriteMmio8(base, offset, (CARD8)(val))
-#define MMIO_ONB8(base, offset, val) \
-    xf86WriteMmioNB8(base, offset, (CARD8)(val))
 
 #if defined(PPC_MMIO_IS_BE)     /* No byteswapping */
 #define MMIO_IN16(base, offset) xf86ReadMmio16Be(base, offset)
@@ -1230,10 +1088,6 @@ extern _X_EXPORT void xf86SlowBCopyToBus(unsigned char *, unsigned char *, int);
     xf86WriteMmio16Be(base, offset, (CARD16)(val))
 #define MMIO_OUT32(base, offset, val) \
     xf86WriteMmio32Be(base, offset, (CARD32)(val))
-#define MMIO_ONB16(base, offset, val) \
-    xf86WriteMmioNB16Be(base, offset, (CARD16)(val))
-#define MMIO_ONB32(base, offset, val) \
-    xf86WriteMmioNB32Be(base, offset, (CARD32)(val))
 #else                           /* byteswapping is the default */
 #define MMIO_IN16(base, offset) xf86ReadMmio16Le(base, offset)
 #define MMIO_IN32(base, offset) xf86ReadMmio32Le(base, offset)
@@ -1241,10 +1095,6 @@ extern _X_EXPORT void xf86SlowBCopyToBus(unsigned char *, unsigned char *, int);
      xf86WriteMmio16Le(base, offset, (CARD16)(val))
 #define MMIO_OUT32(base, offset, val) \
      xf86WriteMmio32Le(base, offset, (CARD32)(val))
-#define MMIO_ONB16(base, offset, val) \
-     xf86WriteMmioNB16Le(base, offset, (CARD16)(val))
-#define MMIO_ONB32(base, offset, val) \
-     xf86WriteMmioNB32Le(base, offset, (CARD32)(val))
 #endif
 
 #elif defined(__sparc__) || defined(sparc) || defined(__sparc)
@@ -1258,8 +1108,6 @@ extern _X_EXPORT void xf86SlowBCopyToBus(unsigned char *, unsigned char *, int);
 #define MMIO_IN8(base, offset) xf86ReadMmio8(base, offset)
 #define MMIO_OUT8(base, offset, val) \
     xf86WriteMmio8(base, offset, (CARD8)(val))
-#define MMIO_ONB8(base, offset, val) \
-    xf86WriteMmio8NB(base, offset, (CARD8)(val))
 
 #if defined(SPARC_MMIO_IS_BE)   /* No byteswapping */
 #define MMIO_IN16(base, offset) xf86ReadMmio16Be(base, offset)
@@ -1268,10 +1116,6 @@ extern _X_EXPORT void xf86SlowBCopyToBus(unsigned char *, unsigned char *, int);
      xf86WriteMmio16Be(base, offset, (CARD16)(val))
 #define MMIO_OUT32(base, offset, val) \
      xf86WriteMmio32Be(base, offset, (CARD32)(val))
-#define MMIO_ONB16(base, offset, val) \
-     xf86WriteMmio16BeNB(base, offset, (CARD16)(val))
-#define MMIO_ONB32(base, offset, val) \
-     xf86WriteMmio32BeNB(base, offset, (CARD32)(val))
 #else                           /* byteswapping is the default */
 #define MMIO_IN16(base, offset) xf86ReadMmio16Le(base, offset)
 #define MMIO_IN32(base, offset) xf86ReadMmio32Le(base, offset)
@@ -1279,10 +1123,6 @@ extern _X_EXPORT void xf86SlowBCopyToBus(unsigned char *, unsigned char *, int);
      xf86WriteMmio16Le(base, offset, (CARD16)(val))
 #define MMIO_OUT32(base, offset, val) \
      xf86WriteMmio32Le(base, offset, (CARD32)(val))
-#define MMIO_ONB16(base, offset, val) \
-     xf86WriteMmio16LeNB(base, offset, (CARD16)(val))
-#define MMIO_ONB32(base, offset, val) \
-     xf86WriteMmio32LeNB(base, offset, (CARD32)(val))
 #endif
 
 #elif defined(__nds32__)
@@ -1295,8 +1135,6 @@ extern _X_EXPORT void xf86SlowBCopyToBus(unsigned char *, unsigned char *, int);
 #define MMIO_IN8(base, offset) xf86ReadMmio8(base, offset)
 #define MMIO_OUT8(base, offset, val) \
     xf86WriteMmio8(base, offset, (CARD8)(val))
-#define MMIO_ONB8(base, offset, val) \
-    xf86WriteMmioNB8(base, offset, (CARD8)(val))
 
 #if defined(NDS32_MMIO_SWAP)    /* byteswapping */
 #define MMIO_IN16(base, offset) xf86ReadMmio16Swap(base, offset)
@@ -1305,10 +1143,6 @@ extern _X_EXPORT void xf86SlowBCopyToBus(unsigned char *, unsigned char *, int);
     xf86WriteMmio16Swap(base, offset, (CARD16)(val))
 #define MMIO_OUT32(base, offset, val) \
     xf86WriteMmio32Swap(base, offset, (CARD32)(val))
-#define MMIO_ONB16(base, offset, val) \
-    xf86WriteMmioNB16Swap(base, offset, (CARD16)(val))
-#define MMIO_ONB32(base, offset, val) \
-    xf86WriteMmioNB32Swap(base, offset, (CARD32)(val))
 #else                           /* no byteswapping is the default */
 #define MMIO_IN16(base, offset) xf86ReadMmio16(base, offset)
 #define MMIO_IN32(base, offset) xf86ReadMmio32(base, offset)
@@ -1316,10 +1150,6 @@ extern _X_EXPORT void xf86SlowBCopyToBus(unsigned char *, unsigned char *, int);
      xf86WriteMmio16(base, offset, (CARD16)(val))
 #define MMIO_OUT32(base, offset, val) \
      xf86WriteMmio32(base, offset, (CARD32)(val))
-#define MMIO_ONB16(base, offset, val) \
-     xf86WriteMmioNB16(base, offset, (CARD16)(val))
-#define MMIO_ONB32(base, offset, val) \
-     xf86WriteMmioNB32(base, offset, (CARD32)(val))
 #endif
 
 #else                           /* !__alpha__ && !__powerpc__ && !__sparc__ */
@@ -1336,9 +1166,6 @@ extern _X_EXPORT void xf86SlowBCopyToBus(unsigned char *, unsigned char *, int);
 	*(volatile CARD16 *)(void *)(((CARD8*)(base)) + (offset)) = (val)
 #define MMIO_OUT32(base, offset, val) \
 	*(volatile CARD32 *)(void *)(((CARD8*)(base)) + (offset)) = (val)
-#define MMIO_ONB8(base, offset, val) MMIO_OUT8(base, offset, val)
-#define MMIO_ONB16(base, offset, val) MMIO_OUT16(base, offset, val)
-#define MMIO_ONB32(base, offset, val) MMIO_OUT32(base, offset, val)
 
 #endif                          /* __alpha__ */
 
diff --git a/hw/xfree86/os-support/bsd/alpha_video.c b/hw/xfree86/os-support/bsd/alpha_video.c
index 95bd059..f656f55 100644
--- a/hw/xfree86/os-support/bsd/alpha_video.c
+++ b/hw/xfree86/os-support/bsd/alpha_video.c
@@ -431,12 +431,6 @@ extern int readDense8(void *Base, register unsigned long Offset);
 extern int readDense16(void *Base, register unsigned long Offset);
 extern int readDense32(void *Base, register unsigned long Offset);
 extern void
- writeDenseNB8(int Value, void *Base, register unsigned long Offset);
-extern void
- writeDenseNB16(int Value, void *Base, register unsigned long Offset);
-extern void
- writeDenseNB32(int Value, void *Base, register unsigned long Offset);
-extern void
  writeDense8(int Value, void *Base, register unsigned long Offset);
 extern void
  writeDense16(int Value, void *Base, register unsigned long Offset);
@@ -666,12 +660,6 @@ void (*xf86WriteMmio16) (int Value, void *Base, unsigned long Offset)
     = writeDense16;
 void (*xf86WriteMmio32) (int Value, void *Base, unsigned long Offset)
     = writeDense32;
-void (*xf86WriteMmioNB8) (int Value, void *Base, unsigned long Offset)
-    = writeDenseNB8;
-void (*xf86WriteMmioNB16) (int Value, void *Base, unsigned long Offset)
-    = writeDenseNB16;
-void (*xf86WriteMmioNB32) (int Value, void *Base, unsigned long Offset)
-    = writeDenseNB32;
 int (*xf86ReadMmio8) (void *Base, unsigned long Offset)
     = readDense8;
 int (*xf86ReadMmio16) (void *Base, unsigned long Offset)
diff --git a/hw/xfree86/os-support/bsd/bsd_ev56.c b/hw/xfree86/os-support/bsd/bsd_ev56.c
index 320bb23..9588349 100644
--- a/hw/xfree86/os-support/bsd/bsd_ev56.c
+++ b/hw/xfree86/os-support/bsd/bsd_ev56.c
@@ -26,12 +26,6 @@ int readDense8(void *Base, register unsigned long Offset);
 int readDense16(void *Base, register unsigned long Offset);
 int readDense32(void *Base, register unsigned long Offset);
 void
- writeDenseNB8(int Value, void *Base, register unsigned long Offset);
-void
- writeDenseNB16(int Value, void *Base, register unsigned long Offset);
-void
- writeDenseNB32(int Value, void *Base, register unsigned long Offset);
-void
  writeDense8(int Value, void *Base, register unsigned long Offset);
 void
  writeDense16(int Value, void *Base, register unsigned long Offset);
@@ -60,24 +54,6 @@ readDense32(void *Base, register unsigned long Offset)
 }
 
 void
-writeDenseNB8(int Value, void *Base, register unsigned long Offset)
-{
-    alpha_stb((void *) ((unsigned long) Base + (Offset)), Value);
-}
-
-void
-writeDenseNB16(int Value, void *Base, register unsigned long Offset)
-{
-    alpha_stw((void *) ((unsigned long) Base + (Offset)), Value);
-}
-
-void
-writeDenseNB32(int Value, void *Base, register unsigned long Offset)
-{
-    *(volatile CARD32 *) ((unsigned long) Base + (Offset)) = Value;
-}
-
-void
 writeDense8(int Value, void *Base, register unsigned long Offset)
 {
     write_mem_barrier();
diff --git a/hw/xfree86/os-support/linux/lnx_ev56.c b/hw/xfree86/os-support/linux/lnx_ev56.c
index b695000..4e886b6 100644
--- a/hw/xfree86/os-support/linux/lnx_ev56.c
+++ b/hw/xfree86/os-support/linux/lnx_ev56.c
@@ -10,12 +10,6 @@ int readDense8(void *Base, register unsigned long Offset);
 int readDense16(void *Base, register unsigned long Offset);
 int readDense32(void *Base, register unsigned long Offset);
 void
- writeDenseNB8(int Value, void *Base, register unsigned long Offset);
-void
- writeDenseNB16(int Value, void *Base, register unsigned long Offset);
-void
- writeDenseNB32(int Value, void *Base, register unsigned long Offset);
-void
  writeDense8(int Value, void *Base, register unsigned long Offset);
 void
  writeDense16(int Value, void *Base, register unsigned long Offset);
@@ -44,24 +38,6 @@ readDense32(void *Base, register unsigned long Offset)
 }
 
 void
-writeDenseNB8(int Value, void *Base, register unsigned long Offset)
-{
-    *(volatile CARD8 *) ((unsigned long) Base + (Offset)) = Value;
-}
-
-void
-writeDenseNB16(int Value, void *Base, register unsigned long Offset)
-{
-    *(volatile CARD16 *) ((unsigned long) Base + (Offset)) = Value;
-}
-
-void
-writeDenseNB32(int Value, void *Base, register unsigned long Offset)
-{
-    *(volatile CARD32 *) ((unsigned long) Base + (Offset)) = Value;
-}
-
-void
 writeDense8(int Value, void *Base, register unsigned long Offset)
 {
     write_mem_barrier();
diff --git a/hw/xfree86/os-support/linux/lnx_video.c b/hw/xfree86/os-support/linux/lnx_video.c
index 652f963..ffffc81 100644
--- a/hw/xfree86/os-support/linux/lnx_video.c
+++ b/hw/xfree86/os-support/linux/lnx_video.c
@@ -571,12 +571,6 @@ extern int readDense8(void *Base, register unsigned long Offset);
 extern int readDense16(void *Base, register unsigned long Offset);
 extern int readDense32(void *Base, register unsigned long Offset);
 extern void
- writeDenseNB8(int Value, void *Base, register unsigned long Offset);
-extern void
- writeDenseNB16(int Value, void *Base, register unsigned long Offset);
-extern void
- writeDenseNB32(int Value, void *Base, register unsigned long Offset);
-extern void
  writeDense8(int Value, void *Base, register unsigned long Offset);
 extern void
  writeDense16(int Value, void *Base, register unsigned long Offset);
@@ -867,12 +861,6 @@ void (*xf86WriteMmio16) (int Value, void *Base, unsigned long Offset)
     = writeDense16;
 void (*xf86WriteMmio32) (int Value, void *Base, unsigned long Offset)
     = writeDense32;
-void (*xf86WriteMmioNB8) (int Value, void *Base, unsigned long Offset)
-    = writeDenseNB8;
-void (*xf86WriteMmioNB16) (int Value, void *Base, unsigned long Offset)
-    = writeDenseNB16;
-void (*xf86WriteMmioNB32) (int Value, void *Base, unsigned long Offset)
-    = writeDenseNB32;
 int (*xf86ReadMmio8) (void *Base, unsigned long Offset)
     = readDense8;
 int (*xf86ReadMmio16) (void *Base, unsigned long Offset)
commit 9b33e31d4160dc484ee569740f883f4d34e10653
Author: Adam Jackson <ajax at redhat.com>
Date:   Tue Jul 22 10:59:09 2014 -0400

    xfree86: Clean up powerpc barrier decls
    
    I think the externs are there for the non-gcc case?  And maybe there was
    some assembly code to implement that once?  Whatever, at this point on
    ppc the compiler is either gcc or willing to pretend.  The macros below
    the decls take care of the actual eieio so the externs can just go.
    
    Also remove a comment that maybe made sense once upon a time.
    
    Reviewed-by: Julien Cristau <jcristau at debian.org>
    Signed-off-by: Adam Jackson <ajax at redhat.com>
    Signed-off-by: Keith Packard <keithp at keithp.com>

diff --git a/hw/xfree86/common/compiler.h b/hw/xfree86/common/compiler.h
index 5fd0ea0..3430585 100644
--- a/hw/xfree86/common/compiler.h
+++ b/hw/xfree86/common/compiler.h
@@ -136,11 +136,6 @@ extern _X_EXPORT void xf86WriteMmio32LeNB (void *, unsigned long, unsigned int);
 #endif                          /* __sparc__,  __arm32__, __alpha__, __nds32__ */
 #endif                          /* __arm__ */
 
-#if defined(__powerpc__) && !defined(__OpenBSD__)
-extern void mem_barrier(void);
-extern void write_mem_barrier(void);
-#endif                          /* __powerpc__ && !__OpenBSD */
-
 #endif                          /* NO_INLINE || DO_PROTOTYPES */
 
 #ifdef __GNUC__
@@ -195,7 +190,7 @@ extern void write_mem_barrier(void);
 
 #elif defined __powerpc__
 
-#ifndef eieio                   /* We deal with arch-specific eieio() routines above... */
+#ifndef eieio
 #define eieio() __asm__ __volatile__ ("eieio" ::: "memory")
 #endif                          /* eieio */
 #define mem_barrier()	eieio()
commit b5141a1fab4d45c1af62db8dc712deb9776668a9
Author: Adam Jackson <ajax at redhat.com>
Date:   Tue Jul 22 10:59:08 2014 -0400

    xfree86: Simplify a bunch of OS and arch conditionals
    
    All of this is inside #ifdef __GNUC__, between that and configure.ac we
    can assume there's a unixy thing under us.  Given that there's no real
    reason to limit the arch paths to particular OSes, so let's not.
    
    The final #elif here, combined with the ones before it, effectively said
    "if not (alpha amd64 sparc* mips* ppc* arm* nds32 m68k sh hppa s390 m32r)",
    and as the comment above it hints, it's meant to cover i386 (and happens to
    also cover itanic).  Flip the conditional around to be sensible.
    
    Reviewed-by: Julien Cristau <jcristau at debian.org>
    Signed-off-by: Adam Jackson <ajax at redhat.com>
    Signed-off-by: Keith Packard <keithp at keithp.com>

diff --git a/hw/xfree86/common/compiler.h b/hw/xfree86/common/compiler.h
index 54da1fd..5fd0ea0 100644
--- a/hw/xfree86/common/compiler.h
+++ b/hw/xfree86/common/compiler.h
@@ -218,7 +218,7 @@ extern void write_mem_barrier(void);
 #endif
 
 #ifdef __GNUC__
-#if (defined(linux) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__)) && (defined(__alpha__))
+#if defined(__alpha__)
 
 #ifdef linux
 /* for Linux on Alpha, we use the LIBC _inx/_outx routines */
@@ -291,7 +291,7 @@ extern _X_EXPORT unsigned int inl(unsigned int port);
 #include <machine/pio.h>
 #endif                          /* __NetBSD__ */
 
-#elif (defined(linux) || defined(__FreeBSD__)) && defined(__amd64__)
+#elif defined(__amd64__)
 
 #include <inttypes.h>
 
@@ -340,7 +340,7 @@ inl(unsigned short port)
     return ret;
 }
 
-#elif (defined(linux) || defined(sun) || defined(__OpenBSD__) || defined(__FreeBSD__)) && defined(__sparc__)
+#elif defined(__sparc__)
 
 #ifndef ASI_PL
 #define ASI_PL 0x88
@@ -652,7 +652,7 @@ xf86WriteMmio32Be(__volatile__ void *base, const unsigned long offset,
 #endif                          /* !linux */
 #endif                          /* __mips__ */
 
-#elif (defined(linux) || defined(__OpenBSD__) || defined(__NetBSD__) || defined(__FreeBSD__)) && defined(__powerpc__)
+#elif defined(__powerpc__)
 
 #ifndef MAP_FAILED
 #define MAP_FAILED ((void *)-1)
@@ -1103,12 +1103,7 @@ inl(unsigned PORT_SIZE port)
 #define mem_barrier()           /* XXX: nop for now */
 #define write_mem_barrier()     /* XXX: nop for now */
 
-#else                           /* ix86 */
-
-#if !defined(__mc68000__) && !defined(__arm__) && \
-    !defined(__sh__) && !defined(__hppa__) && !defined(__s390__) && \
-    !defined(__m32r__) && !defined(__aarch64__) && !defined(__arc__) && \
-    !defined(__xtensa__)
+#elif defined(__i386__) || defined(__ia64__)
 
 static __inline__ void
 outb(unsigned short port, unsigned char val)
@@ -1155,9 +1150,7 @@ inl(unsigned short port)
     return ret;
 }
 
-#endif
-
-#endif                          /* ix86 */
+#endif                          /* arch madness */
 
 #else                           /* !GNUC */
 #if defined(__STDC__) && (__STDC__ == 1)
commit 6d3ba80f197b04b6e0814190cf5c678c786c14d6
Author: Adam Jackson <ajax at redhat.com>
Date:   Tue Jul 22 10:59:07 2014 -0400

    xfree86: Remove pre-2.6 Linux ppc support
    
    2.6.0 was December 2003, you've had plenty of time to get your head in
    the game.
    
    Reviewed-by: Julien Cristau <jcristau at debian.org>
    Signed-off-by: Adam Jackson <ajax at redhat.com>
    Signed-off-by: Keith Packard <keithp at keithp.com>

diff --git a/hw/xfree86/common/compiler.h b/hw/xfree86/common/compiler.h
index a5426e1..54da1fd 100644
--- a/hw/xfree86/common/compiler.h
+++ b/hw/xfree86/common/compiler.h
@@ -195,13 +195,6 @@ extern void write_mem_barrier(void);
 
 #elif defined __powerpc__
 
-#if defined(linux) && defined(__powerpc64__)
-#include <linux/version.h>
-#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 0)
-#include <asm/memory.h>
-#endif
-#endif                          /* defined(linux) && defined(__powerpc64__) */
-
 #ifndef eieio                   /* We deal with arch-specific eieio() routines above... */
 #define eieio() __asm__ __volatile__ ("eieio" ::: "memory")
 #endif                          /* eieio */
commit e242e82eba17414603c8806fffc9ecd235eebabb
Author: Adam Jackson <ajax at redhat.com>
Date:   Tue Jul 22 10:59:06 2014 -0400

    xfree86: Remove a useless !__SUNPRO_C guard
    
    You can't tell from context here, but this is all inside #ifdef
    __GNUC__, so this conditional can't do squat.
    
    Reviewed-by: Julien Cristau <jcristau at debian.org>
    Signed-off-by: Adam Jackson <ajax at redhat.com>
    Signed-off-by: Keith Packard <keithp at keithp.com>

diff --git a/hw/xfree86/common/compiler.h b/hw/xfree86/common/compiler.h
index 4ed6ca4..a5426e1 100644
--- a/hw/xfree86/common/compiler.h
+++ b/hw/xfree86/common/compiler.h
@@ -1112,7 +1112,6 @@ inl(unsigned PORT_SIZE port)
 
 #else                           /* ix86 */
 
-#if !defined(__SUNPRO_C)
 #if !defined(__mc68000__) && !defined(__arm__) && \
     !defined(__sh__) && !defined(__hppa__) && !defined(__s390__) && \
     !defined(__m32r__) && !defined(__aarch64__) && !defined(__arc__) && \
@@ -1164,7 +1163,6 @@ inl(unsigned short port)
 }
 
 #endif
-#endif                          /* __SUNPRO_C */
 
 #endif                          /* ix86 */
 
commit 93745a6c1afc830759219f8632ec565d83c7bc12
Author: Adam Jackson <ajax at redhat.com>
Date:   Tue Jul 22 10:59:05 2014 -0400

    xfree86: Undef GCCUSESGAS
    
    Can't be needed, we've never defined it in modular xserver.
    
    Reviewed-by: Julien Cristau <jcristau at debian.org>
    Signed-off-by: Adam Jackson <ajax at redhat.com>
    Signed-off-by: Keith Packard <keithp at keithp.com>

diff --git a/hw/xfree86/common/compiler.h b/hw/xfree86/common/compiler.h
index f691f9d..4ed6ca4 100644
--- a/hw/xfree86/common/compiler.h
+++ b/hw/xfree86/common/compiler.h
@@ -1117,59 +1117,6 @@ inl(unsigned PORT_SIZE port)
     !defined(__sh__) && !defined(__hppa__) && !defined(__s390__) && \
     !defined(__m32r__) && !defined(__aarch64__) && !defined(__arc__) && \
     !defined(__xtensa__)
-#ifdef GCCUSESGAS
-
-/*
- * If gcc uses gas rather than the native assembler, the syntax of these
- * inlines has to be different.		DHD
- */
-
-static __inline__ void
-outb(unsigned short port, unsigned char val)
-{
-    __asm__ __volatile__("outb %0,%1"::"a"(val), "d"(port));
-}
-
-static __inline__ void
-outw(unsigned short port, unsigned short val)
-{
-    __asm__ __volatile__("outw %0,%1"::"a"(val), "d"(port));
-}
-
-static __inline__ void
-outl(unsigned short port, unsigned int val)
-{
-    __asm__ __volatile__("outl %0,%1"::"a"(val), "d"(port));
-}
-
-static __inline__ unsigned int
-inb(unsigned short port)
-{
-    unsigned char ret;
-    __asm__ __volatile__("inb %1,%0":"=a"(ret):"d"(port));
-
-    return ret;
-}
-
-static __inline__ unsigned int
-inw(unsigned short port)
-{
-    unsigned short ret;
-    __asm__ __volatile__("inw %1,%0":"=a"(ret):"d"(port));
-
-    return ret;
-}
-
-static __inline__ unsigned int
-inl(unsigned short port)
-{
-    unsigned int ret;
-    __asm__ __volatile__("inl %1,%0":"=a"(ret):"d"(port));
-
-    return ret;
-}
-
-#else                           /* GCCUSESGAS */
 
 static __inline__ void
 outb(unsigned short port, unsigned char val)
@@ -1216,7 +1163,6 @@ inl(unsigned short port)
     return ret;
 }
 
-#endif                          /* GCCUSESGAS */
 #endif
 #endif                          /* __SUNPRO_C */
 
commit b1d9bc8d1d828b0dedda46da98628b47915e6a04
Author: Adam Jackson <ajax at redhat.com>
Date:   Tue Jul 22 10:59:04 2014 -0400

    xfree86: Remove an unlikely bit of #pragma
    
    __USLC__ appears to mean the SCO OpenServer compiler, which configure.ac
    doesn't think is an OS the xfree86 ddx supports.  The conditionals
    surrounding these pragmas effectively mean "if not gcc and not Sun C",
    and probably arbitrary pragmas aren't supported by arbitrary compilers.
    
    Reviewed-by: Julien Cristau <jcristau at debian.org>
    Signed-off-by: Adam Jackson <ajax at redhat.com>
    Signed-off-by: Keith Packard <keithp at keithp.com>

diff --git a/hw/xfree86/common/compiler.h b/hw/xfree86/common/compiler.h
index 0b2f98a..f691f9d 100644
--- a/hw/xfree86/common/compiler.h
+++ b/hw/xfree86/common/compiler.h
@@ -1231,14 +1231,6 @@ inl(unsigned short port)
 #if !defined(__SUNPRO_C)
 #include <sys/inline.h>
 #endif
-#if  !defined(__SUNPRO_C) || defined(__USLC__)
-#pragma asm partial_optimization outl
-#pragma asm partial_optimization outw
-#pragma asm partial_optimization outb
-#pragma asm partial_optimization inl
-#pragma asm partial_optimization inw
-#pragma asm partial_optimization inb
-#endif
 #endif                          /* __GNUC__ */
 
 #ifdef __alpha__
commit f7f9ccef1dc251a1b95ca698ac39bd0a47f0c8fa
Author: Adam Jackson <ajax at redhat.com>
Date:   Tue Jul 22 10:59:03 2014 -0400

    xfree86: Undef __HIGHC__
    
    MetaWare High C++ compiler?  xfree86 cvs history shows this being added
    in a commit whose text is, classically, "updates".  metaware.com
    redirects to a 404 on synopsys.com, which to me indicates it's not super
    important to them, and their order form won't even tell you how much the
    thing costs.  At any rate if this is worth worrying about it's worth
    letting autoconf worry about for us.
    
    Reviewed-by: Julien Cristau <jcristau at debian.org>
    Signed-off-by: Adam Jackson <ajax at redhat.com>
    Signed-off-by: Keith Packard <keithp at keithp.com>

diff --git a/hw/xfree86/common/compiler.h b/hw/xfree86/common/compiler.h
index 2794f44..0b2f98a 100644
--- a/hw/xfree86/common/compiler.h
+++ b/hw/xfree86/common/compiler.h
@@ -79,8 +79,6 @@
 #ifndef __inline__
 #if defined(__GNUC__)
     /* gcc has __inline__ */
-#elif defined(__HIGHC__)
-#define __inline__ _Inline
 #else
 #define __inline__ /**/
 #endif
@@ -88,8 +86,6 @@
 #ifndef __inline
 #if defined(__GNUC__)
     /* gcc has __inline */
-#elif defined(__HIGHC__)
-#define __inline _Inline
 #else
 #define __inline /**/
 #endif
@@ -1235,8 +1231,7 @@ inl(unsigned short port)
 #if !defined(__SUNPRO_C)
 #include <sys/inline.h>
 #endif
-#if !defined(__HIGHC__) && !defined(__SUNPRO_C) || \
-	defined(__USLC__)
+#if  !defined(__SUNPRO_C) || defined(__USLC__)
 #pragma asm partial_optimization outl
 #pragma asm partial_optimization outw
 #pragma asm partial_optimization outb
commit 80446086b9cfcc5e23a400d7fa38ec773fae68fc
Author: Adam Jackson <ajax at redhat.com>
Date:   Tue Jul 22 10:59:02 2014 -0400

    xfree86: Undef FAKEIT
    
    I guess this is meant to stub out all I/O port calls?  Whatever, it's
    not been defined by the buildsystem at least as far back as monolith
    6.8.2.
    
    Reviewed-by: Julien Cristau <jcristau at debian.org>
    Signed-off-by: Adam Jackson <ajax at redhat.com>
    Signed-off-by: Keith Packard <keithp at keithp.com>

diff --git a/hw/xfree86/common/compiler.h b/hw/xfree86/common/compiler.h
index c786868..2794f44 100644
--- a/hw/xfree86/common/compiler.h
+++ b/hw/xfree86/common/compiler.h
@@ -1117,7 +1117,7 @@ inl(unsigned PORT_SIZE port)
 #else                           /* ix86 */
 
 #if !defined(__SUNPRO_C)
-#if !defined(FAKEIT) && !defined(__mc68000__) && !defined(__arm__) && \
+#if !defined(__mc68000__) && !defined(__arm__) && \
     !defined(__sh__) && !defined(__hppa__) && !defined(__s390__) && \
     !defined(__m32r__) && !defined(__aarch64__) && !defined(__arc__) && \
     !defined(__xtensa__)
@@ -1221,43 +1221,7 @@ inl(unsigned short port)
 }
 
 #endif                          /* GCCUSESGAS */
-
-#else                           /* !defined(FAKEIT) && !defined(__mc68000__)  && !defined(__arm__) && !defined(__sh__) && !defined(__hppa__) && !defined(__m32r__) && !defined(__arc__) */
-
-static __inline__ void
-outb(unsigned short port, unsigned char val)
-{
-}
-
-static __inline__ void
-outw(unsigned short port, unsigned short val)
-{
-}
-
-static __inline__ void
-outl(unsigned short port, unsigned int val)
-{
-}
-
-static __inline__ unsigned int
-inb(unsigned short port)
-{
-    return 0;
-}
-
-static __inline__ unsigned int
-inw(unsigned short port)
-{
-    return 0;
-}
-
-static __inline__ unsigned int
-inl(unsigned short port)
-{
-    return 0;
-}
-
-#endif                          /* FAKEIT */
+#endif
 #endif                          /* __SUNPRO_C */
 
 #endif                          /* ix86 */
commit 8002b1a8cb18ecc6526e8ebfd769767f8991ebd6
Author: Adam Jackson <ajax at redhat.com>
Date:   Tue Jul 22 10:59:01 2014 -0400

    xfree86: Remove a few random ppc decls
    
    Whatever these are, they're not something grep can find, they must not
    be used.
    
    Reviewed-by: Julien Cristau <jcristau at debian.org>
    Signed-off-by: Adam Jackson <ajax at redhat.com>
    Signed-off-by: Keith Packard <keithp at keithp.com>

diff --git a/hw/xfree86/common/compiler.h b/hw/xfree86/common/compiler.h
index 5cc8eb0..c786868 100644
--- a/hw/xfree86/common/compiler.h
+++ b/hw/xfree86/common/compiler.h
@@ -143,10 +143,6 @@ extern _X_EXPORT void xf86WriteMmio32LeNB (void *, unsigned long, unsigned int);
 #if defined(__powerpc__) && !defined(__OpenBSD__)
 extern void mem_barrier(void);
 extern void write_mem_barrier(void);
-extern void stl_brx(unsigned long, volatile unsigned char *, int);
-extern void stw_brx(unsigned short, volatile unsigned char *, int);
-extern unsigned long ldl_brx(volatile unsigned char *, int);
-extern unsigned short ldw_brx(volatile unsigned char *, int);
 #endif                          /* __powerpc__ && !__OpenBSD */
 
 #endif                          /* NO_INLINE || DO_PROTOTYPES */
commit 5f5af5d6692b625f6231c8bca3ac801f2ac75717
Author: Adam Jackson <ajax at redhat.com>
Date:   Tue Jul 22 10:59:00 2014 -0400

    xfree86: Remove remaining unused unaligned accessors
    
    Reviewed-by: Julien Cristau <jcristau at debian.org>
    Signed-off-by: Adam Jackson <ajax at redhat.com>
    Signed-off-by: Keith Packard <keithp at keithp.com>

diff --git a/hw/xfree86/common/compiler.h b/hw/xfree86/common/compiler.h
index 06879b1..5cc8eb0 100644
--- a/hw/xfree86/common/compiler.h
+++ b/hw/xfree86/common/compiler.h
@@ -141,10 +141,6 @@ extern _X_EXPORT void xf86WriteMmio32LeNB (void *, unsigned long, unsigned int);
 #endif                          /* __arm__ */
 
 #if defined(__powerpc__) && !defined(__OpenBSD__)
-extern unsigned long ldl_u(unsigned int *);
-extern unsigned long ldw_u(unsigned short *);
-extern void stl_u(unsigned long, unsigned int *);
-extern void stw_u(unsigned long, unsigned short *);
 extern void mem_barrier(void);
 extern void write_mem_barrier(void);
 extern void stl_brx(unsigned long, volatile unsigned char *, int);
@@ -901,8 +897,7 @@ xf_outl(unsigned short port, unsigned int val)
 
 /*
  * Assume all port access are aligned.  We need to revise this implementation
- * if there is unaligned port access.  For ldl_u, ldw_u, stl_u and
- * stw_u, they are assumed unaligned.
+ * if there is unaligned port access.
  */
 
 #define barrier()               /* no barrier */
@@ -1078,28 +1073,6 @@ inl(unsigned PORT_SIZE port)
     return xf86ReadMmio32Swap(IOPortBase, port);
 }
 
-static __inline__ unsigned long
-ldl_u(unsigned int *p)
-{
-    unsigned long addr = (unsigned long) p;
-    unsigned int ret;
-
-    __asm__ __volatile__("lmw.bi %0, [%1], %0, 0;\n\t"
-                         "wsbh %0, %0;\n\t" "rotri %0, %0, 16;\n\t":"=r"(ret)
-                         :"r"(addr));
-
-    return ret;
-}
-
-static __inline__ void
-stl_u(unsigned long val, unsigned int *p)
-{
-    unsigned long addr = (unsigned long) p;
-
-    __asm__ __volatile__("wsbh %0, %0;\n\t" "rotri %0, %0, 16;\n\t" "smw.bi %0, [%1], %0, 0;\n\t":      /* No outputs */
-                         :"r"(val), "r"(addr));
-}
-
 #else                           /* !NDS32_MMIO_SWAP */
 static __inline__ void
 outb(unsigned PORT_SIZE port, unsigned char val)
@@ -1140,40 +1113,8 @@ inl(unsigned PORT_SIZE port)
     return *(volatile unsigned int *) (((unsigned PORT_SIZE) (port)));
 }
 
-static __inline__ unsigned long
-ldl_u(unsigned int *p)
-{
-    unsigned long addr = (unsigned long) p;
-    unsigned int ret;
-
-    __asm__ __volatile__("lmw.bi %0, [%1], %0, 0;\n\t":"=r"(ret)
-                         :"r"(addr));
-
-    return ret;
-}
-
-static __inline__ void
-stl_u(unsigned long val, unsigned int *p)
-{
-    unsigned long addr = (unsigned long) p;
-
-    __asm__ __volatile__("smw.bi %0, [%1], %0, 0;\n\t": /* No outputs */
-                         :"r"(val), "r"(addr));
-}
 #endif                          /* NDS32_MMIO_SWAP */
 
-#if (((X_BYTE_ORDER == X_BIG_ENDIAN) && !defined(NDS32_MMIO_SWAP)) || ((X_BYTE_ORDER != X_BIG_ENDIAN) && defined(NDS32_MMIO_SWAP)))
-#define ldw_u(p)	((*(unsigned char *)(p)) << 8 | \
-			(*((unsigned char *)(p)+1)))
-#define stw_u(v,p)	(*(unsigned char *)(p)) = ((v) >> 8); \
-				(*((unsigned char *)(p)+1)) = (v)
-#else
-#define ldw_u(p)	((*(unsigned char *)(p)) | \
-			(*((unsigned char *)(p)+1)<<8))
-#define stw_u(v,p)	(*(unsigned char *)(p)) = (v); \
-				(*((unsigned char *)(p)+1)) = ((v) >> 8)
-#endif
-
 #define mem_barrier()           /* XXX: nop for now */
 #define write_mem_barrier()     /* XXX: nop for now */
 
commit d28b788e11182d134bce5a414359841b37b62ac0
Author: Adam Jackson <ajax at redhat.com>
Date:   Tue Jul 22 10:58:59 2014 -0400

    xfree86: Move generic unaligned helpers into int10 code
    
    This is the only place they're actually used (well, aside from some XAA
    code in the s3 driver, but one s3 and 2 XAA).
    
    Reviewed-by: Julien Cristau <jcristau at debian.org>
    Signed-off-by: Adam Jackson <ajax at redhat.com>
    Signed-off-by: Keith Packard <keithp at keithp.com>

diff --git a/hw/xfree86/common/compiler.h b/hw/xfree86/common/compiler.h
index fc09cd2..06879b1 100644
--- a/hw/xfree86/common/compiler.h
+++ b/hw/xfree86/common/compiler.h
@@ -236,42 +236,6 @@ extern unsigned short ldw_brx(volatile unsigned char *, int);
 #define write_mem_barrier()     /* NOP */
 #endif
 
-#include <string.h>             /* needed for memmove */
-
-static __inline__ uint32_t
-ldl_u(uint32_t * p)
-{
-    uint32_t ret;
-
-    memmove(&ret, p, sizeof(*p));
-    return ret;
-}
-
-static __inline__ uint16_t
-ldw_u(uint16_t * p)
-{
-    uint16_t ret;
-
-    memmove(&ret, p, sizeof(*p));
-    return ret;
-}
-
-static __inline__ void
-stl_u(uint32_t val, uint32_t * p)
-{
-    uint32_t tmp = val;
-
-    memmove(p, &tmp, sizeof(*p));
-}
-
-static __inline__ void
-stw_u(uint16_t val, uint16_t * p)
-{
-    uint16_t tmp = val;
-
-    memmove(p, &tmp, sizeof(*p));
-}
-
 #ifdef __GNUC__
 #if (defined(linux) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__)) && (defined(__alpha__))
 
diff --git a/hw/xfree86/int10/generic.c b/hw/xfree86/int10/generic.c
index abbd36f..73a1e5e 100644
--- a/hw/xfree86/int10/generic.c
+++ b/hw/xfree86/int10/generic.c
@@ -20,6 +20,42 @@
 
 #define ALLOC_ENTRIES(x) ((V_RAM / x) - 1)
 
+#include <string.h>             /* needed for memmove */
+
+static __inline__ uint32_t
+ldl_u(uint32_t * p)
+{
+    uint32_t ret;
+
+    memmove(&ret, p, sizeof(*p));
+    return ret;
+}
+
+static __inline__ uint16_t
+ldw_u(uint16_t * p)
+{
+    uint16_t ret;
+
+    memmove(&ret, p, sizeof(*p));
+    return ret;
+}
+
+static __inline__ void
+stl_u(uint32_t val, uint32_t * p)
+{
+    uint32_t tmp = val;
+
+    memmove(p, &tmp, sizeof(*p));
+}
+
+static __inline__ void
+stw_u(uint16_t val, uint16_t * p)
+{
+    uint16_t tmp = val;
+
+    memmove(p, &tmp, sizeof(*p));
+}
+
 static uint8_t read_b(xf86Int10InfoPtr pInt, int addr);
 static uint16_t read_w(xf86Int10InfoPtr pInt, int addr);
 static uint32_t read_l(xf86Int10InfoPtr pInt, int addr);
commit 956a8d5c92a66ddd8d00e63a95b17cfd376fe424
Author: Adam Jackson <ajax at redhat.com>
Date:   Tue Jul 22 10:58:58 2014 -0400

    xfree86: Remove unused unaligned int64 helpers
    
    Reviewed-by: Julien Cristau <jcristau at debian.org>
    Signed-off-by: Adam Jackson <ajax at redhat.com>
    Signed-off-by: Keith Packard <keithp at keithp.com>

diff --git a/hw/xfree86/common/compiler.h b/hw/xfree86/common/compiler.h
index 54ebb73..fc09cd2 100644
--- a/hw/xfree86/common/compiler.h
+++ b/hw/xfree86/common/compiler.h
@@ -141,10 +141,8 @@ extern _X_EXPORT void xf86WriteMmio32LeNB (void *, unsigned long, unsigned int);
 #endif                          /* __arm__ */
 
 #if defined(__powerpc__) && !defined(__OpenBSD__)
-extern unsigned long ldq_u(unsigned long *);
 extern unsigned long ldl_u(unsigned int *);
 extern unsigned long ldw_u(unsigned short *);
-extern void stq_u(unsigned long, unsigned long *);
 extern void stl_u(unsigned long, unsigned int *);
 extern void stw_u(unsigned long, unsigned short *);
 extern void mem_barrier(void);
@@ -240,15 +238,6 @@ extern unsigned short ldw_brx(volatile unsigned char *, int);
 
 #include <string.h>             /* needed for memmove */
 
-static __inline__ uint64_t
-ldq_u(uint64_t * p)
-{
-    uint64_t ret;
-
-    memmove(&ret, p, sizeof(*p));
-    return ret;
-}
-
 static __inline__ uint32_t
 ldl_u(uint32_t * p)
 {
@@ -268,14 +257,6 @@ ldw_u(uint16_t * p)
 }
 
 static __inline__ void
-stq_u(uint64_t val, uint64_t * p)
-{
-    uint64_t tmp = val;
-
-    memmove(p, &tmp, sizeof(*p));
-}
-
-static __inline__ void
 stl_u(uint32_t val, uint32_t * p)
 {
     uint32_t tmp = val;
@@ -956,7 +937,7 @@ xf_outl(unsigned short port, unsigned int val)
 
 /*
  * Assume all port access are aligned.  We need to revise this implementation
- * if there is unaligned port access.  For ldq_u, ldl_u, ldw_u, stq_u, stl_u and
+ * if there is unaligned port access.  For ldl_u, ldw_u, stl_u and
  * stw_u, they are assumed unaligned.
  */
 
@@ -1134,19 +1115,6 @@ inl(unsigned PORT_SIZE port)
 }
 
 static __inline__ unsigned long
-ldq_u(unsigned long *p)
-{
-    unsigned long addr = (unsigned long) p;
-    unsigned int ret;
-
-    __asm__ __volatile__("lmw.bi %0, [%1], %0, 0;\n\t"
-                         "wsbh %0, %0;\n\t" "rotri %0, %0, 16;\n\t":"=r"(ret)
-                         :"r"(addr));
-
-    return ret;
-}
-
-static __inline__ unsigned long
 ldl_u(unsigned int *p)
 {
     unsigned long addr = (unsigned long) p;
@@ -1160,15 +1128,6 @@ ldl_u(unsigned int *p)
 }
 
 static __inline__ void
-stq_u(unsigned long val, unsigned long *p)
-{
-    unsigned long addr = (unsigned long) p;
-
-    __asm__ __volatile__("wsbh %0, %0;\n\t" "rotri %0, %0, 16;\n\t" "smw.bi %0, [%1], %0, 0;\n\t":      /* No outputs */
-                         :"r"(val), "r"(addr));
-}
-
-static __inline__ void
 stl_u(unsigned long val, unsigned int *p)
 {
     unsigned long addr = (unsigned long) p;
@@ -1218,18 +1177,6 @@ inl(unsigned PORT_SIZE port)
 }
 
 static __inline__ unsigned long
-ldq_u(unsigned long *p)
-{
-    unsigned long addr = (unsigned long) p;
-    unsigned int ret;
-
-    __asm__ __volatile__("lmw.bi %0, [%1], %0, 0;\n\t":"=r"(ret)
-                         :"r"(addr));
-
-    return ret;
-}
-
-static __inline__ unsigned long
 ldl_u(unsigned int *p)
 {
     unsigned long addr = (unsigned long) p;
@@ -1242,15 +1189,6 @@ ldl_u(unsigned int *p)
 }
 
 static __inline__ void
-stq_u(unsigned long val, unsigned long *p)
-{
-    unsigned long addr = (unsigned long) p;
-
-    __asm__ __volatile__("smw.bi %0, [%1], %0, 0;\n\t": /* No outputs */
-                         :"r"(val), "r"(addr));
-}
-
-static __inline__ void
 stl_u(unsigned long val, unsigned int *p)
 {
     unsigned long addr = (unsigned long) p;
commit da2b2671863655776d60102ddc7af61470d14022
Author: Adam Jackson <ajax at redhat.com>
Date:   Tue Jul 22 10:58:57 2014 -0400

    xfree86: Unspecialize gcc variants of unaligned memory access
    
    Yes yes, very clever, memmove works fine on gcc too, let's just do the
    portable thing since none of this is performance code.
    
    Reviewed-by: Julien Cristau <jcristau at debian.org>
    Signed-off-by: Adam Jackson <ajax at redhat.com>
    Signed-off-by: Keith Packard <keithp at keithp.com>

diff --git a/hw/xfree86/common/compiler.h b/hw/xfree86/common/compiler.h
index 556fa7f..54ebb73 100644
--- a/hw/xfree86/common/compiler.h
+++ b/hw/xfree86/common/compiler.h
@@ -238,73 +238,6 @@ extern unsigned short ldw_brx(volatile unsigned char *, int);
 #define write_mem_barrier()     /* NOP */
 #endif
 
-#ifdef __GNUC__
-
-/* Define some packed structures to use with unaligned accesses */
-
-struct __una_u64 {
-    uint64_t x __attribute__ ((packed));
-};
-struct __una_u32 {
-    uint32_t x __attribute__ ((packed));
-};
-struct __una_u16 {
-    uint16_t x __attribute__ ((packed));
-};
-
-/* Elemental unaligned loads */
-
-static __inline__ uint64_t
-ldq_u(uint64_t * p)
-{
-    const struct __una_u64 *ptr = (const struct __una_u64 *) p;
-
-    return ptr->x;
-}
-
-static __inline__ uint32_t
-ldl_u(uint32_t * p)
-{
-    const struct __una_u32 *ptr = (const struct __una_u32 *) p;
-
-    return ptr->x;
-}
-
-static __inline__ uint16_t
-ldw_u(uint16_t * p)
-{
-    const struct __una_u16 *ptr = (const struct __una_u16 *) p;
-
-    return ptr->x;
-}
-
-/* Elemental unaligned stores */
-
-static __inline__ void
-stq_u(uint64_t val, uint64_t * p)
-{
-    struct __una_u64 *ptr = (struct __una_u64 *) p;
-
-    ptr->x = val;
-}
-
-static __inline__ void
-stl_u(uint32_t val, uint32_t * p)
-{
-    struct __una_u32 *ptr = (struct __una_u32 *) p;
-
-    ptr->x = val;
-}
-
-static __inline__ void
-stw_u(uint16_t val, uint16_t * p)
-{
-    struct __una_u16 *ptr = (struct __una_u16 *) p;
-
-    ptr->x = val;
-}
-#else                           /* !__GNUC__ */
-
 #include <string.h>             /* needed for memmove */
 
 static __inline__ uint64_t
@@ -358,8 +291,6 @@ stw_u(uint16_t val, uint16_t * p)
     memmove(p, &tmp, sizeof(*p));
 }
 
-#endif                          /* __GNUC__ */
-
 #ifdef __GNUC__
 #if (defined(linux) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__)) && (defined(__alpha__))
 
commit e03c902e03dea7a6a98ad5fb00580b9404b67c4d
Author: Adam Jackson <ajax at redhat.com>
Date:   Tue Jul 22 10:58:56 2014 -0400

    xfree86: Undefine NO_INLINE
    
    Nothing in the server defines this, nor do any drivers.
    
    Reviewed-by: Julien Cristau <jcristau at debian.org>
    Signed-off-by: Adam Jackson <ajax at redhat.com>
    Signed-off-by: Keith Packard <keithp at keithp.com>

diff --git a/hw/xfree86/common/compiler.h b/hw/xfree86/common/compiler.h
index 7dc4fab..556fa7f 100644
--- a/hw/xfree86/common/compiler.h
+++ b/hw/xfree86/common/compiler.h
@@ -98,7 +98,7 @@
 #if !defined(__GNUC__) && !defined(__FUNCTION__)
 #define __FUNCTION__ __func__   /* C99 */
 #endif
-#if defined(NO_INLINE) || defined(DO_PROTOTYPES)
+#if defined(DO_PROTOTYPES)
 #if !defined(__arm__)
 #if !defined(__sparc__) && !defined(__sparc) && !defined(__arm32__) && !defined(__nds32__) \
       && !(defined(__alpha__) && defined(linux)) \
@@ -157,7 +157,6 @@ extern unsigned short ldw_brx(volatile unsigned char *, int);
 
 #endif                          /* NO_INLINE || DO_PROTOTYPES */
 
-#ifndef NO_INLINE
 #ifdef __GNUC__
 #ifdef __i386__
 
@@ -230,7 +229,6 @@ extern unsigned short ldw_brx(volatile unsigned char *, int);
 #define write_mem_barrier()     /* XXX: nop for now */
 #endif
 #endif                          /* __GNUC__ */
-#endif                          /* NO_INLINE */
 
 #ifndef mem_barrier
 #define mem_barrier()           /* NOP */
@@ -240,7 +238,6 @@ extern unsigned short ldw_brx(volatile unsigned char *, int);
 #define write_mem_barrier()     /* NOP */
 #endif
 
-#ifndef NO_INLINE
 #ifdef __GNUC__
 
 /* Define some packed structures to use with unaligned accesses */
@@ -362,9 +359,7 @@ stw_u(uint16_t val, uint16_t * p)
 }
 
 #endif                          /* __GNUC__ */
-#endif                          /* NO_INLINE */
 
-#ifndef NO_INLINE
 #ifdef __GNUC__
 #if (defined(linux) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__)) && (defined(__alpha__))
 
@@ -1517,8 +1512,6 @@ inl(unsigned short port)
 #endif
 #endif                          /* __GNUC__ */
 
-#endif                          /* NO_INLINE */
-
 #ifdef __alpha__
 /* entry points for Mmio memory access routines */
 extern _X_EXPORT int (*xf86ReadMmio8) (void *, unsigned long);
commit f63b8e44ab278dd65be93146790bf150717fc1c8
Author: Adam Jackson <ajax at redhat.com>
Date:   Tue Jul 22 10:58:55 2014 -0400

    xfree86: Remove MMIO_MOVE32
    
    Only used by mach64's XAA code, which isn't built if XAA isn't
    available, and it isn't.
    
    Reviewed-by: Julien Cristau <jcristau at debian.org>
    Signed-off-by: Adam Jackson <ajax at redhat.com>
    Signed-off-by: Keith Packard <keithp at keithp.com>

diff --git a/hw/xfree86/common/compiler.h b/hw/xfree86/common/compiler.h
index 50b3b3a..7dc4fab 100644
--- a/hw/xfree86/common/compiler.h
+++ b/hw/xfree86/common/compiler.h
@@ -1571,8 +1571,6 @@ extern _X_EXPORT void xf86SlowBCopyToBus(unsigned char *, unsigned char *, int);
     (*xf86WriteMmioNB8)((CARD8)(val), base, offset)
 #define MMIO_ONB16(base, offset, val) \
     (*xf86WriteMmioNB16)((CARD16)(val), base, offset)
-#define MMIO_MOVE32(base, offset, val) \
-    MMIO_OUT32(base, offset, val)
 
 #elif defined(__powerpc__)
  /* 
@@ -1610,9 +1608,6 @@ extern _X_EXPORT void xf86SlowBCopyToBus(unsigned char *, unsigned char *, int);
      xf86WriteMmioNB32Le(base, offset, (CARD32)(val))
 #endif
 
-#define MMIO_MOVE32(base, offset, val) \
-       xf86WriteMmio32Be(base, offset, (CARD32)(val))
-
 #elif defined(__sparc__) || defined(sparc) || defined(__sparc)
  /*
   * Like powerpc, we provide byteswapping and no byteswapping functions
@@ -1651,9 +1646,6 @@ extern _X_EXPORT void xf86SlowBCopyToBus(unsigned char *, unsigned char *, int);
      xf86WriteMmio32LeNB(base, offset, (CARD32)(val))
 #endif
 
-#define MMIO_MOVE32(base, offset, val) \
-       xf86WriteMmio32Be(base, offset, (CARD32)(val))
-
 #elif defined(__nds32__)
  /*
   * we provide byteswapping and no byteswapping functions here
@@ -1691,9 +1683,6 @@ extern _X_EXPORT void xf86SlowBCopyToBus(unsigned char *, unsigned char *, int);
      xf86WriteMmioNB32(base, offset, (CARD32)(val))
 #endif
 
-#define MMIO_MOVE32(base, offset, val) \
-       xf86WriteMmio32(base, offset, (CARD32)(val))
-
 #else                           /* !__alpha__ && !__powerpc__ && !__sparc__ */
 
 #define MMIO_IN8(base, offset) \
@@ -1712,8 +1701,6 @@ extern _X_EXPORT void xf86SlowBCopyToBus(unsigned char *, unsigned char *, int);
 #define MMIO_ONB16(base, offset, val) MMIO_OUT16(base, offset, val)
 #define MMIO_ONB32(base, offset, val) MMIO_OUT32(base, offset, val)
 
-#define MMIO_MOVE32(base, offset, val) MMIO_OUT32(base, offset, val)
-
 #endif                          /* __alpha__ */
 
 /*
commit 1100935650cc0032709d095d6d5a5f136bec99b9
Author: Adam Jackson <ajax at redhat.com>
Date:   Tue Jul 22 10:58:54 2014 -0400

    xfree86: Remove nds32_flush_icache
    
    I guess this might have been needed for elfloader, except we didn't
    support nds32 back then, so I assume this was cargo-culted from
    ppc_flush_icache, which is also dead now.
    
    Reviewed-by: Julien Cristau <jcristau at debian.org>
    Signed-off-by: Adam Jackson <ajax at redhat.com>
    Signed-off-by: Keith Packard <keithp at keithp.com>

diff --git a/hw/xfree86/common/compiler.h b/hw/xfree86/common/compiler.h
index 1bd8def..50b3b3a 100644
--- a/hw/xfree86/common/compiler.h
+++ b/hw/xfree86/common/compiler.h
@@ -1694,23 +1694,6 @@ extern _X_EXPORT void xf86SlowBCopyToBus(unsigned char *, unsigned char *, int);
 #define MMIO_MOVE32(base, offset, val) \
        xf86WriteMmio32(base, offset, (CARD32)(val))
 
-#ifdef N1213_HC                 /* for NDS32 N1213 hardcore */
-static __inline__ void
-nds32_flush_icache(char *addr)
-{
-    __asm__ volatile ("isync %0;"
-                      "msync;"
-                      "isb;"
-                      "cctl %0,L1I_VA_INVAL;" "isb;"::"r" (addr):"memory");
-}
-#else
-static __inline__ void
-nds32_flush_icache(char *addr)
-{
-    __asm__ volatile ("isync %0;" "isb;"::"r" (addr):"memory");
-}
-#endif
-
 #else                           /* !__alpha__ && !__powerpc__ && !__sparc__ */
 
 #define MMIO_IN8(base, offset) \
commit eb76228080da6fb28c34c903a9854aebe157d2c7
Author: Adam Jackson <ajax at redhat.com>
Date:   Tue Jul 22 10:58:53 2014 -0400

    xfree86: Remove #include "compiler.h" from places that don't need it
    
    Reviewed-by: Julien Cristau <jcristau at debian.org>
    Signed-off-by: Adam Jackson <ajax at redhat.com>
    Signed-off-by: Keith Packard <keithp at keithp.com>

diff --git a/hw/xfree86/common/xf86Cursor.c b/hw/xfree86/common/xf86Cursor.c
index 7d0776e..c6abf12 100644
--- a/hw/xfree86/common/xf86Cursor.c
+++ b/hw/xfree86/common/xf86Cursor.c
@@ -37,8 +37,6 @@
 #include "scrnintstr.h"
 #include "globals.h"
 
-#include "compiler.h"
-
 #include "xf86.h"
 #include "xf86Priv.h"
 #include "xf86_OSproc.h"
diff --git a/hw/xfree86/common/xf86Events.c b/hw/xfree86/common/xf86Events.c
index 35a673d..16b3e28 100644
--- a/hw/xfree86/common/xf86Events.c
+++ b/hw/xfree86/common/xf86Events.c
@@ -58,7 +58,6 @@
 #include <X11/Xproto.h>
 #include <X11/Xatom.h>
 #include "misc.h"
-#include "compiler.h"
 #include "xf86.h"
 #include "xf86Priv.h"
 #define XF86_OS_PRIVS
diff --git a/hw/xfree86/common/xf86Init.c b/hw/xfree86/common/xf86Init.c
index 5a45004..b197c1c 100644
--- a/hw/xfree86/common/xf86Init.c
+++ b/hw/xfree86/common/xf86Init.c
@@ -56,8 +56,6 @@
 #include "dbus-core.h"
 #include "systemd-logind.h"
 
-#include "compiler.h"
-
 #include "loaderProcs.h"
 #ifdef XFreeXDGA
 #include "dgaproc.h"
diff --git a/hw/xfree86/loader/loader.c b/hw/xfree86/loader/loader.c
index 64c69bb..cc41dcb 100644
--- a/hw/xfree86/loader/loader.c
+++ b/hw/xfree86/loader/loader.c
@@ -65,7 +65,6 @@
 #include "loaderProcs.h"
 #include "xf86.h"
 #include "xf86Priv.h"
-#include "compiler.h"
 
 #ifdef HAVE_DLFCN_H
 
diff --git a/hw/xfree86/os-support/xf86_OSlib.h b/hw/xfree86/os-support/xf86_OSlib.h
index eb0a338..9120bd7 100644
--- a/hw/xfree86/os-support/xf86_OSlib.h
+++ b/hw/xfree86/os-support/xf86_OSlib.h
@@ -364,8 +364,4 @@ struct pcvtid {
 #define XF86_OS_PRIVS
 #include "xf86_OSproc.h"
 
-#ifndef NO_COMPILER_H
-#include "compiler.h"
-#endif
-
 #endif                          /* _XF86_OSLIB_H */
diff --git a/hw/xfree86/ramdac/xf86RamDacCmap.c b/hw/xfree86/ramdac/xf86RamDacCmap.c
index fa7a866..2a0f755 100644
--- a/hw/xfree86/ramdac/xf86RamDacCmap.c
+++ b/hw/xfree86/ramdac/xf86RamDacCmap.c
@@ -35,7 +35,6 @@
 #include "micmap.h"
 
 #include "xf86.h"
-#include "compiler.h"
 #include "colormapst.h"
 #include "xf86RamDacPriv.h"
 
diff --git a/hw/xfree86/vgahw/vgaCmap.c b/hw/xfree86/vgahw/vgaCmap.c
index 6e028a7..bf61225 100644
--- a/hw/xfree86/vgahw/vgaCmap.c
+++ b/hw/xfree86/vgahw/vgaCmap.c
@@ -28,7 +28,6 @@
 #include <X11/X.h>
 #include <X11/Xproto.h>
 #include "windowstr.h"
-#include "compiler.h"
 #include "mipointer.h"
 #include "micmap.h"
 
commit 4afedf545b673282f2e214c0e2c759c9be9b9a2a
Author: Ross Burton <ross.burton at intel.com>
Date:   Wed Jul 9 11:33:23 2014 +0100

    configure.ac: add option for xshmfence
    
    xshmfence is usable outside of DRI3, and is currently autodetected which isn't
    good for distributions where deterministic builds are desired.
    
    Signed-off-by: Ross Burton <ross.burton at intel.com>
    Reviewed-by: Matt Turner <mattst88 at gmail.com>
    Signed-off-by: Keith Packard <keithp at keithp.com>

diff --git a/configure.ac b/configure.ac
index 0479fd5..f3d9654 100644
--- a/configure.ac
+++ b/configure.ac
@@ -649,6 +649,7 @@ AC_ARG_ENABLE(kdrive-kbd,     AS_HELP_STRING([--enable-kdrive-kbd], [Build kbd d
 AC_ARG_ENABLE(kdrive-mouse,   AS_HELP_STRING([--enable-kdrive-mouse], [Build mouse driver for kdrive (default: auto)]), [KDRIVE_MOUSE=$enableval], [KDRIVE_MOUSE=auto])
 AC_ARG_ENABLE(kdrive-evdev,   AS_HELP_STRING([--enable-kdrive-evdev], [Build evdev driver for kdrive (default: auto)]), [KDRIVE_EVDEV=$enableval], [KDRIVE_EVDEV=auto])
 AC_ARG_ENABLE(libunwind,      AS_HELP_STRING([--enable-libunwind], [Use libunwind for backtracing (default: auto)]), [LIBUNWIND="$enableval"], [LIBUNWIND="auto"])
+AC_ARG_ENABLE(xshmfence,      AS_HELP_STRING([--disable-xshmfence], [Disable xshmfence (default: auto)]), [XSHMFENCE="$enableval"], [XSHMFENCE="auto"])
 
 
 dnl chown/chmod to be setuid root as part of build
@@ -788,7 +789,7 @@ DMXPROTO="dmxproto >= 2.2.99.1"
 VIDMODEPROTO="xf86vidmodeproto >= 2.2.99.1"
 WINDOWSWMPROTO="windowswmproto"
 APPLEWMPROTO="applewmproto >= 1.4"
-XSHMFENCE="xshmfence >= 1.1"
+LIBXSHMFENCE="xshmfence >= 1.1"
 
 dnl Required modules
 XPROTO="xproto >= 7.0.26"
@@ -1236,20 +1237,23 @@ esac
 
 AM_CONDITIONAL(BUSFAULT, test x"$BUSFAULT" = xyes)
 
-PKG_CHECK_MODULES([XSHMFENCE], $XSHMFENCE,
-		  [HAVE_XSHMFENCE=yes], [HAVE_XSHMFENCE=no])
 
-AM_CONDITIONAL(XSHMFENCE, test "x$HAVE_XSHMFENCE" = xyes)
+PKG_CHECK_MODULES([XSHMFENCE], $LIBXSHMFENCE, [HAVE_XSHMFENCE=yes], [HAVE_XSHMFENCE=no])
+if test "x$XSHMFENCE" = "xauto"; then
+    XSHMFENCE="$HAVE_XSHMFENCE"
+fi
 
-case x"$HAVE_XSHMFENCE" in
-	xyes)
-		AC_DEFINE(HAVE_XSHMFENCE, 1, [Have X Shared Memory Fence library])
-		REQUIRED_LIBS="$REQUIRED_LIBS xshmfence"
-		;;
-esac
+if test "x$XSHMFENCE" = "xyes"; then
+    if test "x$HAVE_XSHMFENCE" != "xyes"; then
+        AC_MSG_ERROR([xshmfence requested but not installed.])
+    fi
+    AC_DEFINE(HAVE_XSHMFENCE, 1, [Have xshmfence support])
+    REQUIRED_LIBS="$REQUIRED_LIBS $LIBXSHMFENCE"
+fi
 
+AM_CONDITIONAL(XSHMFENCE, [test "x$XSHMFENCE" = xyes])
 
-case "$DRI3,$HAVE_XSHMFENCE" in
+case "$DRI3,$XSHMFENCE" in
 	yes,yes | auto,yes)
 		;;
 	yes,no)
commit 2172714c67d8701aa54c202e89f246f1dddac80a
Author: Carlos Garnacho <carlosg at gnome.org>
Date:   Tue Jul 22 17:55:25 2014 +0200

    xwayland: Only disable/enable devices on capabilities change
    
    Anytime a capability is first reported, the device is created, but after
    that, it is only disabled/enabled.
    
    This is a closer behavior to what Xorg does on VT switch, at the expense
    of maybe leaving a dangling "physical" device if a capability goes for good.
    Otherwise, any DeviceIntPtr (re)created after server initialization will be
    left floating, and bad things happen when the wayland enter event handler
    tries to update cursor position based on a floating device.
    
    Signed-off-by: Carlos Garnacho <carlosg at gnome.org>
    Reviewed-by: Daniel Stone <daniel at fooishbar.org>
    Signed-off-by: Keith Packard <keithp at keithp.com>

diff --git a/hw/xwayland/xwayland-input.c b/hw/xwayland/xwayland-input.c
index 990cb82..cc5f7df 100644
--- a/hw/xwayland/xwayland-input.c
+++ b/hw/xwayland/xwayland-input.c
@@ -491,31 +491,43 @@ seat_handle_capabilities(void *data, struct wl_seat *seat,
 {
     struct xwl_seat *xwl_seat = data;
 
-    if (caps & WL_SEAT_CAPABILITY_POINTER && xwl_seat->pointer == NULL) {
+    if (caps & WL_SEAT_CAPABILITY_POINTER && xwl_seat->wl_pointer == NULL) {
         xwl_seat->wl_pointer = wl_seat_get_pointer(seat);
         wl_pointer_add_listener(xwl_seat->wl_pointer,
                                 &pointer_listener, xwl_seat);
-        xwl_seat_set_cursor(xwl_seat);
-        xwl_seat->pointer =
-            add_device(xwl_seat, "xwayland-pointer", xwl_pointer_proc);
-    }
-    else if (!(caps & WL_SEAT_CAPABILITY_POINTER) && xwl_seat->pointer) {
+
+        if (xwl_seat->pointer)
+            EnableDevice(xwl_seat->pointer, TRUE);
+        else {
+            xwl_seat_set_cursor(xwl_seat);
+            xwl_seat->pointer =
+                add_device(xwl_seat, "xwayland-pointer", xwl_pointer_proc);
+        }
+    } else if (!(caps & WL_SEAT_CAPABILITY_POINTER) && xwl_seat->wl_pointer) {
         wl_pointer_release(xwl_seat->wl_pointer);
-        RemoveDevice(xwl_seat->pointer, FALSE);
-        xwl_seat->pointer = NULL;
+        xwl_seat->wl_pointer = NULL;
+
+        if (xwl_seat->pointer)
+            DisableDevice(xwl_seat->pointer, TRUE);
     }
 
-    if (caps & WL_SEAT_CAPABILITY_KEYBOARD && xwl_seat->keyboard == NULL) {
+    if (caps & WL_SEAT_CAPABILITY_KEYBOARD && xwl_seat->wl_keyboard == NULL) {
         xwl_seat->wl_keyboard = wl_seat_get_keyboard(seat);
         wl_keyboard_add_listener(xwl_seat->wl_keyboard,
                                  &keyboard_listener, xwl_seat);
-        xwl_seat->keyboard =
-            add_device(xwl_seat, "xwayland-keyboard", xwl_keyboard_proc);
-    }
-    else if (!(caps & WL_SEAT_CAPABILITY_KEYBOARD) && xwl_seat->keyboard) {
+
+        if (xwl_seat->keyboard)
+            EnableDevice(xwl_seat->keyboard, TRUE);
+        else {
+            xwl_seat->keyboard =
+                add_device(xwl_seat, "xwayland-keyboard", xwl_keyboard_proc);
+        }
+    } else if (!(caps & WL_SEAT_CAPABILITY_KEYBOARD) && xwl_seat->wl_keyboard) {
         wl_keyboard_release(xwl_seat->wl_keyboard);
-        RemoveDevice(xwl_seat->keyboard, FALSE);
-        xwl_seat->keyboard = NULL;
+        xwl_seat->wl_keyboard = NULL;
+
+        if (xwl_seat->keyboard)
+            DisableDevice(xwl_seat->keyboard, TRUE);
     }
 
     xwl_seat->xwl_screen->expecting_event--;
commit 556cdf8fe870bc23e0393c0eed15c86f49a0b9f8
Merge: 83701c4 1faa766
Author: Keith Packard <keithp at keithp.com>
Date:   Thu Jul 24 16:51:00 2014 -0700

    Merge remote-tracking branch 'jeremyhu/master'

commit 83701c4ee8f79f69f4286ef262cd3ae3922629b9
Author: Adam Jackson <ajax at redhat.com>
Date:   Mon Jul 21 10:21:07 2014 -0400

    xfree86: Remove i2c multimedia modules
    
    These came in with the GATOS merge I think.  The only driver using them
    was radeon, and then only in UMS mode.  The radeon driver dropped UMS
    support from the main branch about two years ago, the UMS branch hasn't
    been touched in about fifteen months, and does not build against 1.16 in
    any case, so this is all dead code.
    
    Signed-off-by: Adam Jackson <ajax at redhat.com>
    Reviewed-by: Alex Deucher <alexander.deucher at amd.com>
    Reviewed-by: Daniel Stone <daniels at collabora.com>
    Signed-off-by: Keith Packard <keithp at keithp.com>

diff --git a/hw/xfree86/i2c/Makefile.am b/hw/xfree86/i2c/Makefile.am
index c311591..8bf795d 100644
--- a/hw/xfree86/i2c/Makefile.am
+++ b/hw/xfree86/i2c/Makefile.am
@@ -1,43 +1,9 @@
 noinst_LTLIBRARIES = libi2c.la
 
-multimediadir = $(moduledir)/multimedia
-multimedia_LTLIBRARIES =	\
-	bt829_drv.la		\
-	fi1236_drv.la		\
-	msp3430_drv.la		\
-	tda8425_drv.la		\
-	tda9850_drv.la		\
-	tda9885_drv.la		\
-	uda1380_drv.la
-
 libi2c_la_SOURCES = xf86i2c.c
 
 AM_CPPFLAGS = $(XORG_INCS)
 
 AM_CFLAGS = $(DIX_CFLAGS) $(XORG_CFLAGS)
 
-sdk_HEADERS = xf86i2c.h bt829.h fi1236.h msp3430.h tda8425.h tda9850.h tda9885.h uda1380.h i2c_def.h
-
-#
-# i2c drivers
-#
-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 tda9885.c
-
-msp3430_drv_la_LDFLAGS = -module -avoid-version $(LD_NO_UNDEFINED_FLAG)
-msp3430_drv_la_SOURCES = msp3430.c msp3430.h msp3430_module.c
-
-tda8425_drv_la_LDFLAGS = -module -avoid-version $(LD_NO_UNDEFINED_FLAG)
-tda8425_drv_la_SOURCES = tda8425.c tda8425.h tda8425_module.c
-
-tda9850_drv_la_LDFLAGS = -module -avoid-version $(LD_NO_UNDEFINED_FLAG)
-tda9850_drv_la_SOURCES = tda9850.c tda9850.h tda9850_module.c
-
-tda9885_drv_la_LDFLAGS = -module -avoid-version $(LD_NO_UNDEFINED_FLAG)
-tda9885_drv_la_SOURCES = tda9885.c tda9885.h tda9885_module.c
-
-uda1380_drv_la_LDFLAGS = -module -avoid-version $(LD_NO_UNDEFINED_FLAG)
-uda1380_drv_la_SOURCES = uda1380.c uda1380.h uda1380_module.c
+sdk_HEADERS = xf86i2c.h i2c_def.h
diff --git a/hw/xfree86/i2c/bt829.c b/hw/xfree86/i2c/bt829.c
deleted file mode 100644
index 991c26e..0000000
--- a/hw/xfree86/i2c/bt829.c
+++ /dev/null
@@ -1,822 +0,0 @@
-/* TODO: clean up/fix CC code */
-
-#ifdef HAVE_XORG_CONFIG_H
-#include <xorg-config.h>
-#endif
-
-#include <stdlib.h>
-#include <string.h>
-#include <stdio.h>
-
-#include "xf86.h"
-#include "xf86i2c.h"
-#include "bt829.h"
-#include "i2c_def.h"
-
-/* Changing the following settings (especially VCROP) may */
-/* require modifying code that calls this driver.         */
-#define HCROP	0               /* amount to crop from the left and right edges */
-#define VCROP	0               /* amount to crop from the top and bottom edges */
-
-#define BTVERSION	(bt->id>>4)
-
-#define H(X)		( ((X)>>8) & 0xFF )
-#define L(X)		( (X) & 0xFF )
-
-#define LIMIT(X,A,B)	(((X)<(A)) ? (A) : ((X)>(B)) ? (B) : (X) )
-
-/* Bt829 family chip ID's */
-#define BT815	0x02
-#define BT817	0x06
-#define BT819	0x07
-#define BT827	0x0C
-#define BT829	0x0E
-
-/* Bt829 registers */
-#define STATUS		0x00    /* Device Status */
-#define IFORM		0x01    /* Input Format */
-#define TDEC		0x02    /* Temporal Decimation */
-#define CROP		0x03    /* MSB Cropping */
-#define VDELAY_LO	0x04    /* Vertical Delay */
-#define VACTIVE_LO	0x05    /* Vertical Active */
-#define HDELAY_LO	0x06    /* Horizontal Delay */
-#define HACTIVE_LO	0x07    /* Horizontal Active */
-#define HSCALE_HI	0x08    /* Horizontal Scaling */
-#define HSCALE_LO	0x09    /* Horizontal Scaling */
-#define BRIGHT		0x0A    /* Brightness Control */
-#define CONTROL		0x0B    /* Miscellaneous Control */
-#define CONTRAST_LO	0x0C    /* Luma Gain (Contrast) */
-#define SAT_U_LO	0x0D    /* Chroma (U) Gain (Saturation) */
-#define SAT_V_LO	0x0E    /* Chroma (V) Gain (Saturation) */
-#define HUE		0x0F    /* Hue Control */
-#define SCLOOP		0x10    /* SC Loop Control */
-#define WC_UP		0x11    /* White Crush Up Count */
-#define OFORM		0x12    /* Output Format */
-#define VSCALE_HI	0x13    /* Vertical Scaling */
-#define VSCALE_LO	0x14    /* Vertical Scaling */
-#define TEST		0x15    /* Test Control */
-#define VPOLE		0x16    /* Video Timing Polarity */
-#define IDCODE		0x17    /* ID Code */
-#define ADELAY		0x18    /* AGC Delay */
-#define BDELAY		0x19    /* Burst Gate Delay */
-#define ADC		0x1A    /* ADC Interface */
-#define VTC		0x1B    /* Video Timing Control */
-#define CC_STATUS	0x1C    /* Extended Data Services/Closed Capt Status */
-#define CC_DATA		0x1D    /* Extended Data Services/Closed Capt Data */
-#define WC_DN		0x1E    /* White Crush Down Count */
-#define SRESET		0x1F    /* Software Reset */
-#define P_IO		0x3F    /* Programmable I/O */
-
-static CARD8
-btread(BT829Ptr bt, CARD8 reg)
-{
-    CARD8 v;
-
-    I2C_WriteRead(&(bt->d), &reg, 1, &v, 1);
-
-    return v;
-}
-
-static void
-btwrite(BT829Ptr bt, CARD8 reg, CARD8 val)
-{
-    CARD8 data[2];
-
-    data[0] = reg;
-    data[1] = val;
-    I2C_WriteRead(&(bt->d), data, 2, NULL, 0);
-}
-
-/*
- * Register access
- */
-static void
-btwrite_status(BT829Ptr bt)
-{                               /* STATUS */
-    btwrite(bt, STATUS, 0x00);  /* clear */
-}
-
-static void
-btwrite_iform(BT829Ptr bt)
-{                               /* IFORM */
-    int xtsel;
-
-    switch (bt->format) {
-    case BT829_NTSC:
-    case BT829_NTSC_JAPAN:
-    case BT829_PAL_M:
-    case BT829_PAL_N_COMB:     /* gatos says xtsel = 2 */
-        xtsel = 1;
-        break;
-    case BT829_PAL:
-    case BT829_PAL_N:
-    case BT829_SECAM:
-        xtsel = 2;
-        break;
-    default:                   /* shouldn't get here */
-        xtsel = 3;              /* hardware default */
-        break;
-    }
-
-    btwrite(bt, IFORM, (bt->mux << 5) | (xtsel << 3) | bt->format);
-}
-
-static void
-btwrite_tdec(BT829Ptr bt)
-{                               /* TDEC */
-    /* use default */
-}
-
-static void
-btwrite_crop(BT829Ptr bt)
-{                               /* CROP */
-    btwrite(bt, CROP, (H(bt->vdelay) << 6) | (H(bt->vactive) << 4) |
-            (H(bt->hdelay) << 2) | H(bt->width));
-}
-
-static void
-btwrite_vdelay_lo(BT829Ptr bt)
-{                               /* VDELAY_LO */
-    btwrite(bt, VDELAY_LO, L(bt->vdelay));
-}
-
-static void
-btwrite_vactive_lo(BT829Ptr bt)
-{                               /* VACTIVE_LO */
-    btwrite(bt, VACTIVE_LO, L(bt->vactive));
-}
-
-static void
-btwrite_hdelay_lo(BT829Ptr bt)
-{                               /* HDELAY_LO */
-    btwrite(bt, HDELAY_LO, L(bt->hdelay));
-}
-
-static void
-btwrite_hactive_lo(BT829Ptr bt)
-{                               /* HACTIVE_LO */
-    btwrite(bt, HACTIVE_LO, L(bt->width));
-}
-
-static void
-btwrite_hscale_hi(BT829Ptr bt)
-{                               /* HSCALE_HI */
-    btwrite(bt, HSCALE_HI, H(bt->hscale));
-}
-
-static void
-btwrite_hscale_lo(BT829Ptr bt)
-{                               /* HSCALE_LO */
-    btwrite(bt, HSCALE_LO, L(bt->hscale));
-}
-
-static void
-btwrite_bright(BT829Ptr bt)
-{                               /* BRIGHT */
-    btwrite(bt, BRIGHT, bt->brightness);
-}
-
-static void
-btwrite_control(BT829Ptr bt)
-{                               /* CONTROL */
-    int ldec;
-
-    /* The data sheet says ldec should always be 0 for SECAM */
-    /* but the picture quality is better with ldec = 1       */
-    ldec = (bt->width > 360);   /* gatos says 384 */
-
-    btwrite(bt, CONTROL, ((bt->mux == bt->svideo_mux) ? 0xC0 : 0x00) |  /* LNOTCH and COMP */
-            (ldec << 5) | (H(bt->contrast) << 2) | (H(bt->sat_u) << 1) | H(bt->
-                                                                           sat_v));
-}
-
-static void
-btwrite_contrast_lo(BT829Ptr bt)
-{                               /* CONTRAST_LO */
-    btwrite(bt, CONTRAST_LO, L(bt->contrast));
-}
-
-static void
-btwrite_sat_u_lo(BT829Ptr bt)
-{                               /* SAT_U_LO */
-    btwrite(bt, SAT_U_LO, L(bt->sat_u));
-}
-
-static void
-btwrite_sat_v_lo(BT829Ptr bt)
-{                               /* SAT_V_LO */
-    btwrite(bt, SAT_V_LO, L(bt->sat_v));
-}
-
-static void
-btwrite_hue(BT829Ptr bt)
-{                               /* HUE */
-    btwrite(bt, HUE, bt->hue);
-}
-
-static void
-btwrite_scloop(BT829Ptr bt)
-{                               /* SCLOOP */
-    if (BTVERSION >= BT827) {
-        btwrite(bt, SCLOOP, (bt->format == BT829_SECAM) ? 0x10 : 0x00   /* QCIF or AUTO */
-            );
-    }
-}
-
-static void
-btwrite_wc_up(BT829Ptr bt)
-{                               /* WC_UP */
-    if (BTVERSION >= BT827) {
-        /* use default */
-    }
-}
-
-static void
-btwrite_oform(BT829Ptr bt)
-{                               /* OFORM */
-    btwrite(bt, OFORM, (bt->code << 3) | (bt->len << 2) | 0x02  /* RANGE = 0, CORE = 0, VBI_FRAME = 0, OES = 2 (default) */
-        );
-}
-
-static void
-btwrite_vscale_hi(BT829Ptr bt)
-{                               /* VSCALE_HI */
-    btwrite(bt, VSCALE_HI, H(bt->vscale) | 0x60 /* YCOMB = 0, COMB = 1, INT = 1 (default) */
-        );
-}
-
-static void
-btwrite_vscale_lo(BT829Ptr bt)
-{                               /* VSCALE_LO */
-    btwrite(bt, VSCALE_LO, L(bt->vscale));
-}
-
-/* TEST should not be written to */
-
-static void
-btwrite_vpole(BT829Ptr bt)
-{                               /* VPOLE */
-    btwrite(bt, VPOLE, (bt->out_en << 7));
-}
-
-/* IDCODE is read only */
-
-static void
-btwrite_adelay(BT829Ptr bt)
-{                               /* ADELAY */
-    switch (bt->format) {
-    case BT829_NTSC:
-    case BT829_NTSC_JAPAN:
-    case BT829_PAL_M:
-        btwrite(bt, ADELAY, 104);
-        break;
-    case BT829_PAL:
-    case BT829_PAL_N:
-    case BT829_SECAM:
-    case BT829_PAL_N_COMB:
-        btwrite(bt, ADELAY, 127);
-        break;
-    default:                   /* shouldn't get here */
-        btwrite(bt, ADELAY, 104);       /* hardware default */
-        break;
-    }
-}
-
-static void
-btwrite_bdelay(BT829Ptr bt)
-{                               /* BDELAY */
-    switch (bt->format) {
-    case BT829_NTSC:
-    case BT829_NTSC_JAPAN:
-    case BT829_PAL_M:
-        btwrite(bt, BDELAY, 93);
-        break;
-    case BT829_PAL:
-    case BT829_PAL_N:
-    case BT829_PAL_N_COMB:
-        btwrite(bt, BDELAY, 114);
-        break;
-    case BT829_SECAM:
-        btwrite(bt, BDELAY, 160);
-        break;
-    default:                   /* shouldn't get here */
-        btwrite(bt, BDELAY, 93);        /* hardware default */
-        break;
-    }
-}
-
-static void
-btwrite_adc(BT829Ptr bt)
-{                               /* ADC */
-    btwrite(bt, ADC, bt->mux == bt->svideo_mux ? 0x80 : 0x82);  /* CSLEEP = 0 or 1 */
-}
-
-static void
-btwrite_vtc(BT829Ptr bt)
-{                               /* VTC */
-    int vfilt = 0;              /* hardware default */
-
-    if (BTVERSION > BT827) {    /* gatos says >= BT827 */
-        switch (bt->format) {
-        case BT829_NTSC:
-        case BT829_NTSC_JAPAN:
-        case BT829_PAL_M:
-        case BT829_PAL_N_COMB: /* gatos groups with BT829_PAL */
-            if (bt->width <= 360)
-                vfilt = 1;      /* gatos says <= 240 */
-            if (bt->width <= 180)
-                vfilt = 2;      /* gatos says <= 120 */
-            if (bt->width <= 90)
-                vfilt = 3;      /* gatos says <= 60 */
-            break;
-        case BT829_PAL:
-        case BT829_PAL_N:
-        case BT829_SECAM:
-            if (bt->width <= 384)
-                vfilt = 1;
-            if (bt->width <= 192)
-                vfilt = 2;
-            if (bt->width <= 96)
-                vfilt = 3;
-            break;
-        default:               /* shouldn't get here */
-            break;              /* use hardware default */
-        }
-        btwrite(bt, VTC, (bt->vbien << 4) | (bt->vbifmt << 3) | vfilt);
-    }
-}
-
-static void
-btwrite_cc_status(BT829Ptr bt)
-{                               /* CC_STATUS *//* FIXME: ATI specific */
-    if (BTVERSION >= BT827) {
-        if (bt->ccmode == 0)
-            btwrite(bt, CC_STATUS, 0x00);
-        /* 0x40 is activate to set the CCVALID line. Not required yet */
-        else
-            btwrite(bt, CC_STATUS, (bt->ccmode << 4) | 0x40);
-    }
-}
-
-/* CC_DATA is read only */
-
-static void
-btwrite_wc_dn(BT829Ptr bt)
-{                               /* WC_DN */
-    if (BTVERSION >= BT827) {
-        /* use default */
-    }
-}
-
-static void
-bt_reset(BT829Ptr bt)
-{                               /* SRESET */
-    btwrite(bt, SRESET, 0x0);   /* Reset all registers */
-}
-
-static void
-btwrite_p_io(BT829Ptr bt)
-{                               /* P_IO */
-    if (BTVERSION >= BT827) {
-        btwrite(bt, P_IO, bt->p_io);
-    }
-}
-
-/*
- * Deal with dependencies
- */
-static void
-propagate_changes(BT829Ptr bt)
-{
-    CARD16 hdelay, unscaled_hdelay, vdelay, hscale, vscale;
-    int htotal, vactive;
-
-    switch (bt->format) {
-    case BT829_NTSC:
-    case BT829_NTSC_JAPAN:
-    case BT829_PAL_M:
-        vdelay = 22;
-        htotal = 754;
-        vactive = 480;
-        unscaled_hdelay = 135;
-        break;
-    case BT829_PAL:
-    case BT829_PAL_N:
-        vdelay = (bt->tunertype == 5) ? 34 : 22;
-        htotal = 922;
-        vactive = 576;
-        unscaled_hdelay = 186;
-        break;
-    case BT829_SECAM:
-        vdelay = 34;
-        htotal = 922;
-        vactive = 576;
-        unscaled_hdelay = 186;
-        break;
-    case BT829_PAL_N_COMB:
-        vdelay = (bt->tunertype == 5) ? 34 : 22;        /* windows says 22 */
-        htotal = 754;           /* gatos and windows say 922 */
-        vactive = 576;
-        unscaled_hdelay = 135;  /* gatos and windows say 186 */
-        break;
-    default:                   /* shouldn't get here */
-        vdelay = 22;            /* hardware default */
-        htotal = 754;
-        vactive = 480;          /* hardware default */
-        unscaled_hdelay = 135;
-        break;
-    }
-
-    bt->htotal = htotal;        /* Used for error checking in bt829_SetCaptSize */
-
-    hscale = 4096 * htotal / (bt->width + 2 * HCROP) - 4096;
-    hdelay =
-        (HCROP + (bt->width + 2 * HCROP) * unscaled_hdelay / htotal) & 0x3FE;
-
-    vactive = vactive - 2 * VCROP;
-    vdelay = vdelay + VCROP;
-    vscale = (0x10000 - (512 * vactive / bt->height - 512)) & 0x1FFF;
-
-    if ((hdelay != bt->hdelay) || (vdelay != bt->vdelay) ||
-        (vactive != bt->vactive) || (hscale != bt->hscale) ||
-        (vscale != bt->vscale)) {
-        bt->hdelay = hdelay;
-        bt->vdelay = vdelay;
-        bt->vactive = vactive;
-        bt->hscale = hscale;
-        bt->vscale = vscale;
-        btwrite_crop(bt);
-        btwrite_vdelay_lo(bt);
-        btwrite_vactive_lo(bt);
-        btwrite_hdelay_lo(bt);
-        btwrite_hscale_hi(bt);
-        btwrite_hscale_lo(bt);
-        btwrite_control(bt);
-        btwrite_vscale_hi(bt);
-        btwrite_vscale_lo(bt);
-    }
-}
-
-static void
-write_all(BT829Ptr bt)
-{
-    bt_reset(bt);
-    propagate_changes(bt);      /* ensure consistency */
-    btwrite_iform(bt);
-    btwrite_tdec(bt);
-    btwrite_crop(bt);
-    btwrite_vdelay_lo(bt);
-    btwrite_vactive_lo(bt);
-    btwrite_hdelay_lo(bt);
-    btwrite_hactive_lo(bt);
-    btwrite_hscale_hi(bt);
-    btwrite_hscale_lo(bt);
-    btwrite_bright(bt);
-    btwrite_control(bt);
-    btwrite_contrast_lo(bt);
-    btwrite_sat_u_lo(bt);
-    btwrite_sat_v_lo(bt);
-    btwrite_hue(bt);
-    btwrite_scloop(bt);
-    btwrite_wc_up(bt);
-    btwrite_oform(bt);
-    btwrite_vscale_hi(bt);
-    btwrite_vscale_lo(bt);
-    btwrite_vpole(bt);
-    btwrite_adelay(bt);
-    btwrite_bdelay(bt);
-    btwrite_adc(bt);
-    btwrite_vtc(bt);
-    /*  btwrite_cc_status(bt); *//* FIXME: CC code needs cleaning */
-    btwrite_wc_dn(bt);
-    btwrite_p_io(bt);
-}
-
-/*
- * Public functions
- */
-BT829Ptr
-bt829_Detect(I2CBusPtr b, I2CSlaveAddr addr)
-{
-    BT829Ptr bt;
-    I2CByte a;
-    char *devname;
-
-    bt = calloc(1, sizeof(BT829Rec));
-    if (bt == NULL)
-        return NULL;
-    bt->d.DevName = strdup("BT829 video decoder");
-    bt->d.SlaveAddr = addr;
-    bt->d.pI2CBus = b;
-    bt->d.NextDev = NULL;
-    bt->d.StartTimeout = b->StartTimeout;
-    bt->d.BitTimeout = b->BitTimeout;
-    bt->d.AcknTimeout = b->AcknTimeout;
-    bt->d.ByteTimeout = b->ByteTimeout;
-
-    if (!I2C_WriteRead(&(bt->d), NULL, 0, &a, 1)) {
-        free(bt);
-        return NULL;
-    }
-
-    bt->id = btread(bt, IDCODE);
-
-    free((void *) bt->d.DevName);
-    bt->d.DevName = devname = calloc(200, sizeof(char));
-    switch (BTVERSION) {
-    case BT815:
-        sprintf(devname, "bt815a video decoder, revision %d",
-                bt->id & 0xf);
-        break;
-    case BT817:
-        sprintf(devname, "bt817a video decoder, revision %d",
-                bt->id & 0xf);
-        break;
-    case BT819:
-        sprintf(devname, "bt819a video decoder, revision %d",
-                bt->id & 0xf);
-        break;
-    case BT827:
-        sprintf(devname, "bt827a/b video decoder, revision %d",
-                bt->id & 0xf);
-        break;
-    case BT829:
-        sprintf(devname, "bt829a/b video decoder, revision %d",
-                bt->id & 0xf);
-        break;
-    default:
-        sprintf(devname,
-                "bt8xx/unknown video decoder version %d, revision %d",
-                bt->id >> 4, bt->id & 0xf);
-        break;
-    }
-
-    /* set default parameters */
-    if (!I2CDevInit(&(bt->d))) {
-        free(bt);
-        return NULL;
-    }
-
-    bt->tunertype = 1;
-
-    bt->brightness = 0;         /* hardware default */
-    bt->ccmode = 0;
-    bt->code = 0;               /* hardware default */
-    bt->contrast = 216;         /* hardware default */
-    bt->format = BT829_NTSC;
-    bt->height = 480;           /* hardware default for vactive */
-    bt->hue = 0;                /* hardware default */
-    bt->len = 1;                /* hardware default */
-    bt->mux = BT829_MUX0;       /* hardware default */
-    bt->out_en = 0;             /* hardware default */
-    bt->p_io = 0;               /* hardware default */
-    bt->sat_u = 254;            /* hardware default */
-    bt->sat_v = 180;            /* hardware default */
-    bt->vbien = 0;              /* hardware default */
-    bt->vbifmt = 0;             /* hardware default */
-    bt->width = 640;            /* hardware default for hactive */
-
-    bt->hdelay = 120;           /* hardware default */
-    bt->hscale = 684;           /* hardware default */
-    bt->vactive = 480;          /* hardware default */
-    bt->vdelay = 22;            /* hardware default */
-    bt->vscale = 0;             /* hardware default */
-
-    bt->htotal = 754;           /* NTSC */
-    bt->svideo_mux = 0;         /* no s-video */
-
-    return bt;
-}
-
-int
-bt829_ATIInit(BT829Ptr bt)
-{
-    bt->code = 1;
-    bt->len = 0;
-    bt->vbien = 1;
-    bt->vbifmt = 1;
-    bt->svideo_mux = BT829_MUX1;
-
-    write_all(bt);
-
-    return 0;
-}
-
-int
-bt829_SetFormat(BT829Ptr bt, CARD8 format)
-{
-    if ((format < 1) || (format > 7))
-        return -1;
-    if ((BTVERSION <= BT819) && (format != BT829_NTSC) && (format != BT829_PAL))
-        return -1;
-    if (format == bt->format)
-        return 0;
-    bt->format = format;
-    propagate_changes(bt);
-    btwrite_iform(bt);
-    btwrite_scloop(bt);
-    btwrite_adelay(bt);
-    btwrite_bdelay(bt);
-    btwrite_vtc(bt);
-    return 0;
-}
-
-int
-bt829_SetMux(BT829Ptr bt, CARD8 mux)
-{
-    if ((mux < 1) || (mux > 3))
-        return -1;
-    if (mux == bt->mux)
-        return 0;
-    bt->mux = mux;
-    /* propagate_changes(bt); *//* no dependencies */
-    btwrite_iform(bt);
-    btwrite_control(bt);
-    btwrite_adc(bt);
-    return 0;
-}
-
-void
-bt829_SetBrightness(BT829Ptr bt, int brightness)
-{
-    brightness = LIMIT(brightness, -1000, 999); /* ensure -128 <= brightness <= 127 below */
-    brightness = (128 * brightness) / 1000;
-    if (brightness == bt->brightness)
-        return;
-    bt->brightness = brightness;
-    /* propagate_changes(bt); *//* no dependencies */
-    btwrite_bright(bt);
-}
-
-void
-bt829_SetContrast(BT829Ptr bt, int contrast)
-{
-    contrast = LIMIT(contrast, -1000, 1000);
-    contrast = (216 * (contrast + 1000)) / 1000;
-    if (contrast == bt->contrast)
-        return;
-    bt->contrast = contrast;
-    /* propagate_changes(bt); *//* no dependencies */
-    btwrite_control(bt);
-    btwrite_contrast_lo(bt);
-}
-
-void
-bt829_SetSaturation(BT829Ptr bt, int saturation)
-{
-    CARD16 sat_u, sat_v;
-
-    saturation = LIMIT(saturation, -1000, 1000);
-    sat_u = (254 * (saturation + 1000)) / 1000;
-    sat_v = (180 * (saturation + 1000)) / 1000;
-    if ((sat_u == bt->sat_u) && (sat_v == bt->sat_v))
-        return;
-    bt->sat_u = sat_u;
-    bt->sat_v = sat_v;
-    /* propagate_changes(bt); *//* no dependencies */
-    btwrite_control(bt);
-    btwrite_sat_u_lo(bt);
-    btwrite_sat_v_lo(bt);
-}
-
-void
-bt829_SetTint(BT829Ptr bt, int hue)
-{
-    hue = LIMIT(hue, -1000, 999);       /* ensure -128 <= hue <= 127 below */
-    hue = (128 * hue) / 1000;
-    if (hue == bt->hue)
-        return;
-    bt->hue = hue;
-    /* propagate_changes(bt); *//* no dependencies */
-    btwrite_hue(bt);
-}
-
-int
-bt829_SetCaptSize(BT829Ptr bt, int width, int height)
-{
-    if ((width > bt->htotal - 2 * HCROP) ||
-        (16 * width < bt->htotal - 32 * HCROP))
-        return -1;
-    if ((height > bt->vactive) || (16 * height < bt->vactive))
-        return -1;
-    if ((width == bt->width) && (height == bt->height))
-        return 0;
-    bt->width = width;
-    bt->height = height;
-    propagate_changes(bt);
-    btwrite_crop(bt);
-    btwrite_hactive_lo(bt);
-    btwrite_control(bt);
-    btwrite_vtc(bt);
-    return 0;
-}
-
-int
-bt829_SetCC(BT829Ptr bt)
-{                               /* FIXME: should take ccmode as a parameter */
-    if (BTVERSION < BT827)
-        return -1;              /* can't do it */
-    /* propagate_changes(bt); *//* no dependencies */
-    btwrite_cc_status(bt);
-    /* we write to STATUS to reset the CCVALID flag */
-    if (bt->ccmode != 0)
-        btwrite_status(bt);
-    return 0;
-}
-
-void
-bt829_SetOUT_EN(BT829Ptr bt, BOOL out_en)
-{
-    out_en = (out_en != 0);
-    if (out_en == bt->out_en)
-        return;
-    bt->out_en = out_en;
-    /* propagate_changes(bt); *//* no dependencies */
-    btwrite_vpole(bt);
-}
-
-void
-bt829_SetP_IO(BT829Ptr bt, CARD8 p_io)
-{
-    if (p_io == bt->p_io)
-        return;
-    bt->p_io = p_io;
-    /* propagate_changes(bt); *//* no dependencies */
-    btwrite_p_io(bt);
-}
-
-#define BTREAD(R)	btread(bt,(R))
-
-#if 0
-
-void
-bt829_getCCdata(BT829Ptr bt, struct CCdata *data)
-{
-    CARD8 status;
-
-    data->num_valid = 0;
-    /* wait for buffer to be half full (means 8/16 bytes)
-     * either 4 (one of CC/EDS) or 2 (both CC/EDS) frames */
-    if (!(BTREAD(STATUS) & 0x04))
-        return;                 /* could comment this line */
-    for (; data->num_valid < CC_FIFO_SIZE; data->num_valid++) {
-        status = BTREAD(CC_STATUS);
-        if (!(status & 0x04))
-            break;
-        data->data[data->num_valid] = BTREAD(CC_DATA) & 0x7f;
-        /* stripped high bit (parity) */
-        data->status[data->num_valid] = (CCS_EDS * ((status & 0x02) >> 1)) |
-            (CCS_HIGH * (status & 0x01)) |
-            (CCS_OVER * ((status & 0x08) >> 3)) |
-            (CCS_PAR * ((status & 0x80) >> 7));
-    }
-    btwrite(bt, STATUS, 0x00);  /* Reset CCVALID status bit */
-    return;
-}
-
-#endif
-
-/* ------------------------------------------------------------------------ */
-/* Debug and report routines */
-
-#define DUMPREG(REG)   \
-  xf86DrvMsg(bt->d.pI2CBus->scrnIndex,X_INFO," %-12s (0x%02X) = 0x%02X\n", \
-              #REG,REG,BTREAD(REG))
-
-/*static void bt829_dumpregs(BT829Ptr bt)
-{
-  DUMPREG(STATUS);
-  DUMPREG(IFORM);
-  DUMPREG(TDEC);
-  DUMPREG(CROP);
-  DUMPREG(VDELAY_LO);
-  DUMPREG(VACTIVE_LO);
-  DUMPREG(HDELAY_LO);
-  DUMPREG(HACTIVE_LO);
-  DUMPREG(HSCALE_HI);
-  DUMPREG(HSCALE_LO);
-  DUMPREG(BRIGHT);
-  DUMPREG(CONTROL);
-  DUMPREG(CONTRAST_LO);
-  DUMPREG(SAT_U_LO);
-  DUMPREG(SAT_V_LO);
-  DUMPREG(HUE);
-  if (BTVERSION >= BT827) {
-    DUMPREG(SCLOOP);
-    DUMPREG(WC_UP) ; }
-  DUMPREG(OFORM);
-  DUMPREG(VSCALE_HI);
-  DUMPREG(VSCALE_LO);
-  DUMPREG(TEST);
-  DUMPREG(VPOLE);
-  DUMPREG(IDCODE);
-  DUMPREG(ADELAY);
-  DUMPREG(BDELAY);
-  DUMPREG(ADC);
-  if (BTVERSION >= BT827) {
-    DUMPREG(VTC);
-    DUMPREG(CC_STATUS);
-    DUMPREG(CC_DATA);
-    DUMPREG(WC_DN);
-    DUMPREG(P_IO) ; }
-}*/
diff --git a/hw/xfree86/i2c/bt829.h b/hw/xfree86/i2c/bt829.h
deleted file mode 100644
index 2709bee..0000000
--- a/hw/xfree86/i2c/bt829.h
+++ /dev/null
@@ -1,103 +0,0 @@
-#ifndef __BT829_H__
-#define __BT829_H__
-
-#include "xf86i2c.h"
-
-typedef struct {
-    int tunertype;              /* Must be set before init */
-    /* Private variables */
-    I2CDevRec d;
-
-    CARD8 brightness;
-    CARD8 ccmode;
-    CARD8 code;
-    CARD16 contrast;
-    CARD8 format;
-    int height;
-    CARD8 hue;
-    CARD8 len;
-    CARD8 mux;
-    CARD8 out_en;
-    CARD8 p_io;
-    CARD16 sat_u;
-    CARD16 sat_v;
-    CARD8 vbien;
-    CARD8 vbifmt;
-    int width;
-
-    CARD16 hdelay;
-    CARD16 hscale;
-    CARD16 vactive;
-    CARD16 vdelay;
-    CARD16 vscale;
-
-    CARD16 htotal;
-    CARD8 id;
-    CARD8 svideo_mux;
-} BT829Rec, *BT829Ptr;
-
-#define xf86_bt829_Detect	bt829_Detect
-extern _X_EXPORT BT829Ptr bt829_Detect(I2CBusPtr b, I2CSlaveAddr addr);
-
-/* ATI card specific initialization */
-#define BT829_ATI_ADDR_1	0x8A
-#define BT829_ATI_ADDR_2	0x88
-
-#define xf86_bt829_ATIInit	bt829_ATIInit
-extern _X_EXPORT int bt829_ATIInit(BT829Ptr bt);
-
-#define BT829_NTSC		1       /* NTSC-M */
-#define BT829_NTSC_JAPAN	2       /* NTSC-Japan */
-#define BT829_PAL		3       /* PAL-B,D,G,H,I */
-#define BT829_PAL_M		4       /* PAL-M */
-#define BT829_PAL_N		5       /* PAL-N */
-#define BT829_SECAM		6       /* SECAM */
-#define BT829_PAL_N_COMB	7       /* PAL-N combination */
-
-#define xf86_bt829_SetFormat	bt829_SetFormat
-extern _X_EXPORT int bt829_SetFormat(BT829Ptr bt, CARD8 format);
-
-#define BT829_MUX2	1       /* ATI -> composite video */
-#define BT829_MUX0	2       /* ATI -> tv tuner */
-#define BT829_MUX1	3       /* ATI -> s-video */
-
-#define xf86_bt829_SetMux	bt829_SetMux
-extern _X_EXPORT int bt829_SetMux(BT829Ptr bt, CARD8 mux);
-
-#define xf86_bt829_SetCaptSize		bt829_SetCaptSize
-extern _X_EXPORT int bt829_SetCaptSize(BT829Ptr bt, int width, int height);
-
-#define xf86_bt829_SetBrightness	bt829_SetBrightness
-extern _X_EXPORT void bt829_SetBrightness(BT829Ptr bt, int brightness);
-
-#define xf86_bt829_SetContrast		bt829_SetContrast
-extern _X_EXPORT void bt829_SetContrast(BT829Ptr bt, int contrast);
-
-#define xf86_bt829_SetSaturation	bt829_SetSaturation
-extern _X_EXPORT void bt829_SetSaturation(BT829Ptr bt, int saturation);
-
-#define xf86_bt829_SetTint		bt829_SetTint
-extern _X_EXPORT void bt829_SetTint(BT829Ptr bt, int hue);      /* Hue */
-
-#define xf86_bt829_SetOUT_EN		bt829_SetOUT_EN
-extern _X_EXPORT void bt829_SetOUT_EN(BT829Ptr bt, BOOL out_en);        /* VPOLE register */
-
-#define xf86_bt829_SetP_IO		bt829_SetP_IO
-extern _X_EXPORT void bt829_SetP_IO(BT829Ptr bt, CARD8 p_io);   /* P_IO register */
-
-extern _X_EXPORT int bt829_SetCC(BT829Ptr bt);
-
-#define BT829SymbolsList   \
-		"bt829_Detect", \
-		"bt829_ATIInit", \
-		"bt829_SetFormat", \
-		"bt829_SetMux", \
-		"bt829_SetBrightness", \
-		"bt829_SetContrast", \
-		"bt829_SetSaturation", \
-		"bt829_SetTint", \
-		"bt829_SetCaptSize", \
-		"bt829_SetOUT_EN", \
-		"bt829_SetP_IO"
-
-#endif
diff --git a/hw/xfree86/i2c/bt829_module.c b/hw/xfree86/i2c/bt829_module.c
deleted file mode 100644
index c8a6ac6..0000000
--- a/hw/xfree86/i2c/bt829_module.c
+++ /dev/null
@@ -1,20 +0,0 @@
-#ifdef HAVE_XORG_CONFIG_H
-#include <xorg-config.h>
-#endif
-
-#include "xf86Module.h"
-
-static XF86ModuleVersionInfo bt829VersRec = {
-    "bt829",
-    MODULEVENDORSTRING,
-    MODINFOSTRING1,
-    MODINFOSTRING2,
-    XORG_VERSION_CURRENT,
-    1, 0, 0,
-    ABI_CLASS_VIDEODRV,         /* This needs the video driver ABI */
-    ABI_VIDEODRV_VERSION,
-    MOD_CLASS_NONE,
-    {0, 0, 0, 0}
-};
-
-_X_EXPORT XF86ModuleData bt829ModuleData = { &bt829VersRec, NULL, NULL };
diff --git a/hw/xfree86/i2c/fi1236.c b/hw/xfree86/i2c/fi1236.c
deleted file mode 100644
index ebd1454..0000000
--- a/hw/xfree86/i2c/fi1236.c
+++ /dev/null
@@ -1,686 +0,0 @@
-#ifdef HAVE_XORG_CONFIG_H
-#include <xorg-config.h>
-#endif
-
-#include <unistd.h>
-#include <stdlib.h>
-#include <string.h>
-#include <math.h>
-
-#include "xf86.h"
-#include "xf86i2c.h"
-#include "fi1236.h"
-#include "tda9885.h"
-#include "i2c_def.h"
-
-#define NUM_TUNERS    8
-
-const FI1236_parameters tuner_parms[NUM_TUNERS] = {
-    /* 0 - FI1236 */
-    {733, 884, 12820, 2516, 7220, 0xA2, 0x94, 0x34, 0x8e},
-    /* !!!based on documentation - it should be:
-       {733, 16*55.25, 16*801.25, 16*160, 16*454, 0xA0, 0x90, 0x30, 0x8e}, */
-
-    /* 1 - FI1216 */
-    {623, 16 * 48.75, 16 * 855.25, 16 * 170, 16 * 450, 0xA0, 0x90, 0x30, 0x8e},
-    /* 2 - TEMIC FN5AL */
-    {623, 16 * 45.75, 16 * 855.25, 16 * 169, 16 * 454, 0xA0, 0x90, 0x30, 0x8e},
-    /* 3 - MT2032.. */
-    {733, 768, 13760, 0, 0, 0, 0, 0, 0},
-    /* 4 - FI1246 */
-    {623, 16 * 45.75, 16 * 855.25, 16 * 170, 16 * 450, 0xA0, 0x90, 0x30, 0x8e},
-    /* 5 - FI1256 */
-    {623, 16 * 49.75, 16 * 863.25, 16 * 170, 16 * 450, 0xA0, 0x90, 0x30, 0x8e},
-    /* 6 - FI1236W */
-    /*{ 733, 884, 12820, 2516, 7220, 0x1, 0x2, 0x4, 0x8e }, */
-    {732, 16 * 55.25, 16 * 801.25, 16 * 160, 16 * 442, 0x1, 0x2, 0x4, 0x8e},
-    /* 7 - FM1216ME */
-    {623, 16 * 48.25, 16 * 863.25, 16 * 158.00, 16 * 442.00, 0x1, 0x2, 0x4, 0x8e}
-};
-
-FI1236Ptr
-Detect_FI1236(I2CBusPtr b, I2CSlaveAddr addr)
-{
-    FI1236Ptr f;
-    I2CByte a;
-
-    f = calloc(1, sizeof(FI1236Rec));
-    if (f == NULL)
-        return NULL;
-    f->d.DevName = strdup("FI12xx Tuner");
-    f->d.SlaveAddr = addr;
-    f->d.pI2CBus = b;
-    f->d.NextDev = NULL;
-    f->d.StartTimeout = b->StartTimeout;
-    f->d.BitTimeout = b->BitTimeout;
-    f->d.AcknTimeout = b->AcknTimeout;
-    f->d.ByteTimeout = b->ByteTimeout;
-    f->type = TUNER_TYPE_FI1236;
-    f->afc_timer_installed = FALSE;
-    f->last_afc_hint = TUNER_OFF;
-    f->video_if = 45.7812;
-
-    if (!I2C_WriteRead(&(f->d), NULL, 0, &a, 1)) {
-        free(f);
-        return NULL;
-    }
-    FI1236_set_tuner_type(f, TUNER_TYPE_FI1236);
-    if (!I2CDevInit(&(f->d))) {
-        free(f);
-        return NULL;
-    }
-    return f;
-}
-
-static void
-MT2032_dump_parameters(FI1236Ptr f, MT2032_parameters * m)
-{
-    xf86DrvMsg(f->d.pI2CBus->scrnIndex, X_INFO,
-               "MT2032: input f_rf=%g f_if1=%g f_if2=%g f_ref=%g f_ifbw=%g f_step=%g\n",
-               m->f_rf, m->f_if1, m->f_if2, m->f_ref, m->f_ifbw, m->f_step);
-
-    xf86DrvMsg(f->d.pI2CBus->scrnIndex, X_INFO,
-               "MT2032: computed f_lo1=%g f_lo2=%g LO1I=%d LO2I=%d SEL=%d STEP=%d NUM=%d\n",
-               m->f_lo1, m->f_lo2, m->LO1I, m->LO2I, m->SEL, m->STEP, m->NUM);
-}
-
-static void
-MT2032_getid(FI1236Ptr f)
-{
-    CARD8 out[4];
-    CARD8 in;
-
-    in = 0x11;
-    I2C_WriteRead(&(f->d), (I2CByte *) &in, 1, out, 4);
-    xf86DrvMsg(f->d.pI2CBus->scrnIndex, X_INFO,
-               "MT2032: Company code 0x%02x%02x, part code 0x%02x, revision code 0x%02x\n",
-               out[0], out[1], out[2], out[3]);
-
-}
-
-/* might be buggy */
-#if 0
-static void
-MT2032_shutdown(FI1236Ptr f)
-{
-    CARD8 data[10];
-
-    data[0] = 0x00;             /* start with register 0x00 */
-    data[1] = 0x1A;
-    data[2] = 0x44;
-    data[3] = 0x20;
-
-    I2C_WriteRead(&(f->d), (I2CByte *) data, 4, NULL, 0);
-
-    data[0] = 0x05;             /* now start with register 0x05 */
-    data[1] = 0xD7;
-    data[2] = 0x14;
-    data[3] = 0x05;
-    I2C_WriteRead(&(f->d), (I2CByte *) data, 4, NULL, 0);
-
-    data[0] = 0x0B;             /* now start with register 0x05 */
-    data[1] = 0x8F;
-    data[2] = 0x07;
-    data[3] = 0x43;
-    I2C_WriteRead(&(f->d), (I2CByte *) data, 4, NULL, 0);
-
-    usleep(15000);
-}
-#endif
-
-static void MT2032_dump_status(FI1236Ptr f);
-
-static void
-MT2032_init(FI1236Ptr f)
-{
-    CARD8 data[10];
-    CARD8 value;
-    CARD8 xogc = 0x00;
-
-    MT2032_getid(f);
-
-    data[0] = 0x02;             /* start with register 0x02 */
-    data[1] = 0xFF;
-    data[2] = 0x0F;
-    data[3] = 0x1F;
-
-    I2C_WriteRead(&(f->d), (I2CByte *) data, 4, NULL, 0);
-
-    data[0] = 0x06;             /* now start with register 0x06 */
-    data[1] = 0xE4;
-    data[2] = 0x8F;
-    data[3] = 0xC3;
-    data[4] = 0x4E;
-    data[5] = 0xEC;
-    I2C_WriteRead(&(f->d), (I2CByte *) data, 6, NULL, 0);
-
-    data[0] = 0x0d;             /* now start with register 0x0d */
-    data[1] = 0x32;
-    I2C_WriteRead(&(f->d), (I2CByte *) data, 2, NULL, 0);
-
-    while (1) {
-        usleep(15000);          /* wait 15 milliseconds */
-
-        data[0] = 0x0e;         /* register number 7, status */
-        value = 0xFF;
-        if (!I2C_WriteRead(&(f->d), (I2CByte *) data, 1, &value, 1))
-            xf86DrvMsg(f->d.pI2CBus->scrnIndex, X_INFO,
-                       "MT2032: failed to read XOK\n");
-        xf86DrvMsg(f->d.pI2CBus->scrnIndex, X_INFO,
-                   "MT2032: XOK=%d\n", value & 0x01);
-        if (value & 1)
-            break;
-
-        data[0] = 0x07;
-        if (!I2C_WriteRead(&(f->d), (I2CByte *) data, 1, &value, 1))
-            xf86DrvMsg(f->d.pI2CBus->scrnIndex, X_INFO,
-                       "MT2032: failed to read XOGC\n");
-
-        xogc = value & 0x7;
-        if (xogc == 4)
-            break;              /* XOGC has reached 4.. stop */
-        xogc--;
-        xf86DrvMsg(f->d.pI2CBus->scrnIndex, X_INFO,
-                   "MT2032: try XOGC=%d\n", xogc);
-        usleep(15000);
-        data[0] = 0x07;         /* register number 7, control byte 2 */
-        data[1] = 0x08 | xogc;
-        I2C_WriteRead(&(f->d), (I2CByte *) data, 2, NULL, 0);
-    }
-    f->xogc = xogc;
-    /* wait before continuing */
-    usleep(15000);              /* wait 50 milliseconds */
-    MT2032_dump_status(f);
-}
-
-static int
-MT2032_no_spur_in_band(MT2032_parameters * m)
-{
-    int n_max, n1, n2;
-    double f_test;
-
-    n_max = 5;
-    n1 = 1;
-    while (1) {
-        n2 = -n1;
-        f_test = n1 * (m->f_lo1 - m->f_lo2);
-        while (1) {
-            n2--;
-            f_test = f_test - m->f_lo2;
-            xf86DrvMsg(0, X_INFO,
-                       "testing f_test=%g n1=%d n2=%d f_lo1=%g f_lo2=%g f_if2=%g\n",
-                       f_test, n1, n2, m->f_lo1, m->f_lo2, m->f_if2);
-            xf86DrvMsg(0, X_INFO, "d_f=%g f_ifbw=%g\n",
-                       fabs(fabs(f_test) - m->f_if2), m->f_ifbw);
-            if ((fabs(fabs(f_test) - m->f_if2) * 2.0) <= m->f_ifbw)
-                return 0;
-            if (n2 <= -n_max)
-                break;
-            /* this line in the manual is bogus. I say it is faster
-               and more correct to go over all harmonics.. */
-#if 0
-            if (f_test < (m->f_lo2 - m->f_if2 - m->f_ifbw))
-                break;
-#endif
-        }
-        n1++;
-        if (n1 >= n_max)
-            return 1;
-    }
-
-}
-
-static void
-MT2032_calculate_register_settings(MT2032_parameters * m, double f_rf,
-                                   double f_if1, double f_if2, double f_ref,
-                                   double f_ifbw, double f_step)
-{
-    int n;
-
-    m->f_rf = f_rf;
-    m->f_if1 = f_if1;
-    m->f_if2 = f_if2;
-    m->f_ref = f_ref;
-    m->f_ifbw = f_ifbw;
-    m->f_step = f_step;
-
-    m->f_lo1 = f_rf + f_if1;
-    m->LO1I = lrint(m->f_lo1 / f_ref);
-    m->f_lo1 = f_ref * m->LO1I;
-
-    m->f_lo2 = m->f_lo1 - f_rf - f_if2;
-
-    /* check for spurs */
-    n = 1;
-    while (n < 3) {
-        if (MT2032_no_spur_in_band(m))
-            break;
-
-        if (m->f_lo1 < (f_rf + f_if1))
-            m->LO1I += n;
-        else
-            m->LO1I -= n;
-
-        m->f_lo1 = m->LO1I * f_ref;
-        m->f_lo2 = m->f_lo1 - f_rf - f_if2;
-        n++;
-    }
-    /* xf86DrvMsg(0, X_INFO, "MT2032: n=%d\n", n); */
-    /* select VCO */
-
-    /* m->f_lo1>1100.0 */
-    if (m->f_lo1 < 1370.0)
-        m->SEL = 4;
-    else if (m->f_lo1 < 1530.0)
-        m->SEL = 3;
-    else if (m->f_lo1 < 1720.0)
-        m->SEL = 2;
-    else if (m->f_lo1 < 1890.0)
-        m->SEL = 1;
-    else                        /* m->f_lo1 < 1958.0 */
-        m->SEL = 0;
-
-    /* calculate the rest of the registers */
-    m->LO2I = floor(m->f_lo2 / f_ref);
-    m->STEP = floor(3780.0 * f_step / f_ref);
-    m->NUM = floor(3780.0 * (m->f_lo2 / f_ref - m->LO2I));
-    m->NUM = m->STEP * lrint((1.0 * m->NUM) / (1.0 * m->STEP));
-}
-
-static int
-MT2032_wait_for_lock(FI1236Ptr f)
-{
-    int n;
-    CARD8 data[10];
-    CARD8 value;
-
-    n = 12;
-    while (1) {
-        data[0] = 0x0e;         /* register number 7, status */
-        I2C_WriteRead(&(f->d), (I2CByte *) data, 1, &value, 1);
-        /* xf86DrvMsg(f->d.pI2CBus->scrnIndex, X_INFO,
-           "MT2032: LO1LK=%d LO2LK=%d\n",
-           (value & 0x04)>>2, (value & 0x02)>>1); */
-        if ((value & 6) == 6)
-            break;
-        usleep(1500);
-        n--;
-        if (n < 0)
-            break;
-    }
-    if (n < 0) {
-        xf86DrvMsg(f->d.pI2CBus->scrnIndex, X_INFO,
-                   "MT2032: failed to set frequency\n");
-        return 0;
-    }
-    return 1;
-}
-
-static void
-MT2032_implement_settings(FI1236Ptr f, MT2032_parameters * m)
-{
-    CARD8 data[10];
-    CARD8 value;
-
-    data[0] = 0x00;             /* start with register 0x00 */
-    data[1] = (m->LO1I >> 3) - 1;
-    data[2] = (m->SEL << 4) | (m->LO1I & 0x7);
-    data[3] = 0x86;
-    I2C_WriteRead(&(f->d), (I2CByte *) data, 4, NULL, 0);
-
-    data[0] = 0x05;             /* start with register 0x05 */
-    data[1] = ((m->LO2I & 0x7) << 5) | ((m->LO2I >> 3) - 1);
-    if (m->f_rf < 400.0)
-        data[2] = 0xe4;
-    else
-        data[2] = 0xf4;
-    I2C_WriteRead(&(f->d), (I2CByte *) data, 3, NULL, 0);
-
-    data[0] = 0x07;             /* register number 7, control byte 2 */
-    I2C_WriteRead(&(f->d), (I2CByte *) data, 1, &value, 1);
-    xf86DrvMsg(f->d.pI2CBus->scrnIndex, X_INFO,
-               "MT2032: using XOGC=%d\n", (value & 0x07));
-    data[1] = 8 | (value & 0x7);
-    I2C_WriteRead(&(f->d), (I2CByte *) data, 2, NULL, 0);
-
-    data[0] = 0x0b;             /* start with register 0x0b */
-    data[1] = m->NUM & 0xff;
-    data[2] = (1 << 7) | ((m->NUM >> 8) & 0x0f);
-    I2C_WriteRead(&(f->d), (I2CByte *) data, 3, NULL, 0);
-
-    MT2032_wait_for_lock(f);
-}
-
-static void
-MT2032_optimize_VCO(FI1236Ptr f, MT2032_parameters * m)
-{
-    CARD8 data[10];
-    CARD8 value;
-    CARD8 TAD1;
-
-    data[0] = 0x0f;             /* register number 7, status */
-    I2C_WriteRead(&(f->d), (I2CByte *) data, 1, &value, 1);
-    TAD1 = value & 0x07;
-    xf86DrvMsg(f->d.pI2CBus->scrnIndex, X_INFO,
-               "MT2032: TAD1=%d SEL=%d\n", TAD1, m->SEL);
-    if (TAD1 < 2)
-        return;
-    if (TAD1 == 2) {
-        if (m->SEL == 0)
-            return;
-        m->SEL--;
-    }
-    else {
-        if (m->SEL >= 4)
-            return;
-        m->SEL++;
-    }
-    data[0] = 0x01;             /* start with register 1 */
-    data[1] = (m->SEL << 4) | (m->LO1I & 0x7);
-    I2C_WriteRead(&(f->d), (I2CByte *) data, 2, NULL, 0);
-
-}
-
-static int
-FI1236_get_afc_hint(FI1236Ptr f)
-{
-    CARD8 out;
-    CARD8 AFC;
-
-    if ((f->type == TUNER_TYPE_FM1216ME) || (f->type == TUNER_TYPE_FI1236W)) {
-        TDA9885Ptr t = (TDA9885Ptr) f->afc_source;
-
-        if (t == NULL)
-            return TUNER_OFF;
-
-        tda9885_getstatus(t);
-        tda9885_dumpstatus(t);
-        AFC = t->afc_status & 0x0f;
-
-        xf86DrvMsg(f->d.pI2CBus->scrnIndex, X_INFO,
-                   "AFC: FI1236_get_afc_hint: %i\n", AFC);
-        if (AFC == 0)
-            return TUNER_TUNED;
-        else if (AFC <= 0x07)
-            return TUNER_JUST_BELOW;
-        else if (AFC < 0x0f)
-            return TUNER_JUST_ABOVE;
-        else if (AFC == 0x0f)
-            return TUNER_TUNED;
-    }
-    else {
-        I2C_WriteRead(&(f->d), NULL, 0, &out, 1);
-        AFC = out & 0x7;
-        xf86DrvMsg(f->d.pI2CBus->scrnIndex, X_INFO,
-                   "AFC: FI1236_get_afc_hint: %i\n", AFC);
-        if (AFC == 2)
-            return TUNER_TUNED;
-        if (AFC == 3)
-            return TUNER_JUST_BELOW;
-        if (AFC == 1)
-            return TUNER_JUST_ABOVE;
-        return TUNER_OFF;
-    }
-    return TUNER_OFF;
-}
-
-static int
-MT2032_get_afc_hint(FI1236Ptr f)
-{
-    CARD8 in;
-    CARD8 out[2];
-    CARD8 AFC;
-
-    in = 0x0e;
-    I2C_WriteRead(&(f->d), (I2CByte *) &in, 1, out, 2);
-    AFC = (out[0] >> 4) & 0x7;
-#if 0
-    xf86DrvMsg(f->d.pI2CBus->scrnIndex, X_INFO, "AFC=%d TAD1=%d TAD2=%d\n",
-               AFC, out[1] & 0x7, (out[1] >> 4) & 0x07);
-#endif
-    if (AFC == 2)
-        return TUNER_TUNED;
-    if (AFC == 3)
-        return TUNER_JUST_BELOW;
-    if (AFC == 1)
-        return TUNER_JUST_ABOVE;
-    return TUNER_OFF;
-}
-
-/* this function is for external use only */
-int
-TUNER_get_afc_hint(FI1236Ptr f)
-{
-    if (f->afc_timer_installed)
-        return TUNER_STILL_TUNING;
-    return f->last_afc_hint;
-}
-
-static void
-MT2032_dump_status(FI1236Ptr f)
-{
-    CARD8 in;
-    CARD8 out[2];
-    CARD8 AFC;
-    CARD8 LDONrb;
-    CARD8 LO1LK, LO2LK, XOK;
-    CARD8 TAD2, TAD1;
-
-    in = 0x0e;
-    I2C_WriteRead(&(f->d), (I2CByte *) &in, 1, out, 2);
-    XOK = out[0] & 1;
-    LO1LK = (out[0] >> 2) & 1;
-    LO2LK = (out[0] >> 1) & 1;
-    LDONrb = (out[0] >> 3) & 1;
-
-    AFC = (out[0] >> 4) & 0x7;
-
-    TAD1 = (out[1] & 0x7);
-    TAD2 = (out[1] >> 4) & 0x7;
-
-    xf86DrvMsg(f->d.pI2CBus->scrnIndex, X_INFO,
-               "MT2032: status: XOK=%d LO1LK=%d LO2LK=%d LDONrb=%d AFC=%d TAD1=%d TAD2=%d\n",
-               XOK, LO1LK, LO2LK, LDONrb, AFC, TAD1, TAD2);
-    xf86DrvMsg(f->d.pI2CBus->scrnIndex, X_INFO,
-               "MT2032: status: OSCILLATOR:%s PLL1:%s PLL2:%s\n",
-               XOK ? "ok" : "off",
-               LO1LK ? "locked" : "off", LO2LK ? "locked" : "off");
-
-}
-
-static void
-MT2032_tune(FI1236Ptr f, double freq, double step)
-{
-    MT2032_parameters m;
-    CARD8 data[10];
-    int i;
-
-    /* NTSC IF is 44mhz.. but 733/16=45.8125 and all TDAXXXX docs mention
-       45.75, 39, 58.75 and 30. */
-#if 0
-    MT2032_calculate_register_settings(&m, freq, 1090.0, 45.125, 5.25, 6.0,
-                                       step);
-    MT2032_calculate_register_settings(&m, freq, 1090.0, 45.74, 5.25, 6.0,
-                                       step);
-#endif
-    MT2032_calculate_register_settings(&m, freq, 1090.0, f->video_if, 5.25, 3.0,
-                                       step);
-    MT2032_dump_parameters(f, &m);
-    MT2032_implement_settings(f, &m);
-    /* MT2032_dump_parameters(f, &m); */
-    for (i = 0; i < 3; i++) {
-        MT2032_optimize_VCO(f, &m);
-        if (MT2032_wait_for_lock(f)) {
-            data[0] = 0x02;     /* LO Gain control register 0x02 */
-            data[1] = 0x20;
-            I2C_WriteRead(&(f->d), (I2CByte *) data, 2, NULL, 0);
-            return;
-        }
-        data[0] = 0x07;
-        data[1] = 0x88 | f->xogc;
-        I2C_WriteRead(&(f->d), (I2CByte *) data, 2, NULL, 0);
-        usleep(15000);
-        data[1] = 0x08 | f->xogc;
-        I2C_WriteRead(&(f->d), (I2CByte *) data, 2, NULL, 0);
-    }
-    xf86DrvMsg(f->d.pI2CBus->scrnIndex, X_INFO,
-               "MT2032: failed to set frequency\n");
-}
-
-void
-FI1236_set_tuner_type(FI1236Ptr f, int type)
-{
-    f->type = type;
-    if (type >= NUM_TUNERS)
-        type = NUM_TUNERS - 1;
-    if (type < 0)
-        type = 0;
-    memcpy(&(f->parm), &(tuner_parms[type]), sizeof(FI1236_parameters));
-    f->original_frequency = f->parm.min_freq;
-    f->afc_delta = 0;
-    if (type == TUNER_TYPE_MT2032) {
-        MT2032_init(f);
-        return;
-    }
-}
-
-static CARD32
-AFC_TimerCallback(OsTimerPtr timer, CARD32 time, void *data)
-{
-    FI1236Ptr f = (FI1236Ptr) data;
-
-    if (FI1236_AFC(f))
-        return 150;
-    else {
-        f->afc_timer_installed = FALSE;
-        f->afc_count = 0;
-        return 0;
-    }
-}
-
-void
-FI1236_tune(FI1236Ptr f, CARD32 frequency)
-{
-    CARD16 divider;
-    CARD8 data;
-
-    if (frequency < f->parm.min_freq)
-        frequency = f->parm.min_freq;
-    if (frequency > f->parm.max_freq)
-        frequency = f->parm.max_freq;
-
-    divider = (f->parm.fcar + (CARD16) frequency) & 0x7fff;
-    f->tuner_data.div1 = (CARD8) ((divider >> 8) & 0x7f);
-    f->tuner_data.div2 = (CARD8) (divider & 0xff);
-    f->tuner_data.control = f->parm.control;
-
-    if (frequency < f->parm.threshold1)
-        f->tuner_data.band = f->parm.band_low;
-    else if (frequency < f->parm.threshold2)
-        f->tuner_data.band = f->parm.band_mid;
-    else
-        f->tuner_data.band = f->parm.band_high;
-
-    xf86DrvMsg(f->d.pI2CBus->scrnIndex, X_INFO,
-               "Setting tuner band to %d\n", f->tuner_data.band);
-
-    xf86DrvMsg(f->d.pI2CBus->scrnIndex, X_INFO,
-               "Setting tuner frequency to %d\n", (int) frequency);
-
-    if ((f->type == TUNER_TYPE_FM1216ME) || (f->type == TUNER_TYPE_FI1236W)) {
-        f->tuner_data.aux = 0x20;
-        I2C_WriteRead(&(f->d), (I2CByte *) &(f->tuner_data), 5, NULL, 0);
-        I2C_WriteRead(&(f->d), NULL, 0, &data, 1);
-        xf86DrvMsg(f->d.pI2CBus->scrnIndex, X_INFO, "Tuner status %x\n", data);
-    }
-    else
-        I2C_WriteRead(&(f->d), (I2CByte *) &(f->tuner_data), 4, NULL, 0);
-}
-
-void
-TUNER_set_frequency(FI1236Ptr f, CARD32 frequency)
-{
-    if (frequency < f->parm.min_freq)
-        frequency = f->parm.min_freq;
-    if (frequency > f->parm.max_freq)
-        frequency = f->parm.max_freq;
-
-    f->afc_delta = 0;
-    f->original_frequency = frequency;
-
-    if (f->type == TUNER_TYPE_MT2032)
-        MT2032_tune(f, (1.0 * frequency) / 16.0, 0.0625);
-    else
-        FI1236_tune(f, frequency);
-
-    if (!f->afc_timer_installed) {
-        f->afc_timer_installed = TRUE;
-/*      RegisterBlockAndWakeupHandlers(FI1236_BlockHandler, AFCWakeup, f); */
-        TimerSet(NULL, 0, 300, AFC_TimerCallback, f);
-    }
-
-}
-
-int
-FI1236_AFC(FI1236Ptr f)
-{
-#if 0
-    xf86DrvMsg(f->d.pI2CBus->scrnIndex, X_INFO,
-               "AFC: f=%p f->count=%d f->original_frequency=%d f->afc_delta=%d\n",
-               f, f->afc_count, f->original_frequency, f->afc_delta);
-#endif
-    f->afc_count++;
-    if (f->type == TUNER_TYPE_MT2032) {
-        f->last_afc_hint = MT2032_get_afc_hint(f);
-        xf86DrvMsg(f->d.pI2CBus->scrnIndex, X_INFO,
-                   "AFC: afc_hint=%d\n", f->last_afc_hint);
-        if (f->last_afc_hint == TUNER_TUNED)
-            return 0;
-        if (f->afc_count > 3)
-            f->last_afc_hint = TUNER_OFF;
-        if (f->last_afc_hint == TUNER_OFF)
-            f->afc_delta = 0;
-        else
-            f->afc_delta += f->last_afc_hint;
-
-        xf86DrvMsg(f->d.pI2CBus->scrnIndex, X_INFO,
-                   "AFC: Setting tuner frequency to %g\n",
-                   (0.5 * (2 * f->original_frequency + f->afc_delta)) / 16.0);
-        MT2032_tune(f,
-                    (1.0 * f->original_frequency + 0.5 * f->afc_delta) / 16.0,
-                    0.03125);
-        if (f->last_afc_hint == TUNER_OFF)
-            return 0;
-        return 1;               /* call me again */
-    }
-    else {
-        f->last_afc_hint = FI1236_get_afc_hint(f);
-        if (f->last_afc_hint == TUNER_TUNED) {
-            xf86DrvMsg(f->d.pI2CBus->scrnIndex, X_INFO, "AFC: TUNER_TUNNED\n");
-            return 0;
-        }
-        if (f->afc_count > 3)
-            f->last_afc_hint = TUNER_OFF;
-
-        if (f->last_afc_hint == TUNER_OFF)
-            f->afc_delta = 0;
-        else
-            f->afc_delta += f->last_afc_hint;
-
-        xf86DrvMsg(f->d.pI2CBus->scrnIndex, X_INFO,
-                   "AFC: Setting tuner frequency to %g\n",
-                   (0.5 * (2 * f->original_frequency + f->afc_delta)) / 16.0);
-        FI1236_tune(f, f->original_frequency + f->afc_delta);
-        if (f->last_afc_hint == TUNER_OFF)
-            return 0;
-        return 1;               /* call me again */
-    }
-    return 0;                   /* done */
-}
-
-void
-fi1236_dump_status(FI1236Ptr f)
-{
-    if (f->type == TUNER_TYPE_MT2032)
-        MT2032_dump_status(f);
-}
diff --git a/hw/xfree86/i2c/fi1236.h b/hw/xfree86/i2c/fi1236.h
deleted file mode 100644
index 0530892..0000000
--- a/hw/xfree86/i2c/fi1236.h
+++ /dev/null
@@ -1,113 +0,0 @@
-#ifndef __FI1236_H__
-#define __FI1236_H__
-
-#include "xf86i2c.h"
-
-/* why someone has defined NUM someplace else is beyoung me.. */
-#undef NUM
-
-typedef struct {
-    CARD32 fcar;                /* 16 * fcar_Mhz */
-    CARD32 min_freq;            /* 16 * min_freq_Mhz */
-    CARD32 max_freq;            /* 16 * max_freq_Mhz */
-
-    CARD32 threshold1;          /* 16 * Value_Mhz */
-    CARD32 threshold2;          /* 16 * Value_Mhz */
-
-    CARD8 band_low;
-    CARD8 band_mid;
-    CARD8 band_high;
-    CARD8 control;
-} FI1236_parameters;
-
-typedef struct {
-    /* what we want */
-    /* all frequencies are in Mhz */
-    double f_rf;                /* frequency to tune to */
-    double f_if1;               /* first intermediate frequency */
-    double f_if2;               /* second intermediate frequency */
-    double f_ref;               /* reference frequency */
-    double f_ifbw;              /* bandwidth */
-    double f_step;              /* step */
-
-    /* what we compute */
-    double f_lo1;
-    double f_lo2;
-    int LO1I;
-    int LO2I;
-    int SEL;
-    int STEP;
-    int NUM;
-} MT2032_parameters;
-
-typedef struct {
-    I2CDevRec d;
-    int type;
-
-    void *afc_source;           /* The AFC source may be another chip like TDA988x */
-
-    int afc_delta;
-    CARD32 original_frequency;
-    Bool afc_timer_installed;
-    int afc_count;
-    int last_afc_hint;
-
-    double video_if;
-    FI1236_parameters parm;
-    int xogc;                   /* for MT2032 */
-
-    struct {
-        CARD8 div1;
-        CARD8 div2;
-        CARD8 control;
-        CARD8 band;
-        CARD8 aux;              /* this is for MK3 tuners */
-    } tuner_data;
-} FI1236Rec, *FI1236Ptr;
-
-#define TUNER_TYPE_FI1236              0
-#define TUNER_TYPE_FI1216              1
-#define TUNER_TYPE_TEMIC_FN5AL         2
-#define TUNER_TYPE_MT2032	       3
-#define TUNER_TYPE_FI1246              4
-#define TUNER_TYPE_FI1256              5
-#define TUNER_TYPE_FI1236W             6
-#define TUNER_TYPE_FM1216ME            7
-
-#define FI1236_ADDR(a)        ((a)->d.SlaveAddr)
-
-#define FI1236_ADDR_1	     0xC6
-#define FI1236_ADDR_2        0xC0
-
-#define TUNER_TUNED   0
-#define TUNER_JUST_BELOW 1
-#define TUNER_JUST_ABOVE -1
-#define TUNER_OFF      4
-#define TUNER_STILL_TUNING      5
-
-void FI1236_tune(FI1236Ptr f, CARD32 frequency);
-
-#define FI1236SymbolsList  \
-		"Detect_FI1236", \
-		"FI1236_set_tuner_type", \
-		"TUNER_set_frequency"
-
-#define xf86_Detect_FI1236		Detect_FI1236
-extern _X_EXPORT FI1236Ptr Detect_FI1236(I2CBusPtr b, I2CSlaveAddr addr);
-
-#define xf86_FI1236_set_tuner_type	FI1236_set_tuner_type
-extern _X_EXPORT void FI1236_set_tuner_type(FI1236Ptr f, int type);
-
-#define xf86_TUNER_set_frequency	TUNER_set_frequency
-extern _X_EXPORT void TUNER_set_frequency(FI1236Ptr f, CARD32 frequency);
-
-#define xf86_FI1236_AFC			FI1236_AFC
-extern _X_EXPORT int FI1236_AFC(FI1236Ptr f);
-
-#define xf86_TUNER_get_afc_hint		TUNER_get_afc_hint
-extern _X_EXPORT int TUNER_get_afc_hint(FI1236Ptr f);
-
-#define xf86_fi1236_dump_status		fi1236_dump_status
-extern _X_EXPORT void fi1236_dump_status(FI1236Ptr f);
-
-#endif
diff --git a/hw/xfree86/i2c/fi1236_module.c b/hw/xfree86/i2c/fi1236_module.c
deleted file mode 100644
index 2f453d9..0000000
--- a/hw/xfree86/i2c/fi1236_module.c
+++ /dev/null
@@ -1,24 +0,0 @@
-#ifdef HAVE_XORG_CONFIG_H
-#include <xorg-config.h>
-#endif
-
-#include "xf86Module.h"
-
-static XF86ModuleVersionInfo fi1236VersRec = {
-    "fi1236",
-    MODULEVENDORSTRING,
-    MODINFOSTRING1,
-    MODINFOSTRING2,
-    XORG_VERSION_CURRENT,
-    1, 0, 0,
-    ABI_CLASS_VIDEODRV,         /* This needs the video driver ABI */
-    ABI_VIDEODRV_VERSION,
-    MOD_CLASS_NONE,
-    {0, 0, 0, 0}
-};
-
-_X_EXPORT XF86ModuleData fi1236ModuleData = {
-    &fi1236VersRec,
-    NULL,
-    NULL
-};
diff --git a/hw/xfree86/i2c/msp3430.c b/hw/xfree86/i2c/msp3430.c
deleted file mode 100644
index a501489..0000000
--- a/hw/xfree86/i2c/msp3430.c
+++ /dev/null
@@ -1,779 +0,0 @@
-#ifdef HAVE_XORG_CONFIG_H
-#include <xorg-config.h>
-#endif
-
-#include <string.h>
-#include <unistd.h>
-
-#include "xf86.h"
-#include "xf86i2c.h"
-#include "msp3430.h"
-#include "i2c_def.h"
-
-#define CONTROL         0x00
-#define WR_DEM          0x10
-#define RD_DEM          0x11
-#define WR_DSP          0x12
-#define RD_DSP          0x13
-
-void InitMSP34xxG(MSP3430Ptr m);
-void InitMSP34x5D(MSP3430Ptr m);
-void CheckModeMSP34x5D(MSP3430Ptr m);
-static const char *MSP_getProductName(CARD16 product_id);
-void mpause(int milliseconds);
-
-#define __MSPDEBUG__	0
-
-#if __MSPDEBUG__ > 3
-
-void MSPBeep(MSP3430Ptr m, CARD8 freq);
-
-#define __MSPBEEP MSPBeep(m,0x14);
-
-#else
-
-#define __MSPBEEP
-#endif
-
-static void
-SetMSP3430Control(MSP3430Ptr m, CARD8 RegAddress, CARD8 RegValueHigh,
-                  CARD8 RegValueLow)
-{
-    I2CByte data[3];
-
-    data[0] = RegAddress;
-    data[1] = RegValueHigh;
-    data[2] = RegValueLow;
-
-    I2C_WriteRead(&(m->d), data, 3, NULL, 0);
-}
-
-static void
-SetMSP3430Data(MSP3430Ptr m, CARD8 RegAddress, CARD8 RegSubAddressHigh,
-               CARD8 RegSubAddressLow, CARD8 RegValueHigh, CARD8 RegValueLow)
-{
-    I2CByte data[5];
-
-#ifdef MSP_DEBUG
-    if (!m->registers_present[RegSubAddressLow]) {
-        xf86DrvMsg(m->d.pI2CBus->scrnIndex, X_ERROR,
-                   "Attempt to access non-existent register in MSP34xxX: 0x%02x 0x%02x 0x%02x <- 0x%02x 0x%02x\n",
-                   RegAddress, RegSubAddressHigh, RegSubAddressLow,
-                   RegValueHigh, RegValueLow);
-    }
-#endif
-
-    data[0] = RegAddress;
-    data[1] = RegSubAddressHigh;
-    data[2] = RegSubAddressLow;
-    data[3] = RegValueHigh;
-    data[4] = RegValueLow;
-
-    I2C_WriteRead(&(m->d), data, 5, NULL, 0);
-}
-
-static void
-GetMSP3430Data(MSP3430Ptr m, CARD8 RegAddress, CARD8 RegSubAddressHigh,
-               CARD8 RegSubAddressLow, CARD8 *RegValueHigh, CARD8 *RegValueLow)
-{
-    I2CByte send[3];
-    I2CByte receive[2];
-
-    send[0] = RegAddress;
-    send[1] = RegSubAddressHigh;
-    send[2] = RegSubAddressLow;
-
-    I2C_WriteRead(&(m->d), send, 3, receive, 2);
-
-    *RegValueHigh = receive[0];
-    *RegValueLow = receive[1];
-}
-
-#if __MSPDEBUG__ > 2
-static void
-MSP3430DumpStatus(MSP3430Ptr m)
-{
-    CARD8 status_hi, status_lo;
-    CARD8 subaddr, data[2];
-
-    GetMSP3430Data(m, RD_DEM, 0x02, 0x00, &status_hi, &status_lo);
-    xf86DrvMsg(m->d.pI2CBus->scrnIndex, X_INFO,
-               "MSP34xx: SAP(8)=%d mono/NICAM(7)=%d stereo=%d %s O_1=%d O_0=%d 2nd car=%d 1st car=%d\n",
-               status_hi & 1, (status_lo >> 7) & 1, (status_lo >> 6) & 1,
-               (status_lo >> 5) ? ((status_hi >> 1) & 1 ? "bad NICAM reception"
-                                   : "NICAM") : ((status_hi >> 1) & 1 ? "bogus"
-                                                 : "ANALOG FM/AM"),
-               (status_lo >> 4) & 1, (status_lo >> 3) & 1,
-               !((status_lo >> 2) & 1), !((status_lo >> 1) & 1));
-
-    GetMSP3430Data(m, RD_DEM, 0x00, 0x7E, &status_hi, &status_lo);
-    xf86DrvMsg(m->d.pI2CBus->scrnIndex, X_INFO,
-               "MSP34xx: standard result=0x%02x%02x\n", status_hi, status_lo);
-    subaddr = 0x0;
-    I2C_WriteRead(&(m->d), &subaddr, 1, data, 2);
-    xf86DrvMsg(m->d.pI2CBus->scrnIndex, X_INFO, "MSP34xx: control=0x%02x%02x\n",
-               data[1], data[0]);
-}
-#endif
-
-/* wrapper */
-void
-InitMSP3430(MSP3430Ptr m)
-{
-#if __MSPDEBUG__ > 1
-    xf86DrvMsg(m->d.pI2CBus->scrnIndex, X_INFO,
-               "InitMSP3430(m->connector=%d, m->standard=%d, m->chip_family=%d)\n",
-               m->connector, m->standard, m->chip_family);
-#endif
-    switch (m->chip_family) {
-    case MSPFAMILY_34x0G:
-        InitMSP34xxG(m);
-        break;
-    case MSPFAMILY_34x5G:
-        InitMSP34xxG(m);
-        break;
-    case MSPFAMILY_34x5D:
-        InitMSP34x5D(m);
-        break;
-    }
-}
-
-/*-----------------------------------------------------------------
-| common functions for all MSP34xx chips 
-|----------------------------------------------------------------*/
-
-MSP3430Ptr
-DetectMSP3430(I2CBusPtr b, I2CSlaveAddr addr)
-{
-    MSP3430Ptr m;
-    I2CByte a;
-    CARD8 hardware_version, major_revision, product_code, rom_version;
-    Bool supported;
-
-    m = calloc(1, sizeof(MSP3430Rec));
-    if (m == NULL)
-        return NULL;
-    m->d.DevName = strdup("MSP34xx");
-    m->d.SlaveAddr = addr;
-    m->d.pI2CBus = b;
-    m->d.NextDev = NULL;
-    m->d.StartTimeout = b->StartTimeout;
-    m->d.BitTimeout = b->BitTimeout;
-    m->d.AcknTimeout = b->AcknTimeout;
-    m->d.ByteTimeout = b->ByteTimeout;
-
-    if (!I2C_WriteRead(&(m->d), NULL, 0, &a, 1)) {
-        free((void *) m->d.DevName);
-        free(m);
-        return NULL;
-    }
-
-    m->standard = MSP3430_NTSC;
-    m->connector = MSP3430_CONNECTOR_1;
-    m->mode = MSPMODE_STEREO_A; /*stereo or chanel A if avail. */
-    m->c_format = MSPFORMAT_UNKNOWN;
-    m->c_standard = MSPSTANDARD_UNKNOWN;
-    m->c_matrix = m->c_fmmatrix = m->c_source = 0;
-    m->volume = 0;
-    m->recheck = FALSE;
-
-    GetMSP3430Data(m, RD_DSP, 0x00, 0x1E, &hardware_version, &major_revision);
-    GetMSP3430Data(m, RD_DSP, 0x00, 0x1F, &product_code, &rom_version);
-    m->hardware_version = hardware_version;
-    m->major_revision = major_revision;
-    m->product_code = product_code;
-    m->rom_version = rom_version;
-
-    m->chip_id = ((major_revision << 8) | product_code);
-
-    supported = FALSE;
-    switch (major_revision) {
-    case 4:                    /* 34xxD */
-        switch (product_code) {
-        case 0x05:             /* 3405D */
-        case 0x0A:             /* 3410D */
-        case 0x0F:             /* 3415D */
-            m->chip_family = MSPFAMILY_34x5D;
-            m->recheck = TRUE;
-            supported = TRUE;
-            break;
-        default:
-            m->chip_family = MSPFAMILY_34x0D;
-        }
-        break;
-    case 7:                    /* 34xxG */
-        switch (product_code) {
-        case 0x00:
-        case 0x0A:
-        case 0x1E:
-        case 0x28:
-        case 0x32:
-            m->chip_family = MSPFAMILY_34x0G;
-            supported = TRUE;
-            break;
-        case 0x0f:
-        case 0x19:
-        case 0x2d:
-        case 0x37:
-        case 0x41:
-            m->chip_family = MSPFAMILY_34x5G;
-            supported = TRUE;
-#ifdef MSP_DEBUG
-            memset(m->registers_present, 0, 256);
-#define A(num) m->registers_present[(num)]=1;
-#define B(num1, num2) memset(&(m->registers_present[num1]), 1, num2-num1);
-            A(0x20)
-                A(0x30)
-                A(0x40)
-                A(0x00)
-                B(0x01, 0x08)
-                B(0x0B, 0x0E)
-                A(0x10)
-                B(0x12, 0x14)
-                A(0x16)
-                A(0x29)
-#undef B
-#undef A
-#endif
-                break;
-        default:
-            m->chip_family = MSPFAMILY_UNKNOWN;
-        }
-        break;
-    default:
-        m->chip_family = MSPFAMILY_UNKNOWN;
-    }
-
-    xf86DrvMsg(m->d.pI2CBus->scrnIndex, X_INFO,
-               "Found %s%s, rom version 0x%02x, chip_id=0x%04x\n",
-               MSP_getProductName(m->chip_id),
-               supported ? "" : " (unsupported)", rom_version, m->chip_id);
-
-    if (!supported) {
-        free((void *) m->d.DevName);
-        free(m);
-        return NULL;
-    }
-    if (!I2CDevInit(&(m->d))) {
-        free((void *) m->d.DevName);
-        free(m);
-        return NULL;
-    }
-
-    return m;
-}
-
-void
-ResetMSP3430(MSP3430Ptr m)
-{
-    /* Reset the MSP3430 */
-    SetMSP3430Control(m, 0x00, 0x80, 0x00);
-    /* Set it back to normal operation */
-    SetMSP3430Control(m, 0x00, 0x00, 0x00);
-
-    m->c_format = MSPFORMAT_UNKNOWN;
-    m->c_standard = MSPSTANDARD_UNKNOWN;
-    m->c_matrix = m->c_fmmatrix = m->c_source = 0;
-    m->volume = 0;
-}
-
-void
-MSP3430SetVolume(MSP3430Ptr m, CARD8 value)
-{
-    CARD8 result;
-
-#if 0
-    CARD8 old_volume;
-
-    GetMSP3430Data(m, RD_DSP, 0x00, 0x00, &old_volume, &result);
-    xf86DrvMsg(m->d.pI2CBus->scrnIndex, X_INFO, "MSP3430 result 0x%02x\n",
-               result);
-#endif
-    /* save an extra Get call */
-    result = 0;
-
-    SetMSP3430Data(m, WR_DSP, 0x00, 0x00, value, result);
-
-    SetMSP3430Data(m, WR_DSP, 0x00, 0x07, value, 0);
-    m->volume = value;
-
-#if __MSPDEBUG__ > 2
-    MSP3430DumpStatus(m);
-    __MSPBEEP GetMSP3430Data(m, RD_DSP, 0x00, 0x00, &old_volume, &result);
-    xf86DrvMsg(m->d.pI2CBus->scrnIndex, X_INFO, "MSP3430 volume 0x%02x\n",
-               value);
-#endif
-}
-
-void
-MSP3430SetSAP(MSP3430Ptr m, int mode)
-{
-    xf86DrvMsg(m->d.pI2CBus->scrnIndex, X_INFO,
-               "Put actual code to change SAP here\n");
-
-    SetMSP3430Data(m, WR_DSP, 0x00, 0x08, mode & 0xff, 0x20);
-}
-
-#if 0
-void
-MSP3430SetSource(MSP3430Ptr m, CARD8 value)
-{
-    /* Write to DSP, register 0x0008, (loudspeaker channel source/matrix) */
-    /* This sets the source to the TV tuner, for stereo operation */
-    SetMSP3430Data(m, WR_DSP, 0x00, 0x08, value, 0x20);
-}
-#endif
-
-static const char *
-MSP_getProductName(CARD16 product_id)
-{
-    switch (product_id) {
-    case 0x0400:
-        return "MSP3400D";
-    case 0x040a:
-        return "MSP3410D";
-    case 0x0405:
-        return "MSP3405D";
-    case 0x040f:
-        return "MSP3415D";
-    case 0x0700:
-        return "MSP3400G";
-    case 0x070a:
-        return "MSP3410G";
-    case 0x071e:
-        return "MSP3430G";
-    case 0x0728:
-        return "MSP3440G";
-    case 0x0732:
-        return "MSP3450G";
-    case 0x070f:
-        return "MSP3415G";
-    case 0x0719:
-        return "MSP3425G";
-    case 0x072d:
-        return "MSP3445G";
-    case 0x0737:
-        return "MSP3455G";
-    case 0x0741:
-        return "MSP3465G";
-    }
-    return "MSP - unknown type";
-}
-
-#if __MSPDEBUG__ > 2
-/*puts beep in MSP output
-    freq = 0x01 - 16Hz ... 0x40 - 1kHz ... 0xff - 4kHz  
-*/
-void
-MSPBeep(MSP3430Ptr m, CARD8 freq)
-{
-    SetMSP3430Data(m, WR_DSP, 0x00, freq, 0x7f, 0x40);
-    mpause(100);
-    SetMSP3430Data(m, WR_DSP, 0x00, 0x14, 0x00, 0x00);
-}
-#endif
-
-void
-mpause(int milliseconds)
-{
-    int i, m;
-
-    m = milliseconds / 20;
-    for (i = 0; i < m; i++)
-        usleep(20000);
-}
-
-/*-----------------------------------------------------------------
-| specific functions for all MSP34xxG chips 
-|----------------------------------------------------------------*/
-
-void
-InitMSP34xxG(MSP3430Ptr m)
-{
-
-#if __MSPDEBUG__ > 1
-    xf86DrvMsg(m->d.pI2CBus->scrnIndex, X_INFO,
-               "InitMSP34xxG(m->connector=%d, m->standard=%d, m->chip_family=%d)\n",
-               m->connector, m->standard, m->chip_family);
-#endif
-    /* Reset MSP3430 */
-    SetMSP3430Control(m, 0x00, 0x80, 0x00);
-    /* Set it back to normal operation */
-    SetMSP3430Control(m, 0x00, 0x00, 0x00);
-
-    /*set MODUS register */
-    /* bits: 0 - automatic sound detection */
-    /*       1 - enable STATUS change */
-    /*       12 - detect 6.5 Mhz carrier as D/K1, D/K2 or D/K NICAM  (does not seem to work ) */
-    /*       13 - detect 4.5 Mhz carrier as BTSC */
-    if ((m->standard & 0xff) == MSP3430_PAL) {
-        SetMSP3430Data(m, WR_DEM, 0x00, 0x30, 0x30, 0x03 | 0x08);       /* make O_ pins tristate */
-        /* PAL standard */
-        SetMSP3430Data(m, WR_DEM, 0x00, 0x20, 0x00, 0x01);      /* possibly wrong */
-    }
-    else {
-        SetMSP3430Data(m, WR_DEM, 0x00, 0x30, 0x20, 0x03 | 0x08);
-        /* standard selection is M-BTSC-Stereo */
-        SetMSP3430Data(m, WR_DEM, 0x00, 0x20, 0x00, 0x20);
-    }
-
-    switch (m->connector) {
-    case MSP3430_CONNECTOR_1:
-        SetMSP3430Data(m, WR_DSP, 0x00, 0x08, 0x03, 0x20);
-        break;
-    case MSP3430_CONNECTOR_2:
-        /* this has not been checked yet.. could be bogus */
-        /* SCART Input Prescale: 0 dB gain */
-        SetMSP3430Data(m, WR_DSP, 0x00, 0x0d, 0x19, 0x00);
-        SetMSP3430Data(m, WR_DSP, 0x00, 0x08, 0x02, 0x20);
-        break;
-    case MSP3430_CONNECTOR_3:
-    default:
-        /* SCART Input Prescale: 0 dB gain */
-        SetMSP3430Data(m, WR_DSP, 0x00, 0x0d, 0x19, 0x00);
-
-        SetMSP3430Data(m, WR_DSP, 0x00, 0x08, 0x02, 0x20);
-        break;
-    }
-
-    switch (m->standard) {
-    case MSP3430_PAL:
-        SetMSP3430Data(m, WR_DSP, 0x00, 0x0e, 0x24, 0x03);
-        SetMSP3430Data(m, WR_DSP, 0x00, 0x10, 0x00, 0x5a);
-        SetMSP3430Data(m, WR_DEM, 0x00, 0x20, 0x00, 0x03);
-        /* Set volume to FAST_MUTE. */
-        SetMSP3430Data(m, WR_DSP, 0x00, 0x00, 0xFF, 0x00);
-        break;
-    case MSP3430_PAL_DK1:
-        SetMSP3430Data(m, WR_DSP, 0x00, 0x0e, 0x24, 0x03);
-        SetMSP3430Data(m, WR_DSP, 0x00, 0x10, 0x00, 0x5a);
-        SetMSP3430Data(m, WR_DEM, 0x00, 0x20, 0x00, 0x04);
-        /* Set volume to FAST_MUTE. */
-        SetMSP3430Data(m, WR_DSP, 0x00, 0x00, 0xFF, 0x00);
-        break;
-    case MSP3430_SECAM:        /* is this right ? */
-    case MSP3430_NTSC:
-        /* Write to DSP, register 0x000E, (prescale FM/FM matrix) */
-        SetMSP3430Data(m, WR_DSP, 0x00, 0x0e, 0x24, 0x03);
-
-        /* Set volume to FAST_MUTE. */
-        SetMSP3430Data(m, WR_DSP, 0x00, 0x00, 0xFF, 0x00);
-        break;
-    }
-
-}
-
-/*-----------------------------------------------------------------
-| specific functions for all MSP34x5D chips 
-|----------------------------------------------------------------*/
-
-void
-InitMSP34x5D(MSP3430Ptr m)
-{
-    int count;
-    CARD8 high, low;
-    CARD16 result, standard;
-    CARD16 peak;
-
-    if (m->c_format == MSPFORMAT_UNKNOWN)
-        ResetMSP3430(m);
-    else {
-        /*mute volume */
-        SetMSP3430Data(m, WR_DSP, 0x00, 0x00, 0x00, 0x00);
-    }
-
-    switch (m->connector) {
-    case MSP3430_CONNECTOR_2:
-    case MSP3430_CONNECTOR_3:
-        if (m->c_format != MSPFORMAT_SCART) {
-            /* SCART Input Prescale: 0 dB gain */
-            SetMSP3430Data(m, WR_DSP, 0x00, 0x0d, 0x19, 0x00);
-            /* this has not been checked yet.. could be bogus */
-            m->c_format = MSPFORMAT_SCART;      /*stereo */
-        }
-        break;
-    case MSP3430_CONNECTOR_1:
-    default:
-
-        switch (m->standard & 0x00ff) {
-        case MSP3430_PAL:
-            switch (m->standard) {
-            case MSP3430_PAL_DK1:
-                standard = MSPSTANDARD_FM_DK1;
-                break;
-/*			case MSP3430_PAL_DK2:
-			    standard=MSPSTANDARD_FM_DK2;
-			    break;
-			case MSP3430_PAL_BG:
-			may be FM stereo (Germany) or FM NICAM (Scandinavia,spain)
-			    standard=MSPSTANDARD_AUTO;
-			    break;
-*/
-            default:
-                standard = MSPSTANDARD_AUTO;
-            }
-            break;
-        case MSP3430_SECAM:
-            standard = MSPSTANDARD_AUTO;
-        case MSP3430_NTSC:
-            /* Only MSP34x5 supported format - Korean NTSC-M */
-            standard = MSPSTANDARD_FM_M;
-        default:
-            standard = MSPSTANDARD_AUTO;
-        }
-
-        /*no NICAM support in MSP3410D - force to autodetect */
-        if ((m->chip_id == 0x405) && (standard >= MSPSTANDARD_NICAM_BG))
-            standard = MSPSTANDARD_AUTO;
-
-        if (m->c_standard != standard) {
-
-            SetMSP3430Data(m, WR_DEM, 0x00, 0x20, standard >> 8,
-                           standard & 0xFF);
-            if (standard == MSPSTANDARD_AUTO) {
-                count = 50;     /* time shouldn't exceed 1s, just in case */
-                do {
-                    usleep(20000);
-                    GetMSP3430Data(m, RD_DEM, 0x00, 0x7e, &high, &low);
-                    result = (high << 8) | low;
-                    --count;
-                } while (result > 0x07ff && count > 0);
-
-                if ((result > MSPSTANDARD_AUTO))
-                    standard = result;
-                else
-                    standard = MSPSTANDARD_UNKNOWN;
-#if __MSPDEBUG__ > 1
-                xf86DrvMsg(m->d.pI2CBus->scrnIndex, X_INFO,
-                           "Detected audio standard: %d\n", result);
-#endif
-                /* result = MSPSTANDARD_NICAM_L can be one of:
-                   SECAM_L - MSPSTANDARD_NICAM_L
-                   D/K1 - MSPSTANDARD_FM_DK1
-                   D/K2 - MSPSTANDARD_FM_DK2
-                   D/K-NICAM - MSPSTANDARD_NICAM_DK */
-                if (standard == MSPSTANDARD_NICAM_L) {
-                    if ((m->standard & 0x00ff) == MSP3430_PAL) {
-                        /* force PAL D/K  */
-                        standard = MSPSTANDARD_FM_DK1;
-                        SetMSP3430Data(m, WR_DEM, 0x00, 0x20, standard >> 8,
-                                       standard & 0xFF);
-#if __MSPDEBUG__ > 1
-                        xf86DrvMsg(m->d.pI2CBus->scrnIndex, X_INFO,
-                                   "Detected 6.5MHz carrier - forced to D/K1 !!!\n");
-#endif
-                    }
-                }
-            }
-            m->c_standard = standard;
-        }                       /*end - standard changed */
-        else {
-            if (standard < MSPSTANDARD_NICAM_BG) {
-                /* get old value of ident. mode register */
-                GetMSP3430Data(m, RD_DSP, 0x00, 0x15, &high, &low);
-                /* reset Ident-Filter */
-                SetMSP3430Data(m, WR_DSP, 0x00, 0x14, 0x00, 0x3F);
-                /* put back old value to ident. mode register */
-                SetMSP3430Data(m, WR_DSP, 0x00, 0x14, 0x00, low);
-            }
-        }
-
-        if (standard <= MSPSTANDARD_AUTO) {
-            m->c_format = MSPFORMAT_1xFM;
-        }
-        else if (standard < MSPSTANDARD_NICAM_BG) {
-            /* set FM prescale */
-            SetMSP3430Data(m, WR_DSP, 0x00, 0x0e, 0x30, 0);
-            /* set FM deemphasis */
-            SetMSP3430Data(m, WR_DSP, 0x00, 0x0f,
-                           ((standard == MSPSTANDARD_FM_M) ? 0 : 1), 0);
-
-            /* check if FM2 carrier is present */
-            /*turn off FM DC Notch */
-            SetMSP3430Data(m, WR_DSP, 0x00, 0x17, 0x00, 0x3f);
-            /*matrix source for Quasi-Peak Detector - stereo: ch2->L ch1->R */
-            SetMSP3430Data(m, WR_DSP, 0x00, 0x0c, 0x00, 0x20);
-
-            mpause(250);
-            GetMSP3430Data(m, RD_DSP, 0x00, 0x1A, &high, &low);
-            peak = (high << 8) | low;
-#if __MSPDEBUG__ > 1
-            xf86DrvMsg(m->d.pI2CBus->scrnIndex, X_INFO,
-                       "Second carrier Quasi-Peak detection: %d\n", peak);
-#endif
-            /*turn on FM DC Notch */
-            SetMSP3430Data(m, WR_DSP, 0x00, 0x17, 0x00, 0x00);
-
-            if (peak < 5) {
-                /* if second carrier not detected - only mono from first carrier */
-                m->c_format = MSPFORMAT_1xFM;
-            }
-            else {
-                m->c_format = MSPFORMAT_2xFM;
-                /*start of FM identification process - FM_WAIT
-                   wait at least 0.5s - used 1s - gives beter resolution */
-                mpause(1000);
-            }
-        }
-        else {
-            if (standard == MSPSTANDARD_NICAM_L) {
-                m->c_format = MSPFORMAT_NICAM_AM;
-                /* set AM prescale */
-                SetMSP3430Data(m, WR_DSP, 0x00, 0x0e, 0x7C, 0);
-            }
-            else {
-                m->c_format = MSPFORMAT_NICAM_FM;
-                /* set FM prescale */
-                SetMSP3430Data(m, WR_DSP, 0x00, 0x0e, 0x30, 0);
-            }
-            /* set FM deemphasis */
-            SetMSP3430Data(m, WR_DSP, 0x00, 0x0f, 0x00, 0);
-            /* set NICAM prescale to 0dB */
-            SetMSP3430Data(m, WR_DSP, 0x00, 0x10, 0x20, 0);
-        }
-
-        break;
-    }                           /*end - case conector */
-
-    CheckModeMSP34x5D(m);
-
-    /* Set volume to FAST_MUTE. */
-    /*SetMSP3430Data(m, WR_DSP, 0x00, 0x00, 0xFF, 0x00); */
-    /*set volume */
-    MSP3430SetVolume(m, m->volume);
-
-__MSPBEEP}                      /* EnableMSP34x5D ()... */
-
-void
-CheckModeMSP34x5D(MSP3430Ptr m)
-{
-    const char stereo_on = 25;
-    const char stereo_off = 20;
-    const char dual_on = -stereo_on;
-    const char dual_off = -stereo_off;
-    char detect;
-    CARD8 matrix, fmmatrix, source, high, low;
-
-    fmmatrix = 0;               /*no matrix */
-    source = 0;
-    /*FM*/ switch (m->c_format) {
-    case MSPFORMAT_NICAM_FM:
-    case MSPFORMAT_NICAM_AM:
-    case MSPFORMAT_SCART:
-        source = ((m->c_format == MSPFORMAT_SCART) ? 2 : 1);
-        switch (m->mode) {
-        case MSPMODE_MONO:
-            matrix = 0x30;
-            /*MONO*/ break;
-        case MSPMODE_A:
-            matrix = 0x00;
-            /*A*/ break;
-        case MSPMODE_B:
-            matrix = 0x10;
-            /*B*/ break;
-        default:
-            matrix = 0x20;
-            /*STEREO*/ break;
-        }
-        break;
-    default:
-    case MSPFORMAT_1xFM:
-        matrix = 0x00;
-        /*A*/ break;
-    case MSPFORMAT_2xFM:
-        switch (m->mode) {
-        case MSPMODE_MONO:
-            matrix = 0x30;
-            /*MONO*/ break;
-        case MSPMODE_STEREO:
-            matrix = 0x20;
-            /*STEREO*/ fmmatrix = ((m->c_standard == MSPSTANDARD_FM_M) ? 2 : 1);
-            break;
-        case MSPMODE_AB:
-            matrix = 0x20;
-            /*STEREO*/ break;
-        case MSPMODE_A:
-            matrix = 0x00;
-            /*A*/ break;
-        case MSPMODE_B:
-            matrix = 0x10;
-            /*B*/ break;
-        default:
-            /*FM_IDENT_CHECK */
-            GetMSP3430Data(m, RD_DSP, 0x00, 0x18, &high, &low);
-            detect = (char) high;
-#if __MSPDEBUG__ > 1
-            xf86DrvMsg(m->d.pI2CBus->scrnIndex, X_INFO,
-                       "Stereo Detection Register: %d\n", detect);
-#endif
-            if (detect >=
-                ((m->c_mode == MSPMODE_STEREO) ? stereo_off : stereo_on)) {
-                m->c_mode = MSPMODE_STEREO;
-                matrix = 0x20;
-                /*STEREO*/
-                    fmmatrix = ((m->c_standard == MSPSTANDARD_FM_M) ? 2 : 1);
-            }
-            else if (detect <= ((m->c_mode == MSPMODE_AB) ? dual_off : dual_on)) {
-                m->c_mode = MSPMODE_AB;
-                switch (m->mode) {
-                case MSPMODE_STEREO_AB:
-                    matrix = 0x20;
-                    break;
-                case MSPMODE_STEREO_B:
-                    matrix = 0x10;
-                    break;
-                default:
-                case MSPMODE_A:
-                    matrix = 0x00;
-                    break;
-                }
-            }
-            else {
-                m->c_mode = MSPMODE_MONO;
-                matrix = 0x30;
-            /*MONO*/}
-            break;
-        }                       /* end - case mode */
-        break;
-    }
-
-    if (m->c_fmmatrix != fmmatrix) {
-        GetMSP3430Data(m, RD_DSP, 0x00, 0x0e, &high, &low);
-        SetMSP3430Data(m, WR_DSP, 0x00, 0x0e, high, fmmatrix);
-        m->c_fmmatrix = fmmatrix;
-    }
-
-    if ((m->c_matrix != matrix) || (m->c_source != source)) {
-        /*set chanel source and matrix for loudspeaker */
-        SetMSP3430Data(m, WR_DSP, 0x00, 0x08, source, matrix);
-
-        m->c_matrix = matrix;
-        m->c_source = source;
-    }
-
-    if (((m->c_format) & 0xF0) == MSPFORMAT_NICAM)
-        SetMSP3430Data(m, WR_DEM, 0x00, 0x21, 0, 1);
-
-#if __MSPDEBUG__ > 0
-    char *msg;
-
-    switch (matrix) {
-    case 0x30:
-        /*MONO*/ msg = "MONO";
-        break;
-    case 0x00:
-        /*LEFT*/ msg = "MONO/CHANNEL_1";
-        break;
-    case 0x10:
-        /*RIGHT*/ msg = "MONO/CHANNEL_2";
-        break;
-    case 0x20:
-        /*LEFT*/ msg = "STEREO";
-        break;
-    default:
-        msg = "unknown";
-        break;
-    }
-    xf86DrvMsg(m->d.pI2CBus->scrnIndex, X_INFO, "Audio mode set to: %s\n", msg);
-#endif
-}
diff --git a/hw/xfree86/i2c/msp3430.h b/hw/xfree86/i2c/msp3430.h
deleted file mode 100644
index ef66e1e..0000000
--- a/hw/xfree86/i2c/msp3430.h
+++ /dev/null
@@ -1,116 +0,0 @@
-#ifndef __MSP3430_H__
-#define __MSP3430_H__
-
-#include "xf86i2c.h"
-
-typedef struct {
-    I2CDevRec d;
-
-    int standard;
-    int connector;
-    int mode;
-
-    CARD8 hardware_version, major_revision, product_code, rom_version;
-#ifdef MSP_DEBUG
-    CARD8 registers_present[256];
-#endif
-
-    CARD16 chip_id;
-    CARD8 chip_family;
-    Bool recheck;               /*reinitialization needed after channel change */
-    CARD8 c_format;             /*current state of audio format */
-    CARD16 c_standard;          /*current state of standard register */
-    CARD8 c_source;             /*current state of source register */
-    CARD8 c_matrix;             /*current state of matrix register */
-    CARD8 c_fmmatrix;           /*current state of fmmatrix register */
-    int c_mode;                 /* current state of mode for autoswitchimg */
-    CARD8 volume;
-} MSP3430Rec, *MSP3430Ptr;
-
-#define MSP3430_ADDR_1      0x80
-#define MSP3430_ADDR_2		0x84
-#define MSP3430_ADDR_3		0x88
-
-#define MSP3430_PAL		1
-#define MSP3430_NTSC		2
-#define MSP3430_PAL_DK1         (0x100 | MSP3430_PAL)
-#define MSP3430_SECAM           3
-
-#define MSP3430_CONNECTOR_1     1       /* tuner on AIW cards */
-#define MSP3430_CONNECTOR_2     2       /* SVideo on AIW cards */
-#define MSP3430_CONNECTOR_3     3       /* composite on AIW cards */
-
-#define MSP3430_ADDR(a)         ((a)->d.SlaveAddr)
-
-#define MSP3430_FAST_MUTE	0xFF
-/* a handy volume transform function, -1000..1000 -> 0x01..0x7F */
-#define MSP3430_VOLUME(value) (0x01+(0x7F-0x01)*log(value+1001)/log(2001))
-
-/*----------------------------------------------------------*/
-
-/* MSP chip families */
-#define MSPFAMILY_UNKNOWN	0
-#define MSPFAMILY_34x0D		1
-#define MSPFAMILY_34x5D		2
-#define MSPFAMILY_34x0G		3
-#define MSPFAMILY_34x5G		4
-
-/* values for MSP standard */
-#define MSPSTANDARD_UNKNOWN	0x00
-#define MSPSTANDARD_AUTO	0x01
-#define MSPSTANDARD_FM_M	0x02
-#define MSPSTANDARD_FM_BG	0x03
-#define MSPSTANDARD_FM_DK1	0x04
-#define MSPSTANDARD_FM_DK2	0x04
-#define MSPSTANDARD_NICAM_BG	0x08
-#define MSPSTANDARD_NICAM_L	0x09
-#define MSPSTANDARD_NICAM_I	0x0A
-#define MSPSTANDARD_NICAM_DK	0x0B
-
-/* values for MSP format */
-#define MSPFORMAT_UNKNOWN	0x00
-#define MSPFORMAT_FM		0x10
-#define MSPFORMAT_1xFM		0x00|MSPFORMAT_FM
-#define MSPFORMAT_2xFM		0x01|MSPFORMAT_FM
-#define MSPFORMAT_NICAM		0x20
-#define MSPFORMAT_NICAM_FM	0x00|MSPFORMAT_NICAM
-#define MSPFORMAT_NICAM_AM	0x01|MSPFORMAT_NICAM
-#define MSPFORMAT_SCART		0x30
-
-/* values for MSP mode */
-#define MSPMODE_UNKNOWN		0
-/* automatic modes */
-#define MSPMODE_STEREO_AB	1
-#define MSPMODE_STEREO_A	2
-#define MSPMODE_STEREO_B	3
-/* forced modes */
-#define MSPMODE_MONO		4
-#define MSPMODE_STEREO		5
-#define MSPMODE_AB			6
-#define MSPMODE_A			7
-#define MSPMODE_B			8
-/*----------------------------------------------------------*/
-
-#define xf86_InitMSP3430	InitMSP3430
-extern _X_EXPORT void InitMSP3430(MSP3430Ptr m);
-
-#define xf86_DetectMSP3430	DetectMSP3430
-extern _X_EXPORT MSP3430Ptr DetectMSP3430(I2CBusPtr b, I2CSlaveAddr addr);
-
-#define xf86_ResetMSP3430	ResetMSP3430
-extern _X_EXPORT void ResetMSP3430(MSP3430Ptr m);
-
-#define xf86_MSP3430SetVolume	MSP3430SetVolume
-extern _X_EXPORT void MSP3430SetVolume(MSP3430Ptr m, CARD8 value);
-
-#define xf86_MSP3430SetSAP	MSP3430SetSAP
-extern _X_EXPORT void MSP3430SetSAP(MSP3430Ptr m, int mode);
-
-#define MSP3430SymbolsList \
-		"InitMSP3430", \
-		"DetectMSP3430", \
-		"ResetMSP3430", \
-		"MSP3430SetVolume", \
-		"MSP3430SetSAP"
-
-#endif
diff --git a/hw/xfree86/i2c/msp3430_module.c b/hw/xfree86/i2c/msp3430_module.c
deleted file mode 100644
index e177efe..0000000
--- a/hw/xfree86/i2c/msp3430_module.c
+++ /dev/null
@@ -1,24 +0,0 @@
-#ifdef HAVE_XORG_CONFIG_H
-#include <xorg-config.h>
-#endif
-
-#include "xf86Module.h"
-
-static XF86ModuleVersionInfo msp3430VersRec = {
-    "msp3430",
-    MODULEVENDORSTRING,
-    MODINFOSTRING1,
-    MODINFOSTRING2,
-    XORG_VERSION_CURRENT,
-    1, 0, 0,
-    ABI_CLASS_VIDEODRV,         /* This needs the video driver ABI */
-    ABI_VIDEODRV_VERSION,
-    MOD_CLASS_NONE,
-    {0, 0, 0, 0}
-};
-
-_X_EXPORT XF86ModuleData msp3430ModuleData = {
-    &msp3430VersRec,
-    NULL,
-    NULL
-};
diff --git a/hw/xfree86/i2c/tda8425.c b/hw/xfree86/i2c/tda8425.c
deleted file mode 100644
index 051249b..0000000
--- a/hw/xfree86/i2c/tda8425.c
+++ /dev/null
@@ -1,83 +0,0 @@
-#ifdef HAVE_XORG_CONFIG_H
-#include <xorg-config.h>
-#endif
-
-#include "xf86.h"
-#include "xf86i2c.h"
-#include "tda8425.h"
-#include "i2c_def.h"
-
-#define TDA8425(a,b)	{ \
-		data[0]=a; \
-		data[1]=b; \
-		I2C_WriteRead(&(t->d), data, 2, NULL, 0); \
-		}
-
-TDA8425Ptr
-Detect_tda8425(I2CBusPtr b, I2CSlaveAddr addr, Bool force)
-{
-    TDA8425Ptr t;
-
-    t = calloc(1, sizeof(TDA8425Rec));
-    if (t == NULL)
-        return NULL;
-    t->d.DevName = "TDA8425 BTSC Stereo Audio Processor";
-    t->d.SlaveAddr = addr;
-    t->d.pI2CBus = b;
-    t->d.NextDev = NULL;
-    t->d.StartTimeout = b->StartTimeout;
-    t->d.BitTimeout = b->BitTimeout;
-    t->d.AcknTimeout = b->AcknTimeout;
-    t->d.ByteTimeout = b->ByteTimeout;
-
-    if (!force && !I2CProbeAddress(b, addr)) {
-        free(t);
-        return NULL;
-    }
-
-    /* set default parameters */
-    if (!I2CDevInit(&(t->d))) {
-        free(t);
-        return NULL;
-    }
-
-    return t;
-}
-
-Bool
-tda8425_init(TDA8425Ptr t)
-{
-    t->stereo = 3;              /* 3 = Spacial 2 = Linear 1 = Pseudo 0 = Forced mono */
-    t->v_left = 0xFF;           /* FF - C0 */
-    t->v_right = 0xFF;          /* FF - C0 */
-    t->bass = 0xF6;             /* 0xFF - 0xF0 */
-    t->treble = 0xF6;           /* 0xFF - 0xF0 */
-    t->src_sel = 3;             /* 3 - stereo */
-    t->mute = TRUE;
-    t->mux = 0;                 /* 0 - source one, 1 -source 2 */
-
-    tda8425_setaudio(t);
-    return TRUE;
-}
-
-void
-tda8425_setaudio(TDA8425Ptr t)
-{
-    I2CByte data[2];
-
-    TDA8425(0x00, t->v_left);
-    TDA8425(0x01, t->v_right);
-    TDA8425(0x02, t->bass);
-    TDA8425(0x03, t->treble);
-    TDA8425(0x08,
-            0xC0 | (t->mute ? 0x20 : 0x0) | (t->stereo << 3) | (t->
-                                                                src_sel << 1) |
-            t->mux);
-}
-
-void
-tda8425_mute(TDA8425Ptr t, Bool mute)
-{
-    t->mute = mute;
-    tda8425_setaudio(t);
-}
diff --git a/hw/xfree86/i2c/tda8425.h b/hw/xfree86/i2c/tda8425.h
deleted file mode 100644
index e3dfb13..0000000
--- a/hw/xfree86/i2c/tda8425.h
+++ /dev/null
@@ -1,44 +0,0 @@
-#ifndef __TDA8425_H__
-#define __TDA8425_H__
-
-#include "xf86i2c.h"
-
-typedef struct {
-    I2CDevRec d;
-
-    int mux;
-    int stereo;
-    int v_left;
-    int v_right;
-    int bass;
-    int treble;
-    int src_sel;
-    Bool mute;
-} TDA8425Rec, *TDA8425Ptr;
-
-#define TDA8425_ADDR_1   0x82
-
-/* the third parameter is meant to force detection of tda8425.
-   This is because tda8425 is write-only and complete implementation
-   of I2C protocol is not always available. Besides address there is no good
-   way to autodetect it so we have to _know_ it is there anyway */
-
-#define xf86_Detect_tda8425	Detect_tda8425
-extern _X_EXPORT TDA8425Ptr Detect_tda8425(I2CBusPtr b, I2CSlaveAddr addr,
-                                           Bool force);
-#define xf86_tda8425_init	tda8425_init
-extern _X_EXPORT Bool tda8425_init(TDA8425Ptr t);
-
-#define xf86_tda8425_setaudio	tda8425_setaudio
-extern _X_EXPORT void tda8425_setaudio(TDA8425Ptr t);
-
-#define xf86_tda8425_mute	tda8425_mute
-extern _X_EXPORT void tda8425_mute(TDA8425Ptr t, Bool mute);
-
-#define TDA8425SymbolsList  \
-		"Detect_tda8425", \
-		"tda8425_init", \
-		"tda8425_setaudio", \
-		"tda8425_mute"
-
-#endif
diff --git a/hw/xfree86/i2c/tda8425_module.c b/hw/xfree86/i2c/tda8425_module.c
deleted file mode 100644
index 74c820f..0000000
--- a/hw/xfree86/i2c/tda8425_module.c
+++ /dev/null
@@ -1,24 +0,0 @@
-#ifdef HAVE_XORG_CONFIG_H
-#include <xorg-config.h>
-#endif
-
-#include "xf86Module.h"
-
-static XF86ModuleVersionInfo tda8425VersRec = {
-    "tda8425",
-    MODULEVENDORSTRING,
-    MODINFOSTRING1,
-    MODINFOSTRING2,
-    XORG_VERSION_CURRENT,
-    1, 0, 0,
-    ABI_CLASS_VIDEODRV,         /* This needs the video driver ABI */
-    ABI_VIDEODRV_VERSION,
-    MOD_CLASS_NONE,
-    {0, 0, 0, 0}
-};
-
-_X_EXPORT XF86ModuleData tda8425ModuleData = {
-    &tda8425VersRec,
-    NULL,
-    NULL
-};
diff --git a/hw/xfree86/i2c/tda9850.c b/hw/xfree86/i2c/tda9850.c
deleted file mode 100644
index d258bda..0000000
--- a/hw/xfree86/i2c/tda9850.c
+++ /dev/null
@@ -1,136 +0,0 @@
-#ifdef HAVE_XORG_CONFIG_H
-#include <xorg-config.h>
-#endif
-
-#include "xf86.h"
-#include "xf86i2c.h"
-#include "tda9850.h"
-#include "i2c_def.h"
-
-#define TDA9850(a,b)	{ \
-		data[0]=a; \
-		data[1]=b; \
-		I2C_WriteRead(&(t->d), data, 2, NULL, 0); \
-		}
-
-TDA9850Ptr
-Detect_tda9850(I2CBusPtr b, I2CSlaveAddr addr)
-{
-    TDA9850Ptr t;
-    I2CByte a;
-
-    t = calloc(1, sizeof(TDA9850Rec));
-    if (t == NULL)
-        return NULL;
-    switch (addr) {
-    case TDA9850_ADDR_1:
-        t->d.DevName = "TDA9850 BTSC Stereo+SAP Audio Processor";
-        break;
-    default:
-        t->d.DevName = "Generic TDAxxxx";
-        break;
-    }
-    t->d.SlaveAddr = addr;
-    t->d.pI2CBus = b;
-    t->d.NextDev = NULL;
-    t->d.StartTimeout = b->StartTimeout;
-    t->d.BitTimeout = b->BitTimeout;
-    t->d.AcknTimeout = b->AcknTimeout;
-    t->d.ByteTimeout = b->ByteTimeout;
-
-    if (!I2C_WriteRead(&(t->d), NULL, 0, &a, 1)) {
-        free(t);
-        return NULL;
-    }
-
-    /* set default parameters */
-    if (!I2CDevInit(&(t->d))) {
-        free(t);
-        return NULL;
-    }
-
-    return t;
-}
-
-Bool
-tda9850_init(TDA9850Ptr t)
-{
-    t->stereo = 1;
-    t->sap = 0;
-    t->mute = TRUE;
-    t->sap_mute = TRUE;
-    tda9850_setaudio(t);
-    return TRUE;
-}
-
-void
-tda9850_setaudio(TDA9850Ptr t)
-{
-    CARD8 data[2];
-
-    if (t->mux == 2) {
-        TDA9850(0x04, 0x0F);
-        TDA9850(0x05, 0x0F);
-        TDA9850(0x06, 0x58);
-        TDA9850(0x07, 0x07);
-        TDA9850(0x08, 0x00);
-        TDA9850(0x09, 0x00);
-        TDA9850(0x0A, 0x03);
-    }
-    else {
-        TDA9850(0x04, 0x07);
-        TDA9850(0x05, 0x07);
-        TDA9850(0x06, 0x58);
-        TDA9850(0x07, 0x07);
-        TDA9850(0x08, 0x10);
-        TDA9850(0x09, 0x10);
-        TDA9850(0x0A, 0x03);
-    }
-
-    TDA9850(0x06,
-            (t->stereo << 6) | (t->sap << 7) | (t->mute ? 0x8 : 0) | (t->
-                                                                      sap_mute ?
-                                                                      0x10 :
-                                                                      0x0));
-}
-
-void
-tda9850_mute(TDA9850Ptr t, Bool mute)
-{
-    CARD8 data[2];
-
-    xf86DrvMsg(t->d.pI2CBus->scrnIndex, X_INFO, "tda9850_mute %s\n",
-               mute ? "on" : "off");
-    t->mute = mute;
-
-    TDA9850(0x06,
-            (t->stereo << 6) | (t->sap << 7) | (t->mute ? 0x8 : 0x0) | (t->
-                                                                        sap_mute
-                                                                        ? 0x10 :
-                                                                        0x0));
-}
-
-void
-tda9850_sap_mute(TDA9850Ptr t, Bool sap_mute)
-{
-    CARD8 data[2];
-
-    xf86DrvMsg(t->d.pI2CBus->scrnIndex, X_INFO, "tda9850_sap_mute %s\n",
-               sap_mute ? "on" : "off");
-    t->sap_mute = sap_mute;
-
-    TDA9850(0x06,
-            (t->stereo << 6) | (t->sap << 7) | (t->mute ? 0x8 : 0x0) | (t->
-                                                                        sap_mute
-                                                                        ? 0x10 :
-                                                                        0x0));
-}
-
-CARD16
-tda9850_getstatus(TDA9850Ptr t)
-{
-    CARD16 status;
-
-    I2C_WriteRead(&(t->d), NULL, 0, (I2CByte *) &status, 2);
-    return status;
-}
diff --git a/hw/xfree86/i2c/tda9850.h b/hw/xfree86/i2c/tda9850.h
deleted file mode 100644
index 7d82095..0000000
--- a/hw/xfree86/i2c/tda9850.h
+++ /dev/null
@@ -1,43 +0,0 @@
-#ifndef __TDA9850_H__
-#define __TDA9850_H__
-
-#include "xf86i2c.h"
-
-typedef struct {
-    I2CDevRec d;
-
-    int mux;
-    int stereo;
-    int sap;
-    Bool mute;
-    Bool sap_mute;
-} TDA9850Rec, *TDA9850Ptr;
-
-#define TDA9850_ADDR_1   0xB4
-
-#define xf86_Detect_tda9850	Detect_tda9850
-extern _X_EXPORT TDA9850Ptr Detect_tda9850(I2CBusPtr b, I2CSlaveAddr addr);
-
-#define xf86_tda9850_init	tda9850_init
-extern _X_EXPORT Bool tda9850_init(TDA9850Ptr t);
-
-#define xf86_tda9850_setaudio	tda9850_setaudio
-extern _X_EXPORT void tda9850_setaudio(TDA9850Ptr t);
-
-#define xf86_tda9850_mute	tda9850_mute
-extern _X_EXPORT void tda9850_mute(TDA9850Ptr t, Bool mute);
-
-#define xf86_tda9850_sap_mute	tda9850_sap_mute
-extern _X_EXPORT void tda9850_sap_mute(TDA9850Ptr t, Bool sap_mute);
-
-#define xf86_tda9850_getstatus	tda9850_getstatus
-extern _X_EXPORT CARD16 tda9850_getstatus(TDA9850Ptr t);
-
-#define TDA9850SymbolsList  \
-		"Detect_tda9850", \
-		"tda9850_init", \
-		"tda9850_setaudio", \
-		"tda9850_mute", \
-		"tda9850_sap_mute"
-
-#endif
diff --git a/hw/xfree86/i2c/tda9850_module.c b/hw/xfree86/i2c/tda9850_module.c
deleted file mode 100644
index 197d65a..0000000
--- a/hw/xfree86/i2c/tda9850_module.c
+++ /dev/null
@@ -1,24 +0,0 @@
-#ifdef HAVE_XORG_CONFIG_H
-#include <xorg-config.h>
-#endif
-
-#include "xf86Module.h"
-
-static XF86ModuleVersionInfo tda9850VersRec = {
-    "tda9850",
-    MODULEVENDORSTRING,
-    MODINFOSTRING1,
-    MODINFOSTRING2,
-    XORG_VERSION_CURRENT,
-    1, 0, 0,
-    ABI_CLASS_VIDEODRV,         /* This needs the video driver ABI */
-    ABI_VIDEODRV_VERSION,
-    MOD_CLASS_NONE,
-    {0, 0, 0, 0}
-};
-
-_X_EXPORT XF86ModuleData tda9850ModuleData = {
-    &tda9850VersRec,
-    NULL,
-    NULL
-};
diff --git a/hw/xfree86/i2c/tda9885.c b/hw/xfree86/i2c/tda9885.c
deleted file mode 100644
index fd859bd..0000000
--- a/hw/xfree86/i2c/tda9885.c
+++ /dev/null
@@ -1,100 +0,0 @@
-#ifdef HAVE_XORG_CONFIG_H
-#include <xorg-config.h>
-#endif
-
-#include "xf86.h"
-#include "xf86i2c.h"
-#include "tda9885.h"
-#include "i2c_def.h"
-
-TDA9885Ptr
-Detect_tda9885(I2CBusPtr b, I2CSlaveAddr addr)
-{
-    TDA9885Ptr t;
-    I2CByte a;
-
-    t = calloc(1, sizeof(TDA9885Rec));
-    if (t == NULL)
-        return NULL;
-    switch (addr) {
-    case TDA9885_ADDR_1:
-    case TDA9885_ADDR_2:
-    case TDA9885_ADDR_3:
-    case TDA9885_ADDR_4:
-        t->d.DevName = "TDA9885 Alignment-free IF-PLL";
-        break;
-    default:
-        t->d.DevName = "Generic TDAxxxx";
-        break;
-    }
-    t->d.SlaveAddr = addr;
-    t->d.pI2CBus = b;
-    t->d.NextDev = NULL;
-    t->d.StartTimeout = b->StartTimeout;
-    t->d.BitTimeout = b->BitTimeout;
-    t->d.AcknTimeout = b->AcknTimeout;
-    t->d.ByteTimeout = b->ByteTimeout;
-
-    if (!I2C_WriteRead(&(t->d), NULL, 0, &a, 1)) {
-        free(t);
-        return NULL;
-    }
-
-    /* set default parameters */
-    if (!I2CDevInit(&(t->d))) {
-        free(t);
-        return NULL;
-    }
-
-    return t;
-}
-
-Bool
-tda9885_init(TDA9885Ptr t)
-{
-    t->forced_mute_audio = 1;
-    return TRUE;
-}
-
-void
-tda9885_getstatus(TDA9885Ptr t)
-{
-    CARD8 value;
-
-    I2C_WriteRead(&(t->d), NULL, 0, &value, 1);
-    t->after_reset = value & 1;
-    t->afc_status = (value >> 1) & 0xf;
-    t->fm_carrier = (value >> 5) & 1;
-    t->vif_level = (value >> 6) & 1;
-    t->afc_win = (value >> 7) & 1;
-}
-
-void
-tda9885_setparameters(TDA9885Ptr t)
-{
-    CARD8 data[4];
-
-    data[0] = 0;                /* start with subaddress 0 */
-    data[1] = (t->sound_trap & 1) | ((t->auto_mute_fm & 1) << 1) | ((t->carrier_mode & 1) << 2) | ((t->modulation & 3) << 3) | ((t->forced_mute_audio & 1) << 5) | ((t->port1 & 1) << 6) | ((t->port2 & 1) << 7);       /* B data */
-    data[2] = (t->top_adjustment & 0x1f) | ((t->deemphasis & 0x3) << 5) | ((t->audio_gain & 1) << 7);   /* C data */
-    data[3] = (t->standard_sound_carrier & 0x3) | ((t->standard_video_if & 0x07) << 2) | ((t->minimum_gain & 0x01) << 5) | ((t->gating & 0x01) << 6) | ((t->vif_agc & 0x01) << 7);      /* E data */
-
-    I2C_WriteRead(&(t->d), data, 4, NULL, 0);
-
-    xf86DrvMsg(t->d.pI2CBus->scrnIndex, X_INFO,
-               "TDA9885 setparam: B data: %x, C data: %x, E data: %x\n",
-               data[1], data[2], data[3]);
-}
-
-void
-tda9885_dumpstatus(TDA9885Ptr t)
-{
-    xf86DrvMsg(t->d.pI2CBus->scrnIndex, X_INFO,
-               "TDA9885 status: after_reset=%d afc_status=%d (%3.1f kHz off) fm_carrier=%d vif_level=%d afc_win=%d %s\n",
-               t->after_reset, t->afc_status,
-               (t->afc_status <
-                8) ? -12.5 - t->afc_status * 25.0 : -12.5 + (16 -
-                                                             t->afc_status) *
-               25.0, t->fm_carrier, t->vif_level, t->afc_win,
-               t->afc_win ? "VCO in" : "VCO out");
-}
diff --git a/hw/xfree86/i2c/tda9885.h b/hw/xfree86/i2c/tda9885.h
deleted file mode 100644
index 2d8a8af..0000000
--- a/hw/xfree86/i2c/tda9885.h
+++ /dev/null
@@ -1,63 +0,0 @@
-#ifndef __TDA9885_H__
-#define __TDA9885_H__
-
-#include "xf86i2c.h"
-
-typedef struct {
-    I2CDevRec d;
-
-    /* write-only parameters */
-    /* B DATA */
-    CARD8 sound_trap;
-    CARD8 auto_mute_fm;
-    CARD8 carrier_mode;
-    CARD8 modulation;
-    CARD8 forced_mute_audio;
-    CARD8 port1;
-    CARD8 port2;
-    /* C DATA */
-    CARD8 top_adjustment;
-    CARD8 deemphasis;
-    CARD8 audio_gain;
-    /* E DATA */
-    CARD8 standard_sound_carrier;
-    CARD8 standard_video_if;
-    CARD8 minimum_gain;
-    CARD8 gating;
-    CARD8 vif_agc;
-    /* read-only values */
-
-    CARD8 after_reset;
-    CARD8 afc_status;
-    CARD8 vif_level;
-    CARD8 afc_win;
-    CARD8 fm_carrier;
-} TDA9885Rec, *TDA9885Ptr;
-
-#define TDA9885_ADDR_1   0x86
-#define TDA9885_ADDR_2   0x84
-#define TDA9885_ADDR_3   0x96
-#define TDA9885_ADDR_4   0x94
-
-#define xf86_Detect_tda9885		Detect_tda9885
-extern _X_EXPORT TDA9885Ptr Detect_tda9885(I2CBusPtr b, I2CSlaveAddr addr);
-
-#define xf86_tda9885_init		tda9885_init
-extern _X_EXPORT Bool tda9885_init(TDA9885Ptr t);
-
-#define xf86_tda9885_setparameters	tda9885_setparameters
-extern _X_EXPORT void tda9885_setparameters(TDA9885Ptr t);
-
-#define xf86_tda9885_getstatus		tda9885_getstatus
-extern _X_EXPORT void tda9885_getstatus(TDA9885Ptr t);
-
-#define xf86_tda9885_dumpstatus		tda9885_dumpstatus
-extern _X_EXPORT void tda9885_dumpstatus(TDA9885Ptr t);
-
-#define TDA9885SymbolsList  \
-		"Detect_tda9885", \
-		"tda9885_init", \
-		"tda9885_setaudio", \
-		"tda9885_mute"
-
-#endif
diff --git a/hw/xfree86/i2c/tda9885_module.c b/hw/xfree86/i2c/tda9885_module.c
deleted file mode 100644
index e71bd60..0000000
--- a/hw/xfree86/i2c/tda9885_module.c
+++ /dev/null
@@ -1,24 +0,0 @@
-#ifdef HAVE_XORG_CONFIG_H
-#include <xorg-config.h>
-#endif
-
-#include "xf86Module.h"
-
-static XF86ModuleVersionInfo tda9885VersRec = {
-    "tda9885",
-    MODULEVENDORSTRING,
-    MODINFOSTRING1,
-    MODINFOSTRING2,
-    XORG_VERSION_CURRENT,
-    1, 0, 0,
-    ABI_CLASS_VIDEODRV,         /* This needs the video driver ABI */
-    ABI_VIDEODRV_VERSION,
-    MOD_CLASS_NONE,
-    {0, 0, 0, 0}
-};
-
-_X_EXPORT XF86ModuleData tda9885ModuleData = {
-    &tda9885VersRec,
-    NULL,
-    NULL
-};
diff --git a/hw/xfree86/i2c/uda1380.c b/hw/xfree86/i2c/uda1380.c
deleted file mode 100644
index 8722687..0000000
--- a/hw/xfree86/i2c/uda1380.c
+++ /dev/null
@@ -1,196 +0,0 @@
-/*************************************************************************************
- * Copyright (C) 2005 Bogdan D. bogdand at users.sourceforge.net
- *
- * 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 AUTHOR 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 author 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 author.
- *
- ************************************************************************************/
-
-#ifdef HAVE_XORG_CONFIG_H
-#include <xorg-config.h>
-#endif
-
-#include "xf86.h"
-#include "xf86i2c.h"
-#include "uda1380.h"
-#include "i2c_def.h"
-
-UDA1380Ptr
-Detect_uda1380(I2CBusPtr b, I2CSlaveAddr addr)
-{
-    UDA1380Ptr t;
-    I2CByte a;
-
-    t = calloc(1, sizeof(UDA1380Rec));
-    if (t == NULL)
-        return NULL;
-    switch (addr) {
-    case UDA1380_ADDR_1:
-    case UDA1380_ADDR_2:
-        t->d.DevName = "UDA1380 Stereo audion coder-decoder";
-        break;
-    default:
-        t->d.DevName = "Generic UDAxxxx";
-        break;
-    }
-    t->d.SlaveAddr = addr;
-    t->d.pI2CBus = b;
-    t->d.NextDev = NULL;
-    t->d.StartTimeout = b->StartTimeout;
-    t->d.BitTimeout = b->BitTimeout;
-    t->d.AcknTimeout = b->AcknTimeout;
-    t->d.ByteTimeout = b->ByteTimeout;
-
-    if (!I2C_WriteRead(&(t->d), NULL, 0, &a, 1)) {
-        free(t);
-        return NULL;
-    }
-
-    /* set default parameters */
-    if (!I2CDevInit(&(t->d))) {
-        free(t);
-        return NULL;
-    }
-
-    xf86DrvMsg(t->d.pI2CBus->scrnIndex, X_INFO,
-               "UDA1380 stereo coder-decoder detected\n");
-
-    return t;
-}
-
-Bool
-uda1380_init(UDA1380Ptr t)
-{
-    CARD8 data[3];
-    CARD16 tmp;
-    Bool ret;
-
-    /* Power control */
-    data[0] = 0x02;
-    tmp =
-        (1 << 13) | (1 << 10) | (1 << 8) | (1 << 7) | (1 << 6) | (1 << 3) | (1
-                                                                             <<
-                                                                             1);
-    data[1] = (CARD8) ((tmp >> 8) & 0xff);
-    data[2] = (CARD8) (tmp & 0xff);
-    ret = I2C_WriteRead(&(t->d), data, 3, NULL, 0);
-    if (ret == FALSE) {
-        xf86DrvMsg(t->d.pI2CBus->scrnIndex, X_INFO,
-                   "UDA1380 failed to initialize\n");
-        return FALSE;
-    }
-
-    /* Analog mixer  (AVC) */
-    data[0] = 0x03;
-    /* the analog mixer is muted initially */
-    data[1] = 0x3f;
-    data[2] = 0x3f;
-    ret = I2C_WriteRead(&(t->d), data, 3, NULL, 0);
-    if (ret == FALSE) {
-        xf86DrvMsg(t->d.pI2CBus->scrnIndex, X_INFO,
-                   "UDA1380 failed to initialize\n");
-        return FALSE;
-    }
-
-    xf86DrvMsg(t->d.pI2CBus->scrnIndex, X_INFO, "UDA1380 initialized\n");
-
-    return TRUE;
-}
-
-void
-uda1380_shutdown(UDA1380Ptr t)
-{
-    CARD8 data[3];
-    Bool ret;
-
-    /* Power control */
-    data[0] = 0x02;
-    data[1] = 0;
-    data[2] = 0;
-    ret = I2C_WriteRead(&(t->d), data, 3, NULL, 0);
-    if (ret == FALSE)
-        xf86DrvMsg(t->d.pI2CBus->scrnIndex, X_INFO,
-                   "UDA1380 failed to shutdown\n");
-}
-
-void
-uda1380_setvolume(UDA1380Ptr t, INT32 value)
-{
-    CARD8 data[3];
-
-    /*
-     * We have to scale the value ranging from -1000 to 1000 to 0x2c to 0
-     */
-    CARD8 volume = 47 - (CARD8) ((value + 1000) * 47 / 2000);
-    Bool ret;
-
-    t->analog_mixer_settings = ((volume << 8) & 0x3f00) | (volume & 0x3f);
-
-    /* Analog mixer  (AVC) */
-    data[0] = 0x03;
-    data[1] = volume & 0x3f;
-    data[2] = volume & 0x3f;
-    ret = I2C_WriteRead(&(t->d), data, 3, NULL, 0);
-    if (ret == FALSE)
-        xf86DrvMsg(t->d.pI2CBus->scrnIndex, X_INFO,
-                   "UDA1380 failed to set volume\n");
-}
-
-void
-uda1380_mute(UDA1380Ptr t, Bool mute)
-{
-    CARD8 data[3];
-    Bool ret;
-
-    if (mute == TRUE) {
-        /* Analog mixer  (AVC) */
-        data[0] = 0x03;
-        data[1] = 0xff;
-        data[2] = 0xff;
-        ret = I2C_WriteRead(&(t->d), data, 3, NULL, 0);
-        if (ret == FALSE)
-            xf86DrvMsg(t->d.pI2CBus->scrnIndex, X_INFO,
-                       "UDA1380 failed to mute\n");
-    }
-    else {
-        /* Analog mixer  (AVC) */
-        data[0] = 0x03;
-        data[1] = (CARD8) ((t->analog_mixer_settings >> 8) & 0x3f);
-        data[2] = (CARD8) (t->analog_mixer_settings & 0x3f);
-        ret = I2C_WriteRead(&(t->d), data, 3, NULL, 0);
-        if (ret == FALSE)
-            xf86DrvMsg(t->d.pI2CBus->scrnIndex, X_INFO,
-                       "UDA1380 failed to unmute\n");
-    }
-}
-
-void
-uda1380_getstatus(UDA1380Ptr t)
-{
-}
-
-void
-uda1380_setparameters(UDA1380Ptr t)
-{
-}
-
-void
-uda1380_dumpstatus(UDA1380Ptr t)
-{
-}
diff --git a/hw/xfree86/i2c/uda1380.h b/hw/xfree86/i2c/uda1380.h
deleted file mode 100644
index f0bc616..0000000
--- a/hw/xfree86/i2c/uda1380.h
+++ /dev/null
@@ -1,81 +0,0 @@
-/*************************************************************************************
- * Copyright (C) 2005 Bogdan D. bogdand at users.sourceforge.net
- *
- * 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 AUTHOR 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 author 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 author.
- *
- * Revision 1.3  2005/09/24 21:56:00  bogdand
- * Changed the license to a X/MIT one
- *
- * Revision 1.2  2005/07/01 22:43:11  daniels
- * Change all misc.h and os.h references to <X11/foo.h>.
- *
- *
- ************************************************************************************/
-
-#ifndef __UDA1380_H__
-#define __UDA1380_H__
-
-#include "xf86i2c.h"
-
-typedef struct {
-    I2CDevRec d;
-
-    CARD16 analog_mixer_settings;       /* register 0x03 */
-
-} UDA1380Rec, *UDA1380Ptr;
-
-#define UDA1380_ADDR_1   0x30
-#define UDA1380_ADDR_2   0x34
-
-#define xf86_Detect_uda1380		Detect_uda1380
-extern _X_EXPORT UDA1380Ptr Detect_uda1380(I2CBusPtr b, I2CSlaveAddr addr);
-
-#define xf86_uda1380_init		uda1380_init
-extern _X_EXPORT Bool uda1380_init(UDA1380Ptr t);
-
-#define xf86_uda1380_shutdown		uda1380_shutdown
-extern _X_EXPORT void uda1380_shutdown(UDA1380Ptr t);
-
-#define xf86_uda1380_setvolume		uda1380_setvolume
-extern _X_EXPORT void uda1380_setvolume(UDA1380Ptr t, INT32);
-
-#define xf86_uda1380_mute		uda1380_mute
-extern _X_EXPORT void uda1380_mute(UDA1380Ptr t, Bool);
-
-#define xf86_uda1380_setparameters	uda1380_setparameters
-extern _X_EXPORT void uda1380_setparameters(UDA1380Ptr t);
-
-#define xf86_uda1380_getstatus		uda1380_getstatus
-extern _X_EXPORT void uda1380_getstatus(UDA1380Ptr t);
-
-#define xf86_uda1380_dumpstatus		uda1380_dumpstatus
-extern _X_EXPORT void uda1380_dumpstatus(UDA1380Ptr t);
-
-#define UDA1380SymbolsList  \
-		"Detect_uda1380", \
-		"uda1380_init", \
-		"uda1380_shutdown", \
-		"uda1380_setvolume", \
-		"uda1380_mute", \
-		"uda1380_setparameters", \
-		"uda1380_getstatus", \
-		"uda1380_dumpstatus"
-
-#endif
diff --git a/hw/xfree86/i2c/uda1380_module.c b/hw/xfree86/i2c/uda1380_module.c
deleted file mode 100644
index dca834b..0000000
--- a/hw/xfree86/i2c/uda1380_module.c
+++ /dev/null
@@ -1,24 +0,0 @@
-#ifdef HAVE_XORG_CONFIG_H
-#include <xorg-config.h>
-#endif
-
-#include "xf86Module.h"
-
-static XF86ModuleVersionInfo uda1380VersRec = {
-    "uda1380",
-    MODULEVENDORSTRING,
-    MODINFOSTRING1,
-    MODINFOSTRING2,
-    XORG_VERSION_CURRENT,
-    1, 0, 0,
-    ABI_CLASS_VIDEODRV,         /* This needs the video driver ABI */
-    ABI_VIDEODRV_VERSION,
-    MOD_CLASS_NONE,
-    {0, 0, 0, 0}
-};
-
-_X_EXPORT XF86ModuleData uda1380ModuleData = {
-    &uda1380VersRec,
-    NULL,
-    NULL
-};
diff --git a/hw/xfree86/loader/loadmod.c b/hw/xfree86/loader/loadmod.c
index e1f649a..f1f7c22 100644
--- a/hw/xfree86/loader/loadmod.c
+++ b/hw/xfree86/loader/loadmod.c
@@ -197,7 +197,6 @@ static const char *stdSubdirs[] = {
     "",
     "input/",
     "drivers/",
-    "multimedia/",
     "extensions/",
     "internal/",
     NULL
commit 4302484ef2e67b2e05756c7ee0834dce938f1b44
Author: Adam Jackson <ajax at redhat.com>
Date:   Mon Jul 21 10:06:53 2014 -0400

    dix: Remove arch awareness from servermd.h (v2)
    
    At this point we have no architectures where image byte order is
    different from bitmap bit order, or where either of those two are not
    also the native word endianness.  Hooray, one more place where we don't
    have to worry about enabling new CPU architectures.
    
    v2: Rebase to master to handle the addition of ppc64le, arc, and xtensa,
    and use autoconf's endianness detection instead of gcc predefines.
    
    Signed-off-by: Adam Jackson <ajax at redhat.com>
    Reviewed-by: Daniel Stone <daniels at collabora.com>
    Signed-off-by: Keith Packard <keithp at keithp.com>

diff --git a/configure.ac b/configure.ac
index 4338dc5..0479fd5 100644
--- a/configure.ac
+++ b/configure.ac
@@ -139,7 +139,8 @@ AC_CHECK_HEADERS([fcntl.h stdlib.h string.h unistd.h dlfcn.h stropts.h \
 dnl Checks for typedefs, structures, and compiler characteristics.
 AC_C_CONST
 AC_C_TYPEOF
-AC_C_BIGENDIAN([ENDIAN="X_BIG_ENDIAN"], [ENDIAN="X_LITTLE_ENDIAN"])
+AC_C_BIGENDIAN(AC_DEFINE(X_BYTE_ORDER, X_BIG_ENDIAN, [byte order]),
+               AC_DEFINE(X_BYTE_ORDER, X_LITTLE_ENDIAN, [byte order]))
 
 AC_CHECK_SIZEOF([unsigned long])
 if test "$ac_cv_sizeof_unsigned_long" = 8; then
diff --git a/include/dix-config.h.in b/include/dix-config.h.in
index f980a3d..2203f82 100644
--- a/include/dix-config.h.in
+++ b/include/dix-config.h.in
@@ -493,4 +493,7 @@
 /* Build glamor's GBM-based EGL support */
 #undef GLAMOR_HAS_GBM
 
+/* byte order */
+#undef X_BYTE_ORDER
+
 #endif /* _DIX_CONFIG_H_ */
diff --git a/include/servermd.h b/include/servermd.h
index dd1da7d..0132d67 100644
--- a/include/servermd.h
+++ b/include/servermd.h
@@ -47,195 +47,18 @@ SOFTWARE.
 #ifndef SERVERMD_H
 #define SERVERMD_H 1
 
-/*
- * Note: much of this is vestigial from mfb/cfb times.  This should
- * really be simplified even further.
- */
-
-#ifdef __avr32__
-
-#define IMAGE_BYTE_ORDER        MSBFirst
-#define BITMAP_BIT_ORDER        MSBFirst
-
-#endif                          /* __avr32__ */
-
-#ifdef __arm32__
+#include "dix-config.h"
 
+#if X_BYTE_ORDER == X_LITTLE_ENDIAN
 #define IMAGE_BYTE_ORDER        LSBFirst
 #define BITMAP_BIT_ORDER        LSBFirst
-
-#endif                          /* __arm32__ */
-
-#if defined(__nds32__)
-
-#define IMAGE_BYTE_ORDER	LSBFirst
-
-#endif                          /* __nds32__ */
-
-#if defined __hppa__
-
-#define IMAGE_BYTE_ORDER	MSBFirst
-#define BITMAP_BIT_ORDER	MSBFirst
-#endif                          /* hpux || __hppa__ */
-
-#if defined(__powerpc__) || defined(__ppc__) || defined(__ppc64__)
-
-#if defined(__LITTLE_ENDIAN__)
-#define IMAGE_BYTE_ORDER      LSBFirst
-#define BITMAP_BIT_ORDER      LSBFirst
-#else
-#define IMAGE_BYTE_ORDER      MSBFirst
-#define BITMAP_BIT_ORDER      MSBFirst
-#endif
-
-#endif                          /* PowerPC */
-
-#if defined(__sh__)
-
-#if defined(__BIG_ENDIAN__)
-#define IMAGE_BYTE_ORDER	MSBFirst
-#define BITMAP_BIT_ORDER	MSBFirst
-#else
-#define IMAGE_BYTE_ORDER	LSBFirst
-#define BITMAP_BIT_ORDER	LSBFirst
-#endif
-
-#endif                          /* SuperH */
-
-#if defined(__m32r__)
-
-#if defined(__BIG_ENDIAN__)
-#define IMAGE_BYTE_ORDER      MSBFirst
-#define BITMAP_BIT_ORDER      MSBFirst
-#else
-#define IMAGE_BYTE_ORDER      LSBFirst
-#define BITMAP_BIT_ORDER      LSBFirst
-#endif
-
-#endif                          /* __m32r__ */
-
-#if defined(sun386) || defined(sun5)
-#define IMAGE_BYTE_ORDER	LSBFirst        /* Values for the SUN only */
-#define BITMAP_BIT_ORDER	LSBFirst
-#else
-#define IMAGE_BYTE_ORDER	MSBFirst        /* Values for the SUN only */
-#define BITMAP_BIT_ORDER	MSBFirst
-#endif
-
-#if (defined(mips) || defined(__mips))
-
-#if defined(MIPSEL) || defined(__MIPSEL__)
-#define IMAGE_BYTE_ORDER	LSBFirst        /* Values for the PMAX only */
-#define BITMAP_BIT_ORDER	LSBFirst
-#else
-#define IMAGE_BYTE_ORDER	MSBFirst        /* Values for the MIPS only */
-#define BITMAP_BIT_ORDER	MSBFirst
-#endif
-
-#endif                          /* mips */
-
-#if defined(__alpha) || defined(__alpha__)
-#define IMAGE_BYTE_ORDER	LSBFirst        /* Values for the Alpha only */
-#define BITMAP_BIT_ORDER       LSBFirst
-#endif                          /* alpha */
-
-#if defined (linux) && defined (__s390__)
-
-#define IMAGE_BYTE_ORDER      	MSBFirst
-#define BITMAP_BIT_ORDER      	MSBFirst
-
-#endif                          /* linux/s390 */
-
-#if defined (linux) && defined (__s390x__)
-
-#define IMAGE_BYTE_ORDER       MSBFirst
-#define BITMAP_BIT_ORDER       MSBFirst
-
-#endif                          /* linux/s390x */
-
-#if defined(__ia64__) || defined(ia64)
-
-#define IMAGE_BYTE_ORDER	LSBFirst
-#define BITMAP_BIT_ORDER       LSBFirst
-
-#endif                          /* ia64 */
-
-#if defined(__amd64__) || defined(amd64) || defined(__amd64)
-#define IMAGE_BYTE_ORDER	LSBFirst
-#define BITMAP_BIT_ORDER       LSBFirst
-#endif                          /* AMD64 */
-
-#if	defined(SVR4) && (defined(__i386__) || defined(__i386) ) ||	\
-	defined(__alpha__) || defined(__alpha) || \
-	defined(__i386__)
-
-#ifndef IMAGE_BYTE_ORDER
-#define IMAGE_BYTE_ORDER	LSBFirst
-#endif
-
-#ifndef BITMAP_BIT_ORDER
-#define BITMAP_BIT_ORDER      LSBFirst
-#endif
-
-#endif                          /* SVR4 / BSD / i386 */
-
-#if defined (linux) && defined (__mc68000__)
-
-#define IMAGE_BYTE_ORDER       MSBFirst
-#define BITMAP_BIT_ORDER       MSBFirst
-
-#endif                          /* linux/m68k */
-
-/* linux on ARM */
-#if defined(linux) && defined(__arm__)
-#define IMAGE_BYTE_ORDER	LSBFirst
-#define BITMAP_BIT_ORDER	LSBFirst
-#endif
-
-/* linux on IBM S/390 */
-#if defined (linux) && defined (__s390__)
-#define IMAGE_BYTE_ORDER	MSBFirst
-#define BITMAP_BIT_ORDER	MSBFirst
-#endif                          /* linux/s390 */
-
-#ifdef __aarch64__
-
-#ifdef __AARCH64EL__
-#define IMAGE_BYTE_ORDER        LSBFirst
-#define BITMAP_BIT_ORDER        LSBFirst
-#endif
-#ifdef __AARCH64EB__
+#elif X_BYTE_ORDER == X_BIG_ENDIAN
 #define IMAGE_BYTE_ORDER        MSBFirst
 #define BITMAP_BIT_ORDER        MSBFirst
-#endif
-
-#endif                          /* __aarch64__ */
-
-#if defined(__arc__)
-
-#if defined(__BIG_ENDIAN__)
-#define IMAGE_BYTE_ORDER	MSBFirst
-#define BITMAP_BIT_ORDER	MSBFirst
 #else
-#define IMAGE_BYTE_ORDER	LSBFirst
-#define BITMAP_BIT_ORDER	LSBFirst
+#error "Too weird to live."
 #endif
 
-#endif                          /* ARC */
-
-#ifdef __xtensa__
-
-#ifdef __XTENSA_EL__
-#define IMAGE_BYTE_ORDER        LSBFirst
-#define BITMAP_BIT_ORDER        LSBFirst
-#endif
-#ifdef __XTENSA_EB__
-#define IMAGE_BYTE_ORDER        MSBFirst
-#define BITMAP_BIT_ORDER        MSBFirst
-#endif
-
-#endif                          /* __xtensa__ */
-
 #ifndef GLYPHPADBYTES
 #define GLYPHPADBYTES           4
 #endif
commit 860cd209679a2e56460977882b3b3826ddcb8710
Author: Adam Jackson <ajax at redhat.com>
Date:   Mon Jul 21 10:06:52 2014 -0400

    dix: Remove a weird case of little-endian s390
    
    I really don't think this was ever correct, but I'm also not sure what
    non-Linux Unix this was meant to enable.  The only one I know of was
    OS/390 / z/OS / OpenEdition, but I think that was big-endian too.
    
    At any rate this is all about to go away, so this is just removing an
    edge case.
    
    Signed-off-by: Adam Jackson <ajax at redhat.com>
    Reviewed-by: Daniel Stone <daniels at collabora.com>
    Signed-off-by: Keith Packard <keithp at keithp.com>

diff --git a/include/servermd.h b/include/servermd.h
index a544ce5..dd1da7d 100644
--- a/include/servermd.h
+++ b/include/servermd.h
@@ -167,8 +167,7 @@ SOFTWARE.
 
 #if	defined(SVR4) && (defined(__i386__) || defined(__i386) ) ||	\
 	defined(__alpha__) || defined(__alpha) || \
-	defined(__i386__) || \
-	defined(__s390x__) || defined(__s390__)
+	defined(__i386__)
 
 #ifndef IMAGE_BYTE_ORDER
 #define IMAGE_BYTE_ORDER	LSBFirst
commit f593d76de76a645e29af5dd457ad1fd5a30736cc
Author: Adam Jackson <ajax at redhat.com>
Date:   Mon Jul 21 10:06:51 2014 -0400

    dix: Remove wacky sparc special casing (v2)
    
    This appears to be defining sparc if ever __sparc or __sparc__ were
    defined, which is almost reasonable, but these days we want to be using
    the __arch__ style.  Why any of this would ever be triggered on m68k is
    truly a mystery for the ages.
    
    v2: Fix commit message, as noted by nix
    
    Signed-off-by: Adam Jackson <ajax at redhat.com>
    Reviewed-by: Daniel Stone <daniels at collabora.com>
    Signed-off-by: Keith Packard <keithp at keithp.com>

diff --git a/include/servermd.h b/include/servermd.h
index 72ce6c0..a544ce5 100644
--- a/include/servermd.h
+++ b/include/servermd.h
@@ -114,16 +114,6 @@ SOFTWARE.
 
 #endif                          /* __m32r__ */
 
-#if (defined(sun) && (defined(__sparc) || defined(sparc))) || \
-    (defined(__uxp__) && (defined(sparc) || defined(mc68000))) || \
-    defined(__sparc__) || defined(__mc68000__)
-
-#if defined(__sparc) || defined(__sparc__)
-#if !defined(sparc)
-#define sparc 1
-#endif
-#endif
-
 #if defined(sun386) || defined(sun5)
 #define IMAGE_BYTE_ORDER	LSBFirst        /* Values for the SUN only */
 #define BITMAP_BIT_ORDER	LSBFirst
@@ -131,7 +121,6 @@ SOFTWARE.
 #define IMAGE_BYTE_ORDER	MSBFirst        /* Values for the SUN only */
 #define BITMAP_BIT_ORDER	MSBFirst
 #endif
-#endif                          /* sun && !(i386 && SVR4) */
 
 #if (defined(mips) || defined(__mips))
 
commit 17c3347f14822b9f7da4253c71f6ed51be2b38d1
Author: Adam Jackson <ajax at redhat.com>
Date:   Mon Jul 21 10:06:50 2014 -0400

    dix: Default GLYPHPADBYTES to 4
    
    This effectively no longer varied across architectures anyway.
    
    Signed-off-by: Adam Jackson <ajax at redhat.com>
    Reviewed-by: Daniel Stone <daniels at collabora.com>
    Signed-off-by: Keith Packard <keithp at keithp.com>

diff --git a/include/servermd.h b/include/servermd.h
index 83eaad5..72ce6c0 100644
--- a/include/servermd.h
+++ b/include/servermd.h
@@ -52,26 +52,10 @@ SOFTWARE.
  * really be simplified even further.
  */
 
-/*
- * Machine dependent values:
- * GLYPHPADBYTES should be chosen with consideration for the space-time
- * trade-off.  Padding to 0 bytes means that there is no wasted space
- * in the font bitmaps (both on disk and in memory), but that access of
- * the bitmaps will cause odd-address memory references.  Padding to
- * 2 bytes would ensure even address memory references and would
- * be suitable for a 68010-class machine, but at the expense of wasted
- * space in the font bitmaps.  Padding to 4 bytes would be good
- * for real 32 bit machines, etc.  Be sure that you tell the font
- * compiler what kind of padding you want because its defines are
- * kept separate from this.  See server/include/font.h for how
- * GLYPHPADBYTES is used.
- */
-
 #ifdef __avr32__
 
 #define IMAGE_BYTE_ORDER        MSBFirst
 #define BITMAP_BIT_ORDER        MSBFirst
-#define GLYPHPADBYTES           4
 
 #endif                          /* __avr32__ */
 
@@ -79,7 +63,6 @@ SOFTWARE.
 
 #define IMAGE_BYTE_ORDER        LSBFirst
 #define BITMAP_BIT_ORDER        LSBFirst
-#define GLYPHPADBYTES           4
 
 #endif                          /* __arm32__ */
 
@@ -87,16 +70,12 @@ SOFTWARE.
 
 #define IMAGE_BYTE_ORDER	LSBFirst
 
-#define GLYPHPADBYTES		4
-
 #endif                          /* __nds32__ */
 
 #if defined __hppa__
 
 #define IMAGE_BYTE_ORDER	MSBFirst
 #define BITMAP_BIT_ORDER	MSBFirst
-#define GLYPHPADBYTES		4       /* to make fb work */
-                                        /* byte boundries */
 #endif                          /* hpux || __hppa__ */
 
 #if defined(__powerpc__) || defined(__ppc__) || defined(__ppc64__)
@@ -108,7 +87,6 @@ SOFTWARE.
 #define IMAGE_BYTE_ORDER      MSBFirst
 #define BITMAP_BIT_ORDER      MSBFirst
 #endif
-#define GLYPHPADBYTES           4
 
 #endif                          /* PowerPC */
 
@@ -117,11 +95,9 @@ SOFTWARE.
 #if defined(__BIG_ENDIAN__)
 #define IMAGE_BYTE_ORDER	MSBFirst
 #define BITMAP_BIT_ORDER	MSBFirst
-#define GLYPHPADBYTES		4
 #else
 #define IMAGE_BYTE_ORDER	LSBFirst
 #define BITMAP_BIT_ORDER	LSBFirst
-#define GLYPHPADBYTES		4
 #endif
 
 #endif                          /* SuperH */
@@ -131,11 +107,9 @@ SOFTWARE.
 #if defined(__BIG_ENDIAN__)
 #define IMAGE_BYTE_ORDER      MSBFirst
 #define BITMAP_BIT_ORDER      MSBFirst
-#define GLYPHPADBYTES         4
 #else
 #define IMAGE_BYTE_ORDER      LSBFirst
 #define BITMAP_BIT_ORDER      LSBFirst
-#define GLYPHPADBYTES         4
 #endif
 
 #endif                          /* __m32r__ */
@@ -157,9 +131,6 @@ SOFTWARE.
 #define IMAGE_BYTE_ORDER	MSBFirst        /* Values for the SUN only */
 #define BITMAP_BIT_ORDER	MSBFirst
 #endif
-
-#define	GLYPHPADBYTES		4
-
 #endif                          /* sun && !(i386 && SVR4) */
 
 #if (defined(mips) || defined(__mips))
@@ -167,11 +138,9 @@ SOFTWARE.
 #if defined(MIPSEL) || defined(__MIPSEL__)
 #define IMAGE_BYTE_ORDER	LSBFirst        /* Values for the PMAX only */
 #define BITMAP_BIT_ORDER	LSBFirst
-#define GLYPHPADBYTES		4
 #else
 #define IMAGE_BYTE_ORDER	MSBFirst        /* Values for the MIPS only */
 #define BITMAP_BIT_ORDER	MSBFirst
-#define GLYPHPADBYTES		4
 #endif
 
 #endif                          /* mips */
@@ -179,15 +148,12 @@ SOFTWARE.
 #if defined(__alpha) || defined(__alpha__)
 #define IMAGE_BYTE_ORDER	LSBFirst        /* Values for the Alpha only */
 #define BITMAP_BIT_ORDER       LSBFirst
-#define GLYPHPADBYTES		4
-
 #endif                          /* alpha */
 
 #if defined (linux) && defined (__s390__)
 
 #define IMAGE_BYTE_ORDER      	MSBFirst
 #define BITMAP_BIT_ORDER      	MSBFirst
-#define GLYPHPADBYTES         	4
 
 #endif                          /* linux/s390 */
 
@@ -195,7 +161,6 @@ SOFTWARE.
 
 #define IMAGE_BYTE_ORDER       MSBFirst
 #define BITMAP_BIT_ORDER       MSBFirst
-#define GLYPHPADBYTES          4
 
 #endif                          /* linux/s390x */
 
@@ -203,15 +168,12 @@ SOFTWARE.
 
 #define IMAGE_BYTE_ORDER	LSBFirst
 #define BITMAP_BIT_ORDER       LSBFirst
-#define GLYPHPADBYTES		4
 
 #endif                          /* ia64 */
 
 #if defined(__amd64__) || defined(amd64) || defined(__amd64)
 #define IMAGE_BYTE_ORDER	LSBFirst
 #define BITMAP_BIT_ORDER       LSBFirst
-#define GLYPHPADBYTES		4
-/* ???? */
 #endif                          /* AMD64 */
 
 #if	defined(SVR4) && (defined(__i386__) || defined(__i386) ) ||	\
@@ -227,17 +189,12 @@ SOFTWARE.
 #define BITMAP_BIT_ORDER      LSBFirst
 #endif
 
-#ifndef GLYPHPADBYTES
-#define GLYPHPADBYTES           4
-#endif
-
 #endif                          /* SVR4 / BSD / i386 */
 
 #if defined (linux) && defined (__mc68000__)
 
 #define IMAGE_BYTE_ORDER       MSBFirst
 #define BITMAP_BIT_ORDER       MSBFirst
-#define GLYPHPADBYTES          4
 
 #endif                          /* linux/m68k */
 
@@ -245,14 +202,12 @@ SOFTWARE.
 #if defined(linux) && defined(__arm__)
 #define IMAGE_BYTE_ORDER	LSBFirst
 #define BITMAP_BIT_ORDER	LSBFirst
-#define GLYPHPADBYTES		4
 #endif
 
 /* linux on IBM S/390 */
 #if defined (linux) && defined (__s390__)
 #define IMAGE_BYTE_ORDER	MSBFirst
 #define BITMAP_BIT_ORDER	MSBFirst
-#define GLYPHPADBYTES		4
 #endif                          /* linux/s390 */
 
 #ifdef __aarch64__
@@ -265,7 +220,6 @@ SOFTWARE.
 #define IMAGE_BYTE_ORDER        MSBFirst
 #define BITMAP_BIT_ORDER        MSBFirst
 #endif
-#define GLYPHPADBYTES           4
 
 #endif                          /* __aarch64__ */
 
@@ -278,7 +232,6 @@ SOFTWARE.
 #define IMAGE_BYTE_ORDER	LSBFirst
 #define BITMAP_BIT_ORDER	LSBFirst
 #endif
-#define GLYPHPADBYTES		4
 
 #endif                          /* ARC */
 
@@ -292,10 +245,13 @@ SOFTWARE.
 #define IMAGE_BYTE_ORDER        MSBFirst
 #define BITMAP_BIT_ORDER        MSBFirst
 #endif
-#define GLYPHPADBYTES           4
 
 #endif                          /* __xtensa__ */
 
+#ifndef GLYPHPADBYTES
+#define GLYPHPADBYTES           4
+#endif
+
 /* size of buffer to use with GetImage, measured in bytes. There's obviously
  * a trade-off between the amount of heap used and the number of times the
  * ddx routine has to be called.
commit 094b76735cb99b9f26e21f32170614454c644653
Author: Adam Jackson <ajax at redhat.com>
Date:   Mon Jul 21 10:06:49 2014 -0400

    dix: Remove some cfb leftovers
    
    These macros meant something in cfb, but not in fb.
    
    Signed-off-by: Adam Jackson <ajax at redhat.com>
    Reviewed-by: Daniel Stone <daniels at collabora.com>
    Signed-off-by: Keith Packard <keithp at keithp.com>

diff --git a/include/servermd.h b/include/servermd.h
index b599847..83eaad5 100644
--- a/include/servermd.h
+++ b/include/servermd.h
@@ -88,9 +88,6 @@ SOFTWARE.
 #define IMAGE_BYTE_ORDER	LSBFirst
 
 #define GLYPHPADBYTES		4
-#define GETLEFTBITS_ALIGNMENT	1
-#define LARGE_INSTRUCTION_CACHE
-#define AVOID_MEMORY_READ
 
 #endif                          /* __nds32__ */
 
@@ -192,8 +189,6 @@ SOFTWARE.
 #define BITMAP_BIT_ORDER      	MSBFirst
 #define GLYPHPADBYTES         	4
 
-#define FAST_UNALIGNED_READ
-
 #endif                          /* linux/s390 */
 
 #if defined (linux) && defined (__s390x__)
@@ -202,8 +197,6 @@ SOFTWARE.
 #define BITMAP_BIT_ORDER       MSBFirst
 #define GLYPHPADBYTES          4
 
-#define FAST_UNALIGNED_READ
-
 #endif                          /* linux/s390x */
 
 #if defined(__ia64__) || defined(ia64)
commit fee9a1536651ace9324b956df809ef22a63938f8
Author: Adam Jackson <ajax at redhat.com>
Date:   Mon Jul 21 10:06:48 2014 -0400

    dix: Remove some dead macros
    
    Signed-off-by: Adam Jackson <ajax at redhat.com>
    Reviewed-by: Daniel Stone <daniels at collabora.com>
    Signed-off-by: Keith Packard <keithp at keithp.com>

diff --git a/include/servermd.h b/include/servermd.h
index 16e39a2..b599847 100644
--- a/include/servermd.h
+++ b/include/servermd.h
@@ -361,8 +361,4 @@ extern _X_EXPORT PaddingInfo PixmapWidthPaddingInfo[];
 #define BitmapBytePad(w) \
     (((int)((w) + BITMAP_SCANLINE_PAD - 1) >> LOG2_BITMAP_PAD) << LOG2_BYTES_PER_SCANLINE_PAD)
 
-#define PixmapWidthInPadUnitsProto(w, d) PixmapWidthInPadUnits(w, d)
-#define PixmapBytePadProto(w, d) PixmapBytePad(w, d)
-#define BitmapBytePadProto(w) BitmapBytePad(w)
-
 #endif                          /* SERVERMD_H */
commit 634aa310c5130ef4d38f339bb26b01b5a7bad4e9
Author: Adam Jackson <ajax at redhat.com>
Date:   Mon Jul 21 10:06:47 2014 -0400

    dix: (Don't) change BITMAP_SCANLINE_UNIT on Linux s390{, x}
    
    Every other architecture sets this to 32, and I can't think of any
    benefit s390 would derive from changing it.  It is, at any rate,
    something the client already copes with, and the only internal code
    impact seems to be some complicated math in miGetPlane, which you never
    hit if you're using fb.
    
    Signed-off-by: Adam Jackson <ajax at redhat.com>
    Reviewed-by: Daniel Stone <daniels at collabora.com>
    Signed-off-by: Keith Packard <keithp at keithp.com>

diff --git a/include/servermd.h b/include/servermd.h
index 6e71db4..16e39a2 100644
--- a/include/servermd.h
+++ b/include/servermd.h
@@ -192,7 +192,6 @@ SOFTWARE.
 #define BITMAP_BIT_ORDER      	MSBFirst
 #define GLYPHPADBYTES         	4
 
-#define BITMAP_SCANLINE_UNIT	8
 #define FAST_UNALIGNED_READ
 
 #endif                          /* linux/s390 */
@@ -203,7 +202,6 @@ SOFTWARE.
 #define BITMAP_BIT_ORDER       MSBFirst
 #define GLYPHPADBYTES          4
 
-#define BITMAP_SCANLINE_UNIT	8
 #define FAST_UNALIGNED_READ
 
 #endif                          /* linux/s390x */
commit f6469f1910c72add358b7263d69bd116b4450ece
Author: Adam Jackson <ajax at redhat.com>
Date:   Mon Jul 21 10:06:46 2014 -0400

    dix: Remove some XFree86 3.x leftovers
    
    Signed-off-by: Adam Jackson <ajax at redhat.com>
    Reviewed-by: Daniel Stone <daniels at collabora.com>
    Signed-off-by: Keith Packard <keithp at keithp.com>

diff --git a/include/servermd.h b/include/servermd.h
index 77cc418..6e71db4 100644
--- a/include/servermd.h
+++ b/include/servermd.h
@@ -87,16 +87,6 @@ SOFTWARE.
 
 #define IMAGE_BYTE_ORDER	LSBFirst
 
-#if defined(XF86MONOVGA) || defined(XF86VGA16) || defined(XF86MONO)
-#define BITMAP_BIT_ORDER	MSBFirst
-#else
-#define BITMAP_BIT_ORDER	LSBFirst
-#endif
-
-#if defined(XF86MONOVGA) || defined(XF86VGA16)
-#define BITMAP_SCANLINE_UNIT	8
-#endif
-
 #define GLYPHPADBYTES		4
 #define GETLEFTBITS_ALIGNMENT	1
 #define LARGE_INSTRUCTION_CACHE
commit 5aaacb501ff26bad391664cc7367bfe5164f72c7
Author: Adam Jackson <ajax at redhat.com>
Date:   Mon Jul 21 10:06:45 2014 -0400

    dix: Remove an ancient IBM configuration
    
    Whatever unix this was meant to be is either no longer in circulation,
    or is AIX, which we don't claim to support anyway.
    
    Signed-off-by: Adam Jackson <ajax at redhat.com>
    Reviewed-by: Daniel Stone <daniels at collabora.com>
    Signed-off-by: Keith Packard <keithp at keithp.com>

diff --git a/include/servermd.h b/include/servermd.h
index e413314..77cc418 100644
--- a/include/servermd.h
+++ b/include/servermd.h
@@ -175,23 +175,6 @@ SOFTWARE.
 
 #endif                          /* sun && !(i386 && SVR4) */
 
-#if defined(ibm032) || defined (ibm)
-
-#ifdef __i386__
-#define IMAGE_BYTE_ORDER	LSBFirst        /* Value for PS/2 only */
-#else
-#define IMAGE_BYTE_ORDER	MSBFirst        /* Values for the RT only */
-#endif
-#define BITMAP_BIT_ORDER	MSBFirst
-#define	GLYPHPADBYTES		1
-/* ibm pcc doesn't understand pragmas. */
-
-#ifdef __i386__
-#define BITMAP_SCANLINE_UNIT	8
-#endif
-
-#endif                          /* ibm */
-
 #if (defined(mips) || defined(__mips))
 
 #if defined(MIPSEL) || defined(__MIPSEL__)
commit 06268a0c55b7ce2737bdaa39f11cce07efa8bfa3
Author: Aaron Plattner <aplattner at nvidia.com>
Date:   Sat Jul 19 09:59:07 2014 -0700

    xfree86: Remove stale /usr/share/X11/xorg.conf.d hard-code from the xorg.conf man page
    
    I forgot that the old behavior of searching in /usr/share/X11/xorg.conf.d was
    documented in the man page.
    
    Signed-off-by: Aaron Plattner <aplattner at nvidia.com>
    Fixes: acc0b5edd1dc ("xfree86: Only support one sysconfigdir")
    Reviewed-by: Peter Hutterer <peter.hutterer at who-t.net>
    Signed-off-by: Keith Packard <keithp at keithp.com>

diff --git a/hw/xfree86/man/xorg.conf.man b/hw/xfree86/man/xorg.conf.man
index bc33df1..1631212 100644
--- a/hw/xfree86/man/xorg.conf.man
+++ b/hw/xfree86/man/xorg.conf.man
@@ -132,14 +132,14 @@ is the path specified with the
 .B \-configdir
 command line option (which may be absolute or relative).
 .PP
-Finally, configuration files will also be searched for in directories
-reserved for system use. These are to separate configuration files from
-the vendor or 3rd party packages from those of local administration.
-These files are found in the following directories:
+Finally, configuration files will also be searched for in a directory reserved
+for system use.
+This is to separate configuration files from the vendor or 3rd party packages
+from those of local administration.
+These files are found in the following directory:
 .PP
 .RS 4
 .nf
-.I /usr/share/X11/__xconfigdir__
 .I __datadir__/X11/__xconfigdir__
 .fi
 .RE
commit 5f3485b06e180674af640e7e9d7d56f67b61735b
Author: Maarten Lankhorst <maarten.lankhorst at canonical.com>
Date:   Thu Jun 26 10:37:19 2014 +0200

    bump to 0.9.0
commit 042bae0b49f6192ec3cb8bb51423c90c44638134
Author: Adam Jackson <ajax at redhat.com>
Date:   Wed May 21 10:16:39 2014 -0400

    Use own thunk function instead of shadowUpdatePackedWeak
    
    I plan to remove the Weak functions from a future server.
    
    Signed-off-by: Adam Jackson <ajax at redhat.com>

diff --git a/hw/xfree86/drivers/modesetting/driver.c b/hw/xfree86/drivers/modesetting/driver.c
index 21274a9..d99b027 100644
--- a/hw/xfree86/drivers/modesetting/driver.c
+++ b/hw/xfree86/drivers/modesetting/driver.c
@@ -810,6 +810,12 @@ msShadowWindow(ScreenPtr screen, CARD32 row, CARD32 offset, int mode,
     return ((uint8_t *)ms->drmmode.front_bo->ptr + row * stride + offset);
 }
 
+static void
+msUpdatePacked(ScreenPtr pScreen, shadowBufPtr pBuf)
+{
+    shadowUpdatePacked(pScreen, pBuf);
+}
+
 static Bool
 CreateScreenResources(ScreenPtr pScreen)
 {
@@ -842,7 +848,7 @@ CreateScreenResources(ScreenPtr pScreen)
 	FatalError("Couldn't adjust screen pixmap\n");
 
     if (ms->drmmode.shadow_enable) {
-	if (!shadowAdd(pScreen, rootPixmap, shadowUpdatePackedWeak(),
+	if (!shadowAdd(pScreen, rootPixmap, msUpdatePacked,
 		       msShadowWindow, 0, 0))
 	    return FALSE;
     }
commit 219ce9e6c34bfc946005fb8e81ab4fb74ae1d25a
Author: Dave Airlie <airlied at redhat.com>
Date:   Fri May 2 13:16:05 2014 +1000

    modesetting: fix build regression against older servers.
    
    Signed-off-by: Dave Airlie <airlied at redhat.com>

diff --git a/hw/xfree86/drivers/modesetting/driver.c b/hw/xfree86/drivers/modesetting/driver.c
index b5fcdaf..21274a9 100644
--- a/hw/xfree86/drivers/modesetting/driver.c
+++ b/hw/xfree86/drivers/modesetting/driver.c
@@ -217,7 +217,7 @@ static Bool probe_hw(const char *dev, struct xf86_platform_device *platform_dev)
 {
     int fd;
 
-#if XSERVER_PLATFORM_BUS
+#if XF86_PDEV_SERVER_FD
     if (platform_dev && (platform_dev->flags & XF86_PDEV_SERVER_FD)) {
         fd = xf86_get_platform_device_int_attrib(platform_dev, ODEV_ATTRIB_FD, -1);
         if (fd == -1)
commit 795af9ff017113788b4bb6d9dbeb5370c5b8165c
Author: Dave Airlie <airlied at redhat.com>
Date:   Fri May 2 13:14:30 2014 +1000

    modesetting: fix use after free.
    
    Signed-off-by: Dave Airlie <airlied at redhat.com>

diff --git a/hw/xfree86/drivers/modesetting/drmmode_display.c b/hw/xfree86/drivers/modesetting/drmmode_display.c
index 28a4abb..c533324 100644
--- a/hw/xfree86/drivers/modesetting/drmmode_display.c
+++ b/hw/xfree86/drivers/modesetting/drmmode_display.c
@@ -778,11 +778,11 @@ drmmode_output_destroy(xf86OutputPtr output)
 		drmModeFreeProperty(drmmode_output->props[i].mode_prop);
 		free(drmmode_output->props[i].atoms);
 	}
+	free(drmmode_output->props);
 	for (i = 0; i < drmmode_output->mode_output->count_encoders; i++) {
 		drmModeFreeEncoder(drmmode_output->mode_encoders[i]);
-		free(drmmode_output->mode_encoders);
 	}
-	free(drmmode_output->props);
+	free(drmmode_output->mode_encoders);
 	drmModeFreeConnector(drmmode_output->mode_output);
 	free(drmmode_output);
 	output->driver_private = NULL;
commit f073b5e58262d5fcc0102d773091d11d175227ce
Author: Hans de Goede <hdegoede at redhat.com>
Date:   Tue Mar 18 15:48:22 2014 +0100

    Add support for server managed fds
    
    Signed-off-by: Hans de Goede <hdegoede at redhat.com>

diff --git a/hw/xfree86/drivers/modesetting/driver.c b/hw/xfree86/drivers/modesetting/driver.c
index 0f9190a..b5fcdaf 100644
--- a/hw/xfree86/drivers/modesetting/driver.c
+++ b/hw/xfree86/drivers/modesetting/driver.c
@@ -213,9 +213,20 @@ static int check_outputs(int fd)
     return ret;
 }
 
-static Bool probe_hw(const char *dev)
+static Bool probe_hw(const char *dev, struct xf86_platform_device *platform_dev)
 {
-    int fd = open_hw(dev);
+    int fd;
+
+#if XSERVER_PLATFORM_BUS
+    if (platform_dev && (platform_dev->flags & XF86_PDEV_SERVER_FD)) {
+        fd = xf86_get_platform_device_int_attrib(platform_dev, ODEV_ATTRIB_FD, -1);
+        if (fd == -1)
+            return FALSE;
+        return check_outputs(fd);
+    }
+#endif
+
+    fd = open_hw(dev);
     if (fd != -1) {
         int ret = check_outputs(fd);
         close(fd);
@@ -283,6 +294,10 @@ ms_driver_func(ScrnInfoPtr scrn, xorgDriverFuncOp op, void *data)
 	    flag = (CARD32 *)data;
 	    (*flag) = 0;
 	    return TRUE;
+#if XORG_VERSION_CURRENT >= XORG_VERSION_NUMERIC(1,15,99,902,0)
+        case SUPPORTS_SERVER_FDS:
+            return TRUE;
+#endif
 	default:
 	    return FALSE;
     }
@@ -341,7 +356,7 @@ ms_platform_probe(DriverPtr driver,
     if (flags & PLATFORM_PROBE_GPU_SCREEN)
             scr_flags = XF86_ALLOCATE_GPU_SCREEN;
 
-    if (probe_hw(path)) {
+    if (probe_hw(path, dev)) {
         scrn = xf86AllocateScreen(driver, scr_flags);
         xf86AddEntityToScreen(scrn, entity_num);
 
@@ -387,7 +402,7 @@ Probe(DriverPtr drv, int flags)
     for (i = 0; i < numDevSections; i++) {
 
 	dev = xf86FindOptionValue(devSections[i]->options,"kmsdev");
-	if (probe_hw(dev)) {
+	if (probe_hw(dev, NULL)) {
 	    int entity;
 	    entity = xf86ClaimFbSlot(drv, 0, devSections[i], TRUE);
 	    scrn = xf86ConfigFbEntity(scrn, 0, entity,
@@ -558,6 +573,10 @@ FreeRec(ScrnInfoPtr pScrn)
         if (ms->pEnt->location.type == BUS_PCI)
             ret = drmClose(ms->fd);
         else
+#ifdef XF86_PDEV_SERVER_FD
+        if (!(ms->pEnt->location.type == BUS_PLATFORM &&
+              (ms->pEnt->location.id.plat->flags & XF86_PDEV_SERVER_FD)))
+#endif
             ret = close(ms->fd);
         (void) ret;
     }
@@ -630,8 +649,15 @@ PreInit(ScrnInfoPtr pScrn, int flags)
 
 #if XSERVER_PLATFORM_BUS
     if (pEnt->location.type == BUS_PLATFORM) {
-        char *path = xf86_get_platform_device_attrib(pEnt->location.id.plat, ODEV_ATTRIB_PATH);
-        ms->fd = open_hw(path);
+#ifdef XF86_PDEV_SERVER_FD
+        if (pEnt->location.id.plat->flags & XF86_PDEV_SERVER_FD)
+            ms->fd = xf86_get_platform_device_int_attrib(pEnt->location.id.plat, ODEV_ATTRIB_FD, -1);
+        else
+#endif
+        {
+            char *path = xf86_get_platform_device_attrib(pEnt->location.id.plat, ODEV_ATTRIB_PATH);
+            ms->fd = open_hw(path);
+        }
     }
     else 
 #endif
@@ -865,21 +891,37 @@ msSetSharedPixmapBacking(PixmapPtr ppix, void *fd_handle)
 #endif
 
 static Bool
+SetMaster(ScrnInfoPtr pScrn)
+{
+    modesettingPtr ms = modesettingPTR(pScrn);
+    int ret;
+
+#ifdef XF86_PDEV_SERVER_FD
+    if (ms->pEnt->location.type == BUS_PLATFORM &&
+            (ms->pEnt->location.id.plat->flags & XF86_PDEV_SERVER_FD))
+        return TRUE;
+#endif
+
+    ret = drmSetMaster(ms->fd);
+    if (ret)
+        xf86DrvMsg(pScrn->scrnIndex, X_ERROR, "drmSetMaster failed: %s\n",
+                   strerror(errno));
+
+    return ret == 0;
+}
+
+static Bool
 ScreenInit(SCREEN_INIT_ARGS_DECL)
 {
     ScrnInfoPtr pScrn = xf86ScreenToScrn(pScreen);
     modesettingPtr ms = modesettingPTR(pScrn);
     VisualPtr visual;
-    int ret;
 
     pScrn->pScreen = pScreen;
 
-    ret = drmSetMaster(ms->fd);
-    if (ret) {
-        ErrorF("Unable to set master\n");
+    if (!SetMaster(pScrn))
         return FALSE;
-    }
-      
+
     /* HW dependent - FIXME */
     pScrn->displayWidth = pScrn->virtualX;
     if (!drmmode_create_initial_bos(pScrn, &ms->drmmode))
@@ -1010,6 +1052,12 @@ LeaveVT(VT_FUNC_ARGS_DECL)
 
     pScrn->vtSema = FALSE;
 
+#ifdef XF86_PDEV_SERVER_FD
+    if (ms->pEnt->location.type == BUS_PLATFORM &&
+            (ms->pEnt->location.id.plat->flags & XF86_PDEV_SERVER_FD))
+        return;
+#endif
+
     drmDropMaster(ms->fd);
 }
 
@@ -1024,10 +1072,7 @@ EnterVT(VT_FUNC_ARGS_DECL)
 
     pScrn->vtSema = TRUE;
 
-    if (drmSetMaster(ms->fd)) {
-        xf86DrvMsg(pScrn->scrnIndex, X_WARNING, "drmSetMaster failed: %s\n",
-                   strerror(errno));
-    }
+    SetMaster(pScrn);
 
     if (!drmmode_set_desired_modes(pScrn, &ms->drmmode))
 	return FALSE;
commit 98f59a33dfc2d47a57c68420f226dc0c17992164
Author: Dave Airlie <airlied at redhat.com>
Date:   Fri Feb 28 12:04:30 2014 +1000

    modesetting: fix cursor rendering with hotspots.
    
    older kernels report EINVAL not ENOSYS, doh.
    
    Signed-off-by: Dave Airlie <airlied at redhat.com>

diff --git a/hw/xfree86/drivers/modesetting/drmmode_display.c b/hw/xfree86/drivers/modesetting/drmmode_display.c
index 5b796e0..28a4abb 100644
--- a/hw/xfree86/drivers/modesetting/drmmode_display.c
+++ b/hw/xfree86/drivers/modesetting/drmmode_display.c
@@ -500,7 +500,7 @@ drmmode_show_cursor (xf86CrtcPtr crtc)
                CursorPtr cursor = xf86_config->cursor;
                int ret;
                ret = drmModeSetCursor2(drmmode->fd, drmmode_crtc->mode_crtc->crtc_id, handle, ms->cursor_width, ms->cursor_height, cursor->bits->xhot, cursor->bits->yhot);
-               if (ret == -ENOSYS)
+               if (ret == -EINVAL)
                        use_set_cursor2 = FALSE;
                else
                        return;
commit 2029c028fcffbe1aa175ab75636ae954a211c82a
Author: Adam Jackson <ajax at redhat.com>
Date:   Tue Feb 25 09:06:55 2014 -0500

    modesetting: Don't (brokenly) double-track software cursor
    
    Signed-off-by: Adam Jackson <ajax at redhat.com>

diff --git a/hw/xfree86/drivers/modesetting/driver.c b/hw/xfree86/drivers/modesetting/driver.c
index 4a74ece..0f9190a 100644
--- a/hw/xfree86/drivers/modesetting/driver.c
+++ b/hw/xfree86/drivers/modesetting/driver.c
@@ -801,7 +801,7 @@ CreateScreenResources(ScreenPtr pScreen)
 
     drmmode_uevent_init(pScrn, &ms->drmmode);
 
-    if (!ms->SWCursor)
+    if (!ms->drmmode.sw_cursor)
         drmmode_map_cursor_bos(pScrn, &ms->drmmode);
     pixels = drmmode_map_front_bo(&ms->drmmode);
     if (!pixels)
diff --git a/hw/xfree86/drivers/modesetting/driver.h b/hw/xfree86/drivers/modesetting/driver.h
index e84d748..450b29c 100644
--- a/hw/xfree86/drivers/modesetting/driver.h
+++ b/hw/xfree86/drivers/modesetting/driver.h
@@ -59,7 +59,6 @@ typedef struct _modesettingRec
 #endif
 
     Bool noAccel;
-    Bool SWCursor;
     CloseScreenProcPtr CloseScreen;
 
     /* Broken-out options. */
commit fac2bcf1da09fba8bc8b22631e31f3c5b2737efd
Author: Dave Airlie <airlied at redhat.com>
Date:   Mon Jan 20 11:06:42 2014 +1000

    modesetting: try and use hotspot cursor support
    
    Signed-off-by: Dave Airlie <airlied at redhat.com>

diff --git a/hw/xfree86/drivers/modesetting/drmmode_display.c b/hw/xfree86/drivers/modesetting/drmmode_display.c
index ccfd75f..5b796e0 100644
--- a/hw/xfree86/drivers/modesetting/drmmode_display.c
+++ b/hw/xfree86/drivers/modesetting/drmmode_display.c
@@ -43,6 +43,8 @@
 #include "xf86Crtc.h"
 #include "drmmode_display.h"
 
+#include <cursorstr.h>
+
 /* DPMS */
 #ifdef HAVE_XEXTPROTO_71
 #include <X11/extensions/dpmsconst.h>
@@ -491,6 +493,18 @@ drmmode_show_cursor (xf86CrtcPtr crtc)
 	drmmode_crtc_private_ptr drmmode_crtc = crtc->driver_private;
 	drmmode_ptr drmmode = drmmode_crtc->drmmode;
 	uint32_t handle = drmmode_crtc->cursor_bo->handle;
+       static Bool use_set_cursor2 = TRUE;
+
+       if (use_set_cursor2) {
+               xf86CrtcConfigPtr   xf86_config = XF86_CRTC_CONFIG_PTR(crtc->scrn);
+               CursorPtr cursor = xf86_config->cursor;
+               int ret;
+               ret = drmModeSetCursor2(drmmode->fd, drmmode_crtc->mode_crtc->crtc_id, handle, ms->cursor_width, ms->cursor_height, cursor->bits->xhot, cursor->bits->yhot);
+               if (ret == -ENOSYS)
+                       use_set_cursor2 = FALSE;
+               else
+                       return;
+       }
 
 	drmModeSetCursor(drmmode->fd, drmmode_crtc->mode_crtc->crtc_id, handle,
 			 ms->cursor_width, ms->cursor_height);
commit 4aab7aa7c1a15af7211996fa30e17a645f120ff9
Author: Dave Airlie <airlied at redhat.com>
Date:   Fri Feb 21 12:48:42 2014 +1000

    modesetting: move closing fd to after we check outputs
    
    On something like cirrus, start X, then attempt to start a second
    X while the first is running, if fbdev is installed it'll fail
    hard.
    
    Signed-off-by: Dave Airlie <airlied at redhat.com>

diff --git a/hw/xfree86/drivers/modesetting/driver.c b/hw/xfree86/drivers/modesetting/driver.c
index b28622a..4a74ece 100644
--- a/hw/xfree86/drivers/modesetting/driver.c
+++ b/hw/xfree86/drivers/modesetting/driver.c
@@ -258,11 +258,11 @@ static Bool probe_hw_pci(const char *dev, struct pci_device *pdev)
 
     id = drmGetBusid(fd);
     devid = ms_DRICreatePCIBusID(pdev);
-    close(fd);
 
     if (id && devid && !strcmp(id, devid))
         ret = check_outputs(fd);
 
+    close(fd);
     free(id);
     free(devid);
     return ret;
commit 02fbae85e7aa17b213e1411fe558256998d367c4
Author: Alex Deucher <alexander.deucher at amd.com>
Date:   Wed Feb 12 13:06:51 2014 -0500

    modesetting: query cursor size from the kernel
    
    Use new drm caps.  This allows hw cursors to work
    correctly on gpus with non-64x64 cursors.
    
    Signed-off-by: Alex Deucher <alexander.deucher at amd.com>

diff --git a/hw/xfree86/drivers/modesetting/driver.c b/hw/xfree86/drivers/modesetting/driver.c
index b84624e..b28622a 100644
--- a/hw/xfree86/drivers/modesetting/driver.c
+++ b/hw/xfree86/drivers/modesetting/driver.c
@@ -566,6 +566,14 @@ FreeRec(ScrnInfoPtr pScrn)
 
 }
 
+#ifndef DRM_CAP_CURSOR_WIDTH
+#define DRM_CAP_CURSOR_WIDTH 0x8
+#endif
+
+#ifndef DRM_CAP_CURSOR_HEIGHT
+#define DRM_CAP_CURSOR_HEIGHT 0x9
+#endif
+
 static Bool
 PreInit(ScrnInfoPtr pScrn, int flags)
 {
@@ -706,6 +714,17 @@ PreInit(ScrnInfoPtr pScrn, int flags)
 	prefer_shadow = !!value;
     }
 
+    ms->cursor_width = 64;
+    ms->cursor_height = 64;
+    ret = drmGetCap(ms->fd, DRM_CAP_CURSOR_WIDTH, &value);
+    if (!ret) {
+	ms->cursor_width = value;
+    }
+    ret = drmGetCap(ms->fd, DRM_CAP_CURSOR_HEIGHT, &value);
+    if (!ret) {
+	ms->cursor_height = value;
+    }
+
     ms->drmmode.shadow_enable = xf86ReturnOptValBool(ms->Options, OPTION_SHADOW_FB, prefer_shadow);
 
     xf86DrvMsg(pScrn->scrnIndex, X_INFO, "ShadowFB: preferred %s, enabled %s\n", prefer_shadow ? "YES" : "NO", ms->drmmode.shadow_enable ? "YES" : "NO");
@@ -933,7 +952,7 @@ ScreenInit(SCREEN_INIT_ARGS_DECL)
 
     /* Need to extend HWcursor support to handle mask interleave */
     if (!ms->drmmode.sw_cursor)
-	xf86_cursors_init(pScreen, 64, 64,
+	xf86_cursors_init(pScreen, ms->cursor_width, ms->cursor_height,
 			  HARDWARE_CURSOR_SOURCE_MASK_INTERLEAVE_64 |
 			  HARDWARE_CURSOR_ARGB);
 
diff --git a/hw/xfree86/drivers/modesetting/driver.h b/hw/xfree86/drivers/modesetting/driver.h
index 79561c8..e84d748 100644
--- a/hw/xfree86/drivers/modesetting/driver.h
+++ b/hw/xfree86/drivers/modesetting/driver.h
@@ -76,6 +76,7 @@ typedef struct _modesettingRec
     DamagePtr damage;
     Bool dirty_enabled;
 
+    uint32_t cursor_width, cursor_height;
 } modesettingRec, *modesettingPtr;
 
 #define modesettingPTR(p) ((modesettingPtr)((p)->driverPrivate))
diff --git a/hw/xfree86/drivers/modesetting/drmmode_display.c b/hw/xfree86/drivers/modesetting/drmmode_display.c
index 25641ce..ccfd75f 100644
--- a/hw/xfree86/drivers/modesetting/drmmode_display.c
+++ b/hw/xfree86/drivers/modesetting/drmmode_display.c
@@ -52,6 +52,8 @@
 #endif
 #include "compat-api.h"
 
+#include "driver.h"
+
 static struct dumb_bo *dumb_bo_create(int fd,
 			  const unsigned width, const unsigned height,
 			  const unsigned bpp)
@@ -445,6 +447,7 @@ drmmode_set_cursor_position (xf86CrtcPtr crtc, int x, int y)
 static void
 drmmode_load_cursor_argb (xf86CrtcPtr crtc, CARD32 *image)
 {
+	modesettingPtr ms = modesettingPTR(crtc->scrn);
 	drmmode_crtc_private_ptr drmmode_crtc = crtc->driver_private;
 	int i;
 	uint32_t *ptr;
@@ -453,10 +456,11 @@ drmmode_load_cursor_argb (xf86CrtcPtr crtc, CARD32 *image)
 	/* cursor should be mapped already */
 	ptr = (uint32_t *)(drmmode_crtc->cursor_bo->ptr);
 
-	for (i = 0; i < 64 * 64; i++)
+	for (i = 0; i < ms->cursor_width * ms->cursor_height; i++)
 		ptr[i] = image[i];// cpu_to_le32(image[i]);
 
-	ret = drmModeSetCursor(drmmode_crtc->drmmode->fd, drmmode_crtc->mode_crtc->crtc_id, handle, 64, 64);
+	ret = drmModeSetCursor(drmmode_crtc->drmmode->fd, drmmode_crtc->mode_crtc->crtc_id, handle,
+			       ms->cursor_width, ms->cursor_height);
 	if (ret) {
 		xf86CrtcConfigPtr   xf86_config = XF86_CRTC_CONFIG_PTR(crtc->scrn);
 		xf86CursorInfoPtr	cursor_info = xf86_config->cursor_info;
@@ -471,21 +475,25 @@ drmmode_load_cursor_argb (xf86CrtcPtr crtc, CARD32 *image)
 static void
 drmmode_hide_cursor (xf86CrtcPtr crtc)
 {
+	modesettingPtr ms = modesettingPTR(crtc->scrn);
 	drmmode_crtc_private_ptr drmmode_crtc = crtc->driver_private;
 	drmmode_ptr drmmode = drmmode_crtc->drmmode;
 
-	drmModeSetCursor(drmmode->fd, drmmode_crtc->mode_crtc->crtc_id, 0, 64, 64);
+	drmModeSetCursor(drmmode->fd, drmmode_crtc->mode_crtc->crtc_id, 0,
+			 ms->cursor_width, ms->cursor_height);
 
 }
 
 static void
 drmmode_show_cursor (xf86CrtcPtr crtc)
 {
+	modesettingPtr ms = modesettingPTR(crtc->scrn);
 	drmmode_crtc_private_ptr drmmode_crtc = crtc->driver_private;
 	drmmode_ptr drmmode = drmmode_crtc->drmmode;
 	uint32_t handle = drmmode_crtc->cursor_bo->handle;
 
-	drmModeSetCursor(drmmode->fd, drmmode_crtc->mode_crtc->crtc_id, handle, 64, 64);
+	drmModeSetCursor(drmmode->fd, drmmode_crtc->mode_crtc->crtc_id, handle,
+			 ms->cursor_width, ms->cursor_height);
 }
 
 static void
@@ -1485,6 +1493,7 @@ void drmmode_uevent_fini(ScrnInfoPtr scrn, drmmode_ptr drmmode)
 /* create front and cursor BOs */
 Bool drmmode_create_initial_bos(ScrnInfoPtr pScrn, drmmode_ptr drmmode)
 {
+	modesettingPtr ms = modesettingPTR(pScrn);
 	xf86CrtcConfigPtr   xf86_config = XF86_CRTC_CONFIG_PTR(pScrn);
 	int width;
 	int height;
@@ -1500,7 +1509,8 @@ Bool drmmode_create_initial_bos(ScrnInfoPtr pScrn, drmmode_ptr drmmode)
 		return FALSE;
 	pScrn->displayWidth = drmmode->front_bo->pitch / cpp;
 
-	width = height = 64;
+	width = ms->cursor_width;
+	height = ms->cursor_height;
 	bpp = 32;
 	for (i = 0; i < xf86_config->num_crtc; i++) {
 		xf86CrtcPtr crtc = xf86_config->crtc[i];
commit ae24f5bf6b31c035af50e14727966055ed8767bd
Author: Maarten Lankhorst <maarten.lankhorst at canonical.com>
Date:   Tue Dec 3 17:01:28 2013 +0100

    bump to 0.8.1
commit 59e324abd7cbda5d301b7b67125cd6d96684f000
Author: Thierry Reding <thierry.reding at gmail.com>
Date:   Tue Nov 26 17:08:03 2013 +0100

    Properly identify DSI outputs
    
    Newer Linux kernels support DSI outputs. To be able to identify them
    properly, add DSI to the list of output names.
    
    Reviewed-by: Aaron Plattner <aplattner at nvidia.com>
    Signed-off-by: Thierry Reding <treding at nvidia.com>

diff --git a/hw/xfree86/drivers/modesetting/drmmode_display.c b/hw/xfree86/drivers/modesetting/drmmode_display.c
index a343778..25641ce 100644
--- a/hw/xfree86/drivers/modesetting/drmmode_display.c
+++ b/hw/xfree86/drivers/modesetting/drmmode_display.c
@@ -977,6 +977,7 @@ static const char * const output_names[] = { "None",
 					     "TV",
 					     "eDP",
 					     "Virtual",
+					     "DSI",
 };
 
 static void
commit 190289f6393191bb3c58067ce1df994809475077
Author: Thierry Reding <thierry.reding at gmail.com>
Date:   Tue Nov 26 17:08:02 2013 +0100

    Staticise and constify output names
    
    This array isn't used anywhere outside this file, so it can be made
    static. While at it, make the array const as well.
    
    Signed-off-by: Thierry Reding <treding at nvidia.com>
    Reviewed-by: Aaron Plattner <aplattner at nvidia.com>

diff --git a/hw/xfree86/drivers/modesetting/drmmode_display.c b/hw/xfree86/drivers/modesetting/drmmode_display.c
index 773ec4c..a343778 100644
--- a/hw/xfree86/drivers/modesetting/drmmode_display.c
+++ b/hw/xfree86/drivers/modesetting/drmmode_display.c
@@ -961,22 +961,22 @@ static int subpixel_conv_table[7] = { 0, SubPixelUnknown,
 				      SubPixelVerticalBGR,
 				      SubPixelNone };
 
-const char *output_names[] = { "None",
-			       "VGA",
-			       "DVI",
-			       "DVI",
-			       "DVI",
-			       "Composite",
-			       "S-video",
-			       "LVDS",
-			       "CTV",
-			       "DIN",
-			       "DisplayPort",
-			       "HDMI",
-			       "HDMI",
-			       "TV",
-			       "eDP",
-			       "Virtual"
+static const char * const output_names[] = { "None",
+					     "VGA",
+					     "DVI",
+					     "DVI",
+					     "DVI",
+					     "Composite",
+					     "S-video",
+					     "LVDS",
+					     "CTV",
+					     "DIN",
+					     "DisplayPort",
+					     "HDMI",
+					     "HDMI",
+					     "TV",
+					     "eDP",
+					     "Virtual",
 };
 
 static void
commit a307ac27382dd0c377cd1a436cb25cb5aaa54416
Author: Keith Packard <keithp at keithp.com>
Date:   Fri Nov 15 13:39:52 2013 +0900

    Handle new DamageUnregister API which has only one argument
    
    API change in 1.15
    
    Signed-off-by: Keith Packard <keithp at keithp.com>

diff --git a/hw/xfree86/drivers/modesetting/drmmode_display.h b/hw/xfree86/drivers/modesetting/drmmode_display.h
index adf4b99..745c484 100644
--- a/hw/xfree86/drivers/modesetting/drmmode_display.h
+++ b/hw/xfree86/drivers/modesetting/drmmode_display.h
@@ -37,6 +37,10 @@
 #define MODESETTING_OUTPUT_SLAVE_SUPPORT 1
 #endif
 
+#if XORG_VERSION_CURRENT >= XORG_VERSION_NUMERIC(1,14,99,2,0)
+#define DamageUnregister(d, dd) DamageUnregister(dd)
+#endif
+
 struct dumb_bo {
     uint32_t handle;
     uint32_t size;
commit d6ffce4b0e2376e1f8f04ee70b323a6aea3e517e
Author: Keith Packard <keithp at keithp.com>
Date:   Fri Nov 15 13:26:36 2013 +0900

    Clean up compiler warnings.
    
    Add const to any immutable string pointers.
    Rename 'range' to 'prop_range' to avoid redefined warning.
    Eliminate some unused return values.
    
    Signed-off-by: Keith Packard <keithp at keithp.com>

diff --git a/hw/xfree86/drivers/modesetting/driver.c b/hw/xfree86/drivers/modesetting/driver.c
index cc526f6..b84624e 100644
--- a/hw/xfree86/drivers/modesetting/driver.c
+++ b/hw/xfree86/drivers/modesetting/driver.c
@@ -183,7 +183,7 @@ Identify(int flags)
 		      Chipsets);
 }
 
-static int open_hw(char *dev)
+static int open_hw(const char *dev)
 {
     int fd;
     if (dev)
@@ -213,7 +213,7 @@ static int check_outputs(int fd)
     return ret;
 }
 
-static Bool probe_hw(char *dev)
+static Bool probe_hw(const char *dev)
 {
     int fd = open_hw(dev);
     if (fd != -1) {
@@ -237,7 +237,7 @@ ms_DRICreatePCIBusID(const struct pci_device *dev)
 }
 
 
-static Bool probe_hw_pci(char *dev, struct pci_device *pdev)
+static Bool probe_hw_pci(const char *dev, struct pci_device *pdev)
 {
     int ret = FALSE, fd = open_hw(dev);
     char *id, *devid;
@@ -298,7 +298,7 @@ ms_pci_probe(DriverPtr driver,
     scrn = xf86ConfigPciEntity(scrn, 0, entity_num, NULL,
 			       NULL, NULL, NULL, NULL, NULL);
     if (scrn) {
-	char *devpath;
+	const char *devpath;
 	GDevPtr devSection = xf86GetDevFromEntity(scrn->entityList[0],
 						  scrn->entityInstanceList[0]);
 
@@ -335,7 +335,7 @@ ms_platform_probe(DriverPtr driver,
               int entity_num, int flags, struct xf86_platform_device *dev, intptr_t match_data)
 {
     ScrnInfoPtr scrn = NULL;
-    char *path = xf86_get_platform_device_attrib(dev, ODEV_ATTRIB_PATH);
+    const char *path = xf86_get_platform_device_attrib(dev, ODEV_ATTRIB_PATH);
     int scr_flags = 0;
 
     if (flags & PLATFORM_PROBE_GPU_SCREEN)
@@ -369,7 +369,7 @@ Probe(DriverPtr drv, int flags)
     int i, numDevSections;
     GDevPtr *devSections;
     Bool foundScreen = FALSE;
-    char *dev;
+    const char *dev;
     ScrnInfoPtr scrn = NULL;
 
     /* For now, just bail out for PROBE_DETECT. */
@@ -559,6 +559,7 @@ FreeRec(ScrnInfoPtr pScrn)
             ret = drmClose(ms->fd);
         else
             ret = close(ms->fd);
+        (void) ret;
     }
     free(ms->Options);
     free(ms);
@@ -572,7 +573,8 @@ PreInit(ScrnInfoPtr pScrn, int flags)
     rgb defaultWeight = { 0, 0, 0 };
     EntityInfoPtr pEnt;
     EntPtr msEnt = NULL;
-    char *BusID = NULL, *devicename;
+    char *BusID = NULL;
+    const char *devicename;
     Bool prefer_shadow = TRUE;
     uint64_t value = 0;
     int ret;
diff --git a/hw/xfree86/drivers/modesetting/drmmode_display.c b/hw/xfree86/drivers/modesetting/drmmode_display.c
index 4fb4d21..773ec4c 100644
--- a/hw/xfree86/drivers/modesetting/drmmode_display.c
+++ b/hw/xfree86/drivers/modesetting/drmmode_display.c
@@ -534,14 +534,13 @@ drmmode_set_scanout_pixmap(xf86CrtcPtr crtc, PixmapPtr ppix)
 	DamageRegister(&ppix->drawable, drmmode_crtc->slave_damage);
 
 	if (ppriv->fb_id == 0) {
-		int r;
-		r = drmModeAddFB(drmmode->fd, ppix->drawable.width,
-				 ppix->drawable.height,
-				 ppix->drawable.depth,
-				 ppix->drawable.bitsPerPixel,
-				 ppix->devKind,
-				 ppriv->backing_bo->handle,
-				 &ppriv->fb_id);
+                drmModeAddFB(drmmode->fd, ppix->drawable.width,
+                             ppix->drawable.height,
+                             ppix->drawable.depth,
+                             ppix->drawable.bitsPerPixel,
+                             ppix->devKind,
+                             ppriv->backing_bo->handle,
+                             &ppriv->fb_id);
 	}
 	return TRUE;
 }
@@ -830,7 +829,7 @@ drmmode_output_create_resources(xf86OutputPtr output)
 	drmmode_prop = p->mode_prop;
 
 	if (drmmode_prop->flags & DRM_MODE_PROP_RANGE) {
-	    INT32 range[2];
+	    INT32 prop_range[2];
 	    INT32 value = p->value;
 
 	    p->num_atoms = 1;
@@ -838,12 +837,12 @@ drmmode_output_create_resources(xf86OutputPtr output)
 	    if (!p->atoms)
 		continue;
 	    p->atoms[0] = MakeAtom(drmmode_prop->name, strlen(drmmode_prop->name), TRUE);
-	    range[0] = drmmode_prop->values[0];
-	    range[1] = drmmode_prop->values[1];
+	    prop_range[0] = drmmode_prop->values[0];
+	    prop_range[1] = drmmode_prop->values[1];
 	    err = RRConfigureOutputProperty(output->randr_output, p->atoms[0],
 		    FALSE, TRUE,
 		    drmmode_prop->flags & DRM_MODE_PROP_IMMUTABLE ? TRUE : FALSE,
-		    2, range);
+		    2, prop_range);
 	    if (err != 0) {
 		xf86DrvMsg(output->scrn->scrnIndex, X_ERROR,
 			"RRConfigureOutputProperty error, %d\n", err);
commit 836daf4c7a276108a9f950e524828744aeda0a3c
Author: Dave Airlie <airlied at redhat.com>
Date:   Wed Jul 31 11:24:48 2013 +1000

    modesetting: change output names for secondary GPUs
    
    if we are a secondary GPU modify the output name to avoid clashes.
    
    Signed-off-by: Dave Airlie <airlied at redhat.com>

diff --git a/hw/xfree86/drivers/modesetting/drmmode_display.c b/hw/xfree86/drivers/modesetting/drmmode_display.c
index ce90cea..4fb4d21 100644
--- a/hw/xfree86/drivers/modesetting/drmmode_display.c
+++ b/hw/xfree86/drivers/modesetting/drmmode_display.c
@@ -1010,6 +1010,10 @@ drmmode_output_init(ScrnInfoPtr pScrn, drmmode_ptr drmmode, int num, int *num_dv
 	/* need to do smart conversion here for compat with non-kms ATI driver */
 	if (koutput->connector_type >= MS_ARRAY_SIZE(output_names))
 		snprintf(name, 32, "Unknown-%d", koutput->connector_type_id - 1);
+#ifdef MODESETTING_OUTPUT_SLAVE_SUPPORT
+	else if (pScrn->is_gpu)
+		snprintf(name, 32, "%s-%d-%d", output_names[koutput->connector_type], pScrn->scrnIndex - GPU_SCREEN_OFFSET + 1, koutput->connector_type_id - 1);
+#endif
 	else
 		snprintf(name, 32, "%s-%d", output_names[koutput->connector_type], koutput->connector_type_id - 1);
 
commit 951d2f83fc65a136717fb8090510d053e3f3a6c0
Author: Maarten Lankhorst <maarten.lankhorst at canonical.com>
Date:   Wed Jun 12 14:11:53 2013 +0200

    bump to 0.8.0
    
    Signed-off-by: Maarten Lankhorst <maarten.lankhorst at canonical.com>
commit 525ac7fb9a0d639253fc5d6556db3edb7239f932
Author: Maarten Lankhorst <maarten.lankhorst at canonical.com>
Date:   Wed Jun 12 14:05:19 2013 +0200

    modesetting: probe only succeeds if connectors are detected
    
    This will prevent modesetting being used for outputless intel or nvidia cards.
    
    Signed-off-by: Maarten Lankhorst <maarten.lankhorst at canonical.com>

diff --git a/hw/xfree86/drivers/modesetting/driver.c b/hw/xfree86/drivers/modesetting/driver.c
index c3d78be..cc526f6 100644
--- a/hw/xfree86/drivers/modesetting/driver.c
+++ b/hw/xfree86/drivers/modesetting/driver.c
@@ -201,12 +201,25 @@ static int open_hw(char *dev)
     return fd;
 }
 
+static int check_outputs(int fd)
+{
+    drmModeResPtr res = drmModeGetResources(fd);
+    int ret;
+
+    if (!res)
+        return FALSE;
+    ret = res->count_connectors > 0;
+    drmModeFreeResources(res);
+    return ret;
+}
+
 static Bool probe_hw(char *dev)
 {
     int fd = open_hw(dev);
     if (fd != -1) {
+        int ret = check_outputs(fd);
         close(fd);
-        return TRUE;
+        return ret;
     }
     return FALSE;
 }
@@ -226,7 +239,7 @@ ms_DRICreatePCIBusID(const struct pci_device *dev)
 
 static Bool probe_hw_pci(char *dev, struct pci_device *pdev)
 {
-    int fd = open_hw(dev);
+    int ret = FALSE, fd = open_hw(dev);
     char *id, *devid;
     drmSetVersion sv;
 
@@ -247,13 +260,12 @@ static Bool probe_hw_pci(char *dev, struct pci_device *pdev)
     devid = ms_DRICreatePCIBusID(pdev);
     close(fd);
 
-    if (!id || !devid)
-	return FALSE;
-
-    if (!strcmp(id, devid))
-	return TRUE;
+    if (id && devid && !strcmp(id, devid))
+        ret = check_outputs(fd);
 
-    return FALSE;
+    free(id);
+    free(devid);
+    return ret;
 }
 static const OptionInfoRec *
 AvailableOptions(int chipid, int busid)
commit d4791dd97b85ddac1295761bf6ab4f10c08346d7
Author: Dave Airlie <airlied at redhat.com>
Date:   Tue Jun 11 10:29:25 2013 +1000

    modesetting: fix adjust frame crash
    
    When SDL called this it was totally broken, actually hook
    up to the underlying drmmode function.
    
    Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=64808
    
    Thanks to Peter Wu <lekensteyn at gmail.com> for harassing me.
    
    Signed-off-by: Dave Airlie <airlied at redhat.com>

diff --git a/hw/xfree86/drivers/modesetting/driver.c b/hw/xfree86/drivers/modesetting/driver.c
index 742aadd..c3d78be 100644
--- a/hw/xfree86/drivers/modesetting/driver.c
+++ b/hw/xfree86/drivers/modesetting/driver.c
@@ -956,16 +956,9 @@ static void
 AdjustFrame(ADJUST_FRAME_ARGS_DECL)
 {
     SCRN_INFO_PTR(arg);
-    xf86CrtcConfigPtr config = XF86_CRTC_CONFIG_PTR(pScrn);
-    xf86OutputPtr output = config->output[config->compat_output];
-    xf86CrtcPtr crtc = output->crtc;
-
-    if (crtc && crtc->enabled) {
-	crtc->funcs->mode_set(crtc, pScrn->currentMode, pScrn->currentMode, x,
-			      y);
-	crtc->x = output->initial_x + x;
-	crtc->y = output->initial_y + y;
-    }
+    modesettingPtr ms = modesettingPTR(pScrn);
+
+    drmmode_adjust_frame(pScrn, &ms->drmmode, x, y);
 }
 
 static void
diff --git a/hw/xfree86/drivers/modesetting/drmmode_display.c b/hw/xfree86/drivers/modesetting/drmmode_display.c
index 2dc7576..ce90cea 100644
--- a/hw/xfree86/drivers/modesetting/drmmode_display.c
+++ b/hw/xfree86/drivers/modesetting/drmmode_display.c
@@ -1267,7 +1267,7 @@ Bool drmmode_pre_init(ScrnInfoPtr pScrn, drmmode_ptr drmmode, int cpp)
 	return TRUE;
 }
 
-void drmmode_adjust_frame(ScrnInfoPtr pScrn, drmmode_ptr drmmode, int x, int y, int flags)
+void drmmode_adjust_frame(ScrnInfoPtr pScrn, drmmode_ptr drmmode, int x, int y)
 {
 	xf86CrtcConfigPtr	config = XF86_CRTC_CONFIG_PTR(pScrn);
 	xf86OutputPtr  output = config->output[config->compat_output];
diff --git a/hw/xfree86/drivers/modesetting/drmmode_display.h b/hw/xfree86/drivers/modesetting/drmmode_display.h
index 1d5522b..adf4b99 100644
--- a/hw/xfree86/drivers/modesetting/drmmode_display.h
+++ b/hw/xfree86/drivers/modesetting/drmmode_display.h
@@ -118,7 +118,7 @@ Bool drmmode_SetSlaveBO(PixmapPtr ppix,
 #endif
 
 extern Bool drmmode_pre_init(ScrnInfoPtr pScrn, drmmode_ptr drmmode, int cpp);
-void drmmode_adjust_frame(ScrnInfoPtr pScrn, drmmode_ptr drmmode, int x, int y, int flags);
+void drmmode_adjust_frame(ScrnInfoPtr pScrn, drmmode_ptr drmmode, int x, int y);
 extern Bool drmmode_set_desired_modes(ScrnInfoPtr pScrn, drmmode_ptr drmmode);
 extern Bool drmmode_setup_colormap(ScreenPtr pScreen, ScrnInfoPtr pScrn);
 
commit c64fa9a2961f82719cc7734a4222f31297a2e593
Author: Maarten Lankhorst <maarten.lankhorst at canonical.com>
Date:   Wed Apr 3 12:08:44 2013 +0200

    support 32 bpp pixmaps when 24 bpp fb is used.
    
    Fixes background corruption in ubuntu.
    
    Signed-off-by: Maarten Lankhorst <maarten.lankhorst at canonical.com>

diff --git a/hw/xfree86/drivers/modesetting/driver.c b/hw/xfree86/drivers/modesetting/driver.c
index 06d6d53..742aadd 100644
--- a/hw/xfree86/drivers/modesetting/driver.c
+++ b/hw/xfree86/drivers/modesetting/driver.c
@@ -650,7 +650,7 @@ PreInit(ScrnInfoPtr pScrn, int flags)
 #endif
     drmmode_get_default_bpp(pScrn, &ms->drmmode, &defaultdepth, &defaultbpp);
     if (defaultdepth == 24 && defaultbpp == 24)
-	    bppflags = Support24bppFb;
+	    bppflags = SupportConvert32to24 | Support24bppFb;
     else
 	    bppflags = PreferConvert24to32 | SupportConvert24to32 | Support32bppFb;
     
commit 3a9a6c972e4bc88dc3dde9399df3b0cda759cd70
Author: Maarten Lankhorst <maarten.lankhorst at canonical.com>
Date:   Wed Mar 27 10:33:46 2013 +0100

    bump version to 0.7.0
commit 862bc2836835b93f4b2cfd2de6ca344f65484a00
Author: Maarten Lankhorst <maarten.lankhorst at canonical.com>
Date:   Tue Mar 26 15:19:52 2013 +0100

    modesetting: return null for get_modes if output could not be retrieved
    
    Signed-off-by: Maarten Lankhorst <maarten.lankhorst at canonical.com>

diff --git a/hw/xfree86/drivers/modesetting/drmmode_display.c b/hw/xfree86/drivers/modesetting/drmmode_display.c
index e8ebef1..2dc7576 100644
--- a/hw/xfree86/drivers/modesetting/drmmode_display.c
+++ b/hw/xfree86/drivers/modesetting/drmmode_display.c
@@ -709,6 +709,9 @@ drmmode_output_get_modes(xf86OutputPtr output)
 	drmModePropertyPtr props;
 	xf86MonPtr mon = NULL;
 
+	if (!koutput)
+		return NULL;
+
 	/* look for an EDID property */
 	for (i = 0; i < koutput->count_props; i++) {
 		props = drmModeGetProperty(drmmode->fd, koutput->props[i]);
commit 6b79a8791d35bbd1a13ebdec1c582f66c559c039
Author: Maarten Lankhorst <maarten.lankhorst at canonical.com>
Date:   Tue Mar 26 15:19:33 2013 +0100

    modesetting: clean up leaks
    
    Signed-off-by: Maarten Lankhorst <maarten.lankhorst at canonical.com>

diff --git a/hw/xfree86/drivers/modesetting/driver.c b/hw/xfree86/drivers/modesetting/driver.c
index 87ba272..06d6d53 100644
--- a/hw/xfree86/drivers/modesetting/driver.c
+++ b/hw/xfree86/drivers/modesetting/driver.c
@@ -206,7 +206,7 @@ static Bool probe_hw(char *dev)
     int fd = open_hw(dev);
     if (fd != -1) {
         close(fd);
-	return TRUE;
+        return TRUE;
     }
     return FALSE;
 }
@@ -530,15 +530,27 @@ static void msBlockHandler(BLOCKHANDLER_ARGS_DECL)
 static void
 FreeRec(ScrnInfoPtr pScrn)
 {
+    modesettingPtr ms;
+
     if (!pScrn)
-	return;
+        return;
 
-    if (!pScrn->driverPrivate)
-	return;
+    ms = modesettingPTR(pScrn);
+    if (!ms)
+        return;
+    pScrn->driverPrivate = NULL;
 
-    free(pScrn->driverPrivate);
+    if (ms->fd > 0) {
+        int ret;
+
+        if (ms->pEnt->location.type == BUS_PCI)
+            ret = drmClose(ms->fd);
+        else
+            ret = close(ms->fd);
+    }
+    free(ms->Options);
+    free(ms);
 
-    pScrn->driverPrivate = NULL;
 }
 
 static Bool
@@ -596,8 +608,8 @@ PreInit(ScrnInfoPtr pScrn, int flags)
 
 #if XSERVER_PLATFORM_BUS
     if (pEnt->location.type == BUS_PLATFORM) {
-            char *path = xf86_get_platform_device_attrib(pEnt->location.id.plat, ODEV_ATTRIB_PATH);
-            ms->fd = open_hw(path);
+        char *path = xf86_get_platform_device_attrib(pEnt->location.id.plat, ODEV_ATTRIB_PATH);
+        ms->fd = open_hw(path);
     }
     else 
 #endif
commit 1754973206c09a901747e71d4abdf666293da59e
Author: Aaron Plattner <aplattner at nvidia.com>
Date:   Wed Feb 20 17:27:16 2013 -0800

    modesetting: match PCI class 3, any subclass
    
    If a device is not primary, the PCI device match fails because the
    xf86-video-modesetting driver looks specifically for a PCI class match of
    0x30000 with a mask of 0xffffff.  This fails to match, for example, a
    non-primary Intel VGA device, because it is reported as having a class of
    0x38000.
    
    Fix that by ignoring the low 16 bits of the class in the pci_id_match table.
    
    Signed-off-by: Aaron Plattner <aplattner at nvidia.com>
    Reviewed on IRC by Adam Jackson <ajax at redhat.com>

diff --git a/hw/xfree86/drivers/modesetting/driver.c b/hw/xfree86/drivers/modesetting/driver.c
index 05b6176..87ba272 100644
--- a/hw/xfree86/drivers/modesetting/driver.c
+++ b/hw/xfree86/drivers/modesetting/driver.c
@@ -86,7 +86,7 @@ static Bool ms_driver_func(ScrnInfoPtr scrn, xorgDriverFuncOp op,
 static const struct pci_id_match ms_device_match[] = {
     {
 	PCI_MATCH_ANY, PCI_MATCH_ANY, PCI_MATCH_ANY, PCI_MATCH_ANY,
-	0x00030000, 0x00ffffff, 0
+	0x00030000, 0x00ff0000, 0
     },
 
     { 0, 0, 0 },
commit beb1715e96b649a0903fa61f30dd1eb69411da2f
Author: Colin Walters <walters at verbum.org>
Date:   Wed Jan 4 22:37:06 2012 +0000

    autogen.sh: Implement GNOME Build API
    
    http://people.gnome.org/~walters/docs/build-api.txt
    
    Signed-off-by: Adam Jackson <ajax at redhat.com>
commit 75815dbb373d5a74d57cbec9d469f9f88a8ee3ef
Author: Chris Wilson <chris at chris-wilson.co.uk>
Date:   Mon Dec 3 13:25:19 2012 +0000

    Add missing GTF modes
    
    A fixed-mode output device like a panel will often only inform of its
    preferred mode through its EDID. However, the driver will adjust user
    specified modes for display through use of a panel-fitter allowing
    greater flexibility in upscaling. This is often used by games to set a
    low resolution for performance and use the panel fitter to fill the
    screen.
    
    v2: Use the presence of the 'scaling mode' connector property as an
    indication that a panel fitter is attached to that pipe.
    
    Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=55564

diff --git a/hw/xfree86/drivers/modesetting/drmmode_display.c b/hw/xfree86/drivers/modesetting/drmmode_display.c
index 63cecc3..e8ebef1 100644
--- a/hw/xfree86/drivers/modesetting/drmmode_display.c
+++ b/hw/xfree86/drivers/modesetting/drmmode_display.c
@@ -626,6 +626,78 @@ drmmode_output_mode_valid(xf86OutputPtr output, DisplayModePtr pModes)
 	return MODE_OK;
 }
 
+static Bool
+has_panel_fitter(xf86OutputPtr output)
+{
+	drmmode_output_private_ptr drmmode_output = output->driver_private;
+	drmModeConnectorPtr koutput = drmmode_output->mode_output;
+	drmmode_ptr drmmode = drmmode_output->drmmode;
+	int i;
+
+	/* Presume that if the output supports scaling, then we have a
+	 * panel fitter capable of adjust any mode to suit.
+	 */
+	for (i = 0; i < koutput->count_props; i++) {
+		drmModePropertyPtr props;
+		Bool found = FALSE;
+
+		props = drmModeGetProperty(drmmode->fd, koutput->props[i]);
+		if (props) {
+			found = strcmp(props->name, "scaling mode") == 0;
+			drmModeFreeProperty(props);
+		}
+
+		if (found)
+			return TRUE;
+	}
+
+	return FALSE;
+}
+
+static DisplayModePtr
+drmmode_output_add_gtf_modes(xf86OutputPtr output,
+			     DisplayModePtr Modes)
+{
+	xf86MonPtr mon = output->MonInfo;
+	DisplayModePtr i, m, preferred = NULL;
+	int max_x = 0, max_y = 0;
+	float max_vrefresh = 0.0;
+
+	if (mon && GTF_SUPPORTED(mon->features.msc))
+		return Modes;
+
+	if (!has_panel_fitter(output))
+		return Modes;
+
+	for (m = Modes; m; m = m->next) {
+		if (m->type & M_T_PREFERRED)
+			preferred = m;
+		max_x = max(max_x, m->HDisplay);
+		max_y = max(max_y, m->VDisplay);
+		max_vrefresh = max(max_vrefresh, xf86ModeVRefresh(m));
+	}
+
+	max_vrefresh = max(max_vrefresh, 60.0);
+	max_vrefresh *= (1 + SYNC_TOLERANCE);
+
+	m = xf86GetDefaultModes();
+	xf86ValidateModesSize(output->scrn, m, max_x, max_y, 0);
+
+	for (i = m; i; i = i->next) {
+		if (xf86ModeVRefresh(i) > max_vrefresh)
+			i->status = MODE_VSYNC;
+		if (preferred &&
+		    i->HDisplay >= preferred->HDisplay &&
+		    i->VDisplay >= preferred->VDisplay &&
+		    xf86ModeVRefresh(i) >= xf86ModeVRefresh(preferred))
+			i->status = MODE_VSYNC;
+	}
+
+	xf86PruneInvalidModes(output->scrn, &m, FALSE);
+
+	return xf86ModesAdd(Modes, m);
+}
+
 static DisplayModePtr
 drmmode_output_get_modes(xf86OutputPtr output)
 {
@@ -666,7 +738,8 @@ drmmode_output_get_modes(xf86OutputPtr output)
 		Modes = xf86ModesAdd(Modes, Mode);
 
 	}
-	return Modes;
+
+	return drmmode_output_add_gtf_modes(output, Modes);
 }
 
 static void
commit ac34281b8a487640c61f258ae45a6f17a4fb3cc0
Author: Dave Airlie <airlied at redhat.com>
Date:   Thu Feb 7 12:24:20 2013 +1000

    modesetting: provide dummy hooks for shadow
    
    Since in some wierd cases the server can call these without checking they
    exist.
    
    Signed-off-by: Dave Airlie <airlied at redhat.com>

diff --git a/hw/xfree86/drivers/modesetting/drmmode_display.c b/hw/xfree86/drivers/modesetting/drmmode_display.c
index 42cd5ac..63cecc3 100644
--- a/hw/xfree86/drivers/modesetting/drmmode_display.c
+++ b/hw/xfree86/drivers/modesetting/drmmode_display.c
@@ -547,6 +547,17 @@ drmmode_set_scanout_pixmap(xf86CrtcPtr crtc, PixmapPtr ppix)
 }
 #endif
 
+static void *drmmode_shadow_allocate(xf86CrtcPtr crtc, int width, int height)
+{
+	return NULL;
+}
+
+static PixmapPtr drmmode_shadow_create(xf86CrtcPtr crtc, void *data, int width,
+				       int height)
+{
+	return NULL;
+}
+
 static const xf86CrtcFuncsRec drmmode_crtc_funcs = {
     .dpms = drmmode_crtc_dpms,
     .set_mode_major = drmmode_set_mode_major,
@@ -561,6 +572,8 @@ static const xf86CrtcFuncsRec drmmode_crtc_funcs = {
 #ifdef MODESETTING_OUTPUT_SLAVE_SUPPORT
     .set_scanout_pixmap = drmmode_set_scanout_pixmap,
 #endif
+    .shadow_allocate = drmmode_shadow_allocate,
+    .shadow_create = drmmode_shadow_create,
 };
 
 static void
commit 34a571c5b9781025897ba5e5c5e2a34ae5262266
Author: Dave Airlie <airlied at redhat.com>
Date:   Wed Jan 9 13:04:00 2013 +1000

    modesetting: bump to 0.6.0
commit 8650ff14a52047173fa32f12f22ec6f4e38ff433
Author: Dave Airlie <airlied at redhat.com>
Date:   Wed Jan 9 12:48:30 2013 +1000

    modesetting: fix crashes caused by udev race conditions
    
    So the kernel removes the device, and the driver processes the first
    udev event, and gets no output back from the kernel, so it check
    and don't fall over.
    
    This fixes a couple of crashes seen when hotplugging USB devices.
    
    Signed-off-by: Dave Airlie <airlied at redhat.com>

diff --git a/hw/xfree86/drivers/modesetting/drmmode_display.c b/hw/xfree86/drivers/modesetting/drmmode_display.c
index 8d760c2..42cd5ac 100644
--- a/hw/xfree86/drivers/modesetting/drmmode_display.c
+++ b/hw/xfree86/drivers/modesetting/drmmode_display.c
@@ -589,6 +589,8 @@ drmmode_output_detect(xf86OutputPtr output)
 	drmModeFreeConnector(drmmode_output->mode_output);
 
 	drmmode_output->mode_output = drmModeGetConnector(drmmode->fd, drmmode_output->output_id);
+	if (!drmmode_output->mode_output)
+		return XF86OutputStatusDisconnected;
 
 	switch (drmmode_output->mode_output->connection) {
 	case DRM_MODE_CONNECTED:
@@ -683,6 +685,9 @@ drmmode_output_dpms(xf86OutputPtr output, int mode)
 	drmModeConnectorPtr koutput = drmmode_output->mode_output;
 	drmmode_ptr drmmode = drmmode_output->drmmode;
 
+	if (!koutput)
+		return;
+
 	drmModeConnectorSetProperty(drmmode->fd, koutput->connector_id,
 				    drmmode_output->dpms_enum_id, mode);
 	return;
commit 0b198248ecfbcb7e7c61688145be4005366da23d
Author: Thierry Reding <thierry.reding at avionic-design.de>
Date:   Thu Nov 8 14:28:10 2012 +0100

    Remove call to miInitializeBackingStore()
    
    Recent versions of the X server no longer provide this function, which
    has been obsolete for over 2 years now.
    
    Signed-off-by: Thierry Reding <thierry.reding at avionic-design.de>
    Reviewed-by: Alex Deucher <alexander.deucher at amd.com>
    Signed-off-by: Dave Airlie <airlied at redhat.com>

diff --git a/hw/xfree86/drivers/modesetting/driver.c b/hw/xfree86/drivers/modesetting/driver.c
index 200a6d8..05b6176 100644
--- a/hw/xfree86/drivers/modesetting/driver.c
+++ b/hw/xfree86/drivers/modesetting/driver.c
@@ -901,7 +901,6 @@ ScreenInit(SCREEN_INIT_ARGS_DECL)
 
     xf86SetBlackWhitePixels(pScreen);
 
-    miInitializeBackingStore(pScreen);
     xf86SetBackingStore(pScreen);
     xf86SetSilkenMouse(pScreen);
     miDCInitialize(pScreen, xf86GetPointerScreenFuncs());
commit 739d6c067a9167226ce248aa82997bfc2cca7259
Author: Thierry Reding <thierry.reding at avionic-design.de>
Date:   Thu Nov 8 14:28:09 2012 +0100

    build: Put m4 macros in m4 subdirectory
    
    This silences a warning from libtoolize when running the autogen.sh
    script.
    
    Signed-off-by: Thierry Reding <thierry.reding at avionic-design.de>
    Signed-off-by: Dave Airlie <airlied at redhat.com>
commit e47ad8a0aec7662970e7f81e6ee487330bf094c1
Author: Dave Airlie <airlied at redhat.com>
Date:   Mon Sep 17 11:48:14 2012 +1000

    modesetting: remove alloca usage again
    
    this slipped back in.
    
    Signed-off-by: Dave Airlie <airlied at redhat.com>

diff --git a/hw/xfree86/drivers/modesetting/driver.c b/hw/xfree86/drivers/modesetting/driver.c
index 38a1c09..200a6d8 100644
--- a/hw/xfree86/drivers/modesetting/driver.c
+++ b/hw/xfree86/drivers/modesetting/driver.c
@@ -428,10 +428,13 @@ static int dispatch_dirty_region(ScrnInfoPtr scrn,
     unsigned num_cliprects = REGION_NUM_RECTS(dirty);
 
     if (num_cliprects) {
-	drmModeClip *clip = alloca(num_cliprects * sizeof(drmModeClip));
+	drmModeClip *clip = malloc(num_cliprects * sizeof(drmModeClip));
 	BoxPtr rect = REGION_RECTS(dirty);
 	int i, ret;
 	    
+	if (!clip)
+	    return -ENOMEM;
+
 	/* XXX no need for copy? */
 	for (i = 0; i < num_cliprects; i++, rect++) {
 	    clip[i].x1 = rect->x1;
@@ -442,6 +445,7 @@ static int dispatch_dirty_region(ScrnInfoPtr scrn,
 
 	/* TODO query connector property to see if this is needed */
 	ret = drmModeDirtyFB(ms->fd, fb_id, clip, num_cliprects);
+	free(clip);
 	DamageEmpty(damage);
 	if (ret) {
 	    if (ret == -EINVAL)
commit f8eb8c1cb4f453bdbe6a81815be8ecefba2084aa
Author: Alon Levy <alevy at redhat.com>
Date:   Tue Aug 28 11:46:47 2012 +1000

    modesetting: add virtual connector support
    
    [airlied: also make sure we don't crash in future.]
    
    Signed-off-by: Alon Levy <alevy at redhat.com>
    Signed-off-by: Dave Airlie <airlied at redhat.com>

diff --git a/hw/xfree86/drivers/modesetting/drmmode_display.c b/hw/xfree86/drivers/modesetting/drmmode_display.c
index 5e38265..8d760c2 100644
--- a/hw/xfree86/drivers/modesetting/drmmode_display.c
+++ b/hw/xfree86/drivers/modesetting/drmmode_display.c
@@ -882,7 +882,8 @@ const char *output_names[] = { "None",
 			       "HDMI",
 			       "HDMI",
 			       "TV",
-			       "eDP"
+			       "eDP",
+			       "Virtual"
 };
 
 static void
@@ -913,7 +914,10 @@ drmmode_output_init(ScrnInfoPtr pScrn, drmmode_ptr drmmode, int num, int *num_dv
 	}
 
 	/* need to do smart conversion here for compat with non-kms ATI driver */
-	snprintf(name, 32, "%s-%d", output_names[koutput->connector_type], koutput->connector_type_id - 1);
+	if (koutput->connector_type >= MS_ARRAY_SIZE(output_names))
+		snprintf(name, 32, "Unknown-%d", koutput->connector_type_id - 1);
+	else
+		snprintf(name, 32, "%s-%d", output_names[koutput->connector_type], koutput->connector_type_id - 1);
 
 	output = xf86OutputCreate (pScrn, &drmmode_output_funcs, name);
 	if (!output) {
diff --git a/hw/xfree86/drivers/modesetting/drmmode_display.h b/hw/xfree86/drivers/modesetting/drmmode_display.h
index 24f7960..1d5522b 100644
--- a/hw/xfree86/drivers/modesetting/drmmode_display.h
+++ b/hw/xfree86/drivers/modesetting/drmmode_display.h
@@ -139,5 +139,7 @@ void drmmode_get_default_bpp(ScrnInfoPtr pScrn, drmmode_ptr drmmmode, int *depth
 #define DRM_CAP_DUMB_PREFER_SHADOW 4
 #endif
 
+#define MS_ARRAY_SIZE(x) (sizeof(x)/sizeof(x[0]))
+
 
 #endif
commit 5eb697d88f0735e98fe9a97770ddda83202b1597
Author: Maarten Lankhorst <maarten.lankhorst at canonical.com>
Date:   Thu Sep 13 08:45:14 2012 +0200

    bump version to 0.5.0
commit e3d7d5d18e3281677890064679af459e1af108cf
Author: Adam Jackson <ajax at redhat.com>
Date:   Thu Jul 19 22:15:10 2012 +0000

    Implement ->driverFunc
    
    Copied from fbdev, makes it so we can run without iopl.
    
    Signed-off-by: Adam Jackson <ajax at redhat.com>

diff --git a/hw/xfree86/drivers/modesetting/driver.c b/hw/xfree86/drivers/modesetting/driver.c
index 371c171..38a1c09 100644
--- a/hw/xfree86/drivers/modesetting/driver.c
+++ b/hw/xfree86/drivers/modesetting/driver.c
@@ -79,6 +79,8 @@ static Bool Probe(DriverPtr drv, int flags);
 static Bool ms_pci_probe(DriverPtr driver,
 			 int entity_num, struct pci_device *device,
 			 intptr_t match_data);
+static Bool ms_driver_func(ScrnInfoPtr scrn, xorgDriverFuncOp op,
+			   void *data);
 
 #ifdef XSERVER_LIBPCIACCESS
 static const struct pci_id_match ms_device_match[] = {
@@ -105,7 +107,7 @@ _X_EXPORT DriverRec modesetting = {
     AvailableOptions,
     NULL,
     0,
-    NULL,
+    ms_driver_func,
     ms_device_match,
     ms_pci_probe,
 #ifdef XSERVER_PLATFORM_BUS
@@ -259,6 +261,21 @@ AvailableOptions(int chipid, int busid)
     return Options;
 }
 
+static Bool
+ms_driver_func(ScrnInfoPtr scrn, xorgDriverFuncOp op, void *data)
+{
+    xorgHWFlags *flag;
+    
+    switch (op) {
+	case GET_REQUIRED_HW_INTERFACES:
+	    flag = (CARD32 *)data;
+	    (*flag) = 0;
+	    return TRUE;
+	default:
+	    return FALSE;
+    }
+}
+
 #if XSERVER_LIBPCIACCESS
 static Bool
 ms_pci_probe(DriverPtr driver,
commit 02811f1a9cc35c5f82accb0459cb3910165e7e45
Author: Dave Airlie <airlied at redhat.com>
Date:   Thu Jul 19 14:12:59 2012 +1000

    modesetting: add output slave support.
    
    This allows the driver to operate as an output slave.
    
    It adds scan out pixmap, and the capability
    checks to make sure they available.
    
    Signed-off-by: Dave Airlie <airlied at redhat.com>

diff --git a/hw/xfree86/drivers/modesetting/driver.c b/hw/xfree86/drivers/modesetting/driver.c
index 86be277..371c171 100644
--- a/hw/xfree86/drivers/modesetting/driver.c
+++ b/hw/xfree86/drivers/modesetting/driver.c
@@ -401,21 +401,20 @@ GetRec(ScrnInfoPtr pScrn)
     return TRUE;
 }
 
-static void dispatch_dirty(ScreenPtr pScreen)
+static int dispatch_dirty_region(ScrnInfoPtr scrn,
+				 PixmapPtr pixmap,
+				 DamagePtr damage,
+				 int fb_id)
 {
-    ScrnInfoPtr scrn = xf86ScreenToScrn(pScreen);
     modesettingPtr ms = modesettingPTR(scrn);
-    RegionPtr dirty = DamageRegion(ms->damage);
+    RegionPtr dirty = DamageRegion(damage);
     unsigned num_cliprects = REGION_NUM_RECTS(dirty);
 
     if (num_cliprects) {
-	drmModeClip *clip = malloc(num_cliprects * sizeof(drmModeClip));
+	drmModeClip *clip = alloca(num_cliprects * sizeof(drmModeClip));
 	BoxPtr rect = REGION_RECTS(dirty);
 	int i, ret;
-	
-	if (!clip)
-		return;
-
+	    
 	/* XXX no need for copy? */
 	for (i = 0; i < num_cliprects; i++, rect++) {
 	    clip[i].x1 = rect->x1;
@@ -425,25 +424,71 @@ static void dispatch_dirty(ScreenPtr pScreen)
 	}
 
 	/* TODO query connector property to see if this is needed */
-	ret = drmModeDirtyFB(ms->fd, ms->drmmode.fb_id, clip, num_cliprects);
-	free(clip);
+	ret = drmModeDirtyFB(ms->fd, fb_id, clip, num_cliprects);
+	DamageEmpty(damage);
 	if (ret) {
-	    if (ret == -EINVAL || ret == -ENOSYS) {
-		ms->dirty_enabled = FALSE;
-		DamageUnregister(&pScreen->GetScreenPixmap(pScreen)->drawable, ms->damage);
-		DamageDestroy(ms->damage);
-		ms->damage = NULL;
-		xf86DrvMsg(scrn->scrnIndex, X_INFO, "Disabling kernel dirty updates, not required.\n");
-		return;
-	    } else
-		ErrorF("%s: failed to send dirty (%i, %s)\n",
-		       __func__, ret, strerror(-ret));
+	    if (ret == -EINVAL)
+		return ret;
 	}
-	
-	DamageEmpty(ms->damage);
+    }
+    return 0;
+}
+
+static void dispatch_dirty(ScreenPtr pScreen)
+{
+    ScrnInfoPtr scrn = xf86ScreenToScrn(pScreen);
+    modesettingPtr ms = modesettingPTR(scrn);
+    PixmapPtr pixmap = pScreen->GetScreenPixmap(pScreen);
+    int fb_id = ms->drmmode.fb_id;
+    int ret;
+
+    ret = dispatch_dirty_region(scrn, pixmap, ms->damage, fb_id);
+    if (ret == -EINVAL || ret == -ENOSYS) {
+	ms->dirty_enabled = FALSE;
+	DamageUnregister(&pScreen->GetScreenPixmap(pScreen)->drawable, ms->damage);
+	DamageDestroy(ms->damage);
+	ms->damage = NULL;
+	xf86DrvMsg(scrn->scrnIndex, X_INFO, "Disabling kernel dirty updates, not required.\n");
+	return;
+    }
+}
+
+#ifdef MODESETTING_OUTPUT_SLAVE_SUPPORT
+static void dispatch_dirty_crtc(ScrnInfoPtr scrn, xf86CrtcPtr crtc)
+{
+    modesettingPtr ms = modesettingPTR(scrn);
+    PixmapPtr pixmap = crtc->randr_crtc->scanout_pixmap;
+    msPixmapPrivPtr ppriv = msGetPixmapPriv(&ms->drmmode, pixmap);
+    drmmode_crtc_private_ptr drmmode_crtc = crtc->driver_private;
+    DamagePtr damage = drmmode_crtc->slave_damage;
+    int fb_id = ppriv->fb_id;
+    int ret;
+
+    ret = dispatch_dirty_region(scrn, pixmap, damage, fb_id);
+    if (ret) {
+
     }
 }
 
+static void dispatch_slave_dirty(ScreenPtr pScreen)
+{
+    ScrnInfoPtr scrn = xf86ScreenToScrn(pScreen);
+    xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(scrn);
+    int c;
+
+    for (c = 0; c < xf86_config->num_crtc; c++) {
+	xf86CrtcPtr crtc = xf86_config->crtc[c];
+
+	if (!crtc->randr_crtc)
+	    continue;
+	if (!crtc->randr_crtc->scanout_pixmap)
+	    continue;
+
+	dispatch_dirty_crtc(scrn, crtc);
+    }
+}
+#endif
+
 static void msBlockHandler(BLOCKHANDLER_ARGS_DECL)
 {
     SCREEN_PTR(arg);
@@ -452,8 +497,13 @@ static void msBlockHandler(BLOCKHANDLER_ARGS_DECL)
     pScreen->BlockHandler = ms->BlockHandler;
     pScreen->BlockHandler(BLOCKHANDLER_ARGS);
     pScreen->BlockHandler = msBlockHandler;
+#ifdef MODESETTING_OUTPUT_SLAVE_SUPPORT
+    if (pScreen->isGPU)
+        dispatch_slave_dirty(pScreen);
+    else
+#endif
     if (ms->dirty_enabled)
-	dispatch_dirty(pScreen);
+        dispatch_dirty(pScreen);
 }
 
 static void
@@ -555,6 +605,16 @@ PreInit(ScrnInfoPtr pScrn, int flags)
 
     ms->drmmode.fd = ms->fd;
 
+#ifdef MODESETTING_OUTPUT_SLAVE_SUPPORT
+    pScrn->capabilities = 0;
+#ifdef DRM_CAP_PRIME
+    ret = drmGetCap(ms->fd, DRM_CAP_PRIME, &value);
+    if (ret == 0) {
+        if (value & DRM_PRIME_CAP_IMPORT)
+            pScrn->capabilities |= RR_Capability_SinkOutput;
+    }
+#endif
+#endif
     drmmode_get_default_bpp(pScrn, &ms->drmmode, &defaultdepth, &defaultbpp);
     if (defaultdepth == 24 && defaultbpp == 24)
 	    bppflags = Support24bppFb;
@@ -719,6 +779,25 @@ msShadowInit(ScreenPtr pScreen)
     return TRUE;
 }
 
+#ifdef MODESETTING_OUTPUT_SLAVE_SUPPORT
+static Bool
+msSetSharedPixmapBacking(PixmapPtr ppix, void *fd_handle)
+{
+    ScreenPtr screen = ppix->drawable.pScreen;
+    ScrnInfoPtr scrn = xf86ScreenToScrn(screen);
+    modesettingPtr ms = modesettingPTR(scrn);
+    Bool ret;
+    int size = ppix->devKind * ppix->drawable.height;
+    int ihandle = (int)(long)fd_handle;
+
+    ret = drmmode_SetSlaveBO(ppix, &ms->drmmode, ihandle, ppix->devKind, size);
+    if (ret == FALSE)
+	    return ret;
+
+    return TRUE;
+}
+#endif
+
 static Bool
 ScreenInit(SCREEN_INIT_ARGS_DECL)
 {
@@ -757,6 +836,13 @@ ScreenInit(SCREEN_INIT_ARGS_DECL)
     if (!miSetPixmapDepths())
 	return FALSE;
 
+#ifdef MODESETTING_OUTPUT_SLAVE_SUPPORT
+    if (!dixRegisterScreenSpecificPrivateKey(pScreen, &ms->drmmode.pixmapPrivateKeyRec,
+        PRIVATE_PIXMAP, sizeof(msPixmapPrivRec))) { 
+	return FALSE;
+    }
+#endif
+
     pScrn->memPhysBase = 0;
     pScrn->fbOffset = 0;
 
@@ -816,6 +902,10 @@ ScreenInit(SCREEN_INIT_ARGS_DECL)
     ms->BlockHandler = pScreen->BlockHandler;
     pScreen->BlockHandler = msBlockHandler;
 
+#ifdef MODESETTING_OUTPUT_SLAVE_SUPPORT
+    pScreen->SetSharedPixmapBacking = msSetSharedPixmapBacking;
+#endif
+
     if (!xf86CrtcScreenInit(pScreen))
 	return FALSE;
 
diff --git a/hw/xfree86/drivers/modesetting/drmmode_display.c b/hw/xfree86/drivers/modesetting/drmmode_display.c
index 9ee553e..5e38265 100644
--- a/hw/xfree86/drivers/modesetting/drmmode_display.c
+++ b/hw/xfree86/drivers/modesetting/drmmode_display.c
@@ -138,6 +138,43 @@ static int dumb_bo_destroy(int fd, struct dumb_bo *bo)
 	return 0;
 }
 
+#ifdef MODESETTING_OUTPUT_SLAVE_SUPPORT
+static struct dumb_bo *dumb_get_bo_from_handle(int fd, int handle, int pitch, int size)
+{
+  	struct dumb_bo *bo;
+	int ret;
+
+	bo = calloc(1, sizeof(*bo));
+	if (!bo)
+		return NULL;
+
+	ret = drmPrimeFDToHandle(fd, handle, &bo->handle);
+	if (ret) {
+		free(bo);
+		return NULL;
+	}
+	bo->pitch = pitch;
+	bo->size = size;
+	return bo;
+}
+#endif
+
+#ifdef MODESETTING_OUTPUT_SLAVE_SUPPORT
+Bool drmmode_SetSlaveBO(PixmapPtr ppix,
+			drmmode_ptr drmmode, 
+			int fd_handle, int pitch, int size)
+{
+    	msPixmapPrivPtr ppriv = msGetPixmapPriv(drmmode, ppix);
+
+	ppriv->backing_bo = dumb_get_bo_from_handle(drmmode->fd, fd_handle, pitch, size);
+	if (!ppriv->backing_bo)
+		return FALSE;
+
+	close(fd_handle);
+	return TRUE;
+}
+#endif
+
 static void
 drmmode_ConvertFromKMode(ScrnInfoPtr	scrn,
 		     drmModeModeInfo *kmode,
@@ -274,7 +311,7 @@ drmmode_set_mode_major(xf86CrtcPtr crtc, DisplayModePtr mode,
 	int output_count = 0;
 	Bool ret = TRUE;
 	int i;
-	int fb_id;
+	uint32_t fb_id;
 	drmModeModeInfo kmode;
 	int height;
 
@@ -338,6 +375,13 @@ drmmode_set_mode_major(xf86CrtcPtr crtc, DisplayModePtr mode,
 		drmmode_ConvertToKMode(crtc->scrn, &kmode, mode);
 
 		fb_id = drmmode->fb_id;
+#ifdef MODESETTING_OUTPUT_SLAVE_SUPPORT
+		if (crtc->randr_crtc->scanout_pixmap) {
+    			msPixmapPrivPtr ppriv = msGetPixmapPriv(drmmode, crtc->randr_crtc->scanout_pixmap);
+			fb_id = ppriv->fb_id;
+			x = y = 0;
+		} else 
+#endif
 		if (drmmode_crtc->rotate_fb_id) {
 			fb_id = drmmode_crtc->rotate_fb_id;
 			x = y = 0;
@@ -455,6 +499,54 @@ drmmode_crtc_gamma_set(xf86CrtcPtr crtc, uint16_t *red, uint16_t *green,
 			    size, red, green, blue);
 }
 
+#ifdef MODESETTING_OUTPUT_SLAVE_SUPPORT
+static Bool
+drmmode_set_scanout_pixmap(xf86CrtcPtr crtc, PixmapPtr ppix)
+{
+	drmmode_crtc_private_ptr drmmode_crtc = crtc->driver_private;
+	drmmode_ptr drmmode = drmmode_crtc->drmmode;
+	msPixmapPrivPtr ppriv;
+	void *ptr;
+
+	if (!ppix) {
+		if (crtc->randr_crtc->scanout_pixmap) {
+    			ppriv = msGetPixmapPriv(drmmode, crtc->randr_crtc->scanout_pixmap);
+			drmModeRmFB(drmmode->fd, ppriv->fb_id);
+		}
+		if (drmmode_crtc->slave_damage) {
+			DamageUnregister(&crtc->randr_crtc->scanout_pixmap->drawable,
+					 drmmode_crtc->slave_damage);
+			drmmode_crtc->slave_damage = NULL;
+		}
+		return TRUE;
+	}
+
+	ppriv = msGetPixmapPriv(drmmode, ppix);
+	if (!drmmode_crtc->slave_damage) {
+		drmmode_crtc->slave_damage = DamageCreate(NULL, NULL,
+							  DamageReportNone,
+							  TRUE,
+							  crtc->randr_crtc->pScreen,
+							  NULL);
+	}
+	ptr = drmmode_map_slave_bo(drmmode, ppriv);
+	ppix->devPrivate.ptr = ptr;
+	DamageRegister(&ppix->drawable, drmmode_crtc->slave_damage);
+
+	if (ppriv->fb_id == 0) {
+		int r;
+		r = drmModeAddFB(drmmode->fd, ppix->drawable.width,
+				 ppix->drawable.height,
+				 ppix->drawable.depth,
+				 ppix->drawable.bitsPerPixel,
+				 ppix->devKind,
+				 ppriv->backing_bo->handle,
+				 &ppriv->fb_id);
+	}
+	return TRUE;
+}
+#endif
+
 static const xf86CrtcFuncsRec drmmode_crtc_funcs = {
     .dpms = drmmode_crtc_dpms,
     .set_mode_major = drmmode_set_mode_major,
@@ -466,6 +558,9 @@ static const xf86CrtcFuncsRec drmmode_crtc_funcs = {
 
     .gamma_set = drmmode_crtc_gamma_set,
     .destroy = NULL, /* XXX */
+#ifdef MODESETTING_OUTPUT_SLAVE_SUPPORT
+    .set_scanout_pixmap = drmmode_set_scanout_pixmap,
+#endif
 };
 
 static void
@@ -1065,6 +1160,10 @@ Bool drmmode_pre_init(ScrnInfoPtr pScrn, drmmode_ptr drmmode, int cpp)
 	/* workout clones */
 	drmmode_clones_init(pScrn, drmmode);
 
+#if XF86_CRTC_VERSION >= 5
+	xf86ProviderSetup(pScrn, NULL, "modesetting");
+#endif
+
 	xf86InitialConfiguration(pScrn, TRUE);
 
 	return TRUE;
@@ -1324,6 +1423,22 @@ void *drmmode_map_front_bo(drmmode_ptr drmmode)
 	
 }
 
+#ifdef MODESETTING_OUTPUT_SLAVE_SUPPORT
+void *drmmode_map_slave_bo(drmmode_ptr drmmode, msPixmapPrivPtr ppriv)
+{
+        int ret;
+
+        if (ppriv->backing_bo->ptr)
+                return ppriv->backing_bo->ptr;
+
+        ret = dumb_bo_map(drmmode->fd, ppriv->backing_bo);
+        if (ret)
+                return NULL;
+
+        return ppriv->backing_bo->ptr;  
+}
+#endif
+
 Bool drmmode_map_cursor_bos(ScrnInfoPtr pScrn, drmmode_ptr drmmode)
 {
 	xf86CrtcConfigPtr   xf86_config = XF86_CRTC_CONFIG_PTR(pScrn);
diff --git a/hw/xfree86/drivers/modesetting/drmmode_display.h b/hw/xfree86/drivers/modesetting/drmmode_display.h
index fa280bd..24f7960 100644
--- a/hw/xfree86/drivers/modesetting/drmmode_display.h
+++ b/hw/xfree86/drivers/modesetting/drmmode_display.h
@@ -32,6 +32,11 @@
 #include "libudev.h"
 #endif
 
+/* the perfect storm */
+#if XF86_CRTC_VERSION >= 5 && defined(HAVE_DRMPRIMEFDTOHANDLE) && HAVE_SCREEN_SPECIFIC_PRIVATE_KEYS
+#define MODESETTING_OUTPUT_SLAVE_SUPPORT 1
+#endif
+
 struct dumb_bo {
     uint32_t handle;
     uint32_t size;
@@ -58,6 +63,9 @@ typedef struct {
     Bool shadow_enable;
     void *shadow_fb;
 
+#ifdef HAVE_SCREEN_SPECIFIC_PRIVATE_KEYS
+    DevPrivateKeyRec pixmapPrivateKeyRec;
+#endif
 } drmmode_rec, *drmmode_ptr;
 
 typedef struct {
@@ -67,6 +75,7 @@ typedef struct {
     struct dumb_bo *cursor_bo;
     unsigned rotate_fb_id;
     uint16_t lut_r[256], lut_g[256], lut_b[256];
+    DamagePtr slave_damage;
 } drmmode_crtc_private_rec, *drmmode_crtc_private_ptr;
 
 typedef struct {
@@ -90,6 +99,23 @@ typedef struct {
     int enc_clone_mask;
 } drmmode_output_private_rec, *drmmode_output_private_ptr;
 
+#ifdef MODESETTING_OUTPUT_SLAVE_SUPPORT
+typedef struct _msPixmapPriv {
+    uint32_t fb_id;
+    struct dumb_bo *backing_bo; /* if this pixmap is backed by a dumb bo */
+} msPixmapPrivRec, *msPixmapPrivPtr;
+
+
+extern DevPrivateKeyRec msPixmapPrivateKeyRec;
+#define msPixmapPrivateKey (&msPixmapPrivateKeyRec)
+
+#define msGetPixmapPriv(drmmode, p) ((msPixmapPrivPtr)dixGetPrivateAddr(&(p)->devPrivates, &(drmmode)->pixmapPrivateKeyRec))
+
+void *drmmode_map_slave_bo(drmmode_ptr drmmode, msPixmapPrivPtr ppriv);
+Bool drmmode_SetSlaveBO(PixmapPtr ppix,
+			drmmode_ptr drmmode,
+			int fd_handle, int pitch, int size);
+#endif
 
 extern Bool drmmode_pre_init(ScrnInfoPtr pScrn, drmmode_ptr drmmode, int cpp);
 void drmmode_adjust_frame(ScrnInfoPtr pScrn, drmmode_ptr drmmode, int x, int y, int flags);
@@ -105,6 +131,7 @@ Bool drmmode_map_cursor_bos(ScrnInfoPtr pScrn, drmmode_ptr drmmode);
 void drmmode_free_bos(ScrnInfoPtr pScrn, drmmode_ptr drmmode);
 void drmmode_get_default_bpp(ScrnInfoPtr pScrn, drmmode_ptr drmmmode, int *depth, int *bpp);
 
+
 #ifndef DRM_CAP_DUMB_PREFERRED_DEPTH
 #define DRM_CAP_DUMB_PREFERRED_DEPTH 3
 #endif
commit fa171c5a81b1c226b5da54f35e6726d9c8e13afb
Author: Dave Airlie <airlied at redhat.com>
Date:   Tue Jun 5 14:43:21 2012 +0100

    modesetting: add platform bus support

diff --git a/hw/xfree86/drivers/modesetting/driver.c b/hw/xfree86/drivers/modesetting/driver.c
index 8c3f4a4..86be277 100644
--- a/hw/xfree86/drivers/modesetting/driver.c
+++ b/hw/xfree86/drivers/modesetting/driver.c
@@ -52,6 +52,9 @@
 #include "xf86xv.h"
 #include <X11/extensions/Xv.h>
 #include <xorg-server.h>
+#ifdef XSERVER_PLATFORM_BUS
+#include "xf86platformBus.h"
+#endif
 #if XSERVER_LIBPCIACCESS
 #include <pciaccess.h>
 #endif
@@ -88,6 +91,12 @@ static const struct pci_id_match ms_device_match[] = {
 };
 #endif
 
+#ifdef XSERVER_PLATFORM_BUS
+static Bool ms_platform_probe(DriverPtr driver,
+                          int entity_num, int flags, struct xf86_platform_device *device,
+			  intptr_t match_data);
+#endif
+
 _X_EXPORT DriverRec modesetting = {
     1,
     "modesetting",
@@ -99,6 +108,9 @@ _X_EXPORT DriverRec modesetting = {
     NULL,
     ms_device_match,
     ms_pci_probe,
+#ifdef XSERVER_PLATFORM_BUS
+    ms_platform_probe,
+#endif
 };
 
 static SymTabRec Chipsets[] = {
@@ -288,6 +300,40 @@ ms_pci_probe(DriverPtr driver,
 }
 #endif
 
+#ifdef XSERVER_PLATFORM_BUS
+static Bool
+ms_platform_probe(DriverPtr driver,
+              int entity_num, int flags, struct xf86_platform_device *dev, intptr_t match_data)
+{
+    ScrnInfoPtr scrn = NULL;
+    char *path = xf86_get_platform_device_attrib(dev, ODEV_ATTRIB_PATH);
+    int scr_flags = 0;
+
+    if (flags & PLATFORM_PROBE_GPU_SCREEN)
+            scr_flags = XF86_ALLOCATE_GPU_SCREEN;
+
+    if (probe_hw(path)) {
+        scrn = xf86AllocateScreen(driver, scr_flags);
+        xf86AddEntityToScreen(scrn, entity_num);
+
+        scrn->driverName = "modesetting";
+        scrn->name = "modesetting";
+        scrn->PreInit = PreInit;
+        scrn->ScreenInit = ScreenInit;
+        scrn->SwitchMode = SwitchMode;
+        scrn->AdjustFrame = AdjustFrame;
+        scrn->EnterVT = EnterVT;
+        scrn->LeaveVT = LeaveVT;
+        scrn->FreeScreen = FreeScreen;
+        scrn->ValidMode = ValidMode;
+        xf86DrvMsg(scrn->scrnIndex, X_INFO,
+                   "using drv %s\n", path ? path : "default device");
+    }
+
+    return scrn != NULL;
+}
+#endif
+
 static Bool
 Probe(DriverPtr drv, int flags)
 {
@@ -431,7 +477,7 @@ PreInit(ScrnInfoPtr pScrn, int flags)
     rgb defaultWeight = { 0, 0, 0 };
     EntityInfoPtr pEnt;
     EntPtr msEnt = NULL;
-    char *BusID, *devicename;
+    char *BusID = NULL, *devicename;
     Bool prefer_shadow = TRUE;
     uint64_t value = 0;
     int ret;
@@ -477,24 +523,32 @@ PreInit(ScrnInfoPtr pScrn, int flags)
     pScrn->progClock = TRUE;
     pScrn->rgbBits = 8;
 
-    ms->PciInfo = xf86GetPciInfoForEntity(ms->pEnt->index);
-    if (ms->PciInfo) {
-       BusID = malloc(64);
-       sprintf(BusID, "PCI:%d:%d:%d",
+#if XSERVER_PLATFORM_BUS
+    if (pEnt->location.type == BUS_PLATFORM) {
+            char *path = xf86_get_platform_device_attrib(pEnt->location.id.plat, ODEV_ATTRIB_PATH);
+            ms->fd = open_hw(path);
+    }
+    else 
+#endif
+    if (pEnt->location.type == BUS_PCI) {
+        ms->PciInfo = xf86GetPciInfoForEntity(ms->pEnt->index);
+        if (ms->PciInfo) {
+            BusID = malloc(64);
+            sprintf(BusID, "PCI:%d:%d:%d",
 #if XSERVER_LIBPCIACCESS
-	        ((ms->PciInfo->domain << 8) | ms->PciInfo->bus),
-	        ms->PciInfo->dev, ms->PciInfo->func
+                    ((ms->PciInfo->domain << 8) | ms->PciInfo->bus),
+                    ms->PciInfo->dev, ms->PciInfo->func
 #else
-	        ((pciConfigPtr) ms->PciInfo->thisCard)->busnum,
-	        ((pciConfigPtr) ms->PciInfo->thisCard)->devnum,
-	        ((pciConfigPtr) ms->PciInfo->thisCard)->funcnum
+                    ((pciConfigPtr) ms->PciInfo->thisCard)->busnum,
+                    ((pciConfigPtr) ms->PciInfo->thisCard)->devnum,
+                    ((pciConfigPtr) ms->PciInfo->thisCard)->funcnum
 #endif
-	    );
-
-       ms->fd = drmOpen(NULL, BusID);
+                );
+        }
+        ms->fd = drmOpen(NULL, BusID);
     } else {
-       devicename = xf86FindOptionValue(ms->pEnt->device->options, "kmsdev");
-       ms->fd = open_hw(devicename);
+        devicename = xf86FindOptionValue(ms->pEnt->device->options, "kmsdev");
+        ms->fd = open_hw(devicename);
     }
     if (ms->fd < 0)
 	return FALSE;
commit 709dbc68cdea9d282ba318c1cbc76614e98f41c4
Author: Dave Airlie <airlied at redhat.com>
Date:   Wed Jul 25 15:38:34 2012 +1000

    modesetting: fix warning about close being undefined.
    
    Signed-off-by: Dave Airlie <airlied at redhat.com>

diff --git a/hw/xfree86/drivers/modesetting/drmmode_display.c b/hw/xfree86/drivers/modesetting/drmmode_display.c
index 185bfe9..9ee553e 100644
--- a/hw/xfree86/drivers/modesetting/drmmode_display.c
+++ b/hw/xfree86/drivers/modesetting/drmmode_display.c
@@ -32,6 +32,7 @@
 #include <errno.h>
 #include <sys/ioctl.h>
 #include <sys/mman.h>
+#include <unistd.h>
 #include "xf86str.h"
 #include "X11/Xatom.h"
 #include "micmap.h"
commit 71b86ea8dd69f21d090edd4f61698ad11b952d5e
Author: Dave Airlie <airlied at redhat.com>
Date:   Wed Jul 25 15:33:52 2012 +1000

    modesetting: drop useless xf86PciInfo include
    
    Signed-off-by: Dave Airlie <airlied at redhat.com>

diff --git a/hw/xfree86/drivers/modesetting/driver.c b/hw/xfree86/drivers/modesetting/driver.c
index ad817c4..8c3f4a4 100644
--- a/hw/xfree86/drivers/modesetting/driver.c
+++ b/hw/xfree86/drivers/modesetting/driver.c
@@ -38,7 +38,6 @@
 #include "xf86.h"
 #include "xf86_OSproc.h"
 #include "compiler.h"
-#include "xf86PciInfo.h"
 #include "xf86Pci.h"
 #include "mipointer.h"
 #include "micmap.h"
commit cf196efa05bbefdeb43f6e6bcc5f6d9080fea715
Author: Dave Airlie <airlied at redhat.com>
Date:   Fri Jun 22 15:24:43 2012 +0100

    modesetting 0.4.0: bump configure.ac
commit 30ab80ef5421fea9d9dd0779aa138892ff62bd6e
Author: Dave Airlie <airlied at gmail.com>
Date:   Fri Jun 22 15:26:28 2012 +0100

    modesetting: pci probing requires interface version 1.4
    
    Set the drm interface version to 1.4 so we get the bus id correctly.
    
    Signed-off-by: Dave Airlie <airlied at redhat.com>

diff --git a/hw/xfree86/drivers/modesetting/driver.c b/hw/xfree86/drivers/modesetting/driver.c
index f0529f5..ad817c4 100644
--- a/hw/xfree86/drivers/modesetting/driver.c
+++ b/hw/xfree86/drivers/modesetting/driver.c
@@ -215,10 +215,21 @@ static Bool probe_hw_pci(char *dev, struct pci_device *pdev)
 {
     int fd = open_hw(dev);
     char *id, *devid;
+    drmSetVersion sv;
 
     if (fd == -1)
 	return FALSE;
 
+    sv.drm_di_major = 1;
+    sv.drm_di_minor = 4;
+    sv.drm_dd_major = -1;
+    sv.drm_dd_minor = -1;
+    if (drmSetInterfaceVersion(fd, &sv)) {
+        close(fd);
+        return FALSE;
+    }
+
+
     id = drmGetBusid(fd);
     devid = ms_DRICreatePCIBusID(pdev);
     close(fd);
commit ec79187d9a23ba30eafc7ba225049559e6bcb78d
Author: Dave Airlie <airlied at redhat.com>
Date:   Tue Jun 5 14:41:18 2012 +0100

    modesetting: workaround kernel bug reporting 0x0 as valid mins
    
    It reports these but then you can't create a 0 sized bo.
    
    Signed-off-by: Dave Airlie <airlied at redhat.com>

diff --git a/hw/xfree86/drivers/modesetting/drmmode_display.c b/hw/xfree86/drivers/modesetting/drmmode_display.c
index c0cc06b..185bfe9 100644
--- a/hw/xfree86/drivers/modesetting/drmmode_display.c
+++ b/hw/xfree86/drivers/modesetting/drmmode_display.c
@@ -1379,6 +1379,10 @@ void drmmode_get_default_bpp(ScrnInfoPtr pScrn, drmmode_ptr drmmode, int *depth,
 	if (!mode_res)
 		return;
 
+	if (mode_res->min_width == 0)
+		mode_res->min_width = 1;
+	if (mode_res->min_height == 0)
+		mode_res->min_height = 1;
 	/*create a bo */
 	bo = dumb_bo_create(drmmode->fd, mode_res->min_width, mode_res->min_height, 32);
 	if (!bo) {
commit e07c945ab992b1b1acdd9f5554e0688f744e4769
Author: Dave Airlie <airlied at redhat.com>
Date:   Fri Jun 1 12:34:42 2012 +0100

    modesetting: bump to latest X server compat api.
    
    Signed-off-by: Dave Airlie <airlied at redhat.com>

diff --git a/hw/xfree86/drivers/modesetting/compat-api.h b/hw/xfree86/drivers/modesetting/compat-api.h
index 1bb7724..df783a8 100644
--- a/hw/xfree86/drivers/modesetting/compat-api.h
+++ b/hw/xfree86/drivers/modesetting/compat-api.h
@@ -38,4 +38,57 @@
 #define xf86ScrnToScreen(s) screenInfo.screens[(s)->scrnIndex]
 #endif
 
+#ifndef XF86_SCRN_INTERFACE
+
+#define SCRN_ARG_TYPE int
+#define SCRN_INFO_PTR(arg1) ScrnInfoPtr pScrn = xf86Screens[(arg1)]
+
+#define SCREEN_ARG_TYPE int
+#define SCREEN_PTR(arg1) ScreenPtr pScreen = screenInfo.screens[(arg1)]
+
+#define SCREEN_INIT_ARGS_DECL int i, ScreenPtr pScreen, int argc, char **argv
+
+#define BLOCKHANDLER_ARGS_DECL int arg, pointer blockData, pointer pTimeout, pointer pReadmask
+#define BLOCKHANDLER_ARGS arg, blockData, pTimeout, pReadmask
+
+#define CLOSE_SCREEN_ARGS_DECL int scrnIndex, ScreenPtr pScreen
+#define CLOSE_SCREEN_ARGS scrnIndex, pScreen
+
+#define ADJUST_FRAME_ARGS_DECL int arg, int x, int y, int flags
+
+#define SWITCH_MODE_ARGS_DECL int arg, DisplayModePtr mode, int flags
+
+#define FREE_SCREEN_ARGS_DECL int arg, int flags
+
+#define VT_FUNC_ARGS_DECL int arg, int flags
+#define VT_FUNC_ARGS pScrn->scrnIndex, 0
+
+#define XF86_ENABLEDISABLEFB_ARG(x) ((x)->scrnIndex)
+#else
+#define SCRN_ARG_TYPE ScrnInfoPtr
+#define SCRN_INFO_PTR(arg1) ScrnInfoPtr pScrn = (arg1)
+
+#define SCREEN_ARG_TYPE ScreenPtr
+#define SCREEN_PTR(arg1) ScreenPtr pScreen = (arg1)
+
+#define SCREEN_INIT_ARGS_DECL ScreenPtr pScreen, int argc, char **argv
+
+#define BLOCKHANDLER_ARGS_DECL ScreenPtr arg, pointer pTimeout, pointer pReadmask
+#define BLOCKHANDLER_ARGS arg, pTimeout, pReadmask
+
+#define CLOSE_SCREEN_ARGS_DECL ScreenPtr pScreen
+#define CLOSE_SCREEN_ARGS pScreen
+
+#define ADJUST_FRAME_ARGS_DECL ScrnInfoPtr arg, int x, int y
+#define SWITCH_MODE_ARGS_DECL ScrnInfoPtr arg, DisplayModePtr mode
+
+#define FREE_SCREEN_ARGS_DECL ScrnInfoPtr arg
+
+#define VT_FUNC_ARGS_DECL ScrnInfoPtr arg
+#define VT_FUNC_ARGS pScrn
+
+#define XF86_ENABLEDISABLEFB_ARG(x) (x)
+
+#endif
+
 #endif
diff --git a/hw/xfree86/drivers/modesetting/driver.c b/hw/xfree86/drivers/modesetting/driver.c
index 61e0615..f0529f5 100644
--- a/hw/xfree86/drivers/modesetting/driver.c
+++ b/hw/xfree86/drivers/modesetting/driver.c
@@ -60,18 +60,17 @@
 #include "compat-api.h"
 #include "driver.h"
 
-static void AdjustFrame(int scrnIndex, int x, int y, int flags);
-static Bool CloseScreen(int scrnIndex, ScreenPtr pScreen);
-static Bool EnterVT(int scrnIndex, int flags);
+static void AdjustFrame(ADJUST_FRAME_ARGS_DECL);
+static Bool CloseScreen(CLOSE_SCREEN_ARGS_DECL);
+static Bool EnterVT(VT_FUNC_ARGS_DECL);
 static void Identify(int flags);
 static const OptionInfoRec *AvailableOptions(int chipid, int busid);
-static ModeStatus ValidMode(int scrnIndex, DisplayModePtr mode, Bool verbose,
+static ModeStatus ValidMode(SCRN_ARG_TYPE arg, DisplayModePtr mode, Bool verbose,
 			    int flags);
-static void FreeScreen(int scrnIndex, int flags);
-static void LeaveVT(int scrnIndex, int flags);
-static Bool SwitchMode(int scrnIndex, DisplayModePtr mode, int flags);
-static Bool ScreenInit(int scrnIndex, ScreenPtr pScreen, int argc,
-		       char **argv);
+static void FreeScreen(FREE_SCREEN_ARGS_DECL);
+static void LeaveVT(VT_FUNC_ARGS_DECL);
+static Bool SwitchMode(SWITCH_MODE_ARGS_DECL);
+static Bool ScreenInit(SCREEN_INIT_ARGS_DECL);
 static Bool PreInit(ScrnInfoPtr pScrn, int flags);
 
 static Bool Probe(DriverPtr drv, int flags);
@@ -389,14 +388,13 @@ static void dispatch_dirty(ScreenPtr pScreen)
     }
 }
 
-static void msBlockHandler(int i, pointer blockData, pointer pTimeout,
-			   pointer pReadmask)
+static void msBlockHandler(BLOCKHANDLER_ARGS_DECL)
 {
-    ScreenPtr pScreen = screenInfo.screens[i];
+    SCREEN_PTR(arg);
     modesettingPtr ms = modesettingPTR(xf86ScreenToScrn(pScreen));
 
     pScreen->BlockHandler = ms->BlockHandler;
-    pScreen->BlockHandler(i, blockData, pTimeout, pReadmask);
+    pScreen->BlockHandler(BLOCKHANDLER_ARGS);
     pScreen->BlockHandler = msBlockHandler;
     if (ms->dirty_enabled)
 	dispatch_dirty(pScreen);
@@ -658,7 +656,7 @@ msShadowInit(ScreenPtr pScreen)
 }
 
 static Bool
-ScreenInit(int scrnIndex, ScreenPtr pScreen, int argc, char **argv)
+ScreenInit(SCREEN_INIT_ARGS_DECL)
 {
     ScrnInfoPtr pScrn = xf86ScreenToScrn(pScreen);
     modesettingPtr ms = modesettingPTR(pScrn);
@@ -722,7 +720,7 @@ ScreenInit(int scrnIndex, ScreenPtr pScreen, int argc, char **argv)
     fbPictureInit(pScreen, NULL, 0);
 
     if (ms->drmmode.shadow_enable && !msShadowInit(pScreen)) {
-	xf86DrvMsg(scrnIndex, X_ERROR,
+	xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
 		   "shadow fb init failed\n");
 	return FALSE;
     }
@@ -765,13 +763,13 @@ ScreenInit(int scrnIndex, ScreenPtr pScreen, int argc, char **argv)
     if (serverGeneration == 1)
 	xf86ShowUnusedOptions(pScrn->scrnIndex, pScrn->options);
 
-    return EnterVT(scrnIndex, 1);
+    return EnterVT(VT_FUNC_ARGS);
 }
 
 static void
-AdjustFrame(int scrnIndex, int x, int y, int flags)
+AdjustFrame(ADJUST_FRAME_ARGS_DECL)
 {
-    ScrnInfoPtr pScrn = xf86Screens[scrnIndex];
+    SCRN_INFO_PTR(arg);
     xf86CrtcConfigPtr config = XF86_CRTC_CONFIG_PTR(pScrn);
     xf86OutputPtr output = config->output[config->compat_output];
     xf86CrtcPtr crtc = output->crtc;
@@ -785,15 +783,16 @@ AdjustFrame(int scrnIndex, int x, int y, int flags)
 }
 
 static void
-FreeScreen(int scrnIndex, int flags)
+FreeScreen(FREE_SCREEN_ARGS_DECL)
 {
-    FreeRec(xf86Screens[scrnIndex]);
+    SCRN_INFO_PTR(arg);
+    FreeRec(pScrn);
 }
 
 static void
-LeaveVT(int scrnIndex, int flags)
+LeaveVT(VT_FUNC_ARGS_DECL)
 {
-    ScrnInfoPtr pScrn = xf86Screens[scrnIndex];
+    SCRN_INFO_PTR(arg);
     modesettingPtr ms = modesettingPTR(pScrn);
     xf86_hide_cursors(pScrn);
 
@@ -806,9 +805,9 @@ LeaveVT(int scrnIndex, int flags)
  * This gets called when gaining control of the VT, and from ScreenInit().
  */
 static Bool
-EnterVT(int scrnIndex, int flags)
+EnterVT(VT_FUNC_ARGS_DECL)
 {
-    ScrnInfoPtr pScrn = xf86Screens[scrnIndex];
+    SCRN_INFO_PTR(arg);
     modesettingPtr ms = modesettingPTR(pScrn);
 
     pScrn->vtSema = TRUE;
@@ -825,17 +824,17 @@ EnterVT(int scrnIndex, int flags)
 }
 
 static Bool
-SwitchMode(int scrnIndex, DisplayModePtr mode, int flags)
+SwitchMode(SWITCH_MODE_ARGS_DECL)
 {
-    ScrnInfoPtr pScrn = xf86Screens[scrnIndex];
+    SCRN_INFO_PTR(arg);
 
     return xf86SetSingleMode(pScrn, mode, RR_Rotate_0);
 }
 
 static Bool
-CloseScreen(int scrnIndex, ScreenPtr pScreen)
+CloseScreen(CLOSE_SCREEN_ARGS_DECL)
 {
-    ScrnInfoPtr pScrn = xf86Screens[scrnIndex];
+    ScrnInfoPtr pScrn = xf86ScreenToScrn(pScreen);
     modesettingPtr ms = modesettingPTR(pScrn);
 
     if (ms->damage) {
@@ -854,7 +853,7 @@ CloseScreen(int scrnIndex, ScreenPtr pScreen)
     drmmode_free_bos(pScrn, &ms->drmmode);
 
     if (pScrn->vtSema) {
-	LeaveVT(scrnIndex, 0);
+        LeaveVT(VT_FUNC_ARGS);
     }
 
     pScreen->CreateScreenResources = ms->createScreenResources;
@@ -862,11 +861,11 @@ CloseScreen(int scrnIndex, ScreenPtr pScreen)
 
     pScrn->vtSema = FALSE;
     pScreen->CloseScreen = ms->CloseScreen;
-    return (*pScreen->CloseScreen) (scrnIndex, pScreen);
+    return (*pScreen->CloseScreen) (CLOSE_SCREEN_ARGS);
 }
 
 static ModeStatus
-ValidMode(int scrnIndex, DisplayModePtr mode, Bool verbose, int flags)
+ValidMode(SCRN_ARG_TYPE arg, DisplayModePtr mode, Bool verbose, int flags)
 {
     return MODE_OK;
 }
commit 1c01090f6485cb82c2511fb461e66ff15a097358
Author: Dave Airlie <airlied at redhat.com>
Date:   Wed May 23 11:31:39 2012 +0100

    modesetting: fix make distcheck
    
    add missing compat header file.
    
    Signed-off-by: Dave Airlie <airlied at redhat.com>

diff --git a/hw/xfree86/drivers/modesetting/Makefile.am b/hw/xfree86/drivers/modesetting/Makefile.am
index 68a63fa..3cc4624 100644
--- a/hw/xfree86/drivers/modesetting/Makefile.am
+++ b/hw/xfree86/drivers/modesetting/Makefile.am
@@ -32,6 +32,7 @@ modesetting_drv_la_LIBADD = @UDEV_LIBS@ @DRM_LIBS@
 modesetting_drv_ladir = @moduledir@/drivers
 
 modesetting_drv_la_SOURCES = \
+	 compat-api.h \
 	 driver.c \
 	 driver.h \
 	 drmmode_display.c \
commit ef47a1b3bfec33d4031af2e01bdd46d634be2f51
Author: Dave Airlie <airlied at redhat.com>
Date:   Wed May 23 11:21:55 2012 +0100

    modesetting: convert to new scrn conversion APIs.
    
    Generated with util/modular/x-driver-screen-scrn-conv.sh
    
    Signed-off-by: Dave Airlie <airlied at redhat.com>

diff --git a/hw/xfree86/drivers/modesetting/driver.c b/hw/xfree86/drivers/modesetting/driver.c
index ce4cdec..61e0615 100644
--- a/hw/xfree86/drivers/modesetting/driver.c
+++ b/hw/xfree86/drivers/modesetting/driver.c
@@ -348,7 +348,7 @@ GetRec(ScrnInfoPtr pScrn)
 
 static void dispatch_dirty(ScreenPtr pScreen)
 {
-    ScrnInfoPtr scrn = xf86Screens[pScreen->myNum];
+    ScrnInfoPtr scrn = xf86ScreenToScrn(pScreen);
     modesettingPtr ms = modesettingPTR(scrn);
     RegionPtr dirty = DamageRegion(ms->damage);
     unsigned num_cliprects = REGION_NUM_RECTS(dirty);
@@ -393,7 +393,7 @@ static void msBlockHandler(int i, pointer blockData, pointer pTimeout,
 			   pointer pReadmask)
 {
     ScreenPtr pScreen = screenInfo.screens[i];
-    modesettingPtr ms = modesettingPTR(xf86Screens[pScreen->myNum]);
+    modesettingPtr ms = modesettingPTR(xf86ScreenToScrn(pScreen));
 
     pScreen->BlockHandler = ms->BlockHandler;
     pScreen->BlockHandler(i, blockData, pTimeout, pReadmask);
@@ -586,7 +586,7 @@ static void *
 msShadowWindow(ScreenPtr screen, CARD32 row, CARD32 offset, int mode,
 	       CARD32 *size, void *closure)
 {
-    ScrnInfoPtr pScrn = xf86Screens[screen->myNum];
+    ScrnInfoPtr pScrn = xf86ScreenToScrn(screen);
     modesettingPtr ms = modesettingPTR(pScrn);
     int stride;
 
@@ -599,7 +599,7 @@ msShadowWindow(ScreenPtr screen, CARD32 row, CARD32 offset, int mode,
 static Bool
 CreateScreenResources(ScreenPtr pScreen)
 {
-    ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
+    ScrnInfoPtr pScrn = xf86ScreenToScrn(pScreen);
     modesettingPtr ms = modesettingPTR(pScrn);
     PixmapPtr rootPixmap;
     Bool ret;
@@ -660,7 +660,7 @@ msShadowInit(ScreenPtr pScreen)
 static Bool
 ScreenInit(int scrnIndex, ScreenPtr pScreen, int argc, char **argv)
 {
-    ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
+    ScrnInfoPtr pScrn = xf86ScreenToScrn(pScreen);
     modesettingPtr ms = modesettingPTR(pScrn);
     VisualPtr visual;
     int ret;
diff --git a/hw/xfree86/drivers/modesetting/drmmode_display.c b/hw/xfree86/drivers/modesetting/drmmode_display.c
index 22fc66a..c0cc06b 100644
--- a/hw/xfree86/drivers/modesetting/drmmode_display.c
+++ b/hw/xfree86/drivers/modesetting/drmmode_display.c
@@ -938,7 +938,7 @@ drmmode_xf86crtc_resize (ScrnInfoPtr scrn, int width, int height)
 	drmmode_ptr drmmode = drmmode_crtc->drmmode;
 	struct dumb_bo *old_front = NULL;
 	Bool	    ret;
-	ScreenPtr   screen = screenInfo.screens[scrn->scrnIndex];
+	ScreenPtr   screen = xf86ScrnToScreen(scrn);
 	uint32_t    old_fb_id;
 	int	    i, pitch, old_width, old_height, old_pitch;
 	int cpp = (scrn->bitsPerPixel + 7) / 8;
@@ -1229,7 +1229,7 @@ drmmode_handle_uevents(int fd, void *closure)
 	if (!dev)
 		return;
 
-	RRGetInfo(screenInfo.screens[scrn->scrnIndex], TRUE);
+	RRGetInfo(xf86ScrnToScreen(scrn), TRUE);
 	udev_device_unref(dev);
 }
 #endif
commit 3e46d578d8c40c95343278db0a66c931e85247c7
Author: Dave Airlie <airlied at redhat.com>
Date:   Wed May 23 11:21:39 2012 +0100

    modesetting: add compat header file
    
    Signed-off-by: Dave Airlie <airlied at redhat.com>

diff --git a/hw/xfree86/drivers/modesetting/compat-api.h b/hw/xfree86/drivers/modesetting/compat-api.h
new file mode 100644
index 0000000..1bb7724
--- /dev/null
+++ b/hw/xfree86/drivers/modesetting/compat-api.h
@@ -0,0 +1,41 @@
+/*
+ * 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.
+ *
+ * Author: Dave Airlie <airlied at redhat.com>
+ */
+
+/* this file provides API compat between server post 1.13 and pre it,
+   it should be reused inside as many drivers as possible */
+#ifndef COMPAT_API_H
+#define COMPAT_API_H
+
+#ifndef GLYPH_HAS_GLYPH_PICTURE_ACCESSOR
+#define GetGlyphPicture(g, s) GlyphPicture((g))[(s)->myNum]
+#define SetGlyphPicture(g, s, p) GlyphPicture((g))[(s)->myNum] = p
+#endif
+
+#ifndef XF86_HAS_SCRN_CONV
+#define xf86ScreenToScrn(s) xf86Screens[(s)->myNum]
+#define xf86ScrnToScreen(s) screenInfo.screens[(s)->scrnIndex]
+#endif
+
+#endif
diff --git a/hw/xfree86/drivers/modesetting/driver.c b/hw/xfree86/drivers/modesetting/driver.c
index e977150..ce4cdec 100644
--- a/hw/xfree86/drivers/modesetting/driver.c
+++ b/hw/xfree86/drivers/modesetting/driver.c
@@ -57,6 +57,7 @@
 #include <pciaccess.h>
 #endif
 
+#include "compat-api.h"
 #include "driver.h"
 
 static void AdjustFrame(int scrnIndex, int x, int y, int flags);
diff --git a/hw/xfree86/drivers/modesetting/drmmode_display.c b/hw/xfree86/drivers/modesetting/drmmode_display.c
index 71f2e02..22fc66a 100644
--- a/hw/xfree86/drivers/modesetting/drmmode_display.c
+++ b/hw/xfree86/drivers/modesetting/drmmode_display.c
@@ -49,6 +49,7 @@
 #define DPMS_SERVER
 #include <X11/extensions/dpms.h>
 #endif
+#include "compat-api.h"
 
 static struct dumb_bo *dumb_bo_create(int fd,
 			  const unsigned width, const unsigned height,
commit e8da587845978ad66c3b3e2e085fd99c16b5d3c8
Author: Dave Airlie <airlied at redhat.com>
Date:   Wed May 9 09:33:54 2012 +0100

    bump version to 0.3.0
commit 62543946490e7decae4f6549d83072f004e850d4
Author: Matt Turner <mattst88 at gmail.com>
Date:   Wed May 9 00:26:29 2012 -0400

    configure.ac: remove DRI and RENDER
    
    Driver doesn't support either of these.
    
    Signed-off-by: Matt Turner <mattst88 at gmail.com>
    Signed-off-by: Dave Airlie <airlied at redhat.com>
commit 7dc22b7911ac3d5c131075903e3fbf52c58eac15
Author: Dave Airlie <airlied at redhat.com>
Date:   Wed May 9 09:32:05 2012 +0100

    modesetting: make sure the pci device corresponds to the drm device
    
    If we get asked to pci open a device with a kms path override,
    make sure they match, otherwise this driver can steal the primary
    device binding for a usb adaptor.
    
    The driver should fallback to the old probe entry point in this case.
    
    Signed-off-by: Dave Airlie <airlied at redhat.com>

diff --git a/hw/xfree86/drivers/modesetting/driver.c b/hw/xfree86/drivers/modesetting/driver.c
index 2c9878c..e977150 100644
--- a/hw/xfree86/drivers/modesetting/driver.c
+++ b/hw/xfree86/drivers/modesetting/driver.c
@@ -198,6 +198,39 @@ static Bool probe_hw(char *dev)
     return FALSE;
 }
 
+static char *
+ms_DRICreatePCIBusID(const struct pci_device *dev)
+{
+    char *busID;
+
+    if (asprintf(&busID, "pci:%04x:%02x:%02x.%d",
+                 dev->domain, dev->bus, dev->dev, dev->func) == -1)
+        return NULL;
+
+    return busID;
+}
+
+
+static Bool probe_hw_pci(char *dev, struct pci_device *pdev)
+{
+    int fd = open_hw(dev);
+    char *id, *devid;
+
+    if (fd == -1)
+	return FALSE;
+
+    id = drmGetBusid(fd);
+    devid = ms_DRICreatePCIBusID(pdev);
+    close(fd);
+
+    if (!id || !devid)
+	return FALSE;
+
+    if (!strcmp(id, devid))
+	return TRUE;
+
+    return FALSE;
+}
 static const OptionInfoRec *
 AvailableOptions(int chipid, int busid)
 {
@@ -219,7 +252,7 @@ ms_pci_probe(DriverPtr driver,
 						  scrn->entityInstanceList[0]);
 
 	devpath = xf86FindOptionValue(devSection->options, "kmsdev");
-	if (probe_hw(devpath)) {
+	if (probe_hw_pci(devpath, dev)) {
 	    scrn->driverVersion = 1;
 	    scrn->driverName = "modesetting";
 	    scrn->name = "modeset";
commit d063f64b5c8c8c27fca41163c93dbca06a774d1c
Author: Dave Airlie <airlied at redhat.com>
Date:   Tue May 1 17:12:29 2012 +0100

    modesetting: attempt to work out if we want 24 or 32bpp
    
    the cirrus driver presents certain challenges, and this is a
    workaround, until we can possibly agree some sane interface
    for exposing this information.
    
    Signed-off-by: Dave Airlie <airlied at redhat.com>

diff --git a/hw/xfree86/drivers/modesetting/driver.c b/hw/xfree86/drivers/modesetting/driver.c
index fb4b410..2c9878c 100644
--- a/hw/xfree86/drivers/modesetting/driver.c
+++ b/hw/xfree86/drivers/modesetting/driver.c
@@ -59,10 +59,6 @@
 
 #include "driver.h"
 
-#ifndef DRM_CAP_DUMB_PREFER_SHADOW
-#define DRM_CAP_DUMB_PREFER_SHADOW 4
-#endif
-
 static void AdjustFrame(int scrnIndex, int x, int y, int flags);
 static Bool CloseScreen(int scrnIndex, ScreenPtr pScreen);
 static Bool EnterVT(int scrnIndex, int flags);
@@ -397,6 +393,8 @@ PreInit(ScrnInfoPtr pScrn, int flags)
     Bool prefer_shadow = TRUE;
     uint64_t value = 0;
     int ret;
+    int bppflags;
+    int defaultdepth, defaultbpp;
 
     if (pScrn->numEntities != 1)
 	return FALSE;
@@ -459,9 +457,16 @@ PreInit(ScrnInfoPtr pScrn, int flags)
     if (ms->fd < 0)
 	return FALSE;
 
+    ms->drmmode.fd = ms->fd;
+
+    drmmode_get_default_bpp(pScrn, &ms->drmmode, &defaultdepth, &defaultbpp);
+    if (defaultdepth == 24 && defaultbpp == 24)
+	    bppflags = Support24bppFb;
+    else
+	    bppflags = PreferConvert24to32 | SupportConvert24to32 | Support32bppFb;
+    
     if (!xf86SetDepthBpp
-	(pScrn, 0, 0, 0,
-	 PreferConvert24to32 | SupportConvert24to32 | Support32bppFb))
+	(pScrn, defaultdepth, defaultdepth, defaultbpp, bppflags))
 	return FALSE;
 
     switch (pScrn->depth) {
@@ -501,7 +506,6 @@ PreInit(ScrnInfoPtr pScrn, int flags)
     ms->drmmode.shadow_enable = xf86ReturnOptValBool(ms->Options, OPTION_SHADOW_FB, prefer_shadow);
 
     xf86DrvMsg(pScrn->scrnIndex, X_INFO, "ShadowFB: preferred %s, enabled %s\n", prefer_shadow ? "YES" : "NO", ms->drmmode.shadow_enable ? "YES" : "NO");
-    ms->drmmode.fd = ms->fd;
     if (drmmode_pre_init(pScrn, &ms->drmmode, pScrn->bitsPerPixel / 8) == FALSE) {
 	xf86DrvMsg(pScrn->scrnIndex, X_ERROR, "KMS setup failed\n");
 	goto fail;
diff --git a/hw/xfree86/drivers/modesetting/drmmode_display.c b/hw/xfree86/drivers/modesetting/drmmode_display.c
index 7fa933a..71f2e02 100644
--- a/hw/xfree86/drivers/modesetting/drmmode_display.c
+++ b/hw/xfree86/drivers/modesetting/drmmode_display.c
@@ -1355,3 +1355,50 @@ void drmmode_free_bos(ScrnInfoPtr pScrn, drmmode_ptr drmmode)
 		dumb_bo_destroy(drmmode->fd, drmmode_crtc->cursor_bo);
 	}
 }
+
+/* ugly workaround to see if we can create 32bpp */
+void drmmode_get_default_bpp(ScrnInfoPtr pScrn, drmmode_ptr drmmode, int *depth, int *bpp)
+{
+	drmModeResPtr mode_res;
+	uint64_t value;
+	struct dumb_bo *bo;
+	uint32_t fb_id;
+	int ret;
+
+	/* 16 is fine */
+	ret = drmGetCap(drmmode->fd, DRM_CAP_DUMB_PREFERRED_DEPTH, &value);
+	if (!ret && (value == 16 || value == 8)) {
+		*depth = value;
+		*bpp = value;
+		return;
+	}
+
+	*depth = 24;
+	mode_res = drmModeGetResources(drmmode->fd);
+	if (!mode_res)
+		return;
+
+	/*create a bo */
+	bo = dumb_bo_create(drmmode->fd, mode_res->min_width, mode_res->min_height, 32);
+	if (!bo) {
+		*bpp = 24;
+		goto out;
+	}
+
+	ret = drmModeAddFB(drmmode->fd, mode_res->min_width, mode_res->min_height,
+			    24, 32, bo->pitch, bo->handle, &fb_id);
+
+	if (ret) {
+		*bpp = 24;
+		dumb_bo_destroy(drmmode->fd, bo);
+		goto out;
+	}
+
+	drmModeRmFB(drmmode->fd, fb_id);
+	*bpp = 32;
+
+	dumb_bo_destroy(drmmode->fd, bo);
+out:	
+	drmModeFreeResources(mode_res);
+	return;
+}
diff --git a/hw/xfree86/drivers/modesetting/drmmode_display.h b/hw/xfree86/drivers/modesetting/drmmode_display.h
index e83167b..fa280bd 100644
--- a/hw/xfree86/drivers/modesetting/drmmode_display.h
+++ b/hw/xfree86/drivers/modesetting/drmmode_display.h
@@ -103,4 +103,14 @@ Bool drmmode_create_initial_bos(ScrnInfoPtr pScrn, drmmode_ptr drmmode);
 void *drmmode_map_front_bo(drmmode_ptr drmmode);
 Bool drmmode_map_cursor_bos(ScrnInfoPtr pScrn, drmmode_ptr drmmode);
 void drmmode_free_bos(ScrnInfoPtr pScrn, drmmode_ptr drmmode);
+void drmmode_get_default_bpp(ScrnInfoPtr pScrn, drmmode_ptr drmmmode, int *depth, int *bpp);
+
+#ifndef DRM_CAP_DUMB_PREFERRED_DEPTH
+#define DRM_CAP_DUMB_PREFERRED_DEPTH 3
+#endif
+#ifndef DRM_CAP_DUMB_PREFER_SHADOW
+#define DRM_CAP_DUMB_PREFER_SHADOW 4
+#endif
+
+
 #endif
commit 610f532e6a3d934c473d2d16dff95f582285b2eb
Author: Dave Airlie <airlied at redhat.com>
Date:   Tue May 1 16:52:18 2012 +0100

    modesetting: move opening kernel device to before setting depth
    
    due to interaction between option handling and set depth, we need
    to what fbdev does to get the device path early.
    
    Signed-off-by: Dave Airlie <airlied at redhat.com>

diff --git a/hw/xfree86/drivers/modesetting/driver.c b/hw/xfree86/drivers/modesetting/driver.c
index 827438a..fb4b410 100644
--- a/hw/xfree86/drivers/modesetting/driver.c
+++ b/hw/xfree86/drivers/modesetting/driver.c
@@ -437,6 +437,28 @@ PreInit(ScrnInfoPtr pScrn, int flags)
     pScrn->progClock = TRUE;
     pScrn->rgbBits = 8;
 
+    ms->PciInfo = xf86GetPciInfoForEntity(ms->pEnt->index);
+    if (ms->PciInfo) {
+       BusID = malloc(64);
+       sprintf(BusID, "PCI:%d:%d:%d",
+#if XSERVER_LIBPCIACCESS
+	        ((ms->PciInfo->domain << 8) | ms->PciInfo->bus),
+	        ms->PciInfo->dev, ms->PciInfo->func
+#else
+	        ((pciConfigPtr) ms->PciInfo->thisCard)->busnum,
+	        ((pciConfigPtr) ms->PciInfo->thisCard)->devnum,
+	        ((pciConfigPtr) ms->PciInfo->thisCard)->funcnum
+#endif
+	    );
+
+       ms->fd = drmOpen(NULL, BusID);
+    } else {
+       devicename = xf86FindOptionValue(ms->pEnt->device->options, "kmsdev");
+       ms->fd = open_hw(devicename);
+    }
+    if (ms->fd < 0)
+	return FALSE;
+
     if (!xf86SetDepthBpp
 	(pScrn, 0, 0, 0,
 	 PreferConvert24to32 | SupportConvert24to32 | Support32bppFb))
@@ -462,28 +484,6 @@ PreInit(ScrnInfoPtr pScrn, int flags)
     memcpy(ms->Options, Options, sizeof(Options));
     xf86ProcessOptions(pScrn->scrnIndex, pScrn->options, ms->Options);
 
-    ms->PciInfo = xf86GetPciInfoForEntity(ms->pEnt->index);
-    if (ms->PciInfo) {
-       BusID = malloc(64);
-       sprintf(BusID, "PCI:%d:%d:%d",
-#if XSERVER_LIBPCIACCESS
-	        ((ms->PciInfo->domain << 8) | ms->PciInfo->bus),
-	        ms->PciInfo->dev, ms->PciInfo->func
-#else
-	        ((pciConfigPtr) ms->PciInfo->thisCard)->busnum,
-	        ((pciConfigPtr) ms->PciInfo->thisCard)->devnum,
-	        ((pciConfigPtr) ms->PciInfo->thisCard)->funcnum
-#endif
-	    );
-
-       ms->fd = drmOpen(NULL, BusID);
-    } else {
-       devicename = xf86GetOptValString(ms->Options, OPTION_DEVICE_PATH);
-       ms->fd = open_hw(devicename);
-    }
-    if (ms->fd < 0)
-	return FALSE;
-
     if (!xf86SetWeight(pScrn, defaultWeight, defaultWeight))
 	return FALSE;
     if (!xf86SetDefaultVisual(pScrn, -1))
commit 00c663a3bc76d567ad7edd6d6ef3f7f725b5df3a
Author: Dave Airlie <airlied at redhat.com>
Date:   Tue Apr 17 11:50:40 2012 +0100

    modesetting: add set/drop master around VT switch

diff --git a/hw/xfree86/drivers/modesetting/driver.c b/hw/xfree86/drivers/modesetting/driver.c
index 516bf61..827438a 100644
--- a/hw/xfree86/drivers/modesetting/driver.c
+++ b/hw/xfree86/drivers/modesetting/driver.c
@@ -756,10 +756,12 @@ static void
 LeaveVT(int scrnIndex, int flags)
 {
     ScrnInfoPtr pScrn = xf86Screens[scrnIndex];
-
+    modesettingPtr ms = modesettingPTR(pScrn);
     xf86_hide_cursors(pScrn);
 
     pScrn->vtSema = FALSE;
+
+    drmDropMaster(ms->fd);
 }
 
 /*
@@ -773,6 +775,11 @@ EnterVT(int scrnIndex, int flags)
 
     pScrn->vtSema = TRUE;
 
+    if (drmSetMaster(ms->fd)) {
+        xf86DrvMsg(pScrn->scrnIndex, X_WARNING, "drmSetMaster failed: %s\n",
+                   strerror(errno));
+    }
+
     if (!drmmode_set_desired_modes(pScrn, &ms->drmmode))
 	return FALSE;
 
@@ -815,8 +822,6 @@ CloseScreen(int scrnIndex, ScreenPtr pScreen)
     pScreen->CreateScreenResources = ms->createScreenResources;
     pScreen->BlockHandler = ms->BlockHandler;
 
-    drmDropMaster(ms->fd);
-
     pScrn->vtSema = FALSE;
     pScreen->CloseScreen = ms->CloseScreen;
     return (*pScreen->CloseScreen) (scrnIndex, pScreen);
commit 001dec898098e11c569abc20a307b3c2af2e2184
Author: Dave Airlie <airlied at redhat.com>
Date:   Tue Apr 17 11:48:03 2012 +0100

    cursor: hide cursors on LeaveVT

diff --git a/hw/xfree86/drivers/modesetting/driver.c b/hw/xfree86/drivers/modesetting/driver.c
index b776ca1..516bf61 100644
--- a/hw/xfree86/drivers/modesetting/driver.c
+++ b/hw/xfree86/drivers/modesetting/driver.c
@@ -757,6 +757,8 @@ LeaveVT(int scrnIndex, int flags)
 {
     ScrnInfoPtr pScrn = xf86Screens[scrnIndex];
 
+    xf86_hide_cursors(pScrn);
+
     pScrn->vtSema = FALSE;
 }
 
commit d5d5b407436dfdbffcd56bbefecf17d11750dddf
Author: Dave Airlie <airlied at redhat.com>
Date:   Sat Apr 14 19:21:47 2012 +0100

    dirty: check malloc return
    
    Suggested by keithp.
    
    Signed-off-by: Dave Airlie <airlied at redhat.com>

diff --git a/hw/xfree86/drivers/modesetting/driver.c b/hw/xfree86/drivers/modesetting/driver.c
index 95d6b90..b776ca1 100644
--- a/hw/xfree86/drivers/modesetting/driver.c
+++ b/hw/xfree86/drivers/modesetting/driver.c
@@ -327,7 +327,10 @@ static void dispatch_dirty(ScreenPtr pScreen)
 	drmModeClip *clip = malloc(num_cliprects * sizeof(drmModeClip));
 	BoxPtr rect = REGION_RECTS(dirty);
 	int i, ret;
-	    
+	
+	if (!clip)
+		return;
+
 	/* XXX no need for copy? */
 	for (i = 0; i < num_cliprects; i++, rect++) {
 	    clip[i].x1 = rect->x1;
commit 6c1b5cb903f2ff9cb915273835c301d6ac255f45
Author: Dave Airlie <airlied at redhat.com>
Date:   Sat Apr 14 15:01:16 2012 +0100

    drop use of alloca, just use malloc/free
    
    Reported-by: Alan Coopersmith <alan.coopersmith at oracle.com>
    Signed-off-by: Dave Airlie <airlied at redhat.com>

diff --git a/hw/xfree86/drivers/modesetting/driver.c b/hw/xfree86/drivers/modesetting/driver.c
index 87431ff..95d6b90 100644
--- a/hw/xfree86/drivers/modesetting/driver.c
+++ b/hw/xfree86/drivers/modesetting/driver.c
@@ -324,7 +324,7 @@ static void dispatch_dirty(ScreenPtr pScreen)
     unsigned num_cliprects = REGION_NUM_RECTS(dirty);
 
     if (num_cliprects) {
-	drmModeClip *clip = alloca(num_cliprects * sizeof(drmModeClip));
+	drmModeClip *clip = malloc(num_cliprects * sizeof(drmModeClip));
 	BoxPtr rect = REGION_RECTS(dirty);
 	int i, ret;
 	    
@@ -338,6 +338,7 @@ static void dispatch_dirty(ScreenPtr pScreen)
 
 	/* TODO query connector property to see if this is needed */
 	ret = drmModeDirtyFB(ms->fd, ms->drmmode.fb_id, clip, num_cliprects);
+	free(clip);
 	if (ret) {
 	    if (ret == -EINVAL || ret == -ENOSYS) {
 		ms->dirty_enabled = FALSE;
commit 0e8ee1cf4f3377a2916c43527ae0dc6cb07a67ec
Author: Dave Airlie <airlied at redhat.com>
Date:   Fri Mar 23 14:54:05 2012 +0000

    modesetting: fix build against older Xext
commit 53204d5c8bd83c957fbdb7d3dc2891118ed7658b
Author: Sascha Hauer <s.hauer at pengutronix.de>
Date:   Sat Mar 3 14:09:25 2012 +0100

    make busID non mandatory
    
    Currently the driver only probes a device when it has a
    busID. The busID is optional so don't depend on it.
    
    Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
    Signed-off-by: Dave Airlie <airlied at redhat.com>

diff --git a/hw/xfree86/drivers/modesetting/driver.c b/hw/xfree86/drivers/modesetting/driver.c
index 7fa2630..87431ff 100644
--- a/hw/xfree86/drivers/modesetting/driver.c
+++ b/hw/xfree86/drivers/modesetting/driver.c
@@ -273,32 +273,30 @@ Probe(DriverPtr drv, int flags)
     for (i = 0; i < numDevSections; i++) {
 
 	dev = xf86FindOptionValue(devSections[i]->options,"kmsdev");
-	if (devSections[i]->busID) {
-	    if (probe_hw(dev)) {
-		int entity;
-		entity = xf86ClaimFbSlot(drv, 0, devSections[i], TRUE);
-		scrn = xf86ConfigFbEntity(scrn, 0, entity,
-					  NULL, NULL, NULL, NULL);
-	    }
+	if (probe_hw(dev)) {
+	    int entity;
+	    entity = xf86ClaimFbSlot(drv, 0, devSections[i], TRUE);
+	    scrn = xf86ConfigFbEntity(scrn, 0, entity,
+				  NULL, NULL, NULL, NULL);
+	}
 
-	    if (scrn) {
-		foundScreen = TRUE;
-		scrn->driverVersion = 1;
-		scrn->driverName = "modesetting";
-		scrn->name = "modesetting";
-		scrn->Probe = Probe;
-		scrn->PreInit = PreInit;
-		scrn->ScreenInit = ScreenInit;
-		scrn->SwitchMode = SwitchMode;
-		scrn->AdjustFrame = AdjustFrame;
-		scrn->EnterVT = EnterVT;
-		scrn->LeaveVT = LeaveVT;
-		scrn->FreeScreen = FreeScreen;
-		scrn->ValidMode = ValidMode;
-
-		xf86DrvMsg(scrn->scrnIndex, X_INFO,
+	if (scrn) {
+	    foundScreen = TRUE;
+	    scrn->driverVersion = 1;
+	    scrn->driverName = "modesetting";
+	    scrn->name = "modesetting";
+	    scrn->Probe = Probe;
+	    scrn->PreInit = PreInit;
+	    scrn->ScreenInit = ScreenInit;
+	    scrn->SwitchMode = SwitchMode;
+	    scrn->AdjustFrame = AdjustFrame;
+	    scrn->EnterVT = EnterVT;
+	    scrn->LeaveVT = LeaveVT;
+	    scrn->FreeScreen = FreeScreen;
+	    scrn->ValidMode = ValidMode;
+
+	    xf86DrvMsg(scrn->scrnIndex, X_INFO,
 			   "using %s\n", dev ? dev : "default device");
-	    }
 	}
     }
 
commit bb7e39c1f2112f5fb7e87baddb114ab164fbc749
Author: Sascha Hauer <s.hauer at pengutronix.de>
Date:   Sat Mar 3 14:09:27 2012 +0100

    do not bail out on non pci devices
    
    To make the driver work on nin PCI devices we shouldn't bail
    out in this case.
    
    Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
    Signed-off-by: Dave Airlie <airlied at redhat.com>

diff --git a/hw/xfree86/drivers/modesetting/driver.c b/hw/xfree86/drivers/modesetting/driver.c
index 45643a8..7fa2630 100644
--- a/hw/xfree86/drivers/modesetting/driver.c
+++ b/hw/xfree86/drivers/modesetting/driver.c
@@ -415,9 +415,6 @@ PreInit(ScrnInfoPtr pScrn, int flags)
 
     pScrn->displayWidth = 640;	       /* default it */
 
-    if (ms->pEnt->location.type != BUS_PCI)
-	return FALSE;
-
     /* Allocate an entity private if necessary */
     if (xf86IsEntityShared(pScrn->entityList[0])) {
 	msEnt = xf86GetEntityPrivate(pScrn->entityList[0],
commit 2b6848fcb3f85f9ce18a6de1dc6c3ac047101aa8
Author: Sascha Hauer <s.hauer at pengutronix.de>
Date:   Sat Mar 3 14:09:26 2012 +0100

    Fix non PCI device probing
    
    When no devicename is found in the option then the driver probes
    by PciInfo no matter if it's valid or not. Instead of doing this
    use PciInfo only when it's valid and fall back to the devicename
    otherwise. With devicename probing use open_hw() to fall back
    on the KMSDEVICE environment variable or to the default device.
    
    Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
    Signed-off-by: Dave Airlie <airlied at redhat.com>

diff --git a/hw/xfree86/drivers/modesetting/driver.c b/hw/xfree86/drivers/modesetting/driver.c
index dc90e04..45643a8 100644
--- a/hw/xfree86/drivers/modesetting/driver.c
+++ b/hw/xfree86/drivers/modesetting/driver.c
@@ -418,8 +418,6 @@ PreInit(ScrnInfoPtr pScrn, int flags)
     if (ms->pEnt->location.type != BUS_PCI)
 	return FALSE;
 
-    ms->PciInfo = xf86GetPciInfoForEntity(ms->pEnt->index);
-
     /* Allocate an entity private if necessary */
     if (xf86IsEntityShared(pScrn->entityList[0])) {
 	msEnt = xf86GetEntityPrivate(pScrn->entityList[0],
@@ -465,8 +463,8 @@ PreInit(ScrnInfoPtr pScrn, int flags)
     memcpy(ms->Options, Options, sizeof(Options));
     xf86ProcessOptions(pScrn->scrnIndex, pScrn->options, ms->Options);
 
-    devicename = xf86GetOptValString(ms->Options, OPTION_DEVICE_PATH);
-    if (!devicename) {
+    ms->PciInfo = xf86GetPciInfoForEntity(ms->pEnt->index);
+    if (ms->PciInfo) {
        BusID = malloc(64);
        sprintf(BusID, "PCI:%d:%d:%d",
 #if XSERVER_LIBPCIACCESS
@@ -481,7 +479,8 @@ PreInit(ScrnInfoPtr pScrn, int flags)
 
        ms->fd = drmOpen(NULL, BusID);
     } else {
-       ms->fd = open(devicename, O_RDWR, 0);
+       devicename = xf86GetOptValString(ms->Options, OPTION_DEVICE_PATH);
+       ms->fd = open_hw(devicename);
     }
     if (ms->fd < 0)
 	return FALSE;
commit 456a001e3f7a24f443cf0bad8400d5d600e2ad46
Author: Sascha Hauer <s.hauer at pengutronix.de>
Date:   Sat Mar 3 14:09:24 2012 +0100

    introduce open_hw() function
    
    probe_hw opens the hardware in the order we want it:
    first try devname, if this is NULL then try the KMSDEVICE
    environment variable and as a last fallback use "/dev/dri/card0".
    Instead of implementing the same code again when really opening
    the device move the code to a open_hw() function and let probe_hw
    use it.
    
    Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
    Signed-off-by: Dave Airlie <airlied at redhat.com>

diff --git a/hw/xfree86/drivers/modesetting/driver.c b/hw/xfree86/drivers/modesetting/driver.c
index 2004434..dc90e04 100644
--- a/hw/xfree86/drivers/modesetting/driver.c
+++ b/hw/xfree86/drivers/modesetting/driver.c
@@ -174,7 +174,7 @@ Identify(int flags)
 		      Chipsets);
 }
 
-static Bool probe_hw(char *dev)
+static int open_hw(char *dev)
 {
     int fd;
     if (dev)
@@ -186,13 +186,20 @@ static Bool probe_hw(char *dev)
 	    fd = open(dev,O_RDWR, 0);
 	}
     }
-    if (fd == -1) {
+    if (fd == -1)
 	xf86DrvMsg(-1, X_ERROR,"open %s: %s\n", dev, strerror(errno));
-	return FALSE;
-    }
-    close(fd);
-    return TRUE;
 
+    return fd;
+}
+
+static Bool probe_hw(char *dev)
+{
+    int fd = open_hw(dev);
+    if (fd != -1) {
+        close(fd);
+	return TRUE;
+    }
+    return FALSE;
 }
 
 static const OptionInfoRec *
commit aa6ceaaa843525b2243569de162ed0b17faa7510
Author: Sascha Hauer <s.hauer at pengutronix.de>
Date:   Sat Mar 3 14:09:23 2012 +0100

    fix if() brackets in Probe function
    
    in Probe() the indention shows what's meant but there are no
    brackets. Add them.
    
    Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
    Signed-off-by: Dave Airlie <airlied at redhat.com>

diff --git a/hw/xfree86/drivers/modesetting/driver.c b/hw/xfree86/drivers/modesetting/driver.c
index d8bb7b5..2004434 100644
--- a/hw/xfree86/drivers/modesetting/driver.c
+++ b/hw/xfree86/drivers/modesetting/driver.c
@@ -274,7 +274,7 @@ Probe(DriverPtr drv, int flags)
 					  NULL, NULL, NULL, NULL);
 	    }
 
-	    if (scrn)
+	    if (scrn) {
 		foundScreen = TRUE;
 		scrn->driverVersion = 1;
 		scrn->driverName = "modesetting";
@@ -291,6 +291,7 @@ Probe(DriverPtr drv, int flags)
 
 		xf86DrvMsg(scrn->scrnIndex, X_INFO,
 			   "using %s\n", dev ? dev : "default device");
+	    }
 	}
     }
 
commit 1349a2b7ab04553c8fddb60534400dea5cbd3cca
Author: Dave Airlie <airlied at redhat.com>
Date:   Wed Feb 22 10:07:06 2012 +0000

    xf86-video-modesetting 0.2.0
commit e5648616d222966a95edd6c35807dcf5b91a0f96
Author: Dave Airlie <airlied at redhat.com>
Date:   Wed Feb 22 09:59:12 2012 +0000

    modesetting: fix warnings, remove dead code.
    
    Signed-off-by: Dave Airlie <airlied at redhat.com>

diff --git a/hw/xfree86/drivers/modesetting/drmmode_display.c b/hw/xfree86/drivers/modesetting/drmmode_display.c
index c004721..7fa933a 100644
--- a/hw/xfree86/drivers/modesetting/drmmode_display.c
+++ b/hw/xfree86/drivers/modesetting/drmmode_display.c
@@ -466,12 +466,6 @@ static const xf86CrtcFuncsRec drmmode_crtc_funcs = {
     .destroy = NULL, /* XXX */
 };
 
-int drmmode_get_crtc_id(xf86CrtcPtr crtc)
-{
-	drmmode_crtc_private_ptr drmmode_crtc = crtc->driver_private;
-	return drmmode_crtc->hw_id;
-}
-
 static void
 drmmode_crtc_init(ScrnInfoPtr pScrn, drmmode_ptr drmmode, int num)
 {
@@ -877,7 +871,7 @@ out_free_encoders:
 	
 }
 
-uint32_t find_clones(ScrnInfoPtr scrn, xf86OutputPtr output)
+static uint32_t find_clones(ScrnInfoPtr scrn, xf86OutputPtr output)
 {
 	drmmode_output_private_ptr drmmode_output = output->driver_private, clone_drmout;
 	int i;
@@ -1074,15 +1068,6 @@ Bool drmmode_pre_init(ScrnInfoPtr pScrn, drmmode_ptr drmmode, int cpp)
 	return TRUE;
 }
 
-void drmmode_set_cursor(ScrnInfoPtr scrn, drmmode_ptr drmmode, int id, struct dumb_bo *bo)
-{
-	xf86CrtcConfigPtr   xf86_config = XF86_CRTC_CONFIG_PTR(scrn);
-	xf86CrtcPtr crtc = xf86_config->crtc[id];
-	drmmode_crtc_private_ptr drmmode_crtc = crtc->driver_private;
-
-	drmmode_crtc->cursor_bo = bo;
-}
-
 void drmmode_adjust_frame(ScrnInfoPtr pScrn, drmmode_ptr drmmode, int x, int y, int flags)
 {
 	xf86CrtcConfigPtr	config = XF86_CRTC_CONFIG_PTR(pScrn);
commit f7724167746d15c0ca32a7f5f95fb594addcddd1
Author: Gaetan Nadon <memsize at videotron.ca>
Date:   Sun Feb 19 16:13:34 2012 -0500

    config: layout and comment the top portion of configure.ac
    
    Reorder statements to be consistent with other modules so things
    are easier to find.
    
    Signed-off-by: Gaetan Nadon <memsize at videotron.ca>
    Signed-off-by: Dave Airlie <airlied at redhat.com>
commit a0bb835dc7db1ddd0472058a2a05a600ddea3930
Author: Gaetan Nadon <memsize at videotron.ca>
Date:   Sun Feb 19 08:36:19 2012 -0500

    config: replace deprecated AC_HELP_STRING with AS_HELP_STRING
    
    Signed-off-by: Gaetan Nadon <memsize at videotron.ca>
    Signed-off-by: Dave Airlie <airlied at redhat.com>
commit d56293cae78323b8976859c4461f8809a76a0b03
Author: Gaetan Nadon <memsize at videotron.ca>
Date:   Sun Feb 19 08:36:17 2012 -0500

    make: add all warnings according to the platform
    
    The current code only adds -Wall and only for gcc.
    Automake reserves the use of CPPFLAGS for the user to override
    on the command line.
    This also breaks the option --enable-strict-compilation
    
    The variable CWARNFLAGS contains the complete set of warnings
    and is platform sensitive.
    
    Signed-off-by: Gaetan Nadon <memsize at videotron.ca>
    Signed-off-by: Dave Airlie <airlied at redhat.com>

diff --git a/hw/xfree86/drivers/modesetting/Makefile.am b/hw/xfree86/drivers/modesetting/Makefile.am
index 40ebf0a..68a63fa 100644
--- a/hw/xfree86/drivers/modesetting/Makefile.am
+++ b/hw/xfree86/drivers/modesetting/Makefile.am
@@ -24,7 +24,7 @@
 # _ladir passes a dummy rpath to libtool so the thing will actually link
 # TODO: -nostdlib/-Bstatic/-lgcc platform magic, not installing the .a, etc.
 
-AM_CFLAGS = @XORG_CFLAGS@ @DRM_CFLAGS@ @UDEV_CFLAGS@
+AM_CFLAGS = $(XORG_CFLAGS) $(DRM_CFLAGS) $(UDEV_CFLAGS) $(CWARNFLAGS)
 
 modesetting_drv_la_LTLIBRARIES = modesetting_drv.la
 modesetting_drv_la_LDFLAGS = -module -avoid-version
commit fa201fe8299099f7192a4399c9df245efcee3f8a
Author: Gaetan Nadon <memsize at videotron.ca>
Date:   Sun Feb 19 08:36:16 2012 -0500

    make: remove empty variable assignment
    
    Signed-off-by: Gaetan Nadon <memsize at videotron.ca>
    Signed-off-by: Dave Airlie <airlied at redhat.com>

diff --git a/hw/xfree86/drivers/modesetting/Makefile.am b/hw/xfree86/drivers/modesetting/Makefile.am
index efc4bc0..40ebf0a 100644
--- a/hw/xfree86/drivers/modesetting/Makefile.am
+++ b/hw/xfree86/drivers/modesetting/Makefile.am
@@ -17,7 +17,6 @@
 #  ADAM JACKSON 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.
-SUBDIRS = 
 
 # this is obnoxious:
 # -module lets us name the module exactly how we want
@@ -37,5 +36,3 @@ modesetting_drv_la_SOURCES = \
 	 driver.h \
 	 drmmode_display.c \
 	 drmmode_display.h
-
-EXTRA_DIST =
commit e159fbd8805005bb7a33bf2076fd2cef00e987c6
Author: Gaetan Nadon <memsize at videotron.ca>
Date:   Sun Feb 19 08:36:15 2012 -0500

    Remove unneeded AM_PROG_CC_C_CO
    
    There are no objects in subdirs or compiled multiple times
    with different flags.
    
    Signed-off-by: Gaetan Nadon <memsize at videotron.ca>
    Signed-off-by: Dave Airlie <airlied at redhat.com>
commit 70558492376e66b73063e51b128b5bbad14b84f4
Author: Gaetan Nadon <memsize at videotron.ca>
Date:   Sun Feb 19 08:34:28 2012 -0500

    Remove redundant AC_PROG_CC
    
    Already covered by XORG_DEFAULT_OPTIONS
    
    Signed-off-by: Gaetan Nadon <memsize at videotron.ca>
    Signed-off-by: Dave Airlie <airlied at redhat.com>
commit d4bb99ce754073de090221d98000f609a3891380
Author: Gaetan Nadon <memsize at videotron.ca>
Date:   Sun Feb 19 08:34:27 2012 -0500

    Replace obsolete AM_CONFIG_HEADER with AC_CONFIG_HEADERS
    
    Signed-off-by: Gaetan Nadon <memsize at videotron.ca>
    Signed-off-by: Dave Airlie <airlied at redhat.com>
commit 5c2d152cad66c3f8ed6a4e82c3e6a45269bbb66d
Author: Gaetan Nadon <memsize at videotron.ca>
Date:   Sun Feb 19 08:34:26 2012 -0500

    Add missing targets for ChangeLog and INSTALL
    
    Signed-off-by: Gaetan Nadon <memsize at videotron.ca>
    Signed-off-by: Dave Airlie <airlied at redhat.com>
commit 8673f545cdb465b6e74f1d2fcabe29bc7fa0243d
Author: Gaetan Nadon <memsize at videotron.ca>
Date:   Sun Feb 19 08:34:25 2012 -0500

    Remove redundant EXTRA_DIST for the README file.
    
    Autotools know about it, it is always distributed.
    
    Signed-off-by: Gaetan Nadon <memsize at videotron.ca>
    Signed-off-by: Dave Airlie <airlied at redhat.com>
commit 88b637e59a37af8ec6c4c0783504b8f1a49e5595
Author: Gaetan Nadon <memsize at videotron.ca>
Date:   Sun Feb 19 08:34:24 2012 -0500

    make: remove redundant AUTOMAKE_OPTIONS
    
    Already covered by AM_INIT_AUTOMAKE([foreign dist-bzip2])
    
    Signed-off-by: Gaetan Nadon <memsize at videotron.ca>
    Signed-off-by: Dave Airlie <airlied at redhat.com>
commit a7ea959094e9a8d862637a0ea515f687aaf89d29
Author: Gaetan Nadon <memsize at videotron.ca>
Date:   Sun Feb 19 08:34:23 2012 -0500

    Fix typo in .gitignore
    
    Signed-off-by: Gaetan Nadon <memsize at videotron.ca>
    Signed-off-by: Dave Airlie <airlied at redhat.com>
commit 861e2b444ffb24921e07fdc25ab2679c9b6d2f4d
Author: Gaetan Nadon <memsize at videotron.ca>
Date:   Sun Feb 19 08:34:22 2012 -0500

    man: missing AM_V_GEN and hard-coded sed command name
    
    Let's use the common xorg makefile for all drivers.
    This ensures no new problems are introduced.
    Improvements are welcome and to be applied to all drivers.
    
    Signed-off-by: Gaetan Nadon <memsize at videotron.ca>
    Signed-off-by: Dave Airlie <airlied at redhat.com>
commit 453bbe5b442a9c21d7c22437545e487e2993ceb7
Author: Gaetan Nadon <memsize at videotron.ca>
Date:   Sun Feb 19 08:34:21 2012 -0500

    Add contact information to the README file
    
    Signed-off-by: Gaetan Nadon <memsize at videotron.ca>
    Signed-off-by: Dave Airlie <airlied at redhat.com>
commit dd1d7e3519ea2f148be83ef7ab0b228da95ff9c3
Author: Gaetan Nadon <memsize at videotron.ca>
Date:   Sun Feb 19 08:34:20 2012 -0500

    Fill the COPYING file with license text
    
    This reflects the copyright license text in the source code
    
    Signed-off-by: Gaetan Nadon <memsize at videotron.ca>
    Signed-off-by: Dave Airlie <airlied at redhat.com>

diff --git a/hw/xfree86/drivers/modesetting/COPYING b/hw/xfree86/drivers/modesetting/COPYING
index 7f33cbf..9508e25 100644
--- a/hw/xfree86/drivers/modesetting/COPYING
+++ b/hw/xfree86/drivers/modesetting/COPYING
@@ -1,12 +1,44 @@
-This is a stub file.  This package has not yet had its complete licensing
-information compiled.  Please see the individual source files for details on
-your rights to use and modify this software.
+Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas.
+Copyright 2011 Dave Airlie
+All Rights Reserved.
 
-Please submit updated COPYING files to the Xorg bugzilla:
+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:
 
-https://bugs.freedesktop.org/enter_bug.cgi?product=xorg
+The above copyright notice and this permission notice (including the
+next paragraph) shall be included in all copies or substantial portions
+of the Software.
 
-All licensing questions regarding this software should be directed at the
-Xorg mailing list:
+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 TUNGSTEN GRAPHICS 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.
 
-http://lists.freedesktop.org/mailman/listinfo/xorg
+Copyright © 2007 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.
commit b0e12e250d4b3438fb3306155a7bbff3e2d7f9b7
Author: Dave Airlie <airlied at redhat.com>
Date:   Mon Feb 20 11:08:40 2012 +0000

    modesetting: disable dirty updates for ENOSYS
    
    the kernel can also return ENOSYS for this to say its not used.
    
    Signed-off-by: Dave Airlie <airlied at redhat.com>

diff --git a/hw/xfree86/drivers/modesetting/driver.c b/hw/xfree86/drivers/modesetting/driver.c
index 8703b0b..d8bb7b5 100644
--- a/hw/xfree86/drivers/modesetting/driver.c
+++ b/hw/xfree86/drivers/modesetting/driver.c
@@ -333,7 +333,7 @@ static void dispatch_dirty(ScreenPtr pScreen)
 	/* TODO query connector property to see if this is needed */
 	ret = drmModeDirtyFB(ms->fd, ms->drmmode.fb_id, clip, num_cliprects);
 	if (ret) {
-	    if (ret == -EINVAL) {
+	    if (ret == -EINVAL || ret == -ENOSYS) {
 		ms->dirty_enabled = FALSE;
 		DamageUnregister(&pScreen->GetScreenPixmap(pScreen)->drawable, ms->damage);
 		DamageDestroy(ms->damage);
commit c5529d68c5b01cf0f36d8f2ce3694a7a0f3333da
Author: Dave Airlie <airlied at redhat.com>
Date:   Mon Feb 20 11:05:59 2012 +0000

    modesetting: fix shadow resizing.
    
    if we hotplugged and output, the shadow got disabled by accident.
    
    Signed-off-by: Dave Airlie <airlied at redhat.com>

diff --git a/hw/xfree86/drivers/modesetting/drmmode_display.c b/hw/xfree86/drivers/modesetting/drmmode_display.c
index caa9f44..c004721 100644
--- a/hw/xfree86/drivers/modesetting/drmmode_display.c
+++ b/hw/xfree86/drivers/modesetting/drmmode_display.c
@@ -984,8 +984,21 @@ drmmode_xf86crtc_resize (ScrnInfoPtr scrn, int width, int height)
 	if (!new_pixels)
 		goto fail;
 
-	screen->ModifyPixmapHeader(ppix, width, height, -1, -1,
-				   pitch, new_pixels);
+	if (!drmmode->shadow_enable)
+		screen->ModifyPixmapHeader(ppix, width, height, -1, -1,
+					   pitch, new_pixels);
+	else {
+		void *new_shadow;
+		uint32_t size = scrn->displayWidth * scrn->virtualY *
+			((scrn->bitsPerPixel + 7) >> 3);
+		new_shadow = calloc(1, size);
+		if (new_shadow == NULL)
+			goto fail;
+		free(drmmode->shadow_fb);
+		drmmode->shadow_fb = new_shadow;
+		screen->ModifyPixmapHeader(ppix, width, height, -1, -1,
+					   pitch, drmmode->shadow_fb);
+	}
 
 #if XORG_VERSION_CURRENT < XORG_VERSION_NUMERIC(1,9,99,1,0)
 	scrn->pixmapPrivate.ptr = ppix->devPrivate.ptr;
commit f3b9e52b29e8b8c4b12bc2ce290ab44e88750ad9
Author: Dave Airlie <airlied at redhat.com>
Date:   Mon Feb 20 11:00:56 2012 +0000

    modesetting: move shadow stuff to other structure
    
    we need this for resize to work properly.
    
    Signed-off-by: Dave Airlie <airlied at redhat.com>

diff --git a/hw/xfree86/drivers/modesetting/driver.c b/hw/xfree86/drivers/modesetting/driver.c
index b66f0d7..8703b0b 100644
--- a/hw/xfree86/drivers/modesetting/driver.c
+++ b/hw/xfree86/drivers/modesetting/driver.c
@@ -492,9 +492,9 @@ PreInit(ScrnInfoPtr pScrn, int flags)
 	prefer_shadow = !!value;
     }
 
-    ms->shadow_enable = xf86ReturnOptValBool(ms->Options, OPTION_SHADOW_FB, prefer_shadow);
+    ms->drmmode.shadow_enable = xf86ReturnOptValBool(ms->Options, OPTION_SHADOW_FB, prefer_shadow);
 
-    xf86DrvMsg(pScrn->scrnIndex, X_INFO, "ShadowFB: preferred %s, enabled %s\n", prefer_shadow ? "YES" : "NO", ms->shadow_enable ? "YES" : "NO");
+    xf86DrvMsg(pScrn->scrnIndex, X_INFO, "ShadowFB: preferred %s, enabled %s\n", prefer_shadow ? "YES" : "NO", ms->drmmode.shadow_enable ? "YES" : "NO");
     ms->drmmode.fd = ms->fd;
     if (drmmode_pre_init(pScrn, &ms->drmmode, pScrn->bitsPerPixel / 8) == FALSE) {
 	xf86DrvMsg(pScrn->scrnIndex, X_ERROR, "KMS setup failed\n");
@@ -527,7 +527,7 @@ PreInit(ScrnInfoPtr pScrn, int flags)
 	return FALSE;
     }
 
-    if (ms->shadow_enable) {
+    if (ms->drmmode.shadow_enable) {
 	if (!xf86LoadSubModule(pScrn, "shadow")) {
 	    return FALSE;
 	}
@@ -577,13 +577,13 @@ CreateScreenResources(ScreenPtr pScreen)
 
     rootPixmap = pScreen->GetScreenPixmap(pScreen);
 
-    if (ms->shadow_enable)
-	pixels = ms->shadow_fb;
+    if (ms->drmmode.shadow_enable)
+	pixels = ms->drmmode.shadow_fb;
     
     if (!pScreen->ModifyPixmapHeader(rootPixmap, -1, -1, -1, -1, -1, pixels))
 	FatalError("Couldn't adjust screen pixmap\n");
 
-    if (ms->shadow_enable) {
+    if (ms->drmmode.shadow_enable) {
 	if (!shadowAdd(pScreen, rootPixmap, shadowUpdatePackedWeak(),
 		       msShadowWindow, 0, 0))
 	    return FALSE;
@@ -634,11 +634,11 @@ ScreenInit(int scrnIndex, ScreenPtr pScreen, int argc, char **argv)
     if (!drmmode_create_initial_bos(pScrn, &ms->drmmode))
 	return FALSE;
 
-    if (ms->shadow_enable) {
-	ms->shadow_fb = calloc(1, pScrn->displayWidth * pScrn->virtualY *
+    if (ms->drmmode.shadow_enable) {
+	ms->drmmode.shadow_fb = calloc(1, pScrn->displayWidth * pScrn->virtualY *
 			       ((pScrn->bitsPerPixel + 7) >> 3));
-	if (!ms->shadow_fb)
-	    ms->shadow_enable = FALSE;
+	if (!ms->drmmode.shadow_fb)
+	    ms->drmmode.shadow_enable = FALSE;
     }	
     
     miClearVisualTypes();
@@ -677,7 +677,7 @@ ScreenInit(int scrnIndex, ScreenPtr pScreen, int argc, char **argv)
 
     fbPictureInit(pScreen, NULL, 0);
 
-    if (ms->shadow_enable && !msShadowInit(pScreen)) {
+    if (ms->drmmode.shadow_enable && !msShadowInit(pScreen)) {
 	xf86DrvMsg(scrnIndex, X_ERROR,
 		   "shadow fb init failed\n");
 	return FALSE;
@@ -791,10 +791,10 @@ CloseScreen(int scrnIndex, ScreenPtr pScreen)
 	ms->damage = NULL;
     }
 
-    if (ms->shadow_enable) {
+    if (ms->drmmode.shadow_enable) {
 	shadowRemove(pScreen, pScreen->GetScreenPixmap(pScreen));
-	free(ms->shadow_fb);
-	ms->shadow_fb = NULL;
+	free(ms->drmmode.shadow_fb);
+	ms->drmmode.shadow_fb = NULL;
     }
     drmmode_uevent_fini(pScrn, &ms->drmmode);
 
diff --git a/hw/xfree86/drivers/modesetting/driver.h b/hw/xfree86/drivers/modesetting/driver.h
index 2e51089..79561c8 100644
--- a/hw/xfree86/drivers/modesetting/driver.h
+++ b/hw/xfree86/drivers/modesetting/driver.h
@@ -75,8 +75,7 @@ typedef struct _modesettingRec
 
     DamagePtr damage;
     Bool dirty_enabled;
-    Bool shadow_enable;
-    void *shadow_fb;
+
 } modesettingRec, *modesettingPtr;
 
 #define modesettingPTR(p) ((modesettingPtr)((p)->driverPrivate))
diff --git a/hw/xfree86/drivers/modesetting/drmmode_display.h b/hw/xfree86/drivers/modesetting/drmmode_display.h
index 7ede159..e83167b 100644
--- a/hw/xfree86/drivers/modesetting/drmmode_display.h
+++ b/hw/xfree86/drivers/modesetting/drmmode_display.h
@@ -54,6 +54,10 @@ typedef struct {
     drmEventContext event_context;
     struct dumb_bo *front_bo;
     Bool sw_cursor;
+
+    Bool shadow_enable;
+    void *shadow_fb;
+
 } drmmode_rec, *drmmode_ptr;
 
 typedef struct {
commit eb44a004b7230321ce6837ef44610153b1d2017b
Author: Dave Airlie <airlied at redhat.com>
Date:   Mon Feb 20 10:54:36 2012 +0000

    modesetting: fix stride if kernel modifies it.
    
    If the kernel aligns things use its values instead.
    
    fixes output on nouveau here.
    
    Signed-off-by: Dave Airlie <airlied at redhat.com>

diff --git a/hw/xfree86/drivers/modesetting/drmmode_display.c b/hw/xfree86/drivers/modesetting/drmmode_display.c
index 57ac521..caa9f44 100644
--- a/hw/xfree86/drivers/modesetting/drmmode_display.c
+++ b/hw/xfree86/drivers/modesetting/drmmode_display.c
@@ -946,7 +946,7 @@ drmmode_xf86crtc_resize (ScrnInfoPtr scrn, int width, int height)
 	ScreenPtr   screen = screenInfo.screens[scrn->scrnIndex];
 	uint32_t    old_fb_id;
 	int	    i, pitch, old_width, old_height, old_pitch;
-	int cpp = (scrn->bitsPerPixel + 1) / 8;
+	int cpp = (scrn->bitsPerPixel + 7) / 8;
 	PixmapPtr ppix = screen->GetScreenPixmap(screen);
 	void *new_pixels;
 
@@ -1287,16 +1287,17 @@ Bool drmmode_create_initial_bos(ScrnInfoPtr pScrn, drmmode_ptr drmmode)
 	xf86CrtcConfigPtr   xf86_config = XF86_CRTC_CONFIG_PTR(pScrn);
 	int width;
 	int height;
-	int bpp;
+	int bpp = pScrn->bitsPerPixel;
 	int i;
+	int cpp = (bpp + 7) / 8;
 
 	width = pScrn->virtualX;
 	height = pScrn->virtualY;
-	bpp = pScrn->bitsPerPixel;
+
 	drmmode->front_bo = dumb_bo_create(drmmode->fd, width, height, bpp);
 	if (!drmmode->front_bo)
 		return FALSE;
-
+	pScrn->displayWidth = drmmode->front_bo->pitch / cpp;
 
 	width = height = 64;
 	bpp = 32;
commit 2150cbda8c75d348f39926bbc23d3e4ca9b42c88
Author: Dave Airlie <airlied at redhat.com>
Date:   Mon Feb 20 10:54:21 2012 +0000

    shadowfb: dump shadowfb state at startup

diff --git a/hw/xfree86/drivers/modesetting/driver.c b/hw/xfree86/drivers/modesetting/driver.c
index 8af9a9f..b66f0d7 100644
--- a/hw/xfree86/drivers/modesetting/driver.c
+++ b/hw/xfree86/drivers/modesetting/driver.c
@@ -494,6 +494,7 @@ PreInit(ScrnInfoPtr pScrn, int flags)
 
     ms->shadow_enable = xf86ReturnOptValBool(ms->Options, OPTION_SHADOW_FB, prefer_shadow);
 
+    xf86DrvMsg(pScrn->scrnIndex, X_INFO, "ShadowFB: preferred %s, enabled %s\n", prefer_shadow ? "YES" : "NO", ms->shadow_enable ? "YES" : "NO");
     ms->drmmode.fd = ms->fd;
     if (drmmode_pre_init(pScrn, &ms->drmmode, pScrn->bitsPerPixel / 8) == FALSE) {
 	xf86DrvMsg(pScrn->scrnIndex, X_ERROR, "KMS setup failed\n");
commit 86080a5f7a589e55a485c42bab47c6c8ff6428c1
Author: Dave Airlie <airlied at redhat.com>
Date:   Thu Feb 16 19:41:40 2012 +0000

    use a cap to decide if shadow is preferred or not.

diff --git a/hw/xfree86/drivers/modesetting/driver.c b/hw/xfree86/drivers/modesetting/driver.c
index 7ce1ac1..8af9a9f 100644
--- a/hw/xfree86/drivers/modesetting/driver.c
+++ b/hw/xfree86/drivers/modesetting/driver.c
@@ -59,6 +59,10 @@
 
 #include "driver.h"
 
+#ifndef DRM_CAP_DUMB_PREFER_SHADOW
+#define DRM_CAP_DUMB_PREFER_SHADOW 4
+#endif
+
 static void AdjustFrame(int scrnIndex, int x, int y, int flags);
 static Bool CloseScreen(int scrnIndex, ScreenPtr pScreen);
 static Bool EnterVT(int scrnIndex, int flags);
@@ -380,6 +384,9 @@ PreInit(ScrnInfoPtr pScrn, int flags)
     EntityInfoPtr pEnt;
     EntPtr msEnt = NULL;
     char *BusID, *devicename;
+    Bool prefer_shadow = TRUE;
+    uint64_t value = 0;
+    int ret;
 
     if (pScrn->numEntities != 1)
 	return FALSE;
@@ -480,7 +487,12 @@ PreInit(ScrnInfoPtr pScrn, int flags)
 	ms->drmmode.sw_cursor = TRUE;
     }
 
-    ms->shadow_enable = xf86ReturnOptValBool(ms->Options, OPTION_SHADOW_FB, TRUE);
+    ret = drmGetCap(ms->fd, DRM_CAP_DUMB_PREFER_SHADOW, &value);
+    if (!ret) {
+	prefer_shadow = !!value;
+    }
+
+    ms->shadow_enable = xf86ReturnOptValBool(ms->Options, OPTION_SHADOW_FB, prefer_shadow);
 
     ms->drmmode.fd = ms->fd;
     if (drmmode_pre_init(pScrn, &ms->drmmode, pScrn->bitsPerPixel / 8) == FALSE) {
commit fc5f39acd49d023a82ab05fffde1b423b697753c
Author: Dave Airlie <airlied at redhat.com>
Date:   Thu Feb 16 19:41:30 2012 +0000

    cleanup dumb cap fetch

diff --git a/hw/xfree86/drivers/modesetting/drmmode_display.c b/hw/xfree86/drivers/modesetting/drmmode_display.c
index ec39967..57ac521 100644
--- a/hw/xfree86/drivers/modesetting/drmmode_display.c
+++ b/hw/xfree86/drivers/modesetting/drmmode_display.c
@@ -1028,15 +1028,13 @@ Bool drmmode_pre_init(ScrnInfoPtr pScrn, drmmode_ptr drmmode, int cpp)
 {
 	int i, num_dvi = 0, num_hdmi = 0;
 	int ret;
+	uint64_t value = 0;
 
 	/* check for dumb capability */
-	{
-		uint64_t value = 0;
-		ret = drmGetCap(drmmode->fd, DRM_CAP_DUMB_BUFFER, &value);
-		if (ret > 0 || value != 1) {
-			xf86DrvMsg(pScrn->scrnIndex, X_ERROR, "KMS doesn't support dumb interface\n");
-			return FALSE;
-		}
+	ret = drmGetCap(drmmode->fd, DRM_CAP_DUMB_BUFFER, &value);
+	if (ret > 0 || value != 1) {
+		xf86DrvMsg(pScrn->scrnIndex, X_ERROR, "KMS doesn't support dumb interface\n");
+		return FALSE;
 	}
 
 	xf86CrtcConfigInit(pScrn, &drmmode_xf86crtc_config_funcs);
commit d94b3eaba9a33d0d78ed2d9acbc33394f40fdc2e
Author: Dave Airlie <airlied at redhat.com>
Date:   Mon Nov 14 11:22:44 2011 +0000

    modesetting: add cursor fallback if kernel rejects cursor.
    
    If the kernel rejects a cursor, cause a fallback, this isn't 100% as
    we can lose the initial cursor, but it works fine once wm starts.
    
    Signed-off-by: Dave Airlie <airlied at redhat.com>

diff --git a/hw/xfree86/drivers/modesetting/driver.c b/hw/xfree86/drivers/modesetting/driver.c
index 69a5fe0..7ce1ac1 100644
--- a/hw/xfree86/drivers/modesetting/driver.c
+++ b/hw/xfree86/drivers/modesetting/driver.c
@@ -477,7 +477,7 @@ PreInit(ScrnInfoPtr pScrn, int flags)
 	return FALSE;
 
     if (xf86ReturnOptValBool(ms->Options, OPTION_SW_CURSOR, FALSE)) {
-	ms->SWCursor = TRUE;
+	ms->drmmode.sw_cursor = TRUE;
     }
 
     ms->shadow_enable = xf86ReturnOptValBool(ms->Options, OPTION_SHADOW_FB, TRUE);
@@ -681,7 +681,7 @@ ScreenInit(int scrnIndex, ScreenPtr pScreen, int argc, char **argv)
     miDCInitialize(pScreen, xf86GetPointerScreenFuncs());
 
     /* Need to extend HWcursor support to handle mask interleave */
-    if (!ms->SWCursor)
+    if (!ms->drmmode.sw_cursor)
 	xf86_cursors_init(pScreen, 64, 64,
 			  HARDWARE_CURSOR_SOURCE_MASK_INTERLEAVE_64 |
 			  HARDWARE_CURSOR_ARGB);
diff --git a/hw/xfree86/drivers/modesetting/drmmode_display.c b/hw/xfree86/drivers/modesetting/drmmode_display.c
index dcf3eb3..ec39967 100644
--- a/hw/xfree86/drivers/modesetting/drmmode_display.c
+++ b/hw/xfree86/drivers/modesetting/drmmode_display.c
@@ -402,12 +402,23 @@ drmmode_load_cursor_argb (xf86CrtcPtr crtc, CARD32 *image)
 	drmmode_crtc_private_ptr drmmode_crtc = crtc->driver_private;
 	int i;
 	uint32_t *ptr;
-
+	uint32_t handle = drmmode_crtc->cursor_bo->handle;
+	int ret;
 	/* cursor should be mapped already */
 	ptr = (uint32_t *)(drmmode_crtc->cursor_bo->ptr);
 
 	for (i = 0; i < 64 * 64; i++)
 		ptr[i] = image[i];// cpu_to_le32(image[i]);
+
+	ret = drmModeSetCursor(drmmode_crtc->drmmode->fd, drmmode_crtc->mode_crtc->crtc_id, handle, 64, 64);
+	if (ret) {
+		xf86CrtcConfigPtr   xf86_config = XF86_CRTC_CONFIG_PTR(crtc->scrn);
+		xf86CursorInfoPtr	cursor_info = xf86_config->cursor_info;
+		
+		cursor_info->MaxWidth = cursor_info->MaxHeight = 0;
+		drmmode_crtc->drmmode->sw_cursor = TRUE;
+		/* fallback to swcursor */
+	}
 }
 
 
diff --git a/hw/xfree86/drivers/modesetting/drmmode_display.h b/hw/xfree86/drivers/modesetting/drmmode_display.h
index 845207a..7ede159 100644
--- a/hw/xfree86/drivers/modesetting/drmmode_display.h
+++ b/hw/xfree86/drivers/modesetting/drmmode_display.h
@@ -53,6 +53,7 @@ typedef struct {
 #endif
     drmEventContext event_context;
     struct dumb_bo *front_bo;
+    Bool sw_cursor;
 } drmmode_rec, *drmmode_ptr;
 
 typedef struct {
commit 594b3c4d6f6f748e08baffc4bc1c3ffad9b0d9cf
Author: Dave Airlie <airlied at redhat.com>
Date:   Thu Feb 16 19:31:33 2012 +0000

    fix some whitespace

diff --git a/hw/xfree86/drivers/modesetting/driver.c b/hw/xfree86/drivers/modesetting/driver.c
index 03aa027..69a5fe0 100644
--- a/hw/xfree86/drivers/modesetting/driver.c
+++ b/hw/xfree86/drivers/modesetting/driver.c
@@ -471,9 +471,6 @@ PreInit(ScrnInfoPtr pScrn, int flags)
     if (ms->fd < 0)
 	return FALSE;
 
-
-
-
     if (!xf86SetWeight(pScrn, defaultWeight, defaultWeight))
 	return FALSE;
     if (!xf86SetDefaultVisual(pScrn, -1))
commit 2e297978c928c571cf0a80e8d38423089014f07e
Author: Dave Airlie <airlied at redhat.com>
Date:   Wed Oct 5 15:12:43 2011 +0100

    fixup device open
    
    Signed-off-by: Dave Airlie <airlied at redhat.com>

diff --git a/hw/xfree86/drivers/modesetting/driver.c b/hw/xfree86/drivers/modesetting/driver.c
index 7060d37..03aa027 100644
--- a/hw/xfree86/drivers/modesetting/driver.c
+++ b/hw/xfree86/drivers/modesetting/driver.c
@@ -379,7 +379,7 @@ PreInit(ScrnInfoPtr pScrn, int flags)
     rgb defaultWeight = { 0, 0, 0 };
     EntityInfoPtr pEnt;
     EntPtr msEnt = NULL;
-    char *BusID;
+    char *BusID, *devicename;
 
     if (pScrn->numEntities != 1)
 	return FALSE;
@@ -421,22 +421,6 @@ PreInit(ScrnInfoPtr pScrn, int flags)
 	}
     }
 
-    BusID = malloc(64);
-    sprintf(BusID, "PCI:%d:%d:%d",
-#if XSERVER_LIBPCIACCESS
-	    ((ms->PciInfo->domain << 8) | ms->PciInfo->bus),
-	    ms->PciInfo->dev, ms->PciInfo->func
-#else
-	    ((pciConfigPtr) ms->PciInfo->thisCard)->busnum,
-	    ((pciConfigPtr) ms->PciInfo->thisCard)->devnum,
-	    ((pciConfigPtr) ms->PciInfo->thisCard)->funcnum
-#endif
-	);
-
-    ms->fd = drmOpen(NULL, BusID);
-    if (ms->fd < 0)
-	return FALSE;
-
     pScrn->monitor = pScrn->confScreen->monitor;
     pScrn->progClock = TRUE;
     pScrn->rgbBits = 8;
@@ -459,11 +443,6 @@ PreInit(ScrnInfoPtr pScrn, int flags)
     }
     xf86PrintDepthBpp(pScrn);
 
-    if (!xf86SetWeight(pScrn, defaultWeight, defaultWeight))
-	return FALSE;
-    if (!xf86SetDefaultVisual(pScrn, -1))
-	return FALSE;
-
     /* Process the options */
     xf86CollectOptions(pScrn, NULL);
     if (!(ms->Options = malloc(sizeof(Options))))
@@ -471,6 +450,35 @@ PreInit(ScrnInfoPtr pScrn, int flags)
     memcpy(ms->Options, Options, sizeof(Options));
     xf86ProcessOptions(pScrn->scrnIndex, pScrn->options, ms->Options);
 
+    devicename = xf86GetOptValString(ms->Options, OPTION_DEVICE_PATH);
+    if (!devicename) {
+       BusID = malloc(64);
+       sprintf(BusID, "PCI:%d:%d:%d",
+#if XSERVER_LIBPCIACCESS
+	        ((ms->PciInfo->domain << 8) | ms->PciInfo->bus),
+	        ms->PciInfo->dev, ms->PciInfo->func
+#else
+	        ((pciConfigPtr) ms->PciInfo->thisCard)->busnum,
+	        ((pciConfigPtr) ms->PciInfo->thisCard)->devnum,
+	        ((pciConfigPtr) ms->PciInfo->thisCard)->funcnum
+#endif
+	    );
+
+       ms->fd = drmOpen(NULL, BusID);
+    } else {
+       ms->fd = open(devicename, O_RDWR, 0);
+    }
+    if (ms->fd < 0)
+	return FALSE;
+
+
+
+
+    if (!xf86SetWeight(pScrn, defaultWeight, defaultWeight))
+	return FALSE;
+    if (!xf86SetDefaultVisual(pScrn, -1))
+	return FALSE;
+
     if (xf86ReturnOptValBool(ms->Options, OPTION_SW_CURSOR, FALSE)) {
 	ms->SWCursor = TRUE;
     }
commit f47f6b6a53d414f28374391964c2930427d28f46
Author: James Simmons <jsimmons at infradead.org>
Date:   Thu Nov 3 13:20:18 2011 +0000

    don't map cursors in sw cursor mode

diff --git a/hw/xfree86/drivers/modesetting/driver.c b/hw/xfree86/drivers/modesetting/driver.c
index 7df587e..7060d37 100644
--- a/hw/xfree86/drivers/modesetting/driver.c
+++ b/hw/xfree86/drivers/modesetting/driver.c
@@ -551,7 +551,8 @@ CreateScreenResources(ScreenPtr pScreen)
 
     drmmode_uevent_init(pScrn, &ms->drmmode);
 
-    drmmode_map_cursor_bos(pScrn, &ms->drmmode);
+    if (!ms->SWCursor)
+        drmmode_map_cursor_bos(pScrn, &ms->drmmode);
     pixels = drmmode_map_front_bo(&ms->drmmode);
     if (!pixels)
 	return FALSE;
commit d4eebe5217a89de196c1933e1fe4d37e22d59c6b
Author: Dave Airlie <airlied at redhat.com>
Date:   Thu Nov 3 13:18:46 2011 +0000

    configure: don't require xvmc.
    
    Not needed in here
commit 6f581e3fde7ddc943c04f274e01735beb358b7f9
Author: Dave Airlie <airlied at redhat.com>
Date:   Mon Oct 3 16:09:12 2011 +0100

    fix fb_id for dirty reporting

diff --git a/hw/xfree86/drivers/modesetting/driver.c b/hw/xfree86/drivers/modesetting/driver.c
index bde690c..7df587e 100644
--- a/hw/xfree86/drivers/modesetting/driver.c
+++ b/hw/xfree86/drivers/modesetting/driver.c
@@ -327,7 +327,7 @@ static void dispatch_dirty(ScreenPtr pScreen)
 	}
 
 	/* TODO query connector property to see if this is needed */
-	ret = drmModeDirtyFB(ms->fd, ms->fb_id, clip, num_cliprects);
+	ret = drmModeDirtyFB(ms->fd, ms->drmmode.fb_id, clip, num_cliprects);
 	if (ret) {
 	    if (ret == -EINVAL) {
 		ms->dirty_enabled = FALSE;
diff --git a/hw/xfree86/drivers/modesetting/driver.h b/hw/xfree86/drivers/modesetting/driver.h
index 494ca0c..2e51089 100644
--- a/hw/xfree86/drivers/modesetting/driver.h
+++ b/hw/xfree86/drivers/modesetting/driver.h
@@ -46,7 +46,6 @@ typedef struct
 typedef struct _modesettingRec
 {
     int fd;
-    unsigned int fb_id;
 
     EntPtr entityPrivate;
 
commit 79959b734702486971447a11b2e4181463fda3bf
Author: Dave Airlie <airlied at redhat.com>
Date:   Mon Oct 3 11:35:39 2011 +0100

    fix make distcheck

diff --git a/hw/xfree86/drivers/modesetting/Makefile.am b/hw/xfree86/drivers/modesetting/Makefile.am
index 4337977..efc4bc0 100644
--- a/hw/xfree86/drivers/modesetting/Makefile.am
+++ b/hw/xfree86/drivers/modesetting/Makefile.am
@@ -35,6 +35,7 @@ modesetting_drv_ladir = @moduledir@/drivers
 modesetting_drv_la_SOURCES = \
 	 driver.c \
 	 driver.h \
-	 drmmode_display.c
+	 drmmode_display.c \
+	 drmmode_display.h
 
 EXTRA_DIST =
commit cb65ec6b58daf9a1afc40c8693fa0632f8cf0585
Author: Dave Airlie <airlied at redhat.com>
Date:   Thu Sep 29 16:06:52 2011 +0100

    check drm support dumb buffer capability

diff --git a/hw/xfree86/drivers/modesetting/drmmode_display.c b/hw/xfree86/drivers/modesetting/drmmode_display.c
index 375170f..dcf3eb3 100644
--- a/hw/xfree86/drivers/modesetting/drmmode_display.c
+++ b/hw/xfree86/drivers/modesetting/drmmode_display.c
@@ -1016,6 +1016,17 @@ static const xf86CrtcConfigFuncsRec drmmode_xf86crtc_config_funcs = {
 Bool drmmode_pre_init(ScrnInfoPtr pScrn, drmmode_ptr drmmode, int cpp)
 {
 	int i, num_dvi = 0, num_hdmi = 0;
+	int ret;
+
+	/* check for dumb capability */
+	{
+		uint64_t value = 0;
+		ret = drmGetCap(drmmode->fd, DRM_CAP_DUMB_BUFFER, &value);
+		if (ret > 0 || value != 1) {
+			xf86DrvMsg(pScrn->scrnIndex, X_ERROR, "KMS doesn't support dumb interface\n");
+			return FALSE;
+		}
+	}
 
 	xf86CrtcConfigInit(pScrn, &drmmode_xf86crtc_config_funcs);
 
commit 6ccd13a2d7d78db2d5bd3fafb00f78d2ceb11741
Author: Dave Airlie <airlied at redhat.com>
Date:   Thu Sep 29 16:00:50 2011 +0100

    add initial man page

diff --git a/hw/xfree86/drivers/modesetting/modesetting.man b/hw/xfree86/drivers/modesetting/modesetting.man
index e69de29..34baa9c 100644
--- a/hw/xfree86/drivers/modesetting/modesetting.man
+++ b/hw/xfree86/drivers/modesetting/modesetting.man
@@ -0,0 +1,54 @@
+.\" shorthand for double quote that works everywhere.
+.ds q \N'34'
+.TH MODESETTING __drivermansuffix__ __vendorversion__
+.SH NAME
+modesetting \- video driver for framebuffer device
+.SH SYNOPSIS
+.nf
+.B "Section \*qDevice\*q"
+.BI "  Identifier \*q"  devname \*q
+.B  "  Driver \*qmodesetting\*q"
+.BI "  BusID  \*qpci:" bus : dev : func \*q
+\ \ ...
+.B EndSection
+.fi
+.SH DESCRIPTION
+.B modesetting
+is an __xservername__ driver for KMS devices.  This is a non-accelerated
+driver, the following framebuffer depths are supported: 8, 15, 16, 24.
+All visual types are supported for depth 8, and TrueColor visual is
+supported for the other depths.  RandR 1.2 is supported.
+.SH SUPPORTED HARDWARE
+The 
+.B modesetting
+driver supports all hardware where a KMS driver is available.
+modesetting uses the Linux DRM KMS ioctls and dumb object create/map.
+.SH CONFIGURATION DETAILS
+Please refer to __xconfigfile__(__filemansuffix__) for general configuration
+details.  This section only covers configuration details specific to
+this driver.
+.PP
+For this driver it is not required to specify modes in the screen 
+section of the config file.  The
+.B modesetting
+driver can pick up the currently used video mode from the kernel
+driver and will use it if there are no video modes configured.
+.PP
+For PCI boards you might have to add a BusID line to the Device
+section.  See above for a sample line.
+.PP
+The following driver 
+.B Options
+are supported:
+.TP
+.BI "Option \*qkmsdev\*q \*q" string \*q
+The framebuffer device to use. Default: /dev/dri/card0.
+.TP
+.BI "Option \*qShadowFB\*q \*q" boolean \*q
+Enable or disable use of the shadow framebuffer layer.  Default: on.
+.TP
+.SH "SEE ALSO"
+__xservername__(__appmansuffix__), __xconfigfile__(__filemansuffix__), Xserver(__appmansuffix__),
+X(__miscmansuffix__)
+.SH AUTHORS
+Authors include: Dave Airlie
commit 1f37991dec98073d5dfbf0c30213f838999bd9da
Author: Dave Airlie <airlied at redhat.com>
Date:   Thu Sep 29 15:55:36 2011 +0100

    add shadowfb support, default to on.
    
    we should probably expose a bit from kernel to say if shadow is preferred
    or wasteful.

diff --git a/hw/xfree86/drivers/modesetting/driver.c b/hw/xfree86/drivers/modesetting/driver.c
index 1192878..bde690c 100644
--- a/hw/xfree86/drivers/modesetting/driver.c
+++ b/hw/xfree86/drivers/modesetting/driver.c
@@ -49,6 +49,7 @@
 #include "xf86Crtc.h"
 #include "miscstruct.h"
 #include "dixstruct.h"
+#include "shadow.h"
 #include "xf86xv.h"
 #include <X11/extensions/Xv.h>
 #include <xorg-server.h>
@@ -110,11 +111,13 @@ typedef enum
 {
     OPTION_SW_CURSOR,
     OPTION_DEVICE_PATH,
+    OPTION_SHADOW_FB,
 } modesettingOpts;
 
 static const OptionInfoRec Options[] = {
     {OPTION_SW_CURSOR, "SWcursor", OPTV_BOOLEAN, {0}, FALSE},
     {OPTION_DEVICE_PATH, "kmsdev", OPTV_STRING, {0}, FALSE },
+    {OPTION_SHADOW_FB, "ShadowFB", OPTV_BOOLEAN, {0}, FALSE },
     {-1, NULL, OPTV_NONE, {0}, FALSE}
 };
 
@@ -472,6 +475,8 @@ PreInit(ScrnInfoPtr pScrn, int flags)
 	ms->SWCursor = TRUE;
     }
 
+    ms->shadow_enable = xf86ReturnOptValBool(ms->Options, OPTION_SHADOW_FB, TRUE);
+
     ms->drmmode.fd = ms->fd;
     if (drmmode_pre_init(pScrn, &ms->drmmode, pScrn->bitsPerPixel / 8) == FALSE) {
 	xf86DrvMsg(pScrn->scrnIndex, X_ERROR, "KMS setup failed\n");
@@ -504,11 +509,31 @@ PreInit(ScrnInfoPtr pScrn, int flags)
 	return FALSE;
     }
 
+    if (ms->shadow_enable) {
+	if (!xf86LoadSubModule(pScrn, "shadow")) {
+	    return FALSE;
+	}
+    }
+
     return TRUE;
     fail:
     return FALSE;
 }
 
+static void *
+msShadowWindow(ScreenPtr screen, CARD32 row, CARD32 offset, int mode,
+	       CARD32 *size, void *closure)
+{
+    ScrnInfoPtr pScrn = xf86Screens[screen->myNum];
+    modesettingPtr ms = modesettingPTR(pScrn);
+    int stride;
+
+    stride = (pScrn->displayWidth * pScrn->bitsPerPixel) / 8;
+    *size = stride;
+
+    return ((uint8_t *)ms->drmmode.front_bo->ptr + row * stride + offset);
+}
+
 static Bool
 CreateScreenResources(ScreenPtr pScreen)
 {
@@ -532,9 +557,19 @@ CreateScreenResources(ScreenPtr pScreen)
 	return FALSE;
 
     rootPixmap = pScreen->GetScreenPixmap(pScreen);
+
+    if (ms->shadow_enable)
+	pixels = ms->shadow_fb;
+    
     if (!pScreen->ModifyPixmapHeader(rootPixmap, -1, -1, -1, -1, -1, pixels))
 	FatalError("Couldn't adjust screen pixmap\n");
 
+    if (ms->shadow_enable) {
+	if (!shadowAdd(pScreen, rootPixmap, shadowUpdatePackedWeak(),
+		       msShadowWindow, 0, 0))
+	    return FALSE;
+    }
+
     ms->damage = DamageCreate(NULL, NULL, DamageReportNone, TRUE,
                               pScreen, rootPixmap);
 
@@ -551,6 +586,15 @@ CreateScreenResources(ScreenPtr pScreen)
 }
 
 static Bool
+msShadowInit(ScreenPtr pScreen)
+{
+    if (!shadowSetup(pScreen)) {
+	return FALSE;
+    }
+    return TRUE;
+}
+
+static Bool
 ScreenInit(int scrnIndex, ScreenPtr pScreen, int argc, char **argv)
 {
     ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
@@ -571,6 +615,13 @@ ScreenInit(int scrnIndex, ScreenPtr pScreen, int argc, char **argv)
     if (!drmmode_create_initial_bos(pScrn, &ms->drmmode))
 	return FALSE;
 
+    if (ms->shadow_enable) {
+	ms->shadow_fb = calloc(1, pScrn->displayWidth * pScrn->virtualY *
+			       ((pScrn->bitsPerPixel + 7) >> 3));
+	if (!ms->shadow_fb)
+	    ms->shadow_enable = FALSE;
+    }	
+    
     miClearVisualTypes();
 
     if (!miSetVisualTypes(pScrn->depth,
@@ -607,6 +658,12 @@ ScreenInit(int scrnIndex, ScreenPtr pScreen, int argc, char **argv)
 
     fbPictureInit(pScreen, NULL, 0);
 
+    if (ms->shadow_enable && !msShadowInit(pScreen)) {
+	xf86DrvMsg(scrnIndex, X_ERROR,
+		   "shadow fb init failed\n");
+	return FALSE;
+    }
+  
     ms->createScreenResources = pScreen->CreateScreenResources;
     pScreen->CreateScreenResources = CreateScreenResources;
 
@@ -715,6 +772,11 @@ CloseScreen(int scrnIndex, ScreenPtr pScreen)
 	ms->damage = NULL;
     }
 
+    if (ms->shadow_enable) {
+	shadowRemove(pScreen, pScreen->GetScreenPixmap(pScreen));
+	free(ms->shadow_fb);
+	ms->shadow_fb = NULL;
+    }
     drmmode_uevent_fini(pScrn, &ms->drmmode);
 
     drmmode_free_bos(pScrn, &ms->drmmode);
diff --git a/hw/xfree86/drivers/modesetting/driver.h b/hw/xfree86/drivers/modesetting/driver.h
index beb5f8d..494ca0c 100644
--- a/hw/xfree86/drivers/modesetting/driver.h
+++ b/hw/xfree86/drivers/modesetting/driver.h
@@ -76,6 +76,8 @@ typedef struct _modesettingRec
 
     DamagePtr damage;
     Bool dirty_enabled;
+    Bool shadow_enable;
+    void *shadow_fb;
 } modesettingRec, *modesettingPtr;
 
 #define modesettingPTR(p) ((modesettingPtr)((p)->driverPrivate))
commit 0b5e574dff230c7879eb9655bb7252553bbace50
Author: Dave Airlie <airlied at redhat.com>
Date:   Thu Sep 29 15:55:24 2011 +0100

    remove unused debug

diff --git a/hw/xfree86/drivers/modesetting/driver.c b/hw/xfree86/drivers/modesetting/driver.c
index d1348c9..1192878 100644
--- a/hw/xfree86/drivers/modesetting/driver.c
+++ b/hw/xfree86/drivers/modesetting/driver.c
@@ -558,7 +558,6 @@ ScreenInit(int scrnIndex, ScreenPtr pScreen, int argc, char **argv)
     VisualPtr visual;
     int ret;
 
-    ErrorF("ms is %p\n", ms);
     pScrn->pScreen = pScreen;
 
     ret = drmSetMaster(ms->fd);
commit d686130c17126d86db55aae6b65b12d8bcf6a098
Author: Dave Airlie <airlied at redhat.com>
Date:   Thu Sep 29 14:13:58 2011 +0100

    add -Wall, cleanup warnings

diff --git a/hw/xfree86/drivers/modesetting/driver.c b/hw/xfree86/drivers/modesetting/driver.c
index b56db94..d1348c9 100644
--- a/hw/xfree86/drivers/modesetting/driver.c
+++ b/hw/xfree86/drivers/modesetting/driver.c
@@ -33,6 +33,7 @@
 #include "config.h"
 #endif
 
+#include <unistd.h>
 #include <fcntl.h>
 #include "xf86.h"
 #include "xf86_OSproc.h"
@@ -199,8 +200,6 @@ ms_pci_probe(DriverPtr driver,
 	     int entity_num, struct pci_device *dev, intptr_t match_data)
 {
     ScrnInfoPtr scrn = NULL;
-    EntityInfoPtr entity;
-    DevUnion *private;
 
     scrn = xf86ConfigPciEntity(scrn, 0, entity_num, NULL,
 			       NULL, NULL, NULL, NULL, NULL);
@@ -239,14 +238,11 @@ ms_pci_probe(DriverPtr driver,
 static Bool
 Probe(DriverPtr drv, int flags)
 {
-    int i, numUsed, numDevSections, *usedChips;
-    EntPtr msEnt = NULL;
-    DevUnion *pPriv;
+    int i, numDevSections;
     GDevPtr *devSections;
     Bool foundScreen = FALSE;
-    int numDevs;
     char *dev;
-    ScrnInfoPtr scrn;
+    ScrnInfoPtr scrn = NULL;
 
     /* For now, just bail out for PROBE_DETECT. */
     if (flags & PROBE_DETECT)
@@ -268,7 +264,7 @@ Probe(DriverPtr drv, int flags)
 		int entity;
 		entity = xf86ClaimFbSlot(drv, 0, devSections[i], TRUE);
 		scrn = xf86ConfigFbEntity(scrn, 0, entity,
-					   NULL, NULL, NULL, NULL);
+					  NULL, NULL, NULL, NULL);
 	    }
 
 	    if (scrn)
@@ -376,17 +372,11 @@ FreeRec(ScrnInfoPtr pScrn)
 static Bool
 PreInit(ScrnInfoPtr pScrn, int flags)
 {
-    xf86CrtcConfigPtr xf86_config;
     modesettingPtr ms;
-    MessageType from = X_PROBED;
     rgb defaultWeight = { 0, 0, 0 };
     EntityInfoPtr pEnt;
     EntPtr msEnt = NULL;
     char *BusID;
-    int i;
-    char *s;
-    int num_pipe;
-    int max_width, max_height;
 
     if (pScrn->numEntities != 1)
 	return FALSE;
@@ -526,7 +516,6 @@ CreateScreenResources(ScreenPtr pScreen)
     modesettingPtr ms = modesettingPTR(pScrn);
     PixmapPtr rootPixmap;
     Bool ret;
-    int flags;
     void *pixels;
     pScreen->CreateScreenResources = ms->createScreenResources;
     ret = pScreen->CreateScreenResources(pScreen);
@@ -567,9 +556,6 @@ ScreenInit(int scrnIndex, ScreenPtr pScreen, int argc, char **argv)
     ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
     modesettingPtr ms = modesettingPTR(pScrn);
     VisualPtr visual;
-    unsigned long sys_mem;
-    int c;
-    MessageType from;
     int ret;
 
     ErrorF("ms is %p\n", ms);
diff --git a/hw/xfree86/drivers/modesetting/drmmode_display.c b/hw/xfree86/drivers/modesetting/drmmode_display.c
index 4f25bbe..375170f 100644
--- a/hw/xfree86/drivers/modesetting/drmmode_display.c
+++ b/hw/xfree86/drivers/modesetting/drmmode_display.c
@@ -108,11 +108,13 @@ static int dumb_bo_map(int fd, struct dumb_bo *bo)
 	return 0;
 }
 
+#if 0
 static int dumb_bo_unmap(int fd, struct dumb_bo *bo)
 {
 	bo->map_count--;
 	return 0;
 }
+#endif
 
 static int dumb_bo_destroy(int fd, struct dumb_bo *bo)
 {
@@ -260,7 +262,6 @@ drmmode_set_mode_major(xf86CrtcPtr crtc, DisplayModePtr mode,
 		     Rotation rotation, int x, int y)
 {
 	ScrnInfoPtr pScrn = crtc->scrn;
-	//	RADEONInfoPtr info = RADEONPTR(pScrn);
 	xf86CrtcConfigPtr   xf86_config = XF86_CRTC_CONFIG_PTR(crtc->scrn);
 	drmmode_crtc_private_ptr drmmode_crtc = crtc->driver_private;
 	drmmode_ptr drmmode = drmmode_crtc->drmmode;
@@ -273,11 +274,8 @@ drmmode_set_mode_major(xf86CrtcPtr crtc, DisplayModePtr mode,
 	int i;
 	int fb_id;
 	drmModeModeInfo kmode;
-	int pitch;
-	uint32_t tiling_flags = 0;
 	int height;
 
-	pitch = pScrn->displayWidth;
 	height = pScrn->virtualY;
 
 	if (drmmode->fb_id == 0) {
@@ -795,7 +793,6 @@ drmmode_output_init(ScrnInfoPtr pScrn, drmmode_ptr drmmode, int num, int *num_dv
 	drmModePropertyPtr props;
 	char name[32];
 	int i;
-	const char *s;
 
 	koutput = drmModeGetConnector(drmmode->fd, drmmode->mode_res->connectors[num]);
 	if (!koutput)
@@ -938,10 +935,7 @@ drmmode_xf86crtc_resize (ScrnInfoPtr scrn, int width, int height)
 	ScreenPtr   screen = screenInfo.screens[scrn->scrnIndex];
 	uint32_t    old_fb_id;
 	int	    i, pitch, old_width, old_height, old_pitch;
-	int screen_size;
 	int cpp = (scrn->bitsPerPixel + 1) / 8;
-	struct dumb_bo *front_bo;
-	uint32_t tiling_flags = 0;
 	PixmapPtr ppix = screen->GetScreenPixmap(screen);
 	void *new_pixels;
 
@@ -949,12 +943,12 @@ drmmode_xf86crtc_resize (ScrnInfoPtr scrn, int width, int height)
 		return TRUE;
 
 	xf86DrvMsg(scrn->scrnIndex, X_INFO,
-		   "Allocate new frame buffer %dx%d stride %d\n",
-		   width, height, pitch / cpp);
+		   "Allocate new frame buffer %dx%d stride\n",
+		   width, height);
 
 	old_width = scrn->virtualX;
 	old_height = scrn->virtualY;
-	old_pitch = scrn->displayWidth;
+	old_pitch = drmmode->front_bo->pitch;
 	old_fb_id = drmmode->fb_id;
 	old_front = drmmode->front_bo;
 
@@ -1009,7 +1003,7 @@ drmmode_xf86crtc_resize (ScrnInfoPtr scrn, int width, int height)
 	drmmode->front_bo = old_front;
 	scrn->virtualX = old_width;
 	scrn->virtualY = old_height;
-	scrn->displayWidth = old_pitch;
+	scrn->displayWidth = old_pitch / cpp;
 	drmmode->fb_id = old_fb_id;
 
 	return FALSE;
@@ -1021,11 +1015,9 @@ static const xf86CrtcConfigFuncsRec drmmode_xf86crtc_config_funcs = {
 
 Bool drmmode_pre_init(ScrnInfoPtr pScrn, drmmode_ptr drmmode, int cpp)
 {
-	xf86CrtcConfigPtr xf86_config;
 	int i, num_dvi = 0, num_hdmi = 0;
 
 	xf86CrtcConfigInit(pScrn, &drmmode_xf86crtc_config_funcs);
-	xf86_config = XF86_CRTC_CONFIG_PTR(pScrn);
 
 	drmmode->scrn = pScrn;
 	drmmode->cpp = cpp;
commit a4f6e661b5d6662c413c86eeefb4affddd65c562
Author: Dave Airlie <airlied at redhat.com>
Date:   Thu Sep 29 14:05:43 2011 +0100

    fix server recycling

diff --git a/hw/xfree86/drivers/modesetting/driver.c b/hw/xfree86/drivers/modesetting/driver.c
index bc80e30..b56db94 100644
--- a/hw/xfree86/drivers/modesetting/driver.c
+++ b/hw/xfree86/drivers/modesetting/driver.c
@@ -570,31 +570,17 @@ ScreenInit(int scrnIndex, ScreenPtr pScreen, int argc, char **argv)
     unsigned long sys_mem;
     int c;
     MessageType from;
+    int ret;
 
-    /* deal with server regeneration */
-    if (ms->fd < 0) {
-	char *BusID;
-
-	BusID = malloc(64);
-	sprintf(BusID, "PCI:%d:%d:%d",
-#if XSERVER_LIBPCIACCESS
-		((ms->PciInfo->domain << 8) | ms->PciInfo->bus),
-		ms->PciInfo->dev, ms->PciInfo->func
-#else
-		((pciConfigPtr) ms->PciInfo->thisCard)->busnum,
-		((pciConfigPtr) ms->PciInfo->thisCard)->devnum,
-		((pciConfigPtr) ms->PciInfo->thisCard)->funcnum
-#endif
-	    );
-
-	ms->fd = drmOpen(NULL, BusID);
-
-	if (ms->fd < 0)
-	    return FALSE;
-    }
-
+    ErrorF("ms is %p\n", ms);
     pScrn->pScreen = pScreen;
 
+    ret = drmSetMaster(ms->fd);
+    if (ret) {
+        ErrorF("Unable to set master\n");
+        return FALSE;
+    }
+      
     /* HW dependent - FIXME */
     pScrn->displayWidth = pScrn->virtualX;
     if (!drmmode_create_initial_bos(pScrn, &ms->drmmode))
@@ -716,7 +702,9 @@ EnterVT(int scrnIndex, int flags)
     ScrnInfoPtr pScrn = xf86Screens[scrnIndex];
     modesettingPtr ms = modesettingPTR(pScrn);
 
-    if (!xf86SetDesiredModes(pScrn))
+    pScrn->vtSema = TRUE;
+
+    if (!drmmode_set_desired_modes(pScrn, &ms->drmmode))
 	return FALSE;
 
     return TRUE;
@@ -752,8 +740,8 @@ CloseScreen(int scrnIndex, ScreenPtr pScreen)
 
     pScreen->CreateScreenResources = ms->createScreenResources;
     pScreen->BlockHandler = ms->BlockHandler;
-    drmClose(ms->fd);
-    ms->fd = -1;
+
+    drmDropMaster(ms->fd);
 
     pScrn->vtSema = FALSE;
     pScreen->CloseScreen = ms->CloseScreen;
diff --git a/hw/xfree86/drivers/modesetting/drmmode_display.c b/hw/xfree86/drivers/modesetting/drmmode_display.c
index d94ce03..4f25bbe 100644
--- a/hw/xfree86/drivers/modesetting/drmmode_display.c
+++ b/hw/xfree86/drivers/modesetting/drmmode_display.c
@@ -1329,6 +1329,12 @@ void drmmode_free_bos(ScrnInfoPtr pScrn, drmmode_ptr drmmode)
 {
 	xf86CrtcConfigPtr   xf86_config = XF86_CRTC_CONFIG_PTR(pScrn);
 	int i;
+
+	if (drmmode->fb_id) {
+		drmModeRmFB(drmmode->fd, drmmode->fb_id);
+		drmmode->fb_id = 0;
+	}
+
 	dumb_bo_destroy(drmmode->fd, drmmode->front_bo);
 	drmmode->front_bo = NULL;
 
commit 7847321138be62b929123b25929a69f0a57aca3f
Author: Dave Airlie <airlied at redhat.com>
Date:   Thu Sep 29 12:38:26 2011 +0100

    port damage tracking code from st/xorg

diff --git a/hw/xfree86/drivers/modesetting/driver.c b/hw/xfree86/drivers/modesetting/driver.c
index 0aaafd1..bc80e30 100644
--- a/hw/xfree86/drivers/modesetting/driver.c
+++ b/hw/xfree86/drivers/modesetting/driver.c
@@ -307,6 +307,58 @@ GetRec(ScrnInfoPtr pScrn)
     return TRUE;
 }
 
+static void dispatch_dirty(ScreenPtr pScreen)
+{
+    ScrnInfoPtr scrn = xf86Screens[pScreen->myNum];
+    modesettingPtr ms = modesettingPTR(scrn);
+    RegionPtr dirty = DamageRegion(ms->damage);
+    unsigned num_cliprects = REGION_NUM_RECTS(dirty);
+
+    if (num_cliprects) {
+	drmModeClip *clip = alloca(num_cliprects * sizeof(drmModeClip));
+	BoxPtr rect = REGION_RECTS(dirty);
+	int i, ret;
+	    
+	/* XXX no need for copy? */
+	for (i = 0; i < num_cliprects; i++, rect++) {
+	    clip[i].x1 = rect->x1;
+	    clip[i].y1 = rect->y1;
+	    clip[i].x2 = rect->x2;
+	    clip[i].y2 = rect->y2;
+	}
+
+	/* TODO query connector property to see if this is needed */
+	ret = drmModeDirtyFB(ms->fd, ms->fb_id, clip, num_cliprects);
+	if (ret) {
+	    if (ret == -EINVAL) {
+		ms->dirty_enabled = FALSE;
+		DamageUnregister(&pScreen->GetScreenPixmap(pScreen)->drawable, ms->damage);
+		DamageDestroy(ms->damage);
+		ms->damage = NULL;
+		xf86DrvMsg(scrn->scrnIndex, X_INFO, "Disabling kernel dirty updates, not required.\n");
+		return;
+	    } else
+		ErrorF("%s: failed to send dirty (%i, %s)\n",
+		       __func__, ret, strerror(-ret));
+	}
+	
+	DamageEmpty(ms->damage);
+    }
+}
+
+static void msBlockHandler(int i, pointer blockData, pointer pTimeout,
+			   pointer pReadmask)
+{
+    ScreenPtr pScreen = screenInfo.screens[i];
+    modesettingPtr ms = modesettingPTR(xf86Screens[pScreen->myNum]);
+
+    pScreen->BlockHandler = ms->BlockHandler;
+    pScreen->BlockHandler(i, blockData, pTimeout, pReadmask);
+    pScreen->BlockHandler = msBlockHandler;
+    if (ms->dirty_enabled)
+	dispatch_dirty(pScreen);
+}
+
 static void
 FreeRec(ScrnInfoPtr pScrn)
 {
@@ -494,6 +546,18 @@ CreateScreenResources(ScreenPtr pScreen)
     if (!pScreen->ModifyPixmapHeader(rootPixmap, -1, -1, -1, -1, -1, pixels))
 	FatalError("Couldn't adjust screen pixmap\n");
 
+    ms->damage = DamageCreate(NULL, NULL, DamageReportNone, TRUE,
+                              pScreen, rootPixmap);
+
+    if (ms->damage) {
+	DamageRegister(&rootPixmap->drawable, ms->damage);
+	ms->dirty_enabled = TRUE;
+	xf86DrvMsg(pScrn->scrnIndex, X_INFO, "Damage tracking initialized\n");
+    } else {
+	xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
+		   "Failed to create screen damage record\n");
+	return FALSE;
+    }
     return ret;
 }
 
@@ -596,6 +660,9 @@ ScreenInit(int scrnIndex, ScreenPtr pScreen, int argc, char **argv)
     ms->CloseScreen = pScreen->CloseScreen;
     pScreen->CloseScreen = CloseScreen;
 
+    ms->BlockHandler = pScreen->BlockHandler;
+    pScreen->BlockHandler = msBlockHandler;
+
     if (!xf86CrtcScreenInit(pScreen))
 	return FALSE;
 
@@ -669,6 +736,12 @@ CloseScreen(int scrnIndex, ScreenPtr pScreen)
     ScrnInfoPtr pScrn = xf86Screens[scrnIndex];
     modesettingPtr ms = modesettingPTR(pScrn);
 
+    if (ms->damage) {
+	DamageUnregister(&pScreen->GetScreenPixmap(pScreen)->drawable, ms->damage);
+	DamageDestroy(ms->damage);
+	ms->damage = NULL;
+    }
+
     drmmode_uevent_fini(pScrn, &ms->drmmode);
 
     drmmode_free_bos(pScrn, &ms->drmmode);
@@ -678,7 +751,7 @@ CloseScreen(int scrnIndex, ScreenPtr pScreen)
     }
 
     pScreen->CreateScreenResources = ms->createScreenResources;
-
+    pScreen->BlockHandler = ms->BlockHandler;
     drmClose(ms->fd);
     ms->fd = -1;
 
diff --git a/hw/xfree86/drivers/modesetting/driver.h b/hw/xfree86/drivers/modesetting/driver.h
index 255dede..beb5f8d 100644
--- a/hw/xfree86/drivers/modesetting/driver.h
+++ b/hw/xfree86/drivers/modesetting/driver.h
@@ -30,6 +30,7 @@
 #include <errno.h>
 #include <drm.h>
 #include <xf86drm.h>
+#include <damage.h>
 
 #include "drmmode_display.h"
 #define DRV_ERROR(msg)	xf86DrvMsg(pScrn->scrnIndex, X_ERROR, msg);
@@ -68,10 +69,13 @@ typedef struct _modesettingRec
     unsigned int SaveGeneration;
 
     CreateScreenResourcesProcPtr createScreenResources;
-
+    ScreenBlockHandlerProcPtr BlockHandler;
     void *driver;
 
     drmmode_rec drmmode;
+
+    DamagePtr damage;
+    Bool dirty_enabled;
 } modesettingRec, *modesettingPtr;
 
 #define modesettingPTR(p) ((modesettingPtr)((p)->driverPrivate))
commit 4d3aadb22fc03f259a9d1717b55ce16d7a32e2be
Author: Dave Airlie <airlied at redhat.com>
Date:   Thu Sep 29 12:34:27 2011 +0100

    drop loading dri2

diff --git a/hw/xfree86/drivers/modesetting/driver.c b/hw/xfree86/drivers/modesetting/driver.c
index dee9cff..0aaafd1 100644
--- a/hw/xfree86/drivers/modesetting/driver.c
+++ b/hw/xfree86/drivers/modesetting/driver.c
@@ -462,10 +462,6 @@ PreInit(ScrnInfoPtr pScrn, int flags)
 	return FALSE;
     }
 
-#ifdef DRI2
-    xf86LoadSubModule(pScrn, "dri2");
-#endif
-
     return TRUE;
     fail:
     return FALSE;
commit 1b1382c9e1995dcfe5dfec1de17155fa627ac6e8
Author: Dave Airlie <airlied at redhat.com>
Date:   Thu Sep 29 12:34:17 2011 +0100

    update authors/copyright

diff --git a/hw/xfree86/drivers/modesetting/driver.c b/hw/xfree86/drivers/modesetting/driver.c
index 9bb1cb4..dee9cff 100644
--- a/hw/xfree86/drivers/modesetting/driver.c
+++ b/hw/xfree86/drivers/modesetting/driver.c
@@ -1,5 +1,6 @@
 /*
  * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas.
+ * Copyright 2011 Dave Airlie
  * All Rights Reserved.
  *
  * Permission is hereby granted, free of charge, to any person obtaining a
@@ -23,7 +24,8 @@
  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  *
  *
- * Author: Alan Hourihane <alanh at tungstengraphics.com>
+ * Original Author: Alan Hourihane <alanh at tungstengraphics.com>
+ * Rewrite: Dave Airlie <airlied at redhat.com> 
  *
  */
 
commit 263597dbb3a75d711b5ad2e1f51554e6b2601d9a
Author: Dave Airlie <airlied at redhat.com>
Date:   Thu Sep 29 12:30:46 2011 +0100

    gut some more unneeded code

diff --git a/hw/xfree86/drivers/modesetting/driver.c b/hw/xfree86/drivers/modesetting/driver.c
index be781bc..9bb1cb4 100644
--- a/hw/xfree86/drivers/modesetting/driver.c
+++ b/hw/xfree86/drivers/modesetting/driver.c
@@ -638,24 +638,6 @@ static void
 LeaveVT(int scrnIndex, int flags)
 {
     ScrnInfoPtr pScrn = xf86Screens[scrnIndex];
-    modesettingPtr ms = modesettingPTR(pScrn);
-    xf86CrtcConfigPtr config = XF86_CRTC_CONFIG_PTR(pScrn);
-    int o;
-
-    for (o = 0; o < config->num_crtc; o++) {
-	xf86CrtcPtr crtc = config->crtc[o];
-
-	//	cursor_destroy(crtc);
-
-	if (crtc->rotatedPixmap || crtc->rotatedData) {
-	    crtc->funcs->shadow_destroy(crtc, crtc->rotatedPixmap,
-					crtc->rotatedData);
-	    crtc->rotatedPixmap = NULL;
-	    crtc->rotatedData = NULL;
-	}
-    }
-
-    drmModeRmFB(ms->fd, ms->fb_id);
 
     pScrn->vtSema = FALSE;
 }
commit a72bdf170c8bc55eef3d2dbb8e316839552288a5
Author: Dave Airlie <airlied at redhat.com>
Date:   Thu Sep 29 12:28:59 2011 +0100

    modesetting: rewrite probing based on fbdev.
    
    This isn't perfect, it should really do more with bus id matching
    and finding the write drm device using sysfs if it can. but it removes
    lots of hardcoding of pci ids.

diff --git a/hw/xfree86/drivers/modesetting/driver.c b/hw/xfree86/drivers/modesetting/driver.c
index 47ffb07..be781bc 100644
--- a/hw/xfree86/drivers/modesetting/driver.c
+++ b/hw/xfree86/drivers/modesetting/driver.c
@@ -31,6 +31,7 @@
 #include "config.h"
 #endif
 
+#include <fcntl.h>
 #include "xf86.h"
 #include "xf86_OSproc.h"
 #include "compiler.h"
@@ -68,18 +69,19 @@ static Bool ScreenInit(int scrnIndex, ScreenPtr pScreen, int argc,
 		       char **argv);
 static Bool PreInit(ScrnInfoPtr pScrn, int flags);
 
-#if XSERVER_LIBPCIACCESS
-static Bool
-pci_probe(DriverPtr driver,
-	  int entity_num, struct pci_device *device, intptr_t match_data);
-#else
 static Bool Probe(DriverPtr drv, int flags);
-#endif
+static Bool ms_pci_probe(DriverPtr driver,
+			 int entity_num, struct pci_device *device,
+			 intptr_t match_data);
 
-#if XSERVER_LIBPCIACCESS
-static const struct pci_id_match device_match[] = {
-    {0x8086, 0x0046, 0xffff, 0xffff, 0, 0, 0},
-    {0, 0, 0},
+#ifdef XSERVER_LIBPCIACCESS
+static const struct pci_id_match ms_device_match[] = {
+    {
+	PCI_MATCH_ANY, PCI_MATCH_ANY, PCI_MATCH_ANY, PCI_MATCH_ANY,
+	0x00030000, 0x00ffffff, 0
+    },
+
+    { 0, 0, 0 },
 };
 #endif
 
@@ -87,38 +89,29 @@ _X_EXPORT DriverRec modesetting = {
     1,
     "modesetting",
     Identify,
-#if XSERVER_LIBPCIACCESS
-    NULL,
-#else
     Probe,
-#endif
     AvailableOptions,
     NULL,
     0,
     NULL,
-#if XSERVER_LIBPCIACCESS
-    device_match,
-    pci_probe
-#endif
+    ms_device_match,
+    ms_pci_probe,
 };
 
 static SymTabRec Chipsets[] = {
-    {0x0046, "Intel Graphics Device"},
+    {0, "kms" },
     {-1, NULL}
 };
 
-static PciChipsets PciDevices[] = {
-    {0x2592, 0x0046, RES_SHARED_VGA},
-    {-1, -1, RES_UNDEFINED}
-};
-
 typedef enum
 {
     OPTION_SW_CURSOR,
+    OPTION_DEVICE_PATH,
 } modesettingOpts;
 
 static const OptionInfoRec Options[] = {
     {OPTION_SW_CURSOR, "SWcursor", OPTV_BOOLEAN, {0}, FALSE},
+    {OPTION_DEVICE_PATH, "kmsdev", OPTV_STRING, {0}, FALSE },
     {-1, NULL, OPTV_NONE, {0}, FALSE}
 };
 
@@ -171,6 +164,27 @@ Identify(int flags)
 		      Chipsets);
 }
 
+static Bool probe_hw(char *dev)
+{
+    int fd;
+    if (dev)
+	fd = open(dev, O_RDWR, 0);
+    else {
+	dev = getenv("KMSDEVICE");
+	if ((NULL == dev) || ((fd = open(dev, O_RDWR, 0)) == -1)) {
+	    dev = "/dev/dri/card0";
+	    fd = open(dev,O_RDWR, 0);
+	}
+    }
+    if (fd == -1) {
+	xf86DrvMsg(-1, X_ERROR,"open %s: %s\n", dev, strerror(errno));
+	return FALSE;
+    }
+    close(fd);
+    return TRUE;
+
+}
+
 static const OptionInfoRec *
 AvailableOptions(int chipid, int busid)
 {
@@ -179,25 +193,26 @@ AvailableOptions(int chipid, int busid)
 
 #if XSERVER_LIBPCIACCESS
 static Bool
-pci_probe(DriverPtr driver,
-	  int entity_num, struct pci_device *device, intptr_t match_data)
+ms_pci_probe(DriverPtr driver,
+	     int entity_num, struct pci_device *dev, intptr_t match_data)
 {
     ScrnInfoPtr scrn = NULL;
     EntityInfoPtr entity;
     DevUnion *private;
 
-    scrn = xf86ConfigPciEntity(scrn, 0, entity_num, PciDevices,
+    scrn = xf86ConfigPciEntity(scrn, 0, entity_num, NULL,
 			       NULL, NULL, NULL, NULL, NULL);
-    if (scrn != NULL) {
-	scrn->driverVersion = 1;
-	scrn->driverName = "modesetting";
-	scrn->name = "modesetting";
-	scrn->Probe = NULL;
-
-	entity = xf86GetEntityInfo(entity_num);
-
-	switch (device->device_id) {
-	case 0x0046:
+    if (scrn) {
+	char *devpath;
+	GDevPtr devSection = xf86GetDevFromEntity(scrn->entityList[0],
+						  scrn->entityInstanceList[0]);
+
+	devpath = xf86FindOptionValue(devSection->options, "kmsdev");
+	if (probe_hw(devpath)) {
+	    scrn->driverVersion = 1;
+	    scrn->driverName = "modesetting";
+	    scrn->name = "modeset";
+	    scrn->Probe = NULL;
 	    scrn->PreInit = PreInit;
 	    scrn->ScreenInit = ScreenInit;
 	    scrn->SwitchMode = SwitchMode;
@@ -206,12 +221,19 @@ pci_probe(DriverPtr driver,
 	    scrn->LeaveVT = LeaveVT;
 	    scrn->FreeScreen = FreeScreen;
 	    scrn->ValidMode = ValidMode;
-	    break;
-	}
+
+	    xf86DrvMsg(scrn->scrnIndex, X_CONFIG,
+		       "claimed PCI slot %d@%d:%d:%d\n", 
+		       dev->bus, dev->domain, dev->dev, dev->func);
+	    xf86DrvMsg(scrn->scrnIndex, X_INFO,
+		       "using %s\n", devpath ? devpath : "default device");
+	} else
+	    scrn = NULL;
     }
     return scrn != NULL;
 }
-#else
+#endif
+
 static Bool
 Probe(DriverPtr drv, int flags)
 {
@@ -220,9 +242,13 @@ Probe(DriverPtr drv, int flags)
     DevUnion *pPriv;
     GDevPtr *devSections;
     Bool foundScreen = FALSE;
-    pciVideoPtr *VideoInfo;
-    pciVideoPtr *ppPci;
     int numDevs;
+    char *dev;
+    ScrnInfoPtr scrn;
+
+    /* For now, just bail out for PROBE_DETECT. */
+    if (flags & PROBE_DETECT)
+	return FALSE;
 
     /*
      * Find the config file Device sections that match this
@@ -232,110 +258,41 @@ Probe(DriverPtr drv, int flags)
 	return FALSE;
     }
 
-    /*
-     * This probing is just checking the PCI data the server already
-     * collected.
-     */
-    if (!(VideoInfo = xf86GetPciVideoInfo()))
-	return FALSE;
+    for (i = 0; i < numDevSections; i++) {
 
-#if 0
-    numUsed = 0;
-    for (ppPci = VideoInfo; ppPci != NULL && *ppPci != NULL; ppPci++) {
-	for (numDevs = 0; numDevs < numDevSections; numDevs++) {
-	    if (devSections[numDevs]->busID && *devSections[numDevs]->busID) {
-		if (xf86ComparePciBusString
-		    (devSections[numDevs]->busID, (*ppPci)->bus,
-		     (*ppPci)->device, (*ppPci)->func)) {
-		    /* Claim slot */
-		    if (xf86CheckPciSlot((*ppPci)->bus, (*ppPci)->device,
-					 (*ppPci)->func)) {
-			usedChips[numUsed++] =
-			    xf86ClaimPciSlot((*ppPci)->bus, (*ppPci)->device,
-					     (*ppPci)->func, drv,
-					     (*ppPci)->chipType, NULL, TRUE);
-			ErrorF("CLAIMED %d %d %d\n", (*ppPci)->bus,
-			       (*ppPci)->device, (*ppPci)->func);
-		    }
-		}
+	dev = xf86FindOptionValue(devSections[i]->options,"kmsdev");
+	if (devSections[i]->busID) {
+	    if (probe_hw(dev)) {
+		int entity;
+		entity = xf86ClaimFbSlot(drv, 0, devSections[i], TRUE);
+		scrn = xf86ConfigFbEntity(scrn, 0, entity,
+					   NULL, NULL, NULL, NULL);
 	    }
-	}
-    }
-#else
-    /* Look for Intel i8xx devices. */
-    numUsed = xf86MatchPciInstances("modesetting", PCI_VENDOR_INTEL,
-				    Chipsets, PciDevices,
-				    devSections, numDevSections,
-				    drv, &usedChips);
-#endif
 
-    if (flags & PROBE_DETECT) {
-	if (numUsed > 0)
-	    foundScreen = TRUE;
-    } else {
-	for (i = 0; i < numUsed; i++) {
-	    ScrnInfoPtr pScrn = NULL;
-
-	    /* Allocate new ScrnInfoRec and claim the slot */
-	    if ((pScrn = xf86ConfigPciEntity(pScrn, 0, usedChips[i],
-					     PciDevices, NULL, NULL, NULL,
-					     NULL, NULL))) {
-		EntityInfoPtr pEnt;
-
-		pEnt = xf86GetEntityInfo(usedChips[i]);
-
-		pScrn->driverVersion = 1;
-		pScrn->driverName = "modesetting";
-		pScrn->name = "modesetting";
-		pScrn->Probe = Probe;
+	    if (scrn)
 		foundScreen = TRUE;
-		{
-		    /* Allocate an entity private if necessary */
-		    if (modesettingEntityIndex < 0)
-			modesettingEntityIndex =
-			    xf86AllocateEntityPrivateIndex();
-
-		    pPriv = xf86GetEntityPrivate(pScrn->entityList[0],
-						 modesettingEntityIndex);
-		    if (!pPriv->ptr) {
-			pPriv->ptr = xnfcalloc(sizeof(EntRec), 1);
-			msEnt = pPriv->ptr;
-			msEnt->lastInstance = -1;
-		    } else {
-			msEnt = pPriv->ptr;
-		    }
-
-		    /*
-		     * Set the entity instance for this instance of the driver.
-		     * For dual head per card, instance 0 is the "master"
-		     * instance, driving the primary head, and instance 1 is
-		     * the "slave".
-		     */
-		    msEnt->lastInstance++;
-		    xf86SetEntityInstanceForScreen(pScrn,
-						   pScrn->entityList[0],
-						   msEnt->lastInstance);
-		    pScrn->PreInit = PreInit;
-		    pScrn->ScreenInit = ScreenInit;
-		    pScrn->SwitchMode = SwitchMode;
-		    pScrn->AdjustFrame = AdjustFrame;
-		    pScrn->EnterVT = EnterVT;
-		    pScrn->LeaveVT = LeaveVT;
-		    pScrn->FreeScreen = FreeScreen;
-		    pScrn->ValidMode = ValidMode;
-		    break;
-		}
-	    } else
-		ErrorF("FAILED PSCRN\n");
+		scrn->driverVersion = 1;
+		scrn->driverName = "modesetting";
+		scrn->name = "modesetting";
+		scrn->Probe = Probe;
+		scrn->PreInit = PreInit;
+		scrn->ScreenInit = ScreenInit;
+		scrn->SwitchMode = SwitchMode;
+		scrn->AdjustFrame = AdjustFrame;
+		scrn->EnterVT = EnterVT;
+		scrn->LeaveVT = LeaveVT;
+		scrn->FreeScreen = FreeScreen;
+		scrn->ValidMode = ValidMode;
+
+		xf86DrvMsg(scrn->scrnIndex, X_INFO,
+			   "using %s\n", dev ? dev : "default device");
 	}
     }
 
-    free(usedChips);
     free(devSections);
 
     return foundScreen;
 }
-#endif
 
 static Bool
 GetRec(ScrnInfoPtr pScrn)
commit a77fae850511c4d73af2af2b88804586f950f28d
Author: Dave Airlie <airlied at redhat.com>
Date:   Thu Sep 29 11:52:51 2011 +0100

    cleanup some the drmmode_display header file

diff --git a/hw/xfree86/drivers/modesetting/drmmode_display.h b/hw/xfree86/drivers/modesetting/drmmode_display.h
index 2d72505..845207a 100644
--- a/hw/xfree86/drivers/modesetting/drmmode_display.h
+++ b/hw/xfree86/drivers/modesetting/drmmode_display.h
@@ -33,49 +33,33 @@
 #endif
 
 struct dumb_bo {
-  uint32_t handle;
-  uint32_t size;
-  void *ptr;
-  int map_count;
-  uint32_t pitch;
+    uint32_t handle;
+    uint32_t size;
+    void *ptr;
+    int map_count;
+    uint32_t pitch;
 };
 
 typedef struct {
-  int fd;
-  unsigned fb_id;
-  drmModeResPtr mode_res;
-  drmModeFBPtr mode_fb;
-  int cpp;
-  ScrnInfoPtr scrn;
+    int fd;
+    unsigned fb_id;
+    drmModeResPtr mode_res;
+    drmModeFBPtr mode_fb;
+    int cpp;
+    ScrnInfoPtr scrn;
 #ifdef HAVE_UDEV
-  struct udev_monitor *uevent_monitor;
-  InputHandlerProc uevent_handler;
+    struct udev_monitor *uevent_monitor;
+    InputHandlerProc uevent_handler;
 #endif
-  drmEventContext event_context;
-  struct dumb_bo *front_bo;
+    drmEventContext event_context;
+    struct dumb_bo *front_bo;
 } drmmode_rec, *drmmode_ptr;
 
 typedef struct {
-  drmmode_ptr drmmode;
-  unsigned old_fb_id;
-  int flip_count;
-  void *event_data;
-  unsigned int fe_frame;
-  unsigned int fe_tv_sec;
-  unsigned int fe_tv_usec;
-} drmmode_flipdata_rec, *drmmode_flipdata_ptr;
-
-typedef struct {
-  drmmode_flipdata_ptr flipdata;
-  Bool dispatch_me;
-} drmmode_flipevtcarrier_rec, *drmmode_flipevtcarrier_ptr;
-
-typedef struct {
     drmmode_ptr drmmode;
     drmModeCrtcPtr mode_crtc;
     int hw_id;
     struct dumb_bo *cursor_bo;
-  //    struct radeon_bo *rotate_bo;
     unsigned rotate_fb_id;
     uint16_t lut_r[256], lut_g[256], lut_b[256];
 } drmmode_crtc_private_rec, *drmmode_crtc_private_ptr;
@@ -103,21 +87,13 @@ typedef struct {
 
 
 extern Bool drmmode_pre_init(ScrnInfoPtr pScrn, drmmode_ptr drmmode, int cpp);
-//extern Bool drmmode_set_bufmgr(ScrnInfoPtr pScrn, drmmode_ptr drmmode, struct radeon_bo_manager *bufmgr);
-//extern void drmmode_set_cursor(ScrnInfoPtr scrn, drmmode_ptr drmmode, int id, struct radeon_bo *bo);
 void drmmode_adjust_frame(ScrnInfoPtr pScrn, drmmode_ptr drmmode, int x, int y, int flags);
 extern Bool drmmode_set_desired_modes(ScrnInfoPtr pScrn, drmmode_ptr drmmode);
-extern void drmmode_copy_fb(ScrnInfoPtr pScrn, drmmode_ptr drmmode);
 extern Bool drmmode_setup_colormap(ScreenPtr pScreen, ScrnInfoPtr pScrn);
 
 extern void drmmode_uevent_init(ScrnInfoPtr scrn, drmmode_ptr drmmode);
 extern void drmmode_uevent_fini(ScrnInfoPtr scrn, drmmode_ptr drmmode);
 
-extern int drmmode_get_height_align(ScrnInfoPtr scrn, uint32_t tiling);
-extern int drmmode_get_pitch_align(ScrnInfoPtr scrn, int bpe, uint32_t tiling);
-extern int drmmode_get_base_align(ScrnInfoPtr scrn, int bpe, uint32_t tiling);
-
-//Bool radeon_do_pageflip(ScrnInfoPtr scrn, struct radeon_bo *new_front, void *data, int ref_crtc_hw_id);
 Bool drmmode_create_initial_bos(ScrnInfoPtr pScrn, drmmode_ptr drmmode);
 void *drmmode_map_front_bo(drmmode_ptr drmmode);
 Bool drmmode_map_cursor_bos(ScrnInfoPtr pScrn, drmmode_ptr drmmode);
commit 2a4618905445ce13fd272a4634ef5103dc804231
Author: Dave Airlie <airlied at redhat.com>
Date:   Thu Sep 29 11:49:26 2011 +0100

    modesetting: restart driver effort from other codebases
    
    This starts a randr 1.2 compatible driver with cursors.
    
    TODO:
    libkms
    dirty handling
    server recycling.

diff --git a/hw/xfree86/drivers/modesetting/Makefile.am b/hw/xfree86/drivers/modesetting/Makefile.am
index 23e78b7..4337977 100644
--- a/hw/xfree86/drivers/modesetting/Makefile.am
+++ b/hw/xfree86/drivers/modesetting/Makefile.am
@@ -25,19 +25,16 @@ SUBDIRS =
 # _ladir passes a dummy rpath to libtool so the thing will actually link
 # TODO: -nostdlib/-Bstatic/-lgcc platform magic, not installing the .a, etc.
 
-AM_CFLAGS = @WARN_CFLAGS@ @XORG_CFLAGS@ @DRI_CFLAGS@ @PCIACCESS_CFLAGS@ \
-	-I at GALLIUM_DIR@/src/gallium/include \
-	-I at GALLIUM_DIR@/src/gallium/auxiliary
+AM_CFLAGS = @XORG_CFLAGS@ @DRM_CFLAGS@ @UDEV_CFLAGS@
 
 modesetting_drv_la_LTLIBRARIES = modesetting_drv.la
-modesetting_drv_la_LDFLAGS = -module -avoid-version -ldrm
+modesetting_drv_la_LDFLAGS = -module -avoid-version
+modesetting_drv_la_LIBADD = @UDEV_LIBS@ @DRM_LIBS@
 modesetting_drv_ladir = @moduledir@/drivers
 
 modesetting_drv_la_SOURCES = \
 	 driver.c \
 	 driver.h \
-	 output.c \
-	 crtc.c \
-	 dri2.c
+	 drmmode_display.c
 
 EXTRA_DIST =
diff --git a/hw/xfree86/drivers/modesetting/crtc.c b/hw/xfree86/drivers/modesetting/crtc.c
deleted file mode 100644
index d4f449b..0000000
--- a/hw/xfree86/drivers/modesetting/crtc.c
+++ /dev/null
@@ -1,307 +0,0 @@
-/*
- * Copyright 2008 Tungsten Graphics, 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 TUNGSTEN GRAPHICS 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.
- *
- *
- * Author: Alan Hourihane <alanh at tungstengraphics.com>
- *
- */
-
-#ifdef HAVE_CONFIG_H
-#include "config.h"
-#endif
-
-#include <unistd.h>
-#include <string.h>
-#include <assert.h>
-#include <stdlib.h>
-#include <math.h>
-#include <stdint.h>
-
-#include <xf86.h>
-#include <xf86i2c.h>
-#include <xf86Crtc.h>
-#include "driver.h"
-#include "xf86Modes.h"
-
-#define DPMS_SERVER
-#include <X11/extensions/dpms.h>
-
-struct crtc_private
-{
-    drmModeCrtcPtr drm_crtc;
-
-    /* hwcursor */
-    drmBO cursor_bo;
-};
-
-static void
-crtc_dpms(xf86CrtcPtr crtc, int mode)
-{
-    ScrnInfoPtr pScrn = crtc->scrn;
-
-    switch (mode) {
-    case DPMSModeOn:
-    case DPMSModeStandby:
-    case DPMSModeSuspend:
-	break;
-    case DPMSModeOff:
-	break;
-    }
-}
-
-static Bool
-crtc_lock(xf86CrtcPtr crtc)
-{
-    return FALSE;
-}
-
-static void
-crtc_unlock(xf86CrtcPtr crtc)
-{
-}
-
-static void
-crtc_prepare(xf86CrtcPtr crtc)
-{
-}
-
-static void
-crtc_commit(xf86CrtcPtr crtc)
-{
-}
-
-static Bool
-crtc_mode_fixup(xf86CrtcPtr crtc, DisplayModePtr mode,
-		DisplayModePtr adjusted_mode)
-{
-    return TRUE;
-}
-
-static void
-crtc_mode_set(xf86CrtcPtr crtc, DisplayModePtr mode,
-	      DisplayModePtr adjusted_mode, int x, int y)
-{
-    xf86CrtcConfigPtr config = XF86_CRTC_CONFIG_PTR(crtc->scrn);
-    modesettingPtr ms = modesettingPTR(crtc->scrn);
-    xf86OutputPtr output = config->output[config->compat_output];
-    drmModeConnectorPtr drm_connector = output->driver_private;
-    struct crtc_private *crtcp = crtc->driver_private;
-    drmModeCrtcPtr drm_crtc = crtcp->drm_crtc;
-    struct drm_mode_modeinfo drm_mode;
-
-    drm_mode.clock = mode->Clock;
-    drm_mode.hdisplay = mode->HDisplay;
-    drm_mode.hsync_start = mode->HSyncStart;
-    drm_mode.hsync_end = mode->HSyncEnd;
-    drm_mode.htotal = mode->HTotal;
-    drm_mode.vdisplay = mode->VDisplay;
-    drm_mode.vsync_start = mode->VSyncStart;
-    drm_mode.vsync_end = mode->VSyncEnd;
-    drm_mode.vtotal = mode->VTotal;
-    drm_mode.flags = mode->Flags;
-    drm_mode.hskew = mode->HSkew;
-    drm_mode.vscan = mode->VScan;
-    drm_mode.vrefresh = mode->VRefresh;
-    if (!mode->name)
-	xf86SetModeDefaultName(mode);
-    strncpy(drm_mode.name, mode->name, DRM_DISPLAY_MODE_LEN);
-
-    drmModeSetCrtc(ms->fd, drm_crtc->crtc_id, ms->fb_id, x, y,
-		   &drm_connector->connector_id, 1, &drm_mode);
-}
-
-void
-crtc_load_lut(xf86CrtcPtr crtc)
-{
-    ScrnInfoPtr pScrn = crtc->scrn;
-}
-
-static void
-crtc_gamma_set(xf86CrtcPtr crtc, CARD16 * red, CARD16 * green, CARD16 * blue,
-	       int size)
-{
-}
-
-static void *
-crtc_shadow_allocate(xf86CrtcPtr crtc, int width, int height)
-{
-    ScrnInfoPtr pScrn = crtc->scrn;
-
-    return NULL;
-}
-
-static PixmapPtr
-crtc_shadow_create(xf86CrtcPtr crtc, void *data, int width, int height)
-{
-    ScrnInfoPtr pScrn = crtc->scrn;
-
-    return NULL;
-}
-
-static void
-crtc_shadow_destroy(xf86CrtcPtr crtc, PixmapPtr rotate_pixmap, void *data)
-{
-    ScrnInfoPtr pScrn = crtc->scrn;
-}
-
-static void
-crtc_destroy(xf86CrtcPtr crtc)
-{
-    modesettingPtr ms = modesettingPTR(crtc->scrn);
-    struct crtc_private *crtcp = crtc->driver_private;
-
-    if (crtcp->cursor_bo.handle)
-	drmBOUnreference(ms->fd, &crtcp->cursor_bo);
-
-    drmModeFreeCrtc(crtcp->drm_crtc);
-    xfree(crtcp);
-}
-
-static void
-crtc_load_cursor_argb(xf86CrtcPtr crtc, CARD32 * image)
-{
-    unsigned char *ptr;
-    modesettingPtr ms = modesettingPTR(crtc->scrn);
-    struct crtc_private *crtcp = crtc->driver_private;
-
-    if (!crtcp->cursor_bo.handle)
-	drmBOCreate(ms->fd, 64 * 64 * 4, 0, NULL,
-		    DRM_BO_FLAG_READ | DRM_BO_FLAG_WRITE
-		    | DRM_BO_FLAG_NO_EVICT | DRM_BO_FLAG_MAPPABLE |
-		    DRM_BO_FLAG_MEM_VRAM,
-		    DRM_BO_HINT_DONT_FENCE, &crtcp->cursor_bo);
-
-    drmBOMap(ms->fd, &crtcp->cursor_bo, DRM_BO_FLAG_WRITE,
-	     DRM_BO_HINT_DONT_FENCE, (void **)&ptr);
-
-    if (ptr)
-	memcpy(ptr, image, 64 * 64 * 4);
-
-    drmBOUnmap(ms->fd, &crtcp->cursor_bo);
-}
-
-static void
-crtc_set_cursor_position(xf86CrtcPtr crtc, int x, int y)
-{
-    modesettingPtr ms = modesettingPTR(crtc->scrn);
-    struct crtc_private *crtcp = crtc->driver_private;
-
-    drmModeMoveCursor(ms->fd, crtcp->drm_crtc->crtc_id, x, y);
-}
-
-static void
-crtc_show_cursor(xf86CrtcPtr crtc)
-{
-    modesettingPtr ms = modesettingPTR(crtc->scrn);
-    struct crtc_private *crtcp = crtc->driver_private;
-
-    if (crtcp->cursor_bo.handle)
-	drmModeSetCursor(ms->fd, crtcp->drm_crtc->crtc_id,
-			 crtcp->cursor_bo.handle, 64, 64);
-}
-
-static void
-crtc_hide_cursor(xf86CrtcPtr crtc)
-{
-    modesettingPtr ms = modesettingPTR(crtc->scrn);
-    struct crtc_private *crtcp = crtc->driver_private;
-
-    drmModeSetCursor(ms->fd, crtcp->drm_crtc->crtc_id, 0, 0, 0);
-}
-
-static const xf86CrtcFuncsRec crtc_funcs = {
-    .dpms = crtc_dpms,
-    .save = NULL,
-    .restore = NULL,
-    .lock = crtc_lock,
-    .unlock = crtc_unlock,
-    .mode_fixup = crtc_mode_fixup,
-    .prepare = crtc_prepare,
-    .mode_set = crtc_mode_set,
-    .commit = crtc_commit,
-    .gamma_set = crtc_gamma_set,
-    .shadow_create = crtc_shadow_create,
-    .shadow_allocate = crtc_shadow_allocate,
-    .shadow_destroy = crtc_shadow_destroy,
-    .set_cursor_position = crtc_set_cursor_position,
-    .show_cursor = crtc_show_cursor,
-    .hide_cursor = crtc_hide_cursor,
-    .load_cursor_image = NULL,	       /* lets convert to argb only */
-    .set_cursor_colors = NULL,	       /* using argb only */
-    .load_cursor_argb = crtc_load_cursor_argb,
-    .destroy = crtc_destroy,
-};
-
-void
-cursor_destroy(xf86CrtcPtr crtc)
-{
-    modesettingPtr ms = modesettingPTR(crtc->scrn);
-    struct crtc_private *crtcp = crtc->driver_private;
-
-    if (crtcp->cursor_bo.handle) {
-	drmBOSetStatus(ms->fd, &crtcp->cursor_bo, 0, 0, 0, 0, 0);
-	drmBOUnreference(ms->fd, &crtcp->cursor_bo);
-    }
-}
-
-void
-crtc_init(ScrnInfoPtr pScrn)
-{
-    modesettingPtr ms = modesettingPTR(pScrn);
-    xf86CrtcPtr crtc;
-    drmModeResPtr res;
-    drmModeCrtcPtr drm_crtc = NULL;
-    struct crtc_private *crtcp;
-    int c, k, p;
-
-    res = drmModeGetResources(ms->fd);
-    if (res == 0) {
-	ErrorF("Failed drmModeGetResources %d\n", errno);
-	return;
-    }
-
-    for (c = 0; c < res->count_crtcs; c++) {
-	drm_crtc = drmModeGetCrtc(ms->fd, res->crtcs[c]);
-	if (!drm_crtc)
-	    continue;
-
-	crtc = xf86CrtcCreate(pScrn, &crtc_funcs);
-	if (crtc == NULL)
-	    goto out;
-
-	crtcp = xcalloc(1, sizeof(struct crtc_private));
-	if (!crtcp) {
-	    xf86CrtcDestroy(crtc);
-	    goto out;
-	}
-
-	crtcp->drm_crtc = drm_crtc;
-
-	crtc->driver_private = crtcp;
-
-    }
-
-  out:
-    drmModeFreeResources(res);
-}
diff --git a/hw/xfree86/drivers/modesetting/dri2.c b/hw/xfree86/drivers/modesetting/dri2.c
deleted file mode 100644
index 7fd9fca..0000000
--- a/hw/xfree86/drivers/modesetting/dri2.c
+++ /dev/null
@@ -1,128 +0,0 @@
-/*
- * Copyright 2008 Tungsten Graphics, 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 TUNGSTEN GRAPHICS 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.
- *
- *
- * Author: Alan Hourihane <alanh at tungstengraphics.com>
- *
- */
-#ifdef HAVE_CONFIG_H
-#include "config.h"
-#endif
-
-#include "xf86.h"
-#include "xf86_OSproc.h"
-
-#include "driver.h"
-
-#include "dri2.h"
-
-extern unsigned int
-driGetPixmapHandle(PixmapPtr pPixmap, unsigned int *flags);
-
-void
-driLock(ScreenPtr pScreen)
-{
-    ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
-    modesettingPtr ms = modesettingPTR(pScrn);
-
-    if (!ms->lock_held)
-	DRM_LOCK(ms->fd, ms->lock, ms->context, 0);
-
-    ms->lock_held = 1;
-}
-
-void
-driUnlock(ScreenPtr pScreen)
-{
-    ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
-    modesettingPtr ms = modesettingPTR(pScrn);
-
-    if (ms->lock_held)
-	DRM_UNLOCK(ms->fd, ms->lock, ms->context);
-
-    ms->lock_held = 0;
-}
-
-static void
-driBeginClipNotify(ScreenPtr pScreen)
-{
-    driLock(pScreen);
-}
-
-static void
-driEndClipNotify(ScreenPtr pScreen)
-{
-    driUnlock(pScreen);
-}
-
-struct __DRILock
-{
-    unsigned int block_header;
-    drm_hw_lock_t lock;
-    unsigned int next_id;
-};
-
-#define DRI2_SAREA_BLOCK_HEADER(type, size) (((type) << 16) | (size))
-#define DRI2_SAREA_BLOCK_LOCK		0x0001
-
-void
-driScreenInit(ScreenPtr pScreen)
-{
-    ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
-    modesettingPtr ms = modesettingPTR(pScrn);
-    DRI2InfoRec dri2info;
-    const char *driverName;
-    unsigned int sarea_handle;
-    struct __DRILock *DRILock;
-    void *p;
-
-    dri2info.version = 1;
-    dri2info.fd = ms->fd;
-    dri2info.driverSareaSize = sizeof(struct __DRILock);
-    dri2info.driverName = "i915";      /* FIXME */
-    dri2info.getPixmapHandle = driGetPixmapHandle;
-    dri2info.beginClipNotify = driBeginClipNotify;
-    dri2info.endClipNotify = driEndClipNotify;
-
-    p = DRI2ScreenInit(pScreen, &dri2info);
-    if (!p)
-	return;
-
-    DRILock = p;
-    DRILock->block_header =
-	DRI2_SAREA_BLOCK_HEADER(DRI2_SAREA_BLOCK_LOCK, sizeof *DRILock);
-    ms->lock = &DRILock->lock;
-    ms->context = 1;
-    DRILock->next_id = 2;
-    driLock(pScreen);
-
-    DRI2Connect(pScreen, &ms->fd, &driverName, &sarea_handle);
-}
-
-void
-driCloseScreen(ScreenPtr pScreen)
-{
-    driUnlock(pScreen);
-    DRI2CloseScreen(pScreen);
-}
diff --git a/hw/xfree86/drivers/modesetting/driver.c b/hw/xfree86/drivers/modesetting/driver.c
index 6b70d4b..47ffb07 100644
--- a/hw/xfree86/drivers/modesetting/driver.c
+++ b/hw/xfree86/drivers/modesetting/driver.c
@@ -34,10 +34,8 @@
 #include "xf86.h"
 #include "xf86_OSproc.h"
 #include "compiler.h"
-#include "xf86RAC.h"
 #include "xf86PciInfo.h"
 #include "xf86Pci.h"
-#include "xf86Resources.h"
 #include "mipointer.h"
 #include "micmap.h"
 #include <X11/extensions/randr.h>
@@ -59,8 +57,6 @@
 static void AdjustFrame(int scrnIndex, int x, int y, int flags);
 static Bool CloseScreen(int scrnIndex, ScreenPtr pScreen);
 static Bool EnterVT(int scrnIndex, int flags);
-static Bool SaveHWState(ScrnInfoPtr pScrn);
-static Bool RestoreHWState(ScrnInfoPtr pScrn);
 static void Identify(int flags);
 static const OptionInfoRec *AvailableOptions(int chipid, int busid);
 static ModeStatus ValidMode(int scrnIndex, DisplayModePtr mode, Bool verbose,
@@ -82,7 +78,7 @@ static Bool Probe(DriverPtr drv, int flags);
 
 #if XSERVER_LIBPCIACCESS
 static const struct pci_id_match device_match[] = {
-    {0x8086, 0x2592, 0xffff, 0xffff, 0, 0, 0},
+    {0x8086, 0x0046, 0xffff, 0xffff, 0, 0, 0},
     {0, 0, 0},
 };
 #endif
@@ -107,12 +103,12 @@ _X_EXPORT DriverRec modesetting = {
 };
 
 static SymTabRec Chipsets[] = {
-    {0x2592, "Intel Graphics Device"},
+    {0x0046, "Intel Graphics Device"},
     {-1, NULL}
 };
 
 static PciChipsets PciDevices[] = {
-    {0x2592, 0x2592, RES_SHARED_VGA},
+    {0x2592, 0x0046, RES_SHARED_VGA},
     {-1, -1, RES_UNDEFINED}
 };
 
@@ -126,24 +122,6 @@ static const OptionInfoRec Options[] = {
     {-1, NULL, OPTV_NONE, {0}, FALSE}
 };
 
-static const char *fbSymbols[] = {
-    "fbPictureInit",
-    "fbScreenInit",
-    NULL
-};
-
-static const char *ddcSymbols[] = {
-    "xf86PrintEDID",
-    "xf86SetDDCproperties",
-    NULL
-};
-
-static const char *i2cSymbols[] = {
-    "xf86CreateI2CBusRec",
-    "xf86I2CBusInit",
-    NULL
-};
-
 int modesettingEntityIndex = -1;
 
 static MODULESETUPPROTO(Setup);
@@ -175,12 +153,6 @@ Setup(pointer module, pointer opts, int *errmaj, int *errmin)
 	xf86AddDriver(&modesetting, module, HaveDriverFuncs);
 
 	/*
-	 * Tell the loader about symbols from other modules that this module
-	 * might refer to.
-	 */
-	LoaderRefSymLists(fbSymbols, ddcSymbols, NULL);
-
-	/*
 	 * The return value must be non-NULL on success even though there
 	 * is no TearDownProc.
 	 */
@@ -225,7 +197,7 @@ pci_probe(DriverPtr driver,
 	entity = xf86GetEntityInfo(entity_num);
 
 	switch (device->device_id) {
-	case 0x2592:
+	case 0x0046:
 	    scrn->PreInit = PreInit;
 	    scrn->ScreenInit = ScreenInit;
 	    scrn->SwitchMode = SwitchMode;
@@ -358,8 +330,8 @@ Probe(DriverPtr drv, int flags)
 	}
     }
 
-    xfree(usedChips);
-    xfree(devSections);
+    free(usedChips);
+    free(devSections);
 
     return foundScreen;
 }
@@ -385,76 +357,11 @@ FreeRec(ScrnInfoPtr pScrn)
     if (!pScrn->driverPrivate)
 	return;
 
-    xfree(pScrn->driverPrivate);
+    free(pScrn->driverPrivate);
 
     pScrn->driverPrivate = NULL;
 }
 
-static void
-ProbeDDC(ScrnInfoPtr pScrn, int index)
-{
-    ConfiguredMonitor = NULL;
-}
-
-static Bool
-CreateFrontBuffer(ScrnInfoPtr pScrn)
-{
-    modesettingPtr ms = modesettingPTR(pScrn);
-    ScreenPtr pScreen = pScrn->pScreen;
-    PixmapPtr rootPixmap = pScreen->GetScreenPixmap(pScreen);
-    Bool fbAccessDisabled;
-    int flags;
-
-    pScreen->ModifyPixmapHeader(rootPixmap,
-				pScrn->virtualX, pScrn->virtualY,
-				pScrn->depth, pScrn->bitsPerPixel,
-				pScrn->displayWidth * pScrn->bitsPerPixel / 8,
-				NULL);
-    drmModeAddFB(ms->fd,
-		 pScrn->virtualX,
-		 pScrn->virtualY,
-		 pScrn->depth,
-		 pScrn->bitsPerPixel,
-		 pScrn->displayWidth * pScrn->bitsPerPixel / 8,
-		 driGetPixmapHandle(rootPixmap, &flags), &ms->fb_id);
-
-    pScrn->frameX0 = 0;
-    pScrn->frameY0 = 0;
-    AdjustFrame(pScrn->scrnIndex, pScrn->frameX0, pScrn->frameY0, 0);
-
-    return TRUE;
-}
-
-static Bool
-crtc_resize(ScrnInfoPtr pScrn, int width, int height)
-{
-    modesettingPtr ms = modesettingPTR(pScrn);
-    ScreenPtr pScreen = pScrn->pScreen;
-    PixmapPtr rootPixmap = pScreen->GetScreenPixmap(pScreen);
-    Bool fbAccessDisabled;
-    CARD8 *fbstart;
-
-    if (width == pScrn->virtualX && height == pScrn->virtualY)
-	return TRUE;
-
-    ErrorF("RESIZING TO %dx%d\n", width, height);
-
-    pScrn->virtualX = width;
-    pScrn->virtualY = height;
-
-    /* HW dependent - FIXME */
-    pScrn->displayWidth = pScrn->virtualX;
-
-    drmModeRmFB(ms->fd, ms->fb_id);
-
-    /* now create new frontbuffer */
-    return CreateFrontBuffer(pScrn);
-}
-
-static const xf86CrtcConfigFuncsRec crtc_config_funcs = {
-    crtc_resize
-};
-
 static Bool
 PreInit(ScrnInfoPtr pScrn, int flags)
 {
@@ -476,8 +383,7 @@ PreInit(ScrnInfoPtr pScrn, int flags)
     pEnt = xf86GetEntityInfo(pScrn->entityList[0]);
 
     if (flags & PROBE_DETECT) {
-	ProbeDDC(pScrn, pEnt->index);
-	return TRUE;
+	return FALSE;
     }
 
     /* Allocate driverPrivate */
@@ -503,10 +409,6 @@ PreInit(ScrnInfoPtr pScrn, int flags)
     } else
 	ms->entityPrivate = NULL;
 
-    if (xf86RegisterResources(ms->pEnt->index, NULL, ResNone)) {
-	return FALSE;
-    }
-
     if (xf86IsEntityShared(pScrn->entityList[0])) {
 	if (xf86IsPrimInitDone(pScrn->entityList[0])) {
 	    /* do something */
@@ -515,7 +417,7 @@ PreInit(ScrnInfoPtr pScrn, int flags)
 	}
     }
 
-    BusID = xalloc(64);
+    BusID = malloc(64);
     sprintf(BusID, "PCI:%d:%d:%d",
 #if XSERVER_LIBPCIACCESS
 	    ((ms->PciInfo->domain << 8) | ms->PciInfo->bus),
@@ -528,11 +430,9 @@ PreInit(ScrnInfoPtr pScrn, int flags)
 	);
 
     ms->fd = drmOpen(NULL, BusID);
-
     if (ms->fd < 0)
 	return FALSE;
 
-    pScrn->racMemFlags = RAC_FB | RAC_COLORMAP;
     pScrn->monitor = pScrn->confScreen->monitor;
     pScrn->progClock = TRUE;
     pScrn->rgbBits = 8;
@@ -562,36 +462,21 @@ PreInit(ScrnInfoPtr pScrn, int flags)
 
     /* Process the options */
     xf86CollectOptions(pScrn, NULL);
-    if (!(ms->Options = xalloc(sizeof(Options))))
+    if (!(ms->Options = malloc(sizeof(Options))))
 	return FALSE;
     memcpy(ms->Options, Options, sizeof(Options));
     xf86ProcessOptions(pScrn->scrnIndex, pScrn->options, ms->Options);
 
-    /* Allocate an xf86CrtcConfig */
-    xf86CrtcConfigInit(pScrn, &crtc_config_funcs);
-    xf86_config = XF86_CRTC_CONFIG_PTR(pScrn);
-
-    max_width = 8192;
-    max_height = 8192;
-    xf86CrtcSetSizeRange(pScrn, 320, 200, max_width, max_height);
-
     if (xf86ReturnOptValBool(ms->Options, OPTION_SW_CURSOR, FALSE)) {
 	ms->SWCursor = TRUE;
     }
 
-    SaveHWState(pScrn);
-
-    crtc_init(pScrn);
-    output_init(pScrn);
-
-    if (!xf86InitialConfiguration(pScrn, TRUE)) {
-	xf86DrvMsg(pScrn->scrnIndex, X_ERROR, "No valid modes.\n");
-	RestoreHWState(pScrn);
-	return FALSE;
+    ms->drmmode.fd = ms->fd;
+    if (drmmode_pre_init(pScrn, &ms->drmmode, pScrn->bitsPerPixel / 8) == FALSE) {
+	xf86DrvMsg(pScrn->scrnIndex, X_ERROR, "KMS setup failed\n");
+	goto fail;
     }
 
-    RestoreHWState(pScrn);
-
     /*
      * If the driver can do gamma correction, it should call xf86SetGamma() here.
      */
@@ -618,29 +503,13 @@ PreInit(ScrnInfoPtr pScrn, int flags)
 	return FALSE;
     }
 
-    xf86LoaderReqSymLists(fbSymbols, NULL);
-
 #ifdef DRI2
     xf86LoadSubModule(pScrn, "dri2");
 #endif
 
     return TRUE;
-}
-
-static Bool
-SaveHWState(ScrnInfoPtr pScrn)
-{
-    xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(pScrn);
-
-    return TRUE;
-}
-
-static Bool
-RestoreHWState(ScrnInfoPtr pScrn)
-{
-    xf86CrtcConfigPtr config = XF86_CRTC_CONFIG_PTR(pScrn);
-
-    return TRUE;
+    fail:
+    return FALSE;
 }
 
 static Bool
@@ -651,25 +520,24 @@ CreateScreenResources(ScreenPtr pScreen)
     PixmapPtr rootPixmap;
     Bool ret;
     int flags;
-
+    void *pixels;
     pScreen->CreateScreenResources = ms->createScreenResources;
     ret = pScreen->CreateScreenResources(pScreen);
     pScreen->CreateScreenResources = CreateScreenResources;
 
-    rootPixmap = pScreen->GetScreenPixmap(pScreen);
+    if (!drmmode_set_desired_modes(pScrn, &ms->drmmode))
+      return FALSE;
 
-    if (!pScreen->ModifyPixmapHeader(rootPixmap, -1, -1, -1, -1, -1, NULL))
-	FatalError("Couldn't adjust screen pixmap\n");
+    drmmode_uevent_init(pScrn, &ms->drmmode);
 
-    drmModeAddFB(ms->fd,
-		 pScrn->virtualX,
-		 pScrn->virtualY,
-		 pScrn->depth,
-		 pScrn->bitsPerPixel,
-		 pScrn->displayWidth * pScrn->bitsPerPixel / 8,
-		 driGetPixmapHandle(rootPixmap, &flags), &ms->fb_id);
+    drmmode_map_cursor_bos(pScrn, &ms->drmmode);
+    pixels = drmmode_map_front_bo(&ms->drmmode);
+    if (!pixels)
+	return FALSE;
 
-    AdjustFrame(pScrn->scrnIndex, pScrn->frameX0, pScrn->frameY0, 0);
+    rootPixmap = pScreen->GetScreenPixmap(pScreen);
+    if (!pScreen->ModifyPixmapHeader(rootPixmap, -1, -1, -1, -1, -1, pixels))
+	FatalError("Couldn't adjust screen pixmap\n");
 
     return ret;
 }
@@ -688,7 +556,7 @@ ScreenInit(int scrnIndex, ScreenPtr pScreen, int argc, char **argv)
     if (ms->fd < 0) {
 	char *BusID;
 
-	BusID = xalloc(64);
+	BusID = malloc(64);
 	sprintf(BusID, "PCI:%d:%d:%d",
 #if XSERVER_LIBPCIACCESS
 		((ms->PciInfo->domain << 8) | ms->PciInfo->bus),
@@ -710,6 +578,8 @@ ScreenInit(int scrnIndex, ScreenPtr pScreen, int argc, char **argv)
 
     /* HW dependent - FIXME */
     pScrn->displayWidth = pScrn->virtualX;
+    if (!drmmode_create_initial_bos(pScrn, &ms->drmmode))
+	return FALSE;
 
     miClearVisualTypes();
 
@@ -782,10 +652,6 @@ ScreenInit(int scrnIndex, ScreenPtr pScreen, int argc, char **argv)
     if (serverGeneration == 1)
 	xf86ShowUnusedOptions(pScrn->scrnIndex, pScrn->options);
 
-#ifdef DRI2
-    driScreenInit(pScreen);
-#endif
-
     return EnterVT(scrnIndex, 1);
 }
 
@@ -822,7 +688,7 @@ LeaveVT(int scrnIndex, int flags)
     for (o = 0; o < config->num_crtc; o++) {
 	xf86CrtcPtr crtc = config->crtc[o];
 
-	cursor_destroy(crtc);
+	//	cursor_destroy(crtc);
 
 	if (crtc->rotatedPixmap || crtc->rotatedData) {
 	    crtc->funcs->shadow_destroy(crtc, crtc->rotatedPixmap,
@@ -834,16 +700,6 @@ LeaveVT(int scrnIndex, int flags)
 
     drmModeRmFB(ms->fd, ms->fb_id);
 
-    RestoreHWState(pScrn);
-
-#if 0
-    drmMMLock(ms->fd, DRM_BO_MEM_VRAM, 1, 0);
-    drmMMLock(ms->fd, DRM_BO_MEM_TT, 1, 0);
-#endif
-#ifdef DRI2
-    driLock(pScrn->pScreen);
-#endif
-
     pScrn->vtSema = FALSE;
 }
 
@@ -856,29 +712,6 @@ EnterVT(int scrnIndex, int flags)
     ScrnInfoPtr pScrn = xf86Screens[scrnIndex];
     modesettingPtr ms = modesettingPTR(pScrn);
 
-#if 0
-    if (pScrn->vtSema) {
-	drmMMUnlock(ms->fd, DRM_BO_MEM_VRAM, 1);
-	drmMMUnlock(ms->fd, DRM_BO_MEM_TT, 1);
-    }
-#endif
-
-#ifdef DRI2
-    driUnlock(pScrn->pScreen);
-#endif
-
-    /*
-     * Only save state once per server generation since that's what most
-     * drivers do.  Could change this to save state at each VT enter.
-     */
-    if (ms->SaveGeneration != serverGeneration) {
-	ms->SaveGeneration = serverGeneration;
-	SaveHWState(pScrn);
-    }
-
-    if (!flags)			       /* signals startup as we'll do this in CreateScreenResources */
-	CreateFrontBuffer(pScrn);
-
     if (!xf86SetDesiredModes(pScrn))
 	return FALSE;
 
@@ -899,16 +732,13 @@ CloseScreen(int scrnIndex, ScreenPtr pScreen)
     ScrnInfoPtr pScrn = xf86Screens[scrnIndex];
     modesettingPtr ms = modesettingPTR(pScrn);
 
+    drmmode_uevent_fini(pScrn, &ms->drmmode);
+
+    drmmode_free_bos(pScrn, &ms->drmmode);
+
     if (pScrn->vtSema) {
 	LeaveVT(scrnIndex, 0);
-#if 0
-	drmMMUnlock(ms->fd, DRM_BO_MEM_VRAM, 1);
-	drmMMUnlock(ms->fd, DRM_BO_MEM_TT, 1);
-#endif
     }
-#ifdef DRI2
-    driCloseScreen(pScreen);
-#endif
 
     pScreen->CreateScreenResources = ms->createScreenResources;
 
diff --git a/hw/xfree86/drivers/modesetting/driver.h b/hw/xfree86/drivers/modesetting/driver.h
index a673f8f..255dede 100644
--- a/hw/xfree86/drivers/modesetting/driver.h
+++ b/hw/xfree86/drivers/modesetting/driver.h
@@ -30,9 +30,8 @@
 #include <errno.h>
 #include <drm.h>
 #include <xf86drm.h>
-#include <xf86drmMode.h>
-#include <xf86mm.h>
 
+#include "drmmode_display.h"
 #define DRV_ERROR(msg)	xf86DrvMsg(pScrn->scrnIndex, X_ERROR, msg);
 
 typedef struct
@@ -72,10 +71,7 @@ typedef struct _modesettingRec
 
     void *driver;
 
-    /* dri2 */
-    drm_context_t context;
-    drm_hw_lock_t *lock;
-    int lock_held;
+    drmmode_rec drmmode;
 } modesettingRec, *modesettingPtr;
 
 #define modesettingPTR(p) ((modesettingPtr)((p)->driverPrivate))
diff --git a/hw/xfree86/drivers/modesetting/drmmode_display.c b/hw/xfree86/drivers/modesetting/drmmode_display.c
new file mode 100644
index 0000000..d94ce03
--- /dev/null
+++ b/hw/xfree86/drivers/modesetting/drmmode_display.c
@@ -0,0 +1,1340 @@
+/*
+ * Copyright © 2007 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.
+ *
+ * Authors:
+ *    Dave Airlie <airlied at redhat.com>
+ *
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <errno.h>
+#include <sys/ioctl.h>
+#include <sys/mman.h>
+#include "xf86str.h"
+#include "X11/Xatom.h"
+#include "micmap.h"
+#include "xf86cmap.h"
+#include "xf86DDC.h"
+
+#include <xf86drm.h>
+#include "xf86Crtc.h"
+#include "drmmode_display.h"
+
+/* DPMS */
+#ifdef HAVE_XEXTPROTO_71
+#include <X11/extensions/dpmsconst.h>
+#else
+#define DPMS_SERVER
+#include <X11/extensions/dpms.h>
+#endif
+
+static struct dumb_bo *dumb_bo_create(int fd,
+			  const unsigned width, const unsigned height,
+			  const unsigned bpp)
+{
+	struct drm_mode_create_dumb arg;
+	struct dumb_bo *bo;
+	int ret;
+
+	bo = calloc(1, sizeof(*bo));
+	if (!bo)
+		return NULL;
+
+	memset(&arg, 0, sizeof(arg));
+	arg.width = width;
+	arg.height = height;
+	arg.bpp = bpp;
+	
+	ret = drmIoctl(fd, DRM_IOCTL_MODE_CREATE_DUMB, &arg);
+	if (ret)
+		goto err_free;
+
+	bo->handle = arg.handle;
+	bo->size = arg.size;
+	bo->pitch = arg.pitch;
+
+	return bo;
+ err_free:
+	free(bo);
+	return NULL;
+}
+
+static int dumb_bo_map(int fd, struct dumb_bo *bo)
+{
+	struct drm_mode_map_dumb arg;
+	int ret;
+	void *map;
+
+	if (bo->ptr) {
+		bo->map_count++;
+		return 0;
+	}
+
+	memset(&arg, 0, sizeof(arg));
+	arg.handle = bo->handle;
+
+	ret = drmIoctl(fd, DRM_IOCTL_MODE_MAP_DUMB, &arg);
+	if (ret)
+		return ret;
+
+	map = mmap(0, bo->size, PROT_READ | PROT_WRITE, MAP_SHARED,
+		   fd, arg.offset);
+	if (map == MAP_FAILED)
+		return -errno;
+
+	bo->ptr = map;
+	return 0;
+}
+
+static int dumb_bo_unmap(int fd, struct dumb_bo *bo)
+{
+	bo->map_count--;
+	return 0;
+}
+
+static int dumb_bo_destroy(int fd, struct dumb_bo *bo)
+{
+	struct drm_mode_destroy_dumb arg;
+	int ret;
+	
+	if (bo->ptr) {
+		munmap(bo->ptr, bo->size);
+		bo->ptr = NULL;
+	}
+
+	memset(&arg, 0, sizeof(arg));
+	arg.handle = bo->handle;
+	ret = drmIoctl(fd, DRM_IOCTL_MODE_DESTROY_DUMB, &arg);
+	if (ret)
+		return -errno;
+
+	free(bo);
+	return 0;
+}
+
+static void
+drmmode_ConvertFromKMode(ScrnInfoPtr	scrn,
+		     drmModeModeInfo *kmode,
+		     DisplayModePtr	mode)
+{
+	memset(mode, 0, sizeof(DisplayModeRec));
+	mode->status = MODE_OK;
+
+	mode->Clock = kmode->clock;
+
+	mode->HDisplay = kmode->hdisplay;
+	mode->HSyncStart = kmode->hsync_start;
+	mode->HSyncEnd = kmode->hsync_end;
+	mode->HTotal = kmode->htotal;
+	mode->HSkew = kmode->hskew;
+
+	mode->VDisplay = kmode->vdisplay;
+	mode->VSyncStart = kmode->vsync_start;
+	mode->VSyncEnd = kmode->vsync_end;
+	mode->VTotal = kmode->vtotal;
+	mode->VScan = kmode->vscan;
+
+	mode->Flags = kmode->flags; //& FLAG_BITS;
+	mode->name = strdup(kmode->name);
+
+	if (kmode->type & DRM_MODE_TYPE_DRIVER)
+		mode->type = M_T_DRIVER;
+	if (kmode->type & DRM_MODE_TYPE_PREFERRED)
+		mode->type |= M_T_PREFERRED;
+	xf86SetModeCrtc (mode, scrn->adjustFlags);
+}
+
+static void
+drmmode_ConvertToKMode(ScrnInfoPtr	scrn,
+		     drmModeModeInfo *kmode,
+		     DisplayModePtr	mode)
+{
+	memset(kmode, 0, sizeof(*kmode));
+
+	kmode->clock = mode->Clock;
+	kmode->hdisplay = mode->HDisplay;
+	kmode->hsync_start = mode->HSyncStart;
+	kmode->hsync_end = mode->HSyncEnd;
+	kmode->htotal = mode->HTotal;
+	kmode->hskew = mode->HSkew;
+
+	kmode->vdisplay = mode->VDisplay;
+	kmode->vsync_start = mode->VSyncStart;
+	kmode->vsync_end = mode->VSyncEnd;
+	kmode->vtotal = mode->VTotal;
+	kmode->vscan = mode->VScan;
+
+	kmode->flags = mode->Flags; //& FLAG_BITS;
+	if (mode->name)
+		strncpy(kmode->name, mode->name, DRM_DISPLAY_MODE_LEN);
+	kmode->name[DRM_DISPLAY_MODE_LEN-1] = 0;
+
+}
+
+static void
+drmmode_crtc_dpms(xf86CrtcPtr crtc, int mode)
+{
+#if 0
+	xf86CrtcConfigPtr   xf86_config = XF86_CRTC_CONFIG_PTR(crtc->scrn);
+//	drmmode_crtc_private_ptr drmmode_crtc = crtc->driver_private;
+//	drmmode_ptr drmmode = drmmode_crtc->drmmode;
+
+	/* bonghits in the randr 1.2 - uses dpms to disable crtc - bad buzz */
+	if (mode == DPMSModeOff) {
+//		drmModeSetCrtc(drmmode->fd, drmmode_crtc->mode_crtc->crtc_id,
+//			       0, 0, 0, NULL, 0, NULL);
+	}
+#endif
+}
+
+#if 0
+static PixmapPtr
+create_pixmap_for_fbcon(drmmode_ptr drmmode,
+			ScrnInfoPtr pScrn, int crtc_id)
+{
+	xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(pScrn);
+	drmmode_crtc_private_ptr drmmode_crtc;
+	ScreenPtr pScreen = pScrn->pScreen;
+	PixmapPtr pixmap;
+	struct radeon_bo *bo;
+	drmModeFBPtr fbcon;
+	struct drm_gem_flink flink;
+
+	drmmode_crtc = xf86_config->crtc[crtc_id]->driver_private;
+
+	fbcon = drmModeGetFB(drmmode->fd, drmmode_crtc->mode_crtc->buffer_id);
+	if (fbcon == NULL)
+		return NULL;
+
+	flink.handle = fbcon->handle;
+	if (ioctl(drmmode->fd, DRM_IOCTL_GEM_FLINK, &flink) < 0) {
+		xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
+			   "Couldn't flink fbcon handle\n");
+		return NULL;
+	}
+
+	bo = radeon_bo_open(drmmode->bufmgr, flink.name, 0, 0, 0, 0);
+	if (bo == NULL) {
+		xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
+			   "Couldn't allocate bo for fbcon handle\n");
+		return NULL;
+	}
+
+	pixmap = drmmode_create_bo_pixmap(pScreen, fbcon->width, fbcon->height,
+					  fbcon->depth, fbcon->bpp,
+					  fbcon->pitch, bo);
+	if (!pixmap) 
+		return NULL;
+
+	radeon_bo_unref(bo);
+	drmModeFreeFB(fbcon);
+	return pixmap;
+}
+
+#endif
+
+static Bool
+drmmode_set_mode_major(xf86CrtcPtr crtc, DisplayModePtr mode,
+		     Rotation rotation, int x, int y)
+{
+	ScrnInfoPtr pScrn = crtc->scrn;
+	//	RADEONInfoPtr info = RADEONPTR(pScrn);
+	xf86CrtcConfigPtr   xf86_config = XF86_CRTC_CONFIG_PTR(crtc->scrn);
+	drmmode_crtc_private_ptr drmmode_crtc = crtc->driver_private;
+	drmmode_ptr drmmode = drmmode_crtc->drmmode;
+	int saved_x, saved_y;
+	Rotation saved_rotation;
+	DisplayModeRec saved_mode;
+	uint32_t *output_ids;
+	int output_count = 0;
+	Bool ret = TRUE;
+	int i;
+	int fb_id;
+	drmModeModeInfo kmode;
+	int pitch;
+	uint32_t tiling_flags = 0;
+	int height;
+
+	pitch = pScrn->displayWidth;
+	height = pScrn->virtualY;
+
+	if (drmmode->fb_id == 0) {
+		ret = drmModeAddFB(drmmode->fd,
+				   pScrn->virtualX, height,
+                                   pScrn->depth, pScrn->bitsPerPixel,
+				   drmmode->front_bo->pitch,
+				   drmmode->front_bo->handle,
+                                   &drmmode->fb_id);
+                if (ret < 0) {
+                        ErrorF("failed to add fb %d\n", ret);
+                        return FALSE;
+                }
+        }
+
+	saved_mode = crtc->mode;
+	saved_x = crtc->x;
+	saved_y = crtc->y;
+	saved_rotation = crtc->rotation;
+
+	if (mode) {
+		crtc->mode = *mode;
+		crtc->x = x;
+		crtc->y = y;
+		crtc->rotation = rotation;
+#if XORG_VERSION_CURRENT >= XORG_VERSION_NUMERIC(1,5,99,0,0)
+		crtc->transformPresent = FALSE;
+#endif
+	}
+
+	output_ids = calloc(sizeof(uint32_t), xf86_config->num_output);
+	if (!output_ids) {
+		ret = FALSE;
+		goto done;
+	}
+
+	if (mode) {
+		for (i = 0; i < xf86_config->num_output; i++) {
+			xf86OutputPtr output = xf86_config->output[i];
+			drmmode_output_private_ptr drmmode_output;
+
+			if (output->crtc != crtc)
+				continue;
+
+			drmmode_output = output->driver_private;
+			output_ids[output_count] = drmmode_output->mode_output->connector_id;
+			output_count++;
+		}
+
+		if (!xf86CrtcRotate(crtc)) {
+			goto done;
+		}
+#if XORG_VERSION_CURRENT >= XORG_VERSION_NUMERIC(1,7,0,0,0)
+		crtc->funcs->gamma_set(crtc, crtc->gamma_red, crtc->gamma_green,
+				       crtc->gamma_blue, crtc->gamma_size);
+#endif
+		
+		drmmode_ConvertToKMode(crtc->scrn, &kmode, mode);
+
+		fb_id = drmmode->fb_id;
+		if (drmmode_crtc->rotate_fb_id) {
+			fb_id = drmmode_crtc->rotate_fb_id;
+			x = y = 0;
+		}
+		ret = drmModeSetCrtc(drmmode->fd, drmmode_crtc->mode_crtc->crtc_id,
+				     fb_id, x, y, output_ids, output_count, &kmode);
+		if (ret)
+			xf86DrvMsg(crtc->scrn->scrnIndex, X_ERROR,
+				   "failed to set mode: %s", strerror(-ret));
+		else
+			ret = TRUE;
+
+		if (crtc->scrn->pScreen)
+			xf86CrtcSetScreenSubpixelOrder(crtc->scrn->pScreen);
+		/* go through all the outputs and force DPMS them back on? */
+		for (i = 0; i < xf86_config->num_output; i++) {
+			xf86OutputPtr output = xf86_config->output[i];
+
+			if (output->crtc != crtc)
+				continue;
+
+			output->funcs->dpms(output, DPMSModeOn);
+		}
+	}
+
+#if 0
+	if (pScrn->pScreen &&
+		!xf86ReturnOptValBool(info->Options, OPTION_SW_CURSOR, FALSE))
+		xf86_reload_cursors(pScrn->pScreen);
+#endif
+done:
+	if (!ret) {
+		crtc->x = saved_x;
+		crtc->y = saved_y;
+		crtc->rotation = saved_rotation;
+		crtc->mode = saved_mode;
+	}
+#if defined(XF86_CRTC_VERSION) && XF86_CRTC_VERSION >= 3
+	else
+		crtc->active = TRUE;
+#endif
+
+	return ret;
+}
+
+static void
+drmmode_set_cursor_colors (xf86CrtcPtr crtc, int bg, int fg)
+{
+
+}
+
+static void
+drmmode_set_cursor_position (xf86CrtcPtr crtc, int x, int y)
+{
+	drmmode_crtc_private_ptr drmmode_crtc = crtc->driver_private;
+	drmmode_ptr drmmode = drmmode_crtc->drmmode;
+
+	drmModeMoveCursor(drmmode->fd, drmmode_crtc->mode_crtc->crtc_id, x, y);
+}
+
+static void
+drmmode_load_cursor_argb (xf86CrtcPtr crtc, CARD32 *image)
+{
+	drmmode_crtc_private_ptr drmmode_crtc = crtc->driver_private;
+	int i;
+	uint32_t *ptr;
+
+	/* cursor should be mapped already */
+	ptr = (uint32_t *)(drmmode_crtc->cursor_bo->ptr);
+
+	for (i = 0; i < 64 * 64; i++)
+		ptr[i] = image[i];// cpu_to_le32(image[i]);
+}
+
+
+static void
+drmmode_hide_cursor (xf86CrtcPtr crtc)
+{
+	drmmode_crtc_private_ptr drmmode_crtc = crtc->driver_private;
+	drmmode_ptr drmmode = drmmode_crtc->drmmode;
+
+	drmModeSetCursor(drmmode->fd, drmmode_crtc->mode_crtc->crtc_id, 0, 64, 64);
+
+}
+
+static void
+drmmode_show_cursor (xf86CrtcPtr crtc)
+{
+	drmmode_crtc_private_ptr drmmode_crtc = crtc->driver_private;
+	drmmode_ptr drmmode = drmmode_crtc->drmmode;
+	uint32_t handle = drmmode_crtc->cursor_bo->handle;
+
+	drmModeSetCursor(drmmode->fd, drmmode_crtc->mode_crtc->crtc_id, handle, 64, 64);
+}
+
+static void
+drmmode_crtc_gamma_set(xf86CrtcPtr crtc, uint16_t *red, uint16_t *green,
+                      uint16_t *blue, int size)
+{
+	drmmode_crtc_private_ptr drmmode_crtc = crtc->driver_private;
+	drmmode_ptr drmmode = drmmode_crtc->drmmode;
+
+	drmModeCrtcSetGamma(drmmode->fd, drmmode_crtc->mode_crtc->crtc_id,
+			    size, red, green, blue);
+}
+
+static const xf86CrtcFuncsRec drmmode_crtc_funcs = {
+    .dpms = drmmode_crtc_dpms,
+    .set_mode_major = drmmode_set_mode_major,
+    .set_cursor_colors = drmmode_set_cursor_colors,
+    .set_cursor_position = drmmode_set_cursor_position,
+    .show_cursor = drmmode_show_cursor,
+    .hide_cursor = drmmode_hide_cursor,
+    .load_cursor_argb = drmmode_load_cursor_argb,
+
+    .gamma_set = drmmode_crtc_gamma_set,
+    .destroy = NULL, /* XXX */
+};
+
+int drmmode_get_crtc_id(xf86CrtcPtr crtc)
+{
+	drmmode_crtc_private_ptr drmmode_crtc = crtc->driver_private;
+	return drmmode_crtc->hw_id;
+}
+
+static void
+drmmode_crtc_init(ScrnInfoPtr pScrn, drmmode_ptr drmmode, int num)
+{
+	xf86CrtcPtr crtc;
+	drmmode_crtc_private_ptr drmmode_crtc;
+
+	crtc = xf86CrtcCreate(pScrn, &drmmode_crtc_funcs);
+	if (crtc == NULL)
+		return;
+
+	drmmode_crtc = xnfcalloc(sizeof(drmmode_crtc_private_rec), 1);
+	drmmode_crtc->mode_crtc = drmModeGetCrtc(drmmode->fd, drmmode->mode_res->crtcs[num]);
+	drmmode_crtc->drmmode = drmmode;
+	crtc->driver_private = drmmode_crtc;
+}
+
+static xf86OutputStatus
+drmmode_output_detect(xf86OutputPtr output)
+{
+	/* go to the hw and retrieve a new output struct */
+	drmmode_output_private_ptr drmmode_output = output->driver_private;
+	drmmode_ptr drmmode = drmmode_output->drmmode;
+	xf86OutputStatus status;
+	drmModeFreeConnector(drmmode_output->mode_output);
+
+	drmmode_output->mode_output = drmModeGetConnector(drmmode->fd, drmmode_output->output_id);
+
+	switch (drmmode_output->mode_output->connection) {
+	case DRM_MODE_CONNECTED:
+		status = XF86OutputStatusConnected;
+		break;
+	case DRM_MODE_DISCONNECTED:
+		status = XF86OutputStatusDisconnected;
+		break;
+	default:
+	case DRM_MODE_UNKNOWNCONNECTION:
+		status = XF86OutputStatusUnknown;
+		break;
+	}
+	return status;
+}
+
+static Bool
+drmmode_output_mode_valid(xf86OutputPtr output, DisplayModePtr pModes)
+{
+	return MODE_OK;
+}
+
+static DisplayModePtr
+drmmode_output_get_modes(xf86OutputPtr output)
+{
+	drmmode_output_private_ptr drmmode_output = output->driver_private;
+	drmModeConnectorPtr koutput = drmmode_output->mode_output;
+	drmmode_ptr drmmode = drmmode_output->drmmode;
+	int i;
+	DisplayModePtr Modes = NULL, Mode;
+	drmModePropertyPtr props;
+	xf86MonPtr mon = NULL;
+
+	/* look for an EDID property */
+	for (i = 0; i < koutput->count_props; i++) {
+		props = drmModeGetProperty(drmmode->fd, koutput->props[i]);
+		if (props && (props->flags & DRM_MODE_PROP_BLOB)) {
+			if (!strcmp(props->name, "EDID")) {
+				if (drmmode_output->edid_blob)
+					drmModeFreePropertyBlob(drmmode_output->edid_blob);
+				drmmode_output->edid_blob = drmModeGetPropertyBlob(drmmode->fd, koutput->prop_values[i]);
+			}
+			drmModeFreeProperty(props);
+		}
+	}
+
+	if (drmmode_output->edid_blob) {
+		mon = xf86InterpretEDID(output->scrn->scrnIndex,
+					drmmode_output->edid_blob->data);
+		if (mon && drmmode_output->edid_blob->length > 128)
+			mon->flags |= MONITOR_EDID_COMPLETE_RAWDATA;
+	}
+	xf86OutputSetEDID(output, mon);
+
+	/* modes should already be available */
+	for (i = 0; i < koutput->count_modes; i++) {
+		Mode = xnfalloc(sizeof(DisplayModeRec));
+
+		drmmode_ConvertFromKMode(output->scrn, &koutput->modes[i], Mode);
+		Modes = xf86ModesAdd(Modes, Mode);
+
+	}
+	return Modes;
+}
+
+static void
+drmmode_output_destroy(xf86OutputPtr output)
+{
+	drmmode_output_private_ptr drmmode_output = output->driver_private;
+	int i;
+
+	if (drmmode_output->edid_blob)
+		drmModeFreePropertyBlob(drmmode_output->edid_blob);
+	for (i = 0; i < drmmode_output->num_props; i++) {
+		drmModeFreeProperty(drmmode_output->props[i].mode_prop);
+		free(drmmode_output->props[i].atoms);
+	}
+	for (i = 0; i < drmmode_output->mode_output->count_encoders; i++) {
+		drmModeFreeEncoder(drmmode_output->mode_encoders[i]);
+		free(drmmode_output->mode_encoders);
+	}
+	free(drmmode_output->props);
+	drmModeFreeConnector(drmmode_output->mode_output);
+	free(drmmode_output);
+	output->driver_private = NULL;
+}
+
+static void
+drmmode_output_dpms(xf86OutputPtr output, int mode)
+{
+	drmmode_output_private_ptr drmmode_output = output->driver_private;
+	drmModeConnectorPtr koutput = drmmode_output->mode_output;
+	drmmode_ptr drmmode = drmmode_output->drmmode;
+
+	drmModeConnectorSetProperty(drmmode->fd, koutput->connector_id,
+				    drmmode_output->dpms_enum_id, mode);
+	return;
+}
+
+
+static Bool
+drmmode_property_ignore(drmModePropertyPtr prop)
+{
+    if (!prop)
+	return TRUE;
+    /* ignore blob prop */
+    if (prop->flags & DRM_MODE_PROP_BLOB)
+	return TRUE;
+    /* ignore standard property */
+    if (!strcmp(prop->name, "EDID") ||
+	    !strcmp(prop->name, "DPMS"))
+	return TRUE;
+
+    return FALSE;
+}
+
+static void
+drmmode_output_create_resources(xf86OutputPtr output)
+{
+    drmmode_output_private_ptr drmmode_output = output->driver_private;
+    drmModeConnectorPtr mode_output = drmmode_output->mode_output;
+    drmmode_ptr drmmode = drmmode_output->drmmode;
+    drmModePropertyPtr drmmode_prop;
+    int i, j, err;
+
+    drmmode_output->props = calloc(mode_output->count_props, sizeof(drmmode_prop_rec));
+    if (!drmmode_output->props)
+	return;
+    
+    drmmode_output->num_props = 0;
+    for (i = 0, j = 0; i < mode_output->count_props; i++) {
+	drmmode_prop = drmModeGetProperty(drmmode->fd, mode_output->props[i]);
+	if (drmmode_property_ignore(drmmode_prop)) {
+	    drmModeFreeProperty(drmmode_prop);
+	    continue;
+	}
+	drmmode_output->props[j].mode_prop = drmmode_prop;
+	drmmode_output->props[j].value = mode_output->prop_values[i];
+	drmmode_output->num_props++;
+	j++;
+    }
+
+    for (i = 0; i < drmmode_output->num_props; i++) {
+	drmmode_prop_ptr p = &drmmode_output->props[i];
+	drmmode_prop = p->mode_prop;
+
+	if (drmmode_prop->flags & DRM_MODE_PROP_RANGE) {
+	    INT32 range[2];
+	    INT32 value = p->value;
+
+	    p->num_atoms = 1;
+	    p->atoms = calloc(p->num_atoms, sizeof(Atom));
+	    if (!p->atoms)
+		continue;
+	    p->atoms[0] = MakeAtom(drmmode_prop->name, strlen(drmmode_prop->name), TRUE);
+	    range[0] = drmmode_prop->values[0];
+	    range[1] = drmmode_prop->values[1];
+	    err = RRConfigureOutputProperty(output->randr_output, p->atoms[0],
+		    FALSE, TRUE,
+		    drmmode_prop->flags & DRM_MODE_PROP_IMMUTABLE ? TRUE : FALSE,
+		    2, range);
+	    if (err != 0) {
+		xf86DrvMsg(output->scrn->scrnIndex, X_ERROR,
+			"RRConfigureOutputProperty error, %d\n", err);
+	    }
+	    err = RRChangeOutputProperty(output->randr_output, p->atoms[0],
+		    XA_INTEGER, 32, PropModeReplace, 1, &value, FALSE, TRUE);
+	    if (err != 0) {
+		xf86DrvMsg(output->scrn->scrnIndex, X_ERROR,
+			"RRChangeOutputProperty error, %d\n", err);
+	    }
+	} else if (drmmode_prop->flags & DRM_MODE_PROP_ENUM) {
+	    p->num_atoms = drmmode_prop->count_enums + 1;
+	    p->atoms = calloc(p->num_atoms, sizeof(Atom));
+	    if (!p->atoms)
+		continue;
+	    p->atoms[0] = MakeAtom(drmmode_prop->name, strlen(drmmode_prop->name), TRUE);
+	    for (j = 1; j <= drmmode_prop->count_enums; j++) {
+		struct drm_mode_property_enum *e = &drmmode_prop->enums[j-1];
+		p->atoms[j] = MakeAtom(e->name, strlen(e->name), TRUE);
+	    }
+	    err = RRConfigureOutputProperty(output->randr_output, p->atoms[0],
+		    FALSE, FALSE,
+		    drmmode_prop->flags & DRM_MODE_PROP_IMMUTABLE ? TRUE : FALSE,
+		    p->num_atoms - 1, (INT32 *)&p->atoms[1]);
+	    if (err != 0) {
+		xf86DrvMsg(output->scrn->scrnIndex, X_ERROR,
+			"RRConfigureOutputProperty error, %d\n", err);
+	    }
+	    for (j = 0; j < drmmode_prop->count_enums; j++)
+		if (drmmode_prop->enums[j].value == p->value)
+		    break;
+	    /* there's always a matching value */
+	    err = RRChangeOutputProperty(output->randr_output, p->atoms[0],
+		    XA_ATOM, 32, PropModeReplace, 1, &p->atoms[j+1], FALSE, TRUE);
+	    if (err != 0) {
+		xf86DrvMsg(output->scrn->scrnIndex, X_ERROR,
+			"RRChangeOutputProperty error, %d\n", err);
+	    }
+	}
+    }
+}
+
+static Bool
+drmmode_output_set_property(xf86OutputPtr output, Atom property,
+		RRPropertyValuePtr value)
+{
+    drmmode_output_private_ptr drmmode_output = output->driver_private;
+    drmmode_ptr drmmode = drmmode_output->drmmode;
+    int i;
+
+    for (i = 0; i < drmmode_output->num_props; i++) {
+	drmmode_prop_ptr p = &drmmode_output->props[i];
+
+	if (p->atoms[0] != property)
+	    continue;
+
+	if (p->mode_prop->flags & DRM_MODE_PROP_RANGE) {
+	    uint32_t val;
+
+	    if (value->type != XA_INTEGER || value->format != 32 ||
+		    value->size != 1)
+		return FALSE;
+	    val = *(uint32_t *)value->data;
+
+	    drmModeConnectorSetProperty(drmmode->fd, drmmode_output->output_id,
+		    p->mode_prop->prop_id, (uint64_t)val);
+	    return TRUE;
+	} else if (p->mode_prop->flags & DRM_MODE_PROP_ENUM) {
+	    Atom	atom;
+	    const char	*name;
+	    int		j;
+
+	    if (value->type != XA_ATOM || value->format != 32 || value->size != 1)
+		return FALSE;
+	    memcpy(&atom, value->data, 4);
+	    name = NameForAtom(atom);
+
+	    /* search for matching name string, then set its value down */
+	    for (j = 0; j < p->mode_prop->count_enums; j++) {
+		if (!strcmp(p->mode_prop->enums[j].name, name)) {
+		    drmModeConnectorSetProperty(drmmode->fd, drmmode_output->output_id,
+			    p->mode_prop->prop_id, p->mode_prop->enums[j].value);
+		    return TRUE;
+		}
+	    }
+	}
+    }
+
+    return TRUE;
+}
+
+static Bool
+drmmode_output_get_property(xf86OutputPtr output, Atom property)
+{
+    return TRUE;
+}
+
+static const xf86OutputFuncsRec drmmode_output_funcs = {
+    .dpms = drmmode_output_dpms,
+    .create_resources = drmmode_output_create_resources,
+#ifdef RANDR_12_INTERFACE
+    .set_property = drmmode_output_set_property,
+    .get_property = drmmode_output_get_property,
+#endif
+    .detect = drmmode_output_detect,
+    .mode_valid = drmmode_output_mode_valid,
+
+    .get_modes = drmmode_output_get_modes,
+    .destroy = drmmode_output_destroy
+};
+
+static int subpixel_conv_table[7] = { 0, SubPixelUnknown,
+				      SubPixelHorizontalRGB,
+				      SubPixelHorizontalBGR,
+				      SubPixelVerticalRGB,
+				      SubPixelVerticalBGR,
+				      SubPixelNone };
+
+const char *output_names[] = { "None",
+			       "VGA",
+			       "DVI",
+			       "DVI",
+			       "DVI",
+			       "Composite",
+			       "S-video",
+			       "LVDS",
+			       "CTV",
+			       "DIN",
+			       "DisplayPort",
+			       "HDMI",
+			       "HDMI",
+			       "TV",
+			       "eDP"
+};
+
+static void
+drmmode_output_init(ScrnInfoPtr pScrn, drmmode_ptr drmmode, int num, int *num_dvi, int *num_hdmi)
+{
+	xf86OutputPtr output;
+	drmModeConnectorPtr koutput;
+	drmModeEncoderPtr *kencoders = NULL;
+	drmmode_output_private_ptr drmmode_output;
+	drmModePropertyPtr props;
+	char name[32];
+	int i;
+	const char *s;
+
+	koutput = drmModeGetConnector(drmmode->fd, drmmode->mode_res->connectors[num]);
+	if (!koutput)
+		return;
+
+	kencoders = calloc(sizeof(drmModeEncoderPtr), koutput->count_encoders);
+	if (!kencoders) {
+		goto out_free_encoders;
+	}
+
+	for (i = 0; i < koutput->count_encoders; i++) {
+		kencoders[i] = drmModeGetEncoder(drmmode->fd, koutput->encoders[i]);
+		if (!kencoders[i]) {
+			goto out_free_encoders;
+		}
+	}
+
+	/* need to do smart conversion here for compat with non-kms ATI driver */
+	snprintf(name, 32, "%s-%d", output_names[koutput->connector_type], koutput->connector_type_id - 1);
+
+	output = xf86OutputCreate (pScrn, &drmmode_output_funcs, name);
+	if (!output) {
+		goto out_free_encoders;
+	}
+
+	drmmode_output = calloc(sizeof(drmmode_output_private_rec), 1);
+	if (!drmmode_output) {
+		xf86OutputDestroy(output);
+		goto out_free_encoders;
+	}
+
+	drmmode_output->output_id = drmmode->mode_res->connectors[num];
+	drmmode_output->mode_output = koutput;
+	drmmode_output->mode_encoders = kencoders;
+	drmmode_output->drmmode = drmmode;
+	output->mm_width = koutput->mmWidth;
+	output->mm_height = koutput->mmHeight;
+
+	output->subpixel_order = subpixel_conv_table[koutput->subpixel];
+	output->interlaceAllowed = TRUE;
+	output->doubleScanAllowed = TRUE;
+	output->driver_private = drmmode_output;
+	
+	output->possible_crtcs = 0x7f;
+	for (i = 0; i < koutput->count_encoders; i++) {
+		output->possible_crtcs &= kencoders[i]->possible_crtcs;
+	}
+	/* work out the possible clones later */
+	output->possible_clones = 0;
+
+	for (i = 0; i < koutput->count_props; i++) {
+		props = drmModeGetProperty(drmmode->fd, koutput->props[i]);
+		if (props && (props->flags & DRM_MODE_PROP_ENUM)) {
+			if (!strcmp(props->name, "DPMS")) {
+				drmmode_output->dpms_enum_id = koutput->props[i];
+				drmModeFreeProperty(props);
+				break;
+			}
+			drmModeFreeProperty(props);
+		}
+	}
+
+	return;
+out_free_encoders:
+	if (kencoders){
+		for (i = 0; i < koutput->count_encoders; i++)
+			drmModeFreeEncoder(kencoders[i]);
+		free(kencoders);
+	}
+	drmModeFreeConnector(koutput);
+	
+}
+
+uint32_t find_clones(ScrnInfoPtr scrn, xf86OutputPtr output)
+{
+	drmmode_output_private_ptr drmmode_output = output->driver_private, clone_drmout;
+	int i;
+	xf86OutputPtr clone_output;
+	xf86CrtcConfigPtr   xf86_config = XF86_CRTC_CONFIG_PTR(scrn);
+	int index_mask = 0;
+
+	if (drmmode_output->enc_clone_mask == 0)
+		return index_mask;
+
+	for (i = 0; i < xf86_config->num_output; i++) {
+		clone_output = xf86_config->output[i];
+		clone_drmout = clone_output->driver_private;
+		if (output == clone_output)
+			continue;
+		
+		if (clone_drmout->enc_mask == 0)
+			continue;
+		if (drmmode_output->enc_clone_mask == clone_drmout->enc_mask)
+			index_mask |= (1 << i);
+	}
+	return index_mask;
+}
+
+
+static void
+drmmode_clones_init(ScrnInfoPtr scrn, drmmode_ptr drmmode)
+{
+	int i, j;
+	xf86CrtcConfigPtr   xf86_config = XF86_CRTC_CONFIG_PTR(scrn);
+
+	for (i = 0; i < xf86_config->num_output; i++) {
+		xf86OutputPtr output = xf86_config->output[i];
+		drmmode_output_private_ptr drmmode_output;
+
+		drmmode_output = output->driver_private;
+		drmmode_output->enc_clone_mask = 0xff;
+		/* and all the possible encoder clones for this output together */
+		for (j = 0; j < drmmode_output->mode_output->count_encoders; j++)
+		{
+			int k;
+			for (k = 0; k < drmmode->mode_res->count_encoders; k++) {
+				if (drmmode->mode_res->encoders[k] == drmmode_output->mode_encoders[j]->encoder_id)
+					drmmode_output->enc_mask |= (1 << k);
+			}
+
+			drmmode_output->enc_clone_mask &= drmmode_output->mode_encoders[j]->possible_clones;
+		}
+	}
+
+	for (i = 0; i < xf86_config->num_output; i++) {
+		xf86OutputPtr output = xf86_config->output[i];
+		output->possible_clones = find_clones(scrn, output);
+	}
+}
+
+static Bool
+drmmode_xf86crtc_resize (ScrnInfoPtr scrn, int width, int height)
+{
+	xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(scrn);
+	drmmode_crtc_private_ptr
+		    drmmode_crtc = xf86_config->crtc[0]->driver_private;
+	drmmode_ptr drmmode = drmmode_crtc->drmmode;
+	struct dumb_bo *old_front = NULL;
+	Bool	    ret;
+	ScreenPtr   screen = screenInfo.screens[scrn->scrnIndex];
+	uint32_t    old_fb_id;
+	int	    i, pitch, old_width, old_height, old_pitch;
+	int screen_size;
+	int cpp = (scrn->bitsPerPixel + 1) / 8;
+	struct dumb_bo *front_bo;
+	uint32_t tiling_flags = 0;
+	PixmapPtr ppix = screen->GetScreenPixmap(screen);
+	void *new_pixels;
+
+	if (scrn->virtualX == width && scrn->virtualY == height)
+		return TRUE;
+
+	xf86DrvMsg(scrn->scrnIndex, X_INFO,
+		   "Allocate new frame buffer %dx%d stride %d\n",
+		   width, height, pitch / cpp);
+
+	old_width = scrn->virtualX;
+	old_height = scrn->virtualY;
+	old_pitch = scrn->displayWidth;
+	old_fb_id = drmmode->fb_id;
+	old_front = drmmode->front_bo;
+
+	drmmode->front_bo = dumb_bo_create(drmmode->fd, width, height, scrn->bitsPerPixel);
+	if (!drmmode->front_bo)
+		goto fail;
+
+	pitch = drmmode->front_bo->pitch;
+
+	scrn->virtualX = width;
+	scrn->virtualY = height;
+	scrn->displayWidth = pitch / cpp;
+
+	ret = drmModeAddFB(drmmode->fd, width, height, scrn->depth,
+			   scrn->bitsPerPixel, pitch,
+			   drmmode->front_bo->handle,
+			   &drmmode->fb_id);
+	if (ret)
+		goto fail;
+	
+	new_pixels  = drmmode_map_front_bo(drmmode);
+	if (!new_pixels)
+		goto fail;
+
+	screen->ModifyPixmapHeader(ppix, width, height, -1, -1,
+				   pitch, new_pixels);
+
+#if XORG_VERSION_CURRENT < XORG_VERSION_NUMERIC(1,9,99,1,0)
+	scrn->pixmapPrivate.ptr = ppix->devPrivate.ptr;
+#endif
+
+	for (i = 0; i < xf86_config->num_crtc; i++) {
+		xf86CrtcPtr crtc = xf86_config->crtc[i];
+
+		if (!crtc->enabled)
+			continue;
+
+		drmmode_set_mode_major(crtc, &crtc->mode,
+				       crtc->rotation, crtc->x, crtc->y);
+	}
+
+	if (old_fb_id) {
+		drmModeRmFB(drmmode->fd, old_fb_id);
+		dumb_bo_destroy(drmmode->fd, old_front);
+	}
+
+	return TRUE;
+
+ fail:
+	if (drmmode->front_bo)
+		dumb_bo_destroy(drmmode->fd, drmmode->front_bo);
+	drmmode->front_bo = old_front;
+	scrn->virtualX = old_width;
+	scrn->virtualY = old_height;
+	scrn->displayWidth = old_pitch;
+	drmmode->fb_id = old_fb_id;
+
+	return FALSE;
+}
+
+static const xf86CrtcConfigFuncsRec drmmode_xf86crtc_config_funcs = {
+	drmmode_xf86crtc_resize
+};
+
+Bool drmmode_pre_init(ScrnInfoPtr pScrn, drmmode_ptr drmmode, int cpp)
+{
+	xf86CrtcConfigPtr xf86_config;
+	int i, num_dvi = 0, num_hdmi = 0;
+
+	xf86CrtcConfigInit(pScrn, &drmmode_xf86crtc_config_funcs);
+	xf86_config = XF86_CRTC_CONFIG_PTR(pScrn);
+
+	drmmode->scrn = pScrn;
+	drmmode->cpp = cpp;
+	drmmode->mode_res = drmModeGetResources(drmmode->fd);
+	if (!drmmode->mode_res)
+		return FALSE;
+
+	xf86CrtcSetSizeRange(pScrn, 320, 200, drmmode->mode_res->max_width, drmmode->mode_res->max_height);
+	for (i = 0; i < drmmode->mode_res->count_crtcs; i++)
+		if (!xf86IsEntityShared(pScrn->entityList[0]) || pScrn->confScreen->device->screen == i)
+			drmmode_crtc_init(pScrn, drmmode, i);
+
+	for (i = 0; i < drmmode->mode_res->count_connectors; i++)
+		drmmode_output_init(pScrn, drmmode, i, &num_dvi, &num_hdmi);
+
+	/* workout clones */
+	drmmode_clones_init(pScrn, drmmode);
+
+	xf86InitialConfiguration(pScrn, TRUE);
+
+	return TRUE;
+}
+
+void drmmode_set_cursor(ScrnInfoPtr scrn, drmmode_ptr drmmode, int id, struct dumb_bo *bo)
+{
+	xf86CrtcConfigPtr   xf86_config = XF86_CRTC_CONFIG_PTR(scrn);
+	xf86CrtcPtr crtc = xf86_config->crtc[id];
+	drmmode_crtc_private_ptr drmmode_crtc = crtc->driver_private;
+
+	drmmode_crtc->cursor_bo = bo;
+}
+
+void drmmode_adjust_frame(ScrnInfoPtr pScrn, drmmode_ptr drmmode, int x, int y, int flags)
+{
+	xf86CrtcConfigPtr	config = XF86_CRTC_CONFIG_PTR(pScrn);
+	xf86OutputPtr  output = config->output[config->compat_output];
+	xf86CrtcPtr	crtc = output->crtc;
+
+	if (crtc && crtc->enabled) {
+		drmmode_set_mode_major(crtc, &crtc->mode, crtc->rotation,
+				       x, y);
+	}
+}
+
+Bool drmmode_set_desired_modes(ScrnInfoPtr pScrn, drmmode_ptr drmmode)
+{
+	xf86CrtcConfigPtr   config = XF86_CRTC_CONFIG_PTR(pScrn);
+	int c;
+
+	for (c = 0; c < config->num_crtc; c++) {
+		xf86CrtcPtr	crtc = config->crtc[c];
+		drmmode_crtc_private_ptr drmmode_crtc = crtc->driver_private;
+		xf86OutputPtr	output = NULL;
+		int		o;
+
+		/* Skip disabled CRTCs */
+		if (!crtc->enabled) {
+			drmModeSetCrtc(drmmode->fd, drmmode_crtc->mode_crtc->crtc_id,
+				       0, 0, 0, NULL, 0, NULL);
+			continue;
+		}
+
+		if (config->output[config->compat_output]->crtc == crtc)
+			output = config->output[config->compat_output];
+		else
+		{
+			for (o = 0; o < config->num_output; o++)
+				if (config->output[o]->crtc == crtc)
+				{
+					output = config->output[o];
+					break;
+				}
+		}
+		/* paranoia */
+		if (!output)
+			continue;
+
+		/* Mark that we'll need to re-set the mode for sure */
+		memset(&crtc->mode, 0, sizeof(crtc->mode));
+		if (!crtc->desiredMode.CrtcHDisplay)
+		{
+			DisplayModePtr  mode = xf86OutputFindClosestMode (output, pScrn->currentMode);
+
+			if (!mode)
+				return FALSE;
+			crtc->desiredMode = *mode;
+			crtc->desiredRotation = RR_Rotate_0;
+			crtc->desiredX = 0;
+			crtc->desiredY = 0;
+		}
+
+		if (!crtc->funcs->set_mode_major(crtc, &crtc->desiredMode, crtc->desiredRotation,
+						 crtc->desiredX, crtc->desiredY))
+			return FALSE;
+	}
+	return TRUE;
+}
+
+static void drmmode_load_palette(ScrnInfoPtr pScrn, int numColors,
+                                 int *indices, LOCO *colors, VisualPtr pVisual)
+{
+    xf86CrtcConfigPtr   xf86_config = XF86_CRTC_CONFIG_PTR(pScrn);
+    uint16_t       lut_r[256], lut_g[256], lut_b[256];
+    int index, j, i;
+    int c;
+
+    for (c = 0; c < xf86_config->num_crtc; c++) {
+        xf86CrtcPtr crtc = xf86_config->crtc[c];
+	drmmode_crtc_private_ptr drmmode_crtc = crtc->driver_private;
+
+        for (i = 0 ; i < 256; i++) {
+            lut_r[i] = drmmode_crtc->lut_r[i] << 6;
+            lut_g[i] = drmmode_crtc->lut_g[i] << 6;
+            lut_b[i] = drmmode_crtc->lut_b[i] << 6;
+        }
+
+        switch(pScrn->depth) {
+        case 15:
+            for (i = 0; i < numColors; i++) {
+                index = indices[i];
+                for (j = 0; j < 8; j++) {
+                    lut_r[index * 8 + j] = colors[index].red << 6;
+                    lut_g[index * 8 + j] = colors[index].green << 6;
+                    lut_b[index * 8 + j] = colors[index].blue << 6;
+                }
+            }
+         break;
+         case 16:
+             for (i = 0; i < numColors; i++) {
+                 index = indices[i];
+
+                  if (i <= 31) {
+                      for (j = 0; j < 8; j++) {
+                          lut_r[index * 8 + j] = colors[index].red << 6;
+                          lut_b[index * 8 + j] = colors[index].blue << 6;
+                      }
+                  }
+
+                  for (j = 0; j < 4; j++) {
+                      lut_g[index * 4 + j] = colors[index].green << 6;
+                  }
+              }
+	  break;
+          default:
+              for (i = 0; i < numColors; i++) {
+                  index = indices[i];
+                  lut_r[index] = colors[index].red << 6;
+                  lut_g[index] = colors[index].green << 6;
+                  lut_b[index] = colors[index].blue << 6;
+              }
+              break;
+          }
+
+    /* Make the change through RandR */
+#ifdef RANDR_12_INTERFACE
+        if (crtc->randr_crtc)
+            RRCrtcGammaSet(crtc->randr_crtc, lut_r, lut_g, lut_b);
+        else
+#endif
+            crtc->funcs->gamma_set(crtc, lut_r, lut_g, lut_b, 256);
+     }
+}
+
+Bool drmmode_setup_colormap(ScreenPtr pScreen, ScrnInfoPtr pScrn)
+{
+    xf86DrvMsgVerb(pScrn->scrnIndex, X_INFO, 0,
+                  "Initializing kms color map\n");
+    if (!miCreateDefColormap(pScreen))
+        return FALSE;
+    /* all radeons support 10 bit CLUTs */
+    if (!xf86HandleColormaps(pScreen, 256, 10,
+                             drmmode_load_palette, NULL,
+                             CMAP_PALETTED_TRUECOLOR
+#if 0 /* This option messes up text mode! (eich at suse.de) */
+                             | CMAP_LOAD_EVEN_IF_OFFSCREEN
+#endif
+                             | CMAP_RELOAD_ON_MODE_SWITCH))
+         return FALSE;
+    return TRUE;
+}
+
+#ifdef HAVE_UDEV
+static void
+drmmode_handle_uevents(int fd, void *closure)
+{
+	drmmode_ptr drmmode = closure;
+	ScrnInfoPtr scrn = drmmode->scrn;
+	struct udev_device *dev;
+	dev = udev_monitor_receive_device(drmmode->uevent_monitor);
+	if (!dev)
+		return;
+
+	RRGetInfo(screenInfo.screens[scrn->scrnIndex], TRUE);
+	udev_device_unref(dev);
+}
+#endif
+
+void drmmode_uevent_init(ScrnInfoPtr scrn, drmmode_ptr drmmode)
+{
+#ifdef HAVE_UDEV
+	struct udev *u;
+	struct udev_monitor *mon;
+
+	u = udev_new();
+	if (!u)
+		return;
+	mon = udev_monitor_new_from_netlink(u, "udev");
+	if (!mon) {
+		udev_unref(u);
+		return;
+	}
+
+	if (udev_monitor_filter_add_match_subsystem_devtype(mon,
+							    "drm",
+							    "drm_minor") < 0 ||
+	    udev_monitor_enable_receiving(mon) < 0) {
+		udev_monitor_unref(mon);
+		udev_unref(u);
+		return;
+	}
+
+	drmmode->uevent_handler =
+		xf86AddGeneralHandler(udev_monitor_get_fd(mon),
+				      drmmode_handle_uevents,
+				      drmmode);
+
+	drmmode->uevent_monitor = mon;
+#endif
+}
+
+void drmmode_uevent_fini(ScrnInfoPtr scrn, drmmode_ptr drmmode)
+{
+#ifdef HAVE_UDEV
+	if (drmmode->uevent_handler) {
+		struct udev *u = udev_monitor_get_udev(drmmode->uevent_monitor);
+		xf86RemoveGeneralHandler(drmmode->uevent_handler);
+
+		udev_monitor_unref(drmmode->uevent_monitor);
+		udev_unref(u);
+	}
+#endif
+}
+
+/* create front and cursor BOs */
+Bool drmmode_create_initial_bos(ScrnInfoPtr pScrn, drmmode_ptr drmmode)
+{
+	xf86CrtcConfigPtr   xf86_config = XF86_CRTC_CONFIG_PTR(pScrn);
+	int width;
+	int height;
+	int bpp;
+	int i;
+
+	width = pScrn->virtualX;
+	height = pScrn->virtualY;
+	bpp = pScrn->bitsPerPixel;
+	drmmode->front_bo = dumb_bo_create(drmmode->fd, width, height, bpp);
+	if (!drmmode->front_bo)
+		return FALSE;
+
+
+	width = height = 64;
+	bpp = 32;
+	for (i = 0; i < xf86_config->num_crtc; i++) {
+		xf86CrtcPtr crtc = xf86_config->crtc[i];
+		drmmode_crtc_private_ptr drmmode_crtc = crtc->driver_private;
+		drmmode_crtc->cursor_bo = dumb_bo_create(drmmode->fd, width, height, bpp);
+	}
+	return TRUE;
+}
+
+void *drmmode_map_front_bo(drmmode_ptr drmmode)
+{
+	int ret;
+
+	if (drmmode->front_bo->ptr)
+		return drmmode->front_bo->ptr;
+
+	ret = dumb_bo_map(drmmode->fd, drmmode->front_bo);
+	if (ret)
+		return NULL;
+
+	return drmmode->front_bo->ptr;
+	
+}
+
+Bool drmmode_map_cursor_bos(ScrnInfoPtr pScrn, drmmode_ptr drmmode)
+{
+	xf86CrtcConfigPtr   xf86_config = XF86_CRTC_CONFIG_PTR(pScrn);
+	int i, ret;
+	for (i = 0; i < xf86_config->num_crtc; i++) {
+		xf86CrtcPtr crtc = xf86_config->crtc[i];
+		drmmode_crtc_private_ptr drmmode_crtc = crtc->driver_private;
+		ret = dumb_bo_map(drmmode->fd, drmmode_crtc->cursor_bo);
+		if (ret)
+			return FALSE;
+	}
+	return TRUE;
+}
+
+void drmmode_free_bos(ScrnInfoPtr pScrn, drmmode_ptr drmmode)
+{
+	xf86CrtcConfigPtr   xf86_config = XF86_CRTC_CONFIG_PTR(pScrn);
+	int i;
+	dumb_bo_destroy(drmmode->fd, drmmode->front_bo);
+	drmmode->front_bo = NULL;
+
+	for (i = 0; i < xf86_config->num_crtc; i++) {
+		xf86CrtcPtr crtc = xf86_config->crtc[i];
+		drmmode_crtc_private_ptr drmmode_crtc = crtc->driver_private;
+		dumb_bo_destroy(drmmode->fd, drmmode_crtc->cursor_bo);
+	}
+}
diff --git a/hw/xfree86/drivers/modesetting/drmmode_display.h b/hw/xfree86/drivers/modesetting/drmmode_display.h
new file mode 100644
index 0000000..2d72505
--- /dev/null
+++ b/hw/xfree86/drivers/modesetting/drmmode_display.h
@@ -0,0 +1,125 @@
+/*
+ * Copyright © 2007 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.
+ *
+ * Authors:
+ *     Dave Airlie <airlied at redhat.com>
+ *
+ */
+#ifndef DRMMODE_DISPLAY_H
+#define DRMMODE_DISPLAY_H
+
+#include "xf86drmMode.h"
+#ifdef HAVE_UDEV
+#include "libudev.h"
+#endif
+
+struct dumb_bo {
+  uint32_t handle;
+  uint32_t size;
+  void *ptr;
+  int map_count;
+  uint32_t pitch;
+};
+
+typedef struct {
+  int fd;
+  unsigned fb_id;
+  drmModeResPtr mode_res;
+  drmModeFBPtr mode_fb;
+  int cpp;
+  ScrnInfoPtr scrn;
+#ifdef HAVE_UDEV
+  struct udev_monitor *uevent_monitor;
+  InputHandlerProc uevent_handler;
+#endif
+  drmEventContext event_context;
+  struct dumb_bo *front_bo;
+} drmmode_rec, *drmmode_ptr;
+
+typedef struct {
+  drmmode_ptr drmmode;
+  unsigned old_fb_id;
+  int flip_count;
+  void *event_data;
+  unsigned int fe_frame;
+  unsigned int fe_tv_sec;
+  unsigned int fe_tv_usec;
+} drmmode_flipdata_rec, *drmmode_flipdata_ptr;
+
+typedef struct {
+  drmmode_flipdata_ptr flipdata;
+  Bool dispatch_me;
+} drmmode_flipevtcarrier_rec, *drmmode_flipevtcarrier_ptr;
+
+typedef struct {
+    drmmode_ptr drmmode;
+    drmModeCrtcPtr mode_crtc;
+    int hw_id;
+    struct dumb_bo *cursor_bo;
+  //    struct radeon_bo *rotate_bo;
+    unsigned rotate_fb_id;
+    uint16_t lut_r[256], lut_g[256], lut_b[256];
+} drmmode_crtc_private_rec, *drmmode_crtc_private_ptr;
+
+typedef struct {
+    drmModePropertyPtr mode_prop;
+    uint64_t value;
+    int num_atoms; /* if range prop, num_atoms == 1; if enum prop, num_atoms == num_enums + 1 */
+    Atom *atoms;
+} drmmode_prop_rec, *drmmode_prop_ptr;
+
+
+typedef struct {
+    drmmode_ptr drmmode;
+    int output_id;
+    drmModeConnectorPtr mode_output;
+    drmModeEncoderPtr *mode_encoders;
+    drmModePropertyBlobPtr edid_blob;
+    int dpms_enum_id;
+    int num_props;
+    drmmode_prop_ptr props;
+    int enc_mask;
+    int enc_clone_mask;
+} drmmode_output_private_rec, *drmmode_output_private_ptr;
+
+
+extern Bool drmmode_pre_init(ScrnInfoPtr pScrn, drmmode_ptr drmmode, int cpp);
+//extern Bool drmmode_set_bufmgr(ScrnInfoPtr pScrn, drmmode_ptr drmmode, struct radeon_bo_manager *bufmgr);
+//extern void drmmode_set_cursor(ScrnInfoPtr scrn, drmmode_ptr drmmode, int id, struct radeon_bo *bo);
+void drmmode_adjust_frame(ScrnInfoPtr pScrn, drmmode_ptr drmmode, int x, int y, int flags);
+extern Bool drmmode_set_desired_modes(ScrnInfoPtr pScrn, drmmode_ptr drmmode);
+extern void drmmode_copy_fb(ScrnInfoPtr pScrn, drmmode_ptr drmmode);
+extern Bool drmmode_setup_colormap(ScreenPtr pScreen, ScrnInfoPtr pScrn);
+
+extern void drmmode_uevent_init(ScrnInfoPtr scrn, drmmode_ptr drmmode);
+extern void drmmode_uevent_fini(ScrnInfoPtr scrn, drmmode_ptr drmmode);
+
+extern int drmmode_get_height_align(ScrnInfoPtr scrn, uint32_t tiling);
+extern int drmmode_get_pitch_align(ScrnInfoPtr scrn, int bpe, uint32_t tiling);
+extern int drmmode_get_base_align(ScrnInfoPtr scrn, int bpe, uint32_t tiling);
+
+//Bool radeon_do_pageflip(ScrnInfoPtr scrn, struct radeon_bo *new_front, void *data, int ref_crtc_hw_id);
+Bool drmmode_create_initial_bos(ScrnInfoPtr pScrn, drmmode_ptr drmmode);
+void *drmmode_map_front_bo(drmmode_ptr drmmode);
+Bool drmmode_map_cursor_bos(ScrnInfoPtr pScrn, drmmode_ptr drmmode);
+void drmmode_free_bos(ScrnInfoPtr pScrn, drmmode_ptr drmmode);
+#endif
diff --git a/hw/xfree86/drivers/modesetting/output.c b/hw/xfree86/drivers/modesetting/output.c
deleted file mode 100644
index 1f95a2f..0000000
--- a/hw/xfree86/drivers/modesetting/output.c
+++ /dev/null
@@ -1,292 +0,0 @@
-/*
- * Copyright 2008 Tungsten Graphics, 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 TUNGSTEN GRAPHICS 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.
- *
- *
- * Author: Alan Hourihane <alanh at tungstengraphics.com>
- *
- */
-
-#ifdef HAVE_CONFIG_H
-#include "config.h"
-#endif
-
-#include <xf86.h>
-#include <xf86i2c.h>
-#include <xf86Crtc.h>
-#include <errno.h>
-#include <fcntl.h>
-#include <unistd.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <stdint.h>
-#include <string.h>
-#include <sys/stat.h>
-#include <sys/types.h>
-
-#define DPMS_SERVER
-#include <X11/extensions/dpms.h>
-
-#include "X11/Xatom.h"
-
-#include "driver.h"
-
-static char *connector_enum_list[] = {
-    "Unknown",
-    "VGA",
-    "DVI-I",
-    "DVI-D",
-    "DVI-A",
-    "Composite",
-    "SVIDEO",
-    "LVDS",
-    "Component",
-    "9-pin DIN",
-    "DisplayPort",
-    "HDMI Type A",
-    "HDMI Type B",
-};
-
-static void
-dpms(xf86OutputPtr output, int mode)
-{
-}
-
-static void
-save(xf86OutputPtr output)
-{
-}
-
-static void
-restore(xf86OutputPtr output)
-{
-}
-
-static int
-mode_valid(xf86OutputPtr output, DisplayModePtr pMode)
-{
-    return MODE_OK;
-}
-
-static Bool
-mode_fixup(xf86OutputPtr output, DisplayModePtr mode,
-	   DisplayModePtr adjusted_mode)
-{
-    return TRUE;
-}
-
-static void
-prepare(xf86OutputPtr output)
-{
-    dpms(output, DPMSModeOff);
-}
-
-static void
-mode_set(xf86OutputPtr output, DisplayModePtr mode,
-	 DisplayModePtr adjusted_mode)
-{
-}
-
-static void
-commit(xf86OutputPtr output)
-{
-    dpms(output, DPMSModeOn);
-
-    if (output->scrn->pScreen != NULL)
-	xf86_reload_cursors(output->scrn->pScreen);
-}
-
-static xf86OutputStatus
-detect(xf86OutputPtr output)
-{
-    drmModeConnectorPtr drm_connector = output->driver_private;
-
-    switch (drm_connector->connection) {
-    case DRM_MODE_CONNECTED:
-	return XF86OutputStatusConnected;
-    case DRM_MODE_DISCONNECTED:
-	return XF86OutputStatusDisconnected;
-    default:
-	return XF86OutputStatusUnknown;
-    }
-}
-
-static DisplayModePtr
-get_modes(xf86OutputPtr output)
-{
-    drmModeConnectorPtr drm_connector = output->driver_private;
-    struct drm_mode_modeinfo *drm_mode = NULL;
-    DisplayModePtr modes = NULL, mode = NULL;
-    int i;
-
-    for (i = 0; i < drm_connector->count_modes; i++) {
-	drm_mode = &drm_connector->modes[i];
-	if (drm_mode) {
-	    mode = xcalloc(1, sizeof(DisplayModeRec));
-	    if (!mode)
-		continue;
-	    mode->type = 0;
-	    mode->Clock = drm_mode->clock;
-	    mode->HDisplay = drm_mode->hdisplay;
-	    mode->HSyncStart = drm_mode->hsync_start;
-	    mode->HSyncEnd = drm_mode->hsync_end;
-	    mode->HTotal = drm_mode->htotal;
-	    mode->VDisplay = drm_mode->vdisplay;
-	    mode->VSyncStart = drm_mode->vsync_start;
-	    mode->VSyncEnd = drm_mode->vsync_end;
-	    mode->VTotal = drm_mode->vtotal;
-	    mode->Flags = drm_mode->flags;
-	    mode->HSkew = drm_mode->hskew;
-	    mode->VScan = drm_mode->vscan;
-	    mode->VRefresh = xf86ModeVRefresh(mode);
-	    mode->Private = (void *)drm_mode;
-	    xf86SetModeDefaultName(mode);
-	    modes = xf86ModesAdd(modes, mode);
-	    xf86PrintModeline(0, mode);
-	}
-    }
-
-    return modes;
-}
-
-static void
-destroy(xf86OutputPtr output)
-{
-    drmModeFreeConnector(output->driver_private);
-}
-
-static void
-create_resources(xf86OutputPtr output)
-{
-#ifdef RANDR_12_INTERFACE
-#endif /* RANDR_12_INTERFACE */
-}
-
-#ifdef RANDR_12_INTERFACE
-static Bool
-set_property(xf86OutputPtr output, Atom property, RRPropertyValuePtr value)
-{
-    return TRUE;
-}
-#endif /* RANDR_12_INTERFACE */
-
-#ifdef RANDR_13_INTERFACE
-static Bool
-get_property(xf86OutputPtr output, Atom property)
-{
-    return TRUE;
-}
-#endif /* RANDR_13_INTERFACE */
-
-#ifdef RANDR_GET_CRTC_INTERFACE
-static xf86CrtcPtr
-get_crtc(xf86OutputPtr output)
-{
-    return NULL;
-}
-#endif
-
-static const xf86OutputFuncsRec output_funcs = {
-    .create_resources = create_resources,
-    .dpms = dpms,
-    .save = save,
-    .restore = restore,
-    .mode_valid = mode_valid,
-    .mode_fixup = mode_fixup,
-    .prepare = prepare,
-    .mode_set = mode_set,
-    .commit = commit,
-    .detect = detect,
-    .get_modes = get_modes,
-#ifdef RANDR_12_INTERFACE
-    .set_property = set_property,
-#endif
-#ifdef RANDR_13_INTERFACE
-    .get_property = get_property,
-#endif
-    .destroy = destroy,
-#ifdef RANDR_GET_CRTC_INTERFACE
-    .get_crtc = get_crtc,
-#endif
-};
-
-void
-output_init(ScrnInfoPtr pScrn)
-{
-    modesettingPtr ms = modesettingPTR(pScrn);
-    xf86OutputPtr output;
-    drmModeResPtr res;
-    drmModeConnectorPtr drm_connector = NULL;
-    drmModeEncoderPtr drm_encoder = NULL;
-    drmModeCrtcPtr crtc;
-    char *name;
-    int c, v, p;
-
-    res = drmModeGetResources(ms->fd);
-    if (res == 0) {
-	DRV_ERROR("Failed drmModeGetResources\n");
-	return;
-    }
-
-    for (c = 0; c < res->count_connectors; c++) {
-	drm_connector = drmModeGetConnector(ms->fd, res->connectors[c]);
-	if (!drm_connector)
-	    goto out;
-
-	for (p = 0; p < drm_connector->count_props; p++) {
-	    drmModePropertyPtr prop;
-
-	    prop = drmModeGetProperty(ms->fd, drm_connector->props[p]);
-
-	    name = NULL;
-	    if (prop) {
-		ErrorF("VALUES %d\n", prop->count_values);
-
-		for (v = 0; v < prop->count_values; v++)
-		    ErrorF("%s %lld\n", prop->name, prop->values[v]);
-	    }
-	}
-
-	name = connector_enum_list[drm_connector->connector_type];
-
-	output = xf86OutputCreate(pScrn, &output_funcs, name);
-	if (!output)
-	    continue;
-
-	drm_encoder = drmModeGetEncoder(ms->fd, drm_connector->encoders[0]);
-	if (drm_encoder) {
-	    output->possible_crtcs = drm_encoder->crtcs;
-	    output->possible_clones = drm_encoder->clones;
-	} else {
-	    output->possible_crtcs = 0;
-	    output->possible_clones = 0;
-	}
-	output->driver_private = drm_connector;
-	output->subpixel_order = SubPixelHorizontalRGB;
-	output->interlaceAllowed = FALSE;
-	output->doubleScanAllowed = FALSE;
-    }
-
-  out:
-    drmModeFreeResources(res);
-}
commit e2f8315daefc6e56ac8395a9f58f87bbf0809039
Author: Dave Airlie <airlied at redhat.com>
Date:   Thu Mar 10 09:13:50 2011 +1000

    drop exa
    
    don't provide accel in this framework

diff --git a/hw/xfree86/drivers/modesetting/Makefile.am b/hw/xfree86/drivers/modesetting/Makefile.am
index e3cc3cc..23e78b7 100644
--- a/hw/xfree86/drivers/modesetting/Makefile.am
+++ b/hw/xfree86/drivers/modesetting/Makefile.am
@@ -38,7 +38,6 @@ modesetting_drv_la_SOURCES = \
 	 driver.h \
 	 output.c \
 	 crtc.c \
-	 exa.c \
 	 dri2.c
 
 EXTRA_DIST =
diff --git a/hw/xfree86/drivers/modesetting/driver.c b/hw/xfree86/drivers/modesetting/driver.c
index 0e6f4c8..6b70d4b 100644
--- a/hw/xfree86/drivers/modesetting/driver.c
+++ b/hw/xfree86/drivers/modesetting/driver.c
@@ -126,16 +126,6 @@ static const OptionInfoRec Options[] = {
     {-1, NULL, OPTV_NONE, {0}, FALSE}
 };
 
-static const char *exaSymbols[] = {
-    "exaGetVersion",
-    "exaDriverInit",
-    "exaDriverFini",
-    "exaOffscreenAlloc",
-    "exaOffscreenFree",
-    "exaWaitSync",
-    NULL
-};
-
 static const char *fbSymbols[] = {
     "fbPictureInit",
     "fbScreenInit",
@@ -188,7 +178,7 @@ Setup(pointer module, pointer opts, int *errmaj, int *errmin)
 	 * Tell the loader about symbols from other modules that this module
 	 * might refer to.
 	 */
-	LoaderRefSymLists(exaSymbols, fbSymbols, ddcSymbols, NULL);
+	LoaderRefSymLists(fbSymbols, ddcSymbols, NULL);
 
 	/*
 	 * The return value must be non-NULL on success even though there
@@ -415,14 +405,11 @@ CreateFrontBuffer(ScrnInfoPtr pScrn)
     Bool fbAccessDisabled;
     int flags;
 
-    ms->noEvict = TRUE;
     pScreen->ModifyPixmapHeader(rootPixmap,
 				pScrn->virtualX, pScrn->virtualY,
 				pScrn->depth, pScrn->bitsPerPixel,
 				pScrn->displayWidth * pScrn->bitsPerPixel / 8,
 				NULL);
-    ms->noEvict = FALSE;
-
     drmModeAddFB(ms->fd,
 		 pScrn->virtualX,
 		 pScrn->virtualY,
@@ -633,8 +620,6 @@ PreInit(ScrnInfoPtr pScrn, int flags)
 
     xf86LoaderReqSymLists(fbSymbols, NULL);
 
-    xf86LoadSubModule(pScrn, "exa");
-
 #ifdef DRI2
     xf86LoadSubModule(pScrn, "dri2");
 #endif
@@ -667,8 +652,6 @@ CreateScreenResources(ScreenPtr pScreen)
     Bool ret;
     int flags;
 
-    ms->noEvict = TRUE;
-
     pScreen->CreateScreenResources = ms->createScreenResources;
     ret = pScreen->CreateScreenResources(pScreen);
     pScreen->CreateScreenResources = CreateScreenResources;
@@ -678,8 +661,6 @@ CreateScreenResources(ScreenPtr pScreen)
     if (!pScreen->ModifyPixmapHeader(rootPixmap, -1, -1, -1, -1, -1, NULL))
 	FatalError("Couldn't adjust screen pixmap\n");
 
-    ms->noEvict = FALSE;
-
     drmModeAddFB(ms->fd,
 		 pScrn->virtualX,
 		 pScrn->virtualY,
@@ -771,8 +752,6 @@ ScreenInit(int scrnIndex, ScreenPtr pScreen, int argc, char **argv)
 
     xf86SetBlackWhitePixels(pScreen);
 
-    ms->exa = ExaInit(pScrn);
-
     miInitializeBackingStore(pScreen);
     xf86SetBackingStore(pScreen);
     xf86SetSilkenMouse(pScreen);
@@ -933,9 +912,6 @@ CloseScreen(int scrnIndex, ScreenPtr pScreen)
 
     pScreen->CreateScreenResources = ms->createScreenResources;
 
-    if (ms->exa)
-	ExaClose(pScrn);
-
     drmClose(ms->fd);
     ms->fd = -1;
 
diff --git a/hw/xfree86/drivers/modesetting/driver.h b/hw/xfree86/drivers/modesetting/driver.h
index 5b31188..a673f8f 100644
--- a/hw/xfree86/drivers/modesetting/driver.h
+++ b/hw/xfree86/drivers/modesetting/driver.h
@@ -32,7 +32,6 @@
 #include <xf86drm.h>
 #include <xf86drmMode.h>
 #include <xf86mm.h>
-#include "exa.h"
 
 #define DRV_ERROR(msg)	xf86DrvMsg(pScrn->scrnIndex, X_ERROR, msg);
 
@@ -71,10 +70,7 @@ typedef struct _modesettingRec
 
     CreateScreenResourcesProcPtr createScreenResources;
 
-    /* exa */
-    void *exa;
     void *driver;
-    Bool noEvict;
 
     /* dri2 */
     drm_context_t context;
diff --git a/hw/xfree86/drivers/modesetting/exa.c b/hw/xfree86/drivers/modesetting/exa.c
deleted file mode 100644
index f688472..0000000
--- a/hw/xfree86/drivers/modesetting/exa.c
+++ /dev/null
@@ -1,850 +0,0 @@
-/*
- * Copyright 2008 Tungsten Graphics, 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 TUNGSTEN GRAPHICS 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.
- *
- *
- * Author: Alan Hourihane <alanh at tungstengraphics.com>
- *
- */
-
-#ifdef HAVE_CONFIG_H
-#include "config.h"
-#endif
-
-/* FIXME ! */
-#define DRI_DRIVER_PATH "/ISO/X.Org/modular/i386/lib/dri"
-
-#include "xf86.h"
-#include "xf86_OSproc.h"
-#include "driver.h"
-#include <dlfcn.h>
-
-#include "pipe/p_winsys.h"
-#include "pipe/p_format.h"
-#include "pipe/p_context.h"
-#include "pipe/p_util.h"
-#include "pipe/p_state.h"
-#include "pipe/p_inlines.h"
-
-/* EXA winsys */
-struct exa_context
-{
-};
-
-struct exa_winsys
-{
-    struct pipe_winsys base;
-    modesettingPtr ms;
-};
-
-struct exa_buffer
-{
-    struct pipe_buffer base;
-    drmBO bo;
-    boolean userBuffer;	/** Is this a user-space buffer? */
-    //void *data;
-    //void *mapped;
-};
-
-struct exa_surface
-{
-    struct pipe_surface surface;
-};
-
-struct exa_entity
-{
-    ExaDriverPtr pExa;
-    struct exa_context *c;
-    struct pipe_winsys *ws;
-    struct pipe_context *ctx;
-    struct pipe_screen *scrn;
-};
-
-static INLINE struct exa_winsys *
-exa_get_winsys(struct pipe_winsys *ws)
-{
-    return (struct exa_winsys *)ws;
-}
-
-static INLINE struct exa_surface *
-exa_get_surface(struct pipe_surface *ps)
-{
-    return (struct exa_surface *)ps;
-}
-
-static INLINE struct exa_buffer *
-exa_get_buffer(struct pipe_buffer *buf)
-{
-    return (struct exa_buffer *)buf;
-}
-
-static void *
-exa_buffer_map(struct pipe_winsys *pws, struct pipe_buffer *buf,
-	       unsigned flags)
-{
-    struct exa_buffer *exa_buf = exa_get_buffer(buf);
-    struct exa_winsys *exa_winsys = exa_get_winsys(pws);
-    void *virtual;
-
-    drmBOMap(exa_winsys->ms->fd,
-	     &exa_buf->bo, DRM_BO_FLAG_READ | DRM_BO_FLAG_WRITE, 0, &virtual);
-
-    return virtual;
-}
-
-static void
-exa_buffer_unmap(struct pipe_winsys *pws, struct pipe_buffer *buf)
-{
-    struct exa_buffer *exa_buf = exa_get_buffer(buf);
-    struct exa_winsys *exa_winsys = exa_get_winsys(pws);
-
-    drmBOUnmap(exa_winsys->ms->fd, &exa_buf->bo);
-}
-
-static void
-exa_buffer_destroy(struct pipe_winsys *pws, struct pipe_buffer *buf)
-{
-    struct exa_winsys *exa_winsys = exa_get_winsys(pws);
-    struct exa_buffer *exa_buf = exa_get_buffer(buf);
-
-    drmBOUnreference(exa_winsys->ms->fd, &exa_buf->bo);
-
-    free(exa_buf);
-}
-
-static void
-exa_flush_frontbuffer(struct pipe_winsys *pws,
-		      struct pipe_surface *surf, void *context_private)
-{
-    struct exa_buffer *exa_buf = exa_get_buffer(surf->buffer);
-
-    ErrorF("WANT TO FLUSH\n");
-}
-
-static const char *
-exa_get_name(struct pipe_winsys *pws)
-{
-    return "EXA";
-}
-
-static struct pipe_buffer *
-exa_buffer_create(struct pipe_winsys *pws,
-		  unsigned alignment, unsigned usage, unsigned size)
-{
-    struct exa_buffer *buffer = xcalloc(1, sizeof(struct exa_buffer));
-    struct exa_winsys *exa_winsys = exa_get_winsys(pws);
-    unsigned int flags = 0;
-
-    buffer->base.refcount = 1;
-    buffer->base.alignment = alignment;
-    buffer->base.usage = usage;
-    buffer->base.size = size;
-
-    if (exa_winsys->ms->noEvict) {
-	flags = DRM_BO_FLAG_NO_EVICT;
-	ErrorF("DISPLAY TARGET\n");
-    }
-
-    ErrorF("SIZE %d %d\n", size, alignment);
-    if (!buffer->bo.handle) {
-	// buffer->data = align_malloc(size, alignment);
-	drmBOCreate(exa_winsys->ms->fd, size, 0, NULL,
-		    DRM_BO_FLAG_READ | DRM_BO_FLAG_WRITE |
-		    DRM_BO_FLAG_SHAREABLE | DRM_BO_FLAG_MEM_TT |
-		    DRM_BO_FLAG_MAPPABLE | flags,
-		    0, &buffer->bo);
-    }
-
-    return &buffer->base;
-}
-
-static struct pipe_buffer *
-exa_user_buffer_create(struct pipe_winsys *pws, void *ptr, unsigned bytes)
-{
-    struct exa_buffer *buffer = xcalloc(1, sizeof(struct exa_buffer));
-
-    buffer->base.refcount = 1;
-    buffer->base.size = bytes;
-    buffer->userBuffer = TRUE;
-    //buffer->data = ptr;
-    ErrorF("USERBUFFER\n");
-
-    return &buffer->base;
-}
-
-/**
- * Round n up to next multiple.
- */
-static INLINE unsigned
-round_up(unsigned n, unsigned multiple)
-{
-    return (n + multiple - 1) & ~(multiple - 1);
-}
-
-static int
-exa_surface_alloc_storage(struct pipe_winsys *winsys,
-			  struct pipe_surface *surf,
-			  unsigned width, unsigned height,
-			  enum pipe_format format,
-			  unsigned flags, unsigned tex_usage)
-{
-    const unsigned alignment = 64;
-
-    surf->width = width;
-    surf->height = height;
-    surf->format = format;
-    pf_get_block(format, &surf->block);
-    surf->stride = round_up(surf->nblocksx * surf->block.size, alignment);
-
-    assert(!surf->buffer);
-    surf->buffer = winsys->buffer_create(winsys, alignment,
-					 PIPE_BUFFER_USAGE_PIXEL,
-					 surf->stride * height);
-    if (!surf->buffer)
-	return -1;
-
-    return 0;
-}
-
-/**
- * Called via winsys->surface_alloc() to create new surfaces.
- */
-static struct pipe_surface *
-exa_surface_alloc(struct pipe_winsys *ws)
-{
-    struct exa_surface *wms = xcalloc(1, sizeof(struct exa_surface));
-
-    assert(ws);
-
-    wms->surface.refcount = 1;
-    wms->surface.winsys = ws;
-
-    return &wms->surface;
-}
-
-static void
-exa_surface_release(struct pipe_winsys *winsys, struct pipe_surface **s)
-{
-    struct pipe_surface *surf = *s;
-
-    surf->refcount--;
-    if (surf->refcount == 0) {
-	if (surf->buffer)
-	    pipe_buffer_reference(winsys, &surf->buffer, NULL);
-	free(surf);
-    }
-    *s = NULL;
-}
-
-/*
- * Fence functions - basically nothing to do, as we don't create any actual
- * fence objects.
- */
-static void
-exa_fence_reference(struct pipe_winsys *sws, struct pipe_fence_handle **ptr,
-		    struct pipe_fence_handle *fence)
-{
-}
-
-static int
-exa_fence_signalled(struct pipe_winsys *sws, struct pipe_fence_handle *fence,
-		    unsigned flag)
-{
-    return 0;
-}
-
-static int
-exa_fence_finish(struct pipe_winsys *sws, struct pipe_fence_handle *fence,
-		 unsigned flag)
-{
-    return 0;
-}
-
-struct pipe_winsys *
-exa_get_pipe_winsys(modesettingPtr ms)
-{
-    static struct exa_winsys *ws = NULL;
-
-    if (!ws) {
-	ws = xcalloc(1, sizeof(struct exa_winsys));
-
-	/* Fill in this struct with callbacks that pipe will need to
-	 * communicate with the window system, buffer manager, etc. 
-	 */
-	ws->base.buffer_create = exa_buffer_create;
-	ws->base.user_buffer_create = exa_user_buffer_create;
-	ws->base.buffer_map = exa_buffer_map;
-	ws->base.buffer_unmap = exa_buffer_unmap;
-	ws->base.buffer_destroy = exa_buffer_destroy;
-
-	ws->base.surface_alloc = exa_surface_alloc;
-	ws->base.surface_alloc_storage = exa_surface_alloc_storage;
-	ws->base.surface_release = exa_surface_release;
-
-	ws->base.fence_reference = exa_fence_reference;
-	ws->base.fence_signalled = exa_fence_signalled;
-	ws->base.fence_finish = exa_fence_finish;
-
-	ws->base.flush_frontbuffer = exa_flush_frontbuffer;
-	ws->base.get_name = exa_get_name;
-
-	ws->ms = ms;
-    }
-
-    return &ws->base;
-}
-
-/* EXA functions */
-
-struct PixmapPriv
-{
-    drmBO bo;
-#if 0
-    dri_fence *fence;
-#endif
-    int flags;
-
-    struct pipe_texture *tex;
-    unsigned int color;
-    struct pipe_surface *src_surf;     /* for copies */
-};
-
-static enum pipe_format
-exa_get_pipe_format(int depth)
-{
-    switch (depth) {
-    case 32:
-    case 24:
-	return PIPE_FORMAT_A8R8G8B8_UNORM;
-    case 16:
-	return PIPE_FORMAT_R5G6B5_UNORM;
-    case 15:
-	return PIPE_FORMAT_A1R5G5B5_UNORM;
-    case 8:
-    case 4:
-    case 1:
-	return PIPE_FORMAT_A8R8G8B8_UNORM;	/* bad bad bad */
-    default:
-	assert(0);
-	return 0;
-    }
-}
-
-/*
- * EXA functions
- */
-
-static void
-ExaWaitMarker(ScreenPtr pScreen, int marker)
-{
-}
-
-static int
-ExaMarkSync(ScreenPtr pScreen)
-{
-    return 1;
-}
-
-Bool
-ExaPrepareAccess(PixmapPtr pPix, int index)
-{
-    ScreenPtr pScreen = pPix->drawable.pScreen;
-    ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
-    modesettingPtr ms = modesettingPTR(pScrn);
-    PixmapPtr rootPixmap = pScreen->GetScreenPixmap(pScreen);
-    struct exa_entity *exa = ms->exa;
-    struct PixmapPriv *priv;
-    int ret;
-
-    priv = exaGetPixmapDriverPrivate(pPix);
-
-    if (!priv)
-	return FALSE;
-
-    if (!priv->tex)
-	return FALSE;
-    {
-	struct pipe_surface *surf =
-	    exa->scrn->get_tex_surface(exa->scrn, priv->tex, 0, 0, 0,
-				       PIPE_BUFFER_USAGE_CPU_READ |
-				       PIPE_BUFFER_USAGE_CPU_WRITE);
-	pPix->devPrivate.ptr =
-	    exa->scrn->surface_map(exa->scrn, surf,
-				   PIPE_BUFFER_USAGE_CPU_READ |
-				   PIPE_BUFFER_USAGE_CPU_WRITE);
-	exa->scrn->tex_surface_release(exa->scrn, &surf);
-    }
-
-    return TRUE;
-}
-
-void
-ExaFinishAccess(PixmapPtr pPix, int index)
-{
-    ScreenPtr pScreen = pPix->drawable.pScreen;
-    ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
-    modesettingPtr ms = modesettingPTR(pScrn);
-    PixmapPtr rootPixmap = pScreen->GetScreenPixmap(pScreen);
-    struct PixmapPriv *priv;
-    struct exa_entity *exa = ms->exa;
-    int ret;
-
-    priv = exaGetPixmapDriverPrivate(pPix);
-
-    if (!priv)
-	return;
-
-    if (!priv->tex)
-	return;
-    {
-	struct pipe_surface *surf =
-	    exa->scrn->get_tex_surface(exa->scrn, priv->tex, 0, 0, 0,
-				       PIPE_BUFFER_USAGE_CPU_READ |
-				       PIPE_BUFFER_USAGE_CPU_WRITE);
-	exa->scrn->surface_unmap(exa->scrn, surf);
-	exa->scrn->tex_surface_release(exa->scrn, &surf);
-	pPix->devPrivate.ptr = NULL;
-    }
-}
-
-static void
-ExaDone(PixmapPtr pPixmap)
-{
-    ScrnInfoPtr pScrn = xf86Screens[pPixmap->drawable.pScreen->myNum];
-    modesettingPtr ms = modesettingPTR(pScrn);
-    struct PixmapPriv *priv = exaGetPixmapDriverPrivate(pPixmap);
-    struct exa_entity *exa = ms->exa;
-
-    if (!priv)
-	return;
-
-    if (priv->src_surf)
-	exa->scrn->tex_surface_release(exa->scrn, &priv->src_surf);
-    priv->src_surf = NULL;
-}
-
-static void
-ExaDoneComposite(PixmapPtr pPixmap)
-{
-    ScrnInfoPtr pScrn = xf86Screens[pPixmap->drawable.pScreen->myNum];
-}
-
-static Bool
-ExaPrepareSolid(PixmapPtr pPixmap, int alu, Pixel planeMask, Pixel fg)
-{
-    ScrnInfoPtr pScrn = xf86Screens[pPixmap->drawable.pScreen->myNum];
-    modesettingPtr ms = modesettingPTR(pScrn);
-    struct PixmapPriv *priv = exaGetPixmapDriverPrivate(pPixmap);
-    struct exa_entity *exa = ms->exa;
-
-    if (pPixmap->drawable.depth < 15)
-	return FALSE;
-
-    if (!EXA_PM_IS_SOLID(&pPixmap->drawable, planeMask))
-	return FALSE;
-
-    if (!priv || !priv->tex)
-	return FALSE;
-
-    if (alu != GXcopy)
-	return FALSE;
-
-    if (!exa->ctx || !exa->ctx->surface_fill)
-	return FALSE;
-
-    priv->color = fg;
-
-    return TRUE;
-}
-
-static void
-ExaSolid(PixmapPtr pPixmap, int x0, int y0, int x1, int y1)
-{
-    ScrnInfoPtr pScrn = xf86Screens[pPixmap->drawable.pScreen->myNum];
-    modesettingPtr ms = modesettingPTR(pScrn);
-    struct exa_entity *exa = ms->exa;
-    struct PixmapPriv *priv = exaGetPixmapDriverPrivate(pPixmap);
-    struct pipe_surface *surf =
-	exa->scrn->get_tex_surface(exa->scrn, priv->tex, 0, 0, 0,
-				   PIPE_BUFFER_USAGE_GPU_READ |
-				   PIPE_BUFFER_USAGE_GPU_WRITE);
-
-    exa->ctx->surface_fill(exa->ctx, surf, x0, y0, x1 - x0, y1 - y0,
-			   priv->color);
-
-    exa->scrn->tex_surface_release(exa->scrn, &surf);
-}
-
-static Bool
-ExaPrepareCopy(PixmapPtr pSrcPixmap, PixmapPtr pDstPixmap, int xdir,
-	       int ydir, int alu, Pixel planeMask)
-{
-    ScrnInfoPtr pScrn = xf86Screens[pDstPixmap->drawable.pScreen->myNum];
-    modesettingPtr ms = modesettingPTR(pScrn);
-    struct exa_entity *exa = ms->exa;
-    struct pipe_surface *src_surf;
-    struct PixmapPriv *priv = exaGetPixmapDriverPrivate(pDstPixmap);
-    struct PixmapPriv *src_priv = exaGetPixmapDriverPrivate(pSrcPixmap);
-
-    if (alu != GXcopy)
-	return FALSE;
-
-    if (pSrcPixmap->drawable.depth < 15 || pDstPixmap->drawable.depth < 15)
-	return FALSE;
-
-    if (!EXA_PM_IS_SOLID(&pSrcPixmap->drawable, planeMask))
-	return FALSE;
-
-    if (!priv || !src_priv)
-	return FALSE;
-
-    if (!priv->tex || !src_priv->tex)
-	return FALSE;
-
-    if (!exa->ctx || !exa->ctx->surface_copy)
-	return FALSE;
-
-    priv->src_surf =
-	exa->scrn->get_tex_surface(exa->scrn, src_priv->tex, 0, 0, 0,
-				   PIPE_BUFFER_USAGE_GPU_READ |
-				   PIPE_BUFFER_USAGE_GPU_WRITE);
-
-    return FALSE;
-}
-
-static void
-ExaCopy(PixmapPtr pDstPixmap, int srcX, int srcY, int dstX, int dstY,
-	int width, int height)
-{
-    ScrnInfoPtr pScrn = xf86Screens[pDstPixmap->drawable.pScreen->myNum];
-    modesettingPtr ms = modesettingPTR(pScrn);
-    struct exa_entity *exa = ms->exa;
-    struct PixmapPriv *priv = exaGetPixmapDriverPrivate(pDstPixmap);
-    struct pipe_surface *surf =
-	exa->scrn->get_tex_surface(exa->scrn, priv->tex, 0, 0, 0,
-				   PIPE_BUFFER_USAGE_GPU_READ |
-				   PIPE_BUFFER_USAGE_GPU_WRITE);
-
-    exa->ctx->surface_copy(exa->ctx, 0, surf, dstX, dstY, priv->src_surf,
-			   srcX, srcY, width, height);
-    exa->scrn->tex_surface_release(exa->scrn, &surf);
-}
-
-static Bool
-ExaPrepareComposite(int op, PicturePtr pSrcPicture,
-		    PicturePtr pMaskPicture, PicturePtr pDstPicture,
-		    PixmapPtr pSrc, PixmapPtr pMask, PixmapPtr pDst)
-{
-    ScreenPtr pScreen = pDst->drawable.pScreen;
-    ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
-
-    return FALSE;
-}
-
-static Bool
-ExaUploadToScreen(PixmapPtr pDst, int x, int y, int w, int h, char *src,
-		  int src_pitch)
-{
-    ScreenPtr pScreen = pDst->drawable.pScreen;
-    ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
-
-    ErrorF("UPLOAD\n");
-
-    return FALSE;
-}
-
-static void
-ExaComposite(PixmapPtr pDst, int srcX, int srcY, int maskX, int maskY,
-	     int dstX, int dstY, int width, int height)
-{
-    ScreenPtr pScreen = pDst->drawable.pScreen;
-    ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
-}
-
-static Bool
-ExaCheckComposite(int op,
-		  PicturePtr pSrcPicture, PicturePtr pMaskPicture,
-		  PicturePtr pDstPicture)
-{
-    DrawablePtr pDraw = pSrcPicture->pDrawable;
-    int w = pDraw->width;
-    int h = pDraw->height;
-
-    return FALSE;
-}
-
-static void *
-ExaCreatePixmap(ScreenPtr pScreen, int size, int align)
-{
-    ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
-    modesettingPtr ms = modesettingPTR(pScrn);
-    struct PixmapPriv *priv;
-    void *virtual;
-
-    priv = xcalloc(1, sizeof(struct PixmapPriv));
-    if (!priv)
-	return NULL;
-
-    return priv;
-}
-
-static void
-ExaDestroyPixmap(ScreenPtr pScreen, void *dPriv)
-{
-    struct PixmapPriv *priv = (struct PixmapPriv *)dPriv;
-    ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
-    modesettingPtr ms = modesettingPTR(pScrn);
-    struct exa_entity *exa = ms->exa;
-
-    if (!priv)
-	return;
-
-    if (priv->tex)
-	exa->scrn->texture_release(exa->scrn, &priv->tex);
-
-    xfree(priv);
-}
-
-static Bool
-ExaPixmapIsOffscreen(PixmapPtr pPixmap)
-{
-    struct PixmapPriv *priv;
-    ScreenPtr pScreen = pPixmap->drawable.pScreen;
-    PixmapPtr rootPixmap = pScreen->GetScreenPixmap(pScreen);
-
-    priv = exaGetPixmapDriverPrivate(pPixmap);
-
-    if (!priv)
-	return FALSE;
-
-    if (priv->tex)
-	return TRUE;
-
-    return FALSE;
-}
-
-/* FIXME !! */
-unsigned int
-driGetPixmapHandle(PixmapPtr pPixmap, unsigned int *flags)
-{
-    ScreenPtr pScreen = pPixmap->drawable.pScreen;
-    PixmapPtr rootPixmap = pScreen->GetScreenPixmap(pScreen);
-    ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
-    modesettingPtr ms = modesettingPTR(pScrn);
-    struct exa_entity *exa = ms->exa;
-    struct exa_buffer *exa_buf;
-    struct pipe_surface *surf;
-    struct PixmapPriv *priv;
-
-    *flags = 0;
-
-    if (!ms->exa) {
-	FatalError("NO MS->EXA\n");
-	return 0;
-    }
-
-    priv = exaGetPixmapDriverPrivate(pPixmap);
-
-    if (!priv) {
-	FatalError("NO PIXMAP PRIVATE\n");
-	return 0;
-    }
-
-    surf =
-	exa->scrn->get_tex_surface(exa->scrn, priv->tex, 0, 0, 0,
-				   PIPE_BUFFER_USAGE_CPU_READ |
-				   PIPE_BUFFER_USAGE_CPU_WRITE);
-    exa_buf = exa_get_buffer(surf->buffer);
-    exa->scrn->tex_surface_release(exa->scrn, &surf);
-
-    if (exa_buf->bo.handle)
-	return exa_buf->bo.handle;
-
-    return 0;
-}
-
-static Bool
-ExaModifyPixmapHeader(PixmapPtr pPixmap, int width, int height,
-		      int depth, int bitsPerPixel, int devKind,
-		      pointer pPixData)
-{
-    ScreenPtr pScreen = pPixmap->drawable.pScreen;
-    ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
-    struct PixmapPriv *priv = exaGetPixmapDriverPrivate(pPixmap);
-    modesettingPtr ms = modesettingPTR(pScrn);
-    PixmapPtr rootPixmap = pScreen->GetScreenPixmap(pScreen);
-    struct exa_entity *exa = ms->exa;
-
-    if (!priv)
-	return FALSE;
-
-    if (depth <= 0)
-	depth = pPixmap->drawable.depth;
-
-    if (bitsPerPixel <= 0)
-	bitsPerPixel = pPixmap->drawable.bitsPerPixel;
-
-    if (width <= 0)
-	width = pPixmap->drawable.width;
-
-    if (height <= 0)
-	height = pPixmap->drawable.height;
-
-    if (width <= 0 || height <= 0 || depth <= 0)
-	return FALSE;
-
-    miModifyPixmapHeader(pPixmap, width, height, depth,
-			     bitsPerPixel, devKind, NULL);
-
-    /* Deal with screen resize */
-    if (priv->tex) {
-	struct pipe_surface *surf =
-	    exa->scrn->get_tex_surface(exa->scrn, priv->tex, 0, 0, 0,
-				       PIPE_BUFFER_USAGE_CPU_READ |
-				       PIPE_BUFFER_USAGE_CPU_WRITE);
-
-	ErrorF("RESIZE %d %d to %d %d\n", surf->width, surf->height, width,
-	       height);
-	if (surf->width != width || surf->height != height) {
-	    exa->scrn->texture_release(exa->scrn, &priv->tex);
-	    priv->tex = NULL;
-	}
-	exa->scrn->tex_surface_release(exa->scrn, &surf);
-    }
-
-    if (!priv->tex) {
-	struct pipe_texture template;
-
-	memset(&template, 0, sizeof(template));
-	template.target = PIPE_TEXTURE_2D;
-	template.compressed = 0;
-	template.format = exa_get_pipe_format(depth);
-	pf_get_block(template.format, &template.block);
-	template.width[0] = width;
-	template.height[0] = height;
-	template.depth[0] = 1;
-	template.last_level = 0;
-	template.tex_usage = PIPE_TEXTURE_USAGE_RENDER_TARGET;
-	priv->tex = exa->scrn->texture_create(exa->scrn, &template);
-    }
-
-    return TRUE;
-}
-
-void
-ExaClose(ScrnInfoPtr pScrn)
-{
-    modesettingPtr ms = modesettingPTR(pScrn);
-    struct exa_entity *exa = ms->exa;
-
-    exaDriverFini(pScrn->pScreen);
-
-    dlclose(ms->driver);
-}
-
-void *
-ExaInit(ScrnInfoPtr pScrn)
-{
-    modesettingPtr ms = modesettingPTR(pScrn);
-    struct exa_entity *exa;
-    ExaDriverPtr pExa;
-
-    exa = xcalloc(1, sizeof(struct exa_entity));
-    if (!exa)
-	return NULL;
-
-    pExa = exaDriverAlloc();
-    if (!pExa) {
-	goto out_err;
-    }
-
-    memset(pExa, 0, sizeof(*pExa));
-    pExa->exa_major = 2;
-    pExa->exa_minor = 4;
-    pExa->memoryBase = 0;
-    pExa->memorySize = 0;
-    pExa->offScreenBase = 0;
-    pExa->pixmapOffsetAlign = 0;
-    pExa->pixmapPitchAlign = 1;
-    pExa->flags = EXA_OFFSCREEN_PIXMAPS | EXA_HANDLES_PIXMAPS;
-    pExa->maxX = 8191;		       /* FIXME */
-    pExa->maxY = 8191;		       /* FIXME */
-    pExa->WaitMarker = ExaWaitMarker;
-    pExa->MarkSync = ExaMarkSync;
-    pExa->PrepareSolid = ExaPrepareSolid;
-    pExa->Solid = ExaSolid;
-    pExa->DoneSolid = ExaDone;
-    pExa->PrepareCopy = ExaPrepareCopy;
-    pExa->Copy = ExaCopy;
-    pExa->DoneCopy = ExaDone;
-    pExa->CheckComposite = ExaCheckComposite;
-    pExa->PrepareComposite = ExaPrepareComposite;
-    pExa->Composite = ExaComposite;
-    pExa->DoneComposite = ExaDoneComposite;
-    pExa->PixmapIsOffscreen = ExaPixmapIsOffscreen;
-    pExa->PrepareAccess = ExaPrepareAccess;
-    pExa->FinishAccess = ExaFinishAccess;
-    pExa->UploadToScreen = ExaUploadToScreen;
-    pExa->CreatePixmap = ExaCreatePixmap;
-    pExa->DestroyPixmap = ExaDestroyPixmap;
-    pExa->ModifyPixmapHeader = ExaModifyPixmapHeader;
-
-    if (!exaDriverInit(pScrn->pScreen, pExa)) {
-	goto out_err;
-    }
-
-    {
-	char filename[128];
-	char dri_driver_path[] = DRI_DRIVER_PATH;
-
-	snprintf(filename, sizeof filename,
-		 "%s/%s_dri.so", dri_driver_path, "i915");
-
-	ms->driver = dlopen(filename, RTLD_NOW | RTLD_DEEPBIND | RTLD_GLOBAL);
-	if (!ms->driver)
-		FatalError("failed to initialize i915 - for softpipe only.\n");
-
-	exa->c = xcalloc(1, sizeof(struct exa_context));
-
-	exa->ws = exa_get_pipe_winsys(ms);
-	if (!exa->ws)
-		FatalError("BAD WINSYS\n");
-
-	exa->scrn = softpipe_create_screen(exa->ws);
-	if (!exa->scrn)
-		FatalError("BAD SCREEN\n");
-
-	exa->ctx = softpipe_create(exa->scrn, exa->ws, NULL);
-	if (!exa->ctx)
-	   	FatalError("BAD CTX\n");
-
-	exa->ctx->priv = exa->c;
-    }
-
-    return (void *)exa;
-
-  out_err:
-    ExaClose(pScrn);
-
-    return NULL;
-}
commit 1f0e69b3a13258b79bffdec76b46f7960eb334b3
Author: Matt Turner <mattst88 at gmail.com>
Date:   Mon Mar 8 10:54:21 2010 -0500

    Don't check for Xinerama.
    
    It doesn't seem to be used anywhere, so don't require it.
    
    CC: Jerome Glisse <jglisse at redhat.com>
    CC: Alex Deucher <alexdeucher at gmail.com>
    CC: Dave Airlie <airlied at redhat.com>
    Signed-off-by: Matt Turner <mattst88 at gmail.com>
commit 9c4c323d50bd8b369e82a1dff28abdc15a219a5e
Author: Thomas Hellstrom <thomas-at-tungstengraphics.com>
Date:   Mon Jun 30 18:59:13 2008 +0100

    Avoid an EXA init segfault.
    Don't allocate each VRAM buffer with a 16MB alignment.

diff --git a/hw/xfree86/drivers/modesetting/exa.c b/hw/xfree86/drivers/modesetting/exa.c
index 8368114..f688472 100644
--- a/hw/xfree86/drivers/modesetting/exa.c
+++ b/hw/xfree86/drivers/modesetting/exa.c
@@ -168,10 +168,10 @@ exa_buffer_create(struct pipe_winsys *pws,
     ErrorF("SIZE %d %d\n", size, alignment);
     if (!buffer->bo.handle) {
 	// buffer->data = align_malloc(size, alignment);
-	drmBOCreate(exa_winsys->ms->fd, size, 4096, NULL,
+	drmBOCreate(exa_winsys->ms->fd, size, 0, NULL,
 		    DRM_BO_FLAG_READ | DRM_BO_FLAG_WRITE |
 		    DRM_BO_FLAG_SHAREABLE | DRM_BO_FLAG_MEM_TT |
-		    DRM_BO_FLAG_MAPPABLE | DRM_BO_FLAG_CACHED_MAPPED | flags,
+		    DRM_BO_FLAG_MAPPABLE | flags,
 		    0, &buffer->bo);
     }
 
@@ -767,7 +767,7 @@ ExaInit(ScrnInfoPtr pScrn)
 {
     modesettingPtr ms = modesettingPTR(pScrn);
     struct exa_entity *exa;
-    ExaDriverPtr pExa = exa->pExa;
+    ExaDriverPtr pExa;
 
     exa = xcalloc(1, sizeof(struct exa_entity));
     if (!exa)
commit a65888d6785934a669ad3b822bf2d636db351858
Author: Alan Hourihane <alanh at tungstengraphics.com>
Date:   Fri Jun 27 17:32:28 2008 +0100

    fixes for gallium stride changes

diff --git a/hw/xfree86/drivers/modesetting/exa.c b/hw/xfree86/drivers/modesetting/exa.c
index 5cf1d96..8368114 100644
--- a/hw/xfree86/drivers/modesetting/exa.c
+++ b/hw/xfree86/drivers/modesetting/exa.c
@@ -213,13 +213,13 @@ exa_surface_alloc_storage(struct pipe_winsys *winsys,
     surf->width = width;
     surf->height = height;
     surf->format = format;
-    surf->cpp = pf_get_size(format);
-    surf->pitch = round_up(width, alignment / surf->cpp);
+    pf_get_block(format, &surf->block);
+    surf->stride = round_up(surf->nblocksx * surf->block.size, alignment);
 
     assert(!surf->buffer);
     surf->buffer = winsys->buffer_create(winsys, alignment,
 					 PIPE_BUFFER_USAGE_PIXEL,
-					 surf->pitch * surf->cpp * height);
+					 surf->stride * height);
     if (!surf->buffer)
 	return -1;
 
@@ -739,7 +739,7 @@ ExaModifyPixmapHeader(PixmapPtr pPixmap, int width, int height,
 	template.target = PIPE_TEXTURE_2D;
 	template.compressed = 0;
 	template.format = exa_get_pipe_format(depth);
-	template.cpp = pf_get_size(template.format);
+	pf_get_block(template.format, &template.block);
 	template.width[0] = width;
 	template.height[0] = height;
 	template.depth[0] = 1;
commit e0c43fff3208350995c45604624dd4825f40598c
Author: Alan Hourihane <alanh at tungstengraphics.com>
Date:   Fri Jun 27 09:46:24 2008 +0100

    More error checking

diff --git a/hw/xfree86/drivers/modesetting/exa.c b/hw/xfree86/drivers/modesetting/exa.c
index a804feb..5cf1d96 100644
--- a/hw/xfree86/drivers/modesetting/exa.c
+++ b/hw/xfree86/drivers/modesetting/exa.c
@@ -695,11 +695,6 @@ ExaModifyPixmapHeader(PixmapPtr pPixmap, int width, int height,
     PixmapPtr rootPixmap = pScreen->GetScreenPixmap(pScreen);
     struct exa_entity *exa = ms->exa;
 
-    if (rootPixmap == pPixmap) {
-	miModifyPixmapHeader(pPixmap, width, height, depth,
-			     bitsPerPixel, devKind, NULL);
-    }
-
     if (!priv)
 	return FALSE;
 
@@ -718,6 +713,9 @@ ExaModifyPixmapHeader(PixmapPtr pPixmap, int width, int height,
     if (width <= 0 || height <= 0 || depth <= 0)
 	return FALSE;
 
+    miModifyPixmapHeader(pPixmap, width, height, depth,
+			     bitsPerPixel, devKind, NULL);
+
     /* Deal with screen resize */
     if (priv->tex) {
 	struct pipe_surface *surf =
@@ -750,9 +748,6 @@ ExaModifyPixmapHeader(PixmapPtr pPixmap, int width, int height,
 	priv->tex = exa->scrn->texture_create(exa->scrn, &template);
     }
 
-    if (rootPixmap == pPixmap)
-	return TRUE;
-
     return TRUE;
 }
 
@@ -826,17 +821,22 @@ ExaInit(ScrnInfoPtr pScrn)
 		 "%s/%s_dri.so", dri_driver_path, "i915");
 
 	ms->driver = dlopen(filename, RTLD_NOW | RTLD_DEEPBIND | RTLD_GLOBAL);
+	if (!ms->driver)
+		FatalError("failed to initialize i915 - for softpipe only.\n");
 
 	exa->c = xcalloc(1, sizeof(struct exa_context));
 
 	exa->ws = exa_get_pipe_winsys(ms);
+	if (!exa->ws)
+		FatalError("BAD WINSYS\n");
 
 	exa->scrn = softpipe_create_screen(exa->ws);
+	if (!exa->scrn)
+		FatalError("BAD SCREEN\n");
 
 	exa->ctx = softpipe_create(exa->scrn, exa->ws, NULL);
-
 	if (!exa->ctx)
-	    ErrorF("BAD CTX\n");
+	   	FatalError("BAD CTX\n");
 
 	exa->ctx->priv = exa->c;
     }
commit 387ec961f2a5e791fd010906a5115cf8393471f3
Author: Alan Hourihane <alanh at tungstengraphics.com>
Date:   Thu Jun 26 23:34:51 2008 +0100

    add --with-gallium-dir to specify location of gallium tree

diff --git a/hw/xfree86/drivers/modesetting/Makefile.am b/hw/xfree86/drivers/modesetting/Makefile.am
index a182d44..e3cc3cc 100644
--- a/hw/xfree86/drivers/modesetting/Makefile.am
+++ b/hw/xfree86/drivers/modesetting/Makefile.am
@@ -26,7 +26,8 @@ SUBDIRS =
 # TODO: -nostdlib/-Bstatic/-lgcc platform magic, not installing the .a, etc.
 
 AM_CFLAGS = @WARN_CFLAGS@ @XORG_CFLAGS@ @DRI_CFLAGS@ @PCIACCESS_CFLAGS@ \
-	@XMODES_CFLAGS@
+	-I at GALLIUM_DIR@/src/gallium/include \
+	-I at GALLIUM_DIR@/src/gallium/auxiliary
 
 modesetting_drv_la_LTLIBRARIES = modesetting_drv.la
 modesetting_drv_la_LDFLAGS = -module -avoid-version -ldrm
commit 410b0a4254ca48548b443c1e8fbbcf7a6b9aa862
Author: Alan Hourihane <alanh at tungstengraphics.com>
Date:   Thu Jun 26 22:49:33 2008 +0100

    NULL checks

diff --git a/hw/xfree86/drivers/modesetting/exa.c b/hw/xfree86/drivers/modesetting/exa.c
index cab6870..a804feb 100644
--- a/hw/xfree86/drivers/modesetting/exa.c
+++ b/hw/xfree86/drivers/modesetting/exa.c
@@ -463,7 +463,7 @@ ExaPrepareSolid(PixmapPtr pPixmap, int alu, Pixel planeMask, Pixel fg)
     if (!EXA_PM_IS_SOLID(&pPixmap->drawable, planeMask))
 	return FALSE;
 
-    if (!priv->tex)
+    if (!priv || !priv->tex)
 	return FALSE;
 
     if (alu != GXcopy)
@@ -515,6 +515,9 @@ ExaPrepareCopy(PixmapPtr pSrcPixmap, PixmapPtr pDstPixmap, int xdir,
     if (!EXA_PM_IS_SOLID(&pSrcPixmap->drawable, planeMask))
 	return FALSE;
 
+    if (!priv || !src_priv)
+	return FALSE;
+
     if (!priv->tex || !src_priv->tex)
 	return FALSE;
 
commit 621fa337fb53d535f53cec30bb7161801001bb7f
Author: Alan Hourihane <alanh at tungstengraphics.com>
Date:   Thu Jun 26 22:47:20 2008 +0100

    Fix copy surface

diff --git a/hw/xfree86/drivers/modesetting/exa.c b/hw/xfree86/drivers/modesetting/exa.c
index 124dc03..cab6870 100644
--- a/hw/xfree86/drivers/modesetting/exa.c
+++ b/hw/xfree86/drivers/modesetting/exa.c
@@ -504,6 +504,7 @@ ExaPrepareCopy(PixmapPtr pSrcPixmap, PixmapPtr pDstPixmap, int xdir,
     struct exa_entity *exa = ms->exa;
     struct pipe_surface *src_surf;
     struct PixmapPriv *priv = exaGetPixmapDriverPrivate(pDstPixmap);
+    struct PixmapPriv *src_priv = exaGetPixmapDriverPrivate(pSrcPixmap);
 
     if (alu != GXcopy)
 	return FALSE;
@@ -514,14 +515,14 @@ ExaPrepareCopy(PixmapPtr pSrcPixmap, PixmapPtr pDstPixmap, int xdir,
     if (!EXA_PM_IS_SOLID(&pSrcPixmap->drawable, planeMask))
 	return FALSE;
 
-    if (!priv->tex)
+    if (!priv->tex || !src_priv->tex)
 	return FALSE;
 
     if (!exa->ctx || !exa->ctx->surface_copy)
 	return FALSE;
 
     priv->src_surf =
-	exa->scrn->get_tex_surface(exa->scrn, priv->tex, 0, 0, 0,
+	exa->scrn->get_tex_surface(exa->scrn, src_priv->tex, 0, 0, 0,
 				   PIPE_BUFFER_USAGE_GPU_READ |
 				   PIPE_BUFFER_USAGE_GPU_WRITE);
 
@@ -691,7 +692,7 @@ ExaModifyPixmapHeader(PixmapPtr pPixmap, int width, int height,
     PixmapPtr rootPixmap = pScreen->GetScreenPixmap(pScreen);
     struct exa_entity *exa = ms->exa;
 
-    /*if (rootPixmap == pPixmap) */  {
+    if (rootPixmap == pPixmap) {
 	miModifyPixmapHeader(pPixmap, width, height, depth,
 			     bitsPerPixel, devKind, NULL);
     }
commit ccd0c76472a7d8a85aed0ea6fea4011109f305d6
Author: Alan Hourihane <alanh at tungstengraphics.com>
Date:   Thu Jun 26 22:27:44 2008 +0100

    Add EXA winsys for gallium pipe driver interface.
    
    Plug in the EXA framework into the pipe driver
    for surface_copy & surface_fill.
    
    Back pixmaps with drmBO's including the front buffer.

diff --git a/hw/xfree86/drivers/modesetting/driver.c b/hw/xfree86/drivers/modesetting/driver.c
index 6bf6388..0e6f4c8 100644
--- a/hw/xfree86/drivers/modesetting/driver.c
+++ b/hw/xfree86/drivers/modesetting/driver.c
@@ -40,7 +40,6 @@
 #include "xf86Resources.h"
 #include "mipointer.h"
 #include "micmap.h"
-#include "shadowfb.h"
 #include <X11/extensions/randr.h>
 #include "fb.h"
 #include "edid.h"
@@ -50,7 +49,6 @@
 #include "dixstruct.h"
 #include "xf86xv.h"
 #include <X11/extensions/Xv.h>
-#include "shadow.h"
 #include <xorg-server.h>
 #if XSERVER_LIBPCIACCESS
 #include <pciaccess.h>
@@ -120,15 +118,11 @@ static PciChipsets PciDevices[] = {
 
 typedef enum
 {
-    OPTION_NOACCEL,
     OPTION_SW_CURSOR,
-    OPTION_SHADOWFB,
 } modesettingOpts;
 
 static const OptionInfoRec Options[] = {
-    {OPTION_NOACCEL, "NoAccel", OPTV_BOOLEAN, {0}, FALSE},
     {OPTION_SW_CURSOR, "SWcursor", OPTV_BOOLEAN, {0}, FALSE},
-    {OPTION_SHADOWFB, "ShadowFB", OPTV_BOOLEAN, {0}, FALSE},
     {-1, NULL, OPTV_NONE, {0}, FALSE}
 };
 
@@ -154,12 +148,6 @@ static const char *ddcSymbols[] = {
     NULL
 };
 
-static const char *shadowSymbols[] = {
-    "shadowInit",
-    "shadowUpdatePackedWeak",
-    NULL
-};
-
 static const char *i2cSymbols[] = {
     "xf86CreateI2CBusRec",
     "xf86I2CBusInit",
@@ -200,7 +188,7 @@ Setup(pointer module, pointer opts, int *errmaj, int *errmin)
 	 * Tell the loader about symbols from other modules that this module
 	 * might refer to.
 	 */
-	LoaderRefSymLists(exaSymbols, fbSymbols, shadowSymbols, ddcSymbols, NULL);
+	LoaderRefSymLists(exaSymbols, fbSymbols, ddcSymbols, NULL);
 
 	/*
 	 * The return value must be non-NULL on success even though there
@@ -323,7 +311,6 @@ Probe(DriverPtr drv, int flags)
 	if (numUsed > 0)
 	    foundScreen = TRUE;
     } else {
-	ErrorF("NUMUSED %d\n", numUsed);
 	for (i = 0; i < numUsed; i++) {
 	    ScrnInfoPtr pScrn = NULL;
 
@@ -420,54 +407,21 @@ ProbeDDC(ScrnInfoPtr pScrn, int index)
 }
 
 static Bool
-MapMem(ScrnInfoPtr pScrn)
-{
-    modesettingPtr ms = modesettingPTR(pScrn);
-
-    drmBOMap(ms->fd,
-	     &ms->bo, DRM_BO_FLAG_READ | DRM_BO_FLAG_WRITE, 0, &ms->virtual);
-
-    ms->virtual = ms->bo.virtual;
-
-    return TRUE;
-}
-
-static Bool
-UnmapMem(ScrnInfoPtr pScrn)
-{
-    modesettingPtr ms = modesettingPTR(pScrn);
-
-    drmBOUnmap(ms->fd, &ms->bo);
-
-    return TRUE;
-}
-
-static void
-LoadPalette(ScrnInfoPtr pScrn, int numColors, int *indices,
-	    LOCO * colors, VisualPtr pVisual)
-{
-    xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(pScrn);
-}
-
-static Bool
 CreateFrontBuffer(ScrnInfoPtr pScrn)
 {
     modesettingPtr ms = modesettingPTR(pScrn);
     ScreenPtr pScreen = pScrn->pScreen;
     PixmapPtr rootPixmap = pScreen->GetScreenPixmap(pScreen);
     Bool fbAccessDisabled;
-    CARD8 *fbstart;
+    int flags;
 
-    drmBOCreate(ms->fd,
-		pScrn->virtualY * pScrn->displayWidth *
-		pScrn->bitsPerPixel / 8, 0, NULL,
-		DRM_BO_FLAG_READ | DRM_BO_FLAG_WRITE | DRM_BO_FLAG_SHAREABLE
-		| DRM_BO_FLAG_CACHED_MAPPED
-		| DRM_BO_FLAG_NO_EVICT | DRM_BO_FLAG_MAPPABLE |
-		/*DRM_BO_FLAG_MEM_VRAM |*/ DRM_BO_FLAG_MEM_TT,
-		0, &ms->bo);
-
-    MapMem(pScrn);
+    ms->noEvict = TRUE;
+    pScreen->ModifyPixmapHeader(rootPixmap,
+				pScrn->virtualX, pScrn->virtualY,
+				pScrn->depth, pScrn->bitsPerPixel,
+				pScrn->displayWidth * pScrn->bitsPerPixel / 8,
+				NULL);
+    ms->noEvict = FALSE;
 
     drmModeAddFB(ms->fd,
 		 pScrn->virtualX,
@@ -475,50 +429,12 @@ CreateFrontBuffer(ScrnInfoPtr pScrn)
 		 pScrn->depth,
 		 pScrn->bitsPerPixel,
 		 pScrn->displayWidth * pScrn->bitsPerPixel / 8,
-		 ms->bo.handle, &ms->fb_id);
-
-    if (ms->shadowFB) {
-	if ((ms->shadowMem =
-	     shadowAlloc(pScrn->displayWidth, pScrn->virtualY,
-			 pScrn->bitsPerPixel)) == NULL) {
-	    xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
-		       "Allocation of shadow memory failed\n");
-	    return FALSE;
-	}
-	fbstart = ms->shadowMem;
-    } else {
-	fbstart = ms->bo.virtual;
-    }
-
-    /*
-     * If we are in a fb disabled state, the virtual address of the root
-     * pixmap should always be NULL, and it will be overwritten later
-     * if we try to set it to something.
-     *
-     * Therefore, set it to NULL, and modify the backup copy instead.
-     */
-
-    fbAccessDisabled = (rootPixmap->devPrivate.ptr == NULL);
-
-    pScreen->ModifyPixmapHeader(rootPixmap,
-				pScrn->virtualX, pScrn->virtualY,
-				pScrn->depth, pScrn->bitsPerPixel,
-				pScrn->displayWidth * pScrn->bitsPerPixel / 8,
-				fbstart);
-
-    if (fbAccessDisabled) {
-	pScrn->pixmapPrivate.ptr = fbstart;
-	rootPixmap->devPrivate.ptr = NULL;
-    }
+		 driGetPixmapHandle(rootPixmap, &flags), &ms->fb_id);
 
     pScrn->frameX0 = 0;
     pScrn->frameY0 = 0;
     AdjustFrame(pScrn->scrnIndex, pScrn->frameX0, pScrn->frameY0, 0);
 
-    UnmapMem(pScrn);
-
-    ms->front = TRUE;
-
     return TRUE;
 }
 
@@ -538,22 +454,12 @@ crtc_resize(ScrnInfoPtr pScrn, int width, int height)
 
     pScrn->virtualX = width;
     pScrn->virtualY = height;
-    pScrn->displayWidth = (pScrn->virtualX + 63) & ~63;
 
-    if (ms->shadowMem) {
-	xfree(ms->shadowMem);
-	ms->shadowMem = NULL;
-    }
+    /* HW dependent - FIXME */
+    pScrn->displayWidth = pScrn->virtualX;
 
     drmModeRmFB(ms->fd, ms->fb_id);
 
-    /* move old buffer out of the way */
-    drmBOSetStatus(ms->fd, &ms->bo, 0, 0, 0, 0, 0);
-
-    /* unreference it */
-    drmBOUnreference(ms->fd, &ms->bo);
-    ms->front = FALSE;
-
     /* now create new frontbuffer */
     return CreateFrontBuffer(pScrn);
 }
@@ -571,7 +477,6 @@ PreInit(ScrnInfoPtr pScrn, int flags)
     rgb defaultWeight = { 0, 0, 0 };
     EntityInfoPtr pEnt;
     EntPtr msEnt = NULL;
-    int flags24;
     char *BusID;
     int i;
     char *s;
@@ -645,13 +550,12 @@ PreInit(ScrnInfoPtr pScrn, int flags)
     pScrn->progClock = TRUE;
     pScrn->rgbBits = 8;
 
-    flags24 = Support32bppFb | PreferConvert24to32 | SupportConvert24to32;
-
-    if (!xf86SetDepthBpp(pScrn, 0, 0, 0, flags24))
+    if (!xf86SetDepthBpp
+	(pScrn, 0, 0, 0,
+	 PreferConvert24to32 | SupportConvert24to32 | Support32bppFb))
 	return FALSE;
 
     switch (pScrn->depth) {
-    case 8:
     case 15:
     case 16:
     case 24:
@@ -684,23 +588,10 @@ PreInit(ScrnInfoPtr pScrn, int flags)
     max_height = 8192;
     xf86CrtcSetSizeRange(pScrn, 320, 200, max_width, max_height);
 
-    if (xf86ReturnOptValBool(ms->Options, OPTION_NOACCEL, FALSE)) {
-	ms->noAccel = TRUE;
-    }
-
     if (xf86ReturnOptValBool(ms->Options, OPTION_SW_CURSOR, FALSE)) {
 	ms->SWCursor = TRUE;
     }
 
-    if (xf86ReturnOptValBool(ms->Options, OPTION_SHADOWFB, FALSE)) {
-	if (!xf86LoadSubModule(pScrn, "shadow"))
-	    return FALSE;
-
-	xf86LoaderReqSymLists(shadowSymbols, NULL);
-
-	ms->shadowFB = TRUE;
-    }
-
     SaveHWState(pScrn);
 
     crtc_init(pScrn);
@@ -767,42 +658,37 @@ RestoreHWState(ScrnInfoPtr pScrn)
     return TRUE;
 }
 
-static void *
-WindowLinear(ScreenPtr pScreen, CARD32 row, CARD32 offset, int mode,
-	     CARD32 * size, void *closure)
-{
-    ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
-    modesettingPtr ms = modesettingPTR(pScrn);
-
-    if (!pScrn->vtSema)
-	return NULL;
-
-    *size = pScrn->displayWidth * pScrn->bitsPerPixel / 8;
-
-    return ((CARD8 *) ms->bo.virtual + row * (*size) + offset);
-}
-
 static Bool
 CreateScreenResources(ScreenPtr pScreen)
 {
     ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
     modesettingPtr ms = modesettingPTR(pScrn);
-    PixmapPtr rootPixmap = pScreen->GetScreenPixmap(pScreen);
+    PixmapPtr rootPixmap;
     Bool ret;
+    int flags;
+
+    ms->noEvict = TRUE;
 
     pScreen->CreateScreenResources = ms->createScreenResources;
     ret = pScreen->CreateScreenResources(pScreen);
     pScreen->CreateScreenResources = CreateScreenResources;
 
-    if (ms->shadowFB)
-    	shadowAdd(pScreen, rootPixmap,
-	      ms->update, WindowLinear, 0, 0);
+    rootPixmap = pScreen->GetScreenPixmap(pScreen);
 
-    if (!pScreen->ModifyPixmapHeader(pScreen->GetScreenPixmap(pScreen),
-                                     -1, -1, -1, -1, -1,
-                                     ms->shadowFB ? (pointer)ms->shadowMem : (pointer)ms->bo.virtual))
+    if (!pScreen->ModifyPixmapHeader(rootPixmap, -1, -1, -1, -1, -1, NULL))
 	FatalError("Couldn't adjust screen pixmap\n");
 
+    ms->noEvict = FALSE;
+
+    drmModeAddFB(ms->fd,
+		 pScrn->virtualX,
+		 pScrn->virtualY,
+		 pScrn->depth,
+		 pScrn->bitsPerPixel,
+		 pScrn->displayWidth * pScrn->bitsPerPixel / 8,
+		 driGetPixmapHandle(rootPixmap, &flags), &ms->fb_id);
+
+    AdjustFrame(pScrn->scrnIndex, pScrn->frameX0, pScrn->frameY0, 0);
 
     return ret;
 }
@@ -816,33 +702,33 @@ ScreenInit(int scrnIndex, ScreenPtr pScreen, int argc, char **argv)
     unsigned long sys_mem;
     int c;
     MessageType from;
-    CARD8 *fbstart;
 
     /* deal with server regeneration */
     if (ms->fd < 0) {
-    	char *BusID;
+	char *BusID;
 
-    	BusID = xalloc(64);
-    	sprintf(BusID, "PCI:%d:%d:%d",
+	BusID = xalloc(64);
+	sprintf(BusID, "PCI:%d:%d:%d",
 #if XSERVER_LIBPCIACCESS
-	    ((ms->PciInfo->domain << 8) | ms->PciInfo->bus),
-	    ms->PciInfo->dev, ms->PciInfo->func
+		((ms->PciInfo->domain << 8) | ms->PciInfo->bus),
+		ms->PciInfo->dev, ms->PciInfo->func
 #else
-	    ((pciConfigPtr) ms->PciInfo->thisCard)->busnum,
-	    ((pciConfigPtr) ms->PciInfo->thisCard)->devnum,
-	    ((pciConfigPtr) ms->PciInfo->thisCard)->funcnum
+		((pciConfigPtr) ms->PciInfo->thisCard)->busnum,
+		((pciConfigPtr) ms->PciInfo->thisCard)->devnum,
+		((pciConfigPtr) ms->PciInfo->thisCard)->funcnum
 #endif
-	);
+	    );
 
-    	ms->fd = drmOpen(NULL, BusID);
+	ms->fd = drmOpen(NULL, BusID);
 
-    	if (ms->fd < 0)
+	if (ms->fd < 0)
 	    return FALSE;
     }
 
     pScrn->pScreen = pScreen;
 
-    pScrn->displayWidth = (pScrn->virtualX + 63) & ~63;
+    /* HW dependent - FIXME */
+    pScrn->displayWidth = pScrn->virtualX;
 
     miClearVisualTypes();
 
@@ -857,39 +743,7 @@ ScreenInit(int scrnIndex, ScreenPtr pScreen, int argc, char **argv)
     pScrn->memPhysBase = 0;
     pScrn->fbOffset = 0;
 
-    drmBOCreate(ms->fd,
-		pScrn->virtualY * pScrn->displayWidth *
-		pScrn->bitsPerPixel / 8, 0, NULL,
-		DRM_BO_FLAG_READ | DRM_BO_FLAG_WRITE | DRM_BO_FLAG_SHAREABLE
-		| DRM_BO_FLAG_CACHED_MAPPED
-		| DRM_BO_FLAG_NO_EVICT | DRM_BO_FLAG_MAPPABLE |
-		/*DRM_BO_FLAG_MEM_VRAM |*/ DRM_BO_FLAG_MEM_TT,
-		0, &ms->bo);
-
-    MapMem(pScrn);
-
-    drmModeAddFB(ms->fd,
-		 pScrn->virtualX,
-		 pScrn->virtualY,
-		 pScrn->depth,
-		 pScrn->bitsPerPixel,
-		 pScrn->displayWidth * pScrn->bitsPerPixel / 8,
-		 ms->bo.handle, &ms->fb_id);
-
-    if (ms->shadowFB) {
-	if ((ms->shadowMem =
-	     shadowAlloc(pScrn->displayWidth, pScrn->virtualY,
-			 pScrn->bitsPerPixel)) == NULL) {
-	    xf86DrvMsg(scrnIndex, X_ERROR,
-		       "Allocation of shadow memory failed\n");
-	    return FALSE;
-	}
-	fbstart = ms->shadowMem;
-    } else {
-	fbstart = ms->bo.virtual;
-    }
-
-    if (!fbScreenInit(pScreen, fbstart,
+    if (!fbScreenInit(pScreen, NULL,
 		      pScrn->virtualX, pScrn->virtualY,
 		      pScrn->xDpi, pScrn->yDpi,
 		      pScrn->displayWidth, pScrn->bitsPerPixel))
@@ -911,26 +765,13 @@ ScreenInit(int scrnIndex, ScreenPtr pScreen, int argc, char **argv)
     }
 
     fbPictureInit(pScreen, NULL, 0);
-    if (ms->shadowFB) {
-	ms->update = shadowUpdatePackedWeak();
-	if (!shadowSetup(pScreen)) {
-	    xf86DrvMsg(scrnIndex, X_ERROR,
-		       "Shadow framebuffer initialization failed.\n");
-	    return FALSE;
-	}
-    }
 
     ms->createScreenResources = pScreen->CreateScreenResources;
     pScreen->CreateScreenResources = CreateScreenResources;
 
     xf86SetBlackWhitePixels(pScreen);
 
-#if 0
-    glucoseScreenInit(pScreen, 0);
-#endif
-#if 1
-    ms->pExa = ExaInit(pScrn);
-#endif
+    ms->exa = ExaInit(pScrn);
 
     miInitializeBackingStore(pScreen);
     xf86SetBackingStore(pScreen);
@@ -939,9 +780,9 @@ ScreenInit(int scrnIndex, ScreenPtr pScreen, int argc, char **argv)
 
     /* Need to extend HWcursor support to handle mask interleave */
     if (!ms->SWCursor)
-	xf86_cursors_init (pScreen, 64, 64,
-			       HARDWARE_CURSOR_SOURCE_MASK_INTERLEAVE_64 |
-			       HARDWARE_CURSOR_ARGB);
+	xf86_cursors_init(pScreen, 64, 64,
+			  HARDWARE_CURSOR_SOURCE_MASK_INTERLEAVE_64 |
+			  HARDWARE_CURSOR_ARGB);
 
     /* Must force it before EnterVT, so we are in control of VT and
      * later memory should be bound when allocating, e.g rotate_mem */
@@ -957,20 +798,8 @@ ScreenInit(int scrnIndex, ScreenPtr pScreen, int argc, char **argv)
     if (!miCreateDefColormap(pScreen))
 	return FALSE;
 
-#if 0
-    if (!xf86HandleColormaps(pScreen, 256, 8, LoadPalette, NULL,
-			     CMAP_RELOAD_ON_MODE_SWITCH |
-			     CMAP_PALETTED_TRUECOLOR)) {
-	return FALSE;
-    }
-#endif
-
     xf86DPMSInit(pScreen, xf86DPMSSet, 0);
 
-#if 0
-    glucoseInitVideo(pScreen);
-#endif
-
     if (serverGeneration == 1)
 	xf86ShowUnusedOptions(pScrn->scrnIndex, pScrn->options);
 
@@ -978,11 +807,7 @@ ScreenInit(int scrnIndex, ScreenPtr pScreen, int argc, char **argv)
     driScreenInit(pScreen);
 #endif
 
-    UnmapMem(pScrn);
-
-    ms->front = TRUE;
-
-    return EnterVT(scrnIndex, 0);
+    return EnterVT(scrnIndex, 1);
 }
 
 static void
@@ -1018,7 +843,7 @@ LeaveVT(int scrnIndex, int flags)
     for (o = 0; o < config->num_crtc; o++) {
 	xf86CrtcPtr crtc = config->crtc[o];
 
-    	cursor_destroy(crtc);
+	cursor_destroy(crtc);
 
 	if (crtc->rotatedPixmap || crtc->rotatedData) {
 	    crtc->funcs->shadow_destroy(crtc, crtc->rotatedPixmap,
@@ -1030,12 +855,6 @@ LeaveVT(int scrnIndex, int flags)
 
     drmModeRmFB(ms->fd, ms->fb_id);
 
-    /* move old buffer out of the way */
-    drmBOSetStatus(ms->fd, &ms->bo, 0, 0, 0, 0, 0);
-
-    drmBOUnreference(ms->fd, &ms->bo);
-    ms->front = FALSE;
-
     RestoreHWState(pScrn);
 
 #if 0
@@ -1078,14 +897,12 @@ EnterVT(int scrnIndex, int flags)
 	SaveHWState(pScrn);
     }
 
-    if (!ms->front)
+    if (!flags)			       /* signals startup as we'll do this in CreateScreenResources */
 	CreateFrontBuffer(pScrn);
 
     if (!xf86SetDesiredModes(pScrn))
 	return FALSE;
 
-    AdjustFrame(pScrn->scrnIndex, pScrn->frameX0, pScrn->frameY0, 0);
-
     return TRUE;
 }
 
@@ -1104,25 +921,19 @@ CloseScreen(int scrnIndex, ScreenPtr pScreen)
     modesettingPtr ms = modesettingPTR(pScrn);
 
     if (pScrn->vtSema) {
-    	LeaveVT(scrnIndex, 0);
+	LeaveVT(scrnIndex, 0);
 #if 0
-    	drmMMUnlock(ms->fd, DRM_BO_MEM_VRAM, 1);
-    	drmMMUnlock(ms->fd, DRM_BO_MEM_TT, 1);
+	drmMMUnlock(ms->fd, DRM_BO_MEM_VRAM, 1);
+	drmMMUnlock(ms->fd, DRM_BO_MEM_TT, 1);
 #endif
     }
-
 #ifdef DRI2
     driCloseScreen(pScreen);
 #endif
 
     pScreen->CreateScreenResources = ms->createScreenResources;
 
-    if (ms->shadowMem) {
-	xfree(ms->shadowMem);
-	ms->shadowMem = NULL;
-    }
-
-    if (ms->pExa)
+    if (ms->exa)
 	ExaClose(pScrn);
 
     drmClose(ms->fd);
diff --git a/hw/xfree86/drivers/modesetting/driver.h b/hw/xfree86/drivers/modesetting/driver.h
index 7ac6466..5b31188 100644
--- a/hw/xfree86/drivers/modesetting/driver.h
+++ b/hw/xfree86/drivers/modesetting/driver.h
@@ -32,7 +32,6 @@
 #include <xf86drm.h>
 #include <xf86drmMode.h>
 #include <xf86mm.h>
-#include "shadow.h"
 #include "exa.h"
 
 #define DRV_ERROR(msg)	xf86DrvMsg(pScrn->scrnIndex, X_ERROR, msg);
@@ -49,14 +48,9 @@ typedef struct _modesettingRec
 {
     int fd;
     unsigned int fb_id;
-    void *virtual;
-    drmBO bo;
-    Bool front;
 
     EntPtr entityPrivate;
 
-    void (*PointerMoved) (int, int, int);
-
     int Chipset;
     EntityInfoPtr pEnt;
 #if XSERVER_LIBPCIACCESS
@@ -75,15 +69,12 @@ typedef struct _modesettingRec
 
     unsigned int SaveGeneration;
 
-    /* shadowfb */
-    CARD8 *shadowMem;
-    Bool shadowFB;
     CreateScreenResourcesProcPtr createScreenResources;
-    ShadowUpdateProc update;
 
     /* exa */
-    ExaDriverPtr pExa;
-    drmBO exa_bo;
+    void *exa;
+    void *driver;
+    Bool noEvict;
 
     /* dri2 */
     drm_context_t context;
diff --git a/hw/xfree86/drivers/modesetting/exa.c b/hw/xfree86/drivers/modesetting/exa.c
index 9327cbc..124dc03 100644
--- a/hw/xfree86/drivers/modesetting/exa.c
+++ b/hw/xfree86/drivers/modesetting/exa.c
@@ -31,19 +31,329 @@
 #include "config.h"
 #endif
 
+/* FIXME ! */
+#define DRI_DRIVER_PATH "/ISO/X.Org/modular/i386/lib/dri"
+
 #include "xf86.h"
 #include "xf86_OSproc.h"
-
 #include "driver.h"
+#include <dlfcn.h>
+
+#include "pipe/p_winsys.h"
+#include "pipe/p_format.h"
+#include "pipe/p_context.h"
+#include "pipe/p_util.h"
+#include "pipe/p_state.h"
+#include "pipe/p_inlines.h"
+
+/* EXA winsys */
+struct exa_context
+{
+};
+
+struct exa_winsys
+{
+    struct pipe_winsys base;
+    modesettingPtr ms;
+};
 
-struct PixmapPriv {
+struct exa_buffer
+{
+    struct pipe_buffer base;
     drmBO bo;
-    #if 0
+    boolean userBuffer;	/** Is this a user-space buffer? */
+    //void *data;
+    //void *mapped;
+};
+
+struct exa_surface
+{
+    struct pipe_surface surface;
+};
+
+struct exa_entity
+{
+    ExaDriverPtr pExa;
+    struct exa_context *c;
+    struct pipe_winsys *ws;
+    struct pipe_context *ctx;
+    struct pipe_screen *scrn;
+};
+
+static INLINE struct exa_winsys *
+exa_get_winsys(struct pipe_winsys *ws)
+{
+    return (struct exa_winsys *)ws;
+}
+
+static INLINE struct exa_surface *
+exa_get_surface(struct pipe_surface *ps)
+{
+    return (struct exa_surface *)ps;
+}
+
+static INLINE struct exa_buffer *
+exa_get_buffer(struct pipe_buffer *buf)
+{
+    return (struct exa_buffer *)buf;
+}
+
+static void *
+exa_buffer_map(struct pipe_winsys *pws, struct pipe_buffer *buf,
+	       unsigned flags)
+{
+    struct exa_buffer *exa_buf = exa_get_buffer(buf);
+    struct exa_winsys *exa_winsys = exa_get_winsys(pws);
+    void *virtual;
+
+    drmBOMap(exa_winsys->ms->fd,
+	     &exa_buf->bo, DRM_BO_FLAG_READ | DRM_BO_FLAG_WRITE, 0, &virtual);
+
+    return virtual;
+}
+
+static void
+exa_buffer_unmap(struct pipe_winsys *pws, struct pipe_buffer *buf)
+{
+    struct exa_buffer *exa_buf = exa_get_buffer(buf);
+    struct exa_winsys *exa_winsys = exa_get_winsys(pws);
+
+    drmBOUnmap(exa_winsys->ms->fd, &exa_buf->bo);
+}
+
+static void
+exa_buffer_destroy(struct pipe_winsys *pws, struct pipe_buffer *buf)
+{
+    struct exa_winsys *exa_winsys = exa_get_winsys(pws);
+    struct exa_buffer *exa_buf = exa_get_buffer(buf);
+
+    drmBOUnreference(exa_winsys->ms->fd, &exa_buf->bo);
+
+    free(exa_buf);
+}
+
+static void
+exa_flush_frontbuffer(struct pipe_winsys *pws,
+		      struct pipe_surface *surf, void *context_private)
+{
+    struct exa_buffer *exa_buf = exa_get_buffer(surf->buffer);
+
+    ErrorF("WANT TO FLUSH\n");
+}
+
+static const char *
+exa_get_name(struct pipe_winsys *pws)
+{
+    return "EXA";
+}
+
+static struct pipe_buffer *
+exa_buffer_create(struct pipe_winsys *pws,
+		  unsigned alignment, unsigned usage, unsigned size)
+{
+    struct exa_buffer *buffer = xcalloc(1, sizeof(struct exa_buffer));
+    struct exa_winsys *exa_winsys = exa_get_winsys(pws);
+    unsigned int flags = 0;
+
+    buffer->base.refcount = 1;
+    buffer->base.alignment = alignment;
+    buffer->base.usage = usage;
+    buffer->base.size = size;
+
+    if (exa_winsys->ms->noEvict) {
+	flags = DRM_BO_FLAG_NO_EVICT;
+	ErrorF("DISPLAY TARGET\n");
+    }
+
+    ErrorF("SIZE %d %d\n", size, alignment);
+    if (!buffer->bo.handle) {
+	// buffer->data = align_malloc(size, alignment);
+	drmBOCreate(exa_winsys->ms->fd, size, 4096, NULL,
+		    DRM_BO_FLAG_READ | DRM_BO_FLAG_WRITE |
+		    DRM_BO_FLAG_SHAREABLE | DRM_BO_FLAG_MEM_TT |
+		    DRM_BO_FLAG_MAPPABLE | DRM_BO_FLAG_CACHED_MAPPED | flags,
+		    0, &buffer->bo);
+    }
+
+    return &buffer->base;
+}
+
+static struct pipe_buffer *
+exa_user_buffer_create(struct pipe_winsys *pws, void *ptr, unsigned bytes)
+{
+    struct exa_buffer *buffer = xcalloc(1, sizeof(struct exa_buffer));
+
+    buffer->base.refcount = 1;
+    buffer->base.size = bytes;
+    buffer->userBuffer = TRUE;
+    //buffer->data = ptr;
+    ErrorF("USERBUFFER\n");
+
+    return &buffer->base;
+}
+
+/**
+ * Round n up to next multiple.
+ */
+static INLINE unsigned
+round_up(unsigned n, unsigned multiple)
+{
+    return (n + multiple - 1) & ~(multiple - 1);
+}
+
+static int
+exa_surface_alloc_storage(struct pipe_winsys *winsys,
+			  struct pipe_surface *surf,
+			  unsigned width, unsigned height,
+			  enum pipe_format format,
+			  unsigned flags, unsigned tex_usage)
+{
+    const unsigned alignment = 64;
+
+    surf->width = width;
+    surf->height = height;
+    surf->format = format;
+    surf->cpp = pf_get_size(format);
+    surf->pitch = round_up(width, alignment / surf->cpp);
+
+    assert(!surf->buffer);
+    surf->buffer = winsys->buffer_create(winsys, alignment,
+					 PIPE_BUFFER_USAGE_PIXEL,
+					 surf->pitch * surf->cpp * height);
+    if (!surf->buffer)
+	return -1;
+
+    return 0;
+}
+
+/**
+ * Called via winsys->surface_alloc() to create new surfaces.
+ */
+static struct pipe_surface *
+exa_surface_alloc(struct pipe_winsys *ws)
+{
+    struct exa_surface *wms = xcalloc(1, sizeof(struct exa_surface));
+
+    assert(ws);
+
+    wms->surface.refcount = 1;
+    wms->surface.winsys = ws;
+
+    return &wms->surface;
+}
+
+static void
+exa_surface_release(struct pipe_winsys *winsys, struct pipe_surface **s)
+{
+    struct pipe_surface *surf = *s;
+
+    surf->refcount--;
+    if (surf->refcount == 0) {
+	if (surf->buffer)
+	    pipe_buffer_reference(winsys, &surf->buffer, NULL);
+	free(surf);
+    }
+    *s = NULL;
+}
+
+/*
+ * Fence functions - basically nothing to do, as we don't create any actual
+ * fence objects.
+ */
+static void
+exa_fence_reference(struct pipe_winsys *sws, struct pipe_fence_handle **ptr,
+		    struct pipe_fence_handle *fence)
+{
+}
+
+static int
+exa_fence_signalled(struct pipe_winsys *sws, struct pipe_fence_handle *fence,
+		    unsigned flag)
+{
+    return 0;
+}
+
+static int
+exa_fence_finish(struct pipe_winsys *sws, struct pipe_fence_handle *fence,
+		 unsigned flag)
+{
+    return 0;
+}
+
+struct pipe_winsys *
+exa_get_pipe_winsys(modesettingPtr ms)
+{
+    static struct exa_winsys *ws = NULL;
+
+    if (!ws) {
+	ws = xcalloc(1, sizeof(struct exa_winsys));
+
+	/* Fill in this struct with callbacks that pipe will need to
+	 * communicate with the window system, buffer manager, etc. 
+	 */
+	ws->base.buffer_create = exa_buffer_create;
+	ws->base.user_buffer_create = exa_user_buffer_create;
+	ws->base.buffer_map = exa_buffer_map;
+	ws->base.buffer_unmap = exa_buffer_unmap;
+	ws->base.buffer_destroy = exa_buffer_destroy;
+
+	ws->base.surface_alloc = exa_surface_alloc;
+	ws->base.surface_alloc_storage = exa_surface_alloc_storage;
+	ws->base.surface_release = exa_surface_release;
+
+	ws->base.fence_reference = exa_fence_reference;
+	ws->base.fence_signalled = exa_fence_signalled;
+	ws->base.fence_finish = exa_fence_finish;
+
+	ws->base.flush_frontbuffer = exa_flush_frontbuffer;
+	ws->base.get_name = exa_get_name;
+
+	ws->ms = ms;
+    }
+
+    return &ws->base;
+}
+
+/* EXA functions */
+
+struct PixmapPriv
+{
+    drmBO bo;
+#if 0
     dri_fence *fence;
-    #endif
+#endif
     int flags;
+
+    struct pipe_texture *tex;
+    unsigned int color;
+    struct pipe_surface *src_surf;     /* for copies */
 };
 
+static enum pipe_format
+exa_get_pipe_format(int depth)
+{
+    switch (depth) {
+    case 32:
+    case 24:
+	return PIPE_FORMAT_A8R8G8B8_UNORM;
+    case 16:
+	return PIPE_FORMAT_R5G6B5_UNORM;
+    case 15:
+	return PIPE_FORMAT_A1R5G5B5_UNORM;
+    case 8:
+    case 4:
+    case 1:
+	return PIPE_FORMAT_A8R8G8B8_UNORM;	/* bad bad bad */
+    default:
+	assert(0);
+	return 0;
+    }
+}
+
+/*
+ * EXA functions
+ */
+
 static void
 ExaWaitMarker(ScreenPtr pScreen, int marker)
 {
@@ -62,6 +372,7 @@ ExaPrepareAccess(PixmapPtr pPix, int index)
     ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
     modesettingPtr ms = modesettingPTR(pScrn);
     PixmapPtr rootPixmap = pScreen->GetScreenPixmap(pScreen);
+    struct exa_entity *exa = ms->exa;
     struct PixmapPriv *priv;
     int ret;
 
@@ -70,21 +381,20 @@ ExaPrepareAccess(PixmapPtr pPix, int index)
     if (!priv)
 	return FALSE;
 
-    if (priv->bo.handle) {
-    	void *virtual;
-
-    	ret = drmBOMap(ms->fd,
-	     &priv->bo, DRM_BO_FLAG_READ | DRM_BO_FLAG_WRITE, 0, &virtual);
-	if (ret) {
-    	    driUnlock(pScreen);
-	    FatalError("Failed to map pixmap: %s\n", strerror(-ret));
-	    return;
-	}
-
-	pPix->devPrivate.ptr = priv->bo.virtual;
+    if (!priv->tex)
+	return FALSE;
+    {
+	struct pipe_surface *surf =
+	    exa->scrn->get_tex_surface(exa->scrn, priv->tex, 0, 0, 0,
+				       PIPE_BUFFER_USAGE_CPU_READ |
+				       PIPE_BUFFER_USAGE_CPU_WRITE);
+	pPix->devPrivate.ptr =
+	    exa->scrn->surface_map(exa->scrn, surf,
+				   PIPE_BUFFER_USAGE_CPU_READ |
+				   PIPE_BUFFER_USAGE_CPU_WRITE);
+	exa->scrn->tex_surface_release(exa->scrn, &surf);
     }
 
-
     return TRUE;
 }
 
@@ -96,6 +406,7 @@ ExaFinishAccess(PixmapPtr pPix, int index)
     modesettingPtr ms = modesettingPTR(pScrn);
     PixmapPtr rootPixmap = pScreen->GetScreenPixmap(pScreen);
     struct PixmapPriv *priv;
+    struct exa_entity *exa = ms->exa;
     int ret;
 
     priv = exaGetPixmapDriverPrivate(pPix);
@@ -103,14 +414,15 @@ ExaFinishAccess(PixmapPtr pPix, int index)
     if (!priv)
 	return;
 
-    if (priv->bo.handle) {
-	ret = drmBOUnmap(ms->fd, &priv->bo);
-	if (ret) {
-	    driUnlock(pScreen);
-	    FatalError("Failed to unmap pixmap: %s\n", strerror(-ret));
-	    return;
-	}
-
+    if (!priv->tex)
+	return;
+    {
+	struct pipe_surface *surf =
+	    exa->scrn->get_tex_surface(exa->scrn, priv->tex, 0, 0, 0,
+				       PIPE_BUFFER_USAGE_CPU_READ |
+				       PIPE_BUFFER_USAGE_CPU_WRITE);
+	exa->scrn->surface_unmap(exa->scrn, surf);
+	exa->scrn->tex_surface_release(exa->scrn, &surf);
 	pPix->devPrivate.ptr = NULL;
     }
 }
@@ -119,6 +431,16 @@ static void
 ExaDone(PixmapPtr pPixmap)
 {
     ScrnInfoPtr pScrn = xf86Screens[pPixmap->drawable.pScreen->myNum];
+    modesettingPtr ms = modesettingPTR(pScrn);
+    struct PixmapPriv *priv = exaGetPixmapDriverPrivate(pPixmap);
+    struct exa_entity *exa = ms->exa;
+
+    if (!priv)
+	return;
+
+    if (priv->src_surf)
+	exa->scrn->tex_surface_release(exa->scrn, &priv->src_surf);
+    priv->src_surf = NULL;
 }
 
 static void
@@ -131,23 +453,46 @@ static Bool
 ExaPrepareSolid(PixmapPtr pPixmap, int alu, Pixel planeMask, Pixel fg)
 {
     ScrnInfoPtr pScrn = xf86Screens[pPixmap->drawable.pScreen->myNum];
+    modesettingPtr ms = modesettingPTR(pScrn);
+    struct PixmapPriv *priv = exaGetPixmapDriverPrivate(pPixmap);
+    struct exa_entity *exa = ms->exa;
 
-    ErrorF("SOLID\n");
+    if (pPixmap->drawable.depth < 15)
+	return FALSE;
 
     if (!EXA_PM_IS_SOLID(&pPixmap->drawable, planeMask))
 	return FALSE;
 
-    /* can't do depth 4 */
-    if (pPixmap->drawable.depth == 4)
+    if (!priv->tex)
 	return FALSE;
 
-    return FALSE;
+    if (alu != GXcopy)
+	return FALSE;
+
+    if (!exa->ctx || !exa->ctx->surface_fill)
+	return FALSE;
+
+    priv->color = fg;
+
+    return TRUE;
 }
 
 static void
-ExaSolid(PixmapPtr pPixmap, int x1, int y1, int x2, int y2)
+ExaSolid(PixmapPtr pPixmap, int x0, int y0, int x1, int y1)
 {
     ScrnInfoPtr pScrn = xf86Screens[pPixmap->drawable.pScreen->myNum];
+    modesettingPtr ms = modesettingPTR(pScrn);
+    struct exa_entity *exa = ms->exa;
+    struct PixmapPriv *priv = exaGetPixmapDriverPrivate(pPixmap);
+    struct pipe_surface *surf =
+	exa->scrn->get_tex_surface(exa->scrn, priv->tex, 0, 0, 0,
+				   PIPE_BUFFER_USAGE_GPU_READ |
+				   PIPE_BUFFER_USAGE_GPU_WRITE);
+
+    exa->ctx->surface_fill(exa->ctx, surf, x0, y0, x1 - x0, y1 - y0,
+			   priv->color);
+
+    exa->scrn->tex_surface_release(exa->scrn, &surf);
 }
 
 static Bool
@@ -155,13 +500,31 @@ ExaPrepareCopy(PixmapPtr pSrcPixmap, PixmapPtr pDstPixmap, int xdir,
 	       int ydir, int alu, Pixel planeMask)
 {
     ScrnInfoPtr pScrn = xf86Screens[pDstPixmap->drawable.pScreen->myNum];
+    modesettingPtr ms = modesettingPTR(pScrn);
+    struct exa_entity *exa = ms->exa;
+    struct pipe_surface *src_surf;
+    struct PixmapPriv *priv = exaGetPixmapDriverPrivate(pDstPixmap);
+
+    if (alu != GXcopy)
+	return FALSE;
+
+    if (pSrcPixmap->drawable.depth < 15 || pDstPixmap->drawable.depth < 15)
+	return FALSE;
+
+    if (!EXA_PM_IS_SOLID(&pSrcPixmap->drawable, planeMask))
+	return FALSE;
 
-    ErrorF("COPY\n");
+    if (!priv->tex)
+	return FALSE;
 
-    /* can't do depth 4 */
-    if (pSrcPixmap->drawable.depth == 4 || pDstPixmap->drawable.depth == 4)
+    if (!exa->ctx || !exa->ctx->surface_copy)
 	return FALSE;
 
+    priv->src_surf =
+	exa->scrn->get_tex_surface(exa->scrn, priv->tex, 0, 0, 0,
+				   PIPE_BUFFER_USAGE_GPU_READ |
+				   PIPE_BUFFER_USAGE_GPU_WRITE);
+
     return FALSE;
 }
 
@@ -170,6 +533,17 @@ ExaCopy(PixmapPtr pDstPixmap, int srcX, int srcY, int dstX, int dstY,
 	int width, int height)
 {
     ScrnInfoPtr pScrn = xf86Screens[pDstPixmap->drawable.pScreen->myNum];
+    modesettingPtr ms = modesettingPTR(pScrn);
+    struct exa_entity *exa = ms->exa;
+    struct PixmapPriv *priv = exaGetPixmapDriverPrivate(pDstPixmap);
+    struct pipe_surface *surf =
+	exa->scrn->get_tex_surface(exa->scrn, priv->tex, 0, 0, 0,
+				   PIPE_BUFFER_USAGE_GPU_READ |
+				   PIPE_BUFFER_USAGE_GPU_WRITE);
+
+    exa->ctx->surface_copy(exa->ctx, 0, surf, dstX, dstY, priv->src_surf,
+			   srcX, srcY, width, height);
+    exa->scrn->tex_surface_release(exa->scrn, &surf);
 }
 
 static Bool
@@ -225,37 +599,29 @@ ExaCreatePixmap(ScreenPtr pScreen, int size, int align)
 
     priv = xcalloc(1, sizeof(struct PixmapPriv));
     if (!priv)
-        return NULL;
-
-    if (size == 0)
-	return priv;
-
-    drmBOCreate(ms->fd, size, 4096, NULL,
-		DRM_BO_FLAG_READ | DRM_BO_FLAG_WRITE | DRM_BO_FLAG_SHAREABLE
-		| DRM_BO_FLAG_MEM_TT | DRM_BO_FLAG_MAPPABLE |
-		DRM_BO_FLAG_CACHED_MAPPED,
-		0, &priv->bo);
+	return NULL;
 
     return priv;
 }
 
-static void 
+static void
 ExaDestroyPixmap(ScreenPtr pScreen, void *dPriv)
 {
     struct PixmapPriv *priv = (struct PixmapPriv *)dPriv;
     ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
     modesettingPtr ms = modesettingPTR(pScrn);
+    struct exa_entity *exa = ms->exa;
 
     if (!priv)
-    	return;
+	return;
 
-    if (priv->bo.handle)
-	drmBOUnreference(ms->fd, &priv->bo);
+    if (priv->tex)
+	exa->scrn->texture_release(exa->scrn, &priv->tex);
 
     xfree(priv);
 }
 
-static Bool 
+static Bool
 ExaPixmapIsOffscreen(PixmapPtr pPixmap)
 {
     struct PixmapPriv *priv;
@@ -265,10 +631,10 @@ ExaPixmapIsOffscreen(PixmapPtr pPixmap)
     priv = exaGetPixmapDriverPrivate(pPixmap);
 
     if (!priv)
-       return FALSE;
+	return FALSE;
 
-    if (priv->bo.handle)
-       return TRUE;
+    if (priv->tex)
+	return TRUE;
 
     return FALSE;
 }
@@ -281,87 +647,146 @@ driGetPixmapHandle(PixmapPtr pPixmap, unsigned int *flags)
     PixmapPtr rootPixmap = pScreen->GetScreenPixmap(pScreen);
     ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
     modesettingPtr ms = modesettingPTR(pScrn);
+    struct exa_entity *exa = ms->exa;
+    struct exa_buffer *exa_buf;
+    struct pipe_surface *surf;
     struct PixmapPriv *priv;
 
     *flags = 0;
 
-    if (rootPixmap == pPixmap)
-        return ms->bo.handle;
-
-    if (!ms->pExa)
-    	return 0;
+    if (!ms->exa) {
+	FatalError("NO MS->EXA\n");
+	return 0;
+    }
 
     priv = exaGetPixmapDriverPrivate(pPixmap);
 
-    if (!priv)
-       return 0;
+    if (!priv) {
+	FatalError("NO PIXMAP PRIVATE\n");
+	return 0;
+    }
+
+    surf =
+	exa->scrn->get_tex_surface(exa->scrn, priv->tex, 0, 0, 0,
+				   PIPE_BUFFER_USAGE_CPU_READ |
+				   PIPE_BUFFER_USAGE_CPU_WRITE);
+    exa_buf = exa_get_buffer(surf->buffer);
+    exa->scrn->tex_surface_release(exa->scrn, &surf);
 
-    if (priv->bo.handle)
-        return priv->bo.handle;
+    if (exa_buf->bo.handle)
+	return exa_buf->bo.handle;
 
     return 0;
 }
 
-static Bool 
+static Bool
 ExaModifyPixmapHeader(PixmapPtr pPixmap, int width, int height,
 		      int depth, int bitsPerPixel, int devKind,
 		      pointer pPixData)
 {
-    ScreenPtr	pScreen = pPixmap->drawable.pScreen;
+    ScreenPtr pScreen = pPixmap->drawable.pScreen;
     ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
     struct PixmapPriv *priv = exaGetPixmapDriverPrivate(pPixmap);
     modesettingPtr ms = modesettingPTR(pScrn);
     PixmapPtr rootPixmap = pScreen->GetScreenPixmap(pScreen);
+    struct exa_entity *exa = ms->exa;
 
-    if (rootPixmap == pPixmap) {
+    /*if (rootPixmap == pPixmap) */  {
 	miModifyPixmapHeader(pPixmap, width, height, depth,
 			     bitsPerPixel, devKind, NULL);
+    }
 
-	return TRUE;
+    if (!priv)
+	return FALSE;
+
+    if (depth <= 0)
+	depth = pPixmap->drawable.depth;
+
+    if (bitsPerPixel <= 0)
+	bitsPerPixel = pPixmap->drawable.bitsPerPixel;
+
+    if (width <= 0)
+	width = pPixmap->drawable.width;
+
+    if (height <= 0)
+	height = pPixmap->drawable.height;
+
+    if (width <= 0 || height <= 0 || depth <= 0)
+	return FALSE;
+
+    /* Deal with screen resize */
+    if (priv->tex) {
+	struct pipe_surface *surf =
+	    exa->scrn->get_tex_surface(exa->scrn, priv->tex, 0, 0, 0,
+				       PIPE_BUFFER_USAGE_CPU_READ |
+				       PIPE_BUFFER_USAGE_CPU_WRITE);
+
+	ErrorF("RESIZE %d %d to %d %d\n", surf->width, surf->height, width,
+	       height);
+	if (surf->width != width || surf->height != height) {
+	    exa->scrn->texture_release(exa->scrn, &priv->tex);
+	    priv->tex = NULL;
+	}
+	exa->scrn->tex_surface_release(exa->scrn, &surf);
     }
 
-    return FALSE;
-}
+    if (!priv->tex) {
+	struct pipe_texture template;
+
+	memset(&template, 0, sizeof(template));
+	template.target = PIPE_TEXTURE_2D;
+	template.compressed = 0;
+	template.format = exa_get_pipe_format(depth);
+	template.cpp = pf_get_size(template.format);
+	template.width[0] = width;
+	template.height[0] = height;
+	template.depth[0] = 1;
+	template.last_level = 0;
+	template.tex_usage = PIPE_TEXTURE_USAGE_RENDER_TARGET;
+	priv->tex = exa->scrn->texture_create(exa->scrn, &template);
+    }
+
+    if (rootPixmap == pPixmap)
+	return TRUE;
 
+    return TRUE;
+}
 
 void
 ExaClose(ScrnInfoPtr pScrn)
 {
     modesettingPtr ms = modesettingPTR(pScrn);
+    struct exa_entity *exa = ms->exa;
 
     exaDriverFini(pScrn->pScreen);
 
-#if 0
-    drmBOUnreference(ms->fd, &ms->exa_bo);
-#endif
+    dlclose(ms->driver);
 }
 
-ExaDriverPtr
+void *
 ExaInit(ScrnInfoPtr pScrn)
 {
     modesettingPtr ms = modesettingPTR(pScrn);
-    ExaDriverPtr pExa;
+    struct exa_entity *exa;
+    ExaDriverPtr pExa = exa->pExa;
+
+    exa = xcalloc(1, sizeof(struct exa_entity));
+    if (!exa)
+	return NULL;
 
     pExa = exaDriverAlloc();
     if (!pExa) {
 	goto out_err;
     }
 
-#if 0
-    /* Create a 256KB offscreen area */
-    drmBOCreate(ms->fd, 256 * 1024, 0, NULL,
-		DRM_BO_FLAG_READ | DRM_BO_FLAG_WRITE | DRM_BO_FLAG_MEM_TT,
-		DRM_BO_HINT_DONT_FENCE, &ms->exa_bo);
-#endif
-
     memset(pExa, 0, sizeof(*pExa));
     pExa->exa_major = 2;
     pExa->exa_minor = 4;
-    pExa->memoryBase = 0; /* ms->exa_bo.virtual; */
-    pExa->memorySize = 0; /* ms->exa_bo.size; */
+    pExa->memoryBase = 0;
+    pExa->memorySize = 0;
     pExa->offScreenBase = 0;
-    pExa->pixmapOffsetAlign = 8;
-    pExa->pixmapPitchAlign = 32 * 4;
+    pExa->pixmapOffsetAlign = 0;
+    pExa->pixmapPitchAlign = 1;
     pExa->flags = EXA_OFFSCREEN_PIXMAPS | EXA_HANDLES_PIXMAPS;
     pExa->maxX = 8191;		       /* FIXME */
     pExa->maxY = 8191;		       /* FIXME */
@@ -389,7 +814,30 @@ ExaInit(ScrnInfoPtr pScrn)
 	goto out_err;
     }
 
-    return pExa;
+    {
+	char filename[128];
+	char dri_driver_path[] = DRI_DRIVER_PATH;
+
+	snprintf(filename, sizeof filename,
+		 "%s/%s_dri.so", dri_driver_path, "i915");
+
+	ms->driver = dlopen(filename, RTLD_NOW | RTLD_DEEPBIND | RTLD_GLOBAL);
+
+	exa->c = xcalloc(1, sizeof(struct exa_context));
+
+	exa->ws = exa_get_pipe_winsys(ms);
+
+	exa->scrn = softpipe_create_screen(exa->ws);
+
+	exa->ctx = softpipe_create(exa->scrn, exa->ws, NULL);
+
+	if (!exa->ctx)
+	    ErrorF("BAD CTX\n");
+
+	exa->ctx->priv = exa->c;
+    }
+
+    return (void *)exa;
 
   out_err:
     ExaClose(pScrn);
commit 0e1aa03708d95cc1542bee31709a345d0f748f0c
Author: Alan Hourihane <alanh at tungstengraphics.com>
Date:   Thu Jun 26 22:27:14 2008 +0100

    yet more

diff --git a/hw/xfree86/drivers/modesetting/output.c b/hw/xfree86/drivers/modesetting/output.c
index 484acb2..1f95a2f 100644
--- a/hw/xfree86/drivers/modesetting/output.c
+++ b/hw/xfree86/drivers/modesetting/output.c
@@ -67,7 +67,6 @@ static char *connector_enum_list[] = {
     "HDMI Type B",
 };
 
-
 static void
 dpms(xf86OutputPtr output, int mode)
 {
@@ -162,7 +161,6 @@ get_modes(xf86OutputPtr output)
 	    mode->VRefresh = xf86ModeVRefresh(mode);
 	    mode->Private = (void *)drm_mode;
 	    xf86SetModeDefaultName(mode);
-	    ErrorF("MODE %s\n",mode->name);
 	    modes = xf86ModesAdd(modes, mode);
 	    xf86PrintModeline(0, mode);
 	}
@@ -277,11 +275,11 @@ output_init(ScrnInfoPtr pScrn)
 
 	drm_encoder = drmModeGetEncoder(ms->fd, drm_connector->encoders[0]);
 	if (drm_encoder) {
-	output->possible_crtcs = drm_encoder->crtcs;
-	output->possible_clones = drm_encoder->clones;
+	    output->possible_crtcs = drm_encoder->crtcs;
+	    output->possible_clones = drm_encoder->clones;
 	} else {
-	output->possible_crtcs = 0;
-	output->possible_clones = 0;
+	    output->possible_crtcs = 0;
+	    output->possible_clones = 0;
 	}
 	output->driver_private = drm_connector;
 	output->subpixel_order = SubPixelHorizontalRGB;
commit 2b3a3bc9202f4e6f9886a08a4dfa597a83a5e933
Author: Alan Hourihane <alanh at tungstengraphics.com>
Date:   Thu Jun 26 22:26:16 2008 +0100

    more formatting fixes

diff --git a/hw/xfree86/drivers/modesetting/dri2.c b/hw/xfree86/drivers/modesetting/dri2.c
index eec8069..7fd9fca 100644
--- a/hw/xfree86/drivers/modesetting/dri2.c
+++ b/hw/xfree86/drivers/modesetting/dri2.c
@@ -76,7 +76,8 @@ driEndClipNotify(ScreenPtr pScreen)
     driUnlock(pScreen);
 }
 
-struct __DRILock {
+struct __DRILock
+{
     unsigned int block_header;
     drm_hw_lock_t lock;
     unsigned int next_id;
@@ -99,13 +100,13 @@ driScreenInit(ScreenPtr pScreen)
     dri2info.version = 1;
     dri2info.fd = ms->fd;
     dri2info.driverSareaSize = sizeof(struct __DRILock);
-    dri2info.driverName = "i915"; /* FIXME */
+    dri2info.driverName = "i915";      /* FIXME */
     dri2info.getPixmapHandle = driGetPixmapHandle;
     dri2info.beginClipNotify = driBeginClipNotify;
-    dri2info.endClipNotify   = driEndClipNotify;
+    dri2info.endClipNotify = driEndClipNotify;
 
     p = DRI2ScreenInit(pScreen, &dri2info);
-    if (!p) 
+    if (!p)
 	return;
 
     DRILock = p;
commit 2a45c28712a544c6f1c3eb753678ba1738cfdd67
Author: Alan Hourihane <alanh at tungstengraphics.com>
Date:   Thu Jun 26 22:25:17 2008 +0100

    formatting fixes

diff --git a/hw/xfree86/drivers/modesetting/crtc.c b/hw/xfree86/drivers/modesetting/crtc.c
index 89ffe92..d4f449b 100644
--- a/hw/xfree86/drivers/modesetting/crtc.c
+++ b/hw/xfree86/drivers/modesetting/crtc.c
@@ -47,7 +47,8 @@
 #define DPMS_SERVER
 #include <X11/extensions/dpms.h>
 
-struct crtc_private {
+struct crtc_private
+{
     drmModeCrtcPtr drm_crtc;
 
     /* hwcursor */
@@ -122,6 +123,8 @@ crtc_mode_set(xf86CrtcPtr crtc, DisplayModePtr mode,
     drm_mode.hskew = mode->HSkew;
     drm_mode.vscan = mode->VScan;
     drm_mode.vrefresh = mode->VRefresh;
+    if (!mode->name)
+	xf86SetModeDefaultName(mode);
     strncpy(drm_mode.name, mode->name, DRM_DISPLAY_MODE_LEN);
 
     drmModeSetCrtc(ms->fd, drm_crtc->crtc_id, ms->fb_id, x, y,
@@ -176,29 +179,30 @@ crtc_destroy(xf86CrtcPtr crtc)
 }
 
 static void
-crtc_load_cursor_argb (xf86CrtcPtr crtc, CARD32 *image)
+crtc_load_cursor_argb(xf86CrtcPtr crtc, CARD32 * image)
 {
     unsigned char *ptr;
     modesettingPtr ms = modesettingPTR(crtc->scrn);
     struct crtc_private *crtcp = crtc->driver_private;
 
     if (!crtcp->cursor_bo.handle)
-        drmBOCreate(ms->fd, 64 * 64 * 4, 0, NULL,
-		DRM_BO_FLAG_READ | DRM_BO_FLAG_WRITE 
-		| DRM_BO_FLAG_NO_EVICT | DRM_BO_FLAG_MAPPABLE |
-		DRM_BO_FLAG_MEM_VRAM,
-		DRM_BO_HINT_DONT_FENCE, &crtcp->cursor_bo);
+	drmBOCreate(ms->fd, 64 * 64 * 4, 0, NULL,
+		    DRM_BO_FLAG_READ | DRM_BO_FLAG_WRITE
+		    | DRM_BO_FLAG_NO_EVICT | DRM_BO_FLAG_MAPPABLE |
+		    DRM_BO_FLAG_MEM_VRAM,
+		    DRM_BO_HINT_DONT_FENCE, &crtcp->cursor_bo);
 
-    drmBOMap(ms->fd, &crtcp->cursor_bo, DRM_BO_FLAG_WRITE, DRM_BO_HINT_DONT_FENCE, (void **)&ptr);
+    drmBOMap(ms->fd, &crtcp->cursor_bo, DRM_BO_FLAG_WRITE,
+	     DRM_BO_HINT_DONT_FENCE, (void **)&ptr);
 
     if (ptr)
-	memcpy (ptr, image, 64 * 64 * 4);
+	memcpy(ptr, image, 64 * 64 * 4);
 
     drmBOUnmap(ms->fd, &crtcp->cursor_bo);
 }
 
 static void
-crtc_set_cursor_position (xf86CrtcPtr crtc, int x, int y)
+crtc_set_cursor_position(xf86CrtcPtr crtc, int x, int y)
 {
     modesettingPtr ms = modesettingPTR(crtc->scrn);
     struct crtc_private *crtcp = crtc->driver_private;
@@ -207,17 +211,18 @@ crtc_set_cursor_position (xf86CrtcPtr crtc, int x, int y)
 }
 
 static void
-crtc_show_cursor (xf86CrtcPtr crtc)
+crtc_show_cursor(xf86CrtcPtr crtc)
 {
     modesettingPtr ms = modesettingPTR(crtc->scrn);
     struct crtc_private *crtcp = crtc->driver_private;
 
     if (crtcp->cursor_bo.handle)
-	drmModeSetCursor(ms->fd, crtcp->drm_crtc->crtc_id, crtcp->cursor_bo.handle, 64, 64);
+	drmModeSetCursor(ms->fd, crtcp->drm_crtc->crtc_id,
+			 crtcp->cursor_bo.handle, 64, 64);
 }
 
 static void
-crtc_hide_cursor (xf86CrtcPtr crtc)
+crtc_hide_cursor(xf86CrtcPtr crtc)
 {
     modesettingPtr ms = modesettingPTR(crtc->scrn);
     struct crtc_private *crtcp = crtc->driver_private;
@@ -242,8 +247,8 @@ static const xf86CrtcFuncsRec crtc_funcs = {
     .set_cursor_position = crtc_set_cursor_position,
     .show_cursor = crtc_show_cursor,
     .hide_cursor = crtc_hide_cursor,
-    .load_cursor_image = NULL,	/* lets convert to argb only */
-    .set_cursor_colors = NULL, /* using argb only */
+    .load_cursor_image = NULL,	       /* lets convert to argb only */
+    .set_cursor_colors = NULL,	       /* using argb only */
     .load_cursor_argb = crtc_load_cursor_argb,
     .destroy = crtc_destroy,
 };
@@ -255,8 +260,8 @@ cursor_destroy(xf86CrtcPtr crtc)
     struct crtc_private *crtcp = crtc->driver_private;
 
     if (crtcp->cursor_bo.handle) {
-    	drmBOSetStatus(ms->fd, &crtcp->cursor_bo, 0, 0, 0, 0, 0);
-    	drmBOUnreference(ms->fd, &crtcp->cursor_bo);
+	drmBOSetStatus(ms->fd, &crtcp->cursor_bo, 0, 0, 0, 0, 0);
+	drmBOUnreference(ms->fd, &crtcp->cursor_bo);
     }
 }
 
@@ -291,10 +296,10 @@ crtc_init(ScrnInfoPtr pScrn)
 	    goto out;
 	}
 
- 	crtcp->drm_crtc = drm_crtc;
+	crtcp->drm_crtc = drm_crtc;
 
 	crtc->driver_private = crtcp;
-    
+
     }
 
   out:
commit 47969d79289ad92f658c9a6dd2a2fc6b5f1b6c99
Author: Alan Hourihane <alanh at tungstengraphics.com>
Date:   Mon Jun 16 15:07:39 2008 +0100

    Add DRI2 support.
    
    Add EXA stubs.
    
    Currently tested with i915.

diff --git a/hw/xfree86/drivers/modesetting/Makefile.am b/hw/xfree86/drivers/modesetting/Makefile.am
index 17d884f..a182d44 100644
--- a/hw/xfree86/drivers/modesetting/Makefile.am
+++ b/hw/xfree86/drivers/modesetting/Makefile.am
@@ -37,6 +37,7 @@ modesetting_drv_la_SOURCES = \
 	 driver.h \
 	 output.c \
 	 crtc.c \
-	 exa.c
+	 exa.c \
+	 dri2.c
 
 EXTRA_DIST =
diff --git a/hw/xfree86/drivers/modesetting/crtc.c b/hw/xfree86/drivers/modesetting/crtc.c
index 14ee53e..89ffe92 100644
--- a/hw/xfree86/drivers/modesetting/crtc.c
+++ b/hw/xfree86/drivers/modesetting/crtc.c
@@ -168,8 +168,11 @@ crtc_destroy(xf86CrtcPtr crtc)
     modesettingPtr ms = modesettingPTR(crtc->scrn);
     struct crtc_private *crtcp = crtc->driver_private;
 
-    drmBOUnreference(ms->fd, &crtcp->cursor_bo);
+    if (crtcp->cursor_bo.handle)
+	drmBOUnreference(ms->fd, &crtcp->cursor_bo);
+
     drmModeFreeCrtc(crtcp->drm_crtc);
+    xfree(crtcp);
 }
 
 static void
@@ -179,9 +182,17 @@ crtc_load_cursor_argb (xf86CrtcPtr crtc, CARD32 *image)
     modesettingPtr ms = modesettingPTR(crtc->scrn);
     struct crtc_private *crtcp = crtc->driver_private;
 
-    drmBOMap(ms->fd, &crtcp->cursor_bo, DRM_BO_FLAG_WRITE, 0, (void **)&ptr);
+    if (!crtcp->cursor_bo.handle)
+        drmBOCreate(ms->fd, 64 * 64 * 4, 0, NULL,
+		DRM_BO_FLAG_READ | DRM_BO_FLAG_WRITE 
+		| DRM_BO_FLAG_NO_EVICT | DRM_BO_FLAG_MAPPABLE |
+		DRM_BO_FLAG_MEM_VRAM,
+		DRM_BO_HINT_DONT_FENCE, &crtcp->cursor_bo);
+
+    drmBOMap(ms->fd, &crtcp->cursor_bo, DRM_BO_FLAG_WRITE, DRM_BO_HINT_DONT_FENCE, (void **)&ptr);
 
-    memcpy (ptr, image, 64 * 64 * 4);
+    if (ptr)
+	memcpy (ptr, image, 64 * 64 * 4);
 
     drmBOUnmap(ms->fd, &crtcp->cursor_bo);
 }
@@ -201,7 +212,8 @@ crtc_show_cursor (xf86CrtcPtr crtc)
     modesettingPtr ms = modesettingPTR(crtc->scrn);
     struct crtc_private *crtcp = crtc->driver_private;
 
-    drmModeSetCursor(ms->fd, crtcp->drm_crtc->crtc_id, crtcp->cursor_bo.handle, 64, 64);
+    if (crtcp->cursor_bo.handle)
+	drmModeSetCursor(ms->fd, crtcp->drm_crtc->crtc_id, crtcp->cursor_bo.handle, 64, 64);
 }
 
 static void
@@ -213,12 +225,6 @@ crtc_hide_cursor (xf86CrtcPtr crtc)
     drmModeSetCursor(ms->fd, crtcp->drm_crtc->crtc_id, 0, 0, 0);
 }
 
-static void
-crtc_set_cursor_colors (xf86CrtcPtr crtc, int bg, int fg)
-{
-    ScrnInfoPtr		scrn = crtc->scrn;
-}
-
 static const xf86CrtcFuncsRec crtc_funcs = {
     .dpms = crtc_dpms,
     .save = NULL,
@@ -233,16 +239,28 @@ static const xf86CrtcFuncsRec crtc_funcs = {
     .shadow_create = crtc_shadow_create,
     .shadow_allocate = crtc_shadow_allocate,
     .shadow_destroy = crtc_shadow_destroy,
-    .set_cursor_colors = crtc_set_cursor_colors,
     .set_cursor_position = crtc_set_cursor_position,
     .show_cursor = crtc_show_cursor,
     .hide_cursor = crtc_hide_cursor,
     .load_cursor_image = NULL,	/* lets convert to argb only */
+    .set_cursor_colors = NULL, /* using argb only */
     .load_cursor_argb = crtc_load_cursor_argb,
     .destroy = crtc_destroy,
 };
 
 void
+cursor_destroy(xf86CrtcPtr crtc)
+{
+    modesettingPtr ms = modesettingPTR(crtc->scrn);
+    struct crtc_private *crtcp = crtc->driver_private;
+
+    if (crtcp->cursor_bo.handle) {
+    	drmBOSetStatus(ms->fd, &crtcp->cursor_bo, 0, 0, 0, 0, 0);
+    	drmBOUnreference(ms->fd, &crtcp->cursor_bo);
+    }
+}
+
+void
 crtc_init(ScrnInfoPtr pScrn)
 {
     modesettingPtr ms = modesettingPTR(pScrn);
@@ -267,7 +285,7 @@ crtc_init(ScrnInfoPtr pScrn)
 	if (crtc == NULL)
 	    goto out;
 
-	crtcp = xalloc(sizeof(struct crtc_private));
+	crtcp = xcalloc(1, sizeof(struct crtc_private));
 	if (!crtcp) {
 	    xf86CrtcDestroy(crtc);
 	    goto out;
@@ -277,11 +295,6 @@ crtc_init(ScrnInfoPtr pScrn)
 
 	crtc->driver_private = crtcp;
     
-        drmBOCreate(ms->fd, 64 * 64 * 4, 0, NULL,
-		DRM_BO_FLAG_READ | DRM_BO_FLAG_WRITE 
-		| DRM_BO_FLAG_NO_EVICT | DRM_BO_FLAG_MAPPABLE |
-		DRM_BO_FLAG_MEM_VRAM | DRM_BO_FLAG_MEM_TT,
-		DRM_BO_HINT_DONT_FENCE, &crtcp->cursor_bo);
     }
 
   out:
diff --git a/hw/xfree86/drivers/modesetting/dri2.c b/hw/xfree86/drivers/modesetting/dri2.c
new file mode 100644
index 0000000..eec8069
--- /dev/null
+++ b/hw/xfree86/drivers/modesetting/dri2.c
@@ -0,0 +1,127 @@
+/*
+ * Copyright 2008 Tungsten Graphics, 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 TUNGSTEN GRAPHICS 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.
+ *
+ *
+ * Author: Alan Hourihane <alanh at tungstengraphics.com>
+ *
+ */
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include "xf86.h"
+#include "xf86_OSproc.h"
+
+#include "driver.h"
+
+#include "dri2.h"
+
+extern unsigned int
+driGetPixmapHandle(PixmapPtr pPixmap, unsigned int *flags);
+
+void
+driLock(ScreenPtr pScreen)
+{
+    ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
+    modesettingPtr ms = modesettingPTR(pScrn);
+
+    if (!ms->lock_held)
+	DRM_LOCK(ms->fd, ms->lock, ms->context, 0);
+
+    ms->lock_held = 1;
+}
+
+void
+driUnlock(ScreenPtr pScreen)
+{
+    ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
+    modesettingPtr ms = modesettingPTR(pScrn);
+
+    if (ms->lock_held)
+	DRM_UNLOCK(ms->fd, ms->lock, ms->context);
+
+    ms->lock_held = 0;
+}
+
+static void
+driBeginClipNotify(ScreenPtr pScreen)
+{
+    driLock(pScreen);
+}
+
+static void
+driEndClipNotify(ScreenPtr pScreen)
+{
+    driUnlock(pScreen);
+}
+
+struct __DRILock {
+    unsigned int block_header;
+    drm_hw_lock_t lock;
+    unsigned int next_id;
+};
+
+#define DRI2_SAREA_BLOCK_HEADER(type, size) (((type) << 16) | (size))
+#define DRI2_SAREA_BLOCK_LOCK		0x0001
+
+void
+driScreenInit(ScreenPtr pScreen)
+{
+    ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
+    modesettingPtr ms = modesettingPTR(pScrn);
+    DRI2InfoRec dri2info;
+    const char *driverName;
+    unsigned int sarea_handle;
+    struct __DRILock *DRILock;
+    void *p;
+
+    dri2info.version = 1;
+    dri2info.fd = ms->fd;
+    dri2info.driverSareaSize = sizeof(struct __DRILock);
+    dri2info.driverName = "i915"; /* FIXME */
+    dri2info.getPixmapHandle = driGetPixmapHandle;
+    dri2info.beginClipNotify = driBeginClipNotify;
+    dri2info.endClipNotify   = driEndClipNotify;
+
+    p = DRI2ScreenInit(pScreen, &dri2info);
+    if (!p) 
+	return;
+
+    DRILock = p;
+    DRILock->block_header =
+	DRI2_SAREA_BLOCK_HEADER(DRI2_SAREA_BLOCK_LOCK, sizeof *DRILock);
+    ms->lock = &DRILock->lock;
+    ms->context = 1;
+    DRILock->next_id = 2;
+    driLock(pScreen);
+
+    DRI2Connect(pScreen, &ms->fd, &driverName, &sarea_handle);
+}
+
+void
+driCloseScreen(ScreenPtr pScreen)
+{
+    driUnlock(pScreen);
+    DRI2CloseScreen(pScreen);
+}
diff --git a/hw/xfree86/drivers/modesetting/driver.c b/hw/xfree86/drivers/modesetting/driver.c
index 8f1c905..6bf6388 100644
--- a/hw/xfree86/drivers/modesetting/driver.c
+++ b/hw/xfree86/drivers/modesetting/driver.c
@@ -132,6 +132,16 @@ static const OptionInfoRec Options[] = {
     {-1, NULL, OPTV_NONE, {0}, FALSE}
 };
 
+static const char *exaSymbols[] = {
+    "exaGetVersion",
+    "exaDriverInit",
+    "exaDriverFini",
+    "exaOffscreenAlloc",
+    "exaOffscreenFree",
+    "exaWaitSync",
+    NULL
+};
+
 static const char *fbSymbols[] = {
     "fbPictureInit",
     "fbScreenInit",
@@ -190,7 +200,7 @@ Setup(pointer module, pointer opts, int *errmaj, int *errmin)
 	 * Tell the loader about symbols from other modules that this module
 	 * might refer to.
 	 */
-	LoaderRefSymLists(fbSymbols, shadowSymbols, ddcSymbols, NULL);
+	LoaderRefSymLists(exaSymbols, fbSymbols, shadowSymbols, ddcSymbols, NULL);
 
 	/*
 	 * The return value must be non-NULL on success even though there
@@ -417,6 +427,8 @@ MapMem(ScrnInfoPtr pScrn)
     drmBOMap(ms->fd,
 	     &ms->bo, DRM_BO_FLAG_READ | DRM_BO_FLAG_WRITE, 0, &ms->virtual);
 
+    ms->virtual = ms->bo.virtual;
+
     return TRUE;
 }
 
@@ -438,7 +450,7 @@ LoadPalette(ScrnInfoPtr pScrn, int numColors, int *indices,
 }
 
 static Bool
-crtc_resize(ScrnInfoPtr pScrn, int width, int height)
+CreateFrontBuffer(ScrnInfoPtr pScrn)
 {
     modesettingPtr ms = modesettingPTR(pScrn);
     ScreenPtr pScreen = pScrn->pScreen;
@@ -446,37 +458,14 @@ crtc_resize(ScrnInfoPtr pScrn, int width, int height)
     Bool fbAccessDisabled;
     CARD8 *fbstart;
 
-    if (width == pScrn->virtualX && height == pScrn->virtualY)
-	return TRUE;
-
-    ErrorF("RESIZING TO %dx%d\n", width, height);
-
-    pScrn->virtualX = width;
-    pScrn->virtualY = height;
-    pScrn->displayWidth = (pScrn->virtualX + 63) & ~63;
-
-    if (ms->shadowMem) {
-	xfree(ms->shadowMem);
-	ms->shadowMem = NULL;
-    }
-
-    UnmapMem(pScrn);
-
-    /* move old buffer out of the way */
-    drmBOSetStatus(ms->fd, &ms->bo, DRM_BO_FLAG_READ | DRM_BO_FLAG_MEM_LOCAL,
-		   DRM_BO_MASK_MEM | DRM_BO_FLAG_NO_EVICT,
-		   DRM_BO_HINT_DONT_FENCE, 0, 0);
-
-    /* unreference it */
-    drmBOUnreference(ms->fd, &ms->bo);
-
     drmBOCreate(ms->fd,
 		pScrn->virtualY * pScrn->displayWidth *
 		pScrn->bitsPerPixel / 8, 0, NULL,
 		DRM_BO_FLAG_READ | DRM_BO_FLAG_WRITE | DRM_BO_FLAG_SHAREABLE
+		| DRM_BO_FLAG_CACHED_MAPPED
 		| DRM_BO_FLAG_NO_EVICT | DRM_BO_FLAG_MAPPABLE |
-		DRM_BO_FLAG_MEM_VRAM | DRM_BO_FLAG_MEM_TT,
-		DRM_BO_HINT_DONT_FENCE, &ms->bo);
+		/*DRM_BO_FLAG_MEM_VRAM |*/ DRM_BO_FLAG_MEM_TT,
+		0, &ms->bo);
 
     MapMem(pScrn);
 
@@ -498,7 +487,7 @@ crtc_resize(ScrnInfoPtr pScrn, int width, int height)
 	}
 	fbstart = ms->shadowMem;
     } else {
-	fbstart = ms->virtual;
+	fbstart = ms->bo.virtual;
     }
 
     /*
@@ -526,9 +515,49 @@ crtc_resize(ScrnInfoPtr pScrn, int width, int height)
     pScrn->frameY0 = 0;
     AdjustFrame(pScrn->scrnIndex, pScrn->frameX0, pScrn->frameY0, 0);
 
+    UnmapMem(pScrn);
+
+    ms->front = TRUE;
+
     return TRUE;
 }
 
+static Bool
+crtc_resize(ScrnInfoPtr pScrn, int width, int height)
+{
+    modesettingPtr ms = modesettingPTR(pScrn);
+    ScreenPtr pScreen = pScrn->pScreen;
+    PixmapPtr rootPixmap = pScreen->GetScreenPixmap(pScreen);
+    Bool fbAccessDisabled;
+    CARD8 *fbstart;
+
+    if (width == pScrn->virtualX && height == pScrn->virtualY)
+	return TRUE;
+
+    ErrorF("RESIZING TO %dx%d\n", width, height);
+
+    pScrn->virtualX = width;
+    pScrn->virtualY = height;
+    pScrn->displayWidth = (pScrn->virtualX + 63) & ~63;
+
+    if (ms->shadowMem) {
+	xfree(ms->shadowMem);
+	ms->shadowMem = NULL;
+    }
+
+    drmModeRmFB(ms->fd, ms->fb_id);
+
+    /* move old buffer out of the way */
+    drmBOSetStatus(ms->fd, &ms->bo, 0, 0, 0, 0, 0);
+
+    /* unreference it */
+    drmBOUnreference(ms->fd, &ms->bo);
+    ms->front = FALSE;
+
+    /* now create new frontbuffer */
+    return CreateFrontBuffer(pScrn);
+}
+
 static const xf86CrtcConfigFuncsRec crtc_config_funcs = {
     crtc_resize
 };
@@ -713,6 +742,12 @@ PreInit(ScrnInfoPtr pScrn, int flags)
 
     xf86LoaderReqSymLists(fbSymbols, NULL);
 
+    xf86LoadSubModule(pScrn, "exa");
+
+#ifdef DRI2
+    xf86LoadSubModule(pScrn, "dri2");
+#endif
+
     return TRUE;
 }
 
@@ -744,7 +779,7 @@ WindowLinear(ScreenPtr pScreen, CARD32 row, CARD32 offset, int mode,
 
     *size = pScrn->displayWidth * pScrn->bitsPerPixel / 8;
 
-    return ((CARD8 *) ms->virtual + row * (*size) + offset);
+    return ((CARD8 *) ms->bo.virtual + row * (*size) + offset);
 }
 
 static Bool
@@ -752,15 +787,23 @@ CreateScreenResources(ScreenPtr pScreen)
 {
     ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
     modesettingPtr ms = modesettingPTR(pScrn);
+    PixmapPtr rootPixmap = pScreen->GetScreenPixmap(pScreen);
     Bool ret;
 
     pScreen->CreateScreenResources = ms->createScreenResources;
     ret = pScreen->CreateScreenResources(pScreen);
     pScreen->CreateScreenResources = CreateScreenResources;
 
-    shadowAdd(pScreen, pScreen->GetScreenPixmap(pScreen),
+    if (ms->shadowFB)
+    	shadowAdd(pScreen, rootPixmap,
 	      ms->update, WindowLinear, 0, 0);
 
+    if (!pScreen->ModifyPixmapHeader(pScreen->GetScreenPixmap(pScreen),
+                                     -1, -1, -1, -1, -1,
+                                     ms->shadowFB ? (pointer)ms->shadowMem : (pointer)ms->bo.virtual))
+	FatalError("Couldn't adjust screen pixmap\n");
+
+
     return ret;
 }
 
@@ -775,6 +818,30 @@ ScreenInit(int scrnIndex, ScreenPtr pScreen, int argc, char **argv)
     MessageType from;
     CARD8 *fbstart;
 
+    /* deal with server regeneration */
+    if (ms->fd < 0) {
+    	char *BusID;
+
+    	BusID = xalloc(64);
+    	sprintf(BusID, "PCI:%d:%d:%d",
+#if XSERVER_LIBPCIACCESS
+	    ((ms->PciInfo->domain << 8) | ms->PciInfo->bus),
+	    ms->PciInfo->dev, ms->PciInfo->func
+#else
+	    ((pciConfigPtr) ms->PciInfo->thisCard)->busnum,
+	    ((pciConfigPtr) ms->PciInfo->thisCard)->devnum,
+	    ((pciConfigPtr) ms->PciInfo->thisCard)->funcnum
+#endif
+	);
+
+    	ms->fd = drmOpen(NULL, BusID);
+
+    	if (ms->fd < 0)
+	    return FALSE;
+    }
+
+    pScrn->pScreen = pScreen;
+
     pScrn->displayWidth = (pScrn->virtualX + 63) & ~63;
 
     miClearVisualTypes();
@@ -787,9 +854,6 @@ ScreenInit(int scrnIndex, ScreenPtr pScreen, int argc, char **argv)
     if (!miSetPixmapDepths())
 	return FALSE;
 
-    if (!MapMem(pScrn))
-	return FALSE;
-
     pScrn->memPhysBase = 0;
     pScrn->fbOffset = 0;
 
@@ -797,9 +861,10 @@ ScreenInit(int scrnIndex, ScreenPtr pScreen, int argc, char **argv)
 		pScrn->virtualY * pScrn->displayWidth *
 		pScrn->bitsPerPixel / 8, 0, NULL,
 		DRM_BO_FLAG_READ | DRM_BO_FLAG_WRITE | DRM_BO_FLAG_SHAREABLE
+		| DRM_BO_FLAG_CACHED_MAPPED
 		| DRM_BO_FLAG_NO_EVICT | DRM_BO_FLAG_MAPPABLE |
-		DRM_BO_FLAG_MEM_VRAM | DRM_BO_FLAG_MEM_TT,
-		DRM_BO_HINT_DONT_FENCE, &ms->bo);
+		/*DRM_BO_FLAG_MEM_VRAM |*/ DRM_BO_FLAG_MEM_TT,
+		0, &ms->bo);
 
     MapMem(pScrn);
 
@@ -821,7 +886,7 @@ ScreenInit(int scrnIndex, ScreenPtr pScreen, int argc, char **argv)
 	}
 	fbstart = ms->shadowMem;
     } else {
-	fbstart = ms->virtual;
+	fbstart = ms->bo.virtual;
     }
 
     if (!fbScreenInit(pScreen, fbstart,
@@ -853,18 +918,18 @@ ScreenInit(int scrnIndex, ScreenPtr pScreen, int argc, char **argv)
 		       "Shadow framebuffer initialization failed.\n");
 	    return FALSE;
 	}
-
-	ms->createScreenResources = pScreen->CreateScreenResources;
-	pScreen->CreateScreenResources = CreateScreenResources;
     }
 
+    ms->createScreenResources = pScreen->CreateScreenResources;
+    pScreen->CreateScreenResources = CreateScreenResources;
+
     xf86SetBlackWhitePixels(pScreen);
 
 #if 0
     glucoseScreenInit(pScreen, 0);
 #endif
-#if 0
-    ms->pExa = ExaInit(pScreen);
+#if 1
+    ms->pExa = ExaInit(pScrn);
 #endif
 
     miInitializeBackingStore(pScreen);
@@ -872,8 +937,9 @@ ScreenInit(int scrnIndex, ScreenPtr pScreen, int argc, char **argv)
     xf86SetSilkenMouse(pScreen);
     miDCInitialize(pScreen, xf86GetPointerScreenFuncs());
 
-    /* Need to extend HWcursor support in kernel to handle mask interleave ?? */
-    xf86_cursors_init (pScreen, 64, 64,
+    /* Need to extend HWcursor support to handle mask interleave */
+    if (!ms->SWCursor)
+	xf86_cursors_init (pScreen, 64, 64,
 			       HARDWARE_CURSOR_SOURCE_MASK_INTERLEAVE_64 |
 			       HARDWARE_CURSOR_ARGB);
 
@@ -908,6 +974,14 @@ ScreenInit(int scrnIndex, ScreenPtr pScreen, int argc, char **argv)
     if (serverGeneration == 1)
 	xf86ShowUnusedOptions(pScrn->scrnIndex, pScrn->options);
 
+#ifdef DRI2
+    driScreenInit(pScreen);
+#endif
+
+    UnmapMem(pScrn);
+
+    ms->front = TRUE;
+
     return EnterVT(scrnIndex, 0);
 }
 
@@ -944,6 +1018,8 @@ LeaveVT(int scrnIndex, int flags)
     for (o = 0; o < config->num_crtc; o++) {
 	xf86CrtcPtr crtc = config->crtc[o];
 
+    	cursor_destroy(crtc);
+
 	if (crtc->rotatedPixmap || crtc->rotatedData) {
 	    crtc->funcs->shadow_destroy(crtc, crtc->rotatedPixmap,
 					crtc->rotatedData);
@@ -952,11 +1028,25 @@ LeaveVT(int scrnIndex, int flags)
 	}
     }
 
-    xf86_hide_cursors(pScrn);
+    drmModeRmFB(ms->fd, ms->fb_id);
 
-    drmMMLock(ms->fd, DRM_BO_MEM_VRAM, 1, 0);
+    /* move old buffer out of the way */
+    drmBOSetStatus(ms->fd, &ms->bo, 0, 0, 0, 0, 0);
+
+    drmBOUnreference(ms->fd, &ms->bo);
+    ms->front = FALSE;
 
     RestoreHWState(pScrn);
+
+#if 0
+    drmMMLock(ms->fd, DRM_BO_MEM_VRAM, 1, 0);
+    drmMMLock(ms->fd, DRM_BO_MEM_TT, 1, 0);
+#endif
+#ifdef DRI2
+    driLock(pScrn->pScreen);
+#endif
+
+    pScrn->vtSema = FALSE;
 }
 
 /*
@@ -968,6 +1058,17 @@ EnterVT(int scrnIndex, int flags)
     ScrnInfoPtr pScrn = xf86Screens[scrnIndex];
     modesettingPtr ms = modesettingPTR(pScrn);
 
+#if 0
+    if (pScrn->vtSema) {
+	drmMMUnlock(ms->fd, DRM_BO_MEM_VRAM, 1);
+	drmMMUnlock(ms->fd, DRM_BO_MEM_TT, 1);
+    }
+#endif
+
+#ifdef DRI2
+    driUnlock(pScrn->pScreen);
+#endif
+
     /*
      * Only save state once per server generation since that's what most
      * drivers do.  Could change this to save state at each VT enter.
@@ -977,7 +1078,8 @@ EnterVT(int scrnIndex, int flags)
 	SaveHWState(pScrn);
     }
 
-    drmMMUnlock(ms->fd, DRM_BO_MEM_VRAM, 1);
+    if (!ms->front)
+	CreateFrontBuffer(pScrn);
 
     if (!xf86SetDesiredModes(pScrn))
 	return FALSE;
@@ -1001,15 +1103,19 @@ CloseScreen(int scrnIndex, ScreenPtr pScreen)
     ScrnInfoPtr pScrn = xf86Screens[scrnIndex];
     modesettingPtr ms = modesettingPTR(pScrn);
 
-    if (pScrn->vtSema == TRUE) {
-	LeaveVT(scrnIndex, 0);
-	drmMMUnlock(ms->fd, DRM_BO_MEM_VRAM, 1);
+    if (pScrn->vtSema) {
+    	LeaveVT(scrnIndex, 0);
+#if 0
+    	drmMMUnlock(ms->fd, DRM_BO_MEM_VRAM, 1);
+    	drmMMUnlock(ms->fd, DRM_BO_MEM_TT, 1);
+#endif
     }
 
-    UnmapMem(pScrn);
+#ifdef DRI2
+    driCloseScreen(pScreen);
+#endif
 
-    if (ms->shadowFB)
-	pScreen->CreateScreenResources = ms->createScreenResources;
+    pScreen->CreateScreenResources = ms->createScreenResources;
 
     if (ms->shadowMem) {
 	xfree(ms->shadowMem);
@@ -1019,14 +1125,8 @@ CloseScreen(int scrnIndex, ScreenPtr pScreen)
     if (ms->pExa)
 	ExaClose(pScrn);
 
-    /* move old buffer out of the way */
-    drmBOSetStatus(ms->fd, &ms->bo, DRM_BO_FLAG_READ | DRM_BO_FLAG_MEM_LOCAL,
-		   DRM_BO_MASK_MEM | DRM_BO_FLAG_NO_EVICT,
-		   DRM_BO_HINT_DONT_FENCE, 0, 0);
-
-    drmBOUnreference(ms->fd, &ms->bo);
-
     drmClose(ms->fd);
+    ms->fd = -1;
 
     pScrn->vtSema = FALSE;
     pScreen->CloseScreen = ms->CloseScreen;
diff --git a/hw/xfree86/drivers/modesetting/driver.h b/hw/xfree86/drivers/modesetting/driver.h
index c9cb764..7ac6466 100644
--- a/hw/xfree86/drivers/modesetting/driver.h
+++ b/hw/xfree86/drivers/modesetting/driver.h
@@ -31,6 +31,7 @@
 #include <drm.h>
 #include <xf86drm.h>
 #include <xf86drmMode.h>
+#include <xf86mm.h>
 #include "shadow.h"
 #include "exa.h"
 
@@ -50,6 +51,7 @@ typedef struct _modesettingRec
     unsigned int fb_id;
     void *virtual;
     drmBO bo;
+    Bool front;
 
     EntPtr entityPrivate;
 
@@ -68,9 +70,6 @@ typedef struct _modesettingRec
     Bool SWCursor;
     CloseScreenProcPtr CloseScreen;
 
-    Bool directRenderingDisabled;      /* DRI disabled in PreInit. */
-    Bool directRenderingEnabled;       /* DRI enabled this generation. */
-
     /* Broken-out options. */
     OptionInfoPtr Options;
 
@@ -85,6 +84,11 @@ typedef struct _modesettingRec
     /* exa */
     ExaDriverPtr pExa;
     drmBO exa_bo;
+
+    /* dri2 */
+    drm_context_t context;
+    drm_hw_lock_t *lock;
+    int lock_held;
 } modesettingRec, *modesettingPtr;
 
 #define modesettingPTR(p) ((modesettingPtr)((p)->driverPrivate))
diff --git a/hw/xfree86/drivers/modesetting/exa.c b/hw/xfree86/drivers/modesetting/exa.c
index 70968f0..9327cbc 100644
--- a/hw/xfree86/drivers/modesetting/exa.c
+++ b/hw/xfree86/drivers/modesetting/exa.c
@@ -36,6 +36,14 @@
 
 #include "driver.h"
 
+struct PixmapPriv {
+    drmBO bo;
+    #if 0
+    dri_fence *fence;
+    #endif
+    int flags;
+};
+
 static void
 ExaWaitMarker(ScreenPtr pScreen, int marker)
 {
@@ -44,10 +52,6 @@ ExaWaitMarker(ScreenPtr pScreen, int marker)
 static int
 ExaMarkSync(ScreenPtr pScreen)
 {
-    /*
-     * See ExaWaitMarker.
-     */
-
     return 1;
 }
 
@@ -56,6 +60,30 @@ ExaPrepareAccess(PixmapPtr pPix, int index)
 {
     ScreenPtr pScreen = pPix->drawable.pScreen;
     ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
+    modesettingPtr ms = modesettingPTR(pScrn);
+    PixmapPtr rootPixmap = pScreen->GetScreenPixmap(pScreen);
+    struct PixmapPriv *priv;
+    int ret;
+
+    priv = exaGetPixmapDriverPrivate(pPix);
+
+    if (!priv)
+	return FALSE;
+
+    if (priv->bo.handle) {
+    	void *virtual;
+
+    	ret = drmBOMap(ms->fd,
+	     &priv->bo, DRM_BO_FLAG_READ | DRM_BO_FLAG_WRITE, 0, &virtual);
+	if (ret) {
+    	    driUnlock(pScreen);
+	    FatalError("Failed to map pixmap: %s\n", strerror(-ret));
+	    return;
+	}
+
+	pPix->devPrivate.ptr = priv->bo.virtual;
+    }
+
 
     return TRUE;
 }
@@ -65,6 +93,26 @@ ExaFinishAccess(PixmapPtr pPix, int index)
 {
     ScreenPtr pScreen = pPix->drawable.pScreen;
     ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
+    modesettingPtr ms = modesettingPTR(pScrn);
+    PixmapPtr rootPixmap = pScreen->GetScreenPixmap(pScreen);
+    struct PixmapPriv *priv;
+    int ret;
+
+    priv = exaGetPixmapDriverPrivate(pPix);
+
+    if (!priv)
+	return;
+
+    if (priv->bo.handle) {
+	ret = drmBOUnmap(ms->fd, &priv->bo);
+	if (ret) {
+	    driUnlock(pScreen);
+	    FatalError("Failed to unmap pixmap: %s\n", strerror(-ret));
+	    return;
+	}
+
+	pPix->devPrivate.ptr = NULL;
+    }
 }
 
 static void
@@ -84,6 +132,8 @@ ExaPrepareSolid(PixmapPtr pPixmap, int alu, Pixel planeMask, Pixel fg)
 {
     ScrnInfoPtr pScrn = xf86Screens[pPixmap->drawable.pScreen->myNum];
 
+    ErrorF("SOLID\n");
+
     if (!EXA_PM_IS_SOLID(&pPixmap->drawable, planeMask))
 	return FALSE;
 
@@ -91,7 +141,7 @@ ExaPrepareSolid(PixmapPtr pPixmap, int alu, Pixel planeMask, Pixel fg)
     if (pPixmap->drawable.depth == 4)
 	return FALSE;
 
-    return TRUE;
+    return FALSE;
 }
 
 static void
@@ -106,11 +156,13 @@ ExaPrepareCopy(PixmapPtr pSrcPixmap, PixmapPtr pDstPixmap, int xdir,
 {
     ScrnInfoPtr pScrn = xf86Screens[pDstPixmap->drawable.pScreen->myNum];
 
+    ErrorF("COPY\n");
+
     /* can't do depth 4 */
     if (pSrcPixmap->drawable.depth == 4 || pDstPixmap->drawable.depth == 4)
 	return FALSE;
 
-    return TRUE;
+    return FALSE;
 }
 
 static void
@@ -138,6 +190,8 @@ ExaUploadToScreen(PixmapPtr pDst, int x, int y, int w, int h, char *src,
     ScreenPtr pScreen = pDst->drawable.pScreen;
     ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
 
+    ErrorF("UPLOAD\n");
+
     return FALSE;
 }
 
@@ -158,18 +212,118 @@ ExaCheckComposite(int op,
     int w = pDraw->width;
     int h = pDraw->height;
 
-    return TRUE;
+    return FALSE;
 }
 
-static Bool
-ExaPixmapIsOffscreen(PixmapPtr p)
+static void *
+ExaCreatePixmap(ScreenPtr pScreen, int size, int align)
 {
-    ScreenPtr pScreen = p->drawable.pScreen;
     ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
+    modesettingPtr ms = modesettingPTR(pScrn);
+    struct PixmapPriv *priv;
+    void *virtual;
+
+    priv = xcalloc(1, sizeof(struct PixmapPriv));
+    if (!priv)
+        return NULL;
+
+    if (size == 0)
+	return priv;
+
+    drmBOCreate(ms->fd, size, 4096, NULL,
+		DRM_BO_FLAG_READ | DRM_BO_FLAG_WRITE | DRM_BO_FLAG_SHAREABLE
+		| DRM_BO_FLAG_MEM_TT | DRM_BO_FLAG_MAPPABLE |
+		DRM_BO_FLAG_CACHED_MAPPED,
+		0, &priv->bo);
+
+    return priv;
+}
+
+static void 
+ExaDestroyPixmap(ScreenPtr pScreen, void *dPriv)
+{
+    struct PixmapPriv *priv = (struct PixmapPriv *)dPriv;
+    ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
+    modesettingPtr ms = modesettingPTR(pScrn);
+
+    if (!priv)
+    	return;
+
+    if (priv->bo.handle)
+	drmBOUnreference(ms->fd, &priv->bo);
+
+    xfree(priv);
+}
+
+static Bool 
+ExaPixmapIsOffscreen(PixmapPtr pPixmap)
+{
+    struct PixmapPriv *priv;
+    ScreenPtr pScreen = pPixmap->drawable.pScreen;
+    PixmapPtr rootPixmap = pScreen->GetScreenPixmap(pScreen);
+
+    priv = exaGetPixmapDriverPrivate(pPixmap);
+
+    if (!priv)
+       return FALSE;
+
+    if (priv->bo.handle)
+       return TRUE;
 
     return FALSE;
 }
 
+/* FIXME !! */
+unsigned int
+driGetPixmapHandle(PixmapPtr pPixmap, unsigned int *flags)
+{
+    ScreenPtr pScreen = pPixmap->drawable.pScreen;
+    PixmapPtr rootPixmap = pScreen->GetScreenPixmap(pScreen);
+    ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
+    modesettingPtr ms = modesettingPTR(pScrn);
+    struct PixmapPriv *priv;
+
+    *flags = 0;
+
+    if (rootPixmap == pPixmap)
+        return ms->bo.handle;
+
+    if (!ms->pExa)
+    	return 0;
+
+    priv = exaGetPixmapDriverPrivate(pPixmap);
+
+    if (!priv)
+       return 0;
+
+    if (priv->bo.handle)
+        return priv->bo.handle;
+
+    return 0;
+}
+
+static Bool 
+ExaModifyPixmapHeader(PixmapPtr pPixmap, int width, int height,
+		      int depth, int bitsPerPixel, int devKind,
+		      pointer pPixData)
+{
+    ScreenPtr	pScreen = pPixmap->drawable.pScreen;
+    ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
+    struct PixmapPriv *priv = exaGetPixmapDriverPrivate(pPixmap);
+    modesettingPtr ms = modesettingPTR(pScrn);
+    PixmapPtr rootPixmap = pScreen->GetScreenPixmap(pScreen);
+
+    if (rootPixmap == pPixmap) {
+	miModifyPixmapHeader(pPixmap, width, height, depth,
+			     bitsPerPixel, devKind, NULL);
+
+	return TRUE;
+    }
+
+    return FALSE;
+}
+
+
 void
 ExaClose(ScrnInfoPtr pScrn)
 {
@@ -177,7 +331,9 @@ ExaClose(ScrnInfoPtr pScrn)
 
     exaDriverFini(pScrn->pScreen);
 
+#if 0
     drmBOUnreference(ms->fd, &ms->exa_bo);
+#endif
 }
 
 ExaDriverPtr
@@ -191,20 +347,22 @@ ExaInit(ScrnInfoPtr pScrn)
 	goto out_err;
     }
 
+#if 0
     /* Create a 256KB offscreen area */
     drmBOCreate(ms->fd, 256 * 1024, 0, NULL,
 		DRM_BO_FLAG_READ | DRM_BO_FLAG_WRITE | DRM_BO_FLAG_MEM_TT,
 		DRM_BO_HINT_DONT_FENCE, &ms->exa_bo);
+#endif
 
     memset(pExa, 0, sizeof(*pExa));
     pExa->exa_major = 2;
-    pExa->exa_minor = 2;
-    pExa->memoryBase = ms->exa_bo.virtual;
+    pExa->exa_minor = 4;
+    pExa->memoryBase = 0; /* ms->exa_bo.virtual; */
+    pExa->memorySize = 0; /* ms->exa_bo.size; */
     pExa->offScreenBase = 0;
-    pExa->memorySize = ms->exa_bo.size;
     pExa->pixmapOffsetAlign = 8;
     pExa->pixmapPitchAlign = 32 * 4;
-    pExa->flags = EXA_OFFSCREEN_PIXMAPS;
+    pExa->flags = EXA_OFFSCREEN_PIXMAPS | EXA_HANDLES_PIXMAPS;
     pExa->maxX = 8191;		       /* FIXME */
     pExa->maxY = 8191;		       /* FIXME */
     pExa->WaitMarker = ExaWaitMarker;
@@ -223,6 +381,9 @@ ExaInit(ScrnInfoPtr pScrn)
     pExa->PrepareAccess = ExaPrepareAccess;
     pExa->FinishAccess = ExaFinishAccess;
     pExa->UploadToScreen = ExaUploadToScreen;
+    pExa->CreatePixmap = ExaCreatePixmap;
+    pExa->DestroyPixmap = ExaDestroyPixmap;
+    pExa->ModifyPixmapHeader = ExaModifyPixmapHeader;
 
     if (!exaDriverInit(pScrn->pScreen, pExa)) {
 	goto out_err;
diff --git a/hw/xfree86/drivers/modesetting/output.c b/hw/xfree86/drivers/modesetting/output.c
index 7767ef2..484acb2 100644
--- a/hw/xfree86/drivers/modesetting/output.c
+++ b/hw/xfree86/drivers/modesetting/output.c
@@ -51,6 +51,23 @@
 
 #include "driver.h"
 
+static char *connector_enum_list[] = {
+    "Unknown",
+    "VGA",
+    "DVI-I",
+    "DVI-D",
+    "DVI-A",
+    "Composite",
+    "SVIDEO",
+    "LVDS",
+    "Component",
+    "9-pin DIN",
+    "DisplayPort",
+    "HDMI Type A",
+    "HDMI Type B",
+};
+
+
 static void
 dpms(xf86OutputPtr output, int mode)
 {
@@ -145,6 +162,7 @@ get_modes(xf86OutputPtr output)
 	    mode->VRefresh = xf86ModeVRefresh(mode);
 	    mode->Private = (void *)drm_mode;
 	    xf86SetModeDefaultName(mode);
+	    ErrorF("MODE %s\n",mode->name);
 	    modes = xf86ModesAdd(modes, mode);
 	    xf86PrintModeline(0, mode);
 	}
@@ -237,7 +255,6 @@ output_init(ScrnInfoPtr pScrn)
 	if (!drm_connector)
 	    goto out;
 
-#if 0
 	for (p = 0; p < drm_connector->count_props; p++) {
 	    drmModePropertyPtr prop;
 
@@ -249,41 +266,16 @@ output_init(ScrnInfoPtr pScrn)
 
 		for (v = 0; v < prop->count_values; v++)
 		    ErrorF("%s %lld\n", prop->name, prop->values[v]);
-
-		for (v = 0; v < prop->count_enums; v++) {
-		    ErrorF("%s %s\n", prop->name, prop->enums[v].name);
-		    if (drm_connector->prop_values[p] == prop->enums[v].value) {
-			if (!strncmp("Connector Type", prop->name, 14)) {
-			    ErrorF("WE'VE GOT %s\n", prop->enums[v].name);
-			    name = xalloc(strlen(prop->enums[v].name));
-			    strncpy(name, prop->enums[v].name, strlen(name));
-			}
-		    }
-		    if (name)
-			break;
-		}
-		if (name)
-		    break;
 	    }
 	}
 
-	if (!name)
-	    continue;
-#endif
-
-
-#if 0
-	free(name);
-#endif
-
-	
-	name = "Unknown";
+	name = connector_enum_list[drm_connector->connector_type];
 
 	output = xf86OutputCreate(pScrn, &output_funcs, name);
 	if (!output)
 	    continue;
 
-	drm_encoder = drmModeGetEncoder(ms->fd, drm_connector->encoder);
+	drm_encoder = drmModeGetEncoder(ms->fd, drm_connector->encoders[0]);
 	if (drm_encoder) {
 	output->possible_crtcs = drm_encoder->crtcs;
 	output->possible_clones = drm_encoder->clones;
commit 6a1910a0e562e36e0836e948b287ec37c90df02d
Author: Zack Rusin <zack at tungstengraphics.com>
Date:   Mon Jun 16 00:31:53 2008 -0400

    Adding some readme.
commit cba8b25a7e2608cd093283f86f08fba50a6a62f7
Author: Alan Hourihane <alanh at tungstengraphics.com>
Date:   Mon Jun 2 11:17:47 2008 +0100

    Bring inline with current modesetting-101 branch for connector/encoder changes

diff --git a/hw/xfree86/drivers/modesetting/crtc.c b/hw/xfree86/drivers/modesetting/crtc.c
index bf726b5..14ee53e 100644
--- a/hw/xfree86/drivers/modesetting/crtc.c
+++ b/hw/xfree86/drivers/modesetting/crtc.c
@@ -104,7 +104,7 @@ crtc_mode_set(xf86CrtcPtr crtc, DisplayModePtr mode,
     xf86CrtcConfigPtr config = XF86_CRTC_CONFIG_PTR(crtc->scrn);
     modesettingPtr ms = modesettingPTR(crtc->scrn);
     xf86OutputPtr output = config->output[config->compat_output];
-    drmModeOutputPtr drm_output = output->driver_private;
+    drmModeConnectorPtr drm_connector = output->driver_private;
     struct crtc_private *crtcp = crtc->driver_private;
     drmModeCrtcPtr drm_crtc = crtcp->drm_crtc;
     struct drm_mode_modeinfo drm_mode;
@@ -125,7 +125,7 @@ crtc_mode_set(xf86CrtcPtr crtc, DisplayModePtr mode,
     strncpy(drm_mode.name, mode->name, DRM_DISPLAY_MODE_LEN);
 
     drmModeSetCrtc(ms->fd, drm_crtc->crtc_id, ms->fb_id, x, y,
-		   &drm_output->output_id, 1, &drm_mode);
+		   &drm_connector->connector_id, 1, &drm_mode);
 }
 
 void
diff --git a/hw/xfree86/drivers/modesetting/output.c b/hw/xfree86/drivers/modesetting/output.c
index 4a67ccc..7767ef2 100644
--- a/hw/xfree86/drivers/modesetting/output.c
+++ b/hw/xfree86/drivers/modesetting/output.c
@@ -103,9 +103,9 @@ commit(xf86OutputPtr output)
 static xf86OutputStatus
 detect(xf86OutputPtr output)
 {
-    drmModeOutputPtr drm_output = output->driver_private;
+    drmModeConnectorPtr drm_connector = output->driver_private;
 
-    switch (drm_output->connection) {
+    switch (drm_connector->connection) {
     case DRM_MODE_CONNECTED:
 	return XF86OutputStatusConnected;
     case DRM_MODE_DISCONNECTED:
@@ -118,13 +118,13 @@ detect(xf86OutputPtr output)
 static DisplayModePtr
 get_modes(xf86OutputPtr output)
 {
-    drmModeOutputPtr drm_output = output->driver_private;
+    drmModeConnectorPtr drm_connector = output->driver_private;
     struct drm_mode_modeinfo *drm_mode = NULL;
     DisplayModePtr modes = NULL, mode = NULL;
     int i;
 
-    for (i = 0; i < drm_output->count_modes; i++) {
-	drm_mode = &drm_output->modes[i];
+    for (i = 0; i < drm_connector->count_modes; i++) {
+	drm_mode = &drm_connector->modes[i];
 	if (drm_mode) {
 	    mode = xcalloc(1, sizeof(DisplayModeRec));
 	    if (!mode)
@@ -156,7 +156,7 @@ get_modes(xf86OutputPtr output)
 static void
 destroy(xf86OutputPtr output)
 {
-    drmModeFreeOutput(output->driver_private);
+    drmModeFreeConnector(output->driver_private);
 }
 
 static void
@@ -220,10 +220,11 @@ output_init(ScrnInfoPtr pScrn)
     modesettingPtr ms = modesettingPTR(pScrn);
     xf86OutputPtr output;
     drmModeResPtr res;
-    drmModeOutputPtr drm_output = NULL;
+    drmModeConnectorPtr drm_connector = NULL;
+    drmModeEncoderPtr drm_encoder = NULL;
     drmModeCrtcPtr crtc;
     char *name;
-    int o, v, p;
+    int c, v, p;
 
     res = drmModeGetResources(ms->fd);
     if (res == 0) {
@@ -231,15 +232,16 @@ output_init(ScrnInfoPtr pScrn)
 	return;
     }
 
-    for (o = 0; o < res->count_outputs; o++) {
-	drm_output = drmModeGetOutput(ms->fd, res->outputs[o]);
-	if (!drm_output)
+    for (c = 0; c < res->count_connectors; c++) {
+	drm_connector = drmModeGetConnector(ms->fd, res->connectors[c]);
+	if (!drm_connector)
 	    goto out;
 
-	for (p = 0; p < drm_output->count_props; p++) {
+#if 0
+	for (p = 0; p < drm_connector->count_props; p++) {
 	    drmModePropertyPtr prop;
 
-	    prop = drmModeGetProperty(ms->fd, drm_output->props[p]);
+	    prop = drmModeGetProperty(ms->fd, drm_connector->props[p]);
 
 	    name = NULL;
 	    if (prop) {
@@ -250,7 +252,7 @@ output_init(ScrnInfoPtr pScrn)
 
 		for (v = 0; v < prop->count_enums; v++) {
 		    ErrorF("%s %s\n", prop->name, prop->enums[v].name);
-		    if (drm_output->prop_values[p] == prop->enums[v].value) {
+		    if (drm_connector->prop_values[p] == prop->enums[v].value) {
 			if (!strncmp("Connector Type", prop->name, 14)) {
 			    ErrorF("WE'VE GOT %s\n", prop->enums[v].name);
 			    name = xalloc(strlen(prop->enums[v].name));
@@ -267,16 +269,29 @@ output_init(ScrnInfoPtr pScrn)
 
 	if (!name)
 	    continue;
+#endif
+
+
+#if 0
+	free(name);
+#endif
+
+	
+	name = "Unknown";
 
 	output = xf86OutputCreate(pScrn, &output_funcs, name);
 	if (!output)
 	    continue;
 
-	free(name);
-
-	output->possible_crtcs = drm_output->crtcs;
-	output->possible_clones = drm_output->clones;
-	output->driver_private = drm_output;
+	drm_encoder = drmModeGetEncoder(ms->fd, drm_connector->encoder);
+	if (drm_encoder) {
+	output->possible_crtcs = drm_encoder->crtcs;
+	output->possible_clones = drm_encoder->clones;
+	} else {
+	output->possible_crtcs = 0;
+	output->possible_clones = 0;
+	}
+	output->driver_private = drm_connector;
 	output->subpixel_order = SubPixelHorizontalRGB;
 	output->interlaceAllowed = FALSE;
 	output->doubleScanAllowed = FALSE;
commit 000ead4503ddcfdf66ce9fffc572a3a741f4055a
Author: Alan Hourihane <alanh at tungstengraphics.com>
Date:   Wed May 28 19:59:38 2008 +0100

    Plug in hardware cursor support

diff --git a/hw/xfree86/drivers/modesetting/crtc.c b/hw/xfree86/drivers/modesetting/crtc.c
index 66b23f6..bf726b5 100644
--- a/hw/xfree86/drivers/modesetting/crtc.c
+++ b/hw/xfree86/drivers/modesetting/crtc.c
@@ -47,6 +47,13 @@
 #define DPMS_SERVER
 #include <X11/extensions/dpms.h>
 
+struct crtc_private {
+    drmModeCrtcPtr drm_crtc;
+
+    /* hwcursor */
+    drmBO cursor_bo;
+};
+
 static void
 crtc_dpms(xf86CrtcPtr crtc, int mode)
 {
@@ -98,7 +105,8 @@ crtc_mode_set(xf86CrtcPtr crtc, DisplayModePtr mode,
     modesettingPtr ms = modesettingPTR(crtc->scrn);
     xf86OutputPtr output = config->output[config->compat_output];
     drmModeOutputPtr drm_output = output->driver_private;
-    drmModeCrtcPtr drm_crtc = crtc->driver_private;
+    struct crtc_private *crtcp = crtc->driver_private;
+    drmModeCrtcPtr drm_crtc = crtcp->drm_crtc;
     struct drm_mode_modeinfo drm_mode;
 
     drm_mode.clock = mode->Clock;
@@ -157,13 +165,64 @@ crtc_shadow_destroy(xf86CrtcPtr crtc, PixmapPtr rotate_pixmap, void *data)
 static void
 crtc_destroy(xf86CrtcPtr crtc)
 {
-    drmModeFreeCrtc(crtc->driver_private);
+    modesettingPtr ms = modesettingPTR(crtc->scrn);
+    struct crtc_private *crtcp = crtc->driver_private;
+
+    drmBOUnreference(ms->fd, &crtcp->cursor_bo);
+    drmModeFreeCrtc(crtcp->drm_crtc);
+}
+
+static void
+crtc_load_cursor_argb (xf86CrtcPtr crtc, CARD32 *image)
+{
+    unsigned char *ptr;
+    modesettingPtr ms = modesettingPTR(crtc->scrn);
+    struct crtc_private *crtcp = crtc->driver_private;
+
+    drmBOMap(ms->fd, &crtcp->cursor_bo, DRM_BO_FLAG_WRITE, 0, (void **)&ptr);
+
+    memcpy (ptr, image, 64 * 64 * 4);
+
+    drmBOUnmap(ms->fd, &crtcp->cursor_bo);
+}
+
+static void
+crtc_set_cursor_position (xf86CrtcPtr crtc, int x, int y)
+{
+    modesettingPtr ms = modesettingPTR(crtc->scrn);
+    struct crtc_private *crtcp = crtc->driver_private;
+
+    drmModeMoveCursor(ms->fd, crtcp->drm_crtc->crtc_id, x, y);
+}
+
+static void
+crtc_show_cursor (xf86CrtcPtr crtc)
+{
+    modesettingPtr ms = modesettingPTR(crtc->scrn);
+    struct crtc_private *crtcp = crtc->driver_private;
+
+    drmModeSetCursor(ms->fd, crtcp->drm_crtc->crtc_id, crtcp->cursor_bo.handle, 64, 64);
+}
+
+static void
+crtc_hide_cursor (xf86CrtcPtr crtc)
+{
+    modesettingPtr ms = modesettingPTR(crtc->scrn);
+    struct crtc_private *crtcp = crtc->driver_private;
+
+    drmModeSetCursor(ms->fd, crtcp->drm_crtc->crtc_id, 0, 0, 0);
+}
+
+static void
+crtc_set_cursor_colors (xf86CrtcPtr crtc, int bg, int fg)
+{
+    ScrnInfoPtr		scrn = crtc->scrn;
 }
 
 static const xf86CrtcFuncsRec crtc_funcs = {
     .dpms = crtc_dpms,
-    .save = NULL,		       /* XXX */
-    .restore = NULL,		       /* XXX */
+    .save = NULL,
+    .restore = NULL,
     .lock = crtc_lock,
     .unlock = crtc_unlock,
     .mode_fixup = crtc_mode_fixup,
@@ -174,13 +233,13 @@ static const xf86CrtcFuncsRec crtc_funcs = {
     .shadow_create = crtc_shadow_create,
     .shadow_allocate = crtc_shadow_allocate,
     .shadow_destroy = crtc_shadow_destroy,
-//    .set_cursor_colors = crtc_set_cursor_colors,
-//    .set_cursor_position = crtc_set_cursor_position,
-//    .show_cursor = crtc_show_cursor,
-//    .hide_cursor = crtc_hide_cursor,
-//    .load_cursor_image = crtc_load_cursor_image, 
-//    .load_cursor_argb = crtc_load_cursor_argb,
-    .destroy = crtc_destroy,	       /* XXX */
+    .set_cursor_colors = crtc_set_cursor_colors,
+    .set_cursor_position = crtc_set_cursor_position,
+    .show_cursor = crtc_show_cursor,
+    .hide_cursor = crtc_hide_cursor,
+    .load_cursor_image = NULL,	/* lets convert to argb only */
+    .load_cursor_argb = crtc_load_cursor_argb,
+    .destroy = crtc_destroy,
 };
 
 void
@@ -190,6 +249,7 @@ crtc_init(ScrnInfoPtr pScrn)
     xf86CrtcPtr crtc;
     drmModeResPtr res;
     drmModeCrtcPtr drm_crtc = NULL;
+    struct crtc_private *crtcp;
     int c, k, p;
 
     res = drmModeGetResources(ms->fd);
@@ -207,7 +267,21 @@ crtc_init(ScrnInfoPtr pScrn)
 	if (crtc == NULL)
 	    goto out;
 
-	crtc->driver_private = drm_crtc;
+	crtcp = xalloc(sizeof(struct crtc_private));
+	if (!crtcp) {
+	    xf86CrtcDestroy(crtc);
+	    goto out;
+	}
+
+ 	crtcp->drm_crtc = drm_crtc;
+
+	crtc->driver_private = crtcp;
+    
+        drmBOCreate(ms->fd, 64 * 64 * 4, 0, NULL,
+		DRM_BO_FLAG_READ | DRM_BO_FLAG_WRITE 
+		| DRM_BO_FLAG_NO_EVICT | DRM_BO_FLAG_MAPPABLE |
+		DRM_BO_FLAG_MEM_VRAM | DRM_BO_FLAG_MEM_TT,
+		DRM_BO_HINT_DONT_FENCE, &crtcp->cursor_bo);
     }
 
   out:
diff --git a/hw/xfree86/drivers/modesetting/driver.c b/hw/xfree86/drivers/modesetting/driver.c
index de4b260..8f1c905 100644
--- a/hw/xfree86/drivers/modesetting/driver.c
+++ b/hw/xfree86/drivers/modesetting/driver.c
@@ -872,6 +872,11 @@ ScreenInit(int scrnIndex, ScreenPtr pScreen, int argc, char **argv)
     xf86SetSilkenMouse(pScreen);
     miDCInitialize(pScreen, xf86GetPointerScreenFuncs());
 
+    /* Need to extend HWcursor support in kernel to handle mask interleave ?? */
+    xf86_cursors_init (pScreen, 64, 64,
+			       HARDWARE_CURSOR_SOURCE_MASK_INTERLEAVE_64 |
+			       HARDWARE_CURSOR_ARGB);
+
     /* Must force it before EnterVT, so we are in control of VT and
      * later memory should be bound when allocating, e.g rotate_mem */
     pScrn->vtSema = TRUE;
commit f9f7a872bf3f8522213aabb291d9d54e56d48c4b
Author: Alan Hourihane <alanh at tungstengraphics.com>
Date:   Wed May 28 15:55:36 2008 +0100

    Run indent

diff --git a/hw/xfree86/drivers/modesetting/crtc.c b/hw/xfree86/drivers/modesetting/crtc.c
index f168126..66b23f6 100644
--- a/hw/xfree86/drivers/modesetting/crtc.c
+++ b/hw/xfree86/drivers/modesetting/crtc.c
@@ -50,22 +50,22 @@
 static void
 crtc_dpms(xf86CrtcPtr crtc, int mode)
 {
-   ScrnInfoPtr pScrn = crtc->scrn;
-
-   switch (mode) {
-   case DPMSModeOn:
-   case DPMSModeStandby:
-   case DPMSModeSuspend:
-      break;
-   case DPMSModeOff:
-      break;
-   }
+    ScrnInfoPtr pScrn = crtc->scrn;
+
+    switch (mode) {
+    case DPMSModeOn:
+    case DPMSModeStandby:
+    case DPMSModeSuspend:
+	break;
+    case DPMSModeOff:
+	break;
+    }
 }
 
 static Bool
 crtc_lock(xf86CrtcPtr crtc)
 {
-   return FALSE;
+    return FALSE;
 }
 
 static void
@@ -87,43 +87,43 @@ static Bool
 crtc_mode_fixup(xf86CrtcPtr crtc, DisplayModePtr mode,
 		DisplayModePtr adjusted_mode)
 {
-   return TRUE;
+    return TRUE;
 }
 
 static void
 crtc_mode_set(xf86CrtcPtr crtc, DisplayModePtr mode,
 	      DisplayModePtr adjusted_mode, int x, int y)
 {
-   xf86CrtcConfigPtr config = XF86_CRTC_CONFIG_PTR(crtc->scrn);
-   modesettingPtr ms = modesettingPTR(crtc->scrn);
-   xf86OutputPtr output = config->output[config->compat_output];
-   drmModeOutputPtr drm_output = output->driver_private;
-   drmModeCrtcPtr drm_crtc = crtc->driver_private;
-   struct drm_mode_modeinfo drm_mode;
-
-   drm_mode.clock = mode->Clock;
-   drm_mode.hdisplay = mode->HDisplay;
-   drm_mode.hsync_start = mode->HSyncStart;
-   drm_mode.hsync_end = mode->HSyncEnd;
-   drm_mode.htotal = mode->HTotal;
-   drm_mode.vdisplay = mode->VDisplay;
-   drm_mode.vsync_start = mode->VSyncStart;
-   drm_mode.vsync_end = mode->VSyncEnd;
-   drm_mode.vtotal = mode->VTotal;
-   drm_mode.flags = mode->Flags;
-   drm_mode.hskew = mode->HSkew;
-   drm_mode.vscan = mode->VScan;
-   drm_mode.vrefresh = mode->VRefresh;
-   strncpy(drm_mode.name, mode->name, DRM_DISPLAY_MODE_LEN);
-
-   drmModeSetCrtc(ms->fd, drm_crtc->crtc_id, ms->fb_id, x, y,
-		     &drm_output->output_id, 1, &drm_mode);
+    xf86CrtcConfigPtr config = XF86_CRTC_CONFIG_PTR(crtc->scrn);
+    modesettingPtr ms = modesettingPTR(crtc->scrn);
+    xf86OutputPtr output = config->output[config->compat_output];
+    drmModeOutputPtr drm_output = output->driver_private;
+    drmModeCrtcPtr drm_crtc = crtc->driver_private;
+    struct drm_mode_modeinfo drm_mode;
+
+    drm_mode.clock = mode->Clock;
+    drm_mode.hdisplay = mode->HDisplay;
+    drm_mode.hsync_start = mode->HSyncStart;
+    drm_mode.hsync_end = mode->HSyncEnd;
+    drm_mode.htotal = mode->HTotal;
+    drm_mode.vdisplay = mode->VDisplay;
+    drm_mode.vsync_start = mode->VSyncStart;
+    drm_mode.vsync_end = mode->VSyncEnd;
+    drm_mode.vtotal = mode->VTotal;
+    drm_mode.flags = mode->Flags;
+    drm_mode.hskew = mode->HSkew;
+    drm_mode.vscan = mode->VScan;
+    drm_mode.vrefresh = mode->VRefresh;
+    strncpy(drm_mode.name, mode->name, DRM_DISPLAY_MODE_LEN);
+
+    drmModeSetCrtc(ms->fd, drm_crtc->crtc_id, ms->fb_id, x, y,
+		   &drm_output->output_id, 1, &drm_mode);
 }
 
 void
 crtc_load_lut(xf86CrtcPtr crtc)
 {
-   ScrnInfoPtr pScrn = crtc->scrn;
+    ScrnInfoPtr pScrn = crtc->scrn;
 }
 
 static void
@@ -135,81 +135,81 @@ crtc_gamma_set(xf86CrtcPtr crtc, CARD16 * red, CARD16 * green, CARD16 * blue,
 static void *
 crtc_shadow_allocate(xf86CrtcPtr crtc, int width, int height)
 {
-   ScrnInfoPtr pScrn = crtc->scrn;
+    ScrnInfoPtr pScrn = crtc->scrn;
 
-   return NULL;
+    return NULL;
 }
 
 static PixmapPtr
 crtc_shadow_create(xf86CrtcPtr crtc, void *data, int width, int height)
 {
-   ScrnInfoPtr pScrn = crtc->scrn;
+    ScrnInfoPtr pScrn = crtc->scrn;
 
-   return NULL;
+    return NULL;
 }
 
 static void
 crtc_shadow_destroy(xf86CrtcPtr crtc, PixmapPtr rotate_pixmap, void *data)
 {
-   ScrnInfoPtr pScrn = crtc->scrn;
+    ScrnInfoPtr pScrn = crtc->scrn;
 }
 
 static void
 crtc_destroy(xf86CrtcPtr crtc)
 {
-   drmModeFreeCrtc(crtc->driver_private);
+    drmModeFreeCrtc(crtc->driver_private);
 }
 
 static const xf86CrtcFuncsRec crtc_funcs = {
-   .dpms = crtc_dpms,
-   .save = NULL,			/* XXX */
-   .restore = NULL,			/* XXX */
-   .lock = crtc_lock,
-   .unlock = crtc_unlock,
-   .mode_fixup = crtc_mode_fixup,
-   .prepare = crtc_prepare,
-   .mode_set = crtc_mode_set,
-   .commit = crtc_commit,
-   .gamma_set = crtc_gamma_set,
-   .shadow_create = crtc_shadow_create,
-   .shadow_allocate = crtc_shadow_allocate,
-   .shadow_destroy = crtc_shadow_destroy,
+    .dpms = crtc_dpms,
+    .save = NULL,		       /* XXX */
+    .restore = NULL,		       /* XXX */
+    .lock = crtc_lock,
+    .unlock = crtc_unlock,
+    .mode_fixup = crtc_mode_fixup,
+    .prepare = crtc_prepare,
+    .mode_set = crtc_mode_set,
+    .commit = crtc_commit,
+    .gamma_set = crtc_gamma_set,
+    .shadow_create = crtc_shadow_create,
+    .shadow_allocate = crtc_shadow_allocate,
+    .shadow_destroy = crtc_shadow_destroy,
 //    .set_cursor_colors = crtc_set_cursor_colors,
 //    .set_cursor_position = crtc_set_cursor_position,
 //    .show_cursor = crtc_show_cursor,
 //    .hide_cursor = crtc_hide_cursor,
 //    .load_cursor_image = crtc_load_cursor_image, 
 //    .load_cursor_argb = crtc_load_cursor_argb,
-   .destroy = crtc_destroy,		/* XXX */
+    .destroy = crtc_destroy,	       /* XXX */
 };
 
 void
 crtc_init(ScrnInfoPtr pScrn)
 {
-   modesettingPtr ms = modesettingPTR(pScrn);
-   xf86CrtcPtr crtc;
-   drmModeResPtr res;
-   drmModeCrtcPtr drm_crtc = NULL;
-   int c, k, p;
-
-   res = drmModeGetResources(ms->fd);
-   if (res == 0) {
-      ErrorF("Failed drmModeGetResources %d\n",errno);
-      return;
-   }
-
-   for (c = 0; c < res->count_crtcs; c++) {
-      drm_crtc = drmModeGetCrtc(ms->fd, res->crtcs[c]);
-      if (!drm_crtc)
-	 continue;
-
-      crtc = xf86CrtcCreate(pScrn, &crtc_funcs);
-      if (crtc == NULL)
-	 goto out;
-
-      crtc->driver_private = drm_crtc;
-   }
-
-out:
-   drmModeFreeResources(res);
+    modesettingPtr ms = modesettingPTR(pScrn);
+    xf86CrtcPtr crtc;
+    drmModeResPtr res;
+    drmModeCrtcPtr drm_crtc = NULL;
+    int c, k, p;
+
+    res = drmModeGetResources(ms->fd);
+    if (res == 0) {
+	ErrorF("Failed drmModeGetResources %d\n", errno);
+	return;
+    }
+
+    for (c = 0; c < res->count_crtcs; c++) {
+	drm_crtc = drmModeGetCrtc(ms->fd, res->crtcs[c]);
+	if (!drm_crtc)
+	    continue;
+
+	crtc = xf86CrtcCreate(pScrn, &crtc_funcs);
+	if (crtc == NULL)
+	    goto out;
+
+	crtc->driver_private = drm_crtc;
+    }
+
+  out:
+    drmModeFreeResources(res);
 }
diff --git a/hw/xfree86/drivers/modesetting/driver.c b/hw/xfree86/drivers/modesetting/driver.c
index ba6bfdf..de4b260 100644
--- a/hw/xfree86/drivers/modesetting/driver.c
+++ b/hw/xfree86/drivers/modesetting/driver.c
@@ -65,12 +65,15 @@ static Bool SaveHWState(ScrnInfoPtr pScrn);
 static Bool RestoreHWState(ScrnInfoPtr pScrn);
 static void Identify(int flags);
 static const OptionInfoRec *AvailableOptions(int chipid, int busid);
-static ModeStatus ValidMode(int scrnIndex, DisplayModePtr mode, Bool verbose, int flags);
+static ModeStatus ValidMode(int scrnIndex, DisplayModePtr mode, Bool verbose,
+			    int flags);
 static void FreeScreen(int scrnIndex, int flags);
 static void LeaveVT(int scrnIndex, int flags);
 static Bool SwitchMode(int scrnIndex, DisplayModePtr mode, int flags);
-static Bool ScreenInit(int scrnIndex, ScreenPtr pScreen, int argc, char **argv);
+static Bool ScreenInit(int scrnIndex, ScreenPtr pScreen, int argc,
+		       char **argv);
 static Bool PreInit(ScrnInfoPtr pScrn, int flags);
+
 #if XSERVER_LIBPCIACCESS
 static Bool
 pci_probe(DriverPtr driver,
@@ -81,64 +84,64 @@ static Bool Probe(DriverPtr drv, int flags);
 
 #if XSERVER_LIBPCIACCESS
 static const struct pci_id_match device_match[] = {
-   {0x8086, 0x2592, 0xffff, 0xffff, 0, 0, 0},
-   {0, 0, 0},
+    {0x8086, 0x2592, 0xffff, 0xffff, 0, 0, 0},
+    {0, 0, 0},
 };
 #endif
 
 _X_EXPORT DriverRec modesetting = {
-   1,
-   "modesetting",
-   Identify,
+    1,
+    "modesetting",
+    Identify,
 #if XSERVER_LIBPCIACCESS
-   NULL,
+    NULL,
 #else
-   Probe,
+    Probe,
 #endif
-   AvailableOptions,
-   NULL,
-   0,
-   NULL,
+    AvailableOptions,
+    NULL,
+    0,
+    NULL,
 #if XSERVER_LIBPCIACCESS
-   device_match,
-   pci_probe
+    device_match,
+    pci_probe
 #endif
 };
 
 static SymTabRec Chipsets[] = {
-   {0x2592, "Intel Graphics Device"},
-   {-1, NULL}
+    {0x2592, "Intel Graphics Device"},
+    {-1, NULL}
 };
 
 static PciChipsets PciDevices[] = {
-   {0x2592, 0x2592, RES_SHARED_VGA},
-   {-1, -1, RES_UNDEFINED}
+    {0x2592, 0x2592, RES_SHARED_VGA},
+    {-1, -1, RES_UNDEFINED}
 };
 
 typedef enum
 {
-   OPTION_NOACCEL,
-   OPTION_SW_CURSOR,
-   OPTION_SHADOWFB,
+    OPTION_NOACCEL,
+    OPTION_SW_CURSOR,
+    OPTION_SHADOWFB,
 } modesettingOpts;
 
 static const OptionInfoRec Options[] = {
-   {OPTION_NOACCEL, "NoAccel", OPTV_BOOLEAN, {0}, FALSE},
-   {OPTION_SW_CURSOR, "SWcursor", OPTV_BOOLEAN, {0}, FALSE},
-   {OPTION_SHADOWFB, "ShadowFB", OPTV_BOOLEAN, {0}, FALSE},
-   {-1, NULL, OPTV_NONE, {0}, FALSE}
+    {OPTION_NOACCEL, "NoAccel", OPTV_BOOLEAN, {0}, FALSE},
+    {OPTION_SW_CURSOR, "SWcursor", OPTV_BOOLEAN, {0}, FALSE},
+    {OPTION_SHADOWFB, "ShadowFB", OPTV_BOOLEAN, {0}, FALSE},
+    {-1, NULL, OPTV_NONE, {0}, FALSE}
 };
 
 static const char *fbSymbols[] = {
-   "fbPictureInit",
-   "fbScreenInit",
-   NULL
+    "fbPictureInit",
+    "fbScreenInit",
+    NULL
 };
 
 static const char *ddcSymbols[] = {
-   "xf86PrintEDID",
-   "xf86SetDDCproperties",
-   NULL
+    "xf86PrintEDID",
+    "xf86SetDDCproperties",
+    NULL
 };
 
 static const char *shadowSymbols[] = {
@@ -148,9 +151,9 @@ static const char *shadowSymbols[] = {
 };
 
 static const char *i2cSymbols[] = {
-   "xf86CreateI2CBusRec",
-   "xf86I2CBusInit",
-   NULL
+    "xf86CreateI2CBusRec",
+    "xf86I2CBusInit",
+    NULL
 };
 
 int modesettingEntityIndex = -1;
@@ -158,16 +161,16 @@ int modesettingEntityIndex = -1;
 static MODULESETUPPROTO(Setup);
 
 static XF86ModuleVersionInfo VersRec = {
-   "modesetting",
-   MODULEVENDORSTRING,
-   MODINFOSTRING1,
-   MODINFOSTRING2,
-   XORG_VERSION_CURRENT,
-   PACKAGE_VERSION_MAJOR, PACKAGE_VERSION_MINOR, PACKAGE_VERSION_PATCHLEVEL,
-   ABI_CLASS_VIDEODRV,
-   ABI_VIDEODRV_VERSION,
-   MOD_CLASS_VIDEODRV,
-   {0, 0, 0, 0}
+    "modesetting",
+    MODULEVENDORSTRING,
+    MODINFOSTRING1,
+    MODINFOSTRING2,
+    XORG_VERSION_CURRENT,
+    PACKAGE_VERSION_MAJOR, PACKAGE_VERSION_MINOR, PACKAGE_VERSION_PATCHLEVEL,
+    ABI_CLASS_VIDEODRV,
+    ABI_VIDEODRV_VERSION,
+    MOD_CLASS_VIDEODRV,
+    {0, 0, 0, 0}
 };
 
 _X_EXPORT XF86ModuleData modesettingModuleData = { &VersRec, Setup, NULL };
@@ -175,44 +178,43 @@ _X_EXPORT XF86ModuleData modesettingModuleData = { &VersRec, Setup, NULL };
 static pointer
 Setup(pointer module, pointer opts, int *errmaj, int *errmin)
 {
-   static Bool setupDone = 0;
-
-   /* This module should be loaded only once, but check to be sure.
-    */
-   if (!setupDone) {
-      setupDone = 1;
-      xf86AddDriver(&modesetting, module, HaveDriverFuncs);
-
-      /*
-       * Tell the loader about symbols from other modules that this module
-       * might refer to.
-       */
-      LoaderRefSymLists(fbSymbols,
-			shadowSymbols, ddcSymbols, NULL);
-
-      /*
-       * The return value must be non-NULL on success even though there
-       * is no TearDownProc.
-       */
-      return (pointer) 1;
-   } else {
-      if (errmaj)
-	 *errmaj = LDR_ONCEONLY;
-      return NULL;
-   }
+    static Bool setupDone = 0;
+
+    /* This module should be loaded only once, but check to be sure.
+     */
+    if (!setupDone) {
+	setupDone = 1;
+	xf86AddDriver(&modesetting, module, HaveDriverFuncs);
+
+	/*
+	 * Tell the loader about symbols from other modules that this module
+	 * might refer to.
+	 */
+	LoaderRefSymLists(fbSymbols, shadowSymbols, ddcSymbols, NULL);
+
+	/*
+	 * The return value must be non-NULL on success even though there
+	 * is no TearDownProc.
+	 */
+	return (pointer) 1;
+    } else {
+	if (errmaj)
+	    *errmaj = LDR_ONCEONLY;
+	return NULL;
+    }
 }
 
 static void
 Identify(int flags)
 {
-   xf86PrintChipsets("modesetting", "Driver for Modesetting Kernel Drivers",
-		     Chipsets);
+    xf86PrintChipsets("modesetting", "Driver for Modesetting Kernel Drivers",
+		      Chipsets);
 }
 
 static const OptionInfoRec *
 AvailableOptions(int chipid, int busid)
 {
-   return Options;
+    return Options;
 }
 
 #if XSERVER_LIBPCIACCESS
@@ -220,267 +222,271 @@ static Bool
 pci_probe(DriverPtr driver,
 	  int entity_num, struct pci_device *device, intptr_t match_data)
 {
-   ScrnInfoPtr scrn = NULL;
-   EntityInfoPtr entity;
-   DevUnion *private;
-
-   scrn = xf86ConfigPciEntity(scrn, 0, entity_num, PciDevices,
-			      NULL, NULL, NULL, NULL, NULL);
-   if (scrn != NULL) {
-      scrn->driverVersion = 1;
-      scrn->driverName = "modesetting";
-      scrn->name = "modesetting";
-      scrn->Probe = NULL;
-
-      entity = xf86GetEntityInfo(entity_num);
-
-      switch (device->device_id) {
-      case 0x2592:
-	 scrn->PreInit = PreInit;
-	 scrn->ScreenInit = ScreenInit;
-	 scrn->SwitchMode = SwitchMode;
-	 scrn->AdjustFrame = AdjustFrame;
-	 scrn->EnterVT = EnterVT;
-	 scrn->LeaveVT = LeaveVT;
-	 scrn->FreeScreen = FreeScreen;
-	 scrn->ValidMode = ValidMode;
-	 break;
-      }
-   }
-   return scrn != NULL;
+    ScrnInfoPtr scrn = NULL;
+    EntityInfoPtr entity;
+    DevUnion *private;
+
+    scrn = xf86ConfigPciEntity(scrn, 0, entity_num, PciDevices,
+			       NULL, NULL, NULL, NULL, NULL);
+    if (scrn != NULL) {
+	scrn->driverVersion = 1;
+	scrn->driverName = "modesetting";
+	scrn->name = "modesetting";
+	scrn->Probe = NULL;
+
+	entity = xf86GetEntityInfo(entity_num);
+
+	switch (device->device_id) {
+	case 0x2592:
+	    scrn->PreInit = PreInit;
+	    scrn->ScreenInit = ScreenInit;
+	    scrn->SwitchMode = SwitchMode;
+	    scrn->AdjustFrame = AdjustFrame;
+	    scrn->EnterVT = EnterVT;
+	    scrn->LeaveVT = LeaveVT;
+	    scrn->FreeScreen = FreeScreen;
+	    scrn->ValidMode = ValidMode;
+	    break;
+	}
+    }
+    return scrn != NULL;
 }
 #else
 static Bool
 Probe(DriverPtr drv, int flags)
 {
-   int i, numUsed, numDevSections, *usedChips;
-   EntPtr msEnt = NULL;
-   DevUnion *pPriv;
-   GDevPtr *devSections;
-   Bool foundScreen = FALSE;
-   pciVideoPtr *VideoInfo;
-   pciVideoPtr *ppPci;
-   int numDevs;
-
-   /*
-    * Find the config file Device sections that match this
-    * driver, and return if there are none.
-    */
-   if ((numDevSections =
-	xf86MatchDevice("modesetting", &devSections)) <= 0) {
-      return FALSE;
-   }
-
-   /*
-    * This probing is just checking the PCI data the server already
-    * collected.
-    */
-   if (!(VideoInfo = xf86GetPciVideoInfo()))
-      return FALSE;
+    int i, numUsed, numDevSections, *usedChips;
+    EntPtr msEnt = NULL;
+    DevUnion *pPriv;
+    GDevPtr *devSections;
+    Bool foundScreen = FALSE;
+    pciVideoPtr *VideoInfo;
+    pciVideoPtr *ppPci;
+    int numDevs;
+
+    /*
+     * Find the config file Device sections that match this
+     * driver, and return if there are none.
+     */
+    if ((numDevSections = xf86MatchDevice("modesetting", &devSections)) <= 0) {
+	return FALSE;
+    }
+
+    /*
+     * This probing is just checking the PCI data the server already
+     * collected.
+     */
+    if (!(VideoInfo = xf86GetPciVideoInfo()))
+	return FALSE;
 
 #if 0
-   numUsed = 0;
-   for (ppPci = VideoInfo; ppPci != NULL && *ppPci != NULL; ppPci++) {
-      for (numDevs = 0; numDevs < numDevSections; numDevs++) {
-         if (devSections[numDevs]->busID && *devSections[numDevs]->busID) {
-	 if (xf86ComparePciBusString(devSections[numDevs]->busID, (*ppPci)->bus, (*ppPci)->device, (*ppPci)->func)) {
-         /* Claim slot */
-         if (xf86CheckPciSlot((*ppPci)->bus, (*ppPci)->device,
-				    (*ppPci)->func)) {
-	    usedChips[numUsed++] = xf86ClaimPciSlot((*ppPci)->bus, (*ppPci)->device,
-				   (*ppPci)->func, drv, (*ppPci)->chipType,
-				   NULL, TRUE);
-				   ErrorF("CLAIMED %d %d %d\n",(*ppPci)->bus,(*ppPci)->device, (*ppPci)->func);
-	 }
-	 }
-	 }
-      }
-   }
+    numUsed = 0;
+    for (ppPci = VideoInfo; ppPci != NULL && *ppPci != NULL; ppPci++) {
+	for (numDevs = 0; numDevs < numDevSections; numDevs++) {
+	    if (devSections[numDevs]->busID && *devSections[numDevs]->busID) {
+		if (xf86ComparePciBusString
+		    (devSections[numDevs]->busID, (*ppPci)->bus,
+		     (*ppPci)->device, (*ppPci)->func)) {
+		    /* Claim slot */
+		    if (xf86CheckPciSlot((*ppPci)->bus, (*ppPci)->device,
+					 (*ppPci)->func)) {
+			usedChips[numUsed++] =
+			    xf86ClaimPciSlot((*ppPci)->bus, (*ppPci)->device,
+					     (*ppPci)->func, drv,
+					     (*ppPci)->chipType, NULL, TRUE);
+			ErrorF("CLAIMED %d %d %d\n", (*ppPci)->bus,
+			       (*ppPci)->device, (*ppPci)->func);
+		    }
+		}
+	    }
+	}
+    }
 #else
-   /* Look for Intel i8xx devices. */
-   numUsed = xf86MatchPciInstances("modesetting", PCI_VENDOR_INTEL,
-				   Chipsets, PciDevices,
-				   devSections, numDevSections,
-				   drv, &usedChips);
+    /* Look for Intel i8xx devices. */
+    numUsed = xf86MatchPciInstances("modesetting", PCI_VENDOR_INTEL,
+				    Chipsets, PciDevices,
+				    devSections, numDevSections,
+				    drv, &usedChips);
 #endif
 
-   if (flags & PROBE_DETECT) {
-      if (numUsed > 0)
-	 foundScreen = TRUE;
-   } else {
-   ErrorF("NUMUSED %d\n",numUsed);
-      for (i = 0; i < numUsed; i++) {
-	 ScrnInfoPtr pScrn = NULL;
-
-	 /* Allocate new ScrnInfoRec and claim the slot */
-	 if ((pScrn = xf86ConfigPciEntity(pScrn, 0, usedChips[i],
-					  PciDevices, NULL, NULL, NULL,
-					  NULL, NULL))) {
-	    EntityInfoPtr pEnt;
-
-	    pEnt = xf86GetEntityInfo(usedChips[i]);
-
-	    pScrn->driverVersion = 1;
-	    pScrn->driverName = "modesetting";
-	    pScrn->name = "modesetting";
-	    pScrn->Probe = Probe;
+    if (flags & PROBE_DETECT) {
+	if (numUsed > 0)
 	    foundScreen = TRUE;
-	    {
-	       /* Allocate an entity private if necessary */
-	       if (modesettingEntityIndex < 0)
-		  modesettingEntityIndex = xf86AllocateEntityPrivateIndex();
-
-	       pPriv = xf86GetEntityPrivate(pScrn->entityList[0],
-					    modesettingEntityIndex);
-	       if (!pPriv->ptr) {
-		  pPriv->ptr = xnfcalloc(sizeof(EntRec), 1);
-		  msEnt = pPriv->ptr;
-		  msEnt->lastInstance = -1;
-	       } else {
-		  msEnt = pPriv->ptr;
-	       }
-
-	       /*
-	        * Set the entity instance for this instance of the driver.
-	        * For dual head per card, instance 0 is the "master"
-	        * instance, driving the primary head, and instance 1 is
-	        * the "slave".
-	        */
-	       msEnt->lastInstance++;
-	       xf86SetEntityInstanceForScreen(pScrn,
-					      pScrn->entityList[0],
-					      msEnt->lastInstance);
-	       pScrn->PreInit = PreInit;
-	       pScrn->ScreenInit = ScreenInit;
-	       pScrn->SwitchMode = SwitchMode;
-	       pScrn->AdjustFrame = AdjustFrame;
-	       pScrn->EnterVT = EnterVT;
-	       pScrn->LeaveVT = LeaveVT;
-	       pScrn->FreeScreen = FreeScreen;
-	       pScrn->ValidMode = ValidMode;
-	       break;
-	    }
-	 } else
-	 	ErrorF("FAILED PSCRN\n");
-      }
-   }
+    } else {
+	ErrorF("NUMUSED %d\n", numUsed);
+	for (i = 0; i < numUsed; i++) {
+	    ScrnInfoPtr pScrn = NULL;
+
+	    /* Allocate new ScrnInfoRec and claim the slot */
+	    if ((pScrn = xf86ConfigPciEntity(pScrn, 0, usedChips[i],
+					     PciDevices, NULL, NULL, NULL,
+					     NULL, NULL))) {
+		EntityInfoPtr pEnt;
+
+		pEnt = xf86GetEntityInfo(usedChips[i]);
+
+		pScrn->driverVersion = 1;
+		pScrn->driverName = "modesetting";
+		pScrn->name = "modesetting";
+		pScrn->Probe = Probe;
+		foundScreen = TRUE;
+		{
+		    /* Allocate an entity private if necessary */
+		    if (modesettingEntityIndex < 0)
+			modesettingEntityIndex =
+			    xf86AllocateEntityPrivateIndex();
+
+		    pPriv = xf86GetEntityPrivate(pScrn->entityList[0],
+						 modesettingEntityIndex);
+		    if (!pPriv->ptr) {
+			pPriv->ptr = xnfcalloc(sizeof(EntRec), 1);
+			msEnt = pPriv->ptr;
+			msEnt->lastInstance = -1;
+		    } else {
+			msEnt = pPriv->ptr;
+		    }
+
+		    /*
+		     * Set the entity instance for this instance of the driver.
+		     * For dual head per card, instance 0 is the "master"
+		     * instance, driving the primary head, and instance 1 is
+		     * the "slave".
+		     */
+		    msEnt->lastInstance++;
+		    xf86SetEntityInstanceForScreen(pScrn,
+						   pScrn->entityList[0],
+						   msEnt->lastInstance);
+		    pScrn->PreInit = PreInit;
+		    pScrn->ScreenInit = ScreenInit;
+		    pScrn->SwitchMode = SwitchMode;
+		    pScrn->AdjustFrame = AdjustFrame;
+		    pScrn->EnterVT = EnterVT;
+		    pScrn->LeaveVT = LeaveVT;
+		    pScrn->FreeScreen = FreeScreen;
+		    pScrn->ValidMode = ValidMode;
+		    break;
+		}
+	    } else
+		ErrorF("FAILED PSCRN\n");
+	}
+    }
 
-   xfree(usedChips);
-   xfree(devSections);
+    xfree(usedChips);
+    xfree(devSections);
 
-   return foundScreen;
+    return foundScreen;
 }
 #endif
 
 static Bool
 GetRec(ScrnInfoPtr pScrn)
 {
-   if (pScrn->driverPrivate)
-      return TRUE;
+    if (pScrn->driverPrivate)
+	return TRUE;
 
-   pScrn->driverPrivate = xnfcalloc(sizeof(modesettingRec), 1);
+    pScrn->driverPrivate = xnfcalloc(sizeof(modesettingRec), 1);
 
-   return TRUE;
+    return TRUE;
 }
 
 static void
 FreeRec(ScrnInfoPtr pScrn)
 {
-   if (!pScrn)
-      return;
+    if (!pScrn)
+	return;
 
-   if (!pScrn->driverPrivate)
-      return;
+    if (!pScrn->driverPrivate)
+	return;
 
-   xfree(pScrn->driverPrivate);
+    xfree(pScrn->driverPrivate);
 
-   pScrn->driverPrivate = NULL;
+    pScrn->driverPrivate = NULL;
 }
 
 static void
 ProbeDDC(ScrnInfoPtr pScrn, int index)
 {
-   ConfiguredMonitor = NULL;
+    ConfiguredMonitor = NULL;
 }
 
 static Bool
 MapMem(ScrnInfoPtr pScrn)
 {
-   modesettingPtr ms = modesettingPTR(pScrn);
+    modesettingPtr ms = modesettingPTR(pScrn);
 
-   drmBOMap(ms->fd,
-	    &ms->bo, DRM_BO_FLAG_READ | DRM_BO_FLAG_WRITE, 0, &ms->virtual);
+    drmBOMap(ms->fd,
+	     &ms->bo, DRM_BO_FLAG_READ | DRM_BO_FLAG_WRITE, 0, &ms->virtual);
 
-   return TRUE;
+    return TRUE;
 }
 
 static Bool
 UnmapMem(ScrnInfoPtr pScrn)
 {
-   modesettingPtr ms = modesettingPTR(pScrn);
+    modesettingPtr ms = modesettingPTR(pScrn);
 
-   drmBOUnmap(ms->fd, &ms->bo);
+    drmBOUnmap(ms->fd, &ms->bo);
 
-   return TRUE;
+    return TRUE;
 }
 
 static void
 LoadPalette(ScrnInfoPtr pScrn, int numColors, int *indices,
 	    LOCO * colors, VisualPtr pVisual)
 {
-   xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(pScrn);
+    xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(pScrn);
 }
 
 static Bool
 crtc_resize(ScrnInfoPtr pScrn, int width, int height)
 {
-   modesettingPtr ms = modesettingPTR(pScrn);
-   ScreenPtr pScreen = pScrn->pScreen;
-   PixmapPtr rootPixmap = pScreen->GetScreenPixmap(pScreen);
-   Bool fbAccessDisabled;
-   CARD8 *fbstart;
-
-   if (width == pScrn->virtualX && height == pScrn->virtualY)
-      return TRUE;
-
-   ErrorF("RESIZING TO %dx%d\n",width,height);
-
-   pScrn->virtualX = width;
-   pScrn->virtualY = height;
-   pScrn->displayWidth = (pScrn->virtualX + 63) & ~63;
-
-   if (ms->shadowMem) {
-      xfree(ms->shadowMem);
-      ms->shadowMem = NULL;
-   }
-
-   UnmapMem(pScrn);
-
-   /* move old buffer out of the way */
-   drmBOSetStatus(ms->fd, &ms->bo, DRM_BO_FLAG_READ | DRM_BO_FLAG_MEM_LOCAL,
-   				   DRM_BO_MASK_MEM | DRM_BO_FLAG_NO_EVICT,
-				   DRM_BO_HINT_DONT_FENCE, 0, 0);
-
-   /* unreference it */
-   drmBOUnreference(ms->fd, &ms->bo);
-
-   drmBOCreate(ms->fd,
-	       pScrn->virtualY * pScrn->displayWidth *
-	       pScrn->bitsPerPixel / 8, 0, NULL,
-	       DRM_BO_FLAG_READ | DRM_BO_FLAG_WRITE | DRM_BO_FLAG_SHAREABLE
-	       | DRM_BO_FLAG_NO_EVICT | DRM_BO_FLAG_MAPPABLE |
-	       DRM_BO_FLAG_MEM_VRAM | DRM_BO_FLAG_MEM_TT, DRM_BO_HINT_DONT_FENCE, &ms->bo);
-
-   MapMem(pScrn);
-
-   drmModeAddFB(ms->fd,
-		pScrn->virtualX,
-		pScrn->virtualY,
-		pScrn->depth,
-		pScrn->bitsPerPixel,
-		pScrn->displayWidth * pScrn->bitsPerPixel / 8,
-		ms->bo.handle, 
-		&ms->fb_id);
+    modesettingPtr ms = modesettingPTR(pScrn);
+    ScreenPtr pScreen = pScrn->pScreen;
+    PixmapPtr rootPixmap = pScreen->GetScreenPixmap(pScreen);
+    Bool fbAccessDisabled;
+    CARD8 *fbstart;
+
+    if (width == pScrn->virtualX && height == pScrn->virtualY)
+	return TRUE;
+
+    ErrorF("RESIZING TO %dx%d\n", width, height);
+
+    pScrn->virtualX = width;
+    pScrn->virtualY = height;
+    pScrn->displayWidth = (pScrn->virtualX + 63) & ~63;
+
+    if (ms->shadowMem) {
+	xfree(ms->shadowMem);
+	ms->shadowMem = NULL;
+    }
+
+    UnmapMem(pScrn);
+
+    /* move old buffer out of the way */
+    drmBOSetStatus(ms->fd, &ms->bo, DRM_BO_FLAG_READ | DRM_BO_FLAG_MEM_LOCAL,
+		   DRM_BO_MASK_MEM | DRM_BO_FLAG_NO_EVICT,
+		   DRM_BO_HINT_DONT_FENCE, 0, 0);
+
+    /* unreference it */
+    drmBOUnreference(ms->fd, &ms->bo);
+
+    drmBOCreate(ms->fd,
+		pScrn->virtualY * pScrn->displayWidth *
+		pScrn->bitsPerPixel / 8, 0, NULL,
+		DRM_BO_FLAG_READ | DRM_BO_FLAG_WRITE | DRM_BO_FLAG_SHAREABLE
+		| DRM_BO_FLAG_NO_EVICT | DRM_BO_FLAG_MAPPABLE |
+		DRM_BO_FLAG_MEM_VRAM | DRM_BO_FLAG_MEM_TT,
+		DRM_BO_HINT_DONT_FENCE, &ms->bo);
+
+    MapMem(pScrn);
+
+    drmModeAddFB(ms->fd,
+		 pScrn->virtualX,
+		 pScrn->virtualY,
+		 pScrn->depth,
+		 pScrn->bitsPerPixel,
+		 pScrn->displayWidth * pScrn->bitsPerPixel / 8,
+		 ms->bo.handle, &ms->fb_id);
 
     if (ms->shadowFB) {
 	if ((ms->shadowMem =
@@ -488,7 +494,7 @@ crtc_resize(ScrnInfoPtr pScrn, int width, int height)
 			 pScrn->bitsPerPixel)) == NULL) {
 	    xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
 		       "Allocation of shadow memory failed\n");
-		return FALSE;
+	    return FALSE;
 	}
 	fbstart = ms->shadowMem;
     } else {
@@ -508,7 +514,7 @@ crtc_resize(ScrnInfoPtr pScrn, int width, int height)
     pScreen->ModifyPixmapHeader(rootPixmap,
 				pScrn->virtualX, pScrn->virtualY,
 				pScrn->depth, pScrn->bitsPerPixel,
-				pScrn->displayWidth * pScrn->bitsPerPixel / 8, 
+				pScrn->displayWidth * pScrn->bitsPerPixel / 8,
 				fbstart);
 
     if (fbAccessDisabled) {
@@ -516,148 +522,148 @@ crtc_resize(ScrnInfoPtr pScrn, int width, int height)
 	rootPixmap->devPrivate.ptr = NULL;
     }
 
-   pScrn->frameX0 = 0;
-   pScrn->frameY0 = 0;
-   AdjustFrame(pScrn->scrnIndex, pScrn->frameX0, pScrn->frameY0, 0);
+    pScrn->frameX0 = 0;
+    pScrn->frameY0 = 0;
+    AdjustFrame(pScrn->scrnIndex, pScrn->frameX0, pScrn->frameY0, 0);
 
-   return TRUE;
+    return TRUE;
 }
 
 static const xf86CrtcConfigFuncsRec crtc_config_funcs = {
-   crtc_resize
+    crtc_resize
 };
 
 static Bool
 PreInit(ScrnInfoPtr pScrn, int flags)
 {
-   xf86CrtcConfigPtr xf86_config;
-   modesettingPtr ms;
-   MessageType from = X_PROBED;
-   rgb defaultWeight = { 0, 0, 0 };
-   EntityInfoPtr pEnt;
-   EntPtr msEnt = NULL;
-   int flags24;
-   char *BusID;
-   int i;
-   char *s;
-   int num_pipe;
-   int max_width, max_height;
-
-   if (pScrn->numEntities != 1)
-      return FALSE;
-
-   pEnt = xf86GetEntityInfo(pScrn->entityList[0]);
-
-   if (flags & PROBE_DETECT) {
-      ProbeDDC(pScrn, pEnt->index);
-      return TRUE;
-   }
-
-   /* Allocate driverPrivate */
-   if (!GetRec(pScrn))
-      return FALSE;
-
-   ms = modesettingPTR(pScrn);
-   ms->SaveGeneration = -1;
-   ms->pEnt = pEnt;
-
-   pScrn->displayWidth = 640;		/* default it */
-
-   if (ms->pEnt->location.type != BUS_PCI)
-      return FALSE;
-
-   ms->PciInfo = xf86GetPciInfoForEntity(ms->pEnt->index);
-
-   /* Allocate an entity private if necessary */
-   if (xf86IsEntityShared(pScrn->entityList[0])) {
-      msEnt = xf86GetEntityPrivate(pScrn->entityList[0],
-				   modesettingEntityIndex)->ptr;
-      ms->entityPrivate = msEnt;
-   } else
-      ms->entityPrivate = NULL;
-
-   if (xf86RegisterResources(ms->pEnt->index, NULL, ResNone)) {
-      return FALSE;
-   }
-
-   if (xf86IsEntityShared(pScrn->entityList[0])) {
-      if (xf86IsPrimInitDone(pScrn->entityList[0])) {
-	 /* do something */
-      } else {
-	 xf86SetPrimInitDone(pScrn->entityList[0]);
-      }
-   }
-
-   BusID = xalloc(64);
-   sprintf(BusID, "PCI:%d:%d:%d",
+    xf86CrtcConfigPtr xf86_config;
+    modesettingPtr ms;
+    MessageType from = X_PROBED;
+    rgb defaultWeight = { 0, 0, 0 };
+    EntityInfoPtr pEnt;
+    EntPtr msEnt = NULL;
+    int flags24;
+    char *BusID;
+    int i;
+    char *s;
+    int num_pipe;
+    int max_width, max_height;
+
+    if (pScrn->numEntities != 1)
+	return FALSE;
+
+    pEnt = xf86GetEntityInfo(pScrn->entityList[0]);
+
+    if (flags & PROBE_DETECT) {
+	ProbeDDC(pScrn, pEnt->index);
+	return TRUE;
+    }
+
+    /* Allocate driverPrivate */
+    if (!GetRec(pScrn))
+	return FALSE;
+
+    ms = modesettingPTR(pScrn);
+    ms->SaveGeneration = -1;
+    ms->pEnt = pEnt;
+
+    pScrn->displayWidth = 640;	       /* default it */
+
+    if (ms->pEnt->location.type != BUS_PCI)
+	return FALSE;
+
+    ms->PciInfo = xf86GetPciInfoForEntity(ms->pEnt->index);
+
+    /* Allocate an entity private if necessary */
+    if (xf86IsEntityShared(pScrn->entityList[0])) {
+	msEnt = xf86GetEntityPrivate(pScrn->entityList[0],
+				     modesettingEntityIndex)->ptr;
+	ms->entityPrivate = msEnt;
+    } else
+	ms->entityPrivate = NULL;
+
+    if (xf86RegisterResources(ms->pEnt->index, NULL, ResNone)) {
+	return FALSE;
+    }
+
+    if (xf86IsEntityShared(pScrn->entityList[0])) {
+	if (xf86IsPrimInitDone(pScrn->entityList[0])) {
+	    /* do something */
+	} else {
+	    xf86SetPrimInitDone(pScrn->entityList[0]);
+	}
+    }
+
+    BusID = xalloc(64);
+    sprintf(BusID, "PCI:%d:%d:%d",
 #if XSERVER_LIBPCIACCESS
-	   ((ms->PciInfo->domain << 8) | ms->PciInfo->bus),
-	   ms->PciInfo->dev, ms->PciInfo->func
+	    ((ms->PciInfo->domain << 8) | ms->PciInfo->bus),
+	    ms->PciInfo->dev, ms->PciInfo->func
 #else
-	   ((pciConfigPtr) ms->PciInfo->thisCard)->busnum,
-	   ((pciConfigPtr) ms->PciInfo->thisCard)->devnum,
-	   ((pciConfigPtr) ms->PciInfo->thisCard)->funcnum
+	    ((pciConfigPtr) ms->PciInfo->thisCard)->busnum,
+	    ((pciConfigPtr) ms->PciInfo->thisCard)->devnum,
+	    ((pciConfigPtr) ms->PciInfo->thisCard)->funcnum
 #endif
-	 );
-
-   ms->fd = drmOpen(NULL, BusID);
-
-   if (ms->fd < 0)
-      return FALSE;
-
-   pScrn->racMemFlags = RAC_FB | RAC_COLORMAP;
-   pScrn->monitor = pScrn->confScreen->monitor;
-   pScrn->progClock = TRUE;
-   pScrn->rgbBits = 8;
-
-   flags24 = Support32bppFb | PreferConvert24to32 | SupportConvert24to32;
-
-   if (!xf86SetDepthBpp(pScrn, 0, 0, 0, flags24))
-      return FALSE;
-
-   switch (pScrn->depth) {
-   case 8:
-   case 15:
-   case 16:
-   case 24:
-      break;
-   default:
-      xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
-		 "Given depth (%d) is not supported by the driver\n",
-		 pScrn->depth);
-      return FALSE;
-   }
-   xf86PrintDepthBpp(pScrn);
-
-   if (!xf86SetWeight(pScrn, defaultWeight, defaultWeight))
-      return FALSE;
-   if (!xf86SetDefaultVisual(pScrn, -1))
-      return FALSE;
-
-   /* Process the options */
-   xf86CollectOptions(pScrn, NULL);
-   if (!(ms->Options = xalloc(sizeof(Options))))
-      return FALSE;
-   memcpy(ms->Options, Options, sizeof(Options));
-   xf86ProcessOptions(pScrn->scrnIndex, pScrn->options, ms->Options);
-
-   /* Allocate an xf86CrtcConfig */
-   xf86CrtcConfigInit(pScrn, &crtc_config_funcs);
-   xf86_config = XF86_CRTC_CONFIG_PTR(pScrn);
-
-   max_width = 8192;
-   max_height = 8192;
-   xf86CrtcSetSizeRange(pScrn, 320, 200, max_width, max_height);
-
-   if (xf86ReturnOptValBool(ms->Options, OPTION_NOACCEL, FALSE)) {
-      ms->noAccel = TRUE;
-   }
-
-   if (xf86ReturnOptValBool(ms->Options, OPTION_SW_CURSOR, FALSE)) {
-      ms->SWCursor = TRUE;
-   }
-
-   if (xf86ReturnOptValBool(ms->Options, OPTION_SHADOWFB, FALSE)) {
+	);
+
+    ms->fd = drmOpen(NULL, BusID);
+
+    if (ms->fd < 0)
+	return FALSE;
+
+    pScrn->racMemFlags = RAC_FB | RAC_COLORMAP;
+    pScrn->monitor = pScrn->confScreen->monitor;
+    pScrn->progClock = TRUE;
+    pScrn->rgbBits = 8;
+
+    flags24 = Support32bppFb | PreferConvert24to32 | SupportConvert24to32;
+
+    if (!xf86SetDepthBpp(pScrn, 0, 0, 0, flags24))
+	return FALSE;
+
+    switch (pScrn->depth) {
+    case 8:
+    case 15:
+    case 16:
+    case 24:
+	break;
+    default:
+	xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
+		   "Given depth (%d) is not supported by the driver\n",
+		   pScrn->depth);
+	return FALSE;
+    }
+    xf86PrintDepthBpp(pScrn);
+
+    if (!xf86SetWeight(pScrn, defaultWeight, defaultWeight))
+	return FALSE;
+    if (!xf86SetDefaultVisual(pScrn, -1))
+	return FALSE;
+
+    /* Process the options */
+    xf86CollectOptions(pScrn, NULL);
+    if (!(ms->Options = xalloc(sizeof(Options))))
+	return FALSE;
+    memcpy(ms->Options, Options, sizeof(Options));
+    xf86ProcessOptions(pScrn->scrnIndex, pScrn->options, ms->Options);
+
+    /* Allocate an xf86CrtcConfig */
+    xf86CrtcConfigInit(pScrn, &crtc_config_funcs);
+    xf86_config = XF86_CRTC_CONFIG_PTR(pScrn);
+
+    max_width = 8192;
+    max_height = 8192;
+    xf86CrtcSetSizeRange(pScrn, 320, 200, max_width, max_height);
+
+    if (xf86ReturnOptValBool(ms->Options, OPTION_NOACCEL, FALSE)) {
+	ms->noAccel = TRUE;
+    }
+
+    if (xf86ReturnOptValBool(ms->Options, OPTION_SW_CURSOR, FALSE)) {
+	ms->SWCursor = TRUE;
+    }
+
+    if (xf86ReturnOptValBool(ms->Options, OPTION_SHADOWFB, FALSE)) {
 	if (!xf86LoadSubModule(pScrn, "shadow"))
 	    return FALSE;
 
@@ -666,144 +672,144 @@ PreInit(ScrnInfoPtr pScrn, int flags)
 	ms->shadowFB = TRUE;
     }
 
-   SaveHWState(pScrn);
+    SaveHWState(pScrn);
 
-   crtc_init(pScrn);
-   output_init(pScrn);
+    crtc_init(pScrn);
+    output_init(pScrn);
 
-   if (!xf86InitialConfiguration(pScrn, TRUE)) {
-      xf86DrvMsg(pScrn->scrnIndex, X_ERROR, "No valid modes.\n");
-      RestoreHWState(pScrn);
-      return FALSE;
-   }
+    if (!xf86InitialConfiguration(pScrn, TRUE)) {
+	xf86DrvMsg(pScrn->scrnIndex, X_ERROR, "No valid modes.\n");
+	RestoreHWState(pScrn);
+	return FALSE;
+    }
 
-   RestoreHWState(pScrn);
+    RestoreHWState(pScrn);
 
-   /*
-    * If the driver can do gamma correction, it should call xf86SetGamma() here.
-    */
-   {
-      Gamma zeros = { 0.0, 0.0, 0.0 };
+    /*
+     * If the driver can do gamma correction, it should call xf86SetGamma() here.
+     */
+    {
+	Gamma zeros = { 0.0, 0.0, 0.0 };
 
-      if (!xf86SetGamma(pScrn, zeros)) {
-	 return FALSE;
-      }
-   }
+	if (!xf86SetGamma(pScrn, zeros)) {
+	    return FALSE;
+	}
+    }
 
-   if (pScrn->modes == NULL) {
-      xf86DrvMsg(pScrn->scrnIndex, X_ERROR, "No modes.\n");
-      return FALSE;
-   }
+    if (pScrn->modes == NULL) {
+	xf86DrvMsg(pScrn->scrnIndex, X_ERROR, "No modes.\n");
+	return FALSE;
+    }
 
-   pScrn->currentMode = pScrn->modes;
+    pScrn->currentMode = pScrn->modes;
 
-   /* Set display resolution */
-   xf86SetDpi(pScrn, 0, 0);
+    /* Set display resolution */
+    xf86SetDpi(pScrn, 0, 0);
 
-   /* Load the required sub modules */
-   if (!xf86LoadSubModule(pScrn, "fb")) {
-      return FALSE;
-   }
+    /* Load the required sub modules */
+    if (!xf86LoadSubModule(pScrn, "fb")) {
+	return FALSE;
+    }
 
-   xf86LoaderReqSymLists(fbSymbols, NULL);
+    xf86LoaderReqSymLists(fbSymbols, NULL);
 
-   return TRUE;
+    return TRUE;
 }
 
 static Bool
 SaveHWState(ScrnInfoPtr pScrn)
 {
-   xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(pScrn);
+    xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(pScrn);
 
-   return TRUE;
+    return TRUE;
 }
 
 static Bool
 RestoreHWState(ScrnInfoPtr pScrn)
 {
-   xf86CrtcConfigPtr config = XF86_CRTC_CONFIG_PTR(pScrn);
+    xf86CrtcConfigPtr config = XF86_CRTC_CONFIG_PTR(pScrn);
 
-   return TRUE;
+    return TRUE;
 }
 
 static void *
 WindowLinear(ScreenPtr pScreen, CARD32 row, CARD32 offset, int mode,
-		CARD32 * size, void *closure)
+	     CARD32 * size, void *closure)
 {
-   ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
-   modesettingPtr ms = modesettingPTR(pScrn);
+    ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
+    modesettingPtr ms = modesettingPTR(pScrn);
 
-   if (!pScrn->vtSema)
-      return NULL;
+    if (!pScrn->vtSema)
+	return NULL;
 
-   *size = pScrn->displayWidth * pScrn->bitsPerPixel / 8;
+    *size = pScrn->displayWidth * pScrn->bitsPerPixel / 8;
 
-   return ((CARD8 *) ms->virtual + row * (*size) + offset);
+    return ((CARD8 *) ms->virtual + row * (*size) + offset);
 }
 
 static Bool
 CreateScreenResources(ScreenPtr pScreen)
 {
-   ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
-   modesettingPtr ms = modesettingPTR(pScrn);
-   Bool ret;
+    ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
+    modesettingPtr ms = modesettingPTR(pScrn);
+    Bool ret;
 
-   pScreen->CreateScreenResources = ms->createScreenResources;
-   ret = pScreen->CreateScreenResources(pScreen);
-   pScreen->CreateScreenResources = CreateScreenResources;
+    pScreen->CreateScreenResources = ms->createScreenResources;
+    ret = pScreen->CreateScreenResources(pScreen);
+    pScreen->CreateScreenResources = CreateScreenResources;
 
-   shadowAdd(pScreen, pScreen->GetScreenPixmap(pScreen),
+    shadowAdd(pScreen, pScreen->GetScreenPixmap(pScreen),
 	      ms->update, WindowLinear, 0, 0);
 
-   return ret;
+    return ret;
 }
 
 static Bool
 ScreenInit(int scrnIndex, ScreenPtr pScreen, int argc, char **argv)
 {
-   ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
-   modesettingPtr ms = modesettingPTR(pScrn);
-   VisualPtr visual;
-   unsigned long sys_mem;
-   int c;
-   MessageType from;
-   CARD8 *fbstart;
-
-   pScrn->displayWidth = (pScrn->virtualX + 63) & ~63;
-
-   miClearVisualTypes();
-
-   if (!miSetVisualTypes(pScrn->depth,
-			 miGetDefaultVisualMask(pScrn->depth),
-			 pScrn->rgbBits, pScrn->defaultVisual))
-      return FALSE;
-
-   if (!miSetPixmapDepths())
-      return FALSE;
-
-   if (!MapMem(pScrn))
-      return FALSE;
-
-   pScrn->memPhysBase = 0;
-   pScrn->fbOffset = 0;
-
-   drmBOCreate(ms->fd,
-	       pScrn->virtualY * pScrn->displayWidth *
-	       pScrn->bitsPerPixel / 8, 0, NULL,
-	       DRM_BO_FLAG_READ | DRM_BO_FLAG_WRITE | DRM_BO_FLAG_SHAREABLE
-	       | DRM_BO_FLAG_NO_EVICT | DRM_BO_FLAG_MAPPABLE |
-	       DRM_BO_FLAG_MEM_VRAM | DRM_BO_FLAG_MEM_TT, DRM_BO_HINT_DONT_FENCE, &ms->bo);
-
-   MapMem(pScrn);
-
-   drmModeAddFB(ms->fd,
-		pScrn->virtualX,
-		pScrn->virtualY,
-		pScrn->depth,
-		pScrn->bitsPerPixel,
-		pScrn->displayWidth * pScrn->bitsPerPixel / 8,
-		ms->bo.handle, 
-		&ms->fb_id);
+    ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
+    modesettingPtr ms = modesettingPTR(pScrn);
+    VisualPtr visual;
+    unsigned long sys_mem;
+    int c;
+    MessageType from;
+    CARD8 *fbstart;
+
+    pScrn->displayWidth = (pScrn->virtualX + 63) & ~63;
+
+    miClearVisualTypes();
+
+    if (!miSetVisualTypes(pScrn->depth,
+			  miGetDefaultVisualMask(pScrn->depth),
+			  pScrn->rgbBits, pScrn->defaultVisual))
+	return FALSE;
+
+    if (!miSetPixmapDepths())
+	return FALSE;
+
+    if (!MapMem(pScrn))
+	return FALSE;
+
+    pScrn->memPhysBase = 0;
+    pScrn->fbOffset = 0;
+
+    drmBOCreate(ms->fd,
+		pScrn->virtualY * pScrn->displayWidth *
+		pScrn->bitsPerPixel / 8, 0, NULL,
+		DRM_BO_FLAG_READ | DRM_BO_FLAG_WRITE | DRM_BO_FLAG_SHAREABLE
+		| DRM_BO_FLAG_NO_EVICT | DRM_BO_FLAG_MAPPABLE |
+		DRM_BO_FLAG_MEM_VRAM | DRM_BO_FLAG_MEM_TT,
+		DRM_BO_HINT_DONT_FENCE, &ms->bo);
+
+    MapMem(pScrn);
+
+    drmModeAddFB(ms->fd,
+		 pScrn->virtualX,
+		 pScrn->virtualY,
+		 pScrn->depth,
+		 pScrn->bitsPerPixel,
+		 pScrn->displayWidth * pScrn->bitsPerPixel / 8,
+		 ms->bo.handle, &ms->fb_id);
 
     if (ms->shadowFB) {
 	if ((ms->shadowMem =
@@ -811,140 +817,141 @@ ScreenInit(int scrnIndex, ScreenPtr pScreen, int argc, char **argv)
 			 pScrn->bitsPerPixel)) == NULL) {
 	    xf86DrvMsg(scrnIndex, X_ERROR,
 		       "Allocation of shadow memory failed\n");
-		return FALSE;
+	    return FALSE;
 	}
 	fbstart = ms->shadowMem;
     } else {
 	fbstart = ms->virtual;
     }
 
-   if (!fbScreenInit(pScreen, fbstart,
-		     pScrn->virtualX, pScrn->virtualY,
-		     pScrn->xDpi, pScrn->yDpi,
-		     pScrn->displayWidth, pScrn->bitsPerPixel))
-      return FALSE;
-
-   if (pScrn->bitsPerPixel > 8) {
-      /* Fixup RGB ordering */
-      visual = pScreen->visuals + pScreen->numVisuals;
-      while (--visual >= pScreen->visuals) {
-	 if ((visual->class | DynamicClass) == DirectColor) {
-	    visual->offsetRed = pScrn->offset.red;
-	    visual->offsetGreen = pScrn->offset.green;
-	    visual->offsetBlue = pScrn->offset.blue;
-	    visual->redMask = pScrn->mask.red;
-	    visual->greenMask = pScrn->mask.green;
-	    visual->blueMask = pScrn->mask.blue;
-	 }
-      }
-   }
-
-   fbPictureInit(pScreen, NULL, 0);
+    if (!fbScreenInit(pScreen, fbstart,
+		      pScrn->virtualX, pScrn->virtualY,
+		      pScrn->xDpi, pScrn->yDpi,
+		      pScrn->displayWidth, pScrn->bitsPerPixel))
+	return FALSE;
+
+    if (pScrn->bitsPerPixel > 8) {
+	/* Fixup RGB ordering */
+	visual = pScreen->visuals + pScreen->numVisuals;
+	while (--visual >= pScreen->visuals) {
+	    if ((visual->class | DynamicClass) == DirectColor) {
+		visual->offsetRed = pScrn->offset.red;
+		visual->offsetGreen = pScrn->offset.green;
+		visual->offsetBlue = pScrn->offset.blue;
+		visual->redMask = pScrn->mask.red;
+		visual->greenMask = pScrn->mask.green;
+		visual->blueMask = pScrn->mask.blue;
+	    }
+	}
+    }
+
+    fbPictureInit(pScreen, NULL, 0);
     if (ms->shadowFB) {
 	ms->update = shadowUpdatePackedWeak();
 	if (!shadowSetup(pScreen)) {
 	    xf86DrvMsg(scrnIndex, X_ERROR,
 		       "Shadow framebuffer initialization failed.\n");
-	 	return FALSE;
+	    return FALSE;
 	}
 
 	ms->createScreenResources = pScreen->CreateScreenResources;
 	pScreen->CreateScreenResources = CreateScreenResources;
     }
 
-   xf86SetBlackWhitePixels(pScreen);
+    xf86SetBlackWhitePixels(pScreen);
 
 #if 0
-   glucoseScreenInit(pScreen, 0);
+    glucoseScreenInit(pScreen, 0);
 #endif
 #if 0
-   ms->pExa = ExaInit(pScreen);
+    ms->pExa = ExaInit(pScreen);
 #endif
 
-   miInitializeBackingStore(pScreen);
-   xf86SetBackingStore(pScreen);
-   xf86SetSilkenMouse(pScreen);
-   miDCInitialize(pScreen, xf86GetPointerScreenFuncs());
+    miInitializeBackingStore(pScreen);
+    xf86SetBackingStore(pScreen);
+    xf86SetSilkenMouse(pScreen);
+    miDCInitialize(pScreen, xf86GetPointerScreenFuncs());
 
-   /* Must force it before EnterVT, so we are in control of VT and
-    * later memory should be bound when allocating, e.g rotate_mem */
-   pScrn->vtSema = TRUE;
+    /* Must force it before EnterVT, so we are in control of VT and
+     * later memory should be bound when allocating, e.g rotate_mem */
+    pScrn->vtSema = TRUE;
 
-   pScreen->SaveScreen = xf86SaveScreen;
-   ms->CloseScreen = pScreen->CloseScreen;
-   pScreen->CloseScreen = CloseScreen;
+    pScreen->SaveScreen = xf86SaveScreen;
+    ms->CloseScreen = pScreen->CloseScreen;
+    pScreen->CloseScreen = CloseScreen;
 
-   if (!xf86CrtcScreenInit(pScreen))
-      return FALSE;
+    if (!xf86CrtcScreenInit(pScreen))
+	return FALSE;
 
-   if (!miCreateDefColormap(pScreen))
-      return FALSE;
+    if (!miCreateDefColormap(pScreen))
+	return FALSE;
 
 #if 0
-   if (!xf86HandleColormaps(pScreen, 256, 8, LoadPalette, NULL,
-			    CMAP_RELOAD_ON_MODE_SWITCH |
-			    CMAP_PALETTED_TRUECOLOR)) {
-      return FALSE;
-   }
+    if (!xf86HandleColormaps(pScreen, 256, 8, LoadPalette, NULL,
+			     CMAP_RELOAD_ON_MODE_SWITCH |
+			     CMAP_PALETTED_TRUECOLOR)) {
+	return FALSE;
+    }
 #endif
 
-   xf86DPMSInit(pScreen, xf86DPMSSet, 0);
+    xf86DPMSInit(pScreen, xf86DPMSSet, 0);
 
 #if 0
-   glucoseInitVideo(pScreen);
+    glucoseInitVideo(pScreen);
 #endif
 
-   if (serverGeneration == 1)
-      xf86ShowUnusedOptions(pScrn->scrnIndex, pScrn->options);
+    if (serverGeneration == 1)
+	xf86ShowUnusedOptions(pScrn->scrnIndex, pScrn->options);
 
-   return EnterVT(scrnIndex, 0);
+    return EnterVT(scrnIndex, 0);
 }
 
 static void
 AdjustFrame(int scrnIndex, int x, int y, int flags)
 {
-   ScrnInfoPtr pScrn = xf86Screens[scrnIndex];
-   xf86CrtcConfigPtr config = XF86_CRTC_CONFIG_PTR(pScrn);
-   xf86OutputPtr output = config->output[config->compat_output];
-   xf86CrtcPtr crtc = output->crtc;
-
-   if (crtc && crtc->enabled) {
-      crtc->funcs->mode_set(crtc, pScrn->currentMode, pScrn->currentMode, x, y);
-      crtc->x = output->initial_x + x;
-      crtc->y = output->initial_y + y;
-   }
+    ScrnInfoPtr pScrn = xf86Screens[scrnIndex];
+    xf86CrtcConfigPtr config = XF86_CRTC_CONFIG_PTR(pScrn);
+    xf86OutputPtr output = config->output[config->compat_output];
+    xf86CrtcPtr crtc = output->crtc;
+
+    if (crtc && crtc->enabled) {
+	crtc->funcs->mode_set(crtc, pScrn->currentMode, pScrn->currentMode, x,
+			      y);
+	crtc->x = output->initial_x + x;
+	crtc->y = output->initial_y + y;
+    }
 }
 
 static void
 FreeScreen(int scrnIndex, int flags)
 {
-   FreeRec(xf86Screens[scrnIndex]);
+    FreeRec(xf86Screens[scrnIndex]);
 }
 
 static void
 LeaveVT(int scrnIndex, int flags)
 {
-   ScrnInfoPtr pScrn = xf86Screens[scrnIndex];
-   modesettingPtr ms = modesettingPTR(pScrn);
-   xf86CrtcConfigPtr config = XF86_CRTC_CONFIG_PTR(pScrn);
-   int o;
-
-   for (o = 0; o < config->num_crtc; o++) {
-      xf86CrtcPtr crtc = config->crtc[o];
-
-      if (crtc->rotatedPixmap || crtc->rotatedData) {
-	 crtc->funcs->shadow_destroy(crtc, crtc->rotatedPixmap,
-				     crtc->rotatedData);
-	 crtc->rotatedPixmap = NULL;
-	 crtc->rotatedData = NULL;
-      }
-   }
+    ScrnInfoPtr pScrn = xf86Screens[scrnIndex];
+    modesettingPtr ms = modesettingPTR(pScrn);
+    xf86CrtcConfigPtr config = XF86_CRTC_CONFIG_PTR(pScrn);
+    int o;
+
+    for (o = 0; o < config->num_crtc; o++) {
+	xf86CrtcPtr crtc = config->crtc[o];
+
+	if (crtc->rotatedPixmap || crtc->rotatedData) {
+	    crtc->funcs->shadow_destroy(crtc, crtc->rotatedPixmap,
+					crtc->rotatedData);
+	    crtc->rotatedPixmap = NULL;
+	    crtc->rotatedData = NULL;
+	}
+    }
 
-   xf86_hide_cursors(pScrn);
+    xf86_hide_cursors(pScrn);
 
-   drmMMLock(ms->fd, DRM_BO_MEM_VRAM, 1, 0);
+    drmMMLock(ms->fd, DRM_BO_MEM_VRAM, 1, 0);
 
-   RestoreHWState(pScrn);
+    RestoreHWState(pScrn);
 }
 
 /*
@@ -953,76 +960,76 @@ LeaveVT(int scrnIndex, int flags)
 static Bool
 EnterVT(int scrnIndex, int flags)
 {
-   ScrnInfoPtr pScrn = xf86Screens[scrnIndex];
-   modesettingPtr ms = modesettingPTR(pScrn);
+    ScrnInfoPtr pScrn = xf86Screens[scrnIndex];
+    modesettingPtr ms = modesettingPTR(pScrn);
 
-   /*
-    * Only save state once per server generation since that's what most
-    * drivers do.  Could change this to save state at each VT enter.
-    */
-   if (ms->SaveGeneration != serverGeneration) {
-      ms->SaveGeneration = serverGeneration;
-      SaveHWState(pScrn);
-   }
+    /*
+     * Only save state once per server generation since that's what most
+     * drivers do.  Could change this to save state at each VT enter.
+     */
+    if (ms->SaveGeneration != serverGeneration) {
+	ms->SaveGeneration = serverGeneration;
+	SaveHWState(pScrn);
+    }
 
-   drmMMUnlock(ms->fd, DRM_BO_MEM_VRAM, 1);
+    drmMMUnlock(ms->fd, DRM_BO_MEM_VRAM, 1);
 
-   if (!xf86SetDesiredModes(pScrn))
-      return FALSE;
+    if (!xf86SetDesiredModes(pScrn))
+	return FALSE;
 
-   AdjustFrame(pScrn->scrnIndex, pScrn->frameX0, pScrn->frameY0, 0);
+    AdjustFrame(pScrn->scrnIndex, pScrn->frameX0, pScrn->frameY0, 0);
 
-   return TRUE;
+    return TRUE;
 }
 
 static Bool
 SwitchMode(int scrnIndex, DisplayModePtr mode, int flags)
 {
-   ScrnInfoPtr pScrn = xf86Screens[scrnIndex];
+    ScrnInfoPtr pScrn = xf86Screens[scrnIndex];
 
-   return xf86SetSingleMode(pScrn, mode, RR_Rotate_0);
+    return xf86SetSingleMode(pScrn, mode, RR_Rotate_0);
 }
 
 static Bool
 CloseScreen(int scrnIndex, ScreenPtr pScreen)
 {
-   ScrnInfoPtr pScrn = xf86Screens[scrnIndex];
-   modesettingPtr ms = modesettingPTR(pScrn);
+    ScrnInfoPtr pScrn = xf86Screens[scrnIndex];
+    modesettingPtr ms = modesettingPTR(pScrn);
 
-   if (pScrn->vtSema == TRUE) {
-      LeaveVT(scrnIndex, 0);
-      drmMMUnlock(ms->fd, DRM_BO_MEM_VRAM, 1);
-   }
+    if (pScrn->vtSema == TRUE) {
+	LeaveVT(scrnIndex, 0);
+	drmMMUnlock(ms->fd, DRM_BO_MEM_VRAM, 1);
+    }
 
-   UnmapMem(pScrn);
+    UnmapMem(pScrn);
 
-   if (ms->shadowFB)
-      pScreen->CreateScreenResources = ms->createScreenResources;
+    if (ms->shadowFB)
+	pScreen->CreateScreenResources = ms->createScreenResources;
 
-   if (ms->shadowMem) {
-      xfree(ms->shadowMem);
-      ms->shadowMem = NULL;
-   }
+    if (ms->shadowMem) {
+	xfree(ms->shadowMem);
+	ms->shadowMem = NULL;
+    }
 
-   if (ms->pExa)
-      ExaClose(pScrn);
+    if (ms->pExa)
+	ExaClose(pScrn);
 
-   /* move old buffer out of the way */
-   drmBOSetStatus(ms->fd, &ms->bo, DRM_BO_FLAG_READ | DRM_BO_FLAG_MEM_LOCAL,
-   				   DRM_BO_MASK_MEM | DRM_BO_FLAG_NO_EVICT,
-				   DRM_BO_HINT_DONT_FENCE, 0, 0);
+    /* move old buffer out of the way */
+    drmBOSetStatus(ms->fd, &ms->bo, DRM_BO_FLAG_READ | DRM_BO_FLAG_MEM_LOCAL,
+		   DRM_BO_MASK_MEM | DRM_BO_FLAG_NO_EVICT,
+		   DRM_BO_HINT_DONT_FENCE, 0, 0);
 
-   drmBOUnreference(ms->fd, &ms->bo);
+    drmBOUnreference(ms->fd, &ms->bo);
 
-   drmClose(ms->fd);
+    drmClose(ms->fd);
 
-   pScrn->vtSema = FALSE;
-   pScreen->CloseScreen = ms->CloseScreen;
-   return (*pScreen->CloseScreen) (scrnIndex, pScreen);
+    pScrn->vtSema = FALSE;
+    pScreen->CloseScreen = ms->CloseScreen;
+    return (*pScreen->CloseScreen) (scrnIndex, pScreen);
 }
 
 static ModeStatus
 ValidMode(int scrnIndex, DisplayModePtr mode, Bool verbose, int flags)
 {
-   return MODE_OK;
+    return MODE_OK;
 }
diff --git a/hw/xfree86/drivers/modesetting/driver.h b/hw/xfree86/drivers/modesetting/driver.h
index 2a09903..c9cb764 100644
--- a/hw/xfree86/drivers/modesetting/driver.h
+++ b/hw/xfree86/drivers/modesetting/driver.h
@@ -36,53 +36,55 @@
 
 #define DRV_ERROR(msg)	xf86DrvMsg(pScrn->scrnIndex, X_ERROR, msg);
 
-typedef struct {
-   int            lastInstance;
-   int            refCount;
-   ScrnInfoPtr    pScrn_1;
-   ScrnInfoPtr    pScrn_2;
+typedef struct
+{
+    int lastInstance;
+    int refCount;
+    ScrnInfoPtr pScrn_1;
+    ScrnInfoPtr pScrn_2;
 } EntRec, *EntPtr;
 
-typedef struct _modesettingRec {
-   int fd;
-   unsigned int fb_id;
-   void *virtual;
-   drmBO bo;
+typedef struct _modesettingRec
+{
+    int fd;
+    unsigned int fb_id;
+    void *virtual;
+    drmBO bo;
 
-   EntPtr entityPrivate;	
+    EntPtr entityPrivate;
 
-   void (*PointerMoved)(int, int, int);
+    void (*PointerMoved) (int, int, int);
 
-   int Chipset;
-   EntityInfoPtr pEnt;
+    int Chipset;
+    EntityInfoPtr pEnt;
 #if XSERVER_LIBPCIACCESS
-   struct pci_device *PciInfo;
+    struct pci_device *PciInfo;
 #else
-   pciVideoPtr PciInfo;
-   PCITAG PciTag;
+    pciVideoPtr PciInfo;
+    PCITAG PciTag;
 #endif
 
-   Bool noAccel;
-   Bool SWCursor;
-   CloseScreenProcPtr CloseScreen;
+    Bool noAccel;
+    Bool SWCursor;
+    CloseScreenProcPtr CloseScreen;
 
-   Bool directRenderingDisabled;	/* DRI disabled in PreInit. */
-   Bool directRenderingEnabled;		/* DRI enabled this generation. */
+    Bool directRenderingDisabled;      /* DRI disabled in PreInit. */
+    Bool directRenderingEnabled;       /* DRI enabled this generation. */
 
-   /* Broken-out options. */
-   OptionInfoPtr Options;
+    /* Broken-out options. */
+    OptionInfoPtr Options;
 
-   unsigned int SaveGeneration;
+    unsigned int SaveGeneration;
 
-   /* shadowfb */
-   CARD8 *shadowMem;
-   Bool shadowFB;
-   CreateScreenResourcesProcPtr createScreenResources;
-   ShadowUpdateProc update;
+    /* shadowfb */
+    CARD8 *shadowMem;
+    Bool shadowFB;
+    CreateScreenResourcesProcPtr createScreenResources;
+    ShadowUpdateProc update;
 
-   /* exa */
-   ExaDriverPtr pExa;
-   drmBO exa_bo;
+    /* exa */
+    ExaDriverPtr pExa;
+    drmBO exa_bo;
 } modesettingRec, *modesettingPtr;
 
 #define modesettingPTR(p) ((modesettingPtr)((p)->driverPrivate))
diff --git a/hw/xfree86/drivers/modesetting/exa.c b/hw/xfree86/drivers/modesetting/exa.c
index a9be2c1..70968f0 100644
--- a/hw/xfree86/drivers/modesetting/exa.c
+++ b/hw/xfree86/drivers/modesetting/exa.c
@@ -102,7 +102,7 @@ ExaSolid(PixmapPtr pPixmap, int x1, int y1, int x2, int y2)
 
 static Bool
 ExaPrepareCopy(PixmapPtr pSrcPixmap, PixmapPtr pDstPixmap, int xdir,
-		       int ydir, int alu, Pixel planeMask)
+	       int ydir, int alu, Pixel planeMask)
 {
     ScrnInfoPtr pScrn = xf86Screens[pDstPixmap->drawable.pScreen->myNum];
 
@@ -115,15 +115,15 @@ ExaPrepareCopy(PixmapPtr pSrcPixmap, PixmapPtr pDstPixmap, int xdir,
 
 static void
 ExaCopy(PixmapPtr pDstPixmap, int srcX, int srcY, int dstX, int dstY,
-		int width, int height)
+	int width, int height)
 {
     ScrnInfoPtr pScrn = xf86Screens[pDstPixmap->drawable.pScreen->myNum];
 }
 
 static Bool
 ExaPrepareComposite(int op, PicturePtr pSrcPicture,
-			    PicturePtr pMaskPicture, PicturePtr pDstPicture,
-			    PixmapPtr pSrc, PixmapPtr pMask, PixmapPtr pDst)
+		    PicturePtr pMaskPicture, PicturePtr pDstPicture,
+		    PixmapPtr pSrc, PixmapPtr pMask, PixmapPtr pDst)
 {
     ScreenPtr pScreen = pDst->drawable.pScreen;
     ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
@@ -133,7 +133,7 @@ ExaPrepareComposite(int op, PicturePtr pSrcPicture,
 
 static Bool
 ExaUploadToScreen(PixmapPtr pDst, int x, int y, int w, int h, char *src,
-		     int src_pitch)
+		  int src_pitch)
 {
     ScreenPtr pScreen = pDst->drawable.pScreen;
     ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
@@ -143,7 +143,7 @@ ExaUploadToScreen(PixmapPtr pDst, int x, int y, int w, int h, char *src,
 
 static void
 ExaComposite(PixmapPtr pDst, int srcX, int srcY, int maskX, int maskY,
-		     int dstX, int dstY, int width, int height)
+	     int dstX, int dstY, int width, int height)
 {
     ScreenPtr pScreen = pDst->drawable.pScreen;
     ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
@@ -151,8 +151,8 @@ ExaComposite(PixmapPtr pDst, int srcX, int srcY, int maskX, int maskY,
 
 static Bool
 ExaCheckComposite(int op,
-		     PicturePtr pSrcPicture, PicturePtr pMaskPicture,
-		     PicturePtr pDstPicture)
+		  PicturePtr pSrcPicture, PicturePtr pMaskPicture,
+		  PicturePtr pDstPicture)
 {
     DrawablePtr pDraw = pSrcPicture->pDrawable;
     int w = pDraw->width;
@@ -173,17 +173,17 @@ ExaPixmapIsOffscreen(PixmapPtr p)
 void
 ExaClose(ScrnInfoPtr pScrn)
 {
-   modesettingPtr ms = modesettingPTR(pScrn);
+    modesettingPtr ms = modesettingPTR(pScrn);
 
     exaDriverFini(pScrn->pScreen);
 
-   drmBOUnreference(ms->fd, &ms->exa_bo);
+    drmBOUnreference(ms->fd, &ms->exa_bo);
 }
 
 ExaDriverPtr
 ExaInit(ScrnInfoPtr pScrn)
 {
-   modesettingPtr ms = modesettingPTR(pScrn);
+    modesettingPtr ms = modesettingPTR(pScrn);
     ExaDriverPtr pExa;
 
     pExa = exaDriverAlloc();
@@ -192,7 +192,9 @@ ExaInit(ScrnInfoPtr pScrn)
     }
 
     /* Create a 256KB offscreen area */
-    drmBOCreate(ms->fd, 256 * 1024, 0, NULL, DRM_BO_FLAG_READ | DRM_BO_FLAG_WRITE | DRM_BO_FLAG_MEM_TT, DRM_BO_HINT_DONT_FENCE, &ms->exa_bo);
+    drmBOCreate(ms->fd, 256 * 1024, 0, NULL,
+		DRM_BO_FLAG_READ | DRM_BO_FLAG_WRITE | DRM_BO_FLAG_MEM_TT,
+		DRM_BO_HINT_DONT_FENCE, &ms->exa_bo);
 
     memset(pExa, 0, sizeof(*pExa));
     pExa->exa_major = 2;
@@ -203,8 +205,8 @@ ExaInit(ScrnInfoPtr pScrn)
     pExa->pixmapOffsetAlign = 8;
     pExa->pixmapPitchAlign = 32 * 4;
     pExa->flags = EXA_OFFSCREEN_PIXMAPS;
-    pExa->maxX = 8191; /* FIXME */
-    pExa->maxY = 8191; /* FIXME */
+    pExa->maxX = 8191;		       /* FIXME */
+    pExa->maxY = 8191;		       /* FIXME */
     pExa->WaitMarker = ExaWaitMarker;
     pExa->MarkSync = ExaMarkSync;
     pExa->PrepareSolid = ExaPrepareSolid;
diff --git a/hw/xfree86/drivers/modesetting/output.c b/hw/xfree86/drivers/modesetting/output.c
index b25540e..4a67ccc 100644
--- a/hw/xfree86/drivers/modesetting/output.c
+++ b/hw/xfree86/drivers/modesetting/output.c
@@ -69,20 +69,20 @@ restore(xf86OutputPtr output)
 static int
 mode_valid(xf86OutputPtr output, DisplayModePtr pMode)
 {
-   return MODE_OK;
+    return MODE_OK;
 }
 
 static Bool
 mode_fixup(xf86OutputPtr output, DisplayModePtr mode,
 	   DisplayModePtr adjusted_mode)
 {
-   return TRUE;
+    return TRUE;
 }
 
 static void
 prepare(xf86OutputPtr output)
 {
-   dpms(output, DPMSModeOff);
+    dpms(output, DPMSModeOff);
 }
 
 static void
@@ -94,69 +94,69 @@ mode_set(xf86OutputPtr output, DisplayModePtr mode,
 static void
 commit(xf86OutputPtr output)
 {
-   dpms(output, DPMSModeOn);
+    dpms(output, DPMSModeOn);
 
-   if (output->scrn->pScreen != NULL)
-      xf86_reload_cursors(output->scrn->pScreen);
+    if (output->scrn->pScreen != NULL)
+	xf86_reload_cursors(output->scrn->pScreen);
 }
 
 static xf86OutputStatus
 detect(xf86OutputPtr output)
 {
-   drmModeOutputPtr drm_output = output->driver_private;
-
-   switch (drm_output->connection) {
-   	case DRM_MODE_CONNECTED:
-	    return XF86OutputStatusConnected;
-	case DRM_MODE_DISCONNECTED:
-	    return XF86OutputStatusDisconnected;
-	default:
-	    return XF86OutputStatusUnknown;
-   }
+    drmModeOutputPtr drm_output = output->driver_private;
+
+    switch (drm_output->connection) {
+    case DRM_MODE_CONNECTED:
+	return XF86OutputStatusConnected;
+    case DRM_MODE_DISCONNECTED:
+	return XF86OutputStatusDisconnected;
+    default:
+	return XF86OutputStatusUnknown;
+    }
 }
 
 static DisplayModePtr
 get_modes(xf86OutputPtr output)
 {
-   drmModeOutputPtr drm_output = output->driver_private;
-   struct drm_mode_modeinfo *drm_mode = NULL;
-   DisplayModePtr modes = NULL, mode = NULL;
-   int i;
-
-   for (i = 0; i < drm_output->count_modes; i++) {
-      drm_mode = &drm_output->modes[i];
-      if (drm_mode) {
-	 mode = xcalloc(1, sizeof(DisplayModeRec));
-	 if (!mode)
-	    continue;
-	 mode->type = 0;
-	 mode->Clock = drm_mode->clock;
-	 mode->HDisplay = drm_mode->hdisplay;
-	 mode->HSyncStart = drm_mode->hsync_start;
-	 mode->HSyncEnd = drm_mode->hsync_end;
-	 mode->HTotal = drm_mode->htotal;
-	 mode->VDisplay = drm_mode->vdisplay;
-	 mode->VSyncStart = drm_mode->vsync_start;
-	 mode->VSyncEnd = drm_mode->vsync_end;
-	 mode->VTotal = drm_mode->vtotal;
-	 mode->Flags = drm_mode->flags;
-	 mode->HSkew = drm_mode->hskew;
-	 mode->VScan = drm_mode->vscan;
-	 mode->VRefresh = xf86ModeVRefresh(mode);
-	 mode->Private = (void *)drm_mode;
-	 xf86SetModeDefaultName(mode);
-	 modes = xf86ModesAdd(modes, mode);
-	 xf86PrintModeline(0, mode);
-      }
-   }
-
-   return modes;
+    drmModeOutputPtr drm_output = output->driver_private;
+    struct drm_mode_modeinfo *drm_mode = NULL;
+    DisplayModePtr modes = NULL, mode = NULL;
+    int i;
+
+    for (i = 0; i < drm_output->count_modes; i++) {
+	drm_mode = &drm_output->modes[i];
+	if (drm_mode) {
+	    mode = xcalloc(1, sizeof(DisplayModeRec));
+	    if (!mode)
+		continue;
+	    mode->type = 0;
+	    mode->Clock = drm_mode->clock;
+	    mode->HDisplay = drm_mode->hdisplay;
+	    mode->HSyncStart = drm_mode->hsync_start;
+	    mode->HSyncEnd = drm_mode->hsync_end;
+	    mode->HTotal = drm_mode->htotal;
+	    mode->VDisplay = drm_mode->vdisplay;
+	    mode->VSyncStart = drm_mode->vsync_start;
+	    mode->VSyncEnd = drm_mode->vsync_end;
+	    mode->VTotal = drm_mode->vtotal;
+	    mode->Flags = drm_mode->flags;
+	    mode->HSkew = drm_mode->hskew;
+	    mode->VScan = drm_mode->vscan;
+	    mode->VRefresh = xf86ModeVRefresh(mode);
+	    mode->Private = (void *)drm_mode;
+	    xf86SetModeDefaultName(mode);
+	    modes = xf86ModesAdd(modes, mode);
+	    xf86PrintModeline(0, mode);
+	}
+    }
+
+    return modes;
 }
 
 static void
 destroy(xf86OutputPtr output)
 {
-   drmModeFreeOutput(output->driver_private);
+    drmModeFreeOutput(output->driver_private);
 }
 
 static void
@@ -170,7 +170,7 @@ create_resources(xf86OutputPtr output)
 static Bool
 set_property(xf86OutputPtr output, Atom property, RRPropertyValuePtr value)
 {
-   return TRUE;
+    return TRUE;
 }
 #endif /* RANDR_12_INTERFACE */
 
@@ -178,7 +178,7 @@ set_property(xf86OutputPtr output, Atom property, RRPropertyValuePtr value)
 static Bool
 get_property(xf86OutputPtr output, Atom property)
 {
-   return TRUE;
+    return TRUE;
 }
 #endif /* RANDR_13_INTERFACE */
 
@@ -186,100 +186,102 @@ get_property(xf86OutputPtr output, Atom property)
 static xf86CrtcPtr
 get_crtc(xf86OutputPtr output)
 {
-   return NULL;
+    return NULL;
 }
 #endif
 
 static const xf86OutputFuncsRec output_funcs = {
-   .create_resources = create_resources,
-   .dpms = dpms,
-   .save = save,
-   .restore = restore,
-   .mode_valid = mode_valid,
-   .mode_fixup = mode_fixup,
-   .prepare = prepare,
-   .mode_set = mode_set,
-   .commit = commit,
-   .detect = detect,
-   .get_modes = get_modes,
+    .create_resources = create_resources,
+    .dpms = dpms,
+    .save = save,
+    .restore = restore,
+    .mode_valid = mode_valid,
+    .mode_fixup = mode_fixup,
+    .prepare = prepare,
+    .mode_set = mode_set,
+    .commit = commit,
+    .detect = detect,
+    .get_modes = get_modes,
 #ifdef RANDR_12_INTERFACE
-   .set_property = set_property,
+    .set_property = set_property,
 #endif
 #ifdef RANDR_13_INTERFACE
-   .get_property = get_property,
+    .get_property = get_property,
 #endif
-   .destroy = destroy,
+    .destroy = destroy,
 #ifdef RANDR_GET_CRTC_INTERFACE
-   .get_crtc = get_crtc,
+    .get_crtc = get_crtc,
 #endif
 };
 
 void
 output_init(ScrnInfoPtr pScrn)
 {
-   modesettingPtr ms = modesettingPTR(pScrn);
-   xf86OutputPtr output;
-   drmModeResPtr res;
-   drmModeOutputPtr drm_output = NULL;
-   drmModeCrtcPtr crtc;
-   char *name;
-   int o, v, p;
-
-   res = drmModeGetResources(ms->fd);
-   if (res == 0) {
-      DRV_ERROR("Failed drmModeGetResources\n");
-      return;
-   }
-
-   for (o = 0; o < res->count_outputs; o++) {
-      drm_output = drmModeGetOutput(ms->fd, res->outputs[o]);
-      if (!drm_output)
-         goto out;
-
-      for (p = 0; p < drm_output->count_props; p++) {
-	 drmModePropertyPtr prop;
-
-	 prop = drmModeGetProperty(ms->fd, drm_output->props[p]);
-
-	 name = NULL;
-	 if (prop) {
-	 ErrorF("VALUES %d\n",prop->count_values);
-
-	    for (v=0;v<prop->count_values;v++) 
-	    	ErrorF("%s %lld\n", prop->name, prop->values[v]);
-
-	    for (v=0;v<prop->count_enums;v++) {
-	    	ErrorF("%s %s\n", prop->name, prop->enums[v].name);
-		if (drm_output->prop_values[p] == prop->enums[v].value) {
-		if (!strncmp("Connector Type", prop->name, 14)) {
-			ErrorF("WE'VE GOT %s\n",prop->enums[v].name);
-			name = xalloc(strlen(prop->enums[v].name));
-			strncpy(name, prop->enums[v].name, strlen(name));
-		}
+    modesettingPtr ms = modesettingPTR(pScrn);
+    xf86OutputPtr output;
+    drmModeResPtr res;
+    drmModeOutputPtr drm_output = NULL;
+    drmModeCrtcPtr crtc;
+    char *name;
+    int o, v, p;
+
+    res = drmModeGetResources(ms->fd);
+    if (res == 0) {
+	DRV_ERROR("Failed drmModeGetResources\n");
+	return;
+    }
+
+    for (o = 0; o < res->count_outputs; o++) {
+	drm_output = drmModeGetOutput(ms->fd, res->outputs[o]);
+	if (!drm_output)
+	    goto out;
+
+	for (p = 0; p < drm_output->count_props; p++) {
+	    drmModePropertyPtr prop;
+
+	    prop = drmModeGetProperty(ms->fd, drm_output->props[p]);
+
+	    name = NULL;
+	    if (prop) {
+		ErrorF("VALUES %d\n", prop->count_values);
+
+		for (v = 0; v < prop->count_values; v++)
+		    ErrorF("%s %lld\n", prop->name, prop->values[v]);
+
+		for (v = 0; v < prop->count_enums; v++) {
+		    ErrorF("%s %s\n", prop->name, prop->enums[v].name);
+		    if (drm_output->prop_values[p] == prop->enums[v].value) {
+			if (!strncmp("Connector Type", prop->name, 14)) {
+			    ErrorF("WE'VE GOT %s\n", prop->enums[v].name);
+			    name = xalloc(strlen(prop->enums[v].name));
+			    strncpy(name, prop->enums[v].name, strlen(name));
+			}
+		    }
+		    if (name)
+			break;
 		}
-		if (name) break;
+		if (name)
+		    break;
 	    }
-	    if (name) break;
-	 }
-      }
+	}
 
-      if (!name)
-         continue;
+	if (!name)
+	    continue;
 
-      output = xf86OutputCreate(pScrn, &output_funcs, name);
-      if (!output)
-	 continue;
+	output = xf86OutputCreate(pScrn, &output_funcs, name);
+	if (!output)
+	    continue;
 
 	free(name);
 
-      output->possible_crtcs = drm_output->crtcs;
-      output->possible_clones = drm_output->clones;
-      output->driver_private = drm_output;
-      output->subpixel_order = SubPixelHorizontalRGB;
-      output->interlaceAllowed = FALSE;
-      output->doubleScanAllowed = FALSE;
-   }
+	output->possible_crtcs = drm_output->crtcs;
+	output->possible_clones = drm_output->clones;
+	output->driver_private = drm_output;
+	output->subpixel_order = SubPixelHorizontalRGB;
+	output->interlaceAllowed = FALSE;
+	output->doubleScanAllowed = FALSE;
+    }
 
-out:
-   drmModeFreeResources(res);
+  out:
+    drmModeFreeResources(res);
 }
commit 106bea5ad1bdd5795d6ed625fc6351a161bffa6e
Author: Alan Hourihane <alanh at tungstengraphics.com>
Date:   Wed May 28 13:33:07 2008 +0100

    Initial commit of new modesetting driver

diff --git a/hw/xfree86/drivers/modesetting/COPYING b/hw/xfree86/drivers/modesetting/COPYING
new file mode 100644
index 0000000..7f33cbf
--- /dev/null
+++ b/hw/xfree86/drivers/modesetting/COPYING
@@ -0,0 +1,12 @@
+This is a stub file.  This package has not yet had its complete licensing
+information compiled.  Please see the individual source files for details on
+your rights to use and modify this software.
+
+Please submit updated COPYING files to the Xorg bugzilla:
+
+https://bugs.freedesktop.org/enter_bug.cgi?product=xorg
+
+All licensing questions regarding this software should be directed at the
+Xorg mailing list:
+
+http://lists.freedesktop.org/mailman/listinfo/xorg
diff --git a/hw/xfree86/drivers/modesetting/Makefile.am b/hw/xfree86/drivers/modesetting/Makefile.am
new file mode 100644
index 0000000..17d884f
--- /dev/null
+++ b/hw/xfree86/drivers/modesetting/Makefile.am
@@ -0,0 +1,42 @@
+#  Copyright 2005 Adam Jackson.
+#
+#  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
+#  on 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
+#  ADAM JACKSON 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.
+SUBDIRS = 
+
+# this is obnoxious:
+# -module lets us name the module exactly how we want
+# -avoid-version prevents gratuitous .0.0.0 version numbers on the end
+# _ladir passes a dummy rpath to libtool so the thing will actually link
+# TODO: -nostdlib/-Bstatic/-lgcc platform magic, not installing the .a, etc.
+
+AM_CFLAGS = @WARN_CFLAGS@ @XORG_CFLAGS@ @DRI_CFLAGS@ @PCIACCESS_CFLAGS@ \
+	@XMODES_CFLAGS@
+
+modesetting_drv_la_LTLIBRARIES = modesetting_drv.la
+modesetting_drv_la_LDFLAGS = -module -avoid-version -ldrm
+modesetting_drv_ladir = @moduledir@/drivers
+
+modesetting_drv_la_SOURCES = \
+	 driver.c \
+	 driver.h \
+	 output.c \
+	 crtc.c \
+	 exa.c
+
+EXTRA_DIST =
diff --git a/hw/xfree86/drivers/modesetting/crtc.c b/hw/xfree86/drivers/modesetting/crtc.c
new file mode 100644
index 0000000..f168126
--- /dev/null
+++ b/hw/xfree86/drivers/modesetting/crtc.c
@@ -0,0 +1,215 @@
+/*
+ * Copyright 2008 Tungsten Graphics, 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 TUNGSTEN GRAPHICS 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.
+ *
+ *
+ * Author: Alan Hourihane <alanh at tungstengraphics.com>
+ *
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <unistd.h>
+#include <string.h>
+#include <assert.h>
+#include <stdlib.h>
+#include <math.h>
+#include <stdint.h>
+
+#include <xf86.h>
+#include <xf86i2c.h>
+#include <xf86Crtc.h>
+#include "driver.h"
+#include "xf86Modes.h"
+
+#define DPMS_SERVER
+#include <X11/extensions/dpms.h>
+
+static void
+crtc_dpms(xf86CrtcPtr crtc, int mode)
+{
+   ScrnInfoPtr pScrn = crtc->scrn;
+
+   switch (mode) {
+   case DPMSModeOn:
+   case DPMSModeStandby:
+   case DPMSModeSuspend:
+      break;
+   case DPMSModeOff:
+      break;
+   }
+}
+
+static Bool
+crtc_lock(xf86CrtcPtr crtc)
+{
+   return FALSE;
+}
+
+static void
+crtc_unlock(xf86CrtcPtr crtc)
+{
+}
+
+static void
+crtc_prepare(xf86CrtcPtr crtc)
+{
+}
+
+static void
+crtc_commit(xf86CrtcPtr crtc)
+{
+}
+
+static Bool
+crtc_mode_fixup(xf86CrtcPtr crtc, DisplayModePtr mode,
+		DisplayModePtr adjusted_mode)
+{
+   return TRUE;
+}
+
+static void
+crtc_mode_set(xf86CrtcPtr crtc, DisplayModePtr mode,
+	      DisplayModePtr adjusted_mode, int x, int y)
+{
+   xf86CrtcConfigPtr config = XF86_CRTC_CONFIG_PTR(crtc->scrn);
+   modesettingPtr ms = modesettingPTR(crtc->scrn);
+   xf86OutputPtr output = config->output[config->compat_output];
+   drmModeOutputPtr drm_output = output->driver_private;
+   drmModeCrtcPtr drm_crtc = crtc->driver_private;
+   struct drm_mode_modeinfo drm_mode;
+
+   drm_mode.clock = mode->Clock;
+   drm_mode.hdisplay = mode->HDisplay;
+   drm_mode.hsync_start = mode->HSyncStart;
+   drm_mode.hsync_end = mode->HSyncEnd;
+   drm_mode.htotal = mode->HTotal;
+   drm_mode.vdisplay = mode->VDisplay;
+   drm_mode.vsync_start = mode->VSyncStart;
+   drm_mode.vsync_end = mode->VSyncEnd;
+   drm_mode.vtotal = mode->VTotal;
+   drm_mode.flags = mode->Flags;
+   drm_mode.hskew = mode->HSkew;
+   drm_mode.vscan = mode->VScan;
+   drm_mode.vrefresh = mode->VRefresh;
+   strncpy(drm_mode.name, mode->name, DRM_DISPLAY_MODE_LEN);
+
+   drmModeSetCrtc(ms->fd, drm_crtc->crtc_id, ms->fb_id, x, y,
+		     &drm_output->output_id, 1, &drm_mode);
+}
+
+void
+crtc_load_lut(xf86CrtcPtr crtc)
+{
+   ScrnInfoPtr pScrn = crtc->scrn;
+}
+
+static void
+crtc_gamma_set(xf86CrtcPtr crtc, CARD16 * red, CARD16 * green, CARD16 * blue,
+	       int size)
+{
+}
+
+static void *
+crtc_shadow_allocate(xf86CrtcPtr crtc, int width, int height)
+{
+   ScrnInfoPtr pScrn = crtc->scrn;
+
+   return NULL;
+}
+
+static PixmapPtr
+crtc_shadow_create(xf86CrtcPtr crtc, void *data, int width, int height)
+{
+   ScrnInfoPtr pScrn = crtc->scrn;
+
+   return NULL;
+}
+
+static void
+crtc_shadow_destroy(xf86CrtcPtr crtc, PixmapPtr rotate_pixmap, void *data)
+{
+   ScrnInfoPtr pScrn = crtc->scrn;
+}
+
+static void
+crtc_destroy(xf86CrtcPtr crtc)
+{
+   drmModeFreeCrtc(crtc->driver_private);
+}
+
+static const xf86CrtcFuncsRec crtc_funcs = {
+   .dpms = crtc_dpms,
+   .save = NULL,			/* XXX */
+   .restore = NULL,			/* XXX */
+   .lock = crtc_lock,
+   .unlock = crtc_unlock,
+   .mode_fixup = crtc_mode_fixup,
+   .prepare = crtc_prepare,
+   .mode_set = crtc_mode_set,
+   .commit = crtc_commit,
+   .gamma_set = crtc_gamma_set,
+   .shadow_create = crtc_shadow_create,
+   .shadow_allocate = crtc_shadow_allocate,
+   .shadow_destroy = crtc_shadow_destroy,
+//    .set_cursor_colors = crtc_set_cursor_colors,
+//    .set_cursor_position = crtc_set_cursor_position,
+//    .show_cursor = crtc_show_cursor,
+//    .hide_cursor = crtc_hide_cursor,
+//    .load_cursor_image = crtc_load_cursor_image, 
+//    .load_cursor_argb = crtc_load_cursor_argb,
+   .destroy = crtc_destroy,		/* XXX */
+};
+
+void
+crtc_init(ScrnInfoPtr pScrn)
+{
+   modesettingPtr ms = modesettingPTR(pScrn);
+   xf86CrtcPtr crtc;
+   drmModeResPtr res;
+   drmModeCrtcPtr drm_crtc = NULL;
+   int c, k, p;
+
+   res = drmModeGetResources(ms->fd);
+   if (res == 0) {
+      ErrorF("Failed drmModeGetResources %d\n",errno);
+      return;
+   }
+
+   for (c = 0; c < res->count_crtcs; c++) {
+      drm_crtc = drmModeGetCrtc(ms->fd, res->crtcs[c]);
+      if (!drm_crtc)
+	 continue;
+
+      crtc = xf86CrtcCreate(pScrn, &crtc_funcs);
+      if (crtc == NULL)
+	 goto out;
+
+      crtc->driver_private = drm_crtc;
+   }
+
+out:
+   drmModeFreeResources(res);
+}
diff --git a/hw/xfree86/drivers/modesetting/driver.c b/hw/xfree86/drivers/modesetting/driver.c
new file mode 100644
index 0000000..ba6bfdf
--- /dev/null
+++ b/hw/xfree86/drivers/modesetting/driver.c
@@ -0,0 +1,1028 @@
+/*
+ * Copyright 2008 Tungsten Graphics, 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 TUNGSTEN GRAPHICS 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.
+ *
+ *
+ * Author: Alan Hourihane <alanh at tungstengraphics.com>
+ *
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include "xf86.h"
+#include "xf86_OSproc.h"
+#include "compiler.h"
+#include "xf86RAC.h"
+#include "xf86PciInfo.h"
+#include "xf86Pci.h"
+#include "xf86Resources.h"
+#include "mipointer.h"
+#include "micmap.h"
+#include "shadowfb.h"
+#include <X11/extensions/randr.h>
+#include "fb.h"
+#include "edid.h"
+#include "xf86i2c.h"
+#include "xf86Crtc.h"
+#include "miscstruct.h"
+#include "dixstruct.h"
+#include "xf86xv.h"
+#include <X11/extensions/Xv.h>
+#include "shadow.h"
+#include <xorg-server.h>
+#if XSERVER_LIBPCIACCESS
+#include <pciaccess.h>
+#endif
+
+#include "driver.h"
+
+static void AdjustFrame(int scrnIndex, int x, int y, int flags);
+static Bool CloseScreen(int scrnIndex, ScreenPtr pScreen);
+static Bool EnterVT(int scrnIndex, int flags);
+static Bool SaveHWState(ScrnInfoPtr pScrn);
+static Bool RestoreHWState(ScrnInfoPtr pScrn);
+static void Identify(int flags);
+static const OptionInfoRec *AvailableOptions(int chipid, int busid);
+static ModeStatus ValidMode(int scrnIndex, DisplayModePtr mode, Bool verbose, int flags);
+static void FreeScreen(int scrnIndex, int flags);
+static void LeaveVT(int scrnIndex, int flags);
+static Bool SwitchMode(int scrnIndex, DisplayModePtr mode, int flags);
+static Bool ScreenInit(int scrnIndex, ScreenPtr pScreen, int argc, char **argv);
+static Bool PreInit(ScrnInfoPtr pScrn, int flags);
+#if XSERVER_LIBPCIACCESS
+static Bool
+pci_probe(DriverPtr driver,
+	  int entity_num, struct pci_device *device, intptr_t match_data);
+#else
+static Bool Probe(DriverPtr drv, int flags);
+#endif
+
+#if XSERVER_LIBPCIACCESS
+static const struct pci_id_match device_match[] = {
+   {0x8086, 0x2592, 0xffff, 0xffff, 0, 0, 0},
+   {0, 0, 0},
+};
+#endif
+
+_X_EXPORT DriverRec modesetting = {
+   1,
+   "modesetting",
+   Identify,
+#if XSERVER_LIBPCIACCESS
+   NULL,
+#else
+   Probe,
+#endif
+   AvailableOptions,
+   NULL,
+   0,
+   NULL,
+#if XSERVER_LIBPCIACCESS
+   device_match,
+   pci_probe
+#endif
+};
+
+static SymTabRec Chipsets[] = {
+   {0x2592, "Intel Graphics Device"},
+   {-1, NULL}
+};
+
+static PciChipsets PciDevices[] = {
+   {0x2592, 0x2592, RES_SHARED_VGA},
+   {-1, -1, RES_UNDEFINED}
+};
+
+typedef enum
+{
+   OPTION_NOACCEL,
+   OPTION_SW_CURSOR,
+   OPTION_SHADOWFB,
+} modesettingOpts;
+
+static const OptionInfoRec Options[] = {
+   {OPTION_NOACCEL, "NoAccel", OPTV_BOOLEAN, {0}, FALSE},
+   {OPTION_SW_CURSOR, "SWcursor", OPTV_BOOLEAN, {0}, FALSE},
+   {OPTION_SHADOWFB, "ShadowFB", OPTV_BOOLEAN, {0}, FALSE},
+   {-1, NULL, OPTV_NONE, {0}, FALSE}
+};
+
+static const char *fbSymbols[] = {
+   "fbPictureInit",
+   "fbScreenInit",
+   NULL
+};
+
+static const char *ddcSymbols[] = {
+   "xf86PrintEDID",
+   "xf86SetDDCproperties",
+   NULL
+};
+
+static const char *shadowSymbols[] = {
+    "shadowInit",
+    "shadowUpdatePackedWeak",
+    NULL
+};
+
+static const char *i2cSymbols[] = {
+   "xf86CreateI2CBusRec",
+   "xf86I2CBusInit",
+   NULL
+};
+
+int modesettingEntityIndex = -1;
+
+static MODULESETUPPROTO(Setup);
+
+static XF86ModuleVersionInfo VersRec = {
+   "modesetting",
+   MODULEVENDORSTRING,
+   MODINFOSTRING1,
+   MODINFOSTRING2,
+   XORG_VERSION_CURRENT,
+   PACKAGE_VERSION_MAJOR, PACKAGE_VERSION_MINOR, PACKAGE_VERSION_PATCHLEVEL,
+   ABI_CLASS_VIDEODRV,
+   ABI_VIDEODRV_VERSION,
+   MOD_CLASS_VIDEODRV,
+   {0, 0, 0, 0}
+};
+
+_X_EXPORT XF86ModuleData modesettingModuleData = { &VersRec, Setup, NULL };
+
+static pointer
+Setup(pointer module, pointer opts, int *errmaj, int *errmin)
+{
+   static Bool setupDone = 0;
+
+   /* This module should be loaded only once, but check to be sure.
+    */
+   if (!setupDone) {
+      setupDone = 1;
+      xf86AddDriver(&modesetting, module, HaveDriverFuncs);
+
+      /*
+       * Tell the loader about symbols from other modules that this module
+       * might refer to.
+       */
+      LoaderRefSymLists(fbSymbols,
+			shadowSymbols, ddcSymbols, NULL);
+
+      /*
+       * The return value must be non-NULL on success even though there
+       * is no TearDownProc.
+       */
+      return (pointer) 1;
+   } else {
+      if (errmaj)
+	 *errmaj = LDR_ONCEONLY;
+      return NULL;
+   }
+}
+
+static void
+Identify(int flags)
+{
+   xf86PrintChipsets("modesetting", "Driver for Modesetting Kernel Drivers",
+		     Chipsets);
+}
+
+static const OptionInfoRec *
+AvailableOptions(int chipid, int busid)
+{
+   return Options;
+}
+
+#if XSERVER_LIBPCIACCESS
+static Bool
+pci_probe(DriverPtr driver,
+	  int entity_num, struct pci_device *device, intptr_t match_data)
+{
+   ScrnInfoPtr scrn = NULL;
+   EntityInfoPtr entity;
+   DevUnion *private;
+
+   scrn = xf86ConfigPciEntity(scrn, 0, entity_num, PciDevices,
+			      NULL, NULL, NULL, NULL, NULL);
+   if (scrn != NULL) {
+      scrn->driverVersion = 1;
+      scrn->driverName = "modesetting";
+      scrn->name = "modesetting";
+      scrn->Probe = NULL;
+
+      entity = xf86GetEntityInfo(entity_num);
+
+      switch (device->device_id) {
+      case 0x2592:
+	 scrn->PreInit = PreInit;
+	 scrn->ScreenInit = ScreenInit;
+	 scrn->SwitchMode = SwitchMode;
+	 scrn->AdjustFrame = AdjustFrame;
+	 scrn->EnterVT = EnterVT;
+	 scrn->LeaveVT = LeaveVT;
+	 scrn->FreeScreen = FreeScreen;
+	 scrn->ValidMode = ValidMode;
+	 break;
+      }
+   }
+   return scrn != NULL;
+}
+#else
+static Bool
+Probe(DriverPtr drv, int flags)
+{
+   int i, numUsed, numDevSections, *usedChips;
+   EntPtr msEnt = NULL;
+   DevUnion *pPriv;
+   GDevPtr *devSections;
+   Bool foundScreen = FALSE;
+   pciVideoPtr *VideoInfo;
+   pciVideoPtr *ppPci;
+   int numDevs;
+
+   /*
+    * Find the config file Device sections that match this
+    * driver, and return if there are none.
+    */
+   if ((numDevSections =
+	xf86MatchDevice("modesetting", &devSections)) <= 0) {
+      return FALSE;
+   }
+
+   /*
+    * This probing is just checking the PCI data the server already
+    * collected.
+    */
+   if (!(VideoInfo = xf86GetPciVideoInfo()))
+      return FALSE;
+
+#if 0
+   numUsed = 0;
+   for (ppPci = VideoInfo; ppPci != NULL && *ppPci != NULL; ppPci++) {
+      for (numDevs = 0; numDevs < numDevSections; numDevs++) {
+         if (devSections[numDevs]->busID && *devSections[numDevs]->busID) {
+	 if (xf86ComparePciBusString(devSections[numDevs]->busID, (*ppPci)->bus, (*ppPci)->device, (*ppPci)->func)) {
+         /* Claim slot */
+         if (xf86CheckPciSlot((*ppPci)->bus, (*ppPci)->device,
+				    (*ppPci)->func)) {
+	    usedChips[numUsed++] = xf86ClaimPciSlot((*ppPci)->bus, (*ppPci)->device,
+				   (*ppPci)->func, drv, (*ppPci)->chipType,
+				   NULL, TRUE);
+				   ErrorF("CLAIMED %d %d %d\n",(*ppPci)->bus,(*ppPci)->device, (*ppPci)->func);
+	 }
+	 }
+	 }
+      }
+   }
+#else
+   /* Look for Intel i8xx devices. */
+   numUsed = xf86MatchPciInstances("modesetting", PCI_VENDOR_INTEL,
+				   Chipsets, PciDevices,
+				   devSections, numDevSections,
+				   drv, &usedChips);
+#endif
+
+   if (flags & PROBE_DETECT) {
+      if (numUsed > 0)
+	 foundScreen = TRUE;
+   } else {
+   ErrorF("NUMUSED %d\n",numUsed);
+      for (i = 0; i < numUsed; i++) {
+	 ScrnInfoPtr pScrn = NULL;
+
+	 /* Allocate new ScrnInfoRec and claim the slot */
+	 if ((pScrn = xf86ConfigPciEntity(pScrn, 0, usedChips[i],
+					  PciDevices, NULL, NULL, NULL,
+					  NULL, NULL))) {
+	    EntityInfoPtr pEnt;
+
+	    pEnt = xf86GetEntityInfo(usedChips[i]);
+
+	    pScrn->driverVersion = 1;
+	    pScrn->driverName = "modesetting";
+	    pScrn->name = "modesetting";
+	    pScrn->Probe = Probe;
+	    foundScreen = TRUE;
+	    {
+	       /* Allocate an entity private if necessary */
+	       if (modesettingEntityIndex < 0)
+		  modesettingEntityIndex = xf86AllocateEntityPrivateIndex();
+
+	       pPriv = xf86GetEntityPrivate(pScrn->entityList[0],
+					    modesettingEntityIndex);
+	       if (!pPriv->ptr) {
+		  pPriv->ptr = xnfcalloc(sizeof(EntRec), 1);
+		  msEnt = pPriv->ptr;
+		  msEnt->lastInstance = -1;
+	       } else {
+		  msEnt = pPriv->ptr;
+	       }
+
+	       /*
+	        * Set the entity instance for this instance of the driver.
+	        * For dual head per card, instance 0 is the "master"
+	        * instance, driving the primary head, and instance 1 is
+	        * the "slave".
+	        */
+	       msEnt->lastInstance++;
+	       xf86SetEntityInstanceForScreen(pScrn,
+					      pScrn->entityList[0],
+					      msEnt->lastInstance);
+	       pScrn->PreInit = PreInit;
+	       pScrn->ScreenInit = ScreenInit;
+	       pScrn->SwitchMode = SwitchMode;
+	       pScrn->AdjustFrame = AdjustFrame;
+	       pScrn->EnterVT = EnterVT;
+	       pScrn->LeaveVT = LeaveVT;
+	       pScrn->FreeScreen = FreeScreen;
+	       pScrn->ValidMode = ValidMode;
+	       break;
+	    }
+	 } else
+	 	ErrorF("FAILED PSCRN\n");
+      }
+   }
+
+   xfree(usedChips);
+   xfree(devSections);
+
+   return foundScreen;
+}
+#endif
+
+static Bool
+GetRec(ScrnInfoPtr pScrn)
+{
+   if (pScrn->driverPrivate)
+      return TRUE;
+
+   pScrn->driverPrivate = xnfcalloc(sizeof(modesettingRec), 1);
+
+   return TRUE;
+}
+
+static void
+FreeRec(ScrnInfoPtr pScrn)
+{
+   if (!pScrn)
+      return;
+
+   if (!pScrn->driverPrivate)
+      return;
+
+   xfree(pScrn->driverPrivate);
+
+   pScrn->driverPrivate = NULL;
+}
+
+static void
+ProbeDDC(ScrnInfoPtr pScrn, int index)
+{
+   ConfiguredMonitor = NULL;
+}
+
+static Bool
+MapMem(ScrnInfoPtr pScrn)
+{
+   modesettingPtr ms = modesettingPTR(pScrn);
+
+   drmBOMap(ms->fd,
+	    &ms->bo, DRM_BO_FLAG_READ | DRM_BO_FLAG_WRITE, 0, &ms->virtual);
+
+   return TRUE;
+}
+
+static Bool
+UnmapMem(ScrnInfoPtr pScrn)
+{
+   modesettingPtr ms = modesettingPTR(pScrn);
+
+   drmBOUnmap(ms->fd, &ms->bo);
+
+   return TRUE;
+}
+
+static void
+LoadPalette(ScrnInfoPtr pScrn, int numColors, int *indices,
+	    LOCO * colors, VisualPtr pVisual)
+{
+   xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(pScrn);
+}
+
+static Bool
+crtc_resize(ScrnInfoPtr pScrn, int width, int height)
+{
+   modesettingPtr ms = modesettingPTR(pScrn);
+   ScreenPtr pScreen = pScrn->pScreen;
+   PixmapPtr rootPixmap = pScreen->GetScreenPixmap(pScreen);
+   Bool fbAccessDisabled;
+   CARD8 *fbstart;
+
+   if (width == pScrn->virtualX && height == pScrn->virtualY)
+      return TRUE;
+
+   ErrorF("RESIZING TO %dx%d\n",width,height);
+
+   pScrn->virtualX = width;
+   pScrn->virtualY = height;
+   pScrn->displayWidth = (pScrn->virtualX + 63) & ~63;
+
+   if (ms->shadowMem) {
+      xfree(ms->shadowMem);
+      ms->shadowMem = NULL;
+   }
+
+   UnmapMem(pScrn);
+
+   /* move old buffer out of the way */
+   drmBOSetStatus(ms->fd, &ms->bo, DRM_BO_FLAG_READ | DRM_BO_FLAG_MEM_LOCAL,
+   				   DRM_BO_MASK_MEM | DRM_BO_FLAG_NO_EVICT,
+				   DRM_BO_HINT_DONT_FENCE, 0, 0);
+
+   /* unreference it */
+   drmBOUnreference(ms->fd, &ms->bo);
+
+   drmBOCreate(ms->fd,
+	       pScrn->virtualY * pScrn->displayWidth *
+	       pScrn->bitsPerPixel / 8, 0, NULL,
+	       DRM_BO_FLAG_READ | DRM_BO_FLAG_WRITE | DRM_BO_FLAG_SHAREABLE
+	       | DRM_BO_FLAG_NO_EVICT | DRM_BO_FLAG_MAPPABLE |
+	       DRM_BO_FLAG_MEM_VRAM | DRM_BO_FLAG_MEM_TT, DRM_BO_HINT_DONT_FENCE, &ms->bo);
+
+   MapMem(pScrn);
+
+   drmModeAddFB(ms->fd,
+		pScrn->virtualX,
+		pScrn->virtualY,
+		pScrn->depth,
+		pScrn->bitsPerPixel,
+		pScrn->displayWidth * pScrn->bitsPerPixel / 8,
+		ms->bo.handle, 
+		&ms->fb_id);
+
+    if (ms->shadowFB) {
+	if ((ms->shadowMem =
+	     shadowAlloc(pScrn->displayWidth, pScrn->virtualY,
+			 pScrn->bitsPerPixel)) == NULL) {
+	    xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
+		       "Allocation of shadow memory failed\n");
+		return FALSE;
+	}
+	fbstart = ms->shadowMem;
+    } else {
+	fbstart = ms->virtual;
+    }
+
+    /*
+     * If we are in a fb disabled state, the virtual address of the root
+     * pixmap should always be NULL, and it will be overwritten later
+     * if we try to set it to something.
+     *
+     * Therefore, set it to NULL, and modify the backup copy instead.
+     */
+
+    fbAccessDisabled = (rootPixmap->devPrivate.ptr == NULL);
+
+    pScreen->ModifyPixmapHeader(rootPixmap,
+				pScrn->virtualX, pScrn->virtualY,
+				pScrn->depth, pScrn->bitsPerPixel,
+				pScrn->displayWidth * pScrn->bitsPerPixel / 8, 
+				fbstart);
+
+    if (fbAccessDisabled) {
+	pScrn->pixmapPrivate.ptr = fbstart;
+	rootPixmap->devPrivate.ptr = NULL;
+    }
+
+   pScrn->frameX0 = 0;
+   pScrn->frameY0 = 0;
+   AdjustFrame(pScrn->scrnIndex, pScrn->frameX0, pScrn->frameY0, 0);
+
+   return TRUE;
+}
+
+static const xf86CrtcConfigFuncsRec crtc_config_funcs = {
+   crtc_resize
+};
+
+static Bool
+PreInit(ScrnInfoPtr pScrn, int flags)
+{
+   xf86CrtcConfigPtr xf86_config;
+   modesettingPtr ms;
+   MessageType from = X_PROBED;
+   rgb defaultWeight = { 0, 0, 0 };
+   EntityInfoPtr pEnt;
+   EntPtr msEnt = NULL;
+   int flags24;
+   char *BusID;
+   int i;
+   char *s;
+   int num_pipe;
+   int max_width, max_height;
+
+   if (pScrn->numEntities != 1)
+      return FALSE;
+
+   pEnt = xf86GetEntityInfo(pScrn->entityList[0]);
+
+   if (flags & PROBE_DETECT) {
+      ProbeDDC(pScrn, pEnt->index);
+      return TRUE;
+   }
+
+   /* Allocate driverPrivate */
+   if (!GetRec(pScrn))
+      return FALSE;
+
+   ms = modesettingPTR(pScrn);
+   ms->SaveGeneration = -1;
+   ms->pEnt = pEnt;
+
+   pScrn->displayWidth = 640;		/* default it */
+
+   if (ms->pEnt->location.type != BUS_PCI)
+      return FALSE;
+
+   ms->PciInfo = xf86GetPciInfoForEntity(ms->pEnt->index);
+
+   /* Allocate an entity private if necessary */
+   if (xf86IsEntityShared(pScrn->entityList[0])) {
+      msEnt = xf86GetEntityPrivate(pScrn->entityList[0],
+				   modesettingEntityIndex)->ptr;
+      ms->entityPrivate = msEnt;
+   } else
+      ms->entityPrivate = NULL;
+
+   if (xf86RegisterResources(ms->pEnt->index, NULL, ResNone)) {
+      return FALSE;
+   }
+
+   if (xf86IsEntityShared(pScrn->entityList[0])) {
+      if (xf86IsPrimInitDone(pScrn->entityList[0])) {
+	 /* do something */
+      } else {
+	 xf86SetPrimInitDone(pScrn->entityList[0]);
+      }
+   }
+
+   BusID = xalloc(64);
+   sprintf(BusID, "PCI:%d:%d:%d",
+#if XSERVER_LIBPCIACCESS
+	   ((ms->PciInfo->domain << 8) | ms->PciInfo->bus),
+	   ms->PciInfo->dev, ms->PciInfo->func
+#else
+	   ((pciConfigPtr) ms->PciInfo->thisCard)->busnum,
+	   ((pciConfigPtr) ms->PciInfo->thisCard)->devnum,
+	   ((pciConfigPtr) ms->PciInfo->thisCard)->funcnum
+#endif
+	 );
+
+   ms->fd = drmOpen(NULL, BusID);
+
+   if (ms->fd < 0)
+      return FALSE;
+
+   pScrn->racMemFlags = RAC_FB | RAC_COLORMAP;
+   pScrn->monitor = pScrn->confScreen->monitor;
+   pScrn->progClock = TRUE;
+   pScrn->rgbBits = 8;
+
+   flags24 = Support32bppFb | PreferConvert24to32 | SupportConvert24to32;
+
+   if (!xf86SetDepthBpp(pScrn, 0, 0, 0, flags24))
+      return FALSE;
+
+   switch (pScrn->depth) {
+   case 8:
+   case 15:
+   case 16:
+   case 24:
+      break;
+   default:
+      xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
+		 "Given depth (%d) is not supported by the driver\n",
+		 pScrn->depth);
+      return FALSE;
+   }
+   xf86PrintDepthBpp(pScrn);
+
+   if (!xf86SetWeight(pScrn, defaultWeight, defaultWeight))
+      return FALSE;
+   if (!xf86SetDefaultVisual(pScrn, -1))
+      return FALSE;
+
+   /* Process the options */
+   xf86CollectOptions(pScrn, NULL);
+   if (!(ms->Options = xalloc(sizeof(Options))))
+      return FALSE;
+   memcpy(ms->Options, Options, sizeof(Options));
+   xf86ProcessOptions(pScrn->scrnIndex, pScrn->options, ms->Options);
+
+   /* Allocate an xf86CrtcConfig */
+   xf86CrtcConfigInit(pScrn, &crtc_config_funcs);
+   xf86_config = XF86_CRTC_CONFIG_PTR(pScrn);
+
+   max_width = 8192;
+   max_height = 8192;
+   xf86CrtcSetSizeRange(pScrn, 320, 200, max_width, max_height);
+
+   if (xf86ReturnOptValBool(ms->Options, OPTION_NOACCEL, FALSE)) {
+      ms->noAccel = TRUE;
+   }
+
+   if (xf86ReturnOptValBool(ms->Options, OPTION_SW_CURSOR, FALSE)) {
+      ms->SWCursor = TRUE;
+   }
+
+   if (xf86ReturnOptValBool(ms->Options, OPTION_SHADOWFB, FALSE)) {
+	if (!xf86LoadSubModule(pScrn, "shadow"))
+	    return FALSE;
+
+	xf86LoaderReqSymLists(shadowSymbols, NULL);
+
+	ms->shadowFB = TRUE;
+    }
+
+   SaveHWState(pScrn);
+
+   crtc_init(pScrn);
+   output_init(pScrn);
+
+   if (!xf86InitialConfiguration(pScrn, TRUE)) {
+      xf86DrvMsg(pScrn->scrnIndex, X_ERROR, "No valid modes.\n");
+      RestoreHWState(pScrn);
+      return FALSE;
+   }
+
+   RestoreHWState(pScrn);
+
+   /*
+    * If the driver can do gamma correction, it should call xf86SetGamma() here.
+    */
+   {
+      Gamma zeros = { 0.0, 0.0, 0.0 };
+
+      if (!xf86SetGamma(pScrn, zeros)) {
+	 return FALSE;
+      }
+   }
+
+   if (pScrn->modes == NULL) {
+      xf86DrvMsg(pScrn->scrnIndex, X_ERROR, "No modes.\n");
+      return FALSE;
+   }
+
+   pScrn->currentMode = pScrn->modes;
+
+   /* Set display resolution */
+   xf86SetDpi(pScrn, 0, 0);
+
+   /* Load the required sub modules */
+   if (!xf86LoadSubModule(pScrn, "fb")) {
+      return FALSE;
+   }
+
+   xf86LoaderReqSymLists(fbSymbols, NULL);
+
+   return TRUE;
+}
+
+static Bool
+SaveHWState(ScrnInfoPtr pScrn)
+{
+   xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(pScrn);
+
+   return TRUE;
+}
+
+static Bool
+RestoreHWState(ScrnInfoPtr pScrn)
+{
+   xf86CrtcConfigPtr config = XF86_CRTC_CONFIG_PTR(pScrn);
+
+   return TRUE;
+}
+
+static void *
+WindowLinear(ScreenPtr pScreen, CARD32 row, CARD32 offset, int mode,
+		CARD32 * size, void *closure)
+{
+   ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
+   modesettingPtr ms = modesettingPTR(pScrn);
+
+   if (!pScrn->vtSema)
+      return NULL;
+
+   *size = pScrn->displayWidth * pScrn->bitsPerPixel / 8;
+
+   return ((CARD8 *) ms->virtual + row * (*size) + offset);
+}
+
+static Bool
+CreateScreenResources(ScreenPtr pScreen)
+{
+   ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
+   modesettingPtr ms = modesettingPTR(pScrn);
+   Bool ret;
+
+   pScreen->CreateScreenResources = ms->createScreenResources;
+   ret = pScreen->CreateScreenResources(pScreen);
+   pScreen->CreateScreenResources = CreateScreenResources;
+
+   shadowAdd(pScreen, pScreen->GetScreenPixmap(pScreen),
+	      ms->update, WindowLinear, 0, 0);
+
+   return ret;
+}
+
+static Bool
+ScreenInit(int scrnIndex, ScreenPtr pScreen, int argc, char **argv)
+{
+   ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
+   modesettingPtr ms = modesettingPTR(pScrn);
+   VisualPtr visual;
+   unsigned long sys_mem;
+   int c;
+   MessageType from;
+   CARD8 *fbstart;
+
+   pScrn->displayWidth = (pScrn->virtualX + 63) & ~63;
+
+   miClearVisualTypes();
+
+   if (!miSetVisualTypes(pScrn->depth,
+			 miGetDefaultVisualMask(pScrn->depth),
+			 pScrn->rgbBits, pScrn->defaultVisual))
+      return FALSE;
+
+   if (!miSetPixmapDepths())
+      return FALSE;
+
+   if (!MapMem(pScrn))
+      return FALSE;
+
+   pScrn->memPhysBase = 0;
+   pScrn->fbOffset = 0;
+
+   drmBOCreate(ms->fd,
+	       pScrn->virtualY * pScrn->displayWidth *
+	       pScrn->bitsPerPixel / 8, 0, NULL,
+	       DRM_BO_FLAG_READ | DRM_BO_FLAG_WRITE | DRM_BO_FLAG_SHAREABLE
+	       | DRM_BO_FLAG_NO_EVICT | DRM_BO_FLAG_MAPPABLE |
+	       DRM_BO_FLAG_MEM_VRAM | DRM_BO_FLAG_MEM_TT, DRM_BO_HINT_DONT_FENCE, &ms->bo);
+
+   MapMem(pScrn);
+
+   drmModeAddFB(ms->fd,
+		pScrn->virtualX,
+		pScrn->virtualY,
+		pScrn->depth,
+		pScrn->bitsPerPixel,
+		pScrn->displayWidth * pScrn->bitsPerPixel / 8,
+		ms->bo.handle, 
+		&ms->fb_id);
+
+    if (ms->shadowFB) {
+	if ((ms->shadowMem =
+	     shadowAlloc(pScrn->displayWidth, pScrn->virtualY,
+			 pScrn->bitsPerPixel)) == NULL) {
+	    xf86DrvMsg(scrnIndex, X_ERROR,
+		       "Allocation of shadow memory failed\n");
+		return FALSE;
+	}
+	fbstart = ms->shadowMem;
+    } else {
+	fbstart = ms->virtual;
+    }
+
+   if (!fbScreenInit(pScreen, fbstart,
+		     pScrn->virtualX, pScrn->virtualY,
+		     pScrn->xDpi, pScrn->yDpi,
+		     pScrn->displayWidth, pScrn->bitsPerPixel))
+      return FALSE;
+
+   if (pScrn->bitsPerPixel > 8) {
+      /* Fixup RGB ordering */
+      visual = pScreen->visuals + pScreen->numVisuals;
+      while (--visual >= pScreen->visuals) {
+	 if ((visual->class | DynamicClass) == DirectColor) {
+	    visual->offsetRed = pScrn->offset.red;
+	    visual->offsetGreen = pScrn->offset.green;
+	    visual->offsetBlue = pScrn->offset.blue;
+	    visual->redMask = pScrn->mask.red;
+	    visual->greenMask = pScrn->mask.green;
+	    visual->blueMask = pScrn->mask.blue;
+	 }
+      }
+   }
+
+   fbPictureInit(pScreen, NULL, 0);
+    if (ms->shadowFB) {
+	ms->update = shadowUpdatePackedWeak();
+	if (!shadowSetup(pScreen)) {
+	    xf86DrvMsg(scrnIndex, X_ERROR,
+		       "Shadow framebuffer initialization failed.\n");
+	 	return FALSE;
+	}
+
+	ms->createScreenResources = pScreen->CreateScreenResources;
+	pScreen->CreateScreenResources = CreateScreenResources;
+    }
+
+   xf86SetBlackWhitePixels(pScreen);
+
+#if 0
+   glucoseScreenInit(pScreen, 0);
+#endif
+#if 0
+   ms->pExa = ExaInit(pScreen);
+#endif
+
+   miInitializeBackingStore(pScreen);
+   xf86SetBackingStore(pScreen);
+   xf86SetSilkenMouse(pScreen);
+   miDCInitialize(pScreen, xf86GetPointerScreenFuncs());
+
+   /* Must force it before EnterVT, so we are in control of VT and
+    * later memory should be bound when allocating, e.g rotate_mem */
+   pScrn->vtSema = TRUE;
+
+   pScreen->SaveScreen = xf86SaveScreen;
+   ms->CloseScreen = pScreen->CloseScreen;
+   pScreen->CloseScreen = CloseScreen;
+
+   if (!xf86CrtcScreenInit(pScreen))
+      return FALSE;
+
+   if (!miCreateDefColormap(pScreen))
+      return FALSE;
+
+#if 0
+   if (!xf86HandleColormaps(pScreen, 256, 8, LoadPalette, NULL,
+			    CMAP_RELOAD_ON_MODE_SWITCH |
+			    CMAP_PALETTED_TRUECOLOR)) {
+      return FALSE;
+   }
+#endif
+
+   xf86DPMSInit(pScreen, xf86DPMSSet, 0);
+
+#if 0
+   glucoseInitVideo(pScreen);
+#endif
+
+   if (serverGeneration == 1)
+      xf86ShowUnusedOptions(pScrn->scrnIndex, pScrn->options);
+
+   return EnterVT(scrnIndex, 0);
+}
+
+static void
+AdjustFrame(int scrnIndex, int x, int y, int flags)
+{
+   ScrnInfoPtr pScrn = xf86Screens[scrnIndex];
+   xf86CrtcConfigPtr config = XF86_CRTC_CONFIG_PTR(pScrn);
+   xf86OutputPtr output = config->output[config->compat_output];
+   xf86CrtcPtr crtc = output->crtc;
+
+   if (crtc && crtc->enabled) {
+      crtc->funcs->mode_set(crtc, pScrn->currentMode, pScrn->currentMode, x, y);
+      crtc->x = output->initial_x + x;
+      crtc->y = output->initial_y + y;
+   }
+}
+
+static void
+FreeScreen(int scrnIndex, int flags)
+{
+   FreeRec(xf86Screens[scrnIndex]);
+}
+
+static void
+LeaveVT(int scrnIndex, int flags)
+{
+   ScrnInfoPtr pScrn = xf86Screens[scrnIndex];
+   modesettingPtr ms = modesettingPTR(pScrn);
+   xf86CrtcConfigPtr config = XF86_CRTC_CONFIG_PTR(pScrn);
+   int o;
+
+   for (o = 0; o < config->num_crtc; o++) {
+      xf86CrtcPtr crtc = config->crtc[o];
+
+      if (crtc->rotatedPixmap || crtc->rotatedData) {
+	 crtc->funcs->shadow_destroy(crtc, crtc->rotatedPixmap,
+				     crtc->rotatedData);
+	 crtc->rotatedPixmap = NULL;
+	 crtc->rotatedData = NULL;
+      }
+   }
+
+   xf86_hide_cursors(pScrn);
+
+   drmMMLock(ms->fd, DRM_BO_MEM_VRAM, 1, 0);
+
+   RestoreHWState(pScrn);
+}
+
+/*
+ * This gets called when gaining control of the VT, and from ScreenInit().
+ */
+static Bool
+EnterVT(int scrnIndex, int flags)
+{
+   ScrnInfoPtr pScrn = xf86Screens[scrnIndex];
+   modesettingPtr ms = modesettingPTR(pScrn);
+
+   /*
+    * Only save state once per server generation since that's what most
+    * drivers do.  Could change this to save state at each VT enter.
+    */
+   if (ms->SaveGeneration != serverGeneration) {
+      ms->SaveGeneration = serverGeneration;
+      SaveHWState(pScrn);
+   }
+
+   drmMMUnlock(ms->fd, DRM_BO_MEM_VRAM, 1);
+
+   if (!xf86SetDesiredModes(pScrn))
+      return FALSE;
+
+   AdjustFrame(pScrn->scrnIndex, pScrn->frameX0, pScrn->frameY0, 0);
+
+   return TRUE;
+}
+
+static Bool
+SwitchMode(int scrnIndex, DisplayModePtr mode, int flags)
+{
+   ScrnInfoPtr pScrn = xf86Screens[scrnIndex];
+
+   return xf86SetSingleMode(pScrn, mode, RR_Rotate_0);
+}
+
+static Bool
+CloseScreen(int scrnIndex, ScreenPtr pScreen)
+{
+   ScrnInfoPtr pScrn = xf86Screens[scrnIndex];
+   modesettingPtr ms = modesettingPTR(pScrn);
+
+   if (pScrn->vtSema == TRUE) {
+      LeaveVT(scrnIndex, 0);
+      drmMMUnlock(ms->fd, DRM_BO_MEM_VRAM, 1);
+   }
+
+   UnmapMem(pScrn);
+
+   if (ms->shadowFB)
+      pScreen->CreateScreenResources = ms->createScreenResources;
+
+   if (ms->shadowMem) {
+      xfree(ms->shadowMem);
+      ms->shadowMem = NULL;
+   }
+
+   if (ms->pExa)
+      ExaClose(pScrn);
+
+   /* move old buffer out of the way */
+   drmBOSetStatus(ms->fd, &ms->bo, DRM_BO_FLAG_READ | DRM_BO_FLAG_MEM_LOCAL,
+   				   DRM_BO_MASK_MEM | DRM_BO_FLAG_NO_EVICT,
+				   DRM_BO_HINT_DONT_FENCE, 0, 0);
+
+   drmBOUnreference(ms->fd, &ms->bo);
+
+   drmClose(ms->fd);
+
+   pScrn->vtSema = FALSE;
+   pScreen->CloseScreen = ms->CloseScreen;
+   return (*pScreen->CloseScreen) (scrnIndex, pScreen);
+}
+
+static ModeStatus
+ValidMode(int scrnIndex, DisplayModePtr mode, Bool verbose, int flags)
+{
+   return MODE_OK;
+}
diff --git a/hw/xfree86/drivers/modesetting/driver.h b/hw/xfree86/drivers/modesetting/driver.h
new file mode 100644
index 0000000..2a09903
--- /dev/null
+++ b/hw/xfree86/drivers/modesetting/driver.h
@@ -0,0 +1,88 @@
+/*
+ * Copyright 2008 Tungsten Graphics, 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 TUNGSTEN GRAPHICS 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.
+ *
+ *
+ * Author: Alan Hourihane <alanh at tungstengraphics.com>
+ *
+ */
+
+#include <errno.h>
+#include <drm.h>
+#include <xf86drm.h>
+#include <xf86drmMode.h>
+#include "shadow.h"
+#include "exa.h"
+
+#define DRV_ERROR(msg)	xf86DrvMsg(pScrn->scrnIndex, X_ERROR, msg);
+
+typedef struct {
+   int            lastInstance;
+   int            refCount;
+   ScrnInfoPtr    pScrn_1;
+   ScrnInfoPtr    pScrn_2;
+} EntRec, *EntPtr;
+
+typedef struct _modesettingRec {
+   int fd;
+   unsigned int fb_id;
+   void *virtual;
+   drmBO bo;
+
+   EntPtr entityPrivate;	
+
+   void (*PointerMoved)(int, int, int);
+
+   int Chipset;
+   EntityInfoPtr pEnt;
+#if XSERVER_LIBPCIACCESS
+   struct pci_device *PciInfo;
+#else
+   pciVideoPtr PciInfo;
+   PCITAG PciTag;
+#endif
+
+   Bool noAccel;
+   Bool SWCursor;
+   CloseScreenProcPtr CloseScreen;
+
+   Bool directRenderingDisabled;	/* DRI disabled in PreInit. */
+   Bool directRenderingEnabled;		/* DRI enabled this generation. */
+
+   /* Broken-out options. */
+   OptionInfoPtr Options;
+
+   unsigned int SaveGeneration;
+
+   /* shadowfb */
+   CARD8 *shadowMem;
+   Bool shadowFB;
+   CreateScreenResourcesProcPtr createScreenResources;
+   ShadowUpdateProc update;
+
+   /* exa */
+   ExaDriverPtr pExa;
+   drmBO exa_bo;
+} modesettingRec, *modesettingPtr;
+
+#define modesettingPTR(p) ((modesettingPtr)((p)->driverPrivate))
diff --git a/hw/xfree86/drivers/modesetting/exa.c b/hw/xfree86/drivers/modesetting/exa.c
new file mode 100644
index 0000000..a9be2c1
--- /dev/null
+++ b/hw/xfree86/drivers/modesetting/exa.c
@@ -0,0 +1,235 @@
+/*
+ * Copyright 2008 Tungsten Graphics, 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 TUNGSTEN GRAPHICS 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.
+ *
+ *
+ * Author: Alan Hourihane <alanh at tungstengraphics.com>
+ *
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include "xf86.h"
+#include "xf86_OSproc.h"
+
+#include "driver.h"
+
+static void
+ExaWaitMarker(ScreenPtr pScreen, int marker)
+{
+}
+
+static int
+ExaMarkSync(ScreenPtr pScreen)
+{
+    /*
+     * See ExaWaitMarker.
+     */
+
+    return 1;
+}
+
+Bool
+ExaPrepareAccess(PixmapPtr pPix, int index)
+{
+    ScreenPtr pScreen = pPix->drawable.pScreen;
+    ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
+
+    return TRUE;
+}
+
+void
+ExaFinishAccess(PixmapPtr pPix, int index)
+{
+    ScreenPtr pScreen = pPix->drawable.pScreen;
+    ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
+}
+
+static void
+ExaDone(PixmapPtr pPixmap)
+{
+    ScrnInfoPtr pScrn = xf86Screens[pPixmap->drawable.pScreen->myNum];
+}
+
+static void
+ExaDoneComposite(PixmapPtr pPixmap)
+{
+    ScrnInfoPtr pScrn = xf86Screens[pPixmap->drawable.pScreen->myNum];
+}
+
+static Bool
+ExaPrepareSolid(PixmapPtr pPixmap, int alu, Pixel planeMask, Pixel fg)
+{
+    ScrnInfoPtr pScrn = xf86Screens[pPixmap->drawable.pScreen->myNum];
+
+    if (!EXA_PM_IS_SOLID(&pPixmap->drawable, planeMask))
+	return FALSE;
+
+    /* can't do depth 4 */
+    if (pPixmap->drawable.depth == 4)
+	return FALSE;
+
+    return TRUE;
+}
+
+static void
+ExaSolid(PixmapPtr pPixmap, int x1, int y1, int x2, int y2)
+{
+    ScrnInfoPtr pScrn = xf86Screens[pPixmap->drawable.pScreen->myNum];
+}
+
+static Bool
+ExaPrepareCopy(PixmapPtr pSrcPixmap, PixmapPtr pDstPixmap, int xdir,
+		       int ydir, int alu, Pixel planeMask)
+{
+    ScrnInfoPtr pScrn = xf86Screens[pDstPixmap->drawable.pScreen->myNum];
+
+    /* can't do depth 4 */
+    if (pSrcPixmap->drawable.depth == 4 || pDstPixmap->drawable.depth == 4)
+	return FALSE;
+
+    return TRUE;
+}
+
+static void
+ExaCopy(PixmapPtr pDstPixmap, int srcX, int srcY, int dstX, int dstY,
+		int width, int height)
+{
+    ScrnInfoPtr pScrn = xf86Screens[pDstPixmap->drawable.pScreen->myNum];
+}
+
+static Bool
+ExaPrepareComposite(int op, PicturePtr pSrcPicture,
+			    PicturePtr pMaskPicture, PicturePtr pDstPicture,
+			    PixmapPtr pSrc, PixmapPtr pMask, PixmapPtr pDst)
+{
+    ScreenPtr pScreen = pDst->drawable.pScreen;
+    ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
+
+    return FALSE;
+}
+
+static Bool
+ExaUploadToScreen(PixmapPtr pDst, int x, int y, int w, int h, char *src,
+		     int src_pitch)
+{
+    ScreenPtr pScreen = pDst->drawable.pScreen;
+    ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
+
+    return FALSE;
+}
+
+static void
+ExaComposite(PixmapPtr pDst, int srcX, int srcY, int maskX, int maskY,
+		     int dstX, int dstY, int width, int height)
+{
+    ScreenPtr pScreen = pDst->drawable.pScreen;
+    ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
+}
+
+static Bool
+ExaCheckComposite(int op,
+		     PicturePtr pSrcPicture, PicturePtr pMaskPicture,
+		     PicturePtr pDstPicture)
+{
+    DrawablePtr pDraw = pSrcPicture->pDrawable;
+    int w = pDraw->width;
+    int h = pDraw->height;
+
+    return TRUE;
+}
+
+static Bool
+ExaPixmapIsOffscreen(PixmapPtr p)
+{
+    ScreenPtr pScreen = p->drawable.pScreen;
+    ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
+
+    return FALSE;
+}
+
+void
+ExaClose(ScrnInfoPtr pScrn)
+{
+   modesettingPtr ms = modesettingPTR(pScrn);
+
+    exaDriverFini(pScrn->pScreen);
+
+   drmBOUnreference(ms->fd, &ms->exa_bo);
+}
+
+ExaDriverPtr
+ExaInit(ScrnInfoPtr pScrn)
+{
+   modesettingPtr ms = modesettingPTR(pScrn);
+    ExaDriverPtr pExa;
+
+    pExa = exaDriverAlloc();
+    if (!pExa) {
+	goto out_err;
+    }
+
+    /* Create a 256KB offscreen area */
+    drmBOCreate(ms->fd, 256 * 1024, 0, NULL, DRM_BO_FLAG_READ | DRM_BO_FLAG_WRITE | DRM_BO_FLAG_MEM_TT, DRM_BO_HINT_DONT_FENCE, &ms->exa_bo);
+
+    memset(pExa, 0, sizeof(*pExa));
+    pExa->exa_major = 2;
+    pExa->exa_minor = 2;
+    pExa->memoryBase = ms->exa_bo.virtual;
+    pExa->offScreenBase = 0;
+    pExa->memorySize = ms->exa_bo.size;
+    pExa->pixmapOffsetAlign = 8;
+    pExa->pixmapPitchAlign = 32 * 4;
+    pExa->flags = EXA_OFFSCREEN_PIXMAPS;
+    pExa->maxX = 8191; /* FIXME */
+    pExa->maxY = 8191; /* FIXME */
+    pExa->WaitMarker = ExaWaitMarker;
+    pExa->MarkSync = ExaMarkSync;
+    pExa->PrepareSolid = ExaPrepareSolid;
+    pExa->Solid = ExaSolid;
+    pExa->DoneSolid = ExaDone;
+    pExa->PrepareCopy = ExaPrepareCopy;
+    pExa->Copy = ExaCopy;
+    pExa->DoneCopy = ExaDone;
+    pExa->CheckComposite = ExaCheckComposite;
+    pExa->PrepareComposite = ExaPrepareComposite;
+    pExa->Composite = ExaComposite;
+    pExa->DoneComposite = ExaDoneComposite;
+    pExa->PixmapIsOffscreen = ExaPixmapIsOffscreen;
+    pExa->PrepareAccess = ExaPrepareAccess;
+    pExa->FinishAccess = ExaFinishAccess;
+    pExa->UploadToScreen = ExaUploadToScreen;
+
+    if (!exaDriverInit(pScrn->pScreen, pExa)) {
+	goto out_err;
+    }
+
+    return pExa;
+
+  out_err:
+    ExaClose(pScrn);
+
+    return NULL;
+}
diff --git a/hw/xfree86/drivers/modesetting/modesetting.man b/hw/xfree86/drivers/modesetting/modesetting.man
new file mode 100644
index 0000000..e69de29
diff --git a/hw/xfree86/drivers/modesetting/output.c b/hw/xfree86/drivers/modesetting/output.c
new file mode 100644
index 0000000..b25540e
--- /dev/null
+++ b/hw/xfree86/drivers/modesetting/output.c
@@ -0,0 +1,285 @@
+/*
+ * Copyright 2008 Tungsten Graphics, 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 TUNGSTEN GRAPHICS 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.
+ *
+ *
+ * Author: Alan Hourihane <alanh at tungstengraphics.com>
+ *
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <xf86.h>
+#include <xf86i2c.h>
+#include <xf86Crtc.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdint.h>
+#include <string.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+
+#define DPMS_SERVER
+#include <X11/extensions/dpms.h>
+
+#include "X11/Xatom.h"
+
+#include "driver.h"
+
+static void
+dpms(xf86OutputPtr output, int mode)
+{
+}
+
+static void
+save(xf86OutputPtr output)
+{
+}
+
+static void
+restore(xf86OutputPtr output)
+{
+}
+
+static int
+mode_valid(xf86OutputPtr output, DisplayModePtr pMode)
+{
+   return MODE_OK;
+}
+
+static Bool
+mode_fixup(xf86OutputPtr output, DisplayModePtr mode,
+	   DisplayModePtr adjusted_mode)
+{
+   return TRUE;
+}
+
+static void
+prepare(xf86OutputPtr output)
+{
+   dpms(output, DPMSModeOff);
+}
+
+static void
+mode_set(xf86OutputPtr output, DisplayModePtr mode,
+	 DisplayModePtr adjusted_mode)
+{
+}
+
+static void
+commit(xf86OutputPtr output)
+{
+   dpms(output, DPMSModeOn);
+
+   if (output->scrn->pScreen != NULL)
+      xf86_reload_cursors(output->scrn->pScreen);
+}
+
+static xf86OutputStatus
+detect(xf86OutputPtr output)
+{
+   drmModeOutputPtr drm_output = output->driver_private;
+
+   switch (drm_output->connection) {
+   	case DRM_MODE_CONNECTED:
+	    return XF86OutputStatusConnected;
+	case DRM_MODE_DISCONNECTED:
+	    return XF86OutputStatusDisconnected;
+	default:
+	    return XF86OutputStatusUnknown;
+   }
+}
+
+static DisplayModePtr
+get_modes(xf86OutputPtr output)
+{
+   drmModeOutputPtr drm_output = output->driver_private;
+   struct drm_mode_modeinfo *drm_mode = NULL;
+   DisplayModePtr modes = NULL, mode = NULL;
+   int i;
+
+   for (i = 0; i < drm_output->count_modes; i++) {
+      drm_mode = &drm_output->modes[i];
+      if (drm_mode) {
+	 mode = xcalloc(1, sizeof(DisplayModeRec));
+	 if (!mode)
+	    continue;
+	 mode->type = 0;
+	 mode->Clock = drm_mode->clock;
+	 mode->HDisplay = drm_mode->hdisplay;
+	 mode->HSyncStart = drm_mode->hsync_start;
+	 mode->HSyncEnd = drm_mode->hsync_end;
+	 mode->HTotal = drm_mode->htotal;
+	 mode->VDisplay = drm_mode->vdisplay;
+	 mode->VSyncStart = drm_mode->vsync_start;
+	 mode->VSyncEnd = drm_mode->vsync_end;
+	 mode->VTotal = drm_mode->vtotal;
+	 mode->Flags = drm_mode->flags;
+	 mode->HSkew = drm_mode->hskew;
+	 mode->VScan = drm_mode->vscan;
+	 mode->VRefresh = xf86ModeVRefresh(mode);
+	 mode->Private = (void *)drm_mode;
+	 xf86SetModeDefaultName(mode);
+	 modes = xf86ModesAdd(modes, mode);
+	 xf86PrintModeline(0, mode);
+      }
+   }
+
+   return modes;
+}
+
+static void
+destroy(xf86OutputPtr output)
+{
+   drmModeFreeOutput(output->driver_private);
+}
+
+static void
+create_resources(xf86OutputPtr output)
+{
+#ifdef RANDR_12_INTERFACE
+#endif /* RANDR_12_INTERFACE */
+}
+
+#ifdef RANDR_12_INTERFACE
+static Bool
+set_property(xf86OutputPtr output, Atom property, RRPropertyValuePtr value)
+{
+   return TRUE;
+}
+#endif /* RANDR_12_INTERFACE */
+
+#ifdef RANDR_13_INTERFACE
+static Bool
+get_property(xf86OutputPtr output, Atom property)
+{
+   return TRUE;
+}
+#endif /* RANDR_13_INTERFACE */
+
+#ifdef RANDR_GET_CRTC_INTERFACE
+static xf86CrtcPtr
+get_crtc(xf86OutputPtr output)
+{
+   return NULL;
+}
+#endif
+
+static const xf86OutputFuncsRec output_funcs = {
+   .create_resources = create_resources,
+   .dpms = dpms,
+   .save = save,
+   .restore = restore,
+   .mode_valid = mode_valid,
+   .mode_fixup = mode_fixup,
+   .prepare = prepare,
+   .mode_set = mode_set,
+   .commit = commit,
+   .detect = detect,
+   .get_modes = get_modes,
+#ifdef RANDR_12_INTERFACE
+   .set_property = set_property,
+#endif
+#ifdef RANDR_13_INTERFACE
+   .get_property = get_property,
+#endif
+   .destroy = destroy,
+#ifdef RANDR_GET_CRTC_INTERFACE
+   .get_crtc = get_crtc,
+#endif
+};
+
+void
+output_init(ScrnInfoPtr pScrn)
+{
+   modesettingPtr ms = modesettingPTR(pScrn);
+   xf86OutputPtr output;
+   drmModeResPtr res;
+   drmModeOutputPtr drm_output = NULL;
+   drmModeCrtcPtr crtc;
+   char *name;
+   int o, v, p;
+
+   res = drmModeGetResources(ms->fd);
+   if (res == 0) {
+      DRV_ERROR("Failed drmModeGetResources\n");
+      return;
+   }
+
+   for (o = 0; o < res->count_outputs; o++) {
+      drm_output = drmModeGetOutput(ms->fd, res->outputs[o]);
+      if (!drm_output)
+         goto out;
+
+      for (p = 0; p < drm_output->count_props; p++) {
+	 drmModePropertyPtr prop;
+
+	 prop = drmModeGetProperty(ms->fd, drm_output->props[p]);
+
+	 name = NULL;
+	 if (prop) {
+	 ErrorF("VALUES %d\n",prop->count_values);
+
+	    for (v=0;v<prop->count_values;v++) 
+	    	ErrorF("%s %lld\n", prop->name, prop->values[v]);
+
+	    for (v=0;v<prop->count_enums;v++) {
+	    	ErrorF("%s %s\n", prop->name, prop->enums[v].name);
+		if (drm_output->prop_values[p] == prop->enums[v].value) {
+		if (!strncmp("Connector Type", prop->name, 14)) {
+			ErrorF("WE'VE GOT %s\n",prop->enums[v].name);
+			name = xalloc(strlen(prop->enums[v].name));
+			strncpy(name, prop->enums[v].name, strlen(name));
+		}
+		}
+		if (name) break;
+	    }
+	    if (name) break;
+	 }
+      }
+
+      if (!name)
+         continue;
+
+      output = xf86OutputCreate(pScrn, &output_funcs, name);
+      if (!output)
+	 continue;
+
+	free(name);
+
+      output->possible_crtcs = drm_output->crtcs;
+      output->possible_clones = drm_output->clones;
+      output->driver_private = drm_output;
+      output->subpixel_order = SubPixelHorizontalRGB;
+      output->interlaceAllowed = FALSE;
+      output->doubleScanAllowed = FALSE;
+   }
+
+out:
+   drmModeFreeResources(res);
+}


More information about the Xquartz-changes mailing list