egl: drop unused _EGLDriver from GetProcAddress()
[mesa.git] / src / egl / main / egldriver.c
index ee3dc86e388512c291b0ccce27483fb71e66740c..987b4b333ea3b2abfa60c38105a49991bb757e61 100644 (file)
 
 #include "util/debug.h"
 
-static mtx_t _eglModuleMutex = _MTX_INITIALIZER_NP;
-static _EGLDriver *_eglDriver;
-
-static _EGLDriver *
-_eglGetDriver(void)
-{
-   mtx_lock(&_eglModuleMutex);
-
-   if (!_eglDriver)
-      _eglDriver = _eglBuiltInDriver();
-
-   mtx_unlock(&_eglModuleMutex);
-
-   return _eglDriver;
-}
-
-static _EGLDriver *
-_eglMatchAndInitialize(_EGLDisplay *dpy)
-{
-   if (_eglGetDriver())
-      if (_eglDriver->API.Initialize(_eglDriver, dpy))
-         return _eglDriver;
-
-   return NULL;
-}
+extern const _EGLDriver _eglDriver;
 
 /**
- * Match a display to a driver.  The matching is done by finding the first
- * driver that can initialize the display.
+ * Initialize the display using the driver's function.
+ * If the initialisation fails, try again using only software rendering.
  */
-_EGLDriver *
-_eglMatchDriver(_EGLDisplay *dpy)
+bool
+_eglInitializeDisplay(_EGLDisplay *disp)
 {
-   _EGLDriver *best_drv;
-
-   assert(!dpy->Initialized);
+   assert(!disp->Initialized);
 
    /* set options */
-   dpy->Options.ForceSoftware =
+   disp->Options.ForceSoftware =
       env_var_as_boolean("LIBGL_ALWAYS_SOFTWARE", false);
+   if (disp->Options.ForceSoftware)
+      _eglLog(_EGL_DEBUG, "Found 'LIBGL_ALWAYS_SOFTWARE' set, will use a CPU renderer");
 
-   best_drv = _eglMatchAndInitialize(dpy);
-   if (!best_drv) {
-      dpy->Options.ForceSoftware = EGL_TRUE;
-      best_drv = _eglMatchAndInitialize(dpy);
+   if (_eglDriver.Initialize(disp)) {
+      disp->Driver = &_eglDriver;
+      disp->Initialized = EGL_TRUE;
+      return true;
    }
 
-   if (best_drv) {
-      _eglLog(_EGL_DEBUG, "the best driver is %s",
-            best_drv->Name);
-      dpy->Driver = best_drv;
-      dpy->Initialized = EGL_TRUE;
-   }
+   if (disp->Options.ForceSoftware)
+      return false;
 
-   return best_drv;
+   disp->Options.ForceSoftware = EGL_TRUE;
+   if (!_eglDriver.Initialize(disp))
+      return false;
+
+   disp->Driver = &_eglDriver;
+   disp->Initialized = EGL_TRUE;
+   return true;
 }
 
 __eglMustCastToProperFunctionPointerType
 _eglGetDriverProc(const char *procname)
 {
-   if (_eglGetDriver())
-      return _eglDriver->API.GetProcAddress(_eglDriver, procname);
+   if (_eglDriver.GetProcAddress)
+      return _eglDriver.GetProcAddress(procname);
 
    return NULL;
 }
-
-/**
- * Unload all drivers.
- */
-void
-_eglUnloadDrivers(void)
-{
-   /* this is called at atexit time */
-   free(_eglDriver);
-   _eglDriver = NULL;
-}