SF: Temporarily expose primary display id
WM needs to know the address of the primary display in order to
consume ro.surface_flinger.primary_display_orientation correctly.
This path will be removed in the future once we support per
display install orientations.
Bug: 196167822
Test: check initial buffer transforms on displays with a different
install orientation
Change-Id: I2b0a92196a8a1f05f7d99b531775b9979f07af98
diff --git a/libs/gui/ISurfaceComposer.cpp b/libs/gui/ISurfaceComposer.cpp
index 3bf6306..3c8289f 100644
--- a/libs/gui/ISurfaceComposer.cpp
+++ b/libs/gui/ISurfaceComposer.cpp
@@ -297,6 +297,20 @@
return {};
}
+ status_t getPrimaryPhysicalDisplayId(PhysicalDisplayId* displayId) const override {
+ Parcel data, reply;
+ SAFE_PARCEL(data.writeInterfaceToken, ISurfaceComposer::getInterfaceDescriptor());
+ SAFE_PARCEL(remote()->transact, BnSurfaceComposer::GET_PRIMARY_PHYSICAL_DISPLAY_ID, data,
+ &reply);
+ uint64_t rawId;
+ SAFE_PARCEL(reply.readUint64, &rawId);
+ if (const auto id = DisplayId::fromValue<PhysicalDisplayId>(rawId)) {
+ *displayId = *id;
+ return NO_ERROR;
+ }
+ return NAME_NOT_FOUND;
+ }
+
sp<IBinder> getPhysicalDisplayToken(PhysicalDisplayId displayId) const override {
Parcel data, reply;
data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor());
@@ -1738,6 +1752,16 @@
[](PhysicalDisplayId id) { return id.value; });
return reply->writeUint64Vector(rawIds);
}
+ case GET_PRIMARY_PHYSICAL_DISPLAY_ID: {
+ CHECK_INTERFACE(ISurfaceComposer, data, reply);
+ PhysicalDisplayId id;
+ status_t result = getPrimaryPhysicalDisplayId(&id);
+ if (result != NO_ERROR) {
+ ALOGE("getPrimaryPhysicalDisplayId: Failed to get id");
+ return result;
+ }
+ return reply->writeUint64(id.value);
+ }
case ADD_REGION_SAMPLING_LISTENER: {
CHECK_INTERFACE(ISurfaceComposer, data, reply);
Rect samplingArea;
diff --git a/libs/gui/SurfaceComposerClient.cpp b/libs/gui/SurfaceComposerClient.cpp
index 1bca6f9..364820e 100644
--- a/libs/gui/SurfaceComposerClient.cpp
+++ b/libs/gui/SurfaceComposerClient.cpp
@@ -937,6 +937,10 @@
return ComposerService::getComposerService()->getPhysicalDisplayIds();
}
+status_t SurfaceComposerClient::getPrimaryPhysicalDisplayId(PhysicalDisplayId* id) {
+ return ComposerService::getComposerService()->getPrimaryPhysicalDisplayId(id);
+}
+
std::optional<PhysicalDisplayId> SurfaceComposerClient::getInternalDisplayId() {
return ComposerService::getComposerService()->getInternalDisplayId();
}
diff --git a/libs/gui/include/gui/ISurfaceComposer.h b/libs/gui/include/gui/ISurfaceComposer.h
index b7cd082..408497d 100644
--- a/libs/gui/include/gui/ISurfaceComposer.h
+++ b/libs/gui/include/gui/ISurfaceComposer.h
@@ -146,6 +146,8 @@
*/
virtual std::vector<PhysicalDisplayId> getPhysicalDisplayIds() const = 0;
+ virtual status_t getPrimaryPhysicalDisplayId(PhysicalDisplayId*) const = 0;
+
// TODO(b/74619554): Remove this stopgap once the framework is display-agnostic.
std::optional<PhysicalDisplayId> getInternalDisplayId() const {
const auto displayIds = getPhysicalDisplayIds();
@@ -630,6 +632,7 @@
REMOVE_TUNNEL_MODE_ENABLED_LISTENER,
ADD_WINDOW_INFOS_LISTENER,
REMOVE_WINDOW_INFOS_LISTENER,
+ GET_PRIMARY_PHYSICAL_DISPLAY_ID,
// Always append new enum to the end.
};
diff --git a/libs/gui/include/gui/SurfaceComposerClient.h b/libs/gui/include/gui/SurfaceComposerClient.h
index baa6878..450e9a0 100644
--- a/libs/gui/include/gui/SurfaceComposerClient.h
+++ b/libs/gui/include/gui/SurfaceComposerClient.h
@@ -308,6 +308,7 @@
//! Get stable IDs for connected physical displays
static std::vector<PhysicalDisplayId> getPhysicalDisplayIds();
+ static status_t getPrimaryPhysicalDisplayId(PhysicalDisplayId*);
static std::optional<PhysicalDisplayId> getInternalDisplayId();
//! Get token for a physical display given its stable ID
diff --git a/libs/gui/tests/Surface_test.cpp b/libs/gui/tests/Surface_test.cpp
index d1ad478..a9f4d09 100644
--- a/libs/gui/tests/Surface_test.cpp
+++ b/libs/gui/tests/Surface_test.cpp
@@ -694,6 +694,7 @@
bool /*secure*/) override { return nullptr; }
void destroyDisplay(const sp<IBinder>& /*display */) override {}
std::vector<PhysicalDisplayId> getPhysicalDisplayIds() const override { return {}; }
+ status_t getPrimaryPhysicalDisplayId(PhysicalDisplayId*) const override { return NO_ERROR; }
sp<IBinder> getPhysicalDisplayToken(PhysicalDisplayId) const override { return nullptr; }
status_t setTransactionState(const FrameTimelineInfo& /*frameTimelineInfo*/,
const Vector<ComposerState>& /*state*/,