diff options
author | 2025-01-28 09:13:22 -0800 | |
---|---|---|
committer | 2025-01-28 09:13:22 -0800 | |
commit | 846a73738309d1d2848d2c9b8b7c1f2c0abc9f54 (patch) | |
tree | bf9cf7bbafc67c84444f9b9cdbf228cede18f085 /libs/ui/DisplayIdentification.cpp | |
parent | e17fc7afb267b610350029ddb726d8fdb2eb1fbc (diff) | |
parent | 0bf26cdb198b2b13b492a27de1701599f3b24458 (diff) |
Merge "SF: Add EDID-ID Fabrication Logic" into main
Diffstat (limited to 'libs/ui/DisplayIdentification.cpp')
-rw-r--r-- | libs/ui/DisplayIdentification.cpp | 24 |
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 |