Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit ff793876 authored by Alec Mouri's avatar Alec Mouri
Browse files

Move DisplayIdentification parsing to libui

This is so that the logic can be shared with VTS, as stable display IDs
are generated from edid information or port information.

Bug: 213493262
Test: VtsHalGraphicsComposer3_TargetTest
Change-Id: Id74a2c646558d61bb1a8ae80b038f7108e54e636
parent d4c6a656
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -313,6 +313,7 @@ static inline void PrintTo(const LayerSettings& settings, ::std::ostream* os) {
    PrintTo(settings.shadow, os);
    *os << "\n    .stretchEffect = ";
    PrintTo(settings.stretchEffect, os);
    *os << "\n    .whitePointNits = " << settings.whitePointNits;
    *os << "\n}";
}

+1 −0
Original line number Diff line number Diff line
@@ -123,6 +123,7 @@ cc_library_shared {
    srcs: [
        "DebugUtils.cpp",
        "DeviceProductInfo.cpp",
        "DisplayIdentification.cpp",
        "DisplayMode.cpp",
        "DynamicDisplayInfo.cpp",
        "Fence.cpp",
+62 −3
Original line number Diff line number Diff line
@@ -24,12 +24,63 @@

#include <log/log.h>

#include "DisplayIdentification.h"
#include "Hash.h"
#include <ui/DisplayIdentification.h>

namespace android {
namespace {

template <class T>
inline T load(const void* p) {
    static_assert(std::is_integral<T>::value, "T must be integral");

    T r;
    std::memcpy(&r, p, sizeof(r));
    return r;
}

uint64_t rotateByAtLeast1(uint64_t val, uint8_t shift) {
    return (val >> shift) | (val << (64 - shift));
}

uint64_t shiftMix(uint64_t val) {
    return val ^ (val >> 47);
}

uint64_t hash64Len16(uint64_t u, uint64_t v) {
    constexpr uint64_t kMul = 0x9ddfea08eb382d69;
    uint64_t a = (u ^ v) * kMul;
    a ^= (a >> 47);
    uint64_t b = (v ^ a) * kMul;
    b ^= (b >> 47);
    b *= kMul;
    return b;
}

uint64_t hash64Len0To16(const char* s, uint64_t len) {
    constexpr uint64_t k2 = 0x9ae16a3b2f90404f;
    constexpr uint64_t k3 = 0xc949d7c7509e6557;

    if (len > 8) {
        const uint64_t a = load<uint64_t>(s);
        const uint64_t b = load<uint64_t>(s + len - 8);
        return hash64Len16(a, rotateByAtLeast1(b + len, static_cast<uint8_t>(len))) ^ b;
    }
    if (len >= 4) {
        const uint32_t a = load<uint32_t>(s);
        const uint32_t b = load<uint32_t>(s + len - 4);
        return hash64Len16(len + (a << 3), b);
    }
    if (len > 0) {
        const unsigned char a = static_cast<unsigned char>(s[0]);
        const unsigned char b = static_cast<unsigned char>(s[len >> 1]);
        const unsigned char c = static_cast<unsigned char>(s[len - 1]);
        const uint32_t y = static_cast<uint32_t>(a) + (static_cast<uint32_t>(b) << 8);
        const uint32_t z = static_cast<uint32_t>(len) + (static_cast<uint32_t>(c) << 2);
        return shiftMix(y * k2 ^ z * k3) * k2;
    }
    return k2;
}

using byte_view = std::basic_string_view<uint8_t>;

constexpr size_t kEdidBlockSize = 128;
@@ -339,5 +390,13 @@ PhysicalDisplayId getVirtualDisplayId(uint32_t id) {
    return PhysicalDisplayId::fromEdid(0, kVirtualEdidManufacturerId, id);
}

} // namespace android
uint64_t cityHash64Len0To16(std::string_view sv) {
    auto len = sv.length();
    if (len > 16) {
        ALOGE("%s called with length %zu. Only hashing the first 16 chars", __FUNCTION__, len);
        len = 16;
    }
    return hash64Len0To16(sv.data(), len);
}

} // namespace android
 No newline at end of file
+3 −2
Original line number Diff line number Diff line
@@ -31,7 +31,6 @@

namespace android {


using DisplayIdentificationData = std::vector<uint8_t>;

struct DisplayIdentificationInfo {
@@ -81,5 +80,7 @@ std::optional<DisplayIdentificationInfo> parseDisplayIdentificationData(

PhysicalDisplayId getVirtualDisplayId(uint32_t id);

} // namespace android
// CityHash64 implementation that only hashes at most the first 16 characters of the given string.
uint64_t cityHash64Len0To16(std::string_view sv);

} // namespace android
+2 −2
Original line number Diff line number Diff line
@@ -24,12 +24,12 @@
#include <gmock/gmock.h>
#include <gtest/gtest.h>

#include "DisplayHardware/DisplayIdentification.h"
#include "DisplayHardware/Hash.h"
#include <ui/DisplayIdentification.h>

using ::testing::ElementsAre;

namespace android {

namespace {

const unsigned char kInternalEdid[] =
Loading