eglSwapBuffers blocked in GLSurfaceView onDrawFrame
As my previous question, I am trying " GLSurfaceView + TextureView
" to show camera preview in one GLSurfaceView and multiple TextureViews, but facing some problems...
In GLSurfaceView render thread, I tried to share built-in EGLContext to TextureView, create a EGL surface by TextureView's surfaceTexture, then use GLES to draw on it.
@Override
public void onDrawFrame(final GL10 gl) {
// GLES draw on GLSurfaceView
renderToTextureView();
}
private void renderToTextureView() {
saveEGLState();
for(TextureViewItem item : mTextureViewItemList) {
item.render(mSavedEglContext);
}
restoreEGLState();
}
private void saveEGLState() {
mSavedEglDisplay = EGL14.eglGetCurrentDisplay();
mSavedEglContext = EGL14.eglGetCurrentContext();
mSavedEglDrawSurface = EGL14.eglGetCurrentSurface(EGL14.EGL_DRAW);
mSavedEglReadSurface = EGL14.eglGetCurrentSurface(EGL14.EGL_READ);
}
private void restoreEGLState() {
if (!EGL14.eglMakeCurrent(mSavedEglDisplay, mSavedEglDrawSurface, mSavedEglReadSurface, mSavedEglContext)) {
throw new RuntimeException("eglMakeCurrent failed");
}
}
public class TextureViewItem implements TextureView.SurfaceTextureListener {
private static EglCore sEglCore;
private WindowSurface mWindowSurface;
public void render(EGLContext sharedContext) {
if(mSavedSurfaceTexture == null) return;
getWindowSurface(sharedContext).makeCurrent();
// GLES draw on TextureView
getWindowSurface(sharedContext).swapBuffers();
}
private WindowSurface getWindowSurface(EGLContext sharedContext) {
if(sEglCore == null) {
sEglCore = new EglCore(sharedContext, EglCore.FLAG_TRY_GLES3);
}
if(mWindowSurface == null) {
mWindowSurface = new WindowSurface(mEglCore, mSavedSurfaceTexture);
}
return mWindowSurface;
}
@Override
public void onSurfaceTextureAvailable(SurfaceTexture st, int width, int height) {
if (mSavedSurfaceTexture == null) {
mSavedSurfaceTexture = st;
}
}
@Override
public boolean onSurfaceTextureDestroyed(SurfaceTexture st) {
if (mWindowSurface != null) {
mWindowSurface.release();
}
if (sEglCore != null) {
sEglCore.release();
}
mSavedSurfaceTexture = null;
return true;
}
}
Everything works fine except press "back" key. I call GLSurfaceView's onPause() when the activity pauses, it caused swapBuffers (EGL14.eglSwapBuffers) won't return...
Some suspected logcat messages also
W/WindowManager(1077): Window freeze timeout expired.
I/WindowManager(1077): Screen frozen for +2s42ms due to Window ..
Anyone knows why? And any way to solve this problem?
Thanks.
上一篇: 等待eglSwapBuffers发布完成