SF: Unify data types for display modes
Remove the RefreshRateConfigs::RefreshRate wrapper around DisplayMode.
Store DisplayModes as a SmallMap, so that RefreshRateConfigs uses the
same data structure for lookup by ID. Use iterators into that map for
all bookkeeping in RefreshRateConfigs.
Bug: 182939859
Bug: 185535769
Test: libsurfaceflinger_unittest
Change-Id: I7708fa997089802c45d906b17b7a073f5c82105e
diff --git a/services/surfaceflinger/DisplayDevice.cpp b/services/surfaceflinger/DisplayDevice.cpp
index 99335e5..f5a4b3d 100644
--- a/services/surfaceflinger/DisplayDevice.cpp
+++ b/services/surfaceflinger/DisplayDevice.cpp
@@ -196,7 +196,7 @@
ATRACE_INT(mActiveModeFPSTrace.c_str(), mode->getFps().getIntValue());
mActiveMode = mode;
if (mRefreshRateConfigs) {
- mRefreshRateConfigs->setCurrentModeId(mActiveMode->getId());
+ mRefreshRateConfigs->setActiveModeId(mActiveMode->getId());
}
if (mRefreshRateOverlay) {
mRefreshRateOverlay->changeRefreshRate(mActiveMode->getFps());
@@ -227,21 +227,16 @@
}
DisplayModePtr DisplayDevice::getMode(DisplayModeId modeId) const {
- const auto it =
- std::find_if(mSupportedModes.begin(), mSupportedModes.end(),
- [&](const DisplayModePtr& mode) { return mode->getId() == modeId; });
- if (it != mSupportedModes.end()) {
- return *it;
- }
- return nullptr;
+ const DisplayModePtr nullMode;
+ return mSupportedModes.get(modeId).value_or(std::cref(nullMode));
}
std::optional<DisplayModeId> DisplayDevice::translateModeId(hal::HWConfigId hwcId) const {
const auto it =
std::find_if(mSupportedModes.begin(), mSupportedModes.end(),
- [&](const DisplayModePtr& mode) { return mode->getHwcId() == hwcId; });
+ [hwcId](const auto& pair) { return pair.second->getHwcId() == hwcId; });
if (it != mSupportedModes.end()) {
- return (*it)->getId();
+ return it->second->getId();
}
return {};
}
@@ -366,12 +361,12 @@
activeMode ? to_string(*activeMode).c_str() : "none");
result.append(" supportedModes=\n");
-
- for (const auto& mode : mSupportedModes) {
- result.append(" ");
+ for (const auto& [id, mode] : mSupportedModes) {
+ result.append(" ");
result.append(to_string(*mode));
- result.append("\n");
+ result.push_back('\n');
}
+
StringAppendF(&result, " deviceProductInfo=");
if (mDeviceProductInfo) {
mDeviceProductInfo->dump(result);