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

Commit 326ecde6 authored by Ady Abraham's avatar Ady Abraham
Browse files

SurfaceFlinger: fix wake up time when sf duration change

When SF changes its work duration, it may already have a scheduled
wake up callback. In this case the callback needs to be updated with the
new duration.

Bug: 172683933
Test: launch an app and observe systraces
Change-Id: Ie63cd5fa3f82f193cfba031bbbc0b4f8bf8086a9
parent f7dcb569
Loading
Loading
Loading
Loading
+9 −7
Original line number Diff line number Diff line
@@ -90,6 +90,7 @@ void MessageQueue::vsyncCallback(nsecs_t vsyncTime, nsecs_t targetWakeupTime, ns
    {
        std::lock_guard lock(mVsync.mutex);
        mVsync.lastCallbackTime = std::chrono::nanoseconds(vsyncTime);
        mVsync.mScheduled = false;
    }
    mHandler->dispatchInvalidate(mVsync.tokenManager->generateTokenForPredictions(
                                         {targetWakeupTime, readyTime, vsyncTime}),
@@ -114,6 +115,10 @@ void MessageQueue::setDuration(std::chrono::nanoseconds workDuration) {
    ATRACE_CALL();
    std::lock_guard lock(mVsync.mutex);
    mVsync.workDuration = workDuration;
    if (mVsync.mScheduled) {
        mVsync.registration->schedule({mVsync.workDuration.get().count(), /*readyDuration=*/0,
                                       mVsync.lastCallbackTime.count()});
    }
}

void MessageQueue::waitMessage() {
@@ -147,13 +152,10 @@ void MessageQueue::invalidate() {
    if (mEvents) {
        mEvents->requestNextVsync();
    } else {
        const auto [workDuration, lastVsyncCallback] = [&] {
        std::lock_guard lock(mVsync.mutex);
            std::chrono::nanoseconds mWorkDurationNanos = mVsync.workDuration;
            return std::make_pair(mWorkDurationNanos.count(), mVsync.lastCallbackTime.count());
        }();

        mVsync.registration->schedule({workDuration, /*readyDuration=*/0, lastVsyncCallback});
        mVsync.mScheduled = true;
        mVsync.registration->schedule({mVsync.workDuration.get().count(), /*readyDuration=*/0,
                                       mVsync.lastCallbackTime.count()});
    }
}

+1 −0
Original line number Diff line number Diff line
@@ -109,6 +109,7 @@ protected:
        TracedOrdinal<std::chrono::nanoseconds> workDuration
                GUARDED_BY(mutex) = {"VsyncWorkDuration-sf", std::chrono::nanoseconds(0)};
        std::chrono::nanoseconds lastCallbackTime GUARDED_BY(mutex) = std::chrono::nanoseconds{0};
        bool mScheduled GUARDED_BY(mutex) = false;
        TracedOrdinal<int> value = {"VSYNC-sf", 0};
    };

+3 −1
Original line number Diff line number Diff line
@@ -57,7 +57,9 @@ public:
        trace();
    }

    operator T() const { return mData; }
    T get() const { return mData; }

    operator T() const { return get(); }

    TracedOrdinal& operator=(T other) {
        mData = other;