summaryrefslogtreecommitdiff
path: root/libs/gui/BLASTBufferQueue.cpp
diff options
context:
space:
mode:
author chaviw <chaviw@google.com> 2022-03-17 09:27:03 -0500
committer chaviw <chaviw@google.com> 2022-03-17 10:07:49 -0500
commit3b4bdcf601ef90634c172ce239fc75ddd5b63b84 (patch)
treed57524be3ed8ba278f0fee8396b4c6f5aa21f568 /libs/gui/BLASTBufferQueue.cpp
parenta49b7b35cbf05725ff33badc8794d12fbc8a3190 (diff)
Invoke sync transaction callback if overwritten
If a caller invokes the syncNextTransaction it will overwrite any callback that was set before. This can break since the caller expects to receive the callback. The change invokes the old callback when a new callback overwrites it. It also invokes the callback when the blast buffer queue is torn down in case there's one still pending. Test: Chrome in split + rotation Test: BLASTBufferQueueTest Fixes: 223329500 Change-Id: I91d1d7c47f4eca014c66ba8c2f773ef8be5c674e
Diffstat (limited to 'libs/gui/BLASTBufferQueue.cpp')
-rw-r--r--libs/gui/BLASTBufferQueue.cpp35
1 files changed, 28 insertions, 7 deletions
diff --git a/libs/gui/BLASTBufferQueue.cpp b/libs/gui/BLASTBufferQueue.cpp
index ec4c7c10a4..c2793ac5de 100644
--- a/libs/gui/BLASTBufferQueue.cpp
+++ b/libs/gui/BLASTBufferQueue.cpp
@@ -184,6 +184,10 @@ BLASTBufferQueue::~BLASTBufferQueue() {
mergePendingTransactions(&t, std::numeric_limits<uint64_t>::max() /* frameNumber */);
// All transactions on our apply token are one-way. See comment on mAppliedLastTransaction
t.setApplyToken(mApplyToken).apply(false, true);
+
+ if (mTransactionReadyCallback) {
+ mTransactionReadyCallback(mSyncTransaction);
+ }
}
void BLASTBufferQueue::update(const sp<SurfaceControl>& surface, uint32_t width, uint32_t height,
@@ -702,14 +706,31 @@ void BLASTBufferQueue::syncNextTransaction(
std::function<void(SurfaceComposerClient::Transaction*)> callback,
bool acquireSingleBuffer) {
BBQ_TRACE();
- std::lock_guard _lock{mMutex};
- mTransactionReadyCallback = callback;
- if (callback) {
- mSyncTransaction = new SurfaceComposerClient::Transaction();
- } else {
- mSyncTransaction = nullptr;
+
+ std::function<void(SurfaceComposerClient::Transaction*)> prevCallback = nullptr;
+ SurfaceComposerClient::Transaction* prevTransaction = nullptr;
+
+ {
+ std::lock_guard _lock{mMutex};
+ // We're about to overwrite the previous call so we should invoke that callback
+ // immediately.
+ if (mTransactionReadyCallback) {
+ prevCallback = mTransactionReadyCallback;
+ prevTransaction = mSyncTransaction;
+ }
+
+ mTransactionReadyCallback = callback;
+ if (callback) {
+ mSyncTransaction = new SurfaceComposerClient::Transaction();
+ } else {
+ mSyncTransaction = nullptr;
+ }
+ mAcquireSingleBuffer = mTransactionReadyCallback ? acquireSingleBuffer : true;
+ }
+
+ if (prevCallback) {
+ prevCallback(prevTransaction);
}
- mAcquireSingleBuffer = mTransactionReadyCallback ? acquireSingleBuffer : true;
}
void BLASTBufferQueue::stopContinuousSyncTransaction() {