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

Eric Engestrom eric.engestrom at imgtec.com
Tue Nov 14 17:26:33 UTC 2017


From: Eric Engestrom <eric at engestrom.ch>

This is a revert of Marek's 84f3afc2e122cb418573 revert, with a missing
line added back. I failed a rebase and dropped that crucial line, and
didn't do a runtime test after my rebase, and as a result broke EGL for
everyone.
This commit has been tested by Intel's CI and I re-read it once more, so
it should be good this time.
--

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>
Reviewed-by: Emil Velikov <emil.velikov at collabora.com>
---
 src/egl/drivers/dri2/egl_dri2.c     | 13 +++----------
 src/egl/drivers/haiku/egl_haiku.cpp | 16 +++-------------
 src/egl/main/README.txt             |  9 ++++-----
 src/egl/main/egldriver.c            |  9 +++++++--
 src/egl/main/egldriver.h            |  4 ++--
 5 files changed, 19 insertions(+), 32 deletions(-)

diff --git a/src/egl/drivers/dri2/egl_dri2.c b/src/egl/drivers/dri2/egl_dri2.c
index 8861742c17fbc2fc7cfc..7c63920c54624e0e674e 100644
--- a/src/egl/drivers/dri2/egl_dri2.c
+++ b/src/egl/drivers/dri2/egl_dri2.c
@@ -3216,16 +3216,11 @@ 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.
+ * Gets an _EGLDriver object and init its dispatch table.
  */
-_EGLDriver *
-_eglBuiltInDriver(void)
+void
+_eglInitDriver(_EGLDriver *dri2_drv)
 {
-   _EGLDriver *dri2_drv = calloc(1, sizeof *dri2_drv);
-   if (!dri2_drv)
-      return NULL;
-
-   _eglInitDriverFallbacks(dri2_drv);
    dri2_drv->API.Initialize = dri2_initialize;
    dri2_drv->API.Terminate = dri2_terminate;
    dri2_drv->API.CreateContext = dri2_create_context;
@@ -3276,6 +3271,4 @@ _eglBuiltInDriver(void)
    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 287760661e5c4e3402f1..590e43f00fb96b051fb4 100644
--- a/src/egl/drivers/haiku/egl_haiku.cpp
+++ b/src/egl/drivers/haiku/egl_haiku.cpp
@@ -305,22 +305,14 @@ haiku_swap_buffers(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSurface *surf)
 
 /**
  * This is the main entrypoint into the driver, called by libEGL.
- * Create a new _EGLDriver object and init its dispatch table.
+ * Gets an _EGLDriver object and init its dispatch table.
  */
 extern "C"
-_EGLDriver*
-_eglBuiltInDriver(void)
+void
+_eglInitDriver(_EGLDriver *driver)
 {
 	CALLED();
 
-	_EGLDriver* driver;
-	driver = (_EGLDriver*) 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;
@@ -336,6 +328,4 @@ _eglBuiltInDriver(void)
 	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 1af995997291e301677c..9b5fd410618913f8bdcb 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 34a90ae5dc56c4543b4c..71bfca21ed8c6a666c14 100644
--- a/src/egl/main/egldriver.c
+++ b/src/egl/main/egldriver.c
@@ -54,8 +54,13 @@ _eglGetDriver(void)
 {
    mtx_lock(&_eglModuleMutex);
 
-   if (!_eglDriver)
-      _eglDriver = _eglBuiltInDriver();
+   if (!_eglDriver) {
+      _eglDriver = calloc(1, sizeof(*_eglDriver));
+      if (!_eglDriver)
+         return NULL;
+      _eglInitDriverFallbacks(_eglDriver);
+      _eglInitDriver(_eglDriver);
+   }
 
    mtx_unlock(&_eglModuleMutex);
 
diff --git a/src/egl/main/egldriver.h b/src/egl/main/egldriver.h
index 6ab667c4e699fdfa295f..ba12a060cab7f7c6c223 100644
--- a/src/egl/main/egldriver.h
+++ b/src/egl/main/egldriver.h
@@ -81,8 +81,8 @@ struct _egl_driver
 };
 
 
-extern _EGLDriver*
-_eglBuiltInDriver(void);
+extern void
+_eglInitDriver(_EGLDriver *driver);
 
 
 extern _EGLDriver *
-- 
Cheers,
  Eric



More information about the mesa-dev mailing list