Java Code Examples for android.opengl.EGL14#eglDestroyContext()

The following examples show how to use android.opengl.EGL14#eglDestroyContext() . 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: InputSurface.java    From AndroidVideoSamples with Apache License 2.0 6 votes vote down vote up
/**
 * Discard all resources held by this class, notably the EGL context. Also releases the Surface that was passed to our constructor.
 */
public void release() {
   if ( EGL14.eglGetCurrentContext().equals( mEGLContext ) ) {
      // Clear the current context and surface to ensure they are discarded immediately.
      EGL14.eglMakeCurrent( mEGLDisplay, EGL14.EGL_NO_SURFACE, EGL14.EGL_NO_SURFACE, EGL14.EGL_NO_CONTEXT );
   }
   EGL14.eglDestroySurface( mEGLDisplay, mEGLSurface );
   EGL14.eglDestroyContext( mEGLDisplay, mEGLContext );
   // EGL14.eglTerminate(mEGLDisplay);
   mSurface.release();
   // null everything out so future attempts to use this object will cause an NPE
   mEGLDisplay = null;
   mEGLContext = null;
   mEGLSurface = null;
   mSurface = null;
}
 
Example 2
Source File: EglCore.java    From TikTok with Apache License 2.0 6 votes vote down vote up
/**
 * Discards all resources held by this class, notably the EGL context.  This must be
 * called from the thread where the context was created.
 * <p>
 * On completion, no context will be current.
 */
public void release() {
    if (mEGLDisplay != EGL14.EGL_NO_DISPLAY) {
        // Android is unusual in that it uses a reference-counted EGLDisplay.  So for
        // every eglInitialize() we need an eglTerminate().
        EGL14.eglMakeCurrent(mEGLDisplay, EGL14.EGL_NO_SURFACE, EGL14.EGL_NO_SURFACE,
                EGL14.EGL_NO_CONTEXT);
        EGL14.eglDestroyContext(mEGLDisplay, mEGLContext);
        EGL14.eglReleaseThread();
        EGL14.eglTerminate(mEGLDisplay);
    }

    mEGLDisplay = EGL14.EGL_NO_DISPLAY;
    mEGLContext = EGL14.EGL_NO_CONTEXT;
    mEGLConfig = null;
}
 
Example 3
Source File: EGLBase.java    From UVCCameraZxing with Apache License 2.0 6 votes vote down vote up
private void destroyContext() {
if (DEBUG) Log.v(TAG, "destroyContext:");

      if (!EGL14.eglDestroyContext(mEglDisplay, mEglContext)) {
          Log.e("destroyContext", "display:" + mEglDisplay + " context: " + mEglContext);
          Log.e(TAG, "eglDestroyContex:" + EGL14.eglGetError());
      }
      mEglContext = EGL14.EGL_NO_CONTEXT;
      if (mDefaultContext != EGL14.EGL_NO_CONTEXT) {
       if (!EGL14.eglDestroyContext(mEglDisplay, mDefaultContext)) {
           Log.e("destroyContext", "display:" + mEglDisplay + " context: " + mDefaultContext);
           Log.e(TAG, "eglDestroyContex:" + EGL14.eglGetError());
       }
       mDefaultContext = EGL14.EGL_NO_CONTEXT;
      }
  }
 
Example 4
Source File: EGLBase.java    From CameraRecorder-android with MIT License 6 votes vote down vote up
private void destroyContext() {
    if (DEBUG) Log.v(TAG, "destroyContext:");

    if (!EGL14.eglDestroyContext(eglDisplay, eglContext)) {
        Log.e("destroyContext", "display:" + eglDisplay + " context: " + eglContext);
        Log.e(TAG, "eglDestroyContex:" + EGL14.eglGetError());
    }
    eglContext = EGL14.EGL_NO_CONTEXT;
    if (defaultContext != EGL14.EGL_NO_CONTEXT) {
        if (!EGL14.eglDestroyContext(eglDisplay, defaultContext)) {
            Log.e("destroyContext", "display:" + eglDisplay + " context: " + defaultContext);
            Log.e(TAG, "eglDestroyContex:" + EGL14.eglGetError());
        }
        defaultContext = EGL14.EGL_NO_CONTEXT;
    }
}
 
Example 5
Source File: EGLBase14.java    From libcommon with Apache License 2.0 6 votes vote down vote up
private void destroyContext() {
//		if (DEBUG) Log.v(TAG, "destroyContext:");

        if (!EGL14.eglDestroyContext(mEglDisplay, mContext.eglContext)) {
            Log.e("destroyContext", "display:" + mEglDisplay
            	+ " context: " + mContext.eglContext);
            Log.e(TAG, "eglDestroyContext:" + EGL14.eglGetError());
        }
        mContext = EGL_NO_CONTEXT;
        if (mDefaultContext != EGL14.EGL_NO_CONTEXT) {
	        if (!EGL14.eglDestroyContext(mEglDisplay, mDefaultContext)) {
	            Log.e("destroyContext", "display:" + mEglDisplay
	            	+ " context: " + mDefaultContext);
	            Log.e(TAG, "eglDestroyContext:" + EGL14.eglGetError());
	        }
	        mDefaultContext = EGL14.EGL_NO_CONTEXT;
        }
    }
 
Example 6
Source File: EglCore.java    From AndroidPlayground with MIT License 6 votes vote down vote up
/**
 * Discards all resources held by this class, notably the EGL context.  This must be
 * called from the thread where the context was created.
 * <p>
 * On completion, no context will be current.
 */
public void release() {
    if (mEGLDisplay != EGL14.EGL_NO_DISPLAY) {
        // Android is unusual in that it uses a reference-counted EGLDisplay.  So for
        // every eglInitialize() we need an eglTerminate().
        EGL14.eglMakeCurrent(mEGLDisplay, EGL14.EGL_NO_SURFACE, EGL14.EGL_NO_SURFACE,
                EGL14.EGL_NO_CONTEXT);
        EGL14.eglDestroyContext(mEGLDisplay, mEGLContext);
        EGL14.eglReleaseThread();
        EGL14.eglTerminate(mEGLDisplay);
    }

    mEGLDisplay = EGL14.EGL_NO_DISPLAY;
    mEGLContext = EGL14.EGL_NO_CONTEXT;
    mEGLConfig = null;
}
 
Example 7
Source File: OutputSurface.java    From android-transcoder with Apache License 2.0 6 votes vote down vote up
/**
 * Discard all resources held by this class, notably the EGL context.
 */
public void release() {
    if (mEGLDisplay != EGL14.EGL_NO_DISPLAY) {
        EGL14.eglDestroySurface(mEGLDisplay, mEGLSurface);
        EGL14.eglDestroyContext(mEGLDisplay, mEGLContext);
        EGL14.eglReleaseThread();
        EGL14.eglTerminate(mEGLDisplay);
    }
    mSurface.release();
    // this causes a bunch of warnings that appear harmless but might confuse someone:
    //  W BufferQueue: [unnamed-3997-2] cancelBuffer: BufferQueue has been abandoned!
    //mSurfaceTexture.release();
    mEGLDisplay = EGL14.EGL_NO_DISPLAY;
    mEGLContext = EGL14.EGL_NO_CONTEXT;
    mEGLSurface = EGL14.EGL_NO_SURFACE;
    mTextureRender = null;
    mSurface = null;
    mSurfaceTexture = null;
}
 
Example 8
Source File: EglCore.java    From FuAgoraDemoDroid with MIT License 6 votes vote down vote up
/**
 * Discards all resources held by this class, notably the EGL context.  This must be
 * called from the thread where the context was created.
 * <p>
 * On completion, no context will be current.
 */
public void release() {
    if (mEGLDisplay != EGL14.EGL_NO_DISPLAY) {
        // Android is unusual in that it uses a reference-counted EGLDisplay.  So for
        // every eglInitialize() we need an eglTerminate().
        EGL14.eglMakeCurrent(mEGLDisplay, EGL14.EGL_NO_SURFACE, EGL14.EGL_NO_SURFACE,
                EGL14.EGL_NO_CONTEXT);
        EGL14.eglDestroyContext(mEGLDisplay, mEGLContext);
        EGL14.eglReleaseThread();
        EGL14.eglTerminate(mEGLDisplay);
    }

    mEGLDisplay = EGL14.EGL_NO_DISPLAY;
    mEGLContext = EGL14.EGL_NO_CONTEXT;
    mEGLConfig = null;
}
 
Example 9
Source File: InstantCameraView.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
@Override
protected void finalize() throws Throwable {
    try {
        if (eglDisplay != EGL14.EGL_NO_DISPLAY) {
            EGL14.eglMakeCurrent(eglDisplay, EGL14.EGL_NO_SURFACE, EGL14.EGL_NO_SURFACE, EGL14.EGL_NO_CONTEXT);
            EGL14.eglDestroyContext(eglDisplay, eglContext);
            EGL14.eglReleaseThread();
            EGL14.eglTerminate(eglDisplay);
            eglDisplay = EGL14.EGL_NO_DISPLAY;
            eglContext = EGL14.EGL_NO_CONTEXT;
            eglConfig = null;
        }
    } finally {
        super.finalize();
    }
}
 
Example 10
Source File: EGLBase.java    From TimeLapseRecordingSample with Apache License 2.0 6 votes vote down vote up
private void destroyContext() {
if (DEBUG) Log.v(TAG, "destroyContext:");

      if (!EGL14.eglDestroyContext(mEglDisplay, mEglContext)) {
          Log.e("destroyContext", "display:" + mEglDisplay + " context: " + mEglContext);
          Log.e(TAG, "eglDestroyContex:" + EGL14.eglGetError());
      }
      mEglContext = EGL14.EGL_NO_CONTEXT;
      if (mDefaultContext != EGL14.EGL_NO_CONTEXT) {
       if (!EGL14.eglDestroyContext(mEglDisplay, mDefaultContext)) {
           Log.e("destroyContext", "display:" + mEglDisplay + " context: " + mDefaultContext);
           Log.e(TAG, "eglDestroyContex:" + EGL14.eglGetError());
       }
       mDefaultContext = EGL14.EGL_NO_CONTEXT;
      }
  }
 
Example 11
Source File: InputSurface.java    From Pix-Art-Messenger with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Discard all resources held by this class, notably the EGL context.  Also releases the
 * Surface that was passed to our constructor.
 */
public void release() {
    if (mEGLDisplay != EGL14.EGL_NO_DISPLAY) {
        EGL14.eglDestroySurface(mEGLDisplay, mEGLSurface);
        EGL14.eglDestroyContext(mEGLDisplay, mEGLContext);
        EGL14.eglReleaseThread();
        EGL14.eglTerminate(mEGLDisplay);
    }
    mSurface.release();
    mEGLDisplay = EGL14.EGL_NO_DISPLAY;
    mEGLContext = EGL14.EGL_NO_CONTEXT;
    mEGLSurface = EGL14.EGL_NO_SURFACE;
    mSurface = null;
}
 
Example 12
Source File: EglHelper.java    From AAVT with Apache License 2.0 5 votes vote down vote up
public boolean destroyGLES(EGLSurface surface,EGLContext context){
    EGL14.eglMakeCurrent(mEGLDisplay, EGL14.EGL_NO_SURFACE, EGL14.EGL_NO_SURFACE, EGL14.EGL_NO_CONTEXT);
    if(surface!=null){
        EGL14.eglDestroySurface(mEGLDisplay,surface);
    }
    if(context!=null){
        EGL14.eglDestroyContext(mEGLDisplay,context);
    }
    EGL14.eglTerminate(mEGLDisplay);
    log("gl destroy gles");
    return true;
}
 
Example 13
Source File: InputSurface.java    From VideoProcessor with Apache License 2.0 5 votes vote down vote up
public void release() {
    if (EGL14.eglGetCurrentContext().equals(mEGLContext)) {
        EGL14.eglMakeCurrent(mEGLDisplay, EGL14.EGL_NO_SURFACE, EGL14.EGL_NO_SURFACE, EGL14.EGL_NO_CONTEXT);
    }
    EGL14.eglDestroySurface(mEGLDisplay, mEGLSurface);
    EGL14.eglDestroyContext(mEGLDisplay, mEGLContext);
    mSurface.release();
    mEGLDisplay = null;
    mEGLContext = null;
    mEGLSurface = null;
    mSurface = null;
}
 
Example 14
Source File: SurfaceManager.java    From libstreaming with Apache License 2.0 5 votes vote down vote up
/**
 * Discards all resources held by this class, notably the EGL context.  Also releases the
 * Surface that was passed to our constructor.
 */
public void release() {
	if (mEGLDisplay != EGL14.EGL_NO_DISPLAY) {
		EGL14.eglMakeCurrent(mEGLDisplay, EGL14.EGL_NO_SURFACE, EGL14.EGL_NO_SURFACE,
				EGL14.EGL_NO_CONTEXT);
		EGL14.eglDestroySurface(mEGLDisplay, mEGLSurface);
		EGL14.eglDestroyContext(mEGLDisplay, mEGLContext);
		EGL14.eglReleaseThread();
		EGL14.eglTerminate(mEGLDisplay);
	}
	mEGLDisplay = EGL14.EGL_NO_DISPLAY;
	mEGLContext = EGL14.EGL_NO_CONTEXT;
	mEGLSurface = EGL14.EGL_NO_SURFACE;
	mSurface.release();
}
 
Example 15
Source File: EGLSurfaceTexture.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
/** Releases all allocated resources. */
@SuppressWarnings({"nullness:argument.type.incompatible"})
public void release() {
  handler.removeCallbacks(this);
  try {
    if (texture != null) {
      texture.release();
      GLES20.glDeleteTextures(1, textureIdHolder, 0);
    }
  } finally {
    if (display != null && !display.equals(EGL14.EGL_NO_DISPLAY)) {
      EGL14.eglMakeCurrent(
          display, EGL14.EGL_NO_SURFACE, EGL14.EGL_NO_SURFACE, EGL14.EGL_NO_CONTEXT);
    }
    if (surface != null && !surface.equals(EGL14.EGL_NO_SURFACE)) {
      EGL14.eglDestroySurface(display, surface);
    }
    if (context != null) {
      EGL14.eglDestroyContext(display, context);
    }
    // EGL14.eglReleaseThread could crash before Android K (see [internal: b/11327779]).
    if (Util.SDK_INT >= 19) {
      EGL14.eglReleaseThread();
    }
    if (display != null && !display.equals(EGL14.EGL_NO_DISPLAY)) {
      // Android is unusual in that it uses a reference-counted EGLDisplay.  So for
      // every eglInitialize() we need an eglTerminate().
      EGL14.eglTerminate(display);
    }
    display = null;
    context = null;
    surface = null;
    texture = null;
  }
}
 
Example 16
Source File: InputSurface.java    From deltachat-android with GNU General Public License v3.0 5 votes vote down vote up
public void release() {
    if (EGL14.eglGetCurrentContext().equals(mEGLContext)) {
        EGL14.eglMakeCurrent(mEGLDisplay, EGL14.EGL_NO_SURFACE, EGL14.EGL_NO_SURFACE, EGL14.EGL_NO_CONTEXT);
    }
    EGL14.eglDestroySurface(mEGLDisplay, mEGLSurface);
    EGL14.eglDestroyContext(mEGLDisplay, mEGLContext);
    mSurface.release();
    mEGLDisplay = null;
    mEGLContext = null;
    mEGLSurface = null;
    mSurface = null;
}
 
Example 17
Source File: InputSurface.java    From VideoCompressor with Apache License 2.0 5 votes vote down vote up
public void release() {
    if (EGL14.eglGetCurrentContext().equals(mEGLContext)) {
        EGL14.eglMakeCurrent(mEGLDisplay, EGL14.EGL_NO_SURFACE, EGL14.EGL_NO_SURFACE, EGL14.EGL_NO_CONTEXT);
    }
    EGL14.eglDestroySurface(mEGLDisplay, mEGLSurface);
    EGL14.eglDestroyContext(mEGLDisplay, mEGLContext);
    mSurface.release();
    mEGLDisplay = null;
    mEGLContext = null;
    mEGLSurface = null;
    mSurface = null;
}
 
Example 18
Source File: EGLSurfaceTexture.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
/** Releases all allocated resources. */
@SuppressWarnings({"nullness:argument.type.incompatible"})
public void release() {
  handler.removeCallbacks(this);
  try {
    if (texture != null) {
      texture.release();
      GLES20.glDeleteTextures(1, textureIdHolder, 0);
    }
  } finally {
    if (display != null && !display.equals(EGL14.EGL_NO_DISPLAY)) {
      EGL14.eglMakeCurrent(
          display, EGL14.EGL_NO_SURFACE, EGL14.EGL_NO_SURFACE, EGL14.EGL_NO_CONTEXT);
    }
    if (surface != null && !surface.equals(EGL14.EGL_NO_SURFACE)) {
      EGL14.eglDestroySurface(display, surface);
    }
    if (context != null) {
      EGL14.eglDestroyContext(display, context);
    }
    // EGL14.eglReleaseThread could crash before Android K (see [internal: b/11327779]).
    if (Util.SDK_INT >= 19) {
      EGL14.eglReleaseThread();
    }
    if (display != null && !display.equals(EGL14.EGL_NO_DISPLAY)) {
      // Android is unusual in that it uses a reference-counted EGLDisplay.  So for
      // every eglInitialize() we need an eglTerminate().
      EGL14.eglTerminate(display);
    }
    display = null;
    context = null;
    surface = null;
    texture = null;
  }
}
 
Example 19
Source File: EncoderSurface.java    From GPUVideo-android with MIT License 5 votes vote down vote up
/**
 * Discard all resources held by this class, notably the EGL context.  Also releases the
 * Surface that was passed to our constructor.
 */
public void release() {
    if (eglDisplay != EGL14.EGL_NO_DISPLAY) {
        EGL14.eglDestroySurface(eglDisplay, eglSurface);
        EGL14.eglDestroyContext(eglDisplay, eglContext);
        EGL14.eglReleaseThread();
        EGL14.eglTerminate(eglDisplay);
    }
    surface.release();
    eglDisplay = EGL14.EGL_NO_DISPLAY;
    eglContext = EGL14.EGL_NO_CONTEXT;
    eglSurface = EGL14.EGL_NO_SURFACE;
    surface = null;
}
 
Example 20
Source File: InputSurface.java    From talk-android with MIT License 5 votes vote down vote up
public void release() {
    if (EGL14.eglGetCurrentContext().equals(mEGLContext)) {
        EGL14.eglMakeCurrent(mEGLDisplay, EGL14.EGL_NO_SURFACE, EGL14.EGL_NO_SURFACE, EGL14.EGL_NO_CONTEXT);
    }
    EGL14.eglDestroySurface(mEGLDisplay, mEGLSurface);
    EGL14.eglDestroyContext(mEGLDisplay, mEGLContext);
    mSurface.release();
    mEGLDisplay = null;
    mEGLContext = null;
    mEGLSurface = null;
    mSurface = null;
}