paint method
Draws the current frame into canvas (ports ForGodot's
_drawAnimation). Gathers the FlatBuffers FrameData + SoA views into one
DrawFrame, hands frame placement to the RenderBackend (which centers the
animation's world origin in dst), then dispatches each DrawBatch on its
kind to the backend.
The batch loop, mask pre-pass planning and instance recursion stay here
(backend-agnostic control flow); only the pixel operations go to the
backend. Nines / Text are pre-cut seams and not drawn. Fitting into dst
is not done here: it arrives already solved, in rootTransform.
Call this at most once per frame per player. The hooks below recycle resources that stay live until the recorded picture rasterises, and this is the only place they run — so painting one player into two adapters (two SpriteStudioViews, a view plus a Flame component) within a single frame makes the second call free and rebind what the first call's already-recorded draws still point at: a disposed coverage bitmap, or a pooled shader whose uniforms are overwritten before it rasterises. The visible result is the wrong mask or tint in the first view, or "Image has been disposed". Give each view its own player: players of one pack share its parse and its decoded atlases, so another one costs little more than its playback state.
Implementation
void paint(ui.Canvas canvas, {ui.Rect? dst, ui.Size? sourceSize}) {
_ensureAlive();
// Dispose shaders orphaned by a runtime texture replacement since the last
// frame — once per top-level frame, where the previous frame's recorded
// picture is guaranteed to have rasterised (the same boundary the backend's
// pool rewind relies on), so a live swap can never free a shader a pending
// picture still reads. Instance children draw through this player's registry
// and never reach here, so it runs exactly once for the whole tree.
textures.flushRetired();
// Per-FRAME, not per-player: both hooks recycle resources that stay live
// until the recorded picture rasterises, so an instance child must never run
// them — doing so frees/rebinds what the parent's already-recorded draws are
// still pointing at (a disposed coverage bitmap, or a pooled shader whose
// uniforms get overwritten before it is rasterised).
_backend.releaseCoverage();
_backend.rewindShaderPools();
_backend.beginFrame(canvas,
dst: dst, sourceSize: sourceSize, root: rootTransform);
// The whole tree draws through THIS player's backend — including instance
// children, which share it so their geometry lands in the same target
// (GPU) / on the same canvas (Canvas) under a pushed transform.
_paintTree(canvas, _backend);
_backend.finish();
}