Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Clean SurfaceTexture with black rect

I'm using Exoplayer and an GL SurfaceTexture (from a TextureView) to display a video. I'm reusing the same surface among video play.

I release the player and instantiate a new one. When the SurfaceTexture is displayed the second time, it display the old Texture from last video until the player begin to play and fill the Surface with black.

I'm looking for a way to draw a black rect to fill the surface with black, but unable to achieve this.

like image 298
Hugo Gresse Avatar asked May 11 '15 10:05

Hugo Gresse


People also ask

How do I get rid of the black box around my cursor?

Here are the step that you can follow to eliminate the black box surrounding your cursor: Click Start and type Control Panel and hit Enter. Under Control Panel, click on Ease of Access Center. Select Make the computer easier to see. Under Make things easier to see, Select the thickness of the blinking cursor to 1.

How do I Turn Off the translucent selection rectangle?

The translucent selection rectangle is the box you see when you left click and hold, and then drag the pointer over items to select them when you release the left click. If you like, you can turn off showing the translucent selection rectangle on your desktop.

How do I fix a black box on my screen?

Press Win plus Esc to end that. Otherwise, depending on the size of your "black box" it may only represent a problem with the Mouse pointer options. Then, try changing the mouse pointer to have different attributes.

Why is there a black box around my curser?

This thread is locked. You can follow the question or vote as helpful, but you cannot reply to this thread. BLACK BOX around my curser. Is the Lens Magnifier? Press Win plus Esc to end that. Otherwise, depending on the size of your "black box" it may only represent a problem with the Mouse pointer options.


1 Answers

Using @fadden link on Grafika, I've made my own script to clear the surface. It's compatible from API 16.

GIST

/**
 * Clear the given surface Texture by attaching a GL context and clearing the surface.
 * @param texture a valid SurfaceTexture
 */
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,      // 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, 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);
}
like image 197
Hugo Gresse Avatar answered Sep 18 '22 22:09

Hugo Gresse