Merge "opengl: fix a race condition when unloading gl driver" am: e380e5d82f am: b9a4f9efdd
am: 31397a6eee

Change-Id: I10d3c6feb63dc5a515ec8f5eadb3ca54d6d63e95
diff --git a/opengl/libs/EGL/eglApi.cpp b/opengl/libs/EGL/eglApi.cpp
index 29a966d..c51a129 100644
--- a/opengl/libs/EGL/eglApi.cpp
+++ b/opengl/libs/EGL/eglApi.cpp
@@ -40,7 +40,6 @@
 
 EGLDisplay eglGetDisplay(EGLNativeDisplayType display) {
     ATRACE_CALL();
-    clearError();
 
     if (egl_init_drivers() == EGL_FALSE) {
         return setError(EGL_BAD_PARAMETER, EGL_NO_DISPLAY);
@@ -48,6 +47,7 @@
 
     // Call down the chain, which usually points directly to the impl
     // but may also be routed through layers
+    clearError();
     egl_connection_t* const cnx = &gEGLImpl;
     return cnx->platform.eglGetDisplay(display);
 }
@@ -55,7 +55,6 @@
 EGLDisplay eglGetPlatformDisplay(EGLenum platform, EGLNativeDisplayType display,
                                  const EGLAttrib* attrib_list) {
     ATRACE_CALL();
-    clearError();
 
     if (egl_init_drivers() == EGL_FALSE) {
         return setError(EGL_BAD_PARAMETER, EGL_NO_DISPLAY);
@@ -63,6 +62,7 @@
 
     // Call down the chain, which usually points directly to the impl
     // but may also be routed through layers
+    clearError();
     egl_connection_t* const cnx = &gEGLImpl;
     return cnx->platform.eglGetPlatformDisplay(platform, display, attrib_list);
 }
@@ -239,13 +239,12 @@
     // in which case we must make sure we've initialized ourselves, this
     // happens the first time egl_get_display() is called.
 
-    clearError();
-
     if (egl_init_drivers() == EGL_FALSE) {
         setError(EGL_BAD_PARAMETER, NULL);
         return nullptr;
     }
 
+    clearError();
     egl_connection_t* const cnx = &gEGLImpl;
     return cnx->platform.eglGetProcAddress(procname);
 }
@@ -324,23 +323,21 @@
 }
 
 EGLBoolean eglBindAPI(EGLenum api) {
-    clearError();
-
     if (egl_init_drivers() == EGL_FALSE) {
         return setError(EGL_BAD_PARAMETER, (EGLBoolean)EGL_FALSE);
     }
 
+    clearError();
     egl_connection_t* const cnx = &gEGLImpl;
     return cnx->platform.eglBindAPI(api);
 }
 
 EGLenum eglQueryAPI(void) {
-    clearError();
-
     if (egl_init_drivers() == EGL_FALSE) {
         return setError(EGL_BAD_PARAMETER, (EGLBoolean)EGL_FALSE);
     }
 
+    clearError();
     egl_connection_t* const cnx = &gEGLImpl;
     return cnx->platform.eglQueryAPI();
 }
@@ -595,23 +592,21 @@
 }
 
 EGLuint64NV eglGetSystemTimeFrequencyNV() {
-    clearError();
-
     if (egl_init_drivers() == EGL_FALSE) {
         return setError(EGL_BAD_PARAMETER, (EGLuint64NV)EGL_FALSE);
     }
 
+    clearError();
     egl_connection_t* const cnx = &gEGLImpl;
     return cnx->platform.eglGetSystemTimeFrequencyNV();
 }
 
 EGLuint64NV eglGetSystemTimeNV() {
-    clearError();
-
     if (egl_init_drivers() == EGL_FALSE) {
         return setError(EGL_BAD_PARAMETER, (EGLuint64NV)EGL_FALSE);
     }
 
+    clearError();
     egl_connection_t* const cnx = &gEGLImpl;
     return cnx->platform.eglGetSystemTimeNV();
 }