SF: Match followers' refresh rate to pacesetter's
Multi-display refresh rate selection was flawed: The scheduler runs the
refresh rate selection algorithm for each display, and then filters the
candidate modes of each follower to match the pacesetter's refresh rate.
This means that:
1. The followers incorrectly consider refresh rates that don't match the
pacesetter. Because the DM-specified constraint is [59, 61] Hz, some
situations caused selection of a fractional rate (e.g. 59.94) instead
of 60 on certain external displays. The result would be black screens
for several seconds due to mode sets if the selection was not stable.
2. The followers incorrectly evaluate heuristics that should only affect
the pacesetter, e.g. per-surface votes, global signals.
Fix this by teaching RefreshRateSelector about follower displays.
Foldables also benefit from no longer running the algorithm twice.
Fixes: 324188430
Bug: 329111930
Test: No black screen for 4 seconds upon rotating mirrored YouTube.
Test: 60+60 still works on foldables.
Test: RefreshRateSelectorTest.pacesetterConsidered
Change-Id: Ie1b27e81d860a709c85651f068fedb2b496861de
diff --git a/services/surfaceflinger/Scheduler/RefreshRateSelector.h b/services/surfaceflinger/Scheduler/RefreshRateSelector.h
index 6051e89..a500063 100644
--- a/services/surfaceflinger/Scheduler/RefreshRateSelector.h
+++ b/services/surfaceflinger/Scheduler/RefreshRateSelector.h
@@ -233,14 +233,18 @@
struct RankedFrameRates {
FrameRateRanking ranking; // Ordered by descending score.
GlobalSignals consideredSignals;
+ Fps pacesetterFps;
bool operator==(const RankedFrameRates& other) const {
- return ranking == other.ranking && consideredSignals == other.consideredSignals;
+ return ranking == other.ranking && consideredSignals == other.consideredSignals &&
+ isApproxEqual(pacesetterFps, other.pacesetterFps);
}
};
- RankedFrameRates getRankedFrameRates(const std::vector<LayerRequirement>&, GlobalSignals) const
- EXCLUDES(mLock);
+ // If valid, `pacesetterFps` (used by follower displays) filters the ranking to modes matching
+ // that refresh rate.
+ RankedFrameRates getRankedFrameRates(const std::vector<LayerRequirement>&, GlobalSignals,
+ Fps pacesetterFps = {}) const EXCLUDES(mLock);
FpsRange getSupportedRefreshRateRange() const EXCLUDES(mLock) {
std::lock_guard lock(mLock);
@@ -415,7 +419,8 @@
const FrameRateMode& getActiveModeLocked() const REQUIRES(mLock);
RankedFrameRates getRankedFrameRatesLocked(const std::vector<LayerRequirement>& layers,
- GlobalSignals signals) const REQUIRES(mLock);
+ GlobalSignals signals, Fps pacesetterFps) const
+ REQUIRES(mLock);
// Returns number of display frames and remainder when dividing the layer refresh period by
// display refresh period.
@@ -534,8 +539,16 @@
Config::FrameRateOverride mFrameRateOverrideConfig;
struct GetRankedFrameRatesCache {
- std::pair<std::vector<LayerRequirement>, GlobalSignals> arguments;
+ std::vector<LayerRequirement> layers;
+ GlobalSignals signals;
+ Fps pacesetterFps;
+
RankedFrameRates result;
+
+ bool matches(const GetRankedFrameRatesCache& other) const {
+ return layers == other.layers && signals == other.signals &&
+ isApproxEqual(pacesetterFps, other.pacesetterFps);
+ }
};
mutable std::optional<GetRankedFrameRatesCache> mGetRankedFrameRatesCache GUARDED_BY(mLock);