summaryrefslogtreecommitdiffstats
path: root/libs
diff options
context:
space:
mode:
authorJesse Hall <jessehall@google.com>2011-10-20 09:09:31 -0700
committerAndroid (Google) Code Review <android-gerrit@google.com>2011-10-20 09:09:31 -0700
commit83d3fa10d5d53308fafee8e702ac4dc86dc8383f (patch)
treefe550f3e6ec5fd5c88ab61425c72f171f62c8ef9 /libs
parent84b0ad77b2c99d7201373174962ca351d702d452 (diff)
parent79e3125d56cca5aba88097b5ccd4f1e128bc8141 (diff)
downloadframeworks_native-83d3fa10d5d53308fafee8e702ac4dc86dc8383f.zip
frameworks_native-83d3fa10d5d53308fafee8e702ac4dc86dc8383f.tar.gz
frameworks_native-83d3fa10d5d53308fafee8e702ac4dc86dc8383f.tar.bz2
Merge "SurfaceTexture: add tests for buffer leaks"
Diffstat (limited to 'libs')
-rw-r--r--libs/gui/tests/SurfaceTexture_test.cpp84
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