diff options
author | Jamie Gennis <jgennis@google.com> | 2012-08-28 17:18:50 -0700 |
---|---|---|
committer | Jamie Gennis <jgennis@google.com> | 2012-08-30 18:38:11 -0700 |
commit | 5e5efde7874a9fab650fd4b724ceef46db850470 (patch) | |
tree | ded507b494376a307ac4eae961484620edaf1789 /libs | |
parent | 72f096fb1ad0a0deadbfac5f88627461905d38e8 (diff) | |
download | frameworks_native-5e5efde7874a9fab650fd4b724ceef46db850470.zip frameworks_native-5e5efde7874a9fab650fd4b724ceef46db850470.tar.gz frameworks_native-5e5efde7874a9fab650fd4b724ceef46db850470.tar.bz2 |
BufferQueue: add a check for the max acquired bufs
This change adds an error check to ensure that consumers don't acquire more
buffers than the maximum that they set.
Change-Id: I026643564bde52732e4ee6146972b207ddbbba77
Diffstat (limited to 'libs')
-rw-r--r-- | libs/gui/BufferQueue.cpp | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/libs/gui/BufferQueue.cpp b/libs/gui/BufferQueue.cpp index db021ff..4640149 100644 --- a/libs/gui/BufferQueue.cpp +++ b/libs/gui/BufferQueue.cpp @@ -812,6 +812,23 @@ void BufferQueue::freeAllBuffersLocked() { status_t BufferQueue::acquireBuffer(BufferItem *buffer) { ATRACE_CALL(); Mutex::Autolock _l(mMutex); + + // Check that the consumer doesn't currently have the maximum number of + // buffers acquired. We allow the max buffer count to be exceeded by one + // buffer, so that the consumer can successfully set up the newly acquired + // buffer before releasing the old one. + int numAcquiredBuffers = 0; + for (int i = 0; i < NUM_BUFFER_SLOTS; i++) { + if (mSlots[i].mBufferState == BufferSlot::ACQUIRED) { + numAcquiredBuffers++; + } + } + if (numAcquiredBuffers >= mMaxAcquiredBufferCount+1) { + ST_LOGE("acquireBuffer: max acquired buffer count reached: %d (max=%d)", + numAcquiredBuffers, mMaxAcquiredBufferCount); + return INVALID_OPERATION; + } + // check if queue is empty // In asynchronous mode the list is guaranteed to be one buffer // deep, while in synchronous mode we use the oldest buffer. |