From ac09812abf83b7f46f63a191e62b07c725084ecb Mon Sep 17 00:00:00 2001
From: Joel Winarske <joel.winarske@toyotaconnected.com>
Date: Tue, 24 Oct 2023 14:42:57 -0700
Subject: [PATCH 1/4] EGL compatibility

-For compatibility acquire the egl display using eglGetDisplay().

Signed-off-by: Joel Winarske <joel.winarske@toyotaconnected.com>
---
 shell/backend/egl.cc             | 27 ++-------------------------
 shell/backend/egl.h              | 16 +---------------
 shell/backend/wayland_egl.cc     |  2 +-
 shell/view/compositor_surface.cc |  3 +--
 4 files changed, 5 insertions(+), 43 deletions(-)

diff --git a/shell/backend/egl.cc b/shell/backend/egl.cc
index 055f2ee..af1d785 100644
--- a/shell/backend/egl.cc
+++ b/shell/backend/egl.cc
@@ -25,8 +25,8 @@
 #include "gl_process_resolver.h"
 #include "logging.h"
 
-Egl::Egl(void* native_display, EGLenum platform, int buffer_size, bool debug)
-    : m_dpy(get_egl_display(platform, native_display, nullptr)),
+Egl::Egl(void* native_display, int buffer_size, bool debug)
+    : m_dpy(eglGetDisplay((EGLNativeDisplayType)native_display)),
       m_buffer_size(buffer_size) {
   assert(m_dpy);
 
@@ -777,29 +777,6 @@ void Egl::EGL_KHR_debug_init(
   SPDLOG_TRACE("-EGL_KHR_debug_init");
 }
 
-EGLDisplay Egl::get_egl_display(EGLenum platform,
-                                void* native_display,
-                                const EGLint* attrib_list) {
-  static PFNEGLGETPLATFORMDISPLAYEXTPROC get_platform_display = nullptr;
-  static EGLDisplay dpy = nullptr;
-
-  if (dpy != nullptr)
-    return dpy;
-
-  if (!get_platform_display) {
-    get_platform_display = reinterpret_cast<PFNEGLGETPLATFORMDISPLAYEXTPROC>(
-        eglGetProcAddress("eglGetPlatformDisplayEXT"));
-  }
-
-  if (get_platform_display) {
-    dpy = get_platform_display(platform, native_display, attrib_list);
-    return dpy;
-  }
-
-  dpy = eglGetDisplay((EGLNativeDisplayType)native_display);
-  return dpy;
-}
-
 EGLSurface Egl::create_egl_surface(void* native_window,
                                    const EGLint* attrib_list) {
   static PFNEGLCREATEPLATFORMWINDOWSURFACEEXTPROC create_platform_window =
diff --git a/shell/backend/egl.h b/shell/backend/egl.h
index 2ebcd2e..7c7cc21 100644
--- a/shell/backend/egl.h
+++ b/shell/backend/egl.h
@@ -28,7 +28,7 @@
 
 class Egl {
  public:
-  Egl(void* native_display, EGLenum platform, int buffer_size, bool debug);
+  Egl(void* native_display, int buffer_size, bool debug);
 
   ~Egl();
 
@@ -84,20 +84,6 @@ class Egl {
    */
   bool MakeTextureCurrent();
 
-  /**
-   * @brief Get an EGL display connection
-   * @param[in] platform Platform
-   * @param[in] native_display The native display
-   * @param[in] attrib_list Display attributes
-   * @return EGLDisplay
-   * @retval An EGL display connection
-   * @relation
-   * wayland
-   */
-  static EGLDisplay get_egl_display(EGLenum platform,
-                                    void* native_display,
-                                    const EGLint* attrib_list);
-
   /**
    * @brief Create a new EGL window surface
    * @param[in] native_window The native window
diff --git a/shell/backend/wayland_egl.cc b/shell/backend/wayland_egl.cc
index cc28b02..b6c5fa4 100644
--- a/shell/backend/wayland_egl.cc
+++ b/shell/backend/wayland_egl.cc
@@ -29,7 +29,7 @@ WaylandEglBackend::WaylandEglBackend(struct wl_display* display,
                                      uint32_t initial_height,
                                      bool debug_backend,
                                      int buffer_size)
-    : Egl(display, EGL_PLATFORM_WAYLAND_KHR, buffer_size, debug_backend),
+    : Egl(display, buffer_size, debug_backend),
       Backend(this, Resize, CreateSurface),
       m_initial_width(initial_width),
       m_initial_height(initial_height) {}
diff --git a/shell/view/compositor_surface.cc b/shell/view/compositor_surface.cc
index 85ae470..0f30704 100644
--- a/shell/view/compositor_surface.cc
+++ b/shell/view/compositor_surface.cc
@@ -57,8 +57,7 @@ CompositorSurface::CompositorSurface(
   auto parent_surface = window->GetBaseSurface();
 
   if (m_type == CompositorSurface::egl) {
-    m_wl.egl_display = eglGetPlatformDisplay(EGL_PLATFORM_WAYLAND_KHR,
-                                             display->GetDisplay(), nullptr);
+    m_wl.egl_display = eglGetDisplay((NativeDisplayType)display->GetDisplay());
     m_wl.egl_window = wl_egl_window_create(m_wl.surface, width, height);
     assert(m_wl.egl_display);
     assert(m_wl.egl_window);
-- 
2.41.0

