-
- All Implemented Interfaces:
-
app.rive.core.CheckableAutoCloseable,java.lang.AutoCloseable
@RequiresApi(value = 29) public final class HardwareRenderBuffer implements 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.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description public classHardwareRenderBuffer.Companion
-
Field Summary
Fields Modifier and Type Field Description private final SharedFlow<Unit>frameAvailableprivate final RiveSurfacesurfaceprivate final Booleanclosedprivate final Integerwidthprivate final Integerheight
-
Constructor Summary
Constructors Constructor Description HardwareRenderBuffer(Integer width, Integer height, CommandQueue riveWorker)
-
Method Summary
Modifier and Type Method Description final SharedFlow<Unit>getFrameAvailable()Signal stream for newly published frames. final RiveSurfacegetSurface()Destination surface used by the worker draw call. BooleangetClosed()final IntegergetWidth()final IntegergetHeight()Unitclose()Closes this buffer and its owned render surface. final Unitrender(Artboard artboard, StateMachine stateMachine, Fit fit, Integer clearColor)Enqueues rendering into this hardware surface. final BitmapconsumeLatestBitmap()Returns the latest published bitmap, or null when no frame has been published yet. -
-
Constructor Detail
-
HardwareRenderBuffer
HardwareRenderBuffer(Integer width, Integer height, CommandQueue riveWorker)
- Parameters:
width- Width in pixels.height- Height in pixels.riveWorker- Worker used for draw submission.
-
-
Method Detail
-
getFrameAvailable
final SharedFlow<Unit> getFrameAvailable()
Signal stream for newly published frames.
Collect this flow to know when consumeLatestBitmap should be called.
-
getSurface
final RiveSurface getSurface()
Destination surface used by the worker draw call.
-
render
final Unit render(Artboard artboard, StateMachine stateMachine, Fit fit, Integer clearColor)
Enqueues rendering into this hardware surface.
The first call waits (bounded) for initial frame publication to keep startup deterministic.
-
consumeLatestBitmap
final Bitmap consumeLatestBitmap()
Returns the latest published bitmap, or null when no frame has been published yet.
This is a consume/swap API: when a newer frame exists, prior consumed bitmaps may be superseded and recycled.
-
-
-
-