# GLFrontBufferedRenderer

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) Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/graphics#1.0.0)

*** ** * ** ***


```
@RequiresApi(value = 29)
class GLFrontBufferedRenderer<T : Any?>
```

<br />

*** ** * ** ***

Class responsible for supporting a "front buffered" rendering system. This allows for lower latency graphics by leveraging a combination of front buffered and multi buffered content layers. Active content is rendered first into the front buffered layer which is simultaneously being presented to the display. Periodically content is rendered into the multi buffered layer which will have more traditional latency guarantees, however, minimize the impact of visual artifacts due to graphical tearing.

## Summary

| ### Nested types |
|---|
| `interface https://developer.android.com/reference/kotlin/androidx/graphics/lowlatency/GLFrontBufferedRenderer.Callback<T : https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html?>` 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. |

| ### Public constructors |
|---|
| `<T : https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html?> https://developer.android.com/reference/kotlin/androidx/graphics/lowlatency/GLFrontBufferedRenderer#GLFrontBufferedRenderer(android.view.SurfaceView,androidx.graphics.lowlatency.GLFrontBufferedRenderer.Callback,androidx.graphics.opengl.GLRenderer,kotlin.Int)( surfaceView: https://developer.android.com/reference/android/view/SurfaceView.html, callback: https://developer.android.com/reference/kotlin/androidx/graphics/lowlatency/GLFrontBufferedRenderer.Callback<T>, glRenderer: https://developer.android.com/reference/kotlin/androidx/graphics/opengl/GLRenderer?, bufferFormat: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html )` |

| ### Public functions |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/graphics/lowlatency/GLFrontBufferedRenderer#cancel()()` Requests to cancel rendering and hides the front buffered layer. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/graphics/lowlatency/GLFrontBufferedRenderer#clear()()` Clears the contents of both the front and multi buffered layers. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/graphics/lowlatency/GLFrontBufferedRenderer#commit()()` Requests to render the entire scene to the multi buffered layer and schedules a call to `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)`. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/graphics/lowlatency/GLFrontBufferedRenderer#execute(java.lang.Runnable)(runnable: https://developer.android.com/reference/java/lang/Runnable.html)` Queue a `https://developer.android.com/reference/java/lang/Runnable.html` to be executed on the GL rendering thread. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/androidx/graphics/lowlatency/GLFrontBufferedRenderer#isValid()()` Determines whether or not the `https://developer.android.com/reference/kotlin/androidx/graphics/lowlatency/GLFrontBufferedRenderer` is in a valid state. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/graphics/lowlatency/GLFrontBufferedRenderer#release(kotlin.Boolean,kotlin.Function0)(cancelPending: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html, onReleaseComplete: (() -> https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html)?)` Releases the `https://developer.android.com/reference/kotlin/androidx/graphics/lowlatency/GLFrontBufferedRenderer` and provides an optional callback that is invoked when the `https://developer.android.com/reference/kotlin/androidx/graphics/lowlatency/GLFrontBufferedRenderer` is fully torn down. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/graphics/lowlatency/GLFrontBufferedRenderer#renderFrontBufferedLayer(kotlin.Any)(param: T)` Render content to the front buffered layer providing optional parameters to be consumed in `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)`. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/graphics/lowlatency/GLFrontBufferedRenderer#renderMultiBufferedLayer(kotlin.collections.Collection)(params: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-collection/index.html<T>)` Requests to render to the multi buffered layer. |

| ### Public properties |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/graphics/lowlatency/GLFrontBufferedRenderer#bufferFormat()` format of the underlying buffers being rendered into by `https://developer.android.com/reference/kotlin/androidx/graphics/lowlatency/GLFrontBufferedRenderer`. |

## Public constructors

### GLFrontBufferedRenderer

```
<T : Any?> GLFrontBufferedRenderer(
    surfaceView: SurfaceView,
    callback: GLFrontBufferedRenderer.Callback<T>,
    glRenderer: GLRenderer? = null,
    bufferFormat: Int = HardwareBuffer.RGBA_8888
)
```

| Parameters |
|---|---|
| `surfaceView: https://developer.android.com/reference/android/view/SurfaceView.html` | Target SurfaceView to act as the parent rendering layer for multi buffered content |
| `callback: https://developer.android.com/reference/kotlin/androidx/graphics/lowlatency/GLFrontBufferedRenderer.Callback<T>` | Callbacks used to render into front and multi buffered layers as well as configuring `https://developer.android.com/reference/kotlin/androidx/graphics/surface/SurfaceControlCompat.Transaction`s for controlling these layers in addition to other `https://developer.android.com/reference/kotlin/androidx/graphics/surface/SurfaceControlCompat` instances that must be updated atomically within the user interface. These callbacks are invoked on the backing GL Thread. |
| `glRenderer: https://developer.android.com/reference/kotlin/androidx/graphics/opengl/GLRenderer? = null` | Optional `https://developer.android.com/reference/kotlin/androidx/graphics/opengl/GLRenderer` instance that this `https://developer.android.com/reference/kotlin/androidx/graphics/lowlatency/GLFrontBufferedRenderer` should use for coordinating requests to render content. If this parameter is specified, the caller of this API is responsible for releasing resources on `https://developer.android.com/reference/kotlin/androidx/graphics/opengl/GLRenderer` by calling `https://developer.android.com/reference/kotlin/androidx/graphics/opengl/GLRenderer#stop(kotlin.Boolean,kotlin.Function1)`. Otherwise `https://developer.android.com/reference/kotlin/androidx/graphics/lowlatency/GLFrontBufferedRenderer` will create and manage its own `https://developer.android.com/reference/kotlin/androidx/graphics/opengl/GLRenderer` internally and will automatically release its resources within `https://developer.android.com/reference/kotlin/androidx/graphics/lowlatency/GLFrontBufferedRenderer#release(kotlin.Boolean,kotlin.Function0)` |
| `bufferFormat: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html = HardwareBuffer.RGBA_8888` | format of the underlying buffers being rendered into by `https://developer.android.com/reference/kotlin/androidx/graphics/lowlatency/GLFrontBufferedRenderer`. The set of valid formats is implementation-specific and may depend on additional EGL extensions. The particular valid combinations for a given Android version and implementation should be documented by that version. `https://developer.android.com/reference/android/hardware/HardwareBuffer.html#RGBA_8888` and `https://developer.android.com/reference/android/hardware/HardwareBuffer.html#RGBX_8888` are guaranteed to be supported. However, consumers are recommended to query the desired HardwareBuffer configuration using `https://developer.android.com/reference/android/hardware/HardwareBuffer.html#isSupported(int, int, int, int, long)`. The default is `https://developer.android.com/reference/android/hardware/HardwareBuffer.html#RGBA_8888`. See: khronos.org/registry/EGL/extensions/ANDROID/EGL_ANDROID_get_native_client_buffer.txt and https://developer.android.com/reference/android/hardware/HardwareBuffer Value is one of the following: - `1` - `22` - `43` - `2` - `3` - `4` - `33` - `35` - `48` - `49` - `50` - `51` - `52` - `53` - `54` <br /> |

## Public functions

### cancel

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

```
fun cancel(): Unit
```

Requests to cancel rendering and hides the front buffered layer. Unlike `https://developer.android.com/reference/kotlin/androidx/graphics/lowlatency/GLFrontBufferedRenderer#commit()`, this does not schedule a call to render into the multi buffered layer.

If this `https://developer.android.com/reference/kotlin/androidx/graphics/lowlatency/GLFrontBufferedRenderer` has been released, that is `https://developer.android.com/reference/kotlin/androidx/graphics/lowlatency/GLFrontBufferedRenderer#isValid()` returns `false`, this call is ignored.

### clear

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

```
fun clear(): Unit
```

Clears the contents of both the front and multi buffered layers. This triggers a call to `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)` and hides the front buffered layer.

### commit

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

```
fun commit(): Unit
```

Requests to render the entire scene to the multi buffered layer and schedules a call to `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)`. The parameters provided to `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)` will include each argument provided to every `https://developer.android.com/reference/kotlin/androidx/graphics/lowlatency/GLFrontBufferedRenderer#renderFrontBufferedLayer(kotlin.Any)` call since the last call to `https://developer.android.com/reference/kotlin/androidx/graphics/lowlatency/GLFrontBufferedRenderer#commit()` has been made.

If this `https://developer.android.com/reference/kotlin/androidx/graphics/lowlatency/GLFrontBufferedRenderer` has been released, that is `https://developer.android.com/reference/kotlin/androidx/graphics/lowlatency/GLFrontBufferedRenderer#isValid()` returns `false`, this call is ignored.

### execute

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

```
fun execute(runnable: Runnable): Unit
```

Queue a `https://developer.android.com/reference/java/lang/Runnable.html` to be executed on the GL rendering thread. Note it is important this `https://developer.android.com/reference/java/lang/Runnable.html` does not block otherwise it can stall the GL thread.

| Parameters |
|---|---|
| `runnable: https://developer.android.com/reference/java/lang/Runnable.html` | to be executed |

### isValid

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

```
fun isValid(): Boolean
```

Determines whether or not the `https://developer.android.com/reference/kotlin/androidx/graphics/lowlatency/GLFrontBufferedRenderer` is in a valid state. That is the `https://developer.android.com/reference/kotlin/androidx/graphics/lowlatency/GLFrontBufferedRenderer#release(kotlin.Boolean,kotlin.Function0)` method has not been called. If this returns false, then subsequent calls to `https://developer.android.com/reference/kotlin/androidx/graphics/lowlatency/GLFrontBufferedRenderer#renderFrontBufferedLayer(kotlin.Any)`, `https://developer.android.com/reference/kotlin/androidx/graphics/lowlatency/GLFrontBufferedRenderer#commit()`, and `https://developer.android.com/reference/kotlin/androidx/graphics/lowlatency/GLFrontBufferedRenderer#release(kotlin.Boolean,kotlin.Function0)` are ignored

| Returns |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `true` if this `https://developer.android.com/reference/kotlin/androidx/graphics/lowlatency/GLFrontBufferedRenderer` has been released, `false` otherwise |

### release

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

```
fun release(cancelPending: Boolean, onReleaseComplete: (() -> Unit)? = null): Unit
```

Releases the `https://developer.android.com/reference/kotlin/androidx/graphics/lowlatency/GLFrontBufferedRenderer` and provides an optional callback that is invoked when the `https://developer.android.com/reference/kotlin/androidx/graphics/lowlatency/GLFrontBufferedRenderer` is fully torn down. If the `https://developer.android.com/reference/kotlin/androidx/graphics/lowlatency/GLFrontBufferedRenderer#release(kotlin.Boolean,kotlin.Function0)` flag is false, all pending requests to render into the front or multi buffered layers will be processed before the `https://developer.android.com/reference/kotlin/androidx/graphics/lowlatency/GLFrontBufferedRenderer` is torn down. Otherwise, all in progress requests are ignored. If the `https://developer.android.com/reference/kotlin/androidx/graphics/lowlatency/GLFrontBufferedRenderer` is already released, that is `https://developer.android.com/reference/kotlin/androidx/graphics/lowlatency/GLFrontBufferedRenderer#isValid()` returns `false`, this method does nothing.

| Parameters |
|---|---|
| `cancelPending: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | If true, pending render requests are cancelled immediately. If false, pending render requests are completed before releasing the renderer. |
| `onReleaseComplete: (() -> https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html)? = null` | Optional callback invoked when the `https://developer.android.com/reference/kotlin/androidx/graphics/lowlatency/GLFrontBufferedRenderer` has been released. This callback is invoked on the backing GLThread |

### renderFrontBufferedLayer

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

```
fun renderFrontBufferedLayer(param: T): Unit
```

Render content to the front buffered layer providing optional parameters to be consumed in `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)`. Additionally the parameter provided here will also be consumed in `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)` when the corresponding `https://developer.android.com/reference/kotlin/androidx/graphics/lowlatency/GLFrontBufferedRenderer#commit()` method is invoked, which will include all `https://developer.android.com/reference/kotlin/androidx/graphics/lowlatency/GLFrontBufferedRenderer#renderFrontBufferedLayer(kotlin.Any)`s in each call made to this method up to the corresponding `https://developer.android.com/reference/kotlin/androidx/graphics/lowlatency/GLFrontBufferedRenderer#commit()` call.

If this `https://developer.android.com/reference/kotlin/androidx/graphics/lowlatency/GLFrontBufferedRenderer` has been released, that is `https://developer.android.com/reference/kotlin/androidx/graphics/lowlatency/GLFrontBufferedRenderer#isValid()` returns `false`, this call is ignored.

| Parameters |
|---|---|
| `param: T` | Optional parameter to be consumed when rendering content into the commit layer |

### renderMultiBufferedLayer

```
fun renderMultiBufferedLayer(params: Collection<T>): Unit
```

Requests to render to the multi buffered layer. This schedules a call to `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)` with the parameters provided. If the front buffered layer is visible, this will hide this layer after rendering to the multi buffered layer is complete. This is equivalent to calling `https://developer.android.com/reference/kotlin/androidx/graphics/lowlatency/GLFrontBufferedRenderer#renderFrontBufferedLayer(kotlin.Any)` for each parameter provided in the collection followed by a single call to `https://developer.android.com/reference/kotlin/androidx/graphics/lowlatency/GLFrontBufferedRenderer#commit()`. This is useful for re-rendering the multi buffered scene when the corresponding Activity is being resumed from the background in which the contents should be re-drawn. Additionally this allows for applications to decide to dynamically render to either front or multi buffered layers.

If this `https://developer.android.com/reference/kotlin/androidx/graphics/lowlatency/GLFrontBufferedRenderer` has been released, that is `https://developer.android.com/reference/kotlin/androidx/graphics/lowlatency/GLFrontBufferedRenderer#isValid()` returns 'false', this call is ignored.

| Parameters |
|---|---|
| `params: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-collection/index.html<T>` | Parameters that to be consumed when rendering to the multi buffered layer. These parameters will be provided in the corresponding call to `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)` |

## Public properties

### bufferFormat

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

```
val bufferFormat: Int
```

format of the underlying buffers being rendered into by `https://developer.android.com/reference/kotlin/androidx/graphics/lowlatency/GLFrontBufferedRenderer`. The set of valid formats is implementation-specific and may depend on additional EGL extensions. The particular valid combinations for a given Android version and implementation should be documented by that version. `https://developer.android.com/reference/android/hardware/HardwareBuffer.html#RGBA_8888` and `https://developer.android.com/reference/android/hardware/HardwareBuffer.html#RGBX_8888` are guaranteed to be supported. However, consumers are recommended to query the desired HardwareBuffer configuration using `https://developer.android.com/reference/android/hardware/HardwareBuffer.html#isSupported(int, int, int, int, long)`. The default is `https://developer.android.com/reference/android/hardware/HardwareBuffer.html#RGBA_8888`.

See: khronos.org/registry/EGL/extensions/ANDROID/EGL_ANDROID_get_native_client_buffer.txt and https://developer.android.com/reference/android/hardware/HardwareBuffer

Value is one of the following:

- `1`
- `22`
- `43`
- `2`
- `3`
- `4`
- `33`
- `35`
- `48`
- `49`
- `50`
- `51`
- `52`
- `53`
- `54`

<br />