Check for Wayland EGL platform extension

Change-Id: Ifd4188336dae04c7fc4b2b68b4ec4c898854e43e
Signed-off-by: Eugene Mutavchi <Ievgen_Mutavchi@comcast.com>
diff --git a/src/third_party/starboard/rdk/shared/system/system_egl.cc b/src/third_party/starboard/rdk/shared/system/system_egl.cc
index f73b2e1..4a0db03 100644
--- a/src/third_party/starboard/rdk/shared/system/system_egl.cc
+++ b/src/third_party/starboard/rdk/shared/system/system_egl.cc
@@ -51,6 +51,17 @@
 static PFNEGLCREATEPLATFORMPIXMAPSURFACEEXTPROC gEglCreatePlatformPixmapSurfaceEXT;
 static PFNEGLCREATEPLATFORMWINDOWSURFACEEXTPROC gEglCreatePlatformWindowSurfaceEXT;
 static PFNEGLGETPLATFORMDISPLAYEXTPROC gEglGetPlatformDisplayEXT;
+
+bool isExtensionSupported(const char* extension_list, const char* extension) {
+  int len = strlen(extension);
+  const char* ptr = extension_list;
+  while ((ptr = strstr(ptr, extension))) {
+    if (ptr[len] == ' ' || ptr[len] == '\0')
+      return true;
+    ptr += len;
+  }
+  return false;
+}
 #endif
 
 // Convenience functions that redirect to the intended function but "cast" the
@@ -174,22 +185,27 @@
 
 const SbEglInterface* SbGetEglInterface() {
 #ifdef EGL_PLATFORM_WAYLAND_EXT
-  gEglGetPlatformDisplayEXT = (PFNEGLGETPLATFORMDISPLAYEXTPROC)eglGetProcAddress("eglGetPlatformDisplayEXT");
-  gEglCreatePlatformPixmapSurfaceEXT = (PFNEGLCREATEPLATFORMPIXMAPSURFACEEXTPROC)eglGetProcAddress("eglCreatePlatformPixmapSurfaceEXT");
-  gEglCreatePlatformWindowSurfaceEXT = (PFNEGLCREATEPLATFORMWINDOWSURFACEEXTPROC)eglGetProcAddress("eglCreatePlatformWindowSurfaceEXT");
-  if (!gEglGetPlatformDisplayEXT || !gEglCreatePlatformPixmapSurfaceEXT || !gEglCreatePlatformWindowSurfaceEXT) {
-    if (!gEglGetPlatformDisplayEXT)
-      SB_LOG(INFO) << "eglGetPlatformDisplayEXT is not available";
-    if (!gEglCreatePlatformPixmapSurfaceEXT)
-      SB_LOG(INFO) << "eglCreatePlatformPixmapSurfaceEXT is not available";
-    if (!gEglCreatePlatformWindowSurfaceEXT)
-      SB_LOG(INFO) << "eglCreatePlatformWindowSurfaceEXT is not available";
-    gEglGetPlatformDisplayEXT = nullptr;
-    gEglCreatePlatformPixmapSurfaceEXT = nullptr;
-    gEglCreatePlatformWindowSurfaceEXT = nullptr;
-  }
-  else {
-    SB_LOG(INFO) << "Found EGL platform display extensions.";
+  const char* extensions = eglQueryString(EGL_NO_DISPLAY, EGL_EXTENSIONS);
+  if (!isExtensionSupported(extensions, "EGL_EXT_platform_wayland")) {
+    SB_LOG(INFO) << "Wayland EGL platform extension is not supported.";
+  } else {
+    SB_LOG(INFO) << "Wayland EGL platform extension is supported.";
+    gEglGetPlatformDisplayEXT = (PFNEGLGETPLATFORMDISPLAYEXTPROC)eglGetProcAddress("eglGetPlatformDisplayEXT");
+    gEglCreatePlatformPixmapSurfaceEXT = (PFNEGLCREATEPLATFORMPIXMAPSURFACEEXTPROC)eglGetProcAddress("eglCreatePlatformPixmapSurfaceEXT");
+    gEglCreatePlatformWindowSurfaceEXT = (PFNEGLCREATEPLATFORMWINDOWSURFACEEXTPROC)eglGetProcAddress("eglCreatePlatformWindowSurfaceEXT");
+    if (!gEglGetPlatformDisplayEXT || !gEglCreatePlatformPixmapSurfaceEXT || !gEglCreatePlatformWindowSurfaceEXT) {
+      if (!gEglGetPlatformDisplayEXT)
+        SB_LOG(INFO) << "eglGetPlatformDisplayEXT is not available";
+      if (!gEglCreatePlatformPixmapSurfaceEXT)
+        SB_LOG(INFO) << "eglCreatePlatformPixmapSurfaceEXT is not available";
+      if (!gEglCreatePlatformWindowSurfaceEXT)
+        SB_LOG(INFO) << "eglCreatePlatformWindowSurfaceEXT is not available";
+      gEglGetPlatformDisplayEXT = nullptr;
+      gEglCreatePlatformPixmapSurfaceEXT = nullptr;
+      gEglCreatePlatformWindowSurfaceEXT = nullptr;
+    } else {
+      SB_LOG(INFO) << "Successfully resolved all EGL platform extension functions.";
+    }
   }
 #endif
   return &g_sb_egl_interface;