summaryrefslogtreecommitdiffstats
path: root/libs/gui
diff options
context:
space:
mode:
authorJamie Gennis <jgennis@google.com>2011-11-16 11:34:30 -0800
committerAndroid (Google) Code Review <android-gerrit@google.com>2011-11-16 11:34:30 -0800
commitc1ef3c4d7d008b04331c56490ec755f040b3e57a (patch)
tree476197e8e57e9a4d71714640cfb24601b41590e0 /libs/gui
parentdfc0992233ddcef3851a0b2566d8bbc2c9dfa4e0 (diff)
parenta929748ddb67cbece3337c7fda7877fdeb973aa4 (diff)
downloadframeworks_native-c1ef3c4d7d008b04331c56490ec755f040b3e57a.zip
frameworks_native-c1ef3c4d7d008b04331c56490ec755f040b3e57a.tar.gz
frameworks_native-c1ef3c4d7d008b04331c56490ec755f040b3e57a.tar.bz2
Merge "SurfaceTexture: Fix to return the oldest of free buffers to Client on Dequeue call" into ics-mr1
Diffstat (limited to 'libs/gui')
-rw-r--r--libs/gui/SurfaceTexture.cpp22
1 files changed, 17 insertions, 5 deletions
diff --git a/libs/gui/SurfaceTexture.cpp b/libs/gui/SurfaceTexture.cpp
index 374f3c5..ee54bf4 100644
--- a/libs/gui/SurfaceTexture.cpp
+++ b/libs/gui/SurfaceTexture.cpp
@@ -116,7 +116,8 @@ SurfaceTexture::SurfaceTexture(GLuint tex, bool allowSynchronousMode,
mAllowSynchronousMode(allowSynchronousMode),
mConnectedApi(NO_CONNECTED_API),
mAbandoned(false),
- mTexTarget(texTarget) {
+ mTexTarget(texTarget),
+ mFrameCounter(0) {
// Choose a name using the PID and a process-unique ID.
mName = String8::format("unnamed-%d-%d", getpid(), createProcessUniqueId());
@@ -264,7 +265,8 @@ status_t SurfaceTexture::dequeueBuffer(int *outBuf, uint32_t w, uint32_t h,
status_t returnFlags(OK);
- int found, foundSync;
+ int found = -1;
+ int foundSync = -1;
int dequeuedCount = 0;
bool tryAgain = true;
while (tryAgain) {
@@ -337,9 +339,14 @@ status_t SurfaceTexture::dequeueBuffer(int *outBuf, uint32_t w, uint32_t h,
}
} else {
if (state == BufferSlot::FREE) {
- foundSync = i;
- found = i;
- break;
+ /** For Asynchronous mode, we need to return the oldest of free buffers
+ * There is only one instance when the Framecounter overflows, this logic
+ * might return the earlier buffer to client. Which is a negligible impact
+ **/
+ if (found < 0 || mSlots[i].mFrameNumber < mSlots[found].mFrameNumber) {
+ foundSync = i;
+ found = i;
+ }
}
}
}
@@ -531,6 +538,9 @@ status_t SurfaceTexture::queueBuffer(int buf, int64_t timestamp,
mSlots[buf].mTransform = mNextTransform;
mSlots[buf].mScalingMode = mNextScalingMode;
mSlots[buf].mTimestamp = timestamp;
+ mFrameCounter++;
+ mSlots[buf].mFrameNumber = mFrameCounter;
+
mDequeueCondition.signal();
*outWidth = mDefaultWidth;
@@ -564,6 +574,7 @@ void SurfaceTexture::cancelBuffer(int buf) {
return;
}
mSlots[buf].mBufferState = BufferSlot::FREE;
+ mSlots[buf].mFrameNumber = 0;
mDequeueCondition.signal();
}
@@ -897,6 +908,7 @@ void SurfaceTexture::setFrameAvailableListener(
void SurfaceTexture::freeBufferLocked(int i) {
mSlots[i].mGraphicBuffer = 0;
mSlots[i].mBufferState = BufferSlot::FREE;
+ mSlots[i].mFrameNumber = 0;
if (mSlots[i].mEglImage != EGL_NO_IMAGE_KHR) {
eglDestroyImageKHR(mSlots[i].mEglDisplay, mSlots[i].mEglImage);
mSlots[i].mEglImage = EGL_NO_IMAGE_KHR;