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

Commit 433bf9cd authored by Ady Abraham's avatar Ady Abraham
Browse files

SF: flush pending fences before resetting vsync model

This allows using the most recent vsync timestamp for prediction when HWVsync callabcks are enabled.

Bug: 407541438
Bug: 272802278
Test: manual
Flag: com.android.graphics.surfaceflinger.flags.reset_model_flushes_fence
Change-Id: I81035020bd543c8f054c89c77b72fd35b8df6be0
parent e216fbea
Loading
Loading
Loading
Loading
+29 −14
Original line number Diff line number Diff line
@@ -51,6 +51,25 @@ VSyncReactor::VSyncReactor(PhysicalDisplayId id, std::unique_ptr<Clock> clock,

VSyncReactor::~VSyncReactor() = default;

bool VSyncReactor::updateTrackerWithSignaledFences() {
    bool timestampAccepted = true;
    for (auto it = mUnfiredFences.begin(); it != mUnfiredFences.end();) {
        auto const time = FlagManager::getInstance().reset_model_flushes_fence()
                ? (*it)->getSignalTime()
                : (*it)->getCachedSignalTime();
        if (time == Fence::SIGNAL_TIME_PENDING) {
            it++;
        } else if (time == Fence::SIGNAL_TIME_INVALID) {
            it = mUnfiredFences.erase(it);
        } else {
            timestampAccepted &= mTracker.addVsyncTimestamp(time);

            it = mUnfiredFences.erase(it);
        }
    }
    return timestampAccepted;
}

bool VSyncReactor::addPresentFence(std::shared_ptr<FenceTime> fence) {
    SFTRACE_CALL();

@@ -70,20 +89,7 @@ bool VSyncReactor::addPresentFence(std::shared_ptr<FenceTime> fence) {
        return true;
    }

    bool timestampAccepted = true;
    for (auto it = mUnfiredFences.begin(); it != mUnfiredFences.end();) {
        auto const time = (*it)->getCachedSignalTime();
        if (time == Fence::SIGNAL_TIME_PENDING) {
            it++;
        } else if (time == Fence::SIGNAL_TIME_INVALID) {
            it = mUnfiredFences.erase(it);
        } else {
            timestampAccepted &= mTracker.addVsyncTimestamp(time);

            it = mUnfiredFences.erase(it);
        }
    }

    bool timestampAccepted = updateTrackerWithSignaledFences();
    if (signalTime == Fence::SIGNAL_TIME_PENDING) {
        if (mPendingLimit == mUnfiredFences.size()) {
            mUnfiredFences.erase(mUnfiredFences.begin());
@@ -115,6 +121,9 @@ void VSyncReactor::setIgnorePresentFencesInternal(bool ignore) {

void VSyncReactor::updateIgnorePresentFencesInternal() {
    if (mExternalIgnoreFences || mInternalIgnoreFences) {
        if (FlagManager::getInstance().reset_model_flushes_fence()) {
            updateTrackerWithSignaledFences();
        }
        mUnfiredFences.clear();
    }
}
@@ -233,6 +242,12 @@ void VSyncReactor::setDisplayPowerMode(hal::PowerMode powerMode) {
    mDisplayPowerMode = powerMode;
}

void VSyncReactor::resetModel() {
    std::lock_guard lock(mMutex);
    updateTrackerWithSignaledFences();
    mTracker.resetModel();
}

void VSyncReactor::dump(std::string& result) const {
    std::lock_guard lock(mMutex);
    StringAppendF(&result, "VsyncReactor in use\n");
+3 −0
Original line number Diff line number Diff line
@@ -53,6 +53,8 @@ public:

    void setDisplayPowerMode(hal::PowerMode powerMode) final;

    void resetModel() final;

    void dump(std::string& result) const final;

private:
@@ -62,6 +64,7 @@ private:
    void endPeriodTransition() REQUIRES(mMutex);
    bool periodConfirmed(nsecs_t vsync_timestamp, std::optional<nsecs_t> hwcVsyncPeriod)
            REQUIRES(mMutex);
    bool updateTrackerWithSignaledFences() REQUIRES(mMutex);

    const PhysicalDisplayId mId;
    std::unique_ptr<Clock> const mClock;
+5 −0
Original line number Diff line number Diff line
@@ -83,6 +83,11 @@ public:
     */
    virtual void setDisplayPowerMode(hal::PowerMode powerMode) = 0;

    /*
     * Resets the vsync model
     */
    virtual void resetModel() = 0;

    virtual void dump(std::string& result) const = 0;

protected:
+5 −1
Original line number Diff line number Diff line
@@ -184,7 +184,11 @@ void VsyncSchedule::enableHardwareVsync() {
void VsyncSchedule::enableHardwareVsyncLocked() {
    SFTRACE_CALL();
    if (mHwVsyncState == HwVsyncState::Disabled) {
        if (FlagManager::getInstance().reset_model_flushes_fence()) {
            mController->resetModel();
        } else {
            getTracker().resetModel();
        }
        mRequestHardwareVsync(mId, true);
        mHwVsyncState = HwVsyncState::Enabled;
    }
+1 −1
Original line number Diff line number Diff line
@@ -32,7 +32,7 @@ public:
    MOCK_METHOD(void, onDisplayModeChanged, (ftl::NonNull<DisplayModePtr>, bool), (override));
    MOCK_METHOD(void, setIgnorePresentFences, (bool), (override));
    MOCK_METHOD(void, setDisplayPowerMode, (hal::PowerMode), (override));

    MOCK_METHOD(void, resetModel, (), (override));
    MOCK_METHOD(void, dump, (std::string&), (const, override));
};