renderhost

package
v0.41.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 20, 2026 License: MIT Imports: 16 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package renderhost runs the core module of the Rust renderer (renderer/, SDD-013) from Go with wazero: pure Go, no cgo, no import for the module to reach anything through. It is the only place that knows the exports of SDD-013 section 4.2.

Index

Constants

View Source
const (
	DefaultMaxTextureBytes = 512 << 20
	DefaultMaxBitmapBytes  = 128 << 20
)

Default budgets of vr_init (SDD-013 section 7.2).

View Source
const APIVersion = 3

APIVersion is the vr_api_version this host knows.

View Source
const RenderInputVersion = 1

RenderInputVersion is the version of the render input this host writes (SDD-000 section 12).

Variables

View Source
var ErrClosed = errors.New("renderhost: the instance is closed")

ErrClosed is returned by a host that was closed or whose instance trapped: a trapped instance is discarded and its stored textures are gone.

Functions

func ModuleSHA256

func ModuleSHA256() string

ModuleSHA256 is the digest of the embedded module, as lower-case hex.

Types

type Config

type Config struct {
	MaxTextureBytes uint32
	MaxBitmapBytes  uint32
	// Uncancellable runs the instance without the check that stops a call when its context ends, which is
	// about five times faster. Text requests use it: they are bounded by construction (SDD-013 section 4.6).
	Uncancellable bool
}

Config is what New needs; a zero value is the defaults.

type Error

type Error struct {
	Reason Reason
	Detail string
}

Error is a failure of the renderer. Detail names an item, a key or a limit, never a pixel or a path.

func (*Error) Error

func (e *Error) Error() string

type Host

type Host struct {
	// contains filtered or unexported fields
}

Host runs one instance of the core module. It is not safe for concurrent use.

func New

func New(ctx context.Context, cfg Config) (*Host, error)

New instantiates the embedded module, compiled once per process. The module is refused unless its digest matches, it has no import, and its vr_api_version is APIVersion.

func (*Host) Close

func (h *Host) Close(ctx context.Context) error

Close frees the instance.

func (*Host) PutBitmap

func (h *Host) PutBitmap(ctx context.Context, key string, bm bitmap.Bitmap) error

PutBitmap uploads a bitmap of the rasterizer under its key (plan.BitmapSpec.Key). The module premultiplies it.

func (*Host) PutFont

func (h *Host) PutFont(ctx context.Context, hash string, data []byte) error

PutFont stores the bytes of a user font under its lower-case hex SHA-256 for the requests that name it; empty data records that the file is not stored. The caller has checked that the bytes hash to the digest.

func (*Host) PutLUT

func (h *Host) PutLUT(ctx context.Context, asset string, t *lut.Table) error

PutLUT uploads the lookup table of a lut asset under the asset id, replacing the table of that id (SDD-004 section 3.6): the entries are the little-endian 16-bit values of the table (lut.Table.Bytes).

func (*Host) PutTexture

func (h *Host) PutTexture(ctx context.Context, item string, w, ht int, rgba []byte, opaque bool) error

PutTexture uploads the premultiplied RGBA pixels of a media layer under its item id, replacing the texture of that id. The module copies the pixels, so the caller reuses rgba at once.

func (*Host) Release

func (h *Host) Release(ctx context.Context, id string) error

Release forgets the texture, bitmap or lookup table with that id or key; an unknown one is not an error.

func (*Host) Render

func (h *Host) Render(ctx context.Context, in RenderInput, dst *image.RGBA) error

Render draws the frame into dst: RGBA, no stride padding, exactly Output.Width by Output.Height. With a band (Output.Y1 > Output.Y0) only those rows of dst are written.

func (*Host) RunText

func (h *Host) RunText(ctx context.Context, request []byte) ([]byte, error)

RunText draws or measures a shape, a text or a caption (the request format is in SDD-013 section 4.2) and returns the encoded result. A failure that has a structured detail is a *TextError.

func (*Host) ValidateFont

func (h *Host) ValidateFont(ctx context.Context, data []byte) error

ValidateFont checks a user font file; a refusal is a *TextError of reason font_invalid.

type Output

type Output struct {
	Width, Height int
	Scale         float64
	Y0, Y1        int
}

Output is the frame to write (SDD-013 section 2.1). Width and Height are whole pixels from 1 to 4096; Scale is the output scale of SDD-004 section 6, which multiplies every position and size of the plan. When Y1 is greater than Y0 the module draws only the rows [Y0, Y1) of the frame, which is how a band of the export is rendered by its own instance.

type Reason

type Reason string

Reason is a reason of SDD-013 section 7.1.

const (
	InvalidPlan        Reason = "invalid_plan"
	UnsupportedVersion Reason = "unsupported_version"
	UnsupportedLayer   Reason = "unsupported_layer"
	MissingTexture     Reason = "missing_texture"
	LimitExceeded      Reason = "limit_exceeded"
	OutOfMemory        Reason = "out_of_memory"
	InvalidArgument    Reason = "invalid_argument"
	InvalidSpec        Reason = "invalid_spec"
	FontUnknown        Reason = "font_unknown"
	FontInvalid        Reason = "font_invalid"
	FontNeeded         Reason = "font_needed"
	TextFailed         Reason = "text_failed"
	RenderTrap         Reason = "render_trap"
)

The reasons a call can fail with; RenderTrap has no status, the call itself failed.

type RenderInput

type RenderInput struct {
	Output Output
	Plan   plan.FramePlan
}

RenderInput is what one render call reads: the frame to write and the frame plan to draw.

func (RenderInput) MarshalJSON

func (in RenderInput) MarshalJSON() ([]byte, error)

MarshalJSON writes the render input of SDD-013 section 2.1: the plan keeps the JSON names of core/plan.

type TextError

type TextError struct {
	Reason Reason
	Detail string
	Data   []byte
}

TextError is a failure of a text request that carries the structured detail the module encoded: for font_unknown the family, weight, weights and digest; for font_invalid the reason and message.

func (*TextError) Error

func (e *TextError) Error() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL