Bug 1460603 - GLLibraryEGL: Use wl_display to get EGLDisplay on Wayland r=lsalzman
authorMartin Stransky <stransky@redhat.com>
Wed, 09 May 2018 15:26:15 +0200
changeset 472708 28dd89824e9b748d428c877fc9bf88aaf4356fb2
parent 472707 cb2a199d50d1f79aafd93861ed7f6bc3f1f24eef
child 472709 cd876c420775f0d39eb531464979c68683c32168
push id9374
push userjlund@mozilla.com
push dateMon, 18 Jun 2018 21:43:20 +0000
treeherdermozilla-beta@160e085dfb0b [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerslsalzman
bugs1460603
milestone62.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1460603 - GLLibraryEGL: Use wl_display to get EGLDisplay on Wayland r=lsalzman Patch author is Takuro Ashie <ashie@clear-code.com> 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: ILtRJrW6MDs
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.
@@ -714,17 +721,32 @@ GLLibraryEGL::CreateDisplay(bool forceAc
                     *out_failureId = NS_LITERAL_CSTRING("FEATURE_FAILURE_WARP_FALLBACK");
                 }
                 NS_ERROR("Fallback WARP context failed to initialize.");
                 return nullptr;
             }
             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 nullptr;
+            }
+        }
+#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 nullptr;
@@ -883,9 +905,8 @@ AfterEGLCall(const char* glFunction)
 {
     if (ShouldTrace()) {
         printf_stderr("[egl] < %s\n", glFunction);
     }
 }
 
 } /* namespace gl */
 } /* namespace mozilla */
-