drm_hwcomposer: Produce stable port IDs
Currently, port IDs are generated by returning a monotonically
increasing value (uint64_t hwc2_display_t). This is problematic for
two reasons:
hwc2_display_t is a 64bit value, and the returned port is 8bit.
clients of drm-hwc cannot rely on port ID consistency between
re-plugs to the same connector.
This patch provides a more stable approach to producing port IDs. We
combine the index of the DRM device in the device list, with the
index of the connector within a DRM device in a 3/5 bit split. This will
allow us to support up to 8 DRM devices, each with 32 independent
connectors (ports). If more support is required in the future, we will
have to extend the API to return uint16_t port values instead.
Signed-off-by: Gil Dekel <gildekel@google.com>
diff --git a/hwc2_device/HwcDisplay.cpp b/hwc2_device/HwcDisplay.cpp
index 016998f..42ebd63 100644
--- a/hwc2_device/HwcDisplay.cpp
+++ b/hwc2_device/HwcDisplay.cpp
@@ -1158,12 +1158,21 @@
return HWC2::Error::Unsupported;
}
- auto blob = GetPipe().connector->Get()->GetEdidBlob();
+ auto *connector = GetPipe().connector->Get();
+ auto blob = connector->GetEdidBlob();
if (!blob) {
return HWC2::Error::Unsupported;
}
- *outPort = handle_; /* TDOD(nobody): What should be here? */
+ constexpr uint8_t kDrmDeviceBitShift = 5U;
+ constexpr uint8_t kDrmDeviceBitMask = 0xE0;
+ constexpr uint8_t kConnectorBitMask = 0x1F;
+ const auto kDrmIdx = static_cast<uint8_t>(
+ connector->GetDev().GetIndexInDevArray());
+ const auto kConnectorIdx = static_cast<uint8_t>(
+ connector->GetIndexInResArray());
+ *outPort = (((kDrmIdx << kDrmDeviceBitShift) & kDrmDeviceBitMask) |
+ (kConnectorIdx & kConnectorBitMask));
if (outData) {
*outDataSize = std::min(*outDataSize, blob->length);