Skip to content

Commit 59954c4

Browse files
author
Ben Widawsky
committed
SF: Use VsyncSchedule's ID for EventThread
The existing code will take the first display that is hotplugged and set it as the PhysicalDisplayId associated with the EventThread's future vsync events. There isn't anything wrong with this in the current implementation because SurfaceFlinger is careful about removing/adding displays when pacesetter is changed. The EventThread is already associated with a specific VsyncSchedule. The VsyncSchedule already maintains the PhysicalDisplayId. Use that instead and make the code slightly less fragile. Bug: 352324977 Flag: EXEMPT refactor Test: presubmit Change-Id: I33d7da120289e5cf1127d783eae3011280bf65bd
1 parent 00488b0 commit 59954c4

3 files changed

Lines changed: 9 additions & 11 deletions

File tree

services/surfaceflinger/Scheduler/EventThread.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -426,8 +426,8 @@ void EventThread::onVsync(nsecs_t vsyncTime, nsecs_t wakeupTime, nsecs_t readyTi
426426

427427
LOG_FATAL_IF(!mVSyncState);
428428
mVsyncTracer = (mVsyncTracer + 1) % 2;
429-
mPendingEvents.push_back(makeVSync(mVSyncState->displayId, wakeupTime, ++mVSyncState->count,
430-
vsyncTime, readyTime));
429+
mPendingEvents.push_back(makeVSync(mVsyncSchedule->getPhysicalDisplayId(), wakeupTime,
430+
++mVSyncState->count, vsyncTime, readyTime));
431431
mCondition.notify_all();
432432
}
433433

@@ -486,9 +486,9 @@ void EventThread::threadMain(std::unique_lock<std::mutex>& lock) {
486486
if (event->header.type == DisplayEventReceiver::DISPLAY_EVENT_HOTPLUG) {
487487
if (event->hotplug.connectionError == 0) {
488488
if (event->hotplug.connected && !mVSyncState) {
489-
mVSyncState.emplace(event->header.displayId);
490-
} else if (!event->hotplug.connected && mVSyncState &&
491-
mVSyncState->displayId == event->header.displayId) {
489+
mVSyncState.emplace();
490+
} else if (!event->hotplug.connected &&
491+
mVsyncSchedule->getPhysicalDisplayId() == event->header.displayId) {
492492
mVSyncState.reset();
493493
}
494494
} else {
@@ -559,7 +559,7 @@ void EventThread::threadMain(std::unique_lock<std::mutex>& lock) {
559559
const auto now = systemTime(SYSTEM_TIME_MONOTONIC);
560560
const auto deadlineTimestamp = now + timeout.count();
561561
const auto expectedVSyncTime = deadlineTimestamp + timeout.count();
562-
mPendingEvents.push_back(makeVSync(mVSyncState->displayId, now,
562+
mPendingEvents.push_back(makeVSync(mVsyncSchedule->getPhysicalDisplayId(), now,
563563
++mVSyncState->count, expectedVSyncTime,
564564
deadlineTimestamp));
565565
}
@@ -739,7 +739,7 @@ void EventThread::dump(std::string& result) const {
739739
StringAppendF(&result, "%s: state=%s VSyncState=", mThreadName, toCString(mState));
740740
if (mVSyncState) {
741741
StringAppendF(&result, "{displayId=%s, count=%u%s}\n",
742-
to_string(mVSyncState->displayId).c_str(), mVSyncState->count,
742+
to_string(mVsyncSchedule->getPhysicalDisplayId()).c_str(), mVSyncState->count,
743743
mVSyncState->synthetic ? ", synthetic" : "");
744744
} else {
745745
StringAppendF(&result, "none\n");

services/surfaceflinger/Scheduler/EventThread.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -235,10 +235,6 @@ class EventThread : public android::EventThread {
235235

236236
// VSYNC state of connected display.
237237
struct VSyncState {
238-
explicit VSyncState(PhysicalDisplayId displayId) : displayId(displayId) {}
239-
240-
const PhysicalDisplayId displayId;
241-
242238
// Number of VSYNC events since display was connected.
243239
uint32_t count = 0;
244240

services/surfaceflinger/Scheduler/VsyncSchedule.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,8 @@ class VsyncSchedule final : public IVsyncSource {
112112

113113
bool getPendingHardwareVsyncState() const REQUIRES(kMainThreadContext);
114114

115+
PhysicalDisplayId getPhysicalDisplayId() const { return mId; }
116+
115117
protected:
116118
using ControllerPtr = std::unique_ptr<VsyncController>;
117119

0 commit comments

Comments
 (0)