EGL: Conditionally revert commit a9550f3

This conditionally reverts a commit [1]
which causes random camera crashes on tama devices

[1] https://github.com/LineageOS/android_frameworks_native/commit/a9550f3fe9097e0934e9b44c5aac6b914fb46aec

Change-Id: If3d9c722c63a9da2f9ca10e21de9d7bc6dba7c52
diff --git a/opengl/libs/Android.bp b/opengl/libs/Android.bp
index 8141639..09e3290 100644
--- a/opengl/libs/Android.bp
+++ b/opengl/libs/Android.bp
@@ -138,6 +138,7 @@
     name: "libEGL",
     defaults: [
         "egl_libs_defaults",
+        "egl_display_array_defaults",
         "nvidia_enhancements_defaults"
     ],
     llndk: {
diff --git a/opengl/libs/EGL/egl_display.cpp b/opengl/libs/EGL/egl_display.cpp
index 0b755aa..7eeb57d 100644
--- a/opengl/libs/EGL/egl_display.cpp
+++ b/opengl/libs/EGL/egl_display.cpp
@@ -74,8 +74,12 @@
     return eglDisplay ? eglDisplay->getRefsCount() : 0;
 }
 
+#ifdef EGL_DISPLAY_ARRAY
+egl_display_t egl_display_t::sDisplay[NUM_DISPLAYS];
+#else
 std::map<EGLDisplay, std::unique_ptr<egl_display_t>> egl_display_t::displayMap;
 std::mutex egl_display_t::displayMapLock;
+#endif
 
 egl_display_t::egl_display_t()
       : magic('_dpy'),
@@ -94,12 +98,21 @@
         return nullptr;
     }
 
+#ifdef EGL_DISPLAY_ARRAY
+    uintptr_t index = uintptr_t(dpy) - 1U;
+    if (index >= NUM_DISPLAYS || !sDisplay[index].isValid()) {
+#else
     const std::lock_guard<std::mutex> lock(displayMapLock);
     auto search = displayMap.find(dpy);
     if (search == displayMap.end() || !search->second->isValid()) {
+#endif
         return nullptr;
     }
+#ifdef EGL_DISPLAY_ARRAY
+    return &sDisplay[index];
+#else
     return search->second.get();
+#endif
 }
 
 void egl_display_t::addObject(egl_object_t* object) {
@@ -127,7 +140,11 @@
                                                const EGLAttrib* attrib_list) {
     if (uintptr_t(disp) >= NUM_DISPLAYS) return nullptr;
 
+#ifdef EGL_DISPLAY_ARRAY
+    return sDisplay[uintptr_t(disp)].getPlatformDisplay(disp, attrib_list);
+#else
     return getPlatformDisplay(disp, attrib_list);
+#endif
 }
 
 static EGLDisplay getPlatformDisplayAngle(EGLNativeDisplayType display, egl_connection_t* const cnx,
@@ -182,6 +199,9 @@
 
 EGLDisplay egl_display_t::getPlatformDisplay(EGLNativeDisplayType display,
                                              const EGLAttrib* attrib_list) {
+#ifdef EGL_DISPLAY_ARRAY
+    std::lock_guard<std::mutex> _l(lock);
+#endif
     ATRACE_CALL();
 
     // get our driver loader
@@ -217,9 +237,14 @@
             }
         }
 
+#ifdef EGL_DISPLAY_ARRAY
+        disp.dpy = dpy;
+#endif
         if (dpy == EGL_NO_DISPLAY) {
             loader.close(cnx);
-        } else {
+        }
+#ifndef EGL_DISPLAY_ARRAY
+        else {
             const std::lock_guard<std::mutex> lock(displayMapLock);
             if (displayMap.find(dpy) == displayMap.end()) {
                 auto d = std::make_unique<egl_display_t>();
@@ -228,9 +253,14 @@
             }
             return dpy;
         }
+#endif
     }
 
+#ifdef EGL_DISPLAY_ARRAY
+    return EGLDisplay(uintptr_t(display) + 1U);
+#else
     return nullptr;
+#endif
 }
 
 EGLBoolean egl_display_t::initialize(EGLint* major, EGLint* minor) {
diff --git a/opengl/libs/EGL/egl_display.h b/opengl/libs/EGL/egl_display.h
index 87c2176..4438826 100644
--- a/opengl/libs/EGL/egl_display.h
+++ b/opengl/libs/EGL/egl_display.h
@@ -23,8 +23,10 @@
 #include <stdint.h>
 
 #include <condition_variable>
+#ifndef EGL_DISPLAY_ARRAY
 #include <map>
 #include <memory>
+#endif
 #include <mutex>
 #include <string>
 #include <unordered_set>
@@ -42,11 +44,19 @@
 bool needsAndroidPEglMitigation();
 
 class EGLAPI egl_display_t { // marked as EGLAPI for testing purposes
+#ifdef EGL_DISPLAY_ARRAY
+    static egl_display_t sDisplay[NUM_DISPLAYS];
+#else
     static std::map<EGLDisplay, std::unique_ptr<egl_display_t>> displayMap;
     static std::mutex displayMapLock;
+#endif
     EGLDisplay getDisplay(EGLNativeDisplayType display);
+#ifdef EGL_DISPLAY_ARRAY
+    EGLDisplay getPlatformDisplay(EGLNativeDisplayType display, const EGLAttrib* attrib_list);
+#else
     static EGLDisplay getPlatformDisplay(EGLNativeDisplayType display,
                                          const EGLAttrib* attrib_list);
+#endif
     void loseCurrentImpl(egl_context_t* cur_c);
 
 public: