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
This commit is contained in:
Martin Stransky 2019-11-07 14:28:55 +00:00
Родитель 0aab0b28d6
Коммит f677c03233
9 изменённых файлов: 43 добавлений и 37 удалений

Просмотреть файл

@ -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")) {
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<gfx::VsyncSource> gfxPlatformGtk::CreateHardwareVsyncSource() {
# ifdef MOZ_WAYLAND
if (!mIsX11Display) {
if (IsWaylandDisplay()) {
RefPtr<VsyncSource> vsyncSource = new GtkVsyncSource();
VsyncSource::Display& display = vsyncSource->GetGlobalDisplay();
static_cast<GtkVsyncSource::GLXDisplay&>(display).SetupWayland();
@ -776,7 +776,7 @@ already_AddRefed<gfx::VsyncSource> gfxPlatformGtk::CreateHardwareVsyncSource() {
#ifdef MOZ_WAYLAND
bool gfxPlatformGtk::UseWaylandDMABufSurfaces() {
if (mIsX11Display) {
if (!IsWaylandDisplay()) {
return false;
}
return widget::nsWaylandDisplay::IsDMABufEnabled();

Просмотреть файл

@ -105,6 +105,9 @@ class gfxPlatformGtk : public gfxPlatform {
#endif
bool IsX11Display() { return mIsX11Display; }
bool IsWaylandDisplay() {
return !mIsX11Display && !gfxPlatform::IsHeadless();
}
protected:
void InitPlatformGPUProcessPrefs() override;

Просмотреть файл

@ -10,6 +10,7 @@
#include <gdk/gdkx.h>
#ifdef MOZ_WAYLAND
# include "nsWaylandDisplay.h"
# include "gfxPlatformGtk.h"
# include <wayland-egl.h>
#endif
#include <stdio.h>
@ -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

Просмотреть файл

@ -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 {

Просмотреть файл

@ -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;

Просмотреть файл

@ -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(

Просмотреть файл

@ -31,7 +31,6 @@
#include <gdk/gdkprivate.h>
#include <gtk/gtk.h>
#include <gtk/gtkx.h>
#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();

Просмотреть файл

@ -33,6 +33,7 @@
#include <sys/stat.h>
#include <fcntl.h>
#include <gio/gunixfdlist.h>
#include "gfxPlatformGtk.h"
// for dlsym
#include <dlfcn.h>
@ -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;
}

Просмотреть файл

@ -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;
}