summaryrefslogtreecommitdiffstats
path: root/libs/gui/BufferQueue.cpp
diff options
context:
space:
mode:
authorJamie Gennis <jgennis@google.com>2012-08-27 18:48:37 -0700
committerAndroid (Google) Code Review <android-gerrit@google.com>2012-08-30 18:26:09 -0700
commit72f096fb1ad0a0deadbfac5f88627461905d38e8 (patch)
treeb9053a47c5403de32ee622aba17af574323b5a11 /libs/gui/BufferQueue.cpp
parent1847f7fd799f92300b3786e49f5883eaa03f4507 (diff)
downloadframeworks_native-72f096fb1ad0a0deadbfac5f88627461905d38e8.zip
frameworks_native-72f096fb1ad0a0deadbfac5f88627461905d38e8.tar.gz
frameworks_native-72f096fb1ad0a0deadbfac5f88627461905d38e8.tar.bz2
BufferQueue: use max acquired buffer count
This change makes BufferQueue derive the min undequeued buffer count from a max acquired buffer count that is set by the consumer. This value may be set at any time that a producer is not connected to the BufferQueue rather than at BufferQueue construction time. Change-Id: Icf9f1d91ec612a079968ba0a4621deffe48f4e22
Diffstat (limited to 'libs/gui/BufferQueue.cpp')
-rw-r--r--libs/gui/BufferQueue.cpp43
1 files changed, 29 insertions, 14 deletions
diff --git a/libs/gui/BufferQueue.cpp b/libs/gui/BufferQueue.cpp
index 6689e84..db021ff 100644
--- a/libs/gui/BufferQueue.cpp
+++ b/libs/gui/BufferQueue.cpp
@@ -81,12 +81,12 @@ static const char* scalingModeName(int scalingMode) {
}
}
-BufferQueue::BufferQueue(bool allowSynchronousMode, int bufferCount,
+BufferQueue::BufferQueue(bool allowSynchronousMode,
const sp<IGraphicBufferAlloc>& allocator) :
mDefaultWidth(1),
mDefaultHeight(1),
- mMinUndequeuedBuffers(bufferCount),
- mDefaultMaxBufferCount(bufferCount + 1),
+ mMaxAcquiredBufferCount(1),
+ mDefaultMaxBufferCount(2),
mOverrideMaxBufferCount(0),
mSynchronousMode(false),
mAllowSynchronousMode(allowSynchronousMode),
@@ -233,8 +233,7 @@ int BufferQueue::query(int what, int* outValue)
value = mDefaultBufferFormat;
break;
case NATIVE_WINDOW_MIN_UNDEQUEUED_BUFFERS:
- value = mSynchronousMode ?
- (mMinUndequeuedBuffers-1) : mMinUndequeuedBuffers;
+ value = getMinUndequeuedBufferCountLocked();
break;
case NATIVE_WINDOW_CONSUMER_RUNNING_BEHIND:
value = (mQueue.size() >= 2);
@@ -356,17 +355,18 @@ status_t BufferQueue::dequeueBuffer(int *outBuf, sp<Fence>& outFence,
}
// See whether a buffer has been queued since the last
- // setBufferCount so we know whether to perform the
- // mMinUndequeuedBuffers check below.
+ // setBufferCount so we know whether to perform the min undequeued
+ // buffers check below.
if (mBufferHasBeenQueued) {
// make sure the client is not trying to dequeue more buffers
// than allowed.
- const int avail = maxBufferCount - (dequeuedCount+1);
- if (avail < (mMinUndequeuedBuffers-int(mSynchronousMode))) {
- ST_LOGE("dequeueBuffer: mMinUndequeuedBuffers=%d exceeded "
- "(dequeued=%d)",
- mMinUndequeuedBuffers-int(mSynchronousMode),
- dequeuedCount);
+ const int newUndequeuedCount = maxBufferCount - (dequeuedCount+1);
+ const int minUndequeuedCount = getMinUndequeuedBufferCountLocked();
+ if (newUndequeuedCount < minUndequeuedCount) {
+ ST_LOGE("dequeueBuffer: min undequeued buffer count (%d) "
+ "exceeded (dequeued=%d undequeudCount=%d)",
+ minUndequeuedCount, dequeuedCount,
+ newUndequeuedCount);
return -EBUSY;
}
}
@@ -954,6 +954,16 @@ status_t BufferQueue::setDefaultMaxBufferCount(int bufferCount) {
return setDefaultMaxBufferCountLocked(bufferCount);
}
+status_t BufferQueue::setMaxAcquiredBufferCount(int maxAcquiredBuffers) {
+ ATRACE_CALL();
+ Mutex::Autolock lock(mMutex);
+ if (mConnectedApi != NO_CONNECTED_API) {
+ return INVALID_OPERATION;
+ }
+ mMaxAcquiredBufferCount = maxAcquiredBuffers;
+ return OK;
+}
+
void BufferQueue::freeAllBuffersExceptHeadLocked() {
int head = -1;
if (!mQueue.empty()) {
@@ -996,7 +1006,12 @@ status_t BufferQueue::drainQueueAndFreeBuffersLocked() {
}
int BufferQueue::getMinMaxBufferCountLocked() const {
- return mSynchronousMode ? mMinUndequeuedBuffers : mMinUndequeuedBuffers + 1;
+ return getMinUndequeuedBufferCountLocked() + 1;
+}
+
+int BufferQueue::getMinUndequeuedBufferCountLocked() const {
+ return mSynchronousMode ? mMaxAcquiredBufferCount :
+ mMaxAcquiredBufferCount + 1;
}
int BufferQueue::getMaxBufferCountLocked() const {