egl: move eglQueryContext() fallback to eglapi.c
[mesa.git] / src / egl / main / egldriver.c
index 92ea6450944ac73472bb8583e988f39c1de37c90..4dc46b35e9555f96d4917cb1b03fc1cb8d366544 100644 (file)
@@ -44,6 +44,8 @@
 #include "egldriver.h"
 #include "egllog.h"
 
+#include "util/debug.h"
+
 static mtx_t _eglModuleMutex = _MTX_INITIALIZER_NP;
 static _EGLDriver *_eglDriver;
 
@@ -56,6 +58,7 @@ _eglGetDriver(void)
       _eglDriver = calloc(1, sizeof(*_eglDriver));
       if (!_eglDriver)
          return NULL;
+      _eglInitDriverFallbacks(_eglDriver);
       _eglInitDriver(_eglDriver);
    }
 
@@ -65,44 +68,39 @@ _eglGetDriver(void)
 }
 
 static _EGLDriver *
-_eglMatchAndInitialize(_EGLDisplay *dpy)
+_eglMatchAndInitialize(_EGLDisplay *disp)
 {
    if (_eglGetDriver())
-      if (_eglDriver->API.Initialize(_eglDriver, dpy))
+      if (_eglDriver->API.Initialize(_eglDriver, disp))
          return _eglDriver;
 
    return NULL;
 }
 
 /**
- * Match a display to a driver.  The display is initialized unless test_only is
- * true.  The matching is done by finding the first driver that can initialize
- * the display.
+ * Match a display to a driver.  The matching is done by finding the first
+ * driver that can initialize the display.
  */
 _EGLDriver *
-_eglMatchDriver(_EGLDisplay *dpy, EGLBoolean test_only)
+_eglMatchDriver(_EGLDisplay *disp)
 {
    _EGLDriver *best_drv;
 
-   assert(!dpy->Initialized);
+   assert(!disp->Initialized);
 
    /* set options */
-   dpy->Options.TestOnly = test_only;
-   dpy->Options.UseFallback = EGL_FALSE;
+   disp->Options.ForceSoftware =
+      env_var_as_boolean("LIBGL_ALWAYS_SOFTWARE", false);
 
-   best_drv = _eglMatchAndInitialize(dpy);
-   if (!best_drv) {
-      dpy->Options.UseFallback = EGL_TRUE;
-      best_drv = _eglMatchAndInitialize(dpy);
+   best_drv = _eglMatchAndInitialize(disp);
+   if (!best_drv && !disp->Options.ForceSoftware) {
+      disp->Options.ForceSoftware = EGL_TRUE;
+      best_drv = _eglMatchAndInitialize(disp);
    }
 
    if (best_drv) {
-      _eglLog(_EGL_DEBUG, "the best driver is %s%s",
-            best_drv->Name, (test_only) ? " (test only) " : "");
-      if (!test_only) {
-         dpy->Driver = best_drv;
-         dpy->Initialized = EGL_TRUE;
-      }
+      disp->Driver = best_drv;
+      disp->Initialized = EGL_TRUE;
    }
 
    return best_drv;
@@ -111,7 +109,7 @@ _eglMatchDriver(_EGLDisplay *dpy, EGLBoolean test_only)
 __eglMustCastToProperFunctionPointerType
 _eglGetDriverProc(const char *procname)
 {
-   if (_eglGetDriver())
+   if (_eglGetDriver() && _eglDriver->API.GetProcAddress)
       return _eglDriver->API.GetProcAddress(_eglDriver, procname);
 
    return NULL;