SF: Generate stable display IDs using EDID
The display IDs generated by HWC are opaque handles. In order for SF and
eventually DisplayManagerService to keep track of more than two displays
and recognize previously seen displays, displays should be given stable
and persistent IDs.
If the HWC supports IComposerClient.getDisplayIdentificationData, SF
parses the EDID structure to generate stable display IDs, which will
be used in a follow-up CL to replace HWC_DISPLAY_{PRIMARY,EXTERNAL}.
Bug: 74619554
Test: dumpsys SurfaceFlinger --display-identification
Test: libsurfaceflinger_unittest
Change-Id: I1a710e2efcf1581fabe48ab96a0eb4e7a5163c0c
diff --git a/services/surfaceflinger/DisplayHardware/HWComposer.cpp b/services/surfaceflinger/DisplayHardware/HWComposer.cpp
index f111f2b..8e54392 100644
--- a/services/surfaceflinger/DisplayHardware/HWComposer.cpp
+++ b/services/surfaceflinger/DisplayHardware/HWComposer.cpp
@@ -96,6 +96,22 @@
mHwcDevice->registerCallback(callback, sequenceId);
}
+bool HWComposer::getDisplayIdentificationData(hwc2_display_t displayId, uint8_t* outPort,
+ DisplayIdentificationData* outData) const {
+ HWC2::Display* display = mHwcDevice->getDisplayById(displayId);
+ if (!display) {
+ ALOGE("getDisplayIdentificationData: Attempted to access invalid display %" PRIu64,
+ displayId);
+ return false;
+ }
+ const auto error = display->getIdentificationData(outPort, outData);
+ if (error != HWC2::Error::None) {
+ ALOGE("getDisplayIdentificationData failed for display %" PRIu64, displayId);
+ return false;
+ }
+ return true;
+}
+
bool HWComposer::hasCapability(HWC2::Capability capability) const
{
return mHwcDevice->getCapabilities().count(capability) > 0;
@@ -131,23 +147,35 @@
}
}
-void HWComposer::onHotplug(hwc2_display_t displayId, int32_t displayType,
- HWC2::Connection connection) {
+std::optional<DisplayId> HWComposer::onHotplug(hwc2_display_t displayId, int32_t displayType,
+ HWC2::Connection connection) {
if (displayType >= HWC_NUM_PHYSICAL_DISPLAY_TYPES) {
ALOGE("Invalid display type of %d", displayType);
- return;
+ return {};
}
ALOGV("hotplug: %" PRIu64 ", %s %s", displayId,
displayType == DisplayDevice::DISPLAY_PRIMARY ? "primary" : "external",
to_string(connection).c_str());
mHwcDevice->onHotplug(displayId, connection);
+
+ std::optional<DisplayId> stableId;
+
+ uint8_t port;
+ DisplayIdentificationData data;
+ if (getDisplayIdentificationData(displayId, &port, &data)) {
+ stableId = generateDisplayId(port, data);
+ ALOGE_IF(!stableId, "Failed to generate stable ID for display %" PRIu64, displayId);
+ }
+
// Disconnect is handled through HWComposer::disconnectDisplay via
// SurfaceFlinger's onHotplugReceived callback handling
if (connection == HWC2::Connection::Connected) {
mDisplayData[displayType].hwcDisplay = mHwcDevice->getDisplayById(displayId);
mHwcDisplaySlots[displayId] = displayType;
}
+
+ return stableId;
}
bool HWComposer::onVsync(hwc2_display_t displayId, int64_t timestamp,