Move VsyncConfiguration from SF to Scheduler
This is part of the long term goal, tracked in b/241285191, of moving
scheduling logic/state from SF to Scheduler. It also paves the way for
a cleaner version of Ib927935de6ba2b7b8d5037b42eb635ae92019634.
Bring RefreshRateStats along to Scheduler, since it is updated along
with work that belongs in Scheduler.
Mostly this is intended to not change behavior, but there are some
exceptions:
- the ordering of dumpsys SurfaceFlinger has changed, as some components
are now internal to Scheduler, so they are dumped along with it.
- two extra calls to update the RefreshRateStats along with
updatePhaseConfiguration. The missing calls appear to be an oversight,
and it's more natural to include the update in its new location.
Move construction of VsyncModulator into Scheduler, since it is
constructed from the VsyncConfiguration, now constructed in Scheduler.
Add TestableScheduler.cpp, to prevent adding a circular dependency, now
that the class's constructor references TestableSurfaceFlinger.
Add Dumper::out for simplicity in updating dump calls.
Bug: 241285191
Bug: 255601557
Bug: 256196556
Bug: 259132483
Test: libscheduler_test
Test: libsurfaceflinger_unittest
Change-Id: I01c93cfc3d2342cfbaaf8fe47dc2cd57d0e1fc43
diff --git a/services/surfaceflinger/SurfaceFlinger.cpp b/services/surfaceflinger/SurfaceFlinger.cpp
index 2503efc..4d04aad 100644
--- a/services/surfaceflinger/SurfaceFlinger.cpp
+++ b/services/surfaceflinger/SurfaceFlinger.cpp
@@ -1108,7 +1108,7 @@
outMode.peakRefreshRate = peakFps.getValue();
outMode.vsyncRate = mode->getVsyncRate().getValue();
- const auto vsyncConfigSet = mVsyncConfiguration->getConfigsForRefreshRate(
+ const auto vsyncConfigSet = mScheduler->getVsyncConfiguration().getConfigsForRefreshRate(
Fps::fromValue(outMode.peakRefreshRate));
outMode.appVsyncOffset = vsyncConfigSet.late.appOffset;
outMode.sfVsyncOffset = vsyncConfigSet.late.sfOffset;
@@ -1267,7 +1267,7 @@
mScheduler->modulateVsync(displayId, &VsyncModulator::onRefreshRateChangeInitiated);
if (displayId == mActiveDisplayId) {
- updatePhaseConfiguration(mode.fps);
+ mScheduler->updatePhaseConfiguration(mode.fps);
}
mScheduler->setModeChangePending(true);
@@ -1276,8 +1276,7 @@
mScheduler->setRenderRate(displayId, mode.fps);
if (displayId == mActiveDisplayId) {
- updatePhaseConfiguration(mode.fps);
- mRefreshRateStats->setRefreshRate(mode.fps);
+ mScheduler->updatePhaseConfiguration(mode.fps);
}
if (emitEvent) {
@@ -1369,8 +1368,7 @@
activeMode.fps);
if (displayId == mActiveDisplayId) {
- mRefreshRateStats->setRefreshRate(activeMode.fps);
- updatePhaseConfiguration(activeMode.fps);
+ mScheduler->updatePhaseConfiguration(activeMode.fps);
}
if (pendingModeOpt->emitEvent) {
@@ -1399,7 +1397,7 @@
mScheduler->setRenderRate(displayId, renderFps);
if (displayId == mActiveDisplayId) {
- updatePhaseConfiguration(renderFps);
+ mScheduler->updatePhaseConfiguration(renderFps);
}
}
@@ -2756,7 +2754,8 @@
if (!getHwComposer().getComposer()->isSupported(
Hwc2::Composer::OptionalFeature::ExpectedPresentTime) &&
pacesetterTarget.wouldPresentEarly(minFramePeriod)) {
- const auto hwcMinWorkDuration = mVsyncConfiguration->getCurrentConfigs().hwcMinWorkDuration;
+ const auto hwcMinWorkDuration =
+ mScheduler->getVsyncConfiguration().getCurrentConfigs().hwcMinWorkDuration;
// TODO(b/255601557): Calculate and pass per-display values for each FrameTarget.
refreshArgs.earliestPresentTime =
@@ -3064,7 +3063,8 @@
const auto schedule = mScheduler->getVsyncSchedule();
const TimePoint vsyncDeadline = schedule->vsyncDeadlineAfter(presentTime);
const Period vsyncPeriod = schedule->period();
- const nsecs_t vsyncPhase = mVsyncConfiguration->getCurrentConfigs().late.sfOffset;
+ const nsecs_t vsyncPhase =
+ mScheduler->getVsyncConfiguration().getCurrentConfigs().late.sfOffset;
const CompositorTiming compositorTiming(vsyncDeadline.ns(), vsyncPeriod.ns(), vsyncPhase,
presentLatency.ns());
@@ -3741,7 +3741,7 @@
// TODO(b/175678251) Call a listener instead.
if (currentState.physical->hwcDisplayId == getHwComposer().getPrimaryHwcDisplayId()) {
- resetPhaseConfiguration(display->getActiveMode().fps);
+ mScheduler->resetPhaseConfiguration(display->getActiveMode().fps);
}
}
return;
@@ -3777,15 +3777,6 @@
}
}
-void SurfaceFlinger::resetPhaseConfiguration(Fps refreshRate) {
- // Cancel the pending refresh rate change, if any, before updating the phase configuration.
- mScheduler->vsyncModulator().cancelRefreshRateChange();
-
- mVsyncConfiguration->reset();
- updatePhaseConfiguration(refreshRate);
- mRefreshRateStats->setRefreshRate(refreshRate);
-}
-
void SurfaceFlinger::processDisplayChangesLocked() {
// here we take advantage of Vector's copy-on-write semantics to
// improve performance by skipping the transaction entirely when
@@ -4202,10 +4193,6 @@
const auto activeMode = display->refreshRateSelector().getActiveMode();
const Fps activeRefreshRate = activeMode.fps;
- mRefreshRateStats =
- std::make_unique<RefreshRateStats>(*mTimeStats, activeRefreshRate, hal::PowerMode::OFF);
-
- mVsyncConfiguration = getFactory().createVsyncConfiguration(activeRefreshRate);
FeatureFlags features;
@@ -4232,11 +4219,9 @@
features |= Feature::kBackpressureGpuComposition;
}
- auto modulatorPtr = sp<VsyncModulator>::make(mVsyncConfiguration->getCurrentConfigs());
-
mScheduler = std::make_unique<Scheduler>(static_cast<ICompositor&>(*this),
static_cast<ISchedulerCallback&>(*this), features,
- std::move(modulatorPtr),
+ getFactory(), activeRefreshRate, *mTimeStats,
static_cast<IVsyncTrackerCallback&>(*this));
mScheduler->registerDisplay(display->getPhysicalId(), display->holdRefreshRateSelector());
if (FlagManager::getInstance().vrr_config()) {
@@ -4244,7 +4229,7 @@
}
mScheduler->startTimers();
- const auto configs = mVsyncConfiguration->getCurrentConfigs();
+ const auto configs = mScheduler->getVsyncConfiguration().getCurrentConfigs();
mAppConnectionHandle =
mScheduler->createEventThread(Scheduler::Cycle::Render,
@@ -4266,12 +4251,6 @@
mFpsReporter = sp<FpsReporter>::make(*mFrameTimeline, *this);
}
-void SurfaceFlinger::updatePhaseConfiguration(Fps refreshRate) {
- mVsyncConfiguration->setRefreshRateFps(refreshRate);
- mScheduler->setVsyncConfigSet(mVsyncConfiguration->getCurrentConfigs(),
- refreshRate.getPeriod());
-}
-
void SurfaceFlinger::doCommitTransactions() {
ATRACE_CALL();
@@ -6026,7 +6005,7 @@
if (displayId == mActiveDisplayId) {
mTimeStats->setPowerMode(mode);
- mRefreshRateStats->setPowerMode(mode);
+ mScheduler->setActiveDisplayPowerModeForRefreshRateStats(mode);
}
mScheduler->setDisplayPowerMode(displayId, mode);
@@ -6191,10 +6170,6 @@
dumper.dump("debugDisplayModeSetByBackdoor"sv, mDebugDisplayModeSetByBackdoor);
dumper.eol();
- mRefreshRateStats->dump(result);
- dumper.eol();
-
- mVsyncConfiguration->dump(result);
StringAppendF(&result,
" present offset: %9" PRId64 " ns\t VSYNC period: %9" PRId64
" ns\n\n",
@@ -8634,7 +8609,8 @@
}
int SurfaceFlinger::getMaxAcquiredBufferCountForRefreshRate(Fps refreshRate) const {
- const auto vsyncConfig = mVsyncConfiguration->getConfigsForRefreshRate(refreshRate).late;
+ const auto vsyncConfig =
+ mScheduler->getVsyncConfiguration().getConfigsForRefreshRate(refreshRate).late;
const auto presentLatency = vsyncConfig.appWorkDuration + vsyncConfig.sfWorkDuration;
return calculateMaxAcquiredBufferCount(refreshRate, presentLatency);
}
@@ -8727,7 +8703,7 @@
mActiveDisplayId = activeDisplay.getPhysicalId();
activeDisplay.getCompositionDisplay()->setLayerCachingTexturePoolEnabled(true);
- resetPhaseConfiguration(activeDisplay.getActiveMode().fps);
+ mScheduler->resetPhaseConfiguration(activeDisplay.getActiveMode().fps);
// TODO(b/255635711): Check for pending mode changes on other displays.
mScheduler->setModeChangePending(false);