Skip to content

Commit f7915ce

Browse files
jackpalAndroid (Google) Code Review
authored andcommitted
Merge "Work around race condition when shutting down a surface flinger surface."
2 parents fafc43b + a35c120 commit f7915ce

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

opengl/java/android/opengl/GLSurfaceView.java

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -768,6 +768,9 @@ public void destroyContext(EGL10 egl, EGLDisplay display,
768768
* {@link GLSurfaceView#setEGLWindowSurfaceFactory(EGLWindowSurfaceFactory)}
769769
*/
770770
public interface EGLWindowSurfaceFactory {
771+
/**
772+
* @return null if the surface cannot be constructed.
773+
*/
771774
EGLSurface createWindowSurface(EGL10 egl, EGLDisplay display, EGLConfig config,
772775
Object nativeWindow);
773776
void destroySurface(EGL10 egl, EGLDisplay display, EGLSurface surface);
@@ -777,7 +780,19 @@ private static class DefaultWindowSurfaceFactory implements EGLWindowSurfaceFact
777780

778781
public EGLSurface createWindowSurface(EGL10 egl, EGLDisplay display,
779782
EGLConfig config, Object nativeWindow) {
780-
return egl.eglCreateWindowSurface(display, config, nativeWindow, null);
783+
EGLSurface result = null;
784+
try {
785+
result = egl.eglCreateWindowSurface(display, config, nativeWindow, null);
786+
} catch (IllegalArgumentException e) {
787+
// This exception indicates that the surface flinger surface
788+
// is not valid. This can happen if the surface flinger surface has
789+
// been torn down, but the application has not yet been
790+
// notified via SurfaceHolder.Callback.surfaceDestroyed.
791+
// In theory the application should be notified first,
792+
// but in practice sometimes it is not. See b/4588890
793+
Log.e(TAG, "eglCreateWindowSurface", e);
794+
}
795+
return result;
781796
}
782797

783798
public void destroySurface(EGL10 egl, EGLDisplay display,
@@ -1041,9 +1056,8 @@ public GL createSurface(SurfaceHolder holder) {
10411056
int error = mEgl.eglGetError();
10421057
if (error == EGL10.EGL_BAD_NATIVE_WINDOW) {
10431058
Log.e("EglHelper", "createWindowSurface returned EGL_BAD_NATIVE_WINDOW.");
1044-
return null;
10451059
}
1046-
throwEglException("createWindowSurface", error);
1060+
return null;
10471061
}
10481062

10491063
/*

0 commit comments

Comments
 (0)