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

Commit fae9d607 authored by Chavi Weingarten's avatar Chavi Weingarten Committed by Android (Google) Code Review
Browse files

Merge "Rename nextTransaction to syncTransaction"

parents 33ff59aa a1c4c829
Loading
Loading
Loading
Loading
+14 −14
Original line number Diff line number Diff line
@@ -138,7 +138,7 @@ BLASTBufferQueue::BLASTBufferQueue(const std::string& name, const sp<SurfaceCont
        mSize(width, height),
        mRequestedSize(mSize),
        mFormat(format),
        mNextTransaction(nullptr) {
        mSyncTransaction(nullptr) {
    createBufferQueue(&mProducer, &mConsumer);
    // since the adapter is in the client process, set dequeue timeout
    // explicitly so that dequeueBuffer will block
@@ -290,7 +290,7 @@ void BLASTBufferQueue::transactionCommittedCallback(nsecs_t /*latchTime*/,
                // case, we don't actually want to flush the frames in between since they will get
                // processed and merged with the sync transaction and released earlier than if they
                // were sent to SF
                if (mWaitForTransactionCallback && mNextTransaction == nullptr &&
                if (mWaitForTransactionCallback && mSyncTransaction == nullptr &&
                    currFrameNumber >= mLastAcquiredFrameNumber) {
                    mWaitForTransactionCallback = false;
                    flushShadowQueue();
@@ -420,7 +420,7 @@ void BLASTBufferQueue::releaseBufferCallback(
        mBufferItemConsumer->releaseBuffer(it->second, releaseBuffer.releaseFence);
        mSubmitted.erase(it);
        // Don't process the transactions here if mWaitForTransactionCallback is set. Instead, let
        // onFrameAvailable handle processing them since it will merge with the nextTransaction.
        // onFrameAvailable handle processing them since it will merge with the syncTransaction.
        if (!mWaitForTransactionCallback) {
            acquireNextBufferLocked(std::nullopt);
        }
@@ -593,15 +593,15 @@ void BLASTBufferQueue::onFrameAvailable(const BufferItem& item) {
    ATRACE_CALL();
    std::unique_lock _lock{mMutex};

    const bool nextTransactionSet = mNextTransaction != nullptr;
    BQA_LOGV("onFrameAvailable-start nextTransactionSet=%s", boolToString(nextTransactionSet));
    if (nextTransactionSet) {
    const bool syncTransactionSet = mSyncTransaction != nullptr;
    BQA_LOGV("onFrameAvailable-start syncTransactionSet=%s", boolToString(syncTransactionSet));
    if (syncTransactionSet) {
        if (mWaitForTransactionCallback) {
            // We are waiting on a previous sync's transaction callback so allow another sync
            // transaction to proceed.
            //
            // We need to first flush out the transactions that were in between the two syncs.
            // We do this by merging them into mNextTransaction so any buffer merging will get
            // We do this by merging them into mSyncTransaction so any buffer merging will get
            // a release callback invoked. The release callback will be async so we need to wait
            // on max acquired to make sure we have the capacity to acquire another buffer.
            if (maxBuffersAcquired(false /* includeExtraAcquire */)) {
@@ -625,12 +625,12 @@ void BLASTBufferQueue::onFrameAvailable(const BufferItem& item) {
    ATRACE_INT(mQueuedBufferTrace.c_str(),
               mNumFrameAvailable + mNumAcquired - mPendingRelease.size());

    BQA_LOGV("onFrameAvailable framenumber=%" PRIu64 " nextTransactionSet=%s", item.mFrameNumber,
             boolToString(nextTransactionSet));
    BQA_LOGV("onFrameAvailable framenumber=%" PRIu64 " syncTransactionSet=%s", item.mFrameNumber,
             boolToString(syncTransactionSet));

    if (nextTransactionSet) {
        acquireNextBufferLocked(std::move(mNextTransaction));
        mNextTransaction = nullptr;
    if (syncTransactionSet) {
        acquireNextBufferLocked(std::move(mSyncTransaction));
        mSyncTransaction = nullptr;
        mWaitForTransactionCallback = true;
    } else if (!mWaitForTransactionCallback) {
        acquireNextBufferLocked(std::nullopt);
@@ -652,9 +652,9 @@ void BLASTBufferQueue::onFrameCancelled(const uint64_t bufferId) {
    mDequeueTimestamps.erase(bufferId);
};

void BLASTBufferQueue::setNextTransaction(SurfaceComposerClient::Transaction* t) {
void BLASTBufferQueue::setSyncTransaction(SurfaceComposerClient::Transaction* t) {
    std::lock_guard _lock{mMutex};
    mNextTransaction = t;
    mSyncTransaction = t;
}

bool BLASTBufferQueue::rejectBuffer(const BufferItem& item) {
+2 −2
Original line number Diff line number Diff line
@@ -94,7 +94,7 @@ public:
                                     const std::vector<SurfaceControlStats>& stats);
    void releaseBufferCallback(const ReleaseCallbackId& id, const sp<Fence>& releaseFence,
                               std::optional<uint32_t> currentMaxAcquiredBufferCount);
    void setNextTransaction(SurfaceComposerClient::Transaction *t);
    void setSyncTransaction(SurfaceComposerClient::Transaction* t);
    void mergeWithNextTransaction(SurfaceComposerClient::Transaction* t, uint64_t frameNumber);
    void applyPendingTransactions(uint64_t frameNumber);

@@ -208,7 +208,7 @@ private:
    sp<IGraphicBufferProducer> mProducer;
    sp<BLASTBufferItemConsumer> mBufferItemConsumer;

    SurfaceComposerClient::Transaction* mNextTransaction GUARDED_BY(mMutex);
    SurfaceComposerClient::Transaction* mSyncTransaction GUARDED_BY(mMutex);
    std::vector<std::tuple<uint64_t /* framenumber */, SurfaceComposerClient::Transaction>>
            mPendingTransactions GUARDED_BY(mMutex);

+34 −34
Original line number Diff line number Diff line
@@ -109,15 +109,15 @@ public:
        mBlastBufferQueueAdapter->update(sc, width, height, PIXEL_FORMAT_RGBA_8888);
    }

    void setNextTransaction(Transaction* next) {
        mBlastBufferQueueAdapter->setNextTransaction(next);
    void setSyncTransaction(Transaction* sync) {
        mBlastBufferQueueAdapter->setSyncTransaction(sync);
    }

    int getWidth() { return mBlastBufferQueueAdapter->mSize.width; }

    int getHeight() { return mBlastBufferQueueAdapter->mSize.height; }

    Transaction* getNextTransaction() { return mBlastBufferQueueAdapter->mNextTransaction; }
    Transaction* getSyncTransaction() { return mBlastBufferQueueAdapter->mSyncTransaction; }

    sp<IGraphicBufferProducer> getIGraphicBufferProducer() {
        return mBlastBufferQueueAdapter->getIGraphicBufferProducer();
@@ -337,7 +337,7 @@ TEST_F(BLASTBufferQueueTest, CreateBLASTBufferQueue) {
    ASSERT_EQ(mSurfaceControl, adapter.getSurfaceControl());
    ASSERT_EQ(mDisplayWidth, adapter.getWidth());
    ASSERT_EQ(mDisplayHeight, adapter.getHeight());
    ASSERT_EQ(nullptr, adapter.getNextTransaction());
    ASSERT_EQ(nullptr, adapter.getSyncTransaction());
}

TEST_F(BLASTBufferQueueTest, Update) {
@@ -358,11 +358,11 @@ TEST_F(BLASTBufferQueueTest, Update) {
    ASSERT_EQ(mDisplayHeight / 2, height);
}

TEST_F(BLASTBufferQueueTest, SetNextTransaction) {
TEST_F(BLASTBufferQueueTest, SetSyncTransaction) {
    BLASTBufferQueueHelper adapter(mSurfaceControl, mDisplayWidth, mDisplayHeight);
    Transaction next;
    adapter.setNextTransaction(&next);
    ASSERT_EQ(&next, adapter.getNextTransaction());
    Transaction sync;
    adapter.setSyncTransaction(&sync);
    ASSERT_EQ(&sync, adapter.getSyncTransaction());
}

TEST_F(BLASTBufferQueueTest, DISABLED_onFrameAvailable_ApplyDesiredPresentTime) {
@@ -801,8 +801,8 @@ TEST_F(BLASTBufferQueueTest, SyncThenNoSync) {
    sp<IGraphicBufferProducer> igbProducer;
    setUpProducer(adapter, igbProducer);

    Transaction next;
    adapter.setNextTransaction(&next);
    Transaction sync;
    adapter.setSyncTransaction(&sync);
    queueBuffer(igbProducer, 0, 255, 0, 0);

    // queue non sync buffer, so this one should get blocked
@@ -811,7 +811,7 @@ TEST_F(BLASTBufferQueueTest, SyncThenNoSync) {
    queueBuffer(igbProducer, r, g, b, presentTimeDelay);

    CallbackHelper transactionCallback;
    next.addTransactionCompletedCallback(transactionCallback.function,
    sync.addTransactionCompletedCallback(transactionCallback.function,
                                         transactionCallback.getContext())
            .apply();

@@ -841,16 +841,16 @@ TEST_F(BLASTBufferQueueTest, MultipleSyncTransactions) {

    Transaction mainTransaction;

    Transaction next;
    adapter.setNextTransaction(&next);
    Transaction sync;
    adapter.setSyncTransaction(&sync);
    queueBuffer(igbProducer, 0, 255, 0, 0);

    mainTransaction.merge(std::move(next));
    mainTransaction.merge(std::move(sync));

    adapter.setNextTransaction(&next);
    adapter.setSyncTransaction(&sync);
    queueBuffer(igbProducer, r, g, b, 0);

    mainTransaction.merge(std::move(next));
    mainTransaction.merge(std::move(sync));
    // Expect 1 buffer to be released even before sending to SurfaceFlinger
    mProducerListener->waitOnNumberReleased(1);

@@ -881,24 +881,24 @@ TEST_F(BLASTBufferQueueTest, MultipleSyncTransactionWithNonSync) {

    Transaction mainTransaction;

    Transaction next;
    Transaction sync;
    // queue a sync transaction
    adapter.setNextTransaction(&next);
    adapter.setSyncTransaction(&sync);
    queueBuffer(igbProducer, 0, 255, 0, 0);

    mainTransaction.merge(std::move(next));
    mainTransaction.merge(std::move(sync));

    // queue another buffer without setting next transaction
    // queue another buffer without setting sync transaction
    queueBuffer(igbProducer, 0, 0, 255, 0);

    // queue another sync transaction
    adapter.setNextTransaction(&next);
    adapter.setSyncTransaction(&sync);
    queueBuffer(igbProducer, r, g, b, 0);
    // Expect 1 buffer to be released because the non sync transaction should merge
    // with the sync
    mProducerListener->waitOnNumberReleased(1);

    mainTransaction.merge(std::move(next));
    mainTransaction.merge(std::move(sync));
    // Expect 2 buffers to be released due to merging the two syncs.
    mProducerListener->waitOnNumberReleased(2);

@@ -929,26 +929,26 @@ TEST_F(BLASTBufferQueueTest, MultipleSyncRunOutOfBuffers) {

    Transaction mainTransaction;

    Transaction next;
    Transaction sync;
    // queue a sync transaction
    adapter.setNextTransaction(&next);
    adapter.setSyncTransaction(&sync);
    queueBuffer(igbProducer, 0, 255, 0, 0);

    mainTransaction.merge(std::move(next));
    mainTransaction.merge(std::move(sync));

    // queue a few buffers without setting next transaction
    // queue a few buffers without setting sync transaction
    queueBuffer(igbProducer, 0, 0, 255, 0);
    queueBuffer(igbProducer, 0, 0, 255, 0);
    queueBuffer(igbProducer, 0, 0, 255, 0);

    // queue another sync transaction
    adapter.setNextTransaction(&next);
    adapter.setSyncTransaction(&sync);
    queueBuffer(igbProducer, r, g, b, 0);
    // Expect 3 buffers to be released because the non sync transactions should merge
    // with the sync
    mProducerListener->waitOnNumberReleased(3);

    mainTransaction.merge(std::move(next));
    mainTransaction.merge(std::move(sync));
    // Expect 4 buffers to be released due to merging the two syncs.
    mProducerListener->waitOnNumberReleased(4);

@@ -986,14 +986,14 @@ TEST_F(BLASTBufferQueueTest, RunOutOfBuffersWaitingOnSF) {
    // Send a buffer to SF
    queueBuffer(igbProducer, 0, 255, 0, 0);

    Transaction next;
    Transaction sync;
    // queue a sync transaction
    adapter.setNextTransaction(&next);
    adapter.setSyncTransaction(&sync);
    queueBuffer(igbProducer, 0, 255, 0, 0);

    mainTransaction.merge(std::move(next));
    mainTransaction.merge(std::move(sync));

    // queue a few buffers without setting next transaction
    // queue a few buffers without setting sync transaction
    queueBuffer(igbProducer, 0, 0, 255, 0);
    queueBuffer(igbProducer, 0, 0, 255, 0);
    queueBuffer(igbProducer, 0, 0, 255, 0);
@@ -1002,13 +1002,13 @@ TEST_F(BLASTBufferQueueTest, RunOutOfBuffersWaitingOnSF) {
    mainTransaction.apply();

    // queue another sync transaction
    adapter.setNextTransaction(&next);
    adapter.setSyncTransaction(&sync);
    queueBuffer(igbProducer, r, g, b, 0);
    // Expect 2 buffers to be released because the non sync transactions should merge
    // with the sync
    mProducerListener->waitOnNumberReleased(3);

    mainTransaction.merge(std::move(next));
    mainTransaction.merge(std::move(sync));

    CallbackHelper transactionCallback;
    mainTransaction