diff options
| author | 2024-09-07 01:13:29 +0000 | |
|---|---|---|
| committer | 2024-09-07 01:13:29 +0000 | |
| commit | 9f4086816e2002ce3c96b11288bb12f05e054d15 (patch) | |
| tree | b7c20ba3622d861a20585319db41de019b4668d5 /libs/ui | |
| parent | 5a473e26703f8b8b90c8a352caf7faed3d896a45 (diff) | |
| parent | 60d226fc1fff9274bbb33d9c7c8a3f1b3724e832 (diff) | |
Merge "Merge 24Q3 to AOSP main" into main
Diffstat (limited to 'libs/ui')
| -rw-r--r-- | libs/ui/Android.bp | 10 | ||||
| -rw-r--r-- | libs/ui/DebugUtils.cpp | 113 | ||||
| -rw-r--r-- | libs/ui/DisplayIdentification.cpp | 67 | ||||
| -rw-r--r-- | libs/ui/GraphicBufferAllocator.cpp | 4 | ||||
| -rw-r--r-- | libs/ui/include/ui/DebugUtils.h | 3 | ||||
| -rw-r--r-- | libs/ui/include/ui/DisplayId.h | 42 | ||||
| -rw-r--r-- | libs/ui/include/ui/DisplayIdentification.h | 3 | ||||
| -rw-r--r-- | libs/ui/include/ui/Gralloc.h | 2 | ||||
| -rw-r--r-- | libs/ui/include/ui/Gralloc5.h | 2 | ||||
| -rw-r--r-- | libs/ui/include/ui/GraphicBufferAllocator.h | 2 | ||||
| -rw-r--r-- | libs/ui/include/ui/LayerStack.h | 4 | ||||
| -rw-r--r-- | libs/ui/include/ui/LogicalDisplayId.h | 59 | ||||
| -rw-r--r-- | libs/ui/tests/DisplayId_test.cpp | 47 | ||||
| -rw-r--r-- | libs/ui/tests/DisplayIdentification_test.cpp | 11 |
14 files changed, 219 insertions, 150 deletions
diff --git a/libs/ui/Android.bp b/libs/ui/Android.bp index 312a1e68b3..12230f99d2 100644 --- a/libs/ui/Android.bp +++ b/libs/ui/Android.bp @@ -277,13 +277,3 @@ subdirs = [ "tests", "tools", ] - -filegroup { - name: "libui_host_common", - srcs: [ - "Rect.cpp", - "Region.cpp", - "PixelFormat.cpp", - "Transform.cpp", - ], -} diff --git a/libs/ui/DebugUtils.cpp b/libs/ui/DebugUtils.cpp index 8675f14d43..bee58e548a 100644 --- a/libs/ui/DebugUtils.cpp +++ b/libs/ui/DebugUtils.cpp @@ -22,14 +22,12 @@ #include <android-base/stringprintf.h> #include <string> -using android::base::StringAppendF; using android::base::StringPrintf; using android::ui::ColorMode; using android::ui::RenderIntent; -std::string decodeStandard(android_dataspace dataspace) { - const uint32_t dataspaceSelect = (dataspace & HAL_DATASPACE_STANDARD_MASK); - switch (dataspaceSelect) { +std::string decodeStandardOnly(uint32_t dataspaceStandard) { + switch (dataspaceStandard) { case HAL_DATASPACE_STANDARD_BT709: return std::string("BT709"); @@ -62,63 +60,44 @@ std::string decodeStandard(android_dataspace dataspace) { case HAL_DATASPACE_STANDARD_ADOBE_RGB: return std::string("AdobeRGB"); - - case 0: - switch (dataspace & 0xffff) { - case HAL_DATASPACE_JFIF: - return std::string("(deprecated) JFIF (BT601_625)"); - - case HAL_DATASPACE_BT601_625: - return std::string("(deprecated) BT601_625"); - - case HAL_DATASPACE_BT601_525: - return std::string("(deprecated) BT601_525"); - - case HAL_DATASPACE_SRGB_LINEAR: - case HAL_DATASPACE_SRGB: - return std::string("(deprecated) sRGB"); - - case HAL_DATASPACE_BT709: - return std::string("(deprecated) BT709"); - - case HAL_DATASPACE_ARBITRARY: - return std::string("ARBITRARY"); - - case HAL_DATASPACE_UNKNOWN: - // Fallthrough - default: - return StringPrintf("Unknown deprecated dataspace code %d", dataspace); - } } - return StringPrintf("Unknown dataspace code %d", dataspaceSelect); + return StringPrintf("Unknown dataspace code %d", dataspaceStandard); } -std::string decodeTransfer(android_dataspace dataspace) { - const uint32_t dataspaceSelect = (dataspace & HAL_DATASPACE_STANDARD_MASK); - if (dataspaceSelect == 0) { +std::string decodeStandard(android_dataspace dataspace) { + const uint32_t dataspaceStandard = (dataspace & HAL_DATASPACE_STANDARD_MASK); + if (dataspaceStandard == 0) { switch (dataspace & 0xffff) { case HAL_DATASPACE_JFIF: + return std::string("(deprecated) JFIF (BT601_625)"); + case HAL_DATASPACE_BT601_625: + return std::string("(deprecated) BT601_625"); + case HAL_DATASPACE_BT601_525: - case HAL_DATASPACE_BT709: - return std::string("SMPTE_170M"); + return std::string("(deprecated) BT601_525"); case HAL_DATASPACE_SRGB_LINEAR: - case HAL_DATASPACE_ARBITRARY: - return std::string("Linear"); - case HAL_DATASPACE_SRGB: - return std::string("sRGB"); + return std::string("(deprecated) sRGB"); + + case HAL_DATASPACE_BT709: + return std::string("(deprecated) BT709"); + + case HAL_DATASPACE_ARBITRARY: + return std::string("ARBITRARY"); case HAL_DATASPACE_UNKNOWN: // Fallthrough default: - return std::string(""); + return StringPrintf("Unknown deprecated dataspace code %d", dataspace); } } + return decodeStandardOnly(dataspaceStandard); +} - const uint32_t dataspaceTransfer = (dataspace & HAL_DATASPACE_TRANSFER_MASK); +std::string decodeTransferOnly(uint32_t dataspaceTransfer) { switch (dataspaceTransfer) { case HAL_DATASPACE_TRANSFER_UNSPECIFIED: return std::string("Unspecified"); @@ -151,29 +130,35 @@ std::string decodeTransfer(android_dataspace dataspace) { return StringPrintf("Unknown dataspace transfer %d", dataspaceTransfer); } -std::string decodeRange(android_dataspace dataspace) { +std::string decodeTransfer(android_dataspace dataspace) { const uint32_t dataspaceSelect = (dataspace & HAL_DATASPACE_STANDARD_MASK); if (dataspaceSelect == 0) { switch (dataspace & 0xffff) { case HAL_DATASPACE_JFIF: - case HAL_DATASPACE_SRGB_LINEAR: - case HAL_DATASPACE_SRGB: - return std::string("Full range"); - case HAL_DATASPACE_BT601_625: case HAL_DATASPACE_BT601_525: case HAL_DATASPACE_BT709: - return std::string("Limited range"); + return std::string("SMPTE_170M"); + case HAL_DATASPACE_SRGB_LINEAR: case HAL_DATASPACE_ARBITRARY: + return std::string("Linear"); + + case HAL_DATASPACE_SRGB: + return std::string("sRGB"); + case HAL_DATASPACE_UNKNOWN: // Fallthrough default: - return std::string("unspecified range"); + return std::string(""); } } - const uint32_t dataspaceRange = (dataspace & HAL_DATASPACE_RANGE_MASK); + const uint32_t dataspaceTransfer = (dataspace & HAL_DATASPACE_TRANSFER_MASK); + return decodeTransferOnly(dataspaceTransfer); +} + +std::string decodeRangeOnly(uint32_t dataspaceRange) { switch (dataspaceRange) { case HAL_DATASPACE_RANGE_UNSPECIFIED: return std::string("Range Unspecified"); @@ -191,6 +176,32 @@ std::string decodeRange(android_dataspace dataspace) { return StringPrintf("Unknown dataspace range %d", dataspaceRange); } +std::string decodeRange(android_dataspace dataspace) { + const uint32_t dataspaceSelect = (dataspace & HAL_DATASPACE_STANDARD_MASK); + if (dataspaceSelect == 0) { + switch (dataspace & 0xffff) { + case HAL_DATASPACE_JFIF: + case HAL_DATASPACE_SRGB_LINEAR: + case HAL_DATASPACE_SRGB: + return std::string("Full range"); + + case HAL_DATASPACE_BT601_625: + case HAL_DATASPACE_BT601_525: + case HAL_DATASPACE_BT709: + return std::string("Limited range"); + + case HAL_DATASPACE_ARBITRARY: + case HAL_DATASPACE_UNKNOWN: + // Fallthrough + default: + return std::string("unspecified range"); + } + } + + const uint32_t dataspaceRange = (dataspace & HAL_DATASPACE_RANGE_MASK); + return decodeRangeOnly(dataspaceRange); +} + std::string dataspaceDetails(android_dataspace dataspace) { if (dataspace == 0) { return "Default"; diff --git a/libs/ui/DisplayIdentification.cpp b/libs/ui/DisplayIdentification.cpp index ed7f1930aa..e5af7406ed 100644 --- a/libs/ui/DisplayIdentification.cpp +++ b/libs/ui/DisplayIdentification.cpp @@ -23,67 +23,13 @@ #include <optional> #include <span> +#include <ftl/hash.h> #include <log/log.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); -} - -__attribute__((no_sanitize("unsigned-integer-overflow"))) -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; -} - -__attribute__((no_sanitize("unsigned-integer-overflow"))) -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::span<const uint8_t>; constexpr size_t kEdidBlockSize = 128; @@ -320,7 +266,7 @@ std::optional<Edid> parseEdid(const DisplayIdentificationData& edid) { // Hash model string instead of using product code or (integer) serial number, since the latter // have been observed to change on some displays with multiple inputs. Use a stable hash instead // of std::hash which is only required to be same within a single execution of a program. - const uint32_t modelHash = static_cast<uint32_t>(cityHash64Len0To16(modelString)); + const uint32_t modelHash = static_cast<uint32_t>(*ftl::stable_hash(modelString)); // Parse extension blocks. std::optional<Cea861ExtensionBlock> cea861Block; @@ -399,13 +345,4 @@ PhysicalDisplayId getVirtualDisplayId(uint32_t id) { return PhysicalDisplayId::fromEdid(0, kVirtualEdidManufacturerId, id); } -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 diff --git a/libs/ui/GraphicBufferAllocator.cpp b/libs/ui/GraphicBufferAllocator.cpp index 98082fb81e..1ebe5973fa 100644 --- a/libs/ui/GraphicBufferAllocator.cpp +++ b/libs/ui/GraphicBufferAllocator.cpp @@ -291,5 +291,9 @@ status_t GraphicBufferAllocator::free(buffer_handle_t handle) return NO_ERROR; } +bool GraphicBufferAllocator::supportsAdditionalOptions() const { + return mAllocator->supportsAdditionalOptions(); +} + // --------------------------------------------------------------------------- }; // namespace android diff --git a/libs/ui/include/ui/DebugUtils.h b/libs/ui/include/ui/DebugUtils.h index 18cd487b8f..7c4ac426c1 100644 --- a/libs/ui/include/ui/DebugUtils.h +++ b/libs/ui/include/ui/DebugUtils.h @@ -27,8 +27,11 @@ struct DeviceProductInfo; } std::string decodeStandard(android_dataspace dataspace); +std::string decodeStandardOnly(uint32_t dataspaceStandard); std::string decodeTransfer(android_dataspace dataspace); +std::string decodeTransferOnly(uint32_t dataspaceTransfer); std::string decodeRange(android_dataspace dataspace); +std::string decodeRangeOnly(uint32_t dataspaceRange); std::string dataspaceDetails(android_dataspace dataspace); std::string decodeColorMode(android::ui::ColorMode colormode); std::string decodeColorTransform(android_color_transform colorTransform); diff --git a/libs/ui/include/ui/DisplayId.h b/libs/ui/include/ui/DisplayId.h index 3a31fa0848..8a14db8ffa 100644 --- a/libs/ui/include/ui/DisplayId.h +++ b/libs/ui/include/ui/DisplayId.h @@ -20,6 +20,7 @@ #include <ostream> #include <string> +#include <ftl/hash.h> #include <ftl/optional.h> namespace android { @@ -38,6 +39,9 @@ struct DisplayId { constexpr DisplayId(const DisplayId&) = default; DisplayId& operator=(const DisplayId&) = default; + constexpr bool isVirtual() const { return value & FLAG_VIRTUAL; } + constexpr bool isStable() const { return value & FLAG_STABLE; } + uint64_t value; // For deserialization. @@ -76,10 +80,10 @@ inline std::ostream& operator<<(std::ostream& stream, DisplayId displayId) { // DisplayId of a physical display, such as the internal display or externally connected display. struct PhysicalDisplayId : DisplayId { static constexpr ftl::Optional<PhysicalDisplayId> tryCast(DisplayId id) { - if (id.value & FLAG_VIRTUAL) { + if (id.isVirtual()) { return std::nullopt; } - return {PhysicalDisplayId(id)}; + return PhysicalDisplayId(id); } // Returns a stable ID based on EDID information. @@ -117,25 +121,23 @@ struct VirtualDisplayId : DisplayId { static constexpr uint64_t FLAG_GPU = 1ULL << 61; static constexpr std::optional<VirtualDisplayId> tryCast(DisplayId id) { - if (id.value & FLAG_VIRTUAL) { - return {VirtualDisplayId(id)}; + if (id.isVirtual()) { + return VirtualDisplayId(id); } return std::nullopt; } protected: - constexpr VirtualDisplayId(uint64_t flags, BaseId baseId) - : DisplayId(DisplayId::FLAG_VIRTUAL | flags | baseId) {} - + explicit constexpr VirtualDisplayId(uint64_t value) : DisplayId(FLAG_VIRTUAL | value) {} explicit constexpr VirtualDisplayId(DisplayId other) : DisplayId(other) {} }; struct HalVirtualDisplayId : VirtualDisplayId { - explicit constexpr HalVirtualDisplayId(BaseId baseId) : VirtualDisplayId(0, baseId) {} + explicit constexpr HalVirtualDisplayId(BaseId baseId) : VirtualDisplayId(baseId) {} static constexpr std::optional<HalVirtualDisplayId> tryCast(DisplayId id) { - if ((id.value & FLAG_VIRTUAL) && !(id.value & VirtualDisplayId::FLAG_GPU)) { - return {HalVirtualDisplayId(id)}; + if (id.isVirtual() && !(id.value & FLAG_GPU)) { + return HalVirtualDisplayId(id); } return std::nullopt; } @@ -145,17 +147,27 @@ private: }; struct GpuVirtualDisplayId : VirtualDisplayId { - explicit constexpr GpuVirtualDisplayId(BaseId baseId) - : VirtualDisplayId(VirtualDisplayId::FLAG_GPU, baseId) {} + explicit constexpr GpuVirtualDisplayId(BaseId baseId) : VirtualDisplayId(FLAG_GPU | baseId) {} + + static constexpr std::optional<GpuVirtualDisplayId> fromUniqueId(const std::string& uniqueId) { + if (const auto hashOpt = ftl::stable_hash(uniqueId)) { + return GpuVirtualDisplayId(HashTag{}, *hashOpt); + } + return {}; + } static constexpr std::optional<GpuVirtualDisplayId> tryCast(DisplayId id) { - if ((id.value & FLAG_VIRTUAL) && (id.value & VirtualDisplayId::FLAG_GPU)) { - return {GpuVirtualDisplayId(id)}; + if (id.isVirtual() && (id.value & FLAG_GPU)) { + return GpuVirtualDisplayId(id); } return std::nullopt; } private: + struct HashTag {}; // Disambiguate with BaseId constructor. + constexpr GpuVirtualDisplayId(HashTag, uint64_t hash) + : VirtualDisplayId(FLAG_STABLE | FLAG_GPU | hash) {} + explicit constexpr GpuVirtualDisplayId(DisplayId other) : VirtualDisplayId(other) {} }; @@ -169,7 +181,7 @@ struct HalDisplayId : DisplayId { if (GpuVirtualDisplayId::tryCast(id)) { return std::nullopt; } - return {HalDisplayId(id)}; + return HalDisplayId(id); } private: diff --git a/libs/ui/include/ui/DisplayIdentification.h b/libs/ui/include/ui/DisplayIdentification.h index fc9c0f491b..8bc2017b55 100644 --- a/libs/ui/include/ui/DisplayIdentification.h +++ b/libs/ui/include/ui/DisplayIdentification.h @@ -80,7 +80,4 @@ std::optional<DisplayIdentificationInfo> parseDisplayIdentificationData( PhysicalDisplayId getVirtualDisplayId(uint32_t id); -// CityHash64 implementation that only hashes at most the first 16 characters of the given string. -uint64_t cityHash64Len0To16(std::string_view sv); - } // namespace android diff --git a/libs/ui/include/ui/Gralloc.h b/libs/ui/include/ui/Gralloc.h index e6015e0b5e..4167dcbab1 100644 --- a/libs/ui/include/ui/Gralloc.h +++ b/libs/ui/include/ui/Gralloc.h @@ -226,6 +226,8 @@ public: const GraphicBufferAllocator::AllocationRequest&) const { return GraphicBufferAllocator::AllocationResult(UNKNOWN_TRANSACTION); } + + virtual bool supportsAdditionalOptions() const { return false; } }; } // namespace android diff --git a/libs/ui/include/ui/Gralloc5.h b/libs/ui/include/ui/Gralloc5.h index f9e8f5e9fd..5aa5019603 100644 --- a/libs/ui/include/ui/Gralloc5.h +++ b/libs/ui/include/ui/Gralloc5.h @@ -178,6 +178,8 @@ public: [[nodiscard]] GraphicBufferAllocator::AllocationResult allocate( const GraphicBufferAllocator::AllocationRequest&) const override; + bool supportsAdditionalOptions() const override { return true; } + private: const Gralloc5Mapper &mMapper; std::shared_ptr<aidl::android::hardware::graphics::allocator::IAllocator> mAllocator; diff --git a/libs/ui/include/ui/GraphicBufferAllocator.h b/libs/ui/include/ui/GraphicBufferAllocator.h index 8f461e193b..bbb2d77058 100644 --- a/libs/ui/include/ui/GraphicBufferAllocator.h +++ b/libs/ui/include/ui/GraphicBufferAllocator.h @@ -107,6 +107,8 @@ public: void dump(std::string& res, bool less = true) const; static void dumpToSystemLog(bool less = true); + bool supportsAdditionalOptions() const; + protected: struct alloc_rec_t { uint32_t width; diff --git a/libs/ui/include/ui/LayerStack.h b/libs/ui/include/ui/LayerStack.h index d6ffeb7fad..f4c8ba250e 100644 --- a/libs/ui/include/ui/LayerStack.h +++ b/libs/ui/include/ui/LayerStack.h @@ -55,6 +55,10 @@ inline bool operator>(LayerStack lhs, LayerStack rhs) { return lhs.id > rhs.id; } +inline bool operator<(LayerStack lhs, LayerStack rhs) { + return lhs.id < rhs.id; +} + // A LayerFilter determines if a layer is included for output to a display. struct LayerFilter { LayerStack layerStack; diff --git a/libs/ui/include/ui/LogicalDisplayId.h b/libs/ui/include/ui/LogicalDisplayId.h new file mode 100644 index 0000000000..fd84b12c22 --- /dev/null +++ b/libs/ui/include/ui/LogicalDisplayId.h @@ -0,0 +1,59 @@ +/* + * Copyright 2024 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#pragma once + +#include <ftl/mixins.h> +#include <sys/types.h> +#include <string> + +#include <ostream> + +namespace android::ui { + +// Type-safe wrapper for a logical display id. +struct LogicalDisplayId : ftl::Constructible<LogicalDisplayId, int32_t>, + ftl::Equatable<LogicalDisplayId>, + ftl::Orderable<LogicalDisplayId> { + using Constructible::Constructible; + + constexpr auto val() const { return ftl::to_underlying(*this); } + + constexpr bool isValid() const { return val() >= 0; } + + std::string toString() const { return std::to_string(val()); } + + static const LogicalDisplayId INVALID; + static const LogicalDisplayId DEFAULT; +}; + +constexpr inline LogicalDisplayId LogicalDisplayId::INVALID{-1}; +constexpr inline LogicalDisplayId LogicalDisplayId::DEFAULT{0}; + +inline std::ostream& operator<<(std::ostream& stream, LogicalDisplayId displayId) { + return stream << displayId.val(); +} + +} // namespace android::ui + +namespace std { +template <> +struct hash<android::ui::LogicalDisplayId> { + size_t operator()(const android::ui::LogicalDisplayId& displayId) const { + return hash<int32_t>()(displayId.val()); + } +}; +} // namespace std
\ No newline at end of file diff --git a/libs/ui/tests/DisplayId_test.cpp b/libs/ui/tests/DisplayId_test.cpp index 8ddee7e740..ef686dfc83 100644 --- a/libs/ui/tests/DisplayId_test.cpp +++ b/libs/ui/tests/DisplayId_test.cpp @@ -24,7 +24,7 @@ TEST(DisplayIdTest, createPhysicalIdFromEdid) { constexpr uint8_t port = 1; constexpr uint16_t manufacturerId = 13; constexpr uint32_t modelHash = 42; - PhysicalDisplayId id = PhysicalDisplayId::fromEdid(port, manufacturerId, modelHash); + const PhysicalDisplayId id = PhysicalDisplayId::fromEdid(port, manufacturerId, modelHash); EXPECT_EQ(port, id.getPort()); EXPECT_EQ(manufacturerId, id.getManufacturerId()); EXPECT_FALSE(VirtualDisplayId::tryCast(id)); @@ -39,7 +39,7 @@ TEST(DisplayIdTest, createPhysicalIdFromEdid) { TEST(DisplayIdTest, createPhysicalIdFromPort) { constexpr uint8_t port = 3; - PhysicalDisplayId id = PhysicalDisplayId::fromPort(port); + const PhysicalDisplayId id = PhysicalDisplayId::fromPort(port); EXPECT_EQ(port, id.getPort()); EXPECT_FALSE(VirtualDisplayId::tryCast(id)); EXPECT_FALSE(HalVirtualDisplayId::tryCast(id)); @@ -52,7 +52,34 @@ TEST(DisplayIdTest, createPhysicalIdFromPort) { } TEST(DisplayIdTest, createGpuVirtualId) { - GpuVirtualDisplayId id(42); + const GpuVirtualDisplayId id(42); + EXPECT_TRUE(VirtualDisplayId::tryCast(id)); + EXPECT_TRUE(GpuVirtualDisplayId::tryCast(id)); + EXPECT_FALSE(HalVirtualDisplayId::tryCast(id)); + EXPECT_FALSE(PhysicalDisplayId::tryCast(id)); + EXPECT_FALSE(HalDisplayId::tryCast(id)); + + EXPECT_EQ(id, DisplayId::fromValue(id.value)); + EXPECT_EQ(id, DisplayId::fromValue<GpuVirtualDisplayId>(id.value)); +} + +TEST(DisplayIdTest, createVirtualIdFromGpuVirtualId) { + const VirtualDisplayId id(GpuVirtualDisplayId(42)); + EXPECT_TRUE(VirtualDisplayId::tryCast(id)); + EXPECT_TRUE(GpuVirtualDisplayId::tryCast(id)); + EXPECT_FALSE(HalVirtualDisplayId::tryCast(id)); + EXPECT_FALSE(PhysicalDisplayId::tryCast(id)); + EXPECT_FALSE(HalDisplayId::tryCast(id)); + + const bool isGpuVirtualId = (id.value & VirtualDisplayId::FLAG_GPU); + EXPECT_EQ((id.isVirtual() && isGpuVirtualId), GpuVirtualDisplayId::tryCast(id).has_value()); +} + +TEST(DisplayIdTest, createGpuVirtualIdFromUniqueId) { + static const std::string kUniqueId("virtual:ui:DisplayId_test"); + const auto idOpt = GpuVirtualDisplayId::fromUniqueId(kUniqueId); + ASSERT_TRUE(idOpt.has_value()); + const GpuVirtualDisplayId id = idOpt.value(); EXPECT_TRUE(VirtualDisplayId::tryCast(id)); EXPECT_TRUE(GpuVirtualDisplayId::tryCast(id)); EXPECT_FALSE(HalVirtualDisplayId::tryCast(id)); @@ -64,7 +91,7 @@ TEST(DisplayIdTest, createGpuVirtualId) { } TEST(DisplayIdTest, createHalVirtualId) { - HalVirtualDisplayId id(42); + const HalVirtualDisplayId id(42); EXPECT_TRUE(VirtualDisplayId::tryCast(id)); EXPECT_TRUE(HalVirtualDisplayId::tryCast(id)); EXPECT_FALSE(GpuVirtualDisplayId::tryCast(id)); @@ -75,4 +102,16 @@ TEST(DisplayIdTest, createHalVirtualId) { EXPECT_EQ(id, DisplayId::fromValue<HalVirtualDisplayId>(id.value)); } +TEST(DisplayIdTest, createVirtualIdFromHalVirtualId) { + const VirtualDisplayId id(HalVirtualDisplayId(42)); + EXPECT_TRUE(VirtualDisplayId::tryCast(id)); + EXPECT_TRUE(HalVirtualDisplayId::tryCast(id)); + EXPECT_FALSE(GpuVirtualDisplayId::tryCast(id)); + EXPECT_FALSE(PhysicalDisplayId::tryCast(id)); + EXPECT_TRUE(HalDisplayId::tryCast(id)); + + const bool isGpuVirtualId = (id.value & VirtualDisplayId::FLAG_GPU); + EXPECT_EQ((id.isVirtual() && !isGpuVirtualId), HalVirtualDisplayId::tryCast(id).has_value()); +} + } // namespace android::ui diff --git a/libs/ui/tests/DisplayIdentification_test.cpp b/libs/ui/tests/DisplayIdentification_test.cpp index 736979a7c5..721b46688e 100644 --- a/libs/ui/tests/DisplayIdentification_test.cpp +++ b/libs/ui/tests/DisplayIdentification_test.cpp @@ -21,9 +21,9 @@ #include <functional> #include <string_view> +#include <ftl/hash.h> #include <gmock/gmock.h> #include <gtest/gtest.h> - #include <ui/DisplayIdentification.h> using ::testing::ElementsAre; @@ -135,7 +135,7 @@ DisplayIdentificationData asDisplayIdentificationData(const unsigned char (&byte } uint32_t hash(const char* str) { - return static_cast<uint32_t>(cityHash64Len0To16(str)); + return static_cast<uint32_t>(*ftl::stable_hash(str)); } } // namespace @@ -188,6 +188,7 @@ TEST(DisplayIdentificationTest, parseEdid) { EXPECT_STREQ("SEC", edid->pnpId.data()); // ASCII text should be used as fallback if display name and serial number are missing. EXPECT_EQ(hash("121AT11-801"), edid->modelHash); + EXPECT_EQ(hash("121AT11-801"), 626564263); EXPECT_TRUE(edid->displayName.empty()); EXPECT_EQ(12610, edid->productId); EXPECT_EQ(21, edid->manufactureOrModelYear); @@ -199,6 +200,7 @@ TEST(DisplayIdentificationTest, parseEdid) { EXPECT_EQ(0x22f0u, edid->manufacturerId); EXPECT_STREQ("HWP", edid->pnpId.data()); EXPECT_EQ(hash("HP ZR30w"), edid->modelHash); + EXPECT_EQ(hash("HP ZR30w"), 918492362); EXPECT_EQ("HP ZR30w", edid->displayName); EXPECT_EQ(10348, edid->productId); EXPECT_EQ(22, edid->manufactureOrModelYear); @@ -210,6 +212,7 @@ TEST(DisplayIdentificationTest, parseEdid) { EXPECT_EQ(0x4c2du, edid->manufacturerId); EXPECT_STREQ("SAM", edid->pnpId.data()); EXPECT_EQ(hash("SAMSUNG"), edid->modelHash); + EXPECT_EQ(hash("SAMSUNG"), 1201368132); EXPECT_EQ("SAMSUNG", edid->displayName); EXPECT_EQ(2302, edid->productId); EXPECT_EQ(21, edid->manufactureOrModelYear); @@ -227,6 +230,7 @@ TEST(DisplayIdentificationTest, parseEdid) { EXPECT_EQ(13481, edid->manufacturerId); EXPECT_STREQ("MEI", edid->pnpId.data()); EXPECT_EQ(hash("Panasonic-TV"), edid->modelHash); + EXPECT_EQ(hash("Panasonic-TV"), 3876373262); EXPECT_EQ("Panasonic-TV", edid->displayName); EXPECT_EQ(41622, edid->productId); EXPECT_EQ(29, edid->manufactureOrModelYear); @@ -244,6 +248,7 @@ TEST(DisplayIdentificationTest, parseEdid) { EXPECT_EQ(8355, edid->manufacturerId); EXPECT_STREQ("HEC", edid->pnpId.data()); EXPECT_EQ(hash("Hisense"), edid->modelHash); + EXPECT_EQ(hash("Hisense"), 2859844809); EXPECT_EQ("Hisense", edid->displayName); EXPECT_EQ(0, edid->productId); EXPECT_EQ(29, edid->manufactureOrModelYear); @@ -261,6 +266,7 @@ TEST(DisplayIdentificationTest, parseEdid) { EXPECT_EQ(3724, edid->manufacturerId); EXPECT_STREQ("CTL", edid->pnpId.data()); EXPECT_EQ(hash("LP2361"), edid->modelHash); + EXPECT_EQ(hash("LP2361"), 1523181158); EXPECT_EQ("LP2361", edid->displayName); EXPECT_EQ(9373, edid->productId); EXPECT_EQ(23, edid->manufactureOrModelYear); @@ -281,6 +287,7 @@ TEST(DisplayIdentificationTest, parseInvalidEdid) { // Serial number should be used as fallback if display name is invalid. const auto modelHash = hash("CN4202137Q"); EXPECT_EQ(modelHash, edid->modelHash); + EXPECT_EQ(modelHash, 3582951527); EXPECT_TRUE(edid->displayName.empty()); // Parsing should succeed even if EDID is truncated. |