SF: Simplify getBestRefreshRate caching
Cache the arguments/result as std::pair by removing the out parameter
for GlobalSignals.
Bug: 185535769
Test: libsurfaceflinger_unittest
Change-Id: Ibfb2aa4ca327b378844554bcd96620f84fc0460a
diff --git a/services/surfaceflinger/Scheduler/RefreshRateConfigs.h b/services/surfaceflinger/Scheduler/RefreshRateConfigs.h
index 7ef95f9..ade1787 100644
--- a/services/surfaceflinger/Scheduler/RefreshRateConfigs.h
+++ b/services/surfaceflinger/Scheduler/RefreshRateConfigs.h
@@ -20,6 +20,7 @@
#include <numeric>
#include <optional>
#include <type_traits>
+#include <utility>
#include <android-base/stringprintf.h>
#include <gui/DisplayEventReceiver.h>
@@ -249,11 +250,10 @@
}
};
- // Returns the refresh rate that best fits the given layers. outSignalsConsidered returns
- // whether the refresh rate was chosen based on touch boost and/or idle timer.
- RefreshRate getBestRefreshRate(const std::vector<LayerRequirement>&, GlobalSignals,
- GlobalSignals* outSignalsConsidered = nullptr) const
- EXCLUDES(mLock);
+ // Returns the refresh rate that best fits the given layers, and whether the refresh rate was
+ // chosen based on touch boost and/or idle timer.
+ std::pair<RefreshRate, GlobalSignals> getBestRefreshRate(const std::vector<LayerRequirement>&,
+ GlobalSignals) const EXCLUDES(mLock);
FpsRange getSupportedRefreshRateRange() const EXCLUDES(mLock) {
std::lock_guard lock(mLock);
@@ -403,13 +403,8 @@
const std::function<bool(const RefreshRate&)>& shouldAddRefreshRate,
std::vector<const RefreshRate*>* outRefreshRates) REQUIRES(mLock);
- std::optional<RefreshRate> getCachedBestRefreshRate(const std::vector<LayerRequirement>&,
- GlobalSignals,
- GlobalSignals* outSignalsConsidered) const
- REQUIRES(mLock);
-
- RefreshRate getBestRefreshRateLocked(const std::vector<LayerRequirement>&, GlobalSignals,
- GlobalSignals* outSignalsConsidered) const REQUIRES(mLock);
+ std::pair<RefreshRate, GlobalSignals> getBestRefreshRateLocked(
+ const std::vector<LayerRequirement>&, GlobalSignals) const REQUIRES(mLock);
// Returns the refresh rate with the highest score in the collection specified from begin
// to end. If there are more than one with the same highest refresh rate, the first one is
@@ -497,14 +492,11 @@
const Config mConfig;
bool mSupportsFrameRateOverrideByContent;
- struct GetBestRefreshRateInvocation {
- std::vector<LayerRequirement> layerRequirements;
- GlobalSignals globalSignals;
- GlobalSignals outSignalsConsidered;
- RefreshRate resultingBestRefreshRate;
+ struct GetBestRefreshRateCache {
+ std::pair<std::vector<LayerRequirement>, GlobalSignals> arguments;
+ std::pair<RefreshRate, GlobalSignals> result;
};
- mutable std::optional<GetBestRefreshRateInvocation> lastBestRefreshRateInvocation
- GUARDED_BY(mLock);
+ mutable std::optional<GetBestRefreshRateCache> mGetBestRefreshRateCache GUARDED_BY(mLock);
// Declare mIdleTimer last to ensure its thread joins before the mutex/callbacks are destroyed.
std::mutex mIdleTimerCallbacksMutex;