Bug 1813573 - Part 2. Restart vsync when refresh rate is changed. r=geckoview-reviewers,owlish

When refresh rate is changed, `DisplayListener` is called. So we restart vsync
when refresh rate may be changed.

Differential Revision: https://phabricator.services.mozilla.com/D168666
This commit is contained in:
Makoto Kato 2023-03-01 03:12:32 +00:00
Родитель 9aca857df0
Коммит 051c921a72
5 изменённых файлов: 39 добавлений и 1 удалений

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

@ -336,6 +336,17 @@ class AndroidVsyncSource final : public VsyncSource,
NotifyVsync(vsyncTime, outputTime);
}
void OnMaybeUpdateRefreshRate() override {
NS_DispatchToMainThread(
NS_NewRunnableFunction(__func__, [self = RefPtr{this}]() {
if (!self->mObservingVsync) {
return;
}
self->DisableVsync();
self->EnableVsync();
}));
}
private:
virtual ~AndroidVsyncSource() { DisableVsync(); }

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

@ -45,7 +45,12 @@ public class GeckoScreenChangeListener implements DisplayManager.DisplayListener
return;
}
GeckoScreenOrientation.getInstance().update(displayManager.getDisplay(displayId));
if (GeckoScreenOrientation.getInstance().update(displayManager.getDisplay(displayId))) {
// refreshScreenInfo is already called.
return;
}
ScreenManagerHelper.refreshScreenInfo();
}
private static DisplayManager getDisplayManager() {

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

@ -130,5 +130,18 @@ void AndroidVsync::NotifyVsync(int64_t aFrameTimeNanos) {
}
}
void AndroidVsync::OnMaybeUpdateRefreshRate() {
// Do not keep the lock held while calling OnVsync.
nsTArray<Observer*> observers;
{
auto impl = mImpl.Lock();
observers.AppendElements(impl->mInputObservers);
observers.AppendElements(impl->mRenderObservers);
}
for (Observer* observer : observers) {
observer->OnMaybeUpdateRefreshRate();
}
}
} // namespace widget
} // namespace mozilla

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

@ -35,6 +35,8 @@ class AndroidVsync final : public SupportsThreadSafeWeakPtr<AndroidVsync> {
public:
// Will be called on the Java UI thread.
virtual void OnVsync(const TimeStamp& aTimeStamp) = 0;
// Will be called on the Java UI thread.
virtual void OnMaybeUpdateRefreshRate() {}
// Called when the observer is unregistered, in case it wants to
// manage its own lifetime.
virtual void Dispose() {}
@ -46,6 +48,8 @@ class AndroidVsync final : public SupportsThreadSafeWeakPtr<AndroidVsync> {
void RegisterObserver(Observer* aObserver, ObserverType aType);
void UnregisterObserver(Observer* aObserver, ObserverType aType);
void OnMaybeUpdateRefreshRate();
private:
friend class AndroidVsyncSupport;

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

@ -10,6 +10,7 @@
#include <mozilla/jni/Refs.h>
#include "AndroidVsync.h"
#include "mozilla/Atomics.h"
#include "mozilla/java/GeckoAppShellWrappers.h"
#include "mozilla/java/ScreenManagerHelperNatives.h"
@ -62,4 +63,8 @@ void ScreenHelperAndroid::Refresh() {
AutoTArray<RefPtr<Screen>, 1> screens;
screens.AppendElement(MakePrimaryScreen());
ScreenManager::Refresh(std::move(screens));
if (RefPtr<AndroidVsync> vsync = AndroidVsync::GetInstance()) {
vsync->OnMaybeUpdateRefreshRate();
}
}