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

Commit 42ccc934 authored by Dominik Laskowski's avatar Dominik Laskowski
Browse files

SF: Extract SurfaceFlinger::wouldPresentEarly

Short-circuit a few fetches and arithmetic operations.

Bug: 241285475
Test: libscheduler_test after Idf9f43b37f3479c94a478d154eaa46f43e0c6c9d
Change-Id: Ib40794cca0c44f8151ca9f37ba58ac4d892c66ee
parent 84a221ab
Loading
Loading
Loading
Loading
+12 −13
Original line number Diff line number Diff line
@@ -2146,7 +2146,13 @@ void SurfaceFlinger::setVsyncEnabled(PhysicalDisplayId id, bool enabled) {
    }));
}

auto SurfaceFlinger::getPreviousPresentFence(TimePoint frameTime, Period vsyncPeriod)
bool SurfaceFlinger::wouldPresentEarly(TimePoint frameTime, Period vsyncPeriod) const {
    const bool isThreeVsyncsAhead = mExpectedPresentTime - frameTime > 2 * vsyncPeriod;
    return isThreeVsyncsAhead ||
            mPreviousPresentFences[0].fenceTime->getSignalTime() != Fence::SIGNAL_TIME_PENDING;
}

auto SurfaceFlinger::getPreviousPresentFence(TimePoint frameTime, Period vsyncPeriod) const
        -> const FenceTimePtr& {
    const bool isTwoVsyncsAhead = mExpectedPresentTime - frameTime > vsyncPeriod;
    const size_t i = static_cast<size_t>(isTwoVsyncsAhead);
@@ -2610,21 +2616,14 @@ void SurfaceFlinger::composite(TimePoint frameTime, VsyncId vsyncId)
        refreshArgs.devOptFlashDirtyRegionsDelay = std::chrono::milliseconds(mDebugFlashDelay);
    }

    const auto prevVsyncTime = mExpectedPresentTime - mScheduler->getVsyncSchedule()->period();
    const auto hwcMinWorkDuration = mVsyncConfiguration->getCurrentConfigs().hwcMinWorkDuration;

    const Period vsyncPeriod = mScheduler->getVsyncSchedule()->period();
    const bool threeVsyncsAhead = mExpectedPresentTime - frameTime > 2 * vsyncPeriod;

    // We should wait for the earliest present time if HWC doesn't support ExpectedPresentTime,
    // and the next vsync is not already taken by the previous frame.
    const bool waitForEarliestPresent =
            !getHwComposer().getComposer()->isSupported(
    if (!getHwComposer().getComposer()->isSupported(
                Hwc2::Composer::OptionalFeature::ExpectedPresentTime) &&
            (threeVsyncsAhead ||
             mPreviousPresentFences[0].fenceTime->getSignalTime() != Fence::SIGNAL_TIME_PENDING);
        wouldPresentEarly(frameTime, vsyncPeriod)) {
        const auto prevVsyncTime = mExpectedPresentTime - vsyncPeriod;
        const auto hwcMinWorkDuration = mVsyncConfiguration->getCurrentConfigs().hwcMinWorkDuration;

    if (waitForEarliestPresent) {
        refreshArgs.earliestPresentTime = prevVsyncTime - hwcMinWorkDuration;
    }

+3 −1
Original line number Diff line number Diff line
@@ -998,7 +998,9 @@ private:

    using FenceTimePtr = std::shared_ptr<FenceTime>;

    const FenceTimePtr& getPreviousPresentFence(TimePoint frameTime, Period)
    bool wouldPresentEarly(TimePoint frameTime, Period) const REQUIRES(kMainThreadContext);

    const FenceTimePtr& getPreviousPresentFence(TimePoint frameTime, Period) const
            REQUIRES(kMainThreadContext);

    // Blocks the thread waiting for up to graceTimeMs in case the fence is about to signal.