[Xquartz-changes] xserver: Branch 'server-1.15-apple' - 64 commits

Jeremy Huddleston jeremyhu at freedesktop.org
Wed Jan 1 11:12:47 PST 2014


Rebased ref, commits from common ancestor:
commit f3775fcc72ff3c6c6682101aa935509ac758fc22
Author: Jeremy Huddleston Sequoia <jeremyhu at apple.com>
Date:   Tue Dec 18 01:03:38 2012 -0800

    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"
    
    This reverts commit 9cbcb5bd6a5360a128d15b77a02d8d3351f74366.

diff --git a/fb/fb.h b/fb/fb.h
index 1c6963f..11e6344 100644
--- a/fb/fb.h
+++ b/fb/fb.h
@@ -1310,9 +1310,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 7c2ead5..dc0ca3c 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;
-    }
-}
-
-static void
-fbUnrealizeGlyph(ScreenPtr pScreen,
-		 GlyphPtr pGlyph)
-{
-    if (glyphCache)
-	pixman_glyph_cache_remove (glyphCache, pGlyph, NULL);
-}
-
-static 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 + xDst, ySrc + srcYoff + 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)
 {
@@ -469,8 +323,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->Trapezoids = fbTrapezoids;
diff --git a/fb/fbscreen.c b/fb/fbscreen.c
index f9080a4..7c7d656 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 eafdafd36119c607bdc060fd8768fbcca1e9c06d
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 26957df..1c6963f 100644
--- a/fb/fb.h
+++ b/fb/fb.h
@@ -1652,8 +1652,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 b503858..7c2ead5 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)
@@ -329,57 +326,31 @@ create_bits_picture(PicturePtr pict, Bool has_clip, int *xoff, int *yoff)
         if (pict->clientClipType != CT_NONE)
             pixman_image_set_has_client_clip(image, TRUE);
 
-        if (*xoff || *yoff)
-            pixman_region_translate(pict->pCompositeClip, *xoff, *yoff);
+        pixman_region_translate (pict->pCompositeClip, - pict->pDrawable->x, - pict->pDrawable->y);
 
         pixman_image_set_clip_region(image, pict->pCompositeClip);
 
-        if (*xoff || *yoff)
-            pixman_region_translate(pict->pCompositeClip, -*xoff, -*yoff);
+        pixman_region_translate (pict->pCompositeClip, pict->pDrawable->x, pict->pDrawable->y);
     }
 
     /* Indexed table */
     if (pict->pFormat->index.devPrivate)
         pixman_image_set_indexed(image, pict->pFormat->index.devPrivate);
 
-    /* Add in drawable origin to position within the image */
-    *xoff += pict->pDrawable->x;
-    *yoff += pict->pDrawable->y;
-
     return image;
 }
 
 static pixman_image_t *image_from_pict_internal(PicturePtr pict, Bool has_clip,
-                                                int *xoff, int *yoff,
                                                 Bool is_alpha_map);
 
 static void
-set_image_properties(pixman_image_t * image, PicturePtr pict, Bool has_clip,
-                     int *xoff, int *yoff, Bool is_alpha_map)
+set_image_properties(pixman_image_t * image, PicturePtr pict, Bool is_alpha_map)
 {
     pixman_repeat_t repeat;
     pixman_filter_t filter;
 
     if (pict->transform) {
-        /* For source images, adjust the transform to account
-         * for the drawable offset within the pixman image,
-         * then set the offset to 0 as it will be used
-         * to compute positions within the transformed image.
-         */
-        if (!has_clip) {
-            struct pixman_transform adjusted;
-
-            adjusted = *pict->transform;
-            pixman_transform_translate(&adjusted,
-                                       NULL,
-                                       pixman_int_to_fixed(*xoff),
-                                       pixman_int_to_fixed(*yoff));
-            pixman_image_set_transform(image, &adjusted);
-            *xoff = 0;
-            *yoff = 0;
-        }
-        else
-            pixman_image_set_transform(image, pict->transform);
+        pixman_image_set_transform(image, pict->transform);
     }
 
     switch (pict->repeatType) {
@@ -407,10 +378,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);
@@ -444,8 +413,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;
 
@@ -453,7 +421,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;
@@ -471,19 +439,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 193c16772db00199f7bd64dd2a19ecb1c0dc1b12
Author: Jeremy Huddleston <jeremyhu at apple.com>
Date:   Fri Apr 30 13:08:25 2010 -0700

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

diff --git a/mi/miexpose.c b/mi/miexpose.c
index 8b7c93f..3e972f7 100644
--- a/mi/miexpose.c
+++ b/mi/miexpose.c
@@ -489,7 +489,8 @@ void RootlessSetPixmapOfAncestors(WindowPtr pWin);
 void RootlessStartDrawing(WindowPtr pWin);
 void RootlessDamageRegion(WindowPtr pWin, RegionPtr prgn);
 Bool IsFramedWindow(WindowPtr pWin);
-#endif
+#include "../fb/fb.h"
+#endif 
 
 void
 miPaintWindow(WindowPtr pWin, RegionPtr prgn, int what)
@@ -518,23 +519,37 @@ miPaintWindow(WindowPtr pWin, RegionPtr prgn, int what)
     Bool solid = TRUE;
     DrawablePtr drawable = &pWin->drawable;
 
+#ifdef XQUARTZ_CLIP_DEBUG
+    ErrorF("START %d BS %d (pR = %ld)\n", what, pWin->backgroundState, ParentRelative);
+    ErrorF("      Rgn: %d %d %d %d\n", prgn->extents.x1, prgn->extents.y1,
+	                               prgn->extents.x2 - prgn->extents.x1,
+	                               prgn->extents.y2 - prgn->extents.y1);
+    ErrorF("      Win: %d %d (%d %d) %d %d\n", pWin->origin.x, pWin->origin.y,
+	                                       pWin->winSize.extents.x1, pWin->winSize.extents.y1,
+	                                       pWin->winSize.extents.x2 - pWin->winSize.extents.x1,
+					       pWin->winSize.extents.y2 - pWin->winSize.extents.y1);
+    ErrorF("     Draw: %d %d %d %d\n", pWin->drawable.x, pWin->drawable.y,
+				       pWin->drawable.width, pWin->drawable.height);
+#endif
+
 #ifdef ROOTLESS
     if (!drawable || drawable->type == UNDRAWABLE_WINDOW)
         return;
+#endif
+    
+    if (what == PW_BACKGROUND)
+    {
+#ifdef ROOTLESS
+        if(IsFramedWindow(pWin)) {
+            RootlessStartDrawing(pWin);
+            RootlessDamageRegion(pWin, prgn);
 
-    if (IsFramedWindow(pWin)) {
-        RootlessStartDrawing(pWin);
-        RootlessDamageRegion(pWin, prgn);
-
-        if (pWin->backgroundState == ParentRelative) {
-            if ((what == PW_BACKGROUND) ||
-                (what == PW_BORDER && !pWin->borderIsPixel))
+            if(pWin->backgroundState == ParentRelative) {
                 RootlessSetPixmapOfAncestors(pWin);
+            }
         }
-    }
 #endif
 
-    if (what == PW_BACKGROUND) {
         while (pWin->backgroundState == ParentRelative)
             pWin = pWin->parent;
 
@@ -559,6 +574,18 @@ miPaintWindow(WindowPtr pWin, RegionPtr prgn, int what)
     else {
         PixmapPtr pixmap;
 
+#ifdef ROOTLESS
+	if(IsFramedWindow(pWin)) {
+	    RootlessStartDrawing(pWin);
+	    RootlessDamageRegion(pWin, prgn);
+	    
+	    if(!pWin->borderIsPixel &&
+		pWin->backgroundState == ParentRelative) {
+		RootlessSetPixmapOfAncestors(pWin);
+	    }
+	}
+#endif
+
         tile_x_off = drawable->x;
         tile_y_off = drawable->y;
 
@@ -567,6 +594,12 @@ miPaintWindow(WindowPtr pWin, RegionPtr prgn, int what)
             return;
         pixmap = (*pScreen->GetWindowPixmap) ((WindowPtr) drawable);
         drawable = &pixmap->drawable;
+
+#ifdef XQUARTZ_CLIP_DEBUG
+        ErrorF("     Draw: %d %d %d %d\n",
+               drawable->x, drawable->y, drawable->width, drawable->height);    
+#endif
+	
 #ifdef COMPOSITE
         draw_x_off = pixmap->screen_x;
         draw_y_off = pixmap->screen_y;
@@ -629,6 +662,57 @@ miPaintWindow(WindowPtr pWin, RegionPtr prgn, int what)
     ChangeGC(NullClient, pGC, gcmask, gcval);
     ValidateGC(drawable, pGC);
 
+#ifdef XQUARTZ_CLIP_DEBUG
+    ErrorF("       GC: %d %d %d %d\n",
+	   pGC->pCompositeClip->extents.x1, pGC->pCompositeClip->extents.y1,
+	   pGC->pCompositeClip->extents.x2 - pGC->pCompositeClip->extents.x1,
+	   pGC->pCompositeClip->extents.y2 - pGC->pCompositeClip->extents.y1);
+#endif
+    
+#ifdef XQUARTZ
+    /* Looks like our clipping isn't set right for some reason:
+     * http://xquartz.macosforge.org/trac/ticket/290
+     */
+    if(what == PW_BORDER) {
+
+#if 0
+	if(solid) {
+#if 1
+	    fbFillRegionSolid(&pWin->drawable,
+			      prgn,
+			      0,
+			      fbReplicatePixel(fill.pixel,
+					       pWin->drawable.bitsPerPixel));
+#else
+	    fbFillRegionSolid(drawable,
+			      prgn,
+			      0,
+			      fbReplicatePixel(fill.pixel,
+					       drawable->bitsPerPixel));
+#endif
+	    return;
+	}
+#endif
+    
+	pGC->pCompositeClip->extents.x1 += prgn->extents.x1;
+	pGC->pCompositeClip->extents.y1 += prgn->extents.y1;
+	pGC->pCompositeClip->extents.x2 += prgn->extents.x1;
+	pGC->pCompositeClip->extents.y2 += prgn->extents.y1;
+	
+	if(pGC->pCompositeClip->extents.x2 > drawable->pScreen->width)
+	    pGC->pCompositeClip->extents.x2 = drawable->pScreen->width;
+	if(pGC->pCompositeClip->extents.y2 > drawable->pScreen->height)
+	    pGC->pCompositeClip->extents.y2 = drawable->pScreen->height;
+    }
+#endif
+
+#ifdef XQUARTZ_CLIP_DEBUG
+    ErrorF("       GC: %d %d %d %d\n",
+	   pGC->pCompositeClip->extents.x1, pGC->pCompositeClip->extents.y1,
+	   pGC->pCompositeClip->extents.x2 - pGC->pCompositeClip->extents.x1,
+	   pGC->pCompositeClip->extents.y2 - pGC->pCompositeClip->extents.y1);    
+#endif
+
     numRects = RegionNumRects(prgn);
     pbox = RegionRects(prgn);
     for (i = numRects; --i >= 0; pbox++, prect++) {
commit 175f3e22f2ee80651d5fbb70039714ac284d5349
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 15670d0..b35e464 100644
--- a/hw/xfree86/Makefile.am
+++ b/hw/xfree86/Makefile.am
@@ -43,8 +43,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
 
@@ -118,7 +117,7 @@ CLEANFILES = sdksyms.c sdksyms.dep
 EXTRA_DIST += sdksyms.sh
 
 sdksyms.dep sdksyms.c: sdksyms.sh
-	$(AM_V_GEN)CPP='$(CPP)' AWK='$(AWK)' $(SHELL) $(srcdir)/sdksyms.sh $(top_srcdir) $(CFLAGS) $(AM_CFLAGS) $(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 2ea973e12f5d954211e1d10085a4c74581b43aca
Author: Keith Packard <keithp at keithp.com>
Date:   Fri Dec 27 09:50:55 2013 -0800

    Bump version to 1.15.0
    
    Signed-off-by: Keith Packard <keithp at keithp.com>

diff --git a/configure.ac b/configure.ac
index 7ec1997..8f82386 100644
--- a/configure.ac
+++ b/configure.ac
@@ -26,9 +26,9 @@ dnl
 dnl Process this file with autoconf to create configure.
 
 AC_PREREQ(2.60)
-AC_INIT([xorg-server], 1.14.99.905, [https://bugs.freedesktop.org/enter_bug.cgi?product=xorg], xorg-server)
-RELEASE_DATE="2013-12-19"
-RELEASE_NAME="Kraken"
+AC_INIT([xorg-server], 1.15.0, [https://bugs.freedesktop.org/enter_bug.cgi?product=xorg], xorg-server)
+RELEASE_DATE="2013-12-27"
+RELEASE_NAME="Egg Nog"
 AC_CONFIG_SRCDIR([Makefile.am])
 AM_INIT_AUTOMAKE([foreign dist-bzip2])
 AC_USE_SYSTEM_EXTENSIONS
commit 2eb9915eea358f941702d3dad7434197991885c5
Author: Keith Packard <keithp at keithp.com>
Date:   Thu Dec 12 15:48:08 2013 -0800

    present: Set complete notify mode to Skip as needed
    
    Skipped present pixmap calls were not setting the mode to
    PresentCompleteModeSkip for skipped operations.
    
    Signed-off-by: Keith Packard <keithp at keithp.com>

diff --git a/present/present.c b/present/present.c
index 3caa8b7..30cd3b9 100644
--- a/present/present.c
+++ b/present/present.c
@@ -525,6 +525,7 @@ present_execute(present_vblank_ptr vblank, uint64_t ust, uint64_t crtc_msc)
     WindowPtr                   window = vblank->window;
     ScreenPtr                   screen = window->drawable.pScreen;
     present_screen_priv_ptr     screen_priv = present_screen_priv(screen);
+    uint8_t                     mode;
 
     if (vblank->wait_fence) {
         if (!present_fence_check_triggered(vblank->wait_fence)) {
@@ -604,7 +605,20 @@ present_execute(present_vblank_ptr vblank, uint64_t ust, uint64_t crtc_msc)
 
         present_pixmap_idle(vblank->pixmap, vblank->window, vblank->serial, vblank->idle_fence);
     }
-    present_vblank_notify(vblank, vblank->kind, PresentCompleteModeCopy, ust, crtc_msc);
+
+    /* Compute correct CompleteMode
+     */
+    if (vblank->kind == PresentCompleteKindPixmap) {
+        if (vblank->pixmap && vblank->window)
+            mode = PresentCompleteModeCopy;
+        else
+            mode = PresentCompleteModeSkip;
+    }
+    else
+        mode = PresentCompleteModeCopy;
+
+
+    present_vblank_notify(vblank, vblank->kind, mode, ust, crtc_msc);
     present_vblank_destroy(vblank);
 }
 
commit e487babd525ef1bd016ec7b283fa08cf9e6c6f4f
Author: Keith Packard <keithp at keithp.com>
Date:   Thu Dec 12 14:52:35 2013 -0800

    present: Don't abandon presents which are already queued for flip
    
    Presents which are not marked 'queued' and are in the window present
    list are waiting for the flip event; discarding those won't work very
    well (it'll end up trashing displayed content for the next frame), so
    skip over those when looking for duplicate frame presents
    
    Signed-off-by: Keith Packard <keithp at keithp.com>

diff --git a/present/present.c b/present/present.c
index 4c0d63b..3caa8b7 100644
--- a/present/present.c
+++ b/present/present.c
@@ -689,6 +689,9 @@ present_pixmap(WindowPtr window,
             if (!vblank->pixmap)
                 continue;
 
+            if (!vblank->queued)
+                continue;
+
             if (vblank->crtc != target_crtc || vblank->target_msc != target_msc)
                 continue;
 
commit ca3a5b2a8f9f627bbaa9883e16512a21c2a0b81d
Author: Keith Packard <keithp at keithp.com>
Date:   Thu Dec 12 14:17:40 2013 -0800

    present: Handle PresentOptionAsync for copy mode
    
    Check for Async flag and execute immediately if set, otherwise wait
    for the next appropriate vblank before copying.
    
    Signed-off-by: Keith Packard <keithp at keithp.com>

diff --git a/present/present.c b/present/present.c
index 50bd055..4c0d63b 100644
--- a/present/present.c
+++ b/present/present.c
@@ -663,10 +663,18 @@ present_pixmap(WindowPtr window,
     if (crtc_msc >= target_msc) {
         if (divisor != 0) {
             target_msc = crtc_msc - (crtc_msc % divisor) + remainder;
-            if (target_msc <= crtc_msc)
-                target_msc += divisor;
-        } else
+            if (options & PresentOptionAsync) {
+                if (target_msc < crtc_msc)
+                    target_msc += divisor;
+            } else {
+                if (target_msc <= crtc_msc)
+                    target_msc += divisor;
+            }
+        } else {
             target_msc = crtc_msc;
+            if (!(options & PresentOptionAsync))
+                target_msc++;
+        }
     }
 
     /*
commit a68df147421da21528b5be2d34678383922fa352
Author: Keith Packard <keithp at keithp.com>
Date:   Thu Dec 19 14:31:07 2013 -0800

    Bump version to 1.14.99.905 (1.15 RC5)
    
    Another week, another RC. This should be the last before 1.15 final
    
    Signed-off-by: Keith Packard <keithp at keithp.com>

diff --git a/configure.ac b/configure.ac
index 51ac30b..7ec1997 100644
--- a/configure.ac
+++ b/configure.ac
@@ -26,9 +26,9 @@ dnl
 dnl Process this file with autoconf to create configure.
 
 AC_PREREQ(2.60)
-AC_INIT([xorg-server], 1.14.99.904, [https://bugs.freedesktop.org/enter_bug.cgi?product=xorg], xorg-server)
-RELEASE_DATE="2013-12-10"
-RELEASE_NAME="Chai"
+AC_INIT([xorg-server], 1.14.99.905, [https://bugs.freedesktop.org/enter_bug.cgi?product=xorg], xorg-server)
+RELEASE_DATE="2013-12-19"
+RELEASE_NAME="Kraken"
 AC_CONFIG_SRCDIR([Makefile.am])
 AM_INIT_AUTOMAKE([foreign dist-bzip2])
 AC_USE_SYSTEM_EXTENSIONS
commit 4b1ead9d3400acc3402c2480d7cc0527750c32f0
Merge: 4d62646 929795d
Author: Keith Packard <keithp at keithp.com>
Date:   Thu Dec 19 14:14:59 2013 -0800

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

commit 4d62646142718024b0981eb4f1fd0131e829161f
Merge: f4bfb14 81ba89d
Author: Keith Packard <keithp at keithp.com>
Date:   Mon Dec 16 09:27:57 2013 -0800

    Merge remote-tracking branch 'jeremyhu/master'

commit f4bfb14f53a939574da1f5995f0dad949898b86a
Author: Adam Jackson <ajax at redhat.com>
Date:   Thu Dec 12 10:57:40 2013 -0500

    configure: Fix a typo near dri3/shmfence detection
    
    " is not the mate of ].
    
    Reviewed-by: Jasper St. Pierre <jstpierre at mecheye.net>
    Signed-off-by: Adam Jackson <ajax at redhat.com>

diff --git a/configure.ac b/configure.ac
index 8bedd35..3f2c2d0 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1218,7 +1218,7 @@ case "$DRI3,$HAVE_XSHMFENCE" in
 	yes,yes | auto,yes)
 		;;
 	yes,no)
-		AC_MSG_ERROR("DRI3 requested, but xshmfence not found.])
+		AC_MSG_ERROR([DRI3 requested, but xshmfence not found.])
 		DRI3=no
 		;;
 	no,*)
commit 8248b4af31ef71ac03158871b77f20eb456dbe38
Author: Adam Jackson <ajax at redhat.com>
Date:   Fri Dec 13 15:07:48 2013 -0500

    glx: Add null pointer protection to __glGetProcAddress
    
    This can't happen when GLX is the backing window system, but can
    elsewhere.  We may as well protect against it at a high level.
    
    Reviewed-by: Eric Anholt <eric at anholt.net>
    Signed-off-by: Adam Jackson <ajax at redhat.com>

diff --git a/glx/glxext.c b/glx/glxext.c
index 84ac43d..316b4f6 100644
--- a/glx/glxext.c
+++ b/glx/glxext.c
@@ -554,7 +554,9 @@ __glXsetGetProcAddress(glx_gpa_proc get_proc_address)
 
 void *__glGetProcAddress(const char *proc)
 {
-    return _get_proc_address(proc);
+    void *ret = _get_proc_address(proc);
+
+    return ret ? ret : NoopDDA;
 }
 
 /*
commit 128449dd6498a2f74c3770f89a9dae0f70e2b351
Author: Adam Jackson <ajax at redhat.com>
Date:   Fri Dec 13 11:39:16 2013 -0500

    present: Don't use the major/minor version from the protocol headers
    
    We want to advertise the version we implement, not the version the
    protocol headers happen to describe.
    
    Reviewed-by: Jasper St. Pierre <<jstpierre at mecheye.net>
    Signed-off-by: Adam Jackson <ajax at redhat.com>

diff --git a/include/protocol-versions.h b/include/protocol-versions.h
index 7fe61e0..fc428c8 100644
--- a/include/protocol-versions.h
+++ b/include/protocol-versions.h
@@ -67,6 +67,10 @@
 #define SERVER_PANORAMIX_MAJOR_VERSION          1
 #define SERVER_PANORAMIX_MINOR_VERSION		1
 
+/* Present */
+#define SERVER_PRESENT_MAJOR_VERSION            1
+#define SERVER_PRESENT_MINOR_VERSION            0
+
 /* RandR */
 #define SERVER_RANDR_MAJOR_VERSION		1
 #define SERVER_RANDR_MINOR_VERSION		4
diff --git a/present/present_request.c b/present/present_request.c
index 095fa2d..1064dcb 100644
--- a/present/present_request.c
+++ b/present/present_request.c
@@ -26,6 +26,7 @@
 
 #include "present_priv.h"
 #include "randrstr.h"
+#include <protocol-versions.h>
 
 static int
 proc_present_query_version(ClientPtr client)
@@ -35,8 +36,8 @@ proc_present_query_version(ClientPtr client)
         .type = X_Reply,
         .sequenceNumber = client->sequence,
         .length = 0,
-        .majorVersion = PRESENT_MAJOR,
-        .minorVersion = PRESENT_MINOR
+        .majorVersion = SERVER_PRESENT_MAJOR_VERSION,
+        .minorVersion = SERVER_PRESENT_MINOR_VERSION
     };
 
     REQUEST_SIZE_MATCH(xPresentQueryVersionReq);
commit ec6087bf070131bc3a26848fb9fb840f09b0e19d
Author: Adam Jackson <ajax at redhat.com>
Date:   Fri Dec 13 11:36:38 2013 -0500

    dri3: Don't use the major/minor version from the protocol headers
    
    We want to advertise the version we implement, not the version the
    protocol headers happen to describe.
    
    Reviewed-by: Jasper St. Pierre <<jstpierre at mecheye.net>
    Signed-off-by: Adam Jackson <ajax at redhat.com>

diff --git a/dri3/dri3_request.c b/dri3/dri3_request.c
index 3ebb9d5..4e1408f 100644
--- a/dri3/dri3_request.c
+++ b/dri3/dri3_request.c
@@ -29,6 +29,7 @@
 #include <unistd.h>
 #include <xace.h>
 #include "../Xext/syncsdk.h"
+#include <protocol-versions.h>
 
 static int
 proc_dri3_query_version(ClientPtr client)
@@ -38,8 +39,8 @@ proc_dri3_query_version(ClientPtr client)
         .type = X_Reply,
         .sequenceNumber = client->sequence,
         .length = 0,
-        .majorVersion = DRI3_MAJOR,
-        .minorVersion = DRI3_MINOR
+        .majorVersion = SERVER_DRI3_MAJOR_VERSION,
+        .minorVersion = SERVER_DRI3_MINOR_VERSION
     };
 
     REQUEST_SIZE_MATCH(xDRI3QueryVersionReq);
diff --git a/include/protocol-versions.h b/include/protocol-versions.h
index 95df8ce..7fe61e0 100644
--- a/include/protocol-versions.h
+++ b/include/protocol-versions.h
@@ -46,6 +46,10 @@
 #define SERVER_DAMAGE_MAJOR_VERSION		1
 #define SERVER_DAMAGE_MINOR_VERSION		1
 
+/* DRI3 */
+#define SERVER_DRI3_MAJOR_VERSION               1
+#define SERVER_DRI3_MINOR_VERSION               0
+
 /* DMX */
 #define SERVER_DMX_MAJOR_VERSION		2
 #define SERVER_DMX_MINOR_VERSION		2
commit e6fafd3de70d315130fb6e5732cfd02a5901b788
Author: Adam Jackson <ajax at redhat.com>
Date:   Fri Dec 13 11:28:59 2013 -0500

    dri3: Guard against buggy clients
    
    There's nothing to stop a client from sending these requests to screens
    without DRI3 support, and if they do, we'll crash.  Let's not do that.
    
    Reviewed-by: Jasper St. Pierre <<jstpierre at mecheye.net>
    Signed-off-by: Adam Jackson <ajax at redhat.com>

diff --git a/dri3/dri3_screen.c b/dri3/dri3_screen.c
index cf2735b..c880296 100644
--- a/dri3/dri3_screen.c
+++ b/dri3/dri3_screen.c
@@ -55,6 +55,9 @@ dri3_pixmap_from_fd(PixmapPtr *ppixmap, ScreenPtr screen, int fd,
     dri3_screen_info_ptr        info = ds->info;
     PixmapPtr                   pixmap;
 
+    if (!info || !info->pixmap_from_fd)
+        return BadImplementation;
+
     pixmap = (*info->pixmap_from_fd) (screen, fd, width, height, stride, depth, bpp);
     if (!pixmap)
         return BadAlloc;
@@ -71,6 +74,9 @@ dri3_fd_from_pixmap(int *pfd, PixmapPtr pixmap, CARD16 *stride, CARD32 *size)
     dri3_screen_info_ptr        info = ds->info;
     int                         fd;
 
+    if (!info || !info->fd_from_pixmap)
+        return BadImplementation;
+
     fd = (*info->fd_from_pixmap)(screen, pixmap, stride, size);
     if (fd < 0)
         return BadAlloc;
commit 81ba89d6703a22178a153aa39478ba2d4bde262b
Author: Jeremy Huddleston Sequoia <jeremyhu at apple.com>
Date:   Fri Dec 13 01:39:44 2013 -0800

    configure.ac: Add PRESENT_LIB to XQUARTZ_LIBS
    
    Undefined symbols for architecture x86_64:
      "_present_extension_init", referenced from:
          _staticExtensions in libXquartz.a(miinitext.o)
      "_present_register_complete_notify", referenced from:
          ___glXregisterPresentCompleteNotify in libglx.a(glxcmds.o)
    
    Signed-off-by: Jeremy Huddleston Sequoia <jeremyhu at apple.com>

diff --git a/configure.ac b/configure.ac
index 8bedd35..ac29bd9 100644
--- a/configure.ac
+++ b/configure.ac
@@ -2158,7 +2158,7 @@ if test "x$XQUARTZ" = xyes; then
 	AC_DEFINE(XQUARTZ,1,[Have Quartz])
 	AC_DEFINE(ROOTLESS,1,[Build Rootless code])
 
-	XQUARTZ_LIBS="$FB_LIB $FIXES_LIB $XEXT_LIB $DBE_LIB $RECORD_LIB $RANDR_LIB $RENDER_LIB $DAMAGE_LIB $MIEXT_SYNC_LIB $MIEXT_DAMAGE_LIB $MIEXT_SHADOW_LIB $XI_LIB $XKB_LIB $XKB_STUB_LIB $XPSTUBS_LIB"
+	XQUARTZ_LIBS="$FB_LIB $FIXES_LIB $XEXT_LIB $DBE_LIB $RECORD_LIB $RANDR_LIB $RENDER_LIB $DAMAGE_LIB $MIEXT_SYNC_LIB $MIEXT_DAMAGE_LIB $MIEXT_SHADOW_LIB $XI_LIB $XKB_LIB $XKB_STUB_LIB $XPSTUBS_LIB $PRESENT_LIB"
 	AC_SUBST([XQUARTZ_LIBS])
 
 	AC_CHECK_LIB([Xplugin],[xp_init],[:])
commit d7c9235ee261b0f780320985233e00dec5e2689c
Author: Jeremy Huddleston Sequoia <jeremyhu at apple.com>
Date:   Sat Dec 7 01:36:33 2013 -0800

    XQuartz: Use asl_log_descriptor to log stdout/stderr of child processes
    
    Signed-off-by: Jeremy Huddleston Sequoia <jeremyhu at apple.com>

diff --git a/hw/xquartz/X11Controller.m b/hw/xquartz/X11Controller.m
index 3d094bf..752bda3 100644
--- a/hw/xquartz/X11Controller.m
+++ b/hw/xquartz/X11Controller.m
@@ -347,7 +347,7 @@ extern char *bundle_id_prefix;
     const char *newargv[4];
     char buf[128];
     char *s;
-#if 0 && MAC_OS_X_VERSION_MAX_ALLOWED >= 1080
+#if MAC_OS_X_VERSION_MAX_ALLOWED >= 1080
     int stdout_pipe[2];
     int stderr_pipe[2];
 #endif
@@ -363,7 +363,7 @@ extern char *bundle_id_prefix;
         setenv("DISPLAY", buf, TRUE);
     }
 
-#if 0 && MAC_OS_X_VERSION_MAX_ALLOWED >= 1080
+#if MAC_OS_X_VERSION_MAX_ALLOWED >= 1080
     if (asl_log_descriptor) {
         char *asl_sender;
         aslmsg amsg = asl_new(ASL_TYPE_MSG);
@@ -413,7 +413,7 @@ extern char *bundle_id_prefix;
             _exit(1);
 
         case 0:                                     /* child2 */
-#if 0 && MAC_OS_X_VERSION_MAX_ALLOWED >= 1080
+#if MAC_OS_X_VERSION_MAX_ALLOWED >= 1080
             if (asl_log_descriptor) {
                 /* Replace our stdout/stderr */
                 dup2(stdout_pipe[1], STDOUT_FILENO);
@@ -442,7 +442,7 @@ extern char *bundle_id_prefix;
         waitpid(child1, &status, 0);
     }
 
-#if 0 && MAC_OS_X_VERSION_MAX_ALLOWED >= 1080
+#if MAC_OS_X_VERSION_MAX_ALLOWED >= 1080
     if (asl_log_descriptor) {
         /* Close the write ends of the pipe */
         close(stdout_pipe[1]);
commit ad8111d7c971ce448905c733d65ba0cfc72bdca4
Author: Jeremy Huddleston Sequoia <jeremyhu at apple.com>
Date:   Sat Dec 7 01:14:37 2013 -0800

    darwin: Don't leave stdin/stdout closed
    
    <rdar://problem/15609419>
    
    Signed-off-by: Jeremy Huddleston Sequoia <jeremyhu at apple.com>

diff --git a/os/osinit.c b/os/osinit.c
index 60d1069..4d48ea9 100644
--- a/os/osinit.c
+++ b/os/osinit.c
@@ -213,10 +213,18 @@ OsInit(void)
         dlinfo(RTLD_SELF, RTLD_DI_SETSIGNAL, &failure_signal);
 #endif
 
-#if !defined(__CYGWIN__)
+#if !defined(XQUARTZ)    /* STDIN is already /dev/null and STDOUT/STDERR is managed by console_redirect.c */
+# if defined(__APPLE__)
+        int devnullfd = open(devnull, O_RDWR, 0);
+        assert(devnullfd > 2);
+
+        dup2(devnullfd, STDIN_FILENO);
+        dup2(devnullfd, STDOUT_FILENO);
+        close(devnullfd);
+# elif !defined(__CYGWIN__)
         fclose(stdin);
         fclose(stdout);
-#endif
+# endif
         /* 
          * If a write of zero bytes to stderr returns non-zero, i.e. -1, 
          * then writing to stderr failed, and we'll write somewhere else 
@@ -250,6 +258,7 @@ OsInit(void)
             setlinebuf(stderr);
 #endif
         }
+#endif /* !XQUARTZ */
 
 #if !defined(WIN32) || defined(__CYGWIN__)
         if (getpgrp() == 0)
commit 929795d50d788358d6269ce423f72c6cc40e334b
Author: Peter Hutterer <peter.hutterer at who-t.net>
Date:   Tue Dec 3 10:14:51 2013 +1000

    dix: fix check for grab type
    
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>

diff --git a/dix/events.c b/dix/events.c
index 4632bb7..4aaa54c 100644
--- a/dix/events.c
+++ b/dix/events.c
@@ -4696,7 +4696,7 @@ DeviceEnterLeaveEvent(DeviceIntPtr mouse,
 
     filter = GetEventFilter(mouse, (xEvent *) event);
 
-    if (grab && grab->type == XI2) {
+    if (grab && grab->grabtype == XI2) {
         Mask mask;
 
         mask = xi2mask_isset(grab->xi2mask, mouse, type);
commit 23394c7fea0f5c33333198c87ecfecc9f6c6a791
Author: Peter Hutterer <peter.hutterer at who-t.net>
Date:   Tue Dec 3 08:36:45 2013 +1000

    Xi: ungrab device when releasing a passive grab without ButtonReleaseMask (#71878)
    
    If an touch triggers an async button grab and that grab does not have the
    ButtonReleaseMask set, the TouchEnd is never delivered, deliveries is 0  and
    the grab is never deactivated.
    
    If the grab is pointer async and keyboard sync, the keyboard events are stuck
    in EnqueueEvent until some other pointer event terminates the grab.
    
    Change this to check for the number of listeners. If we're about to deliver a
    TouchEnd to a passive pointer grab, the number of listeners is already 1 -
    pointer grabs always accept so other listeners were removed.
    
    X.Org Bug 71878 <http://bugs.freedesktop.org/show_bug.cgi?id=71878>
    
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>

diff --git a/Xi/exevents.c b/Xi/exevents.c
index 5e1d3e0..dff0a92 100644
--- a/Xi/exevents.c
+++ b/Xi/exevents.c
@@ -1413,7 +1413,8 @@ DeliverTouchEmulatedEvent(DeviceIntPtr dev, TouchPointInfoPtr ti,
                 !(ev->device_event.flags & TOUCH_CLIENT_ID))
                 TouchListenerAcceptReject(dev, ti, 0, XIAcceptTouch);
 
-            if (deliveries && ev->any.type == ET_TouchEnd &&
+            if (ev->any.type == ET_TouchEnd &&
+                ti->num_listeners == 1 &&
                 !dev->button->buttonsDown &&
                 dev->deviceGrab.fromPassiveGrab && GrabIsPointerGrab(grab)) {
                 (*dev->deviceGrab.DeactivateGrab) (dev);
commit c1d30b5bd7f90e68bc38404fd0cc32578d6d3018
Author: Ben Gamari <bgamari.foss at gmail.com>
Date:   Thu Nov 21 21:24:20 2013 -0500

    Xi: Don't ActivateEarlyAccept POINTER_REGULAR listeners
    
    Bug #71878 describes a bug resulting in the server ceasing to respond to
    keyboard input after a touch event. The problem might be the following:
    
    DeliverTouchBeginEvent tries to deliver an event to a listener of type
    LISTENER_POINTER_REGULAR, taking the following if branch,
    
        if (listener->type == LISTENER_POINTER_REGULAR ||
            listener->type == LISTENER_POINTER_GRAB) {
            rc = DeliverTouchEmulatedEvent(dev, ti, ev, listener, client, win,
                                           grab, xi2mask);
            if (rc == Success) {
                listener->state = LISTENER_IS_OWNER;
                /* async grabs cannot replay, so automatically accept this touch */
                if (dev->deviceGrab.grab &&
                    dev->deviceGrab.fromPassiveGrab &&
                    dev->deviceGrab.grab->pointerMode == GrabModeAsync)
                    ActivateEarlyAccept(dev, ti);
            }
            goto out;
        }
    
    DeliverTouchEmulatedEvent succeeds.  The deviceGrab meets all
    three of the conditions of the inner if, enters
    ActivateEarlyAccept which then fails due to,
    
        BUG_RETURN(ti->listeners[0].type != LISTENER_GRAB &&
                   ti->listeners[0].type != LISTENER_POINTER_GRAB);
    
    That is, despite listener->type == LISTENER_POINTER_REGULAR. With my
    non-existent knowledge of XINPUT, it seems like the solution here
    might be to only ActivateEarlyAccept when listener->type ==
    LISTENER_POINTER_GRAB.
    
    Signed-off-by: Ben Gamari <bgamari.foss at gmail.com>
    Reviewed-by: Peter Hutterer <peter.hutterer at who-t.net>
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>

diff --git a/Xi/exevents.c b/Xi/exevents.c
index 5dc9020..5e1d3e0 100644
--- a/Xi/exevents.c
+++ b/Xi/exevents.c
@@ -1845,7 +1845,8 @@ DeliverTouchBeginEvent(DeviceIntPtr dev, TouchPointInfoPtr ti,
         if (rc == Success) {
             listener->state = LISTENER_IS_OWNER;
             /* async grabs cannot replay, so automatically accept this touch */
-            if (dev->deviceGrab.grab &&
+            if (listener->type == LISTENER_POINTER_GRAB &&
+                dev->deviceGrab.grab &&
                 dev->deviceGrab.fromPassiveGrab &&
                 dev->deviceGrab.grab->pointerMode == GrabModeAsync)
                 ActivateEarlyAccept(dev, ti);
commit fe07ec19e212a68076560d243a2a935c54589068
Author: Keith Packard <keithp at keithp.com>
Date:   Tue Dec 10 11:27:47 2013 -0800

    present: recursively set window pixmaps on flip
    
    Newly created windows inherit the pixmap of their parent, similarly,
    reparenting a tree inherits the pixmap of the destination tree.
    
    Making present preserve the invariant that unredirected windows always
    have the same pixmap as their parent ensures that the above cases work
    correctly.
    
    v2: name the recursive function to 'set_tree_pixmap' instead of 'set_window_pixmap'
    
    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 ffbb0b3..50bd055 100644
--- a/present/present.c
+++ b/present/present.c
@@ -312,6 +312,36 @@ present_flip_idle(ScreenPtr screen)
     }
 }
 
+struct pixmap_visit {
+    PixmapPtr   old;
+    PixmapPtr   new;
+};
+
+static int
+present_set_tree_pixmap_visit(WindowPtr window, pointer data)
+{
+    struct pixmap_visit *visit = data;
+    ScreenPtr           screen = window->drawable.pScreen;
+
+    if ((*screen->GetWindowPixmap)(window) != visit->old)
+        return WT_DONTWALKCHILDREN;
+    (*screen->SetWindowPixmap)(window, visit->new);
+    return WT_WALKCHILDREN;
+}
+    
+static void
+present_set_tree_pixmap(WindowPtr window, PixmapPtr pixmap)
+{
+    struct pixmap_visit visit;
+    ScreenPtr           screen = window->drawable.pScreen;
+
+    visit.old = (*screen->GetWindowPixmap)(window);
+    visit.new = pixmap;
+    if (visit.old == visit.new)
+        return;
+    TraverseTree(window, present_set_tree_pixmap_visit, &visit);
+}
+
 static void
 present_unflip(ScreenPtr screen)
 {
@@ -321,10 +351,10 @@ present_unflip(ScreenPtr screen)
     assert (!screen_priv->flip_pending);
 
     if (screen_priv->flip_window)
-        (*screen->SetWindowPixmap)(screen_priv->flip_window,
-                                   (*screen->GetScreenPixmap)(screen));
+        present_set_tree_pixmap(screen_priv->flip_window,
+                                  (*screen->GetScreenPixmap)(screen));
 
-    (*screen->SetWindowPixmap)(screen->root, (*screen->GetScreenPixmap)(screen));
+    present_set_tree_pixmap(screen->root, (*screen->GetScreenPixmap)(screen));
 
     /* Update the screen pixmap with the current flip pixmap contents
      */
@@ -527,10 +557,10 @@ present_execute(present_vblank_ptr vblank, uint64_t ust, uint64_t crtc_msc)
                  *  2) Set current flip window pixmap to the new pixmap
                  */
                 if (screen_priv->flip_window && screen_priv->flip_window != window)
-                    (*screen->SetWindowPixmap)(screen_priv->flip_window,
-                                               (*screen->GetScreenPixmap)(screen));
-                (*screen->SetWindowPixmap)(vblank->window, vblank->pixmap);
-                (*screen->SetWindowPixmap)(screen->root, vblank->pixmap);
+                    present_set_tree_pixmap(screen_priv->flip_window,
+                                              (*screen->GetScreenPixmap)(screen));
+                present_set_tree_pixmap(vblank->window, vblank->pixmap);
+                present_set_tree_pixmap(screen->root, vblank->pixmap);
 
                 /* Report update region as damaged
                  */
commit b3533d0b212b6747a8f9a01931253d6bdb648ee2
Author: Keith Packard <keithp at keithp.com>
Date:   Tue Dec 10 10:29:11 2013 -0800

    Bump version to 1.14.99.904 (1.15 RC4)
    
    Signed-off-by: Keith Packard <keithp at keithp.com>

diff --git a/configure.ac b/configure.ac
index 045dfbe..8bedd35 100644
--- a/configure.ac
+++ b/configure.ac
@@ -26,9 +26,9 @@ dnl
 dnl Process this file with autoconf to create configure.
 
 AC_PREREQ(2.60)
-AC_INIT([xorg-server], 1.14.99.903, [https://bugs.freedesktop.org/enter_bug.cgi?product=xorg], xorg-server)
-RELEASE_DATE="2013-11-23"
-RELEASE_NAME="Apple Pie"
+AC_INIT([xorg-server], 1.14.99.904, [https://bugs.freedesktop.org/enter_bug.cgi?product=xorg], xorg-server)
+RELEASE_DATE="2013-12-10"
+RELEASE_NAME="Chai"
 AC_CONFIG_SRCDIR([Makefile.am])
 AM_INIT_AUTOMAKE([foreign dist-bzip2])
 AC_USE_SYSTEM_EXTENSIONS
commit 9a4d7572fe3be16bb5aded5f48d4217fdf725b1d
Author: Jon TURNEY <jon.turney at dronecode.org.uk>
Date:   Thu Sep 27 18:59:45 2012 +0100

    hw/xwin/glx: Rewrite WGL wrappers after Xserver conversion to direct GL dispatch
    
    v1: Rewrite by Marc Haesen of the WGL wrapper function generation script to use
    Khronos group XML.
    
    v2: Remove -dispatchheader option, since dispatch.h doesn't exist anymore, use
    the private glapi interface to construct the GL dispatch table for the native
    WGL thunks.
    
    v3:
    Rewrite to generate shims for the OpenGL 1.2.1 (GL 1.2 + GL_ARB_imaging
    +GL_ARB_multitexture + GL_ARB_texture_compression(?)) functions the server links
    directly with rather than libGL.
    
    These shims dispatch to either the mesa GL DLL, or a thunking DLL containing
    cdecl-to-stcall wrapper functions for the native GL DLL.
    
    Signed-off-by: Jon TURNEY <jon.turney at dronecode.org.uk>
    Reviewed-by: Adam Jackson <ajax at redhat.com>

diff --git a/configure.ac b/configure.ac
index 3855d72..045dfbe 100644
--- a/configure.ac
+++ b/configure.ac
@@ -2109,7 +2109,7 @@ if test "x$XWIN" = xyes; then
 	esac
 
 	XWIN_LIBS="$FB_LIB $MI_LIB $FIXES_LIB $XEXT_LIB $RANDR_LIB $RENDER_LIB $DBE_LIB $RECORD_LIB $GLX_LIBS $XKB_LIB $XKB_STUB_LIB $COMPOSITE_LIB $DAMAGE_LIB $PRESENT_LIB $MIEXT_SYNC_LIB $MIEXT_DAMAGE_LIB $MIEXT_SHADOW_LIB $XI_LIB $OS_LIB"
-	XWIN_SYS_LIBS="$XWIN_SYS_LIBS $XWINMODULES_LIBS $GLX_SYS_LIBS"
+	XWIN_SYS_LIBS="$XWIN_SYS_LIBS $XWINMODULES_LIBS"
 	AC_SUBST(XWIN_LIBS)
 	AC_SUBST(XWIN_SERVER_NAME)
 	AC_SUBST(XWIN_SYS_LIBS)
@@ -2125,10 +2125,16 @@ if test "x$XWIN" = xyes; then
 
 dnl XWin with AIGLX requires OpenGL spec files in order to generate wrapper code for native GL functions
 	if [test "x$XWIN" = xyes && test "x$AIGLX" = xyes] ; then
-           AC_CHECK_PROG(PYTHON, python, python)
-           if test -z "$PYTHON"; then
-                AC_MSG_ERROR([python not found])
+           AC_CHECK_PROG(PYTHON3, python3, python3)
+           if test -z "$PYTHON3"; then
+                AC_MSG_ERROR([python3 not found])
            fi
+           AC_MSG_CHECKING(for python module lxml)
+           $PYTHON3 -c "import lxml;"
+           if test $? -ne 0 ; then
+                AC_MSG_ERROR([not found])
+           fi
+           AC_MSG_RESULT(yes)
            if test "x$KHRONOS_SPEC_DIR" = "xauto" ; then
 		PKG_CHECK_MODULES([KHRONOS_OPENGL_REGISTRY], [khronos-opengl-registry])
 		KHRONOS_SPEC_DIR=`pkg-config khronos-opengl-registry --variable=specdir`
diff --git a/hw/xwin/Makefile.am b/hw/xwin/Makefile.am
index c700695..7f0eaf0 100644
--- a/hw/xwin/Makefile.am
+++ b/hw/xwin/Makefile.am
@@ -157,7 +157,7 @@ XWIN_LIBS += 	$(top_builddir)/pseudoramiX/libPseudoramiX.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_LDFLAGS = -mwindows -static
+XWin_LDFLAGS = -mwindows -static -Wl,--disable-stdcall-fixup
 
 .rc.o:
 	$(AM_V_GEN)$(WINDRES) --use-temp-file -i $< --input-format=rc -o $@ -O coff -I $(top_builddir)/include
diff --git a/hw/xwin/glx/Makefile.am b/hw/xwin/glx/Makefile.am
index 067ee5b..f2dffbf 100644
--- a/hw/xwin/glx/Makefile.am
+++ b/hw/xwin/glx/Makefile.am
@@ -1,14 +1,18 @@
 noinst_LTLIBRARIES = libXwinGLX.la
+lib_LTLIBRARIES = libnativeGLthunk.la
 
 libXwinGLX_la_SOURCES = \
 	winpriv.c \
 	winpriv.h \
 	glwindows.h \
-	glwrap.c \
+	glshim.c \
 	indirect.c \
 	wgl_ext_api.c \
 	wgl_ext_api.h
 
+libnativeGLthunk_la_SOURCES = \
+	glthunk.c
+
 if XWIN_MULTIWINDOW
 DEFS_MULTIWINDOW = -DXWIN_MULTIWINDOW
 endif
@@ -30,16 +34,32 @@ AM_CFLAGS = -DHAVE_XWIN_CONFIG_H $(DIX_CFLAGS) \
             -I$(top_srcdir) \
             -I$(top_srcdir)/hw/xwin/
 
+libnativeGLthunk_la_CFLAGS = $(AM_CFLAGS) -Wno-unused-function -Wno-missing-prototypes -Wno-missing-declarations
+libnativeGLthunk_la_LDFLAGS = -shared -no-undefined -avoid-version -lopengl32 -export-symbols generated_gl_thunks.def
+EXTRA_libnativeGLthunk_la_DEPENDENCIES = generated_gl_thunks.def
+
 if XWIN_GLX_WINDOWS
 
-generated_gl_wrappers.c: gen_gl_wrappers.py $(KHRONOS_SPEC_DIR)/gl.spec $(KHRONOS_SPEC_DIR)/gl.tm
-	$(AM_V_GEN)$(PYTHON) $(srcdir)/gen_gl_wrappers.py --spec=$(KHRONOS_SPEC_DIR)/gl.spec --typemap=$(KHRONOS_SPEC_DIR)/gl.tm --dispatch-header=$(top_srcdir)/glx/dispatch.h --staticwrappers >generated_gl_wrappers.c
+if DEBUG
+GENGLWRAPPERSOPTS=""
+else
+GENGLWRAPPERSOPTS="-nodebug"
+endif
+
+generated_wgl_wrappers.c: $(srcdir)/gen_gl_wrappers.py $(KHRONOS_SPEC_DIR)/wgl.xml $(KHRONOS_SPEC_DIR)/reg.py
+	$(AM_V_GEN)PYTHONPATH=$(KHRONOS_SPEC_DIR) $(PYTHON3) $(srcdir)/gen_gl_wrappers.py -registry $(KHRONOS_SPEC_DIR)/wgl.xml -prefix wgl -wrapper -preresolve $(GENGLWRAPPERSOPTS) -outfile $@
+
+generated_gl_shim.c: $(srcdir)/gen_gl_wrappers.py $(KHRONOS_SPEC_DIR)/gl.xml $(KHRONOS_SPEC_DIR)/reg.py
+	$(AM_V_GEN)PYTHONPATH=$(KHRONOS_SPEC_DIR) $(PYTHON3) $(srcdir)/gen_gl_wrappers.py -registry $(KHRONOS_SPEC_DIR)/gl.xml -shim $(GENGLWRAPPERSOPTS) -outfile $@
+
+generated_gl_thunks.c: $(srcdir)/gen_gl_wrappers.py $(KHRONOS_SPEC_DIR)/gl.xml $(KHRONOS_SPEC_DIR)/reg.py
+	$(AM_V_GEN)PYTHONPATH=$(KHRONOS_SPEC_DIR) $(PYTHON3) $(srcdir)/gen_gl_wrappers.py -registry $(KHRONOS_SPEC_DIR)/gl.xml -thunk $(GENGLWRAPPERSOPTS) -outfile $@
 
-generated_wgl_wrappers.c: gen_gl_wrappers.py $(KHRONOS_SPEC_DIR)/wglext.spec $(KHRONOS_SPEC_DIR)/wgl.tm
-	$(AM_V_GEN)$(PYTHON) $(srcdir)/gen_gl_wrappers.py --spec=$(KHRONOS_SPEC_DIR)/wglext.spec --typemap=$(KHRONOS_SPEC_DIR)/wgl.tm --prefix=wgl --preresolve >generated_wgl_wrappers.c
+generated_gl_thunks.def: $(srcdir)/gen_gl_wrappers.py $(KHRONOS_SPEC_DIR)/gl.xml $(KHRONOS_SPEC_DIR)/reg.py
+	$(AM_V_GEN)PYTHONPATH=$(KHRONOS_SPEC_DIR) $(PYTHON3) $(srcdir)/gen_gl_wrappers.py -registry $(KHRONOS_SPEC_DIR)/gl.xml -thunkdefs $(GENGLWRAPPERSOPTS) -outfile $@
 endif
 
-BUILT_SOURCES = generated_gl_wrappers.c generated_wgl_wrappers.c
+BUILT_SOURCES = generated_gl_shim.c generated_gl_thunks.c generated_gl_thunks.def generated_wgl_wrappers.c
 CLEANFILES = $(BUILT_SOURCES)
 
 EXTRA_DIST = gen_gl_wrappers.py
diff --git a/hw/xwin/glx/gen_gl_wrappers.py b/hw/xwin/glx/gen_gl_wrappers.py
index 2273589..683b9d9 100755
--- a/hw/xwin/glx/gen_gl_wrappers.py
+++ b/hw/xwin/glx/gen_gl_wrappers.py
@@ -1,325 +1,485 @@
-#!/usr/bin/python
+#!/usr/bin/python3
 #
-# Comedy python script to generate cdecl to stdcall wrappers for GL functions
+# python script to generate cdecl to stdcall wrappers for GL functions
+# adapted from genheaders.py
 #
-# This is designed to operate on OpenGL spec files from
-# http://www.opengl.org/registry/api/
-#
-#
-# Copyright (c) Jon TURNEY 2009
+# Copyright (c) 2013 The Khronos Group 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 ABOVE LISTED COPYRIGHT HOLDER(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(s) of the above copyright
-# holders shall not be used in advertising or otherwise to promote the sale,
-# use or other dealings in this Software without prior written authorization.
-#
-
-import sys
-import re
-import getopt
-
-dispatchheader = ''
-prefix = 'gl'
-preresolve = False
-staticwrappers = False
-
-opts, args = getopt.getopt(sys.argv[1:], "", ['spec=', 'typemap=', 'dispatch-header=', 'prefix=', 'preresolve', 'staticwrappers' ])
-
-for o,a in opts:
-        if o == '--typemap' :
-                typemapfile = a
-        elif o == '--dispatch-header' :
-                dispatchheader = a
-        elif o == '--spec' :
-                specfile = a
-        elif o == '--prefix' :
-                prefix = a
-        elif o == '--preresolve' :
-                preresolve = True
-        elif o == '--staticwrappers' :
-                staticwrappers = True
-
+# copy of this software and/or associated documentation files (the
+# "Materials"), to deal in the Materials without restriction, including
+# without limitation the rights to use, copy, modify, merge, publish,
+# distribute, sublicense, and/or sell copies of the Materials, and to
+# permit persons to whom the Materials are furnished to do so, subject to
+# the following conditions:
 #
-# look for all the SET_ macros in dispatch.h, this is the set of functions
-# we need to generate
-#
-
-dispatch = {}
-
-if dispatchheader :
-        fh = open(dispatchheader)
-        dispatchh = fh.readlines()
-
-        dispatch_regex = re.compile(r'^SET_(\S*)\(')
-
-        for line in dispatchh :
-                line = line.strip()
-                m1 = dispatch_regex.search(line)
-
-                if m1 :
-                        dispatch[m1.group(1)] = 1
-
-        del dispatch['by_offset']
-
+# The above copyright notice and this permission notice shall be included
+# in all copies or substantial portions of the Materials.
 #
-# read the typemap .tm file
-#
-
-typemap = {}
-
-fh = open(typemapfile)
-tm = fh.readlines()
-
-typemap_regex = re.compile(r'#define\sSET_(\S*)\(')
-
-for line in tm :
-        # ignore everything after a '#' as a comment
-        hash = line.find('#')
-        if hash != -1 :
-                line = line[:hash-1]
-
-        # ignore blank lines
-        if line.startswith('#') or len(line) == 0 :
-                continue
-
-        l = line.split(',')
-        typemap[l[0]] = l[3].strip()
-
-# interestingly, * is not a C type
-if typemap['void'] == '*' :
-        typemap['void'] = 'void'
-
-#
-# crudely parse the .spec file
-#
-
-r1 = re.compile(r'\t(\S*)\s+(\S*.*)')
-r2 = re.compile(r'(.*)\((.*)\)')
-r3 = re.compile(r'glWindowPos.*MESA')
-r4 = re.compile(r'gl.*Program(s|)NV')
-r5 = re.compile(r'glGetVertexAttribfvNV')
-
-wrappers = {}
-
-fh = open(specfile)
-glspec = fh.readlines()
-param_count = 0
-
-for line in glspec :
-        line = line.rstrip()
-
-        # ignore everything after a '#' as a comment
-        hash = line.find('#')
-        if hash != -1 :
-                line = line[:hash-1]
-
-        # ignore blank lines
-        if line.startswith('#') or len(line) == 0 :
-                continue
-
-        # lines containing ':' aren't intersting to us
-        if line.count(':') != 0 :
-                continue
-
-        # attributes of each function follow the name, indented by a tab
-        if not line.startswith('\t') :
-                m1 = r2.search(line)
-                if m1 :
-                        function = m1.group(1)
-                        arglist_use = m1.group(2)
-                        wrappers[function] = {}
-
-                        # ensure formal parameter names don't collide with reserved names or shadow global declarations
-                        arglist_use = ',' .join([i.rstrip() + '_' for i in arglist_use.split(",")])
-
-                        wrappers[function]['arglist_use'] = arglist_use
-                        param_count = 0
-        else :
-                m1 = r1.search(line)
-                if m1 :
-                        attribute = m1.group(1)
-                        value = m1.group(2)
-
-                        # make param attributes unique and ordered
-                        if attribute == 'param' :
-                                attribute = 'param' + '%02d' % param_count
-                                param_count += 1
-
-                        wrappers[function][attribute] = value
-
-#
-# now emit code
-#
-
-print '/* Automatically generated by ' + sys.argv[0] + ' DO NOT EDIT */'
-print '/* from ' + specfile + ' and typemap ' + typemapfile + ' */'
-print ''
-
-#
-# if required, emit code for non-lazy function resolving
-#
-
-if preresolve :
-        for w in sorted(wrappers.keys()) :
-                funcname = prefix + w
-                print 'RESOLVE_DECL(PFN' + funcname.upper() + 'PROC);'
-
-        print ''
-        print 'void ' + prefix + 'ResolveExtensionProcs(void)'
-        print '{'
-
-        for w in sorted(wrappers.keys()) :
-                funcname = prefix + w
-                print '  PRERESOLVE(PFN' + funcname.upper() + 'PROC, "' + funcname + '");'
-
-        print '}\n'
+# THE MATERIALS ARE 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
+# MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
+
+import sys, time, pdb, string, cProfile
+from reg import *
+
+# Default input / log files
+errFilename = None
+diagFilename = 'diag.txt'
+regFilename = 'gl.xml'
+outFilename = 'gen_gl_wrappers.c'
+
+protect=True
+prefix="gl"
+preresolve=False
+wrapper=False
+shim=False
+thunk=False
+thunkdefs=False
+staticwrappers=False
+nodebug=False
+
+#exclude base WGL API
+WinGDI={key: 1 for key in [
+     "wglCopyContext"
+    ,"wglCreateContext"
+    ,"wglCreateLayerContext"
+    ,"wglDeleteContext"
+    ,"wglGetCurrentContext"
+    ,"wglGetCurrentDC"
+    ,"wglGetProcAddress"
+    ,"wglMakeCurrent"
+    ,"wglShareLists"
+    ,"wglUseFontBitmapsA"
+    ,"wglUseFontBitmapsW"
+    ,"wglUseFontBitmaps"
+    ,"SwapBuffers"
+    ,"wglUseFontOutlinesA"
+    ,"wglUseFontOutlinesW"
+    ,"wglUseFontOutlines"
+    ,"wglDescribeLayerPlane"
+    ,"wglSetLayerPaletteEntries"
+    ,"wglGetLayerPaletteEntries"
+    ,"wglRealizeLayerPalette"
+    ,"wglSwapLayerBuffers"
+    ,"wglSwapMultipleBuffers"
+    ,"ChoosePixelFormat"
+    ,"DescribePixelFormat"
+    ,"GetEnhMetaFilePixelFormat"
+    ,"GetPixelFormat"
+    ,"SetPixelFormat"
+]}
+
+if __name__ == '__main__':
+    i = 1
+    while (i < len(sys.argv)):
+        arg = sys.argv[i]
+        i = i + 1
+        if (arg == '-noprotect'):
+            print('Disabling inclusion protection in output headers', file=sys.stderr)
+            protect = False
+        elif (arg == '-registry'):
+            regFilename = sys.argv[i]
+            i = i+1
+            print('Using registry', regFilename, file=sys.stderr)
+        elif (arg == '-outfile'):
+            outFilename = sys.argv[i]
+            i = i+1
+        elif (arg == '-preresolve'):
+            preresolve=True
+        elif (arg == '-wrapper'):
+            wrapper=True
+        elif (arg == '-shim'):
+            shim=True
+        elif (arg == '-thunk'):
+            thunk=True
+        elif (arg == '-thunkdefs'):
+            thunkdefs=True
+        elif (arg == '-staticwrappers'):
+            staticwrappers=True
+        elif (arg == '-prefix'):
+            prefix = sys.argv[i]
+            i = i+1
+        elif (arg == '-nodebug'):
+            nodebug = True
+        elif (arg[0:1] == '-'):
+            print('Unrecognized argument:', arg, file=sys.stderr)
+            exit(1)
+
+print('Generating', outFilename, file=sys.stderr)
+
+# Load & parse registry
+reg = Registry()
+tree = etree.parse(regFilename)
+reg.loadElementTree(tree)
+
+allVersions = '.*'
+
+genOpts = CGeneratorOptions(
+        apiname           = prefix,
+        profile           = 'compatibility',
+        versions          = allVersions,
+        emitversions      = allVersions,
+        defaultExtensions = prefix,                   # Default extensions for GL
+        protectFile       = protect,
+        protectFeature    = protect,
+        protectProto      = protect,
+        )
+
+# create error/warning & diagnostic files
+if (errFilename):
+    errWarn = open(errFilename,'w')
+else:
+    errWarn = sys.stderr
+diag = open(diagFilename, 'w')
+
+class PreResolveOutputGenerator(OutputGenerator):
+    def __init__(self,
+                 errFile = sys.stderr,
+                 warnFile = sys.stderr,
+                 diagFile = sys.stdout):
+        OutputGenerator.__init__(self, errFile, warnFile, diagFile)
+        self.wrappers={}
+    def beginFile(self, genOpts):
+        self.outFile.write('/* Automatically generated from %s - DO NOT EDIT */\n\n'%regFilename)
+    def endFile(self):
+        self.outFile.write('\nvoid ' + prefix + 'ResolveExtensionProcs(void)\n{\n')
+        for funcname in self.wrappers.keys():
+            self.outFile.write( '  PRERESOLVE(PFN' + funcname.upper() + 'PROC, "' + funcname + '");\n')
+        self.outFile.write('}\n\n')
+    def beginFeature(self, interface, emit):
+        OutputGenerator.beginFeature(self, interface, emit)
+    def endFeature(self):
+        OutputGenerator.endFeature(self)
+    def genType(self, typeinfo, name):
+        OutputGenerator.genType(self, typeinfo, name)
+    def genEnum(self, enuminfo, name):
+        OutputGenerator.genEnum(self, enuminfo, name)
+    def genCmd(self, cmd, name):
+        OutputGenerator.genCmd(self, cmd, name)
+
+        if name in WinGDI:
+            return
+
+        self.outFile.write('RESOLVE_DECL(PFN' + name.upper() + 'PROC);\n')
+        self.wrappers[name]=1
+
+class WrapperOutputGenerator(OutputGenerator):
+    def __init__(self,
+                 errFile = sys.stderr,
+                 warnFile = sys.stderr,
+                 diagFile = sys.stdout):
+        OutputGenerator.__init__(self, errFile, warnFile, diagFile)
+    def beginFile(self, genOpts):
+        self.outFile.write('/* Automatically generated from %s - DO NOT EDIT */\n\n'%regFilename)
+    def endFile(self):
+        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')
+    def endFeature(self):
+        OutputGenerator.endFeature(self)
+    def genType(self, typeinfo, name):
+        OutputGenerator.genType(self, typeinfo, name)
+    def genEnum(self, enuminfo, name):
+        OutputGenerator.genEnum(self, enuminfo, name)
+    def genCmd(self, cmd, name):
+        OutputGenerator.genCmd(self, cmd, name)
+
+        if name in WinGDI:
+            return
+
+        proto=noneStr(cmd.elem.find('proto'))
+        rettype=noneStr(proto.text)
+        if rettype.lower()!="void ":
+            plist = ([t for t in proto.itertext()])
+            rettype = ''.join(plist[:-1])
+        rettype=rettype.strip()
+        if staticwrappers: self.outFile.write("static ")
+        self.outFile.write("%s %sWrapper("%(rettype, name))
+        params = cmd.elem.findall('param')
+        plist=[]
+        for param in params:
+            paramlist = ([t for t in param.itertext()])
+            paramtype = ''.join(paramlist[:-1])
+            paramname = paramlist[-1]
+            plist.append((paramtype, paramname))
+        Comma=""
+        if len(plist):
+            for ptype, pname in plist:
+                self.outFile.write("%s%s%s_"%(Comma, ptype, pname))
+                Comma=", "
+        else:
+            self.outFile.write("void")
 
-#
-# now emit the wrappers
-# for GL 1.0 and 1.1 functions, generate stdcall wrappers which call the function directly
-# for GL 1.2+ functions, generate wrappers which use wglGetProcAddress()
-#
+        self.outFile.write(")\n{\n")
 
-for w in sorted(wrappers.keys()) :
+        # for GL 1.0 and 1.1 functions, generate stdcall wrappers which call the function directly
+        if self.OldVersion:
+            if not nodebug:
+                self.outFile.write('  if (glxWinDebugSettings.enable%scallTrace) ErrorF("%s\\n");\n'%(prefix.upper(), name))
+                self.outFile.write("  glWinDirectProcCalls++;\n")
+                self.outFile.write("\n")
 
-        funcname = prefix + w
-        returntype = wrappers[w]['return']
-        if returntype != 'void' :
-                returntype = typemap[returntype]
+            if rettype.lower()=="void":
+                self.outFile.write("  %s( "%(name))
+            else:
+                self.outFile.write("  return %s( "%(name))
 
-        # Avoid generating wrappers which aren't referenced by the dispatch table
-        if dispatchheader and not dispatch.has_key(w) :
-                print '/* No wrapper for ' + funcname + ', not in dispatch table */'
-                continue
+            Comma=""
+            for ptype, pname in plist:
+                self.outFile.write("%s%s_"%(Comma, pname))
+                Comma=", "
 
-        # manufacture arglist
-        # if no param attributes were found, it should be 'void'
-        al = []
-        for k in sorted(wrappers[w].keys()) :
-                if k.startswith('param') :
-                        l = wrappers[w][k].split()
+        # for GL 1.2+ functions, generate stdcall wrappers which use wglGetProcAddress()
+        else:
+            if rettype.lower()=="void":
+                self.outFile.write('  RESOLVE(PFN%sPROC, "%s");\n'%(name.upper(), name))
+
+                if not nodebug:
+                    self.outFile.write("\n")
+                    self.outFile.write('  if (glxWinDebugSettings.enable%scallTrace) ErrorF("%s\\n");\n'%(prefix.upper(), name))
+                    self.outFile.write("\n")
+
+                self.outFile.write("  RESOLVED_PROC(PFN%sPROC)( """%(name.upper()))
+            else:
+                self.outFile.write('  RESOLVE_RET(PFN%sPROC, "%s", FALSE);\n'%(name.upper(), name))
+
+                if not nodebug:
+                    self.outFile.write("\n")
+                    self.outFile.write('  if (glxWinDebugSettings.enable%scallTrace) ErrorF("%s\\n");\n'%(prefix.upper(), name))
+                    self.outFile.write("\n")
+
+                self.outFile.write("  return RESOLVED_PROC(PFN%sPROC)("%(name.upper()))
+
+            Comma=""
+            for ptype, pname in plist:
+                self.outFile.write("%s%s_"%(Comma, pname))
+                Comma=", "
+        self.outFile.write(" );\n}\n\n")
+
+class ThunkOutputGenerator(OutputGenerator):
+    def __init__(self,
+                 errFile = sys.stderr,
+                 warnFile = sys.stderr,
+                 diagFile = sys.stdout):
+        OutputGenerator.__init__(self, errFile, warnFile, diagFile)
+    def beginFile(self, genOpts):
+        self.outFile.write('/* Automatically generated from %s - DO NOT EDIT */\n\n'%regFilename)
+    def endFile(self):
+        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')
+    def endFeature(self):
+        OutputGenerator.endFeature(self)
+    def genType(self, typeinfo, name):
+        OutputGenerator.genType(self, typeinfo, name)
+    def genEnum(self, enuminfo, name):
+        OutputGenerator.genEnum(self, enuminfo, name)
+    def genCmd(self, cmd, name):
+        OutputGenerator.genCmd(self, cmd, name)
+
+        proto=noneStr(cmd.elem.find('proto'))
+        rettype=noneStr(proto.text)
+        if rettype.lower()!="void ":
+            plist = ([t for t in proto.itertext()])
+            rettype = ''.join(plist[:-1])
+        rettype=rettype.strip()
+        self.outFile.write("%s %sWrapper("%(rettype, name))
+        params = cmd.elem.findall('param')
+        plist=[]
+        for param in params:
+            paramlist = ([t for t in param.itertext()])
+            paramtype = ''.join(paramlist[:-1])
+            paramname = paramlist[-1]
+            plist.append((paramtype, paramname))
+        Comma=""
+        if len(plist):
+            for ptype, pname in plist:
+                self.outFile.write("%s%s%s_"%(Comma, ptype, pname))
+                Comma=", "
+        else:
+            self.outFile.write("void")
 
-                        # ensure formal parameter names don't collide with reserved names or shadow global declarations
-                        l[0] = l[0] + '_'
+        self.outFile.write(")\n{\n")
 
-                        if l[2] == 'in' :
-                                if l[3] == 'array' :
-                                        arg = 'const ' + typemap[l[1]] + ' *' + l[0]
-                                else :
-                                        arg = typemap[l[1]] + ' ' + l[0]
-                        elif l[2] == 'out' :
-                                arg = typemap[l[1]] + ' *' + l[0]
+        # for GL 1.0 and 1.1 functions, generate stdcall thunk wrappers which call the function directly
+        if self.OldVersion:
+            if rettype.lower()=="void":
+                self.outFile.write("  %s( "%(name))
+            else:
+                self.outFile.write("  return %s( "%(name))
 
-                        al.append(arg)
+            Comma=""
+            for ptype, pname in plist:
+                self.outFile.write("%s%s_"%(Comma, pname))
+                Comma=", "
 
-        if len(al) == 0 :
-                arglist = 'void'
+        # for GL 1.2+ functions, generate wrappers which use wglGetProcAddress()
         else:
-                arglist  = ', '.join(al)
-
-        if wrappers[w]['category'].startswith('VERSION_1_0') or wrappers[w]['category'].startswith('VERSION_1_1') :
-                if staticwrappers :
-                        print 'static',
-                print returntype + ' ' + funcname + 'Wrapper(' + arglist + ')'
-                print '{'
-                print '  if (glxWinDebugSettings.enable' + prefix.upper() + 'callTrace) ErrorF("'+ funcname + '\\n");'
-                print '  glWinDirectProcCalls++;'
-                if returntype.lower() == 'void' :
-                        print '  ' +  funcname + '(',
-                else :
-                        print ' /* returntype was ' + returntype.lower() + '*/'
-                        print '  return ' +  funcname + '(',
-
-                if arglist != 'void' :
-                        print wrappers[w]['arglist_use'],
-
-                print ');'
-                print "}\n"
+            if rettype.lower()=="void":
+                self.outFile.write('  RESOLVE(PFN%sPROC, "%s");\n'%(name.upper(), name))
+                self.outFile.write("  RESOLVED_PROC(PFN%sPROC)( """%(name.upper()))
+            else:
+                self.outFile.write('  RESOLVE_RET(PFN%sPROC, "%s", FALSE);\n'%(name.upper(), name))
+                self.outFile.write("  return RESOLVED_PROC(PFN%sPROC)("%(name.upper()))
+
+            Comma=""
+            for ptype, pname in plist:
+                self.outFile.write("%s%s_"%(Comma, pname))
+                Comma=", "
+        self.outFile.write(" );\n}\n\n")
+
+class ThunkDefsOutputGenerator(OutputGenerator):
+    def __init__(self,
+                 errFile = sys.stderr,
+                 warnFile = sys.stderr,
+                 diagFile = sys.stdout):
+        OutputGenerator.__init__(self, errFile, warnFile, diagFile)
+    def beginFile(self, genOpts):
+        self.outFile.write("EXPORTS\n"); # this must be the first line for libtool to realize this is a .def file
+        self.outFile.write('; Automatically generated from %s - DO NOT EDIT\n\n'%regFilename)
+    def endFile(self):
+        pass
+    def beginFeature(self, interface, emit):
+        OutputGenerator.beginFeature(self, interface, emit)
+    def endFeature(self):
+        OutputGenerator.endFeature(self)
+    def genType(self, typeinfo, name):
+        OutputGenerator.genType(self, typeinfo, name)
+    def genEnum(self, enuminfo, name):
+        OutputGenerator.genEnum(self, enuminfo, name)
+    def genCmd(self, cmd, name):
+        OutputGenerator.genCmd(self, cmd, name)
+
+        # export the wrapper function with the name of the function it wraps
+        self.outFile.write("%s = %sWrapper\n"%(name, name))
+
+class ShimOutputGenerator(OutputGenerator):
+    def __init__(self,
+                 errFile = sys.stderr,
+                 warnFile = sys.stderr,
+                 diagFile = sys.stdout):
+        OutputGenerator.__init__(self, errFile, warnFile, diagFile)
+    def beginFile(self, genOpts):
+        self.outFile.write('/* Automatically generated from %s - DO NOT EDIT */\n\n'%regFilename)
+    def endFile(self):
+        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')
+    def endFeature(self):
+        OutputGenerator.endFeature(self)
+    def genType(self, typeinfo, name):
+        OutputGenerator.genType(self, typeinfo, name)
+    def genEnum(self, enuminfo, name):
+        OutputGenerator.genEnum(self, enuminfo, name)
+    def genCmd(self, cmd, name):
+        OutputGenerator.genCmd(self, cmd, name)
+
+        if not self.OldVersion:
+            return
+
+        # for GL functions which are in the ABI, generate a shim which calls the function via GetProcAddress
+        proto=noneStr(cmd.elem.find('proto'))
+        rettype=noneStr(proto.text)
+        if rettype.lower()!="void ":
+            plist = ([t for t in proto.itertext()])
+            rettype = ''.join(plist[:-1])
+        rettype=rettype.strip()
+        self.outFile.write("%s %s("%(rettype, name))
+        params = cmd.elem.findall('param')
+        plist=[]
+        for param in params:
+            paramlist = ([t for t in param.itertext()])
+            paramtype = ''.join(paramlist[:-1])
+            paramname = paramlist[-1]
+            plist.append((paramtype, paramname))
+        Comma=""
+        if len(plist):
+            for ptype, pname in plist:
+                self.outFile.write("%s%s%s_"%(Comma, ptype, pname))
+                Comma=", "
         else:
-                if staticwrappers :
-                        print 'static',
-                print returntype + ' ' + funcname + 'Wrapper(' + arglist + ')'
-                print '{'
+            self.outFile.write("void")
 
-                stringname = funcname
+        self.outFile.write(")\n{\n")
 
-#
-# special case: Windows OpenGL implementations are far more likely to have GL_ARB_window_pos than GL_MESA_window_pos,
-# so arrange for the wrapper to use the ARB strings to find functions...
-#
+        self.outFile.write('  typedef %s (* PFN%sPROC)(' % (rettype, name.upper()))
 
-                m2 = r3.search(funcname)
-                if m2 :
-                        stringname = stringname.replace('MESA','ARB')
+        if len(plist):
+            Comma=""
+            for ptype, pname in plist:
+                self.outFile.write("%s %s %s_"%(Comma, ptype, pname))
+                Comma=", "
+        else:
+            self.outFile.write("void")
 
-#
-# special case: likewise, implementations are more likely to have GL_ARB_vertex_program than GL_NV_vertex_program,
-# especially if they are not NV implementations, so arrange for the wrapper to use ARB strings to find functions
-#
+        self.outFile.write(');\n')
 
-                m3 = r4.search(funcname)
-                if m3 :
-                        stringname = stringname.replace('NV','ARB')
-                m4 = r5.search(funcname)
-                if m4 :
-                        stringname = stringname.replace('NV','ARB')
-
-                pfntypename = 'PFN' + funcname.upper() + 'PROC'
-
-                if returntype.lower() == 'void' :
-                        print '  RESOLVE(' + pfntypename + ', "' + stringname + '");'
-                        print '  if (glxWinDebugSettings.enable' + prefix.upper() + 'callTrace) ErrorF("'+ funcname + '\\n");'
-                        print '  RESOLVED_PROC(' + pfntypename + ')(',
-                else :
-                        print '  RESOLVE_RET(' + pfntypename + ', "' + stringname + '", FALSE);'
-                        print '  if (glxWinDebugSettings.enable' + prefix.upper() + 'callTrace) ErrorF("'+ funcname + '\\n");'
-                        print '  return RESOLVED_PROC(' + pfntypename + ')(',
-
-                if arglist != 'void' :
-                        print wrappers[w]['arglist_use'],
-
-                print ');'
-                print "}\n"
-
-
-# generate function to setup the dispatch table, which sets each
-# dispatch table entry to point to it's wrapper function
-# (assuming we were able to make one)
-
-if dispatchheader :
-        print 'void glWinSetupDispatchTable(void)'
-        print '{'
-        print '  static struct _glapi_table *disp = NULL;'
-        print ''
-        print '  if (!disp)'
-        print '    {'
-        print '      disp = calloc(sizeof(void *), _glapi_get_dispatch_table_size());'
-        print '      assert(disp);'
-
-        for d in sorted(dispatch.keys()) :
-                if wrappers.has_key(d) :
-                        print '      SET_'+ d + '(disp, (void *)' + prefix + d + 'Wrapper);'
-                else :
-                        print '#warning  No wrapper for ' + prefix + d + ' !'
-
-        print '    }'
-        print ''
-        print '  _glapi_set_dispatch(disp);'
-        print '}'
+        if rettype.lower()=="void":
+            self.outFile.write('  RESOLVE(PFN%sPROC, "%s");\n'%(name.upper(), name))
+            self.outFile.write('  RESOLVED_PROC(')
+        else:
+            self.outFile.write('  RESOLVE_RET(PFN%sPROC, "%s", 0);\n'%(name.upper(), name))
+            self.outFile.write('  return RESOLVED_PROC(')
+
+        Comma=""
+        for ptype, pname in plist:
+            self.outFile.write("%s%s_"%(Comma, pname))
+            Comma=", "
+
+        self.outFile.write(" );\n}\n\n")
+
+def genHeaders():
+    outFile = open(outFilename,"w")
+
+    if preresolve:
+        gen = PreResolveOutputGenerator(errFile=errWarn,
+                                        warnFile=errWarn,
+                                        diagFile=diag)
+        gen.outFile=outFile
+        reg.setGenerator(gen)
+        reg.apiGen(genOpts)
+
+    if wrapper:
+        gen = WrapperOutputGenerator(errFile=errWarn,
+                                     warnFile=errWarn,
+                                     diagFile=diag)
+        gen.outFile=outFile
+        reg.setGenerator(gen)
+        reg.apiGen(genOpts)
+
+    if shim:
+        gen = ShimOutputGenerator(errFile=errWarn,
+                                  warnFile=errWarn,
+                                  diagFile=diag)
+        gen.outFile=outFile
+        reg.setGenerator(gen)
+        reg.apiGen(genOpts)
+
+    if thunk:
+        gen = ThunkOutputGenerator(errFile=errWarn,
+                                   warnFile=errWarn,
+                                   diagFile=diag)
+        gen.outFile=outFile
+        reg.setGenerator(gen)
+        reg.apiGen(genOpts)
+
+
+    if thunkdefs:
+        gen = ThunkDefsOutputGenerator(errFile=errWarn,
+                                       warnFile=errWarn,
+                                       diagFile=diag)
+        gen.outFile=outFile
+        reg.setGenerator(gen)
+        reg.apiGen(genOpts)
+
+    outFile.close()
+
+genHeaders()
diff --git a/hw/xwin/glx/glshim.c b/hw/xwin/glx/glshim.c
new file mode 100644
index 0000000..7109196
--- /dev/null
+++ b/hw/xwin/glx/glshim.c
@@ -0,0 +1,124 @@
+/*
+ * File: glshim.c
+ * Purpose: GL shim which redirects to a specified DLL
+ *
+ * Copyright (c) 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 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 ABOVE LISTED COPYRIGHT HOLDER(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.
+ */
+
+/*
+   A GL shim which redirects to a specified DLL
+
+   XWin is statically linked with this, rather than the system libGL, so that
+   GL calls can be directed to mesa cygGL-1.dll, or cygnativeGLthunk.dll
+   (which contains cdecl-to-stdcall thunks to the native openGL32.dll)
+*/
+
+#ifdef HAVE_XWIN_CONFIG_H
+#include <xwin-config.h>
+#endif
+
+#define GL_GLEXT_LEGACY
+#include <GL/gl.h>
+#undef GL_ARB_imaging
+#undef GL_VERSION_1_3
+#include <GL/glext.h>
+
+#include <X11/Xwindows.h>
+#include <os.h>
+#include "glwindows.h"
+#include <glx/glxserver.h>
+
+static HMODULE hMod = NULL;
+
+/*
+  Implement the __glGetProcAddress function by just using GetProcAddress() on the selected DLL
+*/
+void *glXGetProcAddressARB(const char *symbol)
+{
+    void *proc;
+
+    /* Default to the mesa GL implementation if one hasn't been selected yet */
+    if (!hMod)
+        glWinSelectImplementation(0);
+
+    proc = GetProcAddress(hMod, symbol);
+
+    if (glxWinDebugSettings.enableGLcallTrace)
+        ErrorF("glXGetProcAddressARB: Resolved '%s' in %p to %p\n", symbol, hMod, proc);
+
+    return proc;
+}
+
+/*
+  Select a GL implementation DLL
+*/
+int glWinSelectImplementation(int native)
+{
+    const char *dllname;
+
+    if (native) {
+        dllname = "cygnativeGLthunk.dll";
+    }
+    else {
+        dllname = "cygGL-1.dll";
+    }
+
+    hMod = LoadLibraryEx(dllname, NULL, 0);
+    if (hMod == NULL) {
+        ErrorF("glWinSelectGLimplementation: Could not load '%s'\n", dllname);
+        return -1;
+    }
+
+    ErrorF("glWinSelectGLimplementation: Loaded '%s'\n", dllname);
+
+    /* Connect __glGetProcAddress() to our implementation of glXGetProcAddressARB() above */
+    __glXsetGetProcAddress((glx_gpa_proc)glXGetProcAddressARB);
+
+    return 0;
+}
+
+#define RESOLVE_RET(proctype, symbol, retval) \
+    proctype proc = (proctype)glXGetProcAddressARB(symbol);   \
+    if (proc == NULL) return retval;
+
+#define RESOLVE(proctype, symbol) RESOLVE_RET(proctype, symbol,)
+#define RESOLVED_PROC proc
+
+/* Include generated shims for direct linkage to GL functions which are in the ABI */
+#include "generated_gl_shim.c"
+
+/*
+  Special wrapper for glAddSwapHintRectWIN for copySubBuffers
+
+  Only used with native GL if the GL_WIN_swap_hint extension is present, so we enable
+  GLX_MESA_copy_sub_buffer
+*/
+typedef void (__stdcall * PFNGLADDSWAPHINTRECTWIN) (GLint x, GLint y,
+                                                    GLsizei width,
+                                                    GLsizei height);
+
+void
+glAddSwapHintRectWINWrapper(GLint x, GLint y, GLsizei width,
+                            GLsizei height)
+{
+    RESOLVE(PFNGLADDSWAPHINTRECTWIN, "glAddSwapHintRectWIN");
+    RESOLVED_PROC(x, y, width, height);
+}
diff --git a/hw/xwin/glx/glthunk.c b/hw/xwin/glx/glthunk.c
new file mode 100644
index 0000000..d49fe48
--- /dev/null
+++ b/hw/xwin/glx/glthunk.c
@@ -0,0 +1,87 @@
+/*
+ * File: glthunk.c
+ * Purpose: cdecl thunk wrapper library for Win32 stdcall OpenGL library
+ *
+ * Copyright (c) Jon TURNEY 2009,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 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 ABOVE LISTED COPYRIGHT HOLDER(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.
+ */
+
+// define USE_OPENGL32 makes gl.h declare gl*() function prototypes with stdcall linkage,
+// so our generated wrappers will correctly link with the functions in opengl32.dll
+#define USE_OPENGL32
+
+#ifdef HAVE_XWIN_CONFIG_H
+#include <xwin-config.h>
+#endif
+
+#include <X11/Xwindows.h>
+
+#define GL_GLEXT_LEGACY
+#include <GL/gl.h>
+#undef GL_ARB_imaging
+#undef GL_VERSION_1_3
+#include <GL/glext.h>
+
+static PROC
+glWinResolveHelper(PROC * cache, const char *symbol)
+{
+    PROC proc = NULL;
+
+    /* If not yet cached, call wglGetProcAddress */
+    if ((*cache) == NULL) {
+        proc = wglGetProcAddress(symbol);
+        if (proc == NULL) {
+            (*cache) = (PROC) - 1;
+        }
+        else {
+            (*cache) = proc;
+        }
+    }
+    /* Cached wglGetProcAddress failure */
+    else if ((*cache) == (PROC) - 1) {
+        proc = 0;
+    }
+    /* Cached wglGetProcAddress result */
+    else {
+        proc = (*cache);
+    }
+
+    return proc;
+}
+
+#define RESOLVE_RET(proctype, symbol, retval) \
+    static PROC cache = NULL; \
+    __stdcall proctype proc = (proctype)glWinResolveHelper(&cache, symbol); \
+    if (proc == NULL) { \
+        return retval; \
+    }
+
+#define RESOLVE(proctype, symbol) RESOLVE_RET(proctype, symbol,)
+
+#define RESOLVED_PROC(proctype) proc
+
+/*
+  Include generated cdecl wrappers for stdcall gl*() functions in opengl32.dll
+
+  OpenGL 1.2 and upward is treated as extensions, function address must
+  found using wglGetProcAddress(), but also stdcall so still need wrappers...
+*/
+
+#include "generated_gl_thunks.c"
diff --git a/hw/xwin/glx/glwindows.h b/hw/xwin/glx/glwindows.h
index ec1d1f5..4f859b4 100644
--- a/hw/xwin/glx/glwindows.h
+++ b/hw/xwin/glx/glwindows.h
@@ -42,12 +42,9 @@ typedef struct {
 
 extern glxWinDebugSettingsRec glxWinDebugSettings;
 
-void glWinCallDelta(void);
 void glxWinPushNativeProvider(void);
-const GLubyte *glGetStringWrapperNonstatic(GLenum name);
-void glAddSwapHintRectWINWrapperNonstatic(GLint x, GLint y, GLsizei width,
-                                          GLsizei height);
-void glWinSetupDispatchTable(void);
+void glAddSwapHintRectWINWrapper(GLint x, GLint y, GLsizei width, GLsizei height);
+int glWinSelectImplementation(int native);
 
 #if 1
 #define GLWIN_TRACE_MSG(msg, args...) if (glxWinDebugSettings.enableTrace) ErrorF(msg " [%s:%d]\n" , ##args , __FUNCTION__, __LINE__ )
diff --git a/hw/xwin/glx/glwrap.c b/hw/xwin/glx/glwrap.c
deleted file mode 100644
index 73cff3c..0000000
--- a/hw/xwin/glx/glwrap.c
+++ /dev/null
@@ -1,146 +0,0 @@
-/*
- * File: glwrap.c
- * Purpose: Wrapper functions for Win32 OpenGL functions
- *
- * Authors: Alexander Gottwald
- *          Jon TURNEY
- *
- * Copyright (c) Jon TURNEY 2009
- * Copyright (c) Alexander Gottwald 2004
- *
- *
- * 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 ABOVE LISTED COPYRIGHT HOLDER(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.
- */
-
-// define USE_OPENGL32 makes gl.h declare gl*() function prototypes with stdcall linkage,
-// so our generated wrappers will correctly link with the functions in opengl32.dll
-#define USE_OPENGL32
-
-#ifdef HAVE_XWIN_CONFIG_H
-#include <xwin-config.h>
-#endif
-
-#include <X11/Xwindows.h>
-#include <GL/gl.h>
-#include <GL/glext.h>
-#include <glx/glxserver.h>
-#include <glx/glxext.h>
-#include <glx/glapi.h>
-#include <glx/dispatch.h>
-#include <glwindows.h>
-
-static unsigned int glWinIndirectProcCalls = 0;
-static unsigned int glWinDirectProcCalls = 0;
-
-void
-glWinCallDelta(void)
-{
-    static unsigned int glWinIndirectProcCallsLast = 0;
-    static unsigned int glWinDirectProcCallsLast = 0;
-
-    if ((glWinIndirectProcCalls != glWinIndirectProcCallsLast) ||
-        (glWinDirectProcCalls != glWinDirectProcCallsLast)) {
-        if (glxWinDebugSettings.enableTrace) {
-            ErrorF("after %d direct and %d indirect GL calls\n",
-                   glWinDirectProcCalls - glWinDirectProcCallsLast,
-                   glWinIndirectProcCalls - glWinIndirectProcCallsLast);
-        }
-        glWinDirectProcCallsLast = glWinDirectProcCalls;
-        glWinIndirectProcCallsLast = glWinIndirectProcCalls;
-    }
-}
-
-static PROC
-glWinResolveHelper(PROC * cache, const char *symbol)
-{
-    PROC proc = NULL;
-
-    /* If not yet cached, call wglGetProcAddress */
-    if ((*cache) == NULL) {
-        proc = wglGetProcAddress(symbol);
-        if (proc == NULL) {
-            ErrorF("glwrap: Can't resolve \"%s\"\n", symbol);
-            (*cache) = (PROC) - 1;
-        }
-        else {
-            ErrorF("glwrap: Resolved \"%s\"\n", symbol);
-            (*cache) = proc;
-        }
-    }
-    /* Cached wglGetProcAddress failure */
-    else if ((*cache) == (PROC) - 1) {
-        proc = 0;
-    }
-    /* Cached wglGetProcAddress result */
-    else {
-        proc = (*cache);
-    }
-
-    return proc;
-}
-
-#define RESOLVE_RET(proctype, symbol, retval) \
-    static PROC cache = NULL; \
-    __stdcall proctype proc = (proctype)glWinResolveHelper(&cache, symbol); \
-    if (proc == NULL) { \
-        __glXErrorCallBack(0); \
-        return retval; \
-    } \
-    glWinIndirectProcCalls++;
-
-#define RESOLVE(proctype, symbol) RESOLVE_RET(proctype, symbol,)
-
-#define RESOLVED_PROC(proctype) proc
-
-/*
-  Include generated cdecl wrappers for stdcall gl*() functions in opengl32.dll
-
-  OpenGL 1.2 and upward is treated as extensions, function address must
-  found using wglGetProcAddress(), but also stdcall so still need wrappers...
-
-  Include generated dispatch table setup function
-*/
-
-#include "generated_gl_wrappers.c"
-
-/*
-  Special non-static wrapper for glGetString for debug output
-*/
-
-const GLubyte *
-glGetStringWrapperNonstatic(GLenum name)
-{
-    return glGetString(name);
-}
-
-/*
-  Special non-static wrapper for glAddSwapHintRectWIN for copySubBuffers
-*/
-
-typedef void (__stdcall * PFNGLADDSWAPHINTRECTWIN) (GLint x, GLint y,
-                                                    GLsizei width,
-                                                    GLsizei height);
-
-void
-glAddSwapHintRectWINWrapperNonstatic(GLint x, GLint y, GLsizei width,
-                                     GLsizei height)
-{
-    RESOLVE(PFNGLADDSWAPHINTRECTWIN, "glAddSwapHintRectWIN");
-    proc(x, y, width, height);
-}
diff --git a/hw/xwin/glx/indirect.c b/hw/xwin/glx/indirect.c
index 4f09652..3d01bed 100644
--- a/hw/xwin/glx/indirect.c
+++ b/hw/xwin/glx/indirect.c
@@ -550,7 +550,9 @@ glxWinScreenProbe(ScreenPtr pScreen)
     if (NULL == screen)
         return NULL;
 
-    /* Dump out some useful information about the native renderer */
+    // Select the native GL implementation (WGL)
+    if (glWinSelectImplementation(1))
+        return NULL;
 
     // create window class
 #define WIN_GL_TEST_WINDOW_CLASS "XWinGLTest"
@@ -597,11 +599,12 @@ glxWinScreenProbe(ScreenPtr pScreen)
     // (but we need to have a current context for them to be resolvable)
     wglResolveExtensionProcs();
 
-    ErrorF("GL_VERSION:     %s\n", glGetStringWrapperNonstatic(GL_VERSION));
-    ErrorF("GL_VENDOR:      %s\n", glGetStringWrapperNonstatic(GL_VENDOR));
-    gl_renderer = (const char *) glGetStringWrapperNonstatic(GL_RENDERER);
+    /* Dump out some useful information about the native renderer */
+    ErrorF("GL_VERSION:     %s\n", glGetString(GL_VERSION));
+    ErrorF("GL_VENDOR:      %s\n", glGetString(GL_VENDOR));
+    gl_renderer = (const char *) glGetString(GL_RENDERER);
     ErrorF("GL_RENDERER:    %s\n", gl_renderer);
-    gl_extensions = (const char *) glGetStringWrapperNonstatic(GL_EXTENSIONS);
+    gl_extensions = (const char *) glGetString(GL_EXTENSIONS);
     wgl_extensions = wglGetExtensionsStringARBWrapper(hdc);
     if (!wgl_extensions)
         wgl_extensions = "";
@@ -615,7 +618,7 @@ glxWinScreenProbe(ScreenPtr pScreen)
         free(screen);
         LogMessage(X_ERROR,
                    "AIGLX: Won't use generic native renderer as it is not accelerated\n");
-        return NULL;
+        goto error;
     }
 
     // Can you see the problem here?  The extensions string is DC specific
@@ -726,7 +729,7 @@ glxWinScreenProbe(ScreenPtr pScreen)
             free(screen);
             LogMessage(X_ERROR,
                        "AIGLX: No fbConfigs could be made from native OpenGL pixel formats\n");
-            return NULL;
+            goto error;
         }
 
         /* These will be set by __glXScreenInit */
@@ -789,6 +792,13 @@ glxWinScreenProbe(ScreenPtr pScreen)
     pScreen->CopyWindow = glxWinCopyWindow;
 
     return &screen->base;
+
+ error:
+    // Something went wrong and we can't use the native GL implementation
+    // so make sure the mesa GL implementation is selected instead
+    glWinSelectImplementation(0);
+
+    return NULL;
 }
 
 /* ---------------------------------------------------------------------- */
@@ -910,7 +920,7 @@ static void
 glxWinDrawableCopySubBuffer(__GLXdrawable * drawable,
                             int x, int y, int w, int h)
 {
-    glAddSwapHintRectWINWrapperNonstatic(x, y, w, h);
+    glAddSwapHintRectWINWrapper(x, y, w, h);
     glxWinDrawableSwapBuffers(NULL, drawable);
 }
 
@@ -1458,7 +1468,6 @@ glxWinContextMakeCurrent(__GLXcontext * base)
 
     GLWIN_TRACE_MSG("glxWinContextMakeCurrent context %p (native ctx %p)", gc,
                     gc->ctx);
-    glWinCallDelta();
 
     /* Keep a note of the last active context in the drawable */
     drawPriv = gc->base.drawPriv;
@@ -1528,7 +1537,6 @@ glxWinContextLoseCurrent(__GLXcontext * base)
 
     GLWIN_TRACE_MSG("glxWinContextLoseCurrent context %p (native ctx %p)", gc,
                     gc->ctx);
-    glWinCallDelta();
 
     /*
        An error seems to be reported if we try to make no context current
@@ -1623,8 +1631,6 @@ glxWinCreateContext(__GLXscreen * screen,
     context->ctx = NULL;
     context->shareContext = shareContext;
 
-    glWinSetupDispatchTable();
-
     GLWIN_DEBUG_MSG("GLXcontext %p created", context);
 
     return &(context->base);
commit cb48877a3c4cfb1ae2248000fcd3443e3092bdaa
Author: Jon TURNEY <jon.turney at dronecode.org.uk>
Date:   Fri Dec 6 14:00:21 2013 +0000

    glx: Consistently use ARB-suffixed names for ARB_multitexture functions
    
    At the moment we have a mix of ARB and non-ARB suffixed forms for ARB_multitexture functions
    e.g. glMultiTexCoord1fvARB and glMultiTexCoord1dv
    
    Consistently use the ARB-suffixed form, assuming that is present in all libGL
    which provide the OpenGL 1.2.1 ABI we expect to be able to directly link with.
    
    Signed-off-by: Jon TURNEY <jon.turney at dronecode.org.uk>
    Reviewed-by: Adam Jackson <ajax at redhat.com>

diff --git a/glx/indirect_dispatch.c b/glx/indirect_dispatch.c
index c7a95a4..329b2e6 100644
--- a/glx/indirect_dispatch.c
+++ b/glx/indirect_dispatch.c
@@ -3460,7 +3460,7 @@ __glXDisp_CopyTexSubImage3D(GLbyte * pc)
 void
 __glXDisp_ActiveTexture(GLbyte * pc)
 {
-    glActiveTexture(*(GLenum *) (pc + 0));
+    glActiveTextureARB(*(GLenum *) (pc + 0));
 }
 
 void
@@ -3473,7 +3473,7 @@ __glXDisp_MultiTexCoord1dv(GLbyte * pc)
     }
 #endif
 
-    glMultiTexCoord1dv(*(GLenum *) (pc + 8), (const GLdouble *) (pc + 0));
+    glMultiTexCoord1dvARB(*(GLenum *) (pc + 8), (const GLdouble *) (pc + 0));
 }
 
 void
@@ -3485,13 +3485,13 @@ __glXDisp_MultiTexCoord1fvARB(GLbyte * pc)
 void
 __glXDisp_MultiTexCoord1iv(GLbyte * pc)
 {
-    glMultiTexCoord1iv(*(GLenum *) (pc + 0), (const GLint *) (pc + 4));
+    glMultiTexCoord1ivARB(*(GLenum *) (pc + 0), (const GLint *) (pc + 4));
 }
 
 void
 __glXDisp_MultiTexCoord1sv(GLbyte * pc)
 {
-    glMultiTexCoord1sv(*(GLenum *) (pc + 0), (const GLshort *) (pc + 4));
+    glMultiTexCoord1svARB(*(GLenum *) (pc + 0), (const GLshort *) (pc + 4));
 }
 
 void
@@ -3504,7 +3504,7 @@ __glXDisp_MultiTexCoord2dv(GLbyte * pc)
     }
 #endif
 
-    glMultiTexCoord2dv(*(GLenum *) (pc + 16), (const GLdouble *) (pc + 0));
+    glMultiTexCoord2dvARB(*(GLenum *) (pc + 16), (const GLdouble *) (pc + 0));
 }
 
 void
@@ -3516,13 +3516,13 @@ __glXDisp_MultiTexCoord2fvARB(GLbyte * pc)
 void
 __glXDisp_MultiTexCoord2iv(GLbyte * pc)
 {
-    glMultiTexCoord2iv(*(GLenum *) (pc + 0), (const GLint *) (pc + 4));
+    glMultiTexCoord2ivARB(*(GLenum *) (pc + 0), (const GLint *) (pc + 4));
 }
 
 void
 __glXDisp_MultiTexCoord2sv(GLbyte * pc)
 {
-    glMultiTexCoord2sv(*(GLenum *) (pc + 0), (const GLshort *) (pc + 4));
+    glMultiTexCoord2svARB(*(GLenum *) (pc + 0), (const GLshort *) (pc + 4));
 }
 
 void
@@ -3535,7 +3535,7 @@ __glXDisp_MultiTexCoord3dv(GLbyte * pc)
     }
 #endif
 
-    glMultiTexCoord3dv(*(GLenum *) (pc + 24), (const GLdouble *) (pc + 0));
+    glMultiTexCoord3dvARB(*(GLenum *) (pc + 24), (const GLdouble *) (pc + 0));
 }
 
 void
@@ -3547,13 +3547,13 @@ __glXDisp_MultiTexCoord3fvARB(GLbyte * pc)
 void
 __glXDisp_MultiTexCoord3iv(GLbyte * pc)
 {
-    glMultiTexCoord3iv(*(GLenum *) (pc + 0), (const GLint *) (pc + 4));
+    glMultiTexCoord3ivARB(*(GLenum *) (pc + 0), (const GLint *) (pc + 4));
 }
 
 void
 __glXDisp_MultiTexCoord3sv(GLbyte * pc)
 {
-    glMultiTexCoord3sv(*(GLenum *) (pc + 0), (const GLshort *) (pc + 4));
+    glMultiTexCoord3svARB(*(GLenum *) (pc + 0), (const GLshort *) (pc + 4));
 }
 
 void
@@ -3566,7 +3566,7 @@ __glXDisp_MultiTexCoord4dv(GLbyte * pc)
     }
 #endif
 
-    glMultiTexCoord4dv(*(GLenum *) (pc + 32), (const GLdouble *) (pc + 0));
+    glMultiTexCoord4dvARB(*(GLenum *) (pc + 32), (const GLdouble *) (pc + 0));
 }
 
 void
@@ -3578,13 +3578,13 @@ __glXDisp_MultiTexCoord4fvARB(GLbyte * pc)
 void
 __glXDisp_MultiTexCoord4iv(GLbyte * pc)
 {
-    glMultiTexCoord4iv(*(GLenum *) (pc + 0), (const GLint *) (pc + 4));
+    glMultiTexCoord4ivARB(*(GLenum *) (pc + 0), (const GLint *) (pc + 4));
 }
 
 void
 __glXDisp_MultiTexCoord4sv(GLbyte * pc)
 {
-    glMultiTexCoord4sv(*(GLenum *) (pc + 0), (const GLshort *) (pc + 4));
+    glMultiTexCoord4svARB(*(GLenum *) (pc + 0), (const GLshort *) (pc + 4));
 }
 
 void
diff --git a/glx/indirect_dispatch_swap.c b/glx/indirect_dispatch_swap.c
index ebb2ec6..647d0c9 100644
--- a/glx/indirect_dispatch_swap.c
+++ b/glx/indirect_dispatch_swap.c
@@ -3821,7 +3821,7 @@ __glXDispSwap_CopyTexSubImage3D(GLbyte * pc)
 void
 __glXDispSwap_ActiveTexture(GLbyte * pc)
 {
-    glActiveTexture((GLenum) bswap_ENUM(pc + 0));
+    glActiveTextureARB((GLenum) bswap_ENUM(pc + 0));
 }
 
 void
@@ -3834,8 +3834,8 @@ __glXDispSwap_MultiTexCoord1dv(GLbyte * pc)
     }
 #endif
 
-    glMultiTexCoord1dv((GLenum) bswap_ENUM(pc + 8),
-                       (const GLdouble *) bswap_64_array((uint64_t *) (pc + 0),
+    glMultiTexCoord1dvARB((GLenum) bswap_ENUM(pc + 8),
+                          (const GLdouble *) bswap_64_array((uint64_t *) (pc + 0),
                                                          1));
 }
 
@@ -3850,17 +3850,17 @@ __glXDispSwap_MultiTexCoord1fvARB(GLbyte * pc)
 void
 __glXDispSwap_MultiTexCoord1iv(GLbyte * pc)
 {
-    glMultiTexCoord1iv((GLenum) bswap_ENUM(pc + 0),
-                       (const GLint *) bswap_32_array((uint32_t *) (pc + 4),
-                                                      1));
+    glMultiTexCoord1ivARB((GLenum) bswap_ENUM(pc + 0),
+                          (const GLint *) bswap_32_array((uint32_t *) (pc + 4),
+                                                         1));
 }
 
 void
 __glXDispSwap_MultiTexCoord1sv(GLbyte * pc)
 {
-    glMultiTexCoord1sv((GLenum) bswap_ENUM(pc + 0),
-                       (const GLshort *) bswap_16_array((uint16_t *) (pc + 4),
-                                                        1));
+    glMultiTexCoord1svARB((GLenum) bswap_ENUM(pc + 0),
+                          (const GLshort *) bswap_16_array((uint16_t *) (pc + 4),
+                                                           1));
 }
 
 void
@@ -3873,9 +3873,9 @@ __glXDispSwap_MultiTexCoord2dv(GLbyte * pc)
     }
 #endif
 
-    glMultiTexCoord2dv((GLenum) bswap_ENUM(pc + 16),
-                       (const GLdouble *) bswap_64_array((uint64_t *) (pc + 0),
-                                                         2));
+    glMultiTexCoord2dvARB((GLenum) bswap_ENUM(pc + 16),
+                          (const GLdouble *) bswap_64_array((uint64_t *) (pc + 0),
+                                                            2));
 }
 
 void
@@ -3889,17 +3889,17 @@ __glXDispSwap_MultiTexCoord2fvARB(GLbyte * pc)
 void
 __glXDispSwap_MultiTexCoord2iv(GLbyte * pc)
 {
-    glMultiTexCoord2iv((GLenum) bswap_ENUM(pc + 0),
-                       (const GLint *) bswap_32_array((uint32_t *) (pc + 4),
-                                                      2));
+    glMultiTexCoord2ivARB((GLenum) bswap_ENUM(pc + 0),
+                          (const GLint *) bswap_32_array((uint32_t *) (pc + 4),
+                                                         2));
 }
 
 void
 __glXDispSwap_MultiTexCoord2sv(GLbyte * pc)
 {
-    glMultiTexCoord2sv((GLenum) bswap_ENUM(pc + 0),
-                       (const GLshort *) bswap_16_array((uint16_t *) (pc + 4),
-                                                        2));
+    glMultiTexCoord2svARB((GLenum) bswap_ENUM(pc + 0),
+                          (const GLshort *) bswap_16_array((uint16_t *) (pc + 4),
+                                                           2));
 }
 
 void
@@ -3912,9 +3912,9 @@ __glXDispSwap_MultiTexCoord3dv(GLbyte * pc)
     }
 #endif
 
-    glMultiTexCoord3dv((GLenum) bswap_ENUM(pc + 24),
-                       (const GLdouble *) bswap_64_array((uint64_t *) (pc + 0),
-                                                         3));
+    glMultiTexCoord3dvARB((GLenum) bswap_ENUM(pc + 24),
+                          (const GLdouble *) bswap_64_array((uint64_t *) (pc + 0),
+                                                            3));
 }
 
 void
@@ -3928,17 +3928,17 @@ __glXDispSwap_MultiTexCoord3fvARB(GLbyte * pc)
 void
 __glXDispSwap_MultiTexCoord3iv(GLbyte * pc)
 {
-    glMultiTexCoord3iv((GLenum) bswap_ENUM(pc + 0),
-                       (const GLint *) bswap_32_array((uint32_t *) (pc + 4),
-                                                      3));
+    glMultiTexCoord3ivARB((GLenum) bswap_ENUM(pc + 0),
+                          (const GLint *) bswap_32_array((uint32_t *) (pc + 4),
+                                                         3));
 }
 
 void
 __glXDispSwap_MultiTexCoord3sv(GLbyte * pc)
 {
-    glMultiTexCoord3sv((GLenum) bswap_ENUM(pc + 0),
-                       (const GLshort *) bswap_16_array((uint16_t *) (pc + 4),
-                                                        3));
+    glMultiTexCoord3svARB((GLenum) bswap_ENUM(pc + 0),
+                          (const GLshort *) bswap_16_array((uint16_t *) (pc + 4),
+                                                           3));
 }
 
 void
@@ -3951,9 +3951,9 @@ __glXDispSwap_MultiTexCoord4dv(GLbyte * pc)
     }
 #endif
 
-    glMultiTexCoord4dv((GLenum) bswap_ENUM(pc + 32),
-                       (const GLdouble *) bswap_64_array((uint64_t *) (pc + 0),
-                                                         4));
+    glMultiTexCoord4dvARB((GLenum) bswap_ENUM(pc + 32),
+                          (const GLdouble *) bswap_64_array((uint64_t *) (pc + 0),
+                                                            4));
 }
 
 void
@@ -3967,17 +3967,17 @@ __glXDispSwap_MultiTexCoord4fvARB(GLbyte * pc)
 void
 __glXDispSwap_MultiTexCoord4iv(GLbyte * pc)
 {
-    glMultiTexCoord4iv((GLenum) bswap_ENUM(pc + 0),
-                       (const GLint *) bswap_32_array((uint32_t *) (pc + 4),
-                                                      4));
+    glMultiTexCoord4ivARB((GLenum) bswap_ENUM(pc + 0),
+                          (const GLint *) bswap_32_array((uint32_t *) (pc + 4),
+                                                         4));
 }
 
 void
 __glXDispSwap_MultiTexCoord4sv(GLbyte * pc)
 {
-    glMultiTexCoord4sv((GLenum) bswap_ENUM(pc + 0),
-                       (const GLshort *) bswap_16_array((uint16_t *) (pc + 4),
-                                                        4));
+    glMultiTexCoord4svARB((GLenum) bswap_ENUM(pc + 0),
+                          (const GLshort *) bswap_16_array((uint16_t *) (pc + 4),
+                                                           4));
 }
 
 void
commit 1a021f57a1e75ab63e8f87704f0394162402c4d4
Author: Jon TURNEY <jon.turney at dronecode.org.uk>
Date:   Sun Dec 1 22:25:46 2013 +0000

    ephyr: Fix compilation when ./configure'd with --enable-debug
    
    /jhbuild/checkout/xorg/xserver/hw/kdrive/ephyr/ephyr.c: In function ‘ephyrProcessMouseMotion’:
    /jhbuild/checkout/xorg/xserver/hw/kdrive/ephyr/ephyr.c:946:188: error: ‘ephyrCurScreen’ undeclared (first use in this function)
    /jhbuild/checkout/xorg/xserver/hw/kdrive/ephyr/ephyr.c: In function ‘ephyrProcessButtonPress’:
    /jhbuild/checkout/xorg/xserver/hw/kdrive/ephyr/ephyr.c:980:186: error: ‘ephyrCurScreen’ undeclared (first use in this function)
    /jhbuild/checkout/xorg/xserver/hw/kdrive/ephyr/ephyr.c: In function ‘ephyrProcessButtonRelease’:
    /jhbuild/checkout/xorg/xserver/hw/kdrive/ephyr/ephyr.c:1007:186: error: ‘ephyrCurScreen’ undeclared (first use in this function)
    
    Fix ephyr compilation when ./configure'd with --enable-debug after commit
    46cf6bf5692ef751ec9d17ae2292565d4b13f14b, some instances of ephyrCurScreen were
    not converted to screen->pScreen->myNum.
    
    v2: Don't use a trivial local variable which will be unused when ./configure'd
    with --disable-debug
    
    Signed-off-by: Jon TURNEY <jon.turney at dronecode.org.uk>
    Reviewed-by: Adam Jackson <ajax at redhat.com>

diff --git a/hw/kdrive/ephyr/ephyr.c b/hw/kdrive/ephyr/ephyr.c
index ef4b321..b2a7985 100644
--- a/hw/kdrive/ephyr/ephyr.c
+++ b/hw/kdrive/ephyr/ephyr.c
@@ -943,7 +943,7 @@ ephyrProcessMouseMotion(xcb_generic_event_t *xev)
 #ifdef XF86DRI
         EphyrWindowPair *pair = NULL;
 #endif
-        EPHYR_LOG("enqueuing mouse motion:%d\n", ephyrCurScreen);
+        EPHYR_LOG("enqueuing mouse motion:%d\n", screen->pScreen->myNum);
         x = motion->event_x;
         y = motion->event_y;
         EPHYR_LOG("initial (x,y):(%d,%d)\n", x, y);
@@ -977,7 +977,7 @@ ephyrProcessButtonPress(xcb_generic_event_t *xev)
 
     if (!ephyrMouse ||
         !((EphyrPointerPrivate *) ephyrMouse->driverPrivate)->enabled) {
-        EPHYR_LOG("skipping mouse press:%d\n", ephyrCurScreen);
+        EPHYR_LOG("skipping mouse press:%d\n", screen_from_window(button->event)->pScreen->myNum);
         return;
     }
 
@@ -987,7 +987,7 @@ ephyrProcessButtonPress(xcb_generic_event_t *xev)
      */
     mouseState |= 1 << (button->detail - 1);
 
-    EPHYR_LOG("enqueuing mouse press:%d\n", ephyrCurScreen);
+    EPHYR_LOG("enqueuing mouse press:%d\n", screen_from_window(button->event)->pScreen->myNum);
     KdEnqueuePointerEvent(ephyrMouse, mouseState | KD_MOUSE_DELTA, 0, 0, 0);
 }
 
@@ -1004,7 +1004,7 @@ ephyrProcessButtonRelease(xcb_generic_event_t *xev)
     ephyrUpdateModifierState(button->state);
     mouseState &= ~(1 << (button->detail - 1));
 
-    EPHYR_LOG("enqueuing mouse release:%d\n", ephyrCurScreen);
+    EPHYR_LOG("enqueuing mouse release:%d\n", screen_from_window(button->event)->pScreen->myNum);
     KdEnqueuePointerEvent(ephyrMouse, mouseState | KD_MOUSE_DELTA, 0, 0, 0);
 }
 
commit 875dbcef5bfcb6a94ef8456be6151e133408793f
Author: Jon TURNEY <jon.turney at dronecode.org.uk>
Date:   Fri Nov 29 14:29:20 2013 +0000

    configure.ac: Link XWin with present extension if we are building with it enabled
    
    Signed-off-by: Jon TURNEY <jon.turney at dronecode.org.uk>
    Reviewed-by: Adam Jackson <ajax at redhat.com>

diff --git a/configure.ac b/configure.ac
index a093c19..3855d72 100644
--- a/configure.ac
+++ b/configure.ac
@@ -2108,7 +2108,7 @@ if test "x$XWIN" = xyes; then
 			;;
 	esac
 
-	XWIN_LIBS="$FB_LIB $MI_LIB $FIXES_LIB $XEXT_LIB $RANDR_LIB $RENDER_LIB $DBE_LIB $RECORD_LIB $GLX_LIBS $XKB_LIB $XKB_STUB_LIB $COMPOSITE_LIB $DAMAGE_LIB $MIEXT_SYNC_LIB $MIEXT_DAMAGE_LIB $MIEXT_SHADOW_LIB $XI_LIB $OS_LIB"
+	XWIN_LIBS="$FB_LIB $MI_LIB $FIXES_LIB $XEXT_LIB $RANDR_LIB $RENDER_LIB $DBE_LIB $RECORD_LIB $GLX_LIBS $XKB_LIB $XKB_STUB_LIB $COMPOSITE_LIB $DAMAGE_LIB $PRESENT_LIB $MIEXT_SYNC_LIB $MIEXT_DAMAGE_LIB $MIEXT_SHADOW_LIB $XI_LIB $OS_LIB"
 	XWIN_SYS_LIBS="$XWIN_SYS_LIBS $XWINMODULES_LIBS $GLX_SYS_LIBS"
 	AC_SUBST(XWIN_LIBS)
 	AC_SUBST(XWIN_SERVER_NAME)
commit e61e19959d9138d5b81b1f25b7aa3e257918170d
Author: Adam Jackson <ajax at redhat.com>
Date:   Tue Dec 3 13:45:43 2013 -0500

    xquartz/glx: Convert to non-glapi dispatch
    
    CGL doesn't have anything like glXGetProcAddress, and the old code just
    called down to dlsym in any case.  It's a little mind-warping since
    dlopening a framework actually loads multiple dylibs, but that's just
    how OSX rolls.
    
    Signed-off-by: Adam Jackson <ajax at redhat.com>
    Reviewed-by: Jeremy Huddleston Sequoia <jeremyhu at apple.com>

diff --git a/hw/xquartz/GL/indirect.c b/hw/xquartz/GL/indirect.c
index c4999b5..8dabda1 100644
--- a/hw/xquartz/GL/indirect.c
+++ b/hw/xquartz/GL/indirect.c
@@ -48,8 +48,6 @@
 #include <glxserver.h>
 #include <glxutil.h>
 
-#include <glapi.h>
-
 #include "x-hash.h"
 
 #include "visualConfigs.h"
@@ -643,15 +641,20 @@ __glFloorLog2(GLuint val)
     "/System/Library/Frameworks/OpenGL.framework/OpenGL"
 #endif
 
+static void *opengl_framework_handle;
+
+static glx_gpa_proc
+get_proc_address(const char *sym)
+{
+    return (glx_gpa_proc) dlsym(opengl_framework_handle, sym);
+}
+
 static void
 setup_dispatch_table(void)
 {
-    static struct _glapi_table *disp = NULL;
-    static void *handle;
     const char *opengl_framework_path;
 
-    if (disp) {
-        _glapi_set_dispatch(disp);
+    if (opengl_framework_handle) {
         return;
     }
 
@@ -661,16 +664,13 @@ setup_dispatch_table(void)
     }
 
     (void)dlerror();             /*drain dlerror */
-    handle = dlopen(opengl_framework_path, RTLD_LOCAL);
+    opengl_framework_handle = dlopen(opengl_framework_path, RTLD_LOCAL);
 
-    if (!handle) {
+    if (!opengl_framework_handle) {
         ErrorF("unable to dlopen %s : %s, using RTLD_DEFAULT\n",
                opengl_framework_path, dlerror());
-        handle = RTLD_DEFAULT;
+        opengl_framework_handle = RTLD_DEFAULT;
     }
 
-    disp = _glapi_create_table_from_handle(handle, "gl");
-    assert(disp);
-
-    _glapi_set_dispatch(disp);
+    __glXsetGetProcAddress(get_proc_address);
 }
commit a668aa0e41bc33ff2db7f9c53b6dc321a96926a9
Author: Adam Jackson <ajax at redhat.com>
Date:   Tue Dec 3 15:03:13 2013 -0500

    drisw: Wire up GetProcAddress
    
    Signed-off-by: Adam Jackson <ajax at redhat.com>
    Reviewed-by: Keith Packard <keithp at keithp.com>

diff --git a/glx/glxdriswrast.c b/glx/glxdriswrast.c
index 2d5efa0..cbc109a 100644
--- a/glx/glxdriswrast.c
+++ b/glx/glxdriswrast.c
@@ -425,6 +425,9 @@ initializeExtensions(__GLXDRIscreen * screen)
     }
 }
 
+/* white lie */
+extern glx_func_ptr glXGetProcAddressARB(const char *);
+
 static __GLXscreen *
 __glXDRIscreenProbe(ScreenPtr pScreen)
 {
@@ -472,6 +475,8 @@ __glXDRIscreenProbe(ScreenPtr pScreen)
     screen->base.GLXmajor = 1;
     screen->base.GLXminor = 4;
 
+    __glXsetGetProcAddress(glXGetProcAddressARB);
+
     LogMessage(X_INFO, "AIGLX: Loaded and initialized %s\n", driverName);
 
     return &screen->base;
commit 4fcdfeb7bc55d00d50d7f89788d9b929946ae3d9
Author: Adam Jackson <ajax at redhat.com>
Date:   Tue Dec 3 15:02:57 2013 -0500

    dri2: wire up GetProcAddress
    
    Signed-off-by: Adam Jackson <ajax at redhat.com>
    Reviewed-by: Keith Packard <keithp at keithp.com>

diff --git a/glx/glxdri2.c b/glx/glxdri2.c
index a7ee4a3..b2f3d6e 100644
--- a/glx/glxdri2.c
+++ b/glx/glxdri2.c
@@ -55,7 +55,6 @@ typedef struct __GLXDRIscreen __GLXDRIscreen;
 typedef struct __GLXDRIcontext __GLXDRIcontext;
 typedef struct __GLXDRIdrawable __GLXDRIdrawable;
 
-
 #ifdef __DRI2_ROBUSTNESS
 #define ALL_DRI_CTX_FLAGS (__DRI_CTX_FLAG_DEBUG                         \
                            | __DRI_CTX_FLAG_FORWARD_COMPATIBLE          \
@@ -929,6 +928,9 @@ initializeExtensions(__GLXDRIscreen * screen)
     }
 }
 
+/* white lie */
+extern glx_func_ptr glXGetProcAddressARB(const char *);
+
 static __GLXscreen *
 __glXDRIscreenProbe(ScreenPtr pScreen)
 {
@@ -1013,6 +1015,8 @@ __glXDRIscreenProbe(ScreenPtr pScreen)
     screen->leaveVT = pScrn->LeaveVT;
     pScrn->LeaveVT = glxDRILeaveVT;
 
+    __glXsetGetProcAddress(glXGetProcAddressARB);
+
     LogMessage(X_INFO, "AIGLX: Loaded and initialized %s\n", driverName);
 
     return &screen->base;
commit 47f00b3920be9d8df8b148263d744934f3a02cd4
Author: Adam Jackson <ajax at redhat.com>
Date:   Tue Dec 3 15:01:44 2013 -0500

    glx: Untangle the prototypes around the GetProcAddress thunk
    
    Signed-off-by: Adam Jackson <ajax at redhat.com>
    Reviewed-by: Jeremy Huddleston Sequoia <jeremyhu at apple.com>
    Reviewed-by: Jon TURNEY <jon.turney at dronecode.org.uk>

diff --git a/glx/glxext.c b/glx/glxext.c
index 601d08a..84ac43d 100644
--- a/glx/glxext.c
+++ b/glx/glxext.c
@@ -544,10 +544,10 @@ __glXleaveServer(GLboolean rendering)
     glxServerLeaveCount++;
 }
 
-static void (*(*_get_proc_address)(const char *))(void);
+static glx_gpa_proc _get_proc_address;
 
 void
-__glXsetGetProcAddress(void (*(*get_proc_address) (const char *))(void))
+__glXsetGetProcAddress(glx_gpa_proc get_proc_address)
 {
     _get_proc_address = get_proc_address;
 }
diff --git a/glx/glxserver.h b/glx/glxserver.h
index f862b63..7f36e5f 100644
--- a/glx/glxserver.h
+++ b/glx/glxserver.h
@@ -117,7 +117,9 @@ void __glXleaveServer(GLboolean rendering);
 void glxSuspendClients(void);
 void glxResumeClients(void);
 
-void __glXsetGetProcAddress(void (*(*get_proc_address) (const char *)) (void));
+typedef void (*glx_func_ptr)(void);
+typedef glx_func_ptr (*glx_gpa_proc)(const char *);
+void __glXsetGetProcAddress(glx_gpa_proc get_proc_address);
 void *__glGetProcAddress(const char *);
 
 void
commit c1fd143f2847ef425ec9891d9e1cba44a1bb007d
Author: Adam Jackson <ajax at redhat.com>
Date:   Tue Dec 3 13:11:52 2013 -0500

    glx: Remove function stubs
    
    Now that we're calling non-1.2 ABI things by function pointer this is no
    longer needed.
    
    Signed-off-by: Adam Jackson <ajax at redhat.com>
    Reviewed-by: Jeremy Huddleston Sequoia <jeremyhu at apple.com>
    Reviewed-by: Jon TURNEY <jon.turney at dronecode.org.uk>

diff --git a/glx/Makefile.am b/glx/Makefile.am
index 44d3a7d..54e8140 100644
--- a/glx/Makefile.am
+++ b/glx/Makefile.am
@@ -70,7 +70,6 @@ libglx_la_SOURCES = \
         glxscreens.c \
         glxscreens.h \
         glxserver.h \
-        glxstubs.c \
         glxutil.h \
         render2.c \
         render2swap.c \
diff --git a/glx/glxstubs.c b/glx/glxstubs.c
deleted file mode 100644
index 69bc004..0000000
--- a/glx/glxstubs.c
+++ /dev/null
@@ -1,50 +0,0 @@
-/*
- * Copyright © 2013 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:
- *	Adam Jackson <ajax at redhat.com>
- */
-
-/*
- * Redirection stubs for things that we call by name but that aren't exported
- * from libGL by name.  Strictly speaking this list should be a lot longer,
- * but this is enough to get us linking against contemporary Mesa.
- */
-
-#include <inttypes.h>
-#include "glxserver.h"
-
-#define thunk(name, type, call_args, ...) \
-    _X_HIDDEN void name(__VA_ARGS__) { \
-	static type proc; \
-	if (!proc) proc = __glGetProcAddress(#name); \
-	proc call_args; \
-    }
-
-thunk(glSampleMaskSGIS, PFNGLSAMPLEMASKSGISPROC,
-      (value, invert), GLclampf value, GLboolean invert)
-
-thunk(glSamplePatternSGIS, PFNGLSAMPLEPATTERNSGISPROC,
-      (pattern), GLenum pattern)
-
-thunk(glActiveStencilFaceEXT, PFNGLACTIVESTENCILFACEEXTPROC,
-      (face), GLenum face)
commit 6b93e1f5ff39c6ac5b0d97d4245aeac9113eed8b
Author: Adam Jackson <ajax at redhat.com>
Date:   Tue Dec 3 13:11:09 2013 -0500

    glx: Convert non-generated function pointer thunking
    
    Same concept as the generated code conversion.
    
    Signed-off-by: Adam Jackson <ajax at redhat.com>
    Reviewed-by: Jon TURNEY <jon.turney at dronecode.org.uk>

diff --git a/glx/indirect_program.c b/glx/indirect_program.c
index db22d84..fa4a240 100644
--- a/glx/indirect_program.c
+++ b/glx/indirect_program.c
@@ -104,29 +104,43 @@ DoGetProgramString(struct __GLXclientStateRec *cl, GLbyte * pc,
 int
 __glXDisp_GetProgramStringARB(struct __GLXclientStateRec *cl, GLbyte * pc)
 {
-    return DoGetProgramString(cl, pc, glGetProgramivARB,
-                              glGetProgramStringARB, False);
+    PFNGLGETPROGRAMIVARBPROC get_program =
+        __glGetProcAddress("glGetProgramivARB");
+    PFNGLGETPROGRAMSTRINGARBPROC get_program_string =
+        __glGetProcAddress("glGetProgramStringARB");
+
+    return DoGetProgramString(cl, pc, get_program, get_program_string, False);
 }
 
 int
 __glXDispSwap_GetProgramStringARB(struct __GLXclientStateRec *cl, GLbyte * pc)
 {
-    return DoGetProgramString(cl, pc, glGetProgramivARB,
-                              glGetProgramStringARB, True);
+    PFNGLGETPROGRAMIVARBPROC get_program =
+        __glGetProcAddress("glGetProgramivARB");
+    PFNGLGETPROGRAMSTRINGARBPROC get_program_string =
+        __glGetProcAddress("glGetProgramStringARB");
+
+    return DoGetProgramString(cl, pc, get_program, get_program_string, True);
 }
 
 int
 __glXDisp_GetProgramStringNV(struct __GLXclientStateRec *cl, GLbyte * pc)
 {
-    return DoGetProgramString(cl, pc, (PFNGLGETPROGRAMIVARBPROC)glGetProgramivNV,
-                              (PFNGLGETPROGRAMSTRINGARBPROC)glGetProgramStringNV,
-                              False);
+    PFNGLGETPROGRAMIVARBPROC get_program =
+        __glGetProcAddress("glGetProgramivARB");
+    PFNGLGETPROGRAMSTRINGARBPROC get_program_string =
+        __glGetProcAddress("glGetProgramStringARB");
+
+    return DoGetProgramString(cl, pc, get_program, get_program_string, False);
 }
 
 int
 __glXDispSwap_GetProgramStringNV(struct __GLXclientStateRec *cl, GLbyte * pc)
 {
-    return DoGetProgramString(cl, pc, (PFNGLGETPROGRAMIVARBPROC)glGetProgramivNV,
-                              (PFNGLGETPROGRAMSTRINGARBPROC)glGetProgramStringNV,
-                              True);
+    PFNGLGETPROGRAMIVARBPROC get_program =
+        __glGetProcAddress("glGetProgramivARB");
+    PFNGLGETPROGRAMSTRINGARBPROC get_program_string =
+        __glGetProcAddress("glGetProgramStringARB");
+
+    return DoGetProgramString(cl, pc, get_program, get_program_string, True);
 }
diff --git a/glx/render2.c b/glx/render2.c
index 5a2f482..8d9b5f4 100644
--- a/glx/render2.c
+++ b/glx/render2.c
@@ -231,13 +231,21 @@ __glXDisp_DrawArrays(GLbyte * pc)
             glEdgeFlagPointer(stride, (const GLboolean *) pc);
             break;
         case GL_SECONDARY_COLOR_ARRAY:
+        {
+            PFNGLSECONDARYCOLORPOINTERPROC SecondaryColorPointerEXT =
+                __glGetProcAddress("glSecondaryColorPointerEXT");
             glEnableClientState(GL_SECONDARY_COLOR_ARRAY);
-            glSecondaryColorPointerEXT(numVals, datatype, stride, pc);
+            SecondaryColorPointerEXT(numVals, datatype, stride, pc);
             break;
+        }
         case GL_FOG_COORD_ARRAY:
+        {
+            PFNGLFOGCOORDPOINTERPROC FogCoordPointerEXT =
+                __glGetProcAddress("glFogCoordPointerEXT");
             glEnableClientState(GL_FOG_COORD_ARRAY);
-            glFogCoordPointerEXT(datatype, stride, pc);
+            FogCoordPointerEXT(datatype, stride, pc);
             break;
+        }
         default:
             break;
         }
diff --git a/glx/render2swap.c b/glx/render2swap.c
index e6f73b8..6ed364f 100644
--- a/glx/render2swap.c
+++ b/glx/render2swap.c
@@ -353,13 +353,21 @@ __glXDispSwap_DrawArrays(GLbyte * pc)
             glEdgeFlagPointer(stride, (const GLboolean *) pc);
             break;
         case GL_SECONDARY_COLOR_ARRAY:
+        {
+            PFNGLSECONDARYCOLORPOINTERPROC SecondaryColorPointerEXT =
+                __glGetProcAddress("glSecondaryColorPointerEXT");
             glEnableClientState(GL_SECONDARY_COLOR_ARRAY);
-            glSecondaryColorPointerEXT(numVals, datatype, stride, pc);
+            SecondaryColorPointerEXT(numVals, datatype, stride, pc);
             break;
+        }
         case GL_FOG_COORD_ARRAY:
+        {
+            PFNGLFOGCOORDPOINTERPROC FogCoordPointerEXT =
+                __glGetProcAddress("glFogCoordPointerEXT");
             glEnableClientState(GL_FOG_COORD_ARRAY);
-            glFogCoordPointerEXT(datatype, stride, pc);
+            FogCoordPointerEXT(datatype, stride, pc);
             break;
+        }
         default:
             break;
         }
commit c4567a376083eb7b142a7f003ddf8372d376ea86
Author: Adam Jackson <ajax at redhat.com>
Date:   Tue Dec 3 12:40:24 2013 -0500

    glx: Convert generated code function pointer thunking
    
    We're meant not to call these by name due to ABI.  Rather than try to
    generate a bunch of little stub functions that do the lookup, just
    inline it all directly into the calling function.
    
    This does not cache results.  That's fine, this is not a performance
    path, and if we're atop WGL then we effectively have to do this every
    time anyway because wglGetProcAddress results are context-dependent.
    
    Signed-off-by: Adam Jackson <ajax at redhat.com>
    Jon TURNEY <jon.turney at dronecode.org.uk>

diff --git a/glx/indirect_dispatch.c b/glx/indirect_dispatch.c
index 1eee79a..c7a95a4 100644
--- a/glx/indirect_dispatch.c
+++ b/glx/indirect_dispatch.c
@@ -3590,107 +3590,124 @@ __glXDisp_MultiTexCoord4sv(GLbyte * pc)
 void
 __glXDisp_CompressedTexImage1D(GLbyte * pc)
 {
+    PFNGLCOMPRESSEDTEXIMAGE1DPROC CompressedTexImage1D =
+        __glGetProcAddress("glCompressedTexImage1D");
     const GLsizei imageSize = *(GLsizei *) (pc + 20);
 
-    glCompressedTexImage1D(*(GLenum *) (pc + 0),
-                           *(GLint *) (pc + 4),
-                           *(GLenum *) (pc + 8),
-                           *(GLsizei *) (pc + 12),
-                           *(GLint *) (pc + 16),
-                           imageSize, (const GLvoid *) (pc + 24));
+    CompressedTexImage1D(*(GLenum *) (pc + 0),
+                         *(GLint *) (pc + 4),
+                         *(GLenum *) (pc + 8),
+                         *(GLsizei *) (pc + 12),
+                         *(GLint *) (pc + 16),
+                         imageSize, (const GLvoid *) (pc + 24));
 }
 
 void
 __glXDisp_CompressedTexImage2D(GLbyte * pc)
 {
+    PFNGLCOMPRESSEDTEXIMAGE2DPROC CompressedTexImage2D =
+        __glGetProcAddress("glCompressedTexImage2D");
     const GLsizei imageSize = *(GLsizei *) (pc + 24);
 
-    glCompressedTexImage2D(*(GLenum *) (pc + 0),
-                           *(GLint *) (pc + 4),
-                           *(GLenum *) (pc + 8),
-                           *(GLsizei *) (pc + 12),
-                           *(GLsizei *) (pc + 16),
-                           *(GLint *) (pc + 20),
-                           imageSize, (const GLvoid *) (pc + 28));
+    CompressedTexImage2D(*(GLenum *) (pc + 0),
+                         *(GLint *) (pc + 4),
+                         *(GLenum *) (pc + 8),
+                         *(GLsizei *) (pc + 12),
+                         *(GLsizei *) (pc + 16),
+                         *(GLint *) (pc + 20),
+                         imageSize, (const GLvoid *) (pc + 28));
 }
 
 void
 __glXDisp_CompressedTexImage3D(GLbyte * pc)
 {
+    PFNGLCOMPRESSEDTEXIMAGE3DPROC CompressedTexImage3D =
+        __glGetProcAddress("glCompressedTexImage3D");
     const GLsizei imageSize = *(GLsizei *) (pc + 28);
 
-    glCompressedTexImage3D(*(GLenum *) (pc + 0),
-                           *(GLint *) (pc + 4),
-                           *(GLenum *) (pc + 8),
-                           *(GLsizei *) (pc + 12),
-                           *(GLsizei *) (pc + 16),
-                           *(GLsizei *) (pc + 20),
-                           *(GLint *) (pc + 24),
-                           imageSize, (const GLvoid *) (pc + 32));
+    CompressedTexImage3D(*(GLenum *) (pc + 0),
+                         *(GLint *) (pc + 4),
+                         *(GLenum *) (pc + 8),
+                         *(GLsizei *) (pc + 12),
+                         *(GLsizei *) (pc + 16),
+                         *(GLsizei *) (pc + 20),
+                         *(GLint *) (pc + 24),
+                         imageSize, (const GLvoid *) (pc + 32));
 }
 
 void
 __glXDisp_CompressedTexSubImage1D(GLbyte * pc)
 {
+    PFNGLCOMPRESSEDTEXSUBIMAGE1DPROC CompressedTexSubImage1D =
+        __glGetProcAddress("glCompressedTexSubImage1D");
     const GLsizei imageSize = *(GLsizei *) (pc + 20);
 
-    glCompressedTexSubImage1D(*(GLenum *) (pc + 0),
-                              *(GLint *) (pc + 4),
-                              *(GLint *) (pc + 8),
-                              *(GLsizei *) (pc + 12),
-                              *(GLenum *) (pc + 16),
-                              imageSize, (const GLvoid *) (pc + 24));
+    CompressedTexSubImage1D(*(GLenum *) (pc + 0),
+                            *(GLint *) (pc + 4),
+                            *(GLint *) (pc + 8),
+                            *(GLsizei *) (pc + 12),
+                            *(GLenum *) (pc + 16),
+                            imageSize, (const GLvoid *) (pc + 24));
 }
 
 void
 __glXDisp_CompressedTexSubImage2D(GLbyte * pc)
 {
+    PFNGLCOMPRESSEDTEXSUBIMAGE2DPROC CompressedTexSubImage2D =
+        __glGetProcAddress("glCompressedTexSubImage2D");
     const GLsizei imageSize = *(GLsizei *) (pc + 28);
 
-    glCompressedTexSubImage2D(*(GLenum *) (pc + 0),
-                              *(GLint *) (pc + 4),
-                              *(GLint *) (pc + 8),
-                              *(GLint *) (pc + 12),
-                              *(GLsizei *) (pc + 16),
-                              *(GLsizei *) (pc + 20),
-                              *(GLenum *) (pc + 24),
-                              imageSize, (const GLvoid *) (pc + 32));
+    CompressedTexSubImage2D(*(GLenum *) (pc + 0),
+                            *(GLint *) (pc + 4),
+                            *(GLint *) (pc + 8),
+                            *(GLint *) (pc + 12),
+                            *(GLsizei *) (pc + 16),
+                            *(GLsizei *) (pc + 20),
+                            *(GLenum *) (pc + 24),
+                            imageSize, (const GLvoid *) (pc + 32));
 }
 
 void
 __glXDisp_CompressedTexSubImage3D(GLbyte * pc)
 {
+    PFNGLCOMPRESSEDTEXSUBIMAGE3DPROC CompressedTexSubImage3D =
+        __glGetProcAddress("glCompressedTexSubImage3D");
     const GLsizei imageSize = *(GLsizei *) (pc + 36);
 
-    glCompressedTexSubImage3D(*(GLenum *) (pc + 0),
-                              *(GLint *) (pc + 4),
-                              *(GLint *) (pc + 8),
-                              *(GLint *) (pc + 12),
-                              *(GLint *) (pc + 16),
-                              *(GLsizei *) (pc + 20),
-                              *(GLsizei *) (pc + 24),
-                              *(GLsizei *) (pc + 28),
-                              *(GLenum *) (pc + 32),
-                              imageSize, (const GLvoid *) (pc + 40));
+    CompressedTexSubImage3D(*(GLenum *) (pc + 0),
+                            *(GLint *) (pc + 4),
+                            *(GLint *) (pc + 8),
+                            *(GLint *) (pc + 12),
+                            *(GLint *) (pc + 16),
+                            *(GLsizei *) (pc + 20),
+                            *(GLsizei *) (pc + 24),
+                            *(GLsizei *) (pc + 28),
+                            *(GLenum *) (pc + 32),
+                            imageSize, (const GLvoid *) (pc + 40));
 }
 
 void
 __glXDisp_SampleCoverage(GLbyte * pc)
 {
-    glSampleCoverage(*(GLclampf *) (pc + 0), *(GLboolean *) (pc + 4));
+    PFNGLSAMPLECOVERAGEPROC SampleCoverage =
+        __glGetProcAddress("glSampleCoverage");
+    SampleCoverage(*(GLclampf *) (pc + 0), *(GLboolean *) (pc + 4));
 }
 
 void
 __glXDisp_BlendFuncSeparate(GLbyte * pc)
 {
-    glBlendFuncSeparate(*(GLenum *) (pc + 0),
-                        *(GLenum *) (pc + 4),
-                        *(GLenum *) (pc + 8), *(GLenum *) (pc + 12));
+    PFNGLBLENDFUNCSEPARATEPROC BlendFuncSeparate =
+        __glGetProcAddress("glBlendFuncSeparate");
+    BlendFuncSeparate(*(GLenum *) (pc + 0), *(GLenum *) (pc + 4),
+                      *(GLenum *) (pc + 8), *(GLenum *) (pc + 12));
 }
 
 void
 __glXDisp_FogCoorddv(GLbyte * pc)
 {
+    PFNGLFOGCOORDDVPROC FogCoorddv = __glGetProcAddress("glFogCoorddv");
+
 #ifdef __GLX_ALIGN64
     if ((unsigned long) (pc) & 7) {
         (void) memmove(pc - 4, pc, 8);
@@ -3698,52 +3715,64 @@ __glXDisp_FogCoorddv(GLbyte * pc)
     }
 #endif
 
-    glFogCoorddv((const GLdouble *) (pc + 0));
+    FogCoorddv((const GLdouble *) (pc + 0));
 }
 
 void
 __glXDisp_PointParameterf(GLbyte * pc)
 {
-    glPointParameterf(*(GLenum *) (pc + 0), *(GLfloat *) (pc + 4));
+    PFNGLPOINTPARAMETERFPROC PointParameterf =
+        __glGetProcAddress("glPointParameterf");
+    PointParameterf(*(GLenum *) (pc + 0), *(GLfloat *) (pc + 4));
 }
 
 void
 __glXDisp_PointParameterfv(GLbyte * pc)
 {
+    PFNGLPOINTPARAMETERFVPROC PointParameterfv =
+        __glGetProcAddress("glPointParameterfv");
     const GLenum pname = *(GLenum *) (pc + 0);
     const GLfloat *params;
 
     params = (const GLfloat *) (pc + 4);
 
-    glPointParameterfv(pname, params);
+    PointParameterfv(pname, params);
 }
 
 void
 __glXDisp_PointParameteri(GLbyte * pc)
 {
-    glPointParameteri(*(GLenum *) (pc + 0), *(GLint *) (pc + 4));
+    PFNGLPOINTPARAMETERIPROC PointParameteri =
+        __glGetProcAddress("glPointParameteri");
+    PointParameteri(*(GLenum *) (pc + 0), *(GLint *) (pc + 4));
 }
 
 void
 __glXDisp_PointParameteriv(GLbyte * pc)
 {
+    PFNGLPOINTPARAMETERIVPROC PointParameteriv =
+        __glGetProcAddress("glPointParameteriv");
     const GLenum pname = *(GLenum *) (pc + 0);
     const GLint *params;
 
     params = (const GLint *) (pc + 4);
 
-    glPointParameteriv(pname, params);
+    PointParameteriv(pname, params);
 }
 
 void
 __glXDisp_SecondaryColor3bv(GLbyte * pc)
 {
-    glSecondaryColor3bv((const GLbyte *) (pc + 0));
+    PFNGLSECONDARYCOLOR3BVPROC SecondaryColor3bv =
+        __glGetProcAddress("glSecondaryColor3bv");
+    SecondaryColor3bv((const GLbyte *) (pc + 0));
 }
 
 void
 __glXDisp_SecondaryColor3dv(GLbyte * pc)
 {
+    PFNGLSECONDARYCOLOR3DVPROC SecondaryColor3dv =
+        __glGetProcAddress("glSecondaryColor3dv");
 #ifdef __GLX_ALIGN64
     if ((unsigned long) (pc) & 7) {
         (void) memmove(pc - 4, pc, 24);
@@ -3751,54 +3780,70 @@ __glXDisp_SecondaryColor3dv(GLbyte * pc)
     }
 #endif
 
-    glSecondaryColor3dv((const GLdouble *) (pc + 0));
+    SecondaryColor3dv((const GLdouble *) (pc + 0));
 }
 
 void
 __glXDisp_SecondaryColor3iv(GLbyte * pc)
 {
-    glSecondaryColor3iv((const GLint *) (pc + 0));
+    PFNGLSECONDARYCOLOR3IVPROC SecondaryColor3iv =
+        __glGetProcAddress("glSecondaryColor3iv");
+    SecondaryColor3iv((const GLint *) (pc + 0));
 }
 
 void
 __glXDisp_SecondaryColor3sv(GLbyte * pc)
 {
-    glSecondaryColor3sv((const GLshort *) (pc + 0));
+    PFNGLSECONDARYCOLOR3SVPROC SecondaryColor3sv =
+        __glGetProcAddress("glSecondaryColor3sv");
+    SecondaryColor3sv((const GLshort *) (pc + 0));
 }
 
 void
 __glXDisp_SecondaryColor3ubv(GLbyte * pc)
 {
-    glSecondaryColor3ubv((const GLubyte *) (pc + 0));
+    PFNGLSECONDARYCOLOR3UBVPROC SecondaryColor3ubv =
+        __glGetProcAddress("glSecondaryColor3ubv");
+    SecondaryColor3ubv((const GLubyte *) (pc + 0));
 }
 
 void
 __glXDisp_SecondaryColor3uiv(GLbyte * pc)
 {
-    glSecondaryColor3uiv((const GLuint *) (pc + 0));
+    PFNGLSECONDARYCOLOR3UIVPROC SecondaryColor3uiv =
+        __glGetProcAddress("glSecondaryColor3uiv");
+    SecondaryColor3uiv((const GLuint *) (pc + 0));
 }
 
 void
 __glXDisp_SecondaryColor3usv(GLbyte * pc)
 {
-    glSecondaryColor3usv((const GLushort *) (pc + 0));
+    PFNGLSECONDARYCOLOR3USVPROC SecondaryColor3usv =
+        __glGetProcAddress("glSecondaryColor3usv");
+    SecondaryColor3usv((const GLushort *) (pc + 0));
 }
 
 void
 __glXDisp_WindowPos3fv(GLbyte * pc)
 {
-    glWindowPos3fv((const GLfloat *) (pc + 0));
+    PFNGLWINDOWPOS3FVPROC WindowPos3fv = __glGetProcAddress("glWindowPos3fv");
+
+    WindowPos3fv((const GLfloat *) (pc + 0));
 }
 
 void
 __glXDisp_BeginQuery(GLbyte * pc)
 {
-    glBeginQuery(*(GLenum *) (pc + 0), *(GLuint *) (pc + 4));
+    PFNGLBEGINQUERYPROC BeginQuery = __glGetProcAddress("glBeginQuery");
+
+    BeginQuery(*(GLenum *) (pc + 0), *(GLuint *) (pc + 4));
 }
 
 int
 __glXDisp_DeleteQueries(__GLXclientState * cl, GLbyte * pc)
 {
+    PFNGLDELETEQUERIESPROC DeleteQueries =
+        __glGetProcAddress("glDeleteQueries");
     xGLXSingleReq *const req = (xGLXSingleReq *) pc;
     int error;
     __GLXcontext *const cx = __glXForceCurrent(cl, req->contextTag, &error);
@@ -3807,7 +3852,7 @@ __glXDisp_DeleteQueries(__GLXclientState * cl, GLbyte * pc)
     if (cx != NULL) {
         const GLsizei n = *(GLsizei *) (pc + 0);
 
-        glDeleteQueries(n, (const GLuint *) (pc + 4));
+        DeleteQueries(n, (const GLuint *) (pc + 4));
         error = Success;
     }
 
@@ -3817,12 +3862,15 @@ __glXDisp_DeleteQueries(__GLXclientState * cl, GLbyte * pc)
 void
 __glXDisp_EndQuery(GLbyte * pc)
 {
-    glEndQuery(*(GLenum *) (pc + 0));
+    PFNGLENDQUERYPROC EndQuery = __glGetProcAddress("glEndQuery");
+
+    EndQuery(*(GLenum *) (pc + 0));
 }
 
 int
 __glXDisp_GenQueries(__GLXclientState * cl, GLbyte * pc)
 {
+    PFNGLGENQUERIESPROC GenQueries = __glGetProcAddress("glGenQueries");
     xGLXSingleReq *const req = (xGLXSingleReq *) pc;
     int error;
     __GLXcontext *const cx = __glXForceCurrent(cl, req->contextTag, &error);
@@ -3835,7 +3883,7 @@ __glXDisp_GenQueries(__GLXclientState * cl, GLbyte * pc)
         GLuint *ids =
             __glXGetAnswerBuffer(cl, n * 4, answerBuffer, sizeof(answerBuffer),
                                  4);
-        glGenQueries(n, ids);
+        GenQueries(n, ids);
         __glXSendReply(cl->client, ids, n, 4, GL_TRUE, 0);
         error = Success;
     }
@@ -3846,6 +3894,8 @@ __glXDisp_GenQueries(__GLXclientState * cl, GLbyte * pc)
 int
 __glXDisp_GetQueryObjectiv(__GLXclientState * cl, GLbyte * pc)
 {
+    PFNGLGETQUERYOBJECTIVPROC GetQueryObjectiv =
+        __glGetProcAddress("glGetQueryObjectiv");
     xGLXSingleReq *const req = (xGLXSingleReq *) pc;
     int error;
     __GLXcontext *const cx = __glXForceCurrent(cl, req->contextTag, &error);
@@ -3864,7 +3914,7 @@ __glXDisp_GetQueryObjectiv(__GLXclientState * cl, GLbyte * pc)
             return BadAlloc;
         __glXClearErrorOccured();
 
-        glGetQueryObjectiv(*(GLuint *) (pc + 0), pname, params);
+        GetQueryObjectiv(*(GLuint *) (pc + 0), pname, params);
         __glXSendReply(cl->client, params, compsize, 4, GL_FALSE, 0);
         error = Success;
     }
@@ -3875,6 +3925,8 @@ __glXDisp_GetQueryObjectiv(__GLXclientState * cl, GLbyte * pc)
 int
 __glXDisp_GetQueryObjectuiv(__GLXclientState * cl, GLbyte * pc)
 {
+    PFNGLGETQUERYOBJECTUIVPROC GetQueryObjectuiv =
+        __glGetProcAddress("glGetQueryObjectuiv");
     xGLXSingleReq *const req = (xGLXSingleReq *) pc;
     int error;
     __GLXcontext *const cx = __glXForceCurrent(cl, req->contextTag, &error);
@@ -3893,7 +3945,7 @@ __glXDisp_GetQueryObjectuiv(__GLXclientState * cl, GLbyte * pc)
             return BadAlloc;
         __glXClearErrorOccured();
 
-        glGetQueryObjectuiv(*(GLuint *) (pc + 0), pname, params);
+        GetQueryObjectuiv(*(GLuint *) (pc + 0), pname, params);
         __glXSendReply(cl->client, params, compsize, 4, GL_FALSE, 0);
         error = Success;
     }
@@ -3904,6 +3956,7 @@ __glXDisp_GetQueryObjectuiv(__GLXclientState * cl, GLbyte * pc)
 int
 __glXDisp_GetQueryiv(__GLXclientState * cl, GLbyte * pc)
 {
+    PFNGLGETQUERYIVPROC GetQueryiv = __glGetProcAddress("glGetQueryiv");
     xGLXSingleReq *const req = (xGLXSingleReq *) pc;
     int error;
     __GLXcontext *const cx = __glXForceCurrent(cl, req->contextTag, &error);
@@ -3922,7 +3975,7 @@ __glXDisp_GetQueryiv(__GLXclientState * cl, GLbyte * pc)
             return BadAlloc;
         __glXClearErrorOccured();
 
-        glGetQueryiv(*(GLenum *) (pc + 0), pname, params);
+        GetQueryiv(*(GLenum *) (pc + 0), pname, params);
         __glXSendReply(cl->client, params, compsize, 4, GL_FALSE, 0);
         error = Success;
     }
@@ -3933,6 +3986,7 @@ __glXDisp_GetQueryiv(__GLXclientState * cl, GLbyte * pc)
 int
 __glXDisp_IsQuery(__GLXclientState * cl, GLbyte * pc)
 {
+    PFNGLISQUERYPROC IsQuery = __glGetProcAddress("glIsQuery");
     xGLXSingleReq *const req = (xGLXSingleReq *) pc;
     int error;
     __GLXcontext *const cx = __glXForceCurrent(cl, req->contextTag, &error);
@@ -3941,7 +3995,7 @@ __glXDisp_IsQuery(__GLXclientState * cl, GLbyte * pc)
     if (cx != NULL) {
         GLboolean retval;
 
-        retval = glIsQuery(*(GLuint *) (pc + 0));
+        retval = IsQuery(*(GLuint *) (pc + 0));
         __glXSendReply(cl->client, dummy_answer, 0, 0, GL_FALSE, retval);
         error = Success;
     }
@@ -3952,20 +4006,25 @@ __glXDisp_IsQuery(__GLXclientState * cl, GLbyte * pc)
 void
 __glXDisp_BlendEquationSeparate(GLbyte * pc)
 {
-    glBlendEquationSeparate(*(GLenum *) (pc + 0), *(GLenum *) (pc + 4));
+    PFNGLBLENDEQUATIONSEPARATEPROC BlendEquationSeparate =
+        __glGetProcAddress("glBlendEquationSeparate");
+    BlendEquationSeparate(*(GLenum *) (pc + 0), *(GLenum *) (pc + 4));
 }
 
 void
 __glXDisp_DrawBuffers(GLbyte * pc)
 {
+    PFNGLDRAWBUFFERSPROC DrawBuffers = __glGetProcAddress("glDrawBuffers");
     const GLsizei n = *(GLsizei *) (pc + 0);
 
-    glDrawBuffers(n, (const GLenum *) (pc + 4));
+    DrawBuffers(n, (const GLenum *) (pc + 4));
 }
 
 void
 __glXDisp_VertexAttrib1dv(GLbyte * pc)
 {
+    PFNGLVERTEXATTRIB1DVPROC VertexAttrib1dv =
+        __glGetProcAddress("glVertexAttrib1dv");
 #ifdef __GLX_ALIGN64
     if ((unsigned long) (pc) & 7) {
         (void) memmove(pc - 4, pc, 12);
@@ -3973,18 +4032,22 @@ __glXDisp_VertexAttrib1dv(GLbyte * pc)
     }
 #endif
 
-    glVertexAttrib1dv(*(GLuint *) (pc + 0), (const GLdouble *) (pc + 4));
+    VertexAttrib1dv(*(GLuint *) (pc + 0), (const GLdouble *) (pc + 4));
 }
 
 void
 __glXDisp_VertexAttrib1sv(GLbyte * pc)
 {
-    glVertexAttrib1sv(*(GLuint *) (pc + 0), (const GLshort *) (pc + 4));
+    PFNGLVERTEXATTRIB1SVPROC VertexAttrib1sv =
+        __glGetProcAddress("glVertexAttrib1sv");
+    VertexAttrib1sv(*(GLuint *) (pc + 0), (const GLshort *) (pc + 4));
 }
 
 void
 __glXDisp_VertexAttrib2dv(GLbyte * pc)
 {
+    PFNGLVERTEXATTRIB2DVPROC VertexAttrib2dv =
+        __glGetProcAddress("glVertexAttrib2dv");
 #ifdef __GLX_ALIGN64
     if ((unsigned long) (pc) & 7) {
         (void) memmove(pc - 4, pc, 20);
@@ -3992,18 +4055,22 @@ __glXDisp_VertexAttrib2dv(GLbyte * pc)
     }
 #endif
 
-    glVertexAttrib2dv(*(GLuint *) (pc + 0), (const GLdouble *) (pc + 4));
+    VertexAttrib2dv(*(GLuint *) (pc + 0), (const GLdouble *) (pc + 4));
 }
 
 void
 __glXDisp_VertexAttrib2sv(GLbyte * pc)
 {
-    glVertexAttrib2sv(*(GLuint *) (pc + 0), (const GLshort *) (pc + 4));
+    PFNGLVERTEXATTRIB2SVPROC VertexAttrib2sv =
+        __glGetProcAddress("glVertexAttrib2sv");
+    VertexAttrib2sv(*(GLuint *) (pc + 0), (const GLshort *) (pc + 4));
 }
 
 void
 __glXDisp_VertexAttrib3dv(GLbyte * pc)
 {
+    PFNGLVERTEXATTRIB3DVPROC VertexAttrib3dv =
+        __glGetProcAddress("glVertexAttrib3dv");
 #ifdef __GLX_ALIGN64
     if ((unsigned long) (pc) & 7) {
         (void) memmove(pc - 4, pc, 28);
@@ -4011,60 +4078,78 @@ __glXDisp_VertexAttrib3dv(GLbyte * pc)
     }
 #endif
 
-    glVertexAttrib3dv(*(GLuint *) (pc + 0), (const GLdouble *) (pc + 4));
+    VertexAttrib3dv(*(GLuint *) (pc + 0), (const GLdouble *) (pc + 4));
 }
 
 void
 __glXDisp_VertexAttrib3sv(GLbyte * pc)
 {
-    glVertexAttrib3sv(*(GLuint *) (pc + 0), (const GLshort *) (pc + 4));
+    PFNGLVERTEXATTRIB3SVPROC VertexAttrib3sv =
+        __glGetProcAddress("glVertexAttrib3sv");
+    VertexAttrib3sv(*(GLuint *) (pc + 0), (const GLshort *) (pc + 4));
 }
 
 void
 __glXDisp_VertexAttrib4Nbv(GLbyte * pc)
 {
-    glVertexAttrib4Nbv(*(GLuint *) (pc + 0), (const GLbyte *) (pc + 4));
+    PFNGLVERTEXATTRIB4NBVPROC VertexAttrib4Nbv =
+        __glGetProcAddress("glVertexAttrib4Nbv");
+    VertexAttrib4Nbv(*(GLuint *) (pc + 0), (const GLbyte *) (pc + 4));
 }
 
 void
 __glXDisp_VertexAttrib4Niv(GLbyte * pc)
 {
-    glVertexAttrib4Niv(*(GLuint *) (pc + 0), (const GLint *) (pc + 4));
+    PFNGLVERTEXATTRIB4NIVPROC VertexAttrib4Niv =
+        __glGetProcAddress("glVertexAttrib4Niv");
+    VertexAttrib4Niv(*(GLuint *) (pc + 0), (const GLint *) (pc + 4));
 }
 
 void
 __glXDisp_VertexAttrib4Nsv(GLbyte * pc)
 {
-    glVertexAttrib4Nsv(*(GLuint *) (pc + 0), (const GLshort *) (pc + 4));
+    PFNGLVERTEXATTRIB4NSVPROC VertexAttrib4Nsv =
+        __glGetProcAddress("glVertexAttrib4Nsv");
+    VertexAttrib4Nsv(*(GLuint *) (pc + 0), (const GLshort *) (pc + 4));
 }
 
 void
 __glXDisp_VertexAttrib4Nubv(GLbyte * pc)
 {
-    glVertexAttrib4Nubv(*(GLuint *) (pc + 0), (const GLubyte *) (pc + 4));
+    PFNGLVERTEXATTRIB4NUBVPROC VertexAttrib4Nubv =
+        __glGetProcAddress("glVertexAttrib4Nubv");
+    VertexAttrib4Nubv(*(GLuint *) (pc + 0), (const GLubyte *) (pc + 4));
 }
 
 void
 __glXDisp_VertexAttrib4Nuiv(GLbyte * pc)
 {
-    glVertexAttrib4Nuiv(*(GLuint *) (pc + 0), (const GLuint *) (pc + 4));
+    PFNGLVERTEXATTRIB4NUIVPROC VertexAttrib4Nuiv =
+        __glGetProcAddress("glVertexAttrib4Nuiv");
+    VertexAttrib4Nuiv(*(GLuint *) (pc + 0), (const GLuint *) (pc + 4));
 }
 
 void
 __glXDisp_VertexAttrib4Nusv(GLbyte * pc)
 {
-    glVertexAttrib4Nusv(*(GLuint *) (pc + 0), (const GLushort *) (pc + 4));
+    PFNGLVERTEXATTRIB4NUSVPROC VertexAttrib4Nusv =
+        __glGetProcAddress("glVertexAttrib4Nusv");
+    VertexAttrib4Nusv(*(GLuint *) (pc + 0), (const GLushort *) (pc + 4));
 }
 
 void
 __glXDisp_VertexAttrib4bv(GLbyte * pc)
 {
-    glVertexAttrib4bv(*(GLuint *) (pc + 0), (const GLbyte *) (pc + 4));
+    PFNGLVERTEXATTRIB4BVPROC VertexAttrib4bv =
+        __glGetProcAddress("glVertexAttrib4bv");
+    VertexAttrib4bv(*(GLuint *) (pc + 0), (const GLbyte *) (pc + 4));
 }
 
 void
 __glXDisp_VertexAttrib4dv(GLbyte * pc)
 {
+    PFNGLVERTEXATTRIB4DVPROC VertexAttrib4dv =
+        __glGetProcAddress("glVertexAttrib4dv");
 #ifdef __GLX_ALIGN64
     if ((unsigned long) (pc) & 7) {
         (void) memmove(pc - 4, pc, 36);
@@ -4072,54 +4157,70 @@ __glXDisp_VertexAttrib4dv(GLbyte * pc)
     }
 #endif
 
-    glVertexAttrib4dv(*(GLuint *) (pc + 0), (const GLdouble *) (pc + 4));
+    VertexAttrib4dv(*(GLuint *) (pc + 0), (const GLdouble *) (pc + 4));
 }
 
 void
 __glXDisp_VertexAttrib4iv(GLbyte * pc)
 {
-    glVertexAttrib4iv(*(GLuint *) (pc + 0), (const GLint *) (pc + 4));
+    PFNGLVERTEXATTRIB4IVPROC VertexAttrib4iv =
+        __glGetProcAddress("glVertexAttrib4iv");
+    VertexAttrib4iv(*(GLuint *) (pc + 0), (const GLint *) (pc + 4));
 }
 
 void
 __glXDisp_VertexAttrib4sv(GLbyte * pc)
 {
-    glVertexAttrib4sv(*(GLuint *) (pc + 0), (const GLshort *) (pc + 4));
+    PFNGLVERTEXATTRIB4SVPROC VertexAttrib4sv =
+        __glGetProcAddress("glVertexAttrib4sv");
+    VertexAttrib4sv(*(GLuint *) (pc + 0), (const GLshort *) (pc + 4));
 }
 
 void
 __glXDisp_VertexAttrib4ubv(GLbyte * pc)
 {
-    glVertexAttrib4ubv(*(GLuint *) (pc + 0), (const GLubyte *) (pc + 4));
+    PFNGLVERTEXATTRIB4UBVPROC VertexAttrib4ubv =
+        __glGetProcAddress("glVertexAttrib4ubv");
+    VertexAttrib4ubv(*(GLuint *) (pc + 0), (const GLubyte *) (pc + 4));
 }
 
 void
 __glXDisp_VertexAttrib4uiv(GLbyte * pc)
 {
-    glVertexAttrib4uiv(*(GLuint *) (pc + 0), (const GLuint *) (pc + 4));
+    PFNGLVERTEXATTRIB4UIVPROC VertexAttrib4uiv =
+        __glGetProcAddress("glVertexAttrib4uiv");
+    VertexAttrib4uiv(*(GLuint *) (pc + 0), (const GLuint *) (pc + 4));
 }
 
 void
 __glXDisp_VertexAttrib4usv(GLbyte * pc)
 {
-    glVertexAttrib4usv(*(GLuint *) (pc + 0), (const GLushort *) (pc + 4));
+    PFNGLVERTEXATTRIB4USVPROC VertexAttrib4usv =
+        __glGetProcAddress("glVertexAttrib4usv");
+    VertexAttrib4usv(*(GLuint *) (pc + 0), (const GLushort *) (pc + 4));
 }
 
 void
 __glXDisp_ClampColor(GLbyte * pc)
 {
-    glClampColor(*(GLenum *) (pc + 0), *(GLenum *) (pc + 4));
+    PFNGLCLAMPCOLORPROC ClampColor = __glGetProcAddress("glClampColor");
+
+    ClampColor(*(GLenum *) (pc + 0), *(GLenum *) (pc + 4));
 }
 
 void
 __glXDisp_BindProgramARB(GLbyte * pc)
 {
-    glBindProgramARB(*(GLenum *) (pc + 0), *(GLuint *) (pc + 4));
+    PFNGLBINDPROGRAMARBPROC BindProgramARB =
+        __glGetProcAddress("glBindProgramARB");
+    BindProgramARB(*(GLenum *) (pc + 0), *(GLuint *) (pc + 4));
 }
 
 int
 __glXDisp_DeleteProgramsARB(__GLXclientState * cl, GLbyte * pc)
 {
+    PFNGLDELETEPROGRAMSARBPROC DeleteProgramsARB =
+        __glGetProcAddress("glDeleteProgramsARB");
     xGLXVendorPrivateReq *const req = (xGLXVendorPrivateReq *) pc;
     int error;
     __GLXcontext *const cx = __glXForceCurrent(cl, req->contextTag, &error);
@@ -4128,7 +4229,7 @@ __glXDisp_DeleteProgramsARB(__GLXclientState * cl, GLbyte * pc)
     if (cx != NULL) {
         const GLsizei n = *(GLsizei *) (pc + 0);
 
-        glDeleteProgramsARB(n, (const GLuint *) (pc + 4));
+        DeleteProgramsARB(n, (const GLuint *) (pc + 4));
         error = Success;
     }
 
@@ -4138,6 +4239,8 @@ __glXDisp_DeleteProgramsARB(__GLXclientState * cl, GLbyte * pc)
 int
 __glXDisp_GenProgramsARB(__GLXclientState * cl, GLbyte * pc)
 {
+    PFNGLGENPROGRAMSARBPROC GenProgramsARB =
+        __glGetProcAddress("glGenProgramsARB");
     xGLXVendorPrivateReq *const req = (xGLXVendorPrivateReq *) pc;
     int error;
     __GLXcontext *const cx = __glXForceCurrent(cl, req->contextTag, &error);
@@ -4150,7 +4253,7 @@ __glXDisp_GenProgramsARB(__GLXclientState * cl, GLbyte * pc)
         GLuint *programs =
             __glXGetAnswerBuffer(cl, n * 4, answerBuffer, sizeof(answerBuffer),
                                  4);
-        glGenProgramsARB(n, programs);
+        GenProgramsARB(n, programs);
         __glXSendReply(cl->client, programs, n, 4, GL_TRUE, 0);
         error = Success;
     }
@@ -4161,6 +4264,8 @@ __glXDisp_GenProgramsARB(__GLXclientState * cl, GLbyte * pc)
 int
 __glXDisp_GetProgramEnvParameterdvARB(__GLXclientState * cl, GLbyte * pc)
 {
+    PFNGLGETPROGRAMENVPARAMETERDVARBPROC GetProgramEnvParameterdvARB =
+        __glGetProcAddress("glGetProgramEnvParameterdvARB");
     xGLXVendorPrivateReq *const req = (xGLXVendorPrivateReq *) pc;
     int error;
     __GLXcontext *const cx = __glXForceCurrent(cl, req->contextTag, &error);
@@ -4169,8 +4274,8 @@ __glXDisp_GetProgramEnvParameterdvARB(__GLXclientState * cl, GLbyte * pc)
     if (cx != NULL) {
         GLdouble params[4];
 
-        glGetProgramEnvParameterdvARB(*(GLenum *) (pc + 0),
-                                      *(GLuint *) (pc + 4), params);
+        GetProgramEnvParameterdvARB(*(GLenum *) (pc + 0),
+                                    *(GLuint *) (pc + 4), params);
         __glXSendReply(cl->client, params, 4, 8, GL_FALSE, 0);
         error = Success;
     }
@@ -4181,6 +4286,8 @@ __glXDisp_GetProgramEnvParameterdvARB(__GLXclientState * cl, GLbyte * pc)
 int
 __glXDisp_GetProgramEnvParameterfvARB(__GLXclientState * cl, GLbyte * pc)
 {
+    PFNGLGETPROGRAMENVPARAMETERFVARBPROC GetProgramEnvParameterfvARB =
+        __glGetProcAddress("glGetProgramEnvParameterfvARB");
     xGLXVendorPrivateReq *const req = (xGLXVendorPrivateReq *) pc;
     int error;
     __GLXcontext *const cx = __glXForceCurrent(cl, req->contextTag, &error);
@@ -4189,8 +4296,8 @@ __glXDisp_GetProgramEnvParameterfvARB(__GLXclientState * cl, GLbyte * pc)
     if (cx != NULL) {
         GLfloat params[4];
 
-        glGetProgramEnvParameterfvARB(*(GLenum *) (pc + 0),
-                                      *(GLuint *) (pc + 4), params);
+        GetProgramEnvParameterfvARB(*(GLenum *) (pc + 0),
+                                    *(GLuint *) (pc + 4), params);
         __glXSendReply(cl->client, params, 4, 4, GL_FALSE, 0);
         error = Success;
     }
@@ -4201,6 +4308,8 @@ __glXDisp_GetProgramEnvParameterfvARB(__GLXclientState * cl, GLbyte * pc)
 int
 __glXDisp_GetProgramLocalParameterdvARB(__GLXclientState * cl, GLbyte * pc)
 {
+    PFNGLGETPROGRAMLOCALPARAMETERDVARBPROC GetProgramLocalParameterdvARB =
+        __glGetProcAddress("glGetProgramLocalParameterdvARB");
     xGLXVendorPrivateReq *const req = (xGLXVendorPrivateReq *) pc;
     int error;
     __GLXcontext *const cx = __glXForceCurrent(cl, req->contextTag, &error);
@@ -4209,8 +4318,8 @@ __glXDisp_GetProgramLocalParameterdvARB(__GLXclientState * cl, GLbyte * pc)
     if (cx != NULL) {
         GLdouble params[4];
 
-        glGetProgramLocalParameterdvARB(*(GLenum *) (pc + 0),
-                                        *(GLuint *) (pc + 4), params);
+        GetProgramLocalParameterdvARB(*(GLenum *) (pc + 0),
+                                      *(GLuint *) (pc + 4), params);
         __glXSendReply(cl->client, params, 4, 8, GL_FALSE, 0);
         error = Success;
     }
@@ -4221,6 +4330,8 @@ __glXDisp_GetProgramLocalParameterdvARB(__GLXclientState * cl, GLbyte * pc)
 int
 __glXDisp_GetProgramLocalParameterfvARB(__GLXclientState * cl, GLbyte * pc)
 {
+    PFNGLGETPROGRAMLOCALPARAMETERFVARBPROC GetProgramLocalParameterfvARB =
+        __glGetProcAddress("glGetProgramLocalParameterfvARB");
     xGLXVendorPrivateReq *const req = (xGLXVendorPrivateReq *) pc;
     int error;
     __GLXcontext *const cx = __glXForceCurrent(cl, req->contextTag, &error);
@@ -4229,8 +4340,8 @@ __glXDisp_GetProgramLocalParameterfvARB(__GLXclientState * cl, GLbyte * pc)
     if (cx != NULL) {
         GLfloat params[4];
 
-        glGetProgramLocalParameterfvARB(*(GLenum *) (pc + 0),
-                                        *(GLuint *) (pc + 4), params);
+        GetProgramLocalParameterfvARB(*(GLenum *) (pc + 0),
+                                      *(GLuint *) (pc + 4), params);
         __glXSendReply(cl->client, params, 4, 4, GL_FALSE, 0);
         error = Success;
     }
@@ -4241,6 +4352,8 @@ __glXDisp_GetProgramLocalParameterfvARB(__GLXclientState * cl, GLbyte * pc)
 int
 __glXDisp_GetProgramivARB(__GLXclientState * cl, GLbyte * pc)
 {
+    PFNGLGETPROGRAMIVARBPROC GetProgramivARB =
+        __glGetProcAddress("glGetProgramivARB");
     xGLXVendorPrivateReq *const req = (xGLXVendorPrivateReq *) pc;
     int error;
     __GLXcontext *const cx = __glXForceCurrent(cl, req->contextTag, &error);
@@ -4259,7 +4372,7 @@ __glXDisp_GetProgramivARB(__GLXclientState * cl, GLbyte * pc)
             return BadAlloc;
         __glXClearErrorOccured();
 
-        glGetProgramivARB(*(GLenum *) (pc + 0), pname, params);
+        GetProgramivARB(*(GLenum *) (pc + 0), pname, params);
         __glXSendReply(cl->client, params, compsize, 4, GL_FALSE, 0);
         error = Success;
     }
@@ -4270,6 +4383,7 @@ __glXDisp_GetProgramivARB(__GLXclientState * cl, GLbyte * pc)
 int
 __glXDisp_IsProgramARB(__GLXclientState * cl, GLbyte * pc)
 {
+    PFNGLISPROGRAMARBPROC IsProgramARB = __glGetProcAddress("glIsProgramARB");
     xGLXVendorPrivateReq *const req = (xGLXVendorPrivateReq *) pc;
     int error;
     __GLXcontext *const cx = __glXForceCurrent(cl, req->contextTag, &error);
@@ -4278,7 +4392,7 @@ __glXDisp_IsProgramARB(__GLXclientState * cl, GLbyte * pc)
     if (cx != NULL) {
         GLboolean retval;
 
-        retval = glIsProgramARB(*(GLuint *) (pc + 0));
+        retval = IsProgramARB(*(GLuint *) (pc + 0));
         __glXSendReply(cl->client, dummy_answer, 0, 0, GL_FALSE, retval);
         error = Success;
     }
@@ -4289,6 +4403,8 @@ __glXDisp_IsProgramARB(__GLXclientState * cl, GLbyte * pc)
 void
 __glXDisp_ProgramEnvParameter4dvARB(GLbyte * pc)
 {
+    PFNGLPROGRAMENVPARAMETER4DVARBPROC ProgramEnvParameter4dvARB =
+        __glGetProcAddress("glProgramEnvParameter4dvARB");
 #ifdef __GLX_ALIGN64
     if ((unsigned long) (pc) & 7) {
         (void) memmove(pc - 4, pc, 40);
@@ -4296,22 +4412,25 @@ __glXDisp_ProgramEnvParameter4dvARB(GLbyte * pc)
     }
 #endif
 
-    glProgramEnvParameter4dvARB(*(GLenum *) (pc + 0),
-                                *(GLuint *) (pc + 4),
-                                (const GLdouble *) (pc + 8));
+    ProgramEnvParameter4dvARB(*(GLenum *) (pc + 0),
+                              *(GLuint *) (pc + 4),
+                              (const GLdouble *) (pc + 8));
 }
 
 void
 __glXDisp_ProgramEnvParameter4fvARB(GLbyte * pc)
 {
-    glProgramEnvParameter4fvARB(*(GLenum *) (pc + 0),
-                                *(GLuint *) (pc + 4),
-                                (const GLfloat *) (pc + 8));
+    PFNGLPROGRAMENVPARAMETER4FVARBPROC ProgramEnvParameter4fvARB =
+        __glGetProcAddress("glProgramEnvParameter4fvARB");
+    ProgramEnvParameter4fvARB(*(GLenum *) (pc + 0), *(GLuint *) (pc + 4),
+                              (const GLfloat *) (pc + 8));
 }
 
 void
 __glXDisp_ProgramLocalParameter4dvARB(GLbyte * pc)
 {
+    PFNGLPROGRAMLOCALPARAMETER4DVARBPROC ProgramLocalParameter4dvARB =
+        __glGetProcAddress("glProgramLocalParameter4dvARB");
 #ifdef __GLX_ALIGN64
     if ((unsigned long) (pc) & 7) {
         (void) memmove(pc - 4, pc, 40);
@@ -4319,81 +4438,96 @@ __glXDisp_ProgramLocalParameter4dvARB(GLbyte * pc)
     }
 #endif
 
-    glProgramLocalParameter4dvARB(*(GLenum *) (pc + 0),
-                                  *(GLuint *) (pc + 4),
-                                  (const GLdouble *) (pc + 8));
+    ProgramLocalParameter4dvARB(*(GLenum *) (pc + 0),
+                                *(GLuint *) (pc + 4),
+                                (const GLdouble *) (pc + 8));
 }
 
 void
 __glXDisp_ProgramLocalParameter4fvARB(GLbyte * pc)
 {
-    glProgramLocalParameter4fvARB(*(GLenum *) (pc + 0),
-                                  *(GLuint *) (pc + 4),
-                                  (const GLfloat *) (pc + 8));
+    PFNGLPROGRAMLOCALPARAMETER4FVARBPROC ProgramLocalParameter4fvARB =
+        __glGetProcAddress("glProgramLocalParameter4fvARB");
+    ProgramLocalParameter4fvARB(*(GLenum *) (pc + 0), *(GLuint *) (pc + 4),
+                                (const GLfloat *) (pc + 8));
 }
 
 void
 __glXDisp_ProgramStringARB(GLbyte * pc)
 {
+    PFNGLPROGRAMSTRINGARBPROC ProgramStringARB =
+        __glGetProcAddress("glProgramStringARB");
     const GLsizei len = *(GLsizei *) (pc + 8);
 
-    glProgramStringARB(*(GLenum *) (pc + 0),
-                       *(GLenum *) (pc + 4), len, (const GLvoid *) (pc + 12));
+    ProgramStringARB(*(GLenum *) (pc + 0),
+                     *(GLenum *) (pc + 4), len, (const GLvoid *) (pc + 12));
 }
 
 void
 __glXDisp_VertexAttrib1fvARB(GLbyte * pc)
 {
-    glVertexAttrib1fvARB(*(GLuint *) (pc + 0), (const GLfloat *) (pc + 4));
+    PFNGLVERTEXATTRIB1FVARBPROC VertexAttrib1fvARB =
+        __glGetProcAddress("glVertexAttrib1fvARB");
+    VertexAttrib1fvARB(*(GLuint *) (pc + 0), (const GLfloat *) (pc + 4));
 }
 
 void
 __glXDisp_VertexAttrib2fvARB(GLbyte * pc)
 {
-    glVertexAttrib2fvARB(*(GLuint *) (pc + 0), (const GLfloat *) (pc + 4));
+    PFNGLVERTEXATTRIB2FVARBPROC VertexAttrib2fvARB =
+        __glGetProcAddress("glVertexAttrib2fvARB");
+    VertexAttrib2fvARB(*(GLuint *) (pc + 0), (const GLfloat *) (pc + 4));
 }
 
 void
 __glXDisp_VertexAttrib3fvARB(GLbyte * pc)
 {
-    glVertexAttrib3fvARB(*(GLuint *) (pc + 0), (const GLfloat *) (pc + 4));
+    PFNGLVERTEXATTRIB3FVARBPROC VertexAttrib3fvARB =
+        __glGetProcAddress("glVertexAttrib3fvARB");
+    VertexAttrib3fvARB(*(GLuint *) (pc + 0), (const GLfloat *) (pc + 4));
 }
 
 void
 __glXDisp_VertexAttrib4fvARB(GLbyte * pc)
 {
-    glVertexAttrib4fvARB(*(GLuint *) (pc + 0), (const GLfloat *) (pc + 4));
+    PFNGLVERTEXATTRIB4FVARBPROC VertexAttrib4fvARB =
+        __glGetProcAddress("glVertexAttrib4fvARB");
+    VertexAttrib4fvARB(*(GLuint *) (pc + 0), (const GLfloat *) (pc + 4));
 }
 
 void
 __glXDisp_BindFramebuffer(GLbyte * pc)
 {
-    glBindFramebuffer(*(GLenum *) (pc + 0), *(GLuint *) (pc + 4));
+    PFNGLBINDFRAMEBUFFERPROC BindFramebuffer =
+        __glGetProcAddress("glBindFramebuffer");
+    BindFramebuffer(*(GLenum *) (pc + 0), *(GLuint *) (pc + 4));
 }
 
 void
 __glXDisp_BindRenderbuffer(GLbyte * pc)
 {
-    glBindRenderbuffer(*(GLenum *) (pc + 0), *(GLuint *) (pc + 4));
+    PFNGLBINDRENDERBUFFERPROC BindRenderbuffer =
+        __glGetProcAddress("glBindRenderbuffer");
+    BindRenderbuffer(*(GLenum *) (pc + 0), *(GLuint *) (pc + 4));
 }
 
 void
 __glXDisp_BlitFramebuffer(GLbyte * pc)
 {
-    glBlitFramebuffer(*(GLint *) (pc + 0),
-                      *(GLint *) (pc + 4),
-                      *(GLint *) (pc + 8),
-                      *(GLint *) (pc + 12),
-                      *(GLint *) (pc + 16),
-                      *(GLint *) (pc + 20),
-                      *(GLint *) (pc + 24),
-                      *(GLint *) (pc + 28),
-                      *(GLbitfield *) (pc + 32), *(GLenum *) (pc + 36));
+    PFNGLBLITFRAMEBUFFERPROC BlitFramebuffer =
+        __glGetProcAddress("glBlitFramebuffer");
+    BlitFramebuffer(*(GLint *) (pc + 0), *(GLint *) (pc + 4),
+                    *(GLint *) (pc + 8), *(GLint *) (pc + 12),
+                    *(GLint *) (pc + 16), *(GLint *) (pc + 20),
+                    *(GLint *) (pc + 24), *(GLint *) (pc + 28),
+                    *(GLbitfield *) (pc + 32), *(GLenum *) (pc + 36));
 }
 
 int
 __glXDisp_CheckFramebufferStatus(__GLXclientState * cl, GLbyte * pc)
 {
+    PFNGLCHECKFRAMEBUFFERSTATUSPROC CheckFramebufferStatus =
+        __glGetProcAddress("glCheckFramebufferStatus");
     xGLXVendorPrivateReq *const req = (xGLXVendorPrivateReq *) pc;
     int error;
     __GLXcontext *const cx = __glXForceCurrent(cl, req->contextTag, &error);
@@ -4402,7 +4536,7 @@ __glXDisp_CheckFramebufferStatus(__GLXclientState * cl, GLbyte * pc)
     if (cx != NULL) {
         GLenum retval;
 
-        retval = glCheckFramebufferStatus(*(GLenum *) (pc + 0));
+        retval = CheckFramebufferStatus(*(GLenum *) (pc + 0));
         __glXSendReply(cl->client, dummy_answer, 0, 0, GL_FALSE, retval);
         error = Success;
     }
@@ -4413,67 +4547,77 @@ __glXDisp_CheckFramebufferStatus(__GLXclientState * cl, GLbyte * pc)
 void
 __glXDisp_DeleteFramebuffers(GLbyte * pc)
 {
+    PFNGLDELETEFRAMEBUFFERSPROC DeleteFramebuffers =
+        __glGetProcAddress("glDeleteFramebuffers");
     const GLsizei n = *(GLsizei *) (pc + 0);
 
-    glDeleteFramebuffers(n, (const GLuint *) (pc + 4));
+    DeleteFramebuffers(n, (const GLuint *) (pc + 4));
 }
 
 void
 __glXDisp_DeleteRenderbuffers(GLbyte * pc)
 {
+    PFNGLDELETERENDERBUFFERSPROC DeleteRenderbuffers =
+        __glGetProcAddress("glDeleteRenderbuffers");
     const GLsizei n = *(GLsizei *) (pc + 0);
 
-    glDeleteRenderbuffers(n, (const GLuint *) (pc + 4));
+    DeleteRenderbuffers(n, (const GLuint *) (pc + 4));
 }
 
 void
 __glXDisp_FramebufferRenderbuffer(GLbyte * pc)
 {
-    glFramebufferRenderbuffer(*(GLenum *) (pc + 0),
-                              *(GLenum *) (pc + 4),
-                              *(GLenum *) (pc + 8), *(GLuint *) (pc + 12));
+    PFNGLFRAMEBUFFERRENDERBUFFERPROC FramebufferRenderbuffer =
+        __glGetProcAddress("glFramebufferRenderbuffer");
+    FramebufferRenderbuffer(*(GLenum *) (pc + 0), *(GLenum *) (pc + 4),
+                            *(GLenum *) (pc + 8), *(GLuint *) (pc + 12));
 }
 
 void
 __glXDisp_FramebufferTexture1D(GLbyte * pc)
 {
-    glFramebufferTexture1D(*(GLenum *) (pc + 0),
-                           *(GLenum *) (pc + 4),
-                           *(GLenum *) (pc + 8),
-                           *(GLuint *) (pc + 12), *(GLint *) (pc + 16));
+    PFNGLFRAMEBUFFERTEXTURE1DPROC FramebufferTexture1D =
+        __glGetProcAddress("glFramebufferTexture1D");
+    FramebufferTexture1D(*(GLenum *) (pc + 0), *(GLenum *) (pc + 4),
+                         *(GLenum *) (pc + 8), *(GLuint *) (pc + 12),
+                         *(GLint *) (pc + 16));
 }
 
 void
 __glXDisp_FramebufferTexture2D(GLbyte * pc)
 {
-    glFramebufferTexture2D(*(GLenum *) (pc + 0),
-                           *(GLenum *) (pc + 4),
-                           *(GLenum *) (pc + 8),
-                           *(GLuint *) (pc + 12), *(GLint *) (pc + 16));
+    PFNGLFRAMEBUFFERTEXTURE2DPROC FramebufferTexture2D =
+        __glGetProcAddress("glFramebufferTexture2D");
+    FramebufferTexture2D(*(GLenum *) (pc + 0), *(GLenum *) (pc + 4),
+                         *(GLenum *) (pc + 8), *(GLuint *) (pc + 12),
+                         *(GLint *) (pc + 16));
 }
 
 void
 __glXDisp_FramebufferTexture3D(GLbyte * pc)
 {
-    glFramebufferTexture3D(*(GLenum *) (pc + 0),
-                           *(GLenum *) (pc + 4),
-                           *(GLenum *) (pc + 8),
-                           *(GLuint *) (pc + 12),
-                           *(GLint *) (pc + 16), *(GLint *) (pc + 20));
+    PFNGLFRAMEBUFFERTEXTURE3DPROC FramebufferTexture3D =
+        __glGetProcAddress("glFramebufferTexture3D");
+    FramebufferTexture3D(*(GLenum *) (pc + 0), *(GLenum *) (pc + 4),
+                         *(GLenum *) (pc + 8), *(GLuint *) (pc + 12),
+                         *(GLint *) (pc + 16), *(GLint *) (pc + 20));
 }
 
 void
 __glXDisp_FramebufferTextureLayer(GLbyte * pc)
 {
-    glFramebufferTextureLayer(*(GLenum *) (pc + 0),
-                              *(GLenum *) (pc + 4),
-                              *(GLuint *) (pc + 8),
-                              *(GLint *) (pc + 12), *(GLint *) (pc + 16));
+    PFNGLFRAMEBUFFERTEXTURELAYERPROC FramebufferTextureLayer =
+        __glGetProcAddress("glFramebufferTextureLayer");
+    FramebufferTextureLayer(*(GLenum *) (pc + 0), *(GLenum *) (pc + 4),
+                            *(GLuint *) (pc + 8), *(GLint *) (pc + 12),
+                            *(GLint *) (pc + 16));
 }
 
 int
 __glXDisp_GenFramebuffers(__GLXclientState * cl, GLbyte * pc)
 {
+    PFNGLGENFRAMEBUFFERSPROC GenFramebuffers =
+        __glGetProcAddress("glGenFramebuffers");
     xGLXVendorPrivateReq *const req = (xGLXVendorPrivateReq *) pc;
     int error;
     __GLXcontext *const cx = __glXForceCurrent(cl, req->contextTag, &error);
@@ -4486,7 +4630,7 @@ __glXDisp_GenFramebuffers(__GLXclientState * cl, GLbyte * pc)
         GLuint *framebuffers =
             __glXGetAnswerBuffer(cl, n * 4, answerBuffer, sizeof(answerBuffer),
                                  4);
-        glGenFramebuffers(n, framebuffers);
+        GenFramebuffers(n, framebuffers);
         __glXSendReply(cl->client, framebuffers, n, 4, GL_TRUE, 0);
         error = Success;
     }
@@ -4497,6 +4641,8 @@ __glXDisp_GenFramebuffers(__GLXclientState * cl, GLbyte * pc)
 int
 __glXDisp_GenRenderbuffers(__GLXclientState * cl, GLbyte * pc)
 {
+    PFNGLGENRENDERBUFFERSPROC GenRenderbuffers =
+        __glGetProcAddress("glGenRenderbuffers");
     xGLXVendorPrivateReq *const req = (xGLXVendorPrivateReq *) pc;
     int error;
     __GLXcontext *const cx = __glXForceCurrent(cl, req->contextTag, &error);
@@ -4509,7 +4655,7 @@ __glXDisp_GenRenderbuffers(__GLXclientState * cl, GLbyte * pc)
         GLuint *renderbuffers =
             __glXGetAnswerBuffer(cl, n * 4, answerBuffer, sizeof(answerBuffer),
                                  4);
-        glGenRenderbuffers(n, renderbuffers);
+        GenRenderbuffers(n, renderbuffers);
         __glXSendReply(cl->client, renderbuffers, n, 4, GL_TRUE, 0);
         error = Success;
     }
@@ -4520,13 +4666,18 @@ __glXDisp_GenRenderbuffers(__GLXclientState * cl, GLbyte * pc)
 void
 __glXDisp_GenerateMipmap(GLbyte * pc)
 {
-    glGenerateMipmap(*(GLenum *) (pc + 0));
+    PFNGLGENERATEMIPMAPPROC GenerateMipmap =
+        __glGetProcAddress("glGenerateMipmap");
+    GenerateMipmap(*(GLenum *) (pc + 0));
 }
 
 int
 __glXDisp_GetFramebufferAttachmentParameteriv(__GLXclientState * cl,
                                               GLbyte * pc)
 {
+    PFNGLGETFRAMEBUFFERATTACHMENTPARAMETERIVPROC
+        GetFramebufferAttachmentParameteriv =
+        __glGetProcAddress("glGetFramebufferAttachmentParameteriv");
     xGLXVendorPrivateReq *const req = (xGLXVendorPrivateReq *) pc;
     int error;
     __GLXcontext *const cx = __glXForceCurrent(cl, req->contextTag, &error);
@@ -4535,9 +4686,9 @@ __glXDisp_GetFramebufferAttachmentParameteriv(__GLXclientState * cl,
     if (cx != NULL) {
         GLint params[1];
 
-        glGetFramebufferAttachmentParameteriv(*(GLenum *) (pc + 0),
-                                              *(GLenum *) (pc + 4),
-                                              *(GLenum *) (pc + 8), params);
+        GetFramebufferAttachmentParameteriv(*(GLenum *) (pc + 0),
+                                            *(GLenum *) (pc + 4),
+                                            *(GLenum *) (pc + 8), params);
         __glXSendReply(cl->client, params, 1, 4, GL_FALSE, 0);
         error = Success;
     }
@@ -4548,6 +4699,8 @@ __glXDisp_GetFramebufferAttachmentParameteriv(__GLXclientState * cl,
 int
 __glXDisp_GetRenderbufferParameteriv(__GLXclientState * cl, GLbyte * pc)
 {
+    PFNGLGETRENDERBUFFERPARAMETERIVPROC GetRenderbufferParameteriv =
+        __glGetProcAddress("glGetRenderbufferParameteriv");
     xGLXVendorPrivateReq *const req = (xGLXVendorPrivateReq *) pc;
     int error;
     __GLXcontext *const cx = __glXForceCurrent(cl, req->contextTag, &error);
@@ -4556,8 +4709,8 @@ __glXDisp_GetRenderbufferParameteriv(__GLXclientState * cl, GLbyte * pc)
     if (cx != NULL) {
         GLint params[1];
 
-        glGetRenderbufferParameteriv(*(GLenum *) (pc + 0),
-                                     *(GLenum *) (pc + 4), params);
+        GetRenderbufferParameteriv(*(GLenum *) (pc + 0),
+                                   *(GLenum *) (pc + 4), params);
         __glXSendReply(cl->client, params, 1, 4, GL_FALSE, 0);
         error = Success;
     }
@@ -4568,6 +4721,8 @@ __glXDisp_GetRenderbufferParameteriv(__GLXclientState * cl, GLbyte * pc)
 int
 __glXDisp_IsFramebuffer(__GLXclientState * cl, GLbyte * pc)
 {
+    PFNGLISFRAMEBUFFERPROC IsFramebuffer =
+        __glGetProcAddress("glIsFramebuffer");
     xGLXVendorPrivateReq *const req = (xGLXVendorPrivateReq *) pc;
     int error;
     __GLXcontext *const cx = __glXForceCurrent(cl, req->contextTag, &error);
@@ -4576,7 +4731,7 @@ __glXDisp_IsFramebuffer(__GLXclientState * cl, GLbyte * pc)
     if (cx != NULL) {
         GLboolean retval;
 
-        retval = glIsFramebuffer(*(GLuint *) (pc + 0));
+        retval = IsFramebuffer(*(GLuint *) (pc + 0));
         __glXSendReply(cl->client, dummy_answer, 0, 0, GL_FALSE, retval);
         error = Success;
     }
@@ -4587,6 +4742,8 @@ __glXDisp_IsFramebuffer(__GLXclientState * cl, GLbyte * pc)
 int
 __glXDisp_IsRenderbuffer(__GLXclientState * cl, GLbyte * pc)
 {
+    PFNGLISRENDERBUFFERPROC IsRenderbuffer =
+        __glGetProcAddress("glIsRenderbuffer");
     xGLXVendorPrivateReq *const req = (xGLXVendorPrivateReq *) pc;
     int error;
     __GLXcontext *const cx = __glXForceCurrent(cl, req->contextTag, &error);
@@ -4595,7 +4752,7 @@ __glXDisp_IsRenderbuffer(__GLXclientState * cl, GLbyte * pc)
     if (cx != NULL) {
         GLboolean retval;
 
-        retval = glIsRenderbuffer(*(GLuint *) (pc + 0));
+        retval = IsRenderbuffer(*(GLuint *) (pc + 0));
         __glXSendReply(cl->client, dummy_answer, 0, 0, GL_FALSE, retval);
         error = Success;
     }
@@ -4606,36 +4763,43 @@ __glXDisp_IsRenderbuffer(__GLXclientState * cl, GLbyte * pc)
 void
 __glXDisp_RenderbufferStorage(GLbyte * pc)
 {
-    glRenderbufferStorage(*(GLenum *) (pc + 0),
-                          *(GLenum *) (pc + 4),
-                          *(GLsizei *) (pc + 8), *(GLsizei *) (pc + 12));
+    PFNGLRENDERBUFFERSTORAGEPROC RenderbufferStorage =
+        __glGetProcAddress("glRenderbufferStorage");
+    RenderbufferStorage(*(GLenum *) (pc + 0), *(GLenum *) (pc + 4),
+                        *(GLsizei *) (pc + 8), *(GLsizei *) (pc + 12));
 }
 
 void
 __glXDisp_RenderbufferStorageMultisample(GLbyte * pc)
 {
-    glRenderbufferStorageMultisample(*(GLenum *) (pc + 0),
-                                     *(GLsizei *) (pc + 4),
-                                     *(GLenum *) (pc + 8),
-                                     *(GLsizei *) (pc + 12),
-                                     *(GLsizei *) (pc + 16));
+    PFNGLRENDERBUFFERSTORAGEMULTISAMPLEPROC RenderbufferStorageMultisample =
+        __glGetProcAddress("glRenderbufferStorageMultisample");
+    RenderbufferStorageMultisample(*(GLenum *) (pc + 0), *(GLsizei *) (pc + 4),
+                                   *(GLenum *) (pc + 8), *(GLsizei *) (pc + 12),
+                                   *(GLsizei *) (pc + 16));
 }
 
 void
 __glXDisp_SecondaryColor3fvEXT(GLbyte * pc)
 {
-    glSecondaryColor3fvEXT((const GLfloat *) (pc + 0));
+    PFNGLSECONDARYCOLOR3FVEXTPROC SecondaryColor3fvEXT =
+        __glGetProcAddress("glSecondaryColor3fvEXT");
+    SecondaryColor3fvEXT((const GLfloat *) (pc + 0));
 }
 
 void
 __glXDisp_FogCoordfvEXT(GLbyte * pc)
 {
-    glFogCoordfvEXT((const GLfloat *) (pc + 0));
+    PFNGLFOGCOORDFVEXTPROC FogCoordfvEXT =
+        __glGetProcAddress("glFogCoordfvEXT");
+    FogCoordfvEXT((const GLfloat *) (pc + 0));
 }
 
 void
 __glXDisp_VertexAttrib1dvNV(GLbyte * pc)
 {
+    PFNGLVERTEXATTRIB1DVNVPROC VertexAttrib1dvNV =
+        __glGetProcAddress("glVertexAttrib1dvNV");
 #ifdef __GLX_ALIGN64
     if ((unsigned long) (pc) & 7) {
         (void) memmove(pc - 4, pc, 12);
@@ -4643,24 +4807,30 @@ __glXDisp_VertexAttrib1dvNV(GLbyte * pc)
     }
 #endif
 
-    glVertexAttrib1dvNV(*(GLuint *) (pc + 0), (const GLdouble *) (pc + 4));
+    VertexAttrib1dvNV(*(GLuint *) (pc + 0), (const GLdouble *) (pc + 4));
 }
 
 void
 __glXDisp_VertexAttrib1fvNV(GLbyte * pc)
 {
-    glVertexAttrib1fvNV(*(GLuint *) (pc + 0), (const GLfloat *) (pc + 4));
+    PFNGLVERTEXATTRIB1FVNVPROC VertexAttrib1fvNV =
+        __glGetProcAddress("glVertexAttrib1fvNV");
+    VertexAttrib1fvNV(*(GLuint *) (pc + 0), (const GLfloat *) (pc + 4));
 }
 
 void
 __glXDisp_VertexAttrib1svNV(GLbyte * pc)
 {
-    glVertexAttrib1svNV(*(GLuint *) (pc + 0), (const GLshort *) (pc + 4));
+    PFNGLVERTEXATTRIB1SVNVPROC VertexAttrib1svNV =
+        __glGetProcAddress("glVertexAttrib1svNV");
+    VertexAttrib1svNV(*(GLuint *) (pc + 0), (const GLshort *) (pc + 4));
 }
 
 void
 __glXDisp_VertexAttrib2dvNV(GLbyte * pc)
 {
+    PFNGLVERTEXATTRIB2DVNVPROC VertexAttrib2dvNV =
+        __glGetProcAddress("glVertexAttrib2dvNV");
 #ifdef __GLX_ALIGN64
     if ((unsigned long) (pc) & 7) {
         (void) memmove(pc - 4, pc, 20);
@@ -4668,24 +4838,30 @@ __glXDisp_VertexAttrib2dvNV(GLbyte * pc)
     }
 #endif
 
-    glVertexAttrib2dvNV(*(GLuint *) (pc + 0), (const GLdouble *) (pc + 4));
+    VertexAttrib2dvNV(*(GLuint *) (pc + 0), (const GLdouble *) (pc + 4));
 }
 
 void
 __glXDisp_VertexAttrib2fvNV(GLbyte * pc)
 {
-    glVertexAttrib2fvNV(*(GLuint *) (pc + 0), (const GLfloat *) (pc + 4));
+    PFNGLVERTEXATTRIB2FVNVPROC VertexAttrib2fvNV =
+        __glGetProcAddress("glVertexAttrib2fvNV");
+    VertexAttrib2fvNV(*(GLuint *) (pc + 0), (const GLfloat *) (pc + 4));
 }
 
 void
 __glXDisp_VertexAttrib2svNV(GLbyte * pc)
 {
-    glVertexAttrib2svNV(*(GLuint *) (pc + 0), (const GLshort *) (pc + 4));
+    PFNGLVERTEXATTRIB2SVNVPROC VertexAttrib2svNV =
+        __glGetProcAddress("glVertexAttrib2svNV");
+    VertexAttrib2svNV(*(GLuint *) (pc + 0), (const GLshort *) (pc + 4));
 }
 
 void
 __glXDisp_VertexAttrib3dvNV(GLbyte * pc)
 {
+    PFNGLVERTEXATTRIB3DVNVPROC VertexAttrib3dvNV =
+        __glGetProcAddress("glVertexAttrib3dvNV");
 #ifdef __GLX_ALIGN64
     if ((unsigned long) (pc) & 7) {
         (void) memmove(pc - 4, pc, 28);
@@ -4693,24 +4869,30 @@ __glXDisp_VertexAttrib3dvNV(GLbyte * pc)
     }
 #endif
 
-    glVertexAttrib3dvNV(*(GLuint *) (pc + 0), (const GLdouble *) (pc + 4));
+    VertexAttrib3dvNV(*(GLuint *) (pc + 0), (const GLdouble *) (pc + 4));
 }
 
 void
 __glXDisp_VertexAttrib3fvNV(GLbyte * pc)
 {
-    glVertexAttrib3fvNV(*(GLuint *) (pc + 0), (const GLfloat *) (pc + 4));
+    PFNGLVERTEXATTRIB3FVNVPROC VertexAttrib3fvNV =
+        __glGetProcAddress("glVertexAttrib3fvNV");
+    VertexAttrib3fvNV(*(GLuint *) (pc + 0), (const GLfloat *) (pc + 4));
 }
 
 void
 __glXDisp_VertexAttrib3svNV(GLbyte * pc)
 {
-    glVertexAttrib3svNV(*(GLuint *) (pc + 0), (const GLshort *) (pc + 4));
+    PFNGLVERTEXATTRIB3SVNVPROC VertexAttrib3svNV =
+        __glGetProcAddress("glVertexAttrib3svNV");
+    VertexAttrib3svNV(*(GLuint *) (pc + 0), (const GLshort *) (pc + 4));
 }
 
 void
 __glXDisp_VertexAttrib4dvNV(GLbyte * pc)
 {
+    PFNGLVERTEXATTRIB4DVNVPROC VertexAttrib4dvNV =
+        __glGetProcAddress("glVertexAttrib4dvNV");
 #ifdef __GLX_ALIGN64
     if ((unsigned long) (pc) & 7) {
         (void) memmove(pc - 4, pc, 36);
@@ -4718,30 +4900,38 @@ __glXDisp_VertexAttrib4dvNV(GLbyte * pc)
     }
 #endif
 
-    glVertexAttrib4dvNV(*(GLuint *) (pc + 0), (const GLdouble *) (pc + 4));
+    VertexAttrib4dvNV(*(GLuint *) (pc + 0), (const GLdouble *) (pc + 4));
 }
 
 void
 __glXDisp_VertexAttrib4fvNV(GLbyte * pc)
 {
-    glVertexAttrib4fvNV(*(GLuint *) (pc + 0), (const GLfloat *) (pc + 4));
+    PFNGLVERTEXATTRIB4FVNVPROC VertexAttrib4fvNV =
+        __glGetProcAddress("glVertexAttrib4fvNV");
+    VertexAttrib4fvNV(*(GLuint *) (pc + 0), (const GLfloat *) (pc + 4));
 }
 
 void
 __glXDisp_VertexAttrib4svNV(GLbyte * pc)
 {
-    glVertexAttrib4svNV(*(GLuint *) (pc + 0), (const GLshort *) (pc + 4));
+    PFNGLVERTEXATTRIB4SVNVPROC VertexAttrib4svNV =
+        __glGetProcAddress("glVertexAttrib4svNV");
+    VertexAttrib4svNV(*(GLuint *) (pc + 0), (const GLshort *) (pc + 4));
 }
 
 void
 __glXDisp_VertexAttrib4ubvNV(GLbyte * pc)
 {
-    glVertexAttrib4ubvNV(*(GLuint *) (pc + 0), (const GLubyte *) (pc + 4));
+    PFNGLVERTEXATTRIB4UBVNVPROC VertexAttrib4ubvNV =
+        __glGetProcAddress("glVertexAttrib4ubvNV");
+    VertexAttrib4ubvNV(*(GLuint *) (pc + 0), (const GLubyte *) (pc + 4));
 }
 
 void
 __glXDisp_VertexAttribs1dvNV(GLbyte * pc)
 {
+    PFNGLVERTEXATTRIBS1DVNVPROC VertexAttribs1dvNV =
+        __glGetProcAddress("glVertexAttribs1dvNV");
     const GLsizei n = *(GLsizei *) (pc + 4);
 
 #ifdef __GLX_ALIGN64
@@ -4753,28 +4943,34 @@ __glXDisp_VertexAttribs1dvNV(GLbyte * pc)
     }
 #endif
 
-    glVertexAttribs1dvNV(*(GLuint *) (pc + 0), n, (const GLdouble *) (pc + 8));
+    VertexAttribs1dvNV(*(GLuint *) (pc + 0), n, (const GLdouble *) (pc + 8));
 }
 
 void
 __glXDisp_VertexAttribs1fvNV(GLbyte * pc)
 {
+    PFNGLVERTEXATTRIBS1FVNVPROC VertexAttribs1fvNV =
+        __glGetProcAddress("glVertexAttribs1fvNV");
     const GLsizei n = *(GLsizei *) (pc + 4);
 
-    glVertexAttribs1fvNV(*(GLuint *) (pc + 0), n, (const GLfloat *) (pc + 8));
+    VertexAttribs1fvNV(*(GLuint *) (pc + 0), n, (const GLfloat *) (pc + 8));
 }
 
 void
 __glXDisp_VertexAttribs1svNV(GLbyte * pc)
 {
+    PFNGLVERTEXATTRIBS1SVNVPROC VertexAttribs1svNV =
+        __glGetProcAddress("glVertexAttribs1svNV");
     const GLsizei n = *(GLsizei *) (pc + 4);
 
-    glVertexAttribs1svNV(*(GLuint *) (pc + 0), n, (const GLshort *) (pc + 8));
+    VertexAttribs1svNV(*(GLuint *) (pc + 0), n, (const GLshort *) (pc + 8));
 }
 
 void
 __glXDisp_VertexAttribs2dvNV(GLbyte * pc)
 {
+    PFNGLVERTEXATTRIBS2DVNVPROC VertexAttribs2dvNV =
+        __glGetProcAddress("glVertexAttribs2dvNV");
     const GLsizei n = *(GLsizei *) (pc + 4);
 
 #ifdef __GLX_ALIGN64
@@ -4786,28 +4982,34 @@ __glXDisp_VertexAttribs2dvNV(GLbyte * pc)
     }
 #endif
 
-    glVertexAttribs2dvNV(*(GLuint *) (pc + 0), n, (const GLdouble *) (pc + 8));
+    VertexAttribs2dvNV(*(GLuint *) (pc + 0), n, (const GLdouble *) (pc + 8));
 }
 
 void
 __glXDisp_VertexAttribs2fvNV(GLbyte * pc)
 {
+    PFNGLVERTEXATTRIBS2FVNVPROC VertexAttribs2fvNV =
+        __glGetProcAddress("glVertexAttribs2fvNV");
     const GLsizei n = *(GLsizei *) (pc + 4);
 
-    glVertexAttribs2fvNV(*(GLuint *) (pc + 0), n, (const GLfloat *) (pc + 8));
+    VertexAttribs2fvNV(*(GLuint *) (pc + 0), n, (const GLfloat *) (pc + 8));
 }
 
 void
 __glXDisp_VertexAttribs2svNV(GLbyte * pc)
 {
+    PFNGLVERTEXATTRIBS2SVNVPROC VertexAttribs2svNV =
+        __glGetProcAddress("glVertexAttribs2svNV");
     const GLsizei n = *(GLsizei *) (pc + 4);
 
-    glVertexAttribs2svNV(*(GLuint *) (pc + 0), n, (const GLshort *) (pc + 8));
+    VertexAttribs2svNV(*(GLuint *) (pc + 0), n, (const GLshort *) (pc + 8));
 }
 
 void
 __glXDisp_VertexAttribs3dvNV(GLbyte * pc)
 {
+    PFNGLVERTEXATTRIBS3DVNVPROC VertexAttribs3dvNV =
+        __glGetProcAddress("glVertexAttribs3dvNV");
     const GLsizei n = *(GLsizei *) (pc + 4);
 
 #ifdef __GLX_ALIGN64
@@ -4819,28 +5021,34 @@ __glXDisp_VertexAttribs3dvNV(GLbyte * pc)
     }
 #endif
 
-    glVertexAttribs3dvNV(*(GLuint *) (pc + 0), n, (const GLdouble *) (pc + 8));
+    VertexAttribs3dvNV(*(GLuint *) (pc + 0), n, (const GLdouble *) (pc + 8));
 }
 
 void
 __glXDisp_VertexAttribs3fvNV(GLbyte * pc)
 {
+    PFNGLVERTEXATTRIBS3FVNVPROC VertexAttribs3fvNV =
+        __glGetProcAddress("glVertexAttribs3fvNV");
     const GLsizei n = *(GLsizei *) (pc + 4);
 
-    glVertexAttribs3fvNV(*(GLuint *) (pc + 0), n, (const GLfloat *) (pc + 8));
+    VertexAttribs3fvNV(*(GLuint *) (pc + 0), n, (const GLfloat *) (pc + 8));
 }
 
 void
 __glXDisp_VertexAttribs3svNV(GLbyte * pc)
 {
+    PFNGLVERTEXATTRIBS3SVNVPROC VertexAttribs3svNV =
+        __glGetProcAddress("glVertexAttribs3svNV");
     const GLsizei n = *(GLsizei *) (pc + 4);
 
-    glVertexAttribs3svNV(*(GLuint *) (pc + 0), n, (const GLshort *) (pc + 8));
+    VertexAttribs3svNV(*(GLuint *) (pc + 0), n, (const GLshort *) (pc + 8));
 }
 
 void
 __glXDisp_VertexAttribs4dvNV(GLbyte * pc)
 {
+    PFNGLVERTEXATTRIBS4DVNVPROC VertexAttribs4dvNV =
+        __glGetProcAddress("glVertexAttribs4dvNV");
     const GLsizei n = *(GLsizei *) (pc + 4);
 
 #ifdef __GLX_ALIGN64
@@ -4852,35 +5060,43 @@ __glXDisp_VertexAttribs4dvNV(GLbyte * pc)
     }
 #endif
 
-    glVertexAttribs4dvNV(*(GLuint *) (pc + 0), n, (const GLdouble *) (pc + 8));
+    VertexAttribs4dvNV(*(GLuint *) (pc + 0), n, (const GLdouble *) (pc + 8));
 }
 
 void
 __glXDisp_VertexAttribs4fvNV(GLbyte * pc)
 {
+    PFNGLVERTEXATTRIBS4FVNVPROC VertexAttribs4fvNV =
+        __glGetProcAddress("glVertexAttribs4fvNV");
     const GLsizei n = *(GLsizei *) (pc + 4);
 
-    glVertexAttribs4fvNV(*(GLuint *) (pc + 0), n, (const GLfloat *) (pc + 8));
+    VertexAttribs4fvNV(*(GLuint *) (pc + 0), n, (const GLfloat *) (pc + 8));
 }
 
 void
 __glXDisp_VertexAttribs4svNV(GLbyte * pc)
 {
+    PFNGLVERTEXATTRIBS4SVNVPROC VertexAttribs4svNV =
+        __glGetProcAddress("glVertexAttribs4svNV");
     const GLsizei n = *(GLsizei *) (pc + 4);
 
-    glVertexAttribs4svNV(*(GLuint *) (pc + 0), n, (const GLshort *) (pc + 8));
+    VertexAttribs4svNV(*(GLuint *) (pc + 0), n, (const GLshort *) (pc + 8));
 }
 
 void
 __glXDisp_VertexAttribs4ubvNV(GLbyte * pc)
 {
+    PFNGLVERTEXATTRIBS4UBVNVPROC VertexAttribs4ubvNV =
+        __glGetProcAddress("glVertexAttribs4ubvNV");
     const GLsizei n = *(GLsizei *) (pc + 4);
 
-    glVertexAttribs4ubvNV(*(GLuint *) (pc + 0), n, (const GLubyte *) (pc + 8));
+    VertexAttribs4ubvNV(*(GLuint *) (pc + 0), n, (const GLubyte *) (pc + 8));
 }
 
 void
 __glXDisp_ActiveStencilFaceEXT(GLbyte * pc)
 {
-    glActiveStencilFaceEXT(*(GLenum *) (pc + 0));
+    PFNGLACTIVESTENCILFACEEXTPROC ActiveStencilFaceEXT =
+        __glGetProcAddress("glActiveStencilFaceEXT");
+    ActiveStencilFaceEXT(*(GLenum *) (pc + 0));
 }
diff --git a/glx/indirect_dispatch_swap.c b/glx/indirect_dispatch_swap.c
index 9747514..ebb2ec6 100644
--- a/glx/indirect_dispatch_swap.c
+++ b/glx/indirect_dispatch_swap.c
@@ -3983,108 +3983,125 @@ __glXDispSwap_MultiTexCoord4sv(GLbyte * pc)
 void
 __glXDispSwap_CompressedTexImage1D(GLbyte * pc)
 {
+    PFNGLCOMPRESSEDTEXIMAGE1DPROC CompressedTexImage1D =
+        __glGetProcAddress("glCompressedTexImage1D");
     const GLsizei imageSize = (GLsizei) bswap_CARD32(pc + 20);
 
-    glCompressedTexImage1D((GLenum) bswap_ENUM(pc + 0),
-                           (GLint) bswap_CARD32(pc + 4),
-                           (GLenum) bswap_ENUM(pc + 8),
-                           (GLsizei) bswap_CARD32(pc + 12),
-                           (GLint) bswap_CARD32(pc + 16),
-                           imageSize, (const GLvoid *) (pc + 24));
+    CompressedTexImage1D((GLenum) bswap_ENUM(pc + 0),
+                         (GLint) bswap_CARD32(pc + 4),
+                         (GLenum) bswap_ENUM(pc + 8),
+                         (GLsizei) bswap_CARD32(pc + 12),
+                         (GLint) bswap_CARD32(pc + 16),
+                         imageSize, (const GLvoid *) (pc + 24));
 }
 
 void
 __glXDispSwap_CompressedTexImage2D(GLbyte * pc)
 {
+    PFNGLCOMPRESSEDTEXIMAGE2DPROC CompressedTexImage2D =
+        __glGetProcAddress("glCompressedTexImage2D");
     const GLsizei imageSize = (GLsizei) bswap_CARD32(pc + 24);
 
-    glCompressedTexImage2D((GLenum) bswap_ENUM(pc + 0),
-                           (GLint) bswap_CARD32(pc + 4),
-                           (GLenum) bswap_ENUM(pc + 8),
-                           (GLsizei) bswap_CARD32(pc + 12),
-                           (GLsizei) bswap_CARD32(pc + 16),
-                           (GLint) bswap_CARD32(pc + 20),
-                           imageSize, (const GLvoid *) (pc + 28));
+    CompressedTexImage2D((GLenum) bswap_ENUM(pc + 0),
+                         (GLint) bswap_CARD32(pc + 4),
+                         (GLenum) bswap_ENUM(pc + 8),
+                         (GLsizei) bswap_CARD32(pc + 12),
+                         (GLsizei) bswap_CARD32(pc + 16),
+                         (GLint) bswap_CARD32(pc + 20),
+                         imageSize, (const GLvoid *) (pc + 28));
 }
 
 void
 __glXDispSwap_CompressedTexImage3D(GLbyte * pc)
 {
+    PFNGLCOMPRESSEDTEXIMAGE3DPROC CompressedTexImage3D =
+        __glGetProcAddress("glCompressedTexImage3D");
     const GLsizei imageSize = (GLsizei) bswap_CARD32(pc + 28);
 
-    glCompressedTexImage3D((GLenum) bswap_ENUM(pc + 0),
-                           (GLint) bswap_CARD32(pc + 4),
-                           (GLenum) bswap_ENUM(pc + 8),
-                           (GLsizei) bswap_CARD32(pc + 12),
-                           (GLsizei) bswap_CARD32(pc + 16),
-                           (GLsizei) bswap_CARD32(pc + 20),
-                           (GLint) bswap_CARD32(pc + 24),
-                           imageSize, (const GLvoid *) (pc + 32));
+    CompressedTexImage3D((GLenum) bswap_ENUM(pc + 0),
+                         (GLint) bswap_CARD32(pc + 4),
+                         (GLenum) bswap_ENUM(pc + 8),
+                         (GLsizei) bswap_CARD32(pc + 12),
+                         (GLsizei) bswap_CARD32(pc + 16),
+                         (GLsizei) bswap_CARD32(pc + 20),
+                         (GLint) bswap_CARD32(pc + 24),
+                         imageSize, (const GLvoid *) (pc + 32));
 }
 
 void
 __glXDispSwap_CompressedTexSubImage1D(GLbyte * pc)
 {
+    PFNGLCOMPRESSEDTEXSUBIMAGE1DPROC CompressedTexSubImage1D =
+        __glGetProcAddress("glCompressedTexSubImage1D");
     const GLsizei imageSize = (GLsizei) bswap_CARD32(pc + 20);
 
-    glCompressedTexSubImage1D((GLenum) bswap_ENUM(pc + 0),
-                              (GLint) bswap_CARD32(pc + 4),
-                              (GLint) bswap_CARD32(pc + 8),
-                              (GLsizei) bswap_CARD32(pc + 12),
-                              (GLenum) bswap_ENUM(pc + 16),
-                              imageSize, (const GLvoid *) (pc + 24));
+    CompressedTexSubImage1D((GLenum) bswap_ENUM(pc + 0),
+                            (GLint) bswap_CARD32(pc + 4),
+                            (GLint) bswap_CARD32(pc + 8),
+                            (GLsizei) bswap_CARD32(pc + 12),
+                            (GLenum) bswap_ENUM(pc + 16),
+                            imageSize, (const GLvoid *) (pc + 24));
 }
 
 void
 __glXDispSwap_CompressedTexSubImage2D(GLbyte * pc)
 {
+    PFNGLCOMPRESSEDTEXSUBIMAGE2DPROC CompressedTexSubImage2D =
+        __glGetProcAddress("glCompressedTexSubImage2D");
     const GLsizei imageSize = (GLsizei) bswap_CARD32(pc + 28);
 
-    glCompressedTexSubImage2D((GLenum) bswap_ENUM(pc + 0),
-                              (GLint) bswap_CARD32(pc + 4),
-                              (GLint) bswap_CARD32(pc + 8),
-                              (GLint) bswap_CARD32(pc + 12),
-                              (GLsizei) bswap_CARD32(pc + 16),
-                              (GLsizei) bswap_CARD32(pc + 20),
-                              (GLenum) bswap_ENUM(pc + 24),
-                              imageSize, (const GLvoid *) (pc + 32));
+    CompressedTexSubImage2D((GLenum) bswap_ENUM(pc + 0),
+                            (GLint) bswap_CARD32(pc + 4),
+                            (GLint) bswap_CARD32(pc + 8),
+                            (GLint) bswap_CARD32(pc + 12),
+                            (GLsizei) bswap_CARD32(pc + 16),
+                            (GLsizei) bswap_CARD32(pc + 20),
+                            (GLenum) bswap_ENUM(pc + 24),
+                            imageSize, (const GLvoid *) (pc + 32));
 }
 
 void
 __glXDispSwap_CompressedTexSubImage3D(GLbyte * pc)
 {
+    PFNGLCOMPRESSEDTEXSUBIMAGE3DPROC CompressedTexSubImage3D =
+        __glGetProcAddress("glCompressedTexSubImage3D");
     const GLsizei imageSize = (GLsizei) bswap_CARD32(pc + 36);
 
-    glCompressedTexSubImage3D((GLenum) bswap_ENUM(pc + 0),
-                              (GLint) bswap_CARD32(pc + 4),
-                              (GLint) bswap_CARD32(pc + 8),
-                              (GLint) bswap_CARD32(pc + 12),
-                              (GLint) bswap_CARD32(pc + 16),
-                              (GLsizei) bswap_CARD32(pc + 20),
-                              (GLsizei) bswap_CARD32(pc + 24),
-                              (GLsizei) bswap_CARD32(pc + 28),
-                              (GLenum) bswap_ENUM(pc + 32),
-                              imageSize, (const GLvoid *) (pc + 40));
+    CompressedTexSubImage3D((GLenum) bswap_ENUM(pc + 0),
+                            (GLint) bswap_CARD32(pc + 4),
+                            (GLint) bswap_CARD32(pc + 8),
+                            (GLint) bswap_CARD32(pc + 12),
+                            (GLint) bswap_CARD32(pc + 16),
+                            (GLsizei) bswap_CARD32(pc + 20),
+                            (GLsizei) bswap_CARD32(pc + 24),
+                            (GLsizei) bswap_CARD32(pc + 28),
+                            (GLenum) bswap_ENUM(pc + 32),
+                            imageSize, (const GLvoid *) (pc + 40));
 }
 
 void
 __glXDispSwap_SampleCoverage(GLbyte * pc)
 {
-    glSampleCoverage((GLclampf) bswap_FLOAT32(pc + 0), *(GLboolean *) (pc + 4));
+    PFNGLSAMPLECOVERAGEPROC SampleCoverage =
+        __glGetProcAddress("glSampleCoverage");
+    SampleCoverage((GLclampf) bswap_FLOAT32(pc + 0), *(GLboolean *) (pc + 4));
 }
 
 void
 __glXDispSwap_BlendFuncSeparate(GLbyte * pc)
 {
-    glBlendFuncSeparate((GLenum) bswap_ENUM(pc + 0),
-                        (GLenum) bswap_ENUM(pc + 4),
-                        (GLenum) bswap_ENUM(pc + 8),
-                        (GLenum) bswap_ENUM(pc + 12));
+    PFNGLBLENDFUNCSEPARATEPROC BlendFuncSeparate =
+        __glGetProcAddress("glBlendFuncSeparate");
+    BlendFuncSeparate((GLenum) bswap_ENUM(pc + 0), (GLenum) bswap_ENUM(pc + 4),
+                      (GLenum) bswap_ENUM(pc + 8),
+                      (GLenum) bswap_ENUM(pc + 12));
 }
 
 void
 __glXDispSwap_FogCoorddv(GLbyte * pc)
 {
+    PFNGLFOGCOORDDVPROC FogCoorddv = __glGetProcAddress("glFogCoorddv");
+
 #ifdef __GLX_ALIGN64
     if ((unsigned long) (pc) & 7) {
         (void) memmove(pc - 4, pc, 8);
@@ -4092,19 +4109,23 @@ __glXDispSwap_FogCoorddv(GLbyte * pc)
     }
 #endif
 
-    glFogCoorddv((const GLdouble *) bswap_64_array((uint64_t *) (pc + 0), 1));
+    FogCoorddv((const GLdouble *) bswap_64_array((uint64_t *) (pc + 0), 1));
 }
 
 void
 __glXDispSwap_PointParameterf(GLbyte * pc)
 {
-    glPointParameterf((GLenum) bswap_ENUM(pc + 0),
-                      (GLfloat) bswap_FLOAT32(pc + 4));
+    PFNGLPOINTPARAMETERFPROC PointParameterf =
+        __glGetProcAddress("glPointParameterf");
+    PointParameterf((GLenum) bswap_ENUM(pc + 0),
+                    (GLfloat) bswap_FLOAT32(pc + 4));
 }
 
 void
 __glXDispSwap_PointParameterfv(GLbyte * pc)
 {
+    PFNGLPOINTPARAMETERFVPROC PointParameterfv =
+        __glGetProcAddress("glPointParameterfv");
     const GLenum pname = (GLenum) bswap_ENUM(pc + 0);
     const GLfloat *params;
 
@@ -4112,19 +4133,22 @@ __glXDispSwap_PointParameterfv(GLbyte * pc)
         (const GLfloat *) bswap_32_array((uint32_t *) (pc + 4),
                                          __glPointParameterfv_size(pname));
 
-    glPointParameterfv(pname, params);
+    PointParameterfv(pname, params);
 }
 
 void
 __glXDispSwap_PointParameteri(GLbyte * pc)
 {
-    glPointParameteri((GLenum) bswap_ENUM(pc + 0),
-                      (GLint) bswap_CARD32(pc + 4));
+    PFNGLPOINTPARAMETERIPROC PointParameteri =
+        __glGetProcAddress("glPointParameteri");
+    PointParameteri((GLenum) bswap_ENUM(pc + 0), (GLint) bswap_CARD32(pc + 4));
 }
 
 void
 __glXDispSwap_PointParameteriv(GLbyte * pc)
 {
+    PFNGLPOINTPARAMETERIVPROC PointParameteriv =
+        __glGetProcAddress("glPointParameteriv");
     const GLenum pname = (GLenum) bswap_ENUM(pc + 0);
     const GLint *params;
 
@@ -4132,18 +4156,22 @@ __glXDispSwap_PointParameteriv(GLbyte * pc)
         (const GLint *) bswap_32_array((uint32_t *) (pc + 4),
                                        __glPointParameteriv_size(pname));
 
-    glPointParameteriv(pname, params);
+    PointParameteriv(pname, params);
 }
 
 void
 __glXDispSwap_SecondaryColor3bv(GLbyte * pc)
 {
-    glSecondaryColor3bv((const GLbyte *) (pc + 0));
+    PFNGLSECONDARYCOLOR3BVPROC SecondaryColor3bv =
+        __glGetProcAddress("glSecondaryColor3bv");
+    SecondaryColor3bv((const GLbyte *) (pc + 0));
 }
 
 void
 __glXDispSwap_SecondaryColor3dv(GLbyte * pc)
 {
+    PFNGLSECONDARYCOLOR3DVPROC SecondaryColor3dv =
+        __glGetProcAddress("glSecondaryColor3dv");
 #ifdef __GLX_ALIGN64
     if ((unsigned long) (pc) & 7) {
         (void) memmove(pc - 4, pc, 24);
@@ -4151,59 +4179,74 @@ __glXDispSwap_SecondaryColor3dv(GLbyte * pc)
     }
 #endif
 
-    glSecondaryColor3dv((const GLdouble *)
-                        bswap_64_array((uint64_t *) (pc + 0), 3));
+    SecondaryColor3dv((const GLdouble *)
+                      bswap_64_array((uint64_t *) (pc + 0), 3));
 }
 
 void
 __glXDispSwap_SecondaryColor3iv(GLbyte * pc)
 {
-    glSecondaryColor3iv((const GLint *)
-                        bswap_32_array((uint32_t *) (pc + 0), 3));
+    PFNGLSECONDARYCOLOR3IVPROC SecondaryColor3iv =
+        __glGetProcAddress("glSecondaryColor3iv");
+    SecondaryColor3iv((const GLint *) bswap_32_array((uint32_t *) (pc + 0), 3));
 }
 
 void
 __glXDispSwap_SecondaryColor3sv(GLbyte * pc)
 {
-    glSecondaryColor3sv((const GLshort *)
-                        bswap_16_array((uint16_t *) (pc + 0), 3));
+    PFNGLSECONDARYCOLOR3SVPROC SecondaryColor3sv =
+        __glGetProcAddress("glSecondaryColor3sv");
+    SecondaryColor3sv((const GLshort *)
+                      bswap_16_array((uint16_t *) (pc + 0), 3));
 }
 
 void
 __glXDispSwap_SecondaryColor3ubv(GLbyte * pc)
 {
-    glSecondaryColor3ubv((const GLubyte *) (pc + 0));
+    PFNGLSECONDARYCOLOR3UBVPROC SecondaryColor3ubv =
+        __glGetProcAddress("glSecondaryColor3ubv");
+    SecondaryColor3ubv((const GLubyte *) (pc + 0));
 }
 
 void
 __glXDispSwap_SecondaryColor3uiv(GLbyte * pc)
 {
-    glSecondaryColor3uiv((const GLuint *)
-                         bswap_32_array((uint32_t *) (pc + 0), 3));
+    PFNGLSECONDARYCOLOR3UIVPROC SecondaryColor3uiv =
+        __glGetProcAddress("glSecondaryColor3uiv");
+    SecondaryColor3uiv((const GLuint *)
+                       bswap_32_array((uint32_t *) (pc + 0), 3));
 }
 
 void
 __glXDispSwap_SecondaryColor3usv(GLbyte * pc)
 {
-    glSecondaryColor3usv((const GLushort *)
-                         bswap_16_array((uint16_t *) (pc + 0), 3));
+    PFNGLSECONDARYCOLOR3USVPROC SecondaryColor3usv =
+        __glGetProcAddress("glSecondaryColor3usv");
+    SecondaryColor3usv((const GLushort *)
+                       bswap_16_array((uint16_t *) (pc + 0), 3));
 }
 
 void
 __glXDispSwap_WindowPos3fv(GLbyte * pc)
 {
-    glWindowPos3fv((const GLfloat *) bswap_32_array((uint32_t *) (pc + 0), 3));
+    PFNGLWINDOWPOS3FVPROC WindowPos3fv = __glGetProcAddress("glWindowPos3fv");
+
+    WindowPos3fv((const GLfloat *) bswap_32_array((uint32_t *) (pc + 0), 3));
 }
 
 void
 __glXDispSwap_BeginQuery(GLbyte * pc)
 {
-    glBeginQuery((GLenum) bswap_ENUM(pc + 0), (GLuint) bswap_CARD32(pc + 4));
+    PFNGLBEGINQUERYPROC BeginQuery = __glGetProcAddress("glBeginQuery");
+
+    BeginQuery((GLenum) bswap_ENUM(pc + 0), (GLuint) bswap_CARD32(pc + 4));
 }
 
 int
 __glXDispSwap_DeleteQueries(__GLXclientState * cl, GLbyte * pc)
 {
+    PFNGLDELETEQUERIESPROC DeleteQueries =
+        __glGetProcAddress("glDeleteQueries");
     xGLXSingleReq *const req = (xGLXSingleReq *) pc;
     int error;
     __GLXcontext *const cx =
@@ -4213,9 +4256,9 @@ __glXDispSwap_DeleteQueries(__GLXclientState * cl, GLbyte * pc)
     if (cx != NULL) {
         const GLsizei n = (GLsizei) bswap_CARD32(pc + 0);
 
-        glDeleteQueries(n,
-                        (const GLuint *) bswap_32_array((uint32_t *) (pc + 4),
-                                                        0));
+        DeleteQueries(n,
+                      (const GLuint *) bswap_32_array((uint32_t *) (pc + 4),
+                                                      0));
         error = Success;
     }
 
@@ -4225,12 +4268,15 @@ __glXDispSwap_DeleteQueries(__GLXclientState * cl, GLbyte * pc)
 void
 __glXDispSwap_EndQuery(GLbyte * pc)
 {
-    glEndQuery((GLenum) bswap_ENUM(pc + 0));
+    PFNGLENDQUERYPROC EndQuery = __glGetProcAddress("glEndQuery");
+
+    EndQuery((GLenum) bswap_ENUM(pc + 0));
 }
 
 int
 __glXDispSwap_GenQueries(__GLXclientState * cl, GLbyte * pc)
 {
+    PFNGLGENQUERIESPROC GenQueries = __glGetProcAddress("glGenQueries");
     xGLXSingleReq *const req = (xGLXSingleReq *) pc;
     int error;
     __GLXcontext *const cx =
@@ -4244,7 +4290,7 @@ __glXDispSwap_GenQueries(__GLXclientState * cl, GLbyte * pc)
         GLuint *ids =
             __glXGetAnswerBuffer(cl, n * 4, answerBuffer, sizeof(answerBuffer),
                                  4);
-        glGenQueries(n, ids);
+        GenQueries(n, ids);
         (void) bswap_32_array((uint32_t *) ids, n);
         __glXSendReplySwap(cl->client, ids, n, 4, GL_TRUE, 0);
         error = Success;
@@ -4256,6 +4302,8 @@ __glXDispSwap_GenQueries(__GLXclientState * cl, GLbyte * pc)
 int
 __glXDispSwap_GetQueryObjectiv(__GLXclientState * cl, GLbyte * pc)
 {
+    PFNGLGETQUERYOBJECTIVPROC GetQueryObjectiv =
+        __glGetProcAddress("glGetQueryObjectiv");
     xGLXSingleReq *const req = (xGLXSingleReq *) pc;
     int error;
     __GLXcontext *const cx =
@@ -4275,7 +4323,7 @@ __glXDispSwap_GetQueryObjectiv(__GLXclientState * cl, GLbyte * pc)
             return BadAlloc;
         __glXClearErrorOccured();
 
-        glGetQueryObjectiv((GLuint) bswap_CARD32(pc + 0), pname, params);
+        GetQueryObjectiv((GLuint) bswap_CARD32(pc + 0), pname, params);
         (void) bswap_32_array((uint32_t *) params, compsize);
         __glXSendReplySwap(cl->client, params, compsize, 4, GL_FALSE, 0);
         error = Success;
@@ -4287,6 +4335,8 @@ __glXDispSwap_GetQueryObjectiv(__GLXclientState * cl, GLbyte * pc)
 int
 __glXDispSwap_GetQueryObjectuiv(__GLXclientState * cl, GLbyte * pc)
 {
+    PFNGLGETQUERYOBJECTUIVPROC GetQueryObjectuiv =
+        __glGetProcAddress("glGetQueryObjectuiv");
     xGLXSingleReq *const req = (xGLXSingleReq *) pc;
     int error;
     __GLXcontext *const cx =
@@ -4306,7 +4356,7 @@ __glXDispSwap_GetQueryObjectuiv(__GLXclientState * cl, GLbyte * pc)
             return BadAlloc;
         __glXClearErrorOccured();
 
-        glGetQueryObjectuiv((GLuint) bswap_CARD32(pc + 0), pname, params);
+        GetQueryObjectuiv((GLuint) bswap_CARD32(pc + 0), pname, params);
         (void) bswap_32_array((uint32_t *) params, compsize);
         __glXSendReplySwap(cl->client, params, compsize, 4, GL_FALSE, 0);
         error = Success;
@@ -4318,6 +4368,7 @@ __glXDispSwap_GetQueryObjectuiv(__GLXclientState * cl, GLbyte * pc)
 int
 __glXDispSwap_GetQueryiv(__GLXclientState * cl, GLbyte * pc)
 {
+    PFNGLGETQUERYIVPROC GetQueryiv = __glGetProcAddress("glGetQueryiv");
     xGLXSingleReq *const req = (xGLXSingleReq *) pc;
     int error;
     __GLXcontext *const cx =
@@ -4337,7 +4388,7 @@ __glXDispSwap_GetQueryiv(__GLXclientState * cl, GLbyte * pc)
             return BadAlloc;
         __glXClearErrorOccured();
 
-        glGetQueryiv((GLenum) bswap_ENUM(pc + 0), pname, params);
+        GetQueryiv((GLenum) bswap_ENUM(pc + 0), pname, params);
         (void) bswap_32_array((uint32_t *) params, compsize);
         __glXSendReplySwap(cl->client, params, compsize, 4, GL_FALSE, 0);
         error = Success;
@@ -4349,6 +4400,7 @@ __glXDispSwap_GetQueryiv(__GLXclientState * cl, GLbyte * pc)
 int
 __glXDispSwap_IsQuery(__GLXclientState * cl, GLbyte * pc)
 {
+    PFNGLISQUERYPROC IsQuery = __glGetProcAddress("glIsQuery");
     xGLXSingleReq *const req = (xGLXSingleReq *) pc;
     int error;
     __GLXcontext *const cx =
@@ -4358,7 +4410,7 @@ __glXDispSwap_IsQuery(__GLXclientState * cl, GLbyte * pc)
     if (cx != NULL) {
         GLboolean retval;
 
-        retval = glIsQuery((GLuint) bswap_CARD32(pc + 0));
+        retval = IsQuery((GLuint) bswap_CARD32(pc + 0));
         __glXSendReplySwap(cl->client, dummy_answer, 0, 0, GL_FALSE, retval);
         error = Success;
     }
@@ -4369,21 +4421,26 @@ __glXDispSwap_IsQuery(__GLXclientState * cl, GLbyte * pc)
 void
 __glXDispSwap_BlendEquationSeparate(GLbyte * pc)
 {
-    glBlendEquationSeparate((GLenum) bswap_ENUM(pc + 0),
-                            (GLenum) bswap_ENUM(pc + 4));
+    PFNGLBLENDEQUATIONSEPARATEPROC BlendEquationSeparate =
+        __glGetProcAddress("glBlendEquationSeparate");
+    BlendEquationSeparate((GLenum) bswap_ENUM(pc + 0),
+                          (GLenum) bswap_ENUM(pc + 4));
 }
 
 void
 __glXDispSwap_DrawBuffers(GLbyte * pc)
 {
+    PFNGLDRAWBUFFERSPROC DrawBuffers = __glGetProcAddress("glDrawBuffers");
     const GLsizei n = (GLsizei) bswap_CARD32(pc + 0);
 
-    glDrawBuffers(n, (const GLenum *) bswap_32_array((uint32_t *) (pc + 4), 0));
+    DrawBuffers(n, (const GLenum *) bswap_32_array((uint32_t *) (pc + 4), 0));
 }
 
 void
 __glXDispSwap_VertexAttrib1dv(GLbyte * pc)
 {
+    PFNGLVERTEXATTRIB1DVPROC VertexAttrib1dv =
+        __glGetProcAddress("glVertexAttrib1dv");
 #ifdef __GLX_ALIGN64
     if ((unsigned long) (pc) & 7) {
         (void) memmove(pc - 4, pc, 12);
@@ -4391,22 +4448,25 @@ __glXDispSwap_VertexAttrib1dv(GLbyte * pc)
     }
 #endif
 
-    glVertexAttrib1dv((GLuint) bswap_CARD32(pc + 0),
-                      (const GLdouble *) bswap_64_array((uint64_t *) (pc + 4),
-                                                        1));
+    VertexAttrib1dv((GLuint) bswap_CARD32(pc + 0),
+                    (const GLdouble *) bswap_64_array((uint64_t *) (pc + 4),
+                                                      1));
 }
 
 void
 __glXDispSwap_VertexAttrib1sv(GLbyte * pc)
 {
-    glVertexAttrib1sv((GLuint) bswap_CARD32(pc + 0),
-                      (const GLshort *) bswap_16_array((uint16_t *) (pc + 4),
-                                                       1));
+    PFNGLVERTEXATTRIB1SVPROC VertexAttrib1sv =
+        __glGetProcAddress("glVertexAttrib1sv");
+    VertexAttrib1sv((GLuint) bswap_CARD32(pc + 0),
+                    (const GLshort *) bswap_16_array((uint16_t *) (pc + 4), 1));
 }
 
 void
 __glXDispSwap_VertexAttrib2dv(GLbyte * pc)
 {
+    PFNGLVERTEXATTRIB2DVPROC VertexAttrib2dv =
+        __glGetProcAddress("glVertexAttrib2dv");
 #ifdef __GLX_ALIGN64
     if ((unsigned long) (pc) & 7) {
         (void) memmove(pc - 4, pc, 20);
@@ -4414,22 +4474,25 @@ __glXDispSwap_VertexAttrib2dv(GLbyte * pc)
     }
 #endif
 
-    glVertexAttrib2dv((GLuint) bswap_CARD32(pc + 0),
-                      (const GLdouble *) bswap_64_array((uint64_t *) (pc + 4),
-                                                        2));
+    VertexAttrib2dv((GLuint) bswap_CARD32(pc + 0),
+                    (const GLdouble *) bswap_64_array((uint64_t *) (pc + 4),
+                                                      2));
 }
 
 void
 __glXDispSwap_VertexAttrib2sv(GLbyte * pc)
 {
-    glVertexAttrib2sv((GLuint) bswap_CARD32(pc + 0),
-                      (const GLshort *) bswap_16_array((uint16_t *) (pc + 4),
-                                                       2));
+    PFNGLVERTEXATTRIB2SVPROC VertexAttrib2sv =
+        __glGetProcAddress("glVertexAttrib2sv");
+    VertexAttrib2sv((GLuint) bswap_CARD32(pc + 0),
+                    (const GLshort *) bswap_16_array((uint16_t *) (pc + 4), 2));
 }
 
 void
 __glXDispSwap_VertexAttrib3dv(GLbyte * pc)
 {
+    PFNGLVERTEXATTRIB3DVPROC VertexAttrib3dv =
+        __glGetProcAddress("glVertexAttrib3dv");
 #ifdef __GLX_ALIGN64
     if ((unsigned long) (pc) & 7) {
         (void) memmove(pc - 4, pc, 28);
@@ -4437,74 +4500,89 @@ __glXDispSwap_VertexAttrib3dv(GLbyte * pc)
     }
 #endif
 
-    glVertexAttrib3dv((GLuint) bswap_CARD32(pc + 0),
-                      (const GLdouble *) bswap_64_array((uint64_t *) (pc + 4),
-                                                        3));
+    VertexAttrib3dv((GLuint) bswap_CARD32(pc + 0),
+                    (const GLdouble *) bswap_64_array((uint64_t *) (pc + 4),
+                                                      3));
 }
 
 void
 __glXDispSwap_VertexAttrib3sv(GLbyte * pc)
 {
-    glVertexAttrib3sv((GLuint) bswap_CARD32(pc + 0),
-                      (const GLshort *) bswap_16_array((uint16_t *) (pc + 4),
-                                                       3));
+    PFNGLVERTEXATTRIB3SVPROC VertexAttrib3sv =
+        __glGetProcAddress("glVertexAttrib3sv");
+    VertexAttrib3sv((GLuint) bswap_CARD32(pc + 0),
+                    (const GLshort *) bswap_16_array((uint16_t *) (pc + 4), 3));
 }
 
 void
 __glXDispSwap_VertexAttrib4Nbv(GLbyte * pc)
 {
-    glVertexAttrib4Nbv((GLuint) bswap_CARD32(pc + 0),
-                       (const GLbyte *) (pc + 4));
+    PFNGLVERTEXATTRIB4NBVPROC VertexAttrib4Nbv =
+        __glGetProcAddress("glVertexAttrib4Nbv");
+    VertexAttrib4Nbv((GLuint) bswap_CARD32(pc + 0), (const GLbyte *) (pc + 4));
 }
 
 void
 __glXDispSwap_VertexAttrib4Niv(GLbyte * pc)
 {
-    glVertexAttrib4Niv((GLuint) bswap_CARD32(pc + 0),
-                       (const GLint *) bswap_32_array((uint32_t *) (pc + 4),
-                                                      4));
+    PFNGLVERTEXATTRIB4NIVPROC VertexAttrib4Niv =
+        __glGetProcAddress("glVertexAttrib4Niv");
+    VertexAttrib4Niv((GLuint) bswap_CARD32(pc + 0),
+                     (const GLint *) bswap_32_array((uint32_t *) (pc + 4), 4));
 }
 
 void
 __glXDispSwap_VertexAttrib4Nsv(GLbyte * pc)
 {
-    glVertexAttrib4Nsv((GLuint) bswap_CARD32(pc + 0),
-                       (const GLshort *) bswap_16_array((uint16_t *) (pc + 4),
-                                                        4));
+    PFNGLVERTEXATTRIB4NSVPROC VertexAttrib4Nsv =
+        __glGetProcAddress("glVertexAttrib4Nsv");
+    VertexAttrib4Nsv((GLuint) bswap_CARD32(pc + 0),
+                     (const GLshort *) bswap_16_array((uint16_t *) (pc + 4),
+                                                      4));
 }
 
 void
 __glXDispSwap_VertexAttrib4Nubv(GLbyte * pc)
 {
-    glVertexAttrib4Nubv((GLuint) bswap_CARD32(pc + 0),
-                        (const GLubyte *) (pc + 4));
+    PFNGLVERTEXATTRIB4NUBVPROC VertexAttrib4Nubv =
+        __glGetProcAddress("glVertexAttrib4Nubv");
+    VertexAttrib4Nubv((GLuint) bswap_CARD32(pc + 0),
+                      (const GLubyte *) (pc + 4));
 }
 
 void
 __glXDispSwap_VertexAttrib4Nuiv(GLbyte * pc)
 {
-    glVertexAttrib4Nuiv((GLuint) bswap_CARD32(pc + 0),
-                        (const GLuint *) bswap_32_array((uint32_t *) (pc + 4),
-                                                        4));
+    PFNGLVERTEXATTRIB4NUIVPROC VertexAttrib4Nuiv =
+        __glGetProcAddress("glVertexAttrib4Nuiv");
+    VertexAttrib4Nuiv((GLuint) bswap_CARD32(pc + 0),
+                      (const GLuint *) bswap_32_array((uint32_t *) (pc + 4),
+                                                      4));
 }
 
 void
 __glXDispSwap_VertexAttrib4Nusv(GLbyte * pc)
 {
-    glVertexAttrib4Nusv((GLuint) bswap_CARD32(pc + 0),
-                        (const GLushort *) bswap_16_array((uint16_t *) (pc + 4),
-                                                          4));
+    PFNGLVERTEXATTRIB4NUSVPROC VertexAttrib4Nusv =
+        __glGetProcAddress("glVertexAttrib4Nusv");
+    VertexAttrib4Nusv((GLuint) bswap_CARD32(pc + 0),
+                      (const GLushort *) bswap_16_array((uint16_t *) (pc + 4),
+                                                        4));
 }
 
 void
 __glXDispSwap_VertexAttrib4bv(GLbyte * pc)
 {
-    glVertexAttrib4bv((GLuint) bswap_CARD32(pc + 0), (const GLbyte *) (pc + 4));
+    PFNGLVERTEXATTRIB4BVPROC VertexAttrib4bv =
+        __glGetProcAddress("glVertexAttrib4bv");
+    VertexAttrib4bv((GLuint) bswap_CARD32(pc + 0), (const GLbyte *) (pc + 4));
 }
 
 void
 __glXDispSwap_VertexAttrib4dv(GLbyte * pc)
 {
+    PFNGLVERTEXATTRIB4DVPROC VertexAttrib4dv =
+        __glGetProcAddress("glVertexAttrib4dv");
 #ifdef __GLX_ALIGN64
     if ((unsigned long) (pc) & 7) {
         (void) memmove(pc - 4, pc, 36);
@@ -4512,65 +4590,77 @@ __glXDispSwap_VertexAttrib4dv(GLbyte * pc)
     }
 #endif
 
-    glVertexAttrib4dv((GLuint) bswap_CARD32(pc + 0),
-                      (const GLdouble *) bswap_64_array((uint64_t *) (pc + 4),
-                                                        4));
+    VertexAttrib4dv((GLuint) bswap_CARD32(pc + 0),
+                    (const GLdouble *) bswap_64_array((uint64_t *) (pc + 4),
+                                                      4));
 }
 
 void
 __glXDispSwap_VertexAttrib4iv(GLbyte * pc)
 {
-    glVertexAttrib4iv((GLuint) bswap_CARD32(pc + 0),
-                      (const GLint *) bswap_32_array((uint32_t *) (pc + 4), 4));
+    PFNGLVERTEXATTRIB4IVPROC VertexAttrib4iv =
+        __glGetProcAddress("glVertexAttrib4iv");
+    VertexAttrib4iv((GLuint) bswap_CARD32(pc + 0),
+                    (const GLint *) bswap_32_array((uint32_t *) (pc + 4), 4));
 }
 
 void
 __glXDispSwap_VertexAttrib4sv(GLbyte * pc)
 {
-    glVertexAttrib4sv((GLuint) bswap_CARD32(pc + 0),
-                      (const GLshort *) bswap_16_array((uint16_t *) (pc + 4),
-                                                       4));
+    PFNGLVERTEXATTRIB4SVPROC VertexAttrib4sv =
+        __glGetProcAddress("glVertexAttrib4sv");
+    VertexAttrib4sv((GLuint) bswap_CARD32(pc + 0),
+                    (const GLshort *) bswap_16_array((uint16_t *) (pc + 4), 4));
 }
 
 void
 __glXDispSwap_VertexAttrib4ubv(GLbyte * pc)
 {
-    glVertexAttrib4ubv((GLuint) bswap_CARD32(pc + 0),
-                       (const GLubyte *) (pc + 4));
+    PFNGLVERTEXATTRIB4UBVPROC VertexAttrib4ubv =
+        __glGetProcAddress("glVertexAttrib4ubv");
+    VertexAttrib4ubv((GLuint) bswap_CARD32(pc + 0), (const GLubyte *) (pc + 4));
 }
 
 void
 __glXDispSwap_VertexAttrib4uiv(GLbyte * pc)
 {
-    glVertexAttrib4uiv((GLuint) bswap_CARD32(pc + 0),
-                       (const GLuint *) bswap_32_array((uint32_t *) (pc + 4),
-                                                       4));
+    PFNGLVERTEXATTRIB4UIVPROC VertexAttrib4uiv =
+        __glGetProcAddress("glVertexAttrib4uiv");
+    VertexAttrib4uiv((GLuint) bswap_CARD32(pc + 0),
+                     (const GLuint *) bswap_32_array((uint32_t *) (pc + 4), 4));
 }
 
 void
 __glXDispSwap_VertexAttrib4usv(GLbyte * pc)
 {
-    glVertexAttrib4usv((GLuint) bswap_CARD32(pc + 0),
-                       (const GLushort *) bswap_16_array((uint16_t *) (pc + 4),
-                                                         4));
+    PFNGLVERTEXATTRIB4USVPROC VertexAttrib4usv =
+        __glGetProcAddress("glVertexAttrib4usv");
+    VertexAttrib4usv((GLuint) bswap_CARD32(pc + 0),
+                     (const GLushort *) bswap_16_array((uint16_t *) (pc + 4),
+                                                       4));
 }
 
 void
 __glXDispSwap_ClampColor(GLbyte * pc)
 {
-    glClampColor((GLenum) bswap_ENUM(pc + 0), (GLenum) bswap_ENUM(pc + 4));
+    PFNGLCLAMPCOLORPROC ClampColor = __glGetProcAddress("glClampColor");
+
+    ClampColor((GLenum) bswap_ENUM(pc + 0), (GLenum) bswap_ENUM(pc + 4));
 }
 
 void
 __glXDispSwap_BindProgramARB(GLbyte * pc)
 {
-    glBindProgramARB((GLenum) bswap_ENUM(pc + 0),
-                     (GLuint) bswap_CARD32(pc + 4));
+    PFNGLBINDPROGRAMARBPROC BindProgramARB =
+        __glGetProcAddress("glBindProgramARB");
+    BindProgramARB((GLenum) bswap_ENUM(pc + 0), (GLuint) bswap_CARD32(pc + 4));
 }
 
 int
 __glXDispSwap_DeleteProgramsARB(__GLXclientState * cl, GLbyte * pc)
 {
+    PFNGLDELETEPROGRAMSARBPROC DeleteProgramsARB =
+        __glGetProcAddress("glDeleteProgramsARB");
     xGLXVendorPrivateReq *const req = (xGLXVendorPrivateReq *) pc;
     int error;
     __GLXcontext *const cx =
@@ -4580,9 +4670,9 @@ __glXDispSwap_DeleteProgramsARB(__GLXclientState * cl, GLbyte * pc)
     if (cx != NULL) {
         const GLsizei n = (GLsizei) bswap_CARD32(pc + 0);
 
-        glDeleteProgramsARB(n,
-                            (const GLuint *)
-                            bswap_32_array((uint32_t *) (pc + 4), 0));
+        DeleteProgramsARB(n,
+                          (const GLuint *) bswap_32_array((uint32_t *) (pc + 4),
+                                                          0));
         error = Success;
     }
 
@@ -4592,6 +4682,8 @@ __glXDispSwap_DeleteProgramsARB(__GLXclientState * cl, GLbyte * pc)
 int
 __glXDispSwap_GenProgramsARB(__GLXclientState * cl, GLbyte * pc)
 {
+    PFNGLGENPROGRAMSARBPROC GenProgramsARB =
+        __glGetProcAddress("glGenProgramsARB");
     xGLXVendorPrivateReq *const req = (xGLXVendorPrivateReq *) pc;
     int error;
     __GLXcontext *const cx =
@@ -4605,7 +4697,7 @@ __glXDispSwap_GenProgramsARB(__GLXclientState * cl, GLbyte * pc)
         GLuint *programs =
             __glXGetAnswerBuffer(cl, n * 4, answerBuffer, sizeof(answerBuffer),
                                  4);
-        glGenProgramsARB(n, programs);
+        GenProgramsARB(n, programs);
         (void) bswap_32_array((uint32_t *) programs, n);
         __glXSendReplySwap(cl->client, programs, n, 4, GL_TRUE, 0);
         error = Success;
@@ -4617,6 +4709,8 @@ __glXDispSwap_GenProgramsARB(__GLXclientState * cl, GLbyte * pc)
 int
 __glXDispSwap_GetProgramEnvParameterdvARB(__GLXclientState * cl, GLbyte * pc)
 {
+    PFNGLGETPROGRAMENVPARAMETERDVARBPROC GetProgramEnvParameterdvARB =
+        __glGetProcAddress("glGetProgramEnvParameterdvARB");
     xGLXVendorPrivateReq *const req = (xGLXVendorPrivateReq *) pc;
     int error;
     __GLXcontext *const cx =
@@ -4626,8 +4720,8 @@ __glXDispSwap_GetProgramEnvParameterdvARB(__GLXclientState * cl, GLbyte * pc)
     if (cx != NULL) {
         GLdouble params[4];
 
-        glGetProgramEnvParameterdvARB((GLenum) bswap_ENUM(pc + 0),
-                                      (GLuint) bswap_CARD32(pc + 4), params);
+        GetProgramEnvParameterdvARB((GLenum) bswap_ENUM(pc + 0),
+                                    (GLuint) bswap_CARD32(pc + 4), params);
         (void) bswap_64_array((uint64_t *) params, 4);
         __glXSendReplySwap(cl->client, params, 4, 8, GL_FALSE, 0);
         error = Success;
@@ -4639,6 +4733,8 @@ __glXDispSwap_GetProgramEnvParameterdvARB(__GLXclientState * cl, GLbyte * pc)
 int
 __glXDispSwap_GetProgramEnvParameterfvARB(__GLXclientState * cl, GLbyte * pc)
 {
+    PFNGLGETPROGRAMENVPARAMETERFVARBPROC GetProgramEnvParameterfvARB =
+        __glGetProcAddress("glGetProgramEnvParameterfvARB");
     xGLXVendorPrivateReq *const req = (xGLXVendorPrivateReq *) pc;
     int error;
     __GLXcontext *const cx =
@@ -4648,8 +4744,8 @@ __glXDispSwap_GetProgramEnvParameterfvARB(__GLXclientState * cl, GLbyte * pc)
     if (cx != NULL) {
         GLfloat params[4];
 
-        glGetProgramEnvParameterfvARB((GLenum) bswap_ENUM(pc + 0),
-                                      (GLuint) bswap_CARD32(pc + 4), params);
+        GetProgramEnvParameterfvARB((GLenum) bswap_ENUM(pc + 0),
+                                    (GLuint) bswap_CARD32(pc + 4), params);
         (void) bswap_32_array((uint32_t *) params, 4);
         __glXSendReplySwap(cl->client, params, 4, 4, GL_FALSE, 0);
         error = Success;
@@ -4661,6 +4757,8 @@ __glXDispSwap_GetProgramEnvParameterfvARB(__GLXclientState * cl, GLbyte * pc)
 int
 __glXDispSwap_GetProgramLocalParameterdvARB(__GLXclientState * cl, GLbyte * pc)
 {
+    PFNGLGETPROGRAMLOCALPARAMETERDVARBPROC GetProgramLocalParameterdvARB =
+        __glGetProcAddress("glGetProgramLocalParameterdvARB");
     xGLXVendorPrivateReq *const req = (xGLXVendorPrivateReq *) pc;
     int error;
     __GLXcontext *const cx =
@@ -4670,8 +4768,8 @@ __glXDispSwap_GetProgramLocalParameterdvARB(__GLXclientState * cl, GLbyte * pc)
     if (cx != NULL) {
         GLdouble params[4];
 
-        glGetProgramLocalParameterdvARB((GLenum) bswap_ENUM(pc + 0),
-                                        (GLuint) bswap_CARD32(pc + 4), params);
+        GetProgramLocalParameterdvARB((GLenum) bswap_ENUM(pc + 0),
+                                      (GLuint) bswap_CARD32(pc + 4), params);
         (void) bswap_64_array((uint64_t *) params, 4);
         __glXSendReplySwap(cl->client, params, 4, 8, GL_FALSE, 0);
         error = Success;
@@ -4683,6 +4781,8 @@ __glXDispSwap_GetProgramLocalParameterdvARB(__GLXclientState * cl, GLbyte * pc)
 int
 __glXDispSwap_GetProgramLocalParameterfvARB(__GLXclientState * cl, GLbyte * pc)
 {
+    PFNGLGETPROGRAMLOCALPARAMETERFVARBPROC GetProgramLocalParameterfvARB =
+        __glGetProcAddress("glGetProgramLocalParameterfvARB");
     xGLXVendorPrivateReq *const req = (xGLXVendorPrivateReq *) pc;
     int error;
     __GLXcontext *const cx =
@@ -4692,8 +4792,8 @@ __glXDispSwap_GetProgramLocalParameterfvARB(__GLXclientState * cl, GLbyte * pc)
     if (cx != NULL) {
         GLfloat params[4];
 
-        glGetProgramLocalParameterfvARB((GLenum) bswap_ENUM(pc + 0),
-                                        (GLuint) bswap_CARD32(pc + 4), params);
+        GetProgramLocalParameterfvARB((GLenum) bswap_ENUM(pc + 0),
+                                      (GLuint) bswap_CARD32(pc + 4), params);
         (void) bswap_32_array((uint32_t *) params, 4);
         __glXSendReplySwap(cl->client, params, 4, 4, GL_FALSE, 0);
         error = Success;
@@ -4705,6 +4805,8 @@ __glXDispSwap_GetProgramLocalParameterfvARB(__GLXclientState * cl, GLbyte * pc)
 int
 __glXDispSwap_GetProgramivARB(__GLXclientState * cl, GLbyte * pc)
 {
+    PFNGLGETPROGRAMIVARBPROC GetProgramivARB =
+        __glGetProcAddress("glGetProgramivARB");
     xGLXVendorPrivateReq *const req = (xGLXVendorPrivateReq *) pc;
     int error;
     __GLXcontext *const cx =
@@ -4724,7 +4826,7 @@ __glXDispSwap_GetProgramivARB(__GLXclientState * cl, GLbyte * pc)
             return BadAlloc;
         __glXClearErrorOccured();
 
-        glGetProgramivARB((GLenum) bswap_ENUM(pc + 0), pname, params);
+        GetProgramivARB((GLenum) bswap_ENUM(pc + 0), pname, params);
         (void) bswap_32_array((uint32_t *) params, compsize);
         __glXSendReplySwap(cl->client, params, compsize, 4, GL_FALSE, 0);
         error = Success;
@@ -4736,6 +4838,7 @@ __glXDispSwap_GetProgramivARB(__GLXclientState * cl, GLbyte * pc)
 int
 __glXDispSwap_IsProgramARB(__GLXclientState * cl, GLbyte * pc)
 {
+    PFNGLISPROGRAMARBPROC IsProgramARB = __glGetProcAddress("glIsProgramARB");
     xGLXVendorPrivateReq *const req = (xGLXVendorPrivateReq *) pc;
     int error;
     __GLXcontext *const cx =
@@ -4745,7 +4848,7 @@ __glXDispSwap_IsProgramARB(__GLXclientState * cl, GLbyte * pc)
     if (cx != NULL) {
         GLboolean retval;
 
-        retval = glIsProgramARB((GLuint) bswap_CARD32(pc + 0));
+        retval = IsProgramARB((GLuint) bswap_CARD32(pc + 0));
         __glXSendReplySwap(cl->client, dummy_answer, 0, 0, GL_FALSE, retval);
         error = Success;
     }
@@ -4756,6 +4859,8 @@ __glXDispSwap_IsProgramARB(__GLXclientState * cl, GLbyte * pc)
 void
 __glXDispSwap_ProgramEnvParameter4dvARB(GLbyte * pc)
 {
+    PFNGLPROGRAMENVPARAMETER4DVARBPROC ProgramEnvParameter4dvARB =
+        __glGetProcAddress("glProgramEnvParameter4dvARB");
 #ifdef __GLX_ALIGN64
     if ((unsigned long) (pc) & 7) {
         (void) memmove(pc - 4, pc, 40);
@@ -4763,24 +4868,28 @@ __glXDispSwap_ProgramEnvParameter4dvARB(GLbyte * pc)
     }
 #endif
 
-    glProgramEnvParameter4dvARB((GLenum) bswap_ENUM(pc + 0),
-                                (GLuint) bswap_CARD32(pc + 4),
-                                (const GLdouble *)
-                                bswap_64_array((uint64_t *) (pc + 8), 4));
+    ProgramEnvParameter4dvARB((GLenum) bswap_ENUM(pc + 0),
+                              (GLuint) bswap_CARD32(pc + 4),
+                              (const GLdouble *)
+                              bswap_64_array((uint64_t *) (pc + 8), 4));
 }
 
 void
 __glXDispSwap_ProgramEnvParameter4fvARB(GLbyte * pc)
 {
-    glProgramEnvParameter4fvARB((GLenum) bswap_ENUM(pc + 0),
-                                (GLuint) bswap_CARD32(pc + 4),
-                                (const GLfloat *)
-                                bswap_32_array((uint32_t *) (pc + 8), 4));
+    PFNGLPROGRAMENVPARAMETER4FVARBPROC ProgramEnvParameter4fvARB =
+        __glGetProcAddress("glProgramEnvParameter4fvARB");
+    ProgramEnvParameter4fvARB((GLenum) bswap_ENUM(pc + 0),
+                              (GLuint) bswap_CARD32(pc + 4),
+                              (const GLfloat *)
+                              bswap_32_array((uint32_t *) (pc + 8), 4));
 }
 
 void
 __glXDispSwap_ProgramLocalParameter4dvARB(GLbyte * pc)
 {
+    PFNGLPROGRAMLOCALPARAMETER4DVARBPROC ProgramLocalParameter4dvARB =
+        __glGetProcAddress("glProgramLocalParameter4dvARB");
 #ifdef __GLX_ALIGN64
     if ((unsigned long) (pc) & 7) {
         (void) memmove(pc - 4, pc, 40);
@@ -4788,95 +4897,112 @@ __glXDispSwap_ProgramLocalParameter4dvARB(GLbyte * pc)
     }
 #endif
 
-    glProgramLocalParameter4dvARB((GLenum) bswap_ENUM(pc + 0),
-                                  (GLuint) bswap_CARD32(pc + 4),
-                                  (const GLdouble *)
-                                  bswap_64_array((uint64_t *) (pc + 8), 4));
+    ProgramLocalParameter4dvARB((GLenum) bswap_ENUM(pc + 0),
+                                (GLuint) bswap_CARD32(pc + 4),
+                                (const GLdouble *)
+                                bswap_64_array((uint64_t *) (pc + 8), 4));
 }
 
 void
 __glXDispSwap_ProgramLocalParameter4fvARB(GLbyte * pc)
 {
-    glProgramLocalParameter4fvARB((GLenum) bswap_ENUM(pc + 0),
-                                  (GLuint) bswap_CARD32(pc + 4),
-                                  (const GLfloat *)
-                                  bswap_32_array((uint32_t *) (pc + 8), 4));
+    PFNGLPROGRAMLOCALPARAMETER4FVARBPROC ProgramLocalParameter4fvARB =
+        __glGetProcAddress("glProgramLocalParameter4fvARB");
+    ProgramLocalParameter4fvARB((GLenum) bswap_ENUM(pc + 0),
+                                (GLuint) bswap_CARD32(pc + 4),
+                                (const GLfloat *)
+                                bswap_32_array((uint32_t *) (pc + 8), 4));
 }
 
 void
 __glXDispSwap_ProgramStringARB(GLbyte * pc)
 {
+    PFNGLPROGRAMSTRINGARBPROC ProgramStringARB =
+        __glGetProcAddress("glProgramStringARB");
     const GLsizei len = (GLsizei) bswap_CARD32(pc + 8);
 
-    glProgramStringARB((GLenum) bswap_ENUM(pc + 0),
-                       (GLenum) bswap_ENUM(pc + 4),
-                       len, (const GLvoid *) (pc + 12));
+    ProgramStringARB((GLenum) bswap_ENUM(pc + 0),
+                     (GLenum) bswap_ENUM(pc + 4),
+                     len, (const GLvoid *) (pc + 12));
 }
 
 void
 __glXDispSwap_VertexAttrib1fvARB(GLbyte * pc)
 {
-    glVertexAttrib1fvARB((GLuint) bswap_CARD32(pc + 0),
-                         (const GLfloat *) bswap_32_array((uint32_t *) (pc + 4),
-                                                          1));
+    PFNGLVERTEXATTRIB1FVARBPROC VertexAttrib1fvARB =
+        __glGetProcAddress("glVertexAttrib1fvARB");
+    VertexAttrib1fvARB((GLuint) bswap_CARD32(pc + 0),
+                       (const GLfloat *) bswap_32_array((uint32_t *) (pc + 4),
+                                                        1));
 }
 
 void
 __glXDispSwap_VertexAttrib2fvARB(GLbyte * pc)
 {
-    glVertexAttrib2fvARB((GLuint) bswap_CARD32(pc + 0),
-                         (const GLfloat *) bswap_32_array((uint32_t *) (pc + 4),
-                                                          2));
+    PFNGLVERTEXATTRIB2FVARBPROC VertexAttrib2fvARB =
+        __glGetProcAddress("glVertexAttrib2fvARB");
+    VertexAttrib2fvARB((GLuint) bswap_CARD32(pc + 0),
+                       (const GLfloat *) bswap_32_array((uint32_t *) (pc + 4),
+                                                        2));
 }
 
 void
 __glXDispSwap_VertexAttrib3fvARB(GLbyte * pc)
 {
-    glVertexAttrib3fvARB((GLuint) bswap_CARD32(pc + 0),
-                         (const GLfloat *) bswap_32_array((uint32_t *) (pc + 4),
-                                                          3));
+    PFNGLVERTEXATTRIB3FVARBPROC VertexAttrib3fvARB =
+        __glGetProcAddress("glVertexAttrib3fvARB");
+    VertexAttrib3fvARB((GLuint) bswap_CARD32(pc + 0),
+                       (const GLfloat *) bswap_32_array((uint32_t *) (pc + 4),
+                                                        3));
 }
 
 void
 __glXDispSwap_VertexAttrib4fvARB(GLbyte * pc)
 {
-    glVertexAttrib4fvARB((GLuint) bswap_CARD32(pc + 0),
-                         (const GLfloat *) bswap_32_array((uint32_t *) (pc + 4),
-                                                          4));
+    PFNGLVERTEXATTRIB4FVARBPROC VertexAttrib4fvARB =
+        __glGetProcAddress("glVertexAttrib4fvARB");
+    VertexAttrib4fvARB((GLuint) bswap_CARD32(pc + 0),
+                       (const GLfloat *) bswap_32_array((uint32_t *) (pc + 4),
+                                                        4));
 }
 
 void
 __glXDispSwap_BindFramebuffer(GLbyte * pc)
 {
-    glBindFramebuffer((GLenum) bswap_ENUM(pc + 0),
-                      (GLuint) bswap_CARD32(pc + 4));
+    PFNGLBINDFRAMEBUFFERPROC BindFramebuffer =
+        __glGetProcAddress("glBindFramebuffer");
+    BindFramebuffer((GLenum) bswap_ENUM(pc + 0), (GLuint) bswap_CARD32(pc + 4));
 }
 
 void
 __glXDispSwap_BindRenderbuffer(GLbyte * pc)
 {
-    glBindRenderbuffer((GLenum) bswap_ENUM(pc + 0),
-                       (GLuint) bswap_CARD32(pc + 4));
+    PFNGLBINDRENDERBUFFERPROC BindRenderbuffer =
+        __glGetProcAddress("glBindRenderbuffer");
+    BindRenderbuffer((GLenum) bswap_ENUM(pc + 0),
+                     (GLuint) bswap_CARD32(pc + 4));
 }
 
 void
 __glXDispSwap_BlitFramebuffer(GLbyte * pc)
 {
-    glBlitFramebuffer((GLint) bswap_CARD32(pc + 0),
-                      (GLint) bswap_CARD32(pc + 4),
-                      (GLint) bswap_CARD32(pc + 8),
-                      (GLint) bswap_CARD32(pc + 12),
-                      (GLint) bswap_CARD32(pc + 16),
-                      (GLint) bswap_CARD32(pc + 20),
-                      (GLint) bswap_CARD32(pc + 24),
-                      (GLint) bswap_CARD32(pc + 28),
-                      (GLbitfield) bswap_CARD32(pc + 32),
-                      (GLenum) bswap_ENUM(pc + 36));
+    PFNGLBLITFRAMEBUFFERPROC BlitFramebuffer =
+        __glGetProcAddress("glBlitFramebuffer");
+    BlitFramebuffer((GLint) bswap_CARD32(pc + 0), (GLint) bswap_CARD32(pc + 4),
+                    (GLint) bswap_CARD32(pc + 8), (GLint) bswap_CARD32(pc + 12),
+                    (GLint) bswap_CARD32(pc + 16),
+                    (GLint) bswap_CARD32(pc + 20),
+                    (GLint) bswap_CARD32(pc + 24),
+                    (GLint) bswap_CARD32(pc + 28),
+                    (GLbitfield) bswap_CARD32(pc + 32),
+                    (GLenum) bswap_ENUM(pc + 36));
 }
 
 int
 __glXDispSwap_CheckFramebufferStatus(__GLXclientState * cl, GLbyte * pc)
 {
+    PFNGLCHECKFRAMEBUFFERSTATUSPROC CheckFramebufferStatus =
+        __glGetProcAddress("glCheckFramebufferStatus");
     xGLXVendorPrivateReq *const req = (xGLXVendorPrivateReq *) pc;
     int error;
     __GLXcontext *const cx =
@@ -4886,7 +5012,7 @@ __glXDispSwap_CheckFramebufferStatus(__GLXclientState * cl, GLbyte * pc)
     if (cx != NULL) {
         GLenum retval;
 
-        retval = glCheckFramebufferStatus((GLenum) bswap_ENUM(pc + 0));
+        retval = CheckFramebufferStatus((GLenum) bswap_ENUM(pc + 0));
         __glXSendReplySwap(cl->client, dummy_answer, 0, 0, GL_FALSE, retval);
         error = Success;
     }
@@ -4897,76 +5023,92 @@ __glXDispSwap_CheckFramebufferStatus(__GLXclientState * cl, GLbyte * pc)
 void
 __glXDispSwap_DeleteFramebuffers(GLbyte * pc)
 {
+    PFNGLDELETEFRAMEBUFFERSPROC DeleteFramebuffers =
+        __glGetProcAddress("glDeleteFramebuffers");
     const GLsizei n = (GLsizei) bswap_CARD32(pc + 0);
 
-    glDeleteFramebuffers(n,
-                         (const GLuint *) bswap_32_array((uint32_t *) (pc + 4),
-                                                         0));
+    DeleteFramebuffers(n,
+                       (const GLuint *) bswap_32_array((uint32_t *) (pc + 4),
+                                                       0));
 }
 
 void
 __glXDispSwap_DeleteRenderbuffers(GLbyte * pc)
 {
+    PFNGLDELETERENDERBUFFERSPROC DeleteRenderbuffers =
+        __glGetProcAddress("glDeleteRenderbuffers");
     const GLsizei n = (GLsizei) bswap_CARD32(pc + 0);
 
-    glDeleteRenderbuffers(n,
-                          (const GLuint *) bswap_32_array((uint32_t *) (pc + 4),
-                                                          0));
+    DeleteRenderbuffers(n,
+                        (const GLuint *) bswap_32_array((uint32_t *) (pc + 4),
+                                                        0));
 }
 
 void
 __glXDispSwap_FramebufferRenderbuffer(GLbyte * pc)
 {
-    glFramebufferRenderbuffer((GLenum) bswap_ENUM(pc + 0),
-                              (GLenum) bswap_ENUM(pc + 4),
-                              (GLenum) bswap_ENUM(pc + 8),
-                              (GLuint) bswap_CARD32(pc + 12));
+    PFNGLFRAMEBUFFERRENDERBUFFERPROC FramebufferRenderbuffer =
+        __glGetProcAddress("glFramebufferRenderbuffer");
+    FramebufferRenderbuffer((GLenum) bswap_ENUM(pc + 0),
+                            (GLenum) bswap_ENUM(pc + 4),
+                            (GLenum) bswap_ENUM(pc + 8),
+                            (GLuint) bswap_CARD32(pc + 12));
 }
 
 void
 __glXDispSwap_FramebufferTexture1D(GLbyte * pc)
 {
-    glFramebufferTexture1D((GLenum) bswap_ENUM(pc + 0),
-                           (GLenum) bswap_ENUM(pc + 4),
-                           (GLenum) bswap_ENUM(pc + 8),
-                           (GLuint) bswap_CARD32(pc + 12),
-                           (GLint) bswap_CARD32(pc + 16));
+    PFNGLFRAMEBUFFERTEXTURE1DPROC FramebufferTexture1D =
+        __glGetProcAddress("glFramebufferTexture1D");
+    FramebufferTexture1D((GLenum) bswap_ENUM(pc + 0),
+                         (GLenum) bswap_ENUM(pc + 4),
+                         (GLenum) bswap_ENUM(pc + 8),
+                         (GLuint) bswap_CARD32(pc + 12),
+                         (GLint) bswap_CARD32(pc + 16));
 }
 
 void
 __glXDispSwap_FramebufferTexture2D(GLbyte * pc)
 {
-    glFramebufferTexture2D((GLenum) bswap_ENUM(pc + 0),
-                           (GLenum) bswap_ENUM(pc + 4),
-                           (GLenum) bswap_ENUM(pc + 8),
-                           (GLuint) bswap_CARD32(pc + 12),
-                           (GLint) bswap_CARD32(pc + 16));
+    PFNGLFRAMEBUFFERTEXTURE2DPROC FramebufferTexture2D =
+        __glGetProcAddress("glFramebufferTexture2D");
+    FramebufferTexture2D((GLenum) bswap_ENUM(pc + 0),
+                         (GLenum) bswap_ENUM(pc + 4),
+                         (GLenum) bswap_ENUM(pc + 8),
+                         (GLuint) bswap_CARD32(pc + 12),
+                         (GLint) bswap_CARD32(pc + 16));
 }
 
 void
 __glXDispSwap_FramebufferTexture3D(GLbyte * pc)
 {
-    glFramebufferTexture3D((GLenum) bswap_ENUM(pc + 0),
-                           (GLenum) bswap_ENUM(pc + 4),
-                           (GLenum) bswap_ENUM(pc + 8),
-                           (GLuint) bswap_CARD32(pc + 12),
-                           (GLint) bswap_CARD32(pc + 16),
-                           (GLint) bswap_CARD32(pc + 20));
+    PFNGLFRAMEBUFFERTEXTURE3DPROC FramebufferTexture3D =
+        __glGetProcAddress("glFramebufferTexture3D");
+    FramebufferTexture3D((GLenum) bswap_ENUM(pc + 0),
+                         (GLenum) bswap_ENUM(pc + 4),
+                         (GLenum) bswap_ENUM(pc + 8),
+                         (GLuint) bswap_CARD32(pc + 12),
+                         (GLint) bswap_CARD32(pc + 16),
+                         (GLint) bswap_CARD32(pc + 20));
 }
 
 void
 __glXDispSwap_FramebufferTextureLayer(GLbyte * pc)
 {
-    glFramebufferTextureLayer((GLenum) bswap_ENUM(pc + 0),
-                              (GLenum) bswap_ENUM(pc + 4),
-                              (GLuint) bswap_CARD32(pc + 8),
-                              (GLint) bswap_CARD32(pc + 12),
-                              (GLint) bswap_CARD32(pc + 16));
+    PFNGLFRAMEBUFFERTEXTURELAYERPROC FramebufferTextureLayer =
+        __glGetProcAddress("glFramebufferTextureLayer");
+    FramebufferTextureLayer((GLenum) bswap_ENUM(pc + 0),
+                            (GLenum) bswap_ENUM(pc + 4),
+                            (GLuint) bswap_CARD32(pc + 8),
+                            (GLint) bswap_CARD32(pc + 12),
+                            (GLint) bswap_CARD32(pc + 16));
 }
 
 int
 __glXDispSwap_GenFramebuffers(__GLXclientState * cl, GLbyte * pc)
 {
+    PFNGLGENFRAMEBUFFERSPROC GenFramebuffers =
+        __glGetProcAddress("glGenFramebuffers");
     xGLXVendorPrivateReq *const req = (xGLXVendorPrivateReq *) pc;
     int error;
     __GLXcontext *const cx =
@@ -4980,7 +5122,7 @@ __glXDispSwap_GenFramebuffers(__GLXclientState * cl, GLbyte * pc)
         GLuint *framebuffers =
             __glXGetAnswerBuffer(cl, n * 4, answerBuffer, sizeof(answerBuffer),
                                  4);
-        glGenFramebuffers(n, framebuffers);
+        GenFramebuffers(n, framebuffers);
         (void) bswap_32_array((uint32_t *) framebuffers, n);
         __glXSendReplySwap(cl->client, framebuffers, n, 4, GL_TRUE, 0);
         error = Success;
@@ -4992,6 +5134,8 @@ __glXDispSwap_GenFramebuffers(__GLXclientState * cl, GLbyte * pc)
 int
 __glXDispSwap_GenRenderbuffers(__GLXclientState * cl, GLbyte * pc)
 {
+    PFNGLGENRENDERBUFFERSPROC GenRenderbuffers =
+        __glGetProcAddress("glGenRenderbuffers");
     xGLXVendorPrivateReq *const req = (xGLXVendorPrivateReq *) pc;
     int error;
     __GLXcontext *const cx =
@@ -5005,7 +5149,7 @@ __glXDispSwap_GenRenderbuffers(__GLXclientState * cl, GLbyte * pc)
         GLuint *renderbuffers =
             __glXGetAnswerBuffer(cl, n * 4, answerBuffer, sizeof(answerBuffer),
                                  4);
-        glGenRenderbuffers(n, renderbuffers);
+        GenRenderbuffers(n, renderbuffers);
         (void) bswap_32_array((uint32_t *) renderbuffers, n);
         __glXSendReplySwap(cl->client, renderbuffers, n, 4, GL_TRUE, 0);
         error = Success;
@@ -5017,13 +5161,18 @@ __glXDispSwap_GenRenderbuffers(__GLXclientState * cl, GLbyte * pc)
 void
 __glXDispSwap_GenerateMipmap(GLbyte * pc)
 {
-    glGenerateMipmap((GLenum) bswap_ENUM(pc + 0));
+    PFNGLGENERATEMIPMAPPROC GenerateMipmap =
+        __glGetProcAddress("glGenerateMipmap");
+    GenerateMipmap((GLenum) bswap_ENUM(pc + 0));
 }
 
 int
 __glXDispSwap_GetFramebufferAttachmentParameteriv(__GLXclientState * cl,
                                                   GLbyte * pc)
 {
+    PFNGLGETFRAMEBUFFERATTACHMENTPARAMETERIVPROC
+        GetFramebufferAttachmentParameteriv =
+        __glGetProcAddress("glGetFramebufferAttachmentParameteriv");
     xGLXVendorPrivateReq *const req = (xGLXVendorPrivateReq *) pc;
     int error;
     __GLXcontext *const cx =
@@ -5033,10 +5182,10 @@ __glXDispSwap_GetFramebufferAttachmentParameteriv(__GLXclientState * cl,
     if (cx != NULL) {
         GLint params[1];
 
-        glGetFramebufferAttachmentParameteriv((GLenum) bswap_ENUM(pc + 0),
-                                              (GLenum) bswap_ENUM(pc + 4),
-                                              (GLenum) bswap_ENUM(pc + 8),
-                                              params);
+        GetFramebufferAttachmentParameteriv((GLenum) bswap_ENUM(pc + 0),
+                                            (GLenum) bswap_ENUM(pc + 4),
+                                            (GLenum) bswap_ENUM(pc + 8),
+                                            params);
         (void) bswap_32_array((uint32_t *) params, 1);
         __glXSendReplySwap(cl->client, params, 1, 4, GL_FALSE, 0);
         error = Success;
@@ -5048,6 +5197,8 @@ __glXDispSwap_GetFramebufferAttachmentParameteriv(__GLXclientState * cl,
 int
 __glXDispSwap_GetRenderbufferParameteriv(__GLXclientState * cl, GLbyte * pc)
 {
+    PFNGLGETRENDERBUFFERPARAMETERIVPROC GetRenderbufferParameteriv =
+        __glGetProcAddress("glGetRenderbufferParameteriv");
     xGLXVendorPrivateReq *const req = (xGLXVendorPrivateReq *) pc;
     int error;
     __GLXcontext *const cx =
@@ -5057,8 +5208,8 @@ __glXDispSwap_GetRenderbufferParameteriv(__GLXclientState * cl, GLbyte * pc)
     if (cx != NULL) {
         GLint params[1];
 
-        glGetRenderbufferParameteriv((GLenum) bswap_ENUM(pc + 0),
-                                     (GLenum) bswap_ENUM(pc + 4), params);
+        GetRenderbufferParameteriv((GLenum) bswap_ENUM(pc + 0),
+                                   (GLenum) bswap_ENUM(pc + 4), params);
         (void) bswap_32_array((uint32_t *) params, 1);
         __glXSendReplySwap(cl->client, params, 1, 4, GL_FALSE, 0);
         error = Success;
@@ -5070,6 +5221,8 @@ __glXDispSwap_GetRenderbufferParameteriv(__GLXclientState * cl, GLbyte * pc)
 int
 __glXDispSwap_IsFramebuffer(__GLXclientState * cl, GLbyte * pc)
 {
+    PFNGLISFRAMEBUFFERPROC IsFramebuffer =
+        __glGetProcAddress("glIsFramebuffer");
     xGLXVendorPrivateReq *const req = (xGLXVendorPrivateReq *) pc;
     int error;
     __GLXcontext *const cx =
@@ -5079,7 +5232,7 @@ __glXDispSwap_IsFramebuffer(__GLXclientState * cl, GLbyte * pc)
     if (cx != NULL) {
         GLboolean retval;
 
-        retval = glIsFramebuffer((GLuint) bswap_CARD32(pc + 0));
+        retval = IsFramebuffer((GLuint) bswap_CARD32(pc + 0));
         __glXSendReplySwap(cl->client, dummy_answer, 0, 0, GL_FALSE, retval);
         error = Success;
     }
@@ -5090,6 +5243,8 @@ __glXDispSwap_IsFramebuffer(__GLXclientState * cl, GLbyte * pc)
 int
 __glXDispSwap_IsRenderbuffer(__GLXclientState * cl, GLbyte * pc)
 {
+    PFNGLISRENDERBUFFERPROC IsRenderbuffer =
+        __glGetProcAddress("glIsRenderbuffer");
     xGLXVendorPrivateReq *const req = (xGLXVendorPrivateReq *) pc;
     int error;
     __GLXcontext *const cx =
@@ -5099,7 +5254,7 @@ __glXDispSwap_IsRenderbuffer(__GLXclientState * cl, GLbyte * pc)
     if (cx != NULL) {
         GLboolean retval;
 
-        retval = glIsRenderbuffer((GLuint) bswap_CARD32(pc + 0));
+        retval = IsRenderbuffer((GLuint) bswap_CARD32(pc + 0));
         __glXSendReplySwap(cl->client, dummy_answer, 0, 0, GL_FALSE, retval);
         error = Success;
     }
@@ -5110,38 +5265,48 @@ __glXDispSwap_IsRenderbuffer(__GLXclientState * cl, GLbyte * pc)
 void
 __glXDispSwap_RenderbufferStorage(GLbyte * pc)
 {
-    glRenderbufferStorage((GLenum) bswap_ENUM(pc + 0),
-                          (GLenum) bswap_ENUM(pc + 4),
-                          (GLsizei) bswap_CARD32(pc + 8),
-                          (GLsizei) bswap_CARD32(pc + 12));
+    PFNGLRENDERBUFFERSTORAGEPROC RenderbufferStorage =
+        __glGetProcAddress("glRenderbufferStorage");
+    RenderbufferStorage((GLenum) bswap_ENUM(pc + 0),
+                        (GLenum) bswap_ENUM(pc + 4),
+                        (GLsizei) bswap_CARD32(pc + 8),
+                        (GLsizei) bswap_CARD32(pc + 12));
 }
 
 void
 __glXDispSwap_RenderbufferStorageMultisample(GLbyte * pc)
 {
-    glRenderbufferStorageMultisample((GLenum) bswap_ENUM(pc + 0),
-                                     (GLsizei) bswap_CARD32(pc + 4),
-                                     (GLenum) bswap_ENUM(pc + 8),
-                                     (GLsizei) bswap_CARD32(pc + 12),
-                                     (GLsizei) bswap_CARD32(pc + 16));
+    PFNGLRENDERBUFFERSTORAGEMULTISAMPLEPROC RenderbufferStorageMultisample =
+        __glGetProcAddress("glRenderbufferStorageMultisample");
+    RenderbufferStorageMultisample((GLenum) bswap_ENUM(pc + 0),
+                                   (GLsizei) bswap_CARD32(pc + 4),
+                                   (GLenum) bswap_ENUM(pc + 8),
+                                   (GLsizei) bswap_CARD32(pc + 12),
+                                   (GLsizei) bswap_CARD32(pc + 16));
 }
 
 void
 __glXDispSwap_SecondaryColor3fvEXT(GLbyte * pc)
 {
-    glSecondaryColor3fvEXT((const GLfloat *)
-                           bswap_32_array((uint32_t *) (pc + 0), 3));
+    PFNGLSECONDARYCOLOR3FVEXTPROC SecondaryColor3fvEXT =
+        __glGetProcAddress("glSecondaryColor3fvEXT");
+    SecondaryColor3fvEXT((const GLfloat *)
+                         bswap_32_array((uint32_t *) (pc + 0), 3));
 }
 
 void
 __glXDispSwap_FogCoordfvEXT(GLbyte * pc)
 {
-    glFogCoordfvEXT((const GLfloat *) bswap_32_array((uint32_t *) (pc + 0), 1));
+    PFNGLFOGCOORDFVEXTPROC FogCoordfvEXT =
+        __glGetProcAddress("glFogCoordfvEXT");
+    FogCoordfvEXT((const GLfloat *) bswap_32_array((uint32_t *) (pc + 0), 1));
 }
 
 void
 __glXDispSwap_VertexAttrib1dvNV(GLbyte * pc)
 {
+    PFNGLVERTEXATTRIB1DVNVPROC VertexAttrib1dvNV =
+        __glGetProcAddress("glVertexAttrib1dvNV");
 #ifdef __GLX_ALIGN64
     if ((unsigned long) (pc) & 7) {
         (void) memmove(pc - 4, pc, 12);
@@ -5149,30 +5314,36 @@ __glXDispSwap_VertexAttrib1dvNV(GLbyte * pc)
     }
 #endif
 
-    glVertexAttrib1dvNV((GLuint) bswap_CARD32(pc + 0),
-                        (const GLdouble *) bswap_64_array((uint64_t *) (pc + 4),
-                                                          1));
+    VertexAttrib1dvNV((GLuint) bswap_CARD32(pc + 0),
+                      (const GLdouble *) bswap_64_array((uint64_t *) (pc + 4),
+                                                        1));
 }
 
 void
 __glXDispSwap_VertexAttrib1fvNV(GLbyte * pc)
 {
-    glVertexAttrib1fvNV((GLuint) bswap_CARD32(pc + 0),
-                        (const GLfloat *) bswap_32_array((uint32_t *) (pc + 4),
-                                                         1));
+    PFNGLVERTEXATTRIB1FVNVPROC VertexAttrib1fvNV =
+        __glGetProcAddress("glVertexAttrib1fvNV");
+    VertexAttrib1fvNV((GLuint) bswap_CARD32(pc + 0),
+                      (const GLfloat *) bswap_32_array((uint32_t *) (pc + 4),
+                                                       1));
 }
 
 void
 __glXDispSwap_VertexAttrib1svNV(GLbyte * pc)
 {
-    glVertexAttrib1svNV((GLuint) bswap_CARD32(pc + 0),
-                        (const GLshort *) bswap_16_array((uint16_t *) (pc + 4),
-                                                         1));
+    PFNGLVERTEXATTRIB1SVNVPROC VertexAttrib1svNV =
+        __glGetProcAddress("glVertexAttrib1svNV");
+    VertexAttrib1svNV((GLuint) bswap_CARD32(pc + 0),
+                      (const GLshort *) bswap_16_array((uint16_t *) (pc + 4),
+                                                       1));
 }
 
 void
 __glXDispSwap_VertexAttrib2dvNV(GLbyte * pc)
 {
+    PFNGLVERTEXATTRIB2DVNVPROC VertexAttrib2dvNV =
+        __glGetProcAddress("glVertexAttrib2dvNV");
 #ifdef __GLX_ALIGN64
     if ((unsigned long) (pc) & 7) {
         (void) memmove(pc - 4, pc, 20);
@@ -5180,30 +5351,36 @@ __glXDispSwap_VertexAttrib2dvNV(GLbyte * pc)
     }
 #endif
 
-    glVertexAttrib2dvNV((GLuint) bswap_CARD32(pc + 0),
-                        (const GLdouble *) bswap_64_array((uint64_t *) (pc + 4),
-                                                          2));
+    VertexAttrib2dvNV((GLuint) bswap_CARD32(pc + 0),
+                      (const GLdouble *) bswap_64_array((uint64_t *) (pc + 4),
+                                                        2));
 }
 
 void
 __glXDispSwap_VertexAttrib2fvNV(GLbyte * pc)
 {
-    glVertexAttrib2fvNV((GLuint) bswap_CARD32(pc + 0),
-                        (const GLfloat *) bswap_32_array((uint32_t *) (pc + 4),
-                                                         2));
+    PFNGLVERTEXATTRIB2FVNVPROC VertexAttrib2fvNV =
+        __glGetProcAddress("glVertexAttrib2fvNV");
+    VertexAttrib2fvNV((GLuint) bswap_CARD32(pc + 0),
+                      (const GLfloat *) bswap_32_array((uint32_t *) (pc + 4),
+                                                       2));
 }
 
 void
 __glXDispSwap_VertexAttrib2svNV(GLbyte * pc)
 {
-    glVertexAttrib2svNV((GLuint) bswap_CARD32(pc + 0),
-                        (const GLshort *) bswap_16_array((uint16_t *) (pc + 4),
-                                                         2));
+    PFNGLVERTEXATTRIB2SVNVPROC VertexAttrib2svNV =
+        __glGetProcAddress("glVertexAttrib2svNV");
+    VertexAttrib2svNV((GLuint) bswap_CARD32(pc + 0),
+                      (const GLshort *) bswap_16_array((uint16_t *) (pc + 4),
+                                                       2));
 }
 
 void
 __glXDispSwap_VertexAttrib3dvNV(GLbyte * pc)
 {
+    PFNGLVERTEXATTRIB3DVNVPROC VertexAttrib3dvNV =
+        __glGetProcAddress("glVertexAttrib3dvNV");
 #ifdef __GLX_ALIGN64
     if ((unsigned long) (pc) & 7) {
         (void) memmove(pc - 4, pc, 28);
@@ -5211,30 +5388,36 @@ __glXDispSwap_VertexAttrib3dvNV(GLbyte * pc)
     }
 #endif
 
-    glVertexAttrib3dvNV((GLuint) bswap_CARD32(pc + 0),
-                        (const GLdouble *) bswap_64_array((uint64_t *) (pc + 4),
-                                                          3));
+    VertexAttrib3dvNV((GLuint) bswap_CARD32(pc + 0),
+                      (const GLdouble *) bswap_64_array((uint64_t *) (pc + 4),
+                                                        3));
 }
 
 void
 __glXDispSwap_VertexAttrib3fvNV(GLbyte * pc)
 {
-    glVertexAttrib3fvNV((GLuint) bswap_CARD32(pc + 0),
-                        (const GLfloat *) bswap_32_array((uint32_t *) (pc + 4),
-                                                         3));
+    PFNGLVERTEXATTRIB3FVNVPROC VertexAttrib3fvNV =
+        __glGetProcAddress("glVertexAttrib3fvNV");
+    VertexAttrib3fvNV((GLuint) bswap_CARD32(pc + 0),
+                      (const GLfloat *) bswap_32_array((uint32_t *) (pc + 4),
+                                                       3));
 }
 
 void
 __glXDispSwap_VertexAttrib3svNV(GLbyte * pc)
 {
-    glVertexAttrib3svNV((GLuint) bswap_CARD32(pc + 0),
-                        (const GLshort *) bswap_16_array((uint16_t *) (pc + 4),
-                                                         3));
+    PFNGLVERTEXATTRIB3SVNVPROC VertexAttrib3svNV =
+        __glGetProcAddress("glVertexAttrib3svNV");
+    VertexAttrib3svNV((GLuint) bswap_CARD32(pc + 0),
+                      (const GLshort *) bswap_16_array((uint16_t *) (pc + 4),
+                                                       3));
 }
 
 void
 __glXDispSwap_VertexAttrib4dvNV(GLbyte * pc)
 {
+    PFNGLVERTEXATTRIB4DVNVPROC VertexAttrib4dvNV =
+        __glGetProcAddress("glVertexAttrib4dvNV");
 #ifdef __GLX_ALIGN64
     if ((unsigned long) (pc) & 7) {
         (void) memmove(pc - 4, pc, 36);
@@ -5242,37 +5425,45 @@ __glXDispSwap_VertexAttrib4dvNV(GLbyte * pc)
     }
 #endif
 
-    glVertexAttrib4dvNV((GLuint) bswap_CARD32(pc + 0),
-                        (const GLdouble *) bswap_64_array((uint64_t *) (pc + 4),
-                                                          4));
+    VertexAttrib4dvNV((GLuint) bswap_CARD32(pc + 0),
+                      (const GLdouble *) bswap_64_array((uint64_t *) (pc + 4),
+                                                        4));
 }
 
 void
 __glXDispSwap_VertexAttrib4fvNV(GLbyte * pc)
 {
-    glVertexAttrib4fvNV((GLuint) bswap_CARD32(pc + 0),
-                        (const GLfloat *) bswap_32_array((uint32_t *) (pc + 4),
-                                                         4));
+    PFNGLVERTEXATTRIB4FVNVPROC VertexAttrib4fvNV =
+        __glGetProcAddress("glVertexAttrib4fvNV");
+    VertexAttrib4fvNV((GLuint) bswap_CARD32(pc + 0),
+                      (const GLfloat *) bswap_32_array((uint32_t *) (pc + 4),
+                                                       4));
 }
 
 void
 __glXDispSwap_VertexAttrib4svNV(GLbyte * pc)
 {
-    glVertexAttrib4svNV((GLuint) bswap_CARD32(pc + 0),
-                        (const GLshort *) bswap_16_array((uint16_t *) (pc + 4),
-                                                         4));
+    PFNGLVERTEXATTRIB4SVNVPROC VertexAttrib4svNV =
+        __glGetProcAddress("glVertexAttrib4svNV");
+    VertexAttrib4svNV((GLuint) bswap_CARD32(pc + 0),
+                      (const GLshort *) bswap_16_array((uint16_t *) (pc + 4),
+                                                       4));
 }
 
 void
 __glXDispSwap_VertexAttrib4ubvNV(GLbyte * pc)
 {
-    glVertexAttrib4ubvNV((GLuint) bswap_CARD32(pc + 0),
-                         (const GLubyte *) (pc + 4));
+    PFNGLVERTEXATTRIB4UBVNVPROC VertexAttrib4ubvNV =
+        __glGetProcAddress("glVertexAttrib4ubvNV");
+    VertexAttrib4ubvNV((GLuint) bswap_CARD32(pc + 0),
+                       (const GLubyte *) (pc + 4));
 }
 
 void
 __glXDispSwap_VertexAttribs1dvNV(GLbyte * pc)
 {
+    PFNGLVERTEXATTRIBS1DVNVPROC VertexAttribs1dvNV =
+        __glGetProcAddress("glVertexAttribs1dvNV");
     const GLsizei n = (GLsizei) bswap_CARD32(pc + 4);
 
 #ifdef __GLX_ALIGN64
@@ -5284,37 +5475,43 @@ __glXDispSwap_VertexAttribs1dvNV(GLbyte * pc)
     }
 #endif
 
-    glVertexAttribs1dvNV((GLuint) bswap_CARD32(pc + 0),
-                         n,
-                         (const GLdouble *)
-                         bswap_64_array((uint64_t *) (pc + 8), 0));
+    VertexAttribs1dvNV((GLuint) bswap_CARD32(pc + 0),
+                       n,
+                       (const GLdouble *) bswap_64_array((uint64_t *) (pc + 8),
+                                                         0));
 }
 
 void
 __glXDispSwap_VertexAttribs1fvNV(GLbyte * pc)
 {
+    PFNGLVERTEXATTRIBS1FVNVPROC VertexAttribs1fvNV =
+        __glGetProcAddress("glVertexAttribs1fvNV");
     const GLsizei n = (GLsizei) bswap_CARD32(pc + 4);
 
-    glVertexAttribs1fvNV((GLuint) bswap_CARD32(pc + 0),
-                         n,
-                         (const GLfloat *) bswap_32_array((uint32_t *) (pc + 8),
-                                                          0));
+    VertexAttribs1fvNV((GLuint) bswap_CARD32(pc + 0),
+                       n,
+                       (const GLfloat *) bswap_32_array((uint32_t *) (pc + 8),
+                                                        0));
 }
 
 void
 __glXDispSwap_VertexAttribs1svNV(GLbyte * pc)
 {
+    PFNGLVERTEXATTRIBS1SVNVPROC VertexAttribs1svNV =
+        __glGetProcAddress("glVertexAttribs1svNV");
     const GLsizei n = (GLsizei) bswap_CARD32(pc + 4);
 
-    glVertexAttribs1svNV((GLuint) bswap_CARD32(pc + 0),
-                         n,
-                         (const GLshort *) bswap_16_array((uint16_t *) (pc + 8),
-                                                          0));
+    VertexAttribs1svNV((GLuint) bswap_CARD32(pc + 0),
+                       n,
+                       (const GLshort *) bswap_16_array((uint16_t *) (pc + 8),
+                                                        0));
 }
 
 void
 __glXDispSwap_VertexAttribs2dvNV(GLbyte * pc)
 {
+    PFNGLVERTEXATTRIBS2DVNVPROC VertexAttribs2dvNV =
+        __glGetProcAddress("glVertexAttribs2dvNV");
     const GLsizei n = (GLsizei) bswap_CARD32(pc + 4);
 
 #ifdef __GLX_ALIGN64
@@ -5326,37 +5523,43 @@ __glXDispSwap_VertexAttribs2dvNV(GLbyte * pc)
     }
 #endif
 
-    glVertexAttribs2dvNV((GLuint) bswap_CARD32(pc + 0),
-                         n,
-                         (const GLdouble *)
-                         bswap_64_array((uint64_t *) (pc + 8), 0));
+    VertexAttribs2dvNV((GLuint) bswap_CARD32(pc + 0),
+                       n,
+                       (const GLdouble *) bswap_64_array((uint64_t *) (pc + 8),
+                                                         0));
 }
 
 void
 __glXDispSwap_VertexAttribs2fvNV(GLbyte * pc)
 {
+    PFNGLVERTEXATTRIBS2FVNVPROC VertexAttribs2fvNV =
+        __glGetProcAddress("glVertexAttribs2fvNV");
     const GLsizei n = (GLsizei) bswap_CARD32(pc + 4);
 
-    glVertexAttribs2fvNV((GLuint) bswap_CARD32(pc + 0),
-                         n,
-                         (const GLfloat *) bswap_32_array((uint32_t *) (pc + 8),
-                                                          0));
+    VertexAttribs2fvNV((GLuint) bswap_CARD32(pc + 0),
+                       n,
+                       (const GLfloat *) bswap_32_array((uint32_t *) (pc + 8),
+                                                        0));
 }
 
 void
 __glXDispSwap_VertexAttribs2svNV(GLbyte * pc)
 {
+    PFNGLVERTEXATTRIBS2SVNVPROC VertexAttribs2svNV =
+        __glGetProcAddress("glVertexAttribs2svNV");
     const GLsizei n = (GLsizei) bswap_CARD32(pc + 4);
 
-    glVertexAttribs2svNV((GLuint) bswap_CARD32(pc + 0),
-                         n,
-                         (const GLshort *) bswap_16_array((uint16_t *) (pc + 8),
-                                                          0));
+    VertexAttribs2svNV((GLuint) bswap_CARD32(pc + 0),
+                       n,
+                       (const GLshort *) bswap_16_array((uint16_t *) (pc + 8),
+                                                        0));
 }
 
 void
 __glXDispSwap_VertexAttribs3dvNV(GLbyte * pc)
 {
+    PFNGLVERTEXATTRIBS3DVNVPROC VertexAttribs3dvNV =
+        __glGetProcAddress("glVertexAttribs3dvNV");
     const GLsizei n = (GLsizei) bswap_CARD32(pc + 4);
 
 #ifdef __GLX_ALIGN64
@@ -5368,37 +5571,43 @@ __glXDispSwap_VertexAttribs3dvNV(GLbyte * pc)
     }
 #endif
 
-    glVertexAttribs3dvNV((GLuint) bswap_CARD32(pc + 0),
-                         n,
-                         (const GLdouble *)
-                         bswap_64_array((uint64_t *) (pc + 8), 0));
+    VertexAttribs3dvNV((GLuint) bswap_CARD32(pc + 0),
+                       n,
+                       (const GLdouble *) bswap_64_array((uint64_t *) (pc + 8),
+                                                         0));
 }
 
 void
 __glXDispSwap_VertexAttribs3fvNV(GLbyte * pc)
 {
+    PFNGLVERTEXATTRIBS3FVNVPROC VertexAttribs3fvNV =
+        __glGetProcAddress("glVertexAttribs3fvNV");
     const GLsizei n = (GLsizei) bswap_CARD32(pc + 4);
 
-    glVertexAttribs3fvNV((GLuint) bswap_CARD32(pc + 0),
-                         n,
-                         (const GLfloat *) bswap_32_array((uint32_t *) (pc + 8),
-                                                          0));
+    VertexAttribs3fvNV((GLuint) bswap_CARD32(pc + 0),
+                       n,
+                       (const GLfloat *) bswap_32_array((uint32_t *) (pc + 8),
+                                                        0));
 }
 
 void
 __glXDispSwap_VertexAttribs3svNV(GLbyte * pc)
 {
+    PFNGLVERTEXATTRIBS3SVNVPROC VertexAttribs3svNV =
+        __glGetProcAddress("glVertexAttribs3svNV");
     const GLsizei n = (GLsizei) bswap_CARD32(pc + 4);
 
-    glVertexAttribs3svNV((GLuint) bswap_CARD32(pc + 0),
-                         n,
-                         (const GLshort *) bswap_16_array((uint16_t *) (pc + 8),
-                                                          0));
+    VertexAttribs3svNV((GLuint) bswap_CARD32(pc + 0),
+                       n,
+                       (const GLshort *) bswap_16_array((uint16_t *) (pc + 8),
+                                                        0));
 }
 
 void
 __glXDispSwap_VertexAttribs4dvNV(GLbyte * pc)
 {
+    PFNGLVERTEXATTRIBS4DVNVPROC VertexAttribs4dvNV =
+        __glGetProcAddress("glVertexAttribs4dvNV");
     const GLsizei n = (GLsizei) bswap_CARD32(pc + 4);
 
 #ifdef __GLX_ALIGN64
@@ -5410,45 +5619,53 @@ __glXDispSwap_VertexAttribs4dvNV(GLbyte * pc)
     }
 #endif
 
-    glVertexAttribs4dvNV((GLuint) bswap_CARD32(pc + 0),
-                         n,
-                         (const GLdouble *)
-                         bswap_64_array((uint64_t *) (pc + 8), 0));
+    VertexAttribs4dvNV((GLuint) bswap_CARD32(pc + 0),
+                       n,
+                       (const GLdouble *) bswap_64_array((uint64_t *) (pc + 8),
+                                                         0));
 }
 
 void
 __glXDispSwap_VertexAttribs4fvNV(GLbyte * pc)
 {
+    PFNGLVERTEXATTRIBS4FVNVPROC VertexAttribs4fvNV =
+        __glGetProcAddress("glVertexAttribs4fvNV");
     const GLsizei n = (GLsizei) bswap_CARD32(pc + 4);
 
-    glVertexAttribs4fvNV((GLuint) bswap_CARD32(pc + 0),
-                         n,
-                         (const GLfloat *) bswap_32_array((uint32_t *) (pc + 8),
-                                                          0));
+    VertexAttribs4fvNV((GLuint) bswap_CARD32(pc + 0),
+                       n,
+                       (const GLfloat *) bswap_32_array((uint32_t *) (pc + 8),
+                                                        0));
 }
 
 void
 __glXDispSwap_VertexAttribs4svNV(GLbyte * pc)
 {
+    PFNGLVERTEXATTRIBS4SVNVPROC VertexAttribs4svNV =
+        __glGetProcAddress("glVertexAttribs4svNV");
     const GLsizei n = (GLsizei) bswap_CARD32(pc + 4);
 
-    glVertexAttribs4svNV((GLuint) bswap_CARD32(pc + 0),
-                         n,
-                         (const GLshort *) bswap_16_array((uint16_t *) (pc + 8),
-                                                          0));
+    VertexAttribs4svNV((GLuint) bswap_CARD32(pc + 0),
+                       n,
+                       (const GLshort *) bswap_16_array((uint16_t *) (pc + 8),
+                                                        0));
 }
 
 void
 __glXDispSwap_VertexAttribs4ubvNV(GLbyte * pc)
 {
+    PFNGLVERTEXATTRIBS4UBVNVPROC VertexAttribs4ubvNV =
+        __glGetProcAddress("glVertexAttribs4ubvNV");
     const GLsizei n = (GLsizei) bswap_CARD32(pc + 4);
 
-    glVertexAttribs4ubvNV((GLuint) bswap_CARD32(pc + 0),
-                          n, (const GLubyte *) (pc + 8));
+    VertexAttribs4ubvNV((GLuint) bswap_CARD32(pc + 0),
+                        n, (const GLubyte *) (pc + 8));
 }
 
 void
 __glXDispSwap_ActiveStencilFaceEXT(GLbyte * pc)
 {
-    glActiveStencilFaceEXT((GLenum) bswap_ENUM(pc + 0));
+    PFNGLACTIVESTENCILFACEEXTPROC ActiveStencilFaceEXT =
+        __glGetProcAddress("glActiveStencilFaceEXT");
+    ActiveStencilFaceEXT((GLenum) bswap_ENUM(pc + 0));
 }
commit f69f4f417c6807405e45289b39a80f1b9a55f9e6
Author: Keith Packard <keithp at keithp.com>
Date:   Tue Dec 10 07:09:17 2013 -0800

    Depend on latest glproto (1.4.17)
    
    Signed-off-by: Keith Packard <keithp at keithp.com>

diff --git a/configure.ac b/configure.ac
index 11a3e11..a093c19 100644
--- a/configure.ac
+++ b/configure.ac
@@ -782,7 +782,7 @@ DRI3PROTO="dri3proto >= 1.0"
 XINERAMAPROTO="xineramaproto"
 BIGFONTPROTO="xf86bigfontproto >= 1.2.0"
 DGAPROTO="xf86dgaproto >= 2.0.99.1"
-GLPROTO="glproto >= 1.4.16"
+GLPROTO="glproto >= 1.4.17"
 DMXPROTO="dmxproto >= 2.2.99.1"
 VIDMODEPROTO="xf86vidmodeproto >= 2.2.99.1"
 WINDOWSWMPROTO="windowswmproto"
commit 576f3d36dd324bd0d16c9968f1ded5c5eead3569
Author: Adam Jackson <ajax at redhat.com>
Date:   Mon Dec 9 13:16:01 2013 -0500

    damageext: Die if we can't create the Xinerama resource type
    
    Reviewed-by: Keith Packard <keithp at keithp.com>
    Signed-off-by: Adam Jackson <ajax at redhat.com>

diff --git a/damageext/damageext.c b/damageext/damageext.c
index d646923..5650953 100644
--- a/damageext/damageext.c
+++ b/damageext/damageext.c
@@ -725,6 +725,8 @@ void
 PanoramiXDamageInit(void)
 {
     XRT_DAMAGE = CreateNewResourceType(PanoramiXDamageDelete, "XineramaDamage");
+    if (!XRT_DAMAGE)
+        FatalError("Couldn't Xineramify Damage extension\n");
 
     PanoramiXSaveDamageCreate = ProcDamageVector[X_DamageCreate];
     ProcDamageVector[X_DamageCreate] = PanoramiXDamageCreate;
commit f10f36d91db1b21c2ce5a531b4fa5f96fcbdc2f0
Author: Adam Jackson <ajax at redhat.com>
Date:   Mon Sep 16 15:17:26 2013 -0400

    damageext: Xineramify (v7)
    
    v7: Don't bother making resources for the backing listeners. [keithp]
    
    This is now slightly unlike how other resources are xineramified.  We
    create N+1 internal damage listeners, one that's a real resource and
    reflects the protocol view, and then one per backend screen where the
    report function piles onto the protocol view.  The internal listeners
    are not stored in the resource database directly, they just hang off the
    xinerama resource. We don't wrap Subtract at the dispatch level, but we
    do extend it for the Xinerama case to clip to the root window geometry.
    
    As a result of the N+1 design here, the damage reports we generate are
    not quite minimal.  However they are indistinguishable from sequential
    rendering events happening before the client hears damage, and we don't
    need to add a post-dispatch callback just for this one extension.
    
    Add is probably (still) somewhat broken since it will only hit screen 0,
    but Add really only exists for DRI1's sake, and DRI1 disables itself
    with Xinerama enabled anyway.  In the absence of a use case, I'm leaving
    it unwrapped under Xinerama; if someone wants to define how it ought to
    work, be my guest.
    
    Reviewed-by: Keith Packard <keithp at keithp.com>
    Signed-off-by: Adam Jackson <ajax at redhat.com>

diff --git a/Xext/panoramiX.c b/Xext/panoramiX.c
index 15c38a9..ce0d072 100644
--- a/Xext/panoramiX.c
+++ b/Xext/panoramiX.c
@@ -54,6 +54,7 @@ Equipment Corporation.
 #include "resource.h"
 #include "picturestr.h"
 #include "xfixesint.h"
+#include "damageextint.h"
 #ifdef COMPOSITE
 #include "compint.h"
 #endif
@@ -582,6 +583,7 @@ PanoramiXExtensionInit(void)
 
     PanoramiXRenderInit();
     PanoramiXFixesInit();
+    PanoramiXDamageInit();
 #ifdef COMPOSITE
     PanoramiXCompositeInit();
 #endif
@@ -887,6 +889,7 @@ PanoramiXResetProc(ExtensionEntry * extEntry)
 
     PanoramiXRenderReset();
     PanoramiXFixesReset();
+    PanoramiXDamageReset();
 #ifdef COMPOSITE
     PanoramiXCompositeReset ();
 #endif
diff --git a/damageext/damageext.c b/damageext/damageext.c
index 9521c26..d646923 100644
--- a/damageext/damageext.c
+++ b/damageext/damageext.c
@@ -1,5 +1,6 @@
 /*
  * Copyright © 2002 Keith Packard
+ * Copyright 2013 Red Hat, Inc.
  *
  * Permission to use, copy, modify, distribute, and sell this software and its
  * documentation for any purpose is hereby granted without fee, provided that
@@ -25,9 +26,24 @@
 #endif
 
 #include "damageextint.h"
+#include "damagestr.h"
 #include "protocol-versions.h"
 #include "extinit.h"
 
+#ifdef PANORAMIX
+#include "panoramiX.h"
+#include "panoramiXsrv.h"
+
+typedef struct {
+    DamageExtPtr ext;
+    DamagePtr damage[MAXSCREENS];
+} PanoramiXDamageRes;
+
+static RESTYPE XRT_DAMAGE;
+static int (*PanoramiXSaveDamageCreate) (ClientPtr);
+
+#endif
+
 static unsigned char DamageReqCode;
 static int DamageEventBase;
 static RESTYPE DamageExtType;
@@ -37,13 +53,49 @@ static DevPrivateKeyRec DamageClientPrivateKeyRec;
 #define DamageClientPrivateKey (&DamageClientPrivateKeyRec)
 
 static void
+DamageNoteCritical(ClientPtr pClient)
+{
+    DamageClientPtr pDamageClient = GetDamageClient(pClient);
+
+    /* Composite extension marks clients with manual Subwindows as critical */
+    if (pDamageClient->critical > 0) {
+        SetCriticalOutputPending();
+        pClient->smart_priority = SMART_MAX_PRIORITY;
+    }
+}
+
+static void
+damageGetGeometry(DrawablePtr draw, int *x, int *y, int *w, int *h)
+{
+#ifdef PANORAMIX
+    if (!noPanoramiXExtension && draw->type == DRAWABLE_WINDOW) {
+        WindowPtr win = (WindowPtr)draw;
+
+        if (!win->parent) {
+            *x = screenInfo.x;
+            *y = screenInfo.y;
+            *w = screenInfo.width;
+            *h = screenInfo.height;
+            return;
+        }
+    }
+#endif
+
+    *x = draw->x;
+    *y = draw->y;
+    *w = draw->width;
+    *h = draw->height;
+}
+
+static void
 DamageExtNotify(DamageExtPtr pDamageExt, BoxPtr pBoxes, int nBoxes)
 {
     ClientPtr pClient = pDamageExt->pClient;
-    DamageClientPtr pDamageClient = GetDamageClient(pClient);
     DrawablePtr pDrawable = pDamageExt->pDrawable;
     xDamageNotifyEvent ev;
-    int i;
+    int i, x, y, w, h;
+
+    damageGetGeometry(pDrawable, &x, &y, &w, &h);
 
     UpdateCurrentTimeIf();
     ev = (xDamageNotifyEvent) {
@@ -52,10 +104,10 @@ DamageExtNotify(DamageExtPtr pDamageExt, BoxPtr pBoxes, int nBoxes)
         .drawable = pDamageExt->drawable,
         .damage = pDamageExt->id,
         .timestamp = currentTime.milliseconds,
-        .geometry.x = pDrawable->x,
-        .geometry.y = pDrawable->y,
-        .geometry.width = pDrawable->width,
-        .geometry.height = pDrawable->height
+        .geometry.x = x,
+        .geometry.y = y,
+        .geometry.width = w,
+        .geometry.height = h
     };
     if (pBoxes) {
         for (i = 0; i < nBoxes; i++) {
@@ -72,15 +124,12 @@ DamageExtNotify(DamageExtPtr pDamageExt, BoxPtr pBoxes, int nBoxes)
     else {
         ev.area.x = 0;
         ev.area.y = 0;
-        ev.area.width = pDrawable->width;
-        ev.area.height = pDrawable->height;
+        ev.area.width = w;
+        ev.area.height = h;
         WriteEventsToClient(pClient, 1, (xEvent *) &ev);
     }
-    /* Composite extension marks clients with manual Subwindows as critical */
-    if (pDamageClient->critical > 0) {
-        SetCriticalOutputPending();
-        pClient->smart_priority = SMART_MAX_PRIORITY;
-    }
+
+    DamageNoteCritical(pClient);
 }
 
 static void
@@ -162,23 +211,62 @@ ProcDamageQueryVersion(ClientPtr client)
     return Success;
 }
 
-static int
-ProcDamageCreate(ClientPtr client)
+static void
+DamageExtRegister(DrawablePtr pDrawable, DamagePtr pDamage, Bool report)
+{
+    DamageSetReportAfterOp(pDamage, TRUE);
+    DamageRegister(pDrawable, pDamage);
+
+    if (report) {
+        RegionPtr pRegion = &((WindowPtr) pDrawable)->borderClip;
+        RegionTranslate(pRegion, -pDrawable->x, -pDrawable->y);
+        DamageReportDamage(pDamage, pRegion);
+        RegionTranslate(pRegion, pDrawable->x, pDrawable->y);
+    }
+}
+
+static DamageExtPtr
+DamageExtCreate(DrawablePtr pDrawable, DamageReportLevel level,
+                ClientPtr client, XID id, XID drawable)
+{
+    DamageExtPtr pDamageExt = malloc(sizeof(DamageExtRec));
+    if (!pDamageExt)
+        return NULL;
+
+    pDamageExt->id = id;
+    pDamageExt->drawable = drawable;
+    pDamageExt->pDrawable = pDrawable;
+    pDamageExt->level = level;
+    pDamageExt->pClient = client;
+    pDamageExt->pDamage = DamageCreate(DamageExtReport, DamageExtDestroy, level,
+                                       FALSE, pDrawable->pScreen, pDamageExt);
+    if (!pDamageExt->pDamage) {
+        free(pDamageExt);
+        return NULL;
+    }
+
+    if (!AddResource(id, DamageExtType, (pointer) pDamageExt))
+        return NULL;
+
+    DamageExtRegister(pDrawable, pDamageExt->pDamage,
+                      pDrawable->type == DRAWABLE_WINDOW);
+
+    return pDamageExt;
+}
+
+static DamageExtPtr
+doDamageCreate(ClientPtr client, int *rc)
 {
     DrawablePtr pDrawable;
     DamageExtPtr pDamageExt;
     DamageReportLevel level;
-    RegionPtr pRegion;
-    int rc;
 
     REQUEST(xDamageCreateReq);
 
-    REQUEST_SIZE_MATCH(xDamageCreateReq);
-    LEGAL_NEW_RESOURCE(stuff->damage, client);
-    rc = dixLookupDrawable(&pDrawable, stuff->drawable, client, 0,
-                           DixGetAttrAccess | DixReadAccess);
-    if (rc != Success)
-        return rc;
+    *rc = dixLookupDrawable(&pDrawable, stuff->drawable, client, 0,
+                            DixGetAttrAccess | DixReadAccess);
+    if (*rc != Success)
+        return NULL;
 
     switch (stuff->level) {
     case XDamageReportRawRectangles:
@@ -195,39 +283,27 @@ ProcDamageCreate(ClientPtr client)
         break;
     default:
         client->errorValue = stuff->level;
-        return BadValue;
+        *rc = BadValue;
+        return NULL;
     }
 
-    pDamageExt = malloc(sizeof(DamageExtRec));
+    pDamageExt = DamageExtCreate(pDrawable, level, client, stuff->damage,
+                                 stuff->drawable);
     if (!pDamageExt)
-        return BadAlloc;
-    pDamageExt->id = stuff->damage;
-    pDamageExt->drawable = stuff->drawable;
-    pDamageExt->pDrawable = pDrawable;
-    pDamageExt->level = level;
-    pDamageExt->pClient = client;
-    pDamageExt->pDamage = DamageCreate(DamageExtReport,
-                                       DamageExtDestroy,
-                                       level,
-                                       FALSE, pDrawable->pScreen, pDamageExt);
-    if (!pDamageExt->pDamage) {
-        free(pDamageExt);
-        return BadAlloc;
-    }
-    if (!AddResource(stuff->damage, DamageExtType, (pointer) pDamageExt))
-        return BadAlloc;
-
-    DamageSetReportAfterOp(pDamageExt->pDamage, TRUE);
-    DamageRegister(pDamageExt->pDrawable, pDamageExt->pDamage);
+        *rc = BadAlloc;
 
-    if (pDrawable->type == DRAWABLE_WINDOW) {
-        pRegion = &((WindowPtr) pDrawable)->borderClip;
-        RegionTranslate(pRegion, -pDrawable->x, -pDrawable->y);
-        DamageReportDamage(pDamageExt->pDamage, pRegion);
-        RegionTranslate(pRegion, pDrawable->x, pDrawable->y);
-    }
+    return pDamageExt;
+}
 
-    return Success;
+static int
+ProcDamageCreate(ClientPtr client)
+{
+    int rc;
+    REQUEST(xDamageCreateReq);
+    REQUEST_SIZE_MATCH(xDamageCreateReq);
+    LEGAL_NEW_RESOURCE(stuff->damage, client);
+    doDamageCreate(client, &rc);
+    return rc;
 }
 
 static int
@@ -242,6 +318,88 @@ ProcDamageDestroy(ClientPtr client)
     return Success;
 }
 
+#ifdef PANORAMIX
+static RegionPtr
+DamageExtSubtractWindowClip(DamageExtPtr pDamageExt)
+{
+    WindowPtr win = (WindowPtr)pDamageExt->pDrawable;
+    PanoramiXRes *res = NULL;
+    RegionPtr ret;
+    int i;
+
+    if (!win->parent)
+        return &PanoramiXScreenRegion;
+
+    dixLookupResourceByType((void **)&res, win->drawable.id, XRT_WINDOW,
+                            serverClient, DixReadAccess);
+    if (!res)
+        return NULL;
+
+    ret = RegionCreate(NULL, 0);
+    if (!ret)
+        return NULL;
+
+    FOR_NSCREENS_FORWARD(i) {
+        ScreenPtr screen;
+        if (Success != dixLookupWindow(&win, res->info[i].id, serverClient,
+                                       DixReadAccess))
+            goto out;
+
+        screen = win->drawable.pScreen;
+
+        RegionTranslate(ret, -screen->x, -screen->y);
+        if (!RegionUnion(ret, ret, &win->borderClip))
+            goto out;
+        RegionTranslate(ret, screen->x, screen->y);
+    }
+
+    return ret;
+
+out:
+    RegionDestroy(ret);
+    return NULL;
+}
+
+static void
+DamageExtFreeWindowClip(RegionPtr reg)
+{
+    if (reg != &PanoramiXScreenRegion)
+        RegionDestroy(reg);
+}
+#endif
+
+/*
+ * DamageSubtract intersects with borderClip, so we must reconstruct the
+ * protocol's perspective of same...
+ */
+static Bool
+DamageExtSubtract(DamageExtPtr pDamageExt, const RegionPtr pRegion)
+{
+    DamagePtr pDamage = pDamageExt->pDamage;
+
+#ifdef PANORAMIX
+    if (!noPanoramiXExtension) {
+        RegionPtr damage = DamageRegion(pDamage);
+        RegionSubtract(damage, damage, pRegion);
+
+        if (pDamageExt->pDrawable->type == DRAWABLE_WINDOW) {
+            DrawablePtr pDraw = pDamageExt->pDrawable;
+            RegionPtr clip = DamageExtSubtractWindowClip(pDamageExt);
+            if (clip) {
+                RegionTranslate(clip, -pDraw->x, -pDraw->y);
+                RegionIntersect(damage, damage, clip);
+                RegionTranslate(clip, pDraw->x, pDraw->y);
+                DamageExtFreeWindowClip(clip);
+            }
+        }
+
+        return RegionNotEmpty(damage);
+    }
+#endif
+
+    return DamageSubtract(pDamage, pRegion);
+}
+
 static int
 ProcDamageSubtract(ClientPtr client)
 {
@@ -261,7 +419,7 @@ ProcDamageSubtract(ClientPtr client)
         if (pRepair) {
             if (pParts)
                 RegionIntersect(pParts, DamageRegion(pDamage), pRepair);
-            if (DamageSubtract(pDamage, pRepair))
+            if (DamageExtSubtract(pDamageExt, pRepair))
                 DamageExtReport(pDamage, DamageRegion(pDamage),
                                 (void *) pDamageExt);
         }
@@ -271,6 +429,7 @@ ProcDamageSubtract(ClientPtr client)
             DamageEmpty(pDamage);
         }
     }
+
     return Success;
 }
 
@@ -460,6 +619,125 @@ SDamageNotifyEvent(xDamageNotifyEvent * from, xDamageNotifyEvent * to)
     cpswaps(from->geometry.height, to->geometry.height);
 }
 
+#ifdef PANORAMIX
+
+static void
+PanoramiXDamageReport(DamagePtr pDamage, RegionPtr pRegion, void *closure)
+{
+    PanoramiXDamageRes *res = closure;
+    DamageExtPtr pDamageExt = res->ext;
+    WindowPtr pWin = (WindowPtr)pDamage->pDrawable;
+    ScreenPtr pScreen = pDamage->pScreen;
+
+    /* happens on unmap? sigh xinerama */
+    if (RegionNil(pRegion))
+        return;
+
+    /* translate root windows if necessary */
+    if (!pWin->parent)
+        RegionTranslate(pRegion, pScreen->x, pScreen->y);
+
+    /* add our damage to the protocol view */
+    DamageReportDamage(pDamageExt->pDamage, pRegion);
+
+    /* empty our view */
+    DamageEmpty(pDamage);
+}
+
+static void
+PanoramiXDamageExtDestroy(DamagePtr pDamage, void *closure)
+{
+    PanoramiXDamageRes *damage = closure;
+    damage->damage[pDamage->pScreen->myNum] = NULL;
+}
+
+static int
+PanoramiXDamageCreate(ClientPtr client)
+{
+    PanoramiXDamageRes *damage;
+    PanoramiXRes *draw;
+    int i, rc;
+
+    REQUEST(xDamageCreateReq);
+
+    REQUEST_SIZE_MATCH(xDamageCreateReq);
+    LEGAL_NEW_RESOURCE(stuff->damage, client);
+    rc = dixLookupResourceByClass((void **)&draw, stuff->drawable, XRC_DRAWABLE,
+                                  client, DixGetAttrAccess | DixReadAccess);
+    if (rc != Success)
+        return rc;
+
+    if (!(damage = calloc(1, sizeof(PanoramiXDamageRes))))
+        return BadAlloc;
+
+    if (!AddResource(stuff->damage, XRT_DAMAGE, damage))
+        return BadAlloc;
+
+    damage->ext = doDamageCreate(client, &rc);
+    if (rc == Success && draw->type == XRT_WINDOW) {
+        FOR_NSCREENS_FORWARD(i) {
+            DrawablePtr pDrawable;
+            DamagePtr pDamage = DamageCreate(PanoramiXDamageReport,
+                                             PanoramiXDamageExtDestroy,
+                                             DamageReportRawRegion,
+                                             FALSE,
+                                             screenInfo.screens[i],
+                                             damage);
+            if (!pDamage) {
+                rc = BadAlloc;
+            } else {
+                damage->damage[i] = pDamage;
+                rc = dixLookupDrawable(&pDrawable, draw->info[i].id, client,
+                                       M_WINDOW,
+                                       DixGetAttrAccess | DixReadAccess);
+            }
+            if (rc != Success)
+                break;
+
+            DamageExtRegister(pDrawable, pDamage, i != 0);
+        }
+    }
+
+    if (rc != Success)
+        FreeResource(stuff->damage, RT_NONE);
+
+    return rc;
+}
+
+static int
+PanoramiXDamageDelete(void *res, XID id)
+{
+    int i;
+    PanoramiXDamageRes *damage = res;
+
+    FOR_NSCREENS_BACKWARD(i) {
+        if (damage->damage[i]) {
+            DamageDestroy(damage->damage[i]);
+            damage->damage[i] = NULL;
+        }
+    }
+
+    free(damage);
+    return 1;
+}
+
+void
+PanoramiXDamageInit(void)
+{
+    XRT_DAMAGE = CreateNewResourceType(PanoramiXDamageDelete, "XineramaDamage");
+
+    PanoramiXSaveDamageCreate = ProcDamageVector[X_DamageCreate];
+    ProcDamageVector[X_DamageCreate] = PanoramiXDamageCreate;
+}
+
+void
+PanoramiXDamageReset(void)
+{
+    ProcDamageVector[X_DamageCreate] = PanoramiXSaveDamageCreate;
+}
+
+#endif /* PANORAMIX */
+
 void
 DamageExtensionInit(void)
 {
@@ -490,5 +768,10 @@ DamageExtensionInit(void)
             (EventSwapPtr) SDamageNotifyEvent;
         SetResourceTypeErrorValue(DamageExtType,
                                   extEntry->errorBase + BadDamage);
+#ifdef PANORAMIX
+        if (XRT_DAMAGE)
+            SetResourceTypeErrorValue(XRT_DAMAGE,
+                                      extEntry->errorBase + BadDamage);
+#endif
     }
 }
diff --git a/damageext/damageextint.h b/damageext/damageextint.h
index 2723379..e501495 100644
--- a/damageext/damageextint.h
+++ b/damageext/damageextint.h
@@ -67,4 +67,7 @@ typedef struct _DamageExt {
 void
  DamageExtSetCritical(ClientPtr pClient, Bool critical);
 
+void PanoramiXDamageInit(void);
+void PanoramiXDamageReset(void);
+
 #endif                          /* _DAMAGEEXTINT_H_ */
commit 808303fe5232ba0320ae5a4310b1ed1322e85f1d
Author: Adam Jackson <ajax at redhat.com>
Date:   Mon Nov 4 17:49:34 2013 -0500

    fixes: Fix PanoramiXSetWindowShapeRegion for root windows (v2)
    
    Root windows in Xinerama are in the coordinate space of their root window
    pixmap, not in protocol space.
    
    v2: Only translate for root windows, sice the window shape is
    drawable-relative.
    
    Reviewed-by: Keith Packard <keithp at keithp.com>
    Signed-off-by: Adam Jackson <ajax at redhat.com>

diff --git a/xfixes/region.c b/xfixes/region.c
index f2ae851..14a02ba 100644
--- a/xfixes/region.c
+++ b/xfixes/region.c
@@ -857,6 +857,7 @@ PanoramiXFixesSetWindowShapeRegion(ClientPtr client)
 {
     int result = Success, j;
     PanoramiXRes *win;
+    RegionPtr reg = NULL;
 
     REQUEST(xXFixesSetWindowShapeRegionReq);
 
@@ -869,10 +870,22 @@ PanoramiXFixesSetWindowShapeRegion(ClientPtr client)
         return result;
     }
 
+    if (win->u.win.root)
+        VERIFY_REGION_OR_NONE(reg, stuff->region, client, DixReadAccess);
+
     FOR_NSCREENS_FORWARD(j) {
+        ScreenPtr screen = screenInfo.screens[j];
         stuff->dest = win->info[j].id;
+
+        if (reg)
+            RegionTranslate(reg, -screen->x, -screen->y);
+
         result =
             (*PanoramiXSaveXFixesVector[X_XFixesSetWindowShapeRegion]) (client);
+
+        if (reg)
+            RegionTranslate(reg, screen->x, screen->y);
+
         if (result != Success)
             break;
     }
commit 5c10c7ea2129b70015e745523918d143cc29318d
Author: Adam Jackson <ajax at redhat.com>
Date:   Mon Nov 4 17:49:33 2013 -0500

    fixes: Fix PanoramiXSetPictureClipRegion for root windows (v2)
    
    Root windows in Xinerama are in the coordinate space of their root
    window pixmap, not in protocol space.  This fixes 'xcompmgr -n' when
    Xinerama is active.
    
    v2: Only translate for root windows, since the clip origin is
    drawable-relative.
    
    Reviewed-by: Keith Packard <keithp at keithp.com>
    Signed-off-by: Adam Jackson <ajax at redhat.com>

diff --git a/xfixes/region.c b/xfixes/region.c
index 0e9ca44..f2ae851 100644
--- a/xfixes/region.c
+++ b/xfixes/region.c
@@ -886,6 +886,7 @@ PanoramiXFixesSetPictureClipRegion(ClientPtr client)
     REQUEST(xXFixesSetPictureClipRegionReq);
     int result = Success, j;
     PanoramiXRes *pict;
+    RegionPtr reg = NULL;
 
     REQUEST_SIZE_MATCH(xXFixesSetPictureClipRegionReq);
 
@@ -896,10 +897,22 @@ PanoramiXFixesSetPictureClipRegion(ClientPtr client)
         return result;
     }
 
+    if (pict->u.pict.root)
+        VERIFY_REGION_OR_NONE(reg, stuff->region, client, DixReadAccess);
+
     FOR_NSCREENS_BACKWARD(j) {
+        ScreenPtr screen = screenInfo.screens[j];
         stuff->picture = pict->info[j].id;
+
+        if (reg)
+            RegionTranslate(reg, -screen->x, -screen->y);
+
         result =
             (*PanoramiXSaveXFixesVector[X_XFixesSetPictureClipRegion]) (client);
+
+        if (reg)
+            RegionTranslate(reg, screen->x, screen->y);
+
         if (result != Success)
             break;
     }
commit 1dd839a425adc6e5a1dc377003ed86a374d81f0b
Author: Adam Jackson <ajax at redhat.com>
Date:   Thu Nov 7 13:59:30 2013 -0500

    composite: Fix COW creation for Xinerama (v2)
    
    Say you have two 800x600 screens left/right of each other.  A window
    that's 200x200 at +700+0 in protocol coordinate space will appear to be
    at -100+0 in the coordinate space of the right hand screen.  Put another
    way: windows are in the coordinate space of their root window pixmap.
    
    We weren't doing this translation for the COW, so when rendering came in
    to it you'd see the top-left chunk of the COW on all screens.  Cool
    effect and all, but wrong.
    
    v2: Only translate when Xinerama is active [keithp]
    
    Reviewed-by: Keith Packard <keithp at keithp.com>
    Signed-off-by: Adam Jackson <ajax at redhat.com>

diff --git a/composite/compoverlay.c b/composite/compoverlay.c
index d3cfaf0..bf5434c 100644
--- a/composite/compoverlay.c
+++ b/composite/compoverlay.c
@@ -133,16 +133,19 @@ compCreateOverlayWindow(ScreenPtr pScreen)
     int result;
     int w = pScreen->width;
     int h = pScreen->height;
+    int x = 0, y = 0;
 
 #ifdef PANORAMIX
     if (!noPanoramiXExtension) {
+        x = -pScreen->x;
+        y = -pScreen->y;
         w = PanoramiXPixWidth;
         h = PanoramiXPixHeight;
     }
 #endif
 
     pWin = cs->pOverlayWin =
-        CreateWindow(cs->overlayWid, pRoot, 0, 0, w, h, 0,
+        CreateWindow(cs->overlayWid, pRoot, x, y, w, h, 0,
                      InputOutput, CWBackPixmap | CWOverrideRedirect, &attrs[0],
                      pRoot->drawable.depth,
                      serverClient, pScreen->rootVisual, &result);
commit 8dbe456abae1a32fb6c5c74fa456bc7301cccabe
Author: Adam Jackson <ajax at redhat.com>
Date:   Tue Oct 29 10:44:07 2013 -0400

    xinerama: Export the screen region
    
    damageext wants this so it can intersect subtract requests against the
    root window geometry.
    
    Reviewed-by: Keith Packard <keithp at keithp.com>
    Signed-off-by: Adam Jackson <ajax at redhat.com>

diff --git a/Xext/panoramiX.c b/Xext/panoramiX.c
index 2b3a570..15c38a9 100644
--- a/Xext/panoramiX.c
+++ b/Xext/panoramiX.c
@@ -73,7 +73,7 @@ int PanoramiXPixWidth = 0;
 int PanoramiXPixHeight = 0;
 int PanoramiXNumScreens = 0;
 
-static RegionRec PanoramiXScreenRegion = { {0, 0, 0, 0}, NULL };
+_X_EXPORT RegionRec PanoramiXScreenRegion = { {0, 0, 0, 0}, NULL };
 
 static int PanoramiXNumDepths;
 static DepthPtr PanoramiXDepths;
diff --git a/Xext/panoramiXsrv.h b/Xext/panoramiXsrv.h
index 7c605fe..0fcde4f 100644
--- a/Xext/panoramiXsrv.h
+++ b/Xext/panoramiXsrv.h
@@ -11,6 +11,7 @@
 extern _X_EXPORT int PanoramiXNumScreens;
 extern _X_EXPORT int PanoramiXPixWidth;
 extern _X_EXPORT int PanoramiXPixHeight;
+extern _X_EXPORT RegionRec PanoramiXScreenRegion;
 
 extern _X_EXPORT VisualID PanoramiXTranslateVisualID(int screen, VisualID orig);
 extern _X_EXPORT void PanoramiXConsolidate(void);
commit c6d4c2a24140feee4ceae48c4c74fedcae9b68b3
Author: Adam Jackson <ajax at redhat.com>
Date:   Fri Nov 15 15:13:31 2013 -0500

    xfree86: Prefer fbdev to vesa
    
    On UEFI machines you'd prefer fbdev to grab efifb instead of vesa trying
    to initialize and failing in a way we can't unwind from.  On BIOS
    machines this is harmless: either there is an fbdev driver and it'll
    probably be more capable, or there's not and vesa will kick in anyway.
    
    Reviewed-by: Alex Deucher <alexander.deucher at amd.com>
    Reviewed-by: Eric Anholt <eric at anholt.net>
    Signed-off-by: Adam Jackson <ajax at redhat.com>

diff --git a/hw/xfree86/common/xf86AutoConfig.c b/hw/xfree86/common/xf86AutoConfig.c
index 95d58fe..af2b7f8 100644
--- a/hw/xfree86/common/xf86AutoConfig.c
+++ b/hw/xfree86/common/xf86AutoConfig.c
@@ -267,14 +267,6 @@ listPossibleVideoDrivers(char *matches[], int nmatches)
     if (i < (nmatches - 1))
         i = xf86PciMatchDriver(matches, nmatches);
 #endif
-    /* Fallback to platform default hardware */
-    if (i < (nmatches - 1)) {
-#if defined(__i386__) || defined(__amd64__) || defined(__hurd__)
-        matches[i++] = xnfstrdup("vesa");
-#elif defined(__sparc__) && !defined(sun)
-        matches[i++] = xnfstrdup("sunffb");
-#endif
-    }
 
 #if defined(__linux__)
     matches[i++] = xnfstrdup("modesetting");
@@ -290,6 +282,15 @@ listPossibleVideoDrivers(char *matches[], int nmatches)
 #endif
     }
 #endif                          /* !sun */
+
+    /* Fallback to platform default hardware */
+    if (i < (nmatches - 1)) {
+#if defined(__i386__) || defined(__amd64__) || defined(__hurd__)
+        matches[i++] = xnfstrdup("vesa");
+#elif defined(__sparc__) && !defined(sun)
+        matches[i++] = xnfstrdup("sunffb");
+#endif
+    }
 }
 
 /* copy a screen section and enter the desired driver
diff --git a/hw/xfree86/common/xf86Config.c b/hw/xfree86/common/xf86Config.c
index 74d5ed3..b5efc02 100644
--- a/hw/xfree86/common/xf86Config.c
+++ b/hw/xfree86/common/xf86Config.c
@@ -507,7 +507,7 @@ xf86InputDriverlistFromConfig(void)
 static void
 fixup_video_driver_list(char **drivers)
 {
-    static const char *fallback[4] = { "vesa", "fbdev", "wsfb", NULL };
+    static const char *fallback[4] = { "fbdev", "vesa", "wsfb", NULL };
     char **end, **drv;
     char *x;
     int i;
commit 7b5d4f147fdef9edfeaa9c6565375111079efd11
Author: Adam Jackson <ajax at redhat.com>
Date:   Tue Nov 5 10:12:28 2013 -0500

    composite: Don't double-redirect if someone asks for backing store twice
    
    v2: Belt-and-suspenders the unredirection path [vsyrjala]
    
    Reviewed-by: Keith Packard <keithp at keithp.com>
    Signed-off-by: Adam Jackson <ajax at redhat.com>

diff --git a/composite/compinit.c b/composite/compinit.c
index 6431464..3c91091 100644
--- a/composite/compinit.c
+++ b/composite/compinit.c
@@ -117,11 +117,11 @@ compChangeWindowAttributes(WindowPtr pWin, unsigned long mask)
 
     if (ret && (mask & CWBackingStore) &&
         pScreen->backingStoreSupport != NotUseful) {
-        if (pWin->backingStore != NotUseful) {
+        if (pWin->backingStore != NotUseful && !pWin->backStorage) {
             compRedirectWindow(serverClient, pWin, CompositeRedirectAutomatic);
             pWin->backStorage = (pointer) (intptr_t) 1;
         }
-        else {
+        else if (pWin->backingStore == NotUseful && pWin->backStorage) {
             compUnredirectWindow(serverClient, pWin,
                                  CompositeRedirectAutomatic);
             pWin->backStorage = NULL;
commit a2b2c271e0ca87d3188ba2741b6db9bbbdc599f5
Author: Adam Jackson <ajax at redhat.com>
Date:   Tue Nov 5 10:08:17 2013 -0500

    composite: Automatically enable backing store support on the screen
    
    ... unless you explicitly disabled it with -bs on the command line, or
    with the corresponding thing in xorg.conf.
    
    v2: Drop a bogus hunk from compChangeWindowAttributes [vsyrjala]
    v3: s/TRUE/WhenMapped/ [jcristau]
    
    Reviewed-by: Keith Packard <keithp at keithp.com>
    Signed-off-by: Adam Jackson <ajax at redhat.com>

diff --git a/composite/compinit.c b/composite/compinit.c
index bc1130e..6431464 100644
--- a/composite/compinit.c
+++ b/composite/compinit.c
@@ -355,6 +355,9 @@ compScreenInit(ScreenPtr pScreen)
         return FALSE;
     }
 
+    if (!disableBackingStore)
+        pScreen->backingStoreSupport = WhenMapped;
+
     cs->PositionWindow = pScreen->PositionWindow;
     pScreen->PositionWindow = compPositionWindow;
 
diff --git a/hw/xfree86/common/xf86Helper.c b/hw/xfree86/common/xf86Helper.c
index 4f1f3d4..f1e6783 100644
--- a/hw/xfree86/common/xf86Helper.c
+++ b/hw/xfree86/common/xf86Helper.c
@@ -1638,6 +1638,11 @@ xf86SetBackingStore(ScreenPtr pScreen)
     else {
         if (xf86GetOptValBool(options, OPTION_BACKING_STORE, &useBS))
             from = X_CONFIG;
+#ifdef COMPOSITE
+        if (from != X_CONFIG)
+            useBS = xf86ReturnOptValBool(options, OPTION_BACKING_STORE,
+                                         !noCompositeExtension);
+#endif
     }
     free(options);
     pScreen->backingStoreSupport = useBS ? WhenMapped : NotUseful;
commit e0cac005608a2e5618c7be59701318d684e0bb93
Author: Adam Jackson <ajax at redhat.com>
Date:   Tue Nov 5 09:58:17 2013 -0500

    bs: Set the screen's bs support level to WhenMapped
    
    Since we're using RedirectAutomatic to do this, we don't actually
    preserve contents when unmapped.
    
    v2: Don't say WhenMapped if Composite didn't initialize [vsyrjala]
    
    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 92df1eb..0e9109e 100644
--- a/dix/window.c
+++ b/dix/window.c
@@ -530,7 +530,11 @@ CreateRootWindow(ScreenPtr pScreen)
     if (disableBackingStore)
         pScreen->backingStoreSupport = NotUseful;
     if (enableBackingStore)
-        pScreen->backingStoreSupport = Always;
+        pScreen->backingStoreSupport = WhenMapped;
+#ifdef COMPOSITE
+    if (noCompositeExtension)
+        pScreen->backingStoreSupport = NotUseful;
+#endif
 
     pScreen->saveUnderSupport = NotUseful;
 
diff --git a/hw/xfree86/common/xf86Helper.c b/hw/xfree86/common/xf86Helper.c
index 721159d..4f1f3d4 100644
--- a/hw/xfree86/common/xf86Helper.c
+++ b/hw/xfree86/common/xf86Helper.c
@@ -1640,7 +1640,7 @@ xf86SetBackingStore(ScreenPtr pScreen)
             from = X_CONFIG;
     }
     free(options);
-    pScreen->backingStoreSupport = useBS ? Always : NotUseful;
+    pScreen->backingStoreSupport = useBS ? WhenMapped : NotUseful;
     if (serverGeneration == 1)
         xf86DrvMsg(pScreen->myNum, from, "Backing store %s\n",
                    useBS ? "enabled" : "disabled");
commit b61ccd5d9d368f3fbbae27ce14ac02a3db1884c4
Author: Adam Jackson <ajax at redhat.com>
Date:   Tue Nov 5 10:20:04 2013 -0500

    smartsched: Tweak the default scheduler intervals
    
    A default timeslice of 20ms means a pathological client can ruin up to
    two frames per scheduler tick.  And a fifth of a second is just insane.
    
    Pick two different numbers out of the hat.  A 5ms slice means you can
    probably keep up with two or three abusive clients, and letting it burst
    to 15ms should give you about all the timeslice you need for a
    fullscreen game (that's doing server-side rendering for some reason).
    
    If you're running on a system with a 10ms granularity on SIGALRM, then
    this effectively changes the intervals to 10ms and 30ms.  Which is still
    better, just not as better.
    
    I suspect this is about as good as we can do without actually going
    preemptive, which is an entire other nightmare.
    
    Reviewed-by: Julien Cristau <jcristau at debian.org>
    Signed-off-by: Adam Jackson <ajax at redhat.com>

diff --git a/dix/dispatch.c b/dix/dispatch.c
index 4fecfea..8dcd9cb 100644
--- a/dix/dispatch.c
+++ b/dix/dispatch.c
@@ -220,8 +220,9 @@ UpdateCurrentTimeIf(void)
 
 #undef SMART_DEBUG
 
-#define SMART_SCHEDULE_DEFAULT_INTERVAL	20      /* ms */
-#define SMART_SCHEDULE_MAX_SLICE	200     /* ms */
+/* in milliseconds */
+#define SMART_SCHEDULE_DEFAULT_INTERVAL	5
+#define SMART_SCHEDULE_MAX_SLICE	15
 
 #if defined(WIN32) && !defined(__CYGWIN__)
 Bool SmartScheduleDisable = TRUE;
commit 66310ea2893811614b3c3aade8992624a95a6ee7
Author: Adam Jackson <ajax at redhat.com>
Date:   Fri Nov 8 09:22:37 2013 -0500

    dri3: Disable when Xinerama is active
    
    Pretty sure this can't work.
    
    Reviewed-by: Julien Cristau <jcristau at debian.org>
    Signed-off-by: Adam Jackson <ajax at redhat.com>

diff --git a/dri3/dri3.c b/dri3/dri3.c
index 2bca7ae..76e07b4 100644
--- a/dri3/dri3.c
+++ b/dri3/dri3.c
@@ -68,6 +68,11 @@ dri3_extension_init(void)
     ExtensionEntry *extension;
     int i;
 
+#ifdef PANORAMIX
+    if (!noPanoramiXExtension)
+        return;
+#endif
+
     extension = AddExtension(DRI3_NAME, DRI3NumberEvents, DRI3NumberErrors,
                              proc_dri3_dispatch, sproc_dri3_dispatch,
                              NULL, StandardMinorOpcode);
commit 793fd5eefb0e417614d77fe1522c6548587fbd4e
Author: Adam Jackson <ajax at redhat.com>
Date:   Fri Nov 8 09:20:29 2013 -0500

    dri2: Disable when Xinerama is active
    
    Would only work on ScreenRec 0, which means it's broken.
    
    Reviewed-by: Julien Cristau <jcristau at debian.org>
    Signed-off-by: Adam Jackson <ajax at redhat.com>

diff --git a/hw/xfree86/dri2/dri2ext.c b/hw/xfree86/dri2/dri2ext.c
index e1decec..ffd66fa 100644
--- a/hw/xfree86/dri2/dri2ext.c
+++ b/hw/xfree86/dri2/dri2ext.c
@@ -672,6 +672,11 @@ DRI2ExtensionInit(void)
 {
     ExtensionEntry *dri2Extension;
 
+#ifdef PANORAMIX
+    if (!noPanoramiXExtension)
+        return;
+#endif
+
     dri2Extension = AddExtension(DRI2_NAME,
                                  DRI2NumberEvents,
                                  DRI2NumberErrors,
commit 2bf92108294805c5c6fef249c2f7de6ecf4975d8
Author: Adam Jackson <ajax at redhat.com>
Date:   Fri Nov 8 09:06:59 2013 -0500

    present: Disable when Xinerama is active
    
    Among much else Present depends on RANDR types, and RANDR isn't properly
    Xinerama-aware yet anyway.
    
    Reviewed-by: Julien Cristau <jcristau at debian.org>
    Signed-off-by: Adam Jackson <ajax at redhat.com>

diff --git a/present/present_screen.c b/present/present_screen.c
index 2702cd6..25ef681 100644
--- a/present/present_screen.c
+++ b/present/present_screen.c
@@ -206,6 +206,11 @@ present_extension_init(void)
     ExtensionEntry *extension;
     int i;
 
+#ifdef PANORAMIX
+    if (!noPanoramiXExtension)
+        return;
+#endif
+
     extension = AddExtension(PRESENT_NAME, PresentNumberEvents, PresentNumberErrors,
                              proc_present_dispatch, sproc_present_dispatch,
                              NULL, StandardMinorOpcode);
commit ac772cb187ddf7e04b8f4b3a071b90f18f4488d0
Author: Eric Anholt <eric at anholt.net>
Date:   Thu Nov 14 17:40:47 2013 -0800

    glx: Fix incorrect use of dri_interface.h version defines in driver probing.
    
    If we extend __DRI_CORE or __DRI_SWRAST in dri_interface.h to allow a
    new version, it shouldn't make old server code retroactively require
    the new version from swrast drivers.
    
    Notably, new Mesa defines __DRI_SWRAST version 4, but we still want to
    be able to probe version 1 drivers, since we don't use any features
    beyond version 1 of the struct.
    
    Signed-off-by: Keith Packard <keithp at keithp.com>
    Reviewed-by: Ian Romanick <ian.d.romanick at intel.com>

diff --git a/glx/glxdriswrast.c b/glx/glxdriswrast.c
index aa083e0..2d5efa0 100644
--- a/glx/glxdriswrast.c
+++ b/glx/glxdriswrast.c
@@ -443,9 +443,9 @@ __glXDRIscreenProbe(ScreenPtr pScreen)
 
     screen->driver = glxProbeDriver(driverName,
                                     (void **) &screen->core,
-                                    __DRI_CORE, __DRI_CORE_VERSION,
+                                    __DRI_CORE, 1,
                                     (void **) &screen->swrast,
-                                    __DRI_SWRAST, __DRI_SWRAST_VERSION);
+                                    __DRI_SWRAST, 1);
     if (screen->driver == NULL) {
         goto handle_error;
     }
commit 6e926b18ca1b182253bac435a1d53caaff7ffff6
Author: Eric Anholt <eric at anholt.net>
Date:   Thu Nov 14 17:40:46 2013 -0800

    glx: Fix incorrect use of dri_interface.h version defines in extensions.
    
    Those defines are so you can compile-time check "do I have a
    dri_interface.h that defines this new field of the struct?"  You don't
    want the server to claim it implements the new struct just because you
    installed a new copy of Mesa.
    
    Signed-off-by: Keith Packard <keithp at keithp.com>
    Reviewed-by: Ian Romanick <ian.d.romanick at intel.com>

diff --git a/glx/glxdri2.c b/glx/glxdri2.c
index e245e81..a7ee4a3 100644
--- a/glx/glxdri2.c
+++ b/glx/glxdri2.c
@@ -773,7 +773,7 @@ dri2FlushFrontBuffer(__DRIdrawable * driDrawable, void *loaderPrivate)
 }
 
 static const __DRIdri2LoaderExtension loaderExtension = {
-    {__DRI_DRI2_LOADER, __DRI_DRI2_LOADER_VERSION},
+    {__DRI_DRI2_LOADER, 3},
     dri2GetBuffers,
     dri2FlushFrontBuffer,
     dri2GetBuffersWithFormat,
@@ -781,7 +781,7 @@ static const __DRIdri2LoaderExtension loaderExtension = {
 
 #ifdef __DRI_USE_INVALIDATE
 static const __DRIuseInvalidateExtension dri2UseInvalidate = {
-    {__DRI_USE_INVALIDATE, __DRI_USE_INVALIDATE_VERSION}
+    {__DRI_USE_INVALIDATE, 1}
 };
 #endif
 
diff --git a/glx/glxdricommon.c b/glx/glxdricommon.c
index 1022c00..fc90272 100644
--- a/glx/glxdricommon.c
+++ b/glx/glxdricommon.c
@@ -59,7 +59,7 @@ getUST(int64_t * ust)
 }
 
 const __DRIsystemTimeExtension systemTimeExtension = {
-    {__DRI_SYSTEM_TIME, __DRI_SYSTEM_TIME_VERSION},
+    {__DRI_SYSTEM_TIME, 1},
     getUST,
     NULL,
 };
diff --git a/glx/glxdriswrast.c b/glx/glxdriswrast.c
index c9962dc..aa083e0 100644
--- a/glx/glxdriswrast.c
+++ b/glx/glxdriswrast.c
@@ -386,7 +386,7 @@ swrastGetImage(__DRIdrawable * draw,
 }
 
 static const __DRIswrastLoaderExtension swrastLoaderExtension = {
-    {__DRI_SWRAST_LOADER, __DRI_SWRAST_LOADER_VERSION},
+    {__DRI_SWRAST_LOADER, 1},
     swrastGetDrawableInfo,
     swrastPutImage,
     swrastGetImage
commit 57a8ce927332e855dd29ff30210a211a907adb25
Author: Jon TURNEY <jon.turney at dronecode.org.uk>
Date:   Fri Nov 29 12:26:43 2013 +0000

    configure.ac: Fixup for "Require libpciaccess for int10"
    
    On 16/11/2013 01:00, Connor Behan wrote:
    > A --disable-pciaccess build will fail with an int10 module other than
    > stub.
    >
    > Signed-off-by: Connor Behan <connor.behan-Re5JQEeQqe8AvxtiuMwx3w at public.gmane.org>
    > ---
    >  configure.ac | 3 +++
    >  1 file changed, 3 insertions(+)
    >
    > diff --git a/configure.ac b/configure.ac
    > index 5e621e0..a843770 100644
    > --- a/configure.ac
    > +++ b/configure.ac
    > @@ -1822,6 +1822,9 @@ if test "x$XORG" = xyes; then
    >  		if test "x$CONFIG_UDEV_KMS" = xyes; then
    >  			AC_MSG_ERROR([Platform device enumeration requires libpciaccess])
    >  		fi
    > +		if test "x$INT10" != xstub; then
    > +			AC_MSG_ERROR([Cannot build int10 without libpciaccess])
    > +		fi
    >  	fi
    >  	AC_MSG_RESULT([$PCI])
    >
    
    This causes my build to fail where --disable-int10-module --disable-pciaccess
    is the default (as INT10 still has the default value 'x86emu')
    
    Signed-off-by: Jon TURNEY <jon.turney at dronecode.org.uk>
    Reviewed-by: Jeremy Huddleston Sequoia <jeremyhu at apple.com>
    Tested-by: Jeremy Huddleston Sequoia <jeremyhu at apple.com>
    Signed-off-by: Keith Packard <keithp at keithp.com>

diff --git a/configure.ac b/configure.ac
index 5a36e54..11a3e11 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1873,7 +1873,7 @@ if test "x$XORG" = xyes; then
 		if test "x$CONFIG_UDEV_KMS" = xyes; then
 			AC_MSG_ERROR([Platform device enumeration requires libpciaccess])
 		fi
-		if test "x$INT10" != xstub; then
+		if test "x$INT10MODULE" = xyes && test "x$INT10" != xstub; then
 			AC_MSG_ERROR([Cannot build int10 without libpciaccess])
 		fi
 	fi
commit 653d33941b0808ef910aaa5f3aeab05d9c1a100b
Author: Keith Packard <keithp at keithp.com>
Date:   Tue Nov 26 12:18:12 2013 -0800

    present: Report damage when flipping
    
    Limit damage to the 'update' region.
    
    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 251931a..ffbb0b3 100644
--- a/present/present.c
+++ b/present/present.c
@@ -520,6 +520,7 @@ present_execute(present_vblank_ptr vblank, uint64_t ust, uint64_t crtc_msc)
             /* Try to flip
              */
             if (present_flip(vblank->crtc, vblank->event_id, vblank->target_msc, vblank->pixmap, vblank->sync_flip)) {
+                RegionPtr damage;
 
                 /* Fix window pixmaps:
                  *  1) Restore previous flip window pixmap
@@ -530,6 +531,16 @@ present_execute(present_vblank_ptr vblank, uint64_t ust, uint64_t crtc_msc)
                                                (*screen->GetScreenPixmap)(screen));
                 (*screen->SetWindowPixmap)(vblank->window, vblank->pixmap);
                 (*screen->SetWindowPixmap)(screen->root, vblank->pixmap);
+
+                /* Report update region as damaged
+                 */
+                if (vblank->update) {
+                    damage = vblank->update;
+                    RegionIntersect(damage, damage, &window->clipList);
+                } else
+                    damage = &window->clipList;
+
+                DamageDamageRegion(&vblank->window->drawable, damage);
                 return;
             }
 
commit 5cf12c9569ac3d83fe1b7a8376c15f8f0b01655e
Author: Keith Packard <keithp at keithp.com>
Date:   Tue Nov 26 12:10:48 2013 -0800

    present: Also set the root window pixmap when flipping
    
    This makes sure that things like software cursors continue to work
    while the screen is flipped.
    
    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 3fd5e8b..251931a 100644
--- a/present/present.c
+++ b/present/present.c
@@ -324,6 +324,8 @@ present_unflip(ScreenPtr screen)
         (*screen->SetWindowPixmap)(screen_priv->flip_window,
                                    (*screen->GetScreenPixmap)(screen));
 
+    (*screen->SetWindowPixmap)(screen->root, (*screen->GetScreenPixmap)(screen));
+
     /* Update the screen pixmap with the current flip pixmap contents
      */
     if (screen_priv->flip_pixmap && screen_priv->flip_window) {
@@ -527,6 +529,7 @@ present_execute(present_vblank_ptr vblank, uint64_t ust, uint64_t crtc_msc)
                     (*screen->SetWindowPixmap)(screen_priv->flip_window,
                                                (*screen->GetScreenPixmap)(screen));
                 (*screen->SetWindowPixmap)(vblank->window, vblank->pixmap);
+                (*screen->SetWindowPixmap)(screen->root, vblank->pixmap);
                 return;
             }
 
commit 4aa77378de69efdc10bced6ba650b0ebff50c112
Author: Keith Packard <keithp at keithp.com>
Date:   Tue Nov 26 12:06:57 2013 -0800

    present: Clear target_crtc if driver lacks Present support
    
    If the driver doesn't have the necessary hooks for Present, then the
    target_crtc needs to be set to NULL to make sure the extension uses
    the present_fake code.
    
    Signed-off-by: Keith Packard <keithp at keithp.com>
    Tested-by: Fredrik Höglund <fredrik at kde.org>
    Reviewed-by: Adam Jackson <ajax at redhat.com>

diff --git a/present/present.c b/present/present.c
index 76e12ed..3fd5e8b 100644
--- a/present/present.c
+++ b/present/present.c
@@ -594,7 +594,9 @@ present_pixmap(WindowPtr window,
     if (!window_priv)
         return BadAlloc;
 
-    if (!target_crtc) {
+    if (!screen_priv || !screen_priv->info)
+        target_crtc = NULL;
+    else if (!target_crtc) {
         /* Update the CRTC if we have a pixmap or we don't have a CRTC
          */
         if (!pixmap)
commit 3dd5bfe540b295bb37a2c2fd0ba4a31fb217612b
Author: Keith Packard <keithp at keithp.com>
Date:   Thu Nov 21 22:48:31 2013 -0800

    present: Send GLX_BufferSwapComplete events from present extension
    
    This allows GL to support the GLX_INTEL_swap_event extension.
    
    v2: Return GLX_BLIT_COMPLETE_INTEL for unknown swap types
    
    Signed-off-by: Keith Packard <keithp at keithp.com>
    Reviewed-by: Adam Jackson <ajax at redhat.com>

diff --git a/glx/Makefile.am b/glx/Makefile.am
index 5f28e87..44d3a7d 100644
--- a/glx/Makefile.am
+++ b/glx/Makefile.am
@@ -20,7 +20,8 @@ AM_CPPFLAGS = \
 	-I$(top_srcdir)/hw/xfree86/os-support/bus \
 	-I$(top_srcdir)/hw/xfree86/common \
 	-I$(top_srcdir)/hw/xfree86/dri \
-	-I$(top_srcdir)/mi
+	-I$(top_srcdir)/mi \
+	-I$(top_srcdir)/present
 
 if DRI2_AIGLX
 AM_CPPFLAGS += -I$(top_srcdir)/hw/xfree86/dri2
diff --git a/glx/glxcmds.c b/glx/glxcmds.c
index efa4aec..b8da048 100644
--- a/glx/glxcmds.c
+++ b/glx/glxcmds.c
@@ -2468,3 +2468,64 @@ __glXDisp_ClientInfo(__GLXclientState * cl, GLbyte * pc)
 
     return Success;
 }
+
+#include <GL/glxtokens.h>
+
+void
+__glXsendSwapEvent(__GLXdrawable *drawable, int type, CARD64 ust,
+                   CARD64 msc, CARD32 sbc)
+{
+    ClientPtr client = clients[CLIENT_ID(drawable->drawId)];
+
+    xGLXBufferSwapComplete2 wire =  {
+        .type = __glXEventBase + GLX_BufferSwapComplete
+    };
+
+    if (!client)
+        return;
+
+    if (!(drawable->eventMask & GLX_BUFFER_SWAP_COMPLETE_INTEL_MASK))
+        return;
+
+    wire.event_type = type;
+    wire.drawable = drawable->drawId;
+    wire.ust_hi = ust >> 32;
+    wire.ust_lo = ust & 0xffffffff;
+    wire.msc_hi = msc >> 32;
+    wire.msc_lo = msc & 0xffffffff;
+    wire.sbc = sbc;
+
+    WriteEventsToClient(client, 1, (xEvent *) &wire);
+}
+
+#if PRESENT
+static void
+__glXpresentCompleteNotify(WindowPtr window, CARD8 present_mode, CARD32 serial,
+                           uint64_t ust, uint64_t msc)
+{
+    __GLXdrawable *drawable;
+    int glx_type;
+    int rc;
+
+    rc = dixLookupResourceByType((pointer *) &drawable, window->drawable.id,
+                                 __glXDrawableRes, serverClient, DixGetAttrAccess);
+
+    if (rc != Success)
+        return;
+
+    if (present_mode == PresentCompleteModeFlip)
+        glx_type = GLX_FLIP_COMPLETE_INTEL;
+    else
+        glx_type = GLX_BLIT_COMPLETE_INTEL;
+        
+    __glXsendSwapEvent(drawable, glx_type, ust, msc, serial);
+}
+
+#include <present.h>
+
+void
+__glXregisterPresentCompleteNotify(void)
+{
+    present_register_complete_notify(__glXpresentCompleteNotify);
+}
+#endif
diff --git a/glx/glxdri2.c b/glx/glxdri2.c
index fbbd1fd..e245e81 100644
--- a/glx/glxdri2.c
+++ b/glx/glxdri2.c
@@ -177,36 +177,25 @@ __glXdriSwapEvent(ClientPtr client, void *data, int type, CARD64 ust,
                   CARD64 msc, CARD32 sbc)
 {
     __GLXdrawable *drawable = data;
-    xGLXBufferSwapComplete2 wire =  {
-        .type = __glXEventBase + GLX_BufferSwapComplete
-    };
-
-    if (!(drawable->eventMask & GLX_BUFFER_SWAP_COMPLETE_INTEL_MASK))
-        return;
-
+    int glx_type;
     switch (type) {
     case DRI2_EXCHANGE_COMPLETE:
-        wire.event_type = GLX_EXCHANGE_COMPLETE_INTEL;
+        glx_type = GLX_EXCHANGE_COMPLETE_INTEL;
         break;
+    default:
+        /* unknown swap completion type,
+         * BLIT is a reasonable default, so
+         * fall through ...
+         */
     case DRI2_BLIT_COMPLETE:
-        wire.event_type = GLX_BLIT_COMPLETE_INTEL;
+        glx_type = GLX_BLIT_COMPLETE_INTEL;
         break;
     case DRI2_FLIP_COMPLETE:
-        wire.event_type = GLX_FLIP_COMPLETE_INTEL;
-        break;
-    default:
-        /* unknown swap completion type */
-        wire.event_type = 0;
+        glx_type = GLX_FLIP_COMPLETE_INTEL;
         break;
     }
-    wire.drawable = drawable->drawId;
-    wire.ust_hi = ust >> 32;
-    wire.ust_lo = ust & 0xffffffff;
-    wire.msc_hi = msc >> 32;
-    wire.msc_lo = msc & 0xffffffff;
-    wire.sbc = sbc;
-
-    WriteEventsToClient(client, 1, (xEvent *) &wire);
+    
+    __glXsendSwapEvent(drawable, glx_type, ust, msc, sbc);
 }
 
 /*
diff --git a/glx/glxext.c b/glx/glxext.c
index 3a7de28..601d08a 100644
--- a/glx/glxext.c
+++ b/glx/glxext.c
@@ -399,6 +399,9 @@ GlxExtensionInit(void)
 
     __glXErrorBase = extEntry->errorBase;
     __glXEventBase = extEntry->eventBase;
+#if PRESENT
+    __glXregisterPresentCompleteNotify();
+#endif
 }
 
 /************************************************************************/
diff --git a/glx/glxserver.h b/glx/glxserver.h
index 5e29abb..f862b63 100644
--- a/glx/glxserver.h
+++ b/glx/glxserver.h
@@ -120,6 +120,15 @@ void glxResumeClients(void);
 void __glXsetGetProcAddress(void (*(*get_proc_address) (const char *)) (void));
 void *__glGetProcAddress(const char *);
 
+void
+__glXsendSwapEvent(__GLXdrawable *drawable, int type, CARD64 ust,
+                   CARD64 msc, CARD32 sbc);
+
+#if PRESENT
+void
+__glXregisterPresentCompleteNotify(void);
+#endif
+
 /*
 ** State kept per client.
 */
diff --git a/present/present.h b/present/present.h
index 6a451fb..0e3bdc0 100644
--- a/present/present.h
+++ b/present/present.h
@@ -115,4 +115,13 @@ present_event_abandon(RRCrtcPtr crtc);
 extern _X_EXPORT Bool
 present_screen_init(ScreenPtr screen, present_screen_info_ptr info);
 
+typedef void (*present_complete_notify_proc)(WindowPtr window,
+                                             CARD8 mode,
+                                             CARD32 serial,
+                                             uint64_t ust,
+                                             uint64_t msc);
+
+extern _X_EXPORT void
+present_register_complete_notify(present_complete_notify_proc proc);
+
 #endif /* _PRESENT_H_ */
diff --git a/present/present_event.c b/present/present_event.c
index a8f7176..f0d509e 100644
--- a/present/present_event.c
+++ b/present/present_event.c
@@ -137,6 +137,14 @@ present_send_config_notify(WindowPtr window, int x, int y, int w, int h, int bw,
     }
 }
 
+static present_complete_notify_proc complete_notify;
+
+void
+present_register_complete_notify(present_complete_notify_proc proc)
+{
+    complete_notify = proc;
+}
+
 void
 present_send_complete_notify(WindowPtr window, CARD8 kind, CARD8 mode, CARD32 serial, uint64_t ust, uint64_t msc)
 {
@@ -165,6 +173,8 @@ present_send_complete_notify(WindowPtr window, CARD8 kind, CARD8 mode, CARD32 se
             }
         }
     }
+    if (complete_notify)
+        (*complete_notify)(window, mode, serial, ust, msc);
 }
 
 void
commit cde86e68fcb716f34c90f5a16eb868870f5c85e4
Author: Keith Packard <keithp at keithp.com>
Date:   Mon Nov 25 23:06:08 2013 -0800

    present: Set window pixmap to flipped pixmap
    
    This makes other drawing to the window appear on the screen.
    
    Note that no child windows can be affected because only full-screen
    windows are eligible for flipping, and so we only need to set pixmap
    for the window itself.
    
    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 af5bf64..76e12ed 100644
--- a/present/present.c
+++ b/present/present.c
@@ -115,7 +115,8 @@ present_check_flip(RRCrtcPtr    crtc,
     }
 
     /* Make sure the window hasn't been redirected with Composite */
-    if (screen->GetWindowPixmap(window) != screen->GetScreenPixmap(screen))
+    if (screen->GetWindowPixmap(window) != screen->GetScreenPixmap(screen) &&
+        screen->GetWindowPixmap(window) != screen_priv->flip_pixmap)
         return FALSE;
 
     /* Check for full-screen window */
@@ -319,6 +320,10 @@ present_unflip(ScreenPtr screen)
     assert (!screen_priv->unflip_event_id);
     assert (!screen_priv->flip_pending);
 
+    if (screen_priv->flip_window)
+        (*screen->SetWindowPixmap)(screen_priv->flip_window,
+                                   (*screen->GetScreenPixmap)(screen));
+
     /* Update the screen pixmap with the current flip pixmap contents
      */
     if (screen_priv->flip_pixmap && screen_priv->flip_window) {
@@ -486,7 +491,8 @@ static void
 present_execute(present_vblank_ptr vblank, uint64_t ust, uint64_t crtc_msc)
 {
     WindowPtr                   window = vblank->window;
-    present_screen_priv_ptr     screen_priv = present_screen_priv(window->drawable.pScreen);
+    ScreenPtr                   screen = window->drawable.pScreen;
+    present_screen_priv_ptr     screen_priv = present_screen_priv(screen);
 
     if (vblank->wait_fence) {
         if (!present_fence_check_triggered(vblank->wait_fence)) {
@@ -511,8 +517,18 @@ present_execute(present_vblank_ptr vblank, uint64_t ust, uint64_t crtc_msc)
             xorg_list_add(&vblank->event_queue, &present_flip_queue);
             /* Try to flip
              */
-            if (present_flip(vblank->crtc, vblank->event_id, vblank->target_msc, vblank->pixmap, vblank->sync_flip))
+            if (present_flip(vblank->crtc, vblank->event_id, vblank->target_msc, vblank->pixmap, vblank->sync_flip)) {
+
+                /* Fix window pixmaps:
+                 *  1) Restore previous flip window pixmap
+                 *  2) Set current flip window pixmap to the new pixmap
+                 */
+                if (screen_priv->flip_window && screen_priv->flip_window != window)
+                    (*screen->SetWindowPixmap)(screen_priv->flip_window,
+                                               (*screen->GetScreenPixmap)(screen));
+                (*screen->SetWindowPixmap)(vblank->window, vblank->pixmap);
                 return;
+            }
 
             xorg_list_del(&vblank->event_queue);
             /* Oops, flip failed. Clear the flip_pending field
@@ -532,7 +548,7 @@ present_execute(present_vblank_ptr vblank, uint64_t ust, uint64_t crtc_msc)
             /* Check current flip
              */
             if (window == screen_priv->flip_window)
-                present_unflip(window->drawable.pScreen);
+                present_unflip(screen);
         }
         present_copy_region(&window->drawable, vblank->pixmap, vblank->update, vblank->x_off, vblank->y_off);
 
commit 04e138846e128670d409798aa2e797c3c5503a47
Author: Keith Packard <keithp at keithp.com>
Date:   Mon Nov 25 23:10:17 2013 -0800

    present: Leave vblank on window list until flip complete
    
    If the window is destroyed, then we've got cleanup work to do, even if
    the vblank has already been executed -- we need to clear the window
    pointer so that we don't try to deliver events to it.
    
    Leaving it on the window list meant that when walking that list, we
    need to know whether the vblank is waiting to be executed or waiting
    for the flip to complete, so a new 'queued' flag was added to the
    vblank to distinguish between the two states.
    
    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 f446feb..af5bf64 100644
--- a/present/present.c
+++ b/present/present.c
@@ -348,6 +348,8 @@ present_flip_notify(present_vblank_ptr vblank, uint64_t ust, uint64_t crtc_msc)
 
     present_flip_idle(screen);
 
+    xorg_list_del(&vblank->event_queue);
+
     /* Transfer reference for pixmap and fence from vblank to screen_priv */
     screen_priv->flip_crtc = vblank->crtc;
     screen_priv->flip_window = vblank->window;
@@ -378,14 +380,12 @@ present_event_notify(uint64_t event_id, uint64_t ust, uint64_t msc)
     DebugPresent(("\te %lld ust %lld msc %lld\n", event_id, ust, msc));
     xorg_list_for_each_entry_safe(vblank, tmp, &present_exec_queue, event_queue) {
         if (vblank->event_id == event_id) {
-            xorg_list_del(&vblank->event_queue);
             present_execute(vblank, ust, msc);
             return;
         }
     }
     xorg_list_for_each_entry_safe(vblank, tmp, &present_flip_queue, event_queue) {
         if (vblank->event_id == event_id) {
-            xorg_list_del(&vblank->event_queue);
             present_flip_notify(vblank, ust, msc);
             return;
         }
@@ -447,7 +447,7 @@ present_check_flip_window (WindowPtr window)
 
     /* Now check any queued vblanks */
     xorg_list_for_each_entry(vblank, &window_priv->vblank, window_list) {
-        if (vblank->flip && !present_check_flip(vblank->crtc, window, vblank->pixmap, FALSE, NULL, 0, 0))
+        if (vblank->queued && vblank->flip && !present_check_flip(vblank->crtc, window, vblank->pixmap, FALSE, NULL, 0, 0))
             vblank->flip = FALSE;
     }
 }
@@ -496,16 +496,17 @@ present_execute(present_vblank_ptr vblank, uint64_t ust, uint64_t crtc_msc)
     }
 
     xorg_list_del(&vblank->event_queue);
+    vblank->queued = FALSE;
+
     if (vblank->pixmap && vblank->window) {
 
         if (vblank->flip && screen_priv->flip_pending == NULL && !screen_priv->unflip_event_id) {
 
             DebugPresent(("\tf %p %8lld: %08lx -> %08lx\n", vblank, crtc_msc, vblank->pixmap->drawable.id, vblank->window->drawable.id));
-            /* Prepare to flip by removing from the window/screen lists
+            /* Prepare to flip by placing it in the flip queue and
              * and sticking it into the flip_pending field
              */
             screen_priv->flip_pending = vblank;
-            xorg_list_del(&vblank->window_list);
 
             xorg_list_add(&vblank->event_queue, &present_flip_queue);
             /* Try to flip
@@ -701,10 +702,12 @@ present_pixmap(WindowPtr window,
                       target_crtc));
 
     xorg_list_add(&vblank->event_queue, &present_exec_queue);
+    vblank->queued = TRUE;
     if (target_msc >= crtc_msc) {
         ret = present_queue_vblank(screen, target_crtc, vblank->event_id, target_msc);
         if (ret != Success) {
             xorg_list_del(&vblank->event_queue);
+            vblank->queued = FALSE;
             goto failure;
         }
     } else
@@ -737,6 +740,7 @@ present_abort_vblank(ScreenPtr screen, RRCrtcPtr crtc, uint64_t event_id, uint64
     xorg_list_for_each_entry_safe(vblank, tmp, &present_exec_queue, event_queue) {
         if (vblank->event_id == event_id) {
             xorg_list_del(&vblank->event_queue);
+            vblank->queued = FALSE;
             return;
         }
     }
diff --git a/present/present_priv.h b/present/present_priv.h
index 500c7c2..8d3e007 100644
--- a/present/present_priv.h
+++ b/present/present_priv.h
@@ -69,9 +69,10 @@ struct present_vblank {
     present_fence_ptr   wait_fence;
     present_notify_ptr  notifies;
     int                 num_notifies;
-    Bool                flip;
-    Bool                sync_flip;
-    Bool                abort_flip;
+    Bool                queued;         /* on present_exec_queue */
+    Bool                flip;           /* planning on using flip */
+    Bool                sync_flip;      /* do flip synchronous to vblank */
+    Bool                abort_flip;     /* aborting this flip */
 };
 
 typedef struct present_screen_priv {
commit b121d62accb8c346b4e1b1bce99586e13712f04a
Author: Keith Packard <keithp at keithp.com>
Date:   Tue Nov 26 03:07:55 2013 -0800

    present: Add a debug output line when skipping a pending present
    
    When an application provides two pixmaps for the same MSC, the
    previous one is skipped. This just dumps out some information at that point
    
    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 f9eef6b..f446feb 100644
--- a/present/present.c
+++ b/present/present.c
@@ -621,6 +621,11 @@ present_pixmap(WindowPtr window,
             if (vblank->crtc != target_crtc || vblank->target_msc != target_msc)
                 continue;
 
+            DebugPresent(("\tx %lld %p %8lld: %08lx -> %08lx (crtc %p)\n",
+                          vblank->event_id, vblank, target_msc,
+                          vblank->pixmap->drawable.id, vblank->window->drawable.id,
+                          vblank->crtc));
+
             present_pixmap_idle(vblank->pixmap, vblank->window, vblank->serial, vblank->idle_fence);
             present_fence_destroy(vblank->idle_fence);
             dixDestroyPixmap(vblank->pixmap, vblank->pixmap->drawable.id);
commit eafba23b34be31c141ddafb8380520ac9a0622ac
Author: Keith Packard <keithp at keithp.com>
Date:   Thu Nov 21 22:45:18 2013 -0800

    miext/sync: Handle libxshmfence API change
    
    libxshmfence had an unfortunate 'int32_t' type for the mapped fence.
    That changed to exposing a 'struct shmfence' instead, which is nice
    and opaque and offers fine type checking across the API.
    
    This patch requires the newer version of the library and uses
    the new interface type.
    
    Signed-off-by: Keith Packard <keithp at keithp.com>
    Reviewed-by: Julien Cristau <jcristau at debian.org>

diff --git a/configure.ac b/configure.ac
index f6ecdc6..5a36e54 100644
--- a/configure.ac
+++ b/configure.ac
@@ -787,7 +787,7 @@ DMXPROTO="dmxproto >= 2.2.99.1"
 VIDMODEPROTO="xf86vidmodeproto >= 2.2.99.1"
 WINDOWSWMPROTO="windowswmproto"
 APPLEWMPROTO="applewmproto >= 1.4"
-XSHMFENCE="xshmfence"
+XSHMFENCE="xshmfence >= 1.1"
 
 dnl Required modules
 XPROTO="xproto >= 7.0.22"
diff --git a/miext/sync/misyncshm.c b/miext/sync/misyncshm.c
index 20780fd..01f82fc 100644
--- a/miext/sync/misyncshm.c
+++ b/miext/sync/misyncshm.c
@@ -38,7 +38,7 @@
 static DevPrivateKeyRec syncShmFencePrivateKey;
 
 typedef struct _SyncShmFencePrivate {
-    int32_t             *fence;
+    struct xshmfence    *fence;
     int                 fd;
 } SyncShmFencePrivateRec, *SyncShmFencePrivatePtr;
 
commit b6d7ed4d787a652e8150532f384bfdf51760f3c2
Author: Keith Packard <keithp at keithp.com>
Date:   Thu Nov 21 22:12:34 2013 -0800

    miext: Move SyncShm FDs out of the way of clients
    
    Applications may end up allocating a bunch of shmfence objects, each
    of which uses a file descriptor, which must be kept open lest some
    other client ask for a copy of it later on.
    
    Lacking an API that can turn a memory mapping back into a file
    descriptor, about the best we can do is push the file descriptors out
    of the way of other X clients so that we don't run out of the ability
    to accept new connections.
    
    This uses fcntl F_GETFD to push the FD up above MAXCLIENTS.
    
    Signed-off-by: Keith Packard <keithp at keithp.com>
    Reviewed-by: Julien Cristau <jcristau at debian.org>

diff --git a/include/os.h b/include/os.h
index 450e1a8..9b67294 100644
--- a/include/os.h
+++ b/include/os.h
@@ -686,4 +686,7 @@ LogPrintMarkers(void);
 extern _X_EXPORT void
 xorg_backtrace(void);
 
+extern _X_EXPORT int
+os_move_fd(int fd);
+
 #endif                          /* OS_H */
diff --git a/miext/sync/misyncshm.c b/miext/sync/misyncshm.c
index 3f9350a..20780fd 100644
--- a/miext/sync/misyncshm.c
+++ b/miext/sync/misyncshm.c
@@ -32,6 +32,7 @@
 #include "pixmapstr.h"
 #include <sys/mman.h>
 #include <unistd.h>
+#include <fcntl.h>
 #include <X11/xshmfence.h>
 
 static DevPrivateKeyRec syncShmFencePrivateKey;
@@ -126,6 +127,7 @@ miSyncShmCreateFenceFromFd(ScreenPtr pScreen, SyncFence *pFence, int fd, Bool in
 
     miSyncInitFence(pScreen, pFence, initially_triggered);
 
+    fd = os_move_fd(fd);
     pPriv->fence = xshmfence_map_shm(fd);
     if (pPriv->fence) {
         pPriv->fd = fd;
@@ -145,6 +147,7 @@ miSyncShmGetFenceFd(ScreenPtr pScreen, SyncFence *pFence)
         pPriv->fd = xshmfence_alloc_shm();
         if (pPriv->fd < 0)
             return -1;
+        pPriv->fd = os_move_fd(pPriv->fd);
         pPriv->fence = xshmfence_map_shm(pPriv->fd);
         if (!pPriv->fence) {
             close (pPriv->fd);
diff --git a/os/utils.c b/os/utils.c
index fb20da7..608ee6a 100644
--- a/os/utils.c
+++ b/os/utils.c
@@ -2071,3 +2071,27 @@ FormatUInt64Hex(uint64_t num, char *string)
 
     string[len] = '\0';
 }
+
+/* Move a file descriptor out of the way of our select mask; this
+ * is useful for file descriptors which will never appear in the
+ * select mask to avoid reducing the number of clients that can
+ * connect to the server
+ */
+int
+os_move_fd(int fd)
+{
+    int newfd;
+
+#ifdef F_DUPFD_CLOEXEC
+    newfd = fcntl(fd, F_DUPFD_CLOEXEC, MAXCLIENTS);
+#else
+    newfd = fcntl(fd, F_DUPFD, MAXCLIENTS);
+#endif
+    if (newfd < 0)
+        return fd;
+#ifndef F_DUPFD_CLOEXEC
+    fcntl(newfd, F_SETFD, FD_CLOEXEC);
+#endif
+    close(fd);
+    return newfd;
+}
commit cc63204926c6da83d9221c5f8c0dc8f5e2f2481d
Author: Keith Packard <keithp at keithp.com>
Date:   Wed Nov 13 14:16:33 2013 +0900

    Xext: Use SHMDIR and O_TMPFILE when creating mapping files
    
    ShmCreateSegment asks for a file descriptor for a memory mapped file
    created by the X server. This patch uses O_TMPFILE where available,
    and also uses the SHMDIR directory to store the files, both for the
    O_TMPFILE and mkstemp cases.
    
    Signed-off-by: Keith Packard <keithp at keithp.com>
    Reviewed-by: Julien Cristau <jcristau at debian.org>

diff --git a/Xext/shm.c b/Xext/shm.c
index d014b91..1957a95 100644
--- a/Xext/shm.c
+++ b/Xext/shm.c
@@ -37,6 +37,7 @@ in this Software without prior written authorization from The Open Group.
 #include <sys/shm.h>
 #include <unistd.h>
 #include <sys/stat.h>
+#include <fcntl.h>
 #include <X11/X.h>
 #include <X11/Xproto.h>
 #include "misc.h"
@@ -1177,6 +1178,35 @@ ProcShmAttachFd(ClientPtr client)
 }
 
 static int
+shm_tmpfile(void)
+{
+#ifdef SHMDIR
+	int	fd;
+	int	flags;
+	char	template[] = SHMDIR "/shmfd-XXXXXX";
+#ifdef O_TMPFILE
+	fd = open(SHMDIR, O_TMPFILE|O_RDWR|O_CLOEXEC|O_EXCL, 0666);
+	if (fd >= 0) {
+		ErrorF ("Using O_TMPFILE\n");
+		return fd;
+	}
+	ErrorF ("Not using O_TMPFILE\n");
+#endif
+	fd = mkstemp(template);
+	if (fd < 0)
+		return -1;
+	unlink(template);
+	if (fcntl(fd, F_GETFD, &flags) >= 0) {
+		flags |= FD_CLOEXEC;
+		(void) fcntl(fd, F_SETFD, &flags);
+	}
+	return fd;
+#else
+        return -1;
+#endif
+}
+
+static int
 ProcShmCreateSegment(ClientPtr client)
 {
     int fd;
@@ -1188,17 +1218,15 @@ ProcShmCreateSegment(ClientPtr client)
         .sequenceNumber = client->sequence,
         .length = 0,
     };
-    char template[] = "/tmp/shm-XXXXXX";
 
     REQUEST_SIZE_MATCH(xShmCreateSegmentReq);
     if ((stuff->readOnly != xTrue) && (stuff->readOnly != xFalse)) {
         client->errorValue = stuff->readOnly;
         return BadValue;
     }
-    fd = mkstemp(template);
+    fd = shm_tmpfile();
     if (fd < 0)
         return BadAlloc;
-    unlink(template);
     if (ftruncate(fd, stuff->size) < 0) {
         close(fd);
         return BadAlloc;
commit 5a969f0928b84da5cfe0777dfb542caaacc915ad
Author: Keith Packard <keithp at keithp.com>
Date:   Wed Nov 13 12:17:10 2013 +0900

    Select directory for MIT-SHM temp files at configure time
    
    By default, this looks through a list of directories to find one which
    exists, but can be overridden with --with-shared-memory-dir=PATH
    
    This patch doesn't actually do anything with this directory, just
    makes it available in the configuration
    
    Signed-off-by: Keith Packard <keithp at keithp.com>
    Reviewed-by: Julien Cristau <jcristau at debian.org>

diff --git a/configure.ac b/configure.ac
index 6197e9b..f6ecdc6 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1086,6 +1086,49 @@ case "$DRI2,$HAVE_DRI2PROTO" in
 esac
 AM_CONDITIONAL(DRI2, test "x$DRI2" = xyes)
 
+dnl
+dnl Locate a suitable tmp file system for creating shared memeory files
+dnl
+
+AC_ARG_WITH(shared-memory-dir, AS_HELP_STRING([--with-shared-memory-dir=PATH], [Path to directory in a world-writable temporary directory for anonymous shared memory (default: auto)]),
+[],
+[with_shared_memory_dir=yes])
+
+shmdirs="/run/shm /var/tmp /tmp"
+
+case x"$with_shared_memory_dir" in
+xyes)
+	for dir in $shmdirs; do
+		case x"$with_shared_memory_dir" in
+		xyes)
+			echo Checking temp dir "$dir"
+			if test -d "$dir"; then
+				with_shared_memory_dir="$dir"
+			fi
+			;;
+		esac
+	done
+	;;
+x/*)
+	;;
+xno)
+	;;
+*)
+	AC_MSG_ERROR([Invalid directory specified for --with-shared-memory-dir: $with_shared_memory_dir])
+	;;
+esac
+
+case x"$with_shared_memory_dir" in
+xyes)
+	AC_MSG_ERROR([No directory found for shared memory temp files.])
+	;;
+xno)
+	;;
+*)
+	AC_DEFINE_UNQUOTED(SHMDIR, ["$with_shared_memory_dir"], [Directory for shared memory temp files])
+	;;
+esac
+
 AC_ARG_ENABLE(xtrans-send-fds,	AS_HELP_STRING([--disable-xtrans-send-fds], [Use Xtrans support for fd passing (default: auto)]), [XTRANS_SEND_FDS=$enableval], [XTRANS_SEND_FDS=auto])
 
 case "x$XTRANS_SEND_FDS" in
diff --git a/include/dix-config.h.in b/include/dix-config.h.in
index d4fbe99..3066100 100644
--- a/include/dix-config.h.in
+++ b/include/dix-config.h.in
@@ -466,4 +466,7 @@
 /* Wrap SIGBUS to catch MIT-SHM faults */
 #undef BUSFAULT
 
+/* Directory for shared memory temp files */
+#undef SHMDIR
+
 #endif /* _DIX_CONFIG_H_ */


More information about the Xquartz-changes mailing list