EGLSpec
public 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 methods |
|
|---|---|
abstract int |
eglClientWaitSyncKHR(Blocks the calling thread until the specified sync object is signalled or until |
abstract @NonNull EGLContext |
eglCreateContext(@NonNull EGLConfig config)Create an EGLContext with the default display. |
abstract EGLImageKHR |
@RequiresApi(value = 26)Creates an EGLImage from the provided |
abstract @NonNull EGLSurface |
eglCreatePBufferSurface(Create a Pixel Buffer surface with the corresponding |
abstract EGLSyncKHR |
eglCreateSyncKHR(int type, EGLConfigAttributes attributes)Creates a sync object of the specified type associated with the specified display, and returns a handle to the new object. |
abstract @NonNull EGLSurface |
eglCreateWindowSurface(Creates an on screen EGL window surface from the given |
abstract void |
eglDestroyContext(@NonNull EGLContext eglContext)Destroy the given EGLContext generated in |
abstract boolean |
eglDestroyImageKHR(@NonNull EGLImageKHR image)Destroy the given |
abstract boolean |
eglDestroySurface(@NonNull EGLSurface surface)Destroys an EGL surface. |
abstract boolean |
eglDestroySyncKHR(@NonNull EGLSyncKHR sync)Destroys the given sync object associated with the specified display |
abstract @NonNull EGLSurface |
Return the current surface used for drawing pixels. |
abstract @NonNull EGLSurface |
Return the current surface used for reading or copying pixels. |
abstract int |
Returns the error of the last called EGL function in the current thread. |
abstract boolean |
eglGetSyncAttribKHR(Query attributes of the provided sync object. |
abstract @NonNull EGLVersion |
Initialize the EGL implementation and return the major and minor version of the EGL implementation through |
abstract boolean |
eglMakeCurrent(Binds the current context to the given draw and read surfaces. |
abstract @NonNull String |
eglQueryString(int nameId)Query for the capabilities associated with the given eglDisplay. |
abstract boolean |
eglQuerySurface(Query the EGL attributes of the provided surface |
abstract boolean |
eglSwapBuffers(@NonNull EGLSurface surface)Post EGL surface color buffer to a native window |
default @NonNull String |
Convenience method to obtain the corresponding error string from the error code obtained from |
default static final @NonNull String |
getStatusString(int error)Return a string representation of the corresponding EGL status code. |
abstract EGLConfig |
loadConfig(@NonNull EGLConfigAttributes configAttributes)Load a corresponding EGLConfig from the provided |
Public methods
eglClientWaitSyncKHR
abstract int eglClientWaitSyncKHR(
@NonNull EGLSyncKHR sync,
int flags,
long timeoutNanos
)
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 | |
|---|---|
@NonNull EGLSyncKHR sync |
EGLSyncKHR object to wait on |
int flags |
Optional flags to provide to handle flushing of pending commands |
long timeoutNanos |
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 |
eglCreateContext
abstract @NonNull EGLContext eglCreateContext(@NonNull EGLConfig config)
Create an EGLContext with the default display. If createContext fails to create a rendering context, EGL_NO_CONTEXT is returned
| Parameters | |
|---|---|
@NonNull EGLConfig config |
|
eglCreateImageFromHardwareBuffer
@RequiresApi(value = 26)
abstract EGLImageKHR eglCreateImageFromHardwareBuffer(@NonNull HardwareBuffer hardwareBuffer)
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 | |
|---|---|
@NonNull HardwareBuffer hardwareBuffer |
Backing |
| Returns | |
|---|---|
EGLImageKHR |
an 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
abstract @NonNull EGLSurface eglCreatePBufferSurface(
@NonNull EGLConfig config,
EGLConfigAttributes configAttributes
)
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 | |
|---|---|
@NonNull EGLConfig config |
Specifies the EGL Frame buffer configuration that defines the frame buffer resource available to the surface |
EGLConfigAttributes configAttributes |
Optional list of attributes for the pixel buffer surface |
eglCreateSyncKHR
abstract EGLSyncKHR eglCreateSyncKHR(int type, EGLConfigAttributes attributes)
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 | |
|---|---|
int type |
Indicates the type of sync object that is returned |
EGLConfigAttributes attributes |
Specifies the configuration of the sync object returned |
| Returns | |
|---|---|
EGLSyncKHR |
the |
eglCreateWindowSurface
abstract @NonNull EGLSurface eglCreateWindowSurface(
@NonNull EGLConfig config,
@NonNull Surface surface,
EGLConfigAttributes configAttributes
)
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 | |
|---|---|
@NonNull EGLConfig config |
Specifies the EGL frame buffer configuration that defines the frame buffer resource available to the surface |
@NonNull Surface surface |
Android surface to consume rendered content |
EGLConfigAttributes configAttributes |
Optional list of attributes for the specified surface |
eglDestroyContext
abstract void eglDestroyContext(@NonNull EGLContext eglContext)
Destroy the given EGLContext generated in eglCreateContext
See https://khronos.org/registry/EGL/sdk/docs/man/html/eglDestroyContext.xhtml
| Parameters | |
|---|---|
@NonNull EGLContext eglContext |
EGL rendering context to be destroyed |
eglDestroyImageKHR
abstract boolean eglDestroyImageKHR(@NonNull EGLImageKHR image)
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 | |
|---|---|
@NonNull EGLImageKHR image |
EGLImageKHR to be destroyed |
| Returns | |
|---|---|
boolean |
|
eglDestroySurface
abstract boolean eglDestroySurface(@NonNull EGLSurface surface)
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 |
|
eglDestroySyncKHR
abstract boolean eglDestroySyncKHR(@NonNull EGLSyncKHR sync)
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 | |
|---|---|
@NonNull EGLSyncKHR sync |
Fence object to be destroyed |
| Returns | |
|---|---|
boolean |
|
eglGetCurrentDrawSurface
abstract @NonNull EGLSurface eglGetCurrentDrawSurface()
Return the current surface used for drawing pixels. If no context is current, EGL14.EGL_NO_SURFACE is returned.
eglGetCurrentReadSurface
abstract @NonNull EGLSurface eglGetCurrentReadSurface()
Return the current surface used for reading or copying pixels. If no context is current, EGL14.EGL_NO_SURFACE is returned
eglGetError
abstract int eglGetError()
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
abstract boolean eglGetSyncAttribKHR(
@NonNull EGLSyncKHR sync,
int attribute,
@NonNull int[] value,
int offset
)
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 | |
|---|---|
@NonNull EGLSyncKHR sync |
EGLSyncKHR object to query attributes |
int attribute |
Corresponding EGLSyncKHR attribute to query on |
@NonNull int[] value |
Integer array used to store the result of the query |
int offset |
Index within the value array to store the result of the attribute query |
| Returns | |
|---|---|
boolean |
|
eglInitialize
abstract @NonNull EGLVersion eglInitialize()
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
abstract boolean eglMakeCurrent(
@NonNull EGLContext context,
@NonNull EGLSurface drawSurface,
@NonNull EGLSurface readSurface
)
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 | |
|---|---|
@NonNull EGLContext context |
EGL rendering context to be attached to the surfaces |
@NonNull EGLSurface drawSurface |
EGLSurface to draw pixels into. |
@NonNull EGLSurface readSurface |
EGLSurface used for read/copy operations. |
eglQueryString
abstract @NonNull String eglQueryString(int nameId)
Query for the capabilities associated with the given eglDisplay. The result contains a space separated list of the capabilities.
| Parameters | |
|---|---|
int nameId |
identifier for the EGL string to query |
eglQuerySurface
abstract boolean eglQuerySurface(
@NonNull EGLSurface surface,
int attribute,
@NonNull int[] result,
int offset
)
Query the EGL attributes of the provided surface
| Parameters | |
|---|---|
@NonNull EGLSurface surface |
EGLSurface to be queried |
int attribute |
EGL attribute to query on the given EGL Surface |
@NonNull int[] result |
Int array to store the result of the query |
int offset |
Index within |
| Returns | |
|---|---|
boolean |
|
eglSwapBuffers
abstract boolean eglSwapBuffers(@NonNull EGLSurface surface)
Post EGL surface color buffer to a native window
See https://khronos.org/registry/EGL/sdk/docs/man/html/eglSwapBuffers.xhtml
| Parameters | |
|---|---|
@NonNull EGLSurface surface |
Specifies the EGL drawing surface whose buffers are to be swapped |
| Returns | |
|---|---|
boolean |
|
getErrorMessage
default @NonNull String getErrorMessage()
Convenience method to obtain the corresponding error string from the error code obtained from EGLSpec.eglGetError
getStatusString
default static final @NonNull String getStatusString(int error)
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
loadConfig
abstract EGLConfig loadConfig(@NonNull EGLConfigAttributes configAttributes)
Load a corresponding EGLConfig from the provided EGLConfigAttributes If the EGLConfig could not be loaded, null is returned
| Parameters | |
|---|---|
@NonNull EGLConfigAttributes configAttributes |
Desired |
| Returns | |
|---|---|
EGLConfig |
the |