Tryst::Vector::Surface
A CPU-rendered RGBA surface backed by ThorVG - the Photo-blit counterpart to Tryst::Photo the way Photo itself is to a Tk canvas image item. Draw into it with #draw, then hand the result to a real Tk Photo with #blit_to.
surface = Tryst::Vector::Surface.new(width: 120, height: 56)
surface.draw do |ctx|
ctx.rounded_rect(4, 4, 112, 48, 12).fill(60, 120, 240)
end
surface.blit_to(photo)
HiDPI
scale: renders into a buffer with scale-times as many device pixels as width/height alone would suggest (scale: 2.0 on a 120x56 surface allocates a 240x112 buffer) - but #draw's own coordinate space never changes: every shape a Context creates is scaled to match (see Context's own doc comment), so a #draw block is written once, in logical pixels, and looks right at any scale. #blit_to hands Tk the full device-pixel buffer as-is; sizing and placing that against the surface's own logical width/height (a canvas image item's own scale, or a widget's requested size) is the caller's job - this is deliberately just the buffer, not a second layer of Tk-side scaling on top of ThorVG's own.
Pixel format
ThorVG's ARGB8888S colorspace (straight, non-premultiplied alpha) is byte-for-byte Tryst::PixelFormat::ARGB. #blit_to hands the buffer to Tk with no conversion.
Lifetime
Owns a real ThorVG canvas and its pixel buffer. Call #destroy when done, or let the finalizer do it - same contract as Tryst::Photo.
Constants
Fixed capacity for @@pending_destroy - never allowed to grow, so #finalize (below) never allocates. Generous enough that a realistic burst of simultaneously-collected Surfaces never gets near it - same reasoning and same number as Tryst::Interp's own @finalizer_queue.
Constructors
Class methods
Destroys every canvas #finalize queued - called from #initialize (see there) so this always runs on ordinary application code, never from inside a finalizer itself.
Instance methods
Blits the full device-pixel buffer into photo at (x, y). See this class's own doc comment for why no pixel conversion happens here.
Releases the underlying ThorVG canvas now, rather than waiting for a collection - same contract as Tryst::Photo#delete.
Runs the block with a fresh Context, then renders every shape it creates. Clears the previous frame's content first - #draw always produces one complete frame, never an accumulation of past ones, so it's safe to call repeatedly from an animation tick.
The rendered device-pixel buffer as raw bytes, straight-alpha ARGB (see this class's own doc comment) - for a caller that wants to feed it somewhere other than #blit_to's own Photo, most naturally OwnerDrawnWidget#blit, which manages its own Photo's lifecycle already and just needs the bytes. #blit_to is exactly this plus a direct photo.put_block, kept as its own method since "I already have a Photo in hand" is the common case for a caller using Surface on its own (see this shard's own README).