CanvasBufferedRenderer.RenderRequest


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 functions

suspend CanvasBufferedRenderer.RenderResult
draw(waitForFence: Boolean)

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

Unit
drawAsync(
    executor: Executor,
    callback: Consumer<CanvasBufferedRenderer.RenderResult>
)

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

CanvasBufferedRenderer.RenderRequest

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

CanvasBufferedRenderer.RenderRequest
setBufferTransform(bufferTransform: Int)

Specifies a transform to be applied before content is rendered.

CanvasBufferedRenderer.RenderRequest
setColorSpace(colorSpace: ColorSpace?)

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

Public functions

draw

suspend fun draw(waitForFence: Boolean = true): CanvasBufferedRenderer.RenderResult

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
waitForFence: Boolean = true

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.0-rc01
fun drawAsync(
    executor: Executor,
    callback: Consumer<CanvasBufferedRenderer.RenderResult>
): Unit

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.0-rc01
fun preserveContents(preserve: Boolean): CanvasBufferedRenderer.RenderRequest

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.0-rc01
fun setBufferTransform(bufferTransform: Int): CanvasBufferedRenderer.RenderRequest

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.0-rc01
fun setColorSpace(colorSpace: ColorSpace?): CanvasBufferedRenderer.RenderRequest

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