summaryrefslogtreecommitdiff
path: root/libs/gui/BufferQueue.cpp
diff options
context:
space:
mode:
author Mathias Agopian <mathias@google.com> 2013-07-23 17:28:53 -0700
committer Mathias Agopian <mathias@google.com> 2013-07-26 18:45:02 -0700
commitad678e18b66f495efa78dc3b9ab99b579945c9e2 (patch)
treeb1158419e04a0417533618592ef58d5fa23490b5 /libs/gui/BufferQueue.cpp
parentbf5b849ec7b2050e1fe05aebb3914823da6a0d07 (diff)
single buffer mode for BufferQueue
Bug: 9891035 Change-Id: Id1ab5f911a6dc4c1d8235e65775b3d3635231ad4
Diffstat (limited to 'libs/gui/BufferQueue.cpp')
-rw-r--r--libs/gui/BufferQueue.cpp28
1 files changed, 25 insertions, 3 deletions
diff --git a/libs/gui/BufferQueue.cpp b/libs/gui/BufferQueue.cpp
index 95ba09528a..45488ff8d8 100644
--- a/libs/gui/BufferQueue.cpp
+++ b/libs/gui/BufferQueue.cpp
@@ -72,6 +72,7 @@ BufferQueue::BufferQueue(const sp<IGraphicBufferAlloc>& allocator) :
mOverrideMaxBufferCount(0),
mConsumerControlledByApp(false),
mDequeueBufferCannotBlock(false),
+ mUseAsyncBuffer(true),
mConnectedApi(NO_CONNECTED_API),
mAbandoned(false),
mFrameCounter(0),
@@ -100,7 +101,8 @@ BufferQueue::~BufferQueue() {
}
status_t BufferQueue::setDefaultMaxBufferCountLocked(int count) {
- if (count < 2 || count > NUM_BUFFER_SLOTS)
+ const int minBufferCount = mUseAsyncBuffer ? 2 : 1;
+ if (count < minBufferCount || count > NUM_BUFFER_SLOTS)
return BAD_VALUE;
mDefaultMaxBufferCount = count;
@@ -1033,6 +1035,17 @@ status_t BufferQueue::setDefaultMaxBufferCount(int bufferCount) {
return setDefaultMaxBufferCountLocked(bufferCount);
}
+status_t BufferQueue::disableAsyncBuffer() {
+ ATRACE_CALL();
+ Mutex::Autolock lock(mMutex);
+ if (mConsumerListener != NULL) {
+ ST_LOGE("disableAsyncBuffer: consumer already connected!");
+ return INVALID_OPERATION;
+ }
+ mUseAsyncBuffer = false;
+ return NO_ERROR;
+}
+
status_t BufferQueue::setMaxAcquiredBufferCount(int maxAcquiredBuffers) {
ATRACE_CALL();
Mutex::Autolock lock(mMutex);
@@ -1049,8 +1062,17 @@ status_t BufferQueue::setMaxAcquiredBufferCount(int maxAcquiredBuffers) {
}
int BufferQueue::getMinUndequeuedBufferCount(bool async) const {
- return (mDequeueBufferCannotBlock || async) ?
- mMaxAcquiredBufferCount+1 : mMaxAcquiredBufferCount;
+ // if dequeueBuffer is allowed to error out, we don't have to
+ // add an extra buffer.
+ if (!mUseAsyncBuffer)
+ return mMaxAcquiredBufferCount;
+
+ // we're in async mode, or we want to prevent the app to
+ // deadlock itself, we throw-in an extra buffer to guarantee it.
+ if (mDequeueBufferCannotBlock || async)
+ return mMaxAcquiredBufferCount+1;
+
+ return mMaxAcquiredBufferCount;
}
int BufferQueue::getMinMaxBufferCountLocked(bool async) const {