SF: Plumb physical display IDs to libgui
This CL replaces ISurfaceComposer::{eDisplayIdMain,eDisplayIdHdmi} with
the stable 64-bit display IDs generated by SF. Note that the 64-bit IDs
fall back to the old values if the HWC API for display identification is
not supported.
Bug: 74619554
Test: LocalDisplayAdapter and Choreographer receive 64-bit IDs
Test: 64-bit IDs fall back to 0 and 1 on HWC 2.2 and below
Change-Id: I3c08eff6eb8bb179ecce596ab2820a2aa44c8649
diff --git a/services/surfaceflinger/Scheduler/EventThread.cpp b/services/surfaceflinger/Scheduler/EventThread.cpp
index 52abe9c..91ae087 100644
--- a/services/surfaceflinger/Scheduler/EventThread.cpp
+++ b/services/surfaceflinger/Scheduler/EventThread.cpp
@@ -69,24 +69,28 @@
std::string toString(const DisplayEventReceiver::Event& event) {
switch (event.header.type) {
case DisplayEventReceiver::DISPLAY_EVENT_HOTPLUG:
- return StringPrintf("Hotplug{displayId=%u, %s}", event.header.id,
+ return StringPrintf("Hotplug{displayId=%" ANDROID_PHYSICAL_DISPLAY_ID_FORMAT ", %s}",
+ event.header.displayId,
event.hotplug.connected ? "connected" : "disconnected");
case DisplayEventReceiver::DISPLAY_EVENT_VSYNC:
- return StringPrintf("VSync{displayId=%u, count=%u}", event.header.id,
- event.vsync.count);
+ return StringPrintf("VSync{displayId=%" ANDROID_PHYSICAL_DISPLAY_ID_FORMAT
+ ", count=%u}",
+ event.header.displayId, event.vsync.count);
default:
return "Event{}";
}
}
-DisplayEventReceiver::Event makeHotplug(uint32_t displayId, nsecs_t timestamp, bool connected) {
+DisplayEventReceiver::Event makeHotplug(PhysicalDisplayId displayId, nsecs_t timestamp,
+ bool connected) {
DisplayEventReceiver::Event event;
event.header = {DisplayEventReceiver::DISPLAY_EVENT_HOTPLUG, displayId, timestamp};
event.hotplug.connected = connected;
return event;
}
-DisplayEventReceiver::Event makeVSync(uint32_t displayId, nsecs_t timestamp, uint32_t count) {
+DisplayEventReceiver::Event makeVSync(PhysicalDisplayId displayId, nsecs_t timestamp,
+ uint32_t count) {
DisplayEventReceiver::Event event;
event.header = {DisplayEventReceiver::DISPLAY_EVENT_VSYNC, displayId, timestamp};
event.vsync.count = count;
@@ -290,10 +294,9 @@
mCondition.notify_all();
}
-void EventThread::onHotplugReceived(DisplayType displayType, bool connected) {
+void EventThread::onHotplugReceived(PhysicalDisplayId displayId, bool connected) {
std::lock_guard<std::mutex> lock(mMutex);
- const uint32_t displayId = displayType == DisplayType::Primary ? 0 : 1;
mPendingEvents.push_back(makeHotplug(displayId, systemTime(), connected));
mCondition.notify_all();
}
@@ -312,9 +315,9 @@
switch (event->header.type) {
case DisplayEventReceiver::DISPLAY_EVENT_HOTPLUG:
if (event->hotplug.connected && !mVSyncState) {
- mVSyncState.emplace(event->header.id);
+ mVSyncState.emplace(event->header.displayId);
} else if (!event->hotplug.connected && mVSyncState &&
- mVSyncState->displayId == event->header.id) {
+ mVSyncState->displayId == event->header.displayId) {
mVSyncState.reset();
}
break;
@@ -440,8 +443,9 @@
StringAppendF(&result, "%s: state=%s VSyncState=", mThreadName, toCString(mState));
if (mVSyncState) {
- StringAppendF(&result, "{displayId=%u, count=%u%s}\n", mVSyncState->displayId,
- mVSyncState->count, mVSyncState->synthetic ? ", synthetic" : "");
+ StringAppendF(&result, "{displayId=%" ANDROID_PHYSICAL_DISPLAY_ID_FORMAT ", count=%u%s}\n",
+ mVSyncState->displayId, mVSyncState->count,
+ mVSyncState->synthetic ? ", synthetic" : "");
} else {
StringAppendF(&result, "none\n");
}
diff --git a/services/surfaceflinger/Scheduler/EventThread.h b/services/surfaceflinger/Scheduler/EventThread.h
index 89b799e..62b6a8b 100644
--- a/services/surfaceflinger/Scheduler/EventThread.h
+++ b/services/surfaceflinger/Scheduler/EventThread.h
@@ -94,9 +94,6 @@
class EventThread {
public:
- // TODO: Remove once stable display IDs are plumbed through SF/WM interface.
- enum class DisplayType { Primary, External };
-
virtual ~EventThread();
virtual sp<EventThreadConnection> createEventConnection(
@@ -108,8 +105,7 @@
// called after the screen is turned on from main thread
virtual void onScreenAcquired() = 0;
- // called when receiving a hotplug event
- virtual void onHotplugReceived(DisplayType displayType, bool connected) = 0;
+ virtual void onHotplugReceived(PhysicalDisplayId displayId, bool connected) = 0;
virtual void dump(std::string& result) const = 0;
@@ -151,8 +147,7 @@
// called after the screen is turned on from main thread
void onScreenAcquired() override;
- // called when receiving a hotplug event
- void onHotplugReceived(DisplayType displayType, bool connected) override;
+ void onHotplugReceived(PhysicalDisplayId displayId, bool connected) override;
void dump(std::string& result) const override;
@@ -199,9 +194,9 @@
// VSYNC state of connected display.
struct VSyncState {
- explicit VSyncState(uint32_t displayId) : displayId(displayId) {}
+ explicit VSyncState(PhysicalDisplayId displayId) : displayId(displayId) {}
- const uint32_t displayId;
+ const PhysicalDisplayId displayId;
// Number of VSYNC events since display was connected.
uint32_t count = 0;
diff --git a/services/surfaceflinger/Scheduler/Scheduler.cpp b/services/surfaceflinger/Scheduler/Scheduler.cpp
index 00820f1..a29877e 100644
--- a/services/surfaceflinger/Scheduler/Scheduler.cpp
+++ b/services/surfaceflinger/Scheduler/Scheduler.cpp
@@ -29,7 +29,6 @@
#include <android/hardware/configstore/1.2/ISurfaceFlingerConfigs.h>
#include <configstore/Utils.h>
#include <cutils/properties.h>
-#include <gui/ISurfaceComposer.h>
#include <ui/DisplayStatInfo.h>
#include <utils/Timers.h>
#include <utils/Trace.h>
@@ -128,9 +127,9 @@
}
void Scheduler::hotplugReceived(const sp<Scheduler::ConnectionHandle>& handle,
- EventThread::DisplayType displayType, bool connected) {
+ PhysicalDisplayId displayId, bool connected) {
RETURN_IF_INVALID();
- mConnections[handle->id]->thread->onHotplugReceived(displayType, connected);
+ mConnections[handle->id]->thread->onHotplugReceived(displayId, connected);
}
void Scheduler::onScreenAcquired(const sp<Scheduler::ConnectionHandle>& handle) {
diff --git a/services/surfaceflinger/Scheduler/Scheduler.h b/services/surfaceflinger/Scheduler/Scheduler.h
index b717605..e77dc06 100644
--- a/services/surfaceflinger/Scheduler/Scheduler.h
+++ b/services/surfaceflinger/Scheduler/Scheduler.h
@@ -19,8 +19,8 @@
#include <cstdint>
#include <memory>
-#include <gui/ISurfaceComposer.h>
#include <ui/DisplayStatInfo.h>
+#include <ui/GraphicTypes.h>
#include "DispSync.h"
#include "EventControlThread.h"
@@ -85,7 +85,7 @@
sp<EventThreadConnection> getEventConnection(const sp<ConnectionHandle>& handle);
// Should be called when receiving a hotplug event.
- void hotplugReceived(const sp<ConnectionHandle>& handle, EventThread::DisplayType displayType,
+ void hotplugReceived(const sp<ConnectionHandle>& handle, PhysicalDisplayId displayId,
bool connected);
// Should be called after the screen is turned on.