summaryrefslogtreecommitdiff
path: root/libs/ui/DisplayIdentification.cpp
diff options
context:
space:
mode:
author Gil Dekel <gildekel@google.com> 2024-12-10 15:11:28 -0500
committer Gil Dekel <gildekel@google.com> 2025-01-28 10:53:09 -0500
commit0bf26cdb198b2b13b492a27de1701599f3b24458 (patch)
tree3673ebb7c2385eed2241de32a6b7e27cb55ad847 /libs/ui/DisplayIdentification.cpp
parent04a3b4f2f512fdcba44a5f0434847659328f1a5c (diff)
SF: Add EDID-ID Fabrication Logic
Adds logic to fabricate a display ID that is based solely on a given, pre-parsed EDID data. It does so by concatenating the EDID's generic fields, such as manufacturer ID, product ID, etc. as a string, and hash-combine them with the hashed values of the display serial numbers. All hash functions are stable in order to consistently reproduce display IDs when the same information is fed via the EDID blob. Flag: com.android.graphics.surfaceflinger.flags.stable_edid_ids Bug: 366042891 Test: N/A Change-Id: I7693d4b0ca9fee5ed190c3530a69300a8a530cd2
Diffstat (limited to 'libs/ui/DisplayIdentification.cpp')
-rw-r--r--libs/ui/DisplayIdentification.cpp24
1 files changed, 24 insertions, 0 deletions
diff --git a/libs/ui/DisplayIdentification.cpp b/libs/ui/DisplayIdentification.cpp
index ee38f5044c..b7ef9b3738 100644
--- a/libs/ui/DisplayIdentification.cpp
+++ b/libs/ui/DisplayIdentification.cpp
@@ -26,6 +26,7 @@
#include <string>
#include <string_view>
+#include <ftl/concat.h>
#include <ftl/hash.h>
#include <log/log.h>
#include <ui/DisplayIdentification.h>
@@ -423,4 +424,27 @@ PhysicalDisplayId getVirtualDisplayId(uint32_t id) {
return PhysicalDisplayId::fromEdid(0, kVirtualEdidManufacturerId, id);
}
+PhysicalDisplayId generateEdidDisplayId(const Edid& edid) {
+ const ftl::Concat displayDetailsString{edid.manufacturerId,
+ edid.productId,
+ ftl::truncated<13>(edid.displayName),
+ edid.manufactureWeek,
+ edid.manufactureOrModelYear,
+ edid.physicalSizeInCm.getWidth(),
+ edid.physicalSizeInCm.getHeight()};
+
+ // String has to be cropped to 64 characters (at most) for ftl::stable_hash.
+ // This is fine as the accuracy or completeness of the above fields is not
+ // critical for a ID fabrication.
+ const std::optional<uint64_t> hashedDisplayDetailsOpt =
+ ftl::stable_hash(std::string_view(displayDetailsString.c_str(), 64));
+
+ // Combine the hashes via bit-shifted XORs.
+ const uint64_t id = (hashedDisplayDetailsOpt.value_or(0) << 17) ^
+ (edid.hashedBlockZeroSerialNumberOpt.value_or(0) >> 11) ^
+ (edid.hashedDescriptorBlockSerialNumberOpt.value_or(0) << 23);
+
+ return PhysicalDisplayId::fromEdidHash(id);
+}
+
} // namespace android