[Mesa-dev] [PATCH 14/15] Support loading multiple EGL platforms in a single process

Christopher James Halse Rogers christopher.halse.rogers at canonical.com
Sat Jul 20 04:40:46 PDT 2013


Change EGLModule to have an EGLDriver per supported platform and cache
based on EGLModule-platform pair rather than just EGLModule.
---
 src/egl/main/egldisplay.c |  3 +--
 src/egl/main/egldriver.c  | 55 +++++++++++++++++++++++++++--------------------
 2 files changed, 33 insertions(+), 25 deletions(-)

diff --git a/src/egl/main/egldisplay.c b/src/egl/main/egldisplay.c
index 985e781..482a956 100644
--- a/src/egl/main/egldisplay.c
+++ b/src/egl/main/egldisplay.c
@@ -60,7 +60,6 @@
 #include <sys/stat.h>
 #endif
 
-
 /**
  * Map --with-egl-platforms names to platform types.
  */
@@ -188,7 +187,7 @@ _eglNativePlatformDetectNativeDisplay(EGLNativeDisplayType nativeDisplay)
 _EGLPlatformType
 _eglGetNativePlatform(EGLNativeDisplayType nativeDisplay)
 {
-   static _EGLPlatformType native_platform = _EGL_INVALID_PLATFORM;
+   _EGLPlatformType native_platform = _EGL_INVALID_PLATFORM;
    char *detection_method = NULL;
 
    if (native_platform == _EGL_INVALID_PLATFORM) {
diff --git a/src/egl/main/egldriver.c b/src/egl/main/egldriver.c
index ffdd146..e4c9859 100644
--- a/src/egl/main/egldriver.c
+++ b/src/egl/main/egldriver.c
@@ -57,7 +57,7 @@ typedef struct _egl_module {
    char *Path;
    _EGLMain_t BuiltIn;
    void *Handle;
-   _EGLDriver *Driver;
+   _EGLDriver *Driver[_EGL_NUM_PLATFORMS];
 } _EGLModule;
 
 static _EGL_DECLARE_MUTEX(_eglModuleMutex);
@@ -134,7 +134,6 @@ library_suffix(void)
 
 #endif
 
-
 /**
  * Open the named driver and find its bootstrap function: _eglMain().
  */
@@ -147,8 +146,12 @@ _eglOpenLibrary(const char *driverPath, lib_handle *handle)
 
    assert(driverPath);
 
-   _eglLog(_EGL_DEBUG, "dlopen(%s)", driverPath);
-   lib = open_library(driverPath);
+   if (*handle) {
+      lib = *handle;
+   } else {
+      _eglLog(_EGL_DEBUG, "dlopen(%s)", driverPath);
+      lib = open_library(driverPath);
+   }
 
 #if defined(_EGL_OS_WINDOWS)
    /* XXX untested */
@@ -194,13 +197,13 @@ _eglOpenLibrary(const char *driverPath, lib_handle *handle)
  * Load a module and create the driver object.
  */
 static EGLBoolean
-_eglLoadModule(_EGLModule *mod)
+_eglLoadModule(_EGLModule *mod, _EGLPlatformType plat)
 {
    _EGLMain_t mainFunc;
-   lib_handle lib;
+   lib_handle lib = (lib_handle) mod->Handle;
    _EGLDriver *drv;
 
-   if (mod->Driver)
+   if (mod->Driver[plat])
       return EGL_TRUE;
 
    if (mod->BuiltIn) {
@@ -226,7 +229,7 @@ _eglLoadModule(_EGLModule *mod)
    }
 
    mod->Handle = (void *) lib;
-   mod->Driver = drv;
+   mod->Driver[plat] = drv;
 
    return EGL_TRUE;
 }
@@ -240,8 +243,10 @@ _eglUnloadModule(_EGLModule *mod)
 {
 #if defined(_EGL_OS_UNIX)
    /* destroy the driver */
-   if (mod->Driver && mod->Driver->Unload)
-      mod->Driver->Unload(mod->Driver);
+   for (int plat = 0; plat < _EGL_NUM_PLATFORMS; ++plat) {
+      if (mod->Driver[plat] && mod->Driver[plat]->Unload)
+         mod->Driver[plat]->Unload(mod->Driver[plat]);
+   }
 
    /*
     * XXX At this point (atexit), the module might be the last reference to
@@ -255,7 +260,9 @@ _eglUnloadModule(_EGLModule *mod)
    /* XXX Windows unloads DLLs before atexit */
 #endif
 
-   mod->Driver = NULL;
+   for (int plat = 0; plat < _EGL_NUM_PLATFORMS; ++plat) {
+      mod->Driver[plat] = NULL;
+   }
    mod->Handle = NULL;
 }
 
@@ -599,17 +606,17 @@ _eglMatchAndInitialize(_EGLDisplay *dpy)
    while (i < _eglModules->Size) {
       _EGLModule *mod = (_EGLModule *) _eglModules->Elements[i];
 
-      if (!_eglLoadModule(mod)) {
+      if (!_eglLoadModule(mod, dpy->Platform)) {
          /* remove invalid modules */
          _eglEraseArray(_eglModules, i, _eglFreeModule);
          continue;
       }
 
-      if (mod->Driver->API.Initialize(mod->Driver, dpy)) {
-         drv = mod->Driver;
+      drv = mod->Driver[dpy->Platform];
+      if (drv->API.Initialize(drv, dpy))
          break;
-      }
       else {
+         drv = NULL;
          i++;
       }
    }
@@ -661,7 +668,6 @@ __eglMustCastToProperFunctionPointerType
 _eglGetDriverProc(const char *procname)
 {
    EGLint i;
-   _EGLProc proc = NULL;
 
    if (!_eglModules) {
       /* load the driver for the default display */
@@ -673,15 +679,18 @@ _eglGetDriverProc(const char *procname)
 
    for (i = 0; i < _eglModules->Size; i++) {
       _EGLModule *mod = (_EGLModule *) _eglModules->Elements[i];
-
-      if (!mod->Driver)
-         break;
-      proc = mod->Driver->API.GetProcAddress(mod->Driver, procname);
-      if (proc)
-         break;
+      _EGLProc proc;
+
+      for (_EGLPlatformType plat = 0; plat < _EGL_NUM_PLATFORMS; ++plat) {
+         if (!mod->Driver[plat])
+            continue;
+         proc = mod->Driver[plat]->API.GetProcAddress(mod->Driver[plat], procname);
+         if (proc)
+            return proc;
+      }
    }
 
-   return proc;
+   return NULL;
 }
 
 
-- 
1.8.3.2



More information about the mesa-dev mailing list