Merge "override EGL_DEFAULT_DISPLAY for wayland"
diff --git a/src/starboard/contrib/tizen/shared/gyp_configuration.gypi b/src/starboard/contrib/tizen/shared/gyp_configuration.gypi
index 385c3d9..6e002ad 100644
--- a/src/starboard/contrib/tizen/shared/gyp_configuration.gypi
+++ b/src/starboard/contrib/tizen/shared/gyp_configuration.gypi
@@ -32,6 +32,9 @@
     'cobalt_enable_jit': 0,
 
     'linker_flags': [
+      # We don't wrap these symbols, but this ensures that they aren't
+      # linked in.
+      '-Wl,--wrap=eglGetDisplay',
     ],
     'linker_flags_gold': [
       '-O3',
diff --git a/src/starboard/shared/wayland/egl_workaround.cc b/src/starboard/shared/wayland/egl_workaround.cc
new file mode 100644
index 0000000..24bd097
--- /dev/null
+++ b/src/starboard/shared/wayland/egl_workaround.cc
@@ -0,0 +1,25 @@
+// Copyright 2018 Samsung Electronics. 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 "starboard/log.h"
+#include "cobalt/renderer/backend/egl/display.h"
+#include "starboard/shared/wayland/native_display_type.h"
+
+extern "C" EGLDisplay __real_eglGetDisplay(EGLNativeDisplayType native_display);
+extern "C" EGLDisplay __wrap_eglGetDisplay(EGLNativeDisplayType native_display);
+
+extern "C" EGLDisplay __wrap_eglGetDisplay(EGLNativeDisplayType native_display) {
+  SB_LOG(INFO) << " __wrap_eglGetDisplay ";
+  return __real_eglGetDisplay((EGLNativeDisplayType)WaylandNativeDisplayType());
+}
diff --git a/src/starboard/shared/wayland/native_display_type.cc b/src/starboard/shared/wayland/native_display_type.cc
new file mode 100644
index 0000000..03e118c
--- /dev/null
+++ b/src/starboard/shared/wayland/native_display_type.cc
@@ -0,0 +1,25 @@
+// Copyright 2018 Samsung 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 "starboard/shared/wayland/native_display_type.h"
+
+#include "starboard/log.h"
+#include "starboard/shared/wayland/application_wayland.h"
+
+NativeDisplayType WaylandNativeDisplayType()
+{
+  wl_display* display = starboard::shared::wayland::ApplicationWayland::Get()->GetWLDisplay();
+  SB_LOG(INFO) << " SbNativeDisplayType() " << display;
+  return (NativeDisplayType)display;
+}
diff --git a/src/starboard/shared/wayland/native_display_type.h b/src/starboard/shared/wayland/native_display_type.h
new file mode 100644
index 0000000..4eef08c
--- /dev/null
+++ b/src/starboard/shared/wayland/native_display_type.h
@@ -0,0 +1,27 @@
+// Copyright 2018 Samsung 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.
+
+#ifndef STARBOARD_SHARED_WAYLAND_NATIVE_DISPLAY_TYPE_H_
+#define STARBOARD_SHARED_WAYLAND_NATIVE_DISPLAY_TYPE_H_
+#include <EGL/egl.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+NativeDisplayType WaylandNativeDisplayType();
+
+#ifdef __cplusplus
+}
+#endif
+#endif //STARBOARD_SHARED_WAYLAND_NATIVE_DISPLAY_TYPE_H_