class EGLExt


Utility class that provides some helper methods for interacting EGL Extension APIs

Summary

Constants

const String

Extension that allows creating an EGLClientBuffer from an Android HardwareBuffer object which can later be used to create an EGLImageKHR instance.

const String

Enables using an Android window buffer (struct ANativeWindowBuffer) as an EGLImage source

const String

Determines whether creation of platform specific sync objects are supported.

const Int

Return value used in eglClientWaitSyncKHR to indicate that the sync object had signalled before the timeout expired.

const String

Determines if applications can query the age of the back buffer contents for an EGL surface as the number of frames elapsed since the contents were recently defined

const String

Determines whether the platform framebuffers support rendering in a larger color gamut specified in the BT.2020 color space

const String

Determines whether the underlying platform can support rendering framebuffers in the non-linear Display-P3 color space

const String

Determines whether extended sRGB color spaces are supported options for EGL Surfaces

const String

Determines whether floating point RGBA components are supported

const Int

Constant indicating false within EGL.

const Long

Value that can be sent as the timeoutNanos parameter of eglClientWaitSyncKHR indicating that waiting on the sync object to signal will never time out.

const String

Determines whether an EGLContext can be created with a priority hint.

const String

Determines whether sync objects are supported.

const String

Determines whether to use sRGB format default framebuffers to render sRGB content to display devices.

const String

Extension that defines a new EGL resource type that is suitable for sharing 2D arrays of image data between client APIs, the EGLImage, and allows creating EGLImages from EGL native pixmaps.

const String

Extension for supporting a new EGL resource type that is suitable for sharing 2D arrays of image data between client APIs, the EGLImage.

const String

Determines whether creation of GL and ES contexts without an EGLConfig is allowed

const String

Allows for efficient partial updates to an area of a buffer that has changed since the last time the buffer was used

const String

Determines whether creation of an EGL Context without a surface is supported.

const String

Allows for efficient partial updates to an area of a surface that changes between frames for the surface.

const String

Determines whether waiting for signaling of sync objects is supported.

const Int

Return value when eglGetSyncAttribKHR is called with EGL_SYNC_STATUS_KHR indicating that the sync object has already been signalled.

const Int

Attribute that can be queried in eglGetSyncAttribKHR.

const Int

Create an EGL fence sync object for signalling one time events.

const Int

Accepted in the flags parameter of eglClientWaitSyncKHR.

const Int

This extension enables the creation of EGL fence sync objects that are associated with a native synchronization fence object that is referenced using a file descriptor.

const Int

Return value when eglGetSyncAttribKHR is called with EGL_SYNC_CONDITION_KHR.

const Int

Attribute that can be queried in eglGetSyncAttribKHR.

const Int

Attribute that can be queried in eglGetSyncAttribKHR.

const Int

Return value used in eglClientWaitSyncKHR to indicate that the specified timeout period had expired before a sync object was signalled.

const Int

Constant indicating true within EGL.

const Int

Return value when eglGetSyncAttribKHR is called with EGL_SYNC_STATUS_KHR indicating that the sync object has not yet been signalled.

Public companion functions

Int
eglClientWaitSyncKHR(
    eglDisplay: EGLDisplay,
    sync: EGLSyncKHR,
    flags: Int,
    timeoutNanos: Long
)

Blocks the calling thread until the specified sync object is signalled or until timeoutNanos nanoseconds have passed.

EGLImageKHR?
@RequiresApi(value = 26)
eglCreateImageFromHardwareBuffer(
    eglDisplay: EGLDisplay,
    hardwareBuffer: HardwareBuffer
)

Creates an EGLImage from the provided HardwareBuffer.

EGLSyncKHR?
eglCreateSyncKHR(
    eglDisplay: EGLDisplay,
    type: Int,
    attributes: EGLConfigAttributes?
)

Creates a sync object of the specified type associated with the specified display, and returns a handle to the new object.

Boolean
eglDestroyImageKHR(eglDisplay: EGLDisplay, image: EGLImageKHR)

Destroy the given EGLImageKHR instance.

Boolean
eglDestroySyncKHR(eglDisplay: EGLDisplay, eglSync: EGLSyncKHR)

Destroys the given sync object associated with the specified display

Boolean
eglGetSyncAttribKHR(
    eglDisplay: EGLDisplay,
    sync: EGLSyncKHR,
    attribute: Int,
    value: IntArray,
    offset: Int
)

Query attributes of the provided sync object.

Unit

Upload a given EGLImage to the currently bound GLTexture

Set<String>
parseExtensions(queryString: String)

Returns a set of supported supported extensions from a space separated string that represents the set of OpenGL extensions supported

Constants

EGL_ANDROID_CLIENT_BUFFER

const val EGL_ANDROID_CLIENT_BUFFERString

Extension that allows creating an EGLClientBuffer from an Android HardwareBuffer object which can later be used to create an EGLImageKHR instance. See: https://registry.khronos.org/EGL/extensions/ANDROID/EGL_ANDROID_get_native_client_buffer.txt

EGL_ANDROID_IMAGE_NATIVE_BUFFER

const val EGL_ANDROID_IMAGE_NATIVE_BUFFERString

Enables using an Android window buffer (struct ANativeWindowBuffer) as an EGLImage source

See: https://www.khronos.org/registry/EGL/extensions/ANDROID/EGL_ANDROID_image_native_buffer.txt

EGL_ANDROID_NATIVE_FENCE_SYNC

const val EGL_ANDROID_NATIVE_FENCE_SYNCString

Determines whether creation of platform specific sync objects are supported. These objects that are associated with a native synchronization fence object using a file descriptor.

See: https://www.khronos.org/registry/EGL/extensions/ANDROID/EGL_ANDROID_native_fence_sync.txt

EGL_CONDITION_SATISFIED_KHR

const val EGL_CONDITION_SATISFIED_KHR = 12534: Int

Return value used in eglClientWaitSyncKHR to indicate that the sync object had signalled before the timeout expired. This includes the case where the sync object had already signalled before eglClientWaitSyncKHR was called.

EGL_EXT_BUFFER_AGE

const val EGL_EXT_BUFFER_AGEString

Determines if applications can query the age of the back buffer contents for an EGL surface as the number of frames elapsed since the contents were recently defined

See: https://www.khronos.org/registry/EGL/extensions/EXT/EGL_EXT_buffer_age.txt

EGL_EXT_GL_COLORSPACE_BT2020_PQ

const val EGL_EXT_GL_COLORSPACE_BT2020_PQString

Determines whether the platform framebuffers support rendering in a larger color gamut specified in the BT.2020 color space

See: https://www.khronos.org/registry/EGL/extensions/EXT/EGL_EXT_gl_colorspace_bt2020_linear.txt

EGL_EXT_GL_COLORSPACE_DISPLAY_P3_PASSTHROUGH

const val EGL_EXT_GL_COLORSPACE_DISPLAY_P3_PASSTHROUGHString

Determines whether the underlying platform can support rendering framebuffers in the non-linear Display-P3 color space

See: https://www.khronos.org/registry/EGL/extensions/EXT/EGL_EXT_gl_colorspace_display_p3_passthrough.txt

EGL_EXT_GL_COLORSPACE_SCRGB

const val EGL_EXT_GL_COLORSPACE_SCRGBString

Determines whether extended sRGB color spaces are supported options for EGL Surfaces

See: https://www.khronos.org/registry/EGL/extensions/EXT/EGL_EXT_gl_colorspace_scrgb.txt

EGL_EXT_PIXEL_FORMAT_FLOAT

const val EGL_EXT_PIXEL_FORMAT_FLOATString

Determines whether floating point RGBA components are supported

See: https://www.khronos.org/registry/EGL/extensions/EXT/EGL_EXT_pixel_format_float.txt

EGL_FALSE

const val EGL_FALSE = 0: Int

Constant indicating false within EGL. This is often returned in failure cases.

EGL_FOREVER_KHR

const val EGL_FOREVER_KHRLong

Value that can be sent as the timeoutNanos parameter of eglClientWaitSyncKHR indicating that waiting on the sync object to signal will never time out.

EGL_IMG_CONTEXT_PRIORITY

const val EGL_IMG_CONTEXT_PRIORITYString

Determines whether an EGLContext can be created with a priority hint. Not all implementations are guaranteed to honor the hint.

See: https://www.khronos.org/registry/EGL/extensions/IMG/EGL_IMG_context_priority.txt

EGL_KHR_FENCE_SYNC

const val EGL_KHR_FENCE_SYNCString

Determines whether sync objects are supported. Sync objects are synchronization primitives that represent events whose completion can be tested or waited upon.

See: https://www.khronos.org/registry/EGL/extensions/KHR/EGL_KHR_fence_sync.txt

EGL_KHR_GL_COLORSPACE

const val EGL_KHR_GL_COLORSPACEString

Determines whether to use sRGB format default framebuffers to render sRGB content to display devices. Supports creation of EGLSurfaces which will be rendered to in sRGB by OpenGL contexts supporting that capability.

See: https://www.khronos.org/registry/EGL/extensions/KHR/EGL_KHR_gl_colorspace.txt

EGL_KHR_IMAGE

const val EGL_KHR_IMAGEString

Extension that defines a new EGL resource type that is suitable for sharing 2D arrays of image data between client APIs, the EGLImage, and allows creating EGLImages from EGL native pixmaps.

See: https://www.khronos.org/registry/EGL/extensions/KHR/EGL_KHR_image.txt

EGL_KHR_IMAGE_BASE

const val EGL_KHR_IMAGE_BASEString

Extension for supporting a new EGL resource type that is suitable for sharing 2D arrays of image data between client APIs, the EGLImage. Although the intended purpose is sharing 2D image data, the underlying interface makes no assumptions about the format or purpose of the resource being shared, leaving those decisions to the application and associated client APIs.

See: https://www.khronos.org/registry/EGL/extensions/KHR/EGL_KHR_image_base.txt

EGL_KHR_NO_CONFIG_CONTEXT

const val EGL_KHR_NO_CONFIG_CONTEXTString

Determines whether creation of GL and ES contexts without an EGLConfig is allowed

See: https://www.khronos.org/registry/EGL/extensions/KHR/EGL_KHR_no_config_context.txt

EGL_KHR_PARTIAL_UPDATE

const val EGL_KHR_PARTIAL_UPDATEString

Allows for efficient partial updates to an area of a buffer that has changed since the last time the buffer was used

See: https://www.khronos.org/registry/EGL/extensions/KHR/EGL_KHR_partial_update.txt

EGL_KHR_SURFACELESS_CONTEXT

const val EGL_KHR_SURFACELESS_CONTEXTString

Determines whether creation of an EGL Context without a surface is supported. This is useful for applications that only want to render to client API targets (such as OpenGL framebuffer objects) and avoid the need to a throw-away EGL surface just to get a current context.

See: https://www.khronos.org/registry/EGL/extensions/KHR/EGL_KHR_surfaceless_context.txt

EGL_KHR_SWAP_BUFFERS_WITH_DAMAGE

const val EGL_KHR_SWAP_BUFFERS_WITH_DAMAGEString

Allows for efficient partial updates to an area of a surface that changes between frames for the surface. This relates to the differences between two buffers, the current back buffer and the current front buffer.

See: https://www.khronos.org/registry/EGL/extensions/KHR/EGL_KHR_swap_buffers_with_damage.txt

EGL_KHR_WAIT_SYNC

const val EGL_KHR_WAIT_SYNCString

Determines whether waiting for signaling of sync objects is supported. This form of wait does not necessarily block the application thread which issued the wait. Therefore applications may continue to issue commands to the client API or perform other work in parallel leading to increased performance.

See: https://www.khronos.org/registry/EGL/extensions/KHR/EGL_KHR_wait_sync.txt

EGL_SIGNALED_KHR

const val EGL_SIGNALED_KHR = 12530: Int

Return value when eglGetSyncAttribKHR is called with EGL_SYNC_STATUS_KHR indicating that the sync object has already been signalled.

See: https://www.khronos.org/registry/EGL/extensions/KHR/EGL_KHR_fence_sync.txt

EGL_SYNC_CONDITION_KHR

const val EGL_SYNC_CONDITION_KHR = 12536: Int

Attribute that can be queried in eglGetSyncAttribKHR. This attribute can only be queried on sync objects of the type EGL_SYNC_FENCE_KHR.

See: https://www.khronos.org/registry/EGL/extensions/KHR/EGL_KHR_fence_sync.txt

EGL_SYNC_FENCE_KHR

const val EGL_SYNC_FENCE_KHR = 12537: Int

Create an EGL fence sync object for signalling one time events. The fence object created is not associated with the Android Sync fence object and is not recommended for waiting for events in a portable manner across Android/EGL boundaries but rather other EGL primitives.

See: https://www.khronos.org/registry/EGL/extensions/KHR/EGL_KHR_fence_sync.txt

EGL_SYNC_FLUSH_COMMANDS_BIT_KHR

const val EGL_SYNC_FLUSH_COMMANDS_BIT_KHR = 1: Int

Accepted in the flags parameter of eglClientWaitSyncKHR. This will implicitly ensure pending commands are flushed to prevent eglClientWaitSyncKHR from potentially blocking forever. See eglClientWaitSyncKHR for details.

EGL_SYNC_NATIVE_FENCE_ANDROID

const val EGL_SYNC_NATIVE_FENCE_ANDROID = 12612: Int

This extension enables the creation of EGL fence sync objects that are associated with a native synchronization fence object that is referenced using a file descriptor. These EGL fence sync objects have nearly identical semantics to those defined by the KHR_fence_sync extension, except that they have an additional attribute storing the file descriptor referring to the native fence object. This differs from EGL_SYNC_FENCE_KHR as the fence sync object is associated with an Android Sync HAL fence object.

This extension assumes the existence of a native fence synchronization object that behaves similarly to an EGL fence sync object. These native objects must have a signal status like that of an EGLSyncKHR object that indicates whether the fence has ever been signaled. Once signaled the native object's signal status may not change again.

See: https://www.khronos.org/registry/EGL/extensions/ANDROID/EGL_ANDROID_native_fence_sync.txt

EGL_SYNC_PRIOR_COMMANDS_COMPLETE_KHR

const val EGL_SYNC_PRIOR_COMMANDS_COMPLETE_KHR = 12528: Int

Return value when eglGetSyncAttribKHR is called with EGL_SYNC_CONDITION_KHR. This indicates that the sync object will signal on the condition of the completion of the fence command on the corresponding sync object and all preceding commands in th EGL client API's command stream.

EGL_SYNC_STATUS_KHR

const val EGL_SYNC_STATUS_KHR = 12529: Int

Attribute that can be queried in eglGetSyncAttribKHR. The results can be either EGL_SIGNALED_KHR or EGL_UNSIGNALED_KHR representing whether or not the sync object has been signalled or not. This can be queried on all sync object types.

See: https://www.khronos.org/registry/EGL/extensions/KHR/EGL_KHR_fence_sync.txt

EGL_SYNC_TYPE_KHR

const val EGL_SYNC_TYPE_KHR = 12535: Int

Attribute that can be queried in eglGetSyncAttribKHR. The results can be either EGL_SYNC_FENCE_KHR or EGL_SYNC_NATIVE_FENCE_ANDROID.

See: https://www.khronos.org/registry/EGL/extensions/KHR/EGL_KHR_fence_sync.txt

EGL_TIMEOUT_EXPIRED_KHR

const val EGL_TIMEOUT_EXPIRED_KHR = 12533: Int

Return value used in eglClientWaitSyncKHR to indicate that the specified timeout period had expired before a sync object was signalled.

EGL_TRUE

const val EGL_TRUE = 1: Int

Constant indicating true within EGL. This is often returned in success cases.

EGL_UNSIGNALED_KHR

const val EGL_UNSIGNALED_KHR = 12531: Int

Return value when eglGetSyncAttribKHR is called with EGL_SYNC_STATUS_KHR indicating that the sync object has not yet been signalled.

See: https://www.khronos.org/registry/EGL/extensions/KHR/EGL_KHR_fence_sync.txt

Public companion functions

eglClientWaitSyncKHR

Added in 1.0.2
fun eglClientWaitSyncKHR(
    eglDisplay: EGLDisplay,
    sync: EGLSyncKHR,
    flags: Int,
    timeoutNanos: Long
): Int

Blocks the calling thread until the specified sync object is signalled or until timeoutNanos nanoseconds have passed. More than one eglClientWaitSyncKHR may be outstanding on the same sync at any given time. When there are multiple threads blocked on the same sync and the sync object has signalled, all such threads are released, but the order in which they are released is not defined.

If the value of timeoutNanos is zero, then eglClientWaitSyncKHR simply tests the current status of sync. If the value of timeoutNanos is the special value EGL_FOREVER_KHR, then eglClientWaitSyncKHR does not time out. For all other values, timeoutNanos is adjusted to the closest value allowed by the implementation-dependent timeout accuracy, which may be substantially longer than one nanosecond.

eglClientWaitSyncKHR returns one of three status values describing the reason for returning. A return value of EGL_TIMEOUT_EXPIRED_KHR indicates that the specified timeout period expired before sync was signalled, or if timeoutNanos is zero, indicates that sync is not signaled. A return value of EGL_CONDITION_SATISFIED_KHR indicates that sync was signaled before the timeout expired, which includes the case when sync was already signaled when eglClientWaitSyncKHR was called. If an error occurs then an error is generated and EGL_FALSE is returned.

If the sync object being blocked upon will not be signaled in finite time (for example by an associated fence command issued previously, but not yet flushed to the graphics pipeline), then eglClientWaitSyncKHR may wait forever. To help prevent this behavior, if the EGL_SYNC_FLUSH_COMMANDS_BIT_KHR is set on the flags parameter and the sync is unsignaled when eglClientWaitSyncKHR is called, then the equivalent flush will be performed for the current EGL context before blocking on sync. If no context is current bound for the API, the EGL_SYNC_FLUSH_COMMANDS_BIT_KHR bit is ignored.

Parameters
eglDisplay: EGLDisplay

EGLDisplay to associate the sync object with

sync: EGLSyncKHR

EGLSyncKHR object to wait on

flags: Int

Optional flags to provide to handle flushing of pending commands

timeoutNanos: Long

Optional timeout value to wait before this method returns, measured in nanoseconds. This value is always consumed as an unsigned long value so even negative values will be converted to their unsigned equivalent.

Returns
Int

Result code indicating the status of the wait request. Either EGL_CONDITION_SATISFIED_KHR, if the sync did signal within the specified timeout, EGL_TIMEOUT_EXPIRED_KHR if the sync did not signal within the specified timeout, or EGL_FALSE if an error occurs.

eglCreateImageFromHardwareBuffer

Added in 1.0.2
@RequiresApi(value = 26)
fun eglCreateImageFromHardwareBuffer(
    eglDisplay: EGLDisplay,
    hardwareBuffer: HardwareBuffer
): EGLImageKHR?

Creates an EGLImage from the provided HardwareBuffer. This handles internally creating an EGLClientBuffer and an EGLImageKHR from the client buffer.

When this EGLImageKHR instance is no longer necessary, consumers should be sure to call the corresponding method eglDestroyImageKHR to deallocate the resource.

Parameters
eglDisplay: EGLDisplay

EGLDisplay connection associated with the EGLImage to create

hardwareBuffer: HardwareBuffer

Backing HardwareBuffer for the generated EGLImage instance

Returns
EGLImageKHR?

an EGLImageKHR instance representing the EGLImageKHR created from the HardwareBuffer. Because this is created internally through EGL's eglCreateImageKR method, this has the KHR suffix.

This can return null if the EGL_ANDROID_image_native_buffer and EGL_KHR_image_base extensions are not supported or if allocation of the buffer fails.

See www.khronos.org/registry/EGL/extensions/ANDROID/EGL_ANDROID_get_native_client_buffer.txt

eglCreateSyncKHR

Added in 1.0.2
fun eglCreateSyncKHR(
    eglDisplay: EGLDisplay,
    type: Int,
    attributes: EGLConfigAttributes?
): EGLSyncKHR?

Creates a sync object of the specified type associated with the specified display, and returns a handle to the new object. The configuration of the returned EGLSyncKHR object is specified by the provided attributes.

Consumers should ensure that the EGL_KHR_fence_sync EGL extension is supported before invoking this method otherwise a null EGLSyncFenceKHR object is returned.

Additionally when the EGLSyncKHR instance is no longer necessary, consumers are encouraged to call eglDestroySyncKHR to deallocate this resource.

See: https://www.khronos.org/registry/EGL/extensions/KHR/EGL_KHR_fence_sync.txt

Parameters
eglDisplay: EGLDisplay

EGLDisplay to associate the sync object with

type: Int

Indicates the type of sync object that is returned

attributes: EGLConfigAttributes?

Specifies the configuration of the sync object returned

Returns
EGLSyncKHR?

the EGLSyncKHR object to be used as a fence or null if this extension is not supported

eglDestroyImageKHR

Added in 1.0.2
fun eglDestroyImageKHR(eglDisplay: EGLDisplay, image: EGLImageKHR): Boolean

Destroy the given EGLImageKHR instance. Once destroyed, the image may not be used to create any additional EGLImageKHR target resources within any client API contexts, although existing EGLImageKHR siblings may continue to be used. True is returned if DestroyImageKHR succeeds, false indicates failure. This can return false if the EGLImageKHR is not associated with the default display.

See: https://www.khronos.org/registry/EGL/extensions/KHR/EGL_KHR_image_base.txt

Parameters
eglDisplay: EGLDisplay

EGLDisplay that this EGLImage is connected to

image: EGLImageKHR

EGLImageKHR to be destroyed

Returns
Boolean

True if the destruction of the EGLImageKHR object was successful, false otherwise

eglDestroySyncKHR

Added in 1.0.2
fun eglDestroySyncKHR(eglDisplay: EGLDisplay, eglSync: EGLSyncKHR): Boolean

Destroys the given sync object associated with the specified display

Consumers should ensure that the EGL_KHR_fence_sync EGL extension is supported before invoking this method otherwise a null EGLSyncFenceKHR object is returned. See: https://www.khronos.org/registry/EGL/extensions/KHR/EGL_KHR_fence_sync.txt

Parameters
eglDisplay: EGLDisplay

EGLDisplay instance associated with the fence

eglSync: EGLSyncKHR

Fence object to be destroyed

Returns
Boolean

true if the EGLSyncKHR object was destroyed successfully false otherwise. This can return false if the sync object is not a valid sync object for the provided display or if the display provided in this method does not match the display used to create this sync in eglCreateSyncKHR.

eglGetSyncAttribKHR

Added in 1.0.2
fun eglGetSyncAttribKHR(
    eglDisplay: EGLDisplay,
    sync: EGLSyncKHR,
    attribute: Int,
    value: IntArray,
    offset: Int
): Boolean

Query attributes of the provided sync object. Accepted attributes to query depend on the type of sync object. If no errors are generated, this returns true and the value of the queried attribute is stored in the value array at the offset position. If this method returns false, the provided value array is unmodified.

See: https://www.khronos.org/registry/EGL/extensions/KHR/EGL_KHR_fence_sync.txt

Parameters
eglDisplay: EGLDisplay

EGLDisplay to associate the sync object with

sync: EGLSyncKHR

EGLSyncKHR object to query attributes

attribute: Int

Corresponding EGLSyncKHR attribute to query on sync

value: IntArray

Integer array used to store the result of the query

offset: Int

Index within the value array to store the result of the attribute query

Returns
Boolean

True if the attribute was queried successfully, false otherwise. Failure cases include attempting to call this method on an invalid sync object, or the display provided not matching the display that was used to create this sync object. Additionally if the queried attribute is not supported for the sync object, false is returned.

glEGLImageTargetTexture2DOES

Added in 1.0.2
fun glEGLImageTargetTexture2DOES(target: Int, image: EGLImageKHR): Unit

Upload a given EGLImage to the currently bound GLTexture

This method requires either of the following EGL extensions to be supported: EGL_KHR_image_base or EGL_KHR_image

See: https://www.khronos.org/registry/OpenGL/extensions/OES/OES_EGL_image_external.txt

parseExtensions

Added in 1.0.2
fun parseExtensions(queryString: String): Set<String>

Returns a set of supported supported extensions from a space separated string that represents the set of OpenGL extensions supported