public void destroySurface() {
   if (mEglSurface != null && mEglSurface != EGL10.EGL_NO_SURFACE) {
     mEgl.eglMakeCurrent(
         mEglDisplay, EGL10.EGL_NO_SURFACE, EGL10.EGL_NO_SURFACE, EGL10.EGL_NO_CONTEXT);
     mEGLWindowSurfaceFactory.destroySurface(mEgl, mEglDisplay, mEglSurface);
     mEglSurface = null;
   }
 }
  /*
   * React to the creation of a new surface by creating and returning an OpenGL interface that renders to that
   * surface.
   */
  public GL createSurface(SurfaceHolder holder) {
    /*
     * The window size has changed, so we need to create a new surface.
     */
    if (mEglSurface != null && mEglSurface != EGL10.EGL_NO_SURFACE) {

      /*
       * Unbind and destroy the old EGL surface, if there is one.
       */
      mEgl.eglMakeCurrent(
          mEglDisplay, EGL10.EGL_NO_SURFACE, EGL10.EGL_NO_SURFACE, EGL10.EGL_NO_CONTEXT);
      mEGLWindowSurfaceFactory.destroySurface(mEgl, mEglDisplay, mEglSurface);
    }

    /*
     * Create an EGL surface we can render into.
     */
    mEglSurface =
        mEGLWindowSurfaceFactory.createWindowSurface(mEgl, mEglDisplay, mEglConfig, holder);

    if (mEglSurface == null || mEglSurface == EGL10.EGL_NO_SURFACE) {
      throw new RuntimeException("createWindowSurface failed");
    }

    /*
     * Before we can issue GL commands, we need to make sure the context is current and bound to a surface.
     */
    if (!mEgl.eglMakeCurrent(mEglDisplay, mEglSurface, mEglSurface, mEglContext)) {
      throw new RuntimeException("eglMakeCurrent failed.");
    }

    GL gl = mEglContext.getGL();
    if (mGLWrapper != null) {
      gl = mGLWrapper.wrap(gl);
    }

    /*
     * if ((mDebugFlags & (DEBUG_CHECK_GL_ERROR | DEBUG_LOG_GL_CALLS))!= 0) { int configFlags = 0; Writer log =
     * null; if ((mDebugFlags & DEBUG_CHECK_GL_ERROR) != 0) { configFlags |= GLDebugHelper.CONFIG_CHECK_GL_ERROR; }
     * if ((mDebugFlags & DEBUG_LOG_GL_CALLS) != 0) { log = new LogWriter(); } gl = GLDebugHelper.wrap(gl,
     * configFlags, log); }
     */
    return gl;
  }