From a17009748a2cbc450322180c46dffdcc7efdbf46 Mon Sep 17 00:00:00 2001 From: sotaro Date: Sun, 16 Jan 2022 23:57:41 +0000 Subject: [PATCH] Bug 1732738 - Enable display status handling of window occlusion on Windows r=nical,gfx-reviewers pref handling is removed from WinWindowOcclusionTrackerInteractiveTest. Instead, WinWindowOcclusionTracker::EnsureDisplayStatusObserver() and WinWindowOcclusionTracker::EnsureSessionChangeObserver() are added. Differential Revision: https://phabricator.services.mozilla.com/D133601 --- modules/libpref/init/StaticPrefList.yaml | 2 +- ...stWinWindowOcclusionTrackerInteractive.cpp | 13 +++------- widget/windows/WinEventObserver.cpp | 11 --------- widget/windows/WinWindowOcclusionTracker.cpp | 24 +++++++++++++++++-- widget/windows/WinWindowOcclusionTracker.h | 6 +++++ 5 files changed, 32 insertions(+), 24 deletions(-) diff --git a/modules/libpref/init/StaticPrefList.yaml b/modules/libpref/init/StaticPrefList.yaml index a546c9aac44d..e969ed5d7a11 100644 --- a/modules/libpref/init/StaticPrefList.yaml +++ b/modules/libpref/init/StaticPrefList.yaml @@ -12610,7 +12610,7 @@ - name: widget.windows.window_occlusion_tracking_display_state.enabled type: bool - value: false + value: true mirror: always - name: widget.windows.window_occlusion_tracking_session_lock.enabled diff --git a/widget/tests/gtest/TestWinWindowOcclusionTrackerInteractive.cpp b/widget/tests/gtest/TestWinWindowOcclusionTrackerInteractive.cpp index 3217eda851df..a9e816b96eea 100644 --- a/widget/tests/gtest/TestWinWindowOcclusionTrackerInteractive.cpp +++ b/widget/tests/gtest/TestWinWindowOcclusionTrackerInteractive.cpp @@ -33,21 +33,16 @@ class WinWindowOcclusionTrackerInteractiveTest : public ::testing::Test { } EXPECT_EQ(nullptr, WinWindowOcclusionTracker::Get()); - mOldPrefDisplayStatus = Preferences::GetBool(PREF_DISPLAY_STATE); - Preferences::SetBool(PREF_DISPLAY_STATE, true); - mOldPrefSessionLock = Preferences::GetBool(PREF_SESSION_LOCK); - Preferences::SetBool(PREF_SESSION_LOCK, true); - WinWindowOcclusionTracker::Ensure(); EXPECT_NE(nullptr, WinWindowOcclusionTracker::Get()); + + WinWindowOcclusionTracker::Get()->EnsureDisplayStatusObserver(); + WinWindowOcclusionTracker::Get()->EnsureSessionChangeObserver(); } void TearDown() override { WinWindowOcclusionTracker::ShutDown(); EXPECT_EQ(nullptr, WinWindowOcclusionTracker::Get()); - - Preferences::SetBool(PREF_DISPLAY_STATE, mOldPrefDisplayStatus); - Preferences::SetBool(PREF_SESSION_LOCK, mOldPrefSessionLock); } void SetNativeWindowBounds(HWND aHWnd, const LayoutDeviceIntRect aBounds) { @@ -120,8 +115,6 @@ class WinWindowOcclusionTrackerInteractiveTest : public ::testing::Test { WinWindowOcclusionTracker::Get()->OnDisplayStateChanged(aDisplayOn); } - bool mOldPrefDisplayStatus = false; - bool mOldPrefSessionLock = false; RefPtr mMockWinWidget; }; diff --git a/widget/windows/WinEventObserver.cpp b/widget/windows/WinEventObserver.cpp index 5301b48c2df7..cb6c2eb8ad47 100644 --- a/widget/windows/WinEventObserver.cpp +++ b/widget/windows/WinEventObserver.cpp @@ -12,7 +12,6 @@ #include "mozilla/ClearOnShutdown.h" #include "mozilla/Logging.h" -#include "mozilla/StaticPrefs_widget.h" #include "mozilla/StaticPtr.h" #include "nsHashtablesFwd.h" @@ -121,11 +120,6 @@ void WinEventObserver::Destroy() { // static already_AddRefed DisplayStatusObserver::Create( DisplayStatusListener* aListener) { - if (!StaticPrefs:: - widget_windows_window_occlusion_tracking_display_state_enabled()) { - return nullptr; - } - WinEventHub::Ensure(); RefPtr observer = new DisplayStatusObserver(aListener); WinEventHub::Get()->AddObserver(observer); @@ -172,11 +166,6 @@ void DisplayStatusObserver::OnWinEventProc(HWND aHwnd, UINT aMsg, // static already_AddRefed SessionChangeObserver::Create( SessionChangeListener* aListener) { - if (!StaticPrefs:: - widget_windows_window_occlusion_tracking_session_lock_enabled()) { - return nullptr; - } - WinEventHub::Ensure(); RefPtr observer = new SessionChangeObserver(aListener); WinEventHub::Get()->AddObserver(observer); diff --git a/widget/windows/WinWindowOcclusionTracker.cpp b/widget/windows/WinWindowOcclusionTracker.cpp index f916f072811e..432b07021c83 100644 --- a/widget/windows/WinWindowOcclusionTracker.cpp +++ b/widget/windows/WinWindowOcclusionTracker.cpp @@ -372,6 +372,20 @@ bool WinWindowOcclusionTracker::IsInWinWindowOcclusionThread() { sTracker->mThread->thread_id() == PlatformThread::CurrentId(); } +void WinWindowOcclusionTracker::EnsureDisplayStatusObserver() { + if (mDisplayStatusObserver) { + return; + } + mDisplayStatusObserver = DisplayStatusObserver::Create(this); +} + +void WinWindowOcclusionTracker::EnsureSessionChangeObserver() { + if (mSessionChangeObserver) { + return; + } + mSessionChangeObserver = SessionChangeObserver::Create(this); +} + void WinWindowOcclusionTracker::Enable(nsBaseWidget* aWindow, HWND aHwnd) { MOZ_ASSERT(NS_IsMainThread()); LOG(LogLevel::Info, "WinWindowOcclusionTracker::Enable() aWindow %p aHwnd %p", @@ -432,8 +446,14 @@ WinWindowOcclusionTracker::WinWindowOcclusionTracker(base::Thread* aThread) MOZ_ASSERT(NS_IsMainThread()); LOG(LogLevel::Info, "WinWindowOcclusionTracker::WinWindowOcclusionTracker()"); - mDisplayStatusObserver = DisplayStatusObserver::Create(this); - mSessionChangeObserver = SessionChangeObserver::Create(this); + if (StaticPrefs:: + widget_windows_window_occlusion_tracking_display_state_enabled()) { + mDisplayStatusObserver = DisplayStatusObserver::Create(this); + } + if (StaticPrefs:: + widget_windows_window_occlusion_tracking_session_lock_enabled()) { + mSessionChangeObserver = SessionChangeObserver::Create(this); + } mSerializedTaskDispatcher = new SerializedTaskDispatcher(); } diff --git a/widget/windows/WinWindowOcclusionTracker.h b/widget/windows/WinWindowOcclusionTracker.h index 617a02310074..aafe4091e12f 100644 --- a/widget/windows/WinWindowOcclusionTracker.h +++ b/widget/windows/WinWindowOcclusionTracker.h @@ -60,6 +60,12 @@ class WinWindowOcclusionTracker final : public DisplayStatusListener, /// Can be called from any thread. static bool IsInWinWindowOcclusionThread(); + /// Can only be called from the main thread. + void EnsureDisplayStatusObserver(); + + /// Can only be called from the main thread. + void EnsureSessionChangeObserver(); + // Enables notifying to widget via NotifyOcclusionState() when the occlusion // state has been computed. void Enable(nsBaseWidget* aWindow, HWND aHwnd);