#include "egldriver.h"
#include "egllog.h"
-static mtx_t _eglModuleMutex = _MTX_INITIALIZER_NP;
-static _EGLDriver *_eglDriver;
+#include "util/debug.h"
-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 display is initialized unless test_only is
- * true. 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, EGLBoolean test_only)
+bool
+_eglInitializeDisplay(_EGLDisplay *disp)
{
- _EGLDriver *best_drv;
-
- assert(!dpy->Initialized);
+ assert(!disp->Initialized);
/* set options */
- dpy->Options.TestOnly = test_only;
- dpy->Options.UseFallback = EGL_FALSE;
-
- best_drv = _eglMatchAndInitialize(dpy);
- if (!best_drv) {
- dpy->Options.UseFallback = EGL_TRUE;
- best_drv = _eglMatchAndInitialize(dpy);
+ 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");
+
+ if (_eglDriver.Initialize(disp)) {
+ disp->Driver = &_eglDriver;
+ disp->Initialized = EGL_TRUE;
+ return true;
}
- 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;
- }
- }
+ 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;
-}