Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 59954c48 authored by Ben Widawsky's avatar Ben Widawsky
Browse files

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
parent 00488b08
Loading
Loading
Loading
Loading
+7 −7
Original line number Diff line number Diff line
@@ -426,8 +426,8 @@ void EventThread::onVsync(nsecs_t vsyncTime, nsecs_t wakeupTime, nsecs_t readyTi

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

@@ -486,9 +486,9 @@ void EventThread::threadMain(std::unique_lock<std::mutex>& lock) {
            if (event->header.type == DisplayEventReceiver::DISPLAY_EVENT_HOTPLUG) {
                if (event->hotplug.connectionError == 0) {
                    if (event->hotplug.connected && !mVSyncState) {
                        mVSyncState.emplace(event->header.displayId);
                    } else if (!event->hotplug.connected && mVSyncState &&
                               mVSyncState->displayId == event->header.displayId) {
                        mVSyncState.emplace();
                    } else if (!event->hotplug.connected &&
                               mVsyncSchedule->getPhysicalDisplayId() == event->header.displayId) {
                        mVSyncState.reset();
                    }
                } else {
@@ -559,7 +559,7 @@ void EventThread::threadMain(std::unique_lock<std::mutex>& lock) {
                const auto now = systemTime(SYSTEM_TIME_MONOTONIC);
                const auto deadlineTimestamp = now + timeout.count();
                const auto expectedVSyncTime = deadlineTimestamp + timeout.count();
                mPendingEvents.push_back(makeVSync(mVSyncState->displayId, now,
                mPendingEvents.push_back(makeVSync(mVsyncSchedule->getPhysicalDisplayId(), now,
                                                   ++mVSyncState->count, expectedVSyncTime,
                                                   deadlineTimestamp));
            }
@@ -739,7 +739,7 @@ void EventThread::dump(std::string& result) const {
    StringAppendF(&result, "%s: state=%s VSyncState=", mThreadName, toCString(mState));
    if (mVSyncState) {
        StringAppendF(&result, "{displayId=%s, count=%u%s}\n",
                      to_string(mVSyncState->displayId).c_str(), mVSyncState->count,
                      to_string(mVsyncSchedule->getPhysicalDisplayId()).c_str(), mVSyncState->count,
                      mVSyncState->synthetic ? ", synthetic" : "");
    } else {
        StringAppendF(&result, "none\n");
+0 −4
Original line number Diff line number Diff line
@@ -235,10 +235,6 @@ private:

    // VSYNC state of connected display.
    struct VSyncState {
        explicit VSyncState(PhysicalDisplayId displayId) : displayId(displayId) {}

        const PhysicalDisplayId displayId;

        // Number of VSYNC events since display was connected.
        uint32_t count = 0;

+2 −0
Original line number Diff line number Diff line
@@ -112,6 +112,8 @@ public:

    bool getPendingHardwareVsyncState() const REQUIRES(kMainThreadContext);

    PhysicalDisplayId getPhysicalDisplayId() const { return mId; }

protected:
    using ControllerPtr = std::unique_ptr<VsyncController>;