SF: Move mode caching from Scheduler to RefreshRateConfigs

In the existing behavior Scheduler checks if the
layerReuquirements have changes since the last time
and only then calls into RefreshRateConfigs to
getBestRefreshRate. There are two problems with that

1. on the first iteration of the algorithm
   mFeatures.contentRequirements is empty. If we happen
   to have an empty list of current content requirements
   (for example if all layers have NoVote), we
   won't execute the refresh rate selection algorithm
   and we'll end up with a wrong initial refresh rate.

2. the cached value needs to be invalided when one of
   these change
    - globalSignals
    - supported display modes (happens on TV)
    - display manager policy

Bug: 188872896
Test: atest SchedulerTest RefreshRateConfigsTest
Change-Id: I101f401522fae8358752e283d8375caa93957b6a
diff --git a/services/surfaceflinger/tests/unittests/SchedulerTest.cpp b/services/surfaceflinger/tests/unittests/SchedulerTest.cpp
index 8ad8ea4..423d0cc 100644
--- a/services/surfaceflinger/tests/unittests/SchedulerTest.cpp
+++ b/services/surfaceflinger/tests/unittests/SchedulerTest.cpp
@@ -220,4 +220,25 @@
     EXPECT_EQ(0, mFlinger.calculateExtraBufferCount(Fps(60), 10ms));
 }
 
+MATCHER(Is120Hz, "") {
+    return arg.getFps().equalsWithMargin(Fps(120.f));
+}
+
+TEST_F(SchedulerTest, chooseRefreshRateForContentSelectsMaxRefreshRate) {
+    mConfigs.updateDisplayModes({mode60, mode120}, /* activeMode */ mode60->getId());
+
+    sp<mock::MockLayer> layer = sp<mock::MockLayer>::make(mFlinger.flinger());
+
+    mScheduler->recordLayerHistory(layer.get(), 0, LayerHistory::LayerUpdateType::Buffer);
+
+    constexpr bool kPowerStateNormal = true;
+    mScheduler->setDisplayPowerState(kPowerStateNormal);
+
+    constexpr uint32_t kDisplayArea = 999'999;
+    mScheduler->onPrimaryDisplayAreaChanged(kDisplayArea);
+
+    EXPECT_CALL(mSchedulerCallback, changeRefreshRate(Is120Hz(), _)).Times(1);
+    mScheduler->chooseRefreshRateForContent();
+}
+
 } // namespace android