[CI20] Fix EGL initialization issue

CI20 with 1.14 SGX libraries has issue with EGL initialization.
This change adds workaround by overriding eglGetDisplay() and
eglTerminate() to call XOpenDisplay() and XCloseDisplay().

Change-Id: If3341720e7ee8596438881a9c22f3012835a3c38
diff --git a/src/starboard/contrib/creator/ci20x11/egl_workaround.cc b/src/starboard/contrib/creator/ci20x11/egl_workaround.cc
new file mode 100644
index 0000000..bc350e8
--- /dev/null
+++ b/src/starboard/contrib/creator/ci20x11/egl_workaround.cc
@@ -0,0 +1,35 @@
+// Copyright 2018 Google Inc. All Rights Reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//     http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+#include "cobalt/renderer/backend/egl/display.h"
+
+extern "C" EGLDisplay __real_eglGetDisplay(EGLNativeDisplayType native_display);
+extern "C" EGLDisplay __wrap_eglGetDisplay(EGLNativeDisplayType native_display);
+
+extern "C" EGLBoolean __real_eglTerminate(EGLDisplay display);
+extern "C" EGLBoolean __wrap_eglTerminate(EGLDisplay display);
+
+NativeDisplayType native_display_;
+
+extern "C" EGLDisplay __wrap_eglGetDisplay(EGLNativeDisplayType native_display) {
+  native_display_ = XOpenDisplay(0);
+  return __real_eglGetDisplay((EGLNativeDisplayType) native_display_);
+}
+
+extern "C" EGLBoolean __wrap_eglTerminate(EGLDisplay display) {
+  EGLBoolean result = __real_eglTerminate(display);
+  XCloseDisplay((NativeDisplayType) native_display_);
+  return result;
+}
+
diff --git a/src/starboard/contrib/creator/ci20x11/starboard_platform.gypi b/src/starboard/contrib/creator/ci20x11/starboard_platform.gypi
index a58b89e..ab38135 100644
--- a/src/starboard/contrib/creator/ci20x11/starboard_platform.gypi
+++ b/src/starboard/contrib/creator/ci20x11/starboard_platform.gypi
@@ -19,6 +19,7 @@
       '<(DEPTH)/starboard/contrib/creator/ci20x11/atomic_public.h',
       '<(DEPTH)/starboard/contrib/creator/ci20x11/configuration_public.h',
       '<(DEPTH)/starboard/contrib/creator/ci20x11/main.cc',
+      '<(DEPTH)/starboard/contrib/creator/ci20x11/egl_workaround.cc',
       '<(DEPTH)/starboard/contrib/creator/ci20x11/system_get_property.cc',
       '<(DEPTH)/starboard/shared/starboard/link_receiver.cc',
       '<(DEPTH)/starboard/shared/x11/application_x11.cc',
diff --git a/src/starboard/contrib/creator/shared/gyp_configuration.gypi b/src/starboard/contrib/creator/shared/gyp_configuration.gypi
index fd1b5cb..aa25e94 100644
--- a/src/starboard/contrib/creator/shared/gyp_configuration.gypi
+++ b/src/starboard/contrib/creator/shared/gyp_configuration.gypi
@@ -56,6 +56,8 @@
       '-Wl,--wrap=malloc_usable_size',
       '-Wl,--wrap=malloc_stats_fast',
       '-Wl,--wrap=__cxa_demangle',
+      '-Wl,--wrap=eglGetDisplay',
+      '-Wl,--wrap=eglTerminate',
     ],
   },