Java Code Examples for javax.microedition.khronos.egl.EGL10#EGL_BAD_NATIVE_WINDOW

The following examples show how to use javax.microedition.khronos.egl.EGL10#EGL_BAD_NATIVE_WINDOW . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: EGL.java    From video-player with MIT License 6 votes vote down vote up
public boolean swap() {
  if (!mEgl.eglSwapBuffers(mEglDisplay, mEglSurface)) {
    int error = mEgl.eglGetError();
    switch (error) {
      case EGL11.EGL_CONTEXT_LOST:
        return false;
      case EGL10.EGL_BAD_NATIVE_WINDOW:
        Log.e("EglHelper", "eglSwapBuffers returned EGL_BAD_NATIVE_WINDOW. tid=" + Thread.currentThread().getId());
        break;
      case EGL10.EGL_BAD_SURFACE:
        Log.e("EglHelper", "eglSwapBuffers returned EGL_BAD_SURFACE. tid=" + Thread.currentThread().getId());
        return false;
      default:
        throwEglException("eglSwapBuffers", error);
    }
  }
  return true;
}
 
Example 2
Source File: EGL.java    From HPlayer with Apache License 2.0 6 votes vote down vote up
public boolean swap() {
  if (!mEgl.eglSwapBuffers(mEglDisplay, mEglSurface)) {
    int error = mEgl.eglGetError();
    switch (error) {
      case EGL11.EGL_CONTEXT_LOST:
        return false;
      case EGL10.EGL_BAD_NATIVE_WINDOW:
        Log.e("EglHelper", "eglSwapBuffers returned EGL_BAD_NATIVE_WINDOW. tid=" + Thread.currentThread().getId());
        break;
      case EGL10.EGL_BAD_SURFACE:
        Log.e("EglHelper", "eglSwapBuffers returned EGL_BAD_SURFACE. tid=" + Thread.currentThread().getId());
        return false;
      default:
        throwEglException("eglSwapBuffers", error);
    }
  }
  return true;
}
 
Example 3
Source File: EGL.java    From BambooPlayer with Apache License 2.0 6 votes vote down vote up
public boolean swap() {
  if (!mEgl.eglSwapBuffers(mEglDisplay, mEglSurface)) {
    int error = mEgl.eglGetError();
    switch (error) {
      case EGL11.EGL_CONTEXT_LOST:
        return false;
      case EGL10.EGL_BAD_NATIVE_WINDOW:
        Log.e("EglHelper", "eglSwapBuffers returned EGL_BAD_NATIVE_WINDOW. tid=" + Thread.currentThread().getId());
        break;
      case EGL10.EGL_BAD_SURFACE:
        Log.e("EglHelper", "eglSwapBuffers returned EGL_BAD_SURFACE. tid=" + Thread.currentThread().getId());
        return false;
      default:
        throwEglException("eglSwapBuffers", error);
    }
  }
  return true;
}
 
Example 4
Source File: EGL.java    From NetEasyNews with GNU General Public License v3.0 6 votes vote down vote up
public boolean swap() {
  if (!mEgl.eglSwapBuffers(mEglDisplay, mEglSurface)) {
    int error = mEgl.eglGetError();
    switch (error) {
      case EGL11.EGL_CONTEXT_LOST:
        return false;
      case EGL10.EGL_BAD_NATIVE_WINDOW:
        Log.e("EglHelper", "eglSwapBuffers returned EGL_BAD_NATIVE_WINDOW. tid=" + Thread.currentThread().getId());
        break;
      case EGL10.EGL_BAD_SURFACE:
        Log.e("EglHelper", "eglSwapBuffers returned EGL_BAD_SURFACE. tid=" + Thread.currentThread().getId());
        return false;
      default:
        throwEglException("eglSwapBuffers", error);
    }
  }
  return true;
}
 
Example 5
Source File: EGL.java    From Vitamio with Apache License 2.0 6 votes vote down vote up
public boolean swap() {
  if (!mEgl.eglSwapBuffers(mEglDisplay, mEglSurface)) {
    int error = mEgl.eglGetError();
    switch (error) {
      case EGL11.EGL_CONTEXT_LOST:
        return false;
      case EGL10.EGL_BAD_NATIVE_WINDOW:
        Log.e("EglHelper", "eglSwapBuffers returned EGL_BAD_NATIVE_WINDOW. tid=" + Thread.currentThread().getId());
        break;
      case EGL10.EGL_BAD_SURFACE:
        Log.e("EglHelper", "eglSwapBuffers returned EGL_BAD_SURFACE. tid=" + Thread.currentThread().getId());
        return false;
      default:
        throwEglException("eglSwapBuffers", error);
    }
  }
  return true;
}
 
Example 6
Source File: EGL.java    From video-player with MIT License 5 votes vote down vote up
public GL createSurface(Surface surface) {
  if (mEgl == null)
    throw new RuntimeException("egl not initialized");
  if (mEglDisplay == null)
    throw new RuntimeException("eglDisplay not initialized");
  if (mEglConfig == null)
    throw new RuntimeException("mEglConfig not initialized");

  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 = mEGLWindowSurfaceFactory.createWindowSurface(mEgl, mEglDisplay, mEglConfig, surface);

  if (mEglSurface == null || mEglSurface == EGL10.EGL_NO_SURFACE) {
    int error = mEgl.eglGetError();
    if (error == EGL10.EGL_BAD_NATIVE_WINDOW) {
      Log.e("EglHelper", "createWindowSurface returned EGL_BAD_NATIVE_WINDOW.");
      return null;
    }
    throwEglException("createWindowSurface", error);
  }

  if (!mEgl.eglMakeCurrent(mEglDisplay, mEglSurface, mEglSurface, mEglContext)) {
    throwEglException("eglMakeCurrent");
  }

  GL gl = mEglContext.getGL();

  return gl;
}
 
Example 7
Source File: EGL.java    From Vitamio with Apache License 2.0 5 votes vote down vote up
public GL createSurface(Surface surface) {
  if (mEgl == null)
    throw new RuntimeException("egl not initialized");
  if (mEglDisplay == null)
    throw new RuntimeException("eglDisplay not initialized");
  if (mEglConfig == null)
    throw new RuntimeException("mEglConfig not initialized");

  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 = mEGLWindowSurfaceFactory.createWindowSurface(mEgl, mEglDisplay, mEglConfig, surface);

  if (mEglSurface == null || mEglSurface == EGL10.EGL_NO_SURFACE) {
    int error = mEgl.eglGetError();
    if (error == EGL10.EGL_BAD_NATIVE_WINDOW) {
      Log.e("EglHelper", "createWindowSurface returned EGL_BAD_NATIVE_WINDOW.");
      return null;
    }
    throwEglException("createWindowSurface", error);
  }

  if (!mEgl.eglMakeCurrent(mEglDisplay, mEglSurface, mEglSurface, mEglContext)) {
    throwEglException("eglMakeCurrent");
  }

  GL gl = mEglContext.getGL();

  return gl;
}
 
Example 8
Source File: EGL.java    From BambooPlayer with Apache License 2.0 5 votes vote down vote up
public GL createSurface(Surface surface) {
  if (mEgl == null)
    throw new RuntimeException("egl not initialized");
  if (mEglDisplay == null)
    throw new RuntimeException("eglDisplay not initialized");
  if (mEglConfig == null)
    throw new RuntimeException("mEglConfig not initialized");

  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 = mEGLWindowSurfaceFactory.createWindowSurface(mEgl, mEglDisplay, mEglConfig, surface);

  if (mEglSurface == null || mEglSurface == EGL10.EGL_NO_SURFACE) {
    int error = mEgl.eglGetError();
    if (error == EGL10.EGL_BAD_NATIVE_WINDOW) {
      Log.e("EglHelper", "createWindowSurface returned EGL_BAD_NATIVE_WINDOW.");
      return null;
    }
    throwEglException("createWindowSurface", error);
  }

  if (!mEgl.eglMakeCurrent(mEglDisplay, mEglSurface, mEglSurface, mEglContext)) {
    throwEglException("eglMakeCurrent");
  }

  GL gl = mEglContext.getGL();

  return gl;
}
 
Example 9
Source File: GLSurfaceView.java    From NewsMe with Apache License 2.0 5 votes vote down vote up
/**
 * Display the current render surface.
 * 
 * @return false if the context has been lost.
 */
public boolean swap() {
	if (!mEgl.eglSwapBuffers(mEglDisplay, mEglSurface)) {

		/*
		 * Check for EGL_CONTEXT_LOST, which means the context and all
		 * associated data were lost (For instance because the device
		 * went to sleep). We need to sleep until we get a new surface.
		 */
		int error = mEgl.eglGetError();
		switch (error) {
		case EGL11.EGL_CONTEXT_LOST:
			return false;
		case EGL10.EGL_BAD_NATIVE_WINDOW:
			// The native window is bad, probably because the
			// window manager has closed it. Ignore this error,
			// on the expectation that the application will be
			// closed soon.
			Log.e("EglHelper",
					"eglSwapBuffers returned EGL_BAD_NATIVE_WINDOW. tid="
							+ Thread.currentThread().getId());
			break;
		default:
			throwEglException("eglSwapBuffers", error);
		}
	}
	return true;
}
 
Example 10
Source File: GLSurfaceView.java    From NewsMe with Apache License 2.0 4 votes vote down vote up
public GL createSurface(SurfaceHolder holder) {
	if (LOG_EGL) {
		Log.w("EglHelper", "createSurface()  tid="
				+ Thread.currentThread().getId());
	}
	/*
	 * Check preconditions.
	 */
	if (mEgl == null) {
		throw new RuntimeException("egl not initialized");
	}
	if (mEglDisplay == null) {
		throw new RuntimeException("eglDisplay not initialized");
	}
	if (mEglConfig == null) {
		throw new RuntimeException("mEglConfig not initialized");
	}
	/*
	 * 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) {
		int error = mEgl.eglGetError();
		if (error == EGL10.EGL_BAD_NATIVE_WINDOW) {
			Log.e("EglHelper",
					"createWindowSurface returned EGL_BAD_NATIVE_WINDOW.");
		}
		return null;
	}

	/*
	 * 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)) {
		throwEglException("eglMakeCurrent");
	}

	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;
}
 
Example 11
Source File: BlockingGLTextureView.java    From LB-Launcher with Apache License 2.0 4 votes vote down vote up
/**
 * Create an egl surface for the current SurfaceTexture surface. If a surface
 * already exists, destroy it before creating the new surface.
 *
 * @return true if the surface was created successfully.
 */
public boolean createSurface(SurfaceTexture surface) {
    /*
     * Check preconditions.
     */
    if (mEgl == null) {
        throw new RuntimeException("egl not initialized");
    }
    if (mEglDisplay == null) {
        throw new RuntimeException("eglDisplay not initialized");
    }
    if (mEglConfig == null) {
        throw new RuntimeException("mEglConfig not initialized");
    }

    /*
     *  The window size has changed, so we need to create a new
     *  surface.
     */
    destroySurfaceImp();

    /*
     * Create an EGL surface we can render into.
     */
    if (surface != null) {
        mEglSurface = mEgl.eglCreateWindowSurface(mEglDisplay, mEglConfig, surface, null);
    } else {
        mEglSurface = null;
    }

    if (mEglSurface == null || mEglSurface == EGL10.EGL_NO_SURFACE) {
        int error = mEgl.eglGetError();
        if (error == EGL10.EGL_BAD_NATIVE_WINDOW) {
            Log.e("EglHelper", "createWindowSurface returned EGL_BAD_NATIVE_WINDOW.");
        }
        return false;
    }

    /*
     * 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)) {
        /*
         * Could not make the context current, probably because the underlying
         * SurfaceView surface has been destroyed.
         */
        logEglErrorAsWarning("EGLHelper", "eglMakeCurrent", mEgl.eglGetError());
        return false;
    }

    return true;
}
 
Example 12
Source File: GLSurfaceView.java    From unity-ads-android with Apache License 2.0 4 votes vote down vote up
/**
 * Create an egl surface for the current SurfaceHolder surface. If a surface
 * already exists, destroy it before creating the new surface.
 *
 * @return true if the surface was created successfully.
 */
public boolean createSurface() {
	if (LOG_EGL) {
		Log.w("EglHelper", "createSurface()  tid=" + Thread.currentThread().getId());
	}
	/*
	 * Check preconditions.
	 */
	if (mEgl == null) {
		throw new RuntimeException("egl not initialized");
	}
	if (mEglDisplay == null) {
		throw new RuntimeException("eglDisplay not initialized");
	}
	if (mEglConfig == null) {
		throw new RuntimeException("mEglConfig not initialized");
	}

	/*
	 *  The window size has changed, so we need to create a new
	 *  surface.
	 */
	destroySurfaceImp();

	/*
	 * Create an EGL surface we can render into.
	 */
	GLSurfaceView view = mGLSurfaceViewWeakRef.get();
	if (view != null) {
		mEglSurface = view.mEGLWindowSurfaceFactory.createWindowSurface(mEgl,
				mEglDisplay, mEglConfig, view.getHolder());
	} else {
		mEglSurface = null;
	}

	if (mEglSurface == null || mEglSurface == EGL10.EGL_NO_SURFACE) {
		int error = mEgl.eglGetError();
		if (error == EGL10.EGL_BAD_NATIVE_WINDOW) {
			Log.e("EglHelper", "createWindowSurface returned EGL_BAD_NATIVE_WINDOW.");
		}
		return false;
	}

	/*
	 * 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)) {
		/*
		 * Could not make the context current, probably because the underlying
		 * SurfaceView surface has been destroyed.
		 */
		logEglErrorAsWarning("EGLHelper", "eglMakeCurrent", mEgl.eglGetError());
		return false;
	}

	return true;
}
 
Example 13
Source File: GLTextureView.java    From android-RoundedTextureView with Apache License 2.0 4 votes vote down vote up
/**
 * Create an egl surface for the current SurfaceHolder surface. If a surface
 * already exists, destroy it before creating the new surface.
 *
 * @return true if the surface was created successfully.
 */
public boolean createSurface() {
  if (LOG_EGL) {
    Log.w("EglHelper", "createSurface()  tid=" + Thread.currentThread().getId());
  }
        /*
         * Check preconditions.
         */
  if (egl == null) {
    throw new RuntimeException("egl not initialized");
  }
  if (eglDisplay == null) {
    throw new RuntimeException("eglDisplay not initialized");
  }
  if (eglConfig == null) {
    throw new RuntimeException("eglConfig not initialized");
  }

        /*
         *  The window size has changed, so we need to create a new
         *  surface.
         */
  destroySurfaceImp();

        /*
         * Create an EGL surface we can render into.
         */
  GLTextureView view = glTextureViewWeakRef.get();
  if (view != null) {
    eglSurface = view.eglWindowSurfaceFactory.createWindowSurface(egl, eglDisplay, eglConfig,
        view.getSurfaceTexture());
  } else {
    eglSurface = null;
  }

  if (eglSurface == null || eglSurface == EGL10.EGL_NO_SURFACE) {
    int error = egl.eglGetError();
    if (error == EGL10.EGL_BAD_NATIVE_WINDOW) {
      Log.e("EglHelper", "createWindowSurface returned EGL_BAD_NATIVE_WINDOW.");
    }
    return false;
  }

        /*
         * Before we can issue GL commands, we need to make sure
         * the context is current and bound to a surface.
         */
  if (!egl.eglMakeCurrent(eglDisplay, eglSurface, eglSurface, eglContext)) {
            /*
             * Could not make the context current, probably because the underlying
             * TextureView surface has been destroyed.
             */
    logEglErrorAsWarning("EGLHelper", "eglMakeCurrent", egl.eglGetError());
    return false;
  }

  return true;
}
 
Example 14
Source File: GlTextureView.java    From ParticleView with Apache License 2.0 4 votes vote down vote up
/**
 * Create an egl surface for the current SurfaceHolder surface. If a surface
 * already exists, destroy it before creating the new surface.
 *
 * @return true if the surface was created successfully.
 */
public boolean createSurface() {
    if (LOG_EGL) {
        Log.w("EglHelper", "createSurface()  tid=" + Thread.currentThread().getId());
    }
    /*
     * Check preconditions.
     */
    if (mEgl == null) {
        throw new RuntimeException("egl not initialized");
    }
    if (mEglDisplay == null) {
        throw new RuntimeException("eglDisplay not initialized");
    }
    if (mEglConfig == null) {
        throw new RuntimeException("mEglConfig not initialized");
    }

    /*
     *  The window size has changed, so we need to create a new
     *  surface.
     */
    destroySurfaceImp();

    /*
     * Create an EGL surface we can render into.
     */
    GlTextureView view = mGLTextureViewWeakRef.get();
    if (view != null) {
        mEglSurface = view.mEGLWindowSurfaceFactory.createWindowSurface(mEgl,
                mEglDisplay, mEglConfig, view.getSurfaceTexture());
    } else {
        mEglSurface = null;
    }

    if (mEglSurface == null || mEglSurface == EGL10.EGL_NO_SURFACE) {
        int error = mEgl.eglGetError();
        if (error == EGL10.EGL_BAD_NATIVE_WINDOW) {
            Log.e("EglHelper", "createWindowSurface returned EGL_BAD_NATIVE_WINDOW.");
        }
        return false;
    }

    /*
     * 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)) {
        /*
         * Could not make the context current, probably because the underlying
         * SurfaceView surface has been destroyed.
         */
        logEglErrorAsWarning("EGLHelper", "eglMakeCurrent", mEgl.eglGetError());
        return false;
    }

    return true;
}
 
Example 15
Source File: myGLTextureView.java    From opengl with Apache License 2.0 4 votes vote down vote up
private void initGL() {

        mEgl = (EGL10) EGLContext.getEGL();
        mEglDisplay = mEgl.eglGetDisplay(EGL10.EGL_DEFAULT_DISPLAY);
        if (mEglDisplay == EGL10.EGL_NO_DISPLAY) {
            throw new RuntimeException("eglGetDisplay failed "
                    + GLUtils.getEGLErrorString(mEgl.eglGetError()));
        }
        int[] version = new int[2];
        if (!mEgl.eglInitialize(mEglDisplay, version)) {
            throw new RuntimeException("eglInitialize failed "
                    + GLUtils.getEGLErrorString(mEgl.eglGetError()));
        }
        int[] configsCount = new int[1];
        EGLConfig[] configs = new EGLConfig[1];
        int[] configSpec = {
                EGL10.EGL_RENDERABLE_TYPE,
                EGL_OPENGL_ES2_BIT,
                EGL10.EGL_RED_SIZE, 8,
                EGL10.EGL_GREEN_SIZE, 8,
                EGL10.EGL_BLUE_SIZE, 8,
                EGL10.EGL_ALPHA_SIZE, 8,
                EGL10.EGL_DEPTH_SIZE, 16,  //was 0
                EGL10.EGL_STENCIL_SIZE, 0,
                EGL10.EGL_NONE
        };
        eglConfig = null;
        if (!mEgl.eglChooseConfig(mEglDisplay, configSpec, configs, 1,
                configsCount)) {
            throw new IllegalArgumentException(
                    "eglChooseConfig failed "
                            + GLUtils.getEGLErrorString(mEgl
                            .eglGetError()));
        } else if (configsCount[0] > 0) {
            eglConfig = configs[0];
        }
        if (eglConfig == null) {
            throw new RuntimeException("eglConfig not initialized");
        }
        int[] attrib_list = {
                EGL_CONTEXT_CLIENT_VERSION, 2, EGL10.EGL_NONE
        };
        mEglContext = mEgl.eglCreateContext(mEglDisplay,
                eglConfig, EGL10.EGL_NO_CONTEXT, attrib_list);
        checkEglError();
        mEglSurface = mEgl.eglCreateWindowSurface(
                mEglDisplay, eglConfig, mSurface, null);
        checkEglError();
        if (mEglSurface == null || mEglSurface == EGL10.EGL_NO_SURFACE) {
            int error = mEgl.eglGetError();
            if (error == EGL10.EGL_BAD_NATIVE_WINDOW) {
                Log.e(TAG,
                        "eglCreateWindowSurface returned EGL10.EGL_BAD_NATIVE_WINDOW");
                return;
            }
            throw new RuntimeException(
                    "eglCreateWindowSurface failed "
                            + GLUtils.getEGLErrorString(error));
        }
        if (!mEgl.eglMakeCurrent(mEglDisplay, mEglSurface,
                mEglSurface, mEglContext)) {
            throw new RuntimeException("eglMakeCurrent failed "
                    + GLUtils.getEGLErrorString(mEgl.eglGetError()));
        }
        checkEglError();
        mGl = (GL10) mEglContext.getGL();
        checkEglError();
    }
 
Example 16
Source File: GLSurfaceView.java    From EZFilter with MIT License 4 votes vote down vote up
/**
 * Create an egl surface for the current SurfaceHolder surface. If a surface
 * already exists, destroy it before creating the new surface.
 *
 * @return true if the surface was created successfully.
 */
public boolean createSurface() {
    if (LOG_EGL) {
        Log.w("EglHelper", "createSurface()  tid=" + Thread.currentThread().getId());
    }
    /*
     * Check preconditions.
     */
    if (mEgl == null) {
        throw new RuntimeException("egl not initialized");
    }
    if (mEglDisplay == null) {
        throw new RuntimeException("eglDisplay not initialized");
    }
    if (mEglConfig == null) {
        throw new RuntimeException("mEglConfig not initialized");
    }

    /*
     *  The window size has changed, so we need to create a new
     *  surface.
     */
    destroySurfaceImp();

    /*
     * Create an EGL surface we can render into.
     */
    GLSurfaceView view = mGLSurfaceViewWeakRef.get();
    if (view != null) {
        mEglSurface = view.mEGLWindowSurfaceFactory.createWindowSurface(mEgl,
                mEglDisplay, mEglConfig, view.getHolder());
    } else {
        mEglSurface = null;
    }

    if (mEglSurface == null || mEglSurface == EGL10.EGL_NO_SURFACE) {
        int error = mEgl.eglGetError();
        if (error == EGL10.EGL_BAD_NATIVE_WINDOW) {
            Log.e("EglHelper", "createWindowSurface returned EGL_BAD_NATIVE_WINDOW.");
        }
        return false;
    }

    /*
     * 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)) {
        /*
         * Could not make the context current, probably because the underlying
         * SurfaceView surface has been destroyed.
         */
        logEglErrorAsWarning("EGLHelper", "eglMakeCurrent", mEgl.eglGetError());
        return false;
    }

    return true;
}
 
Example 17
Source File: GLTextureView.java    From alpha-movie with Apache License 2.0 4 votes vote down vote up
/**
 * Create an egl surface for the current SurfaceHolder surface. If a surface
 * already exists, destroy it before creating the new surface.
 *
 * @return true if the surface was created successfully.
 */
public boolean createSurface() {
    if (LOG_EGL) {
        Log.w("EglHelper", "createSurface()  tid=" + Thread.currentThread().getId());
    }
    /*
     * Check preconditions.
     */
    if (mEgl == null) {
        throw new RuntimeException("egl not initialized");
    }
    if (mEglDisplay == null) {
        throw new RuntimeException("eglDisplay not initialized");
    }
    if (mEglConfig == null) {
        throw new RuntimeException("mEglConfig not initialized");
    }

    /*
     *  The window size has changed, so we need to create a new
     *  surface.
     */
    destroySurfaceImp();

    /*
     * Create an EGL surface we can render into.
     */
    GLTextureView view = mGLSurfaceViewWeakRef.get();
    if (view != null) {
        mEglSurface = view.mEGLWindowSurfaceFactory.createWindowSurface(mEgl,
                mEglDisplay, mEglConfig, view.getSurfaceTexture());
    } else {
        mEglSurface = null;
    }

    if (mEglSurface == null || mEglSurface == EGL10.EGL_NO_SURFACE) {
        int error = mEgl.eglGetError();
        if (error == EGL10.EGL_BAD_NATIVE_WINDOW) {
            Log.e("EglHelper", "createWindowSurface returned EGL_BAD_NATIVE_WINDOW.");
        }
        return false;
    }

    /*
     * 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)) {
        /*
         * Could not make the context current, probably because the underlying
         * SurfaceView surface has been destroyed.
         */
        logEglErrorAsWarning("EGLHelper", "eglMakeCurrent", mEgl.eglGetError());
        return false;
    }

    return true;
}
 
Example 18
Source File: EglHelper.java    From DanDanPlayForAndroid with MIT License 4 votes vote down vote up
/**
 * Create an egl surface for the current SurfaceHolder surface. If a surface
 * already exists, destroy it before creating the new surface.
 *
 * @return true if the surface was created successfully.
 */
@Override
public boolean createSurface(Object surface) {
    /*
     * Check preconditions.
     */
    if (mEgl == null) {
        throw new RuntimeException("egl not initialized");
    }
    if (mEglDisplay == null) {
        throw new RuntimeException("eglDisplay not initialized");
    }
    if (mEglConfig == null) {
        throw new RuntimeException("mEglConfig not initialized");
    }

    /*
     *  The window size has changed, so we need to create a new
     *  surface.
     */
    destroySurfaceImp();

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

    if (mEglSurface == null || mEglSurface == EGL10.EGL_NO_SURFACE) {
        int error = mEgl.eglGetError();
        if (error == EGL10.EGL_BAD_NATIVE_WINDOW) {
            Log.e("EglHelper", "createWindowSurface returned EGL_BAD_NATIVE_WINDOW.");
        }
        return false;
    }

    /*
     * 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)) {
        /*
         * Could not make the context current, probably because the underlying
         * SurfaceView surface has been destroyed.
         */
        logEglErrorAsWarning("EGLHelper", "eglMakeCurrent", mEgl.eglGetError());
        return false;
    }

    return true;
}
 
Example 19
Source File: BlockingGLTextureView.java    From TurboLauncher with Apache License 2.0 4 votes vote down vote up
/**
 * Create an egl surface for the current SurfaceTexture surface. If a surface
 * already exists, destroy it before creating the new surface.
 *
 * @return true if the surface was created successfully.
 */
public boolean createSurface(SurfaceTexture surface) {
    /*
     * Check preconditions.
     */
    if (mEgl == null) {
        throw new RuntimeException("egl not initialized");
    }
    if (mEglDisplay == null) {
        throw new RuntimeException("eglDisplay not initialized");
    }
    if (mEglConfig == null) {
        throw new RuntimeException("mEglConfig not initialized");
    }

    /*
     *  The window size has changed, so we need to create a new
     *  surface.
     */
    destroySurfaceImp();

    /*
     * Create an EGL surface we can render into.
     */
    if (surface != null) {
        mEglSurface = mEgl.eglCreateWindowSurface(mEglDisplay, mEglConfig, surface, null);
    } else {
        mEglSurface = null;
    }

    if (mEglSurface == null || mEglSurface == EGL10.EGL_NO_SURFACE) {
        int error = mEgl.eglGetError();
        if (error == EGL10.EGL_BAD_NATIVE_WINDOW) {
            Log.e("EglHelper", "createWindowSurface returned EGL_BAD_NATIVE_WINDOW.");
        }
        return false;
    }

    /*
     * 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)) {
        /*
         * Could not make the context current, probably because the underlying
         * SurfaceView surface has been destroyed.
         */
        logEglErrorAsWarning("EGLHelper", "eglMakeCurrent", mEgl.eglGetError());
        return false;
    }

    return true;
}
 
Example 20
Source File: GLTextureView.java    From Beginner-Level-Android-Studio-Apps with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Create an egl surface for the current SurfaceHolder surface. If a surface
 * already exists, destroy it before creating the new surface.
 *
 * @return true if the surface was created successfully.
 */
public boolean createSurface() {
    if (LOG_EGL) {
        Log.w("EglHelper", "createSurface()  tid=" + Thread.currentThread().getId());
    }
    /*
     * Check preconditions.
     */
    if (mEgl == null) {
        throw new RuntimeException("egl not initialized");
    }
    if (mEglDisplay == null) {
        throw new RuntimeException("eglDisplay not initialized");
    }
    if (mEglConfig == null) {
        throw new RuntimeException("mEglConfig not initialized");
    }

    /*
     *  The window size has changed, so we need to create a new
     *  surface.
     */
    destroySurfaceImp();

    /*
     * Create an EGL surface we can render into.
     */
    GLTextureView view = mGLTextureViewWeakRef.get();
    if (view != null) {
        mEglSurface = view.mEGLWindowSurfaceFactory.createWindowSurface(mEgl,
                mEglDisplay, mEglConfig, view.getSurfaceTexture());
    } else {
        mEglSurface = null;
    }

    if (mEglSurface == null || mEglSurface == EGL10.EGL_NO_SURFACE) {
        int error = mEgl.eglGetError();
        if (error == EGL10.EGL_BAD_NATIVE_WINDOW) {
            Log.e("EglHelper", "createWindowSurface returned EGL_BAD_NATIVE_WINDOW.");
        }
        return false;
    }

    /*
     * 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)) {
        /*
         * Could not make the context current, probably because the underlying
         * SurfaceView surface has been destroyed.
         */
        logEglErrorAsWarning("EGLHelper", "eglMakeCurrent", mEgl.eglGetError());
        return false;
    }

    return true;
}