@@ -30,27 +30,16 @@ struct DisplayId {
3030 // Flag indicating that the display is virtual.
3131 static constexpr uint64_t FLAG_VIRTUAL = 1ULL << 63 ;
3232
33- // TODO( b/162612135) Remove default constructor
33+ // TODO: b/162612135 - Remove default constructor.
3434 DisplayId () = default ;
3535 constexpr DisplayId (const DisplayId&) = default;
3636 DisplayId& operator =(const DisplayId&) = default ;
3737
38+ static constexpr DisplayId fromValue (uint64_t value) { return DisplayId (value); }
3839 constexpr bool isVirtual () const { return value & FLAG_VIRTUAL; }
3940
4041 uint64_t value;
4142
42- // For deserialization.
43- static constexpr std::optional<DisplayId> fromValue (uint64_t );
44-
45- // As above, but also upcast to Id.
46- template <typename Id>
47- static constexpr std::optional<Id> fromValue (uint64_t value) {
48- if (const auto id = Id::tryCast (DisplayId (value))) {
49- return id;
50- }
51- return {};
52- }
53-
5443protected:
5544 explicit constexpr DisplayId (uint64_t id) : value(id) {}
5645};
@@ -74,6 +63,9 @@ inline std::ostream& operator<<(std::ostream& stream, DisplayId displayId) {
7463
7564// DisplayId of a physical display, such as the internal display or externally connected display.
7665struct PhysicalDisplayId : DisplayId {
66+ // TODO: b/162612135 - Remove default constructor.
67+ PhysicalDisplayId () = default ;
68+
7769 static constexpr ftl::Optional<PhysicalDisplayId> tryCast (DisplayId id) {
7870 if (id.isVirtual ()) {
7971 return std::nullopt ;
@@ -87,20 +79,16 @@ struct PhysicalDisplayId : DisplayId {
8779 return PhysicalDisplayId (FLAG_STABLE, port, manufacturerId, modelHash);
8880 }
8981
90- // Returns a stable and consistent ID based exclusively on EDID information.
91- static constexpr PhysicalDisplayId fromEdidHash (uint64_t hashedEdid) {
92- return PhysicalDisplayId (hashedEdid);
93- }
94-
9582 // Returns an unstable ID. If EDID is available using "fromEdid" is preferred.
9683 static constexpr PhysicalDisplayId fromPort (uint8_t port) {
9784 constexpr uint16_t kManufacturerId = 0 ;
9885 constexpr uint32_t kModelHash = 0 ;
9986 return PhysicalDisplayId (0 , port, kManufacturerId , kModelHash );
10087 }
10188
102- // TODO(b/162612135) Remove default constructor
103- PhysicalDisplayId () = default ;
89+ static constexpr PhysicalDisplayId fromValue (uint64_t value) {
90+ return PhysicalDisplayId (value);
91+ }
10492
10593 constexpr uint8_t getPort () const { return static_cast <uint8_t >(value); }
10694
@@ -131,8 +119,15 @@ struct VirtualDisplayId : DisplayId {
131119 return std::nullopt ;
132120 }
133121
122+ static constexpr VirtualDisplayId fromValue (uint64_t value) {
123+ return VirtualDisplayId (SkipVirtualFlag{}, value);
124+ }
125+
134126protected:
127+ struct SkipVirtualFlag {};
128+ constexpr VirtualDisplayId (SkipVirtualFlag, uint64_t value) : DisplayId(value) {}
135129 explicit constexpr VirtualDisplayId (uint64_t value) : DisplayId(FLAG_VIRTUAL | value) {}
130+
136131 explicit constexpr VirtualDisplayId (DisplayId other) : DisplayId(other) {}
137132};
138133
@@ -146,8 +141,12 @@ struct HalVirtualDisplayId : VirtualDisplayId {
146141 return std::nullopt ;
147142 }
148143
144+ static constexpr HalVirtualDisplayId fromValue (uint64_t value) {
145+ return HalVirtualDisplayId (SkipVirtualFlag{}, value);
146+ }
147+
149148private:
150- explicit constexpr HalVirtualDisplayId (DisplayId other) : VirtualDisplayId(other) {}
149+ using VirtualDisplayId:: VirtualDisplayId;
151150};
152151
153152struct GpuVirtualDisplayId : VirtualDisplayId {
@@ -160,8 +159,12 @@ struct GpuVirtualDisplayId : VirtualDisplayId {
160159 return std::nullopt ;
161160 }
162161
162+ static constexpr GpuVirtualDisplayId fromValue (uint64_t value) {
163+ return GpuVirtualDisplayId (SkipVirtualFlag{}, value);
164+ }
165+
163166private:
164- explicit constexpr GpuVirtualDisplayId (DisplayId other) : VirtualDisplayId(other) {}
167+ using VirtualDisplayId:: VirtualDisplayId;
165168};
166169
167170// HalDisplayId is the ID of a display which is managed by HWC.
@@ -177,20 +180,13 @@ struct HalDisplayId : DisplayId {
177180 return HalDisplayId (id);
178181 }
179182
183+ static constexpr HalDisplayId fromValue (uint64_t value) { return HalDisplayId (value); }
184+
180185private:
186+ using DisplayId::DisplayId;
181187 explicit constexpr HalDisplayId (DisplayId other) : DisplayId(other) {}
182188};
183189
184- constexpr std::optional<DisplayId> DisplayId::fromValue (uint64_t value) {
185- if (const auto id = fromValue<PhysicalDisplayId>(value)) {
186- return id;
187- }
188- if (const auto id = fromValue<VirtualDisplayId>(value)) {
189- return id;
190- }
191- return {};
192- }
193-
194190static_assert (sizeof (DisplayId) == sizeof (uint64_t ));
195191static_assert (sizeof (HalDisplayId) == sizeof (uint64_t ));
196192static_assert (sizeof (VirtualDisplayId) == sizeof (uint64_t ));
0 commit comments