CanvasBufferedRenderer.Builder


public final class CanvasBufferedRenderer.Builder


Builder used to construct a CanvasBufferedRenderer instance.

Summary

Public constructors

Builder(int width, int height)

Public methods

final @NonNull CanvasBufferedRenderer

Create the CanvasBufferedRenderer with the specified parameters on this Builder instance.

final @NonNull CanvasBufferedRenderer.Builder
setBufferFormat(int format)

Specify the buffer format of the underlying buffers being rendered into by the created CanvasBufferedRenderer.

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 CanvasBufferedRenderer.

final @NonNull CanvasBufferedRenderer.Builder
setUsageFlags(long usageFlags)

Specify the usage flags to be configured on the underlying HardwareBuffer instances created by the CanvasBufferedRenderer.

Public constructors

Builder

Added in 1.0.0-rc01
public Builder(int width, int height)
Parameters
int width

Width of the buffers created by the CanvasBufferedRenderer instance

int height

Height of the buffers created by the CanvasBufferedRenderer instance

Public methods

build

Added in 1.0.0-rc01
public final @NonNull CanvasBufferedRenderer build()

Create the CanvasBufferedRenderer with the specified parameters on this Builder instance.

Returns
@NonNull CanvasBufferedRenderer

The newly created CanvasBufferedRenderer instance.

setBufferFormat

Added in 1.0.0-rc01
public final @NonNull CanvasBufferedRenderer.Builder setBufferFormat(int format)

Specify the buffer format of the underlying buffers being rendered into by the created 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.

HardwareBuffer.RGBA_8888 and HardwareBuffer.RGBX_8888 are guaranteed to be supported. However, consumers are recommended to query the desired HardwareBuffer configuration using HardwareBuffer.isSupported.

Parameters
int format

Pixel format of the buffers to be rendered into. The default is RGBA_8888.

Returns
@NonNull CanvasBufferedRenderer.Builder

The builder instance

setMaxBuffers

Added in 1.0.0-rc01
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 CanvasBufferedRenderer. If 1 is specified, then the created CanvasBufferedRenderer is running in "single buffer mode". In this case consumption of the buffer content would need to be coordinated with the SyncFenceCompat returned by the callback of RenderRequest.drawAsync.

Parameters
@IntRange(from = 1, to = 64) int numBuffers

The number of buffers within the swap chain to be consumed by the created CanvasBufferedRenderer. This must be greater than zero. The default number of buffers used is 3.

Returns
@NonNull CanvasBufferedRenderer.Builder

The builder instance

See also
drawAsync

setUsageFlags

Added in 1.0.0-rc01
public final @NonNull CanvasBufferedRenderer.Builder setUsageFlags(long usageFlags)

Specify the usage flags to be configured on the underlying HardwareBuffer instances created by the CanvasBufferedRenderer.

Parameters
long usageFlags

Usage flags to be configured on the created HardwareBuffer instances that the CanvasBufferedRenderer will render into. Must be one of HardwareBufferUsage. Note that the provided flags here are combined with the following mandatory default flags, HardwareBuffer.USAGE_GPU_SAMPLED_IMAGE, HardwareBuffer.USAGE_GPU_COLOR_OUTPUT and HardwareBuffer.USAGE_COMPOSER_OVERLAY

Returns
@NonNull CanvasBufferedRenderer.Builder

The builder instance