free EGL resources associated to a thread when it terminates

destroyed but current-to-a-thread resources are only destroyed
when they're made not-current; however, we were not destroying
those when the thread itself terminated, causing these resources
to be leaked forever.

we now install a tls-key destructor that takes care of this
by calling eglReleaseThread upon thread termination.

Bug: 9209776
Change-Id: I88298a34e3a27488eb81eab76717715569c7d57c
diff --git a/opengl/libs/EGL/eglApi.cpp b/opengl/libs/EGL/eglApi.cpp
index 74d3973..334e164 100644
--- a/opengl/libs/EGL/eglApi.cpp
+++ b/opengl/libs/EGL/eglApi.cpp
@@ -1177,6 +1177,11 @@
 {
     clearError();
 
+#if EGL_TRACE
+    if (getEGLDebugLevel() > 0)
+        GLTrace_eglReleaseThread();
+#endif
+
     // If there is context bound to the thread, release it
     egl_display_t::loseCurrent(get_context(getContext()));
 
@@ -1184,12 +1189,7 @@
     if (cnx->dso && cnx->egl.eglReleaseThread) {
         cnx->egl.eglReleaseThread();
     }
-
     egl_tls_t::clearTLS();
-#if EGL_TRACE
-    if (getEGLDebugLevel() > 0)
-        GLTrace_eglReleaseThread();
-#endif
     return EGL_TRUE;
 }