From f677c032337cd65eddad3abe112e305e1ea47b76 Mon Sep 17 00:00:00 2001 From: Martin Stransky Date: Thu, 7 Nov 2019 14:28:55 +0000 Subject: [PATCH] Bug 1589642 - Use gfxPlatformGtk instead of GDK_IS_X11_DISPLAY(gdk_display_get_default() to check current dispay type, r=jhorak Differential Revision: https://phabricator.services.mozilla.com/D49724 --HG-- extra : moz-landing-system : lando --- gfx/thebes/gfxPlatformGtk.cpp | 20 ++++++++++---------- gfx/thebes/gfxPlatformGtk.h | 3 +++ widget/gtk/mozcontainer.cpp | 9 +++++---- widget/gtk/nsClipboard.cpp | 7 ++----- widget/gtk/nsClipboardX11.cpp | 3 ++- widget/gtk/nsGtkKeyUtils.cpp | 14 ++++++++++---- widget/gtk/nsNativeThemeGTK.cpp | 5 ++--- widget/gtk/nsPrintDialogGTK.cpp | 5 +++-- widget/gtk/nsWindow.cpp | 14 ++++++-------- 9 files changed, 43 insertions(+), 37 deletions(-) diff --git a/gfx/thebes/gfxPlatformGtk.cpp b/gfx/thebes/gfxPlatformGtk.cpp index 6a41fc7401d1..808b319e8ed0 100644 --- a/gfx/thebes/gfxPlatformGtk.cpp +++ b/gfx/thebes/gfxPlatformGtk.cpp @@ -81,20 +81,20 @@ gfxPlatformGtk::gfxPlatformGtk() { } mMaxGenericSubstitutions = UNINITIALIZED_VALUE; - mIsX11Display = GDK_IS_X11_DISPLAY(gdk_display_get_default()); - + mIsX11Display = gfxPlatform::IsHeadless() + ? false + : GDK_IS_X11_DISPLAY(gdk_display_get_default()); #ifdef MOZ_X11 - if (!gfxPlatform::IsHeadless() && XRE_IsParentProcess()) { - if (mIsX11Display && mozilla::Preferences::GetBool("gfx.xrender.enabled")) { - gfxVars::SetUseXRender(true); - } + if (mIsX11Display && XRE_IsParentProcess() && + mozilla::Preferences::GetBool("gfx.xrender.enabled")) { + gfxVars::SetUseXRender(true); } #endif InitBackendPrefs(GetBackendPrefs()); #ifdef MOZ_X11 - if (gfxPlatform::IsHeadless() && mIsX11Display) { + if (mIsX11Display) { mCompositorDisplay = XOpenDisplay(nullptr); MOZ_ASSERT(mCompositorDisplay, "Failed to create compositor display!"); } else { @@ -132,7 +132,7 @@ void gfxPlatformGtk::FlushContentDrawing() { void gfxPlatformGtk::InitPlatformGPUProcessPrefs() { #ifdef MOZ_WAYLAND - if (!mIsX11Display) { + if (IsWaylandDisplay()) { FeatureState& gpuProc = gfxConfig::GetFeature(Feature::GPU_PROCESS); gpuProc.ForceDisable(FeatureStatus::Blocked, "Wayland does not work in the GPU process", @@ -745,7 +745,7 @@ class GtkVsyncSource final : public VsyncSource { already_AddRefed gfxPlatformGtk::CreateHardwareVsyncSource() { # ifdef MOZ_WAYLAND - if (!mIsX11Display) { + if (IsWaylandDisplay()) { RefPtr vsyncSource = new GtkVsyncSource(); VsyncSource::Display& display = vsyncSource->GetGlobalDisplay(); static_cast(display).SetupWayland(); @@ -776,7 +776,7 @@ already_AddRefed gfxPlatformGtk::CreateHardwareVsyncSource() { #ifdef MOZ_WAYLAND bool gfxPlatformGtk::UseWaylandDMABufSurfaces() { - if (mIsX11Display) { + if (!IsWaylandDisplay()) { return false; } return widget::nsWaylandDisplay::IsDMABufEnabled(); diff --git a/gfx/thebes/gfxPlatformGtk.h b/gfx/thebes/gfxPlatformGtk.h index f51e64e9c903..f197c5e9fe1f 100644 --- a/gfx/thebes/gfxPlatformGtk.h +++ b/gfx/thebes/gfxPlatformGtk.h @@ -105,6 +105,9 @@ class gfxPlatformGtk : public gfxPlatform { #endif bool IsX11Display() { return mIsX11Display; } + bool IsWaylandDisplay() { + return !mIsX11Display && !gfxPlatform::IsHeadless(); + } protected: void InitPlatformGPUProcessPrefs() override; diff --git a/widget/gtk/mozcontainer.cpp b/widget/gtk/mozcontainer.cpp index 6aab85f4288e..396c325565a2 100644 --- a/widget/gtk/mozcontainer.cpp +++ b/widget/gtk/mozcontainer.cpp @@ -10,6 +10,7 @@ #include #ifdef MOZ_WAYLAND # include "nsWaylandDisplay.h" +# include "gfxPlatformGtk.h" # include #endif #include @@ -169,7 +170,7 @@ void moz_container_class_init(MozContainerClass* klass) { widget_class->map = moz_container_map; #if defined(MOZ_WAYLAND) - if (!GDK_IS_X11_DISPLAY(gdk_display_get_default())) { + if (gfxPlatformGtk::GetPlatform()->IsWaylandDisplay()) { widget_class->map_event = moz_container_map_wayland; } #endif @@ -194,7 +195,7 @@ void moz_container_init(MozContainer* container) { container->frame_callback_handler = nullptr; container->frame_callback_handler_surface_id = -1; // We can draw to x11 window any time. - container->ready_to_draw = GDK_IS_X11_DISPLAY(gdk_display_get_default()); + container->ready_to_draw = gfxPlatformGtk::GetPlatform()->IsX11Display(); container->surface_needs_clear = true; container->inital_draw_cb = nullptr; container->subsurface_dx = 0; @@ -336,7 +337,7 @@ void moz_container_map(GtkWidget* widget) { if (gtk_widget_get_has_window(widget)) { gdk_window_show(gtk_widget_get_window(widget)); #if defined(MOZ_WAYLAND) - if (!GDK_IS_X11_DISPLAY(gdk_display_get_default())) { + if (gfxPlatformGtk::GetPlatform()->IsWaylandDisplay()) { moz_container_map_wayland(widget, nullptr); } #endif @@ -351,7 +352,7 @@ void moz_container_unmap(GtkWidget* widget) { if (gtk_widget_get_has_window(widget)) { gdk_window_hide(gtk_widget_get_window(widget)); #if defined(MOZ_WAYLAND) - if (!GDK_IS_X11_DISPLAY(gdk_display_get_default())) { + if (gfxPlatformGtk::GetPlatform()->IsWaylandDisplay()) { moz_container_unmap_wayland(MOZ_CONTAINER(widget)); } #endif diff --git a/widget/gtk/nsClipboard.cpp b/widget/gtk/nsClipboard.cpp index 566d6243e150..15c552d5b227 100644 --- a/widget/gtk/nsClipboard.cpp +++ b/widget/gtk/nsClipboard.cpp @@ -26,6 +26,7 @@ #include "mozilla/Services.h" #include "mozilla/RefPtr.h" #include "mozilla/TimeStamp.h" +#include "gfxPlatformGtk.h" #include "imgIContainer.h" @@ -90,11 +91,7 @@ nsClipboard::~nsClipboard() { NS_IMPL_ISUPPORTS(nsClipboard, nsIClipboard, nsIObserver) nsresult nsClipboard::Init(void) { - GdkDisplay* display = gdk_display_get_default(); - - // Create a nsRetrievalContext. If there's no default display - // create the X11 one as a fallback. - if (!display || GDK_IS_X11_DISPLAY(display)) { + if (gfxPlatformGtk::GetPlatform()->IsX11Display()) { mContext = new nsRetrievalContextX11(); #if defined(MOZ_WAYLAND) } else { diff --git a/widget/gtk/nsClipboardX11.cpp b/widget/gtk/nsClipboardX11.cpp index 0ed4e30b5497..3be9687f06d3 100644 --- a/widget/gtk/nsClipboardX11.cpp +++ b/widget/gtk/nsClipboardX11.cpp @@ -139,7 +139,8 @@ bool nsRetrievalContextX11::WaitForX11Content() { } GdkDisplay* gdkDisplay = gdk_display_get_default(); - if (GDK_IS_X11_DISPLAY(gdkDisplay)) { + // gdk_display_get_default() returns null on headless + if (gdkDisplay && GDK_IS_X11_DISPLAY(gdkDisplay)) { Display* xDisplay = GDK_DISPLAY_XDISPLAY(gdkDisplay); checkEventContext context; context.cbWidget = nullptr; diff --git a/widget/gtk/nsGtkKeyUtils.cpp b/widget/gtk/nsGtkKeyUtils.cpp index fcec0c105c88..6383cf2669ec 100644 --- a/widget/gtk/nsGtkKeyUtils.cpp +++ b/widget/gtk/nsGtkKeyUtils.cpp @@ -27,6 +27,7 @@ #include "nsPrintfCString.h" #include "nsServiceManagerUtils.h" #include "nsWindow.h" +#include "gfxPlatformGtk.h" #include "mozilla/ArrayUtils.h" #include "mozilla/MouseEvents.h" @@ -346,7 +347,9 @@ KeymapWrapper::KeymapWrapper() g_object_ref(mGdkKeymap); - if (GDK_IS_X11_DISPLAY(gdk_display_get_default())) InitXKBExtension(); + if (gfxPlatformGtk::GetPlatform()->IsX11Display()) { + InitXKBExtension(); + } Init(); } @@ -363,10 +366,13 @@ void KeymapWrapper::Init() { mModifierKeys.Clear(); memset(mModifierMasks, 0, sizeof(mModifierMasks)); - if (GDK_IS_X11_DISPLAY(gdk_display_get_default())) InitBySystemSettingsX11(); + if (gfxPlatformGtk::GetPlatform()->IsX11Display()) { + InitBySystemSettingsX11(); + } #ifdef MOZ_WAYLAND - else + else { InitBySystemSettingsWayland(); + } #endif gdk_window_add_filter(nullptr, FilterEvents, this); @@ -767,7 +773,7 @@ void KeymapWrapper::InitBySystemSettingsWayland() { KeymapWrapper::~KeymapWrapper() { gdk_window_remove_filter(nullptr, FilterEvents, this); - if (GDK_IS_X11_DISPLAY(gdk_display_get_default())) { + if (gfxPlatformGtk::GetPlatform()->IsX11Display()) { g_signal_handlers_disconnect_by_func(mGdkKeymap, FuncToGpointer(OnKeysChanged), this); g_signal_handlers_disconnect_by_func( diff --git a/widget/gtk/nsNativeThemeGTK.cpp b/widget/gtk/nsNativeThemeGTK.cpp index 583844d1d34b..03a9417cc84e 100644 --- a/widget/gtk/nsNativeThemeGTK.cpp +++ b/widget/gtk/nsNativeThemeGTK.cpp @@ -31,7 +31,6 @@ #include #include -#include #include "gfxContext.h" #include "gfxPlatformGtk.h" @@ -864,7 +863,7 @@ static void DrawThemeWithCairo(gfxContext* aContext, DrawTarget* aDrawTarget, const nsIntSize& aDrawSize, GdkRectangle& aGDKRect, nsITheme::Transparency aTransparency) { - bool isX11Display = GDK_IS_X11_DISPLAY(gdk_display_get_default()); + bool isX11Display = gfxPlatformGtk::GetPlatform()->IsX11Display(); static auto sCairoSurfaceSetDeviceScalePtr = (void (*)(cairo_surface_t*, double, double))dlsym( RTLD_DEFAULT, "cairo_surface_set_device_scale"); @@ -1202,7 +1201,7 @@ nsNativeThemeGTK::DrawWidgetBackground(gfxContext* aContext, nsIFrame* aFrame, if (!safeState) { // gdk_flush() call from expose event crashes Gtk+ on Wayland // (Gnome BZ #773307) - if (GDK_IS_X11_DISPLAY(gdk_display_get_default())) { + if (gfxPlatformGtk::GetPlatform()->IsX11Display()) { gdk_flush(); } gLastGdkError = gdk_error_trap_pop(); diff --git a/widget/gtk/nsPrintDialogGTK.cpp b/widget/gtk/nsPrintDialogGTK.cpp index a278ed29b1e1..55899fee549a 100644 --- a/widget/gtk/nsPrintDialogGTK.cpp +++ b/widget/gtk/nsPrintDialogGTK.cpp @@ -33,6 +33,7 @@ #include #include #include +#include "gfxPlatformGtk.h" // for dlsym #include @@ -532,7 +533,7 @@ static void wayland_window_handle_exported(GdkWindow* window, static gboolean window_export_handle(GtkWindow* window, GtkWindowHandleExported callback, gpointer user_data) { - if (GDK_IS_X11_DISPLAY(gtk_widget_get_display(GTK_WIDGET(window)))) { + if (gfxPlatformGtk::GetPlatform()->IsX11Display()) { GdkWindow* gdk_window = gtk_widget_get_window(GTK_WIDGET(window)); char* handle_str; guint32 xid = (guint32)gdk_x11_window_get_xid(gdk_window); @@ -687,7 +688,7 @@ void nsFlatpakPrintPortal::PreparePrint(GtkWindow* aWindow, // We need to remember GtkWindow to unexport window handle after it is // no longer needed by the portal dialog (apply only on non-X11 sessions). - if (!GDK_IS_X11_DISPLAY(gdk_display_get_default())) { + if (gfxPlatformGtk::GetPlatform()->IsWaylandDisplay()) { mParentWindow = aWindow; } diff --git a/widget/gtk/nsWindow.cpp b/widget/gtk/nsWindow.cpp index 870841388b5e..31bc0e895fa2 100644 --- a/widget/gtk/nsWindow.cpp +++ b/widget/gtk/nsWindow.cpp @@ -406,7 +406,7 @@ nsWindow::nsWindow() { mHandleTouchEvent = false; #endif mIsDragPopup = false; - mIsX11Display = GDK_IS_X11_DISPLAY(gdk_display_get_default()); + mIsX11Display = gfxPlatformGtk::GetPlatform()->IsX11Display(); mContainer = nullptr; mGdkWindow = nullptr; @@ -778,8 +778,7 @@ double nsWindow::GetDefaultScaleInternal() { DesktopToLayoutDeviceScale nsWindow::GetDesktopToDeviceScale() { #ifdef MOZ_WAYLAND - GdkDisplay* gdkDisplay = gdk_display_get_default(); - if (!GDK_IS_X11_DISPLAY(gdkDisplay)) { + if (!mIsX11Display) { return DesktopToLayoutDeviceScale(GdkScaleFactor()); } #endif @@ -790,14 +789,13 @@ DesktopToLayoutDeviceScale nsWindow::GetDesktopToDeviceScale() { DesktopToLayoutDeviceScale nsWindow::GetDesktopToDeviceScaleByScreen() { #ifdef MOZ_WAYLAND - GdkDisplay* gdkDisplay = gdk_display_get_default(); // In Wayland there's no way to get absolute position of the window and use it // to determine the screen factor of the monitor on which the window is // placed. The window is notified of the current scale factor but not at this // point, so the GdkScaleFactor can return wrong value which can lead to wrong // popup placement. We need to use parent's window scale factor for the new // one. - if (!GDK_IS_X11_DISPLAY(gdkDisplay)) { + if (!mIsX11Display) { nsView* view = nsView::GetViewFor(this); if (view) { nsView* parentView = view->GetParent(); @@ -1511,7 +1509,7 @@ static void SetUserTimeAndStartupIDForActivatedWindow(GtkWidget* aWindow) { #if defined(MOZ_ENABLE_STARTUP_NOTIFICATION) // TODO - Implement for non-X11 Gtk backends (Bug 726479) - if (GDK_IS_X11_DISPLAY(gdk_display_get_default())) { + if (gfxPlatformGtk::GetPlatform()->IsX11Display()) { GdkWindow* gdkWindow = gtk_widget_get_window(aWindow); GdkScreen* screen = gdk_window_get_screen(gdkWindow); @@ -1857,7 +1855,7 @@ void* nsWindow::GetNativeData(uint32_t aDataType) { case NS_NATIVE_DISPLAY: { #ifdef MOZ_X11 GdkDisplay* gdkDisplay = gdk_display_get_default(); - if (GDK_IS_X11_DISPLAY(gdkDisplay)) { + if (gdkDisplay && GDK_IS_X11_DISPLAY(gdkDisplay)) { return GDK_DISPLAY_XDISPLAY(gdkDisplay); } #endif /* MOZ_X11 */ @@ -7061,7 +7059,7 @@ nsWindow::CSDSupportLevel nsWindow::GetSystemCSDSupportLevel() { } // We use CSD titlebar mode on Wayland only - if (!GDK_IS_X11_DISPLAY(gdk_display_get_default())) { + if (gfxPlatformGtk::GetPlatform()->IsWaylandDisplay()) { sCSDSupportLevel = CSD_SUPPORT_CLIENT; return sCSDSupportLevel; }