Move HwVsyncState into VsyncSchedule
In preparation for having a separate schedule per display, pull state
which is logically for a single display into VsyncSchedule. This should
be a pure refactor.
Consolidate mPrimaryHWVsyncEnabled and mHWVsyncAvailable (now in
VsyncSchedule) into a single enum which better captures the possible
states. Move SF's record of the pending HWC VSYNC state into the same
place, so it sits with other related logic. Remove the last HWC
VSYNC state, which did not affect behavior.
Move ISchedulerCallback into its own file, so that VsyncSchedule.cpp
doesn't need to depend on Scheduler.h.
Rename variables `makeUnavailable` and `makeAvailable` for clarity.
Make addResyncSample return a boolean, instead of void with an out
parameter.
Remove VsyncSchedule's move constructor. Now that it has a mutex, it is
no longer thread-safe. We don't actually need to move it anyway. Replace
std::optional with std::unique_ptr for owning a VsyncSchedule.
Factored out of If60218e85292c786b9fa70ecb33ee374d3a385e0. Relevant
differences from that patch:
- There is still only one VsyncSchedule.
- When SF turns off a display, we still disable vsync on that display.
In If60218e85292c786b9fa70ecb33ee374d3a385e0, this was redundant with
the call to disableHardwareVsync shortly before it, but right now we
only call disableHardwareVsync for the active display.
- Hold the VSYNC lock for more time in resyncToHaredwareVsync. This
better matches the original behavior.
- Remove mLastHwVsyncState.
- Recreate the code for storing and setting the pending VSYNC state.
- Inline setVsyncPeriod at its only call-site.
Bug: 255601557
Bug: 256196556
Bug: 241286146
Fixes: 266712910
Test: libsurfaceflinger_unittest
Change-Id: I54a1304a3428968134cc707b24d5b325927c31df
diff --git a/services/surfaceflinger/SurfaceFlinger.cpp b/services/surfaceflinger/SurfaceFlinger.cpp
index c7c91ce..830537f 100644
--- a/services/surfaceflinger/SurfaceFlinger.cpp
+++ b/services/surfaceflinger/SurfaceFlinger.cpp
@@ -2031,8 +2031,7 @@
return;
}
- bool periodFlushed = false;
- mScheduler->addResyncSample(timestamp, vsyncPeriod, &periodFlushed);
+ const bool periodFlushed = mScheduler->addResyncSample(timestamp, vsyncPeriod);
if (periodFlushed) {
mScheduler->modulateVsync(&VsyncModulator::onRefreshRateChangeCompleted);
}
@@ -2080,11 +2079,14 @@
// On main thread to avoid race conditions with display power state.
static_cast<void>(mScheduler->schedule([=]() FTL_FAKE_GUARD(mStateLock) {
- mHWCVsyncPendingState = enabled ? hal::Vsync::ENABLE : hal::Vsync::DISABLE;
+ {
+ ftl::FakeGuard guard(kMainThreadContext);
+ mScheduler->getVsyncSchedule().setPendingHardwareVsyncState(enabled);
+ }
if (const auto display = getDefaultDisplayDeviceLocked();
display && display->isPoweredOn()) {
- setHWCVsyncEnabled(display->getPhysicalId(), mHWCVsyncPendingState);
+ setHWCVsyncEnabled(display->getPhysicalId(), enabled);
}
}));
}
@@ -5012,7 +5014,8 @@
}
getHwComposer().setPowerMode(displayId, mode);
if (isActiveDisplay && mode != hal::PowerMode::DOZE_SUSPEND) {
- setHWCVsyncEnabled(displayId, mHWCVsyncPendingState);
+ setHWCVsyncEnabled(displayId,
+ mScheduler->getVsyncSchedule().getPendingHardwareVsyncState());
mScheduler->onScreenAcquired(mAppConnectionHandle);
mScheduler->resyncToHardwareVsync(true, refreshRate);
}
@@ -5033,7 +5036,7 @@
}
// Make sure HWVsync is disabled before turning off the display
- setHWCVsyncEnabled(displayId, hal::Vsync::DISABLE);
+ setHWCVsyncEnabled(displayId, false);
getHwComposer().setPowerMode(displayId, mode);
mVisibleRegionsDirty = true;
@@ -5242,14 +5245,6 @@
mScheduler->dump(dumper);
- // TODO(b/241286146): Move to Scheduler.
- {
- utils::Dumper::Indent indent(dumper);
- dumper.dump("lastHwcVsyncState"sv, mLastHWCVsyncState);
- dumper.dump("pendingHwcVsyncState"sv, mHWCVsyncPendingState);
- }
- dumper.eol();
-
// TODO(b/241285876): Move to DisplayModeController.
dumper.dump("debugDisplayModeSetByBackdoor"sv, mDebugDisplayModeSetByBackdoor);
dumper.eol();