diff options
| -rw-r--r-- | include/gui/SurfaceTexture.h | 10 | ||||
| -rw-r--r-- | libs/gui/SurfaceTexture.cpp | 24 |
2 files changed, 30 insertions, 4 deletions
diff --git a/include/gui/SurfaceTexture.h b/include/gui/SurfaceTexture.h index 45f18211dc..43b2fa92dd 100644 --- a/include/gui/SurfaceTexture.h +++ b/include/gui/SurfaceTexture.h @@ -46,6 +46,11 @@ public: enum { NUM_BUFFER_SLOTS = 32 }; struct FrameAvailableListener : public virtual RefBase { + // onFrameAvailable() is called from queueBuffer() is the FIFO is + // empty. You can use SurfaceTexture::getQueuedCount() to + // figure out if there are more frames waiting. + // This is called without any lock held can be called concurrently by + // multiple threads. virtual void onFrameAvailable() = 0; }; @@ -96,6 +101,11 @@ public: // target texture belongs is bound to the calling thread. status_t updateTexImage(); + // getqueuedCount returns the number of queued frames waiting in the + // FIFO. In asynchronous mode, this always returns 0 or 1 since + // frames are not accumulating in the FIFO. + size_t getQueuedCount() const; + // setBufferCountServer set the buffer count. If the client has requested // a buffer count using setBufferCount, the server-buffer count will // take effect once the client sets the count back to zero. diff --git a/libs/gui/SurfaceTexture.cpp b/libs/gui/SurfaceTexture.cpp index 55b1a9cebb..d7c449c353 100644 --- a/libs/gui/SurfaceTexture.cpp +++ b/libs/gui/SurfaceTexture.cpp @@ -385,6 +385,10 @@ status_t SurfaceTexture::setSynchronousMode(bool enabled) { status_t SurfaceTexture::queueBuffer(int buf, int64_t timestamp) { LOGV("SurfaceTexture::queueBuffer"); + + sp<FrameAvailableListener> listener; + + { // scope for the lock Mutex::Autolock lock(mMutex); if (buf < 0 || buf >= mBufferCount) { LOGE("queueBuffer: slot index out of range [0, %d]: %d", @@ -403,6 +407,10 @@ 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 mQueue.push_back(buf); @@ -423,11 +431,13 @@ status_t SurfaceTexture::queueBuffer(int buf, int64_t timestamp) { mSlots[buf].mLastQueuedCrop = mNextCrop; mSlots[buf].mLastQueuedTransform = mNextTransform; mSlots[buf].mLastQueuedTimestamp = timestamp; + mDequeueCondition.signal(); + } // scope for the lock - if (mFrameAvailableListener != 0) { - mFrameAvailableListener->onFrameAvailable(); + // call back without lock held + if (listener != 0) { + listener->onFrameAvailable(); } - mDequeueCondition.signal(); return OK; } @@ -463,6 +473,7 @@ status_t SurfaceTexture::setTransform(uint32_t transform) { status_t SurfaceTexture::updateTexImage() { LOGV("SurfaceTexture::updateTexImage"); + Mutex::Autolock lock(mMutex); int buf = mCurrentTexture; @@ -496,7 +507,7 @@ status_t SurfaceTexture::updateTexImage() { GLint error; while ((error = glGetError()) != GL_NO_ERROR) { - LOGE("GL error cleared before updating SurfaceTexture: %#04x", error); + LOGW("updateTexImage: clearing GL error: %#04x", error); } GLenum target = getTextureTarget(mSlots[buf].mGraphicBuffer->format); @@ -539,6 +550,11 @@ 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) { |