HardwareRenderBuffer

@RequiresApi(value = 29)
class HardwareRenderBuffer(val width: Int, val height: Int, riveWorker: RiveWorker) : CheckableAutoCloseable

GPU-backed offscreen render target for realtime canvas presentation (API 29+).

Use this when you need high-throughput rendering into a hardware-accelerated Canvas without CPU pixel readback. For software pixels, snapshot testing, or CPU-side image workflows, use SoftwareRenderBuffer.

The dimensions of this buffer are fixed at construction and cannot be resized. To render at a different size, create a new buffer.

Ownership/lifecycle:

  • This class owns an ImageReader surface and a callback thread to receive messages from it, and must be closed.

  • It is expected that there is only a single consumer using consumeLatestBitmap.

Performance:

  • render enqueues GPU work and returns; frame publication is asynchronous.

  • Frame publication notifications are exposed via frameAvailable.

Threading:

  • Image acquisition and hardware-buffer wrapping run on a dedicated HandlerThread.

  • render and consumeLatestBitmap are safe to call from the caller thread (typically main).

API level:

  • Requires Android API 29+ for hardware bitmap and usage-flag support.

Parameters

width

Width in pixels.

height

Height in pixels.

riveWorker

Worker used for draw submission.

Throws

if width or height are not > 0.

if hardware rendering is unsupported on this API level.

Constructors

Link copied to clipboard
constructor(width: Int, height: Int, riveWorker: RiveWorker)

Types

Link copied to clipboard
object Companion

Properties

Link copied to clipboard
open override val closed: Boolean

Whether this resource has been closed.

Link copied to clipboard
val frameAvailable: SharedFlow<Unit>

Signal stream for newly published frames.

Link copied to clipboard
val height: Int
Link copied to clipboard

Destination surface used by the worker draw call.

Link copied to clipboard
val width: Int

Functions

Link copied to clipboard
open override fun close()

Closes this resource, releasing any underlying resources.

Link copied to clipboard

Returns the latest published bitmap, or null when no frame has been published yet.

Link copied to clipboard
fun render(artboard: Artboard, stateMachine: StateMachine, fit: Fit = RenderingDefaults.defaultFit(), clearColor: Int = RenderingDefaults.CLEAR_COLOR)

Enqueues rendering into this hardware surface.