Index: /trunk/src/VBox/Additions/x11/vboxvideo/Makefile.kmk
===================================================================
--- /trunk/src/VBox/Additions/x11/vboxvideo/Makefile.kmk	(revision 17317)
+++ /trunk/src/VBox/Additions/x11/vboxvideo/Makefile.kmk	(revision 17318)
@@ -203,5 +203,6 @@
 vboxvideo_drv_15_TEMPLATE = VBOXGUESTR3XORGMOD
 vboxvideo_drv_15_CFLAGS := $(vboxvideo_drv_70_CFLAGS)
-vboxvideo_drv_15_DEFS := $(vboxvideo_drv_70_DEFS) NO_ANSIC PCIACCESS VBOX_NO_LOW_COLOUR
+vboxvideo_drv_15_DEFS := $(vboxvideo_drv_70_DEFS) NO_ANSIC PCIACCESS \
+                         VBOX_NO_LOW_COLOUR # VBOX_DRI
 vboxvideo_drv_15_INCS = \
 	$(VBOX_PATH_X11_XORG_1_5) \
@@ -213,7 +214,6 @@
 vboxvideo_drv_15_SOURCES  = \
 	vboxvideo_15.c \
-	vboxutils.c
-vboxvideo_drv_15_SOURCES += \
-	$(if $(VBOX_OSE),,vboxvideo_dri.c)
+	vboxutils.c \
+	vboxvideo_dri.c
 
 
Index: /trunk/src/VBox/Additions/x11/vboxvideo/vboxutils.c
===================================================================
--- /trunk/src/VBox/Additions/x11/vboxvideo/vboxutils.c	(revision 17317)
+++ /trunk/src/VBox/Additions/x11/vboxvideo/vboxutils.c	(revision 17318)
@@ -48,26 +48,7 @@
 /* #define DEBUG_POINTER */
 
-#ifdef DEBUG_michael
-# define DEBUG_VIDEO
-#endif
-
 #define BOOL_STR(a) ((a) ? "TRUE" : "FALSE")
 
 #ifdef DEBUG_VIDEO
-# define TRACE_ENTRY() \
-do { \
-    xf86Msg(X_INFO, __PRETTY_FUNCTION__); \
-    xf86Msg(X_INFO, ": entering\n"); \
-} while(0)
-# define TRACE_EXIT() \
-do { \
-    xf86Msg(X_INFO, __PRETTY_FUNCTION__); \
-    xf86Msg(X_INFO, ": leaving\n"); \
-} while(0)
-# define TRACE_LOG(...) \
-do { \
-    xf86Msg(X_INFO, __PRETTY_FUNCTION__); \
-    xf86Msg(X_INFO, __VA_ARGS__); \
-} while(0)
 # define TRACE_LINE() do \
     { \
@@ -77,7 +58,4 @@
 #else /* DEBUG_VIDEO not defined */
 # define PUT_PIXEL(c) do { } while(0)
-# define TRACE_ENTRY() do { } while(0)
-# define TRACE_EXIT() do { } while(0)
-# define TRACE_LOG(...) do { } while(0)
 # define TRACE_LINE() do { } while(0)
 #endif /* DEBUG_VIDEO not defined */
Index: /trunk/src/VBox/Additions/x11/vboxvideo/vboxvideo.h
===================================================================
--- /trunk/src/VBox/Additions/x11/vboxvideo/vboxvideo.h	(revision 17317)
+++ /trunk/src/VBox/Additions/x11/vboxvideo/vboxvideo.h	(revision 17318)
@@ -56,4 +56,40 @@
 #ifndef _VBOXVIDEO_H_
 #define _VBOXVIDEO_H_
+
+#ifdef DEBUG_michael
+# define DEBUG_VIDEO 1
+#endif
+
+#ifdef DEBUG_VIDEO
+
+#define TRACE_ENTRY() \
+do { \
+    xf86Msg(X_INFO, __PRETTY_FUNCTION__); \
+    xf86Msg(X_INFO, ": entering\n"); \
+} while(0)
+#define TRACE_EXIT() \
+do { \
+    xf86Msg(X_INFO, __PRETTY_FUNCTION__); \
+    xf86Msg(X_INFO, ": leaving\n"); \
+} while(0)
+#define TRACE_LOG(...) \
+do { \
+    xf86Msg(X_INFO, __PRETTY_FUNCTION__); \
+    xf86Msg(X_INFO, __VA_ARGS__); \
+} while(0)
+# define TRACE_LINE() do \
+{ \
+    ErrorF ("%s: line %d\n", __FUNCTION__, __LINE__); \
+    } while(0)
+
+#else  /* DEBUG_VIDEO not defined */
+
+#define TRACE_ENTRY()  do { } while(0)
+#define TRACE_EXIT()   do { } while(0)
+#define TRACE_LOG(...) do { } while(0)
+
+#endif  /* DEBUG_VIDEO not defined */
+
+#define BOOL_STR(a) ((a) ? "TRUE" : "FALSE")
 
 #include <VBox/VBoxGuest.h>
@@ -118,4 +154,6 @@
 /* Hack to work around a libdrm header which is broken on Solaris */
 #define u_int64_t uint64_t
+/* Get rid of a warning due to a broken header file */
+enum drm_bo_type { DRM_BO_TYPE };
 #include "dri.h"
 #undef u_int64_t
@@ -207,5 +245,7 @@
 
 /* DRI stuff */
-extern Bool VBOXDRIScreenInit(ScrnInfoPtr pScrn, VBOXPtr pVBox);
+extern Bool VBOXDRIScreenInit(int scrnIndex, ScreenPtr pScreen, VBOXPtr pVBox);
+extern Bool VBOXDRIFinishScreenInit(ScreenPtr pScreen);
+extern void VBOXDRICloseScreen(ScreenPtr pScreen, VBOXPtr pVBox);
 
 #endif /* _VBOXVIDEO_H_ */
Index: /trunk/src/VBox/Additions/x11/vboxvideo/vboxvideo_15.c
===================================================================
--- /trunk/src/VBox/Additions/x11/vboxvideo/vboxvideo_15.c	(revision 17317)
+++ /trunk/src/VBox/Additions/x11/vboxvideo/vboxvideo_15.c	(revision 17318)
@@ -51,36 +51,4 @@
  * Authors: Paulo César Pereira de Andrade <pcpa@conectiva.com.br>
  */
-
-#ifdef DEBUG_michael
-# define DEBUG_VIDEO 1
-#endif
-
-#ifdef DEBUG_VIDEO
-
-#define TRACE \
-do { \
-    xf86Msg(X_INFO, __PRETTY_FUNCTION__); \
-    xf86Msg(X_INFO, ": entering\n"); \
-} while(0)
-#define TRACE2 \
-do { \
-    xf86Msg(X_INFO, __PRETTY_FUNCTION__); \
-    xf86Msg(X_INFO, ": leaving\n"); \
-} while(0)
-#define TRACE3(...) \
-do { \
-    xf86Msg(X_INFO, __PRETTY_FUNCTION__); \
-    xf86Msg(X_INFO, __VA_ARGS__); \
-} while(0)
-
-#else  /* DEBUG_VIDEO not defined */
-
-#define TRACE       do { } while(0)
-#define TRACE2      do { } while(0)
-#define TRACE3(...) do { } while(0)
-
-#endif  /* DEBUG_VIDEO not defined */
-
-#define BOOL_STR(a) ((a) ? "TRUE" : "FALSE")
 
 #include "xorg-server.h"
@@ -237,5 +205,5 @@
     Bool rc = TRUE;
 
-    TRACE3("width=%d, height=%d\n", width, height);
+    TRACE_LOG("width=%d, height=%d\n", width, height);
     /* We only support horizontal resolutions which are a multiple of 8.  Round down if
        necessary. */
@@ -278,5 +246,5 @@
         scrn->displayWidth = width;
     }
-    TRACE3("returning %s\n", rc ? "TRUE" : "FALSE");
+    TRACE_LOG("returning %s\n", rc ? "TRUE" : "FALSE");
     return rc;
 }
@@ -302,5 +270,5 @@
 
     (void) mode;
-    TRACE3("name=%s, HDisplay=%d, VDisplay=%d\n", adjusted_mode->name,
+    TRACE_LOG("name=%s, HDisplay=%d, VDisplay=%d\n", adjusted_mode->name,
            adjusted_mode->HDisplay, adjusted_mode->VDisplay);
     /* We only support horizontal resolutions which are a multiple of 8.  Round down if
@@ -325,5 +293,5 @@
 {
     (void) mode;
-    TRACE3("name=%s, HDisplay=%d, VDisplay=%d, x=%d, y=%d\n", adjusted_mode->name,
+    TRACE_LOG("name=%s, HDisplay=%d, VDisplay=%d, x=%d, y=%d\n", adjusted_mode->name,
            adjusted_mode->HDisplay, adjusted_mode->VDisplay, x, y);
     VBOXSetMode(crtc->scrn, adjusted_mode);
@@ -378,5 +346,5 @@
     ScrnInfoPtr pScrn = output->scrn;
     int rc = MODE_OK;
-    TRACE3("HDisplay=%d, VDisplay=%d\n", mode->HDisplay, mode->VDisplay);
+    TRACE_LOG("HDisplay=%d, VDisplay=%d\n", mode->HDisplay, mode->VDisplay);
     /* We always like modes specified by the user in the configuration
      * file, as doing otherwise is likely to annoy people. */
@@ -387,5 +355,5 @@
        )
         rc = MODE_BAD;
-    TRACE3("returning %s\n", MODE_OK == rc ? "MODE_OK" : "MODE_BAD");
+    TRACE_LOG("returning %s\n", MODE_OK == rc ? "MODE_OK" : "MODE_BAD");
     return rc;
 }
@@ -413,5 +381,5 @@
                       Bool isPreferred, Bool isUserDef)
 {
-    TRACE3("pszName=%s, x=%d, y=%d\n", pszName, x, y);
+    TRACE_LOG("pszName=%s, x=%d, y=%d\n", pszName, x, y);
     DisplayModePtr pMode = xnfcalloc(1, sizeof(DisplayModeRec));
 
@@ -449,5 +417,5 @@
     VBOXPtr pVBox = VBOXGetRec(pScrn);
 
-    TRACE;
+    TRACE_ENTRY();
     if (vbox_device_available(pVBox))
     {
@@ -474,5 +442,5 @@
                                  FALSE, TRUE);
     }
-    TRACE2;
+    TRACE_EXIT();
     return pModes;
 }
@@ -550,4 +518,28 @@
 };
 
+#ifdef VBOX_DRI
+static const char *drmSymbols[] = {
+    "drmFreeVersion",
+    "drmGetVersion",
+    NULL
+};
+
+static const char *driSymbols[] = {
+    "DRICloseScreen",
+    "DRICreateInfoRec",
+    "DRIDestroyInfoRec",
+    "DRIFinishScreenInit",
+    "DRIGetSAREAPrivate",
+    "DRILock",
+    "DRIMoveBuffersHelper",
+    "DRIQueryVersion",
+    "DRIScreenInit",
+    "DRIUnlock",
+    "GlxSetVisualConfigs",
+    "DRICreatePCIBusID",
+    NULL
+};
+#endif
+
 #ifdef XFree86LOADER
 /* Module loader interface */
@@ -593,4 +585,7 @@
                           vbeSymbols,
                           ramdacSymbols,
+#ifdef VBOX_DRI
+                          drmSymbols, driSymbols,
+#endif
                           NULL);
         return (pointer)TRUE;
@@ -628,5 +623,5 @@
     ScrnInfoPtr pScrn;
 
-    TRACE;
+    TRACE_ENTRY();
     pScrn = xf86ConfigPciEntity(NULL, 0, entity_num, VBOXPCIchipsets,
                                 NULL, NULL, NULL, NULL, NULL);
@@ -650,5 +645,5 @@
     }
 
-    TRACE3("returning %s\n", BOOL_STR(pScrn != NULL));
+    TRACE_LOG("returning %s\n", BOOL_STR(pScrn != NULL));
     return (pScrn != NULL);
 }
@@ -694,5 +689,5 @@
 			pScrn->name	     = VBOX_NAME;
 			pScrn->Probe	     = VBOXProbe;
-                        pScrn->PreInit       = VBOXPreInit;
+            pScrn->PreInit       = VBOXPreInit;
 			pScrn->ScreenInit    = VBOXScreenInit;
 			pScrn->SwitchMode    = VBOXSwitchMode;
@@ -908,4 +903,10 @@
     pScrn->bitmapBitOrder = BITMAP_BIT_ORDER;
 
+#ifdef VBOX_DRI
+    /* Load the dri module. */
+    if (xf86LoadSubModule(pScrn, "dri")) {
+        xf86LoaderReqSymLists(driSymbols, drmSymbols, NULL);
+    }
+#endif
     return (TRUE);
 }
@@ -926,8 +927,8 @@
     VBOXPtr pVBox = VBOXGetRec(pScrn);
 
-    TRACE3("enable=%s\n", enable ? "TRUE" : "FALSE");
+    TRACE_LOG("enable=%s\n", enable ? "TRUE" : "FALSE");
     pVBox->accessEnabled = enable;
     pVBox->EnableDisableFBAccess(scrnIndex, enable);
-    TRACE2;
+    TRACE_EXIT();
 }
 
@@ -984,4 +985,8 @@
     if (!miSetPixmapDepths())
         return (FALSE);
+
+#ifdef VBOX_DRI
+    pVBox->useDRI = VBOXDRIScreenInit(scrnIndex, pScreen, pVBox);
+#endif
 
     /* I checked in the sources, and XFree86 4.2 does seem to support
@@ -1076,4 +1081,9 @@
         /* Report the largest resolution that we support */
     }
+
+#ifdef VBOX_DRI
+    if (pVBox->useDRI)
+        pVBox->useDRI = VBOXDRIFinishScreenInit(pScreen);
+#endif
     return (TRUE);
 }
@@ -1086,8 +1096,12 @@
     bool rc;
 
-    TRACE;
+    TRACE_ENTRY();
     pVBox->vtSwitch = FALSE;
+#ifdef VBOX_DRI
+    if (pVBox->useDRI)
+        DRIUnlock(screenInfo.screens[scrnIndex]);
+#endif
     rc = xf86SetDesiredModes(pScrn);
-    TRACE3("returning %s\n", rc ? "TRUE" : "FALSE");
+    TRACE_LOG("returning %s\n", rc ? "TRUE" : "FALSE");
     return rc;
 }
@@ -1099,5 +1113,5 @@
     VBOXPtr pVBox = VBOXGetRec(pScrn);
 
-    TRACE;
+    TRACE_ENTRY();
     pVBox->vtSwitch = TRUE;
     VBOXSaveRestore(pScrn, MODE_RESTORE);
@@ -1108,5 +1122,9 @@
         vboxDisableGraphicsCap(pVBox);
     }
-    TRACE2;
+#ifdef VBOX_DRI
+    if (pVBox->useDRI)
+        DRILock(screenInfo.screens[scrnIndex], 0);
+#endif
+    TRACE_EXIT();
 }
 
@@ -1116,4 +1134,10 @@
     ScrnInfoPtr pScrn = xf86Screens[scrnIndex];
     VBOXPtr pVBox = VBOXGetRec(pScrn);
+
+#ifdef VBOX_DRI
+    if (pVBox->useDRI)
+        VBOXDRICloseScreen(pScreen, pVBox);
+    pVBox->useDRI = false;
+#endif
 
     if (vbox_device_available(pVBox))
@@ -1162,5 +1186,5 @@
     float v;
 
-    TRACE3("HDisplay=%d, VDisplay=%d, flag=%s, pass=%d\n",
+    TRACE_LOG("HDisplay=%d, VDisplay=%d, flag=%s, pass=%d\n",
            p->HDisplay, p->VDisplay, flag ? "TRUE" : "FALSE", pass);
     if (pass != MODECHECK_FINAL) {
@@ -1196,5 +1220,5 @@
         xf86DrvMsg(scrn, X_WARNING, "Graphics mode %s rejected by the X server\n", p->name);
     }
-    TRACE3("returning %d\n", ret);
+    TRACE_LOG("returning %d\n", ret);
     return ret;
 }
@@ -1207,5 +1231,5 @@
     Bool rc;
 
-    TRACE3("HDisplay=%d, VDisplay=%d\n", pMode->HDisplay, pMode->VDisplay);
+    TRACE_LOG("HDisplay=%d, VDisplay=%d\n", pMode->HDisplay, pMode->VDisplay);
     pScrn = xf86Screens[scrnIndex];  /* Why does X have three ways of refering to the screen? */
     pVBox = VBOXGetRec(pScrn);
@@ -1217,5 +1241,5 @@
     if (pVBox->accessEnabled)
         pVBox->EnableDisableFBAccess(scrnIndex, TRUE);
-    TRACE3("returning %s\n", rc ? "TRUE" : "FALSE");
+    TRACE_LOG("returning %s\n", rc ? "TRUE" : "FALSE");
     return rc;
 }
@@ -1231,5 +1255,5 @@
 
     int bpp = pScrn->depth == 24 ? 32 : 16;
-    TRACE3("HDisplay=%d, VDisplay=%d\n", pMode->HDisplay, pMode->VDisplay);
+    TRACE_LOG("HDisplay=%d, VDisplay=%d\n", pMode->HDisplay, pMode->VDisplay);
     pVBox = VBOXGetRec(pScrn);
     /* Don't fiddle with the hardware if we are switched
@@ -1275,5 +1299,5 @@
         }
     }
-    TRACE3("returning %s\n", rc ? "TRUE" : "FALSE");
+    TRACE_LOG("returning %s\n", rc ? "TRUE" : "FALSE");
     return rc;
 }
@@ -1285,5 +1309,5 @@
     ScrnInfoPtr pScrn = xf86Screens[scrnIndex];
 
-    TRACE;
+    TRACE_ENTRY();
     /* Don't fiddle with the hardware if we are switched
      * to a virtual terminal. */
@@ -1298,5 +1322,5 @@
             vboxEnableVbva(pScrn);
     }
-    TRACE2;
+    TRACE_EXIT();
 }
 
@@ -1313,5 +1337,5 @@
     Bool rc = TRUE;
 
-    TRACE;
+    TRACE_ENTRY();
     if (NULL == pVBox->base)
     {
@@ -1350,5 +1374,5 @@
         rc = pVBox->base != NULL;
     }
-    TRACE3("returning %s\n", rc ? "TRUE" : "FALSE");
+    TRACE_LOG("returning %s\n", rc ? "TRUE" : "FALSE");
     return rc;
 }
@@ -1359,5 +1383,5 @@
     VBOXPtr pVBox = VBOXGetRec(pScrn);
 
-    TRACE;
+    TRACE_ENTRY();
     if (pVBox->base == NULL)
         return;
@@ -1374,5 +1398,5 @@
 #endif
     pVBox->base = NULL;
-    TRACE2;
+    TRACE_EXIT();
 }
 
@@ -1389,5 +1413,5 @@
     } while (0)
 
-    TRACE;
+    TRACE_ENTRY();
     for (i = 0; i < numColors; i++) {
 	   idx = indices[i];
@@ -1401,5 +1425,5 @@
 	   VBOXDACDelay();
     }
-    TRACE2;
+    TRACE_EXIT();
 }
 
@@ -1475,5 +1499,5 @@
     Bool cont = TRUE;
 
-    TRACE;
+    TRACE_ENTRY();
     if (pVBox->fonts != NULL)
 	cont = FALSE;
@@ -1539,5 +1563,5 @@
         WriteMiscOut(miscOut);
     }
-    TRACE2;
+    TRACE_EXIT();
 }
 
@@ -1548,5 +1572,5 @@
     unsigned char miscOut, attr10, gr1, gr3, gr4, gr5, gr6, gr8, seq2, seq4, scrn;
 
-    TRACE;
+    TRACE_ENTRY();
     if (pVBox->fonts != NULL)
     {
@@ -1610,5 +1634,5 @@
         WriteSeq(0x04, seq4);
     }
-    TRACE2;
+    TRACE_EXIT();
 }
 
@@ -1619,5 +1643,5 @@
     Bool rc = TRUE;
 
-    TRACE;
+    TRACE_ENTRY();
     if (MODE_QUERY < 0 || function > MODE_RESTORE)
 	rc = FALSE;
@@ -1672,5 +1696,5 @@
         }
     }
-    TRACE3("returning %s\n", rc ? "TRUE" : "FALSE");
+    TRACE_LOG("returning %s\n", rc ? "TRUE" : "FALSE");
     return rc;
 }
Index: /trunk/src/VBox/Additions/x11/vboxvideo/vboxvideo_dri.c
===================================================================
--- /trunk/src/VBox/Additions/x11/vboxvideo/vboxvideo_dri.c	(revision 17318)
+++ /trunk/src/VBox/Additions/x11/vboxvideo/vboxvideo_dri.c	(revision 17318)
@@ -0,0 +1,375 @@
+/** @file $Id$
+ *
+ * VirtualBox X11 Additions graphics driver, DRI support
+ */
+
+/*
+ * Copyright (C) 2006-2007 Sun Microsystems, Inc.
+ *
+ * This file is part of VirtualBox Open Source Edition (OSE), as
+ * available from http://www.virtualbox.org. This file is free software;
+ * you can redistribute it and/or modify it under the terms of the GNU
+ * General Public License (GPL) as published by the Free Software
+ * Foundation, in version 2 as it comes in the "COPYING" file of the
+ * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
+ * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
+ * Clara, CA 95054 USA or visit http://www.sun.com if you need
+ * additional information or have any questions.
+ * --------------------------------------------------------------------
+ *
+ * This code is based on:
+ *
+ * X11 TDFX driver, src/tdfx_dri.c
+ *
+ * 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:
+ *   Daryll Strauss <daryll@precisioninsight.com>
+ */
+
+#include "vboxvideo.h"
+#ifndef PCIACCESS
+# include "xf86Pci.h"
+#endif
+
+static Bool
+VBOXCreateContext(ScreenPtr pScreen, VisualPtr visual,
+                  drm_context_t hwContext, void *pVisualConfigPriv,
+                  DRIContextType contextStore);
+static void
+VBOXDestroyContext(ScreenPtr pScreen, drm_context_t hwContext,
+                   DRIContextType contextStore);
+static void
+VBOXDRISwapContext(ScreenPtr pScreen, DRISyncType syncType,
+                   DRIContextType oldContextType, void *oldContext,
+                   DRIContextType newContextType, void *newContext);
+static void
+VBOXDRIInitBuffers(WindowPtr pWin, RegionPtr prgn, CARD32 index);
+static void
+VBOXDRIMoveBuffers(WindowPtr pParent, DDXPointRec ptOldOrg,
+                   RegionPtr prgnSrc, CARD32 index);
+static Bool
+VBOXDRIOpenFullScreen(ScreenPtr pScreen);
+static Bool
+VBOXDRICloseFullScreen(ScreenPtr pScreen);
+static void
+VBOXDRITransitionTo2d(ScreenPtr pScreen);
+static void
+VBOXDRITransitionTo3d(ScreenPtr pScreen);
+
+static Bool
+VBOXInitVisualConfigs(ScrnInfoPtr pScrn, VBOXPtr pVBox)
+{
+    Bool rc = TRUE;
+    TRACE_ENTRY();
+    int cConfigs = 2;  /* With and without double buffering */
+    __GLXvisualConfig *pConfigs = NULL;
+    pConfigs = (__GLXvisualConfig*) xcalloc(sizeof(__GLXvisualConfig),
+                                            cConfigs);
+    if (!pConfigs)
+    {
+        rc = FALSE;
+        xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
+                   "Disabling DRI: out of memory.\n");
+    }
+    for (int i = 0; rc && i < cConfigs; ++i)
+    {
+        pConfigs[i].vid = -1;
+        pConfigs[i].class = -1;
+        pConfigs[i].rgba = TRUE;
+        if (pScrn->bitsPerPixel == 16)
+        {
+            pConfigs[i].redSize = 5;
+            pConfigs[i].greenSize = 6;
+            pConfigs[i].blueSize = 5;
+            pConfigs[i].redMask = 0x0000F800;
+            pConfigs[i].greenMask = 0x000007E0;
+            pConfigs[i].blueMask = 0x0000001F;
+        }
+        else if (pScrn->bitsPerPixel == 32)
+        {
+            pConfigs[i].redSize = 8;
+            pConfigs[i].greenSize = 8;
+            pConfigs[i].blueSize = 8;
+            pConfigs[i].alphaSize = 8;
+            pConfigs[i].redMask   = 0x00ff0000;
+            pConfigs[i].greenMask = 0x0000ff00;
+            pConfigs[i].blueMask  = 0x000000ff;
+            pConfigs[i].alphaMask = 0xff000000;
+        }
+        else
+            rc = FALSE;
+        pConfigs[i].bufferSize = pScrn->bitsPerPixel;
+        pConfigs[i].visualRating = GLX_NONE;
+        pConfigs[i].transparentPixel = GLX_NONE;
+    }
+    if (rc)
+    {
+        pConfigs[0].doubleBuffer = FALSE;
+        pConfigs[1].doubleBuffer = TRUE;
+        pVBox->cVisualConfigs = cConfigs;
+        pVBox->pVisualConfigs = pConfigs;
+        TRACE_LOG("Calling GlxSetVisualConfigs\n");
+        GlxSetVisualConfigs(cConfigs, pConfigs, NULL);
+    }
+    if (!rc && pConfigs)
+        xfree(pConfigs);
+    TRACE_LOG("returning %s\n", BOOL_STR(rc));
+    return rc;
+}
+
+#if 0
+static void
+VBOXDoWakeupHandler(int screenNum, pointer wakeupData, unsigned long result,
+                    pointer pReadmask)
+{
+
+}
+#endif
+
+#if 0
+static void
+VBOXDoBlockHandler(int screenNum, pointer blockData, pointer pTimeout,
+                   pointer pReadmask)
+{
+
+}
+#endif
+
+Bool VBOXDRIScreenInit(int scrnIndex, ScreenPtr pScreen, VBOXPtr pVBox)
+{
+    DRIInfoPtr pDRIInfo = NULL;
+    Bool rc = TRUE;
+    ScrnInfoPtr pScrn = xf86Screens[scrnIndex];
+
+    TRACE_ENTRY();
+    pVBox->drmFD = -1;
+    if (   pScrn->bitsPerPixel != 16
+        && pScrn->bitsPerPixel != 32)
+    {
+        xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
+                   "DRI is only available in 16bpp or 32bpp graphics modes.\n");
+        rc = FALSE;
+    }
+    /* Check that the GLX, DRI, and DRM modules have been loaded by testing for
+     * canonical symbols in each module, the way all existing _dri drivers do.
+     */
+    if (rc)
+    {
+        TRACE_LOG("Checking symbols\n");
+        if (   !xf86LoaderCheckSymbol("GlxSetVisualConfigs")
+            || !xf86LoaderCheckSymbol("drmAvailable")
+            || !xf86LoaderCheckSymbol("DRIQueryVersion"))
+        {
+            xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
+                       "Disabling DRI due to missing server functionality.\n");
+            rc = FALSE;
+        }
+    }
+    /* Check the DRI version */
+    if (rc)
+    {
+        int major, minor, patch;
+        TRACE_LOG("Checking DRI version\n");
+        DRIQueryVersion(&major, &minor, &patch);
+        if (major != DRIINFO_MAJOR_VERSION || minor < DRIINFO_MINOR_VERSION)
+        {
+            xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
+                       "Disabling DRI due to a version mismatch between server and driver.  Server version: %d.%d.  Driver version: %d.%d\n",
+                       major, minor, DRIINFO_MAJOR_VERSION, DRIINFO_MINOR_VERSION);
+            rc = FALSE;
+        }
+    }
+    if (rc)
+    {
+        TRACE_LOG("Creating DRIInfoRec\n");
+        pDRIInfo = DRICreateInfoRec();
+        if (!pDRIInfo)
+        {
+            xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
+                       "Disabling DRI: out of memory.\n");
+            rc = FALSE;
+        }
+        else
+            pVBox->pDRIInfo = pDRIInfo;
+    }
+    if (rc)
+    {
+        pDRIInfo->CreateContext = VBOXCreateContext;
+        pDRIInfo->DestroyContext = VBOXDestroyContext;
+        pDRIInfo->SwapContext = VBOXDRISwapContext;
+        pDRIInfo->InitBuffers = VBOXDRIInitBuffers;
+        pDRIInfo->MoveBuffers = VBOXDRIMoveBuffers;
+        pDRIInfo->OpenFullScreen = VBOXDRIOpenFullScreen;
+        pDRIInfo->CloseFullScreen = VBOXDRICloseFullScreen;
+        pDRIInfo->TransitionTo2d = VBOXDRITransitionTo2d;
+        pDRIInfo->TransitionTo3d = VBOXDRITransitionTo3d;
+
+        /* These two are set in DRICreateInfoRec(). */
+        pDRIInfo->wrap.ValidateTree = NULL;
+        pDRIInfo->wrap.PostValidateTree = NULL;
+
+        pDRIInfo->drmDriverName = VBOX_DRM_DRIVER_NAME;
+        pDRIInfo->clientDriverName = VBOX_DRI_DRIVER_NAME;
+#ifdef PCIACCESS
+        pDRIInfo->busIdString = DRICreatePCIBusID(pVBox->pciInfo);
+#else
+        pDRIInfo->busIdString = xalloc(64);
+        sprintf(pDRIInfo->busIdString, "PCI:%d:%d:%d",
+            ((pciConfigPtr)pVBox->pciInfo->thisCard)->busnum,
+	        ((pciConfigPtr)pVBox->pciInfo->thisCard)->devnum,
+            ((pciConfigPtr)pVBox->pciInfo->thisCard)->funcnum);
+#endif
+        pDRIInfo->ddxDriverMajorVersion = VBOX_VIDEO_MAJOR;
+        pDRIInfo->ddxDriverMinorVersion = VBOX_VIDEO_MINOR;
+        pDRIInfo->ddxDriverPatchVersion = 0;
+        pDRIInfo->ddxDrawableTableEntry = VBOX_MAX_DRAWABLES;
+        pDRIInfo->maxDrawableTableEntry = VBOX_MAX_DRAWABLES;
+        /* This can't be zero, as the server callocs this size and checks for
+         * non-NULL... */
+        pDRIInfo->contextSize = 4;
+        pDRIInfo->driverSwapMethod = DRI_HIDE_X_CONTEXT;
+        pDRIInfo->bufferRequests = DRI_ALL_WINDOWS;
+        TRACE_LOG("Calling DRIScreenInit\n");
+        if (!DRIScreenInit(pScreen, pDRIInfo, &pVBox->drmFD))
+            rc = FALSE;
+        if (!rc)
+            xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
+                       "DRIScreenInit failed, disabling DRI.\n");
+    }
+    if (rc && !VBOXInitVisualConfigs(pScrn, pVBox))
+    {
+        xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
+                   "VBOXInitVisualConfigs failed, disabling DRI.\n");
+        rc = FALSE;
+    }
+    xf86DrvMsg(pScrn->scrnIndex, X_INFO, "visual configurations initialized\n");
+
+    /* Check the DRM version */
+    if (rc)
+    {
+        drmVersionPtr version = drmGetVersion(pVBox->drmFD);
+        TRACE_LOG("Checking DRM version\n");
+        if (version)
+        {
+            if (version->version_major != 1 || version->version_minor < 0)
+            {
+                xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
+                           "Bad DRM driver version %d.%d, expected version 1.0.  Disabling DRI.\n",
+                           version->version_major, version->version_minor);
+                rc = FALSE;
+            }
+            drmFreeVersion(version);
+        }
+    }
+
+    /* Clean up on failure. */
+    if (!rc)
+    {
+        if (pVBox->pDRIInfo)
+            DRIDestroyInfoRec(pVBox->pDRIInfo);
+        pVBox->pDRIInfo = NULL;
+        if (pVBox->drmFD >= 0)
+           VBOXDRICloseScreen(pScreen, pVBox);
+        pVBox->drmFD = -1;
+    }
+    TRACE_LOG("returning %s\n", BOOL_STR(rc));
+    return rc;
+}
+
+void
+VBOXDRICloseScreen(ScreenPtr pScreen, VBOXPtr pVBox)
+{
+    DRICloseScreen(pScreen);
+    DRIDestroyInfoRec(pVBox->pDRIInfo);
+    pVBox->pDRIInfo=0;
+    if (pVBox->pVisualConfigs)
+        xfree(pVBox->pVisualConfigs);
+    pVBox->cVisualConfigs = 0;
+    pVBox->pVisualConfigs = NULL;
+}
+
+static Bool
+VBOXCreateContext(ScreenPtr pScreen, VisualPtr visual,
+                  drm_context_t hwContext, void *pVisualConfigPriv,
+                  DRIContextType contextStore)
+{
+    return TRUE;
+}
+
+static void
+VBOXDestroyContext(ScreenPtr pScreen, drm_context_t hwContext,
+                   DRIContextType contextStore)
+{
+}
+
+Bool
+VBOXDRIFinishScreenInit(ScreenPtr pScreen)
+{
+    return DRIFinishScreenInit(pScreen);
+}
+
+static void
+VBOXDRISwapContext(ScreenPtr pScreen, DRISyncType syncType,
+                   DRIContextType oldContextType, void *oldContext,
+                   DRIContextType newContextType, void *newContext)
+{
+}
+
+static void
+VBOXDRIInitBuffers(WindowPtr pWin, RegionPtr prgn, CARD32 index)
+{
+}
+
+static void
+VBOXDRIMoveBuffers(WindowPtr pParent, DDXPointRec ptOldOrg,
+                   RegionPtr prgnSrc, CARD32 index)
+{
+}
+
+/* Apparantly the next two are just legacy. */
+static Bool
+VBOXDRIOpenFullScreen(ScreenPtr pScreen)
+{
+    return TRUE;
+}
+
+static Bool
+VBOXDRICloseFullScreen(ScreenPtr pScreen)
+{
+    return TRUE;
+}
+
+static void
+VBOXDRITransitionTo2d(ScreenPtr pScreen)
+{
+}
+
+static void
+VBOXDRITransitionTo3d(ScreenPtr pScreen)
+{
+}
+
