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
- Variables
- func ModuleSHA256() string
- type Config
- type Error
- type Host
- func (h *Host) Close(ctx context.Context) error
- func (h *Host) MemoryBytes() int64
- func (h *Host) Prepare(ctx context.Context, in RenderInput) (Prepared, error)
- func (h *Host) PutBitmap(ctx context.Context, key string, bm bitmap.Bitmap) error
- func (h *Host) PutFont(ctx context.Context, hash string, data []byte) error
- func (h *Host) PutLUT(ctx context.Context, asset string, t *lut.Table) error
- func (h *Host) PutPrepared(ctx context.Context, item string, p Prepared) error
- func (h *Host) PutTexture(ctx context.Context, item string, w, ht int, rgba []byte, opaque bool) error
- func (h *Host) Release(ctx context.Context, id string) error
- func (h *Host) Render(ctx context.Context, in RenderInput, dst *image.RGBA) error
- func (h *Host) Reset(ctx context.Context) error
- func (h *Host) RunText(ctx context.Context, request []byte) ([]byte, error)
- func (h *Host) ValidateFont(ctx context.Context, data []byte) error
- type Output
- type Pool
- type Prepared
- type PreparedSize
- type Reason
- type RenderInput
- type TextError
Constants ¶
const ( DefaultMaxTextureBytes = 512 << 20 DefaultMaxBitmapBytes = 128 << 20 )
Default budgets of vr_init (SDD-013 section 7.2).
const APIVersion = 3
APIVersion is the vr_api_version this host knows.
const RenderInputVersion = 1
RenderInputVersion is the version of the render input this host writes (SDD-000 section 12).
Variables ¶
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 ¶
Error is a failure of the renderer. Detail names an item, a key or a limit, never a pixel or a path.
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 ¶
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) MemoryBytes ¶ added in v0.46.0
MemoryBytes is the memory the instance holds; 0 once it is closed.
func (*Host) Prepare ¶ added in v0.46.0
Prepare runs the preparation of the one layer of the plan (SDD-013 section 4.2.2) at opacity 1 and without its clip: its texture or bitmap, and the tables it names, must be stored. A layer that draws nothing gives an empty Prepared.
func (*Host) PutBitmap ¶
PutBitmap uploads a bitmap of the rasterizer under its key (plan.BitmapSpec.Key). The module premultiplies it.
func (*Host) PutFont ¶
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 ¶
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) PutPrepared ¶ added in v0.46.0
PutPrepared stores a prepared layer as the texture of the item id: a media layer of that item is then drawn with no look (SDD-013 section 4.2.2). The module copies the block.
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 ¶
Release forgets the texture, bitmap or lookup table with that id or key; an unknown one is not an error.
func (*Host) Render ¶
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. A band may also be drawn into a view of its rows alone (dst.SubImage of the rectangle from (0, Y0) to (Width, Y1) of the frame): the instance then holds only those rows, not the frame (SDD-013 section 4.2).
func (*Host) Reset ¶ added in v0.46.0
Reset forgets every texture, bitmap and lookup table the instance holds, as vr_init does, and keeps the memory the instance has grown to.
type Output ¶
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 Pool ¶ added in v0.46.0
type Pool struct {
// contains filtered or unexported fields
}
Pool keeps idle instances of the module for the next render. An instance that has drawn a large picture owns the memory it grew to, and a fresh one pays for every page of it again (the pages are faulted in one at a time, and the module's memory is grown by copying): the render of an image document uses up to eight instances at once, so the next one is faster on instances that are already as large as it needs.
A pool bounds what it keeps: at most maxIdle instances and maxIdleBytes of their memory, and it closes them all when none was taken for ttl. An instance that failed is never kept. It is safe for concurrent use; every instance it gives out is the caller's alone until it comes back.
func (*Pool) Get ¶ added in v0.46.0
Get gives an idle instance, with nothing stored in it, or a new one.
type Prepared ¶ added in v0.46.0
type Prepared struct {
// contains filtered or unexported fields
}
Prepared is a layer after its looks, the block `vr_prepare` gives (SDD-013 section 4.2.2): its pixels, the size of the rectangle that draws them and what places it again. It is a plain value: the host that made it and any other instance of the module read it the same way, so it can be kept and uploaded again.
func (Prepared) Size ¶ added in v0.46.0
func (p Prepared) Size() PreparedSize
Size is the geometry of a prepared layer; the zero value for an empty one.
type PreparedSize ¶ added in v0.46.0
type PreparedSize struct {
// W and H are the pixels of the prepared picture.
W, H int
// GrownW and GrownH are the size, in output pixels, of the rectangle that draws it, centred where the layer
// is (a blur makes it larger than the layer).
GrownW, GrownH float64
// OffsetX and OffsetY are what a bitmap's metrics move its centre by; zero for a picture.
OffsetX, OffsetY float64
// Scale is the output scale it was prepared at.
Scale float64
}
PreparedSize is the pixels of a prepared layer and the rectangle that draws them.
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 ¶
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.