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/drm/DrmDevice.cpp b/drm/DrmDevice.cpp
index 787d77c..6fd5c0c 100644
--- a/drm/DrmDevice.cpp
+++ b/drm/DrmDevice.cpp
@@ -35,13 +35,13 @@
namespace android {
auto DrmDevice::CreateInstance(std::string const &path,
- ResourceManager *res_man)
+ ResourceManager *res_man, uint32_t index)
-> std::unique_ptr<DrmDevice> {
if (!IsKMSDev(path.c_str())) {
return {};
}
- auto device = std::unique_ptr<DrmDevice>(new DrmDevice(res_man));
+ auto device = std::unique_ptr<DrmDevice>(new DrmDevice(res_man, index));
if (device->Init(path.c_str()) != 0) {
return {};
@@ -50,7 +50,8 @@
return device;
}
-DrmDevice::DrmDevice(ResourceManager *res_man) : res_man_(res_man) {
+DrmDevice::DrmDevice(ResourceManager *res_man, uint32_t index)
+ : index_in_dev_array_(index), res_man_(res_man) {
drm_fb_importer_ = std::make_unique<DrmFbImporter>(*this);
}