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

Commit 71c2cc42 authored by chaviw's avatar chaviw
Browse files

Add TransactionCompleteCallback

Allow users of BlastBufferQueue to register for transaction complete for
a particular frame number. This will allow VRI to know when a
transaction was applied so it can continue rendering after a relayout.

Test: Split screen with blast sync
Bug: 167202096
Change-Id: If0bb5b496a462ba486b05b0ddc35bff66eb29e1a
parent 9efa8758
Loading
Loading
Loading
Loading
+63 −37
Original line number Diff line number Diff line
@@ -184,6 +184,10 @@ static void transactionCallbackThunk(void* context, nsecs_t latchTime,

void BLASTBufferQueue::transactionCallback(nsecs_t /*latchTime*/, const sp<Fence>& /*presentFence*/,
                                           const std::vector<SurfaceControlStats>& stats) {
    std::function<void(int64_t)> transactionCompleteCallback = nullptr;
    uint64_t currFrameNumber = 0;

    {
        std::unique_lock _lock{mMutex};
        ATRACE_CALL();
        BQA_LOGV("transactionCallback");
@@ -192,11 +196,11 @@ void BLASTBufferQueue::transactionCallback(nsecs_t /*latchTime*/, const sp<Fence
        if (!stats.empty()) {
            mTransformHint = stats[0].transformHint;
            mBufferItemConsumer->setTransformHint(mTransformHint);
        mBufferItemConsumer->updateFrameTimestamps(stats[0].frameEventStats.frameNumber,
            mBufferItemConsumer
                    ->updateFrameTimestamps(stats[0].frameEventStats.frameNumber,
                                            stats[0].frameEventStats.refreshStartTime,
                                            stats[0].frameEventStats.gpuCompositionDoneFence,
                                                   stats[0].presentFence,
                                                   stats[0].previousReleaseFence,
                                            stats[0].presentFence, stats[0].previousReleaseFence,
                                            stats[0].frameEventStats.compositorTiming,
                                            stats[0].latchTime,
                                            stats[0].frameEventStats.dequeueReadyTime);
@@ -225,10 +229,21 @@ void BLASTBufferQueue::transactionCallback(nsecs_t /*latchTime*/, const sp<Fence

        processNextBufferLocked(false);

        currFrameNumber = mPendingReleaseItem.item.mFrameNumber;
        if (mTransactionCompleteCallback && mTransactionCompleteFrameNumber == currFrameNumber) {
            transactionCompleteCallback = std::move(mTransactionCompleteCallback);
            mTransactionCompleteFrameNumber = 0;
        }

        mCallbackCV.notify_all();
        decStrong((void*)transactionCallbackThunk);
    }

    if (transactionCompleteCallback) {
        transactionCompleteCallback(currFrameNumber);
    }
}

void BLASTBufferQueue::processNextBufferLocked(bool useNextTransaction) {
    ATRACE_CALL();
    BQA_LOGV("processNextBufferLocked useNextTransaction=%s", toString(useNextTransaction));
@@ -394,6 +409,17 @@ bool BLASTBufferQueue::rejectBuffer(const BufferItem& item) {
    return mSize != bufferSize;
}

void BLASTBufferQueue::setTransactionCompleteCallback(
        uint64_t frameNumber, std::function<void(int64_t)>&& transactionCompleteCallback) {
    std::lock_guard _lock{mMutex};
    if (transactionCompleteCallback == nullptr) {
        mTransactionCompleteCallback = nullptr;
    } else {
        mTransactionCompleteCallback = std::move(transactionCompleteCallback);
        mTransactionCompleteFrameNumber = frameNumber;
    }
}

// Check if we have acquired the maximum number of buffers.
// As a special case, we wait for the first callback before acquiring the second buffer so we
// can ensure the first buffer is presented if multiple buffers are queued in succession.
+5 −0
Original line number Diff line number Diff line
@@ -82,6 +82,8 @@ public:
    void transactionCallback(nsecs_t latchTime, const sp<Fence>& presentFence,
            const std::vector<SurfaceControlStats>& stats);
    void setNextTransaction(SurfaceComposerClient::Transaction *t);
    void setTransactionCompleteCallback(uint64_t frameNumber,
                                        std::function<void(int64_t)>&& transactionCompleteCallback);

    void update(const sp<SurfaceControl>& surface, uint32_t width, uint32_t height);
    void flushShadowQueue() { mFlushShadowQueue = true; }
@@ -153,6 +155,9 @@ private:
    // layer size immediately or wait until we get the next buffer. This will support scenarios
    // where the layer can change sizes and the buffer will scale to fit the new size.
    uint32_t mLastBufferScalingMode = NATIVE_WINDOW_SCALING_MODE_SCALE_TO_WINDOW;

    std::function<void(int64_t)> mTransactionCompleteCallback GUARDED_BY(mMutex) = nullptr;
    uint64_t mTransactionCompleteFrameNumber GUARDED_BY(mMutex){0};
};

} // namespace android