FrameOptions defines the pixel mapping and hard resource ceilings for one
render. Every limit and Scale must be positive; callers select the limits so
production ceilings are explicit rather than hidden package defaults.Backgroundcolor.ColorMaxAnimationKeyframesintMaxAnimationTracksintMaxAssetBytesint64MaxAssetsint MaxDecodedAssetBytes bounds the cumulative resolver-declared decoded
footprint of all retained raster assets. MaxAssetBytes separately bounds
their encoded bytes together with retained font bytes.MaxDepthint MaxEvenOddClipWork bounds aggregate point-in-edge evaluations used by
supersampled even-odd fills and clips. MaxFontFacesPerText bounds primary plus fallback face selection for one
TextRun. MaxTextCoverageChecks and MaxTextShapingRuns are aggregate frame
work ceilings. Zero selects bounded defaults.MaxHeightint MaxImportDepth bounds active vector-asset nesting. Retained vector roots
and visible vector Image instances start at depth one; raster images do
not consume this budget. Stored vector definitions are charged once by structural graph
validation. Every rendered vector Image then charges its instantiated
subtree again. Animation limits follow the same retained-plus-instantiated
policy and are charged before per-node animation bookkeeping is allocated.
Retained MaxDepth validation includes the unavoidable host Image at depth
one, so an intrinsically unplaceable definition is rejected even if unused.
MaxNodes also bounds aggregate filter entries and synthesized color-glyph
layers as separate structural dimensions, preventing arbitrarily long
identity-filter chains or color-font layer lists. MaxOffscreenBytes bounds the peak live pixel backing storage used by
retained pattern tiles, temporary RGBA effect/filter layers, Alpha blur
and effect masks, and retained scanline-rasterizer scratch. It excludes
decoded assets (bounded separately), the final frame canvas, and returned
image.MaxPathCommandsintMaxPixelsint64 MaxScanlineWork bounds aggregate operation units used by non-zero fills,
strokes, streamed paint coverage, and clips. Zero selects a bounded default;
negative values are invalid.MaxTextCoverageChecksint64 MaxTextRunesPerRun bounds one non-interruptible segmentation/shaping
call. Zero selects the default; negative values are invalid.
Aggregate shaped glyphs remain bounded by MaxPathCommands.MaxTextShapingRunsintMaxWidthintScalefloat64Timetime.Duration
func Render(ctx context.Context, document *d2scene.Document, options FrameOptions) (*image.NRGBA, error)
func RenderBands(ctx context.Context, document *d2scene.Document, options FrameOptions, bandHeight int, consume func(*image.NRGBA) error) error
func (*RenderSession).Render(ctx context.Context, document *d2scene.Document, options FrameOptions) (*image.NRGBA, error)
func (*RenderSession).RenderBands(ctx context.Context, document *d2scene.Document, options FrameOptions, bandHeight int, consume func(*image.NRGBA) error) error
func (*RenderWorkspace).Render(ctx context.Context, session *RenderSession, document *d2scene.Document, options FrameOptions, consume func(*image.NRGBA) error) error
RenderSession reuses immutable parsed fonts and decoded raster pixels
across renders. Scene validation and every per-document resource limit are
still applied independently on every Render call. Callers may replace an
asset value, but must not mutate an existing Data backing allocation, as
required by d2scene.Asset. Render preflights and renders one frame while reusing this session's bounded
parsed-font and decoded-raster cache. RenderBands reuses the session's bounded font and raster-asset cache while
rendering consecutive borrowed bands. Its contract is otherwise RenderBands'. Stats returns a race-free snapshot of cache counters and current retained
charged storage.
func NewRenderSession(options RenderSessionOptions) (*RenderSession, error)
func (*RenderWorkspace).Render(ctx context.Context, session *RenderSession, document *d2scene.Document, options FrameOptions, consume func(*image.NRGBA) error) error
RenderSessionOptions bounds reusable parsed and decoded asset state. Every
field must be positive. MaxCacheEntries independently caps asset entries and
immutable-source key memos, so a session may retain up to twice that many
entries. MaxCacheBytes jointly bounds both groups. Entries charge source and
MIME bytes for fonts, validated decoded footprint and MIME bytes for raster
images, or the encoded source length for key memos, plus
cacheEntryOverheadBytes each.MaxCacheBytesint64MaxCacheEntriesintMaxConcurrentLoadsint
func NewRenderSession(options RenderSessionOptions) (*RenderSession, error)
RenderWorkspace retains at most one final-frame backing store and one
exact-plan scanline rasterizer for a sequence of renders. Before each call it
drops rasterizer capacity that exceeds the new MaxOffscreenBytes limit. Its
zero value is ready for use. Render serializes concurrent calls, while the
separate RenderSession remains safe to share with other workspaces.
Canvas capacity can retain the largest frame reached by a call, including a
call canceled after painting begins, for the workspace's lifetime. Reset
releases all retained storage when an operation ends. A RenderWorkspace must
not be copied after first use.
The frame passed to consume is borrowed and is valid only until consume
returns; callers that retain frames must continue to use RenderSession.Render,
which returns independently owned pixels. Every call still performs complete
preflight and applies all limits from its FrameOptions. Render paints one frame into reusable workspace storage and calls consume
before that storage can be reused. The workspace remains exclusively held
while consume runs, so consume must not re-enter the same RenderWorkspace. Reset releases all final-frame and scanline storage retained by w. It waits
for an active Render and is safe to call on a nil workspace.
Package-Level Functions (total 4)
EncodePNG deterministically encodes img as PNG.
NewRenderSession creates a bounded, concurrent-safe render session.
Render preflights document and returns a newly allocated NRGBA frame. The
viewbox is mapped to LogicalWidth x LogicalHeight and then multiplied by
FrameOptions.Scale.
RenderBands renders a frame from top to bottom using a reusable canvas of at
most bandHeight rows. Each NRGBA band has absolute frame coordinates, full
frame width, and consecutive rows. Its pixels are borrowed only until consume
returns; a consumer that retains a band must copy it.
Geometry and assets are prepared once. All resource limits, including the
aggregate scanline and even-odd work of every band and filter overlap, are
checked before the first callback. MaxPixels still bounds total output pixels;
only the band canvas, rather than the full frame, must fit platform storage.
MaxOffscreenBytes separately bounds retained pattern tiles and rendering
scratch. The final band may have fewer rows. On any error, consume receives no
further bands. A callback must not modify document or its assets.
The pages are generated with Goldsv0.8.7. (GOOS=linux GOARCH=amd64)
Golds is a Go 101 project developed by Tapir Liu.
PR and bug reports are welcome and can be submitted to the issue list.
Please follow @zigo_101 (reachable from the left QR code) to get the latest news of Golds.