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/RefreshRateConfigs.h b/services/surfaceflinger/Scheduler/RefreshRateConfigs.h
index 026f7c7..cbcc031 100644
--- a/services/surfaceflinger/Scheduler/RefreshRateConfigs.h
+++ b/services/surfaceflinger/Scheduler/RefreshRateConfigs.h
@@ -28,7 +28,7 @@
namespace scheduler {
/**
- * This class is used to encapsulate configuration for refresh rates. It holds infomation
+ * This class is used to encapsulate configuration for refresh rates. It holds information
* about available refresh rates on the device, and the mapping between the numbers and human
* readable names.
*/
@@ -40,8 +40,6 @@
enum class RefreshRateType { POWER_SAVING, DEFAULT, PERFORMANCE };
struct RefreshRate {
- // Type of the refresh rate.
- RefreshRateType type;
// This config ID corresponds to the position of the config in the vector that is stored
// on the device.
int configId;
@@ -59,13 +57,16 @@
}
~RefreshRateConfigs() = default;
- const std::vector<RefreshRate>& getRefreshRates() { return mRefreshRates; }
+ const std::unordered_map<RefreshRateType, RefreshRate>& getRefreshRates() {
+ return mRefreshRates;
+ }
+ const RefreshRate& getRefreshRate(RefreshRateType type) { return mRefreshRates[type]; }
private:
void init(const std::vector<std::shared_ptr<const HWC2::Display::Config>>& configs) {
// This is the rate that HWC encapsulates right now when the device is in DOZE mode.
- mRefreshRates.push_back(
- RefreshRate{RefreshRateType::POWER_SAVING, SCREEN_OFF_CONFIG_ID, "ScreenOff", 0});
+ mRefreshRates.emplace(RefreshRateType::POWER_SAVING,
+ RefreshRate{SCREEN_OFF_CONFIG_ID, "ScreenOff", 0});
if (configs.size() < 1) {
ALOGE("Device does not have valid configs. Config size is 0.");
@@ -88,9 +89,10 @@
nsecs_t vsyncPeriod = configIdToVsyncPeriod[0].second;
if (vsyncPeriod != 0) {
const float fps = 1e9 / vsyncPeriod;
- mRefreshRates.push_back(
- RefreshRate{RefreshRateType::DEFAULT, configIdToVsyncPeriod[0].first,
- base::StringPrintf("%2.ffps", fps), static_cast<uint32_t>(fps)});
+ mRefreshRates.emplace(RefreshRateType::DEFAULT,
+ RefreshRate{configIdToVsyncPeriod[0].first,
+ base::StringPrintf("%2.ffps", fps),
+ static_cast<uint32_t>(fps)});
}
if (configs.size() < 2) {
@@ -102,13 +104,14 @@
vsyncPeriod = configIdToVsyncPeriod[1].second;
if (vsyncPeriod != 0) {
const float fps = 1e9 / vsyncPeriod;
- mRefreshRates.push_back(
- RefreshRate{RefreshRateType::PERFORMANCE, configIdToVsyncPeriod[1].first,
- base::StringPrintf("%2.ffps", fps), static_cast<uint32_t>(fps)});
+ mRefreshRates.emplace(RefreshRateType::PERFORMANCE,
+ RefreshRate{configIdToVsyncPeriod[1].first,
+ base::StringPrintf("%2.ffps", fps),
+ static_cast<uint32_t>(fps)});
}
}
- std::vector<RefreshRate> mRefreshRates;
+ std::unordered_map<RefreshRateType, RefreshRate> mRefreshRates;
};
} // namespace scheduler