From bd5404d0312752e7c8946e8540129f0d2d97bcd7 Mon Sep 17 00:00:00 2001 From: Jamie Gennis Date: Sun, 26 Jun 2011 18:27:47 -0700 Subject: SurfaceTexture: change onFrameAvailable behavior This change alters the conditions under which the onFrameAvailable callback gets called by the C++ SurfaceTexture class. The new behavior is to call the callback whenever a frame gets queued that will be visible to the buffer consumer. This means that buffers queued in synchronous mode always trigger the callback, as those buffers will remain pending until they are consumed. Buffers queued in asynchronous mode will only trigger the callback if there was not previously an unconsumed buffer pending. The new behavior means that a consumer should perform a draw operation exactly once for every onFrameAvailable call that it recieves. This change also modifies SurfaceFlinger and the SurfaceTexture JNI to support of the new behavior. Change-Id: I8b2c6e00961d3d58b11c6af50b555b6e4c5f5b40 --- libs/gui/SurfaceTexture.cpp | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) (limited to 'libs/gui/SurfaceTexture.cpp') diff --git a/libs/gui/SurfaceTexture.cpp b/libs/gui/SurfaceTexture.cpp index 37e6d1187db8..96ab28420f5d 100644 --- a/libs/gui/SurfaceTexture.cpp +++ b/libs/gui/SurfaceTexture.cpp @@ -417,17 +417,22 @@ status_t SurfaceTexture::queueBuffer(int buf, int64_t timestamp) { return -EINVAL; } - if (mQueue.empty()) { - listener = mFrameAvailableListener; - } - if (mSynchronousMode) { - // in synchronous mode we queue all buffers in a FIFO + // In synchronous mode we queue all buffers in a FIFO. mQueue.push_back(buf); + + // Synchronous mode always signals that an additional frame should + // be consumed. + listener = mFrameAvailableListener; } else { - // in asynchronous mode we only keep the most recent buffer + // In asynchronous mode we only keep the most recent buffer. if (mQueue.empty()) { mQueue.push_back(buf); + + // Asynchronous mode only signals that a frame should be + // consumed if no previous frame was pending. If a frame were + // pending then the consumer would have already been notified. + listener = mFrameAvailableListener; } else { Fifo::iterator front(mQueue.begin()); // buffer currently queued is freed @@ -561,11 +566,6 @@ status_t SurfaceTexture::updateTexImage() { return OK; } -size_t SurfaceTexture::getQueuedCount() const { - Mutex::Autolock lock(mMutex); - return mQueue.size(); -} - bool SurfaceTexture::isExternalFormat(uint32_t format) { switch (format) { -- cgit v1.2.3-59-g8ed1b From 9fb5976367911d0ab42d296238f0f06d517e867d Mon Sep 17 00:00:00 2001 From: Jamie Gennis Date: Mon, 27 Jun 2011 15:41:52 -0700 Subject: SurfaceTexture: consume buffers after err checks This change moves the point at which queued buffers get consumed to after any error checks that could cause updateTexImage to fail. This way, if updateTexImage returns an error the buffer remains queued. --- libs/gui/SurfaceTexture.cpp | 23 +++++++++-------------- 1 file changed, 9 insertions(+), 14 deletions(-) (limited to 'libs/gui/SurfaceTexture.cpp') diff --git a/libs/gui/SurfaceTexture.cpp b/libs/gui/SurfaceTexture.cpp index 96ab28420f5d..0925001965dd 100644 --- a/libs/gui/SurfaceTexture.cpp +++ b/libs/gui/SurfaceTexture.cpp @@ -488,24 +488,14 @@ status_t SurfaceTexture::setTransform(uint32_t transform) { status_t SurfaceTexture::updateTexImage() { LOGV("SurfaceTexture::updateTexImage"); - Mutex::Autolock lock(mMutex); - int buf = mCurrentTexture; + // In asynchronous mode the list is guaranteed to be one buffer + // deep, while in synchronous mode we use the oldest buffer. if (!mQueue.empty()) { - // in asynchronous mode the list is guaranteed to be one buffer deep, - // while in synchronous mode we use the oldest buffer Fifo::iterator front(mQueue.begin()); - buf = *front; - mQueue.erase(front); - if (mQueue.isEmpty()) { - mDequeueCondition.signal(); - } - } + int buf = *front; - // Initially both mCurrentTexture and buf are INVALID_BUFFER_SLOT, - // so this check will fail until a buffer gets queued. - if (mCurrentTexture != buf) { // Update the GL texture object. EGLImageKHR image = mSlots[buf].mEglImage; if (image == EGL_NO_IMAGE_KHR) { @@ -543,7 +533,7 @@ status_t SurfaceTexture::updateTexImage() { } if (mCurrentTexture != INVALID_BUFFER_SLOT) { - // the current buffer becomes FREE if it was still in the queued + // The current buffer becomes FREE if it was still in the queued // state. If it has already been given to the client // (synchronous mode), then it stays in DEQUEUED state. if (mSlots[mCurrentTexture].mBufferState == BufferSlot::QUEUED) @@ -558,11 +548,16 @@ status_t SurfaceTexture::updateTexImage() { mCurrentTransform = mSlots[buf].mTransform; mCurrentTimestamp = mSlots[buf].mTimestamp; computeCurrentTransformMatrix(); + + // Now that we've passed the point at which failures can happen, + // it's safe to remove the buffer from the front of the queue. + mQueue.erase(front); mDequeueCondition.signal(); } else { // We always bind the texture even if we don't update its contents. glBindTexture(mCurrentTextureTarget, mTexName); } + return OK; } -- cgit v1.2.3-59-g8ed1b