From 0c3f64ce5974f81365bd512e867d4ed6c0bb8828 Mon Sep 17 00:00:00 2001 From: stransky Date: Mon, 19 Jul 2021 07:14:17 +0000 Subject: [PATCH] Bug 1717451 [Wayland] Pause compositor only on accelerated backends, r=sotaro Differential Revision: https://phabricator.services.mozilla.com/D119963 --- widget/gtk/nsWindow.cpp | 62 ++++++++++++++++++++--------------------- widget/gtk/nsWindow.h | 1 + 2 files changed, 32 insertions(+), 31 deletions(-) diff --git a/widget/gtk/nsWindow.cpp b/widget/gtk/nsWindow.cpp index 92e47a9c03da..29cf6482b37f 100644 --- a/widget/gtk/nsWindow.cpp +++ b/widget/gtk/nsWindow.cpp @@ -431,6 +431,7 @@ nsWindow::nsWindow() mWindowScaleFactorChanged(true), mWindowScaleFactor(1), mCompositedScreen(gdk_screen_is_composited(gdk_screen_get_default())), + mIsAccelerated(false), mShell(nullptr), mContainer(nullptr), mGdkWindow(nullptr), @@ -5209,9 +5210,9 @@ nsresult nsWindow::Create(nsIWidget* aParent, nsNativeWidget aNativeParent, } bool isGLVisualSet = false; - bool isAccelerated = ComputeShouldAccelerate(); + mIsAccelerated = ComputeShouldAccelerate(); #ifdef MOZ_X11 - if (isAccelerated) { + if (mIsAccelerated) { isGLVisualSet = ConfigureX11GLVisual(popupNeedsAlphaVisual || toplevelNeedsAlphaVisual); } @@ -5368,7 +5369,7 @@ nsresult nsWindow::Create(nsIWidget* aParent, nsNativeWidget aNativeParent, GtkWidget* container = moz_container_new(); mContainer = MOZ_CONTAINER(container); #ifdef MOZ_WAYLAND - if (GdkIsWaylandDisplay() && isAccelerated) { + if (GdkIsWaylandDisplay() && mIsAccelerated) { mCompositorInitiallyPaused = true; RefPtr self(this); moz_container_wayland_add_initial_draw_callback( @@ -5436,7 +5437,7 @@ nsresult nsWindow::Create(nsIWidget* aParent, nsNativeWidget aNativeParent, // the drawing window mGdkWindow = gtk_widget_get_window(eventWidget); - if (GdkIsX11Display() && gfx::gfxVars::UseEGL() && isAccelerated) { + if (GdkIsX11Display() && gfx::gfxVars::UseEGL() && mIsAccelerated) { mCompositorInitiallyPaused = true; mNeedsCompositorResume = true; MaybeResumeCompositor(); @@ -5892,37 +5893,36 @@ void nsWindow::MaybeResumeCompositor() { } void nsWindow::PauseCompositor() { - if (!mIsDestroyed) { - if (mContainer) { - // Because wl_egl_window is destroyed on moz_container_unmap(), - // the current compositor cannot use it anymore. To avoid crash, - // pause the compositor and destroy EGLSurface & resume the compositor - // and re-create EGLSurface on next expose event. + // Because wl_egl_window is destroyed on moz_container_unmap(), + // the current compositor cannot use it anymore. To avoid crash, + // pause the compositor and destroy EGLSurface & resume the compositor + // and re-create EGLSurface on next expose event. - // moz_container_wayland_has_egl_window() could not be used here, since - // there is a case that resume compositor is not completed yet. + // moz_container_wayland_has_egl_window() could not be used here, since + // there is a case that resume compositor is not completed yet. + if (!mIsAccelerated || mIsDestroyed) { + return; + } - CompositorBridgeChild* remoteRenderer = GetRemoteRenderer(); - bool needsCompositorPause = !mNeedsCompositorResume && !!remoteRenderer && - mCompositorWidgetDelegate; - if (needsCompositorPause) { - // XXX slow sync IPC - remoteRenderer->SendPause(); + CompositorBridgeChild* remoteRenderer = GetRemoteRenderer(); + bool needsCompositorPause = + !mNeedsCompositorResume && !!remoteRenderer && mCompositorWidgetDelegate; + if (needsCompositorPause) { + // XXX slow sync IPC + remoteRenderer->SendPause(); #ifdef MOZ_WAYLAND - if (GdkIsWaylandDisplay()) { - // Re-request initial draw callback - RefPtr self(this); - moz_container_wayland_add_initial_draw_callback( - mContainer, [self]() -> void { - self->mNeedsCompositorResume = true; - self->MaybeResumeCompositor(); - }); - } -#endif - } else { - DestroyLayerManager(); - } + if (GdkIsWaylandDisplay()) { + // Re-request initial draw callback + RefPtr self(this); + moz_container_wayland_add_initial_draw_callback( + mContainer, [self]() -> void { + self->mNeedsCompositorResume = true; + self->MaybeResumeCompositor(); + }); } +#endif + } else { + DestroyLayerManager(); } } diff --git a/widget/gtk/nsWindow.h b/widget/gtk/nsWindow.h index 5d7cbfdb1e35..ff81f870b4f2 100644 --- a/widget/gtk/nsWindow.h +++ b/widget/gtk/nsWindow.h @@ -450,6 +450,7 @@ class nsWindow final : public nsBaseWidget { bool mWindowScaleFactorChanged; int mWindowScaleFactor; bool mCompositedScreen; + bool mIsAccelerated; private: void UpdateAlpha(mozilla::gfx::SourceSurface* aSourceSurface,