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
This commit is contained in:
sotaro 2022-01-16 23:57:41 +00:00
Родитель 7b9c5fc6b2
Коммит a17009748a
5 изменённых файлов: 32 добавлений и 24 удалений

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

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

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

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

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

@ -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> DisplayStatusObserver::Create(
DisplayStatusListener* aListener) {
if (!StaticPrefs::
widget_windows_window_occlusion_tracking_display_state_enabled()) {
return nullptr;
}
WinEventHub::Ensure();
RefPtr<DisplayStatusObserver> observer = new DisplayStatusObserver(aListener);
WinEventHub::Get()->AddObserver(observer);
@ -172,11 +166,6 @@ void DisplayStatusObserver::OnWinEventProc(HWND aHwnd, UINT aMsg,
// static
already_AddRefed<SessionChangeObserver> SessionChangeObserver::Create(
SessionChangeListener* aListener) {
if (!StaticPrefs::
widget_windows_window_occlusion_tracking_session_lock_enabled()) {
return nullptr;
}
WinEventHub::Ensure();
RefPtr<SessionChangeObserver> observer = new SessionChangeObserver(aListener);
WinEventHub::Get()->AddObserver(observer);

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

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

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

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