Determine EGL version

Want to indicate that egl is version 1.5 if the underlying driver
supports 1.5 or 1.4 and necessary extensions.

Test: cts-tradefed run commandAndExit cts -m CtsDeqpTestCases --module-arg 'CtsDeqpTestCases:include-filter:dEQP-EGL.*'

Bug: 80297325
Change-Id: I6eec551caa4572a4fdce43cb35c6888aeae89c79
(cherry picked from commit 4416a7015f08492fbe6aaad7d22685dc32410bd1)
diff --git a/opengl/libs/EGL/egl_display.cpp b/opengl/libs/EGL/egl_display.cpp
index d452a6c..893cf0b 100644
--- a/opengl/libs/EGL/egl_display.cpp
+++ b/opengl/libs/EGL/egl_display.cpp
@@ -46,7 +46,8 @@
 // ----------------------------------------------------------------------------
 
 static char const * const sVendorString     = "Android";
-static char const * const sVersionString    = "1.4 Android META-EGL";
+static char const* const sVersionString14 = "1.4 Android META-EGL";
+static char const* const sVersionString15 = "1.5 Android META-EGL";
 static char const * const sClientApiString  = "OpenGL_ES";
 
 extern char const * const gBuiltinExtensionString;
@@ -358,7 +359,52 @@
 
         // the query strings are per-display
         mVendorString = sVendorString;
-        mVersionString = sVersionString;
+        mVersionString.clear();
+        cnx->driverVersion = EGL_MAKE_VERSION(1, 4, 0);
+        if ((cnx->major == 1) && (cnx->minor == 5)) {
+            mVersionString = sVersionString15;
+            cnx->driverVersion = EGL_MAKE_VERSION(1, 5, 0);
+        } else if ((cnx->major == 1) && (cnx->minor == 4)) {
+            mVersionString = sVersionString14;
+            // Extensions needed for an EGL 1.4 implementation to be
+            // able to support EGL 1.5 functionality
+            std::vector<const char*> egl15extensions = {
+                    "EGL_EXT_client_extensions",
+                    // "EGL_EXT_platform_base",  // implemented by EGL runtime
+                    "EGL_KHR_image_base",
+                    "EGL_KHR_fence_sync",
+                    "EGL_KHR_wait_sync",
+                    "EGL_KHR_create_context",
+                    "EGL_EXT_create_context_robustness",
+                    "EGL_KHR_gl_colorspace",
+                    "EGL_ANDROID_native_fence_sync",
+            };
+            bool extensionsFound = true;
+            for (const auto& name : egl15extensions) {
+                extensionsFound &= findExtension(disp.queryString.extensions, name);
+                ALOGV("Extension %s: %s", name,
+                      findExtension(disp.queryString.extensions, name) ? "Found" : "Missing");
+            }
+            // NOTE: From the spec:
+            // Creation of fence sync objects requires support from the bound
+            // client API, and will not succeed unless the client API satisfies:
+            // client API is OpenGL ES, and either the OpenGL ES version is 3.0
+            // or greater, or the GL_OES_EGL_sync extension is supported.
+            // We don't have a way to check the GL_EXTENSIONS string at this
+            // point in the code, assume that GL_OES_EGL_sync is supported
+            // because EGL_KHR_fence_sync is supported (as verified above).
+            if (extensionsFound) {
+                // Have everything needed to emulate EGL 1.5 so report EGL 1.5
+                // to the application.
+                mVersionString = sVersionString15;
+                cnx->major = 1;
+                cnx->minor = 5;
+            }
+        }
+        if (mVersionString.empty()) {
+            ALOGW("Unexpected driver version: %d.%d, want 1.4 or 1.5", cnx->major, cnx->minor);
+            mVersionString = sVersionString14;
+        }
         mClientApiString = sClientApiString;
 
         mExtensionString = gBuiltinExtensionString;