Skip to content

Commit caa4482

Browse files
author
Jamie Gennis
committed
SurfaceTexture: fix a couple tests
This change fixes some robustness issues with the EglDestroySurfaceUnrefsBuffers and EglDestroySurfaceAfterAbandonUnrefsBuffers tests. The tests previously depended upon GL implementation details that should not have been relied upon. Change-Id: I37fd43b56568efe1dbe69d85e892be8a1cf44d20
1 parent 87f3265 commit caa4482

File tree

1 file changed

+28
-2
lines changed

1 file changed

+28
-2
lines changed

libs/gui/tests/SurfaceTexture_test.cpp

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1176,6 +1176,13 @@ TEST_F(SurfaceTextureGLToGLTest, TexturingFromGLFilledRGBABufferPow2) {
11761176
TEST_F(SurfaceTextureGLToGLTest, EglDestroySurfaceUnrefsBuffers) {
11771177
sp<GraphicBuffer> buffers[3];
11781178

1179+
// This test requires async mode to run on a single thread.
1180+
EXPECT_TRUE(eglMakeCurrent(mEglDisplay, mProducerEglSurface,
1181+
mProducerEglSurface, mProducerEglContext));
1182+
ASSERT_EQ(EGL_SUCCESS, eglGetError());
1183+
EXPECT_TRUE(eglSwapInterval(mEglDisplay, 0));
1184+
ASSERT_EQ(EGL_SUCCESS, eglGetError());
1185+
11791186
for (int i = 0; i < 3; i++) {
11801187
// Produce a frame
11811188
EXPECT_TRUE(eglMakeCurrent(mEglDisplay, mProducerEglSurface,
@@ -1205,12 +1212,25 @@ TEST_F(SurfaceTextureGLToGLTest, EglDestroySurfaceUnrefsBuffers) {
12051212

12061213
EXPECT_EQ(1, buffers[0]->getStrongCount());
12071214
EXPECT_EQ(1, buffers[1]->getStrongCount());
1208-
EXPECT_EQ(1, buffers[2]->getStrongCount());
1215+
1216+
// Depending on how lazily the GL driver dequeues buffers, we may end up
1217+
// with either two or three total buffers. If there are three, make sure
1218+
// the last one was properly down-ref'd.
1219+
if (buffers[2] != buffers[0]) {
1220+
EXPECT_EQ(1, buffers[2]->getStrongCount());
1221+
}
12091222
}
12101223

12111224
TEST_F(SurfaceTextureGLToGLTest, EglDestroySurfaceAfterAbandonUnrefsBuffers) {
12121225
sp<GraphicBuffer> buffers[3];
12131226

1227+
// This test requires async mode to run on a single thread.
1228+
EXPECT_TRUE(eglMakeCurrent(mEglDisplay, mProducerEglSurface,
1229+
mProducerEglSurface, mProducerEglContext));
1230+
ASSERT_EQ(EGL_SUCCESS, eglGetError());
1231+
EXPECT_TRUE(eglSwapInterval(mEglDisplay, 0));
1232+
ASSERT_EQ(EGL_SUCCESS, eglGetError());
1233+
12141234
for (int i = 0; i < 3; i++) {
12151235
// Produce a frame
12161236
EXPECT_TRUE(eglMakeCurrent(mEglDisplay, mProducerEglSurface,
@@ -1242,7 +1262,13 @@ TEST_F(SurfaceTextureGLToGLTest, EglDestroySurfaceAfterAbandonUnrefsBuffers) {
12421262

12431263
EXPECT_EQ(1, buffers[0]->getStrongCount());
12441264
EXPECT_EQ(1, buffers[1]->getStrongCount());
1245-
EXPECT_EQ(1, buffers[2]->getStrongCount());
1265+
1266+
// Depending on how lazily the GL driver dequeues buffers, we may end up
1267+
// with either two or three total buffers. If there are three, make sure
1268+
// the last one was properly down-ref'd.
1269+
if (buffers[2] != buffers[0]) {
1270+
EXPECT_EQ(1, buffers[2]->getStrongCount());
1271+
}
12461272
}
12471273

12481274
TEST_F(SurfaceTextureGLToGLTest, EglSurfaceDefaultsToSynchronousMode) {

0 commit comments

Comments
 (0)