summaryrefslogtreecommitdiff
path: root/libs/gui/BLASTBufferQueue.cpp
diff options
context:
space:
mode:
author Vishnu Nair <vishnun@google.com> 2020-10-16 23:03:51 +0000
committer Android (Google) Code Review <android-gerrit@google.com> 2020-10-16 23:03:51 +0000
commit2dd1a2d01c7c2069db16e7a95fd83f02b0069c4b (patch)
tree9954c7f3cffbfc2f37865e8b10505986cf628b5e /libs/gui/BLASTBufferQueue.cpp
parent5b508ccf3489cd27799deca9975bb8eba1fde59d (diff)
parentbf25577c69c51ad2d1fc54532bb54510da5ddc7c (diff)
Merge changes from topic "flushshadowqueue"
* changes: BlastBufferQueue: Fix wait in onFrameAvailable BlastBufferQueue: Add a function to flush the shadow queue
Diffstat (limited to 'libs/gui/BLASTBufferQueue.cpp')
-rw-r--r--libs/gui/BLASTBufferQueue.cpp31
1 files changed, 21 insertions, 10 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