Loading include/gui/BufferQueue.h +4 −0 Original line number Original line Diff line number Diff line Loading @@ -41,6 +41,10 @@ public: enum { INVALID_BUFFER_SLOT = -1 }; enum { INVALID_BUFFER_SLOT = -1 }; enum { STALE_BUFFER_SLOT = 1, NO_BUFFER_AVAILABLE }; enum { STALE_BUFFER_SLOT = 1, NO_BUFFER_AVAILABLE }; // When in async mode we reserve two slots in order to guarantee that the // producer and consumer can run asynchronously. enum { MAX_MAX_ACQUIRED_BUFFERS = NUM_BUFFER_SLOTS - 2 }; // ConsumerListener is the interface through which the BufferQueue notifies // ConsumerListener is the interface through which the BufferQueue notifies // the consumer of events that the consumer may wish to react to. Because // the consumer of events that the consumer may wish to react to. Because // the consumer will generally have a mutex that is locked during calls from // the consumer will generally have a mutex that is locked during calls from Loading libs/gui/BufferQueue.cpp +5 −0 Original line number Original line Diff line number Diff line Loading @@ -974,6 +974,11 @@ status_t BufferQueue::setDefaultMaxBufferCount(int bufferCount) { status_t BufferQueue::setMaxAcquiredBufferCount(int maxAcquiredBuffers) { status_t BufferQueue::setMaxAcquiredBufferCount(int maxAcquiredBuffers) { ATRACE_CALL(); ATRACE_CALL(); Mutex::Autolock lock(mMutex); Mutex::Autolock lock(mMutex); if (maxAcquiredBuffers < 1 || maxAcquiredBuffers > MAX_MAX_ACQUIRED_BUFFERS) { ST_LOGE("setMaxAcquiredBufferCount: invalid count specified: %d", maxAcquiredBuffers); return BAD_VALUE; } if (mConnectedApi != NO_CONNECTED_API) { if (mConnectedApi != NO_CONNECTED_API) { return INVALID_OPERATION; return INVALID_OPERATION; } } Loading libs/gui/tests/BufferQueue_test.cpp +21 −0 Original line number Original line Diff line number Diff line Loading @@ -93,4 +93,25 @@ TEST_F(BufferQueueTest, AcquireBuffer_ExceedsMaxAcquireCount_Fails) { ASSERT_EQ(INVALID_OPERATION, mBQ->acquireBuffer(&item)); ASSERT_EQ(INVALID_OPERATION, mBQ->acquireBuffer(&item)); } } TEST_F(BufferQueueTest, SetMaxAcquiredBufferCountWithIllegalValues_ReturnsError) { sp<DummyConsumer> dc(new DummyConsumer); mBQ->consumerConnect(dc); ASSERT_EQ(BAD_VALUE, mBQ->setMaxAcquiredBufferCount(0)); ASSERT_EQ(BAD_VALUE, mBQ->setMaxAcquiredBufferCount(-3)); ASSERT_EQ(BAD_VALUE, mBQ->setMaxAcquiredBufferCount( BufferQueue::MAX_MAX_ACQUIRED_BUFFERS+1)); ASSERT_EQ(BAD_VALUE, mBQ->setMaxAcquiredBufferCount(100)); } TEST_F(BufferQueueTest, SetMaxAcquiredBufferCountWithLegalValues_Succeeds) { sp<DummyConsumer> dc(new DummyConsumer); mBQ->consumerConnect(dc); ASSERT_EQ(OK, mBQ->setMaxAcquiredBufferCount(1)); ASSERT_EQ(OK, mBQ->setMaxAcquiredBufferCount(2)); ASSERT_EQ(OK, mBQ->setMaxAcquiredBufferCount( BufferQueue::MAX_MAX_ACQUIRED_BUFFERS)); } } // namespace android } // namespace android Loading
include/gui/BufferQueue.h +4 −0 Original line number Original line Diff line number Diff line Loading @@ -41,6 +41,10 @@ public: enum { INVALID_BUFFER_SLOT = -1 }; enum { INVALID_BUFFER_SLOT = -1 }; enum { STALE_BUFFER_SLOT = 1, NO_BUFFER_AVAILABLE }; enum { STALE_BUFFER_SLOT = 1, NO_BUFFER_AVAILABLE }; // When in async mode we reserve two slots in order to guarantee that the // producer and consumer can run asynchronously. enum { MAX_MAX_ACQUIRED_BUFFERS = NUM_BUFFER_SLOTS - 2 }; // ConsumerListener is the interface through which the BufferQueue notifies // ConsumerListener is the interface through which the BufferQueue notifies // the consumer of events that the consumer may wish to react to. Because // the consumer of events that the consumer may wish to react to. Because // the consumer will generally have a mutex that is locked during calls from // the consumer will generally have a mutex that is locked during calls from Loading
libs/gui/BufferQueue.cpp +5 −0 Original line number Original line Diff line number Diff line Loading @@ -974,6 +974,11 @@ status_t BufferQueue::setDefaultMaxBufferCount(int bufferCount) { status_t BufferQueue::setMaxAcquiredBufferCount(int maxAcquiredBuffers) { status_t BufferQueue::setMaxAcquiredBufferCount(int maxAcquiredBuffers) { ATRACE_CALL(); ATRACE_CALL(); Mutex::Autolock lock(mMutex); Mutex::Autolock lock(mMutex); if (maxAcquiredBuffers < 1 || maxAcquiredBuffers > MAX_MAX_ACQUIRED_BUFFERS) { ST_LOGE("setMaxAcquiredBufferCount: invalid count specified: %d", maxAcquiredBuffers); return BAD_VALUE; } if (mConnectedApi != NO_CONNECTED_API) { if (mConnectedApi != NO_CONNECTED_API) { return INVALID_OPERATION; return INVALID_OPERATION; } } Loading
libs/gui/tests/BufferQueue_test.cpp +21 −0 Original line number Original line Diff line number Diff line Loading @@ -93,4 +93,25 @@ TEST_F(BufferQueueTest, AcquireBuffer_ExceedsMaxAcquireCount_Fails) { ASSERT_EQ(INVALID_OPERATION, mBQ->acquireBuffer(&item)); ASSERT_EQ(INVALID_OPERATION, mBQ->acquireBuffer(&item)); } } TEST_F(BufferQueueTest, SetMaxAcquiredBufferCountWithIllegalValues_ReturnsError) { sp<DummyConsumer> dc(new DummyConsumer); mBQ->consumerConnect(dc); ASSERT_EQ(BAD_VALUE, mBQ->setMaxAcquiredBufferCount(0)); ASSERT_EQ(BAD_VALUE, mBQ->setMaxAcquiredBufferCount(-3)); ASSERT_EQ(BAD_VALUE, mBQ->setMaxAcquiredBufferCount( BufferQueue::MAX_MAX_ACQUIRED_BUFFERS+1)); ASSERT_EQ(BAD_VALUE, mBQ->setMaxAcquiredBufferCount(100)); } TEST_F(BufferQueueTest, SetMaxAcquiredBufferCountWithLegalValues_Succeeds) { sp<DummyConsumer> dc(new DummyConsumer); mBQ->consumerConnect(dc); ASSERT_EQ(OK, mBQ->setMaxAcquiredBufferCount(1)); ASSERT_EQ(OK, mBQ->setMaxAcquiredBufferCount(2)); ASSERT_EQ(OK, mBQ->setMaxAcquiredBufferCount( BufferQueue::MAX_MAX_ACQUIRED_BUFFERS)); } } // namespace android } // namespace android