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

Commit 2fd3ceaf authored by Kevin DuBois's avatar Kevin DuBois
Browse files

SF: VSyncReactor add timestamp querying functions

Adds 2 more functions from the DispSync interface to VSyncReactor,
computeNextRefresh, and expectedPresentTime

Bug: 140303479
Test: 3 new units

Change-Id: I75ea79ed749f05daf3337ddc8ca145e2ecceabcd
parent b2501bad
Loading
Loading
Loading
Loading
+15 −6
Original line number Original line Diff line number Diff line
@@ -21,10 +21,24 @@


namespace android::scheduler {
namespace android::scheduler {


class Clock {
public:
    virtual ~Clock();
    /*
     * Returns the SYSTEM_TIME_MONOTONIC, used by testing infra to stub time.
     */
    virtual nsecs_t now() const = 0;

protected:
    Clock() = default;
    Clock(Clock const&) = delete;
    Clock& operator=(Clock const&) = delete;
};

/*
/*
 * TimeKeeper is the interface for a single-shot timer primitive.
 * TimeKeeper is the interface for a single-shot timer primitive.
 */
 */
class TimeKeeper {
class TimeKeeper : public Clock {
public:
public:
    virtual ~TimeKeeper();
    virtual ~TimeKeeper();


@@ -39,11 +53,6 @@ public:
     */
     */
    virtual void alarmCancel() = 0;
    virtual void alarmCancel() = 0;


    /*
     * Returns the SYSTEM_TIME_MONOTONIC, used by testing infra to stub time.
     */
    virtual nsecs_t now() const = 0;

protected:
protected:
    TimeKeeper(TimeKeeper const&) = delete;
    TimeKeeper(TimeKeeper const&) = delete;
    TimeKeeper& operator=(TimeKeeper const&) = delete;
    TimeKeeper& operator=(TimeKeeper const&) = delete;
+5 −0
Original line number Original line Diff line number Diff line
@@ -54,6 +54,11 @@ bool VSyncPredictor::validate(nsecs_t timestamp) const {
    return percent < kOutlierTolerancePercent || percent > (kMaxPercent - kOutlierTolerancePercent);
    return percent < kOutlierTolerancePercent || percent > (kMaxPercent - kOutlierTolerancePercent);
}
}


nsecs_t VSyncPredictor::currentPeriod() const {
    std::lock_guard<std::mutex> lk(mMutex);
    return std::get<0>(mRateMap.find(mIdealPeriod)->second);
}

void VSyncPredictor::addVsyncTimestamp(nsecs_t timestamp) {
void VSyncPredictor::addVsyncTimestamp(nsecs_t timestamp) {
    std::lock_guard<std::mutex> lk(mMutex);
    std::lock_guard<std::mutex> lk(mMutex);


+1 −0
Original line number Original line Diff line number Diff line
@@ -39,6 +39,7 @@ public:


    void addVsyncTimestamp(nsecs_t timestamp) final;
    void addVsyncTimestamp(nsecs_t timestamp) final;
    nsecs_t nextAnticipatedVSyncTimeFrom(nsecs_t timePoint) const final;
    nsecs_t nextAnticipatedVSyncTimeFrom(nsecs_t timePoint) const final;
    nsecs_t currentPeriod() const final;


    /*
    /*
     * Inform the model that the period is anticipated to change to a new value.
     * Inform the model that the period is anticipated to change to a new value.
+16 −2
Original line number Original line Diff line number Diff line
@@ -15,14 +15,18 @@
 */
 */


#include "VSyncReactor.h"
#include "VSyncReactor.h"
#include "TimeKeeper.h"
#include "VSyncDispatch.h"
#include "VSyncDispatch.h"
#include "VSyncTracker.h"
#include "VSyncTracker.h"


namespace android::scheduler {
namespace android::scheduler {


VSyncReactor::VSyncReactor(std::unique_ptr<VSyncDispatch> dispatch,
Clock::~Clock() = default;

VSyncReactor::VSyncReactor(std::unique_ptr<Clock> clock, std::unique_ptr<VSyncDispatch> dispatch,
                           std::unique_ptr<VSyncTracker> tracker, size_t pendingFenceLimit)
                           std::unique_ptr<VSyncTracker> tracker, size_t pendingFenceLimit)
      : mDispatch(std::move(dispatch)),
      : mClock(std::move(clock)),
        mDispatch(std::move(dispatch)),
        mTracker(std::move(tracker)),
        mTracker(std::move(tracker)),
        mPendingLimit(pendingFenceLimit) {}
        mPendingLimit(pendingFenceLimit) {}


@@ -73,4 +77,14 @@ void VSyncReactor::setIgnorePresentFences(bool ignoration) {
    }
    }
}
}


nsecs_t VSyncReactor::computeNextRefresh(int periodOffset) const {
    auto const now = mClock->now();
    auto const currentPeriod = periodOffset ? mTracker->currentPeriod() : 0;
    return mTracker->nextAnticipatedVSyncTimeFrom(now + periodOffset * currentPeriod);
}

nsecs_t VSyncReactor::expectedPresentTime() {
    return mTracker->nextAnticipatedVSyncTimeFrom(mClock->now());
}

} // namespace android::scheduler
} // namespace android::scheduler
+7 −2
Original line number Original line Diff line number Diff line
@@ -24,19 +24,24 @@


namespace android::scheduler {
namespace android::scheduler {


class Clock;
class VSyncDispatch;
class VSyncDispatch;
class VSyncTracker;
class VSyncTracker;


// TODO (b/145217110): consider renaming.
// TODO (b/145217110): consider renaming.
class VSyncReactor /* TODO (b/140201379): : public android::DispSync */ {
class VSyncReactor /* TODO (b/140201379): : public android::DispSync */ {
public:
public:
    VSyncReactor(std::unique_ptr<VSyncDispatch> dispatch, std::unique_ptr<VSyncTracker> tracker,
    VSyncReactor(std::unique_ptr<Clock> clock, std::unique_ptr<VSyncDispatch> dispatch,
                 size_t pendingFenceLimit);
                 std::unique_ptr<VSyncTracker> tracker, size_t pendingFenceLimit);


    bool addPresentFence(const std::shared_ptr<FenceTime>& fence);
    bool addPresentFence(const std::shared_ptr<FenceTime>& fence);
    void setIgnorePresentFences(bool ignoration);
    void setIgnorePresentFences(bool ignoration);


    nsecs_t computeNextRefresh(int periodOffset) const;
    nsecs_t expectedPresentTime();

private:
private:
    std::unique_ptr<Clock> const mClock;
    std::unique_ptr<VSyncDispatch> const mDispatch;
    std::unique_ptr<VSyncDispatch> const mDispatch;
    std::unique_ptr<VSyncTracker> const mTracker;
    std::unique_ptr<VSyncTracker> const mTracker;
    size_t const mPendingLimit;
    size_t const mPendingLimit;
Loading