diff options
| -rw-r--r-- | libs/gui/BLASTBufferQueue.cpp | 31 | ||||
| -rw-r--r-- | libs/gui/include/gui/BLASTBufferQueue.h | 9 |
2 files changed, 28 insertions, 12 deletions
diff --git a/libs/gui/BLASTBufferQueue.cpp b/libs/gui/BLASTBufferQueue.cpp index 87f797200c..0b942199c3 100644 --- a/libs/gui/BLASTBufferQueue.cpp +++ b/libs/gui/BLASTBufferQueue.cpp @@ -213,12 +213,9 @@ void BLASTBufferQueue::processNextBufferLocked(bool useNextTransaction) { ATRACE_CALL(); BQA_LOGV("processNextBufferLocked useNextTransaction=%s", toString(useNextTransaction)); - // Wait to acquire a buffer if there are no frames available or we have acquired the maximum + // Wait to acquire a buffer if there are no frames available or we have acquired the max // 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. - if (mNumFrameAvailable == 0 || mNumAcquired == MAX_ACQUIRED_BUFFERS + 1 || - (!mInitialCallbackReceived && mNumAcquired == 1)) { + if (mNumFrameAvailable == 0 || maxBuffersAcquired()) { BQA_LOGV("processNextBufferLocked waiting for frame available or callback"); return; } @@ -241,6 +238,7 @@ void BLASTBufferQueue::processNextBufferLocked(bool useNextTransaction) { status_t status = mBufferItemConsumer->acquireBuffer(&bufferItem, -1, false); if (status != OK) { + BQA_LOGE("Failed to acquire a buffer, err=%s", statusToString(status).c_str()); return; } auto buffer = bufferItem.mGraphicBuffer; @@ -248,14 +246,15 @@ void BLASTBufferQueue::processNextBufferLocked(bool useNextTransaction) { if (buffer == nullptr) { mBufferItemConsumer->releaseBuffer(bufferItem, Fence::NO_FENCE); + BQA_LOGE("Buffer was empty"); return; } if (rejectBuffer(bufferItem)) { BQA_LOGE("rejecting buffer:configured size=%dx%d, buffer{size=%dx%d transform=%d}", mWidth, mHeight, buffer->getWidth(), buffer->getHeight(), bufferItem.mTransform); - mBufferItemConsumer->releaseBuffer(bufferItem, Fence::NO_FENCE); - return; + // TODO(b/168917217) temporarily don't reject buffers until we can synchronize buffer size + // changes from ViewRootImpl. } mNumAcquired++; @@ -307,13 +306,16 @@ void BLASTBufferQueue::onFrameAvailable(const BufferItem& /*item*/) { std::unique_lock _lock{mMutex}; const bool nextTransactionSet = mNextTransaction != nullptr; - BQA_LOGV("onFrameAvailable nextTransactionSet=%s", toString(nextTransactionSet)); + BQA_LOGV("onFrameAvailable nextTransactionSet=%s mFlushShadowQueue=%s", + toString(nextTransactionSet), toString(mFlushShadowQueue)); - if (nextTransactionSet) { - while (mNumFrameAvailable > 0 || mNumAcquired == MAX_ACQUIRED_BUFFERS + 1) { + if (nextTransactionSet || mFlushShadowQueue) { + while (mNumFrameAvailable > 0 || maxBuffersAcquired()) { + BQA_LOGV("waiting in onFrameAvailable..."); mCallbackCV.wait(_lock); } } + mFlushShadowQueue = false; // add to shadow queue mNumFrameAvailable++; processNextBufferLocked(true); @@ -341,4 +343,13 @@ bool BLASTBufferQueue::rejectBuffer(const BufferItem& item) const { // reject buffers if the buffer size doesn't match. return bufWidth != mWidth || bufHeight != mHeight; } + +// 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. +bool BLASTBufferQueue::maxBuffersAcquired() const { + return mNumAcquired == MAX_ACQUIRED_BUFFERS + 1 || + (!mInitialCallbackReceived && mNumAcquired == 1); +} + } // namespace android diff --git a/libs/gui/include/gui/BLASTBufferQueue.h b/libs/gui/include/gui/BLASTBufferQueue.h index 5b1a018ca9..634a7aa058 100644 --- a/libs/gui/include/gui/BLASTBufferQueue.h +++ b/libs/gui/include/gui/BLASTBufferQueue.h @@ -82,6 +82,7 @@ public: void setNextTransaction(SurfaceComposerClient::Transaction *t); void update(const sp<SurfaceControl>& surface, uint32_t width, uint32_t height); + void flushShadowQueue() { mFlushShadowQueue = true; } virtual ~BLASTBufferQueue() = default; @@ -93,9 +94,10 @@ private: BLASTBufferQueue(const BLASTBufferQueue& rhs); void processNextBufferLocked(bool useNextTransaction) REQUIRES(mMutex); - Rect computeCrop(const BufferItem& item); + Rect computeCrop(const BufferItem& item) REQUIRES(mMutex); // Return true if we need to reject the buffer based on the scaling mode and the buffer size. - bool rejectBuffer(const BufferItem& item) const; + bool rejectBuffer(const BufferItem& item) const REQUIRES(mMutex); + bool maxBuffersAcquired() const REQUIRES(mMutex); std::string mName; sp<SurfaceControl> mSurfaceControl; @@ -130,6 +132,9 @@ private: sp<BLASTBufferItemConsumer> mBufferItemConsumer; SurfaceComposerClient::Transaction* mNextTransaction GUARDED_BY(mMutex); + // If set to true, the next queue buffer will wait until the shadow queue has been processed by + // the adapter. + bool mFlushShadowQueue = false; }; } // namespace android |