Bug 1561883 - [Wayland] Provide WaylandDisplayGetWLDisplay() to directly get wl_display, r=jhorak
authorMartin Stransky <stransky@redhat.com>
Mon, 01 Jul 2019 06:38:32 +0000
changeset 540406 c078c5a5c8b9ed122e3a86ad3f805539aef82164
parent 540405 3280dc915c88a1876298cdedb28929a188b9d350
child 540407 89d9234f2264d2cf537d371b4c090e2e0d556aa7
push id11529
push userarchaeopteryx@coole-files.de
push dateThu, 04 Jul 2019 15:22:33 +0000
treeherdermozilla-beta@ebb510a784b8 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjhorak
bugs1561883
milestone69.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 1561883 - [Wayland] Provide WaylandDisplayGetWLDisplay() to directly get wl_display, r=jhorak Differential Revision: https://phabricator.services.mozilla.com/D36183
gfx/gl/GLLibraryEGL.cpp
gfx/gl/moz.build
widget/gtk/WindowSurfaceWayland.cpp
widget/gtk/nsGtkKeyUtils.cpp
widget/gtk/nsWaylandDisplay.cpp
widget/gtk/nsWaylandDisplay.h
--- a/gfx/gl/GLLibraryEGL.cpp
+++ b/gfx/gl/GLLibraryEGL.cpp
@@ -31,16 +31,17 @@
 #include "GLContext.h"
 #include "GLContextProvider.h"
 #include "ScopedGLHelpers.h"
 #ifdef MOZ_WIDGET_GTK
 #  include <gdk/gdk.h>
 #  ifdef MOZ_WAYLAND
 #    include <gdk/gdkwayland.h>
 #    include <dlfcn.h>
+#    include "mozilla/widget/nsWaylandDisplay.h"
 #  endif  // MOZ_WIDGET_GTK
 #endif    // MOZ_WAYLAND
 
 namespace mozilla {
 namespace gl {
 
 StaticMutex GLLibraryEGL::sMutex;
 StaticRefPtr<GLLibraryEGL> GLLibraryEGL::sEGLLibrary;
@@ -782,20 +783,17 @@ EGLDisplay GLLibraryEGL::CreateDisplay(b
       mIsWARP = true;
     }
   } else {
     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_X11_DISPLAY(gdkDisplay)) {
-      static auto sGdkWaylandDisplayGetWlDisplay =
-          (wl_display * (*)(GdkDisplay*))
-              dlsym(RTLD_DEFAULT, "gdk_wayland_display_get_wl_display");
-      nativeDisplay = sGdkWaylandDisplayGetWlDisplay(gdkDisplay);
+      nativeDisplay = WaylandDisplayGetWLDisplay(gdkDisplay);
       if (!nativeDisplay) {
         NS_WARNING("Failed to get wl_display.");
         return nullptr;
       }
     }
 #endif
     chosenDisplay = GetAndInitDisplay(*this, nativeDisplay);
   }
--- a/gfx/gl/moz.build
+++ b/gfx/gl/moz.build
@@ -145,12 +145,16 @@ FINAL_LIBRARY = 'xul'
 if CONFIG['MOZ_D3DCOMPILER_VISTA_DLL']:
     DEFINES['MOZ_D3DCOMPILER_VISTA_DLL'] = CONFIG['MOZ_D3DCOMPILER_VISTA_DLL']
 
 CXXFLAGS += CONFIG['MOZ_CAIRO_CFLAGS']
 CXXFLAGS += CONFIG['TK_CFLAGS']
 CFLAGS += CONFIG['MOZ_CAIRO_CFLAGS']
 CFLAGS += CONFIG['TK_CFLAGS']
 
+if CONFIG['MOZ_WAYLAND']:
+    CXXFLAGS += CONFIG['MOZ_WAYLAND_CFLAGS']
+    CFLAGS += CONFIG['MOZ_WAYLAND_CFLAGS']
+
 LOCAL_INCLUDES += CONFIG['SKIA_INCLUDES']
 
 if CONFIG['CC_TYPE'] in ('clang', 'gcc'):
     CXXFLAGS += ['-Wno-error=shadow']
--- a/widget/gtk/WindowSurfaceWayland.cpp
+++ b/widget/gtk/WindowSurfaceWayland.cpp
@@ -372,17 +372,17 @@ void WindowBackBuffer::Attach(wl_surface
       ("%s [%p] wl_surface %p ID %d wl_buffer %p ID %d\n", __PRETTY_FUNCTION__,
        (void*)this, (void*)aSurface,
        aSurface ? wl_proxy_get_id((struct wl_proxy*)aSurface) : -1,
        (void*)GetWlBuffer(),
        GetWlBuffer() ? wl_proxy_get_id((struct wl_proxy*)GetWlBuffer()) : -1));
 
   wl_surface_attach(aSurface, GetWlBuffer(), 0, 0);
   wl_surface_commit(aSurface);
-  wl_display_flush(GetWaylandDisplay()->GetDisplay());
+  wl_display_flush(WaylandDisplayGetWLDisplay());
   SetAttached();
 }
 
 void WindowBackBufferShm::Detach(wl_buffer* aBuffer) {
   LOGWAYLAND(("%s [%p] wl_buffer %p ID %d\n", __PRETTY_FUNCTION__, (void*)this,
               (void*)aBuffer,
               aBuffer ? wl_proxy_get_id((struct wl_proxy*)aBuffer) : -1));
 
--- a/widget/gtk/nsGtkKeyUtils.cpp
+++ b/widget/gtk/nsGtkKeyUtils.cpp
@@ -30,16 +30,17 @@
 
 #include "mozilla/ArrayUtils.h"
 #include "mozilla/MouseEvents.h"
 #include "mozilla/TextEventDispatcher.h"
 #include "mozilla/TextEvents.h"
 
 #ifdef MOZ_WAYLAND
 #  include <sys/mman.h>
+#  include "nsWaylandDisplay.h"
 #endif
 
 namespace mozilla {
 namespace widget {
 
 LazyLogModule gKeymapWrapperLog("KeymapWrapperWidgets");
 
 #define IS_ASCII_ALPHABETICAL(key) \
@@ -753,21 +754,17 @@ static void gdk_registry_handle_global(v
 static void gdk_registry_handle_global_remove(void* data,
                                               struct wl_registry* registry,
                                               uint32_t id) {}
 
 static const struct wl_registry_listener keyboard_registry_listener = {
     gdk_registry_handle_global, gdk_registry_handle_global_remove};
 
 void KeymapWrapper::InitBySystemSettingsWayland() {
-  // Available as of GTK 3.8+
-  static auto sGdkWaylandDisplayGetWlDisplay = (wl_display * (*)(GdkDisplay*))
-      dlsym(RTLD_DEFAULT, "gdk_wayland_display_get_wl_display");
-  wl_display* display =
-      sGdkWaylandDisplayGetWlDisplay(gdk_display_get_default());
+  wl_display* display = WaylandDisplayGetWLDisplay();
   wl_registry_add_listener(wl_display_get_registry(display),
                            &keyboard_registry_listener, this);
 }
 #endif
 
 KeymapWrapper::~KeymapWrapper() {
   gdk_window_remove_filter(nullptr, FilterEvents, this);
   if (GDK_IS_X11_DISPLAY(gdk_display_get_default())) {
--- a/widget/gtk/nsWaylandDisplay.cpp
+++ b/widget/gtk/nsWaylandDisplay.cpp
@@ -11,16 +11,27 @@ namespace mozilla {
 namespace widget {
 
 #define GBMLIB_NAME "libgbm.so.1"
 #define DRMLIB_NAME "libdrm.so.2"
 
 bool nsWaylandDisplay::mIsDMABufEnabled;
 bool nsWaylandDisplay::mIsDMABufPrefLoaded;
 
+wl_display* WaylandDisplayGetWLDisplay(GdkDisplay* aGdkDisplay) {
+  if (!aGdkDisplay) {
+    aGdkDisplay = gdk_display_get_default();
+  }
+
+  // Available as of GTK 3.8+
+  static auto sGdkWaylandDisplayGetWlDisplay = (wl_display * (*)(GdkDisplay*))
+      dlsym(RTLD_DEFAULT, "gdk_wayland_display_get_wl_display");
+  return sGdkWaylandDisplayGetWlDisplay(aGdkDisplay);
+}
+
 // nsWaylandDisplay needs to be created for each calling thread(main thread,
 // compositor thread and render thread)
 #define MAX_DISPLAY_CONNECTIONS 3
 
 static nsWaylandDisplay* gWaylandDisplays[MAX_DISPLAY_CONNECTIONS];
 static StaticMutex gWaylandDisplaysMutex;
 
 void WaylandDisplayShutdown() {
@@ -58,20 +69,17 @@ void WaylandDispatchDisplays() {
           "WaylandDisplayDispatch", &DispatchDisplay, display));
     }
   }
 }
 
 // Get WaylandDisplay for given wl_display and actual calling thread.
 static nsWaylandDisplay* WaylandDisplayGetLocked(GdkDisplay* aGdkDisplay,
                                                  const StaticMutexAutoLock&) {
-  // Available as of GTK 3.8+
-  static auto sGdkWaylandDisplayGetWlDisplay = (wl_display * (*)(GdkDisplay*))
-      dlsym(RTLD_DEFAULT, "gdk_wayland_display_get_wl_display");
-  wl_display* waylandDisplay = sGdkWaylandDisplayGetWlDisplay(aGdkDisplay);
+  wl_display* waylandDisplay = WaylandDisplayGetWLDisplay(aGdkDisplay);
 
   // Search existing display connections for wl_display:thread combination.
   for (auto& display : gWaylandDisplays) {
     if (display && display->Matches(waylandDisplay)) {
       return display;
     }
   }
 
--- a/widget/gtk/nsWaylandDisplay.h
+++ b/widget/gtk/nsWaylandDisplay.h
@@ -96,16 +96,17 @@ class nsWaylandDisplay {
   bool mExplicitSync;
   static bool mIsDMABufEnabled;
   static bool mIsDMABufPrefLoaded;
 };
 
 void WaylandDispatchDisplays();
 void WaylandDisplayShutdown();
 nsWaylandDisplay* WaylandDisplayGet(GdkDisplay* aGdkDisplay = nullptr);
+wl_display* WaylandDisplayGetWLDisplay(GdkDisplay* aGdkDisplay = nullptr);
 
 typedef struct gbm_device* (*CreateDeviceFunc)(int);
 typedef struct gbm_bo* (*CreateFunc)(struct gbm_device*, uint32_t, uint32_t,
                                      uint32_t, uint32_t);
 typedef struct gbm_bo* (*CreateFunc)(struct gbm_device*, uint32_t, uint32_t,
                                      uint32_t, uint32_t);
 typedef struct gbm_bo* (*CreateWithModifiersFunc)(struct gbm_device*, uint32_t,
                                                   uint32_t, uint32_t,