interface EGLSpec


Interface for accessing various EGL facilities independent of EGL versions. That is each EGL version implements this specification.

EGLSpec is not thread safe and is up to the caller of these methods to guarantee thread safety.

Summary

Public companion functions

String

Return a string representation of the corresponding EGL status code.

Public companion properties

EGLSpec

Public functions

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

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

EGLContext

Create an EGLContext with the default display.

EGLImageKHR?

Creates an EGLImage from the provided HardwareBuffer.

EGLSurface
eglCreatePBufferSurface(
    config: EGLConfig,
    configAttributes: EGLConfigAttributes?
)

Create a Pixel Buffer surface with the corresponding EGLConfigAttributes.

EGLSyncKHR?
eglCreateSyncKHR(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.

EGLSurface
eglCreateWindowSurface(
    config: EGLConfig,
    surface: Surface,
    configAttributes: EGLConfigAttributes?
)

Creates an on screen EGL window surface from the given Surface and returns a handle to it.

Unit

Destroy the given EGLContext generated in eglCreateContext

Boolean

Destroy the given EGLImageKHR instance.

Boolean

Destroys an EGL surface.

Boolean

Destroys the given sync object associated with the specified display

EGLSurface

Return the current surface used for drawing pixels.

EGLSurface

Return the current surface used for reading or copying pixels.

Int

Returns the error of the last called EGL function in the current thread.

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

Query attributes of the provided sync object.

EGLVersion

Initialize the EGL implementation and return the major and minor version of the EGL implementation through EGLVersion.

Boolean
eglMakeCurrent(
    context: EGLContext,
    drawSurface: EGLSurface,
    readSurface: EGLSurface
)

Binds the current context to the given draw and read surfaces.

String

Query for the capabilities associated with the given eglDisplay.

Boolean
eglQuerySurface(
    surface: EGLSurface,
    attribute: Int,
    result: IntArray,
    offset: Int
)

Query the EGL attributes of the provided surface

Boolean

Post EGL surface color buffer to a native window

open String

Convenience method to obtain the corresponding error string from the error code obtained from EGLSpec.eglGetError

EGLConfig?
loadConfig(configAttributes: EGLConfigAttributes)

Load a corresponding EGLConfig from the provided EGLConfigAttributes If the EGLConfig could not be loaded, null is returned

Public companion functions

getStatusString

Added in 1.0.0-rc01
fun getStatusString(error: Int): String

Return a string representation of the corresponding EGL status code. If the provided error value is not an EGL status code, the hex representation is returned instead

Public companion properties

V14

val V14EGLSpec

Public functions

eglClientWaitSyncKHR

Added in 1.0.0-rc01
fun eglClientWaitSyncKHR(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
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.

eglCreateContext

Added in 1.0.0-rc01
fun eglCreateContext(config: EGLConfig): EGLContext

Create an EGLContext with the default display. If createContext fails to create a rendering context, EGL_NO_CONTEXT is returned

Parameters
config: EGLConfig

EGLConfig used to create the EGLContext

eglCreateImageFromHardwareBuffer

Added in 1.0.0-rc01
@RequiresApi(value = 26)
fun eglCreateImageFromHardwareBuffer(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
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

eglCreatePBufferSurface

Added in 1.0.0-rc01
fun eglCreatePBufferSurface(
    config: EGLConfig,
    configAttributes: EGLConfigAttributes?
): EGLSurface

Create a Pixel Buffer surface with the corresponding EGLConfigAttributes. Accepted attributes are defined as part of the OpenGL specification here: https://www.khronos.org/registry/EGL/sdk/docs/man/html/eglCreatePbufferSurface.xhtml

If a pixel buffer surface could not be created, EGL14.EGL_NO_SURFACE is returned.

Parameters
config: EGLConfig

Specifies the EGL Frame buffer configuration that defines the frame buffer resource available to the surface

configAttributes: EGLConfigAttributes?

Optional list of attributes for the pixel buffer surface

eglCreateSyncKHR

Added in 1.0.0-rc01
fun eglCreateSyncKHR(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.

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
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

eglCreateWindowSurface

Added in 1.0.0-rc01
fun eglCreateWindowSurface(
    config: EGLConfig,
    surface: Surface,
    configAttributes: EGLConfigAttributes?
): EGLSurface

Creates an on screen EGL window surface from the given Surface and returns a handle to it.

See https://khronos.org/registry/EGL/sdk/docs/man/html/eglCreateWindowSurface.xhtml

Parameters
config: EGLConfig

Specifies the EGL frame buffer configuration that defines the frame buffer resource available to the surface

surface: Surface

Android surface to consume rendered content

configAttributes: EGLConfigAttributes?

Optional list of attributes for the specified surface

eglDestroyContext

Added in 1.0.0-rc01
fun eglDestroyContext(eglContext: EGLContext): Unit

Destroy the given EGLContext generated in eglCreateContext

See https://khronos.org/registry/EGL/sdk/docs/man/html/eglDestroyContext.xhtml

Parameters
eglContext: EGLContext

EGL rendering context to be destroyed

eglDestroyImageKHR

Added in 1.0.0-rc01
fun eglDestroyImageKHR(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 corresponding EGLContext is not valid.

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

Parameters
image: EGLImageKHR

EGLImageKHR to be destroyed

Returns
Boolean

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

eglDestroySurface

Added in 1.0.0-rc01
fun eglDestroySurface(surface: EGLSurface): Boolean

Destroys an EGL surface.

If the EGL surface is not current to any thread, eglDestroySurface destroys it immediately. Otherwise, surface is destroyed when it becomes not current to any thread. Furthermore, resources associated with a pbuffer surface are not released until all color buffers of that pbuffer bound to a texture object have been released. Deferral of surface destruction would still return true as deferral does not indicate a failure condition

Returns
Boolean

true if destruction of the EGLSurface was successful, false otherwise

eglDestroySyncKHR

Added in 1.0.0-rc01
fun eglDestroySyncKHR(sync: 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
sync: 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.

eglGetCurrentDrawSurface

Added in 1.0.0-rc01
fun eglGetCurrentDrawSurface(): EGLSurface

Return the current surface used for drawing pixels. If no context is current, EGL14.EGL_NO_SURFACE is returned.

eglGetCurrentReadSurface

Added in 1.0.0-rc01
fun eglGetCurrentReadSurface(): EGLSurface

Return the current surface used for reading or copying pixels. If no context is current, EGL14.EGL_NO_SURFACE is returned

eglGetError

Added in 1.0.0-rc01
fun eglGetError(): Int

Returns the error of the last called EGL function in the current thread. Initially, the error is set to EGL_SUCCESS. When an EGL function could potentially generate several different errors (for example, when passed both a bad attribute name, and a bad attribute value for a legal attribute name), the implementation may choose to generate any one of the applicable errors.

See https://khronos.org/registry/EGL/sdk/docs/man/html/eglGetError.xhtml for more information and error codes that could potentially be returned

eglGetSyncAttribKHR

Added in 1.0.0-rc01
fun eglGetSyncAttribKHR(
    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
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.

eglInitialize

Added in 1.0.0-rc01
fun eglInitialize(): EGLVersion

Initialize the EGL implementation and return the major and minor version of the EGL implementation through EGLVersion. If initialization fails, this returns EGLVersion.Unknown

eglMakeCurrent

Added in 1.0.0-rc01
fun eglMakeCurrent(
    context: EGLContext,
    drawSurface: EGLSurface,
    readSurface: EGLSurface
): Boolean

Binds the current context to the given draw and read surfaces. The draw surface is used for all operations except for any pixel data read back or copy operations which are taken from the read surface.

The same EGLSurface may be specified for both draw and read surfaces.

See https://www.khronos.org/registry/EGL/sdk/docs/man/html/eglMakeCurrent.xhtml for more information

Parameters
drawSurface: EGLSurface

EGLSurface to draw pixels into.

readSurface: EGLSurface

EGLSurface used for read/copy operations.

eglQueryString

Added in 1.0.0-rc01
fun eglQueryString(nameId: Int): String

Query for the capabilities associated with the given eglDisplay. The result contains a space separated list of the capabilities.

Parameters
nameId: Int

identifier for the EGL string to query

eglQuerySurface

Added in 1.0.0-rc01
fun eglQuerySurface(
    surface: EGLSurface,
    attribute: Int,
    result: IntArray,
    offset: Int
): Boolean

Query the EGL attributes of the provided surface

Parameters
surface: EGLSurface

EGLSurface to be queried

attribute: Int

EGL attribute to query on the given EGL Surface

result: IntArray

Int array to store the result of the query

offset: Int

Index within result to store the value of the queried attribute

Returns
Boolean

true if the query was completed successfully, false otherwise. If the query fails, result is unmodified

eglSwapBuffers

Added in 1.0.0-rc01
fun eglSwapBuffers(surface: EGLSurface): Boolean

Post EGL surface color buffer to a native window

See https://khronos.org/registry/EGL/sdk/docs/man/html/eglSwapBuffers.xhtml

Parameters
surface: EGLSurface

Specifies the EGL drawing surface whose buffers are to be swapped

Returns
Boolean

true if swapping of buffers succeeds, false otherwise

getErrorMessage

Added in 1.0.0-rc01
open fun getErrorMessage(): String

Convenience method to obtain the corresponding error string from the error code obtained from EGLSpec.eglGetError

loadConfig

Added in 1.0.0-rc01
fun loadConfig(configAttributes: EGLConfigAttributes): EGLConfig?

Load a corresponding EGLConfig from the provided EGLConfigAttributes If the EGLConfig could not be loaded, null is returned

Parameters
configAttributes: EGLConfigAttributes

Desired EGLConfigAttributes to create an EGLConfig

Returns
EGLConfig?

the EGLConfig with the provided EGLConfigAttributes or null if an EGLConfig could not be created with the specified attributes