egl: Call loseCurrent after eglReleaseThread

Call the device specific eglReleaseThread before the the device
independent egl_display_t::loseCurrent.  loseCurrent will reset
the surface format in the destructor.  The device specific code
needs an opportunity to finish things up before surface state is
changed.

Change-Id: Icfc79eba440a6c03bd68aacc087402a8c785dd4a
diff --git a/opengl/libs/EGL/eglApi.cpp b/opengl/libs/EGL/eglApi.cpp
index 22990f3..09ac3fc 100644
--- a/opengl/libs/EGL/eglApi.cpp
+++ b/opengl/libs/EGL/eglApi.cpp
@@ -1304,13 +1304,14 @@
         GLTrace_eglReleaseThread();
 #endif
 
-    // If there is context bound to the thread, release it
-    egl_display_t::loseCurrent(get_context(getContext()));
-
     egl_connection_t* const cnx = &gEGLImpl;
     if (cnx->dso && cnx->egl.eglReleaseThread) {
         cnx->egl.eglReleaseThread();
     }
+
+    // If there is context bound to the thread, release it
+    egl_display_t::loseCurrent(get_context(getContext()));
+
     egl_tls_t::clearTLS();
     return EGL_TRUE;
 }