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

Commit ae64582b authored by ramindani's avatar ramindani
Browse files

[SF] Updates to not send hints without a present being followed

Updates the hint to be sent through a frame scheduling.
Reduce the number of callbacks to notifyExpectedPresentIfRequired
by making calls only through EventThread.
Timeout hint is sent directly without scheduling a frame
to avoid delay in sending the hint.
A hint through setTransactionState for ScheduleOnTx will
be in a follow up CL

BUG: 316615878
Test: atest NotifyExpectedPresentTest
Change-Id: I60f555d69626656901951808353f4a632e9b5e71
parent 222d83da
Loading
Loading
Loading
Loading
+8 −0
Original line number Diff line number Diff line
@@ -404,6 +404,9 @@ VsyncEventData EventThread::getLatestVsyncEventData(
    }();
    generateFrameTimeline(vsyncEventData, frameInterval.ns(), systemTime(SYSTEM_TIME_MONOTONIC),
                          presentTime, deadline);
    if (FlagManager::getInstance().vrr_config()) {
        mCallback.onExpectedPresentTimePosted(TimePoint::fromNs(presentTime));
    }
    return vsyncEventData;
}

@@ -721,6 +724,11 @@ void EventThread::dispatchEvent(const DisplayEventReceiver::Event& event,
                removeDisplayEventConnectionLocked(consumer);
        }
    }
    if (event.header.type == DisplayEventReceiver::DISPLAY_EVENT_VSYNC &&
        FlagManager::getInstance().vrr_config()) {
        mCallback.onExpectedPresentTimePosted(
                TimePoint::fromNs(event.vsync.vsyncData.preferredExpectedPresentationTime()));
    }
}

void EventThread::dump(std::string& result) const {
+1 −0
Original line number Diff line number Diff line
@@ -142,6 +142,7 @@ struct IEventThreadCallback {
    virtual bool throttleVsync(TimePoint, uid_t) = 0;
    virtual Period getVsyncPeriod(uid_t) = 0;
    virtual void resync() = 0;
    virtual void onExpectedPresentTimePosted(TimePoint) = 0;
};

namespace impl {
+2 −0
Original line number Diff line number Diff line
@@ -30,6 +30,8 @@ struct ISchedulerCallback {
    virtual void kernelTimerChanged(bool expired) = 0;
    virtual void triggerOnFrameRateOverridesChanged() = 0;
    virtual void onChoreographerAttached() = 0;
    virtual void onExpectedPresentTimePosted(TimePoint, ftl::NonNull<DisplayModePtr>,
                                             Fps renderRate) = 0;

protected:
    ~ISchedulerCallback() = default;
+29 −9
Original line number Diff line number Diff line
@@ -71,15 +71,13 @@
namespace android::scheduler {

Scheduler::Scheduler(ICompositor& compositor, ISchedulerCallback& callback, FeatureFlags features,
                     surfaceflinger::Factory& factory, Fps activeRefreshRate, TimeStats& timeStats,
                     IVsyncTrackerCallback& vsyncTrackerCallback)
                     surfaceflinger::Factory& factory, Fps activeRefreshRate, TimeStats& timeStats)
      : android::impl::MessageQueue(compositor),
        mFeatures(features),
        mVsyncConfiguration(factory.createVsyncConfiguration(activeRefreshRate)),
        mVsyncModulator(sp<VsyncModulator>::make(mVsyncConfiguration->getCurrentConfigs())),
        mRefreshRateStats(std::make_unique<RefreshRateStats>(timeStats, activeRefreshRate)),
        mSchedulerCallback(callback),
        mVsyncTrackerCallback(vsyncTrackerCallback) {}
        mSchedulerCallback(callback) {}

Scheduler::~Scheduler() {
    // MessageQueue depends on VsyncSchedule, so first destroy it.
@@ -134,10 +132,11 @@ void Scheduler::setPacesetterDisplay(std::optional<PhysicalDisplayId> pacesetter
}

void Scheduler::registerDisplay(PhysicalDisplayId displayId, RefreshRateSelectorPtr selectorPtr) {
    auto schedulePtr = std::make_shared<VsyncSchedule>(
            selectorPtr->getActiveMode().modePtr, mFeatures,
            [this](PhysicalDisplayId id, bool enable) { onHardwareVsyncRequest(id, enable); },
            mVsyncTrackerCallback);
    auto schedulePtr =
            std::make_shared<VsyncSchedule>(selectorPtr->getActiveMode().modePtr, mFeatures,
                                            [this](PhysicalDisplayId id, bool enable) {
                                                onHardwareVsyncRequest(id, enable);
                                            });

    registerDisplayInternal(displayId, std::move(selectorPtr), std::move(schedulePtr));
}
@@ -222,7 +221,12 @@ void Scheduler::onFrameSignal(ICompositor& compositor, VsyncId vsyncId,
            targets.try_emplace(id, &targeter.target());
        }

        if (!compositor.commit(pacesetterPtr->displayId, targets)) return;
        if (!compositor.commit(pacesetterPtr->displayId, targets)) {
            if (FlagManager::getInstance().vrr_config()) {
                compositor.sendNotifyExpectedPresentHint(pacesetterPtr->displayId);
            }
            return;
        }
    }

    // The pacesetter may have changed or been registered anew during commit.
@@ -263,6 +267,9 @@ void Scheduler::onFrameSignal(ICompositor& compositor, VsyncId vsyncId,
    }

    const auto resultsPerDisplay = compositor.composite(pacesetterPtr->displayId, targeters);
    if (FlagManager::getInstance().vrr_config()) {
        compositor.sendNotifyExpectedPresentHint(pacesetterPtr->displayId);
    }
    compositor.sample();

    for (const auto& [id, targeter] : targeters) {
@@ -323,6 +330,19 @@ Period Scheduler::getVsyncPeriod(uid_t uid) {
    // behaviour.
    return Period::fromNs(currentPeriod.ns() * divisor);
}
void Scheduler::onExpectedPresentTimePosted(TimePoint expectedPresentTime) {
    const auto frameRateMode = [this] {
        std::scoped_lock lock(mDisplayLock);
        const auto pacesetterOpt = pacesetterDisplayLocked();
        const Display& pacesetter = *pacesetterOpt;
        return pacesetter.selectorPtr->getActiveMode();
    }();

    if (frameRateMode.modePtr->getVrrConfig()) {
        mSchedulerCallback.onExpectedPresentTimePosted(expectedPresentTime, frameRateMode.modePtr,
                                                       frameRateMode.fps);
    }
}

ConnectionHandle Scheduler::createEventThread(Cycle cycle,
                                              frametimeline::TokenManager* tokenManager,
+2 −3
Original line number Diff line number Diff line
@@ -111,7 +111,7 @@ class Scheduler : public IEventThreadCallback, android::impl::MessageQueue {

public:
    Scheduler(ICompositor&, ISchedulerCallback&, FeatureFlags, surfaceflinger::Factory&,
              Fps activeRefreshRate, TimeStats&, IVsyncTrackerCallback&);
              Fps activeRefreshRate, TimeStats&);
    virtual ~Scheduler();

    void startTimers();
@@ -458,6 +458,7 @@ private:
    bool throttleVsync(TimePoint, uid_t) override;
    Period getVsyncPeriod(uid_t) override EXCLUDES(mDisplayLock);
    void resync() override EXCLUDES(mDisplayLock);
    void onExpectedPresentTimePosted(TimePoint expectedPresentTime) override EXCLUDES(mDisplayLock);

    // Stores EventThread associated with a given VSyncSource, and an initial EventThreadConnection.
    struct Connection {
@@ -497,8 +498,6 @@ private:

    ISchedulerCallback& mSchedulerCallback;

    IVsyncTrackerCallback& mVsyncTrackerCallback;

    // mDisplayLock may be locked while under mPolicyLock.
    mutable std::mutex mPolicyLock;

Loading