Add ability to process buffers into the same syncTransaction
In a normal sync case, we send the syncTransaction and then clear it as
soon as a buffer is acquired and placed in the transaction. However, in
some cases, we want to continue processing buffers into the sync
transaction until we get the signal to stop. This is for cases when we
don't have a clear signal which buffer wants to be synced, but know when
it's done waiting for the correct buffer.
This also adds a way to retrieve and clear the buffer from the
transaction to allow BBQ to release the buffer when it knows it's ready
to acquire a new buffer. This speeds up the process so BBQ doesn't need
to wait for the asynchronous callback to release the previous buffer.
This new machanism can be used to synchronize SurfaceViews because it
knows when something has been changed and to wait until the app has
notified that it's drawn. Once it's notified, we can stop processing
frames into the sync transaction and allow the transaction to be applied
with the main window.
Bug: 200284684
Test: BLASTBufferQueueTest
Change-Id: Ibdb524270de368033cf8835f0c305e8a5756ff6e
diff --git a/libs/gui/include/gui/BLASTBufferQueue.h b/libs/gui/include/gui/BLASTBufferQueue.h
index f718de8..d766173 100644
--- a/libs/gui/include/gui/BLASTBufferQueue.h
+++ b/libs/gui/include/gui/BLASTBufferQueue.h
@@ -94,7 +94,7 @@
const std::vector<SurfaceControlStats>& stats);
void releaseBufferCallback(const ReleaseCallbackId& id, const sp<Fence>& releaseFence,
std::optional<uint32_t> currentMaxAcquiredBufferCount);
- void setSyncTransaction(SurfaceComposerClient::Transaction* t);
+ void setSyncTransaction(SurfaceComposerClient::Transaction* t, bool acquireSingleBuffer = true);
void mergeWithNextTransaction(SurfaceComposerClient::Transaction* t, uint64_t frameNumber);
void applyPendingTransactions(uint64_t frameNumber);
@@ -132,6 +132,9 @@
void flushShadowQueue() REQUIRES(mMutex);
void acquireAndReleaseBuffer() REQUIRES(mMutex);
+ void releaseBuffer(const ReleaseCallbackId& callbackId, const sp<Fence>& releaseFence)
+ REQUIRES(mMutex);
+ void flushAndWaitForFreeBuffer(std::unique_lock<std::mutex>& lock);
std::string mName;
// Represents the queued buffer count from buffer queue,
@@ -239,7 +242,11 @@
std::queue<sp<SurfaceControl>> mSurfaceControlsWithPendingCallback GUARDED_BY(mMutex);
uint32_t mCurrentMaxAcquiredBufferCount;
- bool mWaitForTransactionCallback = false;
+ bool mWaitForTransactionCallback GUARDED_BY(mMutex) = false;
+
+ // Flag to determine if syncTransaction should only acquire a single buffer and then clear or
+ // continue to acquire buffers until explicitly cleared
+ bool mAcquireSingleBuffer GUARDED_BY(mMutex) = true;
};
} // namespace android