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

Commit e4f00c5b authored by Vishnu Nair's avatar Vishnu Nair
Browse files

SF: Set eTransactionFlushNeeded after queuing a transaction

Fixes a possible race where the transaction may not be queued
in the binder thread before the main thread wakes up to
flush the queues.

Bug: 251712581
Test: scroll on 90hz device and check all transactions are
applied

Change-Id: I1dbfb2368179d1a101e821e821d1374cd2842965
parent ba75fbf7
Loading
Loading
Loading
Loading
+7 −4
Original line number Diff line number Diff line
@@ -3921,14 +3921,18 @@ uint32_t SurfaceFlinger::getTransactionFlags() const {
}

uint32_t SurfaceFlinger::clearTransactionFlags(uint32_t mask) {
    return mTransactionFlags.fetch_and(~mask) & mask;
    uint32_t transactionFlags = mTransactionFlags.fetch_and(~mask);
    ATRACE_INT("mTransactionFlags", transactionFlags);
    return transactionFlags & mask;
}

void SurfaceFlinger::setTransactionFlags(uint32_t mask, TransactionSchedule schedule,
                                         const sp<IBinder>& applyToken, FrameHint frameHint) {
    mScheduler->modulateVsync({}, &VsyncModulator::setTransactionSchedule, schedule, applyToken);
    uint32_t transactionFlags = mTransactionFlags.fetch_or(mask);
    ATRACE_INT("mTransactionFlags", transactionFlags);

    if (const bool scheduled = mTransactionFlags.fetch_or(mask) & mask; !scheduled) {
    if (const bool scheduled = transactionFlags & mask; !scheduled) {
        scheduleCommit(frameHint);
    } else if (frameHint == FrameHint::kActive) {
        // Even if the next frame is already scheduled, we should reset the idle timer
@@ -4243,9 +4247,8 @@ status_t SurfaceFlinger::setTransactionState(
    }(state.flags);

    const auto frameHint = state.isFrameActive() ? FrameHint::kActive : FrameHint::kNone;
    setTransactionFlags(eTransactionFlushNeeded, schedule, state.applyToken, frameHint);
    mTransactionHandler.queueTransaction(std::move(state));

    setTransactionFlags(eTransactionFlushNeeded, schedule, applyToken, frameHint);
    return NO_ERROR;
}