diff options
author | Jesse Hall <jessehall@google.com> | 2011-10-20 09:09:31 -0700 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2011-10-20 09:09:31 -0700 |
commit | d10475e24f7b393d9f79f3322aabdccc3292131e (patch) | |
tree | cf38897e5fe0e8c58e39ae6de09a396e1babb572 | |
parent | 87e87c210efd04a520c64af90e32bbbc7f3ea501 (diff) | |
parent | 59940b42c34d633f7e5d82e5489423e32fce31ae (diff) | |
download | frameworks_base-d10475e24f7b393d9f79f3322aabdccc3292131e.zip frameworks_base-d10475e24f7b393d9f79f3322aabdccc3292131e.tar.gz frameworks_base-d10475e24f7b393d9f79f3322aabdccc3292131e.tar.bz2 |
Merge "SurfaceTexture: add tests for buffer leaks"
-rw-r--r-- | libs/gui/tests/SurfaceTexture_test.cpp | 84 |
1 files changed, 83 insertions, 1 deletions
diff --git a/libs/gui/tests/SurfaceTexture_test.cpp b/libs/gui/tests/SurfaceTexture_test.cpp index b8bc454..5daafd5 100644 --- a/libs/gui/tests/SurfaceTexture_test.cpp +++ b/libs/gui/tests/SurfaceTexture_test.cpp @@ -334,7 +334,7 @@ protected: class SurfaceTextureGLTest : public GLTest { protected: - static const GLint TEX_ID = 123; + enum { TEX_ID = 123 }; virtual void SetUp() { GLTest::SetUp(); @@ -1438,4 +1438,86 @@ TEST_F(SurfaceTextureGLToGLTest, DISABLED_RepeatedSwapBuffersWhileDequeueStalled } } +TEST_F(SurfaceTextureGLTest, EglDestroySurfaceUnrefsBuffers) { + EGLSurface stcEglSurface = eglCreateWindowSurface(mEglDisplay, mGlConfig, + mANW.get(), NULL); + ASSERT_EQ(EGL_SUCCESS, eglGetError()); + ASSERT_NE(EGL_NO_SURFACE, stcEglSurface); + + sp<GraphicBuffer> buffers[3]; + + for (int i = 0; i < 3; i++) { + // Produce a frame + EXPECT_TRUE(eglMakeCurrent(mEglDisplay, stcEglSurface, stcEglSurface, + mEglContext)); + ASSERT_EQ(EGL_SUCCESS, eglGetError()); + glClear(GL_COLOR_BUFFER_BIT); + eglSwapBuffers(mEglDisplay, stcEglSurface); + + // Consume a frame + EXPECT_TRUE(eglMakeCurrent(mEglDisplay, mEglSurface, mEglSurface, + mEglContext)); + ASSERT_EQ(EGL_SUCCESS, eglGetError()); + mST->updateTexImage(); + buffers[i] = mST->getCurrentBuffer(); + } + + // Destroy the GL texture object to release its ref on buffers[2]. + GLuint texID = TEX_ID; + glDeleteTextures(1, &texID); + + // Destroy the EGLSurface + EXPECT_TRUE(eglDestroySurface(mEglDisplay, stcEglSurface)); + ASSERT_EQ(EGL_SUCCESS, eglGetError()); + + // Release the ref that the SurfaceTexture has on buffers[2]. + mST->abandon(); + + EXPECT_EQ(1, buffers[0]->getStrongCount()); + EXPECT_EQ(1, buffers[1]->getStrongCount()); + EXPECT_EQ(1, buffers[2]->getStrongCount()); +} + +TEST_F(SurfaceTextureGLTest, EglDestroySurfaceAfterAbandonUnrefsBuffers) { + EGLSurface stcEglSurface = eglCreateWindowSurface(mEglDisplay, mGlConfig, + mANW.get(), NULL); + ASSERT_EQ(EGL_SUCCESS, eglGetError()); + ASSERT_NE(EGL_NO_SURFACE, stcEglSurface); + + sp<GraphicBuffer> buffers[3]; + + for (int i = 0; i < 3; i++) { + // Produce a frame + EXPECT_TRUE(eglMakeCurrent(mEglDisplay, stcEglSurface, stcEglSurface, + mEglContext)); + ASSERT_EQ(EGL_SUCCESS, eglGetError()); + glClear(GL_COLOR_BUFFER_BIT); + EXPECT_TRUE(eglSwapBuffers(mEglDisplay, stcEglSurface)); + ASSERT_EQ(EGL_SUCCESS, eglGetError()); + + // Consume a frame + EXPECT_TRUE(eglMakeCurrent(mEglDisplay, mEglSurface, mEglSurface, + mEglContext)); + ASSERT_EQ(EGL_SUCCESS, eglGetError()); + ASSERT_EQ(NO_ERROR, mST->updateTexImage()); + buffers[i] = mST->getCurrentBuffer(); + } + + // Abandon the SurfaceTexture, releasing the ref that the SurfaceTexture has + // on buffers[2]. + mST->abandon(); + + // Destroy the GL texture object to release its ref on buffers[2]. + GLuint texID = TEX_ID; + glDeleteTextures(1, &texID); + + // Destroy the EGLSurface. + EXPECT_TRUE(eglDestroySurface(mEglDisplay, stcEglSurface)); + ASSERT_EQ(EGL_SUCCESS, eglGetError()); + + EXPECT_EQ(1, buffers[0]->getStrongCount()); + EXPECT_EQ(1, buffers[1]->getStrongCount()); + EXPECT_EQ(1, buffers[2]->getStrongCount()); +} + } // namespace android |