diff options
| author | 2020-12-29 02:14:08 +0000 | |
|---|---|---|
| committer | 2020-12-29 02:14:08 +0000 | |
| commit | 57563a1020fefe9645e4d52a4a9d9ebdcab6d222 (patch) | |
| tree | df81974c61b389bd933d44b0c359b10e265ddedb /libs/gui/BLASTBufferQueue.cpp | |
| parent | dbb6dcfdde95318dc9b6090d70233d106c77ec92 (diff) | |
| parent | c4a40c1c522bb6607fb436d81c9ff32947a37328 (diff) | |
Merge "Added mergeWithNextTransaction to BlastBufferQueue"
Diffstat (limited to 'libs/gui/BLASTBufferQueue.cpp')
| -rw-r--r-- | libs/gui/BLASTBufferQueue.cpp | 44 |
1 files changed, 42 insertions, 2 deletions
diff --git a/libs/gui/BLASTBufferQueue.cpp b/libs/gui/BLASTBufferQueue.cpp index 3415d9db61..ee5552f20e 100644 --- a/libs/gui/BLASTBufferQueue.cpp +++ b/libs/gui/BLASTBufferQueue.cpp @@ -151,6 +151,19 @@ BLASTBufferQueue::BLASTBufferQueue(const std::string& name, const sp<SurfaceCont mPendingReleaseItem.releaseFence = nullptr; } +BLASTBufferQueue::~BLASTBufferQueue() { + if (mPendingTransactions.empty()) { + return; + } + BQA_LOGE("Applying pending transactions on dtor %d", + static_cast<uint32_t>(mPendingTransactions.size())); + SurfaceComposerClient::Transaction t; + for (auto& [targetFrameNumber, transaction] : mPendingTransactions) { + t.merge(std::move(transaction)); + } + t.apply(); +} + void BLASTBufferQueue::update(const sp<SurfaceControl>& surface, uint32_t width, uint32_t height) { std::unique_lock _lock{mMutex}; mSurfaceControl = surface; @@ -312,6 +325,7 @@ void BLASTBufferQueue::processNextBufferLocked(bool useNextTransaction) { incStrong((void*)transactionCallbackThunk); mLastBufferScalingMode = bufferItem.mScalingMode; + mLastAcquiredFrameNumber = bufferItem.mFrameNumber; t->setBuffer(mSurfaceControl, buffer); t->setDataspace(mSurfaceControl, static_cast<ui::Dataspace>(bufferItem.mDataSpace)); @@ -341,14 +355,29 @@ void BLASTBufferQueue::processNextBufferLocked(bool useNextTransaction) { mAutoRefresh = bufferItem.mAutoRefresh; } + auto mergeTransaction = + [&t, currentFrameNumber = bufferItem.mFrameNumber]( + std::tuple<uint64_t, SurfaceComposerClient::Transaction> pendingTransaction) { + auto& [targetFrameNumber, transaction] = pendingTransaction; + if (currentFrameNumber < targetFrameNumber) { + return false; + } + t->merge(std::move(transaction)); + return true; + }; + + mPendingTransactions.erase(std::remove_if(mPendingTransactions.begin(), + mPendingTransactions.end(), mergeTransaction), + mPendingTransactions.end()); + if (applyTransaction) { t->apply(); } BQA_LOGV("processNextBufferLocked size=%dx%d mFrameNumber=%" PRIu64 - " applyTransaction=%s mTimestamp=%" PRId64, + " applyTransaction=%s mTimestamp=%" PRId64 " mPendingTransactions.size=%d", mSize.width, mSize.height, bufferItem.mFrameNumber, toString(applyTransaction), - bufferItem.mTimestamp); + bufferItem.mTimestamp, static_cast<uint32_t>(mPendingTransactions.size())); } Rect BLASTBufferQueue::computeCrop(const BufferItem& item) { @@ -487,6 +516,17 @@ sp<Surface> BLASTBufferQueue::getSurface(bool includeSurfaceControlHandle) { return new BBQSurface(mProducer, true, scHandle, this); } +void BLASTBufferQueue::mergeWithNextTransaction(SurfaceComposerClient::Transaction* t, + uint64_t frameNumber) { + std::lock_guard _lock{mMutex}; + if (mLastAcquiredFrameNumber >= frameNumber) { + // Apply the transaction since we have already acquired the desired frame. + t->apply(); + } else { + mPendingTransactions.emplace_back(frameNumber, std::move(*t)); + } +} + // Maintains a single worker thread per process that services a list of runnables. class AsyncWorker : public Singleton<AsyncWorker> { private: |