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

The following examples show how to use android.opengl.EGL14#eglDestroySurface() . 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: GLMovieRecorder.java    From PhotoMovie with Apache License 2.0 6 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);
    }

    mSurface.release();

    mEGLDisplay = EGL14.EGL_NO_DISPLAY;
    mEGLContext = EGL14.EGL_NO_CONTEXT;
    mEGLSurface = EGL14.EGL_NO_SURFACE;

    mSurface = null;
}
 
Example 2
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 3
Source File: InputSurface.java    From SimpleVideoEdit 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 (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 4
Source File: CameraToMpegTest.java    From Android-MediaCodec-Examples with Apache License 2.0 6 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);
    }
    mSurface.release();

    mEGLDisplay = EGL14.EGL_NO_DISPLAY;
    mEGLContext = EGL14.EGL_NO_CONTEXT;
    mEGLSurface = EGL14.EGL_NO_SURFACE;

    mSurface = null;
}
 
Example 5
Source File: VideoRenderOutputSurface.java    From LiTr with BSD 2-Clause "Simplified" License 6 votes vote down vote up
/**
 * Discard all resources held by this class, notably the EGL context.
 */
public void release() {
    if (eglDisplay != EGL14.EGL_NO_DISPLAY) {
        EGL14.eglDestroySurface(eglDisplay, eglSurface);
        EGL14.eglDestroyContext(eglDisplay, eglContext);
        EGL14.eglReleaseThread();
        EGL14.eglTerminate(eglDisplay);

        eglDisplay = EGL14.EGL_NO_DISPLAY;
        eglContext = EGL14.EGL_NO_CONTEXT;
        eglSurface = EGL14.EGL_NO_SURFACE;
    }
    if (surface != null) {
        surface.release();
        surface = null;
    }
}
 
Example 6
Source File: EGLBase14.java    From libcommon with Apache License 2.0 5 votes vote down vote up
private void destroyWindowSurface(EGLSurface surface) {
//		if (DEBUG) Log.v(TAG, "destroySurface:");

        if (surface != EGL14.EGL_NO_SURFACE) {
        	EGL14.eglMakeCurrent(mEglDisplay,
        		EGL14.EGL_NO_SURFACE, EGL14.EGL_NO_SURFACE, EGL14.EGL_NO_CONTEXT);
        	EGL14.eglDestroySurface(mEglDisplay, surface);
        }
//		if (DEBUG) Log.v(TAG, "destroySurface:finished");
	}
 
Example 7
Source File: EGLSurfaceTexture.java    From Telegram 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 8
Source File: InputSurface.java    From react-native-video-helper 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;
}
 
Example 9
Source File: SurfaceManager.java    From spydroid-ipcamera with GNU General Public License v3.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 10
Source File: EGLBase.java    From MegviiFacepp-Android-SDK with Apache License 2.0 5 votes vote down vote up
private void destroyWindowSurface(EGLSurface surface) {
	if (DEBUG) Log.v(TAG, "destroySurface:");

       if (surface != EGL14.EGL_NO_SURFACE) {
       	EGL14.eglMakeCurrent(mEglDisplay,
       		EGL14.EGL_NO_SURFACE, EGL14.EGL_NO_SURFACE, EGL14.EGL_NO_CONTEXT);
       	EGL14.eglDestroySurface(mEglDisplay, surface);
       }
       surface = EGL14.EGL_NO_SURFACE;
       if (DEBUG) Log.v(TAG, "destroySurface:finished");
}
 
Example 11
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 12
Source File: EGLSurfaceTexture.java    From MediaSDK with Apache License 2.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 13
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 14
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 15
Source File: SketchUtils.java    From sketch with Apache License 2.0 4 votes vote down vote up
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
private static int getOpenGLMaxTextureSizeJB1() {
    // Then get a hold of the default display, and initialize.
    // This could get more complex if you have to deal with devices that could have multiple displays,
    // but will be sufficient for a typical phone/tablet:
    android.opengl.EGLDisplay dpy = EGL14.eglGetDisplay(EGL14.EGL_DEFAULT_DISPLAY);
    int[] vers = new int[2];
    EGL14.eglInitialize(dpy, vers, 0, vers, 1);

    // Next, we need to find a config. Since we won't use this context for rendering,
    // the exact attributes aren't very critical:
    int[] configAttr = {
            EGL14.EGL_COLOR_BUFFER_TYPE, EGL14.EGL_RGB_BUFFER,
            EGL14.EGL_LEVEL, 0,
            EGL14.EGL_RENDERABLE_TYPE, EGL14.EGL_OPENGL_ES2_BIT,
            EGL14.EGL_SURFACE_TYPE, EGL14.EGL_PBUFFER_BIT,
            EGL14.EGL_NONE
    };
    android.opengl.EGLConfig[] configs = new android.opengl.EGLConfig[1];
    int[] numConfig = new int[1];
    EGL14.eglChooseConfig(dpy, configAttr, 0,
            configs, 0, 1, numConfig, 0);
    //noinspection StatementWithEmptyBody
    if (numConfig[0] == 0) {
        // TROUBLE! No config found.
    }
    android.opengl.EGLConfig config = configs[0];

    // To make a context current, which we will need later,
    // you need a rendering surface, even if you don't actually plan to render.
    // To satisfy this requirement, create a small offscreen (Pbuffer) surface:
    int[] surfAttr = {
            EGL14.EGL_WIDTH, 64,
            EGL14.EGL_HEIGHT, 64,
            EGL14.EGL_NONE
    };
    android.opengl.EGLSurface surf = EGL14.eglCreatePbufferSurface(dpy, config, surfAttr, 0);

    // Next, create the context:
    int[] ctxAttrib = {
            EGL14.EGL_CONTEXT_CLIENT_VERSION, 2,
            EGL14.EGL_NONE
    };
    android.opengl.EGLContext ctx = EGL14.eglCreateContext(dpy, config, EGL14.EGL_NO_CONTEXT, ctxAttrib, 0);

    // Ready to make the context current now:
    EGL14.eglMakeCurrent(dpy, surf, surf, ctx);

    // If all of the above succeeded (error checking was omitted), you can make your OpenGL calls now:
    int[] maxSize = new int[1];
    GLES20.glGetIntegerv(GLES20.GL_MAX_TEXTURE_SIZE, maxSize, 0);

    // Once you're all done, you can tear down everything:
    EGL14.eglMakeCurrent(dpy, EGL14.EGL_NO_SURFACE, EGL14.EGL_NO_SURFACE,
            EGL14.EGL_NO_CONTEXT);
    EGL14.eglDestroySurface(dpy, surf);
    EGL14.eglDestroyContext(dpy, ctx);
    EGL14.eglTerminate(dpy);

    return maxSize[0];
}
 
Example 16
Source File: EglCore.java    From mobile-ar-sensor-logger with GNU General Public License v3.0 2 votes vote down vote up
/**
 * Destroys the specified surface.  Note the EGLSurface won't actually be destroyed if it's
 * still current in a context.
 */
public void releaseSurface(EGLSurface eglSurface) {
    EGL14.eglDestroySurface(mEGLDisplay, eglSurface);
}
 
Example 17
Source File: EglCore.java    From IjkVRPlayer with Apache License 2.0 2 votes vote down vote up
/**
 * Destroys the specified surface.  Note the EGLSurface won't actually be destroyed if it's
 * still current in a context.
 */
public void releaseSurface(EGLSurface eglSurface) {
    EGL14.eglDestroySurface(mEGLDisplay, eglSurface);
}
 
Example 18
Source File: EglCore.java    From grafika with Apache License 2.0 2 votes vote down vote up
/**
 * Destroys the specified surface.  Note the EGLSurface won't actually be destroyed if it's
 * still current in a context.
 */
public void releaseSurface(EGLSurface eglSurface) {
    EGL14.eglDestroySurface(mEGLDisplay, eglSurface);
}
 
Example 19
Source File: EglCore.java    From MockCamera with Apache License 2.0 2 votes vote down vote up
/**
 * Destroys the specified surface.  Note the EGLSurface won't actually be destroyed if it's
 * still current in a context.
 */
public void releaseSurface(EGLSurface eglSurface) {
    EGL14.eglDestroySurface(eGLDisplay, eglSurface);
}
 
Example 20
Source File: EglCore.java    From PhotoMovie with Apache License 2.0 2 votes vote down vote up
/**
 * Destroys the specified surface.  Note the EGLSurface won't actually be destroyed if it's
 * still current in a context.
 */
public void releaseSurface(EGLSurface eglSurface) {
    EGL14.eglDestroySurface(mEGLDisplay, eglSurface);
}