libGL: Consolidate DRI initialization in dri_glx.c
[mesa.git] / src / glx / x11 / glxext.c
index 85c990d4fc1a612ef417cc15cb35681c8d24d9c9..e07312214bec7002588c9cdc934c3d1c9b7dc0fc 100644 (file)
@@ -360,9 +360,10 @@ static void FreeScreenConfigs(__GLXdisplayPrivate *priv)
 #ifdef GLX_DIRECT_RENDERING
        /* Free the direct rendering per screen data */
        if (psc->driScreen.private)
-           (*psc->driScreen.destroyScreen)(psc->driScreen.private);
+           (*psc->driScreen.destroyScreen)(&psc->driScreen);
        psc->driScreen.private = NULL;
-       __glxHashDestroy(psc->drawHash);
+       if (psc->drawHash)
+           __glxHashDestroy(psc->drawHash);
 #endif
     }
     XFree((char*) priv->screenConfigs);
@@ -632,389 +633,128 @@ __glXInitializeVisualConfigFromTags( __GLcontextModes *config, int count,
     config->haveStencilBuffer = (config->stencilBits > 0);
 }
 
-
-#ifdef GLX_DIRECT_RENDERING
-static unsigned
-filter_modes( __GLcontextModes ** server_modes,
-             const __GLcontextModes * driver_modes )
+static __GLcontextModes *
+createConfigsFromProperties(Display *dpy, int nvisuals, int nprops,
+                           int screen, GLboolean tagged_only)
 {
-    __GLcontextModes * m;
-    __GLcontextModes ** prev_next;
-    const __GLcontextModes * check;
-    unsigned modes_count = 0;
-
-    if ( driver_modes == NULL ) {
-       fprintf(stderr, "libGL warning: 3D driver returned no fbconfigs.\n");
-       return 0;
-    }
-
-    /* For each mode in server_modes, check to see if a matching mode exists
-     * in driver_modes.  If not, then the mode is not available.
-     */
-
-    prev_next = server_modes;
-    for ( m = *prev_next ; m != NULL ; m = *prev_next ) {
-       GLboolean do_delete = GL_TRUE;
+    INT32 buf[__GLX_TOTAL_CONFIG], *props;
+    unsigned prop_size;
+    __GLcontextModes *modes, *m;
+    int i;
 
-       for ( check = driver_modes ; check != NULL ; check = check->next ) {
-           if ( _gl_context_modes_are_same( m, check ) ) {
-               do_delete = GL_FALSE;
-               break;
-           }
-       }
+    if (nprops == 0)
+       return NULL;
 
-       /* The 3D has to support all the modes that match the GLX visuals
-        * sent from the X server.
-        */
-       if ( do_delete && (m->visualID != 0) ) {
-           do_delete = GL_FALSE;
+    /* FIXME: Is the __GLX_MIN_CONFIG_PROPS test correct for FBconfigs? */
 
-           /* don't warn for this visual (Novell #247471 / X.Org #6689) */
-           if (m->visualRating != GLX_NON_CONFORMANT_CONFIG) {
-               fprintf(stderr, "libGL warning: 3D driver claims to not "
-                       "support visual 0x%02x\n", m->visualID);
-           }
-       }
+    /* Check number of properties */
+    if (nprops < __GLX_MIN_CONFIG_PROPS || nprops > __GLX_MAX_CONFIG_PROPS)
+       return NULL;
 
-       if ( do_delete ) {
-           *prev_next = m->next;
+    /* Allocate memory for our config structure */
+    modes = _gl_context_modes_create(nvisuals, sizeof(__GLcontextModes));
+    if (!modes)
+       return NULL;
 
-           m->next = NULL;
-           _gl_context_modes_destroy( m );
-       }
-       else {
-           modes_count++;
-           prev_next = & m->next;
-       }
+    prop_size = nprops * __GLX_SIZE_INT32;
+    if (prop_size <= sizeof(buf))
+       props = buf;
+    else
+       props = Xmalloc(prop_size);
+
+    /* Read each config structure and convert it into our format */
+    m = modes;
+    for (i = 0; i < nvisuals; i++) {
+       _XRead(dpy, (char *)props, prop_size);
+       /* Older X servers don't send this so we default it here. */
+       m->drawableType = GLX_WINDOW_BIT;
+       __glXInitializeVisualConfigFromTags(m, nprops, props,
+                                           tagged_only, GL_TRUE);
+       m->screen = screen;
+       m = m->next;
     }
 
-    return modes_count;
-}
+    if (props != buf)
+       Xfree(props);
 
-
-/**
- * Implement \c __DRIinterfaceMethods::getProcAddress.
- */
-static __DRIfuncPtr get_proc_address( const char * proc_name )
-{
-    if (strcmp( proc_name, "glxEnableExtension" ) == 0) {
-       return (__DRIfuncPtr) __glXScrEnableExtension;
-    }
-    
-    return NULL;
+    return modes;
 }
 
-#ifdef XDAMAGE_1_1_INTERFACE
-static GLboolean has_damage_post(Display *dpy)
+static GLboolean
+getVisualConfigs(Display *dpy, __GLXdisplayPrivate *priv, int screen)
 {
-    static GLboolean inited = GL_FALSE;
-    static GLboolean has_damage;
-
-    if (!inited) {
-       int major, minor;
-
-       if (XDamageQueryVersion(dpy, &major, &minor) &&
-           major == 1 && minor >= 1)
-       {
-           has_damage = GL_TRUE;
-       } else {
-           has_damage = GL_FALSE;
-       }
-       inited = GL_TRUE;
-    }
+    xGLXGetVisualConfigsReq *req;
+    __GLXscreenConfigs *psc;
+    xGLXGetVisualConfigsReply reply;
+    
+    LockDisplay(dpy);
 
-    return has_damage;
-}
-#endif /* XDAMAGE_1_1_INTERFACE */
+    psc = priv->screenConfigs + screen;
+    psc->visuals = NULL;
+    GetReq(GLXGetVisualConfigs, req);
+    req->reqType = priv->majorOpcode;
+    req->glxCode = X_GLXGetVisualConfigs;
+    req->screen = screen;
 
-static void __glXReportDamage(__DRIdrawable *driDraw,
-                             int x, int y,
-                             drm_clip_rect_t *rects, int num_rects,
-                             GLboolean front_buffer)
-{
-#ifdef XDAMAGE_1_1_INTERFACE
-    XRectangle *xrects;
-    XserverRegion region;
-    int i;
-    int x_off, y_off;
-    __GLXdrawable *glxDraw =
-       containerOf(driDraw, __GLXdrawable, driDrawable);
-    __GLXscreenConfigs *psc = glxDraw->psc;
-    Display *dpy = psc->dpy;
-    Drawable drawable;
-
-    if (!has_damage_post(dpy))
-       return;
-
-    if (front_buffer) {
-       x_off = x;
-       y_off = y;
-       drawable = RootWindow(dpy, psc->scr);
-    } else{
-       x_off = 0;
-       y_off = 0;
-       drawable = glxDraw->drawable;
-    }
+    if (!_XReply(dpy, (xReply*) &reply, 0, False))
+       goto out;
 
-    xrects = malloc(sizeof(XRectangle) * num_rects);
-    if (xrects == NULL)
-       return;
+    psc->visuals = createConfigsFromProperties(dpy,
+                                              reply.numVisuals,
+                                              reply.numProps,
+                                              screen, GL_FALSE);
 
-    for (i = 0; i < num_rects; i++) {
-       xrects[i].x = rects[i].x1 + x_off;
-       xrects[i].y = rects[i].y1 + y_off;
-       xrects[i].width = rects[i].x2 - rects[i].x1;
-       xrects[i].height = rects[i].y2 - rects[i].y1;
-    }
-    region = XFixesCreateRegion(dpy, xrects, num_rects);
-    free(xrects);
-    XDamageAdd(dpy, drawable, region);
-    XFixesDestroyRegion(dpy, region);
-#endif
+ out:
+    UnlockDisplay(dpy);
+    return psc->visuals != NULL;
 }
 
 static GLboolean
-__glXDRIGetDrawableInfo(__DRIdrawable *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)
-{
-    __GLXdrawable *glxDraw =
-       containerOf(drawable, __GLXdrawable, driDrawable);
-    __GLXscreenConfigs *psc = glxDraw->psc;
-    Display *dpy = psc->dpy;
-
-    return XF86DRIGetDrawableInfo(dpy, psc->scr, glxDraw->drawable,
-                                 index, stamp, X, Y, W, H,
-                                 numClipRects, pClipRects,
-                                 backX, backY,
-                                 numBackClipRects, pBackClipRects);
-}
-
-
-/**
- * Table of functions exported by the loader to the driver.
- */
-static const __DRIinterfaceMethods interface_methods = {
-    get_proc_address,
-
-    _gl_context_modes_create,
-    _gl_context_modes_destroy,
-
-    __glXDRIGetDrawableInfo,
-
-    __glXGetUST,
-    __glXGetMscRateOML,
-
-    __glXReportDamage,
-};
-
-
-
-/**
- * Perform the required libGL-side initialization and call the client-side
- * driver's \c __driCreateNewScreen function.
- * 
- * \param dpy    Display pointer.
- * \param scrn   Screen number on the display.
- * \param psc    DRI screen information.
- * \param driDpy DRI display information.
- * \param createNewScreen  Pointer to the client-side driver's
- *               \c __driCreateNewScreen function.
- * \returns A pointer to the \c __DRIscreenPrivate structure returned by
- *          the client-side driver on success, or \c NULL on failure.
- * 
- * \todo This function needs to be modified to remove context-modes from the
- *       list stored in the \c __GLXscreenConfigsRec to match the list
- *       returned by the client-side driver.
- */
-static void *
-CallCreateNewScreen(Display *dpy, int scrn, __GLXscreenConfigs *psc,
-                   __DRIdisplay * driDpy,
-                   PFNCREATENEWSCREENFUNC createNewScreen)
+getFBConfigs(Display *dpy, __GLXdisplayPrivate *priv, int screen)
 {
-    __DRIscreenPrivate *psp = NULL;
-#ifndef GLX_USE_APPLEGL
-    drm_handle_t hSAREA;
-    drmAddress pSAREA = MAP_FAILED;
-    char *BusID;
-    __DRIversion   ddx_version;
-    __DRIversion   dri_version;
-    __DRIversion   drm_version;
-    __DRIframebuffer  framebuffer;
-    int   fd = -1;
-    int   status;
-    const char * err_msg;
-    const char * err_extra;
-    int api_ver = __glXGetInternalVersion();
-
-
-    dri_version.major = driDpy->private->driMajor;
-    dri_version.minor = driDpy->private->driMinor;
-    dri_version.patch = driDpy->private->driPatch;
-
-
-    err_msg = "XF86DRIOpenConnection";
-    err_extra = NULL;
-
-    framebuffer.base = MAP_FAILED;
-    framebuffer.dev_priv = NULL;
-
-    if (XF86DRIOpenConnection(dpy, scrn, &hSAREA, &BusID)) {
-        int newlyopened;
-       fd = drmOpenOnce(NULL,BusID, &newlyopened);
-       Xfree(BusID); /* No longer needed */
-
-       err_msg = "open DRM";
-       err_extra = strerror( -fd );
-
-       if (fd >= 0) {
-           drm_magic_t magic;
-
-           err_msg = "drmGetMagic";
-           err_extra = NULL;
-
-           if (!drmGetMagic(fd, &magic)) {
-               drmVersionPtr version = drmGetVersion(fd);
-               if (version) {
-                   drm_version.major = version->version_major;
-                   drm_version.minor = version->version_minor;
-                   drm_version.patch = version->version_patchlevel;
-                   drmFreeVersion(version);
-               }
-               else {
-                   drm_version.major = -1;
-                   drm_version.minor = -1;
-                   drm_version.patch = -1;
-               }
-
-               err_msg = "XF86DRIAuthConnection";
-               if (!newlyopened || XF86DRIAuthConnection(dpy, scrn, magic)) {
-                   char *driverName;
-
-                   /*
-                    * Get device name (like "tdfx") and the ddx version
-                    * numbers.  We'll check the version in each DRI driver's
-                    * "createNewScreen" function.
-                    */
-                   err_msg = "XF86DRIGetClientDriverName";
-                   if (XF86DRIGetClientDriverName(dpy, scrn,
-                                                  &ddx_version.major,
-                                                  &ddx_version.minor,
-                                                  &ddx_version.patch,
-                                                  &driverName)) {
-                       drm_handle_t  hFB;
-                       int        junk;
-
-                       /* No longer needed. */
-                       Xfree( driverName );
-
-
-                       /*
-                        * Get device-specific info.  pDevPriv will point to a struct
-                        * (such as DRIRADEONRec in xfree86/driver/ati/radeon_dri.h)
-                        * that has information about the screen size, depth, pitch,
-                        * ancilliary buffers, DRM mmap handles, etc.
-                        */
-                       err_msg = "XF86DRIGetDeviceInfo";
-                       if (XF86DRIGetDeviceInfo(dpy, scrn,
-                                                &hFB,
-                                                &junk,
-                                                &framebuffer.size,
-                                                &framebuffer.stride,
-                                                &framebuffer.dev_priv_size,
-                                                &framebuffer.dev_priv)) {
-                           framebuffer.width = DisplayWidth(dpy, scrn);
-                           framebuffer.height = DisplayHeight(dpy, scrn);
-
-                           /*
-                            * Map the framebuffer region.
-                            */
-                           status = drmMap(fd, hFB, framebuffer.size, 
-                                           (drmAddressPtr)&framebuffer.base);
-
-                           err_msg = "drmMap of framebuffer";
-                           err_extra = strerror( -status );
-
-                           if ( status == 0 ) {
-                               /*
-                                * Map the SAREA region.  Further mmap regions
-                                * may be setup in each DRI driver's
-                                * "createNewScreen" function.
-                                */
-                               status = drmMap(fd, hSAREA, SAREA_MAX, 
-                                               &pSAREA);
-
-                               err_msg = "drmMap of sarea";
-                               err_extra = strerror( -status );
-
-                               if ( status == 0 ) {
-                                   __GLcontextModes * driver_modes = NULL;
-
-                                   err_msg = "InitDriver";
-                                   err_extra = NULL;
-                                   psp = (*createNewScreen)(scrn,
-                                                            &psc->driScreen,
-                                                            psc->configs,
-                                                            & ddx_version,
-                                                            & dri_version,
-                                                            & drm_version,
-                                                            & framebuffer,
-                                                            pSAREA,
-                                                            fd,
-                                                            api_ver,
-                                                            & interface_methods,
-                                                            & driver_modes );
-
-                                   filter_modes( & psc->configs,
-                                                 driver_modes );
-                                   _gl_context_modes_destroy( driver_modes );
-                               }
-                           }
-                       }
-                   }
-               }
-           }
-       }
-    }
-
-    if ( psp == NULL ) {
-       if ( pSAREA != MAP_FAILED ) {
-           (void)drmUnmap(pSAREA, SAREA_MAX);
-       }
-
-       if ( framebuffer.base != MAP_FAILED ) {
-           (void)drmUnmap((drmAddress)framebuffer.base, framebuffer.size);
-       }
+    xGLXGetFBConfigsReq *fb_req;
+    xGLXGetFBConfigsSGIXReq *sgi_req;
+    xGLXVendorPrivateWithReplyReq *vpreq;
+    xGLXGetFBConfigsReply reply;
+    __GLXscreenConfigs *psc;
 
-       if ( framebuffer.dev_priv != NULL ) {
-           Xfree(framebuffer.dev_priv);
-       }
+    psc = priv->screenConfigs + screen;
+    psc->serverGLXexts = __glXGetStringFromServer(dpy, priv->majorOpcode,
+                                                 X_GLXQueryServerString,
+                                                 screen, GLX_EXTENSIONS);
 
-       if ( fd >= 0 ) {
-           (void)drmCloseOnce(fd);
-       }
+    LockDisplay(dpy);
 
-       (void)XF86DRICloseConnection(dpy, scrn);
+    psc->configs = NULL;
+    if (atof(priv->serverGLXversion) >= 1.3) {
+       GetReq(GLXGetFBConfigs, fb_req);
+       fb_req->reqType = priv->majorOpcode;
+       fb_req->glxCode = X_GLXGetFBConfigs;
+       fb_req->screen = screen;
+    } else if (strstr(psc->serverGLXexts, "GLX_SGIX_fbconfig") != NULL) {
+       GetReqExtra(GLXVendorPrivateWithReply,
+                   sz_xGLXGetFBConfigsSGIXReq +
+                   sz_xGLXVendorPrivateWithReplyReq, vpreq);
+       sgi_req = (xGLXGetFBConfigsSGIXReq *) vpreq;
+       sgi_req->reqType = priv->majorOpcode;
+       sgi_req->glxCode = X_GLXVendorPrivateWithReply;
+       sgi_req->vendorCode = X_GLXvop_GetFBConfigsSGIX;
+       sgi_req->screen = screen;
+    } else
+       goto out;
 
-       if ( err_extra != NULL ) {
-           fprintf(stderr, "libGL error: %s failed (%s)\n", err_msg,
-                   err_extra);
-       }
-       else {
-           fprintf(stderr, "libGL error: %s failed\n", err_msg );
-       }
+    if (!_XReply(dpy, (xReply*) &reply, 0, False))
+       goto out;
 
-        fprintf(stderr, "libGL error: reverting to (slow) indirect rendering\n");
-    }
-#endif /* !GLX_USE_APPLEGL */
+    psc->configs = createConfigsFromProperties(dpy,
+                                              reply.numFBConfigs,
+                                              reply.numAttribs * 2,
+                                              screen, GL_TRUE);
 
-    return psp;
+ out:
+    UnlockDisplay(dpy);
+    return psc->configs != NULL;
 }
-#endif /* GLX_DIRECT_RENDERING */
-
 
 /*
 ** Allocate the memory for the per screen configs for each screen.
@@ -1022,17 +762,8 @@ CallCreateNewScreen(Display *dpy, int scrn, __GLXscreenConfigs *psc,
 */
 static Bool AllocAndFetchScreenConfigs(Display *dpy, __GLXdisplayPrivate *priv)
 {
-    xGLXGetVisualConfigsReq *req;
-    xGLXGetFBConfigsReq *fb_req;
-    xGLXVendorPrivateWithReplyReq *vpreq;
-    xGLXGetFBConfigsSGIXReq *sgi_req;
-    xGLXGetVisualConfigsReply reply;
     __GLXscreenConfigs *psc;
-    __GLcontextModes *config;
-    GLint i, j, nprops, screens;
-    INT32 buf[__GLX_TOTAL_CONFIG], *props;
-    unsigned supported_request = 0;
-    unsigned prop_size;
+    GLint i, screens;
 
     /*
     ** First allocate memory for the array of per screen configs.
@@ -1046,170 +777,21 @@ static Bool AllocAndFetchScreenConfigs(Display *dpy, __GLXdisplayPrivate *priv)
     priv->screenConfigs = psc;
     
     priv->serverGLXversion = __glXGetStringFromServer(dpy, priv->majorOpcode,
-                                        X_GLXQueryServerString,
-                                        0, GLX_VERSION);
+                                                     X_GLXQueryServerString,
+                                                     0, GLX_VERSION);
     if ( priv->serverGLXversion == NULL ) {
        FreeScreenConfigs(priv);
        return GL_FALSE;
     }
 
-    if ( atof( priv->serverGLXversion ) >= 1.3 ) {
-       supported_request = 1;
-    }
-
-    /*
-    ** Now fetch each screens configs structures.  If a screen supports
-    ** GL (by returning a numVisuals > 0) then allocate memory for our
-    ** config structure and then fill it in.
-    */
     for (i = 0; i < screens; i++, psc++) {
-       if ( supported_request != 1 ) {
-           psc->serverGLXexts = __glXGetStringFromServer(dpy, priv->majorOpcode,
-                                                         X_GLXQueryServerString,
-                                                         i, GLX_EXTENSIONS);
-           if ( strstr( psc->serverGLXexts, "GLX_SGIX_fbconfig" ) != NULL ) {
-               supported_request = 2;
-           }
-           else {
-               supported_request = 3;
-           }
-       }
+       getVisualConfigs(dpy, priv, i);
+       getFBConfigs(dpy, priv, i);
 
-
-       LockDisplay(dpy);
-       switch( supported_request ) {
-           case 1:
-           GetReq(GLXGetFBConfigs,fb_req);
-           fb_req->reqType = priv->majorOpcode;
-           fb_req->glxCode = X_GLXGetFBConfigs;
-           fb_req->screen = i;
-           break;
-          
-           case 2:
-           GetReqExtra(GLXVendorPrivateWithReply,
-                       sz_xGLXGetFBConfigsSGIXReq-sz_xGLXVendorPrivateWithReplyReq,vpreq);
-           sgi_req = (xGLXGetFBConfigsSGIXReq *) vpreq;
-           sgi_req->reqType = priv->majorOpcode;
-           sgi_req->glxCode = X_GLXVendorPrivateWithReply;
-           sgi_req->vendorCode = X_GLXvop_GetFBConfigsSGIX;
-           sgi_req->screen = i;
-           break;
-
-           case 3:
-           GetReq(GLXGetVisualConfigs,req);
-           req->reqType = priv->majorOpcode;
-           req->glxCode = X_GLXGetVisualConfigs;
-           req->screen = i;
-           break;
-       }
-
-       if (!_XReply(dpy, (xReply*) &reply, 0, False)) {
-           /* Something is busted. Punt. */
-           UnlockDisplay(dpy);
-           SyncHandle();
-           FreeScreenConfigs(priv);
-           return GL_FALSE;
-       }
-
-       if (!reply.numVisuals) {
-           /* This screen does not support GL rendering */
-           UnlockDisplay(dpy);
-           continue;
-       }
-
-       /* FIXME: Is the __GLX_MIN_CONFIG_PROPS test correct for
-        * FIXME: FBconfigs? 
-        */
-       /* Check number of properties */
-       nprops = reply.numProps;
-       if ((nprops < __GLX_MIN_CONFIG_PROPS) ||
-           (nprops > __GLX_MAX_CONFIG_PROPS)) {
-           /* Huh?  Not in protocol defined limits.  Punt */
-           UnlockDisplay(dpy);
-           SyncHandle();
-           FreeScreenConfigs(priv);
-           return GL_FALSE;
-       }
-
-       /* Allocate memory for our config structure */
-       psc->configs = _gl_context_modes_create(reply.numVisuals,
-                                               sizeof(__GLcontextModes));
-       if (!psc->configs) {
-           UnlockDisplay(dpy);
-           SyncHandle();
-           FreeScreenConfigs(priv);
-           return GL_FALSE;
-       }
-
-       /* Allocate memory for the properties, if needed */
-       if ( supported_request != 3 ) {
-           nprops *= 2;
-       }
-
-       prop_size = nprops * __GLX_SIZE_INT32;
-
-       if (prop_size <= sizeof(buf)) {
-           props = buf;
-       } else {
-           props = (INT32 *) Xmalloc(prop_size);
-       } 
-
-       /* Read each config structure and convert it into our format */
-        config = psc->configs;
-       for (j = 0; j < reply.numVisuals; j++) {
-           assert( config != NULL );
-           _XRead(dpy, (char *)props, prop_size);
-
-           if ( supported_request != 3 ) {
-               config->rgbMode = GL_TRUE;
-               config->drawableType = GLX_WINDOW_BIT;
-           }
-           else {
-               config->drawableType = GLX_WINDOW_BIT | GLX_PIXMAP_BIT;
-           }
-
-           __glXInitializeVisualConfigFromTags( config, nprops, props,
-                                                (supported_request != 3),
-                                                GL_TRUE );
-           if ( config->fbconfigID == GLX_DONT_CARE ) {
-               config->fbconfigID = config->visualID;
-           }
-           config->screen = i;
-           config = config->next;
-       }
-       if (props != buf) {
-           Xfree((char *)props);
-       }
-       UnlockDisplay(dpy);
-
-#ifdef GLX_DIRECT_RENDERING
        psc->scr = i;
        psc->dpy = dpy;
-       /* Create drawable hash */
-       psc->drawHash = __glxHashCreate();
-       if ( psc->drawHash == NULL ) {
-           SyncHandle();
-           FreeScreenConfigs(priv);
-           return GL_FALSE;
-       }
-
-        /* Initialize per screen dynamic client GLX extensions */
-       psc->ext_list_first_time = GL_TRUE;
-       /* Initialize the direct rendering per screen data and functions */
-       if (priv->driDisplay.private != NULL) {
-           /* FIXME: Should it be some sort of an error if createNewScreen[i]
-            * FIXME: is NULL?
-            */
-           if (priv->driDisplay.createNewScreen &&
-               priv->driDisplay.createNewScreen[i]) {
-
-               psc->driScreen.screenConfigs = (void *)psc;
-               psc->driScreen.private =
-                   CallCreateNewScreen(dpy, i, psc,
-                                       & priv->driDisplay,
-                                       priv->driDisplay.createNewScreen[i] );
-           }
-       }
+#ifdef GLX_DIRECT_RENDERING
+       driCreateScreen(psc, i, priv);
 #endif
     }
     SyncHandle();
@@ -1387,7 +969,8 @@ GLubyte *__glXFlushRenderBuffer(__GLXcontext *ctx, GLubyte *pc)
 
     if ( (dpy != NULL) && (size > 0) ) {
 #ifdef USE_XCB
-       xcb_glx_render(c, ctx->currentContextTag, size, (char *)ctx->buf);
+       xcb_glx_render(c, ctx->currentContextTag, size,
+                      (const uint8_t *)ctx->buf);
 #else
        /* Send the entire buffer as an X request */
        LockDisplay(dpy);
@@ -1657,7 +1240,7 @@ FetchDRIDrawable( Display *dpy, GLXDrawable drawable, GLXContext gc)
     }
 
     if (__glxHashInsert(sc->drawHash, drawable, pdraw)) {
-       (*pdraw->driDrawable.destroyDrawable)(pdraw->driDrawable.private);
+       (*pdraw->driDrawable.destroyDrawable)(&pdraw->driDrawable);
        XF86DRIDestroyDrawable(dpy, sc->scr, drawable);
        Xfree(pdraw);
        return NULL;
@@ -1672,7 +1255,7 @@ static Bool BindContextWrapper( Display *dpy, GLXContext gc,
     __DRIdrawable *pdraw = FetchDRIDrawable(dpy, draw, gc);
     __DRIdrawable *pread = FetchDRIDrawable(dpy, read, gc);
 
-    return (*gc->driContext.bindContext)(pdraw, pread, &gc->driContext);
+    return (*gc->driContext.bindContext)(&gc->driContext, pdraw, pread);
 }
 
 
@@ -1790,7 +1373,7 @@ USED static Bool MakeContextCurrent(Display *dpy, GLXDrawable draw,
                if (oldGC->isDirect) {
                    if (oldGC->driContext.private) {
                        (*oldGC->driContext.destroyContext)
-                           (oldGC->driContext.private);
+                           (&oldGC->driContext);
                        XF86DRIDestroyContext(oldGC->createDpy,
                                              oldGC->psc->scr,
                                              gc->hwContextID);