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

Commit 458df796 authored by Vishnu Nair's avatar Vishnu Nair Committed by Automerger Merge Worker
Browse files

Merge "Check transaction queues when dropping or queuing buffers" into sc-dev am: f3ba25b2

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/native/+/13473859

MUST ONLY BE SUBMITTED BY AUTOMERGER

Change-Id: Ic54a9fa24e64217690181913b883811dab411564
parents 7208a6cc f3ba25b2
Loading
Loading
Loading
Loading
+0 −1
Original line number Diff line number Diff line
@@ -937,7 +937,6 @@ public:
    bool mPendingHWCDestroy{false};

    bool backpressureEnabled() { return mDrawingState.flags & layer_state_t::eEnableBackpressure; }
    bool hasPendingBuffer() { return mCurrentState.buffer != mDrawingState.buffer; };

protected:
    class SyncPoint {
+66 −58
Original line number Diff line number Diff line
@@ -3291,6 +3291,10 @@ void SurfaceFlinger::flushTransactionQueues() {
    // we must keep a copy of the transactions (specifically the composer
    // states) around outside the scope of the lock
    std::vector<const TransactionState> transactions;
    // Layer handles that have transactions with buffers that are ready to be applied.
    std::unordered_set<sp<IBinder>, ISurfaceComposer::SpHash<IBinder>> pendingBuffers;
    {
        Mutex::Autolock _l(mStateLock);
        {
            Mutex::Autolock _l(mQueueLock);
            // Collect transactions from pending transaction queue.
@@ -3302,7 +3306,9 @@ void SurfaceFlinger::flushTransactionQueues() {
                    const auto& transaction = transactionQueue.front();
                    if (!transactionIsReadyToBeApplied(transaction.isAutoTimestamp,
                                                       transaction.desiredPresentTime,
                                                   transaction.states)) {
                                                       transaction.states,
                                                       false /* updateTransactionCounters*/,
                                                       pendingBuffers)) {
                        setTransactionFlags(eTransactionFlushNeeded);
                        break;
                    }
@@ -3327,10 +3333,13 @@ void SurfaceFlinger::flushTransactionQueues() {
                bool pendingTransactions = mPendingTransactionQueues.find(transaction.applyToken) !=
                        mPendingTransactionQueues.end();
                // Call transactionIsReadyToBeApplied first in case we need to
            // incrementPendingBufferCount if the transaction contains a buffer.
                // incrementPendingBufferCount and keep track of pending buffers
                // if the transaction contains a buffer.
                if (!transactionIsReadyToBeApplied(transaction.isAutoTimestamp,
                                               transaction.desiredPresentTime, transaction.states,
                                               true) ||
                                                   transaction.desiredPresentTime,
                                                   transaction.states,
                                                   true /* updateTransactionCounters */,
                                                   pendingBuffers) ||
                    pendingTransactions) {
                    mPendingTransactionQueues[transaction.applyToken].push(transaction);
                } else {
@@ -3341,15 +3350,15 @@ void SurfaceFlinger::flushTransactionQueues() {
        }

        // Now apply all transactions.
    Mutex::Autolock _l(mStateLock);
        for (const auto& transaction : transactions) {
            applyTransactionState(transaction.frameTimelineInfo, transaction.states,
                                  transaction.displays, transaction.flags,
                                  transaction.inputWindowCommands, transaction.desiredPresentTime,
                              transaction.isAutoTimestamp, transaction.buffer, transaction.postTime,
                              transaction.privileged, transaction.hasListenerCallbacks,
                              transaction.listenerCallbacks, transaction.originPid,
                              transaction.originUid, transaction.id);
                                  transaction.isAutoTimestamp, transaction.buffer,
                                  transaction.postTime, transaction.privileged,
                                  transaction.hasListenerCallbacks, transaction.listenerCallbacks,
                                  transaction.originPid, transaction.originUid, transaction.id);
        }
    }
}

@@ -3358,9 +3367,10 @@ bool SurfaceFlinger::transactionFlushNeeded() {
    return !mPendingTransactionQueues.empty();
}

bool SurfaceFlinger::transactionIsReadyToBeApplied(bool isAutoTimestamp, int64_t desiredPresentTime,
                                                   const Vector<ComposerState>& states,
                                                   bool updateTransactionCounters) {
bool SurfaceFlinger::transactionIsReadyToBeApplied(
        bool isAutoTimestamp, int64_t desiredPresentTime, const Vector<ComposerState>& states,
        bool updateTransactionCounters,
        std::unordered_set<sp<IBinder>, ISurfaceComposer::SpHash<IBinder>>& pendingBuffers) {
    const nsecs_t expectedPresentTime = mExpectedPresentTime.load();
    bool ready = true;
    // Do not present if the desiredPresentTime has not passed unless it is more than one second
@@ -3379,7 +3389,6 @@ bool SurfaceFlinger::transactionIsReadyToBeApplied(bool isAutoTimestamp, int64_t
            ready = false;
        }

        Mutex::Autolock _l(mStateLock);
        sp<Layer> layer = nullptr;
        if (s.surface) {
            layer = fromHandleLocked(s.surface).promote();
@@ -3402,12 +3411,11 @@ bool SurfaceFlinger::transactionIsReadyToBeApplied(bool isAutoTimestamp, int64_t

        // If backpressure is enabled and we already have a buffer to commit, keep the transaction
        // in the queue.
        bool hasBuffer = s.what & layer_state_t::eBufferChanged ||
                s.what & layer_state_t::eCachedBufferChanged;
        if (hasBuffer && layer->backpressureEnabled() && layer->hasPendingBuffer() &&
            isAutoTimestamp) {
        const bool hasPendingBuffer = pendingBuffers.find(s.surface) != pendingBuffers.end();
        if (layer->backpressureEnabled() && hasPendingBuffer && isAutoTimestamp) {
            ready = false;
        }
        pendingBuffers.insert(s.surface);
    }
    return ready;
}
+5 −3
Original line number Diff line number Diff line
@@ -760,9 +760,11 @@ private:
    uint32_t setTransactionFlags(uint32_t flags, TransactionSchedule);
    void commitTransaction() REQUIRES(mStateLock);
    void commitOffscreenLayers();
    bool transactionIsReadyToBeApplied(bool isAutoTimestamp, int64_t desiredPresentTime,
                                       const Vector<ComposerState>& states,
                                       bool updateTransactionCounters = false);
    bool transactionIsReadyToBeApplied(
            bool isAutoTimestamp, int64_t desiredPresentTime, const Vector<ComposerState>& states,
            bool updateTransactionCounters,
            std::unordered_set<sp<IBinder>, ISurfaceComposer::SpHash<IBinder>>& pendingBuffers)
            REQUIRES(mStateLock);
    uint32_t setDisplayStateLocked(const DisplayState& s) REQUIRES(mStateLock);
    uint32_t addInputWindowCommands(const InputWindowCommands& inputWindowCommands)
            REQUIRES(mStateLock);