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

Commit cc138dad authored by Ady Abraham's avatar Ady Abraham
Browse files

SF: add the first vsync timestamp when confirming period

Test: presubmit
Bug: 422343157
Flag: com.android.graphics.surfaceflinger.flags.add_first_vsync_to_tracker
Change-Id: I32346436cb9e1eed5a86c4035e7af3438523e251
parent 99eac0f4
Loading
Loading
Loading
Loading
+12 −7
Original line number Original line Diff line number Diff line
@@ -170,7 +170,7 @@ bool VSyncReactor::periodConfirmed(nsecs_t vsync_timestamp, std::optional<nsecs_
        return true;
        return true;
    }
    }


    if (!mLastHwVsync && !HwcVsyncPeriod) {
    if (!mLastHwVsync.get() && !HwcVsyncPeriod) {
        return false;
        return false;
    }
    }


@@ -191,7 +191,7 @@ bool VSyncReactor::periodConfirmed(nsecs_t vsync_timestamp, std::optional<nsecs_
        return std::abs(*HwcVsyncPeriod - period) < allowance;
        return std::abs(*HwcVsyncPeriod - period) < allowance;
    }
    }


    auto const distance = vsync_timestamp - *mLastHwVsync;
    auto const distance = vsync_timestamp - *mLastHwVsync.get();
    return std::abs(distance - period) < allowance;
    return std::abs(distance - period) < allowance;
}
}


@@ -207,8 +207,9 @@ bool VSyncReactor::addHwVsyncTimestamp(nsecs_t timestamp, std::optional<nsecs_t>
            *periodFlushed = true;
            *periodFlushed = true;
        }
        }


        if (mLastHwVsync) {
        if (mLastHwVsync.get() &&
            mTracker.addVsyncTimestamp(*mLastHwVsync);
            (!FlagManager::getInstance().add_first_vsync_to_tracker() || !mLastHwVsync.isFirst())) {
            mTracker.addVsyncTimestamp(*mLastHwVsync.get());
        }
        }
        mTracker.addVsyncTimestamp(timestamp);
        mTracker.addVsyncTimestamp(timestamp);


@@ -216,7 +217,11 @@ bool VSyncReactor::addHwVsyncTimestamp(nsecs_t timestamp, std::optional<nsecs_t>
        mMoreSamplesNeeded = mTracker.needsMoreSamples();
        mMoreSamplesNeeded = mTracker.needsMoreSamples();
    } else if (mPeriodConfirmationInProgress) {
    } else if (mPeriodConfirmationInProgress) {
        SFTRACE_FORMAT("VSR %" PRIu64 ": still confirming period", mId.value);
        SFTRACE_FORMAT("VSR %" PRIu64 ": still confirming period", mId.value);
        mLastHwVsync = timestamp;
        mLastHwVsync.set(timestamp);
        // Add the first vsync callback to the tracker to be based on a fresh vsync
        if (FlagManager::getInstance().add_first_vsync_to_tracker() && mLastHwVsync.isFirst()) {
            mTracker.addVsyncTimestamp(*mLastHwVsync.get());
        }
        mMoreSamplesNeeded = true;
        mMoreSamplesNeeded = true;
        *periodFlushed = false;
        *periodFlushed = false;
    } else {
    } else {
@@ -263,9 +268,9 @@ void VSyncReactor::dump(std::string& result) const {
        StringAppendF(&result, "mModePtrTransitioningTo=nullptr\n");
        StringAppendF(&result, "mModePtrTransitioningTo=nullptr\n");
    }
    }


    if (mLastHwVsync) {
    if (mLastHwVsync.get()) {
        StringAppendF(&result, "Last HW vsync was %.2fms ago\n",
        StringAppendF(&result, "Last HW vsync was %.2fms ago\n",
                      (mClock->now() - *mLastHwVsync) / 1e6f);
                      (mClock->now() - *mLastHwVsync.get()) / 1e6f);
    } else {
    } else {
        StringAppendF(&result, "No Last HW vsync\n");
        StringAppendF(&result, "No Last HW vsync\n");
    }
    }
+22 −1
Original line number Original line Diff line number Diff line
@@ -79,7 +79,28 @@ private:
    bool mMoreSamplesNeeded GUARDED_BY(mMutex) = false;
    bool mMoreSamplesNeeded GUARDED_BY(mMutex) = false;
    bool mPeriodConfirmationInProgress GUARDED_BY(mMutex) = false;
    bool mPeriodConfirmationInProgress GUARDED_BY(mMutex) = false;
    DisplayModePtr mModePtrTransitioningTo GUARDED_BY(mMutex);
    DisplayModePtr mModePtrTransitioningTo GUARDED_BY(mMutex);
    std::optional<nsecs_t> mLastHwVsync GUARDED_BY(mMutex);

    class LastHwVsync {
    public:
        LastHwVsync() { reset(); }
        void reset() {
            mFirst = true;
            mVsync.reset();
        }
        bool isFirst() const { return mFirst; }
        std::optional<nsecs_t> get() const { return mVsync; }
        void set(nsecs_t vsync) {
            if (mVsync.has_value()) {
                mFirst = false;
            }
            mVsync = vsync;
        }

    private:
        bool mFirst;
        std::optional<nsecs_t> mVsync;
    };
    LastHwVsync mLastHwVsync GUARDED_BY(mMutex);


    hal::PowerMode mDisplayPowerMode GUARDED_BY(mMutex) = hal::PowerMode::ON;
    hal::PowerMode mDisplayPowerMode GUARDED_BY(mMutex) = hal::PowerMode::ON;