SF: Break dependency between VsyncConfiguration and RefreshRateConfigs
The VsyncConfiguration class doesn't need to know the list of
supported refresh rates, because the offsets can be calculated
and cached on the fly. This is better because the list of refresh
rates can change during runtime (for example for Android TV).
After fixing this the dependency on RefreshRateConfigs is only needed
for getting the current refresh rate at construction time. For
this it's sufficient to pass only the Fps instead of the whole
RefreshRateConfigs object.
Bug: 159590486
Test: presubmit
Change-Id: I1c0ceaf2524b517e85c8067577fc9f5146f1f632
diff --git a/services/surfaceflinger/tests/unittests/FakeVsyncConfiguration.h b/services/surfaceflinger/tests/unittests/FakeVsyncConfiguration.h
index 36e24d2..e890a62 100644
--- a/services/surfaceflinger/tests/unittests/FakeVsyncConfiguration.h
+++ b/services/surfaceflinger/tests/unittests/FakeVsyncConfiguration.h
@@ -37,6 +37,7 @@
FAKE_DURATION_OFFSET_NS}};
}
+ void reset() override {}
void setRefreshRateFps(Fps) override {}
void dump(std::string&) const override {}
};
diff --git a/services/surfaceflinger/tests/unittests/TestableSurfaceFlinger.h b/services/surfaceflinger/tests/unittests/TestableSurfaceFlinger.h
index 7f05a75..49592d9 100644
--- a/services/surfaceflinger/tests/unittests/TestableSurfaceFlinger.h
+++ b/services/surfaceflinger/tests/unittests/TestableSurfaceFlinger.h
@@ -78,7 +78,7 @@
}
std::unique_ptr<scheduler::VsyncConfiguration> createVsyncConfiguration(
- const scheduler::RefreshRateConfigs& /*refreshRateConfigs*/) override {
+ Fps /*currentRefreshRate*/) override {
return std::make_unique<scheduler::FakePhaseOffsets>();
}
@@ -231,8 +231,7 @@
mFlinger->mRefreshRateStats =
std::make_unique<scheduler::RefreshRateStats>(*mFlinger->mTimeStats, currFps,
/*powerMode=*/hal::PowerMode::OFF);
- mFlinger->mVsyncConfiguration =
- mFactory.createVsyncConfiguration(*mFlinger->mRefreshRateConfigs);
+ mFlinger->mVsyncConfiguration = mFactory.createVsyncConfiguration(currFps);
mFlinger->mVsyncModulator.emplace(mFlinger->mVsyncConfiguration->getCurrentConfigs());
mScheduler = new TestableScheduler(std::move(vsyncController), std::move(vsyncTracker),
diff --git a/services/surfaceflinger/tests/unittests/VsyncConfigurationTest.cpp b/services/surfaceflinger/tests/unittests/VsyncConfigurationTest.cpp
index 2a35f69..bb7578d 100644
--- a/services/surfaceflinger/tests/unittests/VsyncConfigurationTest.cpp
+++ b/services/surfaceflinger/tests/unittests/VsyncConfigurationTest.cpp
@@ -19,6 +19,7 @@
#include <gmock/gmock.h>
#include <log/log.h>
+#include <chrono>
#include <thread>
#include "Scheduler/VsyncConfiguration.h"
@@ -27,14 +28,15 @@
namespace android::scheduler {
+using namespace std::chrono_literals;
+
class TestableWorkDuration : public impl::WorkDuration {
public:
TestableWorkDuration(Fps currentFps, nsecs_t sfDuration, nsecs_t appDuration,
nsecs_t sfEarlyDuration, nsecs_t appEarlyDuration,
nsecs_t sfEarlyGlDuration, nsecs_t appEarlyGlDuration)
- : impl::WorkDuration({Fps(60.0f), Fps(90.0f)}, currentFps, sfDuration, appDuration,
- sfEarlyDuration, appEarlyDuration, sfEarlyGlDuration,
- appEarlyGlDuration) {}
+ : impl::WorkDuration(currentFps, sfDuration, appDuration, sfEarlyDuration,
+ appEarlyDuration, sfEarlyGlDuration, appEarlyGlDuration) {}
};
class WorkDurationTest : public testing::Test {
@@ -171,9 +173,9 @@
std::optional<nsecs_t> highFpsEarlyAppOffsetNs,
std::optional<nsecs_t> highFpsEarlyGpuAppOffsetNs,
nsecs_t thresholdForNextVsync)
- : impl::PhaseOffsets({Fps(60.0f), Fps(90.0f)}, Fps(60.0f), vsyncPhaseOffsetNs,
- sfVSyncPhaseOffsetNs, earlySfOffsetNs, earlyGpuSfOffsetNs,
- earlyAppOffsetNs, earlyGpuAppOffsetNs, highFpsVsyncPhaseOffsetNs,
+ : impl::PhaseOffsets(Fps(60.0f), vsyncPhaseOffsetNs, sfVSyncPhaseOffsetNs,
+ earlySfOffsetNs, earlyGpuSfOffsetNs, earlyAppOffsetNs,
+ earlyGpuAppOffsetNs, highFpsVsyncPhaseOffsetNs,
highFpsSfVSyncPhaseOffsetNs, highFpsEarlySfOffsetNs,
highFpsEarlyGpuSfOffsetNs, highFpsEarlyAppOffsetNs,
highFpsEarlyGpuAppOffsetNs, thresholdForNextVsync) {}