# GLFrontBufferedRenderer.Callback

Artifact: [androidx.graphics:graphics-core](https://developer.android.com/jetpack/androidx/releases/graphics) [View Source](https://cs.android.com/search?q=file:androidx/graphics/lowlatency/GLFrontBufferedRenderer.kt+class:androidx.graphics.lowlatency.GLFrontBufferedRenderer.Callback) Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/graphics#1.0.0)

*** ** * ** ***


```
interface GLFrontBufferedRenderer.Callback<T : Any?>
```

<br />

*** ** * ** ***

Provides callbacks for consumers to draw into the front and multi buffered layers as well as provide opportunities to synchronize `https://developer.android.com/reference/kotlin/androidx/graphics/surface/SurfaceControlCompat.Transaction`s to submit the layers to the hardware compositor.

## Summary

| ### Public functions |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `@https://developer.android.com/reference/kotlin/androidx/annotation/WorkerThread https://developer.android.com/reference/kotlin/androidx/graphics/lowlatency/GLFrontBufferedRenderer.Callback#onDrawFrontBufferedLayer(androidx.graphics.opengl.egl.EGLManager,kotlin.Int,kotlin.Int,androidx.graphics.lowlatency.BufferInfo,kotlin.FloatArray,kotlin.Any)( eglManager: https://developer.android.com/reference/kotlin/androidx/graphics/opengl/egl/EGLManager, width: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, height: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, bufferInfo: https://developer.android.com/reference/kotlin/androidx/graphics/lowlatency/BufferInfo, transform: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float-array/index.html, param: T )` Callback invoked to render content into the front buffered layer with the specified parameters. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `@https://developer.android.com/reference/kotlin/androidx/annotation/WorkerThread https://developer.android.com/reference/kotlin/androidx/graphics/lowlatency/GLFrontBufferedRenderer.Callback#onDrawMultiBufferedLayer(androidx.graphics.opengl.egl.EGLManager,kotlin.Int,kotlin.Int,androidx.graphics.lowlatency.BufferInfo,kotlin.FloatArray,kotlin.collections.Collection)( eglManager: https://developer.android.com/reference/kotlin/androidx/graphics/opengl/egl/EGLManager, width: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, height: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, bufferInfo: https://developer.android.com/reference/kotlin/androidx/graphics/lowlatency/BufferInfo, transform: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float-array/index.html, params: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-collection/index.html<T> )` Callback invoked to render content into the multi buffered layer with the specified parameters. |
| `open https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `@https://developer.android.com/reference/kotlin/androidx/annotation/WorkerThread https://developer.android.com/reference/kotlin/androidx/graphics/lowlatency/GLFrontBufferedRenderer.Callback#onFrontBufferedLayerRenderComplete(androidx.graphics.surface.SurfaceControlCompat,androidx.graphics.surface.SurfaceControlCompat.Transaction)( frontBufferedLayerSurfaceControl: https://developer.android.com/reference/kotlin/androidx/graphics/surface/SurfaceControlCompat, transaction: https://developer.android.com/reference/kotlin/androidx/graphics/surface/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 https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `@https://developer.android.com/reference/kotlin/androidx/annotation/WorkerThread https://developer.android.com/reference/kotlin/androidx/graphics/lowlatency/GLFrontBufferedRenderer.Callback#onMultiBufferedLayerRenderComplete(androidx.graphics.surface.SurfaceControlCompat,androidx.graphics.surface.SurfaceControlCompat,androidx.graphics.surface.SurfaceControlCompat.Transaction)( frontBufferedLayerSurfaceControl: https://developer.android.com/reference/kotlin/androidx/graphics/surface/SurfaceControlCompat, multiBufferedLayerSurfaceControl: https://developer.android.com/reference/kotlin/androidx/graphics/surface/SurfaceControlCompat, transaction: https://developer.android.com/reference/kotlin/androidx/graphics/surface/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.0](https://developer.android.com/jetpack/androidx/releases/graphics#1.0.0)

```
@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: https://developer.android.com/reference/kotlin/androidx/graphics/opengl/egl/EGLManager` | `https://developer.android.com/reference/kotlin/androidx/graphics/opengl/egl/EGLManager` useful in configuring EGL objects to be used when issuing OpenGL commands to render into the front buffered layer |
| `width: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | Logical width of the content to render. This dimension matches what is provided from `https://developer.android.com/reference/android/view/SurfaceHolder.Callback.html#surfaceChanged(android.view.SurfaceHolder, int, int, int)` |
| `height: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | Logical height of the content to render. This dimension matches what is provided from `https://developer.android.com/reference/android/view/SurfaceHolder.Callback.html#surfaceChanged(android.view.SurfaceHolder, int, int, int)` |
| `bufferInfo: https://developer.android.com/reference/kotlin/androidx/graphics/lowlatency/BufferInfo` | `https://developer.android.com/reference/kotlin/androidx/graphics/lowlatency/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 `https://developer.android.com/reference/android/view/SurfaceView.html` provided to the `https://developer.android.com/reference/kotlin/androidx/graphics/lowlatency/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 `https://developer.android.com/reference/android/opengl/GLES20.html#glViewport(int, int, int, int)`. 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: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float-array/index.html` | 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 `https://developer.android.com/reference/android/opengl/Matrix.html#multiplyMM(float[], int, float[], int, float[], int)` with this parameter alongside any additional transformations that are to be applied. For example: ```kotlin 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 `https://developer.android.com/reference/kotlin/androidx/graphics/lowlatency/GLFrontBufferedRenderer#renderFrontBufferedLayer(kotlin.Any)` 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: https://developer.android.com/reference/kotlin/androidx/graphics/opengl/egl/EGLManager` | `https://developer.android.com/reference/kotlin/androidx/graphics/opengl/egl/EGLManager` useful in configuring EGL objects to be used when issuing OpenGL commands to render into the multi buffered layer |
| `width: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | Logical width of the content to render. This dimension matches what is provided from `https://developer.android.com/reference/android/view/SurfaceHolder.Callback.html#surfaceChanged(android.view.SurfaceHolder, int, int, int)` |
| `height: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | Logical height of the content to render. This dimension matches what is provided from `https://developer.android.com/reference/android/view/SurfaceHolder.Callback.html#surfaceChanged(android.view.SurfaceHolder, int, int, int)` |
| `bufferInfo: https://developer.android.com/reference/kotlin/androidx/graphics/lowlatency/BufferInfo` | `https://developer.android.com/reference/kotlin/androidx/graphics/lowlatency/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 `https://developer.android.com/reference/android/view/SurfaceView.html` provided to the `https://developer.android.com/reference/kotlin/androidx/graphics/lowlatency/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 `https://developer.android.com/reference/android/opengl/GLES20.html#glViewport(int, int, int, int)`. 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: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float-array/index.html` | 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 `https://developer.android.com/reference/android/opengl/Matrix.html#multiplyMM(float[], int, float[], int, float[], int)` with this parameter alongside any additional transformations that are to be applied. For example: ```kotlin 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: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-collection/index.html<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 `https://developer.android.com/reference/kotlin/androidx/graphics/lowlatency/GLFrontBufferedRenderer#renderFrontBufferedLayer(kotlin.Any)` since the last call to `https://developer.android.com/reference/kotlin/androidx/graphics/lowlatency/GLFrontBufferedRenderer#commit()` has been made. After `https://developer.android.com/reference/kotlin/androidx/graphics/lowlatency/GLFrontBufferedRenderer#commit()` is invoked, this collection is cleared and new parameters are added on each subsequent call to `https://developer.android.com/reference/kotlin/androidx/graphics/lowlatency/GLFrontBufferedRenderer#renderFrontBufferedLayer(kotlin.Any)`. 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 `https://developer.android.com/reference/android/opengl/GLES20.html#glViewport(int, int, int, int)` 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.0](https://developer.android.com/jetpack/androidx/releases/graphics#1.0.0)

```
@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 `https://developer.android.com/reference/kotlin/androidx/graphics/surface/SurfaceControlCompat` objects that maybe rendered within the scene.

| Parameters |
|---|---|
| `frontBufferedLayerSurfaceControl: https://developer.android.com/reference/kotlin/androidx/graphics/surface/SurfaceControlCompat` | Handle to the `https://developer.android.com/reference/kotlin/androidx/graphics/surface/SurfaceControlCompat` where the front buffered layer content is drawn. This can be used to configure various properties of the `https://developer.android.com/reference/kotlin/androidx/graphics/surface/SurfaceControlCompat` like z-ordering or visibility with the corresponding `https://developer.android.com/reference/kotlin/androidx/graphics/surface/SurfaceControlCompat.Transaction`. |
| `transaction: https://developer.android.com/reference/kotlin/androidx/graphics/surface/SurfaceControlCompat.Transaction` | Current `https://developer.android.com/reference/kotlin/androidx/graphics/surface/SurfaceControlCompat.Transaction` to apply updated buffered content to the front buffered layer. |

### onMultiBufferedLayerRenderComplete

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/graphics#1.0.0)

```
@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 `https://developer.android.com/reference/kotlin/androidx/graphics/surface/SurfaceControlCompat` objects that maybe rendered within the scene.

| Parameters |
|---|---|
| `frontBufferedLayerSurfaceControl: https://developer.android.com/reference/kotlin/androidx/graphics/surface/SurfaceControlCompat` | Handle to the `https://developer.android.com/reference/kotlin/androidx/graphics/surface/SurfaceControlCompat` where the front buffered layer content is drawn. This can be used to configure various properties of the `https://developer.android.com/reference/kotlin/androidx/graphics/surface/SurfaceControlCompat` like z-ordering or visibility with the corresponding `https://developer.android.com/reference/kotlin/androidx/graphics/surface/SurfaceControlCompat.Transaction`. |
| `multiBufferedLayerSurfaceControl: https://developer.android.com/reference/kotlin/androidx/graphics/surface/SurfaceControlCompat` | Handle to the `https://developer.android.com/reference/kotlin/androidx/graphics/surface/SurfaceControlCompat` where the front buffered layer content is drawn. This can be used to configure various properties of the `https://developer.android.com/reference/kotlin/androidx/graphics/surface/SurfaceControlCompat` like z-ordering or visibility with the corresponding `https://developer.android.com/reference/kotlin/androidx/graphics/surface/SurfaceControlCompat.Transaction`. |
| `transaction: https://developer.android.com/reference/kotlin/androidx/graphics/surface/SurfaceControlCompat.Transaction` | Current `https://developer.android.com/reference/kotlin/androidx/graphics/surface/SurfaceControlCompat.Transaction` to apply updated buffered content to the multi buffered layer. |