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

Commit 11b6a70c authored by Ady Abraham's avatar Ady Abraham
Browse files

SurfaceFlinger: correct negative offset when refresh rate changes

VsyncModulator sets the phase offset on DispSync source only when it
changes. However, negative offsets depends on the vsync period so setting
the same negative offset might result in a different wake up time
i.e. -5ms on 60Hz is 11ms after the previous vsync where on 90Hz is
6ms after the previous vsync.

Test: UI-Bench
Bug: 135283780
Bug: 135297302
Change-Id: I6a05cd48d563a51d2ee38927c23d4946dd142f4b
parent 42b3beb5
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -78,6 +78,10 @@ void DispSyncSource::setPhaseOffset(nsecs_t phaseOffset) {
    // Normalize phaseOffset to [-period, period)
    const int numPeriods = phaseOffset / period;
    phaseOffset -= numPeriods * period;
    if (mPhaseOffset == phaseOffset) {
        return;
    }

    mPhaseOffset = phaseOffset;
    tracePhaseOffset();

+7 −20
Original line number Diff line number Diff line
@@ -129,30 +129,17 @@ void VSyncModulator::updateOffsets() {

void VSyncModulator::updateOffsetsLocked() {
    const Offsets desired = getNextOffsets();
    const Offsets current = mOffsets;

    bool changed = false;
    if (desired.sf != current.sf) {
    if (mSfConnectionHandle != nullptr) {
        mScheduler->setPhaseOffset(mSfConnectionHandle, desired.sf);
        } else if (mSfEventThread != nullptr) {
            mSfEventThread->setPhaseOffset(desired.sf);
    }
        changed = true;
    }
    if (desired.app != current.app) {

    if (mAppConnectionHandle != nullptr) {
        mScheduler->setPhaseOffset(mAppConnectionHandle, desired.app);
        } else if (mAppEventThread != nullptr) {
            mAppEventThread->setPhaseOffset(desired.app);
        }
        changed = true;
    }

    if (changed) {
    flushOffsets();
}
}

void VSyncModulator::flushOffsets() {
    OffsetType type = getNextOffsetType();
+0 −9
Original line number Diff line number Diff line
@@ -68,12 +68,6 @@ public:
    void setPhaseOffsets(Offsets early, Offsets earlyGl, Offsets late,
                         nsecs_t thresholdForNextVsync) EXCLUDES(mMutex);

    // Sets handles to the SF and app event threads.
    void setEventThreads(EventThread* sfEventThread, EventThread* appEventThread) {
        mSfEventThread = sfEventThread;
        mAppEventThread = appEventThread;
    }

    // Sets the scheduler and vsync connection handlers.
    void setSchedulerAndHandles(Scheduler* scheduler,
                                Scheduler::ConnectionHandle* appConnectionHandle,
@@ -121,9 +115,6 @@ private:
    std::unordered_map<OffsetType, Offsets> mOffsetMap GUARDED_BY(mMutex);
    nsecs_t mThresholdForNextVsync;

    EventThread* mSfEventThread = nullptr;
    EventThread* mAppEventThread = nullptr;

    Scheduler* mScheduler = nullptr;
    Scheduler::ConnectionHandle* mAppConnectionHandle = nullptr;
    Scheduler::ConnectionHandle* mSfConnectionHandle = nullptr;