title: eglSwapBuffers blocked in GLSurfaceView onDrawFrame
body: <p>As my <a href="https://stackoverflow.com/questions/27376340/surfaceview-or-textureview-combination">previous question</a>, I am trying "<code>GLSurfaceView + TextureView</code>" to show camera preview in one GLSurfaceView and multiple TextureViews, but facing some problems...   </p>
  
  <p>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.</p>
  
  <pre><code>    @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;
          }
      }
  </code></pre>
  
  <p>Everything works fine except press "back" key. I call GLSurfaceView's onPause() when the activity pauses, it caused swapBuffers (EGL14.eglSwapBuffers) won't return...</p>
  
  <p>Some suspected logcat messages also<br>
  <code>W/WindowManager(1077): Window freeze timeout expired.</code><br>
  <code>I/WindowManager(1077): Screen frozen for +2s42ms due to Window ..</code></p>
  
  <p>Anyone knows why? And any way to solve this problem?<br>
  Thanks.</p>