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

Commit caeea929 authored by Ady Abraham's avatar Ady Abraham Committed by Android (Google) Code Review
Browse files

Merge "SurfaceFlinger: use intended wake up time when calculating next present time" into rvc-dev

parents 6191fe5a 0ed31c94
Loading
Loading
Loading
Loading
+3 −4
Original line number Diff line number Diff line
@@ -768,9 +768,8 @@ void DispSync::resetErrorLocked() {
    }
}

nsecs_t DispSync::computeNextRefresh(int periodOffset) const {
nsecs_t DispSync::computeNextRefresh(int periodOffset, nsecs_t now) const {
    Mutex::Autolock lock(mMutex);
    nsecs_t now = systemTime(SYSTEM_TIME_MONOTONIC);
    nsecs_t phase = mReferenceTime + mPhase;
    if (mPeriod == 0) {
        return 0;
@@ -837,7 +836,7 @@ void DispSync::dump(std::string& result) const {
    StringAppendF(&result, "current monotonic time: %" PRId64 "\n", now);
}

nsecs_t DispSync::expectedPresentTime() {
nsecs_t DispSync::expectedPresentTime(nsecs_t now) {
    // The HWC doesn't currently have a way to report additional latency.
    // Assume that whatever we submit now will appear right after the flip.
    // For a smart panel this might be 1.  This is expressed in frames,
@@ -846,7 +845,7 @@ nsecs_t DispSync::expectedPresentTime() {
    const uint32_t hwcLatency = 0;

    // Ask DispSync when the next refresh will be (CLOCK_MONOTONIC).
    return computeNextRefresh(hwcLatency);
    return computeNextRefresh(hwcLatency, now);
}

} // namespace impl
+4 −4
Original line number Diff line number Diff line
@@ -58,9 +58,9 @@ public:
                                      nsecs_t lastCallbackTime) = 0;
    virtual status_t removeEventListener(Callback* callback, nsecs_t* outLastCallback) = 0;
    virtual status_t changePhaseOffset(Callback* callback, nsecs_t phase) = 0;
    virtual nsecs_t computeNextRefresh(int periodOffset) const = 0;
    virtual nsecs_t computeNextRefresh(int periodOffset, nsecs_t now) const = 0;
    virtual void setIgnorePresentFences(bool ignore) = 0;
    virtual nsecs_t expectedPresentTime() = 0;
    virtual nsecs_t expectedPresentTime(nsecs_t now) = 0;

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

@@ -167,7 +167,7 @@ public:
    // The periodOffset value can be used to move forward or backward; an
    // offset of zero is the next refresh, -1 is the previous refresh, 1 is
    // the refresh after next. etc.
    nsecs_t computeNextRefresh(int periodOffset) const override;
    nsecs_t computeNextRefresh(int periodOffset, nsecs_t now) const override;

    // In certain situations the present fences aren't a good indicator of vsync
    // time, e.g. when vr flinger is active, or simply aren't available,
@@ -178,7 +178,7 @@ public:
    void setIgnorePresentFences(bool ignore) override;

    // Determine the expected present time when a buffer acquired now will be displayed.
    nsecs_t expectedPresentTime();
    nsecs_t expectedPresentTime(nsecs_t now);

    // dump appends human-readable debug info to the result string.
    void dump(std::string& result) const override;
+5 −4
Original line number Diff line number Diff line
@@ -62,8 +62,9 @@ void MessageQueue::Handler::dispatchRefresh() {
    }
}

void MessageQueue::Handler::dispatchInvalidate() {
void MessageQueue::Handler::dispatchInvalidate(nsecs_t timestamp) {
    if ((android_atomic_or(eventMaskInvalidate, &mEventMask) & eventMaskInvalidate) == 0) {
        mLastVsyncTime = timestamp;
        mQueue.mLooper->sendMessage(this, Message(MessageQueue::INVALIDATE));
    }
}
@@ -72,11 +73,11 @@ void MessageQueue::Handler::handleMessage(const Message& message) {
    switch (message.what) {
        case INVALIDATE:
            android_atomic_and(~eventMaskInvalidate, &mEventMask);
            mQueue.mFlinger->onMessageReceived(message.what);
            mQueue.mFlinger->onMessageReceived(message.what, mLastVsyncTime);
            break;
        case REFRESH:
            android_atomic_and(~eventMaskRefresh, &mEventMask);
            mQueue.mFlinger->onMessageReceived(message.what);
            mQueue.mFlinger->onMessageReceived(message.what, mLastVsyncTime);
            break;
    }
}
@@ -151,7 +152,7 @@ int MessageQueue::eventReceiver(int /*fd*/, int /*events*/) {
    while ((n = DisplayEventReceiver::getEvents(&mEventTube, buffer, 8)) > 0) {
        for (int i = 0; i < n; i++) {
            if (buffer[i].header.type == DisplayEventReceiver::DISPLAY_EVENT_VSYNC) {
                mHandler->dispatchInvalidate();
                mHandler->dispatchInvalidate(buffer[i].header.timestamp);
                break;
            }
        }
+2 −1
Original line number Diff line number Diff line
@@ -101,12 +101,13 @@ class MessageQueue final : public android::MessageQueue {
        enum { eventMaskInvalidate = 0x1, eventMaskRefresh = 0x2, eventMaskTransaction = 0x4 };
        MessageQueue& mQueue;
        int32_t mEventMask;
        std::atomic<nsecs_t> mLastVsyncTime;

    public:
        explicit Handler(MessageQueue& queue) : mQueue(queue), mEventMask(0) {}
        virtual void handleMessage(const Message& message);
        void dispatchRefresh();
        void dispatchInvalidate();
        void dispatchInvalidate(nsecs_t timestamp);
    };

    friend class Handler;
+3 −3
Original line number Diff line number Diff line
@@ -250,7 +250,7 @@ void Scheduler::setPhaseOffset(ConnectionHandle handle, nsecs_t phaseOffset) {
}

void Scheduler::getDisplayStatInfo(DisplayStatInfo* stats) {
    stats->vsyncTime = mPrimaryDispSync->computeNextRefresh(0);
    stats->vsyncTime = mPrimaryDispSync->computeNextRefresh(0, systemTime());
    stats->vsyncPeriod = mPrimaryDispSync->getPeriod();
}

@@ -378,8 +378,8 @@ void Scheduler::setIgnorePresentFences(bool ignore) {
    mPrimaryDispSync->setIgnorePresentFences(ignore);
}

nsecs_t Scheduler::getDispSyncExpectedPresentTime() {
    return mPrimaryDispSync->expectedPresentTime();
nsecs_t Scheduler::getDispSyncExpectedPresentTime(nsecs_t now) {
    return mPrimaryDispSync->expectedPresentTime(now);
}

void Scheduler::registerLayer(Layer* layer) {
Loading