CanvasBufferedRenderer.RenderRequest


public final inner class CanvasBufferedRenderer.RenderRequest


Sets the parameters that can be used to control a render request for a CanvasBufferedRenderer. This is not thread-safe and must not be held on to for longer than a single request.

Summary

Public methods

final @NonNull CanvasBufferedRenderer.RenderResult
draw(boolean waitForFence)

Syncs the RenderNode tree to the render thread and requests content to be drawn synchronously.

final void

Syncs the RenderNode tree to the render thread and requests content to be drawn.

final @NonNull CanvasBufferedRenderer.RenderRequest
preserveContents(boolean preserve)

Determines whether or not previous buffer contents will be persisted across render requests.

final @NonNull CanvasBufferedRenderer.RenderRequest
setBufferTransform(int bufferTransform)

Specifies a transform to be applied before content is rendered.

final @NonNull CanvasBufferedRenderer.RenderRequest

Configures the color space which the content should be rendered in.

Public methods

draw

public final @NonNull CanvasBufferedRenderer.RenderResult draw(boolean waitForFence)

Syncs the RenderNode tree to the render thread and requests content to be drawn synchronously. This RenderRequest instance should no longer be used after calling this method. The system internally may reuse instances of RenderRequest to reduce allocation churn.

Parameters
boolean waitForFence

Optional flag to determine if the SyncFenceCompat is also waited upon before returning as a convenience in order to enable callers to consume the HardwareBuffer returned in the RenderResult immediately after this method returns. Passing false here on Android T and below is a no-op as the graphics rendering pipeline internally blocks on the fence before returning.

drawAsync

Added in 1.0.2
public final void drawAsync(
    @NonNull Executor executor,
    @NonNull Consumer<@NonNull CanvasBufferedRenderer.RenderResult> callback
)

Syncs the RenderNode tree to the render thread and requests content to be drawn. This RenderRequest instance should no longer be used after calling this method. The system internally may reuse instances of RenderRequest to reduce allocation churn.

Throws
kotlin.IllegalStateException

if this method is invoked after the CanvasBufferedRenderer has been closed.

preserveContents

Added in 1.0.2
public final @NonNull CanvasBufferedRenderer.RenderRequest preserveContents(boolean preserve)

Determines whether or not previous buffer contents will be persisted across render requests. If false then contents are cleared before issuing drawing instructions, otherwise contents will remain.

If contents are known in advance to be completely opaque and cover all pixels within the buffer, setting this flag to true will slightly improve performance as the clear operation will be skipped.

For low latency use cases (ex applications that support drawing with a stylus), setting this value to true alongside single buffered rendering by configuring CanvasBufferedRenderer.Builder.setMaxBuffers to 1 allows for reduced latency by allowing consumers to only render the deltas across frames as the previous content would be persisted.

The default setting is false.

setBufferTransform

Added in 1.0.2
public final @NonNull CanvasBufferedRenderer.RenderRequest setBufferTransform(int bufferTransform)

Specifies a transform to be applied before content is rendered. This is useful for pre-rotating content for the current display orientation to increase performance of displaying the associated buffer. This transformation will also adjust the light source position for the specified rotation.

See also
SurfaceControl.Transaction

#setBufferTransform(SurfaceControl, int)

setColorSpace

Added in 1.0.2
public final @NonNull CanvasBufferedRenderer.RenderRequest setColorSpace(ColorSpace colorSpace)

Configures the color space which the content should be rendered in. This affects how the framework will interpret the color at each pixel. The color space provided here must be non-null, RGB based and leverage an ICC parametric curve. The min/max values of the components should not reduce the numerical range compared to the previously assigned color space. If left unspecified, the default color space of SRGB will be used.

NOTE this method is only supported on Android U and above and is ignored on older Android versions