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

Commit 3db93332 authored by Alec Mouri's avatar Alec Mouri Committed by Android (Google) Code Review
Browse files

Merge "When adding event listener, use fuzzy window for last event time."

parents eee90fc4 6db6d622
Loading
Loading
Loading
Loading
+11 −10
Original line number Diff line number Diff line
@@ -211,13 +211,14 @@ public:
            const nsecs_t numPeriodsSinceReference = baseTime / mPeriod;
            const nsecs_t predictedReference = mReferenceTime + numPeriodsSinceReference * mPeriod;
            const nsecs_t phaseCorrection = mPhase + listener.mPhase;
            const nsecs_t predictedLastEventTime = predictedReference + phaseCorrection;
            if (predictedLastEventTime >= now) {
                // Make sure that the last event time does not exceed the current time.
                // If it would, then back the last event time by a period.
                listener.mLastEventTime = predictedLastEventTime - mPeriod;
            } else {
                listener.mLastEventTime = predictedLastEventTime;
            listener.mLastEventTime = predictedReference + phaseCorrection;
            // If we're very close in time to the predicted last event time,
            // then we need to back up the last event time so that we can
            // attempt to fire an event immediately.
            //
            // Otherwise, keep the last event time that we predicted.
            if (isShorterThanPeriod(now - listener.mLastEventTime)) {
                listener.mLastEventTime -= mPeriod;
            }
        } else {
            listener.mLastEventTime = now + mPhase - mWakeupLatency;
@@ -314,7 +315,7 @@ private:

    // Sanity check that the duration is close enough in length to a period without
    // falling into double-rate vsyncs.
    bool isCloseToPeriod(nsecs_t duration) {
    bool isShorterThanPeriod(nsecs_t duration) {
        // Ratio of 3/5 is arbitrary, but it must be greater than 1/2.
        return duration < (3 * mPeriod) / 5;
    }
@@ -330,7 +331,7 @@ private:
            nsecs_t t = computeListenerNextEventTimeLocked(eventListener, onePeriodAgo);

            if (t < now) {
                if (isCloseToPeriod(now - eventListener.mLastCallbackTime)) {
                if (isShorterThanPeriod(now - eventListener.mLastCallbackTime)) {
                    eventListener.mLastEventTime = t;
                    eventListener.mLastCallbackTime = now;
                    ALOGV("[%s] [%s] Skipping event due to model error", mName,
@@ -391,7 +392,7 @@ private:

        // Check that it's been slightly more than half a period since the last
        // event so that we don't accidentally fall into double-rate vsyncs
        if (isCloseToPeriod(t - listener.mLastEventTime)) {
        if (isShorterThanPeriod(t - listener.mLastEventTime)) {
            t += mPeriod;
            ALOGV("[%s] Modifying t -> %" PRId64, mName, ns2us(t));
        }