From ce9e905fc311e1dcf930cd7377a54971a7f942af Mon Sep 17 00:00:00 2001 From: Brad Werth Date: Tue, 28 Feb 2023 23:16:56 +0000 Subject: [PATCH] Bug 1768495 Part 1: Add a method nsIWidget::PauseOrResumeCompositor, and override it in nsCocoaWindow. r=gfx-reviewers,emilio,ahale This change does not affect behavior, it's just prepatory for a later caller to the newly-defined method. Differential Revision: https://phabricator.services.mozilla.com/D169344 --- widget/cocoa/nsCocoaWindow.h | 3 +-- widget/cocoa/nsCocoaWindow.mm | 36 +++++++---------------------------- widget/nsBaseWidget.cpp | 12 ++++++++++++ widget/nsIWidget.h | 5 +++++ 4 files changed, 25 insertions(+), 31 deletions(-) diff --git a/widget/cocoa/nsCocoaWindow.h b/widget/cocoa/nsCocoaWindow.h index 77ce105b0298..0eaf2ed65e7e 100644 --- a/widget/cocoa/nsCocoaWindow.h +++ b/widget/cocoa/nsCocoaWindow.h @@ -354,8 +354,7 @@ class nsCocoaWindow final : public nsBaseWidget, public nsPIWidgetCocoa { bool InFullScreenMode() const { return mInFullScreenMode; } - void PauseCompositor(); - void ResumeCompositor(); + void PauseOrResumeCompositor(bool aPause) override; bool AsyncPanZoomEnabled() const override; diff --git a/widget/cocoa/nsCocoaWindow.mm b/widget/cocoa/nsCocoaWindow.mm index 71759af09b23..e76e683e9e29 100644 --- a/widget/cocoa/nsCocoaWindow.mm +++ b/widget/cocoa/nsCocoaWindow.mm @@ -2111,11 +2111,7 @@ void nsCocoaWindow::DispatchSizeModeEvent() { } if (StaticPrefs::widget_pause_compositor_when_minimized()) { - if (newMode == nsSizeMode_Minimized) { - PauseCompositor(); - } else { - ResumeCompositor(); - } + PauseOrResumeCompositor(newMode == nsSizeMode_Minimized); } } @@ -2155,30 +2151,6 @@ void nsCocoaWindow::ReportSizeEvent() { NS_OBJC_END_TRY_IGNORE_BLOCK; } -void nsCocoaWindow::PauseCompositor() { - nsIWidget* mainChildView = static_cast([[mWindow mainChildView] widget]); - if (!mainChildView) { - return; - } - CompositorBridgeChild* remoteRenderer = mainChildView->GetRemoteRenderer(); - if (!remoteRenderer) { - return; - } - remoteRenderer->SendPause(); -} - -void nsCocoaWindow::ResumeCompositor() { - nsIWidget* mainChildView = static_cast([[mWindow mainChildView] widget]); - if (!mainChildView) { - return; - } - CompositorBridgeChild* remoteRenderer = mainChildView->GetRemoteRenderer(); - if (!remoteRenderer) { - return; - } - remoteRenderer->SendResume(); -} - void nsCocoaWindow::SetMenuBar(RefPtr&& aMenuBar) { if (!mWindow) { mMenuBar = nullptr; @@ -2598,6 +2570,12 @@ bool nsCocoaWindow::GetEditCommands(NativeKeyBindingsType aType, const WidgetKey return true; } +void nsCocoaWindow::PauseOrResumeCompositor(bool aPause) { + if (auto* mainChildView = static_cast([[mWindow mainChildView] widget])) { + mainChildView->PauseOrResumeCompositor(aPause); + } +} + bool nsCocoaWindow::AsyncPanZoomEnabled() const { if (mPopupContentView) { return mPopupContentView->AsyncPanZoomEnabled(); diff --git a/widget/nsBaseWidget.cpp b/widget/nsBaseWidget.cpp index 668f16501e91..68c9df78978c 100644 --- a/widget/nsBaseWidget.cpp +++ b/widget/nsBaseWidget.cpp @@ -988,6 +988,18 @@ void nsBaseWidget::CreateCompositor() { CreateCompositor(rect.Width(), rect.Height()); } +void nsIWidget::PauseOrResumeCompositor(bool aPause) { + auto* renderer = GetRemoteRenderer(); + if (!renderer) { + return; + } + if (aPause) { + renderer->SendPause(); + } else { + renderer->SendResume(); + } +} + already_AddRefed nsBaseWidget::CreateRootContentController() { RefPtr controller = diff --git a/widget/nsIWidget.h b/widget/nsIWidget.h index 152fe7511074..e996f6fc1f59 100644 --- a/widget/nsIWidget.h +++ b/widget/nsIWidget.h @@ -1973,6 +1973,11 @@ class nsIWidget : public nsISupports { */ virtual CompositorBridgeChild* GetRemoteRenderer() { return nullptr; } + /** + * If there is a remote renderer, pause or resume it. + */ + virtual void PauseOrResumeCompositor(bool aPause); + /** * Clear WebRender resources */