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

Commit 73e9ae30 authored by Ady Abraham's avatar Ady Abraham
Browse files

DO NOT MERGE Extend mPreviousPresentFences for high refresh rate

To provide hardware enough time to display a frame under high refresh
rate with long sf-duration, we extend mPreviousPresentFences by storing
extra slots. We check proper present fence at different moment
according to vsync period and sf-duration.

Bug: 241193992
Bug: 361005063
Change-Id: Id44127cb9391799b17834cff0b2e637f273ee2d1
parent 7e84455e
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -106,7 +106,8 @@ protected:
        FenceTimePtr fenceTime = FenceTime::NO_FENCE;
        TimePoint expectedPresentTime = TimePoint();
    };
    std::array<FenceWithFenceTime, 2> mPresentFences;
    // size should be longest sf-duration / shortest vsync period and round up
    std::array<FenceWithFenceTime, 5> mPresentFences; // currently consider 166hz.
    utils::RingBuffer<FenceWithFenceTime, 5> mFenceWithFenceTimes;

    TimePoint mLastSignaledFrameTime;
+22 −4
Original line number Diff line number Diff line
@@ -20,6 +20,20 @@
#include <scheduler/FrameTargeter.h>
#include <scheduler/IVsyncSource.h>

namespace {
size_t getPresentFenceShift(Period minFramePeriod) {
    const bool isTwoVsyncsAhead = targetsVsyncsAhead<2>(minFramePeriod);
    size_t shift = 0;
    if (isTwoVsyncsAhead) {
        shift = static_cast<size_t>(expectedFrameDuration.ns() / minFramePeriod.ns());
        if (shift >= mPresentFences.size()) {
            shift = mPresentFences.size() - 1;
        }
    }
    return shift;
}
} // namespace

namespace android::scheduler {

FrameTarget::FrameTarget(const std::string& displayLabel)
@@ -30,7 +44,7 @@ FrameTarget::FrameTarget(const std::string& displayLabel)

TimePoint FrameTarget::pastVsyncTime(Period minFramePeriod) const {
    // TODO(b/267315508): Generalize to N VSYNCs.
    const int shift = static_cast<int>(targetsVsyncsAhead<2>(minFramePeriod));
    const size_t shift = getPresentFenceShift(minFramePeriod);
    return mExpectedPresentTime - Period::fromNs(minFramePeriod.ns() << shift);
}

@@ -38,8 +52,10 @@ FenceTimePtr FrameTarget::presentFenceForPastVsync(Period minFramePeriod) const
    if (FlagManager::getInstance().allow_n_vsyncs_in_targeter()) {
        return pastVsyncTimePtr();
    }
    const size_t i = static_cast<size_t>(targetsVsyncsAhead<2>(minFramePeriod));
    return mPresentFences[i].fenceTime;

    const size_t shift = getPresentFenceShift(minFramePeriod);
    ATRACE_FORMAT("mPresentFences shift=%zu", shift);
    return mPresentFences[shift].fenceTime;
}

bool FrameTarget::wouldPresentEarly(Period minFramePeriod) const {
@@ -151,7 +167,9 @@ FenceTimePtr FrameTargeter::setPresentFence(sp<Fence> presentFence, FenceTimePtr
    if (FlagManager::getInstance().allow_n_vsyncs_in_targeter()) {
        addFence(std::move(presentFence), presentFenceTime, mExpectedPresentTime);
    } else {
        mPresentFences[1] = mPresentFences[0];
        for (size_t i = mPreviousPresentFences.size()-1; i >= 1; i--) {
            mPresentFences[i] = mPresentFences[i-1];
        }
        mPresentFences[0] = {std::move(presentFence), presentFenceTime, mExpectedPresentTime};
    }
    return presentFenceTime;