summaryrefslogtreecommitdiffstats
path: root/libs
diff options
context:
space:
mode:
authorJamie Gennis <jgennis@google.com>2011-05-23 18:44:04 -0700
committerJamie Gennis <jgennis@google.com>2011-05-25 12:27:33 -0700
commit44e9e0d825aef362a3413dfd63812962f5de1b1a (patch)
treea9f39b6996e0b4092c37b0841da1adfcb3d61ad7 /libs
parenta218715a7fca98c868feccee4751c94e38b676ff (diff)
downloadframeworks_base-44e9e0d825aef362a3413dfd63812962f5de1b1a.zip
frameworks_base-44e9e0d825aef362a3413dfd63812962f5de1b1a.tar.gz
frameworks_base-44e9e0d825aef362a3413dfd63812962f5de1b1a.tar.bz2
SurfaceTexture: fix an error check in dequeueBuffer.
This change fixes the MIN_UNDEQUEUED_BUFFERS error check in dequeueBuffer. The check should only be performed if a buffer has been queued since the last time the buffer count was changed by the client. The check must be applied conditionally because video decoders require all the bufferes to be dequeued and registered before beginning the decode. Change-Id: I08d96b380544e395c2fcf0f3983a199bfd695b09
Diffstat (limited to 'libs')
-rw-r--r--libs/gui/SurfaceTexture.cpp22
-rw-r--r--libs/gui/tests/SurfaceTextureClient_test.cpp9
2 files changed, 21 insertions, 10 deletions
diff --git a/libs/gui/SurfaceTexture.cpp b/libs/gui/SurfaceTexture.cpp
index bcf7a63..ee97dcf 100644
--- a/libs/gui/SurfaceTexture.cpp
+++ b/libs/gui/SurfaceTexture.cpp
@@ -285,15 +285,19 @@ status_t SurfaceTexture::dequeueBuffer(int *outBuf, uint32_t w, uint32_t h,
return -EINVAL;
}
- // 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))) {
- LOGE("dequeueBuffer: MIN_UNDEQUEUED_BUFFERS=%d exceeded (dequeued=%d)",
- MIN_UNDEQUEUED_BUFFERS-int(mSynchronousMode),
- dequeuedCount);
- // TODO: Enable this error report after we fix issue 4435022
- // return -EBUSY;
+ // See whether a buffer has been queued since the last setBufferCount so
+ // we know whether to perform the MIN_UNDEQUEUED_BUFFERS check below.
+ bool bufferHasBeenQueued = mCurrentTexture != INVALID_BUFFER_SLOT;
+ if (bufferHasBeenQueued) {
+ // 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))) {
+ LOGE("dequeueBuffer: MIN_UNDEQUEUED_BUFFERS=%d exceeded (dequeued=%d)",
+ MIN_UNDEQUEUED_BUFFERS-int(mSynchronousMode),
+ dequeuedCount);
+ return -EBUSY;
+ }
}
// we're in synchronous mode and didn't find a buffer, we need to wait
diff --git a/libs/gui/tests/SurfaceTextureClient_test.cpp b/libs/gui/tests/SurfaceTextureClient_test.cpp
index 8340337..8000bde 100644
--- a/libs/gui/tests/SurfaceTextureClient_test.cpp
+++ b/libs/gui/tests/SurfaceTextureClient_test.cpp
@@ -431,10 +431,13 @@ TEST_F(SurfaceTextureClientTest, SurfaceTextureSyncModeMinUndequeued) {
android_native_buffer_t* buf[3];
ASSERT_EQ(OK, st->setSynchronousMode(true));
ASSERT_EQ(OK, native_window_set_buffer_count(anw.get(), 3));
+
+ // We should be able to dequeue all the buffers before we've queued any.
EXPECT_EQ(OK, anw->dequeueBuffer(anw.get(), &buf[0]));
EXPECT_EQ(OK, anw->dequeueBuffer(anw.get(), &buf[1]));
- EXPECT_EQ(-EBUSY, anw->dequeueBuffer(anw.get(), &buf[2]));
+ EXPECT_EQ(OK, anw->dequeueBuffer(anw.get(), &buf[2]));
+ ASSERT_EQ(OK, anw->cancelBuffer(anw.get(), buf[2]));
ASSERT_EQ(OK, anw->queueBuffer(anw.get(), buf[1]));
EXPECT_EQ(OK, st->updateTexImage());
@@ -442,6 +445,10 @@ TEST_F(SurfaceTextureClientTest, SurfaceTextureSyncModeMinUndequeued) {
EXPECT_EQ(OK, anw->dequeueBuffer(anw.get(), &buf[2]));
+ // Once we've queued a buffer, however we should not be able to dequeue more
+ // than (buffer-count - MIN_UNDEQUEUED_BUFFERS), which is 2 in this case.
+ EXPECT_EQ(-EBUSY, anw->dequeueBuffer(anw.get(), &buf[1]));
+
ASSERT_EQ(OK, anw->cancelBuffer(anw.get(), buf[0]));
ASSERT_EQ(OK, anw->cancelBuffer(anw.get(), buf[2]));
}