Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 2640bfd1 authored by Jamie Gennis's avatar Jamie Gennis
Browse files

SurfaceTexture: fix SurfaceTextureGLToGLTest

This change fixes a couple different issues in the
SurfaceTextureGLToGLTest test fixture:
  - incorrect use of conditions
  - move logging after the locks are acquired
  - call the parent class's TearDown method
  - clean up the SurfaceTexture before eglTerminate gets called

Change-Id: I6960e5ab7f144225f01a2089d3f849c99fed0b38
parent 6a90b3a3
Loading
Loading
Loading
Loading
+30 −5
Original line number Diff line number Diff line
@@ -14,6 +14,7 @@
 * limitations under the License.
 */

#define LOG_TAG "SurfaceTexture_test"
//#define LOG_NDEBUG 0

#include <gtest/gtest.h>
@@ -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[] = {
@@ -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");
        }

@@ -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;
@@ -1164,6 +1188,7 @@ protected:
        }
        mProducerThread.clear();
        mFC.clear();
        SurfaceTextureGLTest::TearDown();
    }

    void runProducerThread(const sp<ProducerThread> producerThread) {