Skip to content

Commit d10475e

Browse files
critsecAndroid (Google) Code Review
authored andcommitted
Merge "SurfaceTexture: add tests for buffer leaks"
2 parents 87e87c2 + 59940b4 commit d10475e

File tree

1 file changed

+83
-1
lines changed

1 file changed

+83
-1
lines changed

libs/gui/tests/SurfaceTexture_test.cpp

Lines changed: 83 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,7 @@ class GLTest : public ::testing::Test {
334334

335335
class SurfaceTextureGLTest : public GLTest {
336336
protected:
337-
static const GLint TEX_ID = 123;
337+
enum { TEX_ID = 123 };
338338

339339
virtual void SetUp() {
340340
GLTest::SetUp();
@@ -1438,4 +1438,86 @@ TEST_F(SurfaceTextureGLToGLTest, DISABLED_RepeatedSwapBuffersWhileDequeueStalled
14381438
}
14391439
}
14401440

1441+
TEST_F(SurfaceTextureGLTest, EglDestroySurfaceUnrefsBuffers) {
1442+
EGLSurface stcEglSurface = eglCreateWindowSurface(mEglDisplay, mGlConfig,
1443+
mANW.get(), NULL);
1444+
ASSERT_EQ(EGL_SUCCESS, eglGetError());
1445+
ASSERT_NE(EGL_NO_SURFACE, stcEglSurface);
1446+
1447+
sp<GraphicBuffer> buffers[3];
1448+
1449+
for (int i = 0; i < 3; i++) {
1450+
// Produce a frame
1451+
EXPECT_TRUE(eglMakeCurrent(mEglDisplay, stcEglSurface, stcEglSurface,
1452+
mEglContext));
1453+
ASSERT_EQ(EGL_SUCCESS, eglGetError());
1454+
glClear(GL_COLOR_BUFFER_BIT);
1455+
eglSwapBuffers(mEglDisplay, stcEglSurface);
1456+
1457+
// Consume a frame
1458+
EXPECT_TRUE(eglMakeCurrent(mEglDisplay, mEglSurface, mEglSurface,
1459+
mEglContext));
1460+
ASSERT_EQ(EGL_SUCCESS, eglGetError());
1461+
mST->updateTexImage();
1462+
buffers[i] = mST->getCurrentBuffer();
1463+
}
1464+
1465+
// Destroy the GL texture object to release its ref on buffers[2].
1466+
GLuint texID = TEX_ID;
1467+
glDeleteTextures(1, &texID);
1468+
1469+
// Destroy the EGLSurface
1470+
EXPECT_TRUE(eglDestroySurface(mEglDisplay, stcEglSurface));
1471+
ASSERT_EQ(EGL_SUCCESS, eglGetError());
1472+
1473+
// Release the ref that the SurfaceTexture has on buffers[2].
1474+
mST->abandon();
1475+
1476+
EXPECT_EQ(1, buffers[0]->getStrongCount());
1477+
EXPECT_EQ(1, buffers[1]->getStrongCount());
1478+
EXPECT_EQ(1, buffers[2]->getStrongCount());
1479+
}
1480+
1481+
TEST_F(SurfaceTextureGLTest, EglDestroySurfaceAfterAbandonUnrefsBuffers) {
1482+
EGLSurface stcEglSurface = eglCreateWindowSurface(mEglDisplay, mGlConfig,
1483+
mANW.get(), NULL);
1484+
ASSERT_EQ(EGL_SUCCESS, eglGetError());
1485+
ASSERT_NE(EGL_NO_SURFACE, stcEglSurface);
1486+
1487+
sp<GraphicBuffer> buffers[3];
1488+
1489+
for (int i = 0; i < 3; i++) {
1490+
// Produce a frame
1491+
EXPECT_TRUE(eglMakeCurrent(mEglDisplay, stcEglSurface, stcEglSurface,
1492+
mEglContext));
1493+
ASSERT_EQ(EGL_SUCCESS, eglGetError());
1494+
glClear(GL_COLOR_BUFFER_BIT);
1495+
EXPECT_TRUE(eglSwapBuffers(mEglDisplay, stcEglSurface));
1496+
ASSERT_EQ(EGL_SUCCESS, eglGetError());
1497+
1498+
// Consume a frame
1499+
EXPECT_TRUE(eglMakeCurrent(mEglDisplay, mEglSurface, mEglSurface,
1500+
mEglContext));
1501+
ASSERT_EQ(EGL_SUCCESS, eglGetError());
1502+
ASSERT_EQ(NO_ERROR, mST->updateTexImage());
1503+
buffers[i] = mST->getCurrentBuffer();
1504+
}
1505+
1506+
// Abandon the SurfaceTexture, releasing the ref that the SurfaceTexture has
1507+
// on buffers[2].
1508+
mST->abandon();
1509+
1510+
// Destroy the GL texture object to release its ref on buffers[2].
1511+
GLuint texID = TEX_ID;
1512+
glDeleteTextures(1, &texID);
1513+
1514+
// Destroy the EGLSurface.
1515+
EXPECT_TRUE(eglDestroySurface(mEglDisplay, stcEglSurface));
1516+
ASSERT_EQ(EGL_SUCCESS, eglGetError());
1517+
1518+
EXPECT_EQ(1, buffers[0]->getStrongCount());
1519+
EXPECT_EQ(1, buffers[1]->getStrongCount());
1520+
EXPECT_EQ(1, buffers[2]->getStrongCount());
1521+
}
1522+
14411523
} // namespace android

0 commit comments

Comments
 (0)