summaryrefslogtreecommitdiff
path: root/libs/gui/BufferQueueProducer.cpp
diff options
context:
space:
mode:
author Jorim Jaggi <jjaggi@google.com> 2019-03-28 00:44:03 +0100
committer Jorim Jaggi <jjaggi@google.com> 2019-04-02 22:40:12 +0200
commit35b4e3839a2eb405bd172351042f81d842183715 (patch)
tree39ee0e9f82836355b195abfcc7c8b66a88868af7 /libs/gui/BufferQueueProducer.cpp
parent6ae550323264bacc45da2d8fca90534d02815308 (diff)
Wait for buffer allocation
In dequeueBuffer, if we don't have a free slot but are in the process of allocating, we wait for that to complete instead of kicking off our own allocation, as it's likely that the allocation from allocateBuffers is able to finish earlier than if we'd kick off our own allocation. Test: Swipe up, see less initial buffer dequeue delay Fixes: 111517695 Change-Id: I735d68e87fc7e2ff5b7ec3595f0ced5a94ebbf9c
Diffstat (limited to 'libs/gui/BufferQueueProducer.cpp')
-rw-r--r--libs/gui/BufferQueueProducer.cpp18
1 files changed, 17 insertions, 1 deletions
diff --git a/libs/gui/BufferQueueProducer.cpp b/libs/gui/BufferQueueProducer.cpp
index c17a525cb2..b353ffef92 100644
--- a/libs/gui/BufferQueueProducer.cpp
+++ b/libs/gui/BufferQueueProducer.cpp
@@ -59,7 +59,8 @@ BufferQueueProducer::BufferQueueProducer(const sp<BufferQueueCore>& core,
mNextCallbackTicket(0),
mCurrentCallbackTicket(0),
mCallbackCondition(),
- mDequeueTimeout(-1) {}
+ mDequeueTimeout(-1),
+ mDequeueWaitingForAllocation(false) {}
BufferQueueProducer::~BufferQueueProducer() {}
@@ -383,6 +384,15 @@ status_t BufferQueueProducer::dequeueBuffer(int* outSlot, sp<android::Fence>* ou
{ // Autolock scope
std::unique_lock<std::mutex> lock(mCore->mMutex);
+ // If we don't have a free buffer, but we are currently allocating, we wait until allocation
+ // is finished such that we don't allocate in parallel.
+ if (mCore->mFreeBuffers.empty() && mCore->mIsAllocating) {
+ mDequeueWaitingForAllocation = true;
+ mCore->waitWhileAllocatingLocked(lock);
+ mDequeueWaitingForAllocation = false;
+ mDequeueWaitingForAllocationCondition.notify_all();
+ }
+
if (format == 0) {
format = mCore->mDefaultBufferFormat;
}
@@ -1421,6 +1431,12 @@ void BufferQueueProducer::allocateBuffers(uint32_t width, uint32_t height,
mCore->mIsAllocating = false;
mCore->mIsAllocatingCondition.notify_all();
VALIDATE_CONSISTENCY();
+
+ // If dequeue is waiting for to allocate a buffer, release the lock until it's not
+ // waiting anymore so it can use the buffer we just allocated.
+ while (mDequeueWaitingForAllocation) {
+ mDequeueWaitingForAllocationCondition.wait(lock);
+ }
} // Autolock scope
}
}