From 2d14a0ed4f5861bfa67e9db138ffdc70d2d5e6e4 Mon Sep 17 00:00:00 2001 From: Eric Penner Date: Mon, 25 Aug 2014 20:16:37 -0700 Subject: GLConsumer: Fix eglTerminate/eglInit edge case. If a display is terminated and then initialized, we can't detect this using the display itself (it has the same value), but all EglImages still become invalid for the display. This patch detects this during image binding and forces creation of a new EglImage. Bug: 10430249 Change-Id: I75101c50962f21263dca3ec6e241a2e5a3c23dad --- .../tests/SurfaceTextureMultiContextGL_test.cpp | 55 ++++++++++++++++++++++ 1 file changed, 55 insertions(+) (limited to 'libs/gui/tests') diff --git a/libs/gui/tests/SurfaceTextureMultiContextGL_test.cpp b/libs/gui/tests/SurfaceTextureMultiContextGL_test.cpp index 115a47d..1cd101e 100644 --- a/libs/gui/tests/SurfaceTextureMultiContextGL_test.cpp +++ b/libs/gui/tests/SurfaceTextureMultiContextGL_test.cpp @@ -386,4 +386,59 @@ TEST_F(SurfaceTextureMultiContextGLTest, ASSERT_EQ(OK, mST->updateTexImage()); } +TEST_F(SurfaceTextureMultiContextGLTest, + AttachAfterDisplayTerminatedSucceeds) { + ASSERT_EQ(NO_ERROR, mST->setDefaultMaxBufferCount(2)); + + // produce two frames and consume them both on the primary context + ASSERT_NO_FATAL_FAILURE(produceOneRGBA8Frame(mANW)); + mFW->waitForFrame(); + ASSERT_EQ(OK, mST->updateTexImage()); + + ASSERT_NO_FATAL_FAILURE(produceOneRGBA8Frame(mANW)); + mFW->waitForFrame(); + ASSERT_EQ(OK, mST->updateTexImage()); + + // produce one more frame + ASSERT_NO_FATAL_FAILURE(produceOneRGBA8Frame(mANW)); + + // Detach from the primary context. + ASSERT_EQ(OK, mST->releaseTexImage()); + ASSERT_EQ(OK, mST->detachFromContext()); + + // Terminate and then initialize the display. All contexts, surfaces + // and images are invalid at this point. + EGLDisplay display = eglGetDisplay(EGL_DEFAULT_DISPLAY); + ASSERT_NE(EGL_NO_DISPLAY, mEglDisplay); + EGLint majorVersion = 0; + EGLint minorVersion = 0; + EXPECT_TRUE(eglTerminate(display)); + EXPECT_TRUE(eglInitialize(mEglDisplay, &majorVersion, &minorVersion)); + ASSERT_EQ(EGL_SUCCESS, eglGetError()); + + // The surface is invalid so create it again. + EGLint pbufferAttribs[] = { + EGL_WIDTH, 64, + EGL_HEIGHT, 64, + EGL_NONE }; + mEglSurface = eglCreatePbufferSurface(mEglDisplay, mGlConfig, + pbufferAttribs); + + // The second context is invalid so create it again. + mSecondEglContext = eglCreateContext(mEglDisplay, mGlConfig, + EGL_NO_CONTEXT, getContextAttribs()); + ASSERT_EQ(EGL_SUCCESS, eglGetError()); + ASSERT_NE(EGL_NO_CONTEXT, mSecondEglContext); + + ASSERT_TRUE(eglMakeCurrent(mEglDisplay, mEglSurface, mEglSurface, + mSecondEglContext)); + ASSERT_EQ(EGL_SUCCESS, eglGetError()); + + // Now attach to and consume final frame on secondary context. + ASSERT_EQ(OK, mST->attachToContext(SECOND_TEX_ID)); + mFW->waitForFrame(); + ASSERT_EQ(OK, mST->updateTexImage()); +} + + } // namespace android -- cgit v1.1