Loading libs/gui/tests/SurfaceTexture_test.cpp +30 −5 Original line number Diff line number Diff line Loading @@ -14,6 +14,7 @@ * limitations under the License. */ #define LOG_TAG "SurfaceTexture_test" //#define LOG_NDEBUG 0 #include <gtest/gtest.h> Loading Loading @@ -379,6 +380,13 @@ protected: ASSERT_NE(-1, mTexMatrixHandle); } virtual void TearDown() { mANW.clear(); mSTC.clear(); mST.clear(); GLTest::TearDown(); } // drawTexture draws the SurfaceTexture over the entire GL viewport. void drawTexture() { const GLfloat triangleVertices[] = { Loading Loading @@ -1089,13 +1097,21 @@ protected: // synchronously from SurfaceTexture::queueBuffer. class FrameCondition : public SurfaceTexture::FrameAvailableListener { public: FrameCondition(): mFrameAvailable(false), mFrameFinished(false) { } // waitForFrame waits for the next frame to arrive. This should be // called from the consumer thread once for every frame expected by the // test. void waitForFrame() { LOGV("+waitForFrame"); Mutex::Autolock lock(mMutex); status_t result = mFrameAvailableCondition.wait(mMutex); LOGV("+waitForFrame"); while (!mFrameAvailable) { mFrameAvailableCondition.wait(mMutex); } mFrameAvailable = false; LOGV("-waitForFrame"); } Loading @@ -1103,22 +1119,30 @@ protected: // on to produce the next frame. This should be called by the consumer // thread once for every frame expected by the test. void finishFrame() { LOGV("+finishFrame"); Mutex::Autolock lock(mMutex); LOGV("+finishFrame"); mFrameFinished = true; mFrameFinishCondition.signal(); LOGV("-finishFrame"); } // This should be called by SurfaceTexture on the producer thread. virtual void onFrameAvailable() { LOGV("+onFrameAvailable"); Mutex::Autolock lock(mMutex); LOGV("+onFrameAvailable"); mFrameAvailable = true; mFrameAvailableCondition.signal(); while (!mFrameFinished) { mFrameFinishCondition.wait(mMutex); } mFrameFinished = false; LOGV("-onFrameAvailable"); } protected: bool mFrameAvailable; bool mFrameFinished; Mutex mMutex; Condition mFrameAvailableCondition; Condition mFrameFinishCondition; Loading Loading @@ -1164,6 +1188,7 @@ protected: } mProducerThread.clear(); mFC.clear(); SurfaceTextureGLTest::TearDown(); } void runProducerThread(const sp<ProducerThread> producerThread) { Loading Loading
libs/gui/tests/SurfaceTexture_test.cpp +30 −5 Original line number Diff line number Diff line Loading @@ -14,6 +14,7 @@ * limitations under the License. */ #define LOG_TAG "SurfaceTexture_test" //#define LOG_NDEBUG 0 #include <gtest/gtest.h> Loading Loading @@ -379,6 +380,13 @@ protected: ASSERT_NE(-1, mTexMatrixHandle); } virtual void TearDown() { mANW.clear(); mSTC.clear(); mST.clear(); GLTest::TearDown(); } // drawTexture draws the SurfaceTexture over the entire GL viewport. void drawTexture() { const GLfloat triangleVertices[] = { Loading Loading @@ -1089,13 +1097,21 @@ protected: // synchronously from SurfaceTexture::queueBuffer. class FrameCondition : public SurfaceTexture::FrameAvailableListener { public: FrameCondition(): mFrameAvailable(false), mFrameFinished(false) { } // waitForFrame waits for the next frame to arrive. This should be // called from the consumer thread once for every frame expected by the // test. void waitForFrame() { LOGV("+waitForFrame"); Mutex::Autolock lock(mMutex); status_t result = mFrameAvailableCondition.wait(mMutex); LOGV("+waitForFrame"); while (!mFrameAvailable) { mFrameAvailableCondition.wait(mMutex); } mFrameAvailable = false; LOGV("-waitForFrame"); } Loading @@ -1103,22 +1119,30 @@ protected: // on to produce the next frame. This should be called by the consumer // thread once for every frame expected by the test. void finishFrame() { LOGV("+finishFrame"); Mutex::Autolock lock(mMutex); LOGV("+finishFrame"); mFrameFinished = true; mFrameFinishCondition.signal(); LOGV("-finishFrame"); } // This should be called by SurfaceTexture on the producer thread. virtual void onFrameAvailable() { LOGV("+onFrameAvailable"); Mutex::Autolock lock(mMutex); LOGV("+onFrameAvailable"); mFrameAvailable = true; mFrameAvailableCondition.signal(); while (!mFrameFinished) { mFrameFinishCondition.wait(mMutex); } mFrameFinished = false; LOGV("-onFrameAvailable"); } protected: bool mFrameAvailable; bool mFrameFinished; Mutex mMutex; Condition mFrameAvailableCondition; Condition mFrameFinishCondition; Loading Loading @@ -1164,6 +1188,7 @@ protected: } mProducerThread.clear(); mFC.clear(); SurfaceTextureGLTest::TearDown(); } void runProducerThread(const sp<ProducerThread> producerThread) { Loading