SurfaceFlinger: use scheduler::RefreshRateConfigs in setRefreshRateTo
Use cached values for display configs instead of querying HWC for the
available configs every time we want to change config.
setRefreshRateTo average time reduced from 0.108 ms to 0.032 ms
Test: collected systrace for config changes
Bug: 122906558
Change-Id: I543973ba01df067bd5ad23a2c2ab48b9a90621ae
diff --git a/services/surfaceflinger/Scheduler/RefreshRateStats.h b/services/surfaceflinger/Scheduler/RefreshRateStats.h
index dcb2988..2491081 100644
--- a/services/surfaceflinger/Scheduler/RefreshRateStats.h
+++ b/services/surfaceflinger/Scheduler/RefreshRateStats.h
@@ -41,10 +41,9 @@
static constexpr int64_t MS_PER_DAY = 24 * MS_PER_HOUR;
public:
- explicit RefreshRateStats(
- const std::vector<std::shared_ptr<const HWC2::Display::Config>>& configs,
- const std::shared_ptr<TimeStats>& timeStats)
- : mRefreshRateConfigs(std::make_unique<RefreshRateConfigs>(configs)),
+ explicit RefreshRateStats(const std::shared_ptr<RefreshRateConfigs>& refreshRateConfigs,
+ const std::shared_ptr<TimeStats>& timeStats)
+ : mRefreshRateConfigs(refreshRateConfigs),
mTimeStats(timeStats),
mPreviousRecordedTime(systemTime()) {}
~RefreshRateStats() = default;
@@ -84,7 +83,7 @@
flushTime();
std::unordered_map<std::string, int64_t> totalTime;
- for (auto config : mRefreshRateConfigs->getRefreshRates()) {
+ for (auto [type, config] : mRefreshRateConfigs->getRefreshRates()) {
int64_t totalTimeForConfig = 0;
if (mConfigModesTotalTime.find(config.configId) != mConfigModesTotalTime.end()) {
totalTimeForConfig = mConfigModesTotalTime.at(config.configId);
@@ -124,7 +123,7 @@
mPreviousRecordedTime = currentTime;
mConfigModesTotalTime[mode] += timeElapsedMs;
- for (const auto& config : mRefreshRateConfigs->getRefreshRates()) {
+ for (const auto& [type, config] : mRefreshRateConfigs->getRefreshRates()) {
if (config.configId == mode) {
mTimeStats->recordRefreshRate(config.fps, timeElapsed);
}
@@ -143,7 +142,7 @@
}
// Keeps information about refresh rate configs that device has.
- std::unique_ptr<RefreshRateConfigs> mRefreshRateConfigs;
+ std::shared_ptr<RefreshRateConfigs> mRefreshRateConfigs;
// Aggregate refresh rate statistics for telemetry.
std::shared_ptr<TimeStats> mTimeStats;