[Mesa-dev] [PATCH mesa 5/6] egl: move alloc & init out of _eglBuiltInDriver{DRI2, Haiku}

Eric Engestrom eric at engestrom.ch
Tue Sep 26 22:47:20 UTC 2017


Note: dropping the EGL_BAD_ALLOC in egl_haiku because it's
overwritten by the EGL_NOT_INITIALIZED in eglInitialize().

Signed-off-by: Eric Engestrom <eric at engestrom.ch>
---
 src/egl/drivers/dri2/egl_dri2.c     | 13 ++-----------
 src/egl/drivers/haiku/egl_haiku.cpp | 13 ++-----------
 src/egl/main/README.txt             |  9 ++++-----
 src/egl/main/egldriver.c            |  8 ++++++--
 src/egl/main/egldriver.h            | 10 +++++-----
 5 files changed, 19 insertions(+), 34 deletions(-)

diff --git a/src/egl/drivers/dri2/egl_dri2.c b/src/egl/drivers/dri2/egl_dri2.c
index a2c0d98319..feac606273 100644
--- a/src/egl/drivers/dri2/egl_dri2.c
+++ b/src/egl/drivers/dri2/egl_dri2.c
@@ -3172,16 +3172,9 @@ dri2_interop_export_object(_EGLDisplay *dpy, _EGLContext *ctx,
  * This is the main entrypoint into the driver, called by libEGL.
  * Create a new _EGLDriver object and init its dispatch table.
  */
-_EGLDriver *
-_eglBuiltInDriverDRI2(const char *args)
+void
+_eglBuiltInDriverDRI2(_EGLDriver *dri2_drv)
 {
-   _EGLDriver *dri2_drv = calloc(1, sizeof *dri2_drv);
-   if (!dri2_drv)
-      return NULL;
-
-   (void) args;
-
-   _eglInitDriverFallbacks(dri2_drv);
    dri2_drv->API.Initialize = dri2_initialize;
    dri2_drv->API.Terminate = dri2_terminate;
    dri2_drv->API.CreateContext = dri2_create_context;
@@ -3232,6 +3225,4 @@ _eglBuiltInDriverDRI2(const char *args)
    dri2_drv->API.DupNativeFenceFDANDROID = dri2_dup_native_fence_fd;
 
    dri2_drv->Name = "DRI2";
-
-   return dri2_drv;
 }
diff --git a/src/egl/drivers/haiku/egl_haiku.cpp b/src/egl/drivers/haiku/egl_haiku.cpp
index fea38e76ed..d65d579295 100644
--- a/src/egl/drivers/haiku/egl_haiku.cpp
+++ b/src/egl/drivers/haiku/egl_haiku.cpp
@@ -308,18 +308,11 @@ haiku_swap_buffers(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSurface *surf)
  * Create a new _EGLDriver object and init its dispatch table.
  */
 extern "C"
-_EGLDriver*
-_eglBuiltInDriverHaiku(const char *args)
+void
+_eglBuiltInDriverHaiku(_EGLDriver *driver)
 {
 	CALLED();
 
-	_EGLDriver* driver = calloc(1, sizeof(*driver));
-	if (!driver) {
-		_eglError(EGL_BAD_ALLOC, "_eglBuiltInDriverHaiku");
-		return NULL;
-	}
-
-	_eglInitDriverFallbacks(driver);
 	driver->API.Initialize = init_haiku;
 	driver->API.Terminate = haiku_terminate;
 	driver->API.CreateContext = haiku_create_context;
@@ -335,6 +328,4 @@ _eglBuiltInDriverHaiku(const char *args)
 	driver->Name = "Haiku";
 
 	TRACE("API Calls defined\n");
-
-	return driver;
 }
diff --git a/src/egl/main/README.txt b/src/egl/main/README.txt
index 1af9959972..9b5fd41061 100644
--- a/src/egl/main/README.txt
+++ b/src/egl/main/README.txt
@@ -19,13 +19,12 @@ Bootstrapping:
 When the apps calls eglInitialize() a device driver is selected and loaded
 (look for _eglAddDrivers() and _eglLoadModule() in egldriver.c).
 
-The built-in driver's entry point function is then called.  This driver function
-allocates, initializes and returns a new _EGLDriver object (usually a
-subclass of that type).
+The built-in driver's entry point function is then called and given
+a freshly allocated and initialised _EGLDriver, with default fallback
+entrypoints set.
 
 As part of initialization, the dispatch table in _EGLDriver->API must be
-populated with all the EGL entrypoints.  Typically, _eglInitDriverFallbacks()
-can be used to plug in default/fallback functions.  Some functions like
+populated with all the EGL entrypoints. Some functions like
 driver->API.Initialize and driver->API.Terminate _must_ be implemented
 with driver-specific code (no default/fallback function is possible).
 
diff --git a/src/egl/main/egldriver.c b/src/egl/main/egldriver.c
index 70b9e782e2..69e079283d 100644
--- a/src/egl/main/egldriver.c
+++ b/src/egl/main/egldriver.c
@@ -79,9 +79,13 @@ _eglLoadModule(_EGLModule *mod)
    if (!mod->BuiltIn)
          return EGL_FALSE;
 
-   drv = mod->BuiltIn(NULL);
-   if (!drv || !drv->Name)
+   drv = calloc(1, sizeof(*drv));
+   if (!drv) {
       return EGL_FALSE;
+   }
+
+   _eglInitDriverFallbacks(drv);
+   mod->BuiltIn(drv);
 
    mod->Driver = drv;
 
diff --git a/src/egl/main/egldriver.h b/src/egl/main/egldriver.h
index 3b13772210..5b80a75222 100644
--- a/src/egl/main/egldriver.h
+++ b/src/egl/main/egldriver.h
@@ -70,7 +70,7 @@ extern "C" {
    _EGL_DRIVER_TYPECAST(drvname ## _config, _EGLConfig, obj)
 
 
-typedef _EGLDriver *(*_EGLMain_t)(const char *args);
+typedef void (*_EGLMain_t)(_EGLDriver *drv);
 
 
 /**
@@ -84,12 +84,12 @@ struct _egl_driver
 };
 
 
-extern _EGLDriver *
-_eglBuiltInDriverDRI2(const char *args);
+extern void
+_eglBuiltInDriverDRI2(_EGLDriver *driver);
 
 
-extern _EGLDriver*
-_eglBuiltInDriverHaiku(const char* args);
+extern void
+_eglBuiltInDriverHaiku(_EGLDriver *driver);
 
 
 extern _EGLDriver *
-- 
Cheers,
  Eric



More information about the mesa-dev mailing list