Use type safe display IDs.
Use a type safe wrapper around uint64_t for display ids.
We also modify the format of the EDID generated physical
display IDs by setting bit 62 to 1, which will indicate
that the display id is stable across reboot.
Bug: 160679868
Test: m && flash device
Test: take screnshot on device
Test: atest surfaceflinger_unittest
Change-Id: Ie2c7c2b737e0882fa4208c059caa85b7ded922b2
diff --git a/libs/gui/ISurfaceComposer.cpp b/libs/gui/ISurfaceComposer.cpp
index 6881be3..762cd10 100644
--- a/libs/gui/ISurfaceComposer.cpp
+++ b/libs/gui/ISurfaceComposer.cpp
@@ -327,8 +327,11 @@
data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
if (remote()->transact(BnSurfaceComposer::GET_PHYSICAL_DISPLAY_IDS, data, &reply) ==
NO_ERROR) {
- std::vector<PhysicalDisplayId> displayIds;
- if (reply.readUint64Vector(&displayIds) == NO_ERROR) {
+ std::vector<uint64_t> rawIds;
+ if (reply.readUint64Vector(&rawIds) == NO_ERROR) {
+ std::vector<PhysicalDisplayId> displayIds(rawIds.size());
+ std::transform(rawIds.begin(), rawIds.end(), displayIds.begin(),
+ [](uint64_t rawId) { return PhysicalDisplayId(rawId); });
return displayIds;
}
}
@@ -339,7 +342,7 @@
virtual sp<IBinder> getPhysicalDisplayToken(PhysicalDisplayId displayId) const {
Parcel data, reply;
data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
- data.writeUint64(displayId);
+ data.writeUint64(displayId.value);
remote()->transact(BnSurfaceComposer::GET_PHYSICAL_DISPLAY_TOKEN, data, &reply);
return reply.readStrongBinder();
}
@@ -1417,7 +1420,7 @@
}
case GET_PHYSICAL_DISPLAY_TOKEN: {
CHECK_INTERFACE(ISurfaceComposer, data, reply);
- PhysicalDisplayId displayId = data.readUint64();
+ PhysicalDisplayId displayId(data.readUint64());
sp<IBinder> display = getPhysicalDisplayToken(displayId);
reply->writeStrongBinder(display);
return NO_ERROR;
@@ -1819,7 +1822,11 @@
}
case GET_PHYSICAL_DISPLAY_IDS: {
CHECK_INTERFACE(ISurfaceComposer, data, reply);
- return reply->writeUint64Vector(getPhysicalDisplayIds());
+ std::vector<PhysicalDisplayId> ids = getPhysicalDisplayIds();
+ std::vector<uint64_t> rawIds(ids.size());
+ std::transform(ids.begin(), ids.end(), rawIds.begin(),
+ [](PhysicalDisplayId id) { return id.value; });
+ return reply->writeUint64Vector(rawIds);
}
case ADD_REGION_SAMPLING_LISTENER: {
CHECK_INTERFACE(ISurfaceComposer, data, reply);