Java Code Examples for javax.microedition.khronos.egl.EGL10#eglSwapBuffers()

The following examples show how to use javax.microedition.khronos.egl.EGL10#eglSwapBuffers() . 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: ResizingSurfaceView.java    From ExoMedia with Apache License 2.0 6 votes vote down vote up
/**
 * Clears the frames from the current surface.  This should only be called when
 * the implementing video view has finished playback or otherwise released
 * the surface
 */
@Override
public void clearSurface() {
    try {
        EGL10 gl10 = (EGL10) EGLContext.getEGL();
        EGLDisplay display = gl10.eglGetDisplay(EGL10.EGL_DEFAULT_DISPLAY);
        gl10.eglInitialize(display, null);

        EGLConfig[] configs = new EGLConfig[1];
        gl10.eglChooseConfig(display, GL_CLEAR_CONFIG_ATTRIBUTES, configs, configs.length, new int[1]);
        EGLContext context = gl10.eglCreateContext(display, configs[0], EGL10.EGL_NO_CONTEXT, GL_CLEAR_CONTEXT_ATTRIBUTES);
        EGLSurface eglSurface = gl10.eglCreateWindowSurface(display, configs[0], this, new int[]{EGL10.EGL_NONE});

        gl10.eglMakeCurrent(display, eglSurface, eglSurface, context);
        gl10.eglSwapBuffers(display, eglSurface);
        gl10.eglDestroySurface(display, eglSurface);
        gl10.eglMakeCurrent(display, EGL10.EGL_NO_SURFACE, EGL10.EGL_NO_SURFACE, EGL10.EGL_NO_CONTEXT);
        gl10.eglDestroyContext(display, context);

        gl10.eglTerminate(display);
    } catch (Exception e) {
        Log.e(TAG, "Error clearing surface", e);
    }
}
 
Example 2
Source File: ResizingTextureView.java    From ExoMedia with Apache License 2.0 5 votes vote down vote up
/**
 * Clears the frames from the current surface.  This should only be called when
 * the implementing video view has finished playback or otherwise released
 * the surface
 */
@Override
public void clearSurface() {
    if (getSurfaceTexture() == null) {
        return;
    }

    try {
        EGL10 gl10 = (EGL10) EGLContext.getEGL();
        EGLDisplay display = gl10.eglGetDisplay(EGL10.EGL_DEFAULT_DISPLAY);
        gl10.eglInitialize(display, null);

        EGLConfig[] configs = new EGLConfig[1];
        gl10.eglChooseConfig(display, GL_CLEAR_CONFIG_ATTRIBUTES, configs, configs.length, new int[1]);
        EGLContext context = gl10.eglCreateContext(display, configs[0], EGL10.EGL_NO_CONTEXT, GL_CLEAR_CONTEXT_ATTRIBUTES);
        EGLSurface eglSurface = gl10.eglCreateWindowSurface(display, configs[0], getSurfaceTexture(), new int[]{EGL10.EGL_NONE});

        gl10.eglMakeCurrent(display, eglSurface, eglSurface, context);
        gl10.eglSwapBuffers(display, eglSurface);
        gl10.eglDestroySurface(display, eglSurface);
        gl10.eglMakeCurrent(display, EGL10.EGL_NO_SURFACE, EGL10.EGL_NO_SURFACE, EGL10.EGL_NO_CONTEXT);
        gl10.eglDestroyContext(display, context);

        gl10.eglTerminate(display);
    } catch (Exception e) {
        Log.e(TAG, "Error clearing surface", e);
    }
}
 
Example 3
Source File: TextureVideoView.java    From texturevideoview with Apache License 2.0 5 votes vote down vote up
/**
 * Clears the surface texture by attaching a GL context and clearing it.
 * Code taken from <a href="http://stackoverflow.com/a/31582209">Hugo Gresse's answer on stackoverflow.com</a>.
 */
private void clearSurface() {
    if (mSurface == null || Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) {
        return;
    }

    EGL10 egl = (EGL10) EGLContext.getEGL();
    EGLDisplay display = egl.eglGetDisplay(EGL10.EGL_DEFAULT_DISPLAY);
    egl.eglInitialize(display, null);

    int[] attribList = {
        EGL10.EGL_RED_SIZE, 8,
        EGL10.EGL_GREEN_SIZE, 8,
        EGL10.EGL_BLUE_SIZE, 8,
        EGL10.EGL_ALPHA_SIZE, 8,
        EGL10.EGL_RENDERABLE_TYPE, EGL10.EGL_WINDOW_BIT,
        EGL10.EGL_NONE, 0,      // placeholder for recordable [@-3]
        EGL10.EGL_NONE
    };
    EGLConfig[] configs = new EGLConfig[1];
    int[] numConfigs = new int[1];
    egl.eglChooseConfig(display, attribList, configs, configs.length, numConfigs);
    EGLConfig config = configs[0];
    EGLContext context = egl.eglCreateContext(display, config, EGL10.EGL_NO_CONTEXT, new int[]{
        12440, 2, EGL10.EGL_NONE
    });
    EGLSurface eglSurface = egl.eglCreateWindowSurface(display, config, mSurface, new int[]{
        EGL10.EGL_NONE
    });

    egl.eglMakeCurrent(display, eglSurface, eglSurface, context);
    GLES20.glClearColor(0, 0, 0, 1);
    GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT);
    egl.eglSwapBuffers(display, eglSurface);
    egl.eglDestroySurface(display, eglSurface);
    egl.eglMakeCurrent(display, EGL10.EGL_NO_SURFACE, EGL10.EGL_NO_SURFACE, EGL10.EGL_NO_CONTEXT);
    egl.eglDestroyContext(display, context);
    egl.eglTerminate(display);
}
 
Example 4
Source File: OBVideoPlayer.java    From GLEXP-Team-onebillion with Apache License 2.0 4 votes vote down vote up
private void clearSurface(SurfaceTexture texture)
{
    if(texture == null){
        return;
    }

    EGL10 egl = (EGL10) EGLContext.getEGL();
    EGLDisplay display = egl.eglGetDisplay(EGL10.EGL_DEFAULT_DISPLAY);
    egl.eglInitialize(display, null);

    int[] attribList = {
            EGL10.EGL_RED_SIZE, 8,
            EGL10.EGL_GREEN_SIZE, 8,
            EGL10.EGL_BLUE_SIZE, 8,
            EGL10.EGL_ALPHA_SIZE, 8,
            EGL10.EGL_RENDERABLE_TYPE, EGL10.EGL_WINDOW_BIT,
            EGL10.EGL_NONE, 0,
            EGL10.EGL_NONE
    };
    EGLConfig[] configs = new EGLConfig[1];
    int[] numConfigs = new int[1];
    egl.eglChooseConfig(display, attribList, configs, configs.length, numConfigs);
    EGLConfig config = configs[0];
    EGLContext context = egl.eglCreateContext(display, config, EGL10.EGL_NO_CONTEXT, new int[]{
            12440, 2,
            EGL10.EGL_NONE
    });
    EGLSurface eglSurface = egl.eglCreateWindowSurface(display, config, texture,
            new int[]{
                    EGL10.EGL_NONE
            });

    egl.eglMakeCurrent(display, eglSurface, eglSurface, context);
    GLES20.glClearColor(0, 0, 0, 1);
    GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT);
    egl.eglSwapBuffers(display, eglSurface);
    egl.eglDestroySurface(display, eglSurface);
    egl.eglMakeCurrent(display, EGL10.EGL_NO_SURFACE, EGL10.EGL_NO_SURFACE,
            EGL10.EGL_NO_CONTEXT);
    egl.eglDestroyContext(display, context);
    egl.eglTerminate(display);
}