summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDaniel Lam <dalam@google.com>2012-03-26 20:37:15 -0700
committerDaniel Lam <dalam@google.com>2012-04-06 21:02:13 -0700
commitabe61bfda4938abd932465e27c29ba9e41aea606 (patch)
tree666da3c021038d22a7c9b2d995c32264f9057af7
parenta344c2bb4de5396c4012b6215f9ccb9f5d91a868 (diff)
downloadframeworks_native-abe61bfda4938abd932465e27c29ba9e41aea606.zip
frameworks_native-abe61bfda4938abd932465e27c29ba9e41aea606.tar.gz
frameworks_native-abe61bfda4938abd932465e27c29ba9e41aea606.tar.bz2
BufferQueue no longer hardcodes buffer counts
BufferQueue is now more flexible as it can be used by SurfaceMediaSource in addition to SurfaceTexture. Change-Id: I4222be8918d63372c44fcd412d9ad241c6a3eeb9
-rw-r--r--include/gui/BufferQueue.h19
-rw-r--r--include/gui/SurfaceTextureClient.h1
-rw-r--r--libs/gui/BufferQueue.cpp26
3 files changed, 30 insertions, 16 deletions
diff --git a/include/gui/BufferQueue.h b/include/gui/BufferQueue.h
index 57b9f8a..14f20d7 100644
--- a/include/gui/BufferQueue.h
+++ b/include/gui/BufferQueue.h
@@ -35,10 +35,6 @@ namespace android {
class BufferQueue : public BnSurfaceTexture {
public:
enum { MIN_UNDEQUEUED_BUFFERS = 2 };
- enum {
- MIN_ASYNC_BUFFER_SLOTS = MIN_UNDEQUEUED_BUFFERS + 1,
- MIN_SYNC_BUFFER_SLOTS = MIN_UNDEQUEUED_BUFFERS
- };
enum { NUM_BUFFER_SLOTS = 32 };
enum { NO_CONNECTED_API = 0 };
enum { INVALID_BUFFER_SLOT = -1 };
@@ -99,7 +95,8 @@ public:
// by producers and consumers.
// allowSynchronousMode specifies whether or not synchronous mode can be
// enabled.
- BufferQueue(bool allowSynchronousMode = true);
+ // bufferCount sets the minimum number of undequeued buffers for this queue
+ BufferQueue( bool allowSynchronousMode = true, int bufferCount = MIN_UNDEQUEUED_BUFFERS);
virtual ~BufferQueue();
virtual int query(int what, int* value);
@@ -402,6 +399,18 @@ private:
// in requestBuffers() if a format of zero is specified.
uint32_t mPixelFormat;
+ // mMinUndequeuedBuffers is a constraint on the number of buffers
+ // not dequeued at any time
+ int mMinUndequeuedBuffers;
+
+ // mMinAsyncBufferSlots is a constraint on the minimum mBufferCount
+ // when this BufferQueue is in asynchronous mode
+ int mMinAsyncBufferSlots;
+
+ // mMinSyncBufferSlots is a constraint on the minimum mBufferCount
+ // when this BufferQueue is in synchronous mode
+ int mMinSyncBufferSlots;
+
// mBufferCount is the number of buffer slots that the client and server
// must maintain. It defaults to MIN_ASYNC_BUFFER_SLOTS and can be changed
// by calling setBufferCount or setBufferCountServer
diff --git a/include/gui/SurfaceTextureClient.h b/include/gui/SurfaceTextureClient.h
index b68fa81..8c1e505 100644
--- a/include/gui/SurfaceTextureClient.h
+++ b/include/gui/SurfaceTextureClient.h
@@ -104,7 +104,6 @@ protected:
virtual int lock(ANativeWindow_Buffer* outBuffer, ARect* inOutDirtyBounds);
virtual int unlockAndPost();
- enum { MIN_UNDEQUEUED_BUFFERS = BufferQueue::MIN_UNDEQUEUED_BUFFERS };
enum { NUM_BUFFER_SLOTS = BufferQueue::NUM_BUFFER_SLOTS };
enum { DEFAULT_FORMAT = PIXEL_FORMAT_RGBA_8888 };
diff --git a/libs/gui/BufferQueue.cpp b/libs/gui/BufferQueue.cpp
index 2d042c8..84ccb3f 100644
--- a/libs/gui/BufferQueue.cpp
+++ b/libs/gui/BufferQueue.cpp
@@ -69,13 +69,16 @@ static int32_t createProcessUniqueId() {
return android_atomic_inc(&globalCounter);
}
-BufferQueue::BufferQueue( bool allowSynchronousMode ) :
+BufferQueue::BufferQueue( bool allowSynchronousMode, int bufferCount ) :
mDefaultWidth(1),
mDefaultHeight(1),
mPixelFormat(PIXEL_FORMAT_RGBA_8888),
- mBufferCount(MIN_ASYNC_BUFFER_SLOTS),
+ mMinUndequeuedBuffers(bufferCount),
+ mMinAsyncBufferSlots(bufferCount + 1),
+ mMinSyncBufferSlots(bufferCount),
+ mBufferCount(mMinAsyncBufferSlots),
mClientBufferCount(0),
- mServerBufferCount(MIN_ASYNC_BUFFER_SLOTS),
+ mServerBufferCount(mMinAsyncBufferSlots),
mSynchronousMode(false),
mAllowSynchronousMode(allowSynchronousMode),
mConnectedApi(NO_CONNECTED_API),
@@ -92,6 +95,9 @@ BufferQueue::BufferQueue( bool allowSynchronousMode ) :
ST_LOGV("BufferQueue");
sp<ISurfaceComposer> composer(ComposerService::getComposerService());
mGraphicBufferAlloc = composer->createGraphicBufferAlloc();
+ if (mGraphicBufferAlloc == 0) {
+ ST_LOGE("createGraphicBufferAlloc() failed in BufferQueue()");
+ }
}
BufferQueue::~BufferQueue() {
@@ -186,7 +192,7 @@ status_t BufferQueue::setBufferCount(int bufferCount) {
}
const int minBufferSlots = mSynchronousMode ?
- MIN_SYNC_BUFFER_SLOTS : MIN_ASYNC_BUFFER_SLOTS;
+ mMinSyncBufferSlots : mMinAsyncBufferSlots;
if (bufferCount == 0) {
mClientBufferCount = 0;
bufferCount = (mServerBufferCount >= minBufferSlots) ?
@@ -241,7 +247,7 @@ int BufferQueue::query(int what, int* outValue)
break;
case NATIVE_WINDOW_MIN_UNDEQUEUED_BUFFERS:
value = mSynchronousMode ?
- (MIN_UNDEQUEUED_BUFFERS-1) : MIN_UNDEQUEUED_BUFFERS;
+ (mMinUndequeuedBuffers-1) : mMinUndequeuedBuffers;
break;
default:
return BAD_VALUE;
@@ -317,7 +323,7 @@ status_t BufferQueue::dequeueBuffer(int *outBuf, uint32_t w, uint32_t h,
// wait on mDequeueCondition.
const int minBufferCountNeeded = mSynchronousMode ?
- MIN_SYNC_BUFFER_SLOTS : MIN_ASYNC_BUFFER_SLOTS;
+ mMinSyncBufferSlots : mMinAsyncBufferSlots;
const bool numberOfBuffersNeedsToChange = !mClientBufferCount &&
((mServerBufferCount != mBufferCount) ||
@@ -384,15 +390,15 @@ status_t BufferQueue::dequeueBuffer(int *outBuf, uint32_t w, uint32_t h,
// See whether a buffer has been queued since the last
// setBufferCount so we know whether to perform the
- // MIN_UNDEQUEUED_BUFFERS check below.
+ // mMinUndequeuedBuffers check below.
if (mBufferHasBeenQueued) {
// make sure the client is not trying to dequeue more buffers
// than allowed.
const int avail = mBufferCount - (dequeuedCount+1);
- if (avail < (MIN_UNDEQUEUED_BUFFERS-int(mSynchronousMode))) {
- ST_LOGE("dequeueBuffer: MIN_UNDEQUEUED_BUFFERS=%d exceeded "
+ if (avail < (mMinUndequeuedBuffers-int(mSynchronousMode))) {
+ ST_LOGE("dequeueBuffer: mMinUndequeuedBuffers=%d exceeded "
"(dequeued=%d)",
- MIN_UNDEQUEUED_BUFFERS-int(mSynchronousMode),
+ mMinUndequeuedBuffers-int(mSynchronousMode),
dequeuedCount);
return -EBUSY;
}