Merge branch 'mesa_7_5_branch'
[mesa.git] / src / egl / drivers / dri / egldri.c
index 35b6d0d3d1006e086e2e960120d102f4184462e3..9e400be6248b805b0f445703a88953eb79cc3b00 100644 (file)
@@ -82,7 +82,7 @@ _EGLDriver *
 _eglMain(_EGLDisplay *dpy, const char *args)
 {
 #if 1
-   const int card = atoi(args);
+   const int card = args ? atoi(args) : 0;
    _EGLDriver *driver = NULL;
    char driverName[1000];
 
@@ -114,6 +114,10 @@ _eglMain(_EGLDisplay *dpy, const char *args)
       _eglLog(_EGL_WARNING, "%s DRM devices not found.", path);
       return EGL_FALSE;
    }
+
+   /* loop over dir entries looking for cardX where "X" is in the
+    * dpy->DriverName ":X" string.
+    */
    while ((dirent = readdir(dir))) {
 
       if (strncmp(&dirent->d_name[0], "card", 4) != 0)
@@ -167,7 +171,10 @@ _eglDRICreateContext(_EGLDriver *drv, EGLDisplay dpy, EGLConfig config,
    if (!c)
       return EGL_NO_CONTEXT;
 
-   if (!_eglInitContext(drv, dpy, &c->Base, config, attrib_list)) {
+   conf = _eglLookupConfig(drv, dpy, config);
+   assert(conf);
+
+   if (!_eglInitContext(drv, &c->Base, conf, attrib_list)) {
       free(c);
       return EGL_NO_CONTEXT;
    }
@@ -185,8 +192,6 @@ _eglDRICreateContext(_EGLDriver *drv, EGLDisplay dpy, EGLConfig config,
    else
       sharePriv = NULL;
 
-   conf = _eglLookupConfig(drv, dpy, config);
-   assert(conf);
    _eglConfigToContextModesRec(conf, &visMode);
 
    c->driContext.private = disp->driScreen.createNewContext(disp, &visMode,
@@ -196,8 +201,8 @@ _eglDRICreateContext(_EGLDriver *drv, EGLDisplay dpy, EGLConfig config,
       return EGL_FALSE;
    }
 
-   /* generate handle and insert into hash table */
-   _eglSaveContext(&c->Base);
+   /* link to display */
+   _eglLinkContext(&c->Base, &disp->Base);
 
    return _eglGetContextHandle(&c->Base);
 }
@@ -233,14 +238,18 @@ _eglDRICreatePbufferSurface(_EGLDriver *drv, EGLDisplay dpy, EGLConfig config,
                             const EGLint *attrib_list)
 {
    driSurface *surf;
+   _EGLConfig *conf;
+
+   conf = _eglLookupConfig(drv, dpy, config);
+   assert(conf);
 
    surf = (driSurface *) calloc(1, sizeof(*surf));
    if (!surf) {
       return EGL_NO_SURFACE;
    }
 
-   if (!_eglInitSurface(drv, dpy, &surf->Base, EGL_PBUFFER_BIT,
-                        config, attrib_list)) {
+   if (!_eglInitSurface(drv, &surf->Base, EGL_PBUFFER_BIT,
+                        conf, attrib_list)) {
       free(surf);
       return EGL_NO_SURFACE;
    }
@@ -271,7 +280,7 @@ _eglDRICreatePbufferSurface(_EGLDriver *drv, EGLDisplay dpy, EGLConfig config,
 #endif
    }
 
-   _eglSaveSurface(&surf->Base);
+   _eglLinkSurface(&surf->Base, _eglLookupDisplay(dpy));
 
    return surf->Base.Handle;
 }
@@ -283,16 +292,12 @@ _eglDRIDestroySurface(_EGLDriver *drv, EGLDisplay dpy, EGLSurface surface)
    driDisplay *disp = Lookup_driDisplay(dpy);
    driSurface *fs = Lookup_driSurface(surface);
 
-   _eglRemoveSurface(&fs->Base);
+   _eglUnlinkSurface(&fs->Base);
 
    fs->drawable.destroyDrawable(disp, fs->drawable.private);
 
-   if (fs->Base.IsBound) {
-      fs->Base.DeletePending = EGL_TRUE;
-   }
-   else {
+   if (!_eglIsSurfaceBound(&fs->Base))
       free(fs);
-   }
    return EGL_TRUE;
 }
 
@@ -303,16 +308,12 @@ _eglDRIDestroyContext(_EGLDriver *drv, EGLDisplay dpy, EGLContext context)
    driDisplay *disp = Lookup_driDisplay(dpy);
    driContext *fc = Lookup_driContext(context);
 
-   _eglRemoveContext(&fc->Base);
+   _eglUnlinkContext(&fc->Base);
 
    fc->driContext.destroyContext(disp, 0, fc->driContext.private);
 
-   if (fc->Base.IsBound) {
-      fc->Base.DeletePending = EGL_TRUE;
-   }
-   else {
+   if (!_eglIsContextBound(&fc->Base))
       free(fc);
-   }
    return EGL_TRUE;
 }
 
@@ -336,13 +337,13 @@ _eglDRICreateScreenSurfaceMESA(_EGLDriver *drv, EGLDisplay dpy, EGLConfig cfg,
    }
 
    /* init base class, do error checking, etc. */
-   if (!_eglInitSurface(drv, dpy, &surface->Base, EGL_SCREEN_BIT_MESA,
-                        cfg, attrib_list)) {
+   if (!_eglInitSurface(drv, &surface->Base, EGL_SCREEN_BIT_MESA,
+                        config, attrib_list)) {
       free(surface);
       return EGL_NO_SURFACE;
    }
 
-   _eglSaveSurface(&surface->Base);
+   _eglLinkSurface(&surface->Base &disp->Base);
 
 
    /*
@@ -359,7 +360,7 @@ _eglDRICreateScreenSurfaceMESA(_EGLDriver *drv, EGLDisplay dpy, EGLConfig cfg,
    if (!disp->driScreen.createNewDrawable(disp, &visMode, drawBuf,
                                           &surface->drawable, GLX_WINDOW_BIT,
                                           empty_attribute_list)) {
-      _eglRemoveSurface(&surface->Base);
+      _eglUnlinkSurface(&surface->Base);
       free(surface);
       return EGL_NO_SURFACE;
    }
@@ -1082,8 +1083,10 @@ _eglDRICreateDisplay(driDisplay *dpy, __DRIframebuffer *framebuffer)
                             api_ver,
                             & interface_methods,
                             NULL);
-   if (!dpy->driScreen.private)
+   if (!dpy->driScreen.private) {
+      _eglLog(_EGL_WARNING, "egldri.c: DRI create new screen failed");
       return EGL_FALSE;
+   }
 
    DRM_UNLOCK( dpy->drmFD, dpy->pSAREA, dpy->serverContext );