xserver: Branch 'mpx' - 70 commits

Peter Hutterer whot at kemper.freedesktop.org
Thu May 1 18:51:15 PDT 2008


 GL/Makefile.am                                      |    7 
 GL/apple/Makefile.am                                |   24 
 GL/apple/aglGlx.c                                   | 1354 -------------
 GL/apple/indirect.c                                 | 1938 -------------------
 GL/glx/Makefile.am                                  |    5 
 GL/glx/glxglcore.c                                  |   83 
 GL/glx/glxscreens.c                                 |   13 
 GL/glx/glxutil.c                                    |   58 
 GL/mesa/.gitignore                                  |   32 
 GL/mesa/Makefile.am                                 |   18 
 GL/mesa/X/Makefile.am                               |   27 
 GL/mesa/glapi/Makefile.am                           |   20 
 GL/mesa/main/Makefile.am                            |   86 
 GL/mesa/math/Makefile.am                            |   27 
 GL/mesa/shader/Makefile.am                          |   39 
 GL/mesa/shader/grammar/Makefile.am                  |   20 
 GL/mesa/shader/slang/Makefile.am                    |   41 
 GL/mesa/swrast/Makefile.am                          |   50 
 GL/mesa/swrast_setup/Makefile.am                    |   20 
 GL/mesa/tnl/Makefile.am                             |   37 
 GL/mesa/vbo/Makefile.am                             |   35 
 GL/symlink-mesa.sh                                  |  166 -
 Xext/EVIstruct.h                                    |   58 
 Xi/exevents.c                                       |    2 
 configure.ac                                        |  158 -
 dix/getevents.c                                     |   19 
 dix/main.c                                          |   19 
 exa/Makefile.am                                     |    1 
 exa/exa.c                                           |    9 
 exa/exa_glyphs.c                                    |  897 +++++++++
 exa/exa_priv.h                                      |   58 
 exa/exa_render.c                                    |  225 ++
 hw/kdrive/Makefile.am                               |    4 
 hw/kdrive/ati/Makefile.am                           |    4 
 hw/kdrive/chips/Makefile.am                         |    4 
 hw/kdrive/ephyr/GL/internal/dri_interface.h         |  517 -----
 hw/kdrive/ephyr/Makefile.am                         |  107 -
 hw/kdrive/ephyr/XF86dri.c                           |    7 
 hw/kdrive/ephyr/ephyr.c                             |   18 
 hw/kdrive/ephyr/ephyrdri.c                          |    7 
 hw/kdrive/ephyr/ephyrdriext.c                       |    4 
 hw/kdrive/ephyr/ephyrglxext.c                       |    5 
 hw/kdrive/ephyr/ephyrhostglx.c                      |    4 
 hw/kdrive/ephyr/hostx.c                             |   11 
 hw/kdrive/ephyr/hostx.h                             |    4 
 hw/kdrive/ephyr/xf86dri.h                           |  120 +
 hw/kdrive/epson/Makefile.am                         |    4 
 hw/kdrive/fake/Makefile.am                          |    4 
 hw/kdrive/fbdev/Makefile.am                         |    4 
 hw/kdrive/fbdev/fbdev.c                             |   26 
 hw/kdrive/i810/Makefile.am                          |    4 
 hw/kdrive/linux/keyboard.c                          |   26 
 hw/kdrive/linux/tslib.c                             |    4 
 hw/kdrive/mach64/Makefile.am                        |    4 
 hw/kdrive/mga/Makefile.am                           |    4 
 hw/kdrive/neomagic/Makefile.am                      |    4 
 hw/kdrive/nvidia/Makefile.am                        |    4 
 hw/kdrive/pm2/Makefile.am                           |    4 
 hw/kdrive/r128/Makefile.am                          |    4 
 hw/kdrive/sdl/Makefile.am                           |    4 
 hw/kdrive/sis300/Makefile.am                        |    4 
 hw/kdrive/smi/Makefile.am                           |    4 
 hw/kdrive/vesa/Makefile.am                          |    4 
 hw/kdrive/via/Makefile.am                           |    4 
 hw/xfree86/common/compiler.h                        |    4 
 hw/xfree86/common/xf86AutoConfig.c                  |  141 -
 hw/xfree86/common/xf86Bus.c                         |    4 
 hw/xfree86/common/xf86Init.c                        |   60 
 hw/xfree86/common/xf86Xinput.c                      |   18 
 hw/xfree86/dixmods/GLcoremodule.c                   |   63 
 hw/xfree86/dixmods/Makefile.am                      |    6 
 hw/xfree86/dixmods/glxmodule.c                      |   37 
 hw/xfree86/dri/dri.c                                |    2 
 hw/xfree86/loader/xf86sym.c                         |    1 
 hw/xfree86/modes/xf86Crtc.h                         |    6 
 hw/xfree86/modes/xf86Rotate.c                       |   21 
 hw/xfree86/os-support/bus/Pci.h                     |    6 
 hw/xfree86/os-support/linux/lnxResource.c           |    1 
 hw/xfree86/os-support/linux/lnx_video.c             |    4 
 hw/xfree86/utils/xorgcfg/expert.c                   |   50 
 hw/xquartz/GL/Makefile.am                           |   13 
 hw/xquartz/GL/indirect.c                            | 1940 ++++++++++++++++++++
 hw/xquartz/Makefile.am                              |    7 
 hw/xquartz/X11Application.h                         |    2 
 hw/xquartz/X11Application.m                         |   71 
 hw/xquartz/X11Controller.h                          |    2 
 hw/xquartz/X11Controller.m                          |    4 
 hw/xquartz/bundle/English.lproj/Localizable.strings |binary
 hw/xquartz/darwin.c                                 |   65 
 hw/xquartz/darwin.h                                 |   35 
 hw/xquartz/darwinEvents.c                           |   65 
 hw/xquartz/darwinEvents.h                           |   37 
 hw/xquartz/pseudoramiX.c                            |   37 
 hw/xquartz/quartz.c                                 |    7 
 hw/xquartz/quartz.h                                 |    1 
 hw/xquartz/quartzCocoa.m                            |    2 
 hw/xquartz/quartzStartup.c                          |   91 
 hw/xquartz/threadSafety.c                           |   16 
 hw/xquartz/threadSafety.h                           |   17 
 hw/xquartz/xpr/Makefile.am                          |   18 
 hw/xquartz/xpr/xprFrame.c                           |   41 
 hw/xquartz/xpr/xprScreen.c                          |   44 
 include/dix-config.h.in                             |    5 
 include/servermd.h                                  |   30 
 104 files changed, 4227 insertions(+), 5225 deletions(-)

New commits:
commit 334456952930cb3e55c02fcdada2d0c074cd0520
Merge: 8e56fd9... 3b8d534...
Author: Peter Hutterer <peter at cs.unisa.edu.au>
Date:   Fri May 2 11:00:14 2008 +0930

    Merge branch 'master' into mpx
    
    Conflicts:
    
    	Xi/exevents.c
    	dix/devices.c

diff --cc Xi/exevents.c
index d0c10d9,641bead..b284547
--- a/Xi/exevents.c
+++ b/Xi/exevents.c
@@@ -2140,7 -1279,9 +2140,9 @@@ SendEventToAllWindows(DeviceIntPtr dev
  
      for (i = 0; i < screenInfo.numScreens; i++) {
          pWin = WindowTable[i];
+         if (!pWin)
+             continue;
 -        (void)DeliverEventsToWindow(pWin, ev, count, mask, NullGrab, dev->id);
 +        (void)DeliverEventsToWindow(dev, pWin, ev, count, mask, NullGrab, dev->id);
          p1 = pWin->firstChild;
          FindInterestedChildren(dev, p1, mask, ev, count);
      }
diff --cc dix/getevents.c
index 414e27e,0229c0a..0879434
--- a/dix/getevents.c
+++ b/dix/getevents.c
@@@ -474,10 -407,9 +474,10 @@@ GetKeyboardValuatorEvents(EventList *ev
                            int num_valuators, int *valuators) {
      int numEvents = 0;
      CARD32 ms = 0;
-     KeySym *map = pDev->key->curKeySyms.map;
-     KeySym sym = map[key_code * pDev->key->curKeySyms.mapWidth];
+     KeySym *map;
+     KeySym sym;
      deviceKeyButtonPointer *kbp = NULL;
 +    DeviceIntPtr master;
  
      if (!events)
          return 0;
@@@ -486,29 -418,20 +486,31 @@@
      if (type != KeyPress && type != KeyRelease)
          return 0;
  
--    if (!pDev->key || !pDev->focus || !pDev->kbdfeed ||
-         (pDev->coreEvents && !inputInfo.keyboard->key))
 -        (pDev->coreEvents && !(inputInfo.keyboard && inputInfo.keyboard->key)))
++    if (!pDev->key || !pDev->focus || !pDev->kbdfeed)
          return 0;
  
 +    numEvents = 1;
 +
      if (key_code < 8 || key_code > 255)
          return 0;
 -    
 +
+     map = pDev->key->curKeySyms.map;
+     sym = map[key_code * pDev->key->curKeySyms.mapWidth];
+ 
 -    if (pDev->coreEvents)
 -        numEvents = 2;
 -    else
 -        numEvents = 1;
 +    master = pDev->u.master;
 +    if (master && master->u.lastSlave != pDev)
 +    {
 +        CreateClassesChangedEvent(events, master, pDev);
 +
 +        if (master->valuator && pDev->valuator)
 +        {
 +            pDev->lastx = master->lastx;
 +            pDev->lasty = master->lasty;
 +        }
 +        master->u.lastSlave = pDev;
 +        numEvents++;
 +        events++;
 +    }
  
      if (num_valuators) {
          if ((num_valuators / 6) + 1 > MAX_VALUATOR_EVENTS)
commit 8e56fd9728d63a7a48ef44503425c6e25c7c9ffb
Author: Peter Hutterer <peter at cs.unisa.edu.au>
Date:   Fri May 2 10:22:06 2008 +0930

    dix: continue to check for invalid valuator ranges.
    
    In an ideal world, the drivers would init all axes with NO_AXIS_LIMIT. In the
    real world, this is an ABI break, so let's just leave the old check in.

diff --git a/dix/getevents.c b/dix/getevents.c
index 6f25fe8..414e27e 100644
--- a/dix/getevents.c
+++ b/dix/getevents.c
@@ -358,7 +358,14 @@ clipAxis(DeviceIntPtr pDev, int axisNum, int *val)
 {
     AxisInfoPtr axis = pDev->valuator->axes + axisNum;
 
-    /* InitValuatoraAxisStruct ensures that (min < max) */
+    /* InitValuatoraAxisStruct ensures that (min < max). */
+
+
+    /* FIXME: drivers need to be updated, evdev e.g. inits axes as min = 0 and
+     * max = -1. Leave this extra check until the drivers have been updated.
+     */
+    if (axis->max_value < axis->min_value)
+        return;
 
     if (axis->min_value != NO_AXIS_LIMITS &&
             *val < axis->min_value)
commit 3b8d53452cd6c74d32d7759964a7cd9ee775f161
Author: Michel Dänzer <michel at tungstengraphics.com>
Date:   Thu May 1 15:10:52 2008 +0200

    EXA: Fall back in CompositeRects if the driver can't accelerate Composite.
    
    Fixes http://bugs.freedesktop.org/show_bug.cgi?id=15780 .

diff --git a/exa/exa_render.c b/exa/exa_render.c
index 43b0029..b480c6d 100644
--- a/exa/exa_render.c
+++ b/exa/exa_render.c
@@ -345,6 +345,9 @@ exaTryDriverCompositeRects(CARD8	       op,
     struct _Pixmap scratch;
     ExaMigrationRec pixmaps[2];
 
+    if (!pExaScr->info->PrepareComposite)
+	return -1;
+
     pSrcPix = exaGetDrawablePixmap(pSrc->pDrawable);
     pSrcExaPix = ExaGetPixmapPriv(pSrcPix);
 
commit 01c61f3d972fc2f4e5bb536dd00d8b6bbeb0fb3d
Author: Paulo Cesar Pereira de Andrade <pcpa at mandriva.com.br>
Date:   Thu May 1 01:02:39 2008 -0300

    xorgcfg: Fix a crash if xorg.conf doesn't have a Files section.
    
    This patch only creates a Files section if required, so if no entries are
    added, an empty Files section will not be created.
    
    Signed-off-by: Peter Hutterer <peter at cs.unisa.edu.au>

diff --git a/hw/xfree86/utils/xorgcfg/expert.c b/hw/xfree86/utils/xorgcfg/expert.c
index bb6960c..484c2ec 100644
--- a/hw/xfree86/utils/xorgcfg/expert.c
+++ b/hw/xfree86/utils/xorgcfg/expert.c
@@ -465,7 +465,7 @@ CreateFiles(TreeNode *files)
     Widget w;
     char *value;
 
-    value = file->file_logfile ? file->file_logfile : "";
+    value = (file && file->file_logfile) ? file->file_logfile : "";
     node = NewNode(files, NULL, NULL, files->node, 
 		   (TreeData*)XtCalloc(1, sizeof(TreeData)));
     CreateFilesField(node, "LogFile", value);
@@ -509,10 +509,14 @@ UpdateFiles(TreeNode *files)
     /* LogFile */
     files = files->child;
     XtVaGetValues(files->data->files.text, XtNstring, &str, NULL);
-    XtFree(XF86Config->conf_files->file_logfile);
-    if (*str)
+    if (XF86Config->conf_files && XF86Config->conf_files->file_logfile)
+	XtFree(XF86Config->conf_files->file_logfile);
+    if (*str) {
+	if (XF86Config->conf_files == NULL)
+	    XF86Config->conf_files = XtCalloc(1, sizeof(XF86ConfFilesRec));
 	XF86Config->conf_files->file_logfile = XtNewString(str);
-    else
+    }
+    else if (XF86Config->conf_files)
 	XF86Config->conf_files->file_logfile = NULL;
 }
 
@@ -527,10 +531,11 @@ CreateFontPath(TreeNode *fontpath, char *path)
     if (path == NULL) {
 	if (XF86Font_path) {
 	    path = XtNewString(XF86Font_path);
-	    if (XF86Config->conf_files && XF86Config->conf_files->file_fontpath) {
+	    if (XF86Config->conf_files && XF86Config->conf_files->file_fontpath)
 		XtFree(XF86Config->conf_files->file_fontpath);
-		XF86Config->conf_files->file_fontpath = XtNewString(path);
-	    }
+	    if (XF86Config->conf_files == NULL)
+		XF86Config->conf_files = XtCalloc(1, sizeof(XF86ConfFilesRec));
+	    XF86Config->conf_files->file_fontpath = XtNewString(path);
 	}
 	else if (XF86Config->conf_files && XF86Config->conf_files->file_fontpath)
 	    path = XtNewString(XF86Config->conf_files->file_fontpath);
@@ -629,9 +634,14 @@ FontPathChanged(TreeNode *node)
 	pos += len - 2;
     }
 
-    if (XF86Config->conf_files->file_fontpath)
-	XtFree(XF86Config->conf_files->file_fontpath);
-    XF86Config->conf_files->file_fontpath = fontpath;
+    if (XF86Config->conf_files) {
+	if (XF86Config->conf_files->file_fontpath)
+	    XtFree(XF86Config->conf_files->file_fontpath);
+    }
+    else if (fontpath)
+	XF86Config->conf_files = XtCalloc(1, sizeof(XF86ConfFilesRec));
+    if (XF86Config->conf_files)
+	XF86Config->conf_files->file_fontpath = fontpath;
 }
 
 static void
@@ -703,10 +713,11 @@ CreateModulePath(TreeNode *modulepath, char *path)
     if (path == NULL) {
 	if (XF86Module_path) {
 	    path = XtNewString(XF86Module_path);
-	    if (XF86Config->conf_files && XF86Config->conf_files->file_modulepath) {
+	    if (XF86Config->conf_files == NULL)
+		XF86Config->conf_files = XtCalloc(1, sizeof(XF86ConfFilesRec));
+	    else if (XF86Config->conf_files->file_modulepath)
 		XtFree(XF86Config->conf_files->file_modulepath);
-		XF86Config->conf_files->file_modulepath = XtNewString(path);
-	    }
+	    XF86Config->conf_files->file_modulepath = XtNewString(path);
 	}
 	else if (XF86Config->conf_files && XF86Config->conf_files->file_modulepath)
 	    path = XtNewString(XF86Config->conf_files->file_modulepath);
@@ -799,9 +810,14 @@ ModulePathChanged(TreeNode *node)
 	pos += len - 2;
     }
 
-    if (XF86Config->conf_files->file_modulepath)
-	XtFree(XF86Config->conf_files->file_modulepath);
-    XF86Config->conf_files->file_modulepath = modulepath;
+    if (XF86Config->conf_files) {
+	if (XF86Config->conf_files->file_modulepath)
+	    XtFree(XF86Config->conf_files->file_modulepath);
+    }
+    else if (modulepath)
+	XF86Config->conf_files = XtCalloc(1, sizeof(XF86ConfFilesRec));
+    if (XF86Config->conf_files)
+	XF86Config->conf_files->file_modulepath = modulepath;
 }
 
 static void
@@ -921,6 +937,8 @@ NewModuleCallback(Widget unused, XtPointer user_data, XtPointer call_data)
     DeleteNode(node);
     load = (XF86LoadPtr)XtCalloc(1, sizeof(XF86LoadRec));
     load->load_name = XtNewString(label);
+    if (XF86Config->conf_modules == NULL)
+	XF86Config->conf_modules = XtCalloc(1, sizeof(XF86ConfModuleRec));
     XF86Config->conf_modules->mod_load_lst =
 	xf86addModule(XF86Config->conf_modules->mod_load_lst, load);
 
commit 6899ff81e8f668382e3e2f9afdd9cdf51d0e0f7d
Author: Paulo Cesar Pereira de Andrade <pcpa at mandriva.com.br>
Date:   Wed Apr 30 16:38:42 2008 -0300

    Fix an off by one read error in drmSIGIOHandler().
    
    Signed-off-by: Peter Hutterer <peter at cs.unisa.edu.au>

diff --git a/hw/xfree86/dri/dri.c b/hw/xfree86/dri/dri.c
index b736c6a..ef1a6ea 100644
--- a/hw/xfree86/dri/dri.c
+++ b/hw/xfree86/dri/dri.c
@@ -2436,7 +2436,7 @@ static void drmSIGIOHandler(int interrupt, void *closure)
 #if 0
 	    fprintf(stderr, "Trying %d\n", entry->fd);
 #endif
-	    if ((count = read(entry->fd, buf, sizeof(buf))) > 0) {
+	    if ((count = read(entry->fd, buf, sizeof(buf) - 1)) > 0) {
 		buf[count] = '\0';
 #if 0
 		fprintf(stderr, "Got %s\n", buf);
commit ec0419b50534006a272278b79ee51538193661cb
Author: Jeremy Huddleston <jeremyhu at freedesktop.org>
Date:   Wed Apr 30 17:30:57 2008 -0700

    XQuartz: Moved some relevant stuff from darwin.h to darwinEvents.h
    (cherry picked from commit 1fcf74a436f2e19cceb3f285b89859025d94c040)

diff --git a/hw/xquartz/darwin.h b/hw/xquartz/darwin.h
index 4300b9f..bdf0046 100644
--- a/hw/xquartz/darwin.h
+++ b/hw/xquartz/darwin.h
@@ -89,38 +89,6 @@ extern int              darwinDesiredRefresh;
 extern int              darwinMainScreenX;
 extern int              darwinMainScreenY;
 
-
-/*
- * Special ddx events understood by the X server
- */
-enum {
-    kXquartzReloadKeymap      // Reload system keymap
-            = LASTEvent+1,    // (from X.h list of event names)
-    kXquartzActivate,         // restore X drawing and cursor
-    kXquartzDeactivate,       // clip X drawing and switch to Aqua cursor
-    kXquartzSetRootClip,      // enable or disable drawing to the X screen
-    kXquartzQuit,             // kill the X server and release the display
-    kXquartzReadPasteboard,   // copy Mac OS X pasteboard into X cut buffer
-    kXquartzWritePasteboard,  // copy X cut buffer onto Mac OS X pasteboard
-    kXquartzBringAllToFront,  // bring all X windows to front
-    kXquartzToggleFullscreen, // Enable/Disable fullscreen mode
-    kXquartzSetRootless,      // Set rootless mode
-    kXquartzSpaceChanged,     // Spaces changed
-    /*
-     * AppleWM events
-     */
-    kXquartzControllerNotify, // send an AppleWMControllerNotify event
-    kXquartzPasteboardNotify, // notify the WM to copy or paste
-    /*
-     * Xplugin notification events
-     */
-    kXquartzDisplayChanged,   // display configuration has changed
-    kXquartzWindowState,      // window visibility state has changed
-    kXquartzWindowMoved,      // window has moved on screen
-};
-
-void DarwinSendDDXEvent(int type, int argc, ...);
-
 #define ENABLE_DEBUG_LOG 1
 
 #ifdef ENABLE_DEBUG_LOG
diff --git a/hw/xquartz/darwinEvents.h b/hw/xquartz/darwinEvents.h
index ef8bf39..a676aeb 100644
--- a/hw/xquartz/darwinEvents.h
+++ b/hw/xquartz/darwinEvents.h
@@ -40,4 +40,36 @@ void DarwinSendScrollEvents(float count_x, float count_y, int pointer_x, int poi
 			    float pressure, float tilt_x, float tilt_y);
 void DarwinUpdateModKeys(int flags);
 
+/*
+ * Special ddx events understood by the X server
+ */
+enum {
+    kXquartzReloadKeymap      // Reload system keymap
+    = LASTEvent+1,    // (from X.h list of event names)
+    kXquartzActivate,         // restore X drawing and cursor
+    kXquartzDeactivate,       // clip X drawing and switch to Aqua cursor
+    kXquartzSetRootClip,      // enable or disable drawing to the X screen
+    kXquartzQuit,             // kill the X server and release the display
+    kXquartzReadPasteboard,   // copy Mac OS X pasteboard into X cut buffer
+    kXquartzWritePasteboard,  // copy X cut buffer onto Mac OS X pasteboard
+    kXquartzBringAllToFront,  // bring all X windows to front
+    kXquartzToggleFullscreen, // Enable/Disable fullscreen mode
+    kXquartzSetRootless,      // Set rootless mode
+    kXquartzSpaceChanged,     // Spaces changed
+    /*
+     * AppleWM events
+     */
+    kXquartzControllerNotify, // send an AppleWMControllerNotify event
+    kXquartzPasteboardNotify, // notify the WM to copy or paste
+    /*
+     * Xplugin notification events
+     */
+    kXquartzDisplayChanged,   // display configuration has changed
+    kXquartzWindowState,      // window visibility state has changed
+    kXquartzWindowMoved,      // window has moved on screen
+};
+
+/* Send one of the above events to the server thread. */
+void DarwinSendDDXEvent(int type, int argc, ...);
+
 #endif  /* _DARWIN_EVENTS_H */
commit 28d1e21f1523d475cb757d3cfa33737ed62c534d
Author: Jeremy Huddleston <jeremyhu at freedesktop.org>
Date:   Wed Apr 30 17:30:32 2008 -0700

    Dix: Cleaned up sanity checking in Get{Pointer,Keyboard}Events
    
    XQuartz was crashing because the Appkit thread was trying to GetXXXEvents while the Xserver thread was exiting.
    This adds some more sanity checks and avoids that crash
    (cherry picked from commit 34ec4bd6acb834c0e3f9a5042a0cc3f52c6f3a68)

diff --git a/dix/getevents.c b/dix/getevents.c
index bf9331e..0229c0a 100644
--- a/dix/getevents.c
+++ b/dix/getevents.c
@@ -407,8 +407,8 @@ GetKeyboardValuatorEvents(xEvent *events, DeviceIntPtr pDev, int type,
                           int num_valuators, int *valuators) {
     int numEvents = 0;
     CARD32 ms = 0;
-    KeySym *map = pDev->key->curKeySyms.map;
-    KeySym sym = map[key_code * pDev->key->curKeySyms.mapWidth];
+    KeySym *map;
+    KeySym sym;
     deviceKeyButtonPointer *kbp = NULL;
 
     if (!events)
@@ -419,11 +419,14 @@ GetKeyboardValuatorEvents(xEvent *events, DeviceIntPtr pDev, int type,
         return 0;
 
     if (!pDev->key || !pDev->focus || !pDev->kbdfeed ||
-        (pDev->coreEvents && !inputInfo.keyboard->key))
+        (pDev->coreEvents && !(inputInfo.keyboard && inputInfo.keyboard->key)))
         return 0;
 
     if (key_code < 8 || key_code > 255)
         return 0;
+    
+    map = pDev->key->curKeySyms.map;
+    sym = map[key_code * pDev->key->curKeySyms.mapWidth];
 
     if (pDev->coreEvents)
         numEvents = 2;
@@ -539,6 +542,9 @@ GetPointerEvents(xEvent *events, DeviceIntPtr pDev, int type, int buttons,
 
     if ((type == ButtonPress || type == ButtonRelease) && !pDev->button)
         return 0;
+    
+    if(pDev->coreEvents && !cp)
+        return 0;
 
     /* FIXME: I guess it should, in theory, be possible to post button events
      *        from devices without valuators. */
commit ce36ae526d88d20ff67cd6cb429fb06f48d231f6
Author: Kazuhiro Inaoka <inaoka.kazuhiro at renesas.com>
Date:   Wed Apr 30 11:58:32 2008 +0300

    Add M32R architecture support (bug #10020)
    
    Still needs autotools support, so this won't actually _build_: it's just
    a starting point.

diff --git a/hw/xfree86/common/compiler.h b/hw/xfree86/common/compiler.h
index 7b65da8..9e7f821 100644
--- a/hw/xfree86/common/compiler.h
+++ b/hw/xfree86/common/compiler.h
@@ -1363,7 +1363,7 @@ do {									\
 #    define write_mem_barrier()   /* NOP */
 
 #    if !defined(__SUNPRO_C)
-#    if !defined(FAKEIT) && !defined(__mc68000__) && !defined(__arm__) && !defined(__sh__) && !defined(__hppa__) && !defined(__s390__)
+#    if !defined(FAKEIT) && !defined(__mc68000__) && !defined(__arm__) && !defined(__sh__) && !defined(__hppa__) && !defined(__s390__) && !defined(__m32r__)
 #     ifdef GCCUSESGAS
 
 /*
@@ -1472,7 +1472,7 @@ inl(unsigned short port)
 
 #     endif /* GCCUSESGAS */
 
-#    else /* !defined(FAKEIT) && !defined(__mc68000__)  && !defined(__arm__) && !defined(__sh__) && !defined(__hppa__)*/
+#    else /* !defined(FAKEIT) && !defined(__mc68000__)  && !defined(__arm__) && !defined(__sh__) && !defined(__hppa__) && !defined(__m32r__) */
 
 static __inline__ void
 outb(unsigned short port, unsigned char val)
diff --git a/hw/xfree86/common/xf86Bus.c b/hw/xfree86/common/xf86Bus.c
index f7ffac8..7e6b93a 100644
--- a/hw/xfree86/common/xf86Bus.c
+++ b/hw/xfree86/common/xf86Bus.c
@@ -2773,7 +2773,7 @@ xf86FindPrimaryDevice()
     }
 }
 
-#if !defined(__sparc) && !defined(__sparc__) && !defined(__powerpc__) && !defined(__mips__) && !defined(__arm__)
+#if !defined(__sparc) && !defined(__sparc__) && !defined(__powerpc__) && !defined(__mips__) && !defined(__arm__) && !defined(__m32r__)
 #include "vgaHW.h"
 #include "compiler.h"
 #endif
@@ -2785,7 +2785,7 @@ static void
 CheckGenericGA()
 {
 /* This needs to be changed for multiple domains */
-#if !defined(__sparc__) && !defined(__sparc) && !defined(__powerpc__) && !defined(__mips__) && !defined(__ia64__) && !defined(__arm__) && !defined(__s390__)
+#if !defined(__sparc__) && !defined(__sparc) && !defined(__powerpc__) && !defined(__mips__) && !defined(__ia64__) && !defined(__arm__) && !defined(__s390__) && !defined(__m32r__)
     IOADDRESS GenericIOBase = VGAHW_GET_IOBASE();
     CARD8 CurrentValue, TestValue;
 
diff --git a/hw/xfree86/os-support/bus/Pci.h b/hw/xfree86/os-support/bus/Pci.h
index b78d307..1385eee 100644
--- a/hw/xfree86/os-support/bus/Pci.h
+++ b/hw/xfree86/os-support/bus/Pci.h
@@ -237,6 +237,12 @@
 # if defined(linux)
 #  define ARCH_PCI_INIT linuxPciInit
 # endif
+#elif defined(__m32r__)
+# if defined(linux)
+#  define ARCH_PCI_INIT linuxPciInit
+#  define INCLUDE_XF86_MAP_PCI_MEM
+#  define INCLUDE_XF86_NO_DOMAIN
+# endif
 #elif defined(__sparc__) || defined(sparc)
 # if defined(linux)
 #  define ARCH_PCI_INIT linuxPciInit
diff --git a/hw/xfree86/os-support/linux/lnxResource.c b/hw/xfree86/os-support/linux/lnxResource.c
index 67af9db..734f4d6 100644
--- a/hw/xfree86/os-support/linux/lnxResource.c
+++ b/hw/xfree86/os-support/linux/lnxResource.c
@@ -65,6 +65,7 @@ xf86AccResFromOS(resPtr ret)
       defined(__sparc__) || \
       defined(__mips__) || \
       defined(__sh__) || \
+      defined(__m32r__) || \
       defined(__mc68000__) || \
       defined(__arm__) || \
       defined(__s390__) || \
diff --git a/hw/xfree86/os-support/linux/lnx_video.c b/hw/xfree86/os-support/linux/lnx_video.c
index 1bd2d57..4295937 100644
--- a/hw/xfree86/os-support/linux/lnx_video.c
+++ b/hw/xfree86/os-support/linux/lnx_video.c
@@ -558,7 +558,7 @@ xf86EnableIO(void)
 #endif
 	}
 	close(fd);
-#elif !defined(__mc68000__) && !defined(__sparc__) && !defined(__mips__) && !defined(__sh__) && !defined(__hppa__) && !defined(__s390__) && !defined(__arm__)
+#elif !defined(__mc68000__) && !defined(__sparc__) && !defined(__mips__) && !defined(__sh__) && !defined(__hppa__) && !defined(__s390__) && !defined(__arm__) && !defined(__m32r__)
         if (ioperm(0, 1024, 1) || iopl(3)) {
                 if (errno == ENODEV)
                         ErrorF("xf86EnableIOPorts: no I/O ports found\n");
@@ -585,7 +585,7 @@ xf86DisableIO(void)
 #if defined(__powerpc__)
 	munmap(ioBase, 0x20000);
 	ioBase = NULL;
-#elif !defined(__mc68000__) && !defined(__sparc__) && !defined(__mips__) && !defined(__sh__) && !defined(__hppa__) && !defined(__arm__) && !defined(__s390__)
+#elif !defined(__mc68000__) && !defined(__sparc__) && !defined(__mips__) && !defined(__sh__) && !defined(__hppa__) && !defined(__arm__) && !defined(__s390__) && !defined(__m32r__)
 	iopl(0);
 	ioperm(0, 1024, 0);
 #endif
diff --git a/include/servermd.h b/include/servermd.h
index 7b0a328..8e6de09 100644
--- a/include/servermd.h
+++ b/include/servermd.h
@@ -217,6 +217,26 @@ SOFTWARE.
 
 #endif /* SuperH */
 
+#if defined(__m32r__)
+
+#if defined(__BIG_ENDIAN__)
+# define IMAGE_BYTE_ORDER      MSBFirst
+# define BITMAP_BIT_ORDER      MSBFirst
+# define GLYPHPADBYTES         4
+# define GETLEFTBITS_ALIGNMENT 1
+#else
+# define IMAGE_BYTE_ORDER      LSBFirst
+# define BITMAP_BIT_ORDER      LSBFirst
+# define GLYPHPADBYTES         4
+# define GETLEFTBITS_ALIGNMENT 1
+#endif
+
+#define AVOID_MEMORY_READ
+#define FAST_CONSTANT_OFFSET_MODE
+#define LARGE_INSTRUCTION_CACHE
+#define PLENTIFUL_REGISTERS
+
+#endif /* __m32r__ */
 
 #if (defined(sun) && (defined(__sparc) || defined(sparc))) || \
     (defined(__uxp__) && (defined(sparc) || defined(mc68000))) || \
commit b71b51c982706501b6229532ce342752207426bb
Author: Ben Byer <bbyer at bushing.apple.com>
Date:   Tue Apr 29 23:37:58 2008 -0700

    xquartz: created darwinTablet, to represent tablet events
    (cherry picked from commit 50641bce730ee03738fa0c4beb8125b34fda556f)

diff --git a/hw/xquartz/darwin.c b/hw/xquartz/darwin.c
index 6f47194..f20cce1 100644
--- a/hw/xquartz/darwin.c
+++ b/hw/xquartz/darwin.c
@@ -1,10 +1,9 @@
 /**************************************************************
  *
- * Shared code for the Darwin X Server
- * running with Quartz or IOKit display mode
+ * Xquartz initialization code
  *
+ * Copyright (c) 2007-2008 Apple Inc.
  * Copyright (c) 2001-2004 Torrey T. Lyons. All Rights Reserved.
- * Copyright (c) 2007 Apple Inc.
  *
  * Permission is hereby granted, free of charge, to any person obtaining a
  * copy of this software and associated documentation files (the "Software"),
@@ -112,6 +111,7 @@ int                     darwinFakeMouse3Mask = NX_COMMANDMASK;
 
 // devices
 DeviceIntPtr            darwinPointer = NULL;
+DeviceIntPtr            darwinTablet = NULL;
 DeviceIntPtr            darwinKeyboard = NULL;
 
 // Common pixmap formats
@@ -332,14 +332,13 @@ static void DarwinChangePointerControl(
 #endif
 
 /*
- * DarwinMouseProc
- *  Handle the initialization, etc. of a mouse
+ * DarwinMouseProc: Handle the initialization, etc. of a mouse
  */
 static int DarwinMouseProc(DeviceIntPtr pPointer, int what) {
+	// 7 buttons: left, right, middle, then four scroll wheel "buttons"
     CARD8 map[8] = {0, 1, 2, 3, 4, 5, 6, 7};
     
     switch (what) {
-            
         case DEVICE_INIT:
             pPointer->public.on = FALSE;
             
@@ -347,15 +346,13 @@ static int DarwinMouseProc(DeviceIntPtr pPointer, int what) {
             InitPointerDeviceStruct((DevicePtr)pPointer, map, 7,
                                     GetMotionHistory,
                                     (PtrCtrlProcPtr)NoopDDA,
-                                    GetMotionHistorySize(), 7);
-            InitProximityClassDeviceStruct(pPointer);
+                                    GetMotionHistorySize(), 2);
+								pPointer->name = strdup("Quartz Pointing Device");
             break;
-            
         case DEVICE_ON:
             pPointer->public.on = TRUE;
             AddEnabledDevice( darwinEventReadFD );
             return Success;
-            
         case DEVICE_CLOSE:
         case DEVICE_OFF:
             pPointer->public.on = FALSE;
@@ -366,6 +363,34 @@ static int DarwinMouseProc(DeviceIntPtr pPointer, int what) {
     return Success;
 }
 
+static int DarwinTabletProc(DeviceIntPtr pPointer, int what) {
+    CARD8 map[4] = {0, 1, 2, 3};
+    
+    switch (what) {
+        case DEVICE_INIT:
+            pPointer->public.on = FALSE;
+            
+            // Set button map.
+            InitPointerDeviceStruct((DevicePtr)pPointer, map, 3,
+                                    GetMotionHistory,
+                                    (PtrCtrlProcPtr)NoopDDA,
+                                    GetMotionHistorySize(), 7);
+            InitProximityClassDeviceStruct(pPointer);
+//			InitAbsoluteClassDeviceStruct(pPointer);
+			pPointer->name = strdup("pen");			
+            break;
+        case DEVICE_ON:
+            pPointer->public.on = TRUE;
+            AddEnabledDevice( darwinEventReadFD );
+            return Success;
+        case DEVICE_CLOSE:
+        case DEVICE_OFF:
+            pPointer->public.on = FALSE;
+            RemoveEnabledDevice(darwinEventReadFD);
+            return Success;
+    }
+    return Success;
+}
 
 /*
  * DarwinKeybdProc
@@ -376,6 +401,7 @@ static int DarwinKeybdProc( DeviceIntPtr pDev, int onoff )
     switch ( onoff ) {
         case DEVICE_INIT:
             DarwinKeyboardInit( pDev );
+			pDev->name = strdup("Quartz Keyboard");
             break;
         case DEVICE_ON:
             pDev->public.on = TRUE;
@@ -499,9 +525,11 @@ int DarwinParseModifierList(
 void InitInput( int argc, char **argv )
 {
     darwinPointer = AddInputDevice(DarwinMouseProc, TRUE);
-	darwinPointer->name = strdup("tablet");
     RegisterPointerDevice( darwinPointer );
 
+    darwinTablet = AddInputDevice(DarwinTabletProc, TRUE);
+    RegisterPointerDevice( darwinTablet );
+
     darwinKeyboard = AddInputDevice(DarwinKeybdProc, TRUE);
     RegisterKeyboardDevice( darwinKeyboard );
 
diff --git a/hw/xquartz/darwin.h b/hw/xquartz/darwin.h
index 6d2fbd0..4300b9f 100644
--- a/hw/xquartz/darwin.h
+++ b/hw/xquartz/darwin.h
@@ -71,6 +71,7 @@ extern io_connect_t     darwinParamConnect;
 extern int              darwinEventReadFD;
 extern int              darwinEventWriteFD;
 extern DeviceIntPtr     darwinPointer;
+extern DeviceIntPtr     darwinTablet;
 extern DeviceIntPtr     darwinKeyboard;
 
 // User preferences
diff --git a/hw/xquartz/darwinEvents.c b/hw/xquartz/darwinEvents.c
index e25ae84..7b3091d 100644
--- a/hw/xquartz/darwinEvents.c
+++ b/hw/xquartz/darwinEvents.c
@@ -365,7 +365,8 @@ void DarwinSendPointerEvents(int ev_type, int ev_button, int pointer_x, int poin
 	static int darwinFakeMouseButtonDown = 0;
 	static int darwinFakeMouseButtonMask = 0;
 	int i, num_events;
-
+	DeviceIntPtr dev;
+	
 //    DEBUG_LOG("x=%d, y=%d, p=%f, tx=%f, ty=%f\n", pointer_x, pointer_y, pressure, tilt_x, tilt_y);
     
 	if(!darwinEvents) {
@@ -376,7 +377,10 @@ void DarwinSendPointerEvents(int ev_type, int ev_button, int pointer_x, int poin
 	int valuators[5] = {pointer_x, pointer_y, pressure * SCALEFACTOR_PRESSURE, 
 		      tilt_x * SCALEFACTOR_TILT, tilt_y * SCALEFACTOR_TILT};
 	
-		DEBUG_LOG("Valuators: {%d,%d,%d,%d,%d}\n", 
+	if (pressure == 0 && tilt_x == 0 && tilt_y == 0) dev = darwinPointer;
+	else dev = darwinTablet;
+
+	DEBUG_LOG("Valuators: {%d,%d,%d,%d,%d}\n", 
 			valuators[0], valuators[1], valuators[2], valuators[3], valuators[4]);
 	if (ev_type == ButtonPress && darwinFakeButtons && ev_button == 1) {
 		// Mimic multi-button mouse with modifier-clicks
@@ -410,9 +414,9 @@ void DarwinSendPointerEvents(int ev_type, int ev_button, int pointer_x, int poin
 	} 
 
     mieqEnqueue_lock(); {
-        num_events = GetPointerEvents(darwinEvents, darwinPointer, ev_type, ev_button, 
-                                      POINTER_ABSOLUTE, 0, 5, valuators);
-        for(i=0; i<num_events; i++) mieqEnqueue (darwinPointer,&darwinEvents[i]);
+        num_events = GetPointerEvents(darwinEvents, dev, ev_type, ev_button, 
+                                      POINTER_ABSOLUTE, 0, dev==darwinTablet?5:2, valuators);
+        for(i=0; i<num_events; i++) mieqEnqueue (dev,&darwinEvents[i]);
         DarwinPokeEQ();
 
     } mieqEnqueue_unlock();
@@ -460,9 +464,9 @@ void DarwinSendProximityEvents(int ev_type, int pointer_x, int pointer_y) {
 	}
 
     mieqEnqueue_lock(); {
-        num_events = GetProximityEvents(darwinEvents, darwinPointer, ev_type,
+        num_events = GetProximityEvents(darwinEvents, darwinTablet, ev_type,
                                         0, 5, valuators);
-        for(i=0; i<num_events; i++) mieqEnqueue (darwinPointer,&darwinEvents[i]);
+        for(i=0; i<num_events; i++) mieqEnqueue (darwinTablet,&darwinEvents[i]);
         DarwinPokeEQ();
     } mieqEnqueue_unlock();
 }
commit 519581b0bab5cc6dac397877da485745f18c2120
Author: Ben Byer <bbyer at bushing.apple.com>
Date:   Tue Apr 29 23:00:09 2008 -0700

    xquartz: remove unused params from DarwinEQInit
    (cherry picked from commit 299a056737168ca1faefd675dce6d6ab13176be9)

diff --git a/hw/xquartz/darwin.c b/hw/xquartz/darwin.c
index c18b575..6f47194 100644
--- a/hw/xquartz/darwin.c
+++ b/hw/xquartz/darwin.c
@@ -499,12 +499,13 @@ int DarwinParseModifierList(
 void InitInput( int argc, char **argv )
 {
     darwinPointer = AddInputDevice(DarwinMouseProc, TRUE);
+	darwinPointer->name = strdup("tablet");
     RegisterPointerDevice( darwinPointer );
 
     darwinKeyboard = AddInputDevice(DarwinKeybdProc, TRUE);
     RegisterKeyboardDevice( darwinKeyboard );
 
-    DarwinEQInit( (DevicePtr)darwinKeyboard, (DevicePtr)darwinPointer );
+    DarwinEQInit();
 
     QuartzInitInput(argc, argv);
 }
diff --git a/hw/xquartz/darwinEvents.c b/hw/xquartz/darwinEvents.c
index cd2b49a..e25ae84 100644
--- a/hw/xquartz/darwinEvents.c
+++ b/hw/xquartz/darwinEvents.c
@@ -307,7 +307,7 @@ static void DarwinEventHandler(int screenNum, xEventPtr xe, DeviceIntPtr dev, in
     }
 }
 
-Bool DarwinEQInit(DevicePtr pKbd, DevicePtr pPtr) { 
+Bool DarwinEQInit(void) { 
     if (!darwinEvents)
         darwinEvents = (xEvent *)xcalloc(sizeof(xEvent), GetMaximumEventsNum());
     if (!darwinEvents)
diff --git a/hw/xquartz/darwinEvents.h b/hw/xquartz/darwinEvents.h
index 4a619c9..ef8bf39 100644
--- a/hw/xquartz/darwinEvents.h
+++ b/hw/xquartz/darwinEvents.h
@@ -28,7 +28,7 @@
 #ifndef _DARWIN_EVENTS_H
 #define _DARWIN_EVENTS_H
 
-Bool DarwinEQInit(DevicePtr pKbd, DevicePtr pPtr);
+Bool DarwinEQInit(void);
 void DarwinEQEnqueue(const xEventPtr e);
 void DarwinEQPointerPost(DeviceIntPtr pDev, xEventPtr e);
 void DarwinEQSwitchScreen(ScreenPtr pScreen, Bool fromDIX);
commit d70487a4c09cfeb90d996ab40a23a74b2c15be6f
Author: Jeremy Huddleston <jeremyhu at freedesktop.org>
Date:   Tue Apr 29 23:59:26 2008 -0700

    XQuartz: Fix to tablet-event handling code; we now scale
    more conservatively (to match Linux's Wacom driver) and
    we now receive all tablet-related events.
    (cherry picked from commit 588683cecca2cfc65a28de035cd6ee3d64ff59d2)

diff --git a/hw/xquartz/X11Application.m b/hw/xquartz/X11Application.m
index e10e71e..646b9ef 100644
--- a/hw/xquartz/X11Application.m
+++ b/hw/xquartz/X11Application.m
@@ -49,6 +49,13 @@
 
 #define DEFAULTS_FILE "/usr/X11/lib/X11/xserver/Xquartz.plist"
 
+#ifndef XSERVER_VERSION
+#define XSERVER_VERSION "?"
+#endif
+
+#define ProximityIn    0
+#define ProximityOut   1
+
 int X11EnableKeyEquivalents = TRUE;
 int quartzHasRoot = FALSE, quartzEnableRootless = TRUE;
 
@@ -852,27 +859,37 @@ static void send_nsevent (NSEventType type, NSEvent *e) {
 	tilt_y = 0;
 
 	switch (type) {
-		case NSLeftMouseDown:    ev_button=1; ev_type=ButtonPress; goto handle_mouse;
-		case NSOtherMouseDown:   ev_button=2; ev_type=ButtonPress; goto handle_mouse;
-		case NSRightMouseDown:   ev_button=3; ev_type=ButtonPress; goto handle_mouse;
-		case NSLeftMouseUp:      ev_button=1; ev_type=ButtonRelease; goto handle_mouse;
-		case NSOtherMouseUp:     ev_button=2; ev_type=ButtonRelease; goto handle_mouse;
-		case NSRightMouseUp:     ev_button=3; ev_type=ButtonRelease; goto handle_mouse;
-		case NSLeftMouseDragged:  ev_button=1; ev_type=MotionNotify; goto handle_mouse;
-		case NSOtherMouseDragged: ev_button=2; ev_type=MotionNotify; goto handle_mouse;
-		case NSRightMouseDragged: ev_button=3; ev_type=MotionNotify; goto handle_mouse;
+		case NSLeftMouseDown:    ev_button=1; ev_type=ButtonPress; goto check_subtype;
+		case NSOtherMouseDown:   ev_button=2; ev_type=ButtonPress; goto check_subtype;
+		case NSRightMouseDown:   ev_button=3; ev_type=ButtonPress; goto check_subtype;
+		case NSLeftMouseUp:      ev_button=1; ev_type=ButtonRelease; goto check_subtype;
+		case NSOtherMouseUp:     ev_button=2; ev_type=ButtonRelease; goto check_subtype;
+		case NSRightMouseUp:     ev_button=3; ev_type=ButtonRelease; goto check_subtype;
+		case NSLeftMouseDragged:  ev_button=1; ev_type=MotionNotify; goto check_subtype;
+		case NSOtherMouseDragged: ev_button=2; ev_type=MotionNotify; goto check_subtype;
+		case NSRightMouseDragged: ev_button=3; ev_type=MotionNotify; goto check_subtype;
+		
+check_subtype:
+			if ([e subtype] != NSTabletPointEventSubtype) goto handle_mouse;
+			// fall through to get tablet data
 		case NSTabletPoint:
 			pressure = [e pressure];
 			tilt_x = [e tilt].x;
-			tilt_y = [e tilt].y; // fall through
+			tilt_y = [e tilt].y; 
+			// fall through to normal mouse handling
+
 		case NSMouseMoved: ev_button=0; ev_type=MotionNotify; goto handle_mouse;
-		handle_mouse:
 
-//      if ([e subtype] == NSTabletPointEventSubtype) pressure = [e pressure];
+handle_mouse:
 		DarwinSendPointerEvents(ev_type, ev_button, pointer_x, pointer_y,
 			pressure, tilt_x, tilt_y);
 		break;
 
+		case NSTabletProximity:
+			DarwinSendProximityEvents([e isEnteringProximity]?ProximityIn:ProximityOut,
+				pointer_x, pointer_y);
+		break;
+
 		case NSScrollWheel:
 			DarwinSendScrollEvents([e deltaX], [e deltaY], pointer_x, pointer_y,
 				pressure, tilt_x, tilt_y);
diff --git a/hw/xquartz/darwinEvents.c b/hw/xquartz/darwinEvents.c
index 86e7704..cd2b49a 100644
--- a/hw/xquartz/darwinEvents.c
+++ b/hw/xquartz/darwinEvents.c
@@ -65,6 +65,10 @@ in this Software without prior written authorization from The Open Group.
 #define SCROLLWHEELLEFTFAKE  6
 #define SCROLLWHEELRIGHTFAKE 7
 
+/* These values were chosen to match the output of xinput under Linux */
+#define SCALEFACTOR_TILT        64.0
+#define SCALEFACTOR_PRESSURE    1000.0
+
 #define _APPLEWM_SERVER_
 #include "applewmExt.h"
 #include <X11/extensions/applewm.h>
@@ -362,26 +366,18 @@ void DarwinSendPointerEvents(int ev_type, int ev_button, int pointer_x, int poin
 	static int darwinFakeMouseButtonMask = 0;
 	int i, num_events;
 
-    //DEBUG_LOG("x=%d, y=%d, p=%f, tx=%f, ty=%f\n", pointer_x, pointer_y, pressure, tilt_x, tilt_y);
+//    DEBUG_LOG("x=%d, y=%d, p=%f, tx=%f, ty=%f\n", pointer_x, pointer_y, pressure, tilt_x, tilt_y);
     
 	if(!darwinEvents) {
 		ErrorF("DarwinSendPointerEvents called before darwinEvents was initialized\n");
 		return;
 	}
-	/* I can't find a spec for this, but at least GTK expects that tablets are
-     just like mice, except they have either one or three extra valuators, in this
-     order:
-     
-     X coord, Y coord, pressure, X tilt, Y tilt
-     Pressure and tilt should be represented natively as floats; unfortunately,
-     we can't do that.  Again, GTK seems to record the min/max of each valuator,
-     and then perform scaling back to float itself using that info. Soo.... */
-
-	int valuators[5] = {pointer_x, pointer_y, 
-		      pressure * INT32_MAX * 1.0f, 
-		      tilt_x * INT32_MAX * 1.0f, 
-		      tilt_y * INT32_MAX * 1.0f};
 
+	int valuators[5] = {pointer_x, pointer_y, pressure * SCALEFACTOR_PRESSURE, 
+		      tilt_x * SCALEFACTOR_TILT, tilt_y * SCALEFACTOR_TILT};
+	
+		DEBUG_LOG("Valuators: {%d,%d,%d,%d,%d}\n", 
+			valuators[0], valuators[1], valuators[2], valuators[3], valuators[4]);
 	if (ev_type == ButtonPress && darwinFakeButtons && ev_button == 1) {
 		// Mimic multi-button mouse with modifier-clicks
 		// If both sets of modifiers are pressed,
@@ -450,16 +446,16 @@ void DarwinSendKeyboardEvents(int ev_type, int keycode) {
     } mieqEnqueue_unlock();
 }
 
-void DarwinSendProximityEvents(int ev_type, int pointer_x, int pointer_y, 
-			       float pressure, float tilt_x, float tilt_y) {
+void DarwinSendProximityEvents(int ev_type, int pointer_x, int pointer_y) {
 	int i, num_events;
-	int valuators[5] = {pointer_x, pointer_y, 
-		      pressure * INT32_MAX * 1.0f, 
-		      tilt_x * INT32_MAX * 1.0f, 
-		      tilt_y * INT32_MAX * 1.0f};
 
+	// tilt and pressure have no meaning for a Prox event
+	int valuators[5] = {pointer_x, pointer_y, 0, 0, 0};  
+
+	DEBUG_LOG("DarwinSendProximityEvents(%d, %d, %d)\n", ev_type, pointer_x, pointer_y);
+	
 	if(!darwinEvents) {
-		ErrorF("DarwinSendProximityvents called before darwinEvents was initialized\n");
+		ErrorF("DarwinSendProximityEvents called before darwinEvents was initialized\n");
 		return;
 	}
 
diff --git a/hw/xquartz/darwinEvents.h b/hw/xquartz/darwinEvents.h
index dd3f81c..4a619c9 100644
--- a/hw/xquartz/darwinEvents.h
+++ b/hw/xquartz/darwinEvents.h
@@ -34,8 +34,7 @@ void DarwinEQPointerPost(DeviceIntPtr pDev, xEventPtr e);
 void DarwinEQSwitchScreen(ScreenPtr pScreen, Bool fromDIX);
 void DarwinSendPointerEvents(int ev_type, int ev_button, int pointer_x, int pointer_y,
 			     float pressure, float tilt_x, float tilt_y);
-void DarwinSendProximityEvents(int ev_type, int pointer_x, int pointer_y, 
-			       float pressure, float tilt_x, float tilt_y);
+void DarwinSendProximityEvents(int ev_type, int pointer_x, int pointer_y);
 void DarwinSendKeyboardEvents(int ev_type, int keycode);
 void DarwinSendScrollEvents(float count_x, float count_y, int pointer_x, int pointer_y,
 			    float pressure, float tilt_x, float tilt_y);
commit f65a1a62f9eac2f6620d5d469dbf6c79b2eadab7
Author: Hong Liu <hong.liu at intel.com>
Date:   Tue Apr 29 09:00:11 2008 -0700

    Keep rotation wrappers in place while transforms are in use
    
    LeaveVT/EnterVT cycles will free/realloc shadow frame buffers. Because of
    this, the presense/absence of that data is insufficient to know whether
    the screen function wrappers are necessary. Instead, the 'transform_in_use'
    flag should be used.
    
    This patch also adds 'xf86RotateFreeShadow' for drivers to use at LeaveVT
    time to free the rotation data; it will be reallocated on EnterVT.

diff --git a/hw/xfree86/loader/xf86sym.c b/hw/xfree86/loader/xf86sym.c
index 24fc44c..9833d34 100644
--- a/hw/xfree86/loader/xf86sym.c
+++ b/hw/xfree86/loader/xf86sym.c
@@ -942,6 +942,7 @@ _X_HIDDEN void *xfree86LookupTab[] = {
     SYMFUNC(xf86CrtcDestroy)
     SYMFUNC(xf86CrtcInUse)
     SYMFUNC(xf86CrtcSetScreenSubpixelOrder)
+    SYMFUNC(xf86RotateFreeShadow)
     SYMFUNC(xf86RotateCloseScreen)
     SYMFUNC(xf86CrtcRotate)
     SYMFUNC(xf86CrtcSetMode)
diff --git a/hw/xfree86/modes/xf86Crtc.h b/hw/xfree86/modes/xf86Crtc.h
index 2d723a5..83b1f13 100644
--- a/hw/xfree86/modes/xf86Crtc.h
+++ b/hw/xfree86/modes/xf86Crtc.h
@@ -665,6 +665,12 @@ Bool
 xf86CrtcRotate (xf86CrtcPtr crtc, DisplayModePtr mode, Rotation rotation);
 
 /*
+ * free shadow memory allocated for all crtcs
+ */
+void
+xf86RotateFreeShadow(ScrnInfoPtr pScrn);
+
+/*
  * Clean up rotation during CloseScreen
  */
 void
diff --git a/hw/xfree86/modes/xf86Rotate.c b/hw/xfree86/modes/xf86Rotate.c
index e2d6295..8f34032 100644
--- a/hw/xfree86/modes/xf86Rotate.c
+++ b/hw/xfree86/modes/xf86Rotate.c
@@ -457,8 +457,7 @@ xf86RotateDestroy (xf86CrtcPtr crtc)
     }
 
     for (c = 0; c < xf86_config->num_crtc; c++)
-	if (xf86_config->crtc[c]->rotatedPixmap ||
-	    xf86_config->crtc[c]->rotatedData)
+	if (xf86_config->crtc[c]->transform_in_use)
 	    return;
 
     /*
@@ -479,6 +478,24 @@ xf86RotateDestroy (xf86CrtcPtr crtc)
 }
 
 _X_EXPORT void
+xf86RotateFreeShadow(ScrnInfoPtr pScrn)
+{
+    xf86CrtcConfigPtr config = XF86_CRTC_CONFIG_PTR(pScrn);
+    int c;
+
+   for (c = 0; c < config->num_crtc; c++) {
+       xf86CrtcPtr crtc = config->crtc[c];
+
+       if (crtc->rotatedPixmap || crtc->rotatedData) {
+	   crtc->funcs->shadow_destroy(crtc, crtc->rotatedPixmap,
+				crtc->rotatedData);
+	   crtc->rotatedPixmap = NULL;
+	   crtc->rotatedData = NULL;
+       }
+   }
+}
+
+_X_EXPORT void
 xf86RotateCloseScreen (ScreenPtr screen)
 {
     ScrnInfoPtr		scrn = xf86Screens[screen->myNum];
commit d5ab89f4f1acbe2614036e8934122185ac0f81ee
Author: Jeremy Huddleston <jeremyhu at freedesktop.org>
Date:   Mon Apr 28 15:52:24 2008 -0700

    XQuartz: Unset CFProcessPath... blech
    (cherry picked from commit ce4fbfbc75c62a092214d140c7550279aebe69ef)

diff --git a/hw/xquartz/quartzStartup.c b/hw/xquartz/quartzStartup.c
index 7b6a1a6..a4472e6 100644
--- a/hw/xquartz/quartzStartup.c
+++ b/hw/xquartz/quartzStartup.c
@@ -98,6 +98,12 @@ int main(int argc, char **argv, char **envp) {
     int         i;
     int         fd[2];
 
+    /* Unset CFProcessPath, so our children don't inherit this kludge we need
+     * to load our nib.  If an xterm gets this set, then it fails to
+     * 'open hi.txt' properly.
+     */
+    unsetenv("CFProcessPath");
+    
     // Make a pipe to pass events
     assert( pipe(fd) == 0 );
     darwinEventReadFD = fd[0];
commit 0c2312b21b6700c1425baccaf9c26150b4f0fd6a
Author: Jeremy Huddleston <jeremyhu at freedesktop.org>
Date:   Mon Apr 28 15:28:21 2008 -0700

    XQuartz: xprIsX11Window can be called from the Appkit thread (see X11Application.m)
    (cherry picked from commit 22cf72437601c07b8a6c744b4f2f1f4cd6713e60)

diff --git a/hw/xquartz/xpr/xprFrame.c b/hw/xquartz/xpr/xprFrame.c
index edb4128..9fa9424 100644
--- a/hw/xquartz/xpr/xprFrame.c
+++ b/hw/xquartz/xpr/xprFrame.c
@@ -453,8 +453,6 @@ xprGetXWindow(xp_window_id wid)
 {
     RootlessWindowRec *winRec;
 
-    TA_SERVER();
-    
     if (window_hash == NULL)
         return NULL;
 
@@ -474,8 +472,6 @@ xprGetXWindowFromAppKit(int windowNumber)
     Bool ret;
     xp_window_id wid;
 
-    TA_SERVER();
-    
     if (window_hash == NULL)
         return FALSE;
 
@@ -507,8 +503,6 @@ xprIsX11Window(void *nsWindow, int windowNumber)
     Bool ret;
     xp_window_id wid;
 
-    TA_SERVER();
-    
     if (window_hash == NULL)
         return FALSE;
 
commit c3dc4bdbb018c0606d561e2dfb9a36e9297fa312
Author: Jeremy Huddleston <jeremyhu at freedesktop.org>
Date:   Mon Apr 28 15:42:02 2008 -0700

    XQuartz: Disabled DPMS extension
    (cherry picked from commit 1448fed9b6d484f471b9b2982c76ca921a9273b9)

diff --git a/configure.ac b/configure.ac
index 67606c7..f695551 100644
--- a/configure.ac
+++ b/configure.ac
@@ -524,11 +524,11 @@ AC_ARG_ENABLE(glx-tls,        AS_HELP_STRING([--enable-glx-tls], [Build GLX with
 
 dnl Extensions.
 AC_ARG_ENABLE(registry,       AS_HELP_STRING([--disable-registry], [Build string registry module (default: enabled)]), [XREGISTRY=$enableval], [XREGISTRY=yes])
-AC_ARG_ENABLE(composite,      AS_HELP_STRING([--disable-composite], [Build Composite extension (default: enabled)]), [COMPOSITE=$enableval], [COMPOSITE=auto])
+AC_ARG_ENABLE(composite,      AS_HELP_STRING([--disable-composite], [Build Composite extension (default: enabled)]), [COMPOSITE=$enableval], [COMPOSITE=yes])
 AC_ARG_ENABLE(mitshm,         AS_HELP_STRING([--disable-shm], [Build SHM extension (default: enabled)]), [MITSHM=$enableval], [MITSHM=yes])
 AC_ARG_ENABLE(xres,           AS_HELP_STRING([--disable-xres], [Build XRes extension (default: enabled)]), [RES=$enableval], [RES=yes])
 AC_ARG_ENABLE(xtrap,          AS_HELP_STRING([--disable-xtrap], [Build XTrap extension (default: enabled)]), [XTRAP=$enableval], [XTRAP=yes])
-AC_ARG_ENABLE(record,         AS_HELP_STRING([--disable-record], [Build Record extension (default: disabled)]), [RECORD=$enableval], [RECORD=no])
+AC_ARG_ENABLE(record,         AS_HELP_STRING([--enable-record], [Build Record extension (default: disabled)]), [RECORD=$enableval], [RECORD=no])
 AC_ARG_ENABLE(xv,             AS_HELP_STRING([--disable-xv], [Build Xv extension (default: enabled)]), [XV=$enableval], [XV=yes])
 AC_ARG_ENABLE(xvmc,           AS_HELP_STRING([--disable-xvmc], [Build XvMC extension (default: enabled)]), [XVMC=$enableval], [XVMC=yes])
 AC_ARG_ENABLE(dga,            AS_HELP_STRING([--disable-dga], [Build DGA extension (default: auto)]), [DGA=$enableval], [DGA=auto])
@@ -644,6 +644,40 @@ XORG_CHECK_LINUXDOC
 dnl Handle installing libxf86config
 AM_CONDITIONAL(INSTALL_LIBXF86CONFIG, [test "x$INSTALL_LIBXF86CONFIG" = xyes])
 
+dnl XQuartz DDX Detection... Yes, it's ugly to have it here... but we need to handle this early on
+case $host_os in
+	darwin*)
+		if test x$XQUARTZ = xauto; then
+			AC_CACHE_CHECK([whether to build Xquartz],xorg_cv_Carbon_framework,[
+		 		save_LDFLAGS=$LDFLAGS
+				LDFLAGS="$LDFLAGS -framework Carbon"
+				AC_LINK_IFELSE([char FSFindFolder(); int main() { FSFindFolder(); return 0;}],
+				[xorg_cv_Carbon_framework=yes],
+				[xorg_cv_Carbon_framework=no])
+			LDFLAGS=$save_LDFLAGS])
+                
+			if test "X$xorg_cv_Carbon_framework" = Xyes; then
+				XQUARTZ=yes
+			else
+				XQUARTZ=no
+			fi
+		fi
+
+		if test "x$XQUARTZ" = xyes ; then
+			XQUARTZ=yes
+			XVFB=no
+			XNEST=no
+
+			COMPOSITE=no
+			DGA=no
+			DPMSExtension=no
+			XF86BIGFONT=no
+			XF86MISC=no
+			XF86VIDMODE=no
+		fi
+		;;
+esac
+
 dnl ---------------------------------------------------------------------------
 dnl Extension section
 dnl ---------------------------------------------------------------------------
@@ -780,18 +814,6 @@ if test "x$XREGISTRY" = xyes; then
 	AC_DEFINE(XREGISTRY, 1, [Build registry module])
 fi
 
-dnl XQuartz DDX Detection... Yes, it's ugly to have it here... but we need to disable COMPOSITE for 
-if test "x$COMPOSITE" = xauto; then
-	case $host_os in
-		darwin*)
-			test "x$XQUARTZ" = xyes -o "x$XQUARTZ" = xauto && COMPOSITE=no
-			;;
-		*)
-			COMPOSITE=yes
-			;;
-	esac
-fi
-
 AM_CONDITIONAL(COMPOSITE, [test "x$COMPOSITE" = xyes])
 if test "x$COMPOSITE" = xyes; then
 	AC_DEFINE(COMPOSITE, 1, [Support Composite Extension])
@@ -1706,22 +1728,6 @@ AM_CONDITIONAL(XWIN_RANDR, [test "x$XWIN" = xyes])
 AM_CONDITIONAL(XWIN_XV, [test "x$XWIN" = xyes && test "x$XV" = xyes])
 
 dnl Darwin / OS X DDX
-if test "X$XQUARTZ" = Xauto; then
-	AC_CACHE_CHECK([whether to build Xquartz],xorg_cv_Carbon_framework,[
-	 	save_LDFLAGS=$LDFLAGS
-		LDFLAGS="$LDFLAGS -framework Carbon"
-		AC_LINK_IFELSE([char FSFindFolder(); int main() { FSFindFolder(); return 0;}],
-			[xorg_cv_Carbon_framework=yes],
-			[xorg_cv_Carbon_framework=no])
-		LDFLAGS=$save_LDFLAGS])
-                
-	if test "X$xorg_cv_Carbon_framework" = Xyes; then
-		XQUARTZ=yes
-	else
-		XQUARTZ=no
-	fi
-fi
-
 if test "x$XQUARTZ" = xyes; then
 	AC_DEFINE(XQUARTZ,1,[Have Quartz])
 	AC_DEFINE(ROOTLESS,1,[Build Rootless code])
@@ -1733,23 +1739,6 @@ if test "x$XQUARTZ" = xyes; then
 	AC_CHECK_LIB([Xplugin],[xp_init],[:])
 
 	CFLAGS="${CFLAGS} -DROOTLESS_WORKAROUND -DNO_ALLOCA"
-
-	if test "x$XF86MISC" = xyes || test "x$XF86MISC" = xauto; then
-		AC_MSG_NOTICE([Disabling XF86Misc extension])
-		XF86MISC=no
-	fi
-	if test "x$XF86VIDMODE" = xyes || test "x$XF86VIDMODE" = xauto; then
-		AC_MSG_NOTICE([Disabling XF86VidMode extension])
-		XF86VIDMODE=no
-	fi
-	if test "x$XF86BIGFONT" = xyes || test "x$XF86BIGFONT" = xauto; then
-		AC_MSG_NOTICE([Disabling XF86BigFont extension])
-		XF86BIGFONT=no
-	fi
-	if test "x$DGA" = xyes || test "x$DGA" = xauto; then
-		AC_MSG_NOTICE([Disabling DGA extension])
-		DGA=no
-	fi
 fi
 
 # Support for objc in autotools is minimal and not documented.
diff --git a/hw/xquartz/Makefile.am b/hw/xquartz/Makefile.am
index 1465a52..b2674be 100644
--- a/hw/xquartz/Makefile.am
+++ b/hw/xquartz/Makefile.am
@@ -19,7 +19,6 @@ DIST_SUBDIRS = GL xpr bundle
 libXquartz_la_SOURCES = \
 	$(top_srcdir)/fb/fbcmap_mi.c \
 	$(top_srcdir)/mi/miinitext.c \
-	$(top_srcdir)/Xext/dpmsstubs.c \
 	X11Application.m \
 	X11Controller.m \
 	applewm.c \
commit 07382a70c7ac9807dfb31821a4763bea2309bde6
Author: Jeremy Huddleston <jeremyhu at freedesktop.org>
Date:   Mon Apr 28 12:36:54 2008 -0700

    XQuartz: Added thread debugging to xprFrame.c
    (cherry picked from commit 41542502b321c697271c1752525b600872b6df96)

diff --git a/hw/xquartz/xpr/xprFrame.c b/hw/xquartz/xpr/xprFrame.c
index 901efca..edb4128 100644
--- a/hw/xquartz/xpr/xprFrame.c
+++ b/hw/xquartz/xpr/xprFrame.c
@@ -43,6 +43,8 @@
 #include <X11/Xatom.h>
 #include "windowstr.h"
 
+#include "threadSafety.h"
+
 #include <pthread.h>
 
 #define DEFINE_ATOM_HELPER(func,atom_name)                      \
@@ -69,7 +71,8 @@ static inline xp_error
 xprConfigureWindow(xp_window_id id, unsigned int mask,
                    const xp_window_changes *values)
 {
-  //  ErrorF("xprConfigureWindow()\n");
+    TA_SERVER();
+
     if (!no_configure_window)
         return xp_configure_window(id, mask, values);
     else
@@ -84,6 +87,8 @@ xprSetNativeProperty(RootlessWindowPtr pFrame)
     unsigned int native_id;
     long data;
 
+    TA_SERVER();
+    
     err = xp_get_native_window((xp_window_id) pFrame->wid, &native_id);
     if (err == Success)
     {
@@ -108,6 +113,8 @@ xprCreateFrame(RootlessWindowPtr pFrame, ScreenPtr pScreen,
     unsigned int mask = 0;
     xp_error err;
 
+    TA_SERVER();
+    
     wc.x = newX;
     wc.y = newY;
     wc.width = pFrame->width;
@@ -169,6 +176,8 @@ xprCreateFrame(RootlessWindowPtr pFrame, ScreenPtr pScreen,
 void
 xprDestroyFrame(RootlessFrameID wid)
 {
+    TA_SERVER();
+    
     pthread_mutex_lock(&window_hash_mutex);
     x_hash_table_remove(window_hash, wid);
     pthread_mutex_unlock(&window_hash_mutex);
@@ -183,6 +192,8 @@ xprDestroyFrame(RootlessFrameID wid)
 void
 xprMoveFrame(RootlessFrameID wid, ScreenPtr pScreen, int newX, int newY)
 {
+    TA_SERVER();
+    
     xp_window_changes wc;
 
     wc.x = newX;
@@ -202,6 +213,8 @@ xprResizeFrame(RootlessFrameID wid, ScreenPtr pScreen,
 {
     xp_window_changes wc;
 
+    TA_SERVER();
+    
     wc.x = newX;
     wc.y = newY;
     wc.width = newW;
@@ -223,7 +236,9 @@ xprRestackFrame(RootlessFrameID wid, RootlessFrameID nextWid)
 {
     xp_window_changes wc;
 
-    /* Stack frame below nextWid it if it exists, or raise
+    TA_SERVER();
+    
+   /* Stack frame below nextWid it if it exists, or raise
        frame above everything otherwise. */
 
     if (nextWid == NULL)
@@ -249,6 +264,8 @@ xprReshapeFrame(RootlessFrameID wid, RegionPtr pShape)
 {
     xp_window_changes wc;
 
+    TA_SERVER();
+    
     if (pShape != NULL)
     {
         wc.shape_nrects = REGION_NUM_RECTS(pShape);
@@ -274,6 +291,8 @@ xprUnmapFrame(RootlessFrameID wid)
 {
     xp_window_changes wc;
 
+    TA_SERVER();
+    
     wc.stack_mode = XP_UNMAPPED;
     wc.sibling = 0;
 
@@ -292,6 +311,8 @@ xprStartDrawing(RootlessFrameID wid, char **pixelData, int *bytesPerRow)
     unsigned int rowbytes[2];
     xp_error err;
 
+    TA_SERVER();
+    
     err = xp_lock_window((xp_window_id) wid, NULL, NULL, data, rowbytes, NULL);
     if (err != Success)
         FatalError("Could not lock window %i for drawing.", (int) wid);
@@ -307,6 +328,8 @@ xprStartDrawing(RootlessFrameID wid, char **pixelData, int *bytesPerRow)
 void
 xprStopDrawing(RootlessFrameID wid, Bool flush)
 {
+    TA_SERVER();
+    
     xp_unlock_window((xp_window_id) wid, flush);
 }
 
@@ -317,6 +340,8 @@ xprStopDrawing(RootlessFrameID wid, Bool flush)
 void
 xprUpdateRegion(RootlessFrameID wid, RegionPtr pDamage)
 {
+    TA_SERVER();
+    
     xp_flush_window((xp_window_id) wid);
 }
 
@@ -328,6 +353,8 @@ void
 xprDamageRects(RootlessFrameID wid, int nrects, const BoxRec *rects,
                int shift_x, int shift_y)
 {
+    TA_SERVER();
+    
     xp_mark_window((xp_window_id) wid, nrects, rects, shift_x, shift_y);
 }
 
@@ -341,6 +368,8 @@ xprSwitchWindow(RootlessWindowPtr pFrame, WindowPtr oldWin)
 {
     DeleteProperty(serverClient, oldWin, xa_native_window_id());
 
+    TA_SERVER();
+    
     xprSetNativeProperty(pFrame);
 }
 
@@ -352,6 +381,8 @@ Bool xprDoReorderWindow(RootlessWindowPtr pFrame)
 {
     WindowPtr pWin = pFrame->win;
 
+    TA_SERVER();
+    
     return AppleWMDoReorderWindow(pWin);
 }
 
@@ -364,6 +395,8 @@ void
 xprCopyWindow(RootlessFrameID wid, int dstNrects, const BoxRec *dstRects,
               int dx, int dy)
 {
+    TA_SERVER();
+    
     xp_copy_window((xp_window_id) wid, (xp_window_id) wid,
                    dstNrects, dstRects, dx, dy);
 }
@@ -398,6 +431,8 @@ xprInit(ScreenPtr pScreen)
 {
     RootlessInit(pScreen, &xprRootlessProcs);
 
+    TA_SERVER();
+    
     rootless_CopyBytes_threshold = xp_copy_bytes_threshold;
     rootless_FillBytes_threshold = xp_fill_bytes_threshold;
     rootless_CompositePixels_threshold = xp_composite_area_threshold;
@@ -418,6 +453,8 @@ xprGetXWindow(xp_window_id wid)
 {
     RootlessWindowRec *winRec;
 
+    TA_SERVER();
+    
     if (window_hash == NULL)
         return NULL;
 
@@ -437,6 +474,8 @@ xprGetXWindowFromAppKit(int windowNumber)
     Bool ret;
     xp_window_id wid;
 
+    TA_SERVER();
+    
     if (window_hash == NULL)
         return FALSE;
 
@@ -468,6 +507,8 @@ xprIsX11Window(void *nsWindow, int windowNumber)
     Bool ret;
     xp_window_id wid;
 
+    TA_SERVER();
+    
     if (window_hash == NULL)
         return FALSE;
 
@@ -498,6 +539,8 @@ xprHideWindows(Bool hide)
     int screen;
     WindowPtr pRoot, pWin;
 
+    TA_SERVER();
+    
     for (screen = 0; screen < screenInfo.numScreens; screen++) {
         pRoot = WindowTable[screenInfo.screens[screen]->myNum];
         RootlessFrameID prevWid = NULL;
commit 8349732a6720652bfbad7874a952be73a0e8e77b
Author: Michel Dänzer <michel at tungstengraphics.com>
Date:   Mon Apr 28 21:09:35 2008 +0200

    EXA: Try to accelerate non-antialiased text via the glyph cache as well.
    
    Treat 1 bit glyphs and masks as PICT_a8 in the glyph cache. We're not able to
    accelerate them otherwise.

diff --git a/exa/exa_glyphs.c b/exa/exa_glyphs.c
index 08ec097..ff665d5 100644
--- a/exa/exa_glyphs.c
+++ b/exa/exa_glyphs.c
@@ -374,6 +374,10 @@ exaGlyphCacheUploadGlyph(ScreenPtr         pScreen,
     if (exaPixmapIsOffscreen(pGlyphPixmap))
 	return FALSE;
 
+    /* UploadToScreen only works if bpp match */
+    if (pGlyphPixmap->drawable.bitsPerPixel != pCachePixmap->drawable.bitsPerPixel)
+	return FALSE;
+
     /* cache pixmap must be offscreen. */
     pixmaps[0].as_dst = TRUE;
     pixmaps[0].as_src = FALSE;
@@ -524,6 +528,9 @@ exaBufferGlyph(ScreenPtr         pScreen,
 
     if (buffer->count == GLYPH_BUFFER_SIZE)
 	return ExaGlyphNeedFlush;
+
+    if (PICT_FORMAT_BPP(format) == 1)
+	format = PICT_a8;
     
     for (i = 0; i < EXA_NUM_GLYPH_CACHES; i++) {
 	ExaGlyphCachePtr cache = &pExaScr->glyphCaches[i];
@@ -796,6 +803,14 @@ exaGlyphs (CARD8 	 op,
 	    return;
 	width = extents.x2 - extents.x1;
 	height = extents.y2 - extents.y1;
+
+	if (maskFormat->depth == 1) {
+	    PictFormatPtr a8Format = PictureMatchFormat (pScreen, 8, PICT_a8);
+
+	    if (a8Format)
+		maskFormat = a8Format;
+	}
+
 	pMaskPixmap = (*pScreen->CreatePixmap) (pScreen, width, height,
 						maskFormat->depth,
 						CREATE_PIXMAP_USAGE_SCRATCH);
commit a65d530040bb561ba88c5d8c71633a7c0bf11e89
Author: Michel Dänzer <michel at tungstengraphics.com>
Date:   Mon Apr 28 21:03:12 2008 +0200

    EXA: Accumulate glyphs whenever possible, for full benefits of the glyph cache.

diff --git a/exa/exa_glyphs.c b/exa/exa_glyphs.c
index b618365..08ec097 100644
--- a/exa/exa_glyphs.c
+++ b/exa/exa_glyphs.c
@@ -662,6 +662,79 @@ GlyphExtents (int		nlist,
     }
 }
 
+/**
+ * Returns TRUE if the glyphs in the lists intersect.  Only checks based on
+ * bounding box, which appears to be good enough to catch most cases at least.
+ */
+static Bool
+exaGlyphsIntersect(int nlist, GlyphListPtr list, GlyphPtr *glyphs)
+{
+    int x1, x2, y1, y2;
+    int n;
+    GlyphPtr glyph;
+    int x, y;
+    BoxRec extents;
+    Bool first = TRUE;
+
+    x = 0;
+    y = 0;
+    while (nlist--) {
+       x += list->xOff;
+       y += list->yOff;
+       n = list->len;
+       list++;
+       while (n--) {
+           glyph = *glyphs++;
+
+           if (glyph->info.width == 0 || glyph->info.height == 0) {
+               x += glyph->info.xOff;
+               y += glyph->info.yOff;
+               continue;
+           }
+
+           x1 = x - glyph->info.x;
+           if (x1 < MINSHORT)
+               x1 = MINSHORT;
+           y1 = y - glyph->info.y;
+           if (y1 < MINSHORT)
+               y1 = MINSHORT;
+           x2 = x1 + glyph->info.width;
+           if (x2 > MAXSHORT)
+               x2 = MAXSHORT;
+           y2 = y1 + glyph->info.height;
+           if (y2 > MAXSHORT)
+               y2 = MAXSHORT;
+
+           if (first) {
+               extents.x1 = x1;
+               extents.y1 = y1;
+               extents.x2 = x2;
+               extents.y2 = y2;
+               first = FALSE;
+           } else {
+               if (x1 < extents.x2 && x2 > extents.x1 &&
+                   y1 < extents.y2 && y2 > extents.y1)
+               {
+                   return TRUE;
+               }
+
+               if (x1 < extents.x1)
+                  extents.x1 = x1;
+               if (x2 > extents.x2)
+                   extents.x2 = x2;
+               if (y1 < extents.y1)
+                   extents.y1 = y1;
+               if (y2 > extents.y2)
+                   extents.y2 = y2;
+           }
+           x += glyph->info.xOff;
+           y += glyph->info.yOff;
+       }
+    }
+
+    return FALSE;
+}
+
 #define NeedsComponent(f) (PICT_FORMAT_A(f) != 0 && PICT_FORMAT_RGB(f) != 0)
 
 void
@@ -689,6 +762,29 @@ exaGlyphs (CARD8 	 op,
     CARD32	component_alpha;
     ExaGlyphBuffer buffer;
 
+    /* If we don't have a mask format but all the glyphs have the same format
+     * and don't intersect, use the glyph format as mask format for the full
+     * benefits of the glyph cache.
+     */
+    if (!maskFormat) {
+       Bool sameFormat = TRUE;
+       int i;
+
+       maskFormat = list[0].format;
+
+       for (i = 0; i < nlist; i++) {
+           if (maskFormat->format != list[i].format->format) {
+               sameFormat = FALSE;
+               break;
+           }
+       }
+
+       if (!sameFormat || (maskFormat->depth != 1 &&
+			   exaGlyphsIntersect(nlist, list, glyphs))) {
+	   maskFormat = NULL;
+       }
+    }
+
     if (maskFormat)
     {
 	GCPtr	    pGC;
commit e7eaac59c424a205dd106fc7d70734ff4b390f28
Author: Michel Dänzer <michel at tungstengraphics.com>
Date:   Mon Apr 28 21:00:55 2008 +0200

    EXA: Glyph cache upload tweaks.
    
    Track damage after using UploadToScreen directly.
    
    Don't waste any effort on empty glyphs.

diff --git a/exa/exa_glyphs.c b/exa/exa_glyphs.c
index 95ff4d8..b618365 100644
--- a/exa/exa_glyphs.c
+++ b/exa/exa_glyphs.c
@@ -394,6 +394,12 @@ exaGlyphCacheUploadGlyph(ScreenPtr         pScreen,
 				       pExaPixmap->sys_pitch))
 	return FALSE;
 
+    exaPixmapDirty (pCachePixmap,
+		    CACHE_X(pos) + cacheXoff,
+		    CACHE_Y(pos) + cacheYoff,
+		    CACHE_X(pos) + cacheXoff + pGlyph->info.width,
+		    CACHE_Y(pos) + cacheYoff + pGlyph->info.height);
+
     return TRUE;
 }
 
@@ -737,7 +743,8 @@ exaGlyphs (CARD8 	 op,
 	    glyph = *glyphs++;
 	    pPicture = GlyphPicture (glyph)[pScreen->myNum];
 
-	    if (exaBufferGlyph(pScreen, &buffer, glyph, x, y) == ExaGlyphNeedFlush)
+	    if (glyph->info.width > 0 && glyph->info.height > 0 &&
+		exaBufferGlyph(pScreen, &buffer, glyph, x, y) == ExaGlyphNeedFlush)
 	    {
 		if (maskFormat)
 		    exaGlyphsToMask(pMask, &buffer);
commit cc08c06665ffe29ad44d023d75d0f86e5338875d
Author: Owen Taylor <otaylor at huygens.home.fishsoup.net>
Date:   Mon Apr 28 21:00:55 2008 +0200

    EXA: Use UploadToScreen() for uploads to glyph cache
    
    When possible, use UploadToScreen() rather than CompositePicture()
    to upload glyphs onto the glyph cache pixmap. This avoids allocating
    offscreen memory for each glyph making management of offscreen
    areas much more efficient.

diff --git a/exa/exa_glyphs.c b/exa/exa_glyphs.c
index 27ecd4a..95ff4d8 100644
--- a/exa/exa_glyphs.c
+++ b/exa/exa_glyphs.c
@@ -347,6 +347,56 @@ exaGlyphCacheHashRemove(ExaGlyphCachePtr cache,
 #define CACHE_X(pos) (((pos) % cache->columns) * cache->glyphWidth)
 #define CACHE_Y(pos) (cache->yOffset + ((pos) / cache->columns) * cache->glyphHeight)
 
+/* The most efficient thing to way to upload the glyph to the screen
+ * is to use the UploadToScreen() driver hook; this allows us to
+ * pipeline glyph uploads and to avoid creating offscreen pixmaps for
+ * glyphs that we'll never use again.
+ */
+static Bool
+exaGlyphCacheUploadGlyph(ScreenPtr         pScreen,
+			 ExaGlyphCachePtr  cache,
+			 int               pos,
+			 GlyphPtr          pGlyph)
+{
+    ExaScreenPriv(pScreen);
+    PicturePtr pGlyphPicture = GlyphPicture(pGlyph)[pScreen->myNum];
+    PixmapPtr pGlyphPixmap = (PixmapPtr)pGlyphPicture->pDrawable;
+    ExaPixmapPriv(pGlyphPixmap);
+    PixmapPtr pCachePixmap = (PixmapPtr)cache->picture->pDrawable;
+    ExaMigrationRec pixmaps[1];
+    int cacheXoff, cacheYoff;
+
+    if (!pExaScr->info->UploadToScreen || pExaScr->swappedOut || pExaPixmap->accel_blocked)
+	return FALSE;
+
+    /* If the glyph pixmap is already uploaded, no point in doing
+     * things this way */
+    if (exaPixmapIsOffscreen(pGlyphPixmap))
+	return FALSE;
+
+    /* cache pixmap must be offscreen. */
+    pixmaps[0].as_dst = TRUE;
+    pixmaps[0].as_src = FALSE;
+    pixmaps[0].pPix = pCachePixmap;
+    pixmaps[0].pReg = NULL;
+    exaDoMigration (pixmaps, 1, TRUE);
+
+    pCachePixmap = exaGetOffscreenPixmap ((DrawablePtr)pCachePixmap, &cacheXoff, &cacheYoff);
+    if (!pCachePixmap)
+	return FALSE;
+
+    if (!pExaScr->info->UploadToScreen(pCachePixmap,
+				       CACHE_X(pos) + cacheXoff,
+				       CACHE_Y(pos) + cacheYoff,
+				       pGlyph->info.width,
+				       pGlyph->info.height,
+				       (char *)pExaPixmap->sys_ptr,
+				       pExaPixmap->sys_pitch))
+	return FALSE;
+
+    return TRUE;
+}
+
 static ExaGlyphCacheResult
 exaGlyphCacheBufferGlyph(ScreenPtr         pScreen,
 			 ExaGlyphCachePtr  cache,
@@ -413,18 +463,23 @@ exaGlyphCacheBufferGlyph(ScreenPtr         pScreen,
 	    cache->evictionPosition = rand() % cache->size;
 	}
 
-	/* Now actually upload the glyph into the cache picture */
+	/* Now actually upload the glyph into the cache picture; if
+	 * we can't do it with UploadToScreen (because the glyph is
+	 * offscreen, etc), we fall back to CompositePicture.
+	 */
+	if (!exaGlyphCacheUploadGlyph(pScreen, cache, pos, pGlyph)) {
+	    CompositePicture (PictOpSrc,
+			      GlyphPicture(pGlyph)[pScreen->myNum],
+			      None,
+			      cache->picture,
+			      0, 0,
+			      0, 0,
+			      CACHE_X(pos),
+			      CACHE_Y(pos),
+			      pGlyph->info.width,
+			      pGlyph->info.height);
+	}
 
-	CompositePicture (PictOpSrc,
-			  GlyphPicture(pGlyph)[pScreen->myNum],
-			  None,
-			  cache->picture,
-			  0, 0,
-			  0, 0,
-			  CACHE_X(pos),
-			  CACHE_Y(pos),
-			  pGlyph->info.width,
-			  pGlyph->info.height);
     }
     
 
commit 13fd2256300b61d88b840952d838f834523f5dd7
Author: Owen Taylor <otaylor at huygens.home.fishsoup.net>
Date:   Mon Apr 28 21:00:55 2008 +0200

    EXA: Clean up debug messages

diff --git a/exa/exa_glyphs.c b/exa/exa_glyphs.c
index 851e439..27ecd4a 100644
--- a/exa/exa_glyphs.c
+++ b/exa/exa_glyphs.c
@@ -260,11 +260,9 @@ exaGlyphCacheHashLookup(ExaGlyphCachePtr cache,
 	    return -1;
 
 	if (memcmp(pGlyph->sha1, cache->glyphs[entryPos].sha1, sizeof(pGlyph->sha1)) == 0){
-	    DBG_GLYPH_CACHE((" found entry at %d\n", slot));
 	    return entryPos;
 	}
 	    
-	DBG_GLYPH_CACHE((" lookup linear probe bumpalong\n"));
 	slot--;
 	if (slot < 0)
 	    slot = cache->hashSize - 1;
@@ -284,7 +282,6 @@ exaGlyphCacheHashInsert(ExaGlyphCachePtr cache,
     
     while (TRUE) { /* hash table can never be full */
 	if (cache->hashEntries[slot] == -1) {
-	    DBG_GLYPH_CACHE((" inserting entry at %d\n", slot));
 	    cache->hashEntries[slot] = pos;
 	    return;
 	}
diff --git a/exa/exa_priv.h b/exa/exa_priv.h
index 8a17f65..f3b72ae 100644
--- a/exa/exa_priv.h
+++ b/exa/exa_priv.h
@@ -61,7 +61,7 @@
 #define DEBUG_MIGRATE		0
 #define DEBUG_PIXMAP		0
 #define DEBUG_OFFSCREEN		0
-#define DEBUG_GLYPH_CACHE	1
+#define DEBUG_GLYPH_CACHE	0
 
 #if DEBUG_TRACE_FALL
 #define EXA_FALLBACK(x)     					\
commit fcb5949928f1c27f67f40c094c3c673786574422
Author: Owen Taylor <otaylor at huygens.home.fishsoup.net>
Date:   Mon Apr 28 21:00:54 2008 +0200

    EXA: Fix overlapping glyphs in glyph cache
    
    Allocate each cache at a different vertical position in the
    per-format pixmap. Fix width/height confusion when choosing
    the cache for a glyph.

diff --git a/exa/exa_glyphs.c b/exa/exa_glyphs.c
index 55fdb01..851e439 100644
--- a/exa/exa_glyphs.c
+++ b/exa/exa_glyphs.c
@@ -173,12 +173,13 @@ exaRealizeGlyphCaches(ScreenPtr    pScreen,
     for (i = 0; i < EXA_NUM_GLYPH_CACHES; i++) {
 	ExaGlyphCachePtr cache = &pExaScr->glyphCaches[i];
 	int rows;
-	
+
 	if (cache->format != format)
 	    continue;
 
-	rows = (cache->size + cache->columns - 1) / cache->columns;
+	cache->yOffset = height;
 
+	rows = (cache->size + cache->columns - 1) / cache->columns;
 	height += rows * cache->glyphHeight;
     }
 
@@ -346,6 +347,9 @@ exaGlyphCacheHashRemove(ExaGlyphCachePtr cache,
     }
 }
 
+#define CACHE_X(pos) (((pos) % cache->columns) * cache->glyphWidth)
+#define CACHE_Y(pos) (cache->yOffset + ((pos) / cache->columns) * cache->glyphHeight)
+
 static ExaGlyphCacheResult
 exaGlyphCacheBufferGlyph(ScreenPtr         pScreen,
 			 ExaGlyphCachePtr  cache,
@@ -393,8 +397,8 @@ exaGlyphCacheBufferGlyph(ScreenPtr         pScreen,
 		int x, y;
 		int i;
 		
-		x = (pos % cache->columns) * cache->glyphWidth;
-		y = (pos / cache->columns) * cache->glyphHeight;
+		x = CACHE_X(pos);
+		y = CACHE_Y(pos);
 
 		for (i = 0; i < buffer->count; i++) {
 		    if (buffer->rects[i].xSrc == x && buffer->rects[i].ySrc == y) {
@@ -420,8 +424,8 @@ exaGlyphCacheBufferGlyph(ScreenPtr         pScreen,
 			  cache->picture,
 			  0, 0,
 			  0, 0,
-			  (pos % cache->columns) * cache->glyphWidth,
-			  (pos / cache->columns) * cache->glyphHeight,
+			  CACHE_X(pos),
+			  CACHE_Y(pos),
 			  pGlyph->info.width,
 			  pGlyph->info.height);
     }
@@ -430,8 +434,8 @@ exaGlyphCacheBufferGlyph(ScreenPtr         pScreen,
     buffer->source = cache->picture;
 	    
     rect = &buffer->rects[buffer->count];
-    rect->xSrc = (pos % cache->columns) * cache->glyphWidth;
-    rect->ySrc = (pos / cache->columns) * cache->glyphHeight;
+    rect->xSrc = CACHE_X(pos);
+    rect->ySrc = CACHE_Y(pos);
     rect->xDst = xGlyph - pGlyph->info.x;
     rect->yDst = yGlyph - pGlyph->info.y;
     rect->width = pGlyph->info.width;
@@ -442,6 +446,9 @@ exaGlyphCacheBufferGlyph(ScreenPtr         pScreen,
     return ExaGlyphSuccess;
 }
 
+#undef CACHE_X
+#undef CACHE_Y
+
 static ExaGlyphCacheResult
 exaBufferGlyph(ScreenPtr         pScreen,
 	       ExaGlyphBufferPtr buffer,
@@ -452,7 +459,7 @@ exaBufferGlyph(ScreenPtr         pScreen,
     ExaScreenPriv(pScreen);
     unsigned int format = (GlyphPicture(pGlyph)[pScreen->myNum])->format;
     int width = pGlyph->info.width;
-    int height = pGlyph->info.width;
+    int height = pGlyph->info.height;
     ExaCompositeRectPtr rect;
     PicturePtr source;
     int i;
diff --git a/exa/exa_priv.h b/exa/exa_priv.h
index 0d5d0f5..8a17f65 100644
--- a/exa/exa_priv.h
+++ b/exa/exa_priv.h
@@ -61,7 +61,7 @@
 #define DEBUG_MIGRATE		0
 #define DEBUG_PIXMAP		0
 #define DEBUG_OFFSCREEN		0
-#define DEBUG_GLYPH_CACHE	0
+#define DEBUG_GLYPH_CACHE	1
 
 #if DEBUG_TRACE_FALL
 #define EXA_FALLBACK(x)     					\
@@ -121,6 +121,7 @@ typedef struct {
     int glyphCount; /* Current number of glyphs */
     
     PicturePtr picture;   /* Where the glyphs of the cache are stored */
+    int yOffset;          /* y location within the picture where the cache starts */
     int columns;          /* Number of columns the glyphs are layed out in */
     int evictionPosition; /* Next random position to evict a glyph */
 } ExaGlyphCacheRec, *ExaGlyphCachePtr;
commit 40eb14c9482457969e0bde97c49edad536285e02
Author: Owen Taylor <otaylor at huygens.home.fishsoup.net>
Date:   Mon Apr 28 21:00:54 2008 +0200

    EXA: Add exaCompositeRects()
    
    Add a function to composite multiple independent rectangles
    from the same source to the same destination in a single
    operation: this is useful for building a glyph mask.

diff --git a/exa/exa_glyphs.c b/exa/exa_glyphs.c
index 3fe433a..55fdb01 100644
--- a/exa/exa_glyphs.c
+++ b/exa/exa_glyphs.c
@@ -56,16 +56,6 @@
 #define DBG_GLYPH_CACHE(a)
 #endif
 
-/* Instructions for rendering a single glyph */
-typedef struct {
-    INT16 xSrc;
-    INT16 ySrc;
-    INT16 xDst;
-    INT16 yDst;
-    INT16 width;
-    INT16 height;
-} ExaGlyphRenderRec, *ExaGlyphRenderPtr;
-
 /* Width of the pixmaps we use for the caches; this should be less than
  * max texture size of the driver; this may need to actually come from
  * the driver.
@@ -79,7 +69,7 @@ typedef struct {
 
 typedef struct {
     PicturePtr source;
-    ExaGlyphRenderRec glyphs[GLYPH_BUFFER_SIZE];
+    ExaCompositeRectRec rects[GLYPH_BUFFER_SIZE];
     int count;
 } ExaGlyphBuffer, *ExaGlyphBufferPtr;
 
@@ -364,7 +354,7 @@ exaGlyphCacheBufferGlyph(ScreenPtr         pScreen,
 			 int               xGlyph,
 			 int               yGlyph)
 {
-    ExaGlyphRenderPtr glyphRec;
+    ExaCompositeRectPtr rect;
     int pos;
     
     if (buffer->source && buffer->source != cache->picture)
@@ -407,7 +397,7 @@ exaGlyphCacheBufferGlyph(ScreenPtr         pScreen,
 		y = (pos / cache->columns) * cache->glyphHeight;
 
 		for (i = 0; i < buffer->count; i++) {
-		    if (buffer->glyphs[i].xSrc == x && buffer->glyphs[i].ySrc == y) {
+		    if (buffer->rects[i].xSrc == x && buffer->rects[i].ySrc == y) {
 			DBG_GLYPH_CACHE(("  must flush buffer\n"));
 			return ExaGlyphNeedFlush;
 		    }
@@ -439,13 +429,13 @@ exaGlyphCacheBufferGlyph(ScreenPtr         pScreen,
 
     buffer->source = cache->picture;
 	    
-    glyphRec = &buffer->glyphs[buffer->count];
-    glyphRec->xSrc = (pos % cache->columns) * cache->glyphWidth;
-    glyphRec->ySrc = (pos / cache->columns) * cache->glyphHeight;
-    glyphRec->xDst = xGlyph - pGlyph->info.x;
-    glyphRec->yDst = yGlyph - pGlyph->info.y;
-    glyphRec->width = pGlyph->info.width;
-    glyphRec->height = pGlyph->info.height;
+    rect = &buffer->rects[buffer->count];
+    rect->xSrc = (pos % cache->columns) * cache->glyphWidth;
+    rect->ySrc = (pos / cache->columns) * cache->glyphHeight;
+    rect->xDst = xGlyph - pGlyph->info.x;
+    rect->yDst = yGlyph - pGlyph->info.y;
+    rect->width = pGlyph->info.width;
+    rect->height = pGlyph->info.height;
 	    
     buffer->count++;
 
@@ -463,7 +453,7 @@ exaBufferGlyph(ScreenPtr         pScreen,
     unsigned int format = (GlyphPicture(pGlyph)[pScreen->myNum])->format;
     int width = pGlyph->info.width;
     int height = pGlyph->info.width;
-    ExaGlyphRenderPtr glyphRec;
+    ExaCompositeRectPtr rect;
     PicturePtr source;
     int i;
 
@@ -497,13 +487,13 @@ exaBufferGlyph(ScreenPtr         pScreen,
 
     buffer->source = source;
     
-    glyphRec = &buffer->glyphs[buffer->count];
-    glyphRec->xSrc = 0;
-    glyphRec->ySrc = 0;
-    glyphRec->xDst = xGlyph - pGlyph->info.x;
-    glyphRec->yDst = yGlyph - pGlyph->info.y;
-    glyphRec->width = pGlyph->info.width;
-    glyphRec->height = pGlyph->info.height;
+    rect = &buffer->rects[buffer->count];
+    rect->xSrc = 0;
+    rect->ySrc = 0;
+    rect->xDst = xGlyph - pGlyph->info.x;
+    rect->yDst = yGlyph - pGlyph->info.y;
+    rect->width = pGlyph->info.width;
+    rect->height = pGlyph->info.height;
 
     buffer->count++;
 
@@ -514,23 +504,8 @@ static void
 exaGlyphsToMask(PicturePtr        pMask,
 		ExaGlyphBufferPtr buffer)
 {
-    int i;
-
-    for (i = 0; i < buffer->count; i++) {
-	ExaGlyphRenderPtr glyphRec = &buffer->glyphs[i];
-	
-	CompositePicture (PictOpAdd,
-			  buffer->source,
-			  None,
-			  pMask,
-			  glyphRec->xSrc,
-			  glyphRec->ySrc,
-			  0, 0,
-			  glyphRec->xDst,
-			  glyphRec->yDst,
-			  glyphRec->width,
-			  glyphRec->height);
-    }
+    exaCompositeRects(PictOpAdd, buffer->source, pMask,
+		      buffer->count, buffer->rects);
     
     buffer->count = 0;
     buffer->source = NULL;
@@ -549,20 +524,20 @@ exaGlyphsToDst(CARD8		 op,
     int i;
 
     for (i = 0; i < buffer->count; i++) {
-	ExaGlyphRenderPtr glyphRec = &buffer->glyphs[i];
+	ExaCompositeRectPtr rect = &buffer->rects[i];
 	
 	CompositePicture (op,
 			  pSrc,
 			  buffer->source,
 			  pDst,
-			  xSrc + glyphRec->xDst - xDst,
-			  ySrc + glyphRec->yDst - yDst,
-			  glyphRec->xSrc,
-			  glyphRec->ySrc,
-			  glyphRec->xDst,
-			  glyphRec->yDst,
-			  glyphRec->width,
-			  glyphRec->height);
+			  xSrc + rect->xDst - xDst,
+			  ySrc + rect->yDst - yDst,
+			  rect->xSrc,
+			  rect->ySrc,
+			  rect->xDst,
+			  rect->yDst,
+			  rect->width,
+			  rect->height);
     }
     
     buffer->count = 0;
diff --git a/exa/exa_priv.h b/exa/exa_priv.h
index aaceeb8..0d5d0f5 100644
--- a/exa/exa_priv.h
+++ b/exa/exa_priv.h
@@ -243,6 +243,15 @@ typedef struct _ExaMigrationRec {
     RegionPtr pReg;
 } ExaMigrationRec, *ExaMigrationPtr;
 
+typedef struct {
+    INT16 xSrc;
+    INT16 ySrc;
+    INT16 xDst;
+    INT16 yDst;
+    INT16 width;
+    INT16 height;
+} ExaCompositeRectRec, *ExaCompositeRectPtr;
+
 /**
  * exaDDXDriverInit must be implemented by the DDX using EXA, and is the place
  * to set EXA options or hook in screen functions to handle using EXA as the AA.
@@ -457,6 +466,13 @@ exaComposite(CARD8	op,
 	     CARD16	height);
 
 void
+exaCompositeRects(CARD8	              op,
+		  PicturePtr	      Src,
+		  PicturePtr	      pDst,
+		  int                 nrect,
+		  ExaCompositeRectPtr rects);
+
+void
 exaTrapezoids (CARD8 op, PicturePtr pSrc, PicturePtr pDst,
                PictFormatPtr maskFormat, INT16 xSrc, INT16 ySrc,
                int ntrap, xTrapezoid *traps);
diff --git a/exa/exa_render.c b/exa/exa_render.c
index 1d7b897..43b0029 100644
--- a/exa/exa_render.c
+++ b/exa/exa_render.c
@@ -332,6 +332,228 @@ exaTryDriverSolidFill(PicturePtr	pSrc,
 }
 
 static int
+exaTryDriverCompositeRects(CARD8	       op,
+			   PicturePtr	       pSrc,
+			   PicturePtr	       pDst,
+			   int                 nrect,
+			   ExaCompositeRectPtr rects)
+{
+    ExaScreenPriv (pDst->pDrawable->pScreen);
+    int src_off_x, src_off_y, dst_off_x, dst_off_y;
+    PixmapPtr pSrcPix, pDstPix;
+    ExaPixmapPrivPtr pSrcExaPix, pDstExaPix;
+    struct _Pixmap scratch;
+    ExaMigrationRec pixmaps[2];
+
+    pSrcPix = exaGetDrawablePixmap(pSrc->pDrawable);
+    pSrcExaPix = ExaGetPixmapPriv(pSrcPix);
+
+    pDstPix = exaGetDrawablePixmap(pDst->pDrawable);
+    pDstExaPix = ExaGetPixmapPriv(pDstPix);
+
+    /* Check whether the accelerator can use these pixmaps.
+     * FIXME: If it cannot, use temporary pixmaps so that the drawing
+     * happens within limits.
+     */
+    if (pSrcExaPix->accel_blocked ||
+	pDstExaPix->accel_blocked)
+    {
+	return -1;
+    }
+
+    if (pExaScr->info->CheckComposite &&
+	!(*pExaScr->info->CheckComposite) (op, pSrc, NULL, pDst))
+    {
+	return -1;
+    }
+    
+    exaGetDrawableDeltas (pDst->pDrawable, pDstPix, &dst_off_x, &dst_off_y);
+	
+    pixmaps[0].as_dst = TRUE;
+    pixmaps[0].as_src = exaOpReadsDestination(op);
+    pixmaps[0].pPix = pDstPix;
+    pixmaps[0].pReg = NULL;
+    pixmaps[1].as_dst = FALSE;
+    pixmaps[1].as_src = TRUE;
+    pixmaps[1].pPix = pSrcPix;
+    pixmaps[1].pReg = NULL;
+    exaDoMigration(pixmaps, 2, TRUE);
+
+    pSrcPix = exaGetOffscreenPixmap (pSrc->pDrawable, &src_off_x, &src_off_y);
+    if (!exaPixmapIsOffscreen(pDstPix))
+	return 0;
+    
+    if (!pSrcPix && pExaScr->info->UploadToScratch)
+    {
+	pSrcPix = exaGetDrawablePixmap (pSrc->pDrawable);
+	if ((*pExaScr->info->UploadToScratch) (pSrcPix, &scratch))
+	    pSrcPix = &scratch;
+    }
+
+    if (!pSrcPix)
+	return 0;
+
+    if (!(*pExaScr->info->PrepareComposite) (op, pSrc, NULL, pDst, pSrcPix,
+					     NULL, pDstPix))
+	return -1;
+
+    while (nrect--)
+    {
+	INT16 xDst = rects->xDst + pDst->pDrawable->x;
+	INT16 yDst = rects->yDst + pDst->pDrawable->y;
+	INT16 xSrc = rects->xSrc + pSrc->pDrawable->x;
+	INT16 ySrc = rects->ySrc + pSrc->pDrawable->y;
+	
+	RegionRec region;
+	BoxPtr pbox;
+	int nbox;
+	
+	if (!miComputeCompositeRegion (&region, pSrc, NULL, pDst,
+				       xSrc, ySrc, 0, 0, xDst, yDst,
+				       rects->width, rects->height))
+	    goto next_rect;
+	
+	REGION_TRANSLATE(pScreen, &region, dst_off_x, dst_off_y);
+	
+	nbox = REGION_NUM_RECTS(&region);
+	pbox = REGION_RECTS(&region);
+
+	xSrc = xSrc + src_off_x - xDst - dst_off_x;
+	ySrc = ySrc + src_off_y - yDst - dst_off_y;
+	
+	while (nbox--)
+	{
+	    (*pExaScr->info->Composite) (pDstPix,
+					 pbox->x1 + xSrc,
+					 pbox->y1 + ySrc,
+					 0, 0,
+					 pbox->x1,
+					 pbox->y1,
+					 pbox->x2 - pbox->x1,
+					 pbox->y2 - pbox->y1);
+	    pbox++;
+	}
+
+    next_rect:
+	REGION_UNINIT(pDst->pDrawable->pScreen, &region);
+
+	rects++;
+    }
+    
+    (*pExaScr->info->DoneComposite) (pDstPix);
+    exaMarkSync(pDst->pDrawable->pScreen);
+	
+    return 1;
+}
+
+/**
+ * Copy a number of rectangles from source to destination in a single
+ * operation. This is specialized for building a glyph mask: we don'y
+ * have a mask argument because we don't need it for that, and we
+ * don't have he special-case fallbacks found in exaComposite() - if the
+ * driver can support it, we use the driver functionality, otherwise we
+ * fallback straight to software.
+ */
+void
+exaCompositeRects(CARD8	              op,
+		  PicturePtr	      pSrc,
+		  PicturePtr	      pDst,
+		  int                 nrect,
+		  ExaCompositeRectPtr rects)
+{
+    PixmapPtr pPixmap = exaGetDrawablePixmap(pDst->pDrawable);
+    ExaPixmapPriv(pPixmap);
+    
+    int xoff, yoff;
+    int x1 = MAXSHORT;
+    int y1 = MAXSHORT;
+    int x2 = MINSHORT;
+    int y2 = MINSHORT;
+    RegionRec region;
+    RegionPtr pending_damage;
+    BoxRec box;
+    int n;
+    ExaCompositeRectPtr r;
+    
+    /* We have to manage the damage ourselves, since CompositeRects isn't
+     * something in the screen that can be managed by the damage extension,
+     * and EXA depends on damage to track what needs to be migrated between
+     * offscreen and onscreen.
+     */
+
+    /* Compute the overall extents of the composited region - we're making
+     * the assumption here that we are compositing a bunch of glyphs that
+     * cluster closely together and damaging each glyph individually would
+     * be a loss compared to damaging the bounding box.
+     */
+    n = nrect;
+    r = rects;
+    while (n--) {
+	int rect_x2 = r->xDst + r->width;
+	int rect_y2 = r->yDst + r->width;
+
+	if (r->xDst < x1) x1 = r->xDst;
+	if (r->xDst < y1) y1 = r->xDst;
+	if (rect_x2 > x2) x2 = rect_x2;
+	if (rect_y2 > y2) y2 = rect_y2;
+	
+	r++;
+    }
+
+    if (x2 <= x1 && y2 <= y1)
+	return;
+
+    box.x1 = x1;
+    box.x2 = x2 < MAXSHORT ? x2 : MAXSHORT;
+    box.y1 = y1;
+    box.y2 = y2 < MAXSHORT ? y2 : MAXSHORT;
+    
+    /* The pixmap migration code relies on pendingDamage indicating
+     * the bounds of the current rendering, so we need to force 
+     * the actual damage into that region before we do anything, and
+     * (see use of DamagePendingRegion in exaCopyDirty)
+     */
+    
+    REGION_INIT(pScreen, &region, &box, 1);
+    
+    exaGetDrawableDeltas(pDst->pDrawable, pPixmap, &xoff, &yoff);
+
+    REGION_TRANSLATE(pScreen, &region, xoff, yoff);
+    pending_damage = DamagePendingRegion(pExaPixmap->pDamage);
+    REGION_UNION(pScreen, pending_damage, pending_damage, &region);
+    REGION_TRANSLATE(pScreen, &region, -xoff, -yoff);
+    
+    /************************************************************/
+    
+    ValidatePicture (pSrc);
+    ValidatePicture (pDst);
+    
+    if (exaTryDriverCompositeRects(op, pSrc, pDst, nrect, rects) != 1) {
+	n = nrect;
+	r = rects;
+	while (n--) {
+	    ExaCheckComposite (op, pSrc, NULL, pDst,
+			       r->xSrc, r->ySrc,
+			       0, 0,
+			       r->xDst, r->yDst,
+			       r->width, r->height);
+	    r++;
+	}
+    }
+    
+    /************************************************************/
+
+    /* Now we have to flush the damage out from pendingDamage => damage 
+     * Calling DamageDamageRegion has that effect. (We could pass
+     * in an empty region here, but we pass in the same region we
+     * use above; the effect is the same.)
+     */
+
+    DamageDamageRegion(pDst->pDrawable, &region);
+    REGION_UNINIT(pScreen, &region);
+}
+
+static int
 exaTryDriverComposite(CARD8		op,
 		      PicturePtr	pSrc,
 		      PicturePtr	pMask,
commit 54184110f6f3e5d7276d5431e739a4fcf0c3523e
Author: Owen Taylor <otaylor at huygens.home.fishsoup.net>
Date:   Mon Apr 28 21:00:54 2008 +0200

    EXA: Use a single large glyph cache pixmap
    
    Add back exaGlyphs(); the new version copies the glyph images
    onto a single large glyph pixmap and draws from their to the
    destination surface. This reduces the management of small
    offscreen areas and will allow us to avoid texture unit setup
    between each glyph.

diff --git a/exa/Makefile.am b/exa/Makefile.am
index e2f7ed3..2b3f1e4 100644
--- a/exa/Makefile.am
+++ b/exa/Makefile.am
@@ -18,6 +18,7 @@ libexa_la_SOURCES = \
 	exa.c \
 	exa.h \
 	exa_accel.c \
+	exa_glyphs.c \
 	exa_migration.c \
 	exa_offscreen.c \
 	exa_render.c \
diff --git a/exa/exa.c b/exa/exa.c
index 3a6ad98..809fb4b 100644
--- a/exa/exa.c
+++ b/exa/exa.c
@@ -739,6 +739,8 @@ exaCloseScreen(int i, ScreenPtr pScreen)
     PictureScreenPtr	ps = GetPictureScreenIfSet(pScreen);
 #endif
 
+    exaGlyphsFini(pScreen);
+
     pScreen->CreateGC = pExaScr->SavedCreateGC;
     pScreen->CloseScreen = pExaScr->SavedCloseScreen;
     pScreen->GetImage = pExaScr->SavedGetImage;
@@ -752,7 +754,9 @@ exaCloseScreen(int i, ScreenPtr pScreen)
 #ifdef RENDER
     if (ps) {
 	ps->Composite = pExaScr->SavedComposite;
+	ps->Glyphs = pExaScr->SavedGlyphs;
 	ps->Trapezoids = pExaScr->SavedTrapezoids;
+	ps->Triangles = pExaScr->SavedTriangles;
     }
 #endif
 
@@ -914,6 +918,9 @@ exaDriverInit (ScreenPtr		pScreen,
         pExaScr->SavedComposite = ps->Composite;
 	ps->Composite = exaComposite;
 
+	pExaScr->SavedGlyphs = ps->Glyphs;
+	ps->Glyphs = exaGlyphs;
+	
 	pExaScr->SavedTriangles = ps->Triangles;
 	ps->Triangles = exaTriangles;
 
@@ -973,6 +980,8 @@ exaDriverInit (ScreenPtr		pScreen,
 	}
     }
 
+    exaGlyphsInit(pScreen);
+
     LogMessage(X_INFO, "EXA(%d): Driver registered support for the following"
 	       " operations:\n", pScreen->myNum);
     assert(pScreenInfo->PrepareSolid != NULL);
diff --git a/exa/exa_glyphs.c b/exa/exa_glyphs.c
new file mode 100644
index 0000000..3fe433a
--- /dev/null
+++ b/exa/exa_glyphs.c
@@ -0,0 +1,745 @@
+/*
+ * Copyright © 2008 Red Hat, Inc.
+ * Partly based on code Copyright © 2000 SuSE, Inc.
+ *
+ * Permission to use, copy, modify, distribute, and sell this software and its
+ * documentation for any purpose is hereby granted without fee, provided that
+ * the above copyright notice appear in all copies and that both that
+ * copyright notice and this permission notice appear in supporting
+ * documentation, and that the name of Red Hat not be used in advertising or
+ * publicity pertaining to distribution of the software without specific,
+ * written prior permission.  Red Hat makes no representations about the
+ * suitability of this software for any purpose.  It is provided "as is"
+ * without express or implied warranty.
+ *
+ * Red Hat DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL Red Hat
+ * BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
+ * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN 
+ * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ *
+ * Permission to use, copy, modify, distribute, and sell this software and its
+ * documentation for any purpose is hereby granted without fee, provided that
+ * the above copyright notice appear in all copies and that both that
+ * copyright notice and this permission notice appear in supporting
+ * documentation, and that the name of SuSE not be used in advertising or
+ * publicity pertaining to distribution of the software without specific,
+ * written prior permission.  SuSE makes no representations about the
+ * suitability of this software for any purpose.  It is provided "as is"
+ * without express or implied warranty.
+ *
+ * SuSE DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL SuSE
+ * BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
+ * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN 
+ * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ *
+ * Author: Owen Taylor <otaylor at fishsoup.net>
+ * Based on code by: Keith Packard
+ */
+
+#ifdef HAVE_DIX_CONFIG_H
+#include <dix-config.h>
+#endif
+
+#include <stdlib.h>
+
+#include "exa_priv.h"
+
+#include "mipict.h"
+
+#if DEBUG_GLYPH_CACHE
+#define DBG_GLYPH_CACHE(a) ErrorF a
+#else
+#define DBG_GLYPH_CACHE(a)
+#endif
+
+/* Instructions for rendering a single glyph */
+typedef struct {
+    INT16 xSrc;
+    INT16 ySrc;
+    INT16 xDst;
+    INT16 yDst;
+    INT16 width;
+    INT16 height;
+} ExaGlyphRenderRec, *ExaGlyphRenderPtr;
+
+/* Width of the pixmaps we use for the caches; this should be less than
+ * max texture size of the driver; this may need to actually come from
+ * the driver.
+ */
+#define CACHE_PICTURE_WIDTH 1024
+
+/* Maximum number of glyphs we buffer on the stack before flushing
+ * rendering to the mask or destination surface.
+ */
+#define GLYPH_BUFFER_SIZE 256
+
+typedef struct {
+    PicturePtr source;
+    ExaGlyphRenderRec glyphs[GLYPH_BUFFER_SIZE];
+    int count;
+} ExaGlyphBuffer, *ExaGlyphBufferPtr;
+
+typedef enum {
+    ExaGlyphSuccess,    /* Glyph added to render buffer */
+    ExaGlyphFail,       /* out of memory, etc */
+    ExaGlyphNeedFlush,  /* would evict a glyph already in the buffer */
+} ExaGlyphCacheResult;
+
+void
+exaGlyphsInit(ScreenPtr pScreen)
+{
+    ExaScreenPriv(pScreen);
+    int i = 0;
+
+    memset(pExaScr->glyphCaches, 0, sizeof(pExaScr->glyphCaches));
+
+    pExaScr->glyphCaches[i].format = PICT_a8;
+    pExaScr->glyphCaches[i].glyphWidth = pExaScr->glyphCaches[i].glyphHeight = 16;
+    i++;
+    pExaScr->glyphCaches[i].format = PICT_a8;
+    pExaScr->glyphCaches[i].glyphWidth = pExaScr->glyphCaches[i].glyphHeight = 32;
+    i++;
+    pExaScr->glyphCaches[i].format = PICT_a8r8g8b8;
+    pExaScr->glyphCaches[i].glyphWidth = pExaScr->glyphCaches[i].glyphHeight = 16;
+    i++;
+    pExaScr->glyphCaches[i].format = PICT_a8r8g8b8;
+    pExaScr->glyphCaches[i].glyphWidth = pExaScr->glyphCaches[i].glyphHeight = 32;
+    i++;
+
+    assert(i == EXA_NUM_GLYPH_CACHES);
+    
+    for (i = 0; i < EXA_NUM_GLYPH_CACHES; i++) {
+	pExaScr->glyphCaches[i].columns = CACHE_PICTURE_WIDTH / pExaScr->glyphCaches[i].glyphWidth;
+	pExaScr->glyphCaches[i].size = 256;
+	pExaScr->glyphCaches[i].hashSize = 557;
+    }
+}
+
+static void
+exaUnrealizeGlyphCaches(ScreenPtr    pScreen,
+			unsigned int format)
+{
+    ExaScreenPriv(pScreen);
+    int i;
+
+    for (i = 0; i < EXA_NUM_GLYPH_CACHES; i++) {
+	ExaGlyphCachePtr cache = &pExaScr->glyphCaches[i];
+	
+	if (cache->format != format)
+	    continue;
+
+	if (cache->picture) {
+	    FreePicture ((pointer) cache->picture, (XID) 0);
+	    cache->picture = NULL;
+	}
+
+	if (cache->hashEntries) {
+	    xfree(cache->hashEntries);
+	    cache->hashEntries = NULL;
+	}
+	
+	if (cache->glyphs) {
+	    xfree(cache->glyphs);
+	    cache->glyphs = NULL;
+	}
+	cache->glyphCount = 0;
+    }
+}
+
+/* All caches for a single format share a single pixmap for glyph storage,
+ * allowing mixing glyphs of different sizes without paying a penalty
+ * for switching between source pixmaps. (Note that for a size of font
+ * right at the border between two sizes, we might be switching for almost
+ * every glyph.)
+ *
+ * This function allocates the storage pixmap, and then fills in the
+ * rest of the allocated structures for all caches with the given format.
+ */
+static Bool
+exaRealizeGlyphCaches(ScreenPtr    pScreen,
+		      unsigned int format)
+{
+    ExaScreenPriv(pScreen);
+
+    int depth = PIXMAN_FORMAT_DEPTH(format);
+    PictFormatPtr pPictFormat;
+    PixmapPtr pPixmap;
+    PicturePtr pPicture;
+    int height;
+    int i;
+    int	error;
+
+    pPictFormat = PictureMatchFormat(pScreen, depth, format);
+    if (!pPictFormat)
+	return FALSE;
+    
+    /* Compute the total vertical size needed for the format */
+
+    height = 0;
+    for (i = 0; i < EXA_NUM_GLYPH_CACHES; i++) {
+	ExaGlyphCachePtr cache = &pExaScr->glyphCaches[i];
+	int rows;
+	
+	if (cache->format != format)
+	    continue;
+
+	rows = (cache->size + cache->columns - 1) / cache->columns;
+
+	height += rows * cache->glyphHeight;
+    }
+
+    /* Now allocate the pixmap and picture */
+       
+    pPixmap = (*pScreen->CreatePixmap) (pScreen,
+					CACHE_PICTURE_WIDTH,
+					height, depth, 0);
+    if (!pPixmap)
+	return FALSE;
+
+    pPicture = CreatePicture(0, &pPixmap->drawable, pPictFormat,
+			     0, 0, serverClient, &error);
+
+    (*pScreen->DestroyPixmap) (pPixmap); /* picture holds a refcount */
+
+    if (!pPicture)
+	return FALSE;
+
+    /* And store the picture in all the caches for the format */
+    
+    for (i = 0; i < EXA_NUM_GLYPH_CACHES; i++) {
+	ExaGlyphCachePtr cache = &pExaScr->glyphCaches[i];
+	int j;
+
+	if (cache->format != format)
+	    continue;
+
+	cache->picture = pPicture;
+	cache->picture->refcnt++;
+	cache->hashEntries = xalloc(sizeof(int) * cache->hashSize);
+	cache->glyphs = xalloc(sizeof(ExaCachedGlyphRec) * cache->size);
+	cache->glyphCount = 0;
+
+	if (!cache->hashEntries || !cache->glyphs)
+	    goto bail;
+
+	for (j = 0; j < cache->hashSize; j++)
+	    cache->hashEntries[j] = -1;
+	
+	cache->evictionPosition = rand() % cache->size;
+    }
+
+    /* Each cache references the picture individually */
+    FreePicture ((pointer) pPicture, (XID) 0);
+    return TRUE;
+
+bail:
+    exaUnrealizeGlyphCaches(pScreen, format);
+    return FALSE;
+}
+
+void
+exaGlyphsFini (ScreenPtr pScreen)
+{
+    ExaScreenPriv(pScreen);
+    int i;
+
+    for (i = 0; i < EXA_NUM_GLYPH_CACHES; i++) {
+	ExaGlyphCachePtr cache = &pExaScr->glyphCaches[i];
+
+	if (cache->picture)
+	    exaUnrealizeGlyphCaches(pScreen, cache->format);
+    }
+}
+
+static int
+exaGlyphCacheHashLookup(ExaGlyphCachePtr cache,
+			GlyphPtr         pGlyph)
+{
+    int slot;
+
+    slot = (*(CARD32 *) pGlyph->sha1) % cache->hashSize;
+    
+    while (TRUE) { /* hash table can never be full */
+	int entryPos = cache->hashEntries[slot];
+	if (entryPos == -1)
+	    return -1;
+
+	if (memcmp(pGlyph->sha1, cache->glyphs[entryPos].sha1, sizeof(pGlyph->sha1)) == 0){
+	    DBG_GLYPH_CACHE((" found entry at %d\n", slot));
+	    return entryPos;
+	}
+	    
+	DBG_GLYPH_CACHE((" lookup linear probe bumpalong\n"));
+	slot--;
+	if (slot < 0)
+	    slot = cache->hashSize - 1;
+    }
+}
+
+static void
+exaGlyphCacheHashInsert(ExaGlyphCachePtr cache,
+			GlyphPtr         pGlyph,
+			int              pos)
+{
+    int slot;
+
+    memcpy(cache->glyphs[pos].sha1, pGlyph->sha1, sizeof(pGlyph->sha1));
+    
+    slot = (*(CARD32 *) pGlyph->sha1) % cache->hashSize;
+    
+    while (TRUE) { /* hash table can never be full */
+	if (cache->hashEntries[slot] == -1) {
+	    DBG_GLYPH_CACHE((" inserting entry at %d\n", slot));
+	    cache->hashEntries[slot] = pos;
+	    return;
+	}
+	    
+	slot--;
+	if (slot < 0)
+	    slot = cache->hashSize - 1;
+    }
+}
+
+static void
+exaGlyphCacheHashRemove(ExaGlyphCachePtr cache,
+			int              pos)
+{
+    int slot;
+    int emptiedSlot = -1;
+
+    slot = (*(CARD32 *) cache->glyphs[pos].sha1) % cache->hashSize;
+
+    while (TRUE) { /* hash table can never be full */
+	int entryPos = cache->hashEntries[slot];
+	
+	if (entryPos == -1)
+	    return;
+
+	if (entryPos == pos) {
+	    cache->hashEntries[slot] = -1;
+	    emptiedSlot = slot;
+	} else if (emptiedSlot != -1) {
+	    /* See if we can move this entry into the emptied slot, we can't
+	     * do that if if entry would have hashed between the current position
+	     * and the emptied slot. (taking wrapping into account). Bad positions
+	     * are:
+	     *
+	     * |   XXXXXXXXXX             |
+	     *     i         j            
+	     *                            
+	     * |XXX                   XXXX|
+	     *     j                  i
+	     *
+	     * i - slot, j - emptiedSlot
+	     *
+	     * (Knuth 6.4R)
+	     */
+	    
+	    int entrySlot = (*(CARD32 *) cache->glyphs[entryPos].sha1) % cache->hashSize;
+
+	    if (!((entrySlot >= slot && entrySlot < emptiedSlot) ||
+		  (emptiedSlot < slot && (entrySlot < emptiedSlot || entrySlot >= slot)))) 
+	    {
+		cache->hashEntries[emptiedSlot] = entryPos;
+		cache->hashEntries[slot] = -1;
+		emptiedSlot = slot;
+	    }
+	}
+	
+	slot--;
+	if (slot < 0)
+	    slot = cache->hashSize - 1;
+    }
+}
+
+static ExaGlyphCacheResult
+exaGlyphCacheBufferGlyph(ScreenPtr         pScreen,
+			 ExaGlyphCachePtr  cache,
+			 ExaGlyphBufferPtr buffer,
+			 GlyphPtr          pGlyph,
+			 int               xGlyph,
+			 int               yGlyph)
+{
+    ExaGlyphRenderPtr glyphRec;
+    int pos;
+    
+    if (buffer->source && buffer->source != cache->picture)
+	return ExaGlyphNeedFlush;
+
+    if (!cache->picture) {
+	if (!exaRealizeGlyphCaches(pScreen, cache->format))
+	    return ExaGlyphFail;
+    }
+
+    DBG_GLYPH_CACHE(("(%d,%d,%s): buffering glyph %lx\n",
+		     cache->glyphWidth, cache->glyphHeight, cache->format == PICT_a8 ? "A" : "ARGB",
+		     (long)*(CARD32 *) pGlyph->sha1));
+   
+    pos = exaGlyphCacheHashLookup(cache, pGlyph);
+    if (pos != -1) {
+	DBG_GLYPH_CACHE(("  found existing glyph at %d\n", pos));
+    } else {
+	if (cache->glyphCount < cache->size) {
+	    /* Space remaining; we fill from the start */
+	    pos = cache->glyphCount;
+	    cache->glyphCount++;
+	    DBG_GLYPH_CACHE(("  storing glyph in free space at %d\n", pos));
+
+	    exaGlyphCacheHashInsert(cache, pGlyph, pos);
+
+	} else {
+	    /* Need to evict an entry. We have to see if any glyphs
+	     * already in the output buffer were at this position in
+	     * the cache
+	     */
+	    
+	    pos = cache->evictionPosition;
+	    DBG_GLYPH_CACHE(("  evicting glyph at %d\n", pos));
+	    if (buffer->count) {
+		int x, y;
+		int i;
+		
+		x = (pos % cache->columns) * cache->glyphWidth;
+		y = (pos / cache->columns) * cache->glyphHeight;
+
+		for (i = 0; i < buffer->count; i++) {
+		    if (buffer->glyphs[i].xSrc == x && buffer->glyphs[i].ySrc == y) {
+			DBG_GLYPH_CACHE(("  must flush buffer\n"));
+			return ExaGlyphNeedFlush;
+		    }
+		}
+	    }
+
+	    /* OK, we're all set, swap in the new glyph */
+	    exaGlyphCacheHashRemove(cache, pos);
+	    exaGlyphCacheHashInsert(cache, pGlyph, pos);
+
+	    /* And pick a new eviction position */
+	    cache->evictionPosition = rand() % cache->size;
+	}
+
+	/* Now actually upload the glyph into the cache picture */
+
+	CompositePicture (PictOpSrc,
+			  GlyphPicture(pGlyph)[pScreen->myNum],
+			  None,
+			  cache->picture,
+			  0, 0,
+			  0, 0,
+			  (pos % cache->columns) * cache->glyphWidth,
+			  (pos / cache->columns) * cache->glyphHeight,
+			  pGlyph->info.width,
+			  pGlyph->info.height);
+    }
+    
+
+    buffer->source = cache->picture;
+	    
+    glyphRec = &buffer->glyphs[buffer->count];
+    glyphRec->xSrc = (pos % cache->columns) * cache->glyphWidth;
+    glyphRec->ySrc = (pos / cache->columns) * cache->glyphHeight;
+    glyphRec->xDst = xGlyph - pGlyph->info.x;
+    glyphRec->yDst = yGlyph - pGlyph->info.y;
+    glyphRec->width = pGlyph->info.width;
+    glyphRec->height = pGlyph->info.height;
+	    
+    buffer->count++;
+
+    return ExaGlyphSuccess;
+}
+
+static ExaGlyphCacheResult
+exaBufferGlyph(ScreenPtr         pScreen,
+	       ExaGlyphBufferPtr buffer,
+	       GlyphPtr          pGlyph,
+	       int               xGlyph,
+	       int               yGlyph)
+{
+    ExaScreenPriv(pScreen);
+    unsigned int format = (GlyphPicture(pGlyph)[pScreen->myNum])->format;
+    int width = pGlyph->info.width;
+    int height = pGlyph->info.width;
+    ExaGlyphRenderPtr glyphRec;
+    PicturePtr source;
+    int i;
+
+    if (buffer->count == GLYPH_BUFFER_SIZE)
+	return ExaGlyphNeedFlush;
+    
+    for (i = 0; i < EXA_NUM_GLYPH_CACHES; i++) {
+	ExaGlyphCachePtr cache = &pExaScr->glyphCaches[i];
+
+	if (format == cache->format &&
+	    width <= cache->glyphWidth &&
+	    height <= cache->glyphHeight) {
+	    ExaGlyphCacheResult result = exaGlyphCacheBufferGlyph(pScreen, &pExaScr->glyphCaches[i],
+								  buffer,
+								  pGlyph, xGlyph, yGlyph);
+	    switch (result) {
+	    case ExaGlyphFail:
+		break;
+	    case ExaGlyphSuccess:
+	    case ExaGlyphNeedFlush:
+		return result;
+	    }
+	}
+    }
+
+    /* Couldn't find the glyph in the cache, use the glyph picture directly */
+
+    source = GlyphPicture(pGlyph)[pScreen->myNum];
+    if (buffer->source && buffer->source != source)
+	return ExaGlyphNeedFlush;
+
+    buffer->source = source;
+    
+    glyphRec = &buffer->glyphs[buffer->count];
+    glyphRec->xSrc = 0;
+    glyphRec->ySrc = 0;
+    glyphRec->xDst = xGlyph - pGlyph->info.x;
+    glyphRec->yDst = yGlyph - pGlyph->info.y;
+    glyphRec->width = pGlyph->info.width;
+    glyphRec->height = pGlyph->info.height;
+
+    buffer->count++;
+
+    return ExaGlyphSuccess;
+}
+
+static void
+exaGlyphsToMask(PicturePtr        pMask,
+		ExaGlyphBufferPtr buffer)
+{
+    int i;
+
+    for (i = 0; i < buffer->count; i++) {
+	ExaGlyphRenderPtr glyphRec = &buffer->glyphs[i];
+	
+	CompositePicture (PictOpAdd,
+			  buffer->source,
+			  None,
+			  pMask,
+			  glyphRec->xSrc,
+			  glyphRec->ySrc,
+			  0, 0,
+			  glyphRec->xDst,
+			  glyphRec->yDst,
+			  glyphRec->width,
+			  glyphRec->height);
+    }
+    
+    buffer->count = 0;
+    buffer->source = NULL;
+}
+
+static void
+exaGlyphsToDst(CARD8		 op,
+	       PicturePtr	 pSrc,
+	       PicturePtr	 pDst,
+	       ExaGlyphBufferPtr buffer,
+	       INT16		 xSrc,
+	       INT16		 ySrc,
+	       INT16		 xDst,
+	       INT16		 yDst)
+{
+    int i;
+
+    for (i = 0; i < buffer->count; i++) {
+	ExaGlyphRenderPtr glyphRec = &buffer->glyphs[i];
+	
+	CompositePicture (op,
+			  pSrc,
+			  buffer->source,
+			  pDst,
+			  xSrc + glyphRec->xDst - xDst,
+			  ySrc + glyphRec->yDst - yDst,
+			  glyphRec->xSrc,
+			  glyphRec->ySrc,
+			  glyphRec->xDst,
+			  glyphRec->yDst,
+			  glyphRec->width,
+			  glyphRec->height);
+    }
+    
+    buffer->count = 0;
+    buffer->source = NULL;
+}
+
+/* Cut and paste from render/glyph.c - probably should export it instead */
+static void
+GlyphExtents (int		nlist,
+	      GlyphListPtr	list,
+	      GlyphPtr	       *glyphs,
+	      BoxPtr		extents)
+{
+    int		x1, x2, y1, y2;
+    int		n;
+    GlyphPtr	glyph;
+    int		x, y;
+    
+    x = 0;
+    y = 0;
+    extents->x1 = MAXSHORT;
+    extents->x2 = MINSHORT;
+    extents->y1 = MAXSHORT;
+    extents->y2 = MINSHORT;
+    while (nlist--)
+    {
+	x += list->xOff;
+	y += list->yOff;
+	n = list->len;
+	list++;
+	while (n--)
+	{
+	    glyph = *glyphs++;
+	    x1 = x - glyph->info.x;
+	    if (x1 < MINSHORT)
+		x1 = MINSHORT;
+	    y1 = y - glyph->info.y;
+	    if (y1 < MINSHORT)
+		y1 = MINSHORT;
+	    x2 = x1 + glyph->info.width;
+	    if (x2 > MAXSHORT)
+		x2 = MAXSHORT;
+	    y2 = y1 + glyph->info.height;
+	    if (y2 > MAXSHORT)
+		y2 = MAXSHORT;
+	    if (x1 < extents->x1)
+		extents->x1 = x1;
+	    if (x2 > extents->x2)
+		extents->x2 = x2;
+	    if (y1 < extents->y1)
+		extents->y1 = y1;
+	    if (y2 > extents->y2)
+		extents->y2 = y2;
+	    x += glyph->info.xOff;
+	    y += glyph->info.yOff;
+	}
+    }
+}
+
+#define NeedsComponent(f) (PICT_FORMAT_A(f) != 0 && PICT_FORMAT_RGB(f) != 0)
+
+void
+exaGlyphs (CARD8 	 op,
+	   PicturePtr	 pSrc,
+	   PicturePtr	 pDst,
+	   PictFormatPtr maskFormat,
+	   INT16	 xSrc,
+	   INT16	 ySrc,
+	   int		 nlist,
+	   GlyphListPtr	 list,
+	   GlyphPtr	*glyphs)
+{
+    PicturePtr	pPicture;
+    PixmapPtr   pMaskPixmap = 0;
+    PicturePtr  pMask;
+    ScreenPtr   pScreen = pDst->pDrawable->pScreen;
+    int		width = 0, height = 0;
+    int		x, y;
+    int		xDst = list->xOff, yDst = list->yOff;
+    int		n;
+    GlyphPtr	glyph;
+    int		error;
+    BoxRec	extents = {0, 0, 0, 0};
+    CARD32	component_alpha;
+    ExaGlyphBuffer buffer;
+
+    if (maskFormat)
+    {
+	GCPtr	    pGC;
+	xRectangle  rect;
+
+	GlyphExtents (nlist, list, glyphs, &extents);
+
+	if (extents.x2 <= extents.x1 || extents.y2 <= extents.y1)
+	    return;
+	width = extents.x2 - extents.x1;
+	height = extents.y2 - extents.y1;
+	pMaskPixmap = (*pScreen->CreatePixmap) (pScreen, width, height,
+						maskFormat->depth,
+						CREATE_PIXMAP_USAGE_SCRATCH);
+	if (!pMaskPixmap)
+	    return;
+	component_alpha = NeedsComponent(maskFormat->format);
+	pMask = CreatePicture (0, &pMaskPixmap->drawable,
+			       maskFormat, CPComponentAlpha, &component_alpha,
+			       serverClient, &error);
+	if (!pMask)
+	{
+	    (*pScreen->DestroyPixmap) (pMaskPixmap);
+	    return;
+	}
+	pGC = GetScratchGC (pMaskPixmap->drawable.depth, pScreen);
+	ValidateGC (&pMaskPixmap->drawable, pGC);
+	rect.x = 0;
+	rect.y = 0;
+	rect.width = width;
+	rect.height = height;
+	(*pGC->ops->PolyFillRect) (&pMaskPixmap->drawable, pGC, 1, &rect);
+	FreeScratchGC (pGC);
+	x = -extents.x1;
+	y = -extents.y1;
+    }
+    else
+    {
+	pMask = pDst;
+	x = 0;
+	y = 0;
+    }
+    buffer.count = 0;
+    buffer.source = NULL;
+    while (nlist--)
+    {
+	x += list->xOff;
+	y += list->yOff;
+	n = list->len;
+	while (n--)
+	{
+	    glyph = *glyphs++;
+	    pPicture = GlyphPicture (glyph)[pScreen->myNum];
+
+	    if (exaBufferGlyph(pScreen, &buffer, glyph, x, y) == ExaGlyphNeedFlush)
+	    {
+		if (maskFormat)
+		    exaGlyphsToMask(pMask, &buffer);
+		else
+		    exaGlyphsToDst(op, pSrc, pDst, &buffer,
+				   xSrc, ySrc, xDst, yDst);
+
+		exaBufferGlyph(pScreen, &buffer, glyph, x, y);
+	    }
+
+	    x += glyph->info.xOff;
+	    y += glyph->info.yOff;
+	}
+	list++;
+    }
+    
+    if (maskFormat)
+	exaGlyphsToMask(pMask, &buffer);
+    else
+	exaGlyphsToDst(op, pSrc, pDst, &buffer,
+		       xSrc, ySrc, xDst, yDst);
+    
+    if (maskFormat)
+    {
+	x = extents.x1;
+	y = extents.y1;
+	CompositePicture (op,
+			  pSrc,
+			  pMask,
+			  pDst,
+			  xSrc + x - xDst,
+			  ySrc + y - yDst,
+			  0, 0,
+			  x, y,
+			  width, height);
+	FreePicture ((pointer) pMask, (XID) 0);
+	(*pScreen->DestroyPixmap) (pMaskPixmap);
+    }
+}
diff --git a/exa/exa_priv.h b/exa/exa_priv.h
index 0138e4a..aaceeb8 100644
--- a/exa/exa_priv.h
+++ b/exa/exa_priv.h
@@ -61,6 +61,7 @@
 #define DEBUG_MIGRATE		0
 #define DEBUG_PIXMAP		0
 #define DEBUG_OFFSCREEN		0
+#define DEBUG_GLYPH_CACHE	0
 
 #if DEBUG_TRACE_FALL
 #define EXA_FALLBACK(x)     					\
@@ -95,6 +96,37 @@ enum ExaMigrationHeuristic {
     ExaMigrationSmart
 };
 
+typedef struct {
+    unsigned char sha1[20];
+} ExaCachedGlyphRec, *ExaCachedGlyphPtr;
+
+typedef struct {
+    /* The identity of the cache, statically configured at initialization */
+    unsigned int format;
+    int glyphWidth;
+    int glyphHeight;
+
+    int size; /* Size of cache; eventually this should be dynamically determined */
+
+    /* Hash table mapping from glyph sha1 to position in the glyph; we use
+     * open addressing with a hash table size determined based on size and large
+     * enough so that we always have a good amount of free space, so we can
+     * use linear probing. (Linear probing is preferrable to double hashing
+     * here because it allows us to easily remove entries.)
+     */
+    int *hashEntries;
+    int hashSize;
+    
+    ExaCachedGlyphPtr glyphs;
+    int glyphCount; /* Current number of glyphs */
+    
+    PicturePtr picture;   /* Where the glyphs of the cache are stored */
+    int columns;          /* Number of columns the glyphs are layed out in */
+    int evictionPosition; /* Next random position to evict a glyph */
+} ExaGlyphCacheRec, *ExaGlyphCachePtr;
+
+#define EXA_NUM_GLYPH_CACHES 4
+
 typedef void (*EnableDisableFBAccessProcPtr)(int, Bool);
 typedef struct {
     ExaDriverPtr info;
@@ -122,6 +154,8 @@ typedef struct {
     unsigned			 disableFbCount;
     Bool			 optimize_migration;
     unsigned			 offScreenCounter;
+
+    ExaGlyphCacheRec             glyphCaches[EXA_NUM_GLYPH_CACHES];
 } ExaScreenPrivRec, *ExaScreenPrivPtr;
 
 /*
@@ -432,6 +466,13 @@ exaTriangles (CARD8 op, PicturePtr pSrc, PicturePtr pDst,
 	      PictFormatPtr maskFormat, INT16 xSrc, INT16 ySrc,
 	      int ntri, xTriangle *tris);
 
+/* exa_glyph.c */
+void
+exaGlyphsInit(ScreenPtr pScreen);
+
+void
+exaGlyphsFini (ScreenPtr pScreen);
+
 void
 exaGlyphs (CARD8	op,
 	  PicturePtr	pSrc,
commit e9734306088e12f2cd68bf347ecf8415be4f0268
Author: Jeremy Huddleston <jeremyhu at freedesktop.org>
Date:   Mon Apr 28 11:47:49 2008 -0700

    XQuartz: More startup / threading house cleaning.
    (cherry picked from commit 72653c24c00dfba64ce35a3d400598bcd77defc1)

diff --git a/hw/xquartz/X11Application.h b/hw/xquartz/X11Application.h
index 3869df9..8e7fed2 100644
--- a/hw/xquartz/X11Application.h
+++ b/hw/xquartz/X11Application.h
@@ -71,7 +71,7 @@ void X11ApplicationSetCanQuit (int state);
 void X11ApplicationServerReady (void);
 void X11ApplicationShowHideMenubar (int state);
 
-void X11ApplicationMain(int argc, const char **argv);
+void X11ApplicationMain(int argc, char **argv, char **envp);
 
 extern int X11EnableKeyEquivalents;
 extern int quartzHasRoot, quartzEnableRootless;
diff --git a/hw/xquartz/X11Application.m b/hw/xquartz/X11Application.m
index 7680437..e10e71e 100644
--- a/hw/xquartz/X11Application.m
+++ b/hw/xquartz/X11Application.m
@@ -47,9 +47,6 @@
 #include <mach/mach.h>
 #include <unistd.h>
 
-#include <pthread.h>
-extern pthread_cond_t server_can_start_cond;
-
 #define DEFAULTS_FILE "/usr/X11/lib/X11/xserver/Xquartz.plist"
 
 int X11EnableKeyEquivalents = TRUE;
@@ -776,7 +773,7 @@ environment?", @"Startup xinitrc dialog");
     [X11App prefs_synchronize];
 }
 
-void X11ApplicationMain (int argc, const char **argv) {
+void X11ApplicationMain (int argc, char **argv, char **envp) {
     NSAutoreleasePool *pool;
 
 #ifdef DEBUG
@@ -804,7 +801,7 @@ void X11ApplicationMain (int argc, const char **argv) {
     NSMaxY([[NSScreen mainScreen] visibleFrame]);
 
     /* Tell the server thread that it can proceed */
-    pthread_cond_broadcast(&server_can_start_cond);
+    QuartzInitServer(argc, argv, envp);
 
     [NSApp run];
     /* not reached */
diff --git a/hw/xquartz/X11Controller.h b/hw/xquartz/X11Controller.h
index d33752e..7942bc4 100644
--- a/hw/xquartz/X11Controller.h
+++ b/hw/xquartz/X11Controller.h
@@ -100,6 +100,6 @@
 
 #endif /* __OBJC__ */
 
-void X11ControllerMain(int argc, const char **argv);
+void X11ControllerMain(int argc, char **argv, char **envp);
 
 #endif /* X11CONTROLLER_H */
diff --git a/hw/xquartz/X11Controller.m b/hw/xquartz/X11Controller.m
index 01470e5..df328f3 100644
--- a/hw/xquartz/X11Controller.m
+++ b/hw/xquartz/X11Controller.m
@@ -756,6 +756,6 @@ objectValueForTableColumn:(NSTableColumn *)tableColumn row:(int)row
 
 @end
 
-void X11ControllerMain(int argc, const char **argv) {
-    X11ApplicationMain (argc, argv);
+void X11ControllerMain(int argc, char **argv, char **envp) {
+    X11ApplicationMain (argc, argv, envp);
 }
diff --git a/hw/xquartz/quartz.h b/hw/xquartz/quartz.h
index e116023..1b6d71f 100644
--- a/hw/xquartz/quartz.h
+++ b/hw/xquartz/quartz.h
@@ -128,6 +128,7 @@ Bool QuartzAddScreen(int index, ScreenPtr pScreen);
 Bool QuartzSetupScreen(int index, ScreenPtr pScreen);
 void QuartzInitOutput(int argc,char **argv);
 void QuartzInitInput(int argc, char **argv);
+void QuartzInitServer(int argc, char **argv, char **envp);
 void QuartzGiveUp(void);
 void QuartzProcessEvent(xEvent *xe);
 void QuartzDisplayChangedHandler(int screenNum, xEventPtr xe, DeviceIntPtr dev, int nevents);
diff --git a/hw/xquartz/quartzStartup.c b/hw/xquartz/quartzStartup.c
index 34eaf8a..7b6a1a6 100644
--- a/hw/xquartz/quartzStartup.c
+++ b/hw/xquartz/quartzStartup.c
@@ -58,19 +58,10 @@ struct arg {
     char **envp;
 };
 
-pthread_cond_t server_can_start_cond = PTHREAD_COND_INITIALIZER;
-
 static void server_thread (void *arg) {
-    struct arg *args = (struct arg *)arg;
-
-    /* Wait to be told we can continue */
-    pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
-    pthread_mutex_lock(&mutex);
-    pthread_cond_wait(&server_can_start_cond, &mutex);
-    pthread_mutex_unlock(&mutex);
-    pthread_mutex_destroy(&mutex);
-
-    exit (dix_main(args->argc, args->argv, args->envp));
+    struct arg args = *((struct arg *)arg);
+    free(arg);
+    exit (dix_main(args.argc, args.argv, args.envp));
 }
 
 static pthread_t create_thread (void *func, void *arg) {
@@ -86,16 +77,27 @@ static pthread_t create_thread (void *func, void *arg) {
     return tid;
 }
 
+void QuartzInitServer(int argc, char **argv, char **envp) {
+    struct arg *args = (struct arg*)malloc(sizeof(struct arg));
+    if(!args)
+        FatalError("Could not allocate memory.\n");
+    
+    args->argc = argc;
+    args->argv = argv;
+    args->envp = envp;
+    
+    APPKIT_THREAD_ID = pthread_self();
+    SERVER_THREAD_ID = create_thread(server_thread, args);
+
+    if (!SERVER_THREAD_ID) {
+        FatalError("can't create secondary thread\n");
+    }
+}
+
 int main(int argc, char **argv, char **envp) {
     int         i;
     int         fd[2];
 
-    /* Store the args to pass to dix_main() */
-    struct arg  args;
-    args.argc = argc;
-    args.argv = argv;
-    args.envp = envp;
-
     // Make a pipe to pass events
     assert( pipe(fd) == 0 );
     darwinEventReadFD = fd[0];
@@ -112,18 +114,8 @@ int main(int argc, char **argv, char **envp) {
 
     /* Create the audio mutex */
     QuartzAudioInit();
-    
-    pthread_cond_init(&server_can_start_cond, NULL); 
-    
-    APPKIT_THREAD_ID = pthread_self();
-    SERVER_THREAD_ID = create_thread(server_thread, &args);
-
-    if (!SERVER_THREAD_ID) {
-        ErrorF("can't create secondary thread\n");
-        exit (1);
-    }
 
     QuartzMoveToForeground();
-    X11ControllerMain(argc, (const char **)argv);
+    X11ControllerMain(argc, argv, envp);
     exit(0);
 }
commit 4b46fc931e61bec0abd6a86062e46dd7a408e745
Author: Jeremy Huddleston <jeremyhu at freedesktop.org>
Date:   Mon Apr 28 10:50:51 2008 -0700

    XQuartz: Updated Localizable.strings
    (cherry picked from commit d8d9c866b90fb24c93bd6e25fa90f8f2bf58ad34)

diff --git a/hw/xquartz/bundle/English.lproj/Localizable.strings b/hw/xquartz/bundle/English.lproj/Localizable.strings
index c83b085..63a1352 100644
Binary files a/hw/xquartz/bundle/English.lproj/Localizable.strings and b/hw/xquartz/bundle/English.lproj/Localizable.strings differ
commit 4017ebe5bfa7a261cd1135801756c44e9fe93ca1
Author: Jeremy Huddleston <jeremyhu at freedesktop.org>
Date:   Sun Apr 27 00:01:14 2008 -0700

    XQuartz: Added missing Xquartz.man.pre to EXTRA_DIST
    (cherry picked from commit 03e707987f7f32e47dd0355c6d16bfb9169a379b)

diff --git a/hw/xquartz/xpr/Makefile.am b/hw/xquartz/xpr/Makefile.am
index 12009fb..41f2b86 100644
--- a/hw/xquartz/xpr/Makefile.am
+++ b/hw/xquartz/xpr/Makefile.am
@@ -47,6 +47,7 @@ include $(top_srcdir)/cpprules.in
 	cp $< $@
 
 EXTRA_DIST = \
+	Xquartz.man.pre \
 	dri.h \
 	dristruct.h \
 	appledri.h \
commit 0bd28315afc3b7223f8ff9f17597db09500a9388
Author: Jeremy Huddleston <jeremyhu at freedesktop.org>
Date:   Sat Apr 26 23:00:42 2008 -0700

    Xquartz: Added missing to EXTRA_DIST
    (cherry picked from commit f4b963256feb03e9e6b5521bdefeb390e9a49688)

diff --git a/hw/xquartz/Makefile.am b/hw/xquartz/Makefile.am
index ccef5f6..1465a52 100644
--- a/hw/xquartz/Makefile.am
+++ b/hw/xquartz/Makefile.am
@@ -52,4 +52,6 @@ EXTRA_DIST = \
 	quartzForeground.h \
 	quartzKeyboard.h \
 	quartzPasteboard.h \
+	sanitizedCarbon.h \
+	sanitizedCocoa.h \
 	threadSafety.h
commit ef1c52053755fa14b4ca98b22c506f73f5f4a4b7
Author: Jeremy Huddleston <jeremyhu at freedesktop.org>
Date:   Sat Apr 26 19:21:05 2008 -0700

    XQuartz: Cleaned up startup and thread creation a tad.
    (cherry picked from commit c861fe00e112b21ee0156d09a6cd5281642a1dcc)

diff --git a/dix/main.c b/dix/main.c
index 6d9dd33..fbd6413 100644
--- a/dix/main.c
+++ b/dix/main.c
@@ -237,12 +237,11 @@ static int indexForScanlinePad[ 65 ] = {
 #define MIN(a,b) (((a) < (b)) ? (a) : (b))
 #endif
 
-#ifdef __APPLE__
-void DarwinHandleGUI(int argc, char **argv, char **envp);
+#ifdef XQUARTZ
+int dix_main(int argc, char *argv[], char *envp[])
+#else
+int main(int argc, char *argv[], char *envp[])
 #endif
-
-int
-main(int argc, char *argv[], char *envp[])
 {
     int		i, j, k, error;
     char	*xauthfile;
@@ -256,13 +255,6 @@ main(int argc, char *argv[], char *envp[])
     PrinterInitGlobals();
 #endif
 
-#ifdef XQUARTZ
-    /* Quartz support on Mac OS X requires that the Cocoa event loop be in
-     * the main thread. This allows the X server main to be called again
-     * from another thread. */
-    DarwinHandleGUI(argc, argv, envp);
-#endif
-
     CheckUserParameters(argc, argv, envp);
 
     CheckUserAuthorization();
diff --git a/hw/xquartz/X11Application.h b/hw/xquartz/X11Application.h
index 47c605c..3869df9 100644
--- a/hw/xquartz/X11Application.h
+++ b/hw/xquartz/X11Application.h
@@ -71,7 +71,7 @@ void X11ApplicationSetCanQuit (int state);
 void X11ApplicationServerReady (void);
 void X11ApplicationShowHideMenubar (int state);
 
-void X11ApplicationMain(int argc, const char **argv, void (*server_thread) (void *), void *server_arg);
+void X11ApplicationMain(int argc, const char **argv);
 
 extern int X11EnableKeyEquivalents;
 extern int quartzHasRoot, quartzEnableRootless;
diff --git a/hw/xquartz/X11Application.m b/hw/xquartz/X11Application.m
index eefa45f..7680437 100644
--- a/hw/xquartz/X11Application.m
+++ b/hw/xquartz/X11Application.m
@@ -35,6 +35,7 @@
 
 #include "quartzForeground.h"
 #include "quartzCommon.h"
+
 #import "X11Application.h"
 
 # include "darwin.h"
@@ -45,7 +46,9 @@
 # include "micmap.h"
 #include <mach/mach.h>
 #include <unistd.h>
+
 #include <pthread.h>
+extern pthread_cond_t server_can_start_cond;
 
 #define DEFAULTS_FILE "/usr/X11/lib/X11/xserver/Xquartz.plist"
 
@@ -732,19 +735,6 @@ void X11ApplicationShowHideMenubar (int state) {
     [n release];
 }
 
-static pthread_t create_thread (void *func, void *arg) {
-    pthread_attr_t attr;
-    pthread_t tid;
-	
-    pthread_attr_init (&attr);
-    pthread_attr_setscope (&attr, PTHREAD_SCOPE_SYSTEM);
-    pthread_attr_setdetachstate (&attr, PTHREAD_CREATE_DETACHED);
-    pthread_create (&tid, &attr, func, arg);
-    pthread_attr_destroy (&attr);
-	
-    return tid;
-}
-
 static void check_xinitrc (void) {
     char *tem, buf[1024];
     NSString *msg;
@@ -786,7 +776,7 @@ environment?", @"Startup xinitrc dialog");
     [X11App prefs_synchronize];
 }
 
-void X11ApplicationMain (int argc, const char **argv, void (*server_thread) (void *), void *server_arg) {
+void X11ApplicationMain (int argc, const char **argv) {
     NSAutoreleasePool *pool;
 
 #ifdef DEBUG
@@ -812,16 +802,9 @@ void X11ApplicationMain (int argc, const char **argv, void (*server_thread) (voi
     /* Calculate the height of the menubar so we can avoid it. */
     aquaMenuBarHeight = NSHeight([[NSScreen mainScreen] frame]) -
     NSMaxY([[NSScreen mainScreen] visibleFrame]);
-  
-    APPKIT_THREAD = pthread_self();
-    SERVER_THREAD = create_thread (server_thread, server_arg);
-
-    if (!SERVER_THREAD) {
-        ErrorF("can't create secondary thread\n");
-        exit (1);
-    }
 
-    QuartzMoveToForeground();
+    /* Tell the server thread that it can proceed */
+    pthread_cond_broadcast(&server_can_start_cond);
 
     [NSApp run];
     /* not reached */
diff --git a/hw/xquartz/X11Controller.h b/hw/xquartz/X11Controller.h
index c5994bd..d33752e 100644
--- a/hw/xquartz/X11Controller.h
+++ b/hw/xquartz/X11Controller.h
@@ -100,6 +100,6 @@
 
 #endif /* __OBJC__ */
 
-void X11ControllerMain(int argc, const char **argv, void (*server_thread) (void *), void *server_arg);
+void X11ControllerMain(int argc, const char **argv);
 
 #endif /* X11CONTROLLER_H */
diff --git a/hw/xquartz/X11Controller.m b/hw/xquartz/X11Controller.m
index 8dfe4b3..01470e5 100644
--- a/hw/xquartz/X11Controller.m
+++ b/hw/xquartz/X11Controller.m
@@ -756,6 +756,6 @@ objectValueForTableColumn:(NSTableColumn *)tableColumn row:(int)row
 
 @end
 
-void X11ControllerMain(int argc, const char **argv, void (*server_thread) (void *), void *server_arg) {
-    X11ApplicationMain (argc, argv, server_thread, server_arg);
+void X11ControllerMain(int argc, const char **argv) {
+    X11ApplicationMain (argc, argv);
 }
diff --git a/hw/xquartz/darwinEvents.c b/hw/xquartz/darwinEvents.c
index 0643e53..86e7704 100644
--- a/hw/xquartz/darwinEvents.c
+++ b/hw/xquartz/darwinEvents.c
@@ -78,7 +78,8 @@ static int old_flags = 0;  // last known modifier state
 
 xEvent *darwinEvents = NULL;
 
-pthread_mutex_t mieqEnqueue_mutex;
+pthread_mutex_t mieqEnqueue_mutex = PTHREAD_MUTEX_INITIALIZER;
+
 static inline void mieqEnqueue_lock(void) {
     int err;
     if((err = pthread_mutex_lock(&mieqEnqueue_mutex))) {
@@ -303,17 +304,11 @@ static void DarwinEventHandler(int screenNum, xEventPtr xe, DeviceIntPtr dev, in
 }
 
 Bool DarwinEQInit(DevicePtr pKbd, DevicePtr pPtr) { 
-    int err;
-
     if (!darwinEvents)
         darwinEvents = (xEvent *)xcalloc(sizeof(xEvent), GetMaximumEventsNum());
     if (!darwinEvents)
         FatalError("Couldn't allocate event buffer\n");
 
-    if((err = pthread_mutex_init(&mieqEnqueue_mutex, NULL))) {
-        FatalError("Couldn't allocate mieqEnqueue mutex: %d.\n", err);
-    }
-    
     mieqInit();
     mieqSetHandler(kXquartzReloadKeymap, DarwinKeyboardReloadHandler);
     mieqSetHandler(kXquartzActivate, DarwinEventHandler);
diff --git a/hw/xquartz/quartz.c b/hw/xquartz/quartz.c
index 2cba5df..0635b48 100644
--- a/hw/xquartz/quartz.c
+++ b/hw/xquartz/quartz.c
@@ -39,7 +39,6 @@
 #include "quartz.h"
 #include "darwin.h"
 #include "darwinEvents.h"
-#include "quartzAudio.h"
 #include "pseudoramiX.h"
 #define _APPLEWM_SERVER_
 #include "applewmExt.h"
@@ -156,10 +155,6 @@ void QuartzInitOutput(
     int argc,
     char **argv )
 {
-    if (serverGeneration == 1) {
-        QuartzAudioInit();
-    }
-
     if (!RegisterBlockAndWakeupHandlers(QuartzBlockHandler,
                                         QuartzWakeupHandler,
                                         NULL))
diff --git a/hw/xquartz/quartzStartup.c b/hw/xquartz/quartzStartup.c
index 233e6e6..34eaf8a 100644
--- a/hw/xquartz/quartzStartup.c
+++ b/hw/xquartz/quartzStartup.c
@@ -37,54 +37,71 @@
 #include <unistd.h>
 #include <CoreFoundation/CoreFoundation.h>
 #include "quartzCommon.h"
+#include "quartzForeground.h"
 #include "X11Controller.h"
 #include "darwin.h"
+#include "darwinEvents.h"
+#include "quartzAudio.h"
 #include "quartz.h"
 #include "opaque.h"
 #include "micmap.h"
 
 #include <assert.h>
 
-char **envpGlobal;      // argcGlobal and argvGlobal
-                        // are from dix/globals.c
+#include <pthread.h>
 
-int main(int argc, char **argv, char **envp);
-void _InitHLTB(void);
-void DarwinHandleGUI(int argc, char **argv, char **envp);
+int dix_main(int argc, char **argv, char **envp);
+
+struct arg {
+    int argc;
+    char **argv;
+    char **envp;
+};
+
+pthread_cond_t server_can_start_cond = PTHREAD_COND_INITIALIZER;
 
 static void server_thread (void *arg) {
-  exit (main (argcGlobal, argvGlobal, envpGlobal));
+    struct arg *args = (struct arg *)arg;
+
+    /* Wait to be told we can continue */
+    pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
+    pthread_mutex_lock(&mutex);
+    pthread_cond_wait(&server_can_start_cond, &mutex);
+    pthread_mutex_unlock(&mutex);
+    pthread_mutex_destroy(&mutex);
+
+    exit (dix_main(args->argc, args->argv, args->envp));
 }
 
-/*
- * DarwinHandleGUI
- *  This function is called first from main(). The first time
- *  it is called we start the Mac OS X front end. The front end
- *  will call main() again from another thread to run the X
- *  server. On the second call this function loads the user
- *  preferences set by the Mac OS X front end.
- */
-void DarwinHandleGUI(int argc, char **argv, char **envp) {
-    static Bool been_here = FALSE;
+static pthread_t create_thread (void *func, void *arg) {
+    pthread_attr_t attr;
+    pthread_t tid;
+	
+    pthread_attr_init (&attr);
+    pthread_attr_setscope (&attr, PTHREAD_SCOPE_SYSTEM);
+    pthread_attr_setdetachstate (&attr, PTHREAD_CREATE_DETACHED);
+    pthread_create (&tid, &attr, func, arg);
+    pthread_attr_destroy (&attr);
+	
+    return tid;
+}
+
+int main(int argc, char **argv, char **envp) {
     int         i;
     int         fd[2];
 
-    if (been_here) {
-        return;
-    }
-    been_here = TRUE;
-    
+    /* Store the args to pass to dix_main() */
+    struct arg  args;
+    args.argc = argc;
+    args.argv = argv;
+    args.envp = envp;
+
     // Make a pipe to pass events
     assert( pipe(fd) == 0 );
     darwinEventReadFD = fd[0];
     darwinEventWriteFD = fd[1];
     fcntl(darwinEventReadFD, F_SETFL, O_NONBLOCK);
 
-    // Store command line arguments to pass back to main()
-    argcGlobal = argc;
-    argvGlobal = argv;
-    envpGlobal = envp;
-
     for (i = 1; i < argc; i++) {
         // Display version info without starting Mac OS X UI if requested
         if (!strcmp( argv[i], "-showconfig" ) || !strcmp( argv[i], "-version" )) {
@@ -93,16 +110,20 @@ void DarwinHandleGUI(int argc, char **argv, char **envp) {
         }
     }
 
-    /* Initially I ran the X server on the main thread, and received
-       events on the second thread. But now we may be using Carbon,
-       that needs to run on the main thread. (Otherwise, when it's
-       prebound, it will initialize itself on the wrong thread)
-       
-       grr.. but doing that means that if the X thread gets scheduled
-       before the main thread when we're _not_ prebound, things fail,
-       so initialize by hand. */
-
-    _InitHLTB();    
-    X11ControllerMain(argc, (const char **)argv, server_thread, NULL);
+    /* Create the audio mutex */
+    QuartzAudioInit();
+    
+    pthread_cond_init(&server_can_start_cond, NULL); 
+    
+    APPKIT_THREAD_ID = pthread_self();
+    SERVER_THREAD_ID = create_thread(server_thread, &args);
+
+    if (!SERVER_THREAD_ID) {
+        ErrorF("can't create secondary thread\n");
+        exit (1);
+    }
+
+    QuartzMoveToForeground();
+    X11ControllerMain(argc, (const char **)argv);
     exit(0);
 }
diff --git a/hw/xquartz/threadSafety.c b/hw/xquartz/threadSafety.c
index 7835de6..b5a4ecf 100644
--- a/hw/xquartz/threadSafety.c
+++ b/hw/xquartz/threadSafety.c
@@ -33,8 +33,8 @@
 
 #include <execinfo.h>
 
-pthread_t SERVER_THREAD;
-pthread_t APPKIT_THREAD;
+pthread_t APPKIT_THREAD_ID;
+pthread_t SERVER_THREAD_ID;
 
 void spewCallStack(void) {
     void* callstack[128];
@@ -48,7 +48,7 @@ void spewCallStack(void) {
     free(strs);
 }
 
-void _threadAssert(pthread_t tid, const char *file, const char *fun, int line) {
+void _threadSafetyAssert(pthread_t tid, const char *file, const char *fun, int line) {
     if(pthread_equal(pthread_self(), tid))
         return;
     
@@ -58,3 +58,13 @@ void _threadAssert(pthread_t tid, const char *file, const char *fun, int line) {
            file, fun, line);
     spewCallStack();
 }
+
+const char *threadSafetyID(pthread_t tid) {
+    if(pthread_equal(tid, APPKIT_THREAD_ID)) {
+        return "Appkit Thread";
+    } else if(pthread_equal(tid, SERVER_THREAD_ID)) {
+        return "Xserver Thread";
+    } else {        
+        return "Unknown Thread";
+    }
+}
diff --git a/hw/xquartz/threadSafety.h b/hw/xquartz/threadSafety.h
index ed2ad9f..7b00910 100644
--- a/hw/xquartz/threadSafety.h
+++ b/hw/xquartz/threadSafety.h
@@ -31,22 +31,23 @@
 
 #include <pthread.h>
 
-extern pthread_t SERVER_THREAD;
-extern pthread_t APPKIT_THREAD;
-
-#define threadSafetyID(tid) (pthread_equal((tid), SERVER_THREAD) ? "X Server Thread" : "Appkit Thread")
+extern pthread_t APPKIT_THREAD_ID;
+extern pthread_t SERVER_THREAD_ID;
 
 /* Dump the call stack */
 void spewCallStack(void);
 
 /* Print message to ErrorF if we're in the wrong thread */
-void _threadAssert(pthread_t tid, const char *file, const char *fun, int line);
+void _threadSafetyAssert(pthread_t tid, const char *file, const char *fun, int line);
+
+/* Get a string that identifies our thread nicely */
+const char *threadSafetyID(pthread_t tid);
 
-#define threadAssert(tid) _threadAssert(tid, __FILE__, __FUNCTION__, __LINE__)
+#define threadSafetyAssert(tid) _threadSafetyAssert(tid, __FILE__, __FUNCTION__, __LINE__)
 
 #ifdef DEBUG_THREADS
-#define TA_SERVER() threadAssert(SERVER_THREAD)
-#define TA_APPKIT() threadAssert(APPKIT_THREAD)
+#define TA_APPKIT() threadSafetyAssert(APPKIT_THREAD_ID)
+#define TA_SERVER() threadSafetyAssert(SERVER_THREAD_ID)
 #else
 #define TA_SERVER() 
 #define TA_APPKIT() 
commit b114d4e861885cc5b49cd81b33ad825461811b3e
Author: Jeremy Huddleston <jeremyhu at freedesktop.org>
Date:   Sat Apr 26 17:04:49 2008 -0700

    XQuartz: Don't subtract the titlebar off of the pointer_y
    (cherry picked from commit 00a9567acce2b27a649cbebd4790e3043688a7d8)

diff --git a/hw/xquartz/X11Application.m b/hw/xquartz/X11Application.m
index 265819a..eefa45f 100644
--- a/hw/xquartz/X11Application.m
+++ b/hw/xquartz/X11Application.m
@@ -867,8 +867,6 @@ static void send_nsevent (NSEventType type, NSEvent *e) {
 		pointer_y = (screen.origin.y + screen.size.height) - location.y;
 	}
 
-	pointer_y -= aquaMenuBarHeight;
-
 	pressure = 0;  // for tablets
 	tilt_x = 0;
 	tilt_y = 0;
diff --git a/hw/xquartz/darwinEvents.c b/hw/xquartz/darwinEvents.c
index afa292f..0643e53 100644
--- a/hw/xquartz/darwinEvents.c
+++ b/hw/xquartz/darwinEvents.c
@@ -367,6 +367,8 @@ void DarwinSendPointerEvents(int ev_type, int ev_button, int pointer_x, int poin
 	static int darwinFakeMouseButtonMask = 0;
 	int i, num_events;
 
+    //DEBUG_LOG("x=%d, y=%d, p=%f, tx=%f, ty=%f\n", pointer_x, pointer_y, pressure, tilt_x, tilt_y);
+    
 	if(!darwinEvents) {
 		ErrorF("DarwinSendPointerEvents called before darwinEvents was initialized\n");
 		return;
commit b9ca7896356f79ee27be5d5aa62052f6984282b0
Author: Jeremy Huddleston <jeremyhu at freedesktop.org>
Date:   Fri Apr 25 17:54:36 2008 -0700

    XQuartz: Added some pseudoramiX debug traces
    (cherry picked from commit 5bee1585a399eab0a7b6fc80ad476d81b5d227d3)

diff --git a/hw/xquartz/darwin.h b/hw/xquartz/darwin.h
index 3231077..6d2fbd0 100644
--- a/hw/xquartz/darwin.h
+++ b/hw/xquartz/darwin.h
@@ -130,4 +130,6 @@ extern FILE *debug_log_fp;
 #define DEBUG_LOG(msg, args...) 
 #endif
 
+#define TRACE() DEBUG_LOG("\n")
+
 #endif  /* _DARWIN_H */
diff --git a/hw/xquartz/pseudoramiX.c b/hw/xquartz/pseudoramiX.c
index 49d5eb6..aafaa26 100644
--- a/hw/xquartz/pseudoramiX.c
+++ b/hw/xquartz/pseudoramiX.c
@@ -37,6 +37,7 @@ Equipment Corporation.
 #include <dix-config.h>
 #endif
 
+#include "darwin.h"
 #include "pseudoramiX.h"
 #include "extnsionst.h"
 #include "dixstruct.h"
@@ -99,6 +100,8 @@ PseudoramiXAddScreen(int x, int y, int w, int h)
                                       sizeof(PseudoramiXScreenRec));
     }
 
+    DEBUG_LOG("x: %d, y: %d, w: %d, h: %d\n", x, y, w, h);
+
     s = &pseudoramiXScreens[pseudoramiXNumScreens++];
     s->x = x;
     s->y = y;
@@ -116,6 +119,8 @@ void PseudoramiXExtensionInit(int argc, char *argv[])
 
     if (noPseudoramiXExtension) return;
 
+    TRACE();
+
     /* Even with only one screen we need to enable PseudoramiX to allow
        dynamic screen configuration changes. */
 #if 0
@@ -153,12 +158,16 @@ void PseudoramiXExtensionInit(int argc, char *argv[])
 
 void PseudoramiXResetScreens(void)
 {
+    TRACE();
+
     pseudoramiXNumScreens = 0;
 }
 
 
 static void PseudoramiXResetProc(ExtensionEntry *extEntry)
 {
+    TRACE();
+
     PseudoramiXResetScreens();
 }
 
@@ -166,6 +175,8 @@ static void PseudoramiXResetProc(ExtensionEntry *extEntry)
 // was PanoramiX
 static int ProcPseudoramiXQueryVersion(ClientPtr client)
 {
+    TRACE();
+
     return ProcPanoramiXQueryVersion(client);
 }
 
@@ -178,6 +189,8 @@ static int ProcPseudoramiXGetState(ClientPtr client)
     xPanoramiXGetStateReply rep;
     register int n, rc;
 
+    TRACE();
+    
     REQUEST_SIZE_MATCH(xPanoramiXGetStateReq);
     rc = dixLookupWindow(&pWin, stuff->window, client, DixGetAttrAccess);
     if (rc != Success)
@@ -205,6 +218,8 @@ static int ProcPseudoramiXGetScreenCount(ClientPtr client)
     xPanoramiXGetScreenCountReply rep;
     register int n, rc;
 
+    TRACE();
+    
     REQUEST_SIZE_MATCH(xPanoramiXGetScreenCountReq);
     rc = dixLookupWindow(&pWin, stuff->window, client, DixGetAttrAccess);
     if (rc != Success)
@@ -232,6 +247,8 @@ static int ProcPseudoramiXGetScreenSize(ClientPtr client)
     xPanoramiXGetScreenSizeReply	rep;
     register int			n, rc;
 
+    TRACE();
+    
     REQUEST_SIZE_MATCH(xPanoramiXGetScreenSizeReq);
     rc = dixLookupWindow(&pWin, stuff->window, client, DixGetAttrAccess);
     if (rc != Success)
@@ -262,6 +279,8 @@ static int ProcPseudoramiXIsActive(ClientPtr client)
     /* REQUEST(xXineramaIsActiveReq); */
     xXineramaIsActiveReply	rep;
 
+    TRACE();
+    
     REQUEST_SIZE_MATCH(xXineramaIsActiveReq);
 
     rep.type = X_Reply;
@@ -285,6 +304,8 @@ static int ProcPseudoramiXQueryScreens(ClientPtr client)
     /* REQUEST(xXineramaQueryScreensReq); */
     xXineramaQueryScreensReply	rep;
 
+    DEBUG_LOG("noPseudoramiXExtension=%d, pseudoramiXNumScreens=%d\n", noPseudoramiXExtension, pseudoramiXNumScreens);
+    
     REQUEST_SIZE_MATCH(xXineramaQueryScreensReq);
 
     rep.type = X_Reply;
@@ -327,6 +348,7 @@ static int ProcPseudoramiXQueryScreens(ClientPtr client)
 // was PanoramiX
 static int ProcPseudoramiXDispatch (ClientPtr client)
 {   REQUEST(xReq);
+    TRACE();
     switch (stuff->data)
     {
 	case X_PanoramiXQueryVersion:
@@ -353,6 +375,8 @@ SProcPseudoramiXQueryVersion (ClientPtr client)
 	REQUEST(xPanoramiXQueryVersionReq);
 	register int n;
 
+    TRACE();
+
 	swaps(&stuff->length,n);
 	REQUEST_SIZE_MATCH (xPanoramiXQueryVersionReq);
 	return ProcPseudoramiXQueryVersion(client);
@@ -364,6 +388,8 @@ SProcPseudoramiXGetState(ClientPtr client)
 	REQUEST(xPanoramiXGetStateReq);
 	register int n;
 
+    TRACE();
+
  	swaps (&stuff->length, n);
 	REQUEST_SIZE_MATCH(xPanoramiXGetStateReq);
 	return ProcPseudoramiXGetState(client);
@@ -375,6 +401,8 @@ SProcPseudoramiXGetScreenCount(ClientPtr client)
 	REQUEST(xPanoramiXGetScreenCountReq);
 	register int n;
 
+    TRACE();
+
 	swaps (&stuff->length, n);
 	REQUEST_SIZE_MATCH(xPanoramiXGetScreenCountReq);
 	return ProcPseudoramiXGetScreenCount(client);
@@ -386,6 +414,8 @@ SProcPseudoramiXGetScreenSize(ClientPtr client)
 	REQUEST(xPanoramiXGetScreenSizeReq);
 	register int n;
 
+    TRACE();
+
 	swaps (&stuff->length, n);
 	REQUEST_SIZE_MATCH(xPanoramiXGetScreenSizeReq);
 	return ProcPseudoramiXGetScreenSize(client);
@@ -398,6 +428,8 @@ SProcPseudoramiXIsActive(ClientPtr client)
 	REQUEST(xXineramaIsActiveReq);
 	register int n;
 
+    TRACE();
+
 	swaps (&stuff->length, n);
 	REQUEST_SIZE_MATCH(xXineramaIsActiveReq);
 	return ProcPseudoramiXIsActive(client);
@@ -410,6 +442,8 @@ SProcPseudoramiXQueryScreens(ClientPtr client)
 	REQUEST(xXineramaQueryScreensReq);
 	register int n;
 
+    TRACE();
+
 	swaps (&stuff->length, n);
 	REQUEST_SIZE_MATCH(xXineramaQueryScreensReq);
 	return ProcPseudoramiXQueryScreens(client);
@@ -419,6 +453,9 @@ SProcPseudoramiXQueryScreens(ClientPtr client)
 static int
 SProcPseudoramiXDispatch (ClientPtr client)
 {   REQUEST(xReq);
+
+    TRACE();
+
     switch (stuff->data)
     {
 	case X_PanoramiXQueryVersion:
diff --git a/hw/xquartz/quartzCocoa.m b/hw/xquartz/quartzCocoa.m
index aa4b9fb..2890d34 100644
--- a/hw/xquartz/quartzCocoa.m
+++ b/hw/xquartz/quartzCocoa.m
@@ -44,8 +44,6 @@
 
 #include "darwin.h"
 
-#include "pseudoramiX.h"
-
 extern void FatalError(const char *, ...);
 extern char *display;
 extern int noPanoramiXExtension;
commit 0209e46249b61974a6e3ed54a51cc36dfaf0064f
Author: Jeremy Huddleston <jeremyhu at freedesktop.org>
Date:   Thu Apr 24 23:48:11 2008 -0700

    XQuartz: More multi-monitor work... reverted Ben's workaround (worked for side-by-side only) and added more debugging.
    (cherry picked from commit 515b8b855ac5d2d5aef881053f73b2ad07a6dd2e)

diff --git a/hw/xquartz/darwin.c b/hw/xquartz/darwin.c
index aad55fc..c18b575 100644
--- a/hw/xquartz/darwin.c
+++ b/hw/xquartz/darwin.c
@@ -535,8 +535,7 @@ DarwinAdjustScreenOrigins(ScreenInfo *pScreenInfo)
     /* Find leftmost screen. If there's a tie, take the topmost of the two. */
     for (i = 1; i < pScreenInfo->numScreens; i++) {
         if (dixScreenOrigins[i].x < left  ||
-            (dixScreenOrigins[i].x == left &&
-             dixScreenOrigins[i].y < top))
+            (dixScreenOrigins[i].x == left && dixScreenOrigins[i].y < top))
         {
             left = dixScreenOrigins[i].x;
             top = dixScreenOrigins[i].y;
@@ -545,17 +544,20 @@ DarwinAdjustScreenOrigins(ScreenInfo *pScreenInfo)
 
     darwinMainScreenX = left;
     darwinMainScreenY = top;
+    
+    DEBUG_LOG("top = %d, left=%d\n", top, left);
 
     /* Shift all screens so that there is a screen whose top left
-       is at X11 (0,0) and at global screen coordinate
-       (darwinMainScreenX, darwinMainScreenY). */
+     * is at X11 (0,0) and at global screen coordinate
+     * (darwinMainScreenX, darwinMainScreenY).
+     */
 
     if (darwinMainScreenX != 0 || darwinMainScreenY != 0) {
         for (i = 0; i < pScreenInfo->numScreens; i++) {
             dixScreenOrigins[i].x -= darwinMainScreenX;
             dixScreenOrigins[i].y -= darwinMainScreenY;
-    /*            ErrorF("Screen %d placed at X11 coordinate (%d,%d).\n",
-		  i, dixScreenOrigins[i].x, dixScreenOrigins[i].y); */
+            DEBUG_LOG("Screen %d placed at X11 coordinate (%d,%d).\n",
+                      i, dixScreenOrigins[i].x, dixScreenOrigins[i].y);
         }
     }
 }
diff --git a/hw/xquartz/xpr/xprScreen.c b/hw/xquartz/xpr/xprScreen.c
index 583d7ef..7312226 100644
--- a/hw/xquartz/xpr/xprScreen.c
+++ b/hw/xquartz/xpr/xprScreen.c
@@ -153,7 +153,8 @@ displayScreenBounds(CGDirectDisplayID id, Bool remove_menubar)
               (int)frame.origin.x, (int)frame.origin.y);
     
     /* Remove menubar to help standard X11 window managers. */
-    if (remove_menubar && !quartzHasRoot && id == 0) {
+    if (remove_menubar && !quartzHasRoot && 
+        frame.origin.x == 0 && frame.origin.y == 0) {
         frame.origin.y += aquaMenuBarHeight;
         frame.size.height -= aquaMenuBarHeight;
     }
@@ -201,6 +202,9 @@ xprAddPseudoramiXScreens(int *x, int *y, int *width, int *height)
     *width = unionRect.size.width;
     *height = unionRect.size.height;
 
+    DEBUG_LOG("  screen union origin: (%d,%d) size: (%d,%d).\n",
+              *x, *y, *width, *height);
+
     /* Tell PseudoramiX about the real screens. */
     for (i = 0; i < displayCount; i++)
     {
@@ -229,7 +233,7 @@ xprDisplayInit(void)
 {
     CGDisplayCount displayCount;
 
-    //    ErrorF("Display mode: Rootless Quartz -- Xplugin implementation\n");
+    DEBUG_LOG("");
 
     CGGetActiveDisplayList(0, NULL, &displayCount);
 
@@ -265,6 +269,8 @@ xprAddScreen(int index, ScreenPtr pScreen)
 {
     DarwinFramebufferPtr dfb = SCREEN_PRIV(pScreen);
     int depth = darwinDesiredDepth;
+
+    DEBUG_LOG("index=%d depth=%d\n", index, depth);
     
     if(depth == -1) {
         depth = CGDisplaySamplesPerPixel(kCGDirectMainDisplay) * CGDisplayBitsPerSample(kCGDirectMainDisplay);
commit b65dbd350b8518bb90bed9cdc64dd900bc75d20c
Author: Jeremy Huddleston <jeremyhu at freedesktop.org>
Date:   Thu Apr 24 21:14:04 2008 -0700

    XQuartz: Cleaned up multi-monitor support.
    (cherry picked from commit c05abf0a19b0ef0fc4ace9400a095ce2521456bc)
    (cherry picked from commit 9112f290434c246d3e797551aaaf3a89d2006b23)

diff --git a/hw/xquartz/xpr/xprScreen.c b/hw/xquartz/xpr/xprScreen.c
index 6f7598f..583d7ef 100644
--- a/hw/xquartz/xpr/xprScreen.c
+++ b/hw/xquartz/xpr/xprScreen.c
@@ -142,20 +142,26 @@ displayAtIndex(int index)
  *  Return the bounds of a particular display.
  */
 static CGRect
-displayScreenBounds(CGDirectDisplayID id)
+displayScreenBounds(CGDirectDisplayID id, Bool remove_menubar)
 {
     CGRect frame;
 
     frame = CGDisplayBounds(id);
 
+    DEBUG_LOG("    %dx%d @ (%d,%d).\n",
+              (int)frame.size.width, (int)frame.size.height,
+              (int)frame.origin.x, (int)frame.origin.y);
+    
     /* Remove menubar to help standard X11 window managers. */
-
-    if (frame.origin.y == 0)
-    {
+    if (remove_menubar && !quartzHasRoot && id == 0) {
         frame.origin.y += aquaMenuBarHeight;
         frame.size.height -= aquaMenuBarHeight;
     }
 
+    DEBUG_LOG("    %dx%d @ (%d,%d).\n",
+              (int)frame.size.width, (int)frame.size.height,
+              (int)frame.origin.x, (int)frame.origin.y);
+
     return frame;
 }
 
@@ -179,8 +185,13 @@ xprAddPseudoramiXScreens(int *x, int *y, int *width, int *height)
     /* Get the union of all screens */
     for (i = 0; i < displayCount; i++)
     {
+
+        /* we can't remove the menubar from the screen - doing so
+         * would constrain the pointer to the screen, not allowing it
+         * to reach the menubar..
+         */
         CGDirectDisplayID dpy = displayList[i];
-        frame = displayScreenBounds(dpy);
+        frame = displayScreenBounds(dpy, FALSE);
         unionRect = CGRectUnion(unionRect, frame);
     }
 
@@ -195,17 +206,12 @@ xprAddPseudoramiXScreens(int *x, int *y, int *width, int *height)
     {
         CGDirectDisplayID dpy = displayList[i];
 
-        frame = displayScreenBounds(dpy);
-
-	/*        ErrorF("PseudoramiX screen %d added: %dx%d @ (%d,%d).\n", i,
-               (int)frame.size.width, (int)frame.size.height,
-               (int)frame.origin.x, (int)frame.origin.y); */
-
+        frame = displayScreenBounds(dpy, TRUE);
         frame.origin.x -= unionRect.origin.x;
         frame.origin.y -= unionRect.origin.y;
 
-	/*        ErrorF("PseudoramiX screen %d placed at X11 coordinate (%d,%d).\n",
-		  i, (int)frame.origin.x, (int)frame.origin.y); */
+        DEBUG_LOG("    placed at X11 coordinate (%d,%d).\n",
+                  (int)frame.origin.x, (int)frame.origin.y);
 
         PseudoramiXAddScreen(frame.origin.x, frame.origin.y,
                              frame.size.width, frame.size.height);
@@ -315,12 +321,14 @@ xprAddScreen(int index, ScreenPtr pScreen)
 
     if (noPseudoramiXExtension)
     {
+        ErrorF("Warning: noPseudoramiXExtension!\n");
+        
         CGDirectDisplayID dpy;
         CGRect frame;
 
         dpy = displayAtIndex(index);
 
-        frame = displayScreenBounds(dpy);
+        frame = displayScreenBounds(dpy, TRUE);
 
         dfb->x = frame.origin.x;
         dfb->y = frame.origin.y;
commit 5869e3f5551e7e2d18e06a2f220b77d8c4161db1
Author: Jeremy Huddleston <jeremyhu at freedesktop.org>
Date:   Thu Apr 24 19:39:27 2008 -0700

    darwin gots /dev/urandom, too yo!
    (cherry picked from commit bf0144f38034bc59f108bb2c5270ff37fbe70e10)

diff --git a/configure.ac b/configure.ac
index b42b120..67606c7 100644
--- a/configure.ac
+++ b/configure.ac
@@ -177,7 +177,7 @@ AC_CHECK_FUNC([dlopen], [],
 	AC_CHECK_LIB([dl], [dlopen], DLOPEN_LIBS="-ldl"))
 
 case $host_os in
-    linux*)
+    linux*|darwin*)
 	AC_DEFINE(HAVE_URANDOM, 1, [Has /dev/urandom]) ;;
     solaris*)
 	# Solaris 8 with patches, or Solaris 9 or later have /dev/urandom
commit b1ae7c79db78cc3b789701f81328669f9f8ed80f
Author: Alan Coopersmith <alan.coopersmith at sun.com>
Date:   Thu Apr 24 19:02:43 2008 -0700

    Bug 14247: If pkg-config can't find openssl.pc, just link with -lcrypto
    
    X.Org bugzilla #14247 <http://bugs.freedesktop.org/show_bug.cgi?id=14247>

diff --git a/configure.ac b/configure.ac
index b2a07a6..b42b120 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1118,7 +1118,9 @@ PKG_CHECK_MODULES([XSERVERLIBS], [$REQUIRED_LIBS])
 
 # OpenSSL used for SHA1 hashing in render/glyph.c, but we don't need all of
 # the OpenSSL libraries, just libcrypto
-PKG_CHECK_MODULES([OPENSSL], [openssl], [OPENSSL_LIB_FLAGS=`$PKG_CONFIG --libs-only-L --libs-only-other openssl`])
+PKG_CHECK_EXISTS([openssl],
+ [PKG_CHECK_MODULES([OPENSSL], [openssl],
+   [OPENSSL_LIB_FLAGS=`$PKG_CONFIG --libs-only-L --libs-only-other openssl`])])
 LIBCRYPTO="$OPENSSL_LIB_FLAGS -lcrypto"
 
 # Autotools has some unfortunate issues with library handling.  In order to
commit 1daae4574c19a122baf73b6f9457b0d383b1bc66
Author: Jeremy Huddleston <jeremyhu at freedesktop.org>
Date:   Thu Apr 24 18:22:05 2008 -0700

    Added missing HAVE_LAUNCHD to dix-config.h.in
    (cherry picked from commit 1b4b73cefbc2f3e3f6d0cb84ea202f84fb60abb5)

diff --git a/include/dix-config.h.in b/include/dix-config.h.in
index 135d3d8..fc1caa3 100644
--- a/include/dix-config.h.in
+++ b/include/dix-config.h.in
@@ -148,6 +148,9 @@
 /* Define to 1 if you have version 2.2 (or newer) of the drm library */
 #undef HAVE_LIBDRM_2_2
 
+/* Define to 1 if launchd is available. */
+#undef HAVE_LAUNCHD
+
 /* Have Quartz */
 #undef XQUARTZ
 
commit 63853e4ad211945ed25541223207a78f83766ced
Author: Jeremy Huddleston <jeremyhu at freedesktop.org>
Date:   Thu Apr 24 18:21:42 2008 -0700

    XQuartz: Compile in missing glx source that we still need
    (cherry picked from commit c611335dee267e41dcd1733a6bb5206b102f804e)

diff --git a/GL/glx/Makefile.am b/GL/glx/Makefile.am
index 1d4719c..9bf296c 100644
--- a/GL/glx/Makefile.am
+++ b/GL/glx/Makefile.am
@@ -47,7 +47,12 @@ libglxdri_la_SOURCES = \
         extension_string.c \
         extension_string.h
 
+#if XQUARTZ
+XQUARTZ_libglx_la_SOURCES = glcontextmodes.c
+#endif
+
 libglx_la_SOURCES = \
+	$(XQUARTZ_libglx_la_SOURCES) \
         g_disptab.h \
         glxbyteorder.h \
         glxcmds.c \
commit ae982a27e4059fecd4048d245e6aa02f8dcc97d0
Author: Dave Airlie <airlied at redhat.com>
Date:   Thu Apr 24 16:37:29 2008 +1000

    glx: test for valid read and draw privates before using them
    
    this should fix a bug where f-spot exiting blows up the X server

diff --git a/GL/glx/glxutil.c b/GL/glx/glxutil.c
index 11e9f89..aa23a95 100644
--- a/GL/glx/glxutil.c
+++ b/GL/glx/glxutil.c
@@ -81,38 +81,40 @@ __glXDeassociateContext(__GLXcontext *glxc)
     __GLXcontext *curr, *prev;
 
     prev = NULL;
-    for ( curr = glxc->drawPriv->drawGlxc
-	  ; curr != NULL
-	  ; prev = curr, curr = curr->nextDrawPriv ) {
-	if (curr == glxc) {
-	    /* found context.  Deassociate. */
-	    if (prev == NULL) {
-		glxc->drawPriv->drawGlxc = curr->nextDrawPriv;
-	    } else {
-		prev->nextDrawPriv = curr->nextDrawPriv;
+    if (glxc->drawPriv) {
+        for ( curr = glxc->drawPriv->drawGlxc; curr != NULL
+	      ; prev = curr, curr = curr->nextDrawPriv ) {
+	    if (curr == glxc) {
+	        /* found context.  Deassociate. */
+	        if (prev == NULL) {
+		    glxc->drawPriv->drawGlxc = curr->nextDrawPriv;
+	        } else {
+		    prev->nextDrawPriv = curr->nextDrawPriv;
+	        }
+	        curr->nextDrawPriv = NULL;
+	        __glXUnrefDrawable(glxc->drawPriv);
+	        break;
 	    }
-	    curr->nextDrawPriv = NULL;
-	    __glXUnrefDrawable(glxc->drawPriv);
-	    break;
-	}
+        }
     }
 
-
     prev = NULL;
-    for ( curr = glxc->readPriv->readGlxc
-	  ; curr != NULL 
-	  ; prev = curr, curr = curr->nextReadPriv ) {
-	if (curr == glxc) {
-	    /* found context.  Deassociate. */
-	    if (prev == NULL) {
-		glxc->readPriv->readGlxc = curr->nextReadPriv;
-	    } else {
-		prev->nextReadPriv = curr->nextReadPriv;
-	    }
-	    curr->nextReadPriv = NULL;
-	    __glXUnrefDrawable(glxc->readPriv);
-	    break;
-	}
+    if (glxc->readPriv) {
+        for ( curr = glxc->readPriv->readGlxc
+	      ; curr != NULL 
+	      ; prev = curr, curr = curr->nextReadPriv ) {
+	    if (curr == glxc) {
+	        /* found context.  Deassociate. */
+	        if (prev == NULL) {
+		    glxc->readPriv->readGlxc = curr->nextReadPriv;
+	        } else {
+		    prev->nextReadPriv = curr->nextReadPriv;
+	        }
+	        curr->nextReadPriv = NULL;
+	        __glXUnrefDrawable(glxc->readPriv);
+	       break;
+	   }
+       }
     }
 }
 
commit f377141912594f87144d6d7f7fdd279a101d8e6c
Author: Peter Hutterer <peter at cs.unisa.edu.au>
Date:   Thu Apr 24 13:30:28 2008 +0930

    Xi: don't attempt to send to a NULL window.
    
    Only applicable when the server comes down/restarts. In this case,
    WindowTable[i] may be NULL. Let's not try to send an event then.

diff --git a/Xi/exevents.c b/Xi/exevents.c
index fb84bef..641bead 100644
--- a/Xi/exevents.c
+++ b/Xi/exevents.c
@@ -1279,6 +1279,8 @@ SendEventToAllWindows(DeviceIntPtr dev, Mask mask, xEvent * ev, int count)
 
     for (i = 0; i < screenInfo.numScreens; i++) {
         pWin = WindowTable[i];
+        if (!pWin)
+            continue;
         (void)DeliverEventsToWindow(pWin, ev, count, mask, NullGrab, dev->id);
         p1 = pWin->firstChild;
         FindInterestedChildren(dev, p1, mask, ev, count);
commit aec485f2dcc87b340759d67b60e7dee7931aaec5
Author: Peter Hutterer <peter at cs.unisa.edu.au>
Date:   Thu Apr 24 13:29:46 2008 +0930

    dix: NULL out WindowTable after freeing all the windows.
    
    CloseDownDevices() tries to send PresenceNotify events. If the windows are
    already freed, then we are accessing dangling pointers.

diff --git a/dix/main.c b/dix/main.c
index db43473..6d9dd33 100644
--- a/dix/main.c
+++ b/dix/main.c
@@ -458,7 +458,10 @@ main(int argc, char *argv[], char *envp[])
 #endif
 
         config_fini();
+
+        memset(WindowTable, 0, MAXSCREENS * sizeof(WindowPtr));
 	CloseDownDevices();
+
 	for (i = screenInfo.numScreens - 1; i >= 0; i--)
 	{
 	    FreeScratchPixmapsForScreen(i);
commit 9ab4e2fd8eaa87dbd16835affb1aa54dcb1a619e
Author: Peter Hutterer <peter at cs.unisa.edu.au>
Date:   Wed Apr 23 11:38:08 2008 +0930

    xfree86: don't free the config-file related information in DIDR. #15645
    
    In DeleteInputDeviceRequest, leave the conf_idev (which is shared with
    xf86ConfigLayout.input) alone for devices that were specified in the
    ServerLayout section of the config file. This way, in the next server
    generation we are left with what was the original config and can thus re-init
    the devices.
    
    This is an addon to 6d22a9615a0e6ab3d00b0bcb22ff001b6ece02ae, an attempt to
    fix Bug 14418.
    
    X.Org Bug 15645 <https://bugs.freedesktop.org/show_bug.cgi?id=15645>
    X.Org Bug 14418 <https://bugs.freedesktop.org/show_bug.cgi?id=15645>

diff --git a/hw/xfree86/common/xf86Init.c b/hw/xfree86/common/xf86Init.c
index 6d5eaad..68dc387 100644
--- a/hw/xfree86/common/xf86Init.c
+++ b/hw/xfree86/common/xf86Init.c
@@ -1123,37 +1123,35 @@ InitInput(argc, argv)
     xf86Info.vtRequestsPending = FALSE;
     xf86Info.inputPending = FALSE;
 
-    if (serverGeneration == 1) {
-	/* Call the PreInit function for each input device instance. */
-	for (pDev = xf86ConfigLayout.inputs; pDev && *pDev; pDev++) {
-	    /* Replace obsolete keyboard driver with kbd */
-	    if (!xf86NameCmp((*pDev)->driver, "keyboard")) {
-		strcpy((*pDev)->driver, "kbd");
-            }
-
-	    if ((pDrv = xf86LookupInputDriver((*pDev)->driver)) == NULL) {
-		xf86Msg(X_ERROR, "No Input driver matching `%s'\n", (*pDev)->driver);
-		/* XXX For now, just continue. */
-		continue;
-	    }
-	    if (!pDrv->PreInit) {
-		xf86MsgVerb(X_WARNING, 0,
-		    "Input driver `%s' has no PreInit function (ignoring)\n",
-		    pDrv->driverName);
-		continue;
-	    }
-	    pInfo = pDrv->PreInit(pDrv, *pDev, 0);
-	    if (!pInfo) {
-		xf86Msg(X_ERROR, "PreInit returned NULL for \"%s\"\n",
-			(*pDev)->identifier);
-		continue;
-	    } else if (!(pInfo->flags & XI86_CONFIGURED)) {
-		xf86Msg(X_ERROR, "PreInit failed for input device \"%s\"\n",
-			(*pDev)->identifier);
-		xf86DeleteInput(pInfo, 0);
-		continue;
-	    }
-	}
+    /* Call the PreInit function for each input device instance. */
+    for (pDev = xf86ConfigLayout.inputs; pDev && *pDev; pDev++) {
+        /* Replace obsolete keyboard driver with kbd */
+        if (!xf86NameCmp((*pDev)->driver, "keyboard")) {
+            strcpy((*pDev)->driver, "kbd");
+        }
+
+        if ((pDrv = xf86LookupInputDriver((*pDev)->driver)) == NULL) {
+            xf86Msg(X_ERROR, "No Input driver matching `%s'\n", (*pDev)->driver);
+            /* XXX For now, just continue. */
+            continue;
+        }
+        if (!pDrv->PreInit) {
+            xf86MsgVerb(X_WARNING, 0,
+                    "Input driver `%s' has no PreInit function (ignoring)\n",
+                    pDrv->driverName);
+            continue;
+        }
+        pInfo = pDrv->PreInit(pDrv, *pDev, 0);
+        if (!pInfo) {
+            xf86Msg(X_ERROR, "PreInit returned NULL for \"%s\"\n",
+                    (*pDev)->identifier);
+            continue;
+        } else if (!(pInfo->flags & XI86_CONFIGURED)) {
+            xf86Msg(X_ERROR, "PreInit failed for input device \"%s\"\n",
+                    (*pDev)->identifier);
+            xf86DeleteInput(pInfo, 0);
+            continue;
+        }
     }
 
     /* Initialise all input devices. */
diff --git a/hw/xfree86/common/xf86Xinput.c b/hw/xfree86/common/xf86Xinput.c
index d34238e..710e787 100644
--- a/hw/xfree86/common/xf86Xinput.c
+++ b/hw/xfree86/common/xf86Xinput.c
@@ -448,6 +448,8 @@ DeleteInputDeviceRequest(DeviceIntPtr pDev)
     LocalDevicePtr pInfo = (LocalDevicePtr) pDev->public.devicePrivate;
     InputDriverPtr drv;
     IDevRec *idev;
+    BOOL found;
+    IDevPtr *it;
 
     if (pInfo) /* need to get these before RemoveDevice */
     {
@@ -464,10 +466,18 @@ DeleteInputDeviceRequest(DeviceIntPtr pDev)
     else
         xf86DeleteInput(pInfo, 0);
 
-    xfree(idev->driver);
-    xfree(idev->identifier);
-    xf86optionListFree(idev->commonOptions);
-    xfree(idev);
+    /* devices added through HAL aren't in the config layout */
+    it = xf86ConfigLayout.inputs;
+    while(*it && *it != idev)
+        it++;
+
+    if (!(*it)) /* end of list, not in the layout */
+    {
+        xfree(idev->driver);
+        xfree(idev->identifier);
+        xf86optionListFree(idev->commonOptions);
+        xfree(idev);
+    }
 }
 
 /* 
commit d09c520b322ba5c5f4d6b630a7c0c62e56732f82
Author: Jeremy Huddleston <jeremyhu at freedesktop.org>
Date:   Wed Apr 23 10:22:34 2008 -0700

    Moved Apple GL bits into our DDX subtree
    (cherry picked from commit c9356f32892978faecb30f7b7af7488820ce37ff)

diff --git a/GL/Makefile.am b/GL/Makefile.am
index 44fca18..c3ac155 100644
--- a/GL/Makefile.am
+++ b/GL/Makefile.am
@@ -1,9 +1,4 @@
-if XQUARTZ
-XQUARTZ_SUBDIRS = apple
-endif
-
-SUBDIRS = glx $(XQUARTZ_SUBDIRS)
-DIST_SUBDIRS = glx apple
+SUBDIRS = glx
 
 WINDOWS_EXTRAS = \
 	windows/ChangeLog \
diff --git a/GL/apple/Makefile.am b/GL/apple/Makefile.am
deleted file mode 100644
index 7ad9140..0000000
--- a/GL/apple/Makefile.am
+++ /dev/null
@@ -1,14 +0,0 @@
-AM_CFLAGS = $(DIX_CFLAGS)
-AM_CPPFLAGS = \
-	-I$(top_srcdir) \
-	-I$(top_srcdir)/GL/glx \
-	-I$(top_srcdir)/GL/include \
-	-I$(top_srcdir)/GL/mesa/glapi \
-	-I$(top_srcdir)/hw/xquartz \
-	-I$(top_srcdir)/hw/xquartz/xpr \
-	-I$(top_srcdir)/miext/damage
-
-noinst_LIBRARIES = libCGLcore.a 
-libCGLcore_a_SOURCES = \
-	indirect.c \
-	$(top_srcdir)/hw/dmx/glxProxy/compsize.c
diff --git a/GL/apple/indirect.c b/GL/apple/indirect.c
deleted file mode 100644
index a0884d4..0000000
--- a/GL/apple/indirect.c
+++ /dev/null
@@ -1,1940 +0,0 @@
-/*
- * GLX implementation that uses Apple's OpenGL.framework
- * (Indirect rendering path)
- *
- * Copyright (c) 2007 Apple Inc.
- * Copyright (c) 2004 Torrey T. Lyons. All Rights Reserved.
- * Copyright (c) 2002 Greg Parker. All Rights Reserved.
- *
- * Portions of this file are copied from Mesa's xf86glx.c,
- * which contains the following copyright:
- *
- * Copyright 1998-1999 Precision Insight, Inc., Cedar Park, Texas.
- * All Rights Reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, 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.
- */
-
-#ifdef HAVE_DIX_CONFIG_H
-#include <dix-config.h>
-#endif
-
-#include "dri.h"
-
-#define GL_EXT_histogram 1
-#define GL_EXT_polygon_offset 1
-#define GL_SGIS_pixel_texture 1
-#define GL_SGIX_pixel_texture 1
-#define GL_EXT_multisample 1
-#define GL_SGIS_multisample 1
-#define GL_EXT_vertex_array 1
-#define GL_ARB_point_parameters 1
-#define GL_NV_vertex_array_range 1
-#define GL_MESA_resize_buffers 1
-#define GL_ARB_window_pos 1
-#define GL_EXT_cull_vertex 1
-#define GL_NV_vertex_program 1
-#define GL_APPLE_fence 1
-#define GL_IBM_multimode_draw_arrays 1
-#define GL_EXT_fragment_shader 1
-
-#include <OpenGL/OpenGL.h>
-#include <OpenGL/CGLContext.h>
-
-// X11 and X11's glx
-#include <GL/gl.h>
-#include <GL/glxproto.h>
-#include <windowstr.h>
-#include <resource.h>
-#include <GL/glxint.h>
-#include <GL/glxtokens.h>
-#include <scrnintstr.h>
-#include <glxserver.h>
-#include <glxscreens.h>
-#include <glxdrawable.h>
-#include <glxcontext.h>
-#include <glxext.h>
-#include <glxutil.h>
-#include <glxscreens.h>
-#include <GL/internal/glcore.h>
-#include "x-hash.h"
-#include "x-list.h"
-
-#include <dispatch.h>
-#define GLAPIENTRYP *
-typedef unsigned long long GLuint64EXT;
-typedef long long GLint64EXT;
-#include <Xplugin.h>
-#include "glcontextmodes.h"
-#include <glapi.h>
-#include <glapitable.h>
-
-// ggs: needed to call back to glx with visual configs
-extern void GlxSetVisualConfigs(int nconfigs, __GLXvisualConfig *configs, void **configprivs);
-__GLXprovider * GlxGetMesaProvider (void);
-
-// Write debugging output, or not
-#ifdef GLAQUA_DEBUG
-#define GLAQUA_DEBUG_MSG ErrorF
-#else
-#define GLAQUA_DEBUG_MSG(a, ...)
-#endif
-
-static void setup_dispatch_table(void);
-GLuint __glFloorLog2(GLuint val);
-void warn_func(void * p1, char *format, ...);
-
-// some prototypes
-static __GLXscreen * __glXAquaScreenProbe(ScreenPtr pScreen);
-static __GLXdrawable * __glXAquaScreenCreateDrawable(__GLXscreen *screen, DrawablePtr pDraw, XID drawId, __GLXconfig *modes);
-
-static Bool glAquaInitVisuals(VisualPtr *visualp, DepthPtr *depthp,
-                              int *nvisualp, int *ndepthp,
-                              int *rootDepthp, VisualID *defaultVisp,
-                              unsigned long sizes, int bitsPerRGB);
-static void glAquaSetVisualConfigs(int nconfigs, __GLXvisualConfig *configs,
-                                   void **privates);
-
-static void glAquaResetExtension(void);
-static void __glXAquaContextDestroy(__GLXcontext *baseContext);
-static int __glXAquaContextMakeCurrent(__GLXcontext *baseContext);
-static int __glXAquaContextLoseCurrent(__GLXcontext *baseContext);
-static int __glXAquaContextForceCurrent(__GLXcontext *baseContext);
-static int __glXAquaContextCopy(__GLXcontext *baseDst, __GLXcontext *baseSrc, unsigned long mask);
-
-static CGLPixelFormatObj makeFormat(__GLXconfig *mode);
-
-__GLXprovider __glXMesaProvider = {
-  __glXAquaScreenProbe,
-  "Core OpenGL",
-    NULL
-};
-
-__GLXprovider *
-GlxGetMesaProvider (void)
-{
-  GLAQUA_DEBUG_MSG("GlxGetMesaProvider\n");
-  return &__glXMesaProvider;
-}
-
-typedef struct __GLXAquaScreen   __GLXAquaScreen;
-typedef struct __GLXAquaContext  __GLXAquaContext;
-typedef struct __GLXAquaDrawable __GLXAquaDrawable;
-
-struct __GLXAquaScreen {
-  __GLXscreen   base;
-  int           index;
-    int num_vis;
-    __GLXconfig *modes;
-};
-
-static __GLXAquaScreen glAquaScreens[MAXSCREENS];
-
-struct __GLXAquaContext {
-  __GLXcontext base;
-  CGLContextObj ctx;
-  CGLPixelFormatObj pixelFormat;
-  xp_surface_id sid;
-  unsigned isAttached :1;
-};
-
-struct __GLXAquaDrawable {
-  __GLXdrawable base;
-    DrawablePtr pDraw;
-    xp_surface_id sid;
-};
-
-static __GLXcontext *
-__glXAquaScreenCreateContext(__GLXscreen *screen,
-			     __GLXconfig *config,
-			     __GLXcontext *baseShareContext)
-{
-  __GLXAquaContext *context;
-  __GLXAquaContext *shareContext = (__GLXAquaContext *) baseShareContext;
-  CGLError gl_err;
-  
-  GLAQUA_DEBUG_MSG("glXAquaScreenCreateContext\n");
-
-  context = malloc (sizeof (__GLXAquaContext));
-  if (context == NULL) return NULL;
-
-  memset(context, 0, sizeof *context);
-
-  context->base.pGlxScreen = screen;
-  context->base.config      = config;
-
-  context->base.destroy        = __glXAquaContextDestroy;
-  context->base.makeCurrent    = __glXAquaContextMakeCurrent;
-  context->base.loseCurrent    = __glXAquaContextLoseCurrent;
-  context->base.copy           = __glXAquaContextCopy;
-  context->base.forceCurrent   = __glXAquaContextForceCurrent;
-  //  context->base.createDrawable = __glXAquaContextCreateDrawable;
-
-  context->pixelFormat = makeFormat(config);
-  if (!context->pixelFormat) {
-        free(context);
-        return NULL;
-  }
-
-  context->ctx = NULL;
-  gl_err = CGLCreateContext(context->pixelFormat,
-                            shareContext ? shareContext->ctx : NULL,
-                            &context->ctx);
-
-  if (gl_err != 0) {
-      ErrorF("CGLCreateContext error: %s\n", CGLErrorString(gl_err));
-      CGLDestroyPixelFormat(context->pixelFormat);
-      free(context);
-      return NULL;
-    }
-	setup_dispatch_table();
-    GLAQUA_DEBUG_MSG("glAquaCreateContext done\n");
-  return &context->base;
-}
-
-static __GLXextensionInfo __glDDXExtensionInfo = {
-    GL_CORE_APPLE,
-    glAquaResetExtension,
-    glAquaInitVisuals,
-    glAquaSetVisualConfigs
-};
-
-void *__glXglDDXExtensionInfo(void) {
-  GLAQUA_DEBUG_MSG("glXAglDDXExtensionInfo\n");
-    return &__glDDXExtensionInfo;
-}
-
-/* maps from surface id -> list of __GLcontext */
-static x_hash_table *surface_hash;
-
-static void __glXAquaContextDestroy(__GLXcontext *baseContext) {
-    x_list *lst;
-
-    __GLXAquaContext *context = (__GLXAquaContext *) baseContext;
-
-    GLAQUA_DEBUG_MSG("glAquaContextDestroy (ctx 0x%x)\n",
-                     (unsigned int) baseContext);
-    if (context != NULL) {
-      if (context->sid != 0 && surface_hash != NULL) {
-		lst = x_hash_table_lookup(surface_hash, (void *) context->sid, NULL);
-		lst = x_list_remove(lst, context);
-		x_hash_table_insert(surface_hash, (void *) context->sid, lst);
-      }
-
-      if (context->ctx != NULL) CGLDestroyContext(context->ctx);
-
-      if (context->pixelFormat != NULL)	CGLDestroyPixelFormat(context->pixelFormat);
-      
-      free(context);
-    }
-}
-
-static int __glXAquaContextLoseCurrent(__GLXcontext *baseContext) {
-    CGLError gl_err;
-
-    GLAQUA_DEBUG_MSG("glAquaLoseCurrent (ctx 0x%p)\n", baseContext);
-
-    gl_err = CGLSetCurrentContext(NULL);
-    if (gl_err != 0)
-      ErrorF("CGLSetCurrentContext error: %s\n", CGLErrorString(gl_err));
-
-    __glXLastContext = NULL; // Mesa does this; why?
-
-    return GL_TRUE;
-}
-
-/* Called when a surface is destroyed as a side effect of destroying
-   the window it's attached to. */
-static void surface_notify(void *_arg, void *data) {
-    DRISurfaceNotifyArg *arg = (DRISurfaceNotifyArg *)_arg;
-    __GLXAquaDrawable *draw = (__GLXAquaDrawable *)data;
-    __GLXAquaContext *context;
-    x_list *lst;
-	if(_arg == NULL || data == NULL) {
-		ErrorF("surface_notify called with bad params");
-		return;
-	}
-	
-    GLAQUA_DEBUG_MSG("surface_notify(%p, %p)\n", _arg, data);
-    switch (arg->kind) {
-    case AppleDRISurfaceNotifyDestroyed:
-        if (surface_hash != NULL)
-            x_hash_table_remove(surface_hash, (void *) arg->id);
-	        draw->base.pDraw = NULL;
-			draw->sid = 0;
-        break;
-
-    case AppleDRISurfaceNotifyChanged:
-        if (surface_hash != NULL) {
-            lst = x_hash_table_lookup(surface_hash, (void *) arg->id, NULL);
-            for (; lst != NULL; lst = lst->next)
-            {
-                context = lst->data;
-                xp_update_gl_context(context->ctx);
-            }
-        }
-        break;
-	default:
-		ErrorF("surface_notify: unknown kind %d\n", arg->kind);
-		break;
-    }
-}
-
-static void attach(__GLXAquaContext *context, __GLXAquaDrawable *draw) {
-    DrawablePtr pDraw;
-	GLAQUA_DEBUG_MSG("attach(%p, %p)\n", context, draw);
-    pDraw = draw->base.pDraw;
-
-    if (draw->sid == 0) {
-//        if (!quartzProcs->CreateSurface(pDraw->pScreen, pDraw->id, pDraw,
-        if (!DRICreateSurface(pDraw->pScreen, pDraw->id, pDraw,
-                                        0, &draw->sid, NULL,
-                                        surface_notify, draw))
-            return;
-        draw->pDraw = pDraw;
-	} 
-
-    if (!context->isAttached || context->sid != draw->sid) {
-        x_list *lst;
-
-        if (xp_attach_gl_context(context->ctx, draw->sid) != Success) {
-//            quartzProcs->DestroySurface(pDraw->pScreen, pDraw->id, pDraw,
-            DRIDestroySurface(pDraw->pScreen, pDraw->id, pDraw,
-								surface_notify, draw);
-            if (surface_hash != NULL)
-                x_hash_table_remove(surface_hash, (void *) draw->sid);
-
-            draw->sid = 0;
-            return;
-        }
-
-        context->isAttached = TRUE;
-        context->sid = draw->sid;
-
-        if (surface_hash == NULL)
-            surface_hash = x_hash_table_new(NULL, NULL, NULL, NULL);
-
-        lst = x_hash_table_lookup(surface_hash, (void *) context->sid, NULL);
-        if (x_list_find(lst, context) == NULL) {
-            lst = x_list_prepend(lst, context);
-            x_hash_table_insert(surface_hash, (void *) context->sid, lst);
-        }
-
-        GLAQUA_DEBUG_MSG("attached 0x%x to 0x%x\n", (unsigned int) pDraw->id,
-                         (unsigned int) draw->sid);
-    } 
-}
-
-#if 0     // unused
-static void unattach(__GLXAquaContext *context) {
-	x_list *lst;
-	GLAQUA_DEBUG_MSG("unattach\n");
-	if (context == NULL) {
-		ErrorF("Tried to unattach a null context\n");
-		return;
-	}
-    if (context->isAttached) {
-        GLAQUA_DEBUG_MSG("unattaching\n");
-
-        if (surface_hash != NULL) {
-            lst = x_hash_table_lookup(surface_hash, (void *) context->sid, NULL);
-            lst = x_list_remove(lst, context);
-            x_hash_table_insert(surface_hash, (void *) context->sid, lst);
-        }
-
-        CGLClearDrawable(context->ctx);
-        context->isAttached = FALSE;
-        context->sid = 0;
-    }
-}
-#endif
-
-static int __glXAquaContextMakeCurrent(__GLXcontext *baseContext) {
-    CGLError gl_err;
-    __GLXAquaContext *context = (__GLXAquaContext *) baseContext;
-	__GLXAquaDrawable *drawPriv = (__GLXAquaDrawable *) context->base.drawPriv;
-
-    GLAQUA_DEBUG_MSG("glAquaMakeCurrent (ctx 0x%p)\n", baseContext);
-    
-    attach(context, drawPriv);
-
-    gl_err = CGLSetCurrentContext(context->ctx);
-    if (gl_err != 0)
-        ErrorF("CGLSetCurrentContext error: %s\n", CGLErrorString(gl_err));
-    
-    return gl_err == 0;
-}
-
-static int __glXAquaContextCopy(__GLXcontext *baseDst, __GLXcontext *baseSrc, unsigned long mask)
-{
-    CGLError gl_err;
-
-    __GLXAquaContext *dst = (__GLXAquaContext *) baseDst;
-    __GLXAquaContext *src = (__GLXAquaContext *) baseSrc;
-
-    GLAQUA_DEBUG_MSG("GLXAquaContextCopy\n");
-
-    gl_err = CGLCopyContext(src->ctx, dst->ctx, mask);
-    if (gl_err != 0)
-        ErrorF("CGLCopyContext error: %s\n", CGLErrorString(gl_err));
-
-    return gl_err == 0;
-}
-
-static int __glXAquaContextForceCurrent(__GLXcontext *baseContext)
-{
-    CGLError gl_err;
-    __GLXAquaContext *context = (__GLXAquaContext *) baseContext;
-    GLAQUA_DEBUG_MSG("glAquaForceCurrent (ctx %p)\n", context->ctx);
-
-    gl_err = CGLSetCurrentContext(context->ctx);
-    if (gl_err != 0)
-        ErrorF("CGLSetCurrentContext error: %s\n", CGLErrorString(gl_err));
-
-    return gl_err == 0;
-}
-
-/* Drawing surface notification callbacks */
-
-static GLboolean __glXAquaDrawableResize(__GLXdrawable *base)  {
-    GLAQUA_DEBUG_MSG("unimplemented glAquaDrawableResize\n");
-    return GL_TRUE;
-}
-
-static GLboolean __glXAquaDrawableSwapBuffers(__GLXdrawable *base) {
-    CGLError gl_err;
-	__GLXAquaContext * drawableCtx;
-//    GLAQUA_DEBUG_MSG("glAquaDrawableSwapBuffers(%p)\n",base);
-	
-	if(!base) {
-		ErrorF("glXAquaDrawbleSwapBuffers passed NULL\n");
-	    return GL_FALSE;
-	}
-
-    drawableCtx = (__GLXAquaContext *)base->drawGlxc;
-
-    if (drawableCtx != NULL && drawableCtx->ctx != NULL) {
-        gl_err = CGLFlushDrawable(drawableCtx->ctx);
-        if (gl_err != 0)
-            ErrorF("CGLFlushDrawable error: %s\n", CGLErrorString(gl_err));
-    }
-    return GL_TRUE;
-}
-
-static CGLPixelFormatObj makeFormat(__GLXconfig *config) {
-    int i;
-    CGLPixelFormatAttribute attr[64]; // currently uses max of 30
-    CGLPixelFormatObj result;
-    GLint n_formats;
-    CGLError gl_err;
-    
-    GLAQUA_DEBUG_MSG("makeFormat\n");
-
-    if (!config->rgbMode)
-        return NULL;
-
-    i = 0;
-
-    // attr [i++] = kCGLPFAAcelerated; // require hwaccel - BAD for multiscreen
-    // attr [i++] = kCGLPFANoRecovery; // disable fallback renderers - BAD
-
-    if (config->stereoMode) {
-        attr[i++] = kCGLPFAStereo;
-    }
-
-    if (config->doubleBufferMode) {
-        attr[i++] = kCGLPFADoubleBuffer;
-    }
-
-    if (config->colorIndexMode) {
-        /* ignored */
-    }
-
-    if (config->rgbMode) {
-        attr[i++] = kCGLPFAColorSize;
-        attr[i++] = config->redBits + config->greenBits + config->blueBits;
-        attr[i++] = kCGLPFAAlphaSize;
-        attr[i++] = 1; /* FIXME: ignoring config->alphaBits which is always 0 */
-    }
-
-    if (config->haveAccumBuffer) {
-        attr[i++] = kCGLPFAAccumSize;
-        attr[i++] = config->accumRedBits + config->accumGreenBits
-                    + config->accumBlueBits + config->accumAlphaBits;
-    }
-	
-    if (config->haveDepthBuffer) {
-        attr[i++] = kCGLPFADepthSize;
-        attr[i++] = config->depthBits;
-    }
-	
-    if (config->haveStencilBuffer) {
-        attr[i++] = kCGLPFAStencilSize;
-        attr[i++] = config->stencilBits;
-    }
-
-    attr[i++] = kCGLPFAAuxBuffers;
-    attr[i++] = config->numAuxBuffers;
-
-    /* mode->level ignored */
-
-    /* mode->pixmapMode ? */
-
-    attr[i++] = 0;
-
-    GLAQUA_DEBUG_MSG("makeFormat almost done\n");
-
-    result = NULL;
-    gl_err = CGLChoosePixelFormat(attr, &result, &n_formats);
-    if (gl_err != 0)
-        ErrorF("CGLChoosePixelFormat error: %s\n", CGLErrorString(gl_err));
-
-    GLAQUA_DEBUG_MSG("makeFormat done (0x%x)\n", (unsigned int) result);
-
-    return result;
-}
-
-// Originally copied from Mesa
-
-static int                 numConfigs     = 0;
-static __GLXvisualConfig  *visualConfigs  = NULL;
-static void              **visualPrivates = NULL;
-
-/*
- * In the case the driver defines no GLX visuals we'll use these.
- * Note that for TrueColor and DirectColor visuals, bufferSize is the 
- * sum of redSize, greenSize, blueSize and alphaSize, which may be larger 
- * than the nplanes/rootDepth of the server's X11 visuals
- */
-#define NUM_FALLBACK_CONFIGS 5
-static __GLXvisualConfig FallbackConfigs[NUM_FALLBACK_CONFIGS] = {
-  /* [0] = RGB, double buffered, Z */
-  {
-    -1,                 /* vid */
-    -1,                 /* class */
-    True,               /* rgba */
-    -1, -1, -1, 0,      /* rgba sizes */
-    -1, -1, -1, 0,      /* rgba masks */
-     0,  0,  0, 0,      /* rgba accum sizes */
-    True,               /* doubleBuffer */
-    False,              /* stereo */
-    -1,                 /* bufferSize */
-    16,                 /* depthSize */
-    0,                  /* stencilSize */
-    0,                  /* auxBuffers */
-    0,                  /* level */
-    GLX_NONE,           /* visualRating */
-    GLX_NONE,           /* transparentPixel */
-    0, 0, 0, 0,         /* transparent rgba color (floats scaled to ints) */
-    0                   /* transparentIndex */
-  },
-  /* [1] = RGB, double buffered, Z, stencil, accum */
-  {
-    -1,                 /* vid */
-    -1,                 /* class */
-    True,               /* rgba */
-    -1, -1, -1, 0,      /* rgba sizes */
-    -1, -1, -1, 0,      /* rgba masks */
-    16, 16, 16, 0,      /* rgba accum sizes */
-    True,               /* doubleBuffer */
-    False,              /* stereo */
-    -1,                 /* bufferSize */
-    16,                 /* depthSize */
-    8,                  /* stencilSize */
-    0,                  /* auxBuffers */
-    0,                  /* level */
-    GLX_NONE,           /* visualRating */
-    GLX_NONE,           /* transparentPixel */
-    0, 0, 0, 0,         /* transparent rgba color (floats scaled to ints) */
-    0                   /* transparentIndex */
-  },
-  /* [2] = RGB+Alpha, double buffered, Z, stencil, accum */
-  {
-    -1,                 /* vid */
-    -1,                 /* class */
-    True,               /* rgba */
-    -1, -1, -1, 8,      /* rgba sizes */
-    -1, -1, -1, -1,     /* rgba masks */
-    16, 16, 16, 16,     /* rgba accum sizes */
-    True,               /* doubleBuffer */
-    False,              /* stereo */
-    -1,                 /* bufferSize */
-    16,                 /* depthSize */
-    8,                  /* stencilSize */
-    0,                  /* auxBuffers */
-    0,                  /* level */
-    GLX_NONE,           /* visualRating */
-    GLX_NONE,           /* transparentPixel */
-    0, 0, 0, 0,         /* transparent rgba color (floats scaled to ints) */
-    0                   /* transparentIndex */
-  },
-  /* [3] = RGB+Alpha, single buffered, Z, stencil, accum */
-  {
-    -1,                 /* vid */
-    -1,                 /* class */
-    True,               /* rgba */
-    -1, -1, -1, 8,      /* rgba sizes */
-    -1, -1, -1, -1,     /* rgba masks */
-    16, 16, 16, 16,     /* rgba accum sizes */
-    False,              /* doubleBuffer */
-    False,              /* stereo */
-    -1,                 /* bufferSize */
-    16,                 /* depthSize */
-    8,                  /* stencilSize */
-    0,                  /* auxBuffers */
-    0,                  /* level */
-    GLX_NONE,           /* visualRating */
-    GLX_NONE,           /* transparentPixel */
-    0, 0, 0, 0,         /* transparent rgba color (floats scaled to ints) */
-    0                   /* transparentIndex */
-  },
-  /* [4] = CI, double buffered, Z */
-  {
-    -1,                 /* vid */
-    -1,                 /* class */
-    False,              /* rgba? (false = color index) */
-    -1, -1, -1, 0,      /* rgba sizes */
-    -1, -1, -1, 0,      /* rgba masks */
-     0,  0,  0, 0,      /* rgba accum sizes */
-    True,               /* doubleBuffer */
-    False,              /* stereo */
-    -1,                 /* bufferSize */
-    16,                 /* depthSize */
-    0,                  /* stencilSize */
-    0,                  /* auxBuffers */
-    0,                  /* level */
-    GLX_NONE,           /* visualRating */
-    GLX_NONE,           /* transparentPixel */
-    0, 0, 0, 0,         /* transparent rgba color (floats scaled to ints) */
-    0                   /* transparentIndex */
-  },
-};
-
-static __GLXvisualConfig NullConfig = {
-    -1,                 /* vid */
-    -1,                 /* class */
-    False,              /* rgba */
-    -1, -1, -1, 0,      /* rgba sizes */
-    -1, -1, -1, 0,      /* rgba masks */
-     0,  0,  0, 0,      /* rgba accum sizes */
-    False,              /* doubleBuffer */
-    False,              /* stereo */
-    -1,                 /* bufferSize */
-    16,                 /* depthSize */
-    0,                  /* stencilSize */
-    0,                  /* auxBuffers */
-    0,                  /* level */
-    GLX_NONE_EXT,       /* visualRating */
-    0,                  /* transparentPixel */
-    0, 0, 0, 0,         /* transparent rgba color (floats scaled to ints) */
-    0                   /* transparentIndex */
-};
-
-
-static inline int count_bits(uint32_t x)
-{
-    x = x - ((x >> 1) & 0x55555555);
-    x = (x & 0x33333333) + ((x >> 2) & 0x33333333);
-    x = (x + (x >> 4)) & 0x0f0f0f0f;
-    x = x + (x >> 8);
-    x = x + (x >> 16);
-    return x & 63;
-}
-
-
-static Bool init_visuals(int *nvisualp, VisualPtr *visualp,
-                         VisualID *defaultVisp,
-                         int ndepth, DepthPtr pdepth,
-                         int rootDepth)
-{
-    int numRGBconfigs;
-    int numCIconfigs;
-    int numVisuals = *nvisualp;
-    int numNewVisuals;
-    int numNewConfigs;
-    VisualPtr pVisual = *visualp;
-    VisualPtr pVisualNew = NULL;
-    VisualID *orig_vid = NULL;
-    __GLXconfig *modes;
-    __GLXvisualConfig *pNewVisualConfigs = NULL;
-    void **glXVisualPriv;
-    void **pNewVisualPriv;
-    int found_default;
-    int i, j, k;
-
-    GLAQUA_DEBUG_MSG("init_visuals\n");
-
-    if (numConfigs > 0)
-        numNewConfigs = numConfigs;
-    else
-        numNewConfigs = NUM_FALLBACK_CONFIGS;
-
-    /* Alloc space for the list of new GLX visuals */
-    pNewVisualConfigs = (__GLXvisualConfig *)
-                     malloc(numNewConfigs * sizeof(__GLXvisualConfig));
-    if (!pNewVisualConfigs) {
-        return FALSE;
-    }
-
-    /* Alloc space for the list of new GLX visual privates */
-    pNewVisualPriv = (void **) malloc(numNewConfigs * sizeof(void *));
-    if (!pNewVisualPriv) {
-        free(pNewVisualConfigs);
-        return FALSE;
-    }
-
-    /*
-    ** If SetVisualConfigs was not called, then use default GLX
-    ** visual configs.
-    */
-    if (numConfigs == 0) {
-        memcpy(pNewVisualConfigs, FallbackConfigs,
-               NUM_FALLBACK_CONFIGS * sizeof(__GLXvisualConfig));
-        memset(pNewVisualPriv, 0, NUM_FALLBACK_CONFIGS * sizeof(void *));
-    }
-    else {
-        /* copy driver's visual config info */
-        for (i = 0; i < numConfigs; i++) {
-            pNewVisualConfigs[i] = visualConfigs[i];
-            pNewVisualPriv[i] = visualPrivates[i];
-        }
-    }
-
-    /* Count the number of RGB and CI visual configs */
-    numRGBconfigs = 0;
-    numCIconfigs = 0;
-    for (i = 0; i < numNewConfigs; i++) {
-        if (pNewVisualConfigs[i].rgba)
-            numRGBconfigs++;
-        else
-            numCIconfigs++;
-    }
-
-    /* Count the total number of visuals to compute */
-    numNewVisuals = 0;
-    for (i = 0; i < numVisuals; i++) {
-        int count;
-
-        count = ((pVisual[i].class == TrueColor ||
-                  pVisual[i].class == DirectColor)
-                ? numRGBconfigs : numCIconfigs);
-        if (count == 0)
-            count = 1;          /* preserve the existing visual */
-
-        numNewVisuals += count;
-    }
-
-    /* Reset variables for use with the next screen/driver's visual configs */
-    visualConfigs = NULL;
-    numConfigs = 0;
-
-    /* Alloc temp space for the list of orig VisualIDs for each new visual */
-    orig_vid = (VisualID *)malloc(numNewVisuals * sizeof(VisualID));
-    if (!orig_vid) {
-        free(pNewVisualPriv);
-        free(pNewVisualConfigs);
-        return FALSE;
-    }
-
-    /* Alloc space for the list of glXVisuals */
-    modes = _gl_context_modes_create(numNewVisuals, sizeof(__GLXconfig));
-    if (modes == NULL) {
-        free(orig_vid);
-        free(pNewVisualPriv);
-        free(pNewVisualConfigs);
-        return FALSE;
-    }
-
-    /* Alloc space for the list of glXVisualPrivates */
-    glXVisualPriv = (void **)malloc(numNewVisuals * sizeof(void *));
-    if (!glXVisualPriv) {
-        _gl_context_modes_destroy( modes );
-        free(orig_vid);
-        free(pNewVisualPriv);
-        free(pNewVisualConfigs);
-        return FALSE;
-    }
-
-    /* Alloc space for the new list of the X server's visuals */
-    pVisualNew = (VisualPtr)malloc(numNewVisuals * sizeof(VisualRec));
-    if (!pVisualNew) {
-        free(glXVisualPriv);
-        _gl_context_modes_destroy( modes );
-        free(orig_vid);
-        free(pNewVisualPriv);
-        free(pNewVisualConfigs);
-        return FALSE;
-    }
-
-    /* Initialize the new visuals */
-    found_default = FALSE;
-    glAquaScreens[screenInfo.numScreens-1].modes = modes;
-    for (i = j = 0; i < numVisuals; i++) {
-        int is_rgb = (pVisual[i].class == TrueColor ||
-                      pVisual[i].class == DirectColor);
-
-        if (!is_rgb)
-        {
-            /* We don't support non-rgb visuals for GL. But we don't
-               want to remove them either, so just pass them through
-               with null glX configs */
-
-            pVisualNew[j] = pVisual[i];
-            pVisualNew[j].vid = FakeClientID(0);
-
-            /* Check for the default visual */
-            if (!found_default && pVisual[i].vid == *defaultVisp) {
-                *defaultVisp = pVisualNew[j].vid;
-                found_default = TRUE;
-            }
-
-            /* Save the old VisualID */
-            orig_vid[j] = pVisual[i].vid;
-
-            /* Initialize the glXVisual */
-            _gl_copy_visual_to_context_mode( modes, & NullConfig );
-            modes->visualID = pVisualNew[j].vid;
-
-            j++;
-
-            continue;
-        }
-
-        for (k = 0; k < numNewConfigs; k++) {
-            if (pNewVisualConfigs[k].rgba != is_rgb)
-                continue;
-
-            assert( modes != NULL );
-
-            /* Initialize the new visual */
-            pVisualNew[j] = pVisual[i];
-            pVisualNew[j].vid = FakeClientID(0);
-
-            /* Check for the default visual */
-            if (!found_default && pVisual[i].vid == *defaultVisp) {
-                *defaultVisp = pVisualNew[j].vid;
-                found_default = TRUE;
-            }
-
-            /* Save the old VisualID */
-            orig_vid[j] = pVisual[i].vid;
-
-            /* Initialize the glXVisual */
-            _gl_copy_visual_to_context_mode( modes, & pNewVisualConfigs[k] );
-            modes->visualID = pVisualNew[j].vid;
-
-            /*
-             * If the class is -1, then assume the X visual information
-             * is identical to what GLX needs, and take them from the X
-             * visual.  NOTE: if class != -1, then all other fields MUST
-             * be initialized.
-             */
-            if (modes->visualType == GLX_NONE) {
-                modes->visualType = _gl_convert_from_x_visual_type( pVisual[i].class );
-                modes->redBits    = count_bits(pVisual[i].redMask);
-                modes->greenBits  = count_bits(pVisual[i].greenMask);
-                modes->blueBits   = count_bits(pVisual[i].blueMask);
-                modes->alphaBits  = modes->alphaBits;
-                modes->redMask    = pVisual[i].redMask;
-                modes->greenMask  = pVisual[i].greenMask;
-                modes->blueMask   = pVisual[i].blueMask;
-                modes->alphaMask  = modes->alphaMask;
-                modes->rgbBits = (is_rgb)
-                    ? (modes->redBits + modes->greenBits +
-                       modes->blueBits + modes->alphaBits)
-                    : rootDepth;
-            }
-
-            /* Save the device-dependent private for this visual */
-            glXVisualPriv[j] = pNewVisualPriv[k];
-
-            j++;
-            modes = modes->next;
-        }
-    }
-
-    assert(j <= numNewVisuals);
-
-    /* Save the GLX visuals in the screen structure */
-    glAquaScreens[screenInfo.numScreens-1].num_vis = numNewVisuals;
-    //    glAquaScreens[screenInfo.numScreens-1].priv = glXVisualPriv;
-
-    /* set up depth's VisualIDs */
-    for (i = 0; i < ndepth; i++) {
-        int numVids = 0;
-        VisualID *pVids = NULL;
-        int k, n = 0;
-
-        /* Count the new number of VisualIDs at this depth */
-        for (j = 0; j < pdepth[i].numVids; j++)
-            for (k = 0; k < numNewVisuals; k++)
-            if (pdepth[i].vids[j] == orig_vid[k])
-                numVids++;
-
-        /* Allocate a new list of VisualIDs for this depth */
-        pVids = (VisualID *)malloc(numVids * sizeof(VisualID));
-
-        /* Initialize the new list of VisualIDs for this depth */
-        for (j = 0; j < pdepth[i].numVids; j++)
-            for (k = 0; k < numNewVisuals; k++)
-            if (pdepth[i].vids[j] == orig_vid[k])
-                pVids[n++] = pVisualNew[k].vid;
-
-        /* Update this depth's list of VisualIDs */
-        free(pdepth[i].vids);
-        pdepth[i].vids = pVids;
-        pdepth[i].numVids = numVids;
-    }
-
-    /* Update the X server's visuals */
-    *nvisualp = numNewVisuals;
-    *visualp = pVisualNew;
-
-    /* Free the old list of the X server's visuals */
-    free(pVisual);
-
-    /* Clean up temporary allocations */
-    free(orig_vid);
-    free(pNewVisualPriv);
-    free(pNewVisualConfigs);
-
-    /* Free the private list created by DDX HW driver */
-    if (visualPrivates)
-        free(visualPrivates);
-    visualPrivates = NULL;
-
-    return TRUE;
-}
-
-Bool enable_stereo = FALSE;
-/* based on code in i830_dri.c
-   This ends calling glAquaSetVisualConfigs to set the static
-   numconfigs, etc. */
-// see also glxglcore.c -- bhb
-static void
-glAquaInitVisualConfigs(void)
-{
-    int                 lclNumConfigs     = 0;
-    __GLXvisualConfig  *lclVisualConfigs  = NULL;
-    void              **lclVisualPrivates = NULL;
-
-    int stereo, depth, aux, buffers, stencil, accum;
-    int i = 0;
-
-    GLAQUA_DEBUG_MSG("glAquaInitVisualConfigs ");
-        
-    /* count num configs:
-        2 stereo (on, off) (optional)
-        2 Z buffer (0, 24 bit)
-        2 AUX buffer (0, 2)
-        2 buffers (single, double)
-        2 stencil (0, 8 bit)
-        2 accum (0, 64 bit)
-        = 64 configs with stereo, or 32 without */
-
-    if (enable_stereo) lclNumConfigs = 2 * 2 * 2 * 2 * 2 * 2; /* 64 */
-    else               lclNumConfigs = 2 * 2 * 2 * 2 * 2; /* 32 */
-
-    /* alloc */
-    lclVisualConfigs = xcalloc(sizeof(__GLXvisualConfig), lclNumConfigs);
-    lclVisualPrivates = xcalloc(sizeof(void *), lclNumConfigs);
-
-    /* fill in configs */
-    if (NULL != lclVisualConfigs) {
-        i = 0; /* current buffer */
-        for (stereo = 0; stereo < (enable_stereo ? 2 : 1); stereo++) {
-	  for (depth = 0; depth < 2; depth++) {
-            for (aux = 0; aux < 2; aux++) {
-	      for (buffers = 0; buffers < 2; buffers++) {
-		for (stencil = 0; stencil < 2; stencil++) {
-		  for (accum = 0; accum < 2; accum++) {
-		    lclVisualConfigs[i].vid = -1;
-		    lclVisualConfigs[i].class = -1;
-		    lclVisualConfigs[i].rgba = TRUE;
-		    lclVisualConfigs[i].redSize = -1;
-		    lclVisualConfigs[i].greenSize = -1;
-		    lclVisualConfigs[i].blueSize = -1;
-		    lclVisualConfigs[i].redMask = -1;
-		    lclVisualConfigs[i].greenMask = -1;
-		    lclVisualConfigs[i].blueMask = -1;
-		    lclVisualConfigs[i].alphaMask = 0;
-		    if (accum) {
-		      lclVisualConfigs[i].accumRedSize = 16;
-		      lclVisualConfigs[i].accumGreenSize = 16;
-		      lclVisualConfigs[i].accumBlueSize = 16;
-		      lclVisualConfigs[i].accumAlphaSize = 16;
-		    } else {
-		      lclVisualConfigs[i].accumRedSize = 0;
-		      lclVisualConfigs[i].accumGreenSize = 0;
-		      lclVisualConfigs[i].accumBlueSize = 0;
-		      lclVisualConfigs[i].accumAlphaSize = 0;
-		    }
-		    lclVisualConfigs[i].doubleBuffer = buffers ? TRUE : FALSE;
-		    lclVisualConfigs[i].stereo = stereo ? TRUE : FALSE;
-		    lclVisualConfigs[i].bufferSize = -1;
-		    
-		    lclVisualConfigs[i].depthSize = depth? 24 : 0;
-		    lclVisualConfigs[i].stencilSize = stencil ? 8 : 0;
-		    lclVisualConfigs[i].auxBuffers = aux ? 2 : 0;
-		    lclVisualConfigs[i].level = 0;
-		    lclVisualConfigs[i].visualRating = GLX_NONE_EXT;
-		    lclVisualConfigs[i].transparentPixel = 0;
-		    lclVisualConfigs[i].transparentRed = 0;
-		    lclVisualConfigs[i].transparentGreen = 0;
-		    lclVisualConfigs[i].transparentBlue = 0;
-		    lclVisualConfigs[i].transparentAlpha = 0;
-		    lclVisualConfigs[i].transparentIndex = 0;
-		    i++;
-		  }
-		}
-	      }
-            }
-	  }
-	}
-    }
-    if (i != lclNumConfigs)
-        GLAQUA_DEBUG_MSG("glAquaInitVisualConfigs failed to alloc visual configs");
-
-    GlxSetVisualConfigs(lclNumConfigs, lclVisualConfigs, lclVisualPrivates);
-}
-
-
-static void glAquaSetVisualConfigs(int nconfigs, __GLXvisualConfig *configs,
-                                   void **privates)
-{
-    GLAQUA_DEBUG_MSG("glAquaSetVisualConfigs\n");
-
-    numConfigs = nconfigs;
-    visualConfigs = configs;
-    visualPrivates = privates;
-}
-
-static Bool glAquaInitVisuals(VisualPtr *visualp, DepthPtr *depthp,
-                              int *nvisualp, int *ndepthp,
-                              int *rootDepthp, VisualID *defaultVisp,
-                              unsigned long sizes, int bitsPerRGB)
-{
-    GLAQUA_DEBUG_MSG("glAquaInitVisuals\n");
-    
-    if (numConfigs == 0) /* if no configs */
-        glAquaInitVisualConfigs(); /* ensure the visual configs are setup */
-
-    /*
-     * setup the visuals supported by this particular screen.
-     */
-    return init_visuals(nvisualp, visualp, defaultVisp,
-                        *ndepthp, *depthp, *rootDepthp);
-}
-
-#if 0
-static void fixup_visuals(int screen)
-{
-    ScreenPtr pScreen = screenInfo.screens[screen];
-    glAquaScreenRec *pScr = &glAquaScreens[screen];
-    int j;
-    __GLcontextModes *modes;
-
-    GLAQUA_DEBUG_MSG("fixup_visuals\n");
-
-    for ( modes = pScr->modes ; modes != NULL ; modes = modes->next ) {
-        const int vis_class = _gl_convert_to_x_visual_type( modes->visualType );
-        const int nplanes = (modes->rgbBits - modes->alphaBits);
-        const VisualPtr pVis = pScreen->visuals;
-
-        /* Find a visual that matches the GLX visual's class and size */
-        for (j = 0; j < pScreen->numVisuals; j++) {
-            if (pVis[j].class == vis_class &&
-            pVis[j].nplanes == nplanes) {
-
-            /* Fixup the masks */
-            modes->redMask   = pVis[j].redMask;
-            modes->greenMask = pVis[j].greenMask;
-            modes->blueMask  = pVis[j].blueMask;
-
-            /* Recalc the sizes */
-            modes->redBits   = count_bits(modes->redMask);
-            modes->greenBits = count_bits(modes->greenMask);
-            modes->blueBits  = count_bits(modes->blueMask);
-            }
-        }
-    }
-}
-#endif
-static void __glXAquaScreenDestroy(__GLXscreen *screen) {
-
-	GLAQUA_DEBUG_MSG("glXAquaScreenDestroy(%p)\n", screen);
-  __glXScreenDestroy(screen);
-
-  free(screen);
-}
-
-static void init_screen_visuals(__GLXAquaScreen *screen) {
-  ScreenPtr pScreen = screen->base.pScreen;
-  
-  __GLXconfig *modes;
-  int *used;
-  int i, j;
-  
-    GLAQUA_DEBUG_MSG("init_screen_visuals\n");
-
-    /* FIXME: Change 'used' to be a array of bits (rather than of ints),
-     * FIXME: create a stack array of 8 or 16 bytes.  If 'numVisuals' is less
-     * FIXME: than 64 or 128 the stack array can be used instead of calling
-     * FIXME: malloc / free.  If nothing else, convert 'used' to
-     * FIXME: array of bytes instead of ints!
-     */
-    used = (int *)malloc(pScreen->numVisuals * sizeof(int));
-    memset(used, 0, pScreen->numVisuals * sizeof(int));
-
-    i = 0;
-    for ( modes = screen -> base.visuals
-          ; modes != NULL
-          ; modes = modes->next ) {
-        const int vis_class = _gl_convert_to_x_visual_type( modes->visualType );
-        const int nplanes = (modes->rgbBits - modes->alphaBits);
-        const VisualPtr pVis = pScreen->visuals;
-
-        for (j = 0; j < pScreen->numVisuals; j++) {
-            if (pVis[j].class     == vis_class &&
-                pVis[j].nplanes   == nplanes &&
-                pVis[j].redMask   == modes->redMask &&
-                pVis[j].greenMask == modes->greenMask &&
-                pVis[j].blueMask  == modes->blueMask &&
-                !used[j]) {
-
-                    /* set the VisualID */
-                    modes->visualID = pVis[j].vid;
-
-                    /* Mark this visual used */
-                    used[j] = 1;
-                    break;
-            }
-        }
-        if ( j == pScreen->numVisuals ) {
-            ErrorF("No matching visual for __GLcontextMode with "
-                   "visual class = %d (%d), nplanes = %u\n",
-                   vis_class, 
-                   (int)modes->visualType,
-                   (unsigned int)(modes->rgbBits - modes->alphaBits) );
-        }
-        else if ( modes->visualID == -1 ) {
-            FatalError( "Matching visual found, but visualID still -1!\n" );
-        }
-
-        i++;
-    }
-
-    free(used);
-}
-
-static __GLXscreen * __glXAquaScreenProbe(ScreenPtr pScreen) {
-  __GLXAquaScreen *screen;
-  GLAQUA_DEBUG_MSG("glXAquaScreenProbe\n");
-  if (screen == NULL) return NULL;
-
-  screen = malloc(sizeof *screen);
-
-  __glXScreenInit(&screen->base, pScreen);
-
-  screen->base.destroy        = __glXAquaScreenDestroy;
-  screen->base.createContext  = __glXAquaScreenCreateContext;
-  screen->base.createDrawable = __glXAquaScreenCreateDrawable;
-  screen->base.pScreen       = pScreen;
-
-  init_screen_visuals(screen);
-
-  return &screen->base;
-}
-
-static void __glXAquaDrawableDestroy(__GLXdrawable *base) {
-    GLAQUA_DEBUG_MSG("glAquaDestroyDrawablePrivate\n");
-
-    /* It doesn't work to call DRIDestroySurface here, the drawable's
-       already gone.. But dri.c notices the window destruction and
-       frees the surface itself. */
-
-    free(base);
-}
-
-static __GLXdrawable *
-__glXAquaScreenCreateDrawable(__GLXscreen *screen,
-			      DrawablePtr pDraw,
-			      XID drawId,
-			      __GLXconfig *modes) {
-  __GLXAquaDrawable *glxPriv;
-
-  GLAQUA_DEBUG_MSG("glAquaScreenCreateDrawable(%p,%p,%d,%p)\n", context, pDraw, drawId, modes);
-
-  glxPriv = xalloc(sizeof *glxPriv);
-  if (glxPriv == NULL) return NULL;
-
-  memset(glxPriv, 0, sizeof *glxPriv);
-
-  if (!__glXDrawableInit(&glxPriv->base, screen, pDraw, GLX_DRAWABLE_PIXMAP /*?*/, drawId, modes)) {
-    xfree(glxPriv);
-    return NULL;
-  }
-
-  glxPriv->base.destroy       = __glXAquaDrawableDestroy;
-  glxPriv->base.resize        = __glXAquaDrawableResize;
-  glxPriv->base.swapBuffers   = __glXAquaDrawableSwapBuffers;
-  //  glxPriv->base.copySubBuffer = __glXAquaDrawableCopySubBuffer;
-
-  return &glxPriv->base;
-}
-
-static void glAquaResetExtension(void)
-{
-    GLAQUA_DEBUG_MSG("glAquaResetExtension\n");
-    CGLSetOption(kCGLGOResetLibrary, GL_TRUE);
-}
-
-// Extra goodies for glx
-
-GLuint __glFloorLog2(GLuint val)
-{
-    int c = 0;
-
-    while (val > 1) {
-        c++;
-        val >>= 1;
-    }
-    return c;
-}
-
-void warn_func(void * p1, char *format, ...) {
-  va_list v;
-  va_start(v, format);
-  vfprintf(stderr, format, v);
-  va_end(v);
-}
-
-static void setup_dispatch_table(void) {
-  struct _glapi_table *disp=_glapi_get_dispatch();
-  _glapi_set_warning_func((_glapi_warning_func)warn_func);
-  _glapi_noop_enable_warnings(TRUE);
-
-  SET_Accum(disp, glAccum);
-  SET_ActiveStencilFaceEXT(disp, glActiveStencilFaceEXT);
-  SET_ActiveTextureARB(disp, glActiveTextureARB);
-//SET_AlphaFragmentOp1ATI(disp, glAlphaFragmentOp1EXT);   // <-- EXT -> ATI
-//SET_AlphaFragmentOp2ATI(disp, glAlphaFragmentOp2EXT);
-//SET_AlphaFragmentOp3ATI(disp, glAlphaFragmentOp3EXT);
-  SET_AlphaFunc(disp, glAlphaFunc);
-//SET_AreProgramsResidentNV(disp, glAreProgramsResidentNV);
-  SET_AreTexturesResident(disp, glAreTexturesResident); 
-  SET_ArrayElement(disp, glArrayElement);
-  SET_AttachObjectARB(disp, glAttachObjectARB);
-  SET_Begin(disp, glBegin);
-//SET_BeginFragmentShaderATI(disp, glBeginFragmentShaderEXT);   // <-- EXT -> ATI
-  SET_BeginQueryARB(disp, glBeginQueryARB);
-  SET_BindAttribLocationARB(disp, glBindAttribLocationARB);
-  SET_BindBufferARB(disp, glBindBufferARB);
-//SET_BindFragmentShaderATI(disp, glBindFragmentShaderEXT);     // <-- EXT -> ATI
-  SET_BindFramebufferEXT(disp, glBindFramebufferEXT);
-//SET_BindProgramNV(disp, glBindProgramNV);
-  SET_BindRenderbufferEXT(disp, glBindRenderbufferEXT);
-  SET_BindTexture(disp, glBindTexture);
-  SET_Bitmap(disp, glBitmap);
-  SET_BlendColor(disp, glBlendColor);
-  SET_BlendEquation(disp, glBlendEquation);
-  SET_BlendEquationSeparateEXT(disp, glBlendEquationSeparateEXT);
-  SET_BlendFunc(disp, glBlendFunc);
-  SET_BlendFuncSeparateEXT(disp, glBlendFuncSeparateEXT);
-  SET_BlitFramebufferEXT(disp, glBlitFramebufferEXT);
-  SET_BufferDataARB(disp, glBufferDataARB);
-  SET_BufferSubDataARB(disp, glBufferSubDataARB);
-  SET_CallList(disp, glCallList);
-  SET_CallLists(disp, glCallLists);
-  SET_CheckFramebufferStatusEXT(disp, glCheckFramebufferStatusEXT);
-  SET_Clear(disp, glClear);
-  SET_ClearAccum(disp, glClearAccum);
-  SET_ClearColor(disp, glClearColor);
-  SET_ClearDepth(disp, glClearDepth);
-  SET_ClearIndex(disp, glClearIndex);
-  SET_ClearStencil(disp, glClearStencil);
-  SET_ClientActiveTextureARB(disp, glClientActiveTextureARB);
-  SET_ClipPlane(disp, glClipPlane);
-  SET_Color3b(disp, glColor3b);
-  SET_Color3bv(disp, glColor3bv);
-  SET_Color3d(disp, glColor3d);
-  SET_Color3dv(disp, glColor3dv);
-  SET_Color3f(disp, glColor3f);
-  SET_Color3fv(disp, glColor3fv);
-  SET_Color3i(disp, glColor3i);
-  SET_Color3iv(disp, glColor3iv);
-  SET_Color3s(disp, glColor3s);
-  SET_Color3sv(disp, glColor3sv);
-  SET_Color3ub(disp, glColor3ub);
-  SET_Color3ubv(disp, glColor3ubv);
-  SET_Color3ui(disp, glColor3ui);
-  SET_Color3uiv(disp, glColor3uiv);
-  SET_Color3us(disp, glColor3us);
-  SET_Color3usv(disp, glColor3usv);
-  SET_Color4b(disp, glColor4b);
-  SET_Color4bv(disp, glColor4bv);
-  SET_Color4d(disp, glColor4d);
-  SET_Color4dv(disp, glColor4dv);
-  SET_Color4f(disp, glColor4f);
-  SET_Color4fv(disp, glColor4fv);
-  SET_Color4i(disp, glColor4i);
-  SET_Color4iv(disp, glColor4iv);
-  SET_Color4s(disp, glColor4s);
-  SET_Color4sv(disp, glColor4sv);
-  SET_Color4ub(disp, glColor4ub);
-  SET_Color4ubv(disp, glColor4ubv);
-  SET_Color4ui(disp, glColor4ui);
-  SET_Color4uiv(disp, glColor4uiv);
-  SET_Color4us(disp, glColor4us);
-  SET_Color4usv(disp, glColor4usv);
-//SET_ColorFragmentOp1ATI(disp, glColorFragmentOp1EXT);    // <-- EXT -> ATI
-//SET_ColorFragmentOp2ATI(disp, glColorFragmentOp2EXT);
-//SET_ColorFragmentOp3ATI(disp, glColorFragmentOp3EXT);
-  SET_ColorMask(disp, glColorMask);
-  SET_ColorMaterial(disp, glColorMaterial);
-  SET_ColorPointer(disp, glColorPointer);
-//SET_ColorPointerEXT(disp, glColorPointerEXT);
-  SET_ColorSubTable(disp, glColorSubTable);
-  SET_ColorTable(disp, glColorTable);
-  SET_ColorTableParameterfv(disp, glColorTableParameterfv);
-  SET_ColorTableParameteriv(disp, glColorTableParameteriv);
-  SET_CombinerInputNV(disp, glCombinerInputNV);
-  SET_CombinerOutputNV(disp, glCombinerOutputNV);
-  SET_CombinerParameterfNV(disp, glCombinerParameterfNV);
-  SET_CombinerParameterfvNV(disp, glCombinerParameterfvNV);
-  SET_CombinerParameteriNV(disp, glCombinerParameteriNV);
-  SET_CombinerParameterivNV(disp, glCombinerParameterivNV);
-  SET_CompileShaderARB(disp, glCompileShaderARB);
-  SET_CompressedTexImage1DARB(disp, glCompressedTexImage1DARB);
-  SET_CompressedTexImage2DARB(disp, glCompressedTexImage2DARB);
-  SET_CompressedTexImage3DARB(disp, glCompressedTexImage3DARB);
-  SET_CompressedTexSubImage1DARB(disp, glCompressedTexSubImage1DARB);
-  SET_CompressedTexSubImage2DARB(disp, glCompressedTexSubImage2DARB);
-  SET_CompressedTexSubImage3DARB(disp, glCompressedTexSubImage3DARB);
-  SET_ConvolutionFilter1D(disp, glConvolutionFilter1D);
-  SET_ConvolutionFilter2D(disp, glConvolutionFilter2D);
-  SET_ConvolutionParameterf(disp, glConvolutionParameterf);
-  SET_ConvolutionParameterfv(disp, glConvolutionParameterfv);
-  SET_ConvolutionParameteri(disp, glConvolutionParameteri);
-  SET_ConvolutionParameteriv(disp, glConvolutionParameteriv);
-  SET_CopyColorSubTable(disp, glCopyColorSubTable);
-  SET_CopyColorTable(disp, glCopyColorTable);
-  SET_CopyConvolutionFilter1D(disp, glCopyConvolutionFilter1D);
-  SET_CopyConvolutionFilter2D(disp, glCopyConvolutionFilter2D);
-  SET_CopyPixels(disp, glCopyPixels);
-  SET_CopyTexImage1D(disp, glCopyTexImage1D);
-  SET_CopyTexImage2D(disp, glCopyTexImage2D);
-  SET_CopyTexSubImage1D(disp, glCopyTexSubImage1D);
-  SET_CopyTexSubImage2D(disp, glCopyTexSubImage2D);
-  SET_CopyTexSubImage3D(disp, glCopyTexSubImage3D);
-  SET_CreateProgramObjectARB(disp, glCreateProgramObjectARB);
-  SET_CreateShaderObjectARB(disp, glCreateShaderObjectARB);
-  SET_CullFace(disp, glCullFace);
-//SET_CullParameterdvEXT(disp, glCullParameterdvEXT);
-//SET_CullParameterfvEXT(disp, glCullParameterfvEXT);
-  SET_DeleteBuffersARB(disp, glDeleteBuffersARB);
-  SET_DeleteFencesNV(disp, glDeleteFencesAPPLE);
-//SET_DeleteFragmentShaderATI(disp, glDeleteFragmentShaderEXT);      // <-- EXT -> ATI
-  SET_DeleteFramebuffersEXT(disp, glDeleteFramebuffersEXT);
-  SET_DeleteLists(disp, glDeleteLists);
-  SET_DeleteObjectARB(disp, glDeleteObjectARB);
-//SET_DeleteProgramsNV(disp, glDeleteProgramsNV);
-  SET_DeleteQueriesARB(disp, glDeleteQueriesARB);
-  SET_DeleteRenderbuffersEXT(disp, glDeleteRenderbuffersEXT);
-  SET_DeleteTextures(disp, glDeleteTextures);
-  SET_DepthBoundsEXT(disp, glDepthBoundsEXT);
-  SET_DepthFunc(disp, glDepthFunc);
-  SET_DepthMask(disp, glDepthMask);
-  SET_DepthRange(disp, glDepthRange);
-  SET_DetachObjectARB(disp, glDetachObjectARB);
-  SET_Disable(disp, glDisable);
-  SET_DisableClientState(disp, glDisableClientState);
-  SET_DisableVertexAttribArrayARB(disp, glDisableVertexAttribArrayARB);
-  SET_DrawArrays(disp, glDrawArrays);
-  SET_DrawBuffer(disp, glDrawBuffer);
-  SET_DrawBuffersARB(disp, glDrawBuffersARB);
-  SET_DrawElements(disp, glDrawElements);
-  SET_DrawPixels(disp, glDrawPixels);
-  SET_DrawRangeElements(disp, glDrawRangeElements);
-  SET_EdgeFlag(disp, glEdgeFlag);
-  SET_EdgeFlagPointer(disp, glEdgeFlagPointer);
-//SET_EdgeFlagPointerEXT(disp, glEdgeFlagPointerEXT);
-  SET_EdgeFlagv(disp, glEdgeFlagv);
-  SET_Enable(disp, glEnable);
-  SET_EnableClientState(disp, glEnableClientState);
-  SET_EnableVertexAttribArrayARB(disp, glEnableVertexAttribArrayARB);
-  SET_End(disp, glEnd);
-//SET_EndFragmentShaderATI(disp, glEndFragmentShaderEXT);        // <-- EXT -> ATI
-  SET_EndList(disp, glEndList);
-  SET_EndQueryARB(disp, glEndQueryARB);
-  SET_EvalCoord1d(disp, glEvalCoord1d);
-  SET_EvalCoord1dv(disp, glEvalCoord1dv);
-  SET_EvalCoord1f(disp, glEvalCoord1f);
-  SET_EvalCoord1fv(disp, glEvalCoord1fv);
-  SET_EvalCoord2d(disp, glEvalCoord2d);
-  SET_EvalCoord2dv(disp, glEvalCoord2dv);
-  SET_EvalCoord2f(disp, glEvalCoord2f);
-  SET_EvalCoord2fv(disp, glEvalCoord2fv);
-  SET_EvalMesh1(disp, glEvalMesh1);
-  SET_EvalMesh2(disp, glEvalMesh2);
-  SET_EvalPoint1(disp, glEvalPoint1);
-  SET_EvalPoint2(disp, glEvalPoint2);
-//SET_ExecuteProgramNV(disp, glExecuteProgramNV);
-  SET_FeedbackBuffer(disp, glFeedbackBuffer);
-  SET_FinalCombinerInputNV(disp, glFinalCombinerInputNV);
-  SET_Finish(disp, glFinish);
-  SET_FinishFenceNV(disp, glFinishFenceAPPLE);       // <-- APPLE -> NV
-  SET_Flush(disp, glFlush);
-//SET_FlushVertexArrayRangeNV(disp, glFlushVertexArrayRangeNV);
-  SET_FogCoordPointerEXT(disp, glFogCoordPointerEXT);
-  SET_FogCoorddEXT(disp, glFogCoorddEXT);
-  SET_FogCoorddvEXT(disp, glFogCoorddvEXT);
-  SET_FogCoordfEXT(disp, glFogCoordfEXT);
-  SET_FogCoordfvEXT(disp, glFogCoordfvEXT);
-  SET_Fogf(disp, glFogf);
-  SET_Fogfv(disp, glFogfv);
-  SET_Fogi(disp, glFogi);
-  SET_Fogiv(disp, glFogiv);
-  SET_FramebufferRenderbufferEXT(disp, glFramebufferRenderbufferEXT);
-  SET_FramebufferTexture1DEXT(disp, glFramebufferTexture1DEXT);
-  SET_FramebufferTexture2DEXT(disp, glFramebufferTexture2DEXT);
-  SET_FramebufferTexture3DEXT(disp, glFramebufferTexture3DEXT);
-  SET_FrontFace(disp, glFrontFace);
-  SET_Frustum(disp, glFrustum);
-  SET_GenBuffersARB(disp, glGenBuffersARB);
-  SET_GenFencesNV(disp, glGenFencesAPPLE);            // <-- APPLE -> NV
-//SET_GenFragmentShadersATI(disp, glGenFragmentShadersEXT);         // <-- EXT -> ATI
-  SET_GenFramebuffersEXT(disp, glGenFramebuffersEXT);
-  SET_GenLists(disp, glGenLists);
-//SET_GenProgramsNV(disp, glGenProgramsNV);
-  SET_GenQueriesARB(disp, glGenQueriesARB);
-  SET_GenRenderbuffersEXT(disp, glGenRenderbuffersEXT);
-  SET_GenTextures(disp, glGenTextures);
-  SET_GenerateMipmapEXT(disp, glGenerateMipmapEXT);
-  SET_GetActiveAttribARB(disp, glGetActiveAttribARB);
-  SET_GetActiveUniformARB(disp, glGetActiveUniformARB);
-  SET_GetAttachedObjectsARB(disp, glGetAttachedObjectsARB);
-  SET_GetAttribLocationARB(disp, glGetAttribLocationARB);
-  SET_GetBooleanv(disp, glGetBooleanv);
-  SET_GetBufferParameterivARB(disp, glGetBufferParameterivARB);
-  SET_GetBufferPointervARB(disp, glGetBufferPointervARB);
-  SET_GetBufferSubDataARB(disp, glGetBufferSubDataARB);
-  SET_GetClipPlane(disp, glGetClipPlane);
-  SET_GetColorTable(disp, glGetColorTable);
-  SET_GetColorTableParameterfv(disp, glGetColorTableParameterfv);
-  SET_GetColorTableParameteriv(disp, glGetColorTableParameteriv);
-  SET_GetCombinerInputParameterfvNV(disp, glGetCombinerInputParameterfvNV);
-  SET_GetCombinerInputParameterivNV(disp, glGetCombinerInputParameterivNV);
-  SET_GetCombinerOutputParameterfvNV(disp, glGetCombinerOutputParameterfvNV);
-  SET_GetCombinerOutputParameterivNV(disp, glGetCombinerOutputParameterivNV);
-  SET_GetCompressedTexImageARB(disp, glGetCompressedTexImageARB);
-  SET_GetConvolutionFilter(disp, glGetConvolutionFilter);
-  SET_GetConvolutionParameterfv(disp, glGetConvolutionParameterfv);
-  SET_GetConvolutionParameteriv(disp, glGetConvolutionParameteriv);
-  SET_GetDoublev(disp, glGetDoublev);
-  SET_GetError(disp, glGetError);
-//SET_GetFenceivNV(disp, glGetFenceivNV);
-  SET_GetFinalCombinerInputParameterfvNV(disp, glGetFinalCombinerInputParameterfvNV);
-  SET_GetFinalCombinerInputParameterivNV(disp, glGetFinalCombinerInputParameterivNV);
-  SET_GetFloatv(disp, glGetFloatv);
-  SET_GetFramebufferAttachmentParameterivEXT(disp, glGetFramebufferAttachmentParameterivEXT);
-  SET_GetHandleARB(disp, glGetHandleARB);
-  SET_GetHistogram(disp, glGetHistogram);
-  SET_GetHistogramParameterfv(disp, glGetHistogramParameterfv);
-  SET_GetHistogramParameteriv(disp, glGetHistogramParameteriv);
-  SET_GetInfoLogARB(disp, glGetInfoLogARB);
-  SET_GetIntegerv(disp, glGetIntegerv);
-  SET_GetLightfv(disp, glGetLightfv);
-  SET_GetLightiv(disp, glGetLightiv);
-  SET_GetMapdv(disp, glGetMapdv);
-  SET_GetMapfv(disp, glGetMapfv);
-  SET_GetMapiv(disp, glGetMapiv);
-  SET_GetMaterialfv(disp, glGetMaterialfv);
-  SET_GetMaterialiv(disp, glGetMaterialiv);
-  SET_GetMinmax(disp, glGetMinmax);
-  SET_GetMinmaxParameterfv(disp, glGetMinmaxParameterfv);
-  SET_GetMinmaxParameteriv(disp, glGetMinmaxParameteriv);
-  SET_GetObjectParameterfvARB(disp, glGetObjectParameterfvARB);
-  SET_GetObjectParameterivARB(disp, glGetObjectParameterivARB);
-  SET_GetPixelMapfv(disp, glGetPixelMapfv);
-  SET_GetPixelMapuiv(disp, glGetPixelMapuiv);
-  SET_GetPixelMapusv(disp, glGetPixelMapusv);
-//SET_GetPixelTexGenParameterfvSGIS(disp, glGetPixelTexGenParameterfvSGIS);
-//SET_GetPixelTexGenParameterivSGIS(disp, glGetPixelTexGenParameterivSGIS);
-  SET_GetPointerv(disp, glGetPointerv);
-  SET_GetPolygonStipple(disp, glGetPolygonStipple);
-  SET_GetProgramEnvParameterdvARB(disp, glGetProgramEnvParameterdvARB);
-  SET_GetProgramEnvParameterfvARB(disp, glGetProgramEnvParameterfvARB);
-  SET_GetProgramLocalParameterdvARB(disp, glGetProgramLocalParameterdvARB);
-  SET_GetProgramLocalParameterfvARB(disp, glGetProgramLocalParameterfvARB);
-//SET_GetProgramNamedParameterdvNV(disp, glGetProgramNamedParameterdvNV);
-//SET_GetProgramNamedParameterfvNV(disp, glGetProgramNamedParameterfvNV);
-//SET_GetProgramParameterdvNV(disp, glGetProgramParameterdvNV);
-//SET_GetProgramParameterfvNV(disp, glGetProgramParameterfvNV);
-  SET_GetProgramStringARB(disp, glGetProgramStringARB);
-//SET_GetProgramStringNV(disp, glGetProgramStringNV);
-  SET_GetProgramivARB(disp, glGetProgramivARB);
-//SET_GetProgramivNV(disp, glGetProgramivNV);
-//SET_GetQueryObjecti64vEXT(disp, glGetQueryObjecti64vEXT);
-  SET_GetQueryObjectivARB(disp, glGetQueryObjectivARB);
-//SET_GetQueryObjectui64vEXT(disp, glGetQueryObjectui64vEXT);
-  SET_GetQueryObjectuivARB(disp, glGetQueryObjectuivARB);
-  SET_GetQueryivARB(disp, glGetQueryivARB);
-  SET_GetRenderbufferParameterivEXT(disp, glGetRenderbufferParameterivEXT);
-  SET_GetSeparableFilter(disp, glGetSeparableFilter);
-  SET_GetShaderSourceARB(disp, glGetShaderSourceARB);
-  SET_GetString(disp, glGetString);
-  SET_GetTexEnvfv(disp, glGetTexEnvfv);
-  SET_GetTexEnviv(disp, glGetTexEnviv);
-  SET_GetTexGendv(disp, glGetTexGendv);
-  SET_GetTexGenfv(disp, glGetTexGenfv);
-  SET_GetTexGeniv(disp, glGetTexGeniv);
-  SET_GetTexImage(disp, glGetTexImage);
-  SET_GetTexLevelParameterfv(disp, glGetTexLevelParameterfv);
-  SET_GetTexLevelParameteriv(disp, glGetTexLevelParameteriv);
-  SET_GetTexParameterfv(disp, glGetTexParameterfv);
-  SET_GetTexParameteriv(disp, glGetTexParameteriv);
-//SET_GetTrackMatrixivNV(disp, glGetTrackMatrixivNV);
-  SET_GetUniformLocationARB(disp, glGetUniformLocationARB);
-  SET_GetUniformfvARB(disp, glGetUniformfvARB);
-  SET_GetUniformivARB(disp, glGetUniformivARB);
-//SET_GetVertexAttribPointervNV(disp, glGetVertexAttribPointervNV);
-  SET_GetVertexAttribdvARB(disp, glGetVertexAttribdvARB);
-//SET_GetVertexAttribdvNV(disp, glGetVertexAttribdvNV);
-  SET_GetVertexAttribfvARB(disp, glGetVertexAttribfvARB);
-//SET_GetVertexAttribfvNV(disp, glGetVertexAttribfvNV);
-  SET_GetVertexAttribivARB(disp, glGetVertexAttribivARB);
-//SET_GetVertexAttribivNV(disp, glGetVertexAttribivNV);
-  SET_Hint(disp, glHint);
-  SET_Histogram(disp, glHistogram);
-  SET_IndexMask(disp, glIndexMask);
-  SET_IndexPointer(disp, glIndexPointer);
-//SET_IndexPointerEXT(disp, glIndexPointerEXT);
-  SET_Indexd(disp, glIndexd);
-  SET_Indexdv(disp, glIndexdv);
-  SET_Indexf(disp, glIndexf);
-  SET_Indexfv(disp, glIndexfv);
-  SET_Indexi(disp, glIndexi);
-  SET_Indexiv(disp, glIndexiv);
-  SET_Indexs(disp, glIndexs);
-  SET_Indexsv(disp, glIndexsv);
-  SET_Indexub(disp, glIndexub);
-  SET_Indexubv(disp, glIndexubv);
-  SET_InitNames(disp, glInitNames);
-  SET_InterleavedArrays(disp, glInterleavedArrays);
-  SET_IsBufferARB(disp, glIsBufferARB);
-  SET_IsEnabled(disp, glIsEnabled);
-  SET_IsFenceNV(disp, glIsFenceAPPLE);           // <-- APPLE -> NV
-  SET_IsFramebufferEXT(disp, glIsFramebufferEXT);
-  SET_IsList(disp, glIsList);
-//SET_IsProgramNV(disp, glIsProgramNV);
-  SET_IsQueryARB(disp, glIsQueryARB);
-  SET_IsRenderbufferEXT(disp, glIsRenderbufferEXT);
-  SET_IsTexture(disp, glIsTexture);
-  SET_LightModelf(disp, glLightModelf);
-  SET_LightModelfv(disp, glLightModelfv);
-  SET_LightModeli(disp, glLightModeli);
-  SET_LightModeliv(disp, glLightModeliv);
-  SET_Lightf(disp, glLightf);
-  SET_Lightfv(disp, glLightfv);
-  SET_Lighti(disp, glLighti);
-  SET_Lightiv(disp, glLightiv);
-  SET_LineStipple(disp, glLineStipple);
-  SET_LineWidth(disp, glLineWidth);
-  SET_LinkProgramARB(disp, glLinkProgramARB);
-  SET_ListBase(disp, glListBase);
-  SET_LoadIdentity(disp, glLoadIdentity);
-  SET_LoadMatrixd(disp, glLoadMatrixd);
-  SET_LoadMatrixf(disp, glLoadMatrixf);
-  SET_LoadName(disp, glLoadName);
-//SET_LoadProgramNV(disp, glLoadProgramNV);
-  SET_LoadTransposeMatrixdARB(disp, glLoadTransposeMatrixdARB);
-  SET_LoadTransposeMatrixfARB(disp, glLoadTransposeMatrixfARB);
-  SET_LockArraysEXT(disp, glLockArraysEXT);
-  SET_LogicOp(disp, glLogicOp);
-  SET_Map1d(disp, glMap1d);
-  SET_Map1f(disp, glMap1f);
-  SET_Map2d(disp, glMap2d);
-  SET_Map2f(disp, glMap2f);
-  SET_MapBufferARB(disp, glMapBufferARB);
-  SET_MapGrid1d(disp, glMapGrid1d);
-  SET_MapGrid1f(disp, glMapGrid1f);
-  SET_MapGrid2d(disp, glMapGrid2d);
-  SET_MapGrid2f(disp, glMapGrid2f);
-  SET_Materialf(disp, glMaterialf);
-  SET_Materialfv(disp, glMaterialfv);
-  SET_Materiali(disp, glMateriali);
-  SET_Materialiv(disp, glMaterialiv);
-  SET_MatrixMode(disp, glMatrixMode);
-  SET_Minmax(disp, glMinmax);
-  SET_MultMatrixd(disp, glMultMatrixd);
-  SET_MultMatrixf(disp, glMultMatrixf);
-  SET_MultTransposeMatrixdARB(disp, glMultTransposeMatrixdARB);
-  SET_MultTransposeMatrixfARB(disp, glMultTransposeMatrixfARB);
-  SET_MultiDrawArraysEXT(disp, glMultiDrawArraysEXT);
-  SET_MultiDrawElementsEXT(disp, glMultiDrawElementsEXT);
-//SET_MultiModeDrawArraysIBM(disp, glMultiModeDrawArraysIBM);
-//SET_MultiModeDrawElementsIBM(disp, glMultiModeDrawElementsIBM);
-  SET_MultiTexCoord1dARB(disp, glMultiTexCoord1dARB);
-  SET_MultiTexCoord1dvARB(disp, glMultiTexCoord1dvARB);
-  SET_MultiTexCoord1fARB(disp, glMultiTexCoord1fARB);
-  SET_MultiTexCoord1fvARB(disp, glMultiTexCoord1fvARB);
-  SET_MultiTexCoord1iARB(disp, glMultiTexCoord1iARB);
-  SET_MultiTexCoord1ivARB(disp, glMultiTexCoord1ivARB);
-  SET_MultiTexCoord1sARB(disp, glMultiTexCoord1sARB);
-  SET_MultiTexCoord1svARB(disp, glMultiTexCoord1svARB);
-  SET_MultiTexCoord2dARB(disp, glMultiTexCoord2dARB);
-  SET_MultiTexCoord2dvARB(disp, glMultiTexCoord2dvARB);
-  SET_MultiTexCoord2fARB(disp, glMultiTexCoord2fARB);
-  SET_MultiTexCoord2fvARB(disp, glMultiTexCoord2fvARB);
-  SET_MultiTexCoord2iARB(disp, glMultiTexCoord2iARB);
-  SET_MultiTexCoord2ivARB(disp, glMultiTexCoord2ivARB);
-  SET_MultiTexCoord2sARB(disp, glMultiTexCoord2sARB);
-  SET_MultiTexCoord2svARB(disp, glMultiTexCoord2svARB);
-  SET_MultiTexCoord3dARB(disp, glMultiTexCoord3dARB);
-  SET_MultiTexCoord3dvARB(disp, glMultiTexCoord3dvARB);
-  SET_MultiTexCoord3fARB(disp, glMultiTexCoord3fARB);
-  SET_MultiTexCoord3fvARB(disp, glMultiTexCoord3fvARB);
-  SET_MultiTexCoord3iARB(disp, glMultiTexCoord3iARB);
-  SET_MultiTexCoord3ivARB(disp, glMultiTexCoord3ivARB);
-  SET_MultiTexCoord3sARB(disp, glMultiTexCoord3sARB);
-  SET_MultiTexCoord3svARB(disp, glMultiTexCoord3svARB);
-  SET_MultiTexCoord4dARB(disp, glMultiTexCoord4dARB);
-  SET_MultiTexCoord4dvARB(disp, glMultiTexCoord4dvARB);
-  SET_MultiTexCoord4fARB(disp, glMultiTexCoord4fARB);
-  SET_MultiTexCoord4fvARB(disp, glMultiTexCoord4fvARB);
-  SET_MultiTexCoord4iARB(disp, glMultiTexCoord4iARB);
-  SET_MultiTexCoord4ivARB(disp, glMultiTexCoord4ivARB);
-  SET_MultiTexCoord4sARB(disp, glMultiTexCoord4sARB);
-  SET_MultiTexCoord4svARB(disp, glMultiTexCoord4svARB);
-  SET_NewList(disp, glNewList);
-  SET_Normal3b(disp, glNormal3b);
-  SET_Normal3bv(disp, glNormal3bv);
-  SET_Normal3d(disp, glNormal3d);
-  SET_Normal3dv(disp, glNormal3dv);
-  SET_Normal3f(disp, glNormal3f);
-  SET_Normal3fv(disp, glNormal3fv);
-  SET_Normal3i(disp, glNormal3i);
-  SET_Normal3iv(disp, glNormal3iv);
-  SET_Normal3s(disp, glNormal3s);
-  SET_Normal3sv(disp, glNormal3sv);
-  SET_NormalPointer(disp, glNormalPointer);
-//SET_NormalPointerEXT(disp, glNormalPointerEXT);
-  SET_Ortho(disp, glOrtho);
-//SET_PassTexCoordATI(disp, glPassTexCoordEXT);         // <-- EXT -> ATI
-  SET_PassThrough(disp, glPassThrough);
-  SET_PixelMapfv(disp, glPixelMapfv);
-  SET_PixelMapuiv(disp, glPixelMapuiv);
-  SET_PixelMapusv(disp, glPixelMapusv);
-  SET_PixelStoref(disp, glPixelStoref);
-  SET_PixelStorei(disp, glPixelStorei);
-//SET_PixelTexGenParameterfSGIS(disp, glPixelTexGenParameterfSGIS);
-//SET_PixelTexGenParameterfvSGIS(disp, glPixelTexGenParameterfvSGIS);
-//SET_PixelTexGenParameteriSGIS(disp, glPixelTexGenParameteriSGIS);
-//SET_PixelTexGenParameterivSGIS(disp, glPixelTexGenParameterivSGIS);
-//  SET_PixelTexGenSGIX(disp, glPixelTexGenSGIX);
-  SET_PixelTransferf(disp, glPixelTransferf);
-  SET_PixelTransferi(disp, glPixelTransferi);
-  SET_PixelZoom(disp, glPixelZoom);
-  SET_PointParameterfEXT(disp, glPointParameterfARB);      // <-- ARB -> EXT
-  SET_PointParameterfvEXT(disp, glPointParameterfvARB);    // <-- ARB -> EXT
-  SET_PointParameteriNV(disp, glPointParameteriNV);
-  SET_PointParameterivNV(disp, glPointParameterivNV);
-  SET_PointSize(disp, glPointSize);
-  SET_PolygonMode(disp, glPolygonMode);
-  SET_PolygonOffset(disp, glPolygonOffset);
-//SET_PolygonOffsetEXT(disp, glPolygonOffsetEXT);
-  SET_PolygonStipple(disp, glPolygonStipple);
-  SET_PopAttrib(disp, glPopAttrib);
-  SET_PopClientAttrib(disp, glPopClientAttrib);
-  SET_PopMatrix(disp, glPopMatrix);
-  SET_PopName(disp, glPopName);
-  SET_PrioritizeTextures(disp, glPrioritizeTextures);
-  SET_ProgramEnvParameter4dARB(disp, glProgramEnvParameter4dARB);
-  SET_ProgramEnvParameter4dvARB(disp, glProgramEnvParameter4dvARB);
-  SET_ProgramEnvParameter4fARB(disp, glProgramEnvParameter4fARB);
-  SET_ProgramEnvParameter4fvARB(disp, glProgramEnvParameter4fvARB);
-  SET_ProgramLocalParameter4dARB(disp, glProgramLocalParameter4dARB);
-  SET_ProgramLocalParameter4dvARB(disp, glProgramLocalParameter4dvARB);
-  SET_ProgramLocalParameter4fARB(disp, glProgramLocalParameter4fARB);
-  SET_ProgramLocalParameter4fvARB(disp, glProgramLocalParameter4fvARB);
-//SET_ProgramNamedParameter4dNV(disp, glProgramNamedParameter4dNV);
-//SET_ProgramNamedParameter4dvNV(disp, glProgramNamedParameter4dvNV);
-//SET_ProgramNamedParameter4fNV(disp, glProgramNamedParameter4fNV);
-//SET_ProgramNamedParameter4fvNV(disp, glProgramNamedParameter4fvNV);
-//SET_ProgramParameter4dNV(disp, glProgramParameter4dNV);
-//SET_ProgramParameter4dvNV(disp, glProgramParameter4dvNV);
-//SET_ProgramParameter4fNV(disp, glProgramParameter4fNV);
-//SET_ProgramParameter4fvNV(disp, glProgramParameter4fvNV);
-//SET_ProgramParameters4dvNV(disp, glProgramParameters4dvNV);
-//SET_ProgramParameters4fvNV(disp, glProgramParameters4fvNV);
-  SET_ProgramStringARB(disp, glProgramStringARB);
-  SET_PushAttrib(disp, glPushAttrib);
-  SET_PushClientAttrib(disp, glPushClientAttrib);
-  SET_PushMatrix(disp, glPushMatrix);
-  SET_PushName(disp, glPushName);
-  SET_RasterPos2d(disp, glRasterPos2d);
-  SET_RasterPos2dv(disp, glRasterPos2dv);
-  SET_RasterPos2f(disp, glRasterPos2f);
-  SET_RasterPos2fv(disp, glRasterPos2fv);
-  SET_RasterPos2i(disp, glRasterPos2i);
-  SET_RasterPos2iv(disp, glRasterPos2iv);
-  SET_RasterPos2s(disp, glRasterPos2s);
-  SET_RasterPos2sv(disp, glRasterPos2sv);
-  SET_RasterPos3d(disp, glRasterPos3d);
-  SET_RasterPos3dv(disp, glRasterPos3dv);
-  SET_RasterPos3f(disp, glRasterPos3f);
-  SET_RasterPos3fv(disp, glRasterPos3fv);
-  SET_RasterPos3i(disp, glRasterPos3i);
-  SET_RasterPos3iv(disp, glRasterPos3iv);
-  SET_RasterPos3s(disp, glRasterPos3s);
-  SET_RasterPos3sv(disp, glRasterPos3sv);
-  SET_RasterPos4d(disp, glRasterPos4d);
-  SET_RasterPos4dv(disp, glRasterPos4dv);
-  SET_RasterPos4f(disp, glRasterPos4f);
-  SET_RasterPos4fv(disp, glRasterPos4fv);
-  SET_RasterPos4i(disp, glRasterPos4i);
-  SET_RasterPos4iv(disp, glRasterPos4iv);
-  SET_RasterPos4s(disp, glRasterPos4s);
-  SET_RasterPos4sv(disp, glRasterPos4sv);
-  SET_ReadBuffer(disp, glReadBuffer);
-  SET_ReadPixels(disp, glReadPixels);
-  SET_Rectd(disp, glRectd);
-  SET_Rectdv(disp, glRectdv);
-  SET_Rectf(disp, glRectf);
-  SET_Rectfv(disp, glRectfv);
-  SET_Recti(disp, glRecti);
-  SET_Rectiv(disp, glRectiv);
-  SET_Rects(disp, glRects);
-  SET_Rectsv(disp, glRectsv);
-  SET_RenderMode(disp, glRenderMode);
-  SET_RenderbufferStorageEXT(disp, glRenderbufferStorageEXT);
-//SET_RequestResidentProgramsNV(disp, glRequestResidentProgramsNV);
-  SET_ResetHistogram(disp, glResetHistogram);
-  SET_ResetMinmax(disp, glResetMinmax);
-//SET_ResizeBuffersMESA(disp, glResizeBuffersMESA);
-  SET_Rotated(disp, glRotated);
-  SET_Rotatef(disp, glRotatef);
-  SET_SampleCoverageARB(disp, glSampleCoverageARB);
-//SET_SampleMapATI(disp, glSampleMapEXT);       // <-- EXT -> ATI
-//SET_SampleMaskSGIS(disp, glSampleMaskSGIS);
-//SET_SamplePatternSGIS(disp, glSamplePatternSGIS);
-  SET_Scaled(disp, glScaled);
-  SET_Scalef(disp, glScalef);
-  SET_Scissor(disp, glScissor);
-  SET_SecondaryColor3bEXT(disp, glSecondaryColor3bEXT);
-  SET_SecondaryColor3bvEXT(disp, glSecondaryColor3bvEXT);
-  SET_SecondaryColor3dEXT(disp, glSecondaryColor3dEXT);
-  SET_SecondaryColor3dvEXT(disp, glSecondaryColor3dvEXT);
-  SET_SecondaryColor3fEXT(disp, glSecondaryColor3fEXT);
-  SET_SecondaryColor3fvEXT(disp, glSecondaryColor3fvEXT);
-  SET_SecondaryColor3iEXT(disp, glSecondaryColor3iEXT);
-  SET_SecondaryColor3ivEXT(disp, glSecondaryColor3ivEXT);
-  SET_SecondaryColor3sEXT(disp, glSecondaryColor3sEXT);
-  SET_SecondaryColor3svEXT(disp, glSecondaryColor3svEXT);
-  SET_SecondaryColor3ubEXT(disp, glSecondaryColor3ubEXT);
-  SET_SecondaryColor3ubvEXT(disp, glSecondaryColor3ubvEXT);
-  SET_SecondaryColor3uiEXT(disp, glSecondaryColor3uiEXT);
-  SET_SecondaryColor3uivEXT(disp, glSecondaryColor3uivEXT);
-  SET_SecondaryColor3usEXT(disp, glSecondaryColor3usEXT);
-  SET_SecondaryColor3usvEXT(disp, glSecondaryColor3usvEXT);
-  SET_SecondaryColorPointerEXT(disp, glSecondaryColorPointerEXT);
-  SET_SelectBuffer(disp, glSelectBuffer);
-  SET_SeparableFilter2D(disp, glSeparableFilter2D);
-  SET_SetFenceNV(disp, glSetFenceAPPLE);  // <-- APPLE -> NV
-//SET_SetFragmentShaderConstantATI(disp, glSetFragmentShaderConstantEXT);   // <-- EXT -> ATI
-  SET_ShadeModel(disp, glShadeModel);
-  SET_ShaderSourceARB(disp, glShaderSourceARB);
-  SET_StencilFunc(disp, glStencilFunc);
-  SET_StencilFuncSeparate(disp, glStencilFuncSeparate);
-  SET_StencilMask(disp, glStencilMask);
-  SET_StencilMaskSeparate(disp, glStencilMaskSeparate);
-  SET_StencilOp(disp, glStencilOp);
-  SET_StencilOpSeparate(disp, glStencilOpSeparate);
-  SET_TestFenceNV(disp, glTestFenceAPPLE); // <-- APPLE -> NV
-  SET_TexCoord1d(disp, glTexCoord1d);
-  SET_TexCoord1dv(disp, glTexCoord1dv);
-  SET_TexCoord1f(disp, glTexCoord1f);
-  SET_TexCoord1fv(disp, glTexCoord1fv);
-  SET_TexCoord1i(disp, glTexCoord1i);
-  SET_TexCoord1iv(disp, glTexCoord1iv);
-  SET_TexCoord1s(disp, glTexCoord1s);
-  SET_TexCoord1sv(disp, glTexCoord1sv);
-  SET_TexCoord2d(disp, glTexCoord2d);
-  SET_TexCoord2dv(disp, glTexCoord2dv);
-  SET_TexCoord2f(disp, glTexCoord2f);
-  SET_TexCoord2fv(disp, glTexCoord2fv);
-  SET_TexCoord2i(disp, glTexCoord2i);
-  SET_TexCoord2iv(disp, glTexCoord2iv);
-  SET_TexCoord2s(disp, glTexCoord2s);
-  SET_TexCoord2sv(disp, glTexCoord2sv);
-  SET_TexCoord3d(disp, glTexCoord3d);
-  SET_TexCoord3dv(disp, glTexCoord3dv);
-  SET_TexCoord3f(disp, glTexCoord3f);
-  SET_TexCoord3fv(disp, glTexCoord3fv);
-  SET_TexCoord3i(disp, glTexCoord3i);
-  SET_TexCoord3iv(disp, glTexCoord3iv);
-  SET_TexCoord3s(disp, glTexCoord3s);
-  SET_TexCoord3sv(disp, glTexCoord3sv);
-  SET_TexCoord4d(disp, glTexCoord4d);
-  SET_TexCoord4dv(disp, glTexCoord4dv);
-  SET_TexCoord4f(disp, glTexCoord4f);
-  SET_TexCoord4fv(disp, glTexCoord4fv);
-  SET_TexCoord4i(disp, glTexCoord4i);
-  SET_TexCoord4iv(disp, glTexCoord4iv);
-  SET_TexCoord4s(disp, glTexCoord4s);
-  SET_TexCoord4sv(disp, glTexCoord4sv);
-  SET_TexCoordPointer(disp, glTexCoordPointer);
-//SET_TexCoordPointerEXT(disp, glTexCoordPointerEXT);
-  SET_TexEnvf(disp, glTexEnvf);
-  SET_TexEnvfv(disp, glTexEnvfv);
-  SET_TexEnvi(disp, glTexEnvi);
-  SET_TexEnviv(disp, glTexEnviv);
-  SET_TexGend(disp, glTexGend);
-  SET_TexGendv(disp, glTexGendv);
-  SET_TexGenf(disp, glTexGenf);
-  SET_TexGenfv(disp, glTexGenfv);
-  SET_TexGeni(disp, glTexGeni);
-  SET_TexGeniv(disp, glTexGeniv);
-  SET_TexImage1D(disp, glTexImage1D);
-  SET_TexImage2D(disp, glTexImage2D);
-  SET_TexImage3D(disp, glTexImage3D);
-  SET_TexParameterf(disp, glTexParameterf);
-  SET_TexParameterfv(disp, glTexParameterfv);
-  SET_TexParameteri(disp, glTexParameteri);
-  SET_TexParameteriv(disp, glTexParameteriv);
-  SET_TexSubImage1D(disp, glTexSubImage1D);
-  SET_TexSubImage2D(disp, glTexSubImage2D);
-  SET_TexSubImage3D(disp, glTexSubImage3D);
-//SET_TrackMatrixNV(disp, glTrackMatrixNV);
-  SET_Translated(disp, glTranslated);
-  SET_Translatef(disp, glTranslatef);
-  SET_Uniform1fARB(disp, glUniform1fARB);
-  SET_Uniform1fvARB(disp, glUniform1fvARB);
-  SET_Uniform1iARB(disp, glUniform1iARB);
-  SET_Uniform1ivARB(disp, glUniform1ivARB);
-  SET_Uniform2fARB(disp, glUniform2fARB);
-  SET_Uniform2fvARB(disp, glUniform2fvARB);
-  SET_Uniform2iARB(disp, glUniform2iARB);
-  SET_Uniform2ivARB(disp, glUniform2ivARB);
-  SET_Uniform3fARB(disp, glUniform3fARB);
-  SET_Uniform3fvARB(disp, glUniform3fvARB);
-  SET_Uniform3iARB(disp, glUniform3iARB);
-  SET_Uniform3ivARB(disp, glUniform3ivARB);
-  SET_Uniform4fARB(disp, glUniform4fARB);
-  SET_Uniform4fvARB(disp, glUniform4fvARB);
-  SET_Uniform4iARB(disp, glUniform4iARB);
-  SET_Uniform4ivARB(disp, glUniform4ivARB);
-  SET_UniformMatrix2fvARB(disp, glUniformMatrix2fvARB);
-  SET_UniformMatrix3fvARB(disp, glUniformMatrix3fvARB);
-  SET_UniformMatrix4fvARB(disp, glUniformMatrix4fvARB);
-  SET_UnlockArraysEXT(disp, glUnlockArraysEXT);
-  SET_UnmapBufferARB(disp, glUnmapBufferARB);
-  SET_UseProgramObjectARB(disp, glUseProgramObjectARB);
-  SET_ValidateProgramARB(disp, glValidateProgramARB);
-  SET_Vertex2d(disp, glVertex2d);
-  SET_Vertex2dv(disp, glVertex2dv);
-  SET_Vertex2f(disp, glVertex2f);
-  SET_Vertex2fv(disp, glVertex2fv);
-  SET_Vertex2i(disp, glVertex2i);
-  SET_Vertex2iv(disp, glVertex2iv);
-  SET_Vertex2s(disp, glVertex2s);
-  SET_Vertex2sv(disp, glVertex2sv);
-  SET_Vertex3d(disp, glVertex3d);
-  SET_Vertex3dv(disp, glVertex3dv);
-  SET_Vertex3f(disp, glVertex3f);
-  SET_Vertex3fv(disp, glVertex3fv);
-  SET_Vertex3i(disp, glVertex3i);
-  SET_Vertex3iv(disp, glVertex3iv);
-  SET_Vertex3s(disp, glVertex3s);
-  SET_Vertex3sv(disp, glVertex3sv);
-  SET_Vertex4d(disp, glVertex4d);
-  SET_Vertex4dv(disp, glVertex4dv);
-  SET_Vertex4f(disp, glVertex4f);
-  SET_Vertex4fv(disp, glVertex4fv);
-  SET_Vertex4i(disp, glVertex4i);
-  SET_Vertex4iv(disp, glVertex4iv);
-  SET_Vertex4s(disp, glVertex4s);
-  SET_Vertex4sv(disp, glVertex4sv);
-//SET_VertexArrayRangeNV(disp, glVertexArrayRangeNV);
-  SET_VertexAttrib1dARB(disp, glVertexAttrib1dARB);
-  SET_VertexAttrib1dvARB(disp, glVertexAttrib1dvARB);
-  SET_VertexAttrib1fARB(disp, glVertexAttrib1fARB);
-  SET_VertexAttrib1fvARB(disp, glVertexAttrib1fvARB);
-  SET_VertexAttrib1sARB(disp, glVertexAttrib1sARB);
-  SET_VertexAttrib1svARB(disp, glVertexAttrib1svARB);
-  SET_VertexAttrib2dARB(disp, glVertexAttrib2dARB);
-  SET_VertexAttrib2dvARB(disp, glVertexAttrib2dvARB);
-  SET_VertexAttrib2fARB(disp, glVertexAttrib2fARB);
-  SET_VertexAttrib2fvARB(disp, glVertexAttrib2fvARB);
-  SET_VertexAttrib2sARB(disp, glVertexAttrib2sARB);
-  SET_VertexAttrib2svARB(disp, glVertexAttrib2svARB);
-  SET_VertexAttrib3dARB(disp, glVertexAttrib3dARB);
-  SET_VertexAttrib3dvARB(disp, glVertexAttrib3dvARB);
-  SET_VertexAttrib3fARB(disp, glVertexAttrib3fARB);
-  SET_VertexAttrib3fvARB(disp, glVertexAttrib3fvARB);
-  SET_VertexAttrib3sARB(disp, glVertexAttrib3sARB);
-  SET_VertexAttrib3svARB(disp, glVertexAttrib3svARB);
-  SET_VertexAttrib4NbvARB(disp, glVertexAttrib4NbvARB);
-  SET_VertexAttrib4NivARB(disp, glVertexAttrib4NivARB);
-  SET_VertexAttrib4NsvARB(disp, glVertexAttrib4NsvARB);
-  SET_VertexAttrib4NubARB(disp, glVertexAttrib4NubARB);
-  SET_VertexAttrib4NubvARB(disp, glVertexAttrib4NubvARB);
-  SET_VertexAttrib4NuivARB(disp, glVertexAttrib4NuivARB);
-  SET_VertexAttrib4NusvARB(disp, glVertexAttrib4NusvARB);
-  SET_VertexAttrib4bvARB(disp, glVertexAttrib4bvARB);
-  SET_VertexAttrib4dARB(disp, glVertexAttrib4dARB);
-  SET_VertexAttrib4dvARB(disp, glVertexAttrib4dvARB);
-  SET_VertexAttrib4fARB(disp, glVertexAttrib4fARB);
-  SET_VertexAttrib4fvARB(disp, glVertexAttrib4fvARB);
-  SET_VertexAttrib4ivARB(disp, glVertexAttrib4ivARB);
-  SET_VertexAttrib4sARB(disp, glVertexAttrib4sARB);
-  SET_VertexAttrib4svARB(disp, glVertexAttrib4svARB);
-  SET_VertexAttrib4ubvARB(disp, glVertexAttrib4ubvARB);
-  SET_VertexAttrib4uivARB(disp, glVertexAttrib4uivARB);
-  SET_VertexAttrib4usvARB(disp, glVertexAttrib4usvARB);
-  SET_VertexAttribPointerARB(disp, glVertexAttribPointerARB);
-  SET_VertexPointer(disp, glVertexPointer);
-//  SET_VertexPointerEXT(disp, glVertexPointerEXT);
-  SET_Viewport(disp, glViewport);
-  SET_WindowPos2dMESA(disp, glWindowPos2dARB);
-  SET_WindowPos2dvMESA(disp, glWindowPos2dvARB);
-  SET_WindowPos2fMESA(disp, glWindowPos2fARB);
-  SET_WindowPos2fvMESA(disp, glWindowPos2fvARB);
-  SET_WindowPos2iMESA(disp, glWindowPos2iARB);
-  SET_WindowPos2ivMESA(disp, glWindowPos2ivARB);
-  SET_WindowPos2sMESA(disp, glWindowPos2sARB);
-  SET_WindowPos2svMESA(disp, glWindowPos2svARB);
-  SET_WindowPos3dMESA(disp, glWindowPos3dARB);
-  SET_WindowPos3dvMESA(disp, glWindowPos3dvARB);
-  SET_WindowPos3fMESA(disp, glWindowPos3fARB);
-  SET_WindowPos3fvMESA(disp, glWindowPos3fvARB);
-  SET_WindowPos3iMESA(disp, glWindowPos3iARB);
-  SET_WindowPos3ivMESA(disp, glWindowPos3ivARB);
-  SET_WindowPos3sMESA(disp, glWindowPos3sARB);
-  SET_WindowPos3svMESA(disp, glWindowPos3svARB);
-//SET_WindowPos4dMESA(disp, glWindowPos4dMESA);
-//SET_WindowPos4dvMESA(disp, glWindowPos4dvMESA);
-//SET_WindowPos4fMESA(disp, glWindowPos4fMESA);
-//SET_WindowPos4fvMESA(disp, glWindowPos4fvMESA);
-//SET_WindowPos4iMESA(disp, glWindowPos4iMESA);
-//SET_WindowPos4ivMESA(disp, glWindowPos4ivMESA);
-//SET_WindowPos4sMESA(disp, glWindowPos4sMESA);
-//SET_WindowPos4svMESA(disp, glWindowPos4svMESA);
-}
diff --git a/configure.ac b/configure.ac
index 51ab4c6..b2a07a6 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1724,22 +1724,14 @@ if test "x$XQUARTZ" = xyes; then
 	AC_DEFINE(XQUARTZ,1,[Have Quartz])
 	AC_DEFINE(ROOTLESS,1,[Build Rootless code])
 
-#glxAGL / glxCGL don't work yet
-#	AC_CACHE_CHECK([for AGL framework],xorg_cv_AGL_framework,[
-#		save_LDFLAGS=$LDFLAGS
-#		LDFLAGS="$LDFLAGS -framework AGL"
-#		AC_LINK_IFELSE(
-#			[char aglEnable(); int main() { aglEnable(); return 0;}],
-#			[xorg_cv_AGL_framework=yes],
-#			[xorg_cv_AGL_framework=no])
-#		LDFLAGS=$save_LDFLAGS
-#	])
-	xorg_cv_AGL_framework=no
-	DARWIN_GLX_LIBS='$(top_builddir)/GL/apple/indirect.o $(top_builddir)/GL/glx/libglx.la'
-	DARWIN_LIBS="$MI_LIB $OS_LIB $DIX_LIB $FB_LIB $FIXES_LIB $XEXT_LIB $CONFIG_LIB $DBE_LIB $XTRAP_LIB $RECORD_LIB $RENDER_LIB $RANDR_LIB $DAMAGE_LIB $MIEXT_DAMAGE_LIB $MIEXT_SHADOW_LIB $XI_LIB $XKB_LIB $XKB_STUB_LIB $COMPOSITE_LIB $XPSTUBS_LIB $DARWIN_GLX_LIBS"
+	DARWIN_GLX_LIBS='$(top_builddir)/hw/xquartz/GL/libCGLCore.la $(top_builddir)/GL/glx/libglx.la'
+	DARWIN_LIBS="$MI_LIB $OS_LIB $DIX_LIB $FB_LIB $FIXES_LIB $XEXT_LIB $CONFIG_LIB $DBE_LIB $XTRAP_LIB $RECORD_LIB $RENDER_LIB $RANDR_LIB $DAMAGE_LIB $MIEXT_DAMAGE_LIB $MIEXT_SHADOW_LIB $XI_LIB $XKB_LIB $XKB_STUB_LIB $XPSTUBS_LIB $DARWIN_GLX_LIBS"
 	AC_SUBST([DARWIN_LIBS])
+
 	AC_CHECK_LIB([Xplugin],[xp_init],[:])
+
 	CFLAGS="${CFLAGS} -DROOTLESS_WORKAROUND -DNO_ALLOCA"
+
 	if test "x$XF86MISC" = xyes || test "x$XF86MISC" = xauto; then
 		AC_MSG_NOTICE([Disabling XF86Misc extension])
 		XF86MISC=no
@@ -2087,7 +2079,6 @@ XORG_MANPAGE_SECTIONS
 AC_OUTPUT([
 Makefile
 GL/Makefile
-GL/apple/Makefile
 GL/glx/Makefile
 include/Makefile
 afb/Makefile
@@ -2181,6 +2172,7 @@ hw/xgl/glxext/module/Makefile
 hw/xnest/Makefile
 hw/xwin/Makefile
 hw/xquartz/Makefile
+hw/xquartz/GL/Makefile
 hw/xquartz/bundle/Makefile
 hw/xquartz/xpr/Makefile
 hw/kdrive/Makefile
diff --git a/hw/xquartz/GL/Makefile.am b/hw/xquartz/GL/Makefile.am
new file mode 100644
index 0000000..41d4566
--- /dev/null
+++ b/hw/xquartz/GL/Makefile.am
@@ -0,0 +1,13 @@
+noinst_LTLIBRARIES = libCGLCore.la
+AM_CFLAGS = $(XSERVER_CFLAGS) $(DIX_CFLAGS)
+AM_CPPFLAGS = \
+	-I$(top_srcdir) \
+	-I$(top_srcdir)/GL/glx \
+	-I$(top_srcdir)/GL/include \
+	-I$(top_srcdir)/GL/mesa/glapi \
+	-I$(top_srcdir)/hw/xquartz \
+	-I$(top_srcdir)/hw/xquartz/xpr \
+	-I$(top_srcdir)/miext/damage
+
+libCGLCore_la_SOURCES = \
+	indirect.c
diff --git a/hw/xquartz/GL/indirect.c b/hw/xquartz/GL/indirect.c
new file mode 100644
index 0000000..a0884d4
--- /dev/null
+++ b/hw/xquartz/GL/indirect.c
@@ -0,0 +1,1940 @@
+/*
+ * GLX implementation that uses Apple's OpenGL.framework
+ * (Indirect rendering path)
+ *
+ * Copyright (c) 2007 Apple Inc.
+ * Copyright (c) 2004 Torrey T. Lyons. All Rights Reserved.
+ * Copyright (c) 2002 Greg Parker. All Rights Reserved.
+ *
+ * Portions of this file are copied from Mesa's xf86glx.c,
+ * which contains the following copyright:
+ *
+ * Copyright 1998-1999 Precision Insight, Inc., Cedar Park, Texas.
+ * All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, 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.
+ */
+
+#ifdef HAVE_DIX_CONFIG_H
+#include <dix-config.h>
+#endif
+
+#include "dri.h"
+
+#define GL_EXT_histogram 1
+#define GL_EXT_polygon_offset 1
+#define GL_SGIS_pixel_texture 1
+#define GL_SGIX_pixel_texture 1
+#define GL_EXT_multisample 1
+#define GL_SGIS_multisample 1
+#define GL_EXT_vertex_array 1
+#define GL_ARB_point_parameters 1
+#define GL_NV_vertex_array_range 1
+#define GL_MESA_resize_buffers 1
+#define GL_ARB_window_pos 1
+#define GL_EXT_cull_vertex 1
+#define GL_NV_vertex_program 1
+#define GL_APPLE_fence 1
+#define GL_IBM_multimode_draw_arrays 1
+#define GL_EXT_fragment_shader 1
+
+#include <OpenGL/OpenGL.h>
+#include <OpenGL/CGLContext.h>
+
+// X11 and X11's glx
+#include <GL/gl.h>
+#include <GL/glxproto.h>
+#include <windowstr.h>
+#include <resource.h>
+#include <GL/glxint.h>
+#include <GL/glxtokens.h>
+#include <scrnintstr.h>
+#include <glxserver.h>
+#include <glxscreens.h>
+#include <glxdrawable.h>
+#include <glxcontext.h>
+#include <glxext.h>
+#include <glxutil.h>
+#include <glxscreens.h>
+#include <GL/internal/glcore.h>
+#include "x-hash.h"
+#include "x-list.h"
+
+#include <dispatch.h>
+#define GLAPIENTRYP *
+typedef unsigned long long GLuint64EXT;
+typedef long long GLint64EXT;
+#include <Xplugin.h>
+#include "glcontextmodes.h"
+#include <glapi.h>
+#include <glapitable.h>
+
+// ggs: needed to call back to glx with visual configs
+extern void GlxSetVisualConfigs(int nconfigs, __GLXvisualConfig *configs, void **configprivs);
+__GLXprovider * GlxGetMesaProvider (void);
+
+// Write debugging output, or not
+#ifdef GLAQUA_DEBUG
+#define GLAQUA_DEBUG_MSG ErrorF
+#else
+#define GLAQUA_DEBUG_MSG(a, ...)
+#endif
+
+static void setup_dispatch_table(void);
+GLuint __glFloorLog2(GLuint val);
+void warn_func(void * p1, char *format, ...);
+
+// some prototypes
+static __GLXscreen * __glXAquaScreenProbe(ScreenPtr pScreen);
+static __GLXdrawable * __glXAquaScreenCreateDrawable(__GLXscreen *screen, DrawablePtr pDraw, XID drawId, __GLXconfig *modes);
+
+static Bool glAquaInitVisuals(VisualPtr *visualp, DepthPtr *depthp,
+                              int *nvisualp, int *ndepthp,
+                              int *rootDepthp, VisualID *defaultVisp,
+                              unsigned long sizes, int bitsPerRGB);
+static void glAquaSetVisualConfigs(int nconfigs, __GLXvisualConfig *configs,
+                                   void **privates);
+
+static void glAquaResetExtension(void);
+static void __glXAquaContextDestroy(__GLXcontext *baseContext);
+static int __glXAquaContextMakeCurrent(__GLXcontext *baseContext);
+static int __glXAquaContextLoseCurrent(__GLXcontext *baseContext);
+static int __glXAquaContextForceCurrent(__GLXcontext *baseContext);
+static int __glXAquaContextCopy(__GLXcontext *baseDst, __GLXcontext *baseSrc, unsigned long mask);
+
+static CGLPixelFormatObj makeFormat(__GLXconfig *mode);
+
+__GLXprovider __glXMesaProvider = {
+  __glXAquaScreenProbe,
+  "Core OpenGL",
+    NULL
+};
+
+__GLXprovider *
+GlxGetMesaProvider (void)
+{
+  GLAQUA_DEBUG_MSG("GlxGetMesaProvider\n");
+  return &__glXMesaProvider;
+}
+
+typedef struct __GLXAquaScreen   __GLXAquaScreen;
+typedef struct __GLXAquaContext  __GLXAquaContext;
+typedef struct __GLXAquaDrawable __GLXAquaDrawable;
+
+struct __GLXAquaScreen {
+  __GLXscreen   base;
+  int           index;
+    int num_vis;
+    __GLXconfig *modes;
+};
+
+static __GLXAquaScreen glAquaScreens[MAXSCREENS];
+
+struct __GLXAquaContext {
+  __GLXcontext base;
+  CGLContextObj ctx;
+  CGLPixelFormatObj pixelFormat;
+  xp_surface_id sid;
+  unsigned isAttached :1;
+};
+
+struct __GLXAquaDrawable {
+  __GLXdrawable base;
+    DrawablePtr pDraw;
+    xp_surface_id sid;
+};
+
+static __GLXcontext *
+__glXAquaScreenCreateContext(__GLXscreen *screen,
+			     __GLXconfig *config,
+			     __GLXcontext *baseShareContext)
+{
+  __GLXAquaContext *context;
+  __GLXAquaContext *shareContext = (__GLXAquaContext *) baseShareContext;
+  CGLError gl_err;
+  
+  GLAQUA_DEBUG_MSG("glXAquaScreenCreateContext\n");
+
+  context = malloc (sizeof (__GLXAquaContext));
+  if (context == NULL) return NULL;
+
+  memset(context, 0, sizeof *context);
+
+  context->base.pGlxScreen = screen;
+  context->base.config      = config;
+
+  context->base.destroy        = __glXAquaContextDestroy;
+  context->base.makeCurrent    = __glXAquaContextMakeCurrent;
+  context->base.loseCurrent    = __glXAquaContextLoseCurrent;
+  context->base.copy           = __glXAquaContextCopy;
+  context->base.forceCurrent   = __glXAquaContextForceCurrent;
+  //  context->base.createDrawable = __glXAquaContextCreateDrawable;
+
+  context->pixelFormat = makeFormat(config);
+  if (!context->pixelFormat) {
+        free(context);
+        return NULL;
+  }
+
+  context->ctx = NULL;
+  gl_err = CGLCreateContext(context->pixelFormat,
+                            shareContext ? shareContext->ctx : NULL,
+                            &context->ctx);
+
+  if (gl_err != 0) {
+      ErrorF("CGLCreateContext error: %s\n", CGLErrorString(gl_err));
+      CGLDestroyPixelFormat(context->pixelFormat);
+      free(context);
+      return NULL;
+    }
+	setup_dispatch_table();
+    GLAQUA_DEBUG_MSG("glAquaCreateContext done\n");
+  return &context->base;
+}
+
+static __GLXextensionInfo __glDDXExtensionInfo = {
+    GL_CORE_APPLE,
+    glAquaResetExtension,
+    glAquaInitVisuals,
+    glAquaSetVisualConfigs
+};
+
+void *__glXglDDXExtensionInfo(void) {
+  GLAQUA_DEBUG_MSG("glXAglDDXExtensionInfo\n");
+    return &__glDDXExtensionInfo;
+}
+
+/* maps from surface id -> list of __GLcontext */
+static x_hash_table *surface_hash;
+
+static void __glXAquaContextDestroy(__GLXcontext *baseContext) {
+    x_list *lst;
+
+    __GLXAquaContext *context = (__GLXAquaContext *) baseContext;
+
+    GLAQUA_DEBUG_MSG("glAquaContextDestroy (ctx 0x%x)\n",
+                     (unsigned int) baseContext);
+    if (context != NULL) {
+      if (context->sid != 0 && surface_hash != NULL) {
+		lst = x_hash_table_lookup(surface_hash, (void *) context->sid, NULL);
+		lst = x_list_remove(lst, context);
+		x_hash_table_insert(surface_hash, (void *) context->sid, lst);
+      }
+
+      if (context->ctx != NULL) CGLDestroyContext(context->ctx);
+
+      if (context->pixelFormat != NULL)	CGLDestroyPixelFormat(context->pixelFormat);
+      
+      free(context);
+    }
+}
+
+static int __glXAquaContextLoseCurrent(__GLXcontext *baseContext) {
+    CGLError gl_err;
+
+    GLAQUA_DEBUG_MSG("glAquaLoseCurrent (ctx 0x%p)\n", baseContext);
+
+    gl_err = CGLSetCurrentContext(NULL);
+    if (gl_err != 0)
+      ErrorF("CGLSetCurrentContext error: %s\n", CGLErrorString(gl_err));
+
+    __glXLastContext = NULL; // Mesa does this; why?
+
+    return GL_TRUE;
+}
+
+/* Called when a surface is destroyed as a side effect of destroying
+   the window it's attached to. */
+static void surface_notify(void *_arg, void *data) {
+    DRISurfaceNotifyArg *arg = (DRISurfaceNotifyArg *)_arg;
+    __GLXAquaDrawable *draw = (__GLXAquaDrawable *)data;
+    __GLXAquaContext *context;
+    x_list *lst;
+	if(_arg == NULL || data == NULL) {
+		ErrorF("surface_notify called with bad params");
+		return;
+	}
+	
+    GLAQUA_DEBUG_MSG("surface_notify(%p, %p)\n", _arg, data);
+    switch (arg->kind) {
+    case AppleDRISurfaceNotifyDestroyed:
+        if (surface_hash != NULL)
+            x_hash_table_remove(surface_hash, (void *) arg->id);
+	        draw->base.pDraw = NULL;
+			draw->sid = 0;
+        break;
+
+    case AppleDRISurfaceNotifyChanged:
+        if (surface_hash != NULL) {
+            lst = x_hash_table_lookup(surface_hash, (void *) arg->id, NULL);
+            for (; lst != NULL; lst = lst->next)
+            {
+                context = lst->data;
+                xp_update_gl_context(context->ctx);
+            }
+        }
+        break;
+	default:
+		ErrorF("surface_notify: unknown kind %d\n", arg->kind);
+		break;
+    }
+}
+
+static void attach(__GLXAquaContext *context, __GLXAquaDrawable *draw) {
+    DrawablePtr pDraw;
+	GLAQUA_DEBUG_MSG("attach(%p, %p)\n", context, draw);
+    pDraw = draw->base.pDraw;
+
+    if (draw->sid == 0) {
+//        if (!quartzProcs->CreateSurface(pDraw->pScreen, pDraw->id, pDraw,
+        if (!DRICreateSurface(pDraw->pScreen, pDraw->id, pDraw,
+                                        0, &draw->sid, NULL,
+                                        surface_notify, draw))
+            return;
+        draw->pDraw = pDraw;
+	} 
+
+    if (!context->isAttached || context->sid != draw->sid) {
+        x_list *lst;
+
+        if (xp_attach_gl_context(context->ctx, draw->sid) != Success) {
+//            quartzProcs->DestroySurface(pDraw->pScreen, pDraw->id, pDraw,
+            DRIDestroySurface(pDraw->pScreen, pDraw->id, pDraw,
+								surface_notify, draw);
+            if (surface_hash != NULL)
+                x_hash_table_remove(surface_hash, (void *) draw->sid);
+
+            draw->sid = 0;
+            return;
+        }
+
+        context->isAttached = TRUE;
+        context->sid = draw->sid;
+
+        if (surface_hash == NULL)
+            surface_hash = x_hash_table_new(NULL, NULL, NULL, NULL);
+
+        lst = x_hash_table_lookup(surface_hash, (void *) context->sid, NULL);
+        if (x_list_find(lst, context) == NULL) {
+            lst = x_list_prepend(lst, context);
+            x_hash_table_insert(surface_hash, (void *) context->sid, lst);
+        }
+
+        GLAQUA_DEBUG_MSG("attached 0x%x to 0x%x\n", (unsigned int) pDraw->id,
+                         (unsigned int) draw->sid);
+    } 
+}
+
+#if 0     // unused
+static void unattach(__GLXAquaContext *context) {
+	x_list *lst;
+	GLAQUA_DEBUG_MSG("unattach\n");
+	if (context == NULL) {
+		ErrorF("Tried to unattach a null context\n");
+		return;
+	}
+    if (context->isAttached) {
+        GLAQUA_DEBUG_MSG("unattaching\n");
+
+        if (surface_hash != NULL) {
+            lst = x_hash_table_lookup(surface_hash, (void *) context->sid, NULL);
+            lst = x_list_remove(lst, context);
+            x_hash_table_insert(surface_hash, (void *) context->sid, lst);
+        }
+
+        CGLClearDrawable(context->ctx);
+        context->isAttached = FALSE;
+        context->sid = 0;
+    }
+}
+#endif
+
+static int __glXAquaContextMakeCurrent(__GLXcontext *baseContext) {
+    CGLError gl_err;
+    __GLXAquaContext *context = (__GLXAquaContext *) baseContext;
+	__GLXAquaDrawable *drawPriv = (__GLXAquaDrawable *) context->base.drawPriv;
+
+    GLAQUA_DEBUG_MSG("glAquaMakeCurrent (ctx 0x%p)\n", baseContext);
+    
+    attach(context, drawPriv);
+
+    gl_err = CGLSetCurrentContext(context->ctx);
+    if (gl_err != 0)
+        ErrorF("CGLSetCurrentContext error: %s\n", CGLErrorString(gl_err));
+    
+    return gl_err == 0;
+}
+
+static int __glXAquaContextCopy(__GLXcontext *baseDst, __GLXcontext *baseSrc, unsigned long mask)
+{
+    CGLError gl_err;
+
+    __GLXAquaContext *dst = (__GLXAquaContext *) baseDst;
+    __GLXAquaContext *src = (__GLXAquaContext *) baseSrc;
+
+    GLAQUA_DEBUG_MSG("GLXAquaContextCopy\n");
+
+    gl_err = CGLCopyContext(src->ctx, dst->ctx, mask);
+    if (gl_err != 0)
+        ErrorF("CGLCopyContext error: %s\n", CGLErrorString(gl_err));
+
+    return gl_err == 0;
+}
+
+static int __glXAquaContextForceCurrent(__GLXcontext *baseContext)
+{
+    CGLError gl_err;
+    __GLXAquaContext *context = (__GLXAquaContext *) baseContext;
+    GLAQUA_DEBUG_MSG("glAquaForceCurrent (ctx %p)\n", context->ctx);
+
+    gl_err = CGLSetCurrentContext(context->ctx);
+    if (gl_err != 0)
+        ErrorF("CGLSetCurrentContext error: %s\n", CGLErrorString(gl_err));
+
+    return gl_err == 0;
+}
+
+/* Drawing surface notification callbacks */
+
+static GLboolean __glXAquaDrawableResize(__GLXdrawable *base)  {
+    GLAQUA_DEBUG_MSG("unimplemented glAquaDrawableResize\n");
+    return GL_TRUE;
+}
+
+static GLboolean __glXAquaDrawableSwapBuffers(__GLXdrawable *base) {
+    CGLError gl_err;
+	__GLXAquaContext * drawableCtx;
+//    GLAQUA_DEBUG_MSG("glAquaDrawableSwapBuffers(%p)\n",base);
+	
+	if(!base) {
+		ErrorF("glXAquaDrawbleSwapBuffers passed NULL\n");
+	    return GL_FALSE;
+	}
+
+    drawableCtx = (__GLXAquaContext *)base->drawGlxc;
+
+    if (drawableCtx != NULL && drawableCtx->ctx != NULL) {
+        gl_err = CGLFlushDrawable(drawableCtx->ctx);
+        if (gl_err != 0)
+            ErrorF("CGLFlushDrawable error: %s\n", CGLErrorString(gl_err));
+    }
+    return GL_TRUE;
+}
+
+static CGLPixelFormatObj makeFormat(__GLXconfig *config) {
+    int i;
+    CGLPixelFormatAttribute attr[64]; // currently uses max of 30
+    CGLPixelFormatObj result;
+    GLint n_formats;
+    CGLError gl_err;
+    
+    GLAQUA_DEBUG_MSG("makeFormat\n");
+
+    if (!config->rgbMode)
+        return NULL;
+
+    i = 0;
+
+    // attr [i++] = kCGLPFAAcelerated; // require hwaccel - BAD for multiscreen
+    // attr [i++] = kCGLPFANoRecovery; // disable fallback renderers - BAD
+
+    if (config->stereoMode) {
+        attr[i++] = kCGLPFAStereo;
+    }
+
+    if (config->doubleBufferMode) {
+        attr[i++] = kCGLPFADoubleBuffer;
+    }
+
+    if (config->colorIndexMode) {
+        /* ignored */
+    }
+
+    if (config->rgbMode) {
+        attr[i++] = kCGLPFAColorSize;
+        attr[i++] = config->redBits + config->greenBits + config->blueBits;
+        attr[i++] = kCGLPFAAlphaSize;
+        attr[i++] = 1; /* FIXME: ignoring config->alphaBits which is always 0 */
+    }
+
+    if (config->haveAccumBuffer) {
+        attr[i++] = kCGLPFAAccumSize;
+        attr[i++] = config->accumRedBits + config->accumGreenBits
+                    + config->accumBlueBits + config->accumAlphaBits;
+    }
+	
+    if (config->haveDepthBuffer) {
+        attr[i++] = kCGLPFADepthSize;
+        attr[i++] = config->depthBits;
+    }
+	
+    if (config->haveStencilBuffer) {
+        attr[i++] = kCGLPFAStencilSize;
+        attr[i++] = config->stencilBits;
+    }
+
+    attr[i++] = kCGLPFAAuxBuffers;
+    attr[i++] = config->numAuxBuffers;
+
+    /* mode->level ignored */
+
+    /* mode->pixmapMode ? */
+
+    attr[i++] = 0;
+
+    GLAQUA_DEBUG_MSG("makeFormat almost done\n");
+
+    result = NULL;
+    gl_err = CGLChoosePixelFormat(attr, &result, &n_formats);
+    if (gl_err != 0)
+        ErrorF("CGLChoosePixelFormat error: %s\n", CGLErrorString(gl_err));
+
+    GLAQUA_DEBUG_MSG("makeFormat done (0x%x)\n", (unsigned int) result);
+
+    return result;
+}
+
+// Originally copied from Mesa
+
+static int                 numConfigs     = 0;
+static __GLXvisualConfig  *visualConfigs  = NULL;
+static void              **visualPrivates = NULL;
+
+/*
+ * In the case the driver defines no GLX visuals we'll use these.
+ * Note that for TrueColor and DirectColor visuals, bufferSize is the 
+ * sum of redSize, greenSize, blueSize and alphaSize, which may be larger 
+ * than the nplanes/rootDepth of the server's X11 visuals
+ */
+#define NUM_FALLBACK_CONFIGS 5
+static __GLXvisualConfig FallbackConfigs[NUM_FALLBACK_CONFIGS] = {
+  /* [0] = RGB, double buffered, Z */
+  {
+    -1,                 /* vid */
+    -1,                 /* class */
+    True,               /* rgba */
+    -1, -1, -1, 0,      /* rgba sizes */
+    -1, -1, -1, 0,      /* rgba masks */
+     0,  0,  0, 0,      /* rgba accum sizes */
+    True,               /* doubleBuffer */
+    False,              /* stereo */
+    -1,                 /* bufferSize */
+    16,                 /* depthSize */
+    0,                  /* stencilSize */
+    0,                  /* auxBuffers */
+    0,                  /* level */
+    GLX_NONE,           /* visualRating */
+    GLX_NONE,           /* transparentPixel */
+    0, 0, 0, 0,         /* transparent rgba color (floats scaled to ints) */
+    0                   /* transparentIndex */
+  },
+  /* [1] = RGB, double buffered, Z, stencil, accum */
+  {
+    -1,                 /* vid */
+    -1,                 /* class */
+    True,               /* rgba */
+    -1, -1, -1, 0,      /* rgba sizes */
+    -1, -1, -1, 0,      /* rgba masks */
+    16, 16, 16, 0,      /* rgba accum sizes */
+    True,               /* doubleBuffer */
+    False,              /* stereo */
+    -1,                 /* bufferSize */
+    16,                 /* depthSize */
+    8,                  /* stencilSize */
+    0,                  /* auxBuffers */
+    0,                  /* level */
+    GLX_NONE,           /* visualRating */
+    GLX_NONE,           /* transparentPixel */
+    0, 0, 0, 0,         /* transparent rgba color (floats scaled to ints) */
+    0                   /* transparentIndex */
+  },
+  /* [2] = RGB+Alpha, double buffered, Z, stencil, accum */
+  {
+    -1,                 /* vid */
+    -1,                 /* class */
+    True,               /* rgba */
+    -1, -1, -1, 8,      /* rgba sizes */
+    -1, -1, -1, -1,     /* rgba masks */
+    16, 16, 16, 16,     /* rgba accum sizes */
+    True,               /* doubleBuffer */
+    False,              /* stereo */
+    -1,                 /* bufferSize */
+    16,                 /* depthSize */
+    8,                  /* stencilSize */
+    0,                  /* auxBuffers */
+    0,                  /* level */
+    GLX_NONE,           /* visualRating */
+    GLX_NONE,           /* transparentPixel */
+    0, 0, 0, 0,         /* transparent rgba color (floats scaled to ints) */
+    0                   /* transparentIndex */
+  },
+  /* [3] = RGB+Alpha, single buffered, Z, stencil, accum */
+  {
+    -1,                 /* vid */
+    -1,                 /* class */
+    True,               /* rgba */
+    -1, -1, -1, 8,      /* rgba sizes */
+    -1, -1, -1, -1,     /* rgba masks */
+    16, 16, 16, 16,     /* rgba accum sizes */
+    False,              /* doubleBuffer */
+    False,              /* stereo */
+    -1,                 /* bufferSize */
+    16,                 /* depthSize */
+    8,                  /* stencilSize */
+    0,                  /* auxBuffers */
+    0,                  /* level */
+    GLX_NONE,           /* visualRating */
+    GLX_NONE,           /* transparentPixel */
+    0, 0, 0, 0,         /* transparent rgba color (floats scaled to ints) */
+    0                   /* transparentIndex */
+  },
+  /* [4] = CI, double buffered, Z */
+  {
+    -1,                 /* vid */
+    -1,                 /* class */
+    False,              /* rgba? (false = color index) */
+    -1, -1, -1, 0,      /* rgba sizes */
+    -1, -1, -1, 0,      /* rgba masks */
+     0,  0,  0, 0,      /* rgba accum sizes */
+    True,               /* doubleBuffer */
+    False,              /* stereo */
+    -1,                 /* bufferSize */
+    16,                 /* depthSize */
+    0,                  /* stencilSize */
+    0,                  /* auxBuffers */
+    0,                  /* level */
+    GLX_NONE,           /* visualRating */
+    GLX_NONE,           /* transparentPixel */
+    0, 0, 0, 0,         /* transparent rgba color (floats scaled to ints) */
+    0                   /* transparentIndex */
+  },
+};
+
+static __GLXvisualConfig NullConfig = {
+    -1,                 /* vid */
+    -1,                 /* class */
+    False,              /* rgba */
+    -1, -1, -1, 0,      /* rgba sizes */
+    -1, -1, -1, 0,      /* rgba masks */
+     0,  0,  0, 0,      /* rgba accum sizes */
+    False,              /* doubleBuffer */
+    False,              /* stereo */
+    -1,                 /* bufferSize */
+    16,                 /* depthSize */
+    0,                  /* stencilSize */
+    0,                  /* auxBuffers */
+    0,                  /* level */
+    GLX_NONE_EXT,       /* visualRating */
+    0,                  /* transparentPixel */
+    0, 0, 0, 0,         /* transparent rgba color (floats scaled to ints) */
+    0                   /* transparentIndex */
+};
+
+
+static inline int count_bits(uint32_t x)
+{
+    x = x - ((x >> 1) & 0x55555555);
+    x = (x & 0x33333333) + ((x >> 2) & 0x33333333);
+    x = (x + (x >> 4)) & 0x0f0f0f0f;
+    x = x + (x >> 8);
+    x = x + (x >> 16);
+    return x & 63;
+}
+
+
+static Bool init_visuals(int *nvisualp, VisualPtr *visualp,
+                         VisualID *defaultVisp,
+                         int ndepth, DepthPtr pdepth,
+                         int rootDepth)
+{
+    int numRGBconfigs;
+    int numCIconfigs;
+    int numVisuals = *nvisualp;
+    int numNewVisuals;
+    int numNewConfigs;
+    VisualPtr pVisual = *visualp;
+    VisualPtr pVisualNew = NULL;
+    VisualID *orig_vid = NULL;
+    __GLXconfig *modes;
+    __GLXvisualConfig *pNewVisualConfigs = NULL;
+    void **glXVisualPriv;
+    void **pNewVisualPriv;
+    int found_default;
+    int i, j, k;
+
+    GLAQUA_DEBUG_MSG("init_visuals\n");
+
+    if (numConfigs > 0)
+        numNewConfigs = numConfigs;
+    else
+        numNewConfigs = NUM_FALLBACK_CONFIGS;
+
+    /* Alloc space for the list of new GLX visuals */
+    pNewVisualConfigs = (__GLXvisualConfig *)
+                     malloc(numNewConfigs * sizeof(__GLXvisualConfig));
+    if (!pNewVisualConfigs) {
+        return FALSE;
+    }
+
+    /* Alloc space for the list of new GLX visual privates */
+    pNewVisualPriv = (void **) malloc(numNewConfigs * sizeof(void *));
+    if (!pNewVisualPriv) {
+        free(pNewVisualConfigs);
+        return FALSE;
+    }
+
+    /*
+    ** If SetVisualConfigs was not called, then use default GLX
+    ** visual configs.
+    */
+    if (numConfigs == 0) {
+        memcpy(pNewVisualConfigs, FallbackConfigs,
+               NUM_FALLBACK_CONFIGS * sizeof(__GLXvisualConfig));
+        memset(pNewVisualPriv, 0, NUM_FALLBACK_CONFIGS * sizeof(void *));
+    }
+    else {
+        /* copy driver's visual config info */
+        for (i = 0; i < numConfigs; i++) {
+            pNewVisualConfigs[i] = visualConfigs[i];
+            pNewVisualPriv[i] = visualPrivates[i];
+        }
+    }
+
+    /* Count the number of RGB and CI visual configs */
+    numRGBconfigs = 0;
+    numCIconfigs = 0;
+    for (i = 0; i < numNewConfigs; i++) {
+        if (pNewVisualConfigs[i].rgba)
+            numRGBconfigs++;
+        else
+            numCIconfigs++;
+    }
+
+    /* Count the total number of visuals to compute */
+    numNewVisuals = 0;
+    for (i = 0; i < numVisuals; i++) {
+        int count;
+
+        count = ((pVisual[i].class == TrueColor ||
+                  pVisual[i].class == DirectColor)
+                ? numRGBconfigs : numCIconfigs);
+        if (count == 0)
+            count = 1;          /* preserve the existing visual */
+
+        numNewVisuals += count;
+    }
+
+    /* Reset variables for use with the next screen/driver's visual configs */
+    visualConfigs = NULL;
+    numConfigs = 0;
+
+    /* Alloc temp space for the list of orig VisualIDs for each new visual */
+    orig_vid = (VisualID *)malloc(numNewVisuals * sizeof(VisualID));
+    if (!orig_vid) {
+        free(pNewVisualPriv);
+        free(pNewVisualConfigs);
+        return FALSE;
+    }
+
+    /* Alloc space for the list of glXVisuals */
+    modes = _gl_context_modes_create(numNewVisuals, sizeof(__GLXconfig));
+    if (modes == NULL) {
+        free(orig_vid);
+        free(pNewVisualPriv);
+        free(pNewVisualConfigs);
+        return FALSE;
+    }
+
+    /* Alloc space for the list of glXVisualPrivates */
+    glXVisualPriv = (void **)malloc(numNewVisuals * sizeof(void *));
+    if (!glXVisualPriv) {
+        _gl_context_modes_destroy( modes );
+        free(orig_vid);
+        free(pNewVisualPriv);
+        free(pNewVisualConfigs);
+        return FALSE;
+    }
+
+    /* Alloc space for the new list of the X server's visuals */
+    pVisualNew = (VisualPtr)malloc(numNewVisuals * sizeof(VisualRec));
+    if (!pVisualNew) {
+        free(glXVisualPriv);
+        _gl_context_modes_destroy( modes );
+        free(orig_vid);
+        free(pNewVisualPriv);
+        free(pNewVisualConfigs);
+        return FALSE;
+    }
+
+    /* Initialize the new visuals */
+    found_default = FALSE;
+    glAquaScreens[screenInfo.numScreens-1].modes = modes;
+    for (i = j = 0; i < numVisuals; i++) {
+        int is_rgb = (pVisual[i].class == TrueColor ||
+                      pVisual[i].class == DirectColor);
+
+        if (!is_rgb)
+        {
+            /* We don't support non-rgb visuals for GL. But we don't
+               want to remove them either, so just pass them through
+               with null glX configs */
+
+            pVisualNew[j] = pVisual[i];
+            pVisualNew[j].vid = FakeClientID(0);
+
+            /* Check for the default visual */
+            if (!found_default && pVisual[i].vid == *defaultVisp) {
+                *defaultVisp = pVisualNew[j].vid;
+                found_default = TRUE;
+            }
+
+            /* Save the old VisualID */
+            orig_vid[j] = pVisual[i].vid;
+
+            /* Initialize the glXVisual */
+            _gl_copy_visual_to_context_mode( modes, & NullConfig );
+            modes->visualID = pVisualNew[j].vid;
+
+            j++;
+
+            continue;
+        }
+
+        for (k = 0; k < numNewConfigs; k++) {
+            if (pNewVisualConfigs[k].rgba != is_rgb)
+                continue;
+
+            assert( modes != NULL );
+
+            /* Initialize the new visual */
+            pVisualNew[j] = pVisual[i];
+            pVisualNew[j].vid = FakeClientID(0);
+
+            /* Check for the default visual */
+            if (!found_default && pVisual[i].vid == *defaultVisp) {
+                *defaultVisp = pVisualNew[j].vid;
+                found_default = TRUE;
+            }
+
+            /* Save the old VisualID */
+            orig_vid[j] = pVisual[i].vid;
+
+            /* Initialize the glXVisual */
+            _gl_copy_visual_to_context_mode( modes, & pNewVisualConfigs[k] );
+            modes->visualID = pVisualNew[j].vid;
+
+            /*
+             * If the class is -1, then assume the X visual information
+             * is identical to what GLX needs, and take them from the X
+             * visual.  NOTE: if class != -1, then all other fields MUST
+             * be initialized.
+             */
+            if (modes->visualType == GLX_NONE) {
+                modes->visualType = _gl_convert_from_x_visual_type( pVisual[i].class );
+                modes->redBits    = count_bits(pVisual[i].redMask);
+                modes->greenBits  = count_bits(pVisual[i].greenMask);
+                modes->blueBits   = count_bits(pVisual[i].blueMask);
+                modes->alphaBits  = modes->alphaBits;
+                modes->redMask    = pVisual[i].redMask;
+                modes->greenMask  = pVisual[i].greenMask;
+                modes->blueMask   = pVisual[i].blueMask;
+                modes->alphaMask  = modes->alphaMask;
+                modes->rgbBits = (is_rgb)
+                    ? (modes->redBits + modes->greenBits +
+                       modes->blueBits + modes->alphaBits)
+                    : rootDepth;
+            }
+
+            /* Save the device-dependent private for this visual */
+            glXVisualPriv[j] = pNewVisualPriv[k];
+
+            j++;
+            modes = modes->next;
+        }
+    }
+
+    assert(j <= numNewVisuals);
+
+    /* Save the GLX visuals in the screen structure */
+    glAquaScreens[screenInfo.numScreens-1].num_vis = numNewVisuals;
+    //    glAquaScreens[screenInfo.numScreens-1].priv = glXVisualPriv;
+
+    /* set up depth's VisualIDs */
+    for (i = 0; i < ndepth; i++) {
+        int numVids = 0;
+        VisualID *pVids = NULL;
+        int k, n = 0;
+
+        /* Count the new number of VisualIDs at this depth */
+        for (j = 0; j < pdepth[i].numVids; j++)
+            for (k = 0; k < numNewVisuals; k++)
+            if (pdepth[i].vids[j] == orig_vid[k])
+                numVids++;
+
+        /* Allocate a new list of VisualIDs for this depth */
+        pVids = (VisualID *)malloc(numVids * sizeof(VisualID));
+
+        /* Initialize the new list of VisualIDs for this depth */
+        for (j = 0; j < pdepth[i].numVids; j++)
+            for (k = 0; k < numNewVisuals; k++)
+            if (pdepth[i].vids[j] == orig_vid[k])
+                pVids[n++] = pVisualNew[k].vid;
+
+        /* Update this depth's list of VisualIDs */
+        free(pdepth[i].vids);
+        pdepth[i].vids = pVids;
+        pdepth[i].numVids = numVids;
+    }
+
+    /* Update the X server's visuals */
+    *nvisualp = numNewVisuals;
+    *visualp = pVisualNew;
+
+    /* Free the old list of the X server's visuals */
+    free(pVisual);
+
+    /* Clean up temporary allocations */
+    free(orig_vid);
+    free(pNewVisualPriv);
+    free(pNewVisualConfigs);
+
+    /* Free the private list created by DDX HW driver */
+    if (visualPrivates)
+        free(visualPrivates);
+    visualPrivates = NULL;
+
+    return TRUE;
+}
+
+Bool enable_stereo = FALSE;
+/* based on code in i830_dri.c
+   This ends calling glAquaSetVisualConfigs to set the static
+   numconfigs, etc. */
+// see also glxglcore.c -- bhb
+static void
+glAquaInitVisualConfigs(void)
+{
+    int                 lclNumConfigs     = 0;
+    __GLXvisualConfig  *lclVisualConfigs  = NULL;
+    void              **lclVisualPrivates = NULL;
+
+    int stereo, depth, aux, buffers, stencil, accum;
+    int i = 0;
+
+    GLAQUA_DEBUG_MSG("glAquaInitVisualConfigs ");
+        
+    /* count num configs:
+        2 stereo (on, off) (optional)
+        2 Z buffer (0, 24 bit)
+        2 AUX buffer (0, 2)
+        2 buffers (single, double)
+        2 stencil (0, 8 bit)
+        2 accum (0, 64 bit)
+        = 64 configs with stereo, or 32 without */
+
+    if (enable_stereo) lclNumConfigs = 2 * 2 * 2 * 2 * 2 * 2; /* 64 */
+    else               lclNumConfigs = 2 * 2 * 2 * 2 * 2; /* 32 */
+
+    /* alloc */
+    lclVisualConfigs = xcalloc(sizeof(__GLXvisualConfig), lclNumConfigs);
+    lclVisualPrivates = xcalloc(sizeof(void *), lclNumConfigs);
+
+    /* fill in configs */
+    if (NULL != lclVisualConfigs) {
+        i = 0; /* current buffer */
+        for (stereo = 0; stereo < (enable_stereo ? 2 : 1); stereo++) {
+	  for (depth = 0; depth < 2; depth++) {
+            for (aux = 0; aux < 2; aux++) {
+	      for (buffers = 0; buffers < 2; buffers++) {
+		for (stencil = 0; stencil < 2; stencil++) {
+		  for (accum = 0; accum < 2; accum++) {
+		    lclVisualConfigs[i].vid = -1;
+		    lclVisualConfigs[i].class = -1;
+		    lclVisualConfigs[i].rgba = TRUE;
+		    lclVisualConfigs[i].redSize = -1;
+		    lclVisualConfigs[i].greenSize = -1;
+		    lclVisualConfigs[i].blueSize = -1;
+		    lclVisualConfigs[i].redMask = -1;
+		    lclVisualConfigs[i].greenMask = -1;
+		    lclVisualConfigs[i].blueMask = -1;
+		    lclVisualConfigs[i].alphaMask = 0;
+		    if (accum) {
+		      lclVisualConfigs[i].accumRedSize = 16;
+		      lclVisualConfigs[i].accumGreenSize = 16;
+		      lclVisualConfigs[i].accumBlueSize = 16;
+		      lclVisualConfigs[i].accumAlphaSize = 16;
+		    } else {
+		      lclVisualConfigs[i].accumRedSize = 0;
+		      lclVisualConfigs[i].accumGreenSize = 0;
+		      lclVisualConfigs[i].accumBlueSize = 0;
+		      lclVisualConfigs[i].accumAlphaSize = 0;
+		    }
+		    lclVisualConfigs[i].doubleBuffer = buffers ? TRUE : FALSE;
+		    lclVisualConfigs[i].stereo = stereo ? TRUE : FALSE;
+		    lclVisualConfigs[i].bufferSize = -1;
+		    
+		    lclVisualConfigs[i].depthSize = depth? 24 : 0;
+		    lclVisualConfigs[i].stencilSize = stencil ? 8 : 0;
+		    lclVisualConfigs[i].auxBuffers = aux ? 2 : 0;
+		    lclVisualConfigs[i].level = 0;
+		    lclVisualConfigs[i].visualRating = GLX_NONE_EXT;
+		    lclVisualConfigs[i].transparentPixel = 0;
+		    lclVisualConfigs[i].transparentRed = 0;
+		    lclVisualConfigs[i].transparentGreen = 0;
+		    lclVisualConfigs[i].transparentBlue = 0;
+		    lclVisualConfigs[i].transparentAlpha = 0;
+		    lclVisualConfigs[i].transparentIndex = 0;
+		    i++;
+		  }
+		}
+	      }
+            }
+	  }
+	}
+    }
+    if (i != lclNumConfigs)
+        GLAQUA_DEBUG_MSG("glAquaInitVisualConfigs failed to alloc visual configs");
+
+    GlxSetVisualConfigs(lclNumConfigs, lclVisualConfigs, lclVisualPrivates);
+}
+
+
+static void glAquaSetVisualConfigs(int nconfigs, __GLXvisualConfig *configs,
+                                   void **privates)
+{
+    GLAQUA_DEBUG_MSG("glAquaSetVisualConfigs\n");
+
+    numConfigs = nconfigs;
+    visualConfigs = configs;
+    visualPrivates = privates;
+}
+
+static Bool glAquaInitVisuals(VisualPtr *visualp, DepthPtr *depthp,
+                              int *nvisualp, int *ndepthp,
+                              int *rootDepthp, VisualID *defaultVisp,
+                              unsigned long sizes, int bitsPerRGB)
+{
+    GLAQUA_DEBUG_MSG("glAquaInitVisuals\n");
+    
+    if (numConfigs == 0) /* if no configs */
+        glAquaInitVisualConfigs(); /* ensure the visual configs are setup */
+
+    /*
+     * setup the visuals supported by this particular screen.
+     */
+    return init_visuals(nvisualp, visualp, defaultVisp,
+                        *ndepthp, *depthp, *rootDepthp);
+}
+
+#if 0
+static void fixup_visuals(int screen)
+{
+    ScreenPtr pScreen = screenInfo.screens[screen];
+    glAquaScreenRec *pScr = &glAquaScreens[screen];
+    int j;
+    __GLcontextModes *modes;
+
+    GLAQUA_DEBUG_MSG("fixup_visuals\n");
+
+    for ( modes = pScr->modes ; modes != NULL ; modes = modes->next ) {
+        const int vis_class = _gl_convert_to_x_visual_type( modes->visualType );
+        const int nplanes = (modes->rgbBits - modes->alphaBits);
+        const VisualPtr pVis = pScreen->visuals;
+
+        /* Find a visual that matches the GLX visual's class and size */
+        for (j = 0; j < pScreen->numVisuals; j++) {
+            if (pVis[j].class == vis_class &&
+            pVis[j].nplanes == nplanes) {
+
+            /* Fixup the masks */
+            modes->redMask   = pVis[j].redMask;
+            modes->greenMask = pVis[j].greenMask;
+            modes->blueMask  = pVis[j].blueMask;
+
+            /* Recalc the sizes */
+            modes->redBits   = count_bits(modes->redMask);
+            modes->greenBits = count_bits(modes->greenMask);
+            modes->blueBits  = count_bits(modes->blueMask);
+            }
+        }
+    }
+}
+#endif
+static void __glXAquaScreenDestroy(__GLXscreen *screen) {
+
+	GLAQUA_DEBUG_MSG("glXAquaScreenDestroy(%p)\n", screen);
+  __glXScreenDestroy(screen);
+
+  free(screen);
+}
+
+static void init_screen_visuals(__GLXAquaScreen *screen) {
+  ScreenPtr pScreen = screen->base.pScreen;
+  
+  __GLXconfig *modes;
+  int *used;
+  int i, j;
+  
+    GLAQUA_DEBUG_MSG("init_screen_visuals\n");
+
+    /* FIXME: Change 'used' to be a array of bits (rather than of ints),
+     * FIXME: create a stack array of 8 or 16 bytes.  If 'numVisuals' is less
+     * FIXME: than 64 or 128 the stack array can be used instead of calling
+     * FIXME: malloc / free.  If nothing else, convert 'used' to
+     * FIXME: array of bytes instead of ints!
+     */
+    used = (int *)malloc(pScreen->numVisuals * sizeof(int));
+    memset(used, 0, pScreen->numVisuals * sizeof(int));
+
+    i = 0;
+    for ( modes = screen -> base.visuals
+          ; modes != NULL
+          ; modes = modes->next ) {
+        const int vis_class = _gl_convert_to_x_visual_type( modes->visualType );
+        const int nplanes = (modes->rgbBits - modes->alphaBits);
+        const VisualPtr pVis = pScreen->visuals;
+
+        for (j = 0; j < pScreen->numVisuals; j++) {
+            if (pVis[j].class     == vis_class &&
+                pVis[j].nplanes   == nplanes &&
+                pVis[j].redMask   == modes->redMask &&
+                pVis[j].greenMask == modes->greenMask &&
+                pVis[j].blueMask  == modes->blueMask &&
+                !used[j]) {
+
+                    /* set the VisualID */
+                    modes->visualID = pVis[j].vid;
+
+                    /* Mark this visual used */
+                    used[j] = 1;
+                    break;
+            }
+        }
+        if ( j == pScreen->numVisuals ) {
+            ErrorF("No matching visual for __GLcontextMode with "
+                   "visual class = %d (%d), nplanes = %u\n",
+                   vis_class, 
+                   (int)modes->visualType,
+                   (unsigned int)(modes->rgbBits - modes->alphaBits) );
+        }
+        else if ( modes->visualID == -1 ) {
+            FatalError( "Matching visual found, but visualID still -1!\n" );
+        }
+
+        i++;
+    }
+
+    free(used);
+}
+
+static __GLXscreen * __glXAquaScreenProbe(ScreenPtr pScreen) {
+  __GLXAquaScreen *screen;
+  GLAQUA_DEBUG_MSG("glXAquaScreenProbe\n");
+  if (screen == NULL) return NULL;
+
+  screen = malloc(sizeof *screen);
+
+  __glXScreenInit(&screen->base, pScreen);
+
+  screen->base.destroy        = __glXAquaScreenDestroy;
+  screen->base.createContext  = __glXAquaScreenCreateContext;
+  screen->base.createDrawable = __glXAquaScreenCreateDrawable;
+  screen->base.pScreen       = pScreen;
+
+  init_screen_visuals(screen);
+
+  return &screen->base;
+}
+
+static void __glXAquaDrawableDestroy(__GLXdrawable *base) {
+    GLAQUA_DEBUG_MSG("glAquaDestroyDrawablePrivate\n");
+
+    /* It doesn't work to call DRIDestroySurface here, the drawable's
+       already gone.. But dri.c notices the window destruction and
+       frees the surface itself. */
+
+    free(base);
+}
+
+static __GLXdrawable *
+__glXAquaScreenCreateDrawable(__GLXscreen *screen,
+			      DrawablePtr pDraw,
+			      XID drawId,
+			      __GLXconfig *modes) {
+  __GLXAquaDrawable *glxPriv;
+
+  GLAQUA_DEBUG_MSG("glAquaScreenCreateDrawable(%p,%p,%d,%p)\n", context, pDraw, drawId, modes);
+
+  glxPriv = xalloc(sizeof *glxPriv);
+  if (glxPriv == NULL) return NULL;
+
+  memset(glxPriv, 0, sizeof *glxPriv);
+
+  if (!__glXDrawableInit(&glxPriv->base, screen, pDraw, GLX_DRAWABLE_PIXMAP /*?*/, drawId, modes)) {
+    xfree(glxPriv);
+    return NULL;
+  }
+
+  glxPriv->base.destroy       = __glXAquaDrawableDestroy;
+  glxPriv->base.resize        = __glXAquaDrawableResize;
+  glxPriv->base.swapBuffers   = __glXAquaDrawableSwapBuffers;
+  //  glxPriv->base.copySubBuffer = __glXAquaDrawableCopySubBuffer;
+
+  return &glxPriv->base;
+}
+
+static void glAquaResetExtension(void)
+{
+    GLAQUA_DEBUG_MSG("glAquaResetExtension\n");
+    CGLSetOption(kCGLGOResetLibrary, GL_TRUE);
+}
+
+// Extra goodies for glx
+
+GLuint __glFloorLog2(GLuint val)
+{
+    int c = 0;
+
+    while (val > 1) {
+        c++;
+        val >>= 1;
+    }
+    return c;
+}
+
+void warn_func(void * p1, char *format, ...) {
+  va_list v;
+  va_start(v, format);
+  vfprintf(stderr, format, v);
+  va_end(v);
+}
+
+static void setup_dispatch_table(void) {
+  struct _glapi_table *disp=_glapi_get_dispatch();
+  _glapi_set_warning_func((_glapi_warning_func)warn_func);
+  _glapi_noop_enable_warnings(TRUE);
+
+  SET_Accum(disp, glAccum);
+  SET_ActiveStencilFaceEXT(disp, glActiveStencilFaceEXT);
+  SET_ActiveTextureARB(disp, glActiveTextureARB);
+//SET_AlphaFragmentOp1ATI(disp, glAlphaFragmentOp1EXT);   // <-- EXT -> ATI
+//SET_AlphaFragmentOp2ATI(disp, glAlphaFragmentOp2EXT);
+//SET_AlphaFragmentOp3ATI(disp, glAlphaFragmentOp3EXT);
+  SET_AlphaFunc(disp, glAlphaFunc);
+//SET_AreProgramsResidentNV(disp, glAreProgramsResidentNV);
+  SET_AreTexturesResident(disp, glAreTexturesResident); 
+  SET_ArrayElement(disp, glArrayElement);
+  SET_AttachObjectARB(disp, glAttachObjectARB);
+  SET_Begin(disp, glBegin);
+//SET_BeginFragmentShaderATI(disp, glBeginFragmentShaderEXT);   // <-- EXT -> ATI
+  SET_BeginQueryARB(disp, glBeginQueryARB);
+  SET_BindAttribLocationARB(disp, glBindAttribLocationARB);
+  SET_BindBufferARB(disp, glBindBufferARB);
+//SET_BindFragmentShaderATI(disp, glBindFragmentShaderEXT);     // <-- EXT -> ATI
+  SET_BindFramebufferEXT(disp, glBindFramebufferEXT);
+//SET_BindProgramNV(disp, glBindProgramNV);
+  SET_BindRenderbufferEXT(disp, glBindRenderbufferEXT);
+  SET_BindTexture(disp, glBindTexture);
+  SET_Bitmap(disp, glBitmap);
+  SET_BlendColor(disp, glBlendColor);
+  SET_BlendEquation(disp, glBlendEquation);
+  SET_BlendEquationSeparateEXT(disp, glBlendEquationSeparateEXT);
+  SET_BlendFunc(disp, glBlendFunc);
+  SET_BlendFuncSeparateEXT(disp, glBlendFuncSeparateEXT);
+  SET_BlitFramebufferEXT(disp, glBlitFramebufferEXT);
+  SET_BufferDataARB(disp, glBufferDataARB);
+  SET_BufferSubDataARB(disp, glBufferSubDataARB);
+  SET_CallList(disp, glCallList);
+  SET_CallLists(disp, glCallLists);
+  SET_CheckFramebufferStatusEXT(disp, glCheckFramebufferStatusEXT);
+  SET_Clear(disp, glClear);
+  SET_ClearAccum(disp, glClearAccum);
+  SET_ClearColor(disp, glClearColor);
+  SET_ClearDepth(disp, glClearDepth);
+  SET_ClearIndex(disp, glClearIndex);
+  SET_ClearStencil(disp, glClearStencil);
+  SET_ClientActiveTextureARB(disp, glClientActiveTextureARB);
+  SET_ClipPlane(disp, glClipPlane);
+  SET_Color3b(disp, glColor3b);
+  SET_Color3bv(disp, glColor3bv);
+  SET_Color3d(disp, glColor3d);
+  SET_Color3dv(disp, glColor3dv);
+  SET_Color3f(disp, glColor3f);
+  SET_Color3fv(disp, glColor3fv);
+  SET_Color3i(disp, glColor3i);
+  SET_Color3iv(disp, glColor3iv);
+  SET_Color3s(disp, glColor3s);
+  SET_Color3sv(disp, glColor3sv);
+  SET_Color3ub(disp, glColor3ub);
+  SET_Color3ubv(disp, glColor3ubv);
+  SET_Color3ui(disp, glColor3ui);
+  SET_Color3uiv(disp, glColor3uiv);
+  SET_Color3us(disp, glColor3us);
+  SET_Color3usv(disp, glColor3usv);
+  SET_Color4b(disp, glColor4b);
+  SET_Color4bv(disp, glColor4bv);
+  SET_Color4d(disp, glColor4d);
+  SET_Color4dv(disp, glColor4dv);
+  SET_Color4f(disp, glColor4f);
+  SET_Color4fv(disp, glColor4fv);
+  SET_Color4i(disp, glColor4i);
+  SET_Color4iv(disp, glColor4iv);
+  SET_Color4s(disp, glColor4s);
+  SET_Color4sv(disp, glColor4sv);
+  SET_Color4ub(disp, glColor4ub);
+  SET_Color4ubv(disp, glColor4ubv);
+  SET_Color4ui(disp, glColor4ui);
+  SET_Color4uiv(disp, glColor4uiv);
+  SET_Color4us(disp, glColor4us);
+  SET_Color4usv(disp, glColor4usv);
+//SET_ColorFragmentOp1ATI(disp, glColorFragmentOp1EXT);    // <-- EXT -> ATI
+//SET_ColorFragmentOp2ATI(disp, glColorFragmentOp2EXT);
+//SET_ColorFragmentOp3ATI(disp, glColorFragmentOp3EXT);
+  SET_ColorMask(disp, glColorMask);
+  SET_ColorMaterial(disp, glColorMaterial);
+  SET_ColorPointer(disp, glColorPointer);
+//SET_ColorPointerEXT(disp, glColorPointerEXT);
+  SET_ColorSubTable(disp, glColorSubTable);
+  SET_ColorTable(disp, glColorTable);
+  SET_ColorTableParameterfv(disp, glColorTableParameterfv);
+  SET_ColorTableParameteriv(disp, glColorTableParameteriv);
+  SET_CombinerInputNV(disp, glCombinerInputNV);
+  SET_CombinerOutputNV(disp, glCombinerOutputNV);
+  SET_CombinerParameterfNV(disp, glCombinerParameterfNV);
+  SET_CombinerParameterfvNV(disp, glCombinerParameterfvNV);
+  SET_CombinerParameteriNV(disp, glCombinerParameteriNV);
+  SET_CombinerParameterivNV(disp, glCombinerParameterivNV);
+  SET_CompileShaderARB(disp, glCompileShaderARB);
+  SET_CompressedTexImage1DARB(disp, glCompressedTexImage1DARB);
+  SET_CompressedTexImage2DARB(disp, glCompressedTexImage2DARB);
+  SET_CompressedTexImage3DARB(disp, glCompressedTexImage3DARB);
+  SET_CompressedTexSubImage1DARB(disp, glCompressedTexSubImage1DARB);
+  SET_CompressedTexSubImage2DARB(disp, glCompressedTexSubImage2DARB);
+  SET_CompressedTexSubImage3DARB(disp, glCompressedTexSubImage3DARB);
+  SET_ConvolutionFilter1D(disp, glConvolutionFilter1D);
+  SET_ConvolutionFilter2D(disp, glConvolutionFilter2D);
+  SET_ConvolutionParameterf(disp, glConvolutionParameterf);
+  SET_ConvolutionParameterfv(disp, glConvolutionParameterfv);
+  SET_ConvolutionParameteri(disp, glConvolutionParameteri);
+  SET_ConvolutionParameteriv(disp, glConvolutionParameteriv);
+  SET_CopyColorSubTable(disp, glCopyColorSubTable);
+  SET_CopyColorTable(disp, glCopyColorTable);
+  SET_CopyConvolutionFilter1D(disp, glCopyConvolutionFilter1D);
+  SET_CopyConvolutionFilter2D(disp, glCopyConvolutionFilter2D);
+  SET_CopyPixels(disp, glCopyPixels);
+  SET_CopyTexImage1D(disp, glCopyTexImage1D);
+  SET_CopyTexImage2D(disp, glCopyTexImage2D);
+  SET_CopyTexSubImage1D(disp, glCopyTexSubImage1D);
+  SET_CopyTexSubImage2D(disp, glCopyTexSubImage2D);
+  SET_CopyTexSubImage3D(disp, glCopyTexSubImage3D);
+  SET_CreateProgramObjectARB(disp, glCreateProgramObjectARB);
+  SET_CreateShaderObjectARB(disp, glCreateShaderObjectARB);
+  SET_CullFace(disp, glCullFace);
+//SET_CullParameterdvEXT(disp, glCullParameterdvEXT);
+//SET_CullParameterfvEXT(disp, glCullParameterfvEXT);
+  SET_DeleteBuffersARB(disp, glDeleteBuffersARB);
+  SET_DeleteFencesNV(disp, glDeleteFencesAPPLE);
+//SET_DeleteFragmentShaderATI(disp, glDeleteFragmentShaderEXT);      // <-- EXT -> ATI
+  SET_DeleteFramebuffersEXT(disp, glDeleteFramebuffersEXT);
+  SET_DeleteLists(disp, glDeleteLists);
+  SET_DeleteObjectARB(disp, glDeleteObjectARB);
+//SET_DeleteProgramsNV(disp, glDeleteProgramsNV);
+  SET_DeleteQueriesARB(disp, glDeleteQueriesARB);
+  SET_DeleteRenderbuffersEXT(disp, glDeleteRenderbuffersEXT);
+  SET_DeleteTextures(disp, glDeleteTextures);
+  SET_DepthBoundsEXT(disp, glDepthBoundsEXT);
+  SET_DepthFunc(disp, glDepthFunc);
+  SET_DepthMask(disp, glDepthMask);
+  SET_DepthRange(disp, glDepthRange);
+  SET_DetachObjectARB(disp, glDetachObjectARB);
+  SET_Disable(disp, glDisable);
+  SET_DisableClientState(disp, glDisableClientState);
+  SET_DisableVertexAttribArrayARB(disp, glDisableVertexAttribArrayARB);
+  SET_DrawArrays(disp, glDrawArrays);
+  SET_DrawBuffer(disp, glDrawBuffer);
+  SET_DrawBuffersARB(disp, glDrawBuffersARB);
+  SET_DrawElements(disp, glDrawElements);
+  SET_DrawPixels(disp, glDrawPixels);
+  SET_DrawRangeElements(disp, glDrawRangeElements);
+  SET_EdgeFlag(disp, glEdgeFlag);
+  SET_EdgeFlagPointer(disp, glEdgeFlagPointer);
+//SET_EdgeFlagPointerEXT(disp, glEdgeFlagPointerEXT);
+  SET_EdgeFlagv(disp, glEdgeFlagv);
+  SET_Enable(disp, glEnable);
+  SET_EnableClientState(disp, glEnableClientState);
+  SET_EnableVertexAttribArrayARB(disp, glEnableVertexAttribArrayARB);
+  SET_End(disp, glEnd);
+//SET_EndFragmentShaderATI(disp, glEndFragmentShaderEXT);        // <-- EXT -> ATI
+  SET_EndList(disp, glEndList);
+  SET_EndQueryARB(disp, glEndQueryARB);
+  SET_EvalCoord1d(disp, glEvalCoord1d);
+  SET_EvalCoord1dv(disp, glEvalCoord1dv);
+  SET_EvalCoord1f(disp, glEvalCoord1f);
+  SET_EvalCoord1fv(disp, glEvalCoord1fv);
+  SET_EvalCoord2d(disp, glEvalCoord2d);
+  SET_EvalCoord2dv(disp, glEvalCoord2dv);
+  SET_EvalCoord2f(disp, glEvalCoord2f);
+  SET_EvalCoord2fv(disp, glEvalCoord2fv);
+  SET_EvalMesh1(disp, glEvalMesh1);
+  SET_EvalMesh2(disp, glEvalMesh2);
+  SET_EvalPoint1(disp, glEvalPoint1);
+  SET_EvalPoint2(disp, glEvalPoint2);
+//SET_ExecuteProgramNV(disp, glExecuteProgramNV);
+  SET_FeedbackBuffer(disp, glFeedbackBuffer);
+  SET_FinalCombinerInputNV(disp, glFinalCombinerInputNV);
+  SET_Finish(disp, glFinish);
+  SET_FinishFenceNV(disp, glFinishFenceAPPLE);       // <-- APPLE -> NV
+  SET_Flush(disp, glFlush);
+//SET_FlushVertexArrayRangeNV(disp, glFlushVertexArrayRangeNV);
+  SET_FogCoordPointerEXT(disp, glFogCoordPointerEXT);
+  SET_FogCoorddEXT(disp, glFogCoorddEXT);
+  SET_FogCoorddvEXT(disp, glFogCoorddvEXT);
+  SET_FogCoordfEXT(disp, glFogCoordfEXT);
+  SET_FogCoordfvEXT(disp, glFogCoordfvEXT);
+  SET_Fogf(disp, glFogf);
+  SET_Fogfv(disp, glFogfv);
+  SET_Fogi(disp, glFogi);
+  SET_Fogiv(disp, glFogiv);
+  SET_FramebufferRenderbufferEXT(disp, glFramebufferRenderbufferEXT);
+  SET_FramebufferTexture1DEXT(disp, glFramebufferTexture1DEXT);
+  SET_FramebufferTexture2DEXT(disp, glFramebufferTexture2DEXT);
+  SET_FramebufferTexture3DEXT(disp, glFramebufferTexture3DEXT);
+  SET_FrontFace(disp, glFrontFace);
+  SET_Frustum(disp, glFrustum);
+  SET_GenBuffersARB(disp, glGenBuffersARB);
+  SET_GenFencesNV(disp, glGenFencesAPPLE);            // <-- APPLE -> NV
+//SET_GenFragmentShadersATI(disp, glGenFragmentShadersEXT);         // <-- EXT -> ATI
+  SET_GenFramebuffersEXT(disp, glGenFramebuffersEXT);
+  SET_GenLists(disp, glGenLists);
+//SET_GenProgramsNV(disp, glGenProgramsNV);
+  SET_GenQueriesARB(disp, glGenQueriesARB);
+  SET_GenRenderbuffersEXT(disp, glGenRenderbuffersEXT);
+  SET_GenTextures(disp, glGenTextures);
+  SET_GenerateMipmapEXT(disp, glGenerateMipmapEXT);
+  SET_GetActiveAttribARB(disp, glGetActiveAttribARB);
+  SET_GetActiveUniformARB(disp, glGetActiveUniformARB);
+  SET_GetAttachedObjectsARB(disp, glGetAttachedObjectsARB);
+  SET_GetAttribLocationARB(disp, glGetAttribLocationARB);
+  SET_GetBooleanv(disp, glGetBooleanv);
+  SET_GetBufferParameterivARB(disp, glGetBufferParameterivARB);
+  SET_GetBufferPointervARB(disp, glGetBufferPointervARB);
+  SET_GetBufferSubDataARB(disp, glGetBufferSubDataARB);
+  SET_GetClipPlane(disp, glGetClipPlane);
+  SET_GetColorTable(disp, glGetColorTable);
+  SET_GetColorTableParameterfv(disp, glGetColorTableParameterfv);
+  SET_GetColorTableParameteriv(disp, glGetColorTableParameteriv);
+  SET_GetCombinerInputParameterfvNV(disp, glGetCombinerInputParameterfvNV);
+  SET_GetCombinerInputParameterivNV(disp, glGetCombinerInputParameterivNV);
+  SET_GetCombinerOutputParameterfvNV(disp, glGetCombinerOutputParameterfvNV);
+  SET_GetCombinerOutputParameterivNV(disp, glGetCombinerOutputParameterivNV);
+  SET_GetCompressedTexImageARB(disp, glGetCompressedTexImageARB);
+  SET_GetConvolutionFilter(disp, glGetConvolutionFilter);
+  SET_GetConvolutionParameterfv(disp, glGetConvolutionParameterfv);
+  SET_GetConvolutionParameteriv(disp, glGetConvolutionParameteriv);
+  SET_GetDoublev(disp, glGetDoublev);
+  SET_GetError(disp, glGetError);
+//SET_GetFenceivNV(disp, glGetFenceivNV);
+  SET_GetFinalCombinerInputParameterfvNV(disp, glGetFinalCombinerInputParameterfvNV);
+  SET_GetFinalCombinerInputParameterivNV(disp, glGetFinalCombinerInputParameterivNV);
+  SET_GetFloatv(disp, glGetFloatv);
+  SET_GetFramebufferAttachmentParameterivEXT(disp, glGetFramebufferAttachmentParameterivEXT);
+  SET_GetHandleARB(disp, glGetHandleARB);
+  SET_GetHistogram(disp, glGetHistogram);
+  SET_GetHistogramParameterfv(disp, glGetHistogramParameterfv);
+  SET_GetHistogramParameteriv(disp, glGetHistogramParameteriv);
+  SET_GetInfoLogARB(disp, glGetInfoLogARB);
+  SET_GetIntegerv(disp, glGetIntegerv);
+  SET_GetLightfv(disp, glGetLightfv);
+  SET_GetLightiv(disp, glGetLightiv);
+  SET_GetMapdv(disp, glGetMapdv);
+  SET_GetMapfv(disp, glGetMapfv);
+  SET_GetMapiv(disp, glGetMapiv);
+  SET_GetMaterialfv(disp, glGetMaterialfv);
+  SET_GetMaterialiv(disp, glGetMaterialiv);
+  SET_GetMinmax(disp, glGetMinmax);
+  SET_GetMinmaxParameterfv(disp, glGetMinmaxParameterfv);
+  SET_GetMinmaxParameteriv(disp, glGetMinmaxParameteriv);
+  SET_GetObjectParameterfvARB(disp, glGetObjectParameterfvARB);
+  SET_GetObjectParameterivARB(disp, glGetObjectParameterivARB);
+  SET_GetPixelMapfv(disp, glGetPixelMapfv);
+  SET_GetPixelMapuiv(disp, glGetPixelMapuiv);
+  SET_GetPixelMapusv(disp, glGetPixelMapusv);
+//SET_GetPixelTexGenParameterfvSGIS(disp, glGetPixelTexGenParameterfvSGIS);
+//SET_GetPixelTexGenParameterivSGIS(disp, glGetPixelTexGenParameterivSGIS);
+  SET_GetPointerv(disp, glGetPointerv);
+  SET_GetPolygonStipple(disp, glGetPolygonStipple);
+  SET_GetProgramEnvParameterdvARB(disp, glGetProgramEnvParameterdvARB);
+  SET_GetProgramEnvParameterfvARB(disp, glGetProgramEnvParameterfvARB);
+  SET_GetProgramLocalParameterdvARB(disp, glGetProgramLocalParameterdvARB);
+  SET_GetProgramLocalParameterfvARB(disp, glGetProgramLocalParameterfvARB);
+//SET_GetProgramNamedParameterdvNV(disp, glGetProgramNamedParameterdvNV);
+//SET_GetProgramNamedParameterfvNV(disp, glGetProgramNamedParameterfvNV);
+//SET_GetProgramParameterdvNV(disp, glGetProgramParameterdvNV);
+//SET_GetProgramParameterfvNV(disp, glGetProgramParameterfvNV);
+  SET_GetProgramStringARB(disp, glGetProgramStringARB);
+//SET_GetProgramStringNV(disp, glGetProgramStringNV);
+  SET_GetProgramivARB(disp, glGetProgramivARB);
+//SET_GetProgramivNV(disp, glGetProgramivNV);
+//SET_GetQueryObjecti64vEXT(disp, glGetQueryObjecti64vEXT);
+  SET_GetQueryObjectivARB(disp, glGetQueryObjectivARB);
+//SET_GetQueryObjectui64vEXT(disp, glGetQueryObjectui64vEXT);
+  SET_GetQueryObjectuivARB(disp, glGetQueryObjectuivARB);
+  SET_GetQueryivARB(disp, glGetQueryivARB);
+  SET_GetRenderbufferParameterivEXT(disp, glGetRenderbufferParameterivEXT);
+  SET_GetSeparableFilter(disp, glGetSeparableFilter);
+  SET_GetShaderSourceARB(disp, glGetShaderSourceARB);
+  SET_GetString(disp, glGetString);
+  SET_GetTexEnvfv(disp, glGetTexEnvfv);
+  SET_GetTexEnviv(disp, glGetTexEnviv);
+  SET_GetTexGendv(disp, glGetTexGendv);
+  SET_GetTexGenfv(disp, glGetTexGenfv);
+  SET_GetTexGeniv(disp, glGetTexGeniv);
+  SET_GetTexImage(disp, glGetTexImage);
+  SET_GetTexLevelParameterfv(disp, glGetTexLevelParameterfv);
+  SET_GetTexLevelParameteriv(disp, glGetTexLevelParameteriv);
+  SET_GetTexParameterfv(disp, glGetTexParameterfv);
+  SET_GetTexParameteriv(disp, glGetTexParameteriv);
+//SET_GetTrackMatrixivNV(disp, glGetTrackMatrixivNV);
+  SET_GetUniformLocationARB(disp, glGetUniformLocationARB);
+  SET_GetUniformfvARB(disp, glGetUniformfvARB);
+  SET_GetUniformivARB(disp, glGetUniformivARB);
+//SET_GetVertexAttribPointervNV(disp, glGetVertexAttribPointervNV);
+  SET_GetVertexAttribdvARB(disp, glGetVertexAttribdvARB);
+//SET_GetVertexAttribdvNV(disp, glGetVertexAttribdvNV);
+  SET_GetVertexAttribfvARB(disp, glGetVertexAttribfvARB);
+//SET_GetVertexAttribfvNV(disp, glGetVertexAttribfvNV);
+  SET_GetVertexAttribivARB(disp, glGetVertexAttribivARB);
+//SET_GetVertexAttribivNV(disp, glGetVertexAttribivNV);
+  SET_Hint(disp, glHint);
+  SET_Histogram(disp, glHistogram);
+  SET_IndexMask(disp, glIndexMask);
+  SET_IndexPointer(disp, glIndexPointer);
+//SET_IndexPointerEXT(disp, glIndexPointerEXT);
+  SET_Indexd(disp, glIndexd);
+  SET_Indexdv(disp, glIndexdv);
+  SET_Indexf(disp, glIndexf);
+  SET_Indexfv(disp, glIndexfv);
+  SET_Indexi(disp, glIndexi);
+  SET_Indexiv(disp, glIndexiv);
+  SET_Indexs(disp, glIndexs);
+  SET_Indexsv(disp, glIndexsv);
+  SET_Indexub(disp, glIndexub);
+  SET_Indexubv(disp, glIndexubv);
+  SET_InitNames(disp, glInitNames);
+  SET_InterleavedArrays(disp, glInterleavedArrays);
+  SET_IsBufferARB(disp, glIsBufferARB);
+  SET_IsEnabled(disp, glIsEnabled);
+  SET_IsFenceNV(disp, glIsFenceAPPLE);           // <-- APPLE -> NV
+  SET_IsFramebufferEXT(disp, glIsFramebufferEXT);
+  SET_IsList(disp, glIsList);
+//SET_IsProgramNV(disp, glIsProgramNV);
+  SET_IsQueryARB(disp, glIsQueryARB);
+  SET_IsRenderbufferEXT(disp, glIsRenderbufferEXT);
+  SET_IsTexture(disp, glIsTexture);
+  SET_LightModelf(disp, glLightModelf);
+  SET_LightModelfv(disp, glLightModelfv);
+  SET_LightModeli(disp, glLightModeli);
+  SET_LightModeliv(disp, glLightModeliv);
+  SET_Lightf(disp, glLightf);
+  SET_Lightfv(disp, glLightfv);
+  SET_Lighti(disp, glLighti);
+  SET_Lightiv(disp, glLightiv);
+  SET_LineStipple(disp, glLineStipple);
+  SET_LineWidth(disp, glLineWidth);
+  SET_LinkProgramARB(disp, glLinkProgramARB);
+  SET_ListBase(disp, glListBase);
+  SET_LoadIdentity(disp, glLoadIdentity);
+  SET_LoadMatrixd(disp, glLoadMatrixd);
+  SET_LoadMatrixf(disp, glLoadMatrixf);
+  SET_LoadName(disp, glLoadName);
+//SET_LoadProgramNV(disp, glLoadProgramNV);
+  SET_LoadTransposeMatrixdARB(disp, glLoadTransposeMatrixdARB);
+  SET_LoadTransposeMatrixfARB(disp, glLoadTransposeMatrixfARB);
+  SET_LockArraysEXT(disp, glLockArraysEXT);
+  SET_LogicOp(disp, glLogicOp);
+  SET_Map1d(disp, glMap1d);
+  SET_Map1f(disp, glMap1f);
+  SET_Map2d(disp, glMap2d);
+  SET_Map2f(disp, glMap2f);
+  SET_MapBufferARB(disp, glMapBufferARB);
+  SET_MapGrid1d(disp, glMapGrid1d);
+  SET_MapGrid1f(disp, glMapGrid1f);
+  SET_MapGrid2d(disp, glMapGrid2d);
+  SET_MapGrid2f(disp, glMapGrid2f);
+  SET_Materialf(disp, glMaterialf);
+  SET_Materialfv(disp, glMaterialfv);
+  SET_Materiali(disp, glMateriali);
+  SET_Materialiv(disp, glMaterialiv);
+  SET_MatrixMode(disp, glMatrixMode);
+  SET_Minmax(disp, glMinmax);
+  SET_MultMatrixd(disp, glMultMatrixd);
+  SET_MultMatrixf(disp, glMultMatrixf);
+  SET_MultTransposeMatrixdARB(disp, glMultTransposeMatrixdARB);
+  SET_MultTransposeMatrixfARB(disp, glMultTransposeMatrixfARB);
+  SET_MultiDrawArraysEXT(disp, glMultiDrawArraysEXT);
+  SET_MultiDrawElementsEXT(disp, glMultiDrawElementsEXT);
+//SET_MultiModeDrawArraysIBM(disp, glMultiModeDrawArraysIBM);
+//SET_MultiModeDrawElementsIBM(disp, glMultiModeDrawElementsIBM);
+  SET_MultiTexCoord1dARB(disp, glMultiTexCoord1dARB);
+  SET_MultiTexCoord1dvARB(disp, glMultiTexCoord1dvARB);
+  SET_MultiTexCoord1fARB(disp, glMultiTexCoord1fARB);
+  SET_MultiTexCoord1fvARB(disp, glMultiTexCoord1fvARB);
+  SET_MultiTexCoord1iARB(disp, glMultiTexCoord1iARB);
+  SET_MultiTexCoord1ivARB(disp, glMultiTexCoord1ivARB);
+  SET_MultiTexCoord1sARB(disp, glMultiTexCoord1sARB);
+  SET_MultiTexCoord1svARB(disp, glMultiTexCoord1svARB);
+  SET_MultiTexCoord2dARB(disp, glMultiTexCoord2dARB);
+  SET_MultiTexCoord2dvARB(disp, glMultiTexCoord2dvARB);
+  SET_MultiTexCoord2fARB(disp, glMultiTexCoord2fARB);
+  SET_MultiTexCoord2fvARB(disp, glMultiTexCoord2fvARB);
+  SET_MultiTexCoord2iARB(disp, glMultiTexCoord2iARB);
+  SET_MultiTexCoord2ivARB(disp, glMultiTexCoord2ivARB);
+  SET_MultiTexCoord2sARB(disp, glMultiTexCoord2sARB);
+  SET_MultiTexCoord2svARB(disp, glMultiTexCoord2svARB);
+  SET_MultiTexCoord3dARB(disp, glMultiTexCoord3dARB);
+  SET_MultiTexCoord3dvARB(disp, glMultiTexCoord3dvARB);
+  SET_MultiTexCoord3fARB(disp, glMultiTexCoord3fARB);
+  SET_MultiTexCoord3fvARB(disp, glMultiTexCoord3fvARB);
+  SET_MultiTexCoord3iARB(disp, glMultiTexCoord3iARB);
+  SET_MultiTexCoord3ivARB(disp, glMultiTexCoord3ivARB);
+  SET_MultiTexCoord3sARB(disp, glMultiTexCoord3sARB);
+  SET_MultiTexCoord3svARB(disp, glMultiTexCoord3svARB);
+  SET_MultiTexCoord4dARB(disp, glMultiTexCoord4dARB);
+  SET_MultiTexCoord4dvARB(disp, glMultiTexCoord4dvARB);
+  SET_MultiTexCoord4fARB(disp, glMultiTexCoord4fARB);
+  SET_MultiTexCoord4fvARB(disp, glMultiTexCoord4fvARB);
+  SET_MultiTexCoord4iARB(disp, glMultiTexCoord4iARB);
+  SET_MultiTexCoord4ivARB(disp, glMultiTexCoord4ivARB);
+  SET_MultiTexCoord4sARB(disp, glMultiTexCoord4sARB);
+  SET_MultiTexCoord4svARB(disp, glMultiTexCoord4svARB);
+  SET_NewList(disp, glNewList);
+  SET_Normal3b(disp, glNormal3b);
+  SET_Normal3bv(disp, glNormal3bv);
+  SET_Normal3d(disp, glNormal3d);
+  SET_Normal3dv(disp, glNormal3dv);
+  SET_Normal3f(disp, glNormal3f);
+  SET_Normal3fv(disp, glNormal3fv);
+  SET_Normal3i(disp, glNormal3i);
+  SET_Normal3iv(disp, glNormal3iv);
+  SET_Normal3s(disp, glNormal3s);
+  SET_Normal3sv(disp, glNormal3sv);
+  SET_NormalPointer(disp, glNormalPointer);
+//SET_NormalPointerEXT(disp, glNormalPointerEXT);
+  SET_Ortho(disp, glOrtho);
+//SET_PassTexCoordATI(disp, glPassTexCoordEXT);         // <-- EXT -> ATI
+  SET_PassThrough(disp, glPassThrough);
+  SET_PixelMapfv(disp, glPixelMapfv);
+  SET_PixelMapuiv(disp, glPixelMapuiv);
+  SET_PixelMapusv(disp, glPixelMapusv);
+  SET_PixelStoref(disp, glPixelStoref);
+  SET_PixelStorei(disp, glPixelStorei);
+//SET_PixelTexGenParameterfSGIS(disp, glPixelTexGenParameterfSGIS);
+//SET_PixelTexGenParameterfvSGIS(disp, glPixelTexGenParameterfvSGIS);
+//SET_PixelTexGenParameteriSGIS(disp, glPixelTexGenParameteriSGIS);
+//SET_PixelTexGenParameterivSGIS(disp, glPixelTexGenParameterivSGIS);
+//  SET_PixelTexGenSGIX(disp, glPixelTexGenSGIX);
+  SET_PixelTransferf(disp, glPixelTransferf);
+  SET_PixelTransferi(disp, glPixelTransferi);
+  SET_PixelZoom(disp, glPixelZoom);
+  SET_PointParameterfEXT(disp, glPointParameterfARB);      // <-- ARB -> EXT
+  SET_PointParameterfvEXT(disp, glPointParameterfvARB);    // <-- ARB -> EXT
+  SET_PointParameteriNV(disp, glPointParameteriNV);
+  SET_PointParameterivNV(disp, glPointParameterivNV);
+  SET_PointSize(disp, glPointSize);
+  SET_PolygonMode(disp, glPolygonMode);
+  SET_PolygonOffset(disp, glPolygonOffset);
+//SET_PolygonOffsetEXT(disp, glPolygonOffsetEXT);
+  SET_PolygonStipple(disp, glPolygonStipple);
+  SET_PopAttrib(disp, glPopAttrib);
+  SET_PopClientAttrib(disp, glPopClientAttrib);
+  SET_PopMatrix(disp, glPopMatrix);
+  SET_PopName(disp, glPopName);
+  SET_PrioritizeTextures(disp, glPrioritizeTextures);
+  SET_ProgramEnvParameter4dARB(disp, glProgramEnvParameter4dARB);
+  SET_ProgramEnvParameter4dvARB(disp, glProgramEnvParameter4dvARB);
+  SET_ProgramEnvParameter4fARB(disp, glProgramEnvParameter4fARB);
+  SET_ProgramEnvParameter4fvARB(disp, glProgramEnvParameter4fvARB);
+  SET_ProgramLocalParameter4dARB(disp, glProgramLocalParameter4dARB);
+  SET_ProgramLocalParameter4dvARB(disp, glProgramLocalParameter4dvARB);
+  SET_ProgramLocalParameter4fARB(disp, glProgramLocalParameter4fARB);
+  SET_ProgramLocalParameter4fvARB(disp, glProgramLocalParameter4fvARB);
+//SET_ProgramNamedParameter4dNV(disp, glProgramNamedParameter4dNV);
+//SET_ProgramNamedParameter4dvNV(disp, glProgramNamedParameter4dvNV);
+//SET_ProgramNamedParameter4fNV(disp, glProgramNamedParameter4fNV);
+//SET_ProgramNamedParameter4fvNV(disp, glProgramNamedParameter4fvNV);
+//SET_ProgramParameter4dNV(disp, glProgramParameter4dNV);
+//SET_ProgramParameter4dvNV(disp, glProgramParameter4dvNV);
+//SET_ProgramParameter4fNV(disp, glProgramParameter4fNV);
+//SET_ProgramParameter4fvNV(disp, glProgramParameter4fvNV);
+//SET_ProgramParameters4dvNV(disp, glProgramParameters4dvNV);
+//SET_ProgramParameters4fvNV(disp, glProgramParameters4fvNV);
+  SET_ProgramStringARB(disp, glProgramStringARB);
+  SET_PushAttrib(disp, glPushAttrib);
+  SET_PushClientAttrib(disp, glPushClientAttrib);
+  SET_PushMatrix(disp, glPushMatrix);
+  SET_PushName(disp, glPushName);
+  SET_RasterPos2d(disp, glRasterPos2d);
+  SET_RasterPos2dv(disp, glRasterPos2dv);
+  SET_RasterPos2f(disp, glRasterPos2f);
+  SET_RasterPos2fv(disp, glRasterPos2fv);
+  SET_RasterPos2i(disp, glRasterPos2i);
+  SET_RasterPos2iv(disp, glRasterPos2iv);
+  SET_RasterPos2s(disp, glRasterPos2s);
+  SET_RasterPos2sv(disp, glRasterPos2sv);
+  SET_RasterPos3d(disp, glRasterPos3d);
+  SET_RasterPos3dv(disp, glRasterPos3dv);
+  SET_RasterPos3f(disp, glRasterPos3f);
+  SET_RasterPos3fv(disp, glRasterPos3fv);
+  SET_RasterPos3i(disp, glRasterPos3i);
+  SET_RasterPos3iv(disp, glRasterPos3iv);
+  SET_RasterPos3s(disp, glRasterPos3s);
+  SET_RasterPos3sv(disp, glRasterPos3sv);
+  SET_RasterPos4d(disp, glRasterPos4d);
+  SET_RasterPos4dv(disp, glRasterPos4dv);
+  SET_RasterPos4f(disp, glRasterPos4f);
+  SET_RasterPos4fv(disp, glRasterPos4fv);
+  SET_RasterPos4i(disp, glRasterPos4i);
+  SET_RasterPos4iv(disp, glRasterPos4iv);
+  SET_RasterPos4s(disp, glRasterPos4s);
+  SET_RasterPos4sv(disp, glRasterPos4sv);
+  SET_ReadBuffer(disp, glReadBuffer);
+  SET_ReadPixels(disp, glReadPixels);
+  SET_Rectd(disp, glRectd);
+  SET_Rectdv(disp, glRectdv);
+  SET_Rectf(disp, glRectf);
+  SET_Rectfv(disp, glRectfv);
+  SET_Recti(disp, glRecti);
+  SET_Rectiv(disp, glRectiv);
+  SET_Rects(disp, glRects);
+  SET_Rectsv(disp, glRectsv);
+  SET_RenderMode(disp, glRenderMode);
+  SET_RenderbufferStorageEXT(disp, glRenderbufferStorageEXT);
+//SET_RequestResidentProgramsNV(disp, glRequestResidentProgramsNV);
+  SET_ResetHistogram(disp, glResetHistogram);
+  SET_ResetMinmax(disp, glResetMinmax);
+//SET_ResizeBuffersMESA(disp, glResizeBuffersMESA);
+  SET_Rotated(disp, glRotated);
+  SET_Rotatef(disp, glRotatef);
+  SET_SampleCoverageARB(disp, glSampleCoverageARB);
+//SET_SampleMapATI(disp, glSampleMapEXT);       // <-- EXT -> ATI
+//SET_SampleMaskSGIS(disp, glSampleMaskSGIS);
+//SET_SamplePatternSGIS(disp, glSamplePatternSGIS);
+  SET_Scaled(disp, glScaled);
+  SET_Scalef(disp, glScalef);
+  SET_Scissor(disp, glScissor);
+  SET_SecondaryColor3bEXT(disp, glSecondaryColor3bEXT);
+  SET_SecondaryColor3bvEXT(disp, glSecondaryColor3bvEXT);
+  SET_SecondaryColor3dEXT(disp, glSecondaryColor3dEXT);
+  SET_SecondaryColor3dvEXT(disp, glSecondaryColor3dvEXT);
+  SET_SecondaryColor3fEXT(disp, glSecondaryColor3fEXT);
+  SET_SecondaryColor3fvEXT(disp, glSecondaryColor3fvEXT);
+  SET_SecondaryColor3iEXT(disp, glSecondaryColor3iEXT);
+  SET_SecondaryColor3ivEXT(disp, glSecondaryColor3ivEXT);
+  SET_SecondaryColor3sEXT(disp, glSecondaryColor3sEXT);
+  SET_SecondaryColor3svEXT(disp, glSecondaryColor3svEXT);
+  SET_SecondaryColor3ubEXT(disp, glSecondaryColor3ubEXT);
+  SET_SecondaryColor3ubvEXT(disp, glSecondaryColor3ubvEXT);
+  SET_SecondaryColor3uiEXT(disp, glSecondaryColor3uiEXT);
+  SET_SecondaryColor3uivEXT(disp, glSecondaryColor3uivEXT);
+  SET_SecondaryColor3usEXT(disp, glSecondaryColor3usEXT);
+  SET_SecondaryColor3usvEXT(disp, glSecondaryColor3usvEXT);
+  SET_SecondaryColorPointerEXT(disp, glSecondaryColorPointerEXT);
+  SET_SelectBuffer(disp, glSelectBuffer);
+  SET_SeparableFilter2D(disp, glSeparableFilter2D);
+  SET_SetFenceNV(disp, glSetFenceAPPLE);  // <-- APPLE -> NV
+//SET_SetFragmentShaderConstantATI(disp, glSetFragmentShaderConstantEXT);   // <-- EXT -> ATI
+  SET_ShadeModel(disp, glShadeModel);
+  SET_ShaderSourceARB(disp, glShaderSourceARB);
+  SET_StencilFunc(disp, glStencilFunc);
+  SET_StencilFuncSeparate(disp, glStencilFuncSeparate);
+  SET_StencilMask(disp, glStencilMask);
+  SET_StencilMaskSeparate(disp, glStencilMaskSeparate);
+  SET_StencilOp(disp, glStencilOp);
+  SET_StencilOpSeparate(disp, glStencilOpSeparate);
+  SET_TestFenceNV(disp, glTestFenceAPPLE); // <-- APPLE -> NV
+  SET_TexCoord1d(disp, glTexCoord1d);
+  SET_TexCoord1dv(disp, glTexCoord1dv);
+  SET_TexCoord1f(disp, glTexCoord1f);
+  SET_TexCoord1fv(disp, glTexCoord1fv);
+  SET_TexCoord1i(disp, glTexCoord1i);
+  SET_TexCoord1iv(disp, glTexCoord1iv);
+  SET_TexCoord1s(disp, glTexCoord1s);
+  SET_TexCoord1sv(disp, glTexCoord1sv);
+  SET_TexCoord2d(disp, glTexCoord2d);
+  SET_TexCoord2dv(disp, glTexCoord2dv);
+  SET_TexCoord2f(disp, glTexCoord2f);
+  SET_TexCoord2fv(disp, glTexCoord2fv);
+  SET_TexCoord2i(disp, glTexCoord2i);
+  SET_TexCoord2iv(disp, glTexCoord2iv);
+  SET_TexCoord2s(disp, glTexCoord2s);
+  SET_TexCoord2sv(disp, glTexCoord2sv);
+  SET_TexCoord3d(disp, glTexCoord3d);
+  SET_TexCoord3dv(disp, glTexCoord3dv);
+  SET_TexCoord3f(disp, glTexCoord3f);
+  SET_TexCoord3fv(disp, glTexCoord3fv);
+  SET_TexCoord3i(disp, glTexCoord3i);
+  SET_TexCoord3iv(disp, glTexCoord3iv);
+  SET_TexCoord3s(disp, glTexCoord3s);
+  SET_TexCoord3sv(disp, glTexCoord3sv);
+  SET_TexCoord4d(disp, glTexCoord4d);
+  SET_TexCoord4dv(disp, glTexCoord4dv);
+  SET_TexCoord4f(disp, glTexCoord4f);
+  SET_TexCoord4fv(disp, glTexCoord4fv);
+  SET_TexCoord4i(disp, glTexCoord4i);
+  SET_TexCoord4iv(disp, glTexCoord4iv);
+  SET_TexCoord4s(disp, glTexCoord4s);
+  SET_TexCoord4sv(disp, glTexCoord4sv);
+  SET_TexCoordPointer(disp, glTexCoordPointer);
+//SET_TexCoordPointerEXT(disp, glTexCoordPointerEXT);
+  SET_TexEnvf(disp, glTexEnvf);
+  SET_TexEnvfv(disp, glTexEnvfv);
+  SET_TexEnvi(disp, glTexEnvi);
+  SET_TexEnviv(disp, glTexEnviv);
+  SET_TexGend(disp, glTexGend);
+  SET_TexGendv(disp, glTexGendv);
+  SET_TexGenf(disp, glTexGenf);
+  SET_TexGenfv(disp, glTexGenfv);
+  SET_TexGeni(disp, glTexGeni);
+  SET_TexGeniv(disp, glTexGeniv);
+  SET_TexImage1D(disp, glTexImage1D);
+  SET_TexImage2D(disp, glTexImage2D);
+  SET_TexImage3D(disp, glTexImage3D);
+  SET_TexParameterf(disp, glTexParameterf);
+  SET_TexParameterfv(disp, glTexParameterfv);
+  SET_TexParameteri(disp, glTexParameteri);
+  SET_TexParameteriv(disp, glTexParameteriv);
+  SET_TexSubImage1D(disp, glTexSubImage1D);
+  SET_TexSubImage2D(disp, glTexSubImage2D);
+  SET_TexSubImage3D(disp, glTexSubImage3D);
+//SET_TrackMatrixNV(disp, glTrackMatrixNV);
+  SET_Translated(disp, glTranslated);
+  SET_Translatef(disp, glTranslatef);
+  SET_Uniform1fARB(disp, glUniform1fARB);
+  SET_Uniform1fvARB(disp, glUniform1fvARB);
+  SET_Uniform1iARB(disp, glUniform1iARB);
+  SET_Uniform1ivARB(disp, glUniform1ivARB);
+  SET_Uniform2fARB(disp, glUniform2fARB);
+  SET_Uniform2fvARB(disp, glUniform2fvARB);
+  SET_Uniform2iARB(disp, glUniform2iARB);
+  SET_Uniform2ivARB(disp, glUniform2ivARB);
+  SET_Uniform3fARB(disp, glUniform3fARB);
+  SET_Uniform3fvARB(disp, glUniform3fvARB);
+  SET_Uniform3iARB(disp, glUniform3iARB);
+  SET_Uniform3ivARB(disp, glUniform3ivARB);
+  SET_Uniform4fARB(disp, glUniform4fARB);
+  SET_Uniform4fvARB(disp, glUniform4fvARB);
+  SET_Uniform4iARB(disp, glUniform4iARB);
+  SET_Uniform4ivARB(disp, glUniform4ivARB);
+  SET_UniformMatrix2fvARB(disp, glUniformMatrix2fvARB);
+  SET_UniformMatrix3fvARB(disp, glUniformMatrix3fvARB);
+  SET_UniformMatrix4fvARB(disp, glUniformMatrix4fvARB);
+  SET_UnlockArraysEXT(disp, glUnlockArraysEXT);
+  SET_UnmapBufferARB(disp, glUnmapBufferARB);
+  SET_UseProgramObjectARB(disp, glUseProgramObjectARB);
+  SET_ValidateProgramARB(disp, glValidateProgramARB);
+  SET_Vertex2d(disp, glVertex2d);
+  SET_Vertex2dv(disp, glVertex2dv);
+  SET_Vertex2f(disp, glVertex2f);
+  SET_Vertex2fv(disp, glVertex2fv);
+  SET_Vertex2i(disp, glVertex2i);
+  SET_Vertex2iv(disp, glVertex2iv);
+  SET_Vertex2s(disp, glVertex2s);
+  SET_Vertex2sv(disp, glVertex2sv);
+  SET_Vertex3d(disp, glVertex3d);
+  SET_Vertex3dv(disp, glVertex3dv);
+  SET_Vertex3f(disp, glVertex3f);
+  SET_Vertex3fv(disp, glVertex3fv);
+  SET_Vertex3i(disp, glVertex3i);
+  SET_Vertex3iv(disp, glVertex3iv);
+  SET_Vertex3s(disp, glVertex3s);
+  SET_Vertex3sv(disp, glVertex3sv);
+  SET_Vertex4d(disp, glVertex4d);
+  SET_Vertex4dv(disp, glVertex4dv);
+  SET_Vertex4f(disp, glVertex4f);
+  SET_Vertex4fv(disp, glVertex4fv);
+  SET_Vertex4i(disp, glVertex4i);
+  SET_Vertex4iv(disp, glVertex4iv);
+  SET_Vertex4s(disp, glVertex4s);
+  SET_Vertex4sv(disp, glVertex4sv);
+//SET_VertexArrayRangeNV(disp, glVertexArrayRangeNV);
+  SET_VertexAttrib1dARB(disp, glVertexAttrib1dARB);
+  SET_VertexAttrib1dvARB(disp, glVertexAttrib1dvARB);
+  SET_VertexAttrib1fARB(disp, glVertexAttrib1fARB);
+  SET_VertexAttrib1fvARB(disp, glVertexAttrib1fvARB);
+  SET_VertexAttrib1sARB(disp, glVertexAttrib1sARB);
+  SET_VertexAttrib1svARB(disp, glVertexAttrib1svARB);
+  SET_VertexAttrib2dARB(disp, glVertexAttrib2dARB);
+  SET_VertexAttrib2dvARB(disp, glVertexAttrib2dvARB);
+  SET_VertexAttrib2fARB(disp, glVertexAttrib2fARB);
+  SET_VertexAttrib2fvARB(disp, glVertexAttrib2fvARB);
+  SET_VertexAttrib2sARB(disp, glVertexAttrib2sARB);
+  SET_VertexAttrib2svARB(disp, glVertexAttrib2svARB);
+  SET_VertexAttrib3dARB(disp, glVertexAttrib3dARB);
+  SET_VertexAttrib3dvARB(disp, glVertexAttrib3dvARB);
+  SET_VertexAttrib3fARB(disp, glVertexAttrib3fARB);
+  SET_VertexAttrib3fvARB(disp, glVertexAttrib3fvARB);
+  SET_VertexAttrib3sARB(disp, glVertexAttrib3sARB);
+  SET_VertexAttrib3svARB(disp, glVertexAttrib3svARB);
+  SET_VertexAttrib4NbvARB(disp, glVertexAttrib4NbvARB);
+  SET_VertexAttrib4NivARB(disp, glVertexAttrib4NivARB);
+  SET_VertexAttrib4NsvARB(disp, glVertexAttrib4NsvARB);
+  SET_VertexAttrib4NubARB(disp, glVertexAttrib4NubARB);
+  SET_VertexAttrib4NubvARB(disp, glVertexAttrib4NubvARB);
+  SET_VertexAttrib4NuivARB(disp, glVertexAttrib4NuivARB);
+  SET_VertexAttrib4NusvARB(disp, glVertexAttrib4NusvARB);
+  SET_VertexAttrib4bvARB(disp, glVertexAttrib4bvARB);
+  SET_VertexAttrib4dARB(disp, glVertexAttrib4dARB);
+  SET_VertexAttrib4dvARB(disp, glVertexAttrib4dvARB);
+  SET_VertexAttrib4fARB(disp, glVertexAttrib4fARB);
+  SET_VertexAttrib4fvARB(disp, glVertexAttrib4fvARB);
+  SET_VertexAttrib4ivARB(disp, glVertexAttrib4ivARB);
+  SET_VertexAttrib4sARB(disp, glVertexAttrib4sARB);
+  SET_VertexAttrib4svARB(disp, glVertexAttrib4svARB);
+  SET_VertexAttrib4ubvARB(disp, glVertexAttrib4ubvARB);
+  SET_VertexAttrib4uivARB(disp, glVertexAttrib4uivARB);
+  SET_VertexAttrib4usvARB(disp, glVertexAttrib4usvARB);
+  SET_VertexAttribPointerARB(disp, glVertexAttribPointerARB);
+  SET_VertexPointer(disp, glVertexPointer);
+//  SET_VertexPointerEXT(disp, glVertexPointerEXT);
+  SET_Viewport(disp, glViewport);
+  SET_WindowPos2dMESA(disp, glWindowPos2dARB);
+  SET_WindowPos2dvMESA(disp, glWindowPos2dvARB);
+  SET_WindowPos2fMESA(disp, glWindowPos2fARB);
+  SET_WindowPos2fvMESA(disp, glWindowPos2fvARB);
+  SET_WindowPos2iMESA(disp, glWindowPos2iARB);
+  SET_WindowPos2ivMESA(disp, glWindowPos2ivARB);
+  SET_WindowPos2sMESA(disp, glWindowPos2sARB);
+  SET_WindowPos2svMESA(disp, glWindowPos2svARB);
+  SET_WindowPos3dMESA(disp, glWindowPos3dARB);
+  SET_WindowPos3dvMESA(disp, glWindowPos3dvARB);
+  SET_WindowPos3fMESA(disp, glWindowPos3fARB);
+  SET_WindowPos3fvMESA(disp, glWindowPos3fvARB);
+  SET_WindowPos3iMESA(disp, glWindowPos3iARB);
+  SET_WindowPos3ivMESA(disp, glWindowPos3ivARB);
+  SET_WindowPos3sMESA(disp, glWindowPos3sARB);
+  SET_WindowPos3svMESA(disp, glWindowPos3svARB);
+//SET_WindowPos4dMESA(disp, glWindowPos4dMESA);
+//SET_WindowPos4dvMESA(disp, glWindowPos4dvMESA);
+//SET_WindowPos4fMESA(disp, glWindowPos4fMESA);
+//SET_WindowPos4fvMESA(disp, glWindowPos4fvMESA);
+//SET_WindowPos4iMESA(disp, glWindowPos4iMESA);
+//SET_WindowPos4ivMESA(disp, glWindowPos4ivMESA);
+//SET_WindowPos4sMESA(disp, glWindowPos4sMESA);
+//SET_WindowPos4svMESA(disp, glWindowPos4svMESA);
+}
diff --git a/hw/xquartz/Makefile.am b/hw/xquartz/Makefile.am
index 1c97ac8..ccef5f6 100644
--- a/hw/xquartz/Makefile.am
+++ b/hw/xquartz/Makefile.am
@@ -13,8 +13,8 @@ if X11APP
 X11APP_SUBDIRS = bundle
 endif
 
-SUBDIRS = . xpr $(X11APP_SUBDIRS)
-DIST_SUBDIRS = xpr bundle
+SUBDIRS = . GL xpr $(X11APP_SUBDIRS)
+DIST_SUBDIRS = GL xpr bundle
 
 libXquartz_la_SOURCES = \
 	$(top_srcdir)/fb/fbcmap_mi.c \
commit b05b416c622063b84747702a54ffd9a802d6fc11
Author: Jeremy Huddleston <jeremyhu at freedesktop.org>
Date:   Wed Apr 23 09:59:48 2008 -0700

    XQuartz: No need to include indirect.c a second time
    (cherry picked from commit 41ed532525da85d1bd2c20af5ffa28ac6d1f4996)

diff --git a/hw/xquartz/xpr/Makefile.am b/hw/xquartz/xpr/Makefile.am
index d74cf7d..12009fb 100644
--- a/hw/xquartz/xpr/Makefile.am
+++ b/hw/xquartz/xpr/Makefile.am
@@ -14,7 +14,6 @@ Xquartz_SOURCES = \
 	xprEvent.c \
 	xprFrame.c \
 	xprScreen.c \
-	../../../GL/apple/indirect.c \
 	x-hash.c \
 	x-hook.c \
 	x-list.c
commit 565492c70a280d7e749500c5c0073bdcaf175c86
Author: Ben Byer <bbyer at apple.com>
Date:   Wed Apr 23 06:00:57 2008 -0700

    xquartz: build fixes for GLX/DRI2 fallout (note: not guaranteed)
    (cherry picked from commit 85a5796b667461bf1fafc68c07b3a704cd8efd5b)

diff --git a/GL/apple/indirect.c b/GL/apple/indirect.c
index 2729ab0..a0884d4 100644
--- a/GL/apple/indirect.c
+++ b/GL/apple/indirect.c
@@ -102,7 +102,7 @@ void warn_func(void * p1, char *format, ...);
 
 // some prototypes
 static __GLXscreen * __glXAquaScreenProbe(ScreenPtr pScreen);
-static __GLXdrawable * __glXAquaScreenCreateDrawable(__GLXscreen *screen, DrawablePtr pDraw, XID drawId, __GLcontextModes *modes);
+static __GLXdrawable * __glXAquaScreenCreateDrawable(__GLXscreen *screen, DrawablePtr pDraw, XID drawId, __GLXconfig *modes);
 
 static Bool glAquaInitVisuals(VisualPtr *visualp, DepthPtr *depthp,
                               int *nvisualp, int *ndepthp,
@@ -118,7 +118,7 @@ static int __glXAquaContextLoseCurrent(__GLXcontext *baseContext);
 static int __glXAquaContextForceCurrent(__GLXcontext *baseContext);
 static int __glXAquaContextCopy(__GLXcontext *baseDst, __GLXcontext *baseSrc, unsigned long mask);
 
-static CGLPixelFormatObj makeFormat(__GLcontextModes *mode);
+static CGLPixelFormatObj makeFormat(__GLXconfig *mode);
 
 __GLXprovider __glXMesaProvider = {
   __glXAquaScreenProbe,
@@ -141,7 +141,7 @@ struct __GLXAquaScreen {
   __GLXscreen   base;
   int           index;
     int num_vis;
-    __GLcontextModes *modes;
+    __GLXconfig *modes;
 };
 
 static __GLXAquaScreen glAquaScreens[MAXSCREENS];
@@ -162,7 +162,7 @@ struct __GLXAquaDrawable {
 
 static __GLXcontext *
 __glXAquaScreenCreateContext(__GLXscreen *screen,
-			     __GLcontextModes *modes,
+			     __GLXconfig *config,
 			     __GLXcontext *baseShareContext)
 {
   __GLXAquaContext *context;
@@ -177,7 +177,7 @@ __glXAquaScreenCreateContext(__GLXscreen *screen,
   memset(context, 0, sizeof *context);
 
   context->base.pGlxScreen = screen;
-  context->base.modes      = modes;
+  context->base.config      = config;
 
   context->base.destroy        = __glXAquaContextDestroy;
   context->base.makeCurrent    = __glXAquaContextMakeCurrent;
@@ -186,7 +186,7 @@ __glXAquaScreenCreateContext(__GLXscreen *screen,
   context->base.forceCurrent   = __glXAquaContextForceCurrent;
   //  context->base.createDrawable = __glXAquaContextCreateDrawable;
 
-  context->pixelFormat = makeFormat(modes);
+  context->pixelFormat = makeFormat(config);
   if (!context->pixelFormat) {
         free(context);
         return NULL;
@@ -437,7 +437,7 @@ static GLboolean __glXAquaDrawableSwapBuffers(__GLXdrawable *base) {
     return GL_TRUE;
 }
 
-static CGLPixelFormatObj makeFormat(__GLcontextModes *mode) {
+static CGLPixelFormatObj makeFormat(__GLXconfig *config) {
     int i;
     CGLPixelFormatAttribute attr[64]; // currently uses max of 30
     CGLPixelFormatObj result;
@@ -446,7 +446,7 @@ static CGLPixelFormatObj makeFormat(__GLcontextModes *mode) {
     
     GLAQUA_DEBUG_MSG("makeFormat\n");
 
-    if (!mode->rgbMode)
+    if (!config->rgbMode)
         return NULL;
 
     i = 0;
@@ -454,42 +454,43 @@ static CGLPixelFormatObj makeFormat(__GLcontextModes *mode) {
     // attr [i++] = kCGLPFAAcelerated; // require hwaccel - BAD for multiscreen
     // attr [i++] = kCGLPFANoRecovery; // disable fallback renderers - BAD
 
-    if (mode->stereoMode) {
+    if (config->stereoMode) {
         attr[i++] = kCGLPFAStereo;
     }
-    if (mode->doubleBufferMode) {
+
+    if (config->doubleBufferMode) {
         attr[i++] = kCGLPFADoubleBuffer;
     }
 
-    if (mode->colorIndexMode) {
+    if (config->colorIndexMode) {
         /* ignored */
     }
 
-    if (mode->rgbMode) {
+    if (config->rgbMode) {
         attr[i++] = kCGLPFAColorSize;
-        attr[i++] = mode->redBits + mode->greenBits + mode->blueBits;
+        attr[i++] = config->redBits + config->greenBits + config->blueBits;
         attr[i++] = kCGLPFAAlphaSize;
-        attr[i++] = 1; /* FIXME: ignoring mode->alphaBits which is always 0 */
+        attr[i++] = 1; /* FIXME: ignoring config->alphaBits which is always 0 */
     }
 
-    if (mode->haveAccumBuffer) {
+    if (config->haveAccumBuffer) {
         attr[i++] = kCGLPFAAccumSize;
-        attr[i++] = mode->accumRedBits + mode->accumGreenBits
-                    + mode->accumBlueBits + mode->accumAlphaBits;
+        attr[i++] = config->accumRedBits + config->accumGreenBits
+                    + config->accumBlueBits + config->accumAlphaBits;
     }
 	
-    if (mode->haveDepthBuffer) {
+    if (config->haveDepthBuffer) {
         attr[i++] = kCGLPFADepthSize;
-        attr[i++] = mode->depthBits;
+        attr[i++] = config->depthBits;
     }
 	
-    if (mode->haveStencilBuffer) {
+    if (config->haveStencilBuffer) {
         attr[i++] = kCGLPFAStencilSize;
-        attr[i++] = mode->stencilBits;
+        attr[i++] = config->stencilBits;
     }
 
     attr[i++] = kCGLPFAAuxBuffers;
-    attr[i++] = mode->numAuxBuffers;
+    attr[i++] = config->numAuxBuffers;
 
     /* mode->level ignored */
 
@@ -670,7 +671,7 @@ static Bool init_visuals(int *nvisualp, VisualPtr *visualp,
     VisualPtr pVisual = *visualp;
     VisualPtr pVisualNew = NULL;
     VisualID *orig_vid = NULL;
-    __GLcontextModes *modes;
+    __GLXconfig *modes;
     __GLXvisualConfig *pNewVisualConfigs = NULL;
     void **glXVisualPriv;
     void **pNewVisualPriv;
@@ -752,7 +753,7 @@ static Bool init_visuals(int *nvisualp, VisualPtr *visualp,
     }
 
     /* Alloc space for the list of glXVisuals */
-    modes = _gl_context_modes_create(numNewVisuals, sizeof(__GLcontextModes));
+    modes = _gl_context_modes_create(numNewVisuals, sizeof(__GLXconfig));
     if (modes == NULL) {
         free(orig_vid);
         free(pNewVisualPriv);
@@ -925,6 +926,7 @@ Bool enable_stereo = FALSE;
 /* based on code in i830_dri.c
    This ends calling glAquaSetVisualConfigs to set the static
    numconfigs, etc. */
+// see also glxglcore.c -- bhb
 static void
 glAquaInitVisualConfigs(void)
 {
@@ -1085,7 +1087,7 @@ static void __glXAquaScreenDestroy(__GLXscreen *screen) {
 static void init_screen_visuals(__GLXAquaScreen *screen) {
   ScreenPtr pScreen = screen->base.pScreen;
   
-  __GLcontextModes *modes;
+  __GLXconfig *modes;
   int *used;
   int i, j;
   
@@ -1101,7 +1103,7 @@ static void init_screen_visuals(__GLXAquaScreen *screen) {
     memset(used, 0, pScreen->numVisuals * sizeof(int));
 
     i = 0;
-    for ( modes = screen -> base.modes
+    for ( modes = screen -> base.visuals
           ; modes != NULL
           ; modes = modes->next ) {
         const int vis_class = _gl_convert_to_x_visual_type( modes->visualType );
@@ -1174,7 +1176,7 @@ static __GLXdrawable *
 __glXAquaScreenCreateDrawable(__GLXscreen *screen,
 			      DrawablePtr pDraw,
 			      XID drawId,
-			      __GLcontextModes *modes) {
+			      __GLXconfig *modes) {
   __GLXAquaDrawable *glxPriv;
 
   GLAQUA_DEBUG_MSG("glAquaScreenCreateDrawable(%p,%p,%d,%p)\n", context, pDraw, drawId, modes);
@@ -1184,7 +1186,7 @@ __glXAquaScreenCreateDrawable(__GLXscreen *screen,
 
   memset(glxPriv, 0, sizeof *glxPriv);
 
-  if (!__glXDrawableInit(&glxPriv->base, screen, pDraw, drawId, modes)) {
+  if (!__glXDrawableInit(&glxPriv->base, screen, pDraw, GLX_DRAWABLE_PIXMAP /*?*/, drawId, modes)) {
     xfree(glxPriv);
     return NULL;
   }
commit 6f6505db51763d902142a8161e71cad44f52560c
Author: Ben Byer <bbyer at apple.com>
Date:   Wed Apr 23 03:43:51 2008 -0700

    glx / xquartz:  we still need glxcontentmodes.[ch] kthx
    (cherry picked from commit 27545fd37f8c703b72f7cfc329778abc1ceabfa0)

diff --git a/GL/symlink-mesa.sh b/GL/symlink-mesa.sh
index 8deaa43..def4f63 100755
--- a/GL/symlink-mesa.sh
+++ b/GL/symlink-mesa.sh
@@ -64,6 +64,8 @@ symlink_glx() {
     dst_dir glx
 
     action indirect_size.h
+    action glcontextmodes.c
+    action glcontextmodes.h
     action indirect_dispatch.c
     action indirect_dispatch.h
     action indirect_dispatch_swap.c
commit 4e3a8af5751ff88c0cadd612821b0ef349d250c5
Author: Ben Byer <bbyer at apple.com>
Date:   Wed Apr 23 03:39:41 2008 -0700

    xquartz: clean up linker line for main binary
    (cherry picked from commit 821d7400f2ff917497b2ee58ceef2b69c2d47ec7)

diff --git a/hw/xquartz/xpr/Makefile.am b/hw/xquartz/xpr/Makefile.am
index 6007423..d74cf7d 100644
--- a/hw/xquartz/xpr/Makefile.am
+++ b/hw/xquartz/xpr/Makefile.am
@@ -14,6 +14,7 @@ Xquartz_SOURCES = \
 	xprEvent.c \
 	xprFrame.c \
 	xprScreen.c \
+	../../../GL/apple/indirect.c \
 	x-hash.c \
 	x-hook.c \
 	x-list.c
@@ -21,23 +22,6 @@ Xquartz_SOURCES = \
 Xquartz_LDADD = \
 	$(top_builddir)/hw/xquartz/libXquartz.la \
 	$(top_builddir)/dix/dixfonts.lo \
-	$(top_builddir)/config/libconfig.a \
-	$(top_builddir)/dix/libdix.la \
-	$(top_builddir)/os/libos.la \
-	$(top_builddir)/dix/libxpstubs.la \
-	$(top_builddir)/miext/shadow/libshadow.la \
-	$(top_builddir)/fb/libfb.la \
-	$(top_builddir)/mi/libmi.la \
-	$(top_builddir)/damageext/libdamageext.la \
-	$(top_builddir)/miext/damage/libdamage.la \
-	$(top_builddir)/xfixes/libxfixes.la \
-	$(top_builddir)/Xext/libXext.la \
-	$(top_builddir)/xkb/libxkb.la \
-	$(top_builddir)/xkb/libxkbstubs.la \
-	$(top_builddir)/Xi/libXi.la \
-	$(top_builddir)/dbe/libdbe.la \
-	$(top_builddir)/record/librecord.la \
-	$(top_builddir)/XTrap/libxtrap.la \
 	$(top_builddir)/miext/rootless/librootless.la \
 	$(DARWIN_LIBS) $(XSERVER_LIBS) $(XSERVER_SYS_LIBS) -lXplugin
 
commit 3685b171da51f853bfdb312d36622dfa03ee75be
Author: Ben Byer <bbyer at apple.com>
Date:   Tue Apr 22 23:53:23 2008 -0700

    xquartz: remove vestigial aglGlx.c
    (cherry picked from commit 40bd041e4255f26fcbdf0831e68619ae0f46ab39)

diff --git a/GL/apple/Makefile.am b/GL/apple/Makefile.am
index c064c03..7ad9140 100644
--- a/GL/apple/Makefile.am
+++ b/GL/apple/Makefile.am
@@ -8,17 +8,7 @@ AM_CPPFLAGS = \
 	-I$(top_srcdir)/hw/xquartz/xpr \
 	-I$(top_srcdir)/miext/damage
 
-if HAVE_AGL_FRAMEWORK
-noinst_LIBRARIES = libAGLcore.a 
-libAGLcore_a_SOURCES = aglGlx.c \
-		       $(top_srcdir)/hw/xquartz/xpr/x-list.c \
-		       $(top_srcdir)/hw/xquartz/xpr/x-list.h \
-		       $(top_srcdir)/hw/xquartz/xpr/x-hash.c \
-		       $(top_srcdir)/hw/xquartz/xpr/x-hash.h \
-		       $(top_srcdir)/hw/dmx/glxProxy/compsize.c
-endif
-
-#noinst_LIBRARIES = libCGLcore.a 
-#libCGLcore_a_SOURCES = \
-#	indirect.c \
-#	$(top_srcdir)/hw/dmx/glxProxy/compsize.c
+noinst_LIBRARIES = libCGLcore.a 
+libCGLcore_a_SOURCES = \
+	indirect.c \
+	$(top_srcdir)/hw/dmx/glxProxy/compsize.c
diff --git a/GL/apple/aglGlx.c b/GL/apple/aglGlx.c
deleted file mode 100644
index 900a9a9..0000000
--- a/GL/apple/aglGlx.c
+++ /dev/null
@@ -1,1354 +0,0 @@
-/*
- * GLX implementation that uses Apple's AGL.framework for OpenGL
- *
- * FIXME: This file and indirect.c are very similar. The two should be
- * merged by introducing suitable abstractions.
- */
-/*
- * Copyright (c) 2002 Greg Parker. All Rights Reserved.
- * Copyright (c) 2004 Torrey T. Lyons. All Rights Reserved.
- *
- * Large portions of this file are copied from Mesa's xf86glx.c,
- * which contains the following copyright:
- *
- * Copyright 1998-1999 Precision Insight, Inc., Cedar Park, Texas.
- * All Rights Reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, 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.
- */
-
-#ifdef HAVE_DIX_CONFIG_H
-#include <dix-config.h>
-#endif
-
-#include "quartzCommon.h"
-#include <AGL/agl.h>
-#include "cr.h"
-
-// X11 and X11's glx
-#undef BOOL
-#define BOOL xBOOL
-#include "quartz.h"
-#include <miscstruct.h>
-#include <windowstr.h>
-#include <resource.h>
-#include <GL/glxint.h>
-#include <GL/glxtokens.h>
-#include <scrnintstr.h>
-#include <glxserver.h>
-#include <glxscreens.h>
-#include <glxdrawable.h>
-#include <glxcontext.h>
-#include <glxext.h>
-#include <glxutil.h>
-#include <glxscreens.h>
-#include <GL/internal/glcore.h>
-#undef BOOL
-
-#include "glcontextmodes.h"
-
-// ggs: needed to call back to glx with visual configs
-extern void GlxSetVisualConfigs(int nconfigs, __GLXvisualConfig *configs, void **configprivs);
-
-// Write debugging output, or not
-#ifdef GLAQUA_DEBUG
-#define GLAQUA_DEBUG_MSG ErrorF
-#else
-#define GLAQUA_DEBUG_MSG(a, ...)
-#endif
-
-
-// The following GL functions don't have an EXT suffix in OpenGL.framework.
-GLboolean glAreTexturesResidentEXT (GLsizei a, const GLuint *b, GLboolean *c) {
-    return glAreTexturesResident(a, b, c);
-}
-void glDeleteTexturesEXT (GLsizei d, const GLuint *e) {
-    glDeleteTextures(d, e);
-}
-void glGenTexturesEXT (GLsizei f, GLuint *g) {
-    glGenTextures(f, g);
-}
-GLboolean glIsTextureEXT (GLuint h) {
-    return glIsTexture(h);
-}
-
-
-// some prototypes
-static Bool glAquaScreenProbe(int screen);
-static Bool glAquaInitVisuals(VisualPtr *visualp, DepthPtr *depthp,
-                              int *nvisualp, int *ndepthp,
-                              int *rootDepthp, VisualID *defaultVisp,
-                              unsigned long sizes, int bitsPerRGB);
-static void glAquaSetVisualConfigs(int nconfigs, __GLXvisualConfig *configs,
-                                   void **privates);
-static __GLinterface *glAquaCreateContext(__GLimports *imports,
-                                          __GLcontextModes *mode,
-                                          __GLinterface *shareGC);
-static void glAquaCreateBuffer(__GLXdrawablePrivate *glxPriv);
-static void glAquaResetExtension(void);
-
-
-/*
- * This structure is statically allocated in the __glXScreens[]
- * structure.  This struct is not used anywhere other than in
- * __glXScreenInit to initialize each of the active screens
- * (__glXActiveScreens[]).  Several of the fields must be initialized by
- * the screenProbe routine before they are copied to the active screens
- * struct.  In particular, the contextCreate, modes, numVisuals,
- * and numUsableVisuals fields must be initialized.
- */
-static __GLXscreenInfo __glDDXScreenInfo = {
-    glAquaScreenProbe,   /* Must be generic and handle all screens */
-    glAquaCreateContext, /* Substitute screen's createContext routine */
-    glAquaCreateBuffer,  /* Substitute screen's createBuffer routine */
-    NULL,                 /* Set up modes in probe */
-    NULL,                 /* Set up pVisualPriv in probe */
-    0,                    /* Set up numVisuals in probe */
-    0,                    /* Set up numUsableVisuals in probe */
-    "Vendor String",      /* GLXvendor is overwritten by __glXScreenInit */
-    "Version String",     /* GLXversion is overwritten by __glXScreenInit */
-    "Extensions String",  /* GLXextensions is overwritten by __glXScreenInit */
-    NULL                  /* WrappedPositionWindow is overwritten */
-};
-
-void *__glXglDDXScreenInfo(void) {
-    return &__glDDXScreenInfo;
-}
-
-static __GLXextensionInfo __glDDXExtensionInfo = {
-    GL_CORE_APPLE,
-    glAquaResetExtension,
-    glAquaInitVisuals,
-    glAquaSetVisualConfigs
-};
-
-void *__glXglDDXExtensionInfo(void) {
-    return &__glDDXExtensionInfo;
-}
-
-// prototypes
-
-static GLboolean glAquaDestroyContext(__GLcontext *gc);
-static GLboolean glAquaLoseCurrent(__GLcontext *gc);
-static GLboolean glAquaMakeCurrent(__GLcontext *gc);
-static GLboolean glAquaShareContext(__GLcontext *gc, __GLcontext *gcShare);
-static GLboolean glAquaCopyContext(__GLcontext *dst, const __GLcontext *src,
-                                    GLuint mask);
-static GLboolean glAquaForceCurrent(__GLcontext *gc);
-
-/* Drawing surface notification callbacks */
-static GLboolean glAquaNotifyResize(__GLcontext *gc);
-static void glAquaNotifyDestroy(__GLcontext *gc);
-static void glAquaNotifySwapBuffers(__GLcontext *gc);
-
-/* Dispatch table override control for external agents like libGLS */
-static struct __GLdispatchStateRec* glAquaDispatchExec(__GLcontext *gc);
-static void glAquaBeginDispatchOverride(__GLcontext *gc);
-static void glAquaEndDispatchOverride(__GLcontext *gc);
-
-
-static __GLexports glAquaExports = {
-    glAquaDestroyContext,
-    glAquaLoseCurrent,
-    glAquaMakeCurrent,
-    glAquaShareContext,
-    glAquaCopyContext,
-    glAquaForceCurrent,
-
-    glAquaNotifyResize,
-    glAquaNotifyDestroy,
-    glAquaNotifySwapBuffers,
-
-    glAquaDispatchExec,
-    glAquaBeginDispatchOverride,
-    glAquaEndDispatchOverride
-};
-
-
-typedef struct {
-    int num_vis;
-    __GLcontextModes *modes;
-    void **priv;
-
-    // wrapped screen functions
-    RealizeWindowProcPtr RealizeWindow;
-    UnrealizeWindowProcPtr UnrealizeWindow;
-} glAquaScreenRec;
-
-static glAquaScreenRec glAquaScreens[MAXSCREENS];
-
-
-// __GLdrawablePrivate->private
-typedef struct {
-    GLboolean (*resize)(__GLdrawableBuffer *buf, GLint x, GLint y,
-                        GLuint width, GLuint height,
-                        __GLdrawablePrivate *glPriv,
-                        GLuint bufferMask);
-} GLAquaDrawableRec;
-
-struct __GLcontextRec {
-  struct __GLinterfaceRec interface; // required to be first
-
-  AGLContext ctx;
-  AGLPixelFormat pixelFormat;
-
-  Bool isAttached; // TRUE if ctx is really attached to a window
-};
-
-
-// Context manipulation; return GL_FALSE on failure
-static GLboolean glAquaDestroyContext(__GLcontext *gc)
-{
-    GLAQUA_DEBUG_MSG("glAquaDestroyContext (ctx 0x%x)\n", gc->ctx);
-
-    if (gc) {
-        if (gc->ctx) aglDestroyContext(gc->ctx);
-        if (gc->pixelFormat) aglDestroyPixelFormat(gc->pixelFormat);
-        free(gc);
-    }
-
-    return GL_TRUE;
-}
-
-
-static GLboolean glAquaLoseCurrent(__GLcontext *gc)
-{
-    GLAQUA_DEBUG_MSG("glAquaLoseCurrent (ctx 0x%x)\n", gc->ctx);
-
-    aglSetCurrentContext(NULL);
-    __glXLastContext = NULL; // Mesa does this; why?
-    gc->isAttached = FALSE;
-
-    return GL_TRUE;
-}
-
-
-/*
- * Attach a GL context to a GL drawable
- * If glPriv is NULL, the context is detached.
- */
-static void attach(__GLcontext *gc, __GLdrawablePrivate *glPriv)
-{
-    __GLXdrawablePrivate *glxPriv;
-
-    if (glPriv == NULL) {
-        // attaching to nothing
-        GLAQUA_DEBUG_MSG("unattaching\n");
-        aglSetDrawable(gc->ctx, NULL);
-        gc->isAttached = FALSE;
-        return;
-    }
-
-    // Note that when resizing, the X11 WindowPtr already has its
-    // new size and position, but the Aqua window does not.
-
-    glxPriv = (__GLXdrawablePrivate *)glPriv->other;
-
-    if (glxPriv->type == DRAWABLE_WINDOW) {
-        WindowPtr pWin = (WindowPtr) glxPriv->pDraw;
-        WindowPtr topWin = quartzProcs->TopLevelParent(pWin);
-        CRWindowPtr crWinPtr;
-        AGLDrawable newPort;
-
-        if (glPriv->width <= 0 || glPriv->height <= 0) {
-            // attach to zero size drawable - will really attach later
-            GLAQUA_DEBUG_MSG("couldn't attach to zero size drawable\n");
-            aglSetDrawable(gc->ctx, NULL);
-            gc->isAttached = FALSE;
-            return;
-        }
-
-        crWinPtr = (CRWindowPtr) quartzProcs->FrameForWindow(pWin, FALSE);
-
-        if (crWinPtr) {
-            newPort = (AGLDrawable) crWinPtr->port;
-        } else {
-            newPort = NULL;
-        }
-
-        if (newPort) {
-            // FIXME: won't be a CGrafPtr if currently offscreen or fullscreen
-            AGLDrawable oldPort = aglGetDrawable(gc->ctx);
-            // AGLDrawable newPort = GetWindowPort(window);
-
-            // Frame is GLdrawable in X11 global coordinates
-            // FIXME: Does this work for multiple screens?
-            GLint frame[4] = {glPriv->xOrigin, glPriv->yOrigin, glPriv->width, glPriv->height};
-            GLAQUA_DEBUG_MSG("global size %d %d %d %d\n",
-                             frame[0], frame[1], frame[2], frame[3]);
-
-            // Convert to window-local coordinates
-            frame[0] -= topWin->drawable.x - topWin->borderWidth;
-            frame[1] -= topWin->drawable.y - topWin->borderWidth;
-
-            // AGL uses flipped coordinates
-            frame[1] = topWin->drawable.height + 2*topWin->borderWidth -
-                       frame[1] - frame[3];
-
-            GLAQUA_DEBUG_MSG("local size %d %d %d %d\n",
-                             frame[0], frame[1], frame[2], frame[3]);
-
-            if (oldPort != newPort) {
-                // FIXME: retain/release windows
-                if (!aglSetDrawable(gc->ctx, newPort)) return;
-            }
-            if (!aglSetInteger(gc->ctx, AGL_BUFFER_RECT, frame)) return;
-            if (!aglEnable(gc->ctx, AGL_BUFFER_RECT)) return;
-            if (!aglSetInteger(gc->ctx, AGL_SWAP_RECT, frame)) return;
-            if (!aglEnable(gc->ctx, AGL_SWAP_RECT)) return;
-            if (!aglUpdateContext(gc->ctx)) return;
-
-            gc->isAttached = TRUE;
-            GLAQUA_DEBUG_MSG("attached context 0x%x to window 0x%x\n", gc->ctx,
-                             pWin->drawable.id);
-        } else {
-            // attach to not-yet-realized window - will really attach later
-            GLAQUA_DEBUG_MSG("couldn't attach to unrealized window\n");
-            aglSetDrawable(gc->ctx, NULL);
-            gc->isAttached = FALSE;
-        }
-    } else {
-        GLAQUA_DEBUG_MSG("attach: attach to non-window unimplemented\n");
-        aglSetDrawable(gc->ctx, NULL);
-        gc->isAttached = FALSE;
-    }
-}
-
-static GLboolean glAquaMakeCurrent(__GLcontext *gc)
-{
-    __GLdrawablePrivate *glPriv = gc->interface.imports.getDrawablePrivate(gc);
-
-    GLAQUA_DEBUG_MSG("glAquaMakeCurrent (ctx 0x%x)\n", gc->ctx);
-
-    if (!gc->isAttached) {
-        attach(gc, glPriv);
-    }
-
-    return aglSetCurrentContext(gc->ctx);
-}
-
-static GLboolean glAquaShareContext(__GLcontext *gc, __GLcontext *gcShare)
-{
-  GLAQUA_DEBUG_MSG("glAquaShareContext unimplemented\n");
-
-  return GL_TRUE;
-}
-
-
-static GLboolean glAquaCopyContext(__GLcontext *dst, const __GLcontext *src,
-                                   GLuint mask)
-{
-  GLAQUA_DEBUG_MSG("glAquaCopyContext\n");
-
-    return aglCopyContext(src->ctx, dst->ctx, mask);
-}
-
-static GLboolean glAquaForceCurrent(__GLcontext *gc)
-{
-    //     GLAQUA_DEBUG_MSG("glAquaForceCurrent (ctx 0x%x)\n", gc->ctx);
-    return aglSetCurrentContext(gc->ctx);
-}
-
-/* Drawing surface notification callbacks */
-
-static GLboolean glAquaNotifyResize(__GLcontext *gc)
-{
-    GLAQUA_DEBUG_MSG("unimplemented glAquaNotifyResize");
-    return GL_TRUE;
-}
-
-static void glAquaNotifyDestroy(__GLcontext *gc)
-{
-    GLAQUA_DEBUG_MSG("unimplemented glAquaNotifyDestroy");
-}
-
-static void glAquaNotifySwapBuffers(__GLcontext *gc)
-{
-    GLAQUA_DEBUG_MSG("unimplemented glAquaNotifySwapBuffers");
-}
-
-/* Dispatch table override control for external agents like libGLS */
-static struct __GLdispatchStateRec* glAquaDispatchExec(__GLcontext *gc)
-{
-    GLAQUA_DEBUG_MSG("unimplemented glAquaDispatchExec");
-    return NULL;
-}
-
-static void glAquaBeginDispatchOverride(__GLcontext *gc)
-{
-    GLAQUA_DEBUG_MSG("unimplemented glAquaBeginDispatchOverride");
-}
-
-static void glAquaEndDispatchOverride(__GLcontext *gc)
-{
-    GLAQUA_DEBUG_MSG("unimplemented glAquaEndDispatchOverride");
-}
-
-
-static AGLPixelFormat makeFormat(__GLcontextModes *mode)
-{
-    int i;
-    GLint attr[64]; // currently uses max of 30
-    AGLPixelFormat result;
-
-    GLAQUA_DEBUG_MSG("makeFormat\n");
-
-    i = 0;
-
-    // attr [i++] = AGL_ACCELERATED; // require hwaccel - BAD for multiscreen
-    // attr [i++] = AGL_NO_RECOVERY; // disable fallback renderers - BAD
-
-    if (mode->stereoMode) {
-        attr[i++] = AGL_STEREO;
-    }
-    if (mode->doubleBufferMode) {
-        attr[i++] = AGL_DOUBLEBUFFER;
-    }
-
-    if (mode->colorIndexMode) {
-        attr[i++] = AGL_BUFFER_SIZE;
-        attr[i++] = mode->indexBits;
-    }
-
-    if (mode->rgbMode) {
-        attr[i++] = AGL_RGBA;
-        attr[i++] = AGL_RED_SIZE;
-        attr[i++] = mode->redBits;
-        attr[i++] = AGL_GREEN_SIZE;
-        attr[i++] = mode->greenBits;
-        attr[i++] = AGL_BLUE_SIZE;
-        attr[i++] = mode->blueBits;
-        attr[i++] = AGL_ALPHA_SIZE;
-        attr[i++] = mode->alphaBits;
-    }
-
-    if (mode->haveAccumBuffer) {
-        attr[i++] = AGL_ACCUM_RED_SIZE;
-        attr[i++] = mode->accumRedBits;
-        attr[i++] = AGL_ACCUM_GREEN_SIZE;
-        attr[i++] = mode->accumGreenBits;
-        attr[i++] = AGL_ACCUM_BLUE_SIZE;
-        attr[i++] = mode->accumBlueBits;
-        attr[i++] = AGL_ACCUM_ALPHA_SIZE;
-        attr[i++] = mode->accumAlphaBits;
-    }
-    if (mode->haveDepthBuffer) {
-        attr[i++] = AGL_DEPTH_SIZE;
-        attr[i++] = mode->depthBits;
-    }
-    if (mode->haveStencilBuffer) {
-        attr[i++] = AGL_STENCIL_SIZE;
-        attr[i++] = mode->stencilBits;
-    }
-
-    attr[i++] = AGL_AUX_BUFFERS;
-    attr[i++] = mode->numAuxBuffers;
-
-    attr[i++] = AGL_LEVEL;
-    attr[i++] = mode->level;
-
-    // mode->pixmapMode ?
-
-    attr[i++] = AGL_NONE; // end of option list
-
-    GLAQUA_DEBUG_MSG("makeFormat almost done\n");
-    result = aglChoosePixelFormat(NULL, 0, attr);
-    GLAQUA_DEBUG_MSG("makeFormat done (0x%x)\n", result);
-    return result;
-}
-
-static __GLinterface *glAquaCreateContext(__GLimports *imports,
-                                          __GLcontextModes *mode,
-                                          __GLinterface *shareGC)
-{
-    __GLcontext *result;
-    __GLcontext *sharectx = (__GLcontext *)shareGC;
-
-    GLAQUA_DEBUG_MSG("glAquaCreateContext\n");
-
-    result = (__GLcontext *)calloc(1, sizeof(__GLcontext));
-    if (!result) return NULL;
-
-    result->interface.imports = *imports;
-    result->interface.exports = glAquaExports;
-
-    result->pixelFormat = makeFormat(mode);
-    if (!result->pixelFormat) {
-        free(result);
-        return NULL;
-    }
-
-    result->ctx = aglCreateContext(result->pixelFormat,
-                        (sharectx && sharectx->ctx) ? sharectx->ctx : NULL);
-
-    if (!result->ctx) {
-        aglDestroyPixelFormat(result->pixelFormat);
-        free(result);
-        return NULL;
-    }
-
-    result->isAttached = FALSE;
-
-    GLAQUA_DEBUG_MSG("glAquaCreateContext done\n");
-    return (__GLinterface *)result;
-}
-
-
-Bool
-glAquaRealizeWindow(WindowPtr pWin)
-{
-    // If this window has GL contexts, tell them to reattach
-    Bool result;
-    ScreenPtr pScreen = pWin->drawable.pScreen;
-    glAquaScreenRec *screenPriv = &glAquaScreens[pScreen->myNum];
-    __GLXdrawablePrivate *glxPriv;
-
-    GLAQUA_DEBUG_MSG("glAquaRealizeWindow\n");
-
-    // Allow the window to be created (RootlessRealizeWindow is inside our wrap)
-    pScreen->RealizeWindow = screenPriv->RealizeWindow;
-    result = pScreen->RealizeWindow(pWin);
-    pScreen->RealizeWindow = glAquaRealizeWindow;
-
-    // The Aqua window will already have been created (windows are
-    // realized from top down)
-
-    // Re-attach this window's GL contexts, if any.
-    glxPriv = __glXFindDrawablePrivate(pWin->drawable.id);
-    if (glxPriv) {
-        __GLXcontext *gx;
-        __GLcontext *gc;
-        __GLdrawablePrivate *glPriv = &glxPriv->glPriv;
-        GLAQUA_DEBUG_MSG("glAquaRealizeWindow is GL drawable!\n");
-
-        // GL contexts bound to this window for drawing
-        for (gx = glxPriv->drawGlxc; gx != NULL; gx = gx->nextDrawPriv) {
-            gc = (__GLcontext *)gx->gc;
-            attach(gc, glPriv);
-        }
-
-        // GL contexts bound to this window for reading
-        for (gx = glxPriv->readGlxc; gx != NULL; gx = gx->nextReadPriv) {
-            gc = (__GLcontext *)gx->gc;
-            attach(gc, glPriv);
-        }
-    }
-
-    return result;
-}
-
-Bool
-glAquaUnrealizeWindow(WindowPtr pWin)
-{
-    // If this window has GL contexts, tell them to unattach
-    Bool result;
-    ScreenPtr pScreen = pWin->drawable.pScreen;
-    glAquaScreenRec *screenPriv = &glAquaScreens[pScreen->myNum];
-    __GLXdrawablePrivate *glxPriv;
-
-    GLAQUA_DEBUG_MSG("glAquaUnrealizeWindow\n");
-
-    // The Aqua window may have already been destroyed (windows
-    // are unrealized from top down)
-
-    // Unattach this window's GL contexts, if any.
-    glxPriv = __glXFindDrawablePrivate(pWin->drawable.id);
-    if (glxPriv) {
-        __GLXcontext *gx;
-        __GLcontext *gc;
-        GLAQUA_DEBUG_MSG("glAquaUnealizeWindow is GL drawable!\n");
-
-        // GL contexts bound to this window for drawing
-        for (gx = glxPriv->drawGlxc; gx != NULL; gx = gx->nextDrawPriv) {
-            gc = (__GLcontext *)gx->gc;
-            attach(gc, NULL);
-        }
-
-        // GL contexts bound to this window for reading
-        for (gx = glxPriv->readGlxc; gx != NULL; gx = gx->nextReadPriv) {
-            gc = (__GLcontext *)gx->gc;
-            attach(gc, NULL);
-        }
-    }
-
-    pScreen->UnrealizeWindow = screenPriv->UnrealizeWindow;
-    result = pScreen->UnrealizeWindow(pWin);
-    pScreen->UnrealizeWindow = glAquaUnrealizeWindow;
-
-    return result;
-}
-
-
-// Originally copied from Mesa
-
-static int                 numConfigs     = 0;
-static __GLXvisualConfig  *visualConfigs  = NULL;
-static void              **visualPrivates = NULL;
-
-/*
- * In the case the driver defines no GLX visuals we'll use these.
- * Note that for TrueColor and DirectColor visuals, bufferSize is the 
- * sum of redSize, greenSize, blueSize and alphaSize, which may be larger 
- * than the nplanes/rootDepth of the server's X11 visuals
- */
-#define NUM_FALLBACK_CONFIGS 5
-static __GLXvisualConfig FallbackConfigs[NUM_FALLBACK_CONFIGS] = {
-  /* [0] = RGB, double buffered, Z */
-  {
-    -1,                 /* vid */
-    -1,                 /* class */
-    True,               /* rgba */
-    -1, -1, -1, 0,      /* rgba sizes */
-    -1, -1, -1, 0,      /* rgba masks */
-     0,  0,  0, 0,      /* rgba accum sizes */
-    True,               /* doubleBuffer */
-    False,              /* stereo */
-    -1,                 /* bufferSize */
-    16,                 /* depthSize */
-    0,                  /* stencilSize */
-    0,                  /* auxBuffers */
-    0,                  /* level */
-    GLX_NONE,           /* visualRating */
-    GLX_NONE,           /* transparentPixel */
-    0, 0, 0, 0,         /* transparent rgba color (floats scaled to ints) */
-    0                   /* transparentIndex */
-  },
-  /* [1] = RGB, double buffered, Z, stencil, accum */
-  {
-    -1,                 /* vid */
-    -1,                 /* class */
-    True,               /* rgba */
-    -1, -1, -1, 0,      /* rgba sizes */
-    -1, -1, -1, 0,      /* rgba masks */
-    16, 16, 16, 0,      /* rgba accum sizes */
-    True,               /* doubleBuffer */
-    False,              /* stereo */
-    -1,                 /* bufferSize */
-    16,                 /* depthSize */
-    8,                  /* stencilSize */
-    0,                  /* auxBuffers */
-    0,                  /* level */
-    GLX_NONE,           /* visualRating */
-    GLX_NONE,           /* transparentPixel */
-    0, 0, 0, 0,         /* transparent rgba color (floats scaled to ints) */
-    0                   /* transparentIndex */
-  },
-  /* [2] = RGB+Alpha, double buffered, Z, stencil, accum */
-  {
-    -1,                 /* vid */
-    -1,                 /* class */
-    True,               /* rgba */
-    -1, -1, -1, 8,      /* rgba sizes */
-    -1, -1, -1, -1,     /* rgba masks */
-    16, 16, 16, 16,     /* rgba accum sizes */
-    True,               /* doubleBuffer */
-    False,              /* stereo */
-    -1,                 /* bufferSize */
-    16,                 /* depthSize */
-    8,                  /* stencilSize */
-    0,                  /* auxBuffers */
-    0,                  /* level */
-    GLX_NONE,           /* visualRating */
-    GLX_NONE,           /* transparentPixel */
-    0, 0, 0, 0,         /* transparent rgba color (floats scaled to ints) */
-    0                   /* transparentIndex */
-  },
-  /* [3] = RGB+Alpha, single buffered, Z, stencil, accum */
-  {
-    -1,                 /* vid */
-    -1,                 /* class */
-    True,               /* rgba */
-    -1, -1, -1, 8,      /* rgba sizes */
-    -1, -1, -1, -1,     /* rgba masks */
-    16, 16, 16, 16,     /* rgba accum sizes */
-    False,              /* doubleBuffer */
-    False,              /* stereo */
-    -1,                 /* bufferSize */
-    16,                 /* depthSize */
-    8,                  /* stencilSize */
-    0,                  /* auxBuffers */
-    0,                  /* level */
-    GLX_NONE,           /* visualRating */
-    GLX_NONE,           /* transparentPixel */
-    0, 0, 0, 0,         /* transparent rgba color (floats scaled to ints) */
-    0                   /* transparentIndex */
-  },
-  /* [4] = CI, double buffered, Z */
-  {
-    -1,                 /* vid */
-    -1,                 /* class */
-    False,              /* rgba? (false = color index) */
-    -1, -1, -1, 0,      /* rgba sizes */
-    -1, -1, -1, 0,      /* rgba masks */
-     0,  0,  0, 0,      /* rgba accum sizes */
-    True,               /* doubleBuffer */
-    False,              /* stereo */
-    -1,                 /* bufferSize */
-    16,                 /* depthSize */
-    0,                  /* stencilSize */
-    0,                  /* auxBuffers */
-    0,                  /* level */
-    GLX_NONE,           /* visualRating */
-    GLX_NONE,           /* transparentPixel */
-    0, 0, 0, 0,         /* transparent rgba color (floats scaled to ints) */
-    0                   /* transparentIndex */
-  },
-};
-
-static __GLXvisualConfig NullConfig = {
-    -1,                 /* vid */
-    -1,                 /* class */
-    False,              /* rgba */
-    -1, -1, -1, 0,      /* rgba sizes */
-    -1, -1, -1, 0,      /* rgba masks */
-     0,  0,  0, 0,      /* rgba accum sizes */
-    False,              /* doubleBuffer */
-    False,              /* stereo */
-    -1,                 /* bufferSize */
-    16,                 /* depthSize */
-    0,                  /* stencilSize */
-    0,                  /* auxBuffers */
-    0,                  /* level */
-    GLX_NONE_EXT,       /* visualRating */
-    0,                  /* transparentPixel */
-    0, 0, 0, 0,         /* transparent rgba color (floats scaled to ints) */
-    0                   /* transparentIndex */
-};
-
-
-static int count_bits(unsigned int n)
-{
-   int bits = 0;
-
-   while (n > 0) {
-      if (n & 1) bits++;
-      n >>= 1;
-   }
-   return bits;
-}
-
-
-static Bool init_visuals(int *nvisualp, VisualPtr *visualp,
-                         VisualID *defaultVisp,
-                         int ndepth, DepthPtr pdepth,
-                         int rootDepth)
-{
-    int numRGBconfigs;
-    int numCIconfigs;
-    int numVisuals = *nvisualp;
-    int numNewVisuals;
-    int numNewConfigs;
-    VisualPtr pVisual = *visualp;
-    VisualPtr pVisualNew = NULL;
-    VisualID *orig_vid = NULL;
-    __GLcontextModes *modes;
-    __GLXvisualConfig *pNewVisualConfigs = NULL;
-    void **glXVisualPriv;
-    void **pNewVisualPriv;
-    int found_default;
-    int i, j, k;
-
-    GLAQUA_DEBUG_MSG("init_visuals\n");
-
-    if (numConfigs > 0)
-        numNewConfigs = numConfigs;
-    else
-        numNewConfigs = NUM_FALLBACK_CONFIGS;
-
-    /* Alloc space for the list of new GLX visuals */
-    pNewVisualConfigs = (__GLXvisualConfig *)
-                     __glXMalloc(numNewConfigs * sizeof(__GLXvisualConfig));
-    if (!pNewVisualConfigs) {
-        return FALSE;
-    }
-
-    /* Alloc space for the list of new GLX visual privates */
-    pNewVisualPriv = (void **) __glXMalloc(numNewConfigs * sizeof(void *));
-    if (!pNewVisualPriv) {
-        __glXFree(pNewVisualConfigs);
-        return FALSE;
-    }
-
-    /*
-    ** If SetVisualConfigs was not called, then use default GLX
-    ** visual configs.
-    */
-    if (numConfigs == 0) {
-        memcpy(pNewVisualConfigs, FallbackConfigs,
-               NUM_FALLBACK_CONFIGS * sizeof(__GLXvisualConfig));
-        memset(pNewVisualPriv, 0, NUM_FALLBACK_CONFIGS * sizeof(void *));
-    }
-    else {
-        /* copy driver's visual config info */
-        for (i = 0; i < numConfigs; i++) {
-            pNewVisualConfigs[i] = visualConfigs[i];
-            pNewVisualPriv[i] = visualPrivates[i];
-        }
-    }
-
-    /* Count the number of RGB and CI visual configs */
-    numRGBconfigs = 0;
-    numCIconfigs = 0;
-    for (i = 0; i < numNewConfigs; i++) {
-        if (pNewVisualConfigs[i].rgba)
-            numRGBconfigs++;
-        else
-            numCIconfigs++;
-    }
-
-    /* Count the total number of visuals to compute */
-    numNewVisuals = 0;
-    for (i = 0; i < numVisuals; i++) {
-        int count;
-
-        count = ((pVisual[i].class == TrueColor ||
-                  pVisual[i].class == DirectColor)
-                ? numRGBconfigs : numCIconfigs);
-        if (count == 0)
-            count = 1;          /* preserve the existing visual */
-
-        numNewVisuals += count;
-    }
-
-    /* Reset variables for use with the next screen/driver's visual configs */
-    visualConfigs = NULL;
-    numConfigs = 0;
-
-    /* Alloc temp space for the list of orig VisualIDs for each new visual */
-    orig_vid = (VisualID *)__glXMalloc(numNewVisuals * sizeof(VisualID));
-    if (!orig_vid) {
-        __glXFree(pNewVisualPriv);
-        __glXFree(pNewVisualConfigs);
-        return FALSE;
-    }
-
-    /* Alloc space for the list of glXVisuals */
-    modes = _gl_context_modes_create(numNewVisuals, sizeof(__GLcontextModes));
-    if (modes == NULL) {
-        __glXFree(orig_vid);
-        __glXFree(pNewVisualPriv);
-        __glXFree(pNewVisualConfigs);
-        return FALSE;
-    }
-
-    /* Alloc space for the list of glXVisualPrivates */
-    glXVisualPriv = (void **)__glXMalloc(numNewVisuals * sizeof(void *));
-    if (!glXVisualPriv) {
-        _gl_context_modes_destroy( modes );
-        __glXFree(orig_vid);
-        __glXFree(pNewVisualPriv);
-        __glXFree(pNewVisualConfigs);
-        return FALSE;
-    }
-
-    /* Alloc space for the new list of the X server's visuals */
-    pVisualNew = (VisualPtr)__glXMalloc(numNewVisuals * sizeof(VisualRec));
-    if (!pVisualNew) {
-        __glXFree(glXVisualPriv);
-        _gl_context_modes_destroy( modes );
-        __glXFree(orig_vid);
-        __glXFree(pNewVisualPriv);
-        __glXFree(pNewVisualConfigs);
-        return FALSE;
-    }
-
-    /* Initialize the new visuals */
-    found_default = FALSE;
-    glAquaScreens[screenInfo.numScreens-1].modes = modes;
-    for (i = j = 0; i < numVisuals; i++) {
-        int is_rgb = (pVisual[i].class == TrueColor ||
-                  pVisual[i].class == DirectColor);
-
-        if (!is_rgb)
-        {
-            /* We don't support non-rgb visuals for GL. But we don't
-               want to remove them either, so just pass them through
-               with null glX configs */
-
-            pVisualNew[j] = pVisual[i];
-            pVisualNew[j].vid = FakeClientID(0);
-
-            /* Check for the default visual */
-            if (!found_default && pVisual[i].vid == *defaultVisp) {
-                *defaultVisp = pVisualNew[j].vid;
-                found_default = TRUE;
-            }
-
-            /* Save the old VisualID */
-            orig_vid[j] = pVisual[i].vid;
-
-            /* Initialize the glXVisual */
-            _gl_copy_visual_to_context_mode( modes, & NullConfig );
-            modes->visualID = pVisualNew[j].vid;
-
-            j++;
-
-            continue;
-        }
-
-        for (k = 0; k < numNewConfigs; k++) {
-            if (pNewVisualConfigs[k].rgba != is_rgb)
-                continue;
-
-            assert( modes != NULL );
-
-            /* Initialize the new visual */
-            pVisualNew[j] = pVisual[i];
-            pVisualNew[j].vid = FakeClientID(0);
-
-            /* Check for the default visual */
-            if (!found_default && pVisual[i].vid == *defaultVisp) {
-                *defaultVisp = pVisualNew[j].vid;
-                found_default = TRUE;
-            }
-
-            /* Save the old VisualID */
-            orig_vid[j] = pVisual[i].vid;
-
-            /* Initialize the glXVisual */
-            _gl_copy_visual_to_context_mode( modes, & pNewVisualConfigs[k] );
-            modes->visualID = pVisualNew[j].vid;
-
-            /*
-             * If the class is -1, then assume the X visual information
-             * is identical to what GLX needs, and take them from the X
-             * visual.  NOTE: if class != -1, then all other fields MUST
-             * be initialized.
-             */
-            if (modes->visualType == GLX_NONE) {
-                modes->visualType = _gl_convert_from_x_visual_type( pVisual[i].class );
-                modes->redBits    = count_bits(pVisual[i].redMask);
-                modes->greenBits  = count_bits(pVisual[i].greenMask);
-                modes->blueBits   = count_bits(pVisual[i].blueMask);
-                modes->alphaBits  = modes->alphaBits;
-                modes->redMask    = pVisual[i].redMask;
-                modes->greenMask  = pVisual[i].greenMask;
-                modes->blueMask   = pVisual[i].blueMask;
-                modes->alphaMask  = modes->alphaMask;
-                modes->rgbBits = (is_rgb)
-                    ? (modes->redBits + modes->greenBits +
-                       modes->blueBits + modes->alphaBits)
-                    : rootDepth;
-            }
-
-            /* Save the device-dependent private for this visual */
-            glXVisualPriv[j] = pNewVisualPriv[k];
-
-            j++;
-            modes = modes->next;
-        }
-    }
-
-    assert(j <= numNewVisuals);
-
-    /* Save the GLX visuals in the screen structure */
-    glAquaScreens[screenInfo.numScreens-1].num_vis = numNewVisuals;
-    glAquaScreens[screenInfo.numScreens-1].priv = glXVisualPriv;
-
-    /* Set up depth's VisualIDs */
-    for (i = 0; i < ndepth; i++) {
-        int numVids = 0;
-        VisualID *pVids = NULL;
-        int k, n = 0;
-
-        /* Count the new number of VisualIDs at this depth */
-        for (j = 0; j < pdepth[i].numVids; j++)
-            for (k = 0; k < numNewVisuals; k++)
-            if (pdepth[i].vids[j] == orig_vid[k])
-                numVids++;
-
-        /* Allocate a new list of VisualIDs for this depth */
-        pVids = (VisualID *)__glXMalloc(numVids * sizeof(VisualID));
-
-        /* Initialize the new list of VisualIDs for this depth */
-        for (j = 0; j < pdepth[i].numVids; j++)
-            for (k = 0; k < numNewVisuals; k++)
-            if (pdepth[i].vids[j] == orig_vid[k])
-                pVids[n++] = pVisualNew[k].vid;
-
-        /* Update this depth's list of VisualIDs */
-        __glXFree(pdepth[i].vids);
-        pdepth[i].vids = pVids;
-        pdepth[i].numVids = numVids;
-    }
-
-    /* Update the X server's visuals */
-    *nvisualp = numNewVisuals;
-    *visualp = pVisualNew;
-
-    /* Free the old list of the X server's visuals */
-    __glXFree(pVisual);
-
-    /* Clean up temporary allocations */
-    __glXFree(orig_vid);
-    __glXFree(pNewVisualPriv);
-    __glXFree(pNewVisualConfigs);
-
-    /* Free the private list created by DDX HW driver */
-    if (visualPrivates)
-        xfree(visualPrivates);
-    visualPrivates = NULL;
-
-    return TRUE;
-}
-
-/* based on code in i830_dri.c
-   This ends calling glAquaSetVisualConfigs to set the static
-   numconfigs, etc. */
-static void
-glAquaInitVisualConfigs(void)
-{
-    int                 lclNumConfigs     = 0;
-    __GLXvisualConfig  *lclVisualConfigs  = NULL;
-    void              **lclVisualPrivates = NULL;
-
-    int depth, aux, buffers, stencil, accum;
-    int i = 0;
-
-    GLAQUA_DEBUG_MSG("glAquaInitVisualConfigs ");
-
-    /* count num configs:
-        2 Z buffer (0, 24 bit)
-        2 AUX buffer (0, 2)
-        2 buffers (single, double)
-        2 stencil (0, 8 bit)
-        2 accum (0, 64 bit)
-        = 32 configs */
-
-    lclNumConfigs = 2 * 2 * 2 * 2 * 2; /* 32 */
-
-    /* alloc */
-    lclVisualConfigs = xcalloc(sizeof(__GLXvisualConfig), lclNumConfigs);
-    lclVisualPrivates = xcalloc(sizeof(void *), lclNumConfigs);
-
-    /* fill in configs */
-    if (NULL != lclVisualConfigs) {
-        i = 0; /* current buffer */
-        for (depth = 0; depth < 2; depth++) {
-            for (aux = 0; aux < 2; aux++) {
-                for (buffers = 0; buffers < 2; buffers++) {
-                    for (stencil = 0; stencil < 2; stencil++) {
-                        for (accum = 0; accum < 2; accum++) {
-                            lclVisualConfigs[i].vid = -1;
-                            lclVisualConfigs[i].class = -1;
-                            lclVisualConfigs[i].rgba = TRUE;
-                            lclVisualConfigs[i].redSize = -1;
-                            lclVisualConfigs[i].greenSize = -1;
-                            lclVisualConfigs[i].blueSize = -1;
-                            lclVisualConfigs[i].redMask = -1;
-                            lclVisualConfigs[i].greenMask = -1;
-                            lclVisualConfigs[i].blueMask = -1;
-                            lclVisualConfigs[i].alphaMask = 0;
-                            if (accum) {
-                                lclVisualConfigs[i].accumRedSize = 16;
-                                lclVisualConfigs[i].accumGreenSize = 16;
-                                lclVisualConfigs[i].accumBlueSize = 16;
-                                lclVisualConfigs[i].accumAlphaSize = 16;
-                            }
-                            else {
-                                lclVisualConfigs[i].accumRedSize = 0;
-                                lclVisualConfigs[i].accumGreenSize = 0;
-                                lclVisualConfigs[i].accumBlueSize = 0;
-                                lclVisualConfigs[i].accumAlphaSize = 0;
-                            }
-                            lclVisualConfigs[i].doubleBuffer = buffers ? TRUE : FALSE;
-                            lclVisualConfigs[i].stereo = FALSE;
-                            lclVisualConfigs[i].bufferSize = -1;
-
-                            lclVisualConfigs[i].depthSize = depth? 24 : 0;
-                            lclVisualConfigs[i].stencilSize = stencil ? 8 : 0;
-                            lclVisualConfigs[i].auxBuffers = aux ? 2 : 0;
-                            lclVisualConfigs[i].level = 0;
-                            lclVisualConfigs[i].visualRating = GLX_NONE_EXT;
-                            lclVisualConfigs[i].transparentPixel = 0;
-                            lclVisualConfigs[i].transparentRed = 0;
-                            lclVisualConfigs[i].transparentGreen = 0;
-                            lclVisualConfigs[i].transparentBlue = 0;
-                            lclVisualConfigs[i].transparentAlpha = 0;
-                            lclVisualConfigs[i].transparentIndex = 0;
-                            i++;
-                        }
-                    }
-                }
-            }
-        }
-    }
-    if (i != lclNumConfigs)
-        GLAQUA_DEBUG_MSG("glAquaInitVisualConfigs failed to alloc visual configs");
-
-    GlxSetVisualConfigs(lclNumConfigs, lclVisualConfigs, lclVisualPrivates);
-}
-
-
-static void glAquaSetVisualConfigs(int nconfigs, __GLXvisualConfig *configs,
-                                   void **privates)
-{
-    GLAQUA_DEBUG_MSG("glAquaSetVisualConfigs\n");
-
-    numConfigs = nconfigs;
-    visualConfigs = configs;
-    visualPrivates = privates;
-}
-
-static Bool glAquaInitVisuals(VisualPtr *visualp, DepthPtr *depthp,
-                              int *nvisualp, int *ndepthp,
-                              int *rootDepthp, VisualID *defaultVisp,
-                              unsigned long sizes, int bitsPerRGB)
-{
-    GLAQUA_DEBUG_MSG("glAquaInitVisuals\n");
-
-    if (numConfigs == 0) /* if no configs */
-        glAquaInitVisualConfigs(); /* ensure the visual configs are setup */
-
-    /*
-     * Setup the visuals supported by this particular screen.
-     */
-    return init_visuals(nvisualp, visualp, defaultVisp,
-                        *ndepthp, *depthp, *rootDepthp);
-}
-
-
-static void fixup_visuals(int screen)
-{
-    ScreenPtr pScreen = screenInfo.screens[screen];
-    glAquaScreenRec *pScr = &glAquaScreens[screen];
-    int j;
-    __GLcontextModes *modes;
-
-    GLAQUA_DEBUG_MSG("fixup_visuals\n");
-
-    for ( modes = pScr->modes ; modes != NULL ; modes = modes->next ) {
-        const int vis_class = _gl_convert_to_x_visual_type( modes->visualType );
-        const int nplanes = (modes->rgbBits - modes->alphaBits);
-        const VisualPtr pVis = pScreen->visuals;
-
-        /* Find a visual that matches the GLX visual's class and size */
-        for (j = 0; j < pScreen->numVisuals; j++) {
-            if (pVis[j].class == vis_class &&
-            pVis[j].nplanes == nplanes) {
-
-            /* Fixup the masks */
-            modes->redMask   = pVis[j].redMask;
-            modes->greenMask = pVis[j].greenMask;
-            modes->blueMask  = pVis[j].blueMask;
-
-            /* Recalc the sizes */
-            modes->redBits   = count_bits(modes->redMask);
-            modes->greenBits = count_bits(modes->greenMask);
-            modes->blueBits  = count_bits(modes->blueMask);
-            }
-        }
-    }
-}
-
-static void init_screen_visuals(int screen)
-{
-    ScreenPtr pScreen = screenInfo.screens[screen];
-    __GLcontextModes *modes;
-    int *used;
-    int i, j;
-
-    GLAQUA_DEBUG_MSG("init_screen_visuals\n");
-
-    /* FIXME: Change 'used' to be a array of bits (rather than of ints),
-     * FIXME: create a stack array of 8 or 16 bytes.  If 'numVisuals' is less
-     * FIXME: than 64 or 128 the stack array can be used instead of calling
-     * FIXME: __glXMalloc / __glXFree.  If nothing else, convert 'used' to
-     * FIXME: array of bytes instead of ints!
-     */
-    used = (int *)__glXMalloc(pScreen->numVisuals * sizeof(int));
-    __glXMemset(used, 0, pScreen->numVisuals * sizeof(int));
-
-    i = 0;
-    for ( modes = glAquaScreens[screen].modes 
-          ; modes != NULL
-          ; modes = modes->next ) {
-        const int vis_class = _gl_convert_to_x_visual_type( modes->visualType );
-        const int nplanes = (modes->rgbBits - modes->alphaBits);
-        const VisualPtr pVis = pScreen->visuals;
-
-        for (j = 0; j < pScreen->numVisuals; j++) {
-            if (pVis[j].class     == vis_class &&
-                pVis[j].nplanes   == nplanes &&
-                pVis[j].redMask   == modes->redMask &&
-                pVis[j].greenMask == modes->greenMask &&
-                pVis[j].blueMask  == modes->blueMask &&
-                !used[j]) {
-
-                    /* Set the VisualID */
-                    modes->visualID = pVis[j].vid;
-
-                    /* Mark this visual used */
-                    used[j] = 1;
-                    break;
-            }
-        }
-        if ( j == pScreen->numVisuals ) {
-            ErrorF("No matching visual for __GLcontextMode with "
-                   "visual class = %d (%d), nplanes = %u\n",
-                   vis_class, 
-                   (int)modes->visualType,
-                   (unsigned int)(modes->rgbBits - modes->alphaBits) );
-        }
-        else if ( modes->visualID == -1 ) {
-            FatalError( "Matching visual found, but visualID still -1!\n" );
-        }
-
-        i++;
-    }
-
-    __glXFree(used);
-}
-
-static Bool glAquaScreenProbe(int screen)
-{
-    ScreenPtr pScreen;
-    glAquaScreenRec *screenPriv;
-
-    GLAQUA_DEBUG_MSG("glAquaScreenProbe\n");
-
-    /*
-     * Set up the current screen's visuals.
-     */
-    __glDDXScreenInfo.modes = glAquaScreens[screen].modes;
-    __glDDXScreenInfo.pVisualPriv = glAquaScreens[screen].priv;
-    __glDDXScreenInfo.numVisuals =
-        __glDDXScreenInfo.numUsableVisuals = glAquaScreens[screen].num_vis;
-
-    /*
-     * Set the current screen's createContext routine.  This could be
-     * wrapped by a DDX GLX context creation routine.
-     */
-    __glDDXScreenInfo.createContext = glAquaCreateContext;
-
-    /*
-     * The ordering of the rgb compenents might have been changed by the
-     * driver after mi initialized them.
-     */
-    fixup_visuals(screen);
-
-    /*
-     * Find the GLX visuals that are supported by this screen and create
-     * XMesa's visuals.
-     */
-    init_screen_visuals(screen);
-
-    /*
-     * Wrap RealizeWindow and UnrealizeWindow on this screen
-     */
-    pScreen = screenInfo.screens[screen];
-    screenPriv = &glAquaScreens[screen];
-    screenPriv->RealizeWindow = pScreen->RealizeWindow;
-    pScreen->RealizeWindow = glAquaRealizeWindow;
-    screenPriv->UnrealizeWindow = pScreen->UnrealizeWindow;
-    pScreen->UnrealizeWindow = glAquaUnrealizeWindow;
-
-    return TRUE;
-}
-
-
-static GLboolean glAquaResizeBuffers(__GLdrawableBuffer *buffer,
-                                     GLint x, GLint y,
-                                     GLuint width, GLuint height,
-                                     __GLdrawablePrivate *glPriv,
-                                     GLuint bufferMask)
-{
-    GLAquaDrawableRec *aquaPriv = (GLAquaDrawableRec *)glPriv->private;
-    __GLXdrawablePrivate *glxPriv = (__GLXdrawablePrivate *)glPriv->other;
-    __GLXcontext *gx;
-    __GLcontext *gc;
-
-    GLAQUA_DEBUG_MSG("glAquaResizeBuffers to (%d %d %d %d)\n", x, y, width, height);
-
-    // update all contexts that point at this drawable for drawing (hack?)
-    for (gx = glxPriv->drawGlxc; gx != NULL; gx = gx->nextDrawPriv) {
-        gc = (__GLcontext *)gx->gc;
-        attach(gc, glPriv);
-    }
-
-    // update all contexts that point at this drawable for reading (hack?)
-    for (gx = glxPriv->readGlxc; gx != NULL; gx = gx->nextReadPriv) {
-        gc = (__GLcontext *)gx->gc;
-        attach(gc, glPriv);
-    }
-
-    return aquaPriv->resize(buffer, x, y, width, height, glPriv, bufferMask);
-}
-
-
-static GLboolean glAquaSwapBuffers(__GLXdrawablePrivate *glxPriv)
-{
-    // fixme AGL software renderer will use properties of current QD port (bad)
-
-    // swap buffers on only *one* of the contexts
-    // (e.g. the last one for drawing)
-    __GLcontext *gc = (__GLcontext *)glxPriv->drawGlxc->gc;
-    if (gc && gc->ctx) aglSwapBuffers(gc->ctx);
-
-    return GL_TRUE;
-}
-
-static void glAquaDestroyDrawablePrivate(__GLdrawablePrivate *glPriv)
-{
-    GLAQUA_DEBUG_MSG("glAquaDestroyDrawablePrivate\n");
-
-    free(glPriv->private);
-    glPriv->private = NULL;
-}
-
-static void glAquaCreateBuffer(__GLXdrawablePrivate *glxPriv)
-{
-    GLAquaDrawableRec *aquaPriv = malloc(sizeof(GLAquaDrawableRec));
-    __GLdrawablePrivate *glPriv = &glxPriv->glPriv;
-
-    GLAQUA_DEBUG_MSG("glAquaCreateBuffer\n");
-
-    // replace swapBuffers (original is never called)
-    glxPriv->swapBuffers = glAquaSwapBuffers;
-
-    // wrap front buffer resize
-    aquaPriv->resize = glPriv->frontBuffer.resize;
-    glPriv->frontBuffer.resize = glAquaResizeBuffers;
-
-    // stash private data
-    glPriv->private = aquaPriv;
-    glPriv->freePrivate = glAquaDestroyDrawablePrivate;
-}
-
-
-static void glAquaResetExtension(void)
-{
-    GLAQUA_DEBUG_MSG("glAquaResetExtension\n");
-    aglResetLibrary();
-}
-
-
-
-// Extra goodies for glx
-
-GLuint __glFloorLog2(GLuint val)
-{
-    int c = 0;
-
-    while (val > 1) {
-        c++;
-        val >>= 1;
-    }
-    return c;
-}
commit f6e22d69af6bc8f63c3a46535a09e217696a679f
Author: Hans de Goede <j.w.r.degoede at hhs.nl>
Date:   Wed Apr 23 12:28:30 2008 -0400

    Prefer glxvisuals with stencil buffer for default visuals
    
    The first fbconfig which has a depthbuffer > 0  and doublebuf is choosen
    when associating fbconfigs with the visuals, indepenent of stencil bits.
    This happens to work ok on intel as there all fbconfigs with a
    depthbuffer > 0 also have stencil bits.
    
    This patch fixes this by first trying to get a fbconfig for default X visuals
    with both stencilbuf, depthbuf and doublebuffering, and if that fails fallback
    to trying to get one with only a depthbuf and doublebuffering.

diff --git a/GL/glx/glxscreens.c b/GL/glx/glxscreens.c
index 41ee029..5859de0 100644
--- a/GL/glx/glxscreens.c
+++ b/GL/glx/glxscreens.c
@@ -437,6 +437,7 @@ initGlxVisual(VisualPtr visual, __GLXconfig *config)
 typedef struct {
     GLboolean doubleBuffer;
     GLboolean depthBuffer;
+    GLboolean stencilBuffer;
 } FBConfigTemplateRec, *FBConfigTemplatePtr;
 
 static __GLXconfig *
@@ -453,6 +454,8 @@ pickFBConfig(__GLXscreen *pGlxScreen, FBConfigTemplatePtr template, int class)
 	    continue;
 	if ((config->depthBits > 0) != template->depthBuffer)
 	    continue;
+	if ((config->stencilBits > 0) != template->stencilBuffer)
+	    continue;
 
 	return config;
     }
@@ -466,8 +469,9 @@ addMinimalSet(__GLXscreen *pGlxScreen)
     __GLXconfig *config;
     VisualPtr visuals;
     int i, j;
-    FBConfigTemplateRec best = { GL_TRUE, GL_TRUE };
-    FBConfigTemplateRec minimal = { GL_FALSE, GL_FALSE };
+    FBConfigTemplateRec best = { GL_TRUE, GL_TRUE, GL_TRUE };
+    FBConfigTemplateRec good = { GL_TRUE, GL_TRUE, GL_FALSE };
+    FBConfigTemplateRec minimal = { GL_FALSE, GL_FALSE, GL_FALSE };
 
     pGlxScreen->visuals = xcalloc(pGlxScreen->pScreen->numVisuals,
 				  sizeof (__GLXconfig *));
@@ -480,8 +484,11 @@ addMinimalSet(__GLXscreen *pGlxScreen)
     for (i = 0, j = 0; i < pGlxScreen->pScreen->numVisuals; i++) {
 	if (visuals[i].nplanes == 32)
 	    config = pickFBConfig(pGlxScreen, &minimal, visuals[i].class);
-	else
+	else {
 	    config = pickFBConfig(pGlxScreen, &best, visuals[i].class);
+	    if (config == NULL)
+		config = pickFBConfig(pGlxScreen, &good, visuals[i].class);
+        }
 	if (config == NULL)
 	    config = pGlxScreen->fbconfigs;
 	if (config == NULL)
commit 00effad583713e882c3f2518bcd3da51bf4db716
Author: George Sapountzis <gsap7 at yahoo.gr>
Date:   Wed Apr 23 17:46:30 2008 +0300

    xephyr: XEPHYR_DRI is identical to XF86DRI

diff --git a/configure.ac b/configure.ac
index 21c1d91..51ab4c6 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1925,11 +1925,6 @@ if test "$KDRIVE" = yes; then
     if test "x$XEPHYR" = xauto; then
         XEPHYR=$xephyr
     fi
-    XEPHYR_DRI=no
-    if test x$XEPHYR = xyes -a x$DRI = xyes && test "x$GLX" = xyes; then
-        XEPHYR_DRI=yes
-        AC_DEFINE(XEPHYR_DRI,1,[enable DRI extension in xephyr])
-    fi
 
     # Xephyr needs nanosleep() which is in librt on Solaris
     AC_CHECK_FUNC([nanosleep], [],
@@ -1984,7 +1979,6 @@ AM_CONDITIONAL(KDRIVEFBDEV, [test "x$XFBDEV" = xyes])
 AM_CONDITIONAL(XSDLSERVER, [test x"$XSDL" = xyes])
 AM_CONDITIONAL(XEPHYR, [test "x$KDRIVE" = xyes && test "x$XEPHYR" = xyes])
 AM_CONDITIONAL(BUILD_KDRIVEFBDEVLIB, [test "x$KDRIVE" = xyes && test "x$KDRIVEFBDEVLIB" = xyes])
-AM_CONDITIONAL(XEPHYR_HAS_DRI, [test x$XEPHYR_DRI = xyes])
 AM_CONDITIONAL(XFAKESERVER, [test "x$KDRIVE" = xyes && test "x$XFAKE" = xyes])
 
 dnl these only go in xkb-config.h (which is shared by the Xorg and Xnest servers)
diff --git a/hw/kdrive/ephyr/Makefile.am b/hw/kdrive/ephyr/Makefile.am
index 90fd4d8..5269876 100644
--- a/hw/kdrive/ephyr/Makefile.am
+++ b/hw/kdrive/ephyr/Makefile.am
@@ -11,7 +11,7 @@ if XV
 LIBXEPHYR_HOSTXV=libxephyr-hostxv.a
 endif
 
-if XEPHYR_HAS_DRI
+if DRI
 LIBXEPHYR_HOSTDRI=libxephyr-hostdri.a
 endif
 
@@ -53,7 +53,7 @@ if XV
 libxephyr_hostxv_a_SOURCES = $(HOSTVIDEO_SRCS)
 endif
 
-if XEPHYR_HAS_DRI
+if DRI
 libxephyr_hostdri_a_SOURCES = $(HOSTDRI_SRCS)
 endif
 
diff --git a/hw/kdrive/ephyr/XF86dri.c b/hw/kdrive/ephyr/XF86dri.c
index a5fc9bd..be65edf 100644
--- a/hw/kdrive/ephyr/XF86dri.c
+++ b/hw/kdrive/ephyr/XF86dri.c
@@ -46,8 +46,6 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 #include <kdrive-config.h>
 #endif
 
-#ifdef XEPHYR_DRI
-
 /* THIS IS NOT AN X CONSORTIUM STANDARD */
 
 #define NEED_REPLIES
@@ -639,5 +637,3 @@ XF86DRICloseFullScreen(Display *dpy, int screen, Drawable drawable)
     (void) drawable;
     return True;
 }
-#endif /*EPHYR_DRI*/
-
diff --git a/hw/kdrive/ephyr/ephyr.c b/hw/kdrive/ephyr/ephyr.c
index b02f990..d69e148 100644
--- a/hw/kdrive/ephyr/ephyr.c
+++ b/hw/kdrive/ephyr/ephyr.c
@@ -32,11 +32,11 @@
 #include "scrnintstr.h"
 #include "ephyrlog.h"
 
-#ifdef XEPHYR_DRI
+#ifdef XF86DRI
 #include "ephyrdri.h"
 #include "ephyrdriext.h"
 #include "ephyrglxext.h"
-#endif /*XEPHYR_DRI*/
+#endif /* XF86DRI */
 
 extern int KdTsPhyScreen;
 #ifdef GLXEXT
@@ -631,7 +631,7 @@ ephyrInitScreen (ScreenPtr pScreen)
   }
 #endif /*XV*/
 
-#ifdef XEPHYR_DRI
+#ifdef XF86DRI
   if (!ephyrNoDRI && !hostx_has_dri ()) {
       EPHYR_LOG ("host x does not support DRI. Disabling DRI forwarding\n") ;
       ephyrNoDRI = TRUE ;
@@ -841,7 +841,7 @@ miPointerScreenFuncRec ephyrPointerScreenFuncs =
   ephyrWarpCursor
 };
 
-#ifdef XEPHYR_DRI
+#ifdef XF86DRI
 /**
  * find if the remote window denoted by a_remote
  * is paired with an internal Window within the Xephyr server.
@@ -873,7 +873,7 @@ ephyrExposePairedWindow (int a_remote)
     screen->WindowExposures (pair->local, &reg, NullRegion);
     REGION_UNINIT (screen, &reg);
 }
-#endif /*XEPHYR_DRI*/
+#endif /* XF86DRI */
 
 void
 ephyrPoll(void)
@@ -908,14 +908,14 @@ ephyrPoll(void)
             else
               {
                   int x=0, y=0;
-#ifdef XEPHYR_DRI
+#ifdef XF86DRI
                   EphyrWindowPair *pair = NULL;
 #endif
                   EPHYR_LOG ("enqueuing mouse motion:%d\n", ephyrCurScreen) ;
                   x = ev.data.mouse_motion.x;
                   y = ev.data.mouse_motion.y;
                   EPHYR_LOG ("initial (x,y):(%d,%d)\n", x, y) ;
-#ifdef XEPHYR_DRI
+#ifdef XF86DRI
                   EPHYR_LOG ("is this window peered by a gl drawable ?\n") ;
                   if (findWindowPairFromRemote (ev.data.mouse_motion.window,
                                                 &pair))
@@ -972,7 +972,7 @@ ephyrPoll(void)
 	  KdEnqueueKeyboardEvent (ephyrKbd, ev.data.key_up.scancode, TRUE);
 	  break;
 
-#ifdef XEPHYR_DRI
+#ifdef XF86DRI
 	case EPHYR_EV_EXPOSE:
 	  /*
 	   * We only receive expose events when the expose event have
@@ -982,7 +982,7 @@ ephyrPoll(void)
 	   */
 	  ephyrExposePairedWindow (ev.data.expose.window);
 	  break;
-#endif /*XEPHYR_DRI*/
+#endif /* XF86DRI */
 
 	default:
 	  break;
diff --git a/hw/kdrive/ephyr/ephyrdri.c b/hw/kdrive/ephyr/ephyrdri.c
index bb4f6a1..9aa68b1 100644
--- a/hw/kdrive/ephyr/ephyrdri.c
+++ b/hw/kdrive/ephyr/ephyrdri.c
@@ -29,11 +29,8 @@
 #include <kdrive-config.h>
 #endif
 
-#ifdef XEPHYR_DRI
-
 #include <X11/Xutil.h>
 #include <X11/Xlibint.h>
-/*#define _XF86DRI_SERVER_*/
 #include <GL/glx.h>
 #include "xf86dri.h"
 #include "hostx.h"
@@ -287,5 +284,3 @@ ephyrDRIGetDeviceInfo (int a_screen,
     EPHYR_LOG ("leave:%d\n", is_ok) ;
     return is_ok ;
 }
-#endif /*EPHYR_DRI*/
-
diff --git a/hw/kdrive/ephyr/ephyrdriext.c b/hw/kdrive/ephyr/ephyrdriext.c
index fafe56d..883e330 100644
--- a/hw/kdrive/ephyr/ephyrdriext.c
+++ b/hw/kdrive/ephyr/ephyrdriext.c
@@ -32,8 +32,6 @@
 #include <kdrive-config.h>
 #endif
 
-#ifdef XEPHYR_DRI
-
 #include <string.h>
 
 #define NEED_REPLIES
@@ -1439,5 +1437,3 @@ SProcXF86DRIDispatch (register ClientPtr client)
         }
     }
 }
-
-#endif /*XEPHYR_DRI*/
diff --git a/hw/kdrive/ephyr/ephyrglxext.c b/hw/kdrive/ephyr/ephyrglxext.c
index 43a634d..2e08e39 100644
--- a/hw/kdrive/ephyr/ephyrglxext.c
+++ b/hw/kdrive/ephyr/ephyrglxext.c
@@ -42,8 +42,6 @@
 #include "hostx.h"
 
 
-#ifdef XEPHYR_DRI
-
 #ifndef TRUE
 #define TRUE 1
 #endif
@@ -727,6 +725,3 @@ ephyrGLXIsDirectSwap (__GLXclientState *a_cl, GLbyte *a_pc)
 {
     return ephyrGLXIsDirectReal (a_cl, a_pc, TRUE) ;
 }
-
-#endif /*XEPHYR_DRI*/
-
diff --git a/hw/kdrive/ephyr/ephyrhostglx.c b/hw/kdrive/ephyr/ephyrhostglx.c
index f5db5be..6d783d2 100644
--- a/hw/kdrive/ephyr/ephyrhostglx.c
+++ b/hw/kdrive/ephyr/ephyrhostglx.c
@@ -41,7 +41,6 @@
 #include "ephyrlog.h"
 #include "hostx.h"
 
-#ifdef XEPHYR_DRI
 enum VisualConfRequestType {
     EPHYR_GET_FB_CONFIG,
     EPHYR_VENDOR_PRIV_GET_FB_CONFIG_SGIX,
@@ -687,6 +686,3 @@ out:
     EPHYR_LOG ("leave\n") ;
     return is_ok ;
 }
-
-#endif /*XEPHYR_DRI*/
-
diff --git a/hw/kdrive/ephyr/hostx.c b/hw/kdrive/ephyr/hostx.c
index 1a71d06..74f9f16 100644
--- a/hw/kdrive/ephyr/hostx.c
+++ b/hw/kdrive/ephyr/hostx.c
@@ -45,12 +45,12 @@
 #include <X11/keysym.h>
 #include <X11/extensions/XShm.h>
 #include <X11/extensions/shape.h>
-#ifdef XEPHYR_DRI
+#ifdef XF86DRI
 #include <GL/glx.h>
-#endif /*XEPHYR_DRI*/
+#endif /* XF86DRI */
 #include "ephyrlog.h"
 
-#ifdef XEPHYR_DRI
+#ifdef XF86DRI
 extern Bool XF86DRIQueryExtension (Display *dpy,
                                    int *event_basep,
                                    int *error_basep);
@@ -1315,7 +1315,7 @@ hostx_has_xshape (void)
     return TRUE;
 }
 
-#ifdef XEPHYR_DRI
+#ifdef XF86DRI
 typedef struct {
     int is_valid ;
     int local_id ;
@@ -1418,5 +1418,4 @@ hostx_has_glx (void)
     return TRUE ;
 }
 
-#endif /*XEPHYR_DRI*/
-
+#endif /* XF86DRI */
diff --git a/hw/kdrive/ephyr/hostx.h b/hw/kdrive/ephyr/hostx.h
index 47ba61b..c1b1958 100644
--- a/hw/kdrive/ephyr/hostx.h
+++ b/hw/kdrive/ephyr/hostx.h
@@ -244,7 +244,7 @@ int hostx_set_window_clipping_rectangles (int a_window,
                                           int a_num_rects) ;
 int hostx_has_xshape (void) ;
 
-#ifdef XEPHYR_DRI
+#ifdef XF86DRI
 int hostx_lookup_peer_window (void *a_local_window,
                               int *a_host_peer /*out parameter*/) ;
 int
@@ -256,6 +256,6 @@ hostx_get_resource_id_peer (int a_local_resource_id,
 int hostx_has_dri (void) ;
 
 int hostx_has_glx (void) ;
-#endif /*XEPHYR_DRI*/
+#endif /* XF86DRI */
 
 #endif /*_XLIBS_STUFF_H_*/
diff --git a/include/dix-config.h.in b/include/dix-config.h.in
index 1779082..135d3d8 100644
--- a/include/dix-config.h.in
+++ b/include/dix-config.h.in
@@ -419,8 +419,6 @@
 /* Support DRI extension */
 #undef XF86DRI
 
-#undef XEPHYR_DRI
-
 /* Build DRI2 extension */
 #undef DRI2
 
commit 6a9f7f28ec455d2879ca1a315ce77c48af49e7f4
Author: George Sapountzis <gsap7 at yahoo.gr>
Date:   Wed Apr 23 17:46:15 2008 +0300

    xephyr: sync with mesa

diff --git a/hw/kdrive/ephyr/GL/internal/dri_interface.h b/hw/kdrive/ephyr/GL/internal/dri_interface.h
deleted file mode 100644
index 8d24e31..0000000
--- a/hw/kdrive/ephyr/GL/internal/dri_interface.h
+++ /dev/null
@@ -1,517 +0,0 @@
-/*
- * Copyright 1998-1999 Precision Insight, Inc., Cedar Park, Texas.
- * (C) Copyright IBM Corporation 2004
- * All Rights Reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * on the rights to use, copy, modify, merge, publish, distribute, sub
- * license, and/or sell copies of the Software, and to permit persons to whom
- * the Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice (including the next
- * paragraph) shall be included in all copies or substantial portions of the
- * Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.  IN NO EVENT SHALL
- * THE COPYRIGHT HOLDERS AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
- * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
- * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
- * USE OR OTHER DEALINGS IN THE SOFTWARE.
- */
-
-/**
- * \file dri_interface.h
- *
- * This file contains all the types and functions that define the interface
- * between a DRI driver and driver loader.  Currently, the most common driver
- * loader is the XFree86 libGL.so.  However, other loaders do exist, and in
- * the future the server-side libglx.a will also be a loader.
- * 
- * \author Kevin E. Martin <kevin at precisioninsight.com>
- * \author Ian Romanick <idr at us.ibm.com>
- */
-
-#ifndef DRI_INTERFACE_H
-#define DRI_INTERFACE_H
-
-#include <GL/internal/glcore.h>
-#include <drm.h>
-
-/**
- * \name DRI interface structures
- *
- * The following structures define the interface between the GLX client
- * side library and the DRI (direct rendering infrastructure).
- */
-/*@{*/
-typedef struct __DRIdisplayRec  __DRIdisplay;
-typedef struct __DRIscreenRec   __DRIscreen;
-typedef struct __DRIcontextRec  __DRIcontext;
-typedef struct __DRIdrawableRec __DRIdrawable;
-typedef struct __DRIdriverRec   __DRIdriver;
-typedef struct __DRIframebufferRec __DRIframebuffer;
-typedef struct __DRIversionRec     __DRIversion;
-typedef struct __DRIinterfaceMethodsRec  __DRIinterfaceMethods;
-typedef unsigned long __DRIid;
-typedef void __DRInativeDisplay;
-/*@}*/
-
-
-/**
- * \name Functions provided by the driver loader.
- */
-/*@{*/
-/**
- * Type of a pointer to \c glXGetScreenDriver, as returned by
- * \c glXGetProcAddress.  This function is used to get the name of the DRI
- * driver for the specified screen of the specified display.  The driver
- * name is typically used with \c glXGetDriverConfig.
- *
- * \sa glXGetScreenDriver, glXGetProcAddress, glXGetDriverConfig
- */
-typedef const char * (* PFNGLXGETSCREENDRIVERPROC) (__DRInativeDisplay *dpy, int scrNum);
-
-/**
- * Type of a pointer to \c glXGetDriverConfig, as returned by
- * \c glXGetProcAddress.  This function is used to get the XML document
- * describing the configuration options available for the specified driver.
- *
- * \sa glXGetDriverConfig, glXGetProcAddress, glXGetScreenDriver
- */
-typedef const char * (* PFNGLXGETDRIVERCONFIGPROC) (const char *driverName);
-
-/**
- * Type of a pointer to \c glxEnableExtension, as returned by
- * \c __DRIinterfaceMethods::getProcAddress.  This function is used to enable
- * a GLX extension on the specified screen.
- */
-typedef void (* PFNGLXSCRENABLEEXTENSIONPROC) ( void *psc, const char * name );
-/*@}*/
-
-
-/**
- * \name Functions and data provided by the driver.
- */
-/*@{*/
-
-typedef void *(CREATENEWSCREENFUNC)(__DRInativeDisplay *dpy, int scrn,
-    __DRIscreen *psc, const __GLcontextModes * modes,
-    const __DRIversion * ddx_version, const __DRIversion * dri_version,
-    const __DRIversion * drm_version, const __DRIframebuffer * frame_buffer,
-    void * pSAREA, int fd, int internal_api_version,
-    const __DRIinterfaceMethods * interface,
-    __GLcontextModes ** driver_modes);
-typedef CREATENEWSCREENFUNC* PFNCREATENEWSCREENFUNC;
-extern CREATENEWSCREENFUNC __driCreateNewScreen_20050727;
-
-
-/**
- * XML document describing the configuration options supported by the
- * driver.
- */
-extern const char __driConfigOptions[];
-
-/*@}*/
-
-
-/**
- * Stored version of some component (i.e., server-side DRI module, kernel-side
- * DRM, etc.).
- * 
- * \todo
- * There are several data structures that explicitly store a major version,
- * minor version, and patch level.  These structures should be modified to
- * have a \c __DRIversionRec instead.
- */
-struct __DRIversionRec {
-    int    major;        /**< Major version number. */
-    int    minor;        /**< Minor version number. */
-    int    patch;        /**< Patch-level. */
-};
-
-
-typedef void (*__DRIfuncPtr)(void);
-
-struct __DRIinterfaceMethodsRec {
-    /**
-     * Get pointer to named function.
-     */
-    __DRIfuncPtr (*getProcAddress)( const char * proc_name );
-
-    /**
-     * Create a list of \c __GLcontextModes structures.
-     */
-    __GLcontextModes * (*createContextModes)(unsigned count,
-        size_t minimum_bytes_per_struct);
-
-    /**
-     * Destroy a list of \c __GLcontextModes structures.
-     *
-     * \todo
-     * Determine if the drivers actually need to call this.
-     */
-    void (*destroyContextModes)( __GLcontextModes * modes );
-
-    /**
-     * Get the \c __DRIscreen for a given display and screen number.
-     */
-    __DRIscreen *(*getScreen)(__DRInativeDisplay *dpy, int screenNum);
-
-
-    /**
-     * \name Client/server protocol functions.
-     *
-     * These functions implement the DRI client/server protocol for
-     * context and drawable operations.  Platforms that do not implement
-     * the wire protocol (e.g., EGL) will implement glorified no-op functions.
-     */
-    /*@{*/
-    /**
-     * Determine if the specified window ID still exists.
-     * 
-     * \note
-     * Implementations may assume that the driver will only pass an ID into
-     * this function that actually corresponds to a window.  On
-     * implementations where windows can only be destroyed by the DRI driver
-     * (e.g., EGL), this function is allowed to always return \c GL_TRUE.
-     */
-    GLboolean (*windowExists)(__DRInativeDisplay *dpy, __DRIid draw);
-
-    /**
-     * Create the server-side portion of the GL context.
-     */
-    GLboolean (* createContext)( __DRInativeDisplay *dpy, int screenNum,
-        int configID, void * contextID, drm_context_t * hw_context );
-
-    /**
-     * Destroy the server-side portion of the GL context.
-     */
-    GLboolean (* destroyContext)( __DRInativeDisplay *dpy, int screenNum,
-        __DRIid context );
-
-    /**
-     * Create the server-side portion of the drawable.
-     */
-    GLboolean (*createDrawable)( __DRInativeDisplay * ndpy, int screen,
-        __DRIid drawable, drm_drawable_t * hHWDrawable );
-
-    /**
-     * Destroy the server-side portion of the drawable.
-     */
-    GLboolean (*destroyDrawable)( __DRInativeDisplay * ndpy, int screen,
-        __DRIid drawable );
-
-    /**
-     * This function is used to get information about the position, size, and
-     * clip rects of a drawable.
-     */
-    GLboolean (* getDrawableInfo) ( __DRInativeDisplay *dpy, int scrn,
-        __DRIid draw, unsigned int * index, unsigned int * stamp,
-        int * x, int * y, int * width, int * height,
-        int * numClipRects, drm_clip_rect_t ** pClipRects,
-        int * backX, int * backY,
-        int * numBackClipRects, drm_clip_rect_t ** pBackClipRects );
-    /*@}*/
-
-
-    /**
-     * \name Timing related functions.
-     */
-    /*@{*/
-    /**
-     * Get the 64-bit unadjusted system time (UST).
-     */
-    int (*getUST)(int64_t * ust);
-
-    /**
-     * Get the media stream counter (MSC) rate.
-     * 
-     * Matching the definition in GLX_OML_sync_control, this function returns
-     * the rate of the "media stream counter".  In practical terms, this is
-     * the frame refresh rate of the display.
-     */
-    GLboolean (*getMSCRate)(__DRInativeDisplay * dpy, __DRIid drawable,
-        int32_t * numerator, int32_t * denominator);
-    /*@}*/
-
-    /**
-     * Reports areas of the given drawable which have been modified by the
-     * driver.
-     *
-     * \param drawable which the drawing was done to.
-     * \param rects rectangles affected, with the drawable origin as the
-     *	      origin.
-     * \param x X offset of the drawable within the screen (used in the
-     *	      front_buffer case)
-     * \param y Y offset of the drawable within the screen.
-     * \param front_buffer boolean flag for whether the drawing to the
-     * 	      drawable was actually done directly to the front buffer (instead
-     *	      of backing storage, for example)
-     */
-    void (*reportDamage)(__DRInativeDisplay * dpy, int screen,
-			 __DRIid drawable,
-			 int x, int y,
-			 drm_clip_rect_t *rects, int num_rects,
-			 int front_buffer);
-};
-
-   
-/**
- * Framebuffer information record.  Used by libGL to communicate information
- * about the framebuffer to the driver's \c __driCreateNewScreen function.
- * 
- * In XFree86, most of this information is derrived from data returned by
- * calling \c XF86DRIGetDeviceInfo.
- *
- * \sa XF86DRIGetDeviceInfo __DRIdisplayRec::createNewScreen
- *     __driUtilCreateNewScreen CallCreateNewScreen
- *
- * \bug This structure could be better named.
- */
-struct __DRIframebufferRec {
-    unsigned char *base;    /**< Framebuffer base address in the CPU's
-			     * address space.  This value is calculated by
-			     * calling \c drmMap on the framebuffer handle
-			     * returned by \c XF86DRIGetDeviceInfo (or a
-			     * similar function).
-			     */
-    int size;               /**< Framebuffer size, in bytes. */
-    int stride;             /**< Number of bytes from one line to the next. */
-    int width;              /**< Pixel width of the framebuffer. */
-    int height;             /**< Pixel height of the framebuffer. */
-    int dev_priv_size;      /**< Size of the driver's dev-priv structure. */
-    void *dev_priv;         /**< Pointer to the driver's dev-priv structure. */
-};
-
-
-/**
- * Screen dependent methods.  This structure is initialized during the
- * \c __DRIdisplayRec::createScreen call.
- */
-struct __DRIscreenRec {
-    /**
-     * Method to destroy the private DRI screen data.
-     */
-    void (*destroyScreen)(__DRInativeDisplay *dpy, int scrn, void *screenPrivate);
-
-    /**
-     * Method to create the private DRI drawable data and initialize the
-     * drawable dependent methods.
-     */
-    void *(*createNewDrawable)(__DRInativeDisplay *dpy, const __GLcontextModes *modes,
-			       __DRIid draw, __DRIdrawable *pdraw,
-			       int renderType, const int *attrs);
-
-    /**
-     * Method to return a pointer to the DRI drawable data.
-     */
-    __DRIdrawable *(*getDrawable)(__DRInativeDisplay *dpy, __DRIid draw,
-				  void *drawablePrivate);
-
-    /**
-     * Opaque pointer to private per screen direct rendering data.  \c NULL
-     * if direct rendering is not supported on this screen.  Never
-     * dereferenced in libGL.
-     */
-    void *private;
-
-    /**
-     * Get the number of vertical refreshes since some point in time before
-     * this function was first called (i.e., system start up).
-     * 
-     * \since Internal API version 20030317.
-     */
-    int (*getMSC)( void *screenPrivate, int64_t *msc );
-
-    /**
-     * Opaque pointer that points back to the containing 
-     * \c __GLXscreenConfigs.  This data structure is shared with DRI drivers
-     * but \c __GLXscreenConfigs is not. However, they are needed by some GLX
-     * functions called by DRI drivers.
-     *
-     * \since Internal API version 20030813.
-     */
-    void *screenConfigs;
-
-    /**
-     * Functions associated with MESA_allocate_memory.
-     *
-     * \since Internal API version 20030815.
-     */
-    /*@{*/
-    void *(*allocateMemory)(__DRInativeDisplay *dpy, int scrn, GLsizei size,
-			    GLfloat readfreq, GLfloat writefreq,
-			    GLfloat priority);
-   
-    void (*freeMemory)(__DRInativeDisplay *dpy, int scrn, GLvoid *pointer);
-   
-    GLuint (*memoryOffset)(__DRInativeDisplay *dpy, int scrn, const GLvoid *pointer);
-    /*@}*/
-
-    /**
-     * Method to create the private DRI context data and initialize the
-     * context dependent methods.
-     *
-     * \since Internal API version 20031201.
-     */
-    void * (*createNewContext)(__DRInativeDisplay *dpy, const __GLcontextModes *modes,
-			       int render_type,
-			       void *sharedPrivate, __DRIcontext *pctx);
-
-    /**
-     * Method to override base texture image with a driver specific 'offset'.
-     * The depth passed in allows e.g. to ignore the alpha channel of texture
-     * images where the non-alpha components don't occupy a whole texel.
-     *
-     * For GLX_EXT_texture_from_pixmap with AIGLX.
-     *
-     * \since Internal API version 20070121.
-     */
-    void (*setTexOffset)(__DRIcontext *pDRICtx, GLint texname,
-			 unsigned long long offset, GLint depth, GLuint pitch);
-};
-
-/**
- * Context dependent methods.  This structure is initialized during the
- * \c __DRIscreenRec::createContext call.
- */
-struct __DRIcontextRec {
-    /**
-     * Method to destroy the private DRI context data.
-     */
-    void (*destroyContext)(__DRInativeDisplay *dpy, int scrn, void *contextPrivate);
-
-    /**
-     * Opaque pointer to private per context direct rendering data.
-     * \c NULL if direct rendering is not supported on the display or
-     * screen used to create this context.  Never dereferenced in libGL.
-     */
-    void *private;
-
-    /**
-     * Pointer to the mode used to create this context.
-     *
-     * \since Internal API version 20040317.
-     */
-    const __GLcontextModes * mode;
-
-    /**
-     * Method to bind a DRI drawable to a DRI graphics context.
-     *
-     * \since Internal API version 20050727.
-     */
-    GLboolean (*bindContext)(__DRInativeDisplay *dpy, int scrn, __DRIid draw,
-			 __DRIid read, __DRIcontext *ctx);
-
-    /**
-     * Method to unbind a DRI drawable from a DRI graphics context.
-     *
-     * \since Internal API version 20050727.
-     */
-    GLboolean (*unbindContext)(__DRInativeDisplay *dpy, int scrn, __DRIid draw,
-			   __DRIid read, __DRIcontext *ctx);
-};
-
-/**
- * Drawable dependent methods.  This structure is initialized during the
- * \c __DRIscreenRec::createDrawable call.  \c createDrawable is not called
- * by libGL at this time.  It's currently used via the dri_util.c utility code
- * instead.
- */
-struct __DRIdrawableRec {
-    /**
-     * Method to destroy the private DRI drawable data.
-     */
-    void (*destroyDrawable)(__DRInativeDisplay *dpy, void *drawablePrivate);
-
-    /**
-     * Method to swap the front and back buffers.
-     */
-    void (*swapBuffers)(__DRInativeDisplay *dpy, void *drawablePrivate);
-
-    /**
-     * Opaque pointer to private per drawable direct rendering data.
-     * \c NULL if direct rendering is not supported on the display or
-     * screen used to create this drawable.  Never dereferenced in libGL.
-     */
-    void *private;
-
-    /**
-     * Get the number of completed swap buffers for this drawable.
-     *
-     * \since Internal API version 20030317.
-     */
-    int (*getSBC)(__DRInativeDisplay *dpy, void *drawablePrivate, int64_t *sbc );
-
-    /**
-     * Wait for the SBC to be greater than or equal target_sbc.
-     *
-     * \since Internal API version 20030317.
-     */
-    int (*waitForSBC)( __DRInativeDisplay * dpy, void *drawablePriv,
-		       int64_t target_sbc,
-		       int64_t * msc, int64_t * sbc );
-
-    /**
-     * Wait for the MSC to equal target_msc, or, if that has already passed,
-     * the next time (MSC % divisor) is equal to remainder.  If divisor is
-     * zero, the function will return as soon as MSC is greater than or equal
-     * to target_msc.
-     * 
-     * \since Internal API version 20030317.
-     */
-    int (*waitForMSC)( __DRInativeDisplay * dpy, void *drawablePriv,
-		       int64_t target_msc, int64_t divisor, int64_t remainder,
-		       int64_t * msc, int64_t * sbc );
-
-    /**
-     * Like \c swapBuffers, but does NOT have an implicit \c glFlush.  Once
-     * rendering is complete, waits until MSC is equal to target_msc, or
-     * if that has already passed, waits until (MSC % divisor) is equal
-     * to remainder.  If divisor is zero, the swap will happen as soon as
-     * MSC is greater than or equal to target_msc.
-     * 
-     * \since Internal API version 20030317.
-     */
-    int64_t (*swapBuffersMSC)(__DRInativeDisplay *dpy, void *drawablePrivate,
-			      int64_t target_msc,
-			      int64_t divisor, int64_t remainder);
-
-    /**
-     * Enable or disable frame usage tracking.
-     * 
-     * \since Internal API version 20030317.
-     */
-    int (*frameTracking)(__DRInativeDisplay *dpy, void *drawablePrivate, GLboolean enable);
-
-    /**
-     * Retrieve frame usage information.
-     * 
-     * \since Internal API version 20030317.
-     */
-    int (*queryFrameTracking)(__DRInativeDisplay *dpy, void *drawablePrivate,
-			      int64_t * sbc, int64_t * missedFrames,
-			      float * lastMissedUsage, float * usage );
-
-    /**
-     * Used by drivers that implement the GLX_SGI_swap_control or
-     * GLX_MESA_swap_control extension.
-     *
-     * \since Internal API version 20030317.
-     */
-    unsigned swap_interval;
-
-    /**
-     * Used by drivers that implement the GLX_MESA_copy_sub_buffer extension.
-     *
-     * \since Internal API version 20060314.
-     */
-    void (*copySubBuffer)(__DRInativeDisplay *dpy, void *drawablePrivate,
-			  int x, int y, int w, int h);
-};
-
-#endif
diff --git a/hw/kdrive/ephyr/Makefile.am b/hw/kdrive/ephyr/Makefile.am
index d13bbae..90fd4d8 100644
--- a/hw/kdrive/ephyr/Makefile.am
+++ b/hw/kdrive/ephyr/Makefile.am
@@ -34,6 +34,7 @@ HOSTDRI_SRCS =			\
 	ephyrdri.c		\
 	ephyrdri.h		\
 	XF86dri.c		\
+	xf86dri.h		\
 	ephyrglxext.c		\
 	ephyrglxext.h		\
 	ephyrhostglx.c		\
diff --git a/hw/kdrive/ephyr/XF86dri.c b/hw/kdrive/ephyr/XF86dri.c
index e656ff5..a5fc9bd 100644
--- a/hw/kdrive/ephyr/XF86dri.c
+++ b/hw/kdrive/ephyr/XF86dri.c
@@ -55,9 +55,8 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 #include <X11/extensions/Xext.h>
 #include <X11/extensions/extutil.h>
 #include <GL/glx.h>
-#include <X11/dri/xf86dri.h>
+#include "xf86dri.h"
 #include <X11/dri/xf86dristr.h>
-#include "GL/internal/dri_interface.h"
 
 static XExtensionInfo _xf86dri_info_data;
 static XExtensionInfo *xf86dri_info = &_xf86dri_info_data;
diff --git a/hw/kdrive/ephyr/ephyrdri.c b/hw/kdrive/ephyr/ephyrdri.c
index 53a96ba..bb4f6a1 100644
--- a/hw/kdrive/ephyr/ephyrdri.c
+++ b/hw/kdrive/ephyr/ephyrdri.c
@@ -35,7 +35,7 @@
 #include <X11/Xlibint.h>
 /*#define _XF86DRI_SERVER_*/
 #include <GL/glx.h>
-#include <X11/dri/xf86dri.h>
+#include "xf86dri.h"
 #include "hostx.h"
 #include "ephyrdri.h"
 #define _HAVE_XALLOC_DECLS
diff --git a/hw/kdrive/ephyr/xf86dri.h b/hw/kdrive/ephyr/xf86dri.h
new file mode 100644
index 0000000..cd650b5
--- /dev/null
+++ b/hw/kdrive/ephyr/xf86dri.h
@@ -0,0 +1,120 @@
+/* $XFree86: xc/lib/GL/dri/xf86dri.h,v 1.8 2002/10/30 12:51:25 alanh Exp $ */
+/**************************************************************************
+
+Copyright 1998-1999 Precision Insight, Inc., Cedar Park, Texas.
+Copyright 2000 VA Linux Systems, Inc.
+All Rights Reserved.
+
+Permission is hereby granted, free of charge, to any person obtaining a
+copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sub license, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice (including the
+next paragraph) shall be included in all copies or substantial portions
+of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
+IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
+ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+**************************************************************************/
+
+/**
+ * \file xf86dri.h
+ * Protocol numbers and function prototypes for DRI X protocol.
+ *
+ * \author Kevin E. Martin <martin at valinux.com>
+ * \author Jens Owen <jens at tungstengraphics.com>
+ * \author Rickard E. (Rik) Faith <faith at valinux.com>
+ */
+
+#ifndef _XF86DRI_H_
+#define _XF86DRI_H_
+
+#include <X11/Xfuncproto.h>
+#include <xf86drm.h>
+
+#define X_XF86DRIQueryVersion			0
+#define X_XF86DRIQueryDirectRenderingCapable	1
+#define X_XF86DRIOpenConnection			2
+#define X_XF86DRICloseConnection		3
+#define X_XF86DRIGetClientDriverName		4
+#define X_XF86DRICreateContext			5
+#define X_XF86DRIDestroyContext			6
+#define X_XF86DRICreateDrawable			7
+#define X_XF86DRIDestroyDrawable		8
+#define X_XF86DRIGetDrawableInfo		9
+#define X_XF86DRIGetDeviceInfo			10
+#define X_XF86DRIAuthConnection                 11
+#define X_XF86DRIOpenFullScreen                 12   /* Deprecated */
+#define X_XF86DRICloseFullScreen                13   /* Deprecated */
+
+#define XF86DRINumberEvents		0
+
+#define XF86DRIClientNotLocal		0
+#define XF86DRIOperationNotSupported	1
+#define XF86DRINumberErrors		(XF86DRIOperationNotSupported + 1)
+
+#ifndef _XF86DRI_SERVER_
+
+_XFUNCPROTOBEGIN
+
+Bool XF86DRIQueryExtension( Display *dpy, int *event_base, int *error_base );
+
+Bool XF86DRIQueryVersion( Display *dpy, int *majorVersion, int *minorVersion,
+    int *patchVersion );
+
+Bool XF86DRIQueryDirectRenderingCapable( Display *dpy, int screen,
+    Bool *isCapable );
+
+Bool XF86DRIOpenConnection( Display *dpy, int screen, drm_handle_t *hSAREA,
+    char **busIDString );
+
+Bool XF86DRIAuthConnection( Display *dpy, int screen, drm_magic_t magic );
+
+Bool XF86DRICloseConnection( Display *dpy, int screen );
+
+Bool XF86DRIGetClientDriverName( Display *dpy, int screen,
+    int *ddxDriverMajorVersion, int *ddxDriverMinorVersion,
+    int *ddxDriverPatchVersion, char **clientDriverName );
+
+Bool XF86DRICreateContext( Display *dpy, int screen, Visual *visual,
+    XID *ptr_to_returned_context_id, drm_context_t *hHWContext );
+
+Bool XF86DRICreateContextWithConfig( Display *dpy, int screen, int configID,
+    XID *ptr_to_returned_context_id, drm_context_t *hHWContext );
+
+extern GLboolean XF86DRIDestroyContext( Display *dpy, int screen,
+    XID context_id );
+
+extern GLboolean XF86DRICreateDrawable( Display *dpy, int screen,
+    XID drawable, drm_drawable_t *hHWDrawable );
+
+extern GLboolean XF86DRIDestroyDrawable( Display *dpy, int screen, 
+    XID drawable);
+
+Bool XF86DRIGetDrawableInfo( Display *dpy, int screen, Drawable drawable,
+    unsigned int *index, unsigned int *stamp, 
+    int *X, int *Y, int *W, int *H,
+    int *numClipRects, drm_clip_rect_t ** pClipRects,
+    int *backX, int *backY,
+    int *numBackClipRects, drm_clip_rect_t **pBackClipRects );
+
+Bool XF86DRIGetDeviceInfo( Display *dpy, int screen,
+    drm_handle_t *hFrameBuffer, int *fbOrigin, int *fbSize,
+    int *fbStride, int *devPrivateSize, void **pDevPrivate );
+
+_XFUNCPROTOEND
+
+#endif /* _XF86DRI_SERVER_ */
+
+#endif /* _XF86DRI_H_ */
+
commit 7ffc68c5cc7108c9e56af25f9f9b4398f5b027df
Author: George Sapountzis <gsap7 at yahoo.gr>
Date:   Wed Apr 23 17:45:54 2008 +0300

    xephyr: libGL is client lib

diff --git a/configure.ac b/configure.ac
index c1c10f7..21c1d91 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1917,6 +1917,10 @@ if test "$KDRIVE" = yes; then
     if test "x$XV" = xyes; then
         XEPHYR_REQUIRED_LIBS="$XEPHYR_REQUIRED_LIBS xv"
     fi
+    if test "x$DRI" = xyes && test "x$GLX" = xyes; then
+        XEPHYR_REQUIRED_LIBS="$XEPHYR_REQUIRED_LIBS gl libdrm"
+    fi
+
     PKG_CHECK_MODULES(XEPHYR, $XEPHYR_REQUIRED_LIBS, [xephyr="yes"], [xephyr="no"])
     if test "x$XEPHYR" = xauto; then
         XEPHYR=$xephyr
@@ -1924,10 +1928,6 @@ if test "$KDRIVE" = yes; then
     XEPHYR_DRI=no
     if test x$XEPHYR = xyes -a x$DRI = xyes && test "x$GLX" = xyes; then
         XEPHYR_DRI=yes
-        XEPHYR_DRI_LIBS=-lGL
-        AC_SUBST(XEPHYR_DRI_LIBS)
-    fi
-    if test x$XEPHYR_DRI = xyes ; then
         AC_DEFINE(XEPHYR_DRI,1,[enable DRI extension in xephyr])
     fi
 
@@ -1965,9 +1965,6 @@ if test "$KDRIVE" = yes; then
     KDRIVE_LOCAL_LIBS="$KDRIVE_LOCAL_LIBS $KDRIVE_OS_LIB $OS_LIB"
     KDRIVE_LIBS="$TSLIB_LIBS $KDRIVE_LOCAL_LIBS $XSERVER_SYS_LIBS $GLX_SYS_LIBS"
 
-    # check if we can build Xephyr
-    PKG_CHECK_MODULES(XEPHYR, $XEPHYR_REQUIRED_LIBS, [xephyr="yes"], [xephyr="no"])
-
     AC_SUBST([XEPHYR_LIBS])
     AC_SUBST([XEPHYR_INCS])
     AC_SUBST([XSDL_LIBS])
diff --git a/hw/kdrive/ephyr/Makefile.am b/hw/kdrive/ephyr/Makefile.am
index dc0144a..d13bbae 100644
--- a/hw/kdrive/ephyr/Makefile.am
+++ b/hw/kdrive/ephyr/Makefile.am
@@ -2,15 +2,11 @@ INCLUDES = 			\
 	@KDRIVE_INCS@		\
 	@KDRIVE_CFLAGS@		\
 	@XEPHYR_INCS@		\
+	@XEPHYR_CFLAGS@		\
+	@DRIPROTO_CFLAGS@	\
 	-I$(top_srcdir)		\
 	-I$(top_srcdir)/exa
 
-if XEPHYR_HAS_DRI
-INCLUDES +=			\
-	@LIBDRM_CFLAGS@		\
-	@DRIPROTO_CFLAGS@
-endif
-
 if XV
 LIBXEPHYR_HOSTXV=libxephyr-hostxv.a
 endif
@@ -76,9 +72,7 @@ Xephyr_LDADD = 						\
 	$(LIBXEPHYR_HOSTDRI)				\
 	$(top_builddir)/exa/libexa.la			\
 	@KDRIVE_LIBS@					\
-	@XEPHYR_LIBS@ 					\
-	@LIBDRM_LIBS@					\
-	@XEPHYR_DRI_LIBS@
+	@XEPHYR_LIBS@
 
 Xephyr_DEPENDENCIES =	\
 	libxephyr.a					\
commit a27c244d72603e27766ff3900ab28fe094f7397e
Author: George Sapountzis <gsap7 at yahoo.gr>
Date:   Wed Apr 23 17:45:37 2008 +0300

    xephyr: Makefile cleanup 2

diff --git a/hw/kdrive/ephyr/Makefile.am b/hw/kdrive/ephyr/Makefile.am
index f0182d5..dc0144a 100644
--- a/hw/kdrive/ephyr/Makefile.am
+++ b/hw/kdrive/ephyr/Makefile.am
@@ -23,19 +23,16 @@ noinst_LIBRARIES = libxephyr-hostx.a $(LIBXEPHYR_HOSTXV) $(LIBXEPHYR_HOSTDRI) li
 
 bin_PROGRAMS = Xephyr
 
-libxephyr_hostx_a_SOURCES =	\
+HOSTX_SRCS =			\
 	hostx.c			\
 	hostx.h
 
-if XV
-libxephyr_hostxv_a_SOURCES=	\
+HOSTVIDEO_SRCS =		\
 	ephyrvideo.c		\
 	ephyrhostvideo.c	\
 	ephyrhostvideo.h
-endif
 
-if XEPHYR_HAS_DRI
-libxephyr_hostdri_a_SOURCES=	\
+HOSTDRI_SRCS =			\
 	ephyrdriext.c		\
 	ephyrdriext.h		\
 	ephyrdri.c		\
@@ -45,15 +42,26 @@ libxephyr_hostdri_a_SOURCES=	\
 	ephyrglxext.h		\
 	ephyrhostglx.c		\
 	ephyrhostglx.h
-endif
 
-libxephyr_a_SOURCES =		\
+XEPHYR_SRCS =			\
 	ephyr.c			\
 	ephyr.h			\
 	ephyrlog.h		\
 	ephyr_draw.c		\
 	os.c
 
+libxephyr_hostx_a_SOURCES = $(HOSTX_SRCS)
+
+if XV
+libxephyr_hostxv_a_SOURCES = $(HOSTVIDEO_SRCS)
+endif
+
+if XEPHYR_HAS_DRI
+libxephyr_hostdri_a_SOURCES = $(HOSTDRI_SRCS)
+endif
+
+libxephyr_a_SOURCES = $(XEPHYR_SRCS)
+
 Xephyr_SOURCES = \
 	ephyrinit.c
 
@@ -81,3 +89,7 @@ Xephyr_DEPENDENCIES =	\
 
 relink:
 	rm -f $(bin_PROGRAMS) && make $(bin_PROGRAMS)
+
+EXTRA_DIST = \
+	$(HOSTVIDEO_SRCS) \
+	$(HOSTDRI_SRCS)
commit d4d19b2f22002b1579438cb9cf08dd580c7ec005
Author: George Sapountzis <gsap7 at yahoo.gr>
Date:   Wed Apr 23 17:45:19 2008 +0300

    xephyr: Makefile cleanup 1

diff --git a/hw/kdrive/ephyr/Makefile.am b/hw/kdrive/ephyr/Makefile.am
index 7ef22a3..f0182d5 100644
--- a/hw/kdrive/ephyr/Makefile.am
+++ b/hw/kdrive/ephyr/Makefile.am
@@ -1,68 +1,58 @@
-INCLUDES = 					\
-	@KDRIVE_INCS@				\
-	@KDRIVE_CFLAGS@				\
-	-I$(srcdir)/../../../exa
+INCLUDES = 			\
+	@KDRIVE_INCS@		\
+	@KDRIVE_CFLAGS@		\
+	@XEPHYR_INCS@		\
+	-I$(top_srcdir)		\
+	-I$(top_srcdir)/exa
+
+if XEPHYR_HAS_DRI
+INCLUDES +=			\
+	@LIBDRM_CFLAGS@		\
+	@DRIPROTO_CFLAGS@
+endif
 
 if XV
-    LIBXEPHYR_HOSTXV=libxephyr-hostxv.a
-else
-    LIBXEPHYR_HOSTXV=
+LIBXEPHYR_HOSTXV=libxephyr-hostxv.a
 endif
 
 if XEPHYR_HAS_DRI
-    LIBXEPHYR_HOSTDRI=libxephyr-hostdri.a
-else
-    LIBXEPHYR_HOSTDRI=
+LIBXEPHYR_HOSTDRI=libxephyr-hostdri.a
 endif
 
 noinst_LIBRARIES = libxephyr-hostx.a $(LIBXEPHYR_HOSTXV) $(LIBXEPHYR_HOSTDRI) libxephyr.a
 
 bin_PROGRAMS = Xephyr
 
-libxephyr_hostx_a_SOURCES =                             \
-	hostx.c                                         \
+libxephyr_hostx_a_SOURCES =	\
+	hostx.c			\
 	hostx.h
 
-libxephyr_hostxv_a_INCLUDES = @XEPHYR_INCS@
-
 if XV
-libxephyr_hostxv_a_SOURCES=				\
-	ephyrhostvideo.c \
+libxephyr_hostxv_a_SOURCES=	\
+	ephyrvideo.c		\
+	ephyrhostvideo.c	\
 	ephyrhostvideo.h
 endif
 
 if XEPHYR_HAS_DRI
-
-libxephyr_hostdri_a_SOURCES= \
-ephyrdriext.c	\
-ephyrdriext.h	\
-ephyrdri.c	\
-ephyrdri.h	\
-XF86dri.c	\
-ephyrglxext.c	\
-ephyrglxext.h	\
-ephyrhostglx.c	\
-ephyrhostglx.h	
-
-libxephyr_hostdri_a_CFLAGS= \
--I$(top_srcdir)		\
- at LIBDRM_CFLAGS@ 	\
- at DRIPROTO_CFLAGS@
-
+libxephyr_hostdri_a_SOURCES=	\
+	ephyrdriext.c		\
+	ephyrdriext.h		\
+	ephyrdri.c		\
+	ephyrdri.h		\
+	XF86dri.c		\
+	ephyrglxext.c		\
+	ephyrglxext.h		\
+	ephyrhostglx.c		\
+	ephyrhostglx.h
 endif
 
-libxephyr_a_SOURCES =	\
-	ephyr.c		\
-	ephyr_draw.c	\
-	ephyrvideo.c	\
-	os.c		\
-	hostx.h         \
-	ephyr.h		\
-	ephyrlog.h
-
-libxephyr_a_CFLAGS = \
--I$(top_srcdir) \
- at LIBDRM_CFLAGS@
+libxephyr_a_SOURCES =		\
+	ephyr.c			\
+	ephyr.h			\
+	ephyrlog.h		\
+	ephyr_draw.c		\
+	os.c
 
 Xephyr_SOURCES = \
 	ephyrinit.c
@@ -73,18 +63,18 @@ endif
 
 Xephyr_LDADD = 						\
 	libxephyr.a					\
-	libxephyr-hostx.a			        \
+	libxephyr-hostx.a				\
 	$(LIBXEPHYR_HOSTXV)				\
 	$(LIBXEPHYR_HOSTDRI)				\
-	../../../exa/libexa.la				\
+	$(top_builddir)/exa/libexa.la			\
 	@KDRIVE_LIBS@					\
-        @XEPHYR_LIBS@ 					\
+	@XEPHYR_LIBS@ 					\
 	@LIBDRM_LIBS@					\
 	@XEPHYR_DRI_LIBS@
 
 Xephyr_DEPENDENCIES =	\
 	libxephyr.a					\
-	libxephyr-hostx.a			        \
+	libxephyr-hostx.a				\
 	$(LIBXEPHYR_HOSTXV)				\
 	$(LIBXEPHYR_HOSTDRI)				\
 	@KDRIVE_LOCAL_LIBS@
commit cdc4571b580a8f4fd279404215bff0fb9a5b4816
Author: George Sapountzis <gsap7 at yahoo.gr>
Date:   Sun Apr 20 17:06:26 2008 +0300

    drop TOGCUP remnants

diff --git a/configure.ac b/configure.ac
index aba4619..c1c10f7 100644
--- a/configure.ac
+++ b/configure.ac
@@ -547,7 +547,6 @@ AC_ARG_ENABLE(xcsecurity,     AS_HELP_STRING([--disable-xcsecurity], [Build Secu
 AC_ARG_ENABLE(xcalibrate,     AS_HELP_STRING([--enable-xcalibrate], [Build XCalibrate extension (default: disabled)]), [XCALIBRATE=$enableval], [XCALIBRATE=no])
 AC_ARG_ENABLE(tslib,          AS_HELP_STRING([--enable-tslib], [Build kdrive tslib touchscreen support (default: disabled)]), [TSLIB=$enableval], [TSLIB=no])
 AC_ARG_ENABLE(xevie,          AS_HELP_STRING([--disable-xevie], [Build XEvIE extension (default: enabled)]), [XEVIE=$enableval], [XEVIE=yes])
-AC_ARG_ENABLE(cup,            AS_HELP_STRING([--disable-cup], [Build TOG-CUP extension (default: enabled)]), [CUP=$enableval], [CUP=yes])
 AC_ARG_ENABLE(multibuffer,    AS_HELP_STRING([--enable-multibuffer], [Build Multibuffer extension (default: disabled)]), [MULTIBUFFER=$enableval], [MULTIBUFFER=no])
 AC_ARG_ENABLE(fontcache,      AS_HELP_STRING([--enable-fontcache], [Build FontCache extension (default: disabled)]), [FONTCACHE=$enableval], [FONTCACHE=no])
 AC_ARG_ENABLE(dbe,            AS_HELP_STRING([--disable-dbe], [Build DBE extension (default: enabled)]), [DBE=$enableval], [DBE=yes])
@@ -930,12 +929,6 @@ if test "x$XEVIE" = xyes; then
 	REQUIRED_MODULES="$REQUIRED_MODULES evieproto"
 fi
 
-AM_CONDITIONAL(CUP, [test "x$CUP" = xyes])
-if test "x$CUP" = xyes; then
-	AC_DEFINE(TOGCUP, 1, [Build TOG-CUP extension])
-	# Requires xextproto which is always required
-fi
-
 AM_CONDITIONAL(MULTIBUFFER, [test "x$MULTIBUFFER" = xyes])
 if test "x$MULTIBUFFER" = xyes; then
 	AC_DEFINE(MULTIBUFFER, 1, [Build Multibuffer extension])
commit 6cd9287aed3c128d9c10b9b042ba7b864143d522
Author: George Sapountzis <gsap7 at yahoo.gr>
Date:   Sun Apr 20 16:58:51 2008 +0300

    drop EVI remnants

diff --git a/Xext/EVIstruct.h b/Xext/EVIstruct.h
deleted file mode 100644
index e658190..0000000
--- a/Xext/EVIstruct.h
+++ /dev/null
@@ -1,58 +0,0 @@
-/************************************************************
-Copyright (c) 1997 by Silicon Graphics Computer Systems, Inc.
-Permission to use, copy, modify, and distribute this
-software and its documentation for any purpose and without
-fee is hereby granted, provided that the above copyright
-notice appear in all copies and that both that copyright
-notice and this permission notice appear in supporting
-documentation, and that the name of Silicon Graphics not be
-used in advertising or publicity pertaining to distribution
-of the software without specific prior written permission.
-Silicon Graphics makes no representation about the suitability
-of this software for any purpose. It is provided "as is"
-without any express or implied warranty.
-SILICON GRAPHICS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
-SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
-AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON
-GRAPHICS BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL
-DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
-DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
-OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION  WITH
-THE USE OR PERFORMANCE OF THIS SOFTWARE.
-********************************************************/
-
-#ifdef HAVE_DIX_CONFIG_H
-#include <dix-config.h>
-#endif
-
-#ifndef EVI_STRUCT_H
-#define EVI_STRUCT_H
-
-/*
- ******************************************************************************
- ** Per-ddx data
- ******************************************************************************
- */
-
-typedef int (*GetVisualInfoProc)(
-	VisualID32*,
-	int,
-	xExtendedVisualInfo**,
-	int*,
-	VisualID32**,
-	int*
-);
-
-typedef void (*FreeVisualInfoProc)(
-    xExtendedVisualInfo*,
-    VisualID32*
-);
-typedef struct _EviPrivRec {
-    GetVisualInfoProc getVisualInfo;
-    FreeVisualInfoProc freeVisualInfo;
-} EviPrivRec, *EviPrivPtr;
-
-extern EviPrivPtr eviDDXInit(void);
-extern void eviDDXReset(void);
-
-#endif /* EVI_STRUCT_H */
commit a88c6b66465c039bf92a54a496516fee4d900784
Author: George Sapountzis <gsap7 at yahoo.gr>
Date:   Fri Apr 18 17:47:16 2008 +0300

    glcore: drop GLcore (files)

diff --git a/GL/mesa/.gitignore b/GL/mesa/.gitignore
deleted file mode 100644
index 6b92b24..0000000
--- a/GL/mesa/.gitignore
+++ /dev/null
@@ -1,32 +0,0 @@
-X/drivers
-X/glxheader.h
-X/xm*.h
-X/xm*.c
-mesa/drivers
-mesa/glxheader.h
-mesa/xm*.c
-glapi/*.c
-glapi/*.h
-main/*.c
-main/*.h
-math/*.c
-math/*.h
-ppc
-shader/*.c
-shader/*.h
-shader/slang/*.c
-shader/slang/*.h
-shader/slang/library
-shader/grammar/*.c
-shader/grammar/*.h
-sparc
-swrast/*.c
-swrast/*.h
-swrast_setup/*.c
-swrast_setup/*.h
-tnl/*.c
-tnl/*.h
-x86
-x86-64
-vbo/*.c
-vbo/*.h
diff --git a/GL/mesa/Makefile.am b/GL/mesa/Makefile.am
deleted file mode 100644
index 7f27c58..0000000
--- a/GL/mesa/Makefile.am
+++ /dev/null
@@ -1,18 +0,0 @@
-SUBDIRS = X
-SUBDIRS += main math swrast swrast_setup tnl shader glapi vbo
-
-noinst_LTLIBRARIES = libGLcore.la
-
-libGLcore_la_SOURCES = dummy.c
-MESA_LIBS           = main/libmain.la \
-                      math/libmath.la \
-                      swrast/libswrast.la \
-                      swrast_setup/libss.la \
-                      tnl/libtnl.la \
-                      shader/libshader.la \
-		      shader/grammar/libgrammar.la \
-		      shader/slang/libslang.la \
-                      vbo/libvbo.la
-
-libGLcore_la_LIBADD = $(MESA_LIBS) \
-                      X/libX.la
diff --git a/GL/mesa/X/Makefile.am b/GL/mesa/X/Makefile.am
deleted file mode 100644
index d8abbc6..0000000
--- a/GL/mesa/X/Makefile.am
+++ /dev/null
@@ -1,27 +0,0 @@
-noinst_LTLIBRARIES = libX.la
-
-INCLUDES = -I at MESA_SOURCE@/include \
-           -I. \
-           -I at MESA_SOURCE@/src/mesa/glapi \
-           -I at MESA_SOURCE@/src/mesa/main \
-           -I at MESA_SOURCE@/src/mesa
-
-# -DXFree86Server is required because the X11 driver in Mesa thinks that
-# symbol means "being built in the server"
-AM_CFLAGS = \
-	$(DIX_CFLAGS) \
-	-DXFree86Server \
-	@GLX_DEFINES@
-
-XM_SOURCES = \
-	xm_api.c \
-	xm_buffer.c \
-	xm_dd.c \
-	xm_image.c \
-	xm_line.c \
-	xm_span.c \
-	xm_tri.c
-
-XM_SOURCES += drivers/common/driverfuncs.c
-
-nodist_libX_la_SOURCES = $(XM_SOURCES)
diff --git a/GL/mesa/dummy.c b/GL/mesa/dummy.c
deleted file mode 100644
index e69de29..0000000
diff --git a/GL/mesa/glapi/Makefile.am b/GL/mesa/glapi/Makefile.am
deleted file mode 100644
index db79114..0000000
--- a/GL/mesa/glapi/Makefile.am
+++ /dev/null
@@ -1,20 +0,0 @@
-noinst_LTLIBRARIES = libglapi.la
-
-AM_CFLAGS = \
-	$(DIX_CFLAGS) \
-	-DXFree86Server \
-	@GLX_DEFINES@
-
-INCLUDES = -I at MESA_SOURCE@/include \
-           -I../X \
-           -I../glapi \
-           -I../main \
-           -I../math \
-           -I../shader \
-           -I../swrast \
-           -I../swrast_setup \
-           -I../tnl \
-           -I.. \
-           -I$(top_srcdir)/hw/xfree86/os-support
-
-nodist_libglapi_la_SOURCES = glapi.c glthread.c
diff --git a/GL/mesa/main/Makefile.am b/GL/mesa/main/Makefile.am
deleted file mode 100644
index f8ce137..0000000
--- a/GL/mesa/main/Makefile.am
+++ /dev/null
@@ -1,86 +0,0 @@
-noinst_LTLIBRARIES = libmain.la
-
-AM_CFLAGS = \
-	$(DIX_CFLAGS) \
-	-DXFree86Server \
-	@GLX_DEFINES@
-
-INCLUDES = -I at MESA_SOURCE@/include \
-           -I../X \
-           -I../glapi \
-           -I../main \
-           -I../math \
-           -I../shader \
-           -I../swrast \
-           -I../swrast_setup \
-           -I../tnl \
-           -I.. \
-           -I$(top_srcdir)/hw/xfree86/os-support
-
-if NEED_VSNPRINTF
-VSNPRINTF_SOURCES = vsnprintf.c
-endif
-
-nodist_libmain_la_SOURCES = accum.c \
-                    api_arrayelt.c \
-                    api_loopback.c \
-                    api_noop.c \
-                    api_validate.c \
-                    arrayobj.c \
-                    attrib.c \
-                    blend.c \
-                    bufferobj.c \
-                    buffers.c \
-                    clip.c \
-                    colortab.c \
-                    context.c \
-                    convolve.c \
-                    debug.c \
-                    depth.c \
-		    depthstencil.c \
-                    dlist.c \
-                    drawpix.c \
-                    enable.c \
-                    enums.c \
-                    eval.c \
-                    execmem.c \
-                    extensions.c \
-                    fbobject.c \
-                    feedback.c \
-                    fog.c \
-                    framebuffer.c \
-                    get.c \
-                    getstring.c \
-                    hash.c \
-                    hint.c \
-                    histogram.c \
-                    image.c \
-                    imports.c \
-                    light.c \
-                    lines.c \
-                    matrix.c \
-                    mipmap.c \
-                    mm.c \
-                    pixel.c \
-                    points.c \
-                    polygon.c \
-		    queryobj.c \
-                    rastpos.c \
-                    rbadaptors.c \
-                    renderbuffer.c \
-                    shaders.c \
-                    state.c \
-                    stencil.c \
-                    texcompress.c \
-                    texcompress_fxt1.c \
-                    texcompress_s3tc.c \
-                    texenvprogram.c \
-                    texformat.c \
-                    teximage.c \
-                    texobj.c \
-                    texrender.c \
-                    texstate.c \
-                    texstore.c \
-                    varray.c \
-                    $(VSNPRINTF_SOURCES) \
-                    vtxfmt.c
diff --git a/GL/mesa/math/Makefile.am b/GL/mesa/math/Makefile.am
deleted file mode 100644
index c7c5642..0000000
--- a/GL/mesa/math/Makefile.am
+++ /dev/null
@@ -1,27 +0,0 @@
-noinst_LTLIBRARIES = libmath.la
-
-AM_CFLAGS = \
-	$(DIX_CFLAGS) \
-	-DXFree86Server \
-	@GLX_DEFINES@
-
-INCLUDES = -I at MESA_SOURCE@/include \
-           -I../X \
-           -I../glapi \
-           -I../main \
-           -I../math \
-           -I../shader \
-           -I../swrast \
-           -I../swrast_setup \
-           -I../tnl \
-           -I.. \
-           -I$(top_srcdir)/hw/xfree86/os-support
-
-nodist_libmath_la_SOURCES = m_debug_clip.c \
-                       m_debug_norm.c \
-                       m_debug_xform.c \
-                       m_eval.c \
-                       m_matrix.c \
-                       m_translate.c \
-                       m_vector.c \
-                       m_xform.c
diff --git a/GL/mesa/shader/Makefile.am b/GL/mesa/shader/Makefile.am
deleted file mode 100644
index abde275..0000000
--- a/GL/mesa/shader/Makefile.am
+++ /dev/null
@@ -1,39 +0,0 @@
-SUBDIRS = grammar slang
-
-noinst_LTLIBRARIES = libshader.la
-
-AM_CFLAGS = \
-	$(DIX_CFLAGS) \
-	-DXFree86Server \
-	@GLX_DEFINES@
-
-INCLUDES = -I at MESA_SOURCE@/include \
-           -I../X \
-           -I../glapi \
-           -I../main \
-           -I../math \
-           -I../shader \
-	   -I../shader/grammar \
-	   -I../shader/slang \
-           -I../swrast \
-           -I../swrast_setup \
-           -I../tnl \
-           -I.. \
-           -I$(top_srcdir)/hw/xfree86/os-support
-
-nodist_libshader_la_SOURCES = \
-                      arbprogparse.c \
-                      arbprogram.c \
-                      atifragshader.c \
-                      nvfragparse.c \
-                      nvprogram.c \
-                      nvvertparse.c \
-                      prog_debug.c \
-                      prog_execute.c \
-                      prog_instruction.c \
-                      prog_parameter.c \
-                      prog_print.c \
-                      program.c \
-                      programopt.c \
-                      prog_statevars.c \
-                      shader_api.c
diff --git a/GL/mesa/shader/grammar/Makefile.am b/GL/mesa/shader/grammar/Makefile.am
deleted file mode 100644
index 332c8e9..0000000
--- a/GL/mesa/shader/grammar/Makefile.am
+++ /dev/null
@@ -1,20 +0,0 @@
-noinst_LTLIBRARIES = libgrammar.la
-
-AM_CFLAGS = \
-	$(DIX_CFLAGS) \
-	-DXFree86Server \
-	@GLX_DEFINES@
-
-INCLUDES = -I at MESA_SOURCE@/include \
-           -I../../X \
-           -I../../glapi \
-           -I../../main \
-           -I../../math \
-           -I../../shader \
-           -I../../swrast \
-           -I../../swrast_setup \
-           -I../../tnl \
-           -I../.. \
-           -I$(top_srcdir)/hw/xfree86/os-support
-
-nodist_libgrammar_la_SOURCES = grammar_mesa.c
diff --git a/GL/mesa/shader/slang/Makefile.am b/GL/mesa/shader/slang/Makefile.am
deleted file mode 100644
index 71498ee..0000000
--- a/GL/mesa/shader/slang/Makefile.am
+++ /dev/null
@@ -1,41 +0,0 @@
-noinst_LTLIBRARIES = libslang.la
-
-AM_CFLAGS = \
-	$(DIX_CFLAGS) \
-	-DXFree86Server \
-	@GLX_DEFINES@
-
-INCLUDES = -I at MESA_SOURCE@/include \
-           -I../grammar \
-           -I../../X \
-           -I../../glapi \
-           -I../../main \
-           -I../../math \
-           -I../../shader \
-           -I../../swrast \
-           -I../../swrast_setup \
-           -I../../tnl \
-           -I../.. \
-           -I$(top_srcdir)/hw/xfree86/os-support
-
-nodist_libslang_la_SOURCES = slang_builtin.c \
-		      slang_codegen.c \
-		      slang_compile.c \
-		      slang_compile_function.c \
-		      slang_compile_operation.c \
-		      slang_compile_struct.c \
-		      slang_compile_variable.c \
-		      slang_emit.c \
-		      slang_ir.c \
-		      slang_label.c \
-		      slang_library_noise.c \
-		      slang_link.c \
-		      slang_log.c \
-		      slang_mem.c \
-		      slang_preprocess.c \
-		      slang_print.c \
-		      slang_simplify.c \
-		      slang_storage.c \
-		      slang_typeinfo.c \
-		      slang_utility.c \
-		      slang_vartable.c
diff --git a/GL/mesa/swrast/Makefile.am b/GL/mesa/swrast/Makefile.am
deleted file mode 100644
index bffb1e7..0000000
--- a/GL/mesa/swrast/Makefile.am
+++ /dev/null
@@ -1,50 +0,0 @@
-noinst_LTLIBRARIES = libswrast.la
-
-AM_CFLAGS = \
-	$(DIX_CFLAGS) \
-	-DXFree86Server \
-	@GLX_DEFINES@
-
-INCLUDES = -I at MESA_SOURCE@/include \
-           -I../X \
-           -I../glapi \
-           -I../main \
-           -I../math \
-           -I../shader \
-           -I../shader/slang \
-	   -I../shader/slang \
-           -I../swrast \
-           -I../swrast_setup \
-           -I../tnl \
-           -I.. \
-           -I$(top_srcdir)/hw/xfree86/os-support
-
-nodist_libswrast_la_SOURCES = s_aaline.c \
-                      s_aatriangle.c \
-                      s_accum.c \
-                      s_alpha.c \
-                      s_atifragshader.c \
-                      s_bitmap.c \
-                      s_blend.c \
-                      s_blit.c \
-                      s_buffers.c \
-                      s_context.c \
-                      s_copypix.c \
-                      s_depth.c \
-                      s_drawpix.c \
-                      s_feedback.c \
-                      s_fog.c \
-		      s_fragprog.c \
-                      s_imaging.c \
-                      s_lines.c \
-                      s_logic.c \
-                      s_masking.c \
-                      s_points.c \
-                      s_readpix.c \
-                      s_span.c \
-                      s_stencil.c \
-		      s_texcombine.c \
-		      s_texfilter.c \
-                      s_texstore.c \
-                      s_triangle.c \
-                      s_zoom.c
diff --git a/GL/mesa/swrast_setup/Makefile.am b/GL/mesa/swrast_setup/Makefile.am
deleted file mode 100644
index 1f3c031..0000000
--- a/GL/mesa/swrast_setup/Makefile.am
+++ /dev/null
@@ -1,20 +0,0 @@
-noinst_LTLIBRARIES = libss.la
-
-AM_CFLAGS = \
-	$(DIX_CFLAGS) \
-	-DXFree86Server \
-	@GLX_DEFINES@
-
-INCLUDES = -I at MESA_SOURCE@/include \
-           -I../X \
-           -I../glapi \
-           -I../main \
-           -I../math \
-           -I../shader \
-           -I../swrast \
-           -I../swrast_setup \
-           -I../tnl \
-           -I.. \
-           -I$(top_srcdir)/hw/xfree86/os-support
-
-nodist_libss_la_SOURCES = ss_context.c ss_triangle.c
diff --git a/GL/mesa/tnl/Makefile.am b/GL/mesa/tnl/Makefile.am
deleted file mode 100644
index b3c8206..0000000
--- a/GL/mesa/tnl/Makefile.am
+++ /dev/null
@@ -1,37 +0,0 @@
-noinst_LTLIBRARIES = libtnl.la
-
-AM_CFLAGS = \
-	$(DIX_CFLAGS) \
-	-DXFree86Server \
-	@GLX_DEFINES@
-
-INCLUDES = -I at MESA_SOURCE@/include \
-           -I../X \
-           -I../glapi \
-           -I../main \
-           -I../math \
-           -I../shader \
-           -I../shader/slang \
-           -I../swrast \
-           -I../swrast_setup \
-           -I../tnl \
-           -I.. \
-           -I$(top_srcdir)/hw/xfree86/os-support
-
-nodist_libtnl_la_SOURCES = t_context.c \
-                      t_draw.c \
-                      t_pipeline.c \
-                      t_vb_cull.c \
-                      t_vb_fog.c \
-                      t_vb_light.c \
-                      t_vb_normals.c \
-                      t_vb_points.c \
-                      t_vb_program.c \
-                      t_vb_render.c \
-                      t_vb_texgen.c \
-                      t_vb_texmat.c \
-                      t_vb_vertex.c \
-                      t_vertex.c \
-                      t_vertex_generic.c \
-                      t_vertex_sse.c \
-                      t_vp_build.c
diff --git a/GL/mesa/vbo/Makefile.am b/GL/mesa/vbo/Makefile.am
deleted file mode 100644
index 9943f2a..0000000
--- a/GL/mesa/vbo/Makefile.am
+++ /dev/null
@@ -1,35 +0,0 @@
-noinst_LTLIBRARIES = libvbo.la
-
-AM_CFLAGS = \
-	$(DIX_CFLAGS) \
-	-DXFree86Server \
-	@GLX_DEFINES@
-
-INCLUDES = -I at MESA_SOURCE@/include \
-           -I../X \
-           -I../glapi \
-           -I../main \
-           -I../math \
-           -I../shader \
-           -I../shader/slang \
-	   -I../shader/slang \
-           -I../swrast \
-           -I../swrast_setup \
-           -I../tnl \
-           -I.. \
-           -I$(top_srcdir)/hw/xfree86/os-support
-
-nodist_libvbo_la_SOURCES = vbo_context.c \
-			vbo_exec_api.c \
-			vbo_exec_array.c \
-			vbo_exec.c \
-			vbo_exec_draw.c \
-			vbo_exec_eval.c \
-			vbo_rebase.c \
-			vbo_save_api.c \
-			vbo_save.c \
-			vbo_save_draw.c \
-			vbo_save_loopback.c \
-			vbo_split.c \
-			vbo_split_copy.c \
-			vbo_split_inplace.c
diff --git a/GL/symlink-mesa.sh b/GL/symlink-mesa.sh
index d611fcf..8deaa43 100755
--- a/GL/symlink-mesa.sh
+++ b/GL/symlink-mesa.sh
@@ -58,169 +58,6 @@ main() {
 
 ## actual symlinking
 
-symlink_mesa_glapi() {
-    src_dir src/mesa/glapi
-    dst_dir mesa/glapi
-
-    for src in $REAL_SRC_DIR/*.c $REAL_SRC_DIR/*.h; do
-        action `basename $src`
-    done
-}
-
-symlink_mesa_main() {
-    src_dir src/mesa/main
-    dst_dir mesa/main
-
-    for src in $REAL_SRC_DIR/*.c $REAL_SRC_DIR/*.h; do
-        action `basename $src`
-    done
-}
-
-symlink_mesa_math() {
-    src_dir src/mesa/math
-    dst_dir mesa/math
-
-    for src in $REAL_SRC_DIR/*.c $REAL_SRC_DIR/*.h; do
-        action `basename $src`
-    done
-}
-
-symlink_mesa_swrast() {
-    src_dir src/mesa/swrast
-    dst_dir mesa/swrast
-
-    for src in $REAL_SRC_DIR/*.c $REAL_SRC_DIR/*.h; do
-        action `basename $src`
-    done
-}
-
-symlink_mesa_ss() {
-    src_dir src/mesa/swrast_setup
-    dst_dir mesa/swrast_setup
-
-    for src in $REAL_SRC_DIR/*.c $REAL_SRC_DIR/*.h; do
-        action `basename $src`
-    done
-}
-
-symlink_mesa_tnl() {
-    src_dir src/mesa/tnl
-    dst_dir mesa/tnl
-
-    for src in $REAL_SRC_DIR/*.c $REAL_SRC_DIR/*.h; do
-        action `basename $src`
-    done
-}
-
-symlink_mesa_shader() {
-    src_dir src/mesa/shader
-    dst_dir mesa/shader
-
-    for src in $REAL_SRC_DIR/*.c $REAL_SRC_DIR/*.h; do
-        action `basename $src`
-    done
-}
-
-symlink_mesa_shader_grammar() {
-    src_dir src/mesa/shader/grammar
-    dst_dir mesa/shader/grammar
-
-    for src in $REAL_SRC_DIR/*.c $REAL_SRC_DIR/*.h; do
-        action `basename $src`
-    done
-}
-
-symlink_mesa_shader_slang() {
-    src_dir src/mesa/shader/slang
-    dst_dir mesa/shader/slang
-
-    for src in $REAL_SRC_DIR/*.c $REAL_SRC_DIR/*.h; do
-        action `basename $src`
-    done
-}
-
-symlink_mesa_shader_slang_library() {
-    src_dir src/mesa/shader/slang/library
-    dst_dir mesa/shader/slang/library
-
-    for src in $REAL_SRC_DIR/*.c $REAL_SRC_DIR/*.h; do
-        action `basename $src`
-    done
-}        
-
-symlink_mesa_vbo() {
-    src_dir src/mesa/vbo
-    dst_dir mesa/vbo
-
-    for src in $REAL_SRC_DIR/*.c $REAL_SRC_DIR/*.h; do
-        action `basename $src`
-    done
-}
-
-symlink_mesa_x() {
-    src_dir src/mesa/drivers/x11
-    dst_dir mesa/X
-
-    # action glxapi.h
-    action glxheader.h
-    # action realglx.h
-    # action xfonts.h
-    action xm_api.c
-    action xm_buffer.c
-    action xm_dd.c
-    action xm_image.c
-    action xm_image.h
-    action xm_line.c
-    action xm_span.c
-    action xm_tri.c
-    action xmesaP.h
-
-    # another hack
-    src_dir src/mesa/drivers/common
-    dst_dir mesa/X/drivers/common
-    action driverfuncs.c
-    action driverfuncs.h
-}
-
-symlink_mesa_ppc() {
-    src_dir src/mesa/ppc
-    dst_dir mesa/ppc
-}
-
-symlink_mesa_sparc() {
-    src_dir src/mesa/sparc
-    dst_dir mesa/sparc
-}
-
-symlink_mesa_x86() {
-    src_dir src/mesa/x86
-    dst_dir mesa/x86
-}
-
-symlink_mesa_x8664() {
-    src_dir src/mesa/x86-64
-    dst_dir mesa/x86-64
-}
-
-symlink_mesa() {
-    symlink_mesa_main
-    symlink_mesa_math
-    symlink_mesa_swrast
-    symlink_mesa_ss
-    symlink_mesa_tnl
-    symlink_mesa_shader
-    symlink_mesa_shader_grammar
-    symlink_mesa_shader_slang
-    symlink_mesa_shader_slang_library
-    symlink_mesa_x
-    symlink_mesa_glapi
-    symlink_mesa_ppc
-    symlink_mesa_sparc
-    symlink_mesa_vbo
-    symlink_mesa_x86
-    symlink_mesa_x8664
-}
-
 symlink_glx() {
     # this is... unpleasant
     src_dir src/glx/x11
diff --git a/hw/xfree86/dixmods/GLcoremodule.c b/hw/xfree86/dixmods/GLcoremodule.c
deleted file mode 100644
index d55cb78..0000000
--- a/hw/xfree86/dixmods/GLcoremodule.c
+++ /dev/null
@@ -1,63 +0,0 @@
-/**************************************************************************
-
-Copyright 1998-1999 Precision Insight, Inc., Cedar Park, Texas.
-All Rights Reserved.
-
-Permission is hereby granted, free of charge, to any person obtaining a
-copy of this software and associated documentation files (the
-"Software"), to deal in the Software without restriction, including
-without limitation the rights to use, copy, modify, merge, publish,
-distribute, sub license, and/or sell copies of the Software, and to
-permit persons to whom the Software is furnished to do so, subject to
-the following conditions:
-
-The above copyright notice and this permission notice (including the
-next paragraph) shall be included in all copies or substantial portions
-of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
-OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
-IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
-ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
-TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
-SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-
-**************************************************************************/
-
-/*
- * Authors:
- *   Kevin E. Martin <kevin at precisioninsight.com>
- *
- */
-
-#ifdef HAVE_XORG_CONFIG_H
-#include <xorg-config.h>
-#endif
-
-#include "xf86Module.h"
-
-static MODULESETUPPROTO(GLcoreSetup);
-
-static XF86ModuleVersionInfo VersRec =
-{
-        "GLcore",
-        MODULEVENDORSTRING,
-        MODINFOSTRING1,
-        MODINFOSTRING2,
-        XORG_VERSION_CURRENT,
-        1, 0, 0,
-        ABI_CLASS_EXTENSION,
-        ABI_EXTENSION_VERSION,
-        MOD_CLASS_NONE,
-        {0,0,0,0}
-};
-
-_X_EXPORT XF86ModuleData GLcoreModuleData = { &VersRec, GLcoreSetup, NULL };
-
-static pointer
-GLcoreSetup(pointer module, pointer opts, int *errmaj, int *errmin)
-{
-    /* Need a non-NULL return value to indicate success */
-    return (pointer)1;
-}
commit dd7a53f8f21e41e1ab43f7e684ba586abc97ef7e
Author: George Sapountzis <gsap7 at yahoo.gr>
Date:   Fri Apr 18 17:47:01 2008 +0300

    glcore: drop GLcore (build system)

diff --git a/GL/Makefile.am b/GL/Makefile.am
index 29d03f2..44fca18 100644
--- a/GL/Makefile.am
+++ b/GL/Makefile.am
@@ -2,8 +2,8 @@ if XQUARTZ
 XQUARTZ_SUBDIRS = apple
 endif
 
-SUBDIRS = glx mesa $(XQUARTZ_SUBDIRS)
-DIST_SUBDIRS = glx mesa apple
+SUBDIRS = glx $(XQUARTZ_SUBDIRS)
+DIST_SUBDIRS = glx apple
 
 WINDOWS_EXTRAS = \
 	windows/ChangeLog \
diff --git a/GL/symlink-mesa.sh b/GL/symlink-mesa.sh
index 47afdcd..d611fcf 100755
--- a/GL/symlink-mesa.sh
+++ b/GL/symlink-mesa.sh
@@ -267,7 +267,6 @@ run() {
     # $1 what to do
     # $2 explanation
 
-    ACTION=$1 EXPLANATION=$2 run_module mesa
     ACTION=$1 EXPLANATION=$2 run_module glx
 }
 
diff --git a/configure.ac b/configure.ac
index 5da56b5..aba4619 100644
--- a/configure.ac
+++ b/configure.ac
@@ -837,7 +837,7 @@ if test "x$GLX" = xyes && ! test "x$MESA_SOURCE" = x; then
 	PKG_CHECK_MODULES([GL], [glproto >= 1.4.9])
 	AC_SUBST(XLIB_CFLAGS)
 	AC_DEFINE(GLXEXT, 1, [Build GLX extension])
-	GLX_LIBS='$(top_builddir)/GL/glx/libglx.la $(top_builddir)/GL/mesa/libGLcore.la'
+	GLX_LIBS='$(top_builddir)/GL/glx/libglx.la'
 	test -d GL || mkdir GL
 	case $host_os in
 	  solaris*) 	
@@ -2105,18 +2105,6 @@ Makefile
 GL/Makefile
 GL/apple/Makefile
 GL/glx/Makefile
-GL/mesa/Makefile
-GL/mesa/glapi/Makefile
-GL/mesa/main/Makefile
-GL/mesa/math/Makefile
-GL/mesa/shader/Makefile
-GL/mesa/shader/grammar/Makefile
-GL/mesa/shader/slang/Makefile
-GL/mesa/swrast/Makefile
-GL/mesa/swrast_setup/Makefile
-GL/mesa/tnl/Makefile
-GL/mesa/vbo/Makefile
-GL/mesa/X/Makefile
 include/Makefile
 afb/Makefile
 composite/Makefile
diff --git a/hw/xfree86/dixmods/Makefile.am b/hw/xfree86/dixmods/Makefile.am
index 67967c5..beff9b1 100644
--- a/hw/xfree86/dixmods/Makefile.am
+++ b/hw/xfree86/dixmods/Makefile.am
@@ -3,7 +3,7 @@ noinst_LTLIBRARIES = libdixmods.la libxorgxkb.la
 SUBDIRS = extmod
 
 if GLX
-GLXMODS = libglx.la libGLcore.la
+GLXMODS = libglx.la
 endif
 
 if XTRAP
@@ -48,10 +48,6 @@ INCLUDES = @XORG_INCS@ \
            -I$(top_srcdir)/miext/shadow \
            -I$(top_srcdir)/GL/glx
 
-libGLcore_la_LDFLAGS = -avoid-version
-libGLcore_la_LIBADD = $(top_builddir)/GL/mesa/libGLcore.la
-libGLcore_la_SOURCES = GLcoremodule.c
-
 libafb_la_LDFLAGS = -avoid-version
 libafb_la_LIBADD = $(top_builddir)/afb/libafb.la
 libafb_la_SOURCES = afbmodule.c
commit 567d389d47dee233a973b101e04ce41c47a68f34
Author: George Sapountzis <gsap7 at yahoo.gr>
Date:   Fri Apr 18 17:46:18 2008 +0300

    glcore: build from mesa, dlopen from xorg
    
    * The GLcore interface is disposable
    * GLcore is installed in DRI_DRIVER_INSTALL_DIR which is overloaded for
      GLX_PROVIDER_INSTALL_DIR

diff --git a/GL/glx/glxglcore.c b/GL/glx/glxglcore.c
index c8a2514..dafa9bc 100644
--- a/GL/glx/glxglcore.c
+++ b/GL/glx/glxglcore.c
@@ -37,7 +37,9 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 #endif
 
 #include <string.h>
+#include <dlfcn.h>
 
+#define _NEED_GL_CORE_IF
 #include <GL/xmesa.h>
 #include <GL/internal/glcore.h>
 #include <glxserver.h>
@@ -48,6 +50,22 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 
 #include "os.h"
 
+#define XMesaCreateVisual       (*glcore->XMesaCreateVisual)
+#define XMesaDestroyVisual      (*glcore->XMesaDestroyVisual)
+
+#define XMesaCreateWindowBuffer (*glcore->XMesaCreateWindowBuffer)
+#define XMesaCreatePixmapBuffer (*glcore->XMesaCreatePixmapBuffer)
+#define XMesaDestroyBuffer      (*glcore->XMesaDestroyBuffer)
+#define XMesaSwapBuffers        (*glcore->XMesaSwapBuffers)
+#define XMesaResizeBuffers      (*glcore->XMesaResizeBuffers)
+
+#define XMesaCreateContext      (*glcore->XMesaCreateContext)
+#define XMesaDestroyContext     (*glcore->XMesaDestroyContext)
+#define XMesaCopyContext        (*glcore->XMesaCopyContext)
+#define XMesaMakeCurrent2       (*glcore->XMesaMakeCurrent2)
+#define XMesaForceCurrent       (*glcore->XMesaForceCurrent)
+#define XMesaLoseCurrent        (*glcore->XMesaLoseCurrent)
+
 typedef struct __GLXMESAscreen   __GLXMESAscreen;
 typedef struct __GLXMESAcontext  __GLXMESAcontext;
 typedef struct __GLXMESAdrawable __GLXMESAdrawable;
@@ -55,8 +73,11 @@ typedef struct __GLXMESAdrawable __GLXMESAdrawable;
 struct __GLXMESAscreen {
     __GLXscreen   base;
     int           index;
-    int		  num_vis;
+    int           num_vis;
     XMesaVisual  *xm_vis;
+    void         *driver;
+
+    const __GLcoreModule *glcore;
 };
 
 struct __GLXMESAcontext {
@@ -65,8 +86,9 @@ struct __GLXMESAcontext {
 };
 
 struct __GLXMESAdrawable {
-    __GLXdrawable base;
-    XMesaBuffer   xm_buf;
+    __GLXdrawable    base;
+    XMesaBuffer      xm_buf;
+    __GLXMESAscreen *screen;
 };
 
 static XMesaVisual find_mesa_visual(__GLXscreen *screen, XID fbconfigID);
@@ -76,6 +98,7 @@ static void
 __glXMesaDrawableDestroy(__GLXdrawable *base)
 {
     __GLXMESAdrawable *glxPriv = (__GLXMESAdrawable *) base;
+    const __GLcoreModule *glcore = glxPriv->screen->glcore;
 
     if (glxPriv->xm_buf != NULL)
       XMesaDestroyBuffer(glxPriv->xm_buf);
@@ -86,6 +109,7 @@ static GLboolean
 __glXMesaDrawableResize(__GLXdrawable *base)
 {
     __GLXMESAdrawable *glxPriv = (__GLXMESAdrawable *) base;
+    const __GLcoreModule *glcore = glxPriv->screen->glcore;
 
     XMesaResizeBuffers(glxPriv->xm_buf);
 
@@ -96,6 +120,7 @@ static GLboolean
 __glXMesaDrawableSwapBuffers(__GLXdrawable *base)
 {
     __GLXMESAdrawable *glxPriv = (__GLXMESAdrawable *) base;
+    const __GLcoreModule *glcore = glxPriv->screen->glcore;
 
     /* This is terrifying: XMesaSwapBuffers() ends up calling CopyArea
      * to do the buffer swap, but this assumes that the server holds
@@ -121,6 +146,8 @@ __glXMesaScreenCreateDrawable(__GLXscreen *screen,
 			      XID drawId,
 			      __GLXconfig *modes)
 {
+    __GLXMESAscreen *mesaScreen = (__GLXMESAscreen *) screen;
+    const __GLcoreModule *glcore = mesaScreen->glcore;
     __GLXMESAdrawable *glxPriv;
     XMesaVisual xm_vis;
 
@@ -130,6 +157,7 @@ __glXMesaScreenCreateDrawable(__GLXscreen *screen,
 
     memset(glxPriv, 0, sizeof *glxPriv);
 
+    glxPriv->screen = mesaScreen;
     if (!__glXDrawableInit(&glxPriv->base, screen,
 			   pDraw, type, drawId, modes)) {
         xfree(glxPriv);
@@ -166,6 +194,8 @@ static void
 __glXMesaContextDestroy(__GLXcontext *baseContext)
 {
     __GLXMESAcontext *context = (__GLXMESAcontext *) baseContext;
+    __GLXMESAscreen *screen = (__GLXMESAscreen *) context->base.pGlxScreen;
+    const __GLcoreModule *glcore = screen->glcore;
 
     XMesaDestroyContext(context->xmesa);
     __glXContextDestroy(&context->base);
@@ -179,6 +209,8 @@ __glXMesaContextMakeCurrent(__GLXcontext *baseContext)
     __GLXMESAcontext *context = (__GLXMESAcontext *) baseContext;
     __GLXMESAdrawable *drawPriv = (__GLXMESAdrawable *) context->base.drawPriv;
     __GLXMESAdrawable *readPriv = (__GLXMESAdrawable *) context->base.readPriv;
+    __GLXMESAscreen *screen = (__GLXMESAscreen *) context->base.pGlxScreen;
+    const __GLcoreModule *glcore = screen->glcore;
 
     return XMesaMakeCurrent2(context->xmesa,
 			     drawPriv->xm_buf,
@@ -189,6 +221,8 @@ static int
 __glXMesaContextLoseCurrent(__GLXcontext *baseContext)
 {
     __GLXMESAcontext *context = (__GLXMESAcontext *) baseContext;
+    __GLXMESAscreen *screen = (__GLXMESAscreen *) context->base.pGlxScreen;
+    const __GLcoreModule *glcore = screen->glcore;
 
     return XMesaLoseCurrent(context->xmesa);
 }
@@ -200,6 +234,8 @@ __glXMesaContextCopy(__GLXcontext *baseDst,
 {
     __GLXMESAcontext *dst = (__GLXMESAcontext *) baseDst;
     __GLXMESAcontext *src = (__GLXMESAcontext *) baseSrc;
+    __GLXMESAscreen *screen = (__GLXMESAscreen *) dst->base.pGlxScreen;
+    const __GLcoreModule *glcore = screen->glcore;
 
     return XMesaCopyContext(src->xmesa, dst->xmesa, mask);
 }
@@ -208,6 +244,8 @@ static int
 __glXMesaContextForceCurrent(__GLXcontext *baseContext)
 {
     __GLXMESAcontext *context = (__GLXMESAcontext *) baseContext;
+    __GLXMESAscreen *screen = (__GLXMESAscreen *) context->base.pGlxScreen;
+    const __GLcoreModule *glcore = screen->glcore;
 
     /* GlxSetRenderTables() call for XGL moved in XMesaForceCurrent() */
 
@@ -219,6 +257,8 @@ __glXMesaScreenCreateContext(__GLXscreen *screen,
 			     __GLXconfig *config,
 			     __GLXcontext *baseShareContext)
 {
+    __GLXMESAscreen *mesaScreen = (__GLXMESAscreen *) screen;
+    const __GLcoreModule *glcore = mesaScreen->glcore;
     __GLXMESAcontext *context;
     __GLXMESAcontext *shareContext = (__GLXMESAcontext *) baseShareContext;
     XMesaVisual xm_vis;
@@ -261,6 +301,7 @@ static void
 __glXMesaScreenDestroy(__GLXscreen *screen)
 {
     __GLXMESAscreen *mesaScreen = (__GLXMESAscreen *) screen;
+    const __GLcoreModule *glcore = mesaScreen->glcore;
     int i;
 
     if (mesaScreen->xm_vis) {
@@ -272,6 +313,8 @@ __glXMesaScreenDestroy(__GLXscreen *screen)
 	xfree(mesaScreen->xm_vis);
     }
 
+    dlclose(mesaScreen->driver);
+
     __glXScreenDestroy(screen);
 
     xfree(screen);
@@ -373,6 +416,7 @@ createFBConfigs(__GLXscreen *pGlxScreen, ScreenPtr pScreen)
 static void
 createMesaVisuals(__GLXMESAscreen *pMesaScreen)
 {
+    const __GLcoreModule *glcore = pMesaScreen->glcore;
     __GLXconfig *config;
     ScreenPtr pScreen;
     VisualPtr visual = NULL;
@@ -409,15 +453,35 @@ createMesaVisuals(__GLXMESAscreen *pMesaScreen)
     }
 }
 
+static const char dri_driver_path[] = DRI_DRIVER_PATH;
+
 static __GLXscreen *
 __glXMesaScreenProbe(ScreenPtr pScreen)
 {
     __GLXMESAscreen *screen;
+    char filename[128];
 
     screen = xalloc(sizeof *screen);
     if (screen == NULL)
 	return NULL;
 
+    snprintf(filename, sizeof filename, "%s/%s.so",
+             dri_driver_path, "libGLcore");
+
+    screen->driver = dlopen(filename, RTLD_LAZY | RTLD_LOCAL);
+    if (screen->driver == NULL) {
+        LogMessage(X_ERROR, "GLX error: dlopen of %s failed (%s)\n",
+                   filename, dlerror());
+        goto handle_error;
+    }
+
+    screen->glcore = dlsym(screen->driver, __GL_CORE);
+    if (screen->glcore == NULL) {
+        LogMessage(X_ERROR, "GLX error: dlsym for %s failed (%s)\n",
+                   __GL_CORE, dlerror());
+        goto handle_error;
+    }
+
     /*
      * Find the GLX visuals that are supported by this screen and create
      * XMesa's visuals.
@@ -435,7 +499,20 @@ __glXMesaScreenProbe(ScreenPtr pScreen)
     screen->base.swapInterval  = NULL;
     screen->base.pScreen       = pScreen;
 
+    LogMessage(X_INFO, "GLX: Loaded and initialized %s\n", filename);
+
     return &screen->base;
+
+handle_error:
+
+    if (screen->driver)
+        dlclose(screen->driver);
+
+    xfree(screen);
+
+    FatalError("GLX: could not load software renderer\n");
+
+    return NULL;
 }
 
 __GLXprovider __glXMesaProvider = {
diff --git a/hw/xfree86/dixmods/glxmodule.c b/hw/xfree86/dixmods/glxmodule.c
index a1a0886..88091cd 100644
--- a/hw/xfree86/dixmods/glxmodule.c
+++ b/hw/xfree86/dixmods/glxmodule.c
@@ -72,37 +72,6 @@ static XF86ModuleVersionInfo VersRec =
 
 _X_EXPORT XF86ModuleData glxModuleData = { &VersRec, glxSetup, NULL };
 
-/* We do a little proxy dance here, so we can avoid loading GLcore
- * unless we really need to.*/
-
-static pointer glxModule;
-
-static __GLXscreen *
-__glXMesaProxyScreenProbe(ScreenPtr pScreen)
-{
-  pointer GLcore;
-  static __GLXprovider *provider;
-
-  if (provider == NULL) {
-    GLcore = LoadSubModule(glxModule, "GLcore", NULL, NULL, NULL, NULL, 
-			   NULL, NULL);
-    if (GLcore == NULL)
-      return NULL;
-
-    provider = LoaderSymbol("__glXMesaProvider");
-    if (provider == NULL)
-      return NULL;
-  }
-
-  return provider->screenProbe(pScreen);
-}
-
-static __GLXprovider __glXMesaProxyProvider = {
-    __glXMesaProxyScreenProbe,
-    "MESA-PROXY",
-    NULL
-};
-
 static pointer
 glxSetup(pointer module, pointer opts, int *errmaj, int *errmin)
 {
@@ -116,8 +85,10 @@ glxSetup(pointer module, pointer opts, int *errmaj, int *errmin)
 
     setupDone = TRUE;
 
-    glxModule = module;
-    GlxPushProvider(&__glXMesaProxyProvider);
+    provider = LoaderSymbol("__glXMesaProvider");
+    if (provider == NULL)
+	return NULL;
+    GlxPushProvider(provider);
 
     xf86Msg(xf86Info.aiglxFrom, "AIGLX %s\n", 
 	    xf86Info.aiglx ? "enabled" : "disabled");
commit efb723e166e5fa89e90c7b400fb4c7979b1f50c0
Author: George Sapountzis <gsap7 at yahoo.gr>
Date:   Fri Apr 18 17:45:53 2008 +0300

    glcore: prepare for dynamic loading
    
    glcore gets linked with -ldl, -lpthread for s3tc and glapi
    xserver needs
            DLOPEN_LIBS - to dlopen the glcore dso
            LD_EXPORT_SYMBOLS_FLAG - to export symbols for glcore to use
    
    the ld flag is added to kdrive only when GLX is enabled, the net overhead for
    Xephyr is ~155KB, could be reduced with --dynamic-list.

diff --git a/configure.ac b/configure.ac
index 995a652..5da56b5 100644
--- a/configure.ac
+++ b/configure.ac
@@ -848,6 +848,7 @@ if test "x$GLX" = xyes && ! test "x$MESA_SOURCE" = x; then
 	if test $? -ne 0; then
 		AC_MSG_ERROR([Failed to link Mesa source tree.  Please specify a proper path to Mesa sources, or disable GLX.])
 	fi
+	GLX_SYS_LIBS="$GLX_SYS_LIBS $DLOPEN_LIBS"
 else
         GLX=no
 fi
@@ -1969,7 +1970,7 @@ if test "$KDRIVE" = yes; then
     KDRIVE_LOCAL_LIBS="$DIX_LIB $KDRIVE_LIB $KDRIVE_STUB_LIB $CONFIG_LIB"
     KDRIVE_LOCAL_LIBS="$KDRIVE_LOCAL_LIBS $FB_LIB $MI_LIB $KDRIVE_PURE_LIBS"
     KDRIVE_LOCAL_LIBS="$KDRIVE_LOCAL_LIBS $KDRIVE_OS_LIB $OS_LIB"
-    KDRIVE_LIBS="$TSLIB_LIBS $KDRIVE_LOCAL_LIBS $XSERVER_SYS_LIBS"
+    KDRIVE_LIBS="$TSLIB_LIBS $KDRIVE_LOCAL_LIBS $XSERVER_SYS_LIBS $GLX_SYS_LIBS"
 
     # check if we can build Xephyr
     PKG_CHECK_MODULES(XEPHYR, $XEPHYR_REQUIRED_LIBS, [xephyr="yes"], [xephyr="no"])
diff --git a/hw/kdrive/ati/Makefile.am b/hw/kdrive/ati/Makefile.am
index 8429250..31462bb 100644
--- a/hw/kdrive/ati/Makefile.am
+++ b/hw/kdrive/ati/Makefile.am
@@ -58,6 +58,10 @@ ATI_LIBS =				\
 	$(DRI_LIBS)			\
 	@KDRIVE_LIBS@
 
+if GLX
+Xati_LDFLAGS = $(LD_EXPORT_SYMBOLS_FLAG)
+endif
+
 Xati_LDADD = \
 	$(ATI_LIBS)			\
 	@KDRIVE_LIBS@
diff --git a/hw/kdrive/chips/Makefile.am b/hw/kdrive/chips/Makefile.am
index 51b0edf..46e1760 100644
--- a/hw/kdrive/chips/Makefile.am
+++ b/hw/kdrive/chips/Makefile.am
@@ -20,6 +20,10 @@ CHIPS_LIBS =					 \
 	$(top_builddir)/hw/kdrive/vesa/libvesa.a \
 	@KDRIVE_LIBS@
 
+if GLX
+Xchips_LDFLAGS = $(LD_EXPORT_SYMBOLS_FLAG)
+endif
+
 Xchips_LDADD = \
 	$(CHIPS_LIBS)				\
 	@KDRIVE_LIBS@
diff --git a/hw/kdrive/ephyr/Makefile.am b/hw/kdrive/ephyr/Makefile.am
index 81d3d69..7ef22a3 100644
--- a/hw/kdrive/ephyr/Makefile.am
+++ b/hw/kdrive/ephyr/Makefile.am
@@ -67,6 +67,10 @@ libxephyr_a_CFLAGS = \
 Xephyr_SOURCES = \
 	ephyrinit.c
 
+if GLX
+Xephyr_LDFLAGS = $(LD_EXPORT_SYMBOLS_FLAG)
+endif
+
 Xephyr_LDADD = 						\
 	libxephyr.a					\
 	libxephyr-hostx.a			        \
diff --git a/hw/kdrive/epson/Makefile.am b/hw/kdrive/epson/Makefile.am
index 2a44014..14bb049 100644
--- a/hw/kdrive/epson/Makefile.am
+++ b/hw/kdrive/epson/Makefile.am
@@ -20,6 +20,10 @@ EPSON_LIBS =					\
 	libepson.a 				\
 	@KDRIVE_LIBS@
 
+if GLX
+Xepson_LDFLAGS = $(LD_EXPORT_SYMBOLS_FLAG)
+endif
+
 Xepson_LDADD = \
 	$(EPSON_LIBS)			       \
 	@KDRIVE_LIBS@
diff --git a/hw/kdrive/fake/Makefile.am b/hw/kdrive/fake/Makefile.am
index 09d179e..0f88656 100644
--- a/hw/kdrive/fake/Makefile.am
+++ b/hw/kdrive/fake/Makefile.am
@@ -16,6 +16,10 @@ libfake_a_SOURCES =	\
 Xfake_SOURCES = \
 	fakeinit.c
 
+if GLX
+Xfake_LDFLAGS = $(LD_EXPORT_SYMBOLS_FLAG)
+endif
+
 Xfake_LDADD = 						\
 	libfake.a					\
 	@KDRIVE_LIBS@					\
diff --git a/hw/kdrive/fbdev/Makefile.am b/hw/kdrive/fbdev/Makefile.am
index 420855b..c77f146 100644
--- a/hw/kdrive/fbdev/Makefile.am
+++ b/hw/kdrive/fbdev/Makefile.am
@@ -14,6 +14,10 @@ bin_PROGRAMS = Xfbdev
 Xfbdev_SOURCES = \
 	fbinit.c
 
+if GLX
+Xfbdev_LDFLAGS = $(LD_EXPORT_SYMBOLS_FLAG)
+endif
+
 Xfbdev_LDADD = 						\
 	libfbdev.a					\
 	@KDRIVE_LIBS@
diff --git a/hw/kdrive/i810/Makefile.am b/hw/kdrive/i810/Makefile.am
index ea02cb6..30919fa 100644
--- a/hw/kdrive/i810/Makefile.am
+++ b/hw/kdrive/i810/Makefile.am
@@ -23,6 +23,10 @@ I810_LIBS =						\
 	libi810.a 					\
 	@KDRIVE_LIBS@
 
+if GLX
+Xi810_LDFLAGS = $(LD_EXPORT_SYMBOLS_FLAG)
+endif
+
 Xi810_LDADD = \
 	$(I810_LIBS)					\
 	@KDRIVE_LIBS@
diff --git a/hw/kdrive/mach64/Makefile.am b/hw/kdrive/mach64/Makefile.am
index 746ffff..6ca376a 100644
--- a/hw/kdrive/mach64/Makefile.am
+++ b/hw/kdrive/mach64/Makefile.am
@@ -27,6 +27,10 @@ MACH64_LIBS =						\
 	$(top_builddir)/hw/kdrive/vesa/libvesa.a        
 
 
+if GLX
+Xmach64_LDFLAGS = $(LD_EXPORT_SYMBOLS_FLAG)
+endif
+
 Xmach64_LDADD = 					\
 	$(MACH64_LIBS)					\
 	@KDRIVE_LIBS@
diff --git a/hw/kdrive/mga/Makefile.am b/hw/kdrive/mga/Makefile.am
index 37bc50c..a7dd2cb 100644
--- a/hw/kdrive/mga/Makefile.am
+++ b/hw/kdrive/mga/Makefile.am
@@ -22,6 +22,10 @@ MGA_LIBS =						\
 	$(top_builddir)/hw/kdrive/vesa/libvesa.a	\
 	@KDRIVE_LIBS@
 
+if GLX
+Xmga_LDFLAGS = $(LD_EXPORT_SYMBOLS_FLAG)
+endif
+
 Xmga_LDADD = \
 	$(MGA_LIBS)					\
 	@KDRIVE_LIBS@
diff --git a/hw/kdrive/neomagic/Makefile.am b/hw/kdrive/neomagic/Makefile.am
index 95f0e1e..b449c37 100644
--- a/hw/kdrive/neomagic/Makefile.am
+++ b/hw/kdrive/neomagic/Makefile.am
@@ -32,6 +32,10 @@ NEOMAGIC_LIBS =                 \
 	${VESA_LIBS}                \
 	@KDRIVE_LIBS@
 
+if GLX
+Xneomagic_LDFLAGS = $(LD_EXPORT_SYMBOLS_FLAG)
+endif
+
 Xneomagic_LDADD = \
 	$(NEOMAGIC_LIBS)            \
 	@KDRIVE_LIBS@               \
diff --git a/hw/kdrive/nvidia/Makefile.am b/hw/kdrive/nvidia/Makefile.am
index b380e44..81736c3 100644
--- a/hw/kdrive/nvidia/Makefile.am
+++ b/hw/kdrive/nvidia/Makefile.am
@@ -23,6 +23,10 @@ NVIDIA_LIBS =					\
 	$(top_builddir)/hw/kdrive/vesa/libvesa.a \
 	@KDRIVE_LIBS@
 
+if GLX
+Xnvidia_LDFLAGS = $(LD_EXPORT_SYMBOLS_FLAG)
+endif
+
 Xnvidia_LDADD = \
 	$(NVIDIA_LIBS)				\
 	@KDRIVE_LIBS@
diff --git a/hw/kdrive/pm2/Makefile.am b/hw/kdrive/pm2/Makefile.am
index 208d031..cb28de6 100644
--- a/hw/kdrive/pm2/Makefile.am
+++ b/hw/kdrive/pm2/Makefile.am
@@ -21,6 +21,10 @@ PM2_LIBS =					\
 	$(top_builddir)/hw/kdrive/vesa/libvesa.a \
 	@KDRIVE_LIBS@
 
+if GLX
+Xpm2_LDFLAGS = $(LD_EXPORT_SYMBOLS_FLAG)
+endif
+
 Xpm2_LDADD = \
 	$(PM2_LIBS)				\
 	@KDRIVE_LIBS@
diff --git a/hw/kdrive/r128/Makefile.am b/hw/kdrive/r128/Makefile.am
index 62c1fcf..344fbeb 100644
--- a/hw/kdrive/r128/Makefile.am
+++ b/hw/kdrive/r128/Makefile.am
@@ -20,6 +20,10 @@ R128_LIBS =					\
 	$(top_builddir)/hw/kdrive/vesa/libvesa.a \
 	@KDRIVE_LIBS@
 
+if GLX
+Xr128_LDFLAGS = $(LD_EXPORT_SYMBOLS_FLAG)
+endif
+
 Xr128_LDADD = \
 	$(R128_LIBS)				\
 	@KDRIVE_LIBS@
diff --git a/hw/kdrive/sdl/Makefile.am b/hw/kdrive/sdl/Makefile.am
index fe9309e..a70d147 100644
--- a/hw/kdrive/sdl/Makefile.am
+++ b/hw/kdrive/sdl/Makefile.am
@@ -7,6 +7,10 @@ bin_PROGRAMS = Xsdl
 
 Xsdl_SOURCES = sdl.c
 
+if GLX
+Xsdl_LDFLAGS = $(LD_EXPORT_SYMBOLS_FLAG)
+endif
+
 Xsdl_LDADD = \
 	@KDRIVE_LIBS@                                  \
 	@XSDL_LIBS@
diff --git a/hw/kdrive/sis300/Makefile.am b/hw/kdrive/sis300/Makefile.am
index 3e8ce90..af2500a 100644
--- a/hw/kdrive/sis300/Makefile.am
+++ b/hw/kdrive/sis300/Makefile.am
@@ -34,6 +34,10 @@ SIS_LIBS =				\
 	$(VESA_LIBS)			\
 	@KDRIVE_LIBS@
 
+if GLX
+Xsis_LDFLAGS = $(LD_EXPORT_SYMBOLS_FLAG)
+endif
+
 Xsis_LDADD = \
 	$(SIS_LIBS)				\
 	@KDRIVE_LIBS@                          \
diff --git a/hw/kdrive/smi/Makefile.am b/hw/kdrive/smi/Makefile.am
index a4d6624..bd7077c 100644
--- a/hw/kdrive/smi/Makefile.am
+++ b/hw/kdrive/smi/Makefile.am
@@ -25,6 +25,10 @@ SMI_LIBS =					\
 	$(top_builddir)/hw/kdrive/vesa/libvesa.a \
 	@KDRIVE_LIBS@
 
+if GLX
+Xsmi_LDFLAGS = $(LD_EXPORT_SYMBOLS_FLAG)
+endif
+
 Xsmi_LDADD = \
 	$(SMI_LIBS)				\
 	@KDRIVE_LIBS@
diff --git a/hw/kdrive/vesa/Makefile.am b/hw/kdrive/vesa/Makefile.am
index ac50d2b..ec35c1e 100644
--- a/hw/kdrive/vesa/Makefile.am
+++ b/hw/kdrive/vesa/Makefile.am
@@ -19,6 +19,10 @@ libvesa_a_SOURCES = \
 Xvesa_SOURCES = \
 	vesainit.c
 
+if GLX
+Xvesa_LDFLAGS = $(LD_EXPORT_SYMBOLS_FLAG)
+endif
+
 Xvesa_LDADD = \
 	libvesa.a 				\
 	@KDRIVE_LIBS@
diff --git a/hw/kdrive/via/Makefile.am b/hw/kdrive/via/Makefile.am
index 249b3f3..c659379 100644
--- a/hw/kdrive/via/Makefile.am
+++ b/hw/kdrive/via/Makefile.am
@@ -21,6 +21,10 @@ VIA_LIBS =	\
 	libvia.a	\
 	$(top_builddir)/hw/kdrive/vesa/libvesa.a
 
+if GLX
+Xvia_LDFLAGS = $(LD_EXPORT_SYMBOLS_FLAG)
+endif
+
 Xvia_LDADD =						\
 	$(VIA_LIBS)					\
 	@KDRIVE_LIBS@
commit fbad87f2ae9f97fcb43546b0fa35f1100415dfec
Author: Julien Cristau <jcristau at debian.org>
Date:   Tue Apr 22 23:50:11 2008 +0200

    autoconfig: don't call closedir() when opendir() failed
    
    If opendir() fails, return from matchDriverFromFiles() immediately.
    Ubuntu bug 217647.

diff --git a/hw/xfree86/common/xf86AutoConfig.c b/hw/xfree86/common/xf86AutoConfig.c
index 5ffd847..7e5fab4 100644
--- a/hw/xfree86/common/xf86AutoConfig.c
+++ b/hw/xfree86/common/xf86AutoConfig.c
@@ -330,86 +330,87 @@ matchDriverFromFiles (char** matches, uint16_t match_vendor, uint16_t match_chip
     int i, j;
 
     idsdir = opendir(PCI_TXT_IDS_PATH);
-    if (idsdir) {
-         xf86Msg(X_INFO, "Scanning %s directory for additional PCI ID's supported by the drivers\n", PCI_TXT_IDS_PATH);
-        direntry = readdir(idsdir);
-        /* Read the directory */
-        while (direntry) {
-            if (direntry->d_name[0] == '.') {
-                direntry = readdir(idsdir);
-                continue;
+    if (!idsdir)
+        return;
+
+    xf86Msg(X_INFO, "Scanning %s directory for additional PCI ID's supported by the drivers\n", PCI_TXT_IDS_PATH);
+    direntry = readdir(idsdir);
+    /* Read the directory */
+    while (direntry) {
+        if (direntry->d_name[0] == '.') {
+            direntry = readdir(idsdir);
+            continue;
+        }
+        len = strlen(direntry->d_name);
+        /* A tiny bit of sanity checking. We should probably do better */
+        if (strncmp(&(direntry->d_name[len-4]), ".ids", 4) == 0) {
+            /* We need the full path name to open the file */
+            strncpy(path_name, PCI_TXT_IDS_PATH, 256);
+            strncat(path_name, "/", 1);
+            strncat(path_name, direntry->d_name, (256 - strlen(path_name) - 1));
+            fp = fopen(path_name, "r");
+            if (fp == NULL) {
+                xf86Msg(X_ERROR, "Could not open %s for reading. Exiting.\n", path_name);
+                goto end;
             }
-            len = strlen(direntry->d_name);
-            /* A tiny bit of sanity checking. We should probably do better */
-            if (strncmp(&(direntry->d_name[len-4]), ".ids", 4) == 0) {
-                /* We need the full path name to open the file */
-                strncpy(path_name, PCI_TXT_IDS_PATH, 256);
-                strncat(path_name, "/", 1);
-                strncat(path_name, direntry->d_name, (256 - strlen(path_name) - 1));
-                fp = fopen(path_name, "r");
-                if (fp == NULL) {
-                    xf86Msg(X_ERROR, "Could not open %s for reading. Exiting.\n", path_name);
-                    goto end;
-                }
-                /* Read the file */
-                #ifdef __GLIBC__
-                while ((read = getline(&line, &len, fp)) != -1) {
-                #else
-                while ((line = fgetln(fp, &len)) != (char *)NULL) {
-                #endif /* __GLIBC __ */
-                    xchomp(line);
-                    if (isdigit(line[0])) {
-                        strncpy(vendor_str, line, 4);
-                        vendor_str[4] = '\0';
-                        vendor = (int)strtol(vendor_str, NULL, 16);
-                        if ((strlen(&line[4])) == 0) {
-                                chip_str[0] = '\0';
-                                chip = -1;
+            /* Read the file */
+#ifdef __GLIBC__
+            while ((read = getline(&line, &len, fp)) != -1) {
+#else
+            while ((line = fgetln(fp, &len)) != (char *)NULL) {
+#endif /* __GLIBC __ */
+                xchomp(line);
+                if (isdigit(line[0])) {
+                    strncpy(vendor_str, line, 4);
+                    vendor_str[4] = '\0';
+                    vendor = (int)strtol(vendor_str, NULL, 16);
+                    if ((strlen(&line[4])) == 0) {
+                        chip_str[0] = '\0';
+                        chip = -1;
+                    } else {
+                        /* Handle trailing whitespace */
+                        if (isspace(line[4])) {
+                            chip_str[0] = '\0';
+                            chip = -1;
                         } else {
-                                /* Handle trailing whitespace */
-                                if (isspace(line[4])) {
-                                    chip_str[0] = '\0';
-                                    chip = -1;
-                                } else {
-                                /* Ok, it's a real ID */
-                                    strncpy(chip_str, &line[4], 4);
-                                    chip_str[4] = '\0';
-                                    chip = (int)strtol(chip_str, NULL, 16);
-                                }
+                            /* Ok, it's a real ID */
+                            strncpy(chip_str, &line[4], 4);
+                            chip_str[4] = '\0';
+                            chip = (int)strtol(chip_str, NULL, 16);
                         }
-                        if (vendor == match_vendor && chip == match_chip ) {
-                            i = 0;
-                            while (matches[i]) {
-                                i++;
-                            }
-                            matches[i] = (char*)xalloc(sizeof(char) * strlen(direntry->d_name) -  3);
-                            if (!matches[i]) {
-                                xf86Msg(X_ERROR, "Could not allocate space for the module name. Exiting.\n");
-                                goto end;
-                            }
-                            /* hack off the .ids suffix. This should guard
-                             * against other problems, but it will end up
-                             * taking off anything after the first '.' */
-                            for (j = 0; j < (strlen(direntry->d_name) - 3) ; j++) {
-                                if (direntry->d_name[j] == '.') {
-                                    matches[i][j] = '\0';
-                                    break;
-                                } else {
-                                    matches[i][j] = direntry->d_name[j];
-                                }
+                    }
+                    if (vendor == match_vendor && chip == match_chip ) {
+                        i = 0;
+                        while (matches[i]) {
+                            i++;
+                        }
+                        matches[i] = (char*)xalloc(sizeof(char) * strlen(direntry->d_name) -  3);
+                        if (!matches[i]) {
+                            xf86Msg(X_ERROR, "Could not allocate space for the module name. Exiting.\n");
+                            goto end;
+                        }
+                        /* hack off the .ids suffix. This should guard
+                         * against other problems, but it will end up
+                         * taking off anything after the first '.' */
+                        for (j = 0; j < (strlen(direntry->d_name) - 3) ; j++) {
+                            if (direntry->d_name[j] == '.') {
+                                matches[i][j] = '\0';
+                                break;
+                            } else {
+                                matches[i][j] = direntry->d_name[j];
                             }
-                            xf86Msg(X_INFO, "Matched %s from file name %s\n", matches[i], direntry->d_name);
                         }
-                    } else {
-                        /* TODO Handle driver overrides here */
+                        xf86Msg(X_INFO, "Matched %s from file name %s\n", matches[i], direntry->d_name);
                     }
+                } else {
+                    /* TODO Handle driver overrides here */
                 }
-                fclose(fp);
             }
-            direntry = readdir(idsdir);
+            fclose(fp);
         }
+        direntry = readdir(idsdir);
     }
-    end:
+ end:
     xfree(line);
     closedir(idsdir);
 }
commit 76381092e8f650ec7d1f058fa4c8a7348893f775
Author: Jeremy Huddleston <jeremyhu at freedesktop.org>
Date:   Wed Apr 23 02:22:14 2008 -0700

    XQuartz: Make sure QuartzAudioInit() gets run.
    (cherry picked from commit bb3d034675b70e22e78df5554cab0ec2a3d913d0)
    (cherry picked from commit 824b31c7f8144a67a320442abd3d854e99d2bfe2)

diff --git a/hw/xquartz/quartz.c b/hw/xquartz/quartz.c
index 4d03d02..2cba5df 100644
--- a/hw/xquartz/quartz.c
+++ b/hw/xquartz/quartz.c
@@ -156,7 +156,7 @@ void QuartzInitOutput(
     int argc,
     char **argv )
 {
-    if (serverGeneration == 0) {
+    if (serverGeneration == 1) {
         QuartzAudioInit();
     }
 
@@ -244,7 +244,7 @@ void QuartzDisplayChangedHandler(int screenNum, xEventPtr xe, DeviceIntPtr dev,
     int x, y, width, height, sx, sy;
     xEvent e;
 
-    DEBUG_LOG("QuartzDisplayChangedHandler()\n");
+    DEBUG_LOG("QuartzDisplayChangedHandler(): noPseudoramiXExtension=%d, screenInfo.numScreens=%d\n", noPseudoramiXExtension, screenInfo.numScreens);
     if (noPseudoramiXExtension || screenInfo.numScreens != 1)
     {
         /* FIXME: if not using Xinerama, we have multiple screens, and
commit 00815b3e5223e822f306db45cd4884a22ac9f7ed
Author: Julien Cristau <jcristau at debian.org>
Date:   Mon Apr 21 14:34:39 2008 +0200

    Don't set DRI2=yes if we can't find dri2proto or libdrm

diff --git a/configure.ac b/configure.ac
index 04d976c..995a652 100644
--- a/configure.ac
+++ b/configure.ac
@@ -379,7 +379,7 @@ case $host_os in
 	AC_DEFINE(PCVT_SUPPORT, 1, [System has PCVT console])
 	AC_DEFINE(SYSCONS_SUPPORT, 1, [System has syscons console])
 	DRI=yes
-	DRI2=yes
+	PKG_CHECK_EXISTS([dri2proto >= 1.1 libdrm >= 2.3.1], DRI2=yes, DRI2=no)
 	;;
   *netbsd*)
 	AC_DEFINE(CSRG_BASED, 1, [System is BSD-like])
@@ -387,7 +387,7 @@ case $host_os in
 	AC_DEFINE(PCVT_SUPPORT, 1, [System has PCVT console])
 	AC_DEFINE(WSCONS_SUPPORT, 1, [System has wscons console])
 	DRI=yes
-	DRI2=yes
+	PKG_CHECK_EXISTS([dri2proto >= 1.1 libdrm >= 2.3.1], DRI2=yes, DRI2=no)
 	;;
   *openbsd*)
 	AC_DEFINE(CSRG_BASED, 1, [System is BSD-like])
@@ -396,7 +396,7 @@ case $host_os in
 	;;
   *linux*)
 	DRI=yes
-	DRI2=yes
+	PKG_CHECK_EXISTS([dri2proto >= 1.1 libdrm >= 2.3.1], DRI2=yes, DRI2=no)
 	KDRIVE_HW=yes
 	;;
   *solaris*)
commit e77f65768efbf05cdf363a2f41f036f74eaa45de
Author: Ross Burton <ross at burtonini.com>
Date:   Tue Apr 22 18:07:46 2008 +0100

    Reuse the existing framebuffer mode in kdrive/fbdev
    
    When starting up kdrive/fbdev, if the current framebuffer mode is sensible use
    that unless told otherwise.
    
    Signed-off-by: Daniel Stone <daniel at fooishbar.org>

diff --git a/hw/kdrive/fbdev/fbdev.c b/hw/kdrive/fbdev/fbdev.c
index 177be0b..7721e60 100644
--- a/hw/kdrive/fbdev/fbdev.c
+++ b/hw/kdrive/fbdev/fbdev.c
@@ -179,16 +179,24 @@ fbdevScreenInitialize (KdScreenInfo *screen, FbdevScrPriv *scrpriv)
 	screen->rate = 103; /* FIXME: should get proper value from fb driver */
     }
     if (!screen->fb[0].depth)
-	screen->fb[0].depth = 16;
-
-    t = KdFindMode (screen, fbdevModeSupported);
-    screen->rate = t->rate;
-    screen->width = t->horizontal;
-    screen->height = t->vertical;
+    {
+	if (k >= 0) 
+	    screen->fb[0].depth = var.bits_per_pixel;
+	else
+	    screen->fb[0].depth = 16;
+    }
 
-    /* Now try setting the mode */
-    if (k < 0 || (t->horizontal != var.xres || t->vertical != var.yres))
-        fbdevConvertMonitorTiming (t, &var);
+    if ((screen->width != var.xres) || (screen->height != var.yres))
+    {
+      t = KdFindMode (screen, fbdevModeSupported);
+      screen->rate = t->rate;
+      screen->width = t->horizontal;
+      screen->height = t->vertical;
+
+      /* Now try setting the mode */
+      if (k < 0 || (t->horizontal != var.xres || t->vertical != var.yres))
+          fbdevConvertMonitorTiming (t, &var);
+    }
 
     var.activate = FB_ACTIVATE_NOW;
     var.bits_per_pixel = screen->fb[0].depth;
commit c4fd1121531b0cba1a3e90fa747871d784365c7e
Author: Ross Burton <ross at burtonini.com>
Date:   Tue Apr 22 18:05:53 2008 +0100

    Add mediumraw support to the linux kdrive driver
    
    Signed-off-by: Daniel Stone <daniel at fooishbar.org>

diff --git a/hw/kdrive/linux/keyboard.c b/hw/kdrive/linux/keyboard.c
index 3193ab7..ae981b7 100644
--- a/hw/kdrive/linux/keyboard.c
+++ b/hw/kdrive/linux/keyboard.c
@@ -42,6 +42,8 @@
 #include <sys/ioctl.h>
 
 extern int LinuxConsoleFd;
+static unsigned char mediumraw_data, mediumraw_up;
+static enum { DEFAULT, EXTBYTE1, EXTBYTE2 } mediumraw_state = DEFAULT;
 
 static const KeySym linux_to_x[256] = {
 	NoSymbol,	NoSymbol,	NoSymbol,	NoSymbol,
@@ -701,7 +703,29 @@ LinuxKeyboardRead (int fd, void *closure)
             else
 #endif
                 scancode = b[0] & 0x7f;
-	    KdEnqueueKeyboardEvent (closure, scancode, b[0] & 0x80);
+	    /* This is extended medium raw mode interpreter
+	       see linux/drivers/keyboard.c (kbd->kbdmode == VC_MEDIUMRAW) */
+	    switch (mediumraw_state)
+	    {
+	    case DEFAULT:
+		if (scancode == 0)
+		{
+		    mediumraw_state = EXTBYTE1;
+		    mediumraw_up = b[0] & 0x80;
+		}
+		else
+		    KdEnqueueKeyboardEvent (closure, scancode, b[0] & 0x80);
+		break;
+	    case EXTBYTE1:
+		mediumraw_data = scancode;
+		mediumraw_state = EXTBYTE2;
+		break;
+	    case EXTBYTE2:
+		/* Note: Only codes < 256 will pass correctly through KdEnqueueKeyboardEvent() */
+	      KdEnqueueKeyboardEvent (closure, (int)mediumraw_data << 7 | scancode, mediumraw_up);
+		mediumraw_state = DEFAULT;
+		break;
+	    }
 	    b++;
 	}
     }
commit 455383db95618a05ebdbeae78423e08065f0e14e
Author: Ross Burton <ross at burtonini.com>
Date:   Tue Apr 22 18:04:31 2008 +0100

    Enable the epson kdrive driver
    
    Signed-off-by: Daniel Stone <daniel at fooishbar.org>

diff --git a/hw/kdrive/Makefile.am b/hw/kdrive/Makefile.am
index 5803644..767e1c4 100644
--- a/hw/kdrive/Makefile.am
+++ b/hw/kdrive/Makefile.am
@@ -1,10 +1,10 @@
 if KDRIVEVESA
-VESA_SUBDIRS = vesa ati chips epson i810 mach64 mga nvidia pm2 r128 \
+VESA_SUBDIRS = vesa ati chips i810 mach64 mga nvidia pm2 r128 \
                smi via
 endif
 
 if BUILD_KDRIVEFBDEVLIB
-FBDEV_SUBDIRS = fbdev
+FBDEV_SUBDIRS = fbdev epson
 endif
 
 if XFAKESERVER
commit 82b37d35af13a9f402755e167493ab256b664b9c
Author: Ross Burton <ross at burtonini.com>
Date:   Tue Apr 22 16:38:14 2008 +0100

    Add support for AVR32

diff --git a/include/servermd.h b/include/servermd.h
index 6168410..7b0a328 100644
--- a/include/servermd.h
+++ b/include/servermd.h
@@ -130,6 +130,16 @@ SOFTWARE.
 
 #endif /* vax */
 
+#ifdef __avr32__
+
+#define IMAGE_BYTE_ORDER        MSBFirst
+#define BITMAP_BIT_ORDER        MSBFirst
+#define GLYPHPADBYTES           4
+#define GETLEFTBITS_ALIGNMENT   1
+#define AVOID_MEMORY_READ
+
+#endif /* __avr32__ */ 
+
 #ifdef __arm32__
 
 #define IMAGE_BYTE_ORDER        LSBFirst
commit 20a90bef8b4993f06cf76ad05e3d4c974e1614f6
Author: Ross Burton <ross at burtonini.com>
Date:   Tue Apr 22 16:37:02 2008 +0100

    Add a default touchscreen path
    
    When enabling the touchscreen, open /dev/input/touchscreen0 if no path was
    specified.

diff --git a/hw/kdrive/linux/tslib.c b/hw/kdrive/linux/tslib.c
index 371aece..50cd7cb 100644
--- a/hw/kdrive/linux/tslib.c
+++ b/hw/kdrive/linux/tslib.c
@@ -114,6 +114,10 @@ TslibEnable (KdPointerInfo *pi)
 
     private->raw_event_hook = NULL;
     private->raw_event_closure = NULL;
+    if (!pi->path) {
+        pi->path = "/dev/input/touchscreen0";
+        ErrorF("[tslib/TslibEnable] no device path given, trying %s\n", pi->path);
+    }
     private->tsDev = ts_open(pi->path, 0);
     private->fd = ts_fd(private->tsDev);
     if (!private->tsDev || ts_config(private->tsDev) || private->fd < 0) {
commit b44e89f4683ffcfd75eaf39f1f37d7461db44689
Author: Ross Burton <ross at burtonini.com>
Date:   Tue Apr 22 16:28:39 2008 +0100

    Update to tslib 1.0
    
    Update the pkgconfig checks to tslib 1.0, and fix the LIBS definitions.

diff --git a/configure.ac b/configure.ac
index efb6e66..04d976c 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1942,7 +1942,7 @@ if test "$KDRIVE" = yes; then
         AC_CHECK_LIB([rt], [nanosleep], XEPHYR_LIBS="$XEPHYR_LIBS -lrt"))
     
     if test "x$TSLIB" = xyes; then
-        PKG_CHECK_MODULES([TSLIB], [tslib-0.0], [HAVE_TSLIB="yes"], [HAVE_TSLIB="no"])
+        PKG_CHECK_MODULES([TSLIB], [tslib-1.0], [HAVE_TSLIB="yes"], [HAVE_TSLIB="no"])
         if test "x$HAVE_TSLIB" = xno; then
             AC_MSG_ERROR([tslib must be installed to build the tslib driver. See http://tslib.berlios.de/])
         fi
@@ -1966,10 +1966,10 @@ if test "$KDRIVE" = yes; then
 	    ;;
     esac
     KDRIVE_STUB_LIB='$(top_builddir)/hw/kdrive/src/libkdrivestubs.a'
-    KDRIVE_LOCAL_LIBS="$TSLIB_LIBS $DIX_LIB $KDRIVE_LIB $KDRIVE_STUB_LIB $CONFIG_LIB"
+    KDRIVE_LOCAL_LIBS="$DIX_LIB $KDRIVE_LIB $KDRIVE_STUB_LIB $CONFIG_LIB"
     KDRIVE_LOCAL_LIBS="$KDRIVE_LOCAL_LIBS $FB_LIB $MI_LIB $KDRIVE_PURE_LIBS"
     KDRIVE_LOCAL_LIBS="$KDRIVE_LOCAL_LIBS $KDRIVE_OS_LIB $OS_LIB"
-    KDRIVE_LIBS="$KDRIVE_LOCAL_LIBS $XSERVER_SYS_LIBS"
+    KDRIVE_LIBS="$TSLIB_LIBS $KDRIVE_LOCAL_LIBS $XSERVER_SYS_LIBS"
 
     # check if we can build Xephyr
     PKG_CHECK_MODULES(XEPHYR, $XEPHYR_REQUIRED_LIBS, [xephyr="yes"], [xephyr="no"])
commit 3848422d2354b7a5302fda92b05b0d728190e050
Author: Ross Burton <ross at burtonini.com>
Date:   Tue Apr 22 16:25:23 2008 +0100

    Fix build when XKB is disabled.

diff --git a/dix/devices.c b/dix/devices.c
index 5a726af..2c9a329 100644
--- a/dix/devices.c
+++ b/dix/devices.c
@@ -524,8 +524,8 @@ CloseDevice(DeviceIntPtr dev)
 #ifdef XKB
 	if (dev->key->xkbInfo)
 	    XkbFreeInfo(dev->key->xkbInfo);
-#endif
         dev->key->xkbInfo = NULL;
+#endif
 	xfree(dev->key->curKeySyms.map);
 	xfree(dev->key->modifierKeyMap);
 	xfree(dev->key);
commit 744d0cfda74f8283801cc2d6c5eda48402455bc3
Author: Ben Byer <bbyer at apple.com>
Date:   Mon Apr 21 22:06:38 2008 -0700

    add missing DARWIN_GLX_LIBS in configure.ac
    (cherry picked from commit a033c0b3dbb3b963261faa39f0236457cb00ff44)

diff --git a/configure.ac b/configure.ac
index d3a2317..efb6e66 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1742,7 +1742,7 @@ if test "x$XQUARTZ" = xyes; then
 #	])
 	xorg_cv_AGL_framework=no
 	DARWIN_GLX_LIBS='$(top_builddir)/GL/apple/indirect.o $(top_builddir)/GL/glx/libglx.la'
-	DARWIN_LIBS="$MI_LIB $OS_LIB $DIX_LIB $FB_LIB $FIXES_LIB $XEXT_LIB $CONFIG_LIB $DBE_LIB $XTRAP_LIB $RECORD_LIB $RENDER_LIB $RANDR_LIB $DAMAGE_LIB $MIEXT_DAMAGE_LIB $MIEXT_SHADOW_LIB $XI_LIB $XKB_LIB $XKB_STUB_LIB $COMPOSITE_LIB $XPSTUBS_LIB"
+	DARWIN_LIBS="$MI_LIB $OS_LIB $DIX_LIB $FB_LIB $FIXES_LIB $XEXT_LIB $CONFIG_LIB $DBE_LIB $XTRAP_LIB $RECORD_LIB $RENDER_LIB $RANDR_LIB $DAMAGE_LIB $MIEXT_DAMAGE_LIB $MIEXT_SHADOW_LIB $XI_LIB $XKB_LIB $XKB_STUB_LIB $COMPOSITE_LIB $XPSTUBS_LIB $DARWIN_GLX_LIBS"
 	AC_SUBST([DARWIN_LIBS])
 	AC_CHECK_LIB([Xplugin],[xp_init],[:])
 	CFLAGS="${CFLAGS} -DROOTLESS_WORKAROUND -DNO_ALLOCA"


More information about the xorg-commit mailing list