SF: Cache DisplayConnectionType on first call
The connection type is immutable, so avoid the unnecessary AIDL call to
getDisplayConnectionType for each setActiveConfigWithConstraints.
Fixes: 323905961
Test: HWComposerTest.getDisplayConnectionType
Change-Id: I925510e24bab6bd1665128e67a98611aa9b20cd4
diff --git a/services/surfaceflinger/DisplayHardware/HWComposer.cpp b/services/surfaceflinger/DisplayHardware/HWComposer.cpp
index bac24c7..cfa0339 100644
--- a/services/surfaceflinger/DisplayHardware/HWComposer.cpp
+++ b/services/surfaceflinger/DisplayHardware/HWComposer.cpp
@@ -364,15 +364,13 @@
RETURN_IF_INVALID_DISPLAY(displayId, ui::DisplayConnectionType::Internal);
const auto& hwcDisplay = mDisplayData.at(displayId).hwcDisplay;
- ui::DisplayConnectionType type;
- const auto error = hwcDisplay->getConnectionType(&type);
-
- const auto FALLBACK_TYPE = hwcDisplay->getId() == mPrimaryHwcDisplayId
- ? ui::DisplayConnectionType::Internal
- : ui::DisplayConnectionType::External;
-
- RETURN_IF_HWC_ERROR(error, displayId, FALLBACK_TYPE);
- return type;
+ if (const auto connectionType = hwcDisplay->getConnectionType()) {
+ return connectionType.value();
+ } else {
+ LOG_HWC_ERROR(__func__, connectionType.error(), displayId);
+ return hwcDisplay->getId() == mPrimaryHwcDisplayId ? ui::DisplayConnectionType::Internal
+ : ui::DisplayConnectionType::External;
+ }
}
bool HWComposer::isVsyncPeriodSwitchSupported(PhysicalDisplayId displayId) const {