GLFrontBufferedRenderer.Callback


interface GLFrontBufferedRenderer.Callback<T : Any?>


Provides callbacks for consumers to draw into the front and multi buffered layers as well as provide opportunities to synchronize SurfaceControlCompat.Transactions to submit the layers to the hardware compositor.

Summary

Public functions

Unit
@WorkerThread
onDrawFrontBufferedLayer(
    eglManager: EGLManager,
    width: Int,
    height: Int,
    bufferInfo: BufferInfo,
    transform: FloatArray,
    param: T
)

Callback invoked to render content into the front buffered layer with the specified parameters.

Unit
@WorkerThread
onDrawMultiBufferedLayer(
    eglManager: EGLManager,
    width: Int,
    height: Int,
    bufferInfo: BufferInfo,
    transform: FloatArray,
    params: Collection<T>
)

Callback invoked to render content into the multi buffered layer with the specified parameters.

open Unit
@WorkerThread
onFrontBufferedLayerRenderComplete(
    frontBufferedLayerSurfaceControl: SurfaceControlCompat,
    transaction: SurfaceControlCompat.Transaction
)

Optional callback invoked when rendering to the front buffered layer is complete but before the buffers are submitted to the hardware compositor.

open Unit
@WorkerThread
onMultiBufferedLayerRenderComplete(
    frontBufferedLayerSurfaceControl: SurfaceControlCompat,
    multiBufferedLayerSurfaceControl: SurfaceControlCompat,
    transaction: SurfaceControlCompat.Transaction
)

Optional callback invoked when rendering to the multi buffered layer is complete but before the buffers are submitted to the hardware compositor.

Public functions

onDrawFrontBufferedLayer

Added in 1.0.2
@WorkerThread
fun onDrawFrontBufferedLayer(
    eglManager: EGLManager,
    width: Int,
    height: Int,
    bufferInfo: BufferInfo,
    transform: FloatArray,
    param: T
): Unit

Callback invoked to render content into the front buffered layer with the specified parameters.

Parameters
eglManager: EGLManager

EGLManager useful in configuring EGL objects to be used when issuing OpenGL commands to render into the front buffered layer

width: Int

Logical width of the content to render. This dimension matches what is provided from SurfaceHolder.Callback.surfaceChanged

height: Int

Logical height of the content to render. This dimension matches what is provided from SurfaceHolder.Callback.surfaceChanged

bufferInfo: BufferInfo

BufferInfo about the buffer that is being rendered into. This includes the width and height of the buffer which can be different than the corresponding dimensions of the SurfaceView provided to the GLFrontBufferedRenderer as pre-rotation can occasionally swap width and height parameters in order to avoid GPU composition to rotate content. This should be used as input to GLES20.glViewport. Additionally this also contains a frame buffer identifier that can be used to retarget rendering operations to the original destination after rendering into intermediate scratch buffers.

transform: FloatArray

Matrix that should be applied to the rendering in this callback. This should be consumed as input to any vertex shader implementations. Buffers are pre-rotated in advance in order to avoid unnecessary overhead of GPU composition to rotate content in the same install orientation of the display. This is a 4 x 4 matrix is represented as a flattened array of 16 floating point values. Consumers are expected to leverage Matrix.multiplyMM with this parameter alongside any additional transformations that are to be applied. For example:

val myMatrix = FloatArray(16)
Matrix.orthoM(
myMatrix, // matrix
0, // offset starting index into myMatrix
0f, // left
bufferInfo.bufferWidth.toFloat(), // right
0f, // bottom
bufferInfo.bufferHeight.toFloat(), // top
-1f, // near
1f, // far
)
val result = FloatArray(16)
Matrix.multiplyMM(result, 0, myMatrix, 0, transform, 0)
param: T

optional parameter provided the corresponding GLFrontBufferedRenderer.renderFrontBufferedLayer method that triggered this request to render into the front buffered layer

onDrawMultiBufferedLayer

@WorkerThread
fun onDrawMultiBufferedLayer(
    eglManager: EGLManager,
    width: Int,
    height: Int,
    bufferInfo: BufferInfo,
    transform: FloatArray,
    params: Collection<T>
): Unit

Callback invoked to render content into the multi buffered layer with the specified parameters.

Parameters
eglManager: EGLManager

EGLManager useful in configuring EGL objects to be used when issuing OpenGL commands to render into the multi buffered layer

width: Int

Logical width of the content to render. This dimension matches what is provided from SurfaceHolder.Callback.surfaceChanged

height: Int

Logical height of the content to render. This dimension matches what is provided from SurfaceHolder.Callback.surfaceChanged

bufferInfo: BufferInfo

BufferInfo about the buffer that is being rendered into. This includes the width and height of the buffer which can be different than the corresponding dimensions of the SurfaceView provided to the GLFrontBufferedRenderer as pre-rotation can occasionally swap width and height parameters in order to avoid GPU composition to rotate content. This should be used as input to GLES20.glViewport. Additionally this also contains a frame buffer identifier that can be used to retarget rendering operations to the original destination after rendering into intermediate scratch buffers.

transform: FloatArray

Matrix that should be applied to the rendering in this callback. This should be consumed as input to any vertex shader implementations. Buffers are pre-rotated in advance in order to avoid unnecessary overhead of GPU composition to rotate content in the same install orientation of the display. This is a 4 x 4 matrix is represented as a flattened array of 16 floating point values. Consumers are expected to leverage Matrix.multiplyMM with this parameter alongside any additional transformations that are to be applied. For example:

val myMatrix = FloatArray(16)
Matrix.orthoM(
myMatrix, // matrix
0, // offset starting index into myMatrix
0f, // left
bufferInfo.bufferWidth.toFloat(), // right
0f, // bottom
bufferInfo.bufferHeight.toFloat(), // top
-1f, // near
1f, // far
)
val result = FloatArray(16)
Matrix.multiplyMM(result, 0, myMatrix, 0, transform, 0)
params: Collection<T>

optional parameter provided to render the entire scene into the multi buffered layer. This is a collection of all parameters provided in consecutive invocations to GLFrontBufferedRenderer.renderFrontBufferedLayer since the last call to GLFrontBufferedRenderer.commit has been made. After GLFrontBufferedRenderer.commit is invoked, this collection is cleared and new parameters are added on each subsequent call to GLFrontBufferedRenderer.renderFrontBufferedLayer.

Consider the following example:

myFrontBufferedRenderer.renderFrontBufferedLayer(1) myFrontBufferedRenderer.renderFrontBufferedLayer(2) myFrontBufferedRenderer.renderFrontBufferedLayer(3) myFrontBufferedRenderer.commit()

This will generate a callback to this method with the params collection containing values 1, 2, 3

myFrontBufferedRenderer.renderFrontBufferedLayer(4) myFrontBufferedRenderer.renderFrontBufferedLayer(5) myFrontBufferedRenderer.commit()

This will generate a callback to this method with the params collection containing values 4, 5

By default GLES20.glViewport is invoked with the correct dimensions of the buffer that is being rendered into taking into account pre-rotation transformations

onFrontBufferedLayerRenderComplete

Added in 1.0.2
@WorkerThread
open fun onFrontBufferedLayerRenderComplete(
    frontBufferedLayerSurfaceControl: SurfaceControlCompat,
    transaction: SurfaceControlCompat.Transaction
): Unit

Optional callback invoked when rendering to the front buffered layer is complete but before the buffers are submitted to the hardware compositor. This provides consumers a mechanism for synchronizing the transaction with other SurfaceControlCompat objects that maybe rendered within the scene.

Parameters
frontBufferedLayerSurfaceControl: SurfaceControlCompat

Handle to the SurfaceControlCompat where the front buffered layer content is drawn. This can be used to configure various properties of the SurfaceControlCompat like z-ordering or visibility with the corresponding SurfaceControlCompat.Transaction.

transaction: SurfaceControlCompat.Transaction

Current SurfaceControlCompat.Transaction to apply updated buffered content to the front buffered layer.

onMultiBufferedLayerRenderComplete

Added in 1.0.2
@WorkerThread
open fun onMultiBufferedLayerRenderComplete(
    frontBufferedLayerSurfaceControl: SurfaceControlCompat,
    multiBufferedLayerSurfaceControl: SurfaceControlCompat,
    transaction: SurfaceControlCompat.Transaction
): Unit

Optional callback invoked when rendering to the multi buffered layer is complete but before the buffers are submitted to the hardware compositor. This provides consumers a mechanism for synchronizing the transaction with other SurfaceControlCompat objects that maybe rendered within the scene.

Parameters
frontBufferedLayerSurfaceControl: SurfaceControlCompat

Handle to the SurfaceControlCompat where the front buffered layer content is drawn. This can be used to configure various properties of the SurfaceControlCompat like z-ordering or visibility with the corresponding SurfaceControlCompat.Transaction.

multiBufferedLayerSurfaceControl: SurfaceControlCompat

Handle to the SurfaceControlCompat where the front buffered layer content is drawn. This can be used to configure various properties of the SurfaceControlCompat like z-ordering or visibility with the corresponding SurfaceControlCompat.Transaction.

transaction: SurfaceControlCompat.Transaction

Current SurfaceControlCompat.Transaction to apply updated buffered content to the multi buffered layer.