Loading include/gui/SurfaceTexture.h +10 −0 Original line number Original line Diff line number Diff line Loading @@ -46,6 +46,11 @@ public: enum { NUM_BUFFER_SLOTS = 32 }; enum { NUM_BUFFER_SLOTS = 32 }; struct FrameAvailableListener : public virtual RefBase { 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; virtual void onFrameAvailable() = 0; }; }; Loading Loading @@ -96,6 +101,11 @@ public: // target texture belongs is bound to the calling thread. // target texture belongs is bound to the calling thread. status_t updateTexImage(); 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 // setBufferCountServer set the buffer count. If the client has requested // a buffer count using setBufferCount, the server-buffer count will // a buffer count using setBufferCount, the server-buffer count will // take effect once the client sets the count back to zero. // take effect once the client sets the count back to zero. Loading libs/gui/SurfaceTexture.cpp +20 −4 Original line number Original line Diff line number Diff line Loading @@ -385,6 +385,10 @@ status_t SurfaceTexture::setSynchronousMode(bool enabled) { status_t SurfaceTexture::queueBuffer(int buf, int64_t timestamp) { status_t SurfaceTexture::queueBuffer(int buf, int64_t timestamp) { LOGV("SurfaceTexture::queueBuffer"); LOGV("SurfaceTexture::queueBuffer"); sp<FrameAvailableListener> listener; { // scope for the lock Mutex::Autolock lock(mMutex); Mutex::Autolock lock(mMutex); if (buf < 0 || buf >= mBufferCount) { if (buf < 0 || buf >= mBufferCount) { LOGE("queueBuffer: slot index out of range [0, %d]: %d", LOGE("queueBuffer: slot index out of range [0, %d]: %d", Loading @@ -403,6 +407,10 @@ status_t SurfaceTexture::queueBuffer(int buf, int64_t timestamp) { return -EINVAL; return -EINVAL; } } if (mQueue.empty()) { listener = mFrameAvailableListener; } if (mSynchronousMode) { 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); mQueue.push_back(buf); Loading @@ -423,11 +431,13 @@ status_t SurfaceTexture::queueBuffer(int buf, int64_t timestamp) { mSlots[buf].mLastQueuedCrop = mNextCrop; mSlots[buf].mLastQueuedCrop = mNextCrop; mSlots[buf].mLastQueuedTransform = mNextTransform; mSlots[buf].mLastQueuedTransform = mNextTransform; mSlots[buf].mLastQueuedTimestamp = timestamp; mSlots[buf].mLastQueuedTimestamp = timestamp; mDequeueCondition.signal(); } // scope for the lock if (mFrameAvailableListener != 0) { // call back without lock held mFrameAvailableListener->onFrameAvailable(); if (listener != 0) { listener->onFrameAvailable(); } } mDequeueCondition.signal(); return OK; return OK; } } Loading Loading @@ -463,6 +473,7 @@ status_t SurfaceTexture::setTransform(uint32_t transform) { status_t SurfaceTexture::updateTexImage() { status_t SurfaceTexture::updateTexImage() { LOGV("SurfaceTexture::updateTexImage"); LOGV("SurfaceTexture::updateTexImage"); Mutex::Autolock lock(mMutex); Mutex::Autolock lock(mMutex); int buf = mCurrentTexture; int buf = mCurrentTexture; Loading Loading @@ -496,7 +507,7 @@ status_t SurfaceTexture::updateTexImage() { GLint error; GLint error; while ((error = glGetError()) != GL_NO_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); GLenum target = getTextureTarget(mSlots[buf].mGraphicBuffer->format); Loading Loading @@ -539,6 +550,11 @@ status_t SurfaceTexture::updateTexImage() { return OK; return OK; } } size_t SurfaceTexture::getQueuedCount() const { Mutex::Autolock lock(mMutex); return mQueue.size(); } bool SurfaceTexture::isExternalFormat(uint32_t format) bool SurfaceTexture::isExternalFormat(uint32_t format) { { switch (format) { switch (format) { Loading Loading
include/gui/SurfaceTexture.h +10 −0 Original line number Original line Diff line number Diff line Loading @@ -46,6 +46,11 @@ public: enum { NUM_BUFFER_SLOTS = 32 }; enum { NUM_BUFFER_SLOTS = 32 }; struct FrameAvailableListener : public virtual RefBase { 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; virtual void onFrameAvailable() = 0; }; }; Loading Loading @@ -96,6 +101,11 @@ public: // target texture belongs is bound to the calling thread. // target texture belongs is bound to the calling thread. status_t updateTexImage(); 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 // setBufferCountServer set the buffer count. If the client has requested // a buffer count using setBufferCount, the server-buffer count will // a buffer count using setBufferCount, the server-buffer count will // take effect once the client sets the count back to zero. // take effect once the client sets the count back to zero. Loading
libs/gui/SurfaceTexture.cpp +20 −4 Original line number Original line Diff line number Diff line Loading @@ -385,6 +385,10 @@ status_t SurfaceTexture::setSynchronousMode(bool enabled) { status_t SurfaceTexture::queueBuffer(int buf, int64_t timestamp) { status_t SurfaceTexture::queueBuffer(int buf, int64_t timestamp) { LOGV("SurfaceTexture::queueBuffer"); LOGV("SurfaceTexture::queueBuffer"); sp<FrameAvailableListener> listener; { // scope for the lock Mutex::Autolock lock(mMutex); Mutex::Autolock lock(mMutex); if (buf < 0 || buf >= mBufferCount) { if (buf < 0 || buf >= mBufferCount) { LOGE("queueBuffer: slot index out of range [0, %d]: %d", LOGE("queueBuffer: slot index out of range [0, %d]: %d", Loading @@ -403,6 +407,10 @@ status_t SurfaceTexture::queueBuffer(int buf, int64_t timestamp) { return -EINVAL; return -EINVAL; } } if (mQueue.empty()) { listener = mFrameAvailableListener; } if (mSynchronousMode) { 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); mQueue.push_back(buf); Loading @@ -423,11 +431,13 @@ status_t SurfaceTexture::queueBuffer(int buf, int64_t timestamp) { mSlots[buf].mLastQueuedCrop = mNextCrop; mSlots[buf].mLastQueuedCrop = mNextCrop; mSlots[buf].mLastQueuedTransform = mNextTransform; mSlots[buf].mLastQueuedTransform = mNextTransform; mSlots[buf].mLastQueuedTimestamp = timestamp; mSlots[buf].mLastQueuedTimestamp = timestamp; mDequeueCondition.signal(); } // scope for the lock if (mFrameAvailableListener != 0) { // call back without lock held mFrameAvailableListener->onFrameAvailable(); if (listener != 0) { listener->onFrameAvailable(); } } mDequeueCondition.signal(); return OK; return OK; } } Loading Loading @@ -463,6 +473,7 @@ status_t SurfaceTexture::setTransform(uint32_t transform) { status_t SurfaceTexture::updateTexImage() { status_t SurfaceTexture::updateTexImage() { LOGV("SurfaceTexture::updateTexImage"); LOGV("SurfaceTexture::updateTexImage"); Mutex::Autolock lock(mMutex); Mutex::Autolock lock(mMutex); int buf = mCurrentTexture; int buf = mCurrentTexture; Loading Loading @@ -496,7 +507,7 @@ status_t SurfaceTexture::updateTexImage() { GLint error; GLint error; while ((error = glGetError()) != GL_NO_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); GLenum target = getTextureTarget(mSlots[buf].mGraphicBuffer->format); Loading Loading @@ -539,6 +550,11 @@ status_t SurfaceTexture::updateTexImage() { return OK; return OK; } } size_t SurfaceTexture::getQueuedCount() const { Mutex::Autolock lock(mMutex); return mQueue.size(); } bool SurfaceTexture::isExternalFormat(uint32_t format) bool SurfaceTexture::isExternalFormat(uint32_t format) { { switch (format) { switch (format) { Loading