DefaultGlObjectsProvider


@UnstableApi
public final class DefaultGlObjectsProvider implements GlObjectsProvider


Implementation of GlObjectsProvider that configures an EGLContext to share data with a preexisting sharedEglContext.

The created EGLContext is configured with 8-bit RGB or 10-bit RGB attributes and no depth buffer or render buffers.

Summary

Public constructors

Creates an instance with no shared EGL context.

Creates an instance with the specified shared EGL context.

Public methods

GlTextureInfo
createBuffersForTexture(int texId, int width, int height)

Returns a GlTextureInfo containing the identifiers of the newly created buffers.

EGLContext
createEglContext(
    EGLDisplay eglDisplay,
    int openGlVersion,
    int[] configAttributes
)

Creates a new EGLContext for the specified EGLDisplay.

EGLSurface
createEglSurface(
    EGLDisplay eglDisplay,
    Object surface,
    @C.ColorTransfer int colorTransfer,
    boolean isEncoderInputSurface
)

Creates a new EGLSurface wrapping the specified surface.

EGLSurface
createFocusedPlaceholderEglSurface(
    EGLContext eglContext,
    EGLDisplay eglDisplay
)

Creates and focuses a placeholder EGLSurface.

void
release(EGLDisplay eglDisplay)

Releases the created objects.

Public constructors

DefaultGlObjectsProvider

public DefaultGlObjectsProvider()

Creates an instance with no shared EGL context.

DefaultGlObjectsProvider

public DefaultGlObjectsProvider(@Nullable EGLContext sharedEglContext)

Creates an instance with the specified shared EGL context.

Parameters
@Nullable EGLContext sharedEglContext

The context with which to share data, or null if none.

Public methods

createBuffersForTexture

public GlTextureInfo createBuffersForTexture(int texId, int width, int height)

Returns a GlTextureInfo containing the identifiers of the newly created buffers.

Parameters
int texId

The identifier of the texture to attach to the buffers.

int width

The width of the texture in pixels.

int height

The height of the texture in pixels.

Throws
androidx.media3.common.util.GlUtil.GlException

If an error occurs during creation.

createEglContext

public EGLContext createEglContext(
    EGLDisplay eglDisplay,
    int openGlVersion,
    int[] configAttributes
)

Creates a new EGLContext for the specified EGLDisplay.

Parameters
EGLDisplay eglDisplay

The EGLDisplay to create an EGLContext for.

int openGlVersion

The version of OpenGL ES to configure. Accepts either 2, for OpenGL ES 2.0, or 3, for OpenGL ES 3.0.

int[] configAttributes

The attributes to configure EGL with.

Throws
androidx.media3.common.util.GlUtil.GlException

If an error occurs during creation.

createEglSurface

public EGLSurface createEglSurface(
    EGLDisplay eglDisplay,
    Object surface,
    @C.ColorTransfer int colorTransfer,
    boolean isEncoderInputSurface
)

Creates a new EGLSurface wrapping the specified surface.

Parameters
EGLDisplay eglDisplay

The EGLDisplay to attach the surface to.

Object surface

The surface to wrap; must be a surface, surface texture or surface holder.

@C.ColorTransfer int colorTransfer

The color transfer characteristics to which the surface is configured.

boolean isEncoderInputSurface

Whether the surface is the input surface of an encoder.

Throws
androidx.media3.common.util.GlUtil.GlException

If an error occurs during creation.

createFocusedPlaceholderEglSurface

public EGLSurface createFocusedPlaceholderEglSurface(
    EGLContext eglContext,
    EGLDisplay eglDisplay
)

Creates and focuses a placeholder EGLSurface.

Parameters
EGLContext eglContext

The EGLContext to make current.

EGLDisplay eglDisplay

The EGLDisplay to attach the surface to.

Returns
EGLSurface

A placeholder EGLSurface that has been focused to allow rendering to take place, or EGL_NO_SURFACE if the current context supports rendering without a surface.

Throws
androidx.media3.common.util.GlUtil.GlException

If an error occurs during creation.

release

public void release(EGLDisplay eglDisplay)

Releases the created objects.

Parameters
EGLDisplay eglDisplay

The EGLDisplay to release the objects for.