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

Commit 63258a15 authored by Valerie Hau's avatar Valerie Hau
Browse files

Modifying TransactionCompletedListener to pass back present fence

Bug: 120919468
Test: build, boot, SurfaceFlinger_test
Change-Id: Id3d3b34ffa30291f3dd27040bf97ccd1492e7f9d
parent d85333dd
Loading
Loading
Loading
Loading
+18 −2
Original line number Diff line number Diff line
@@ -59,7 +59,15 @@ status_t TransactionStats::writeToParcel(Parcel* output) const {
    if (err != NO_ERROR) {
        return err;
    }
    err = output->writeInt64(presentTime);
    if (presentFence) {
        err = output->writeBool(true);
        if (err != NO_ERROR) {
            return err;
        }
        err = output->write(*presentFence);
    } else {
        err = output->writeBool(false);
    }
    if (err != NO_ERROR) {
        return err;
    }
@@ -71,10 +79,18 @@ status_t TransactionStats::readFromParcel(const Parcel* input) {
    if (err != NO_ERROR) {
        return err;
    }
    err = input->readInt64(&presentTime);
    bool hasFence = false;
    err = input->readBool(&hasFence);
    if (err != NO_ERROR) {
        return err;
    }
    if (hasFence) {
        presentFence = new Fence();
        err = input->read(*presentFence);
        if (err != NO_ERROR) {
            return err;
        }
    }
    return input->readParcelableVector(&surfaceStats);
}

+2 −1
Original line number Diff line number Diff line
@@ -21,6 +21,7 @@
#include <binder/Parcelable.h>
#include <binder/SafeInterface.h>

#include <ui/Fence.h>
#include <utils/Timers.h>

#include <cstdint>
@@ -65,7 +66,7 @@ public:
    status_t readFromParcel(const Parcel* input) override;

    nsecs_t latchTime = -1;
    nsecs_t presentTime = -1;
    sp<Fence> presentFence = nullptr;
    std::vector<SurfaceStats> surfaceStats;
};

+2 −20
Original line number Diff line number Diff line
@@ -151,18 +151,6 @@ void TransactionCompletedThread::threadMain() {
    while (mKeepRunning) {
        mConditionVariable.wait(mMutex);

        // Present fence should fire almost immediately. If the fence has not signaled in 100ms,
        // there is a major problem and it will probably never fire.
        nsecs_t presentTime = -1;
        if (mPresentFence) {
            status_t status = mPresentFence->wait(100);
            if (status == NO_ERROR) {
                presentTime = mPresentFence->getSignalTime();
            } else {
                ALOGE("present fence has not signaled, err %d", status);
            }
        }

        // We should never hit this case. The release fences from the previous frame should have
        // signaled long before the current frame is presented.
        for (const auto& fence : mPreviousReleaseFences) {
@@ -188,17 +176,11 @@ void TransactionCompletedThread::threadMain() {

                // If the transaction has been latched
                if (transactionStats.latchTime >= 0) {
                    // If the present time is < 0, this transaction has been latched but not
                    // presented. Skip it for now. This can happen when a new transaction comes
                    // in between the latch and present steps. sendCallbacks is called by
                    // SurfaceFlinger when the transaction is received to ensure that if the
                    // transaction that didn't update state it still got a callback.
                    if (presentTime < 0) {
                    if (!mPresentFence) {
                        sendCallback = false;
                        break;
                    }

                    transactionStats.presentTime = presentTime;
                    transactionStats.presentFence = mPresentFence;
                }
            }
            // If the listener has no pending transactions and all latched transactions have been
+3 −3
Original line number Diff line number Diff line
@@ -2502,12 +2502,12 @@ public:
    }

    void verifyTransactionStats(const TransactionStats& transactionStats) const {
        const auto& [latchTime, presentTime, surfaceStats] = transactionStats;
        const auto& [latchTime, presentFence, surfaceStats] = transactionStats;
        if (mTransactionResult == ExpectedResult::Transaction::PRESENTED) {
            ASSERT_GE(latchTime, 0) << "bad latch time";
            ASSERT_GE(presentTime, 0) << "bad present time";
            ASSERT_NE(presentFence, nullptr);
        } else {
            ASSERT_EQ(presentTime, -1) << "transaction shouldn't have been presented";
            ASSERT_EQ(presentFence, nullptr) << "transaction shouldn't have been presented";
            ASSERT_EQ(latchTime, -1) << "unpresented transactions shouldn't be latched";
        }