Bug 1438144 - GLLibraryEGL: Use wl_display to get EGLDisplay on Wayland draft
authorTakuro Ashie <ashie@clear-code.com>
Wed, 28 Mar 2018 14:06:58 +0900
changeset 773593 d51e498eb9d39e864547cfdc3d996dc59ccf96d6
parent 773564 56d6db4ad38c869d0bbc2aea449a4a382f109163
child 773594 f3caa11e1d9a39bab620a025d1db79bd645d3a2a
push id104261
push userbmo:ashie@clear-code.com
push dateWed, 28 Mar 2018 05:26:44 +0000
bugs1438144
milestone61.0a1
Bug 1438144 - GLLibraryEGL: Use wl_display to get EGLDisplay on Wayland Because some drivers doesn't support EGL_DEFAULT_DISPLAY. For example Intel's driver causes crash without this patch. MozReview-Commit-ID: 10eVoZ7mXrU
gfx/gl/GLLibraryEGL.cpp
--- a/gfx/gl/GLLibraryEGL.cpp
+++ b/gfx/gl/GLLibraryEGL.cpp
@@ -26,16 +26,23 @@
 #endif
 #include "OGLShaderProgram.h"
 #include "prenv.h"
 #include "prsystem.h"
 #include "GLContext.h"
 #include "GLContextProvider.h"
 #include "gfxPrefs.h"
 #include "ScopedGLHelpers.h"
+#ifdef MOZ_WIDGET_GTK
+#include <gdk/gdk.h>
+#ifdef MOZ_WAYLAND
+#include <gdk/gdkwayland.h>
+#include <dlfcn.h>
+#endif // MOZ_WIDGET_GTK
+#endif // MOZ_WAYLAND
 
 namespace mozilla {
 namespace gl {
 
 StaticMutex GLLibraryEGL::sMutex;
 GLLibraryEGL sEGLLibrary;
 
 // should match the order of EGLExtensions, and be null-terminated.
@@ -565,17 +572,32 @@ GLLibraryEGL::EnsureInitialized(bool for
                     *out_failureId = NS_LITERAL_CSTRING("FEATURE_FAILURE_WARP_FALLBACK");
                 }
                 NS_ERROR("Fallback WARP context failed to initialize.");
                 return false;
             }
             mIsWARP = true;
         }
     } else {
-        chosenDisplay = GetAndInitDisplay(*this, EGL_DEFAULT_DISPLAY);
+        void *nativeDisplay = EGL_DEFAULT_DISPLAY;
+#ifdef MOZ_WAYLAND
+        // Some drivers doesn't support EGL_DEFAULT_DISPLAY
+        GdkDisplay *gdkDisplay = gdk_display_get_default();
+        if (GDK_IS_WAYLAND_DISPLAY(gdkDisplay)) {
+            static auto sGdkWaylandDisplayGetWlDisplay =
+                (wl_display *(*)(GdkDisplay *))
+                dlsym(RTLD_DEFAULT, "gdk_wayland_display_get_wl_display");
+            nativeDisplay = sGdkWaylandDisplayGetWlDisplay(gdkDisplay);
+            if (!nativeDisplay) {
+              NS_WARNING("Failed to get wl_display.");
+              return false;
+            }
+        }
+#endif
+        chosenDisplay = GetAndInitDisplay(*this, nativeDisplay);
     }
 
     if (!chosenDisplay) {
         if (out_failureId->IsEmpty()) {
             *out_failureId = NS_LITERAL_CSTRING("FEATURE_FAILURE_NO_DISPLAY");
         }
         NS_WARNING("Failed to initialize a display.");
         return false;