# CanvasBufferedRenderer.Builder

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

*** ** * ** ***


```
public final class CanvasBufferedRenderer.Builder
```

<br />

*** ** * ** ***

Builder used to construct a `https://developer.android.com/reference/androidx/graphics/CanvasBufferedRenderer` instance.

## Summary

| ### Public constructors |
|---|
| `https://developer.android.com/reference/androidx/graphics/CanvasBufferedRenderer.Builder#Builder(kotlin.Int,kotlin.Int)(int width, int height)` |

| ### Public methods |
|---|---|
| `final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/graphics/CanvasBufferedRenderer` | `https://developer.android.com/reference/androidx/graphics/CanvasBufferedRenderer.Builder#build()()` Create the `https://developer.android.com/reference/androidx/graphics/CanvasBufferedRenderer` with the specified parameters on this `https://developer.android.com/reference/androidx/graphics/CanvasBufferedRenderer.Builder` instance. |
| `final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/graphics/CanvasBufferedRenderer.Builder` | `https://developer.android.com/reference/androidx/graphics/CanvasBufferedRenderer.Builder#setBufferFormat(kotlin.Int)(int format)` Specify the buffer format of the underlying buffers being rendered into by the created `https://developer.android.com/reference/androidx/graphics/CanvasBufferedRenderer`. |
| `final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/graphics/CanvasBufferedRenderer.Builder` | `https://developer.android.com/reference/androidx/graphics/CanvasBufferedRenderer.Builder#setMaxBuffers(kotlin.Int)(@https://developer.android.com/reference/androidx/annotation/IntRange(from = 1, to = 64) int numBuffers)` Specify the maximum number of buffers used within the swap chain of the `https://developer.android.com/reference/androidx/graphics/CanvasBufferedRenderer`. |
| `final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/graphics/CanvasBufferedRenderer.Builder` | `https://developer.android.com/reference/androidx/graphics/CanvasBufferedRenderer.Builder#setUsageFlags(kotlin.Long)(long usageFlags)` Specify the usage flags to be configured on the underlying `https://developer.android.com/reference/android/hardware/HardwareBuffer.html` instances created by the `https://developer.android.com/reference/androidx/graphics/CanvasBufferedRenderer`. |

## Public constructors

### Builder

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

```
public Builder(int width, int height)
```

| Parameters |
|---|---|
| `int width` | Width of the buffers created by the `https://developer.android.com/reference/androidx/graphics/CanvasBufferedRenderer` instance |
| `int height` | Height of the buffers created by the `https://developer.android.com/reference/androidx/graphics/CanvasBufferedRenderer` instance |

## Public methods

### build

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

```
public final @NonNull CanvasBufferedRenderer build()
```

Create the `https://developer.android.com/reference/androidx/graphics/CanvasBufferedRenderer` with the specified parameters on this `https://developer.android.com/reference/androidx/graphics/CanvasBufferedRenderer.Builder` instance.

| Returns |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/graphics/CanvasBufferedRenderer` | The newly created `https://developer.android.com/reference/androidx/graphics/CanvasBufferedRenderer` instance. |

### setBufferFormat

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

```
public final @NonNull CanvasBufferedRenderer.Builder setBufferFormat(int format)
```

Specify the buffer format of the underlying buffers being rendered into by the created `https://developer.android.com/reference/androidx/graphics/CanvasBufferedRenderer`. The set of valid formats is implementation-specific. 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 `https://developer.android.com/reference/android/hardware/HardwareBuffer.html` configuration using `https://developer.android.com/reference/android/hardware/HardwareBuffer.html#isSupported(int, int, int, int, long)`.

| Parameters |
|---|---|
| `int format` | Pixel format of the buffers to be rendered into. The default is RGBA_8888. Value is one of the following: - `1` - `22` - `43` - `2` - `3` - `4` - `33` - `35` - `48` - `49` - `50` - `51` - `52` - `53` - `54` <br /> |

| Returns |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/graphics/CanvasBufferedRenderer.Builder` | The builder instance |

### setMaxBuffers

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

```
public final @NonNull CanvasBufferedRenderer.Builder setMaxBuffers(@IntRange(from = 1, to = 64) int numBuffers)
```

Specify the maximum number of buffers used within the swap chain of the `https://developer.android.com/reference/androidx/graphics/CanvasBufferedRenderer`. If 1 is specified, then the created `https://developer.android.com/reference/androidx/graphics/CanvasBufferedRenderer` is running in "single buffer mode". In this case consumption of the buffer content would need to be coordinated with the `https://developer.android.com/reference/androidx/hardware/SyncFenceCompat` returned by the callback of `https://developer.android.com/reference/androidx/graphics/CanvasBufferedRenderer.RenderRequest#drawAsync(java.util.concurrent.Executor,androidx.core.util.Consumer)`.

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/IntRange(from = 1, to = 64) int numBuffers` | The number of buffers within the swap chain to be consumed by the created `https://developer.android.com/reference/androidx/graphics/CanvasBufferedRenderer`. This must be greater than zero. The default number of buffers used is 3. |

| Returns |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/graphics/CanvasBufferedRenderer.Builder` | The builder instance |

| See also |
|---|---|
| `https://developer.android.com/reference/androidx/graphics/CanvasBufferedRenderer.RenderRequest#drawAsync(java.util.concurrent.Executor,androidx.core.util.Consumer)` |   |

### setUsageFlags

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

```
public final @NonNull CanvasBufferedRenderer.Builder setUsageFlags(long usageFlags)
```

Specify the usage flags to be configured on the underlying `https://developer.android.com/reference/android/hardware/HardwareBuffer.html` instances created by the `https://developer.android.com/reference/androidx/graphics/CanvasBufferedRenderer`.

| Parameters |
|---|---|
| `long usageFlags` | Usage flags to be configured on the created `https://developer.android.com/reference/android/hardware/HardwareBuffer.html` instances that the `https://developer.android.com/reference/androidx/graphics/CanvasBufferedRenderer` will render into. Must be one of `https://developer.android.com/reference/androidx/hardware/HardwareBufferUsage`. Note that the provided flags here are combined with the following mandatory default flags, `https://developer.android.com/reference/android/hardware/HardwareBuffer.html#USAGE_GPU_SAMPLED_IMAGE`, `https://developer.android.com/reference/android/hardware/HardwareBuffer.html#USAGE_GPU_COLOR_OUTPUT` and `https://developer.android.com/reference/android/hardware/HardwareBuffer.html#USAGE_COMPOSER_OVERLAY` Value is one of the following: - `2` - `3` - `32` - `48` - `256` - `512` - `2048` - `16384` - `65536` - `16777216` - `8388608` - `33554432` - `67108864` - `4294967296` <br /> |

| Returns |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/graphics/CanvasBufferedRenderer.Builder` | The builder instance |