soft

package
v1.17.8 Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2026 License: BSD-3-Clause Imports: 8 Imported by: 0 modules, 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 soft is the pure-Go software rasterizer, used for golden tests and headless rendering.

Flutter: Skia's software rasterizer (the CPU backend used in flutter_test goldens).

Index

Constants

View Source
const MipBudget = 64 << 20

MipBudget is the most memory, in bytes, that the mipmap levels of a Cache's images that were not drawn in the current frame may hold (an image's own pixels, its level 0, are not counted: the image has them anyway).

Flutter: no counterpart

Variables

This section is empty.

Functions

func Render

func Render(scene *ui.Scene, width, height int) (*image.RGBA, error)

Render draws a scene into a new image of width x height pixels, in premultiplied RGBA with a transparent background.

Not everything is supported yet. A layer, an operation or a paint feature that is not returns the error SoftNotImplemented naming it, and no image. What works now: container, transform, offset, clip, opacity and color filter layers and picture layers; every operation, text included; paints with colors, gradients, image shaders, all 29 blend modes, color filters and inverted colors; and SaveLayer with a paint. The blurs, shadows, image filters and the backdrop filter and shader mask layers come with step 2.9, text with 4.x.

Flutter: no counterpart (flutter_test renders with Skia's software backend)

func RenderInto

func RenderInto(dst *image.RGBA, scene *ui.Scene, region image.Rectangle) error

RenderInto draws a scene over the pixels of dst, in premultiplied RGBA, but only inside the region, which is cut to dst. The pixels of the region are changed as Render would change them if they had been transparent before the drawing: the caller clears the region first when it wants the scene alone. Everything the scene draws is clipped to the region as if it were the whole surface, so the pixels in it are those of a drawing of the whole scene. Only a scene with something that reads the pixels outside what it draws (an image filter or a backdrop filter that reaches beyond the region) can differ: a caller that redraws a part of a surface draws the whole of such a scene's reach.

It keeps nothing between calls (a renderer that draws frame after frame uses a Cache, which keeps the mipmap chains of the images), and two calls on different images may run at the same time.

Flutter: no counterpart (flutter_test renders with Skia's software backend)

func Stroke

func Stroke(contours []ui.FlatContour, st StrokeStyle) [][]ui.Offset

Stroke turns flattened contours into the polygons that cover their stroke. The polygons all wind the same way, so they are filled together with FillNonZero.

A contour with a single point, after repeated points are removed, draws a dot for round and square caps and nothing for butt caps.

Flutter: no counterpart (Skia's SkStroke)

Types

type Cache

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

Cache keeps what the software renderer makes from the images of a scene and can use again in the frames after it: the mipmap chain of each image it scales down (SPEC §9.1, "Images"). A renderer that draws frame after frame keeps one Cache, draws every frame with its RenderInto or Render, and calls EndFrame after each frame, as the GPU renderers keep the textures of images: a picture under an animation is not made smaller again in every frame.

A chain is keyed by the image's pixels (gpu.KeyOfImage), so clones share it, and only the levels that a draw needs are made. EndFrame drops the chain of an image that was not drawn for gpu.IdleFrames frames, of an image whose handle it was last drawn with is disposed, and the chains drawn longest ago while the levels are over MipBudget. A Cache may be used by several goroutines at once.

Flutter: no counterpart (Skia keeps the mipmaps of an SkImage with the image)

func NewCache

func NewCache() *Cache

NewCache returns an empty cache.

Flutter: no counterpart

func (*Cache) EndFrame

func (c *Cache) EndFrame()

EndFrame ends a frame: it drops the chains of the images that were not drawn for gpu.IdleFrames frames or whose handle is disposed, and then the chains drawn longest ago, but none drawn in this frame, while the levels hold more than MipBudget.

Flutter: no counterpart

func (*Cache) Render

func (c *Cache) Render(scene *ui.Scene, width, height int) (*image.RGBA, error)

Render is the function Render that uses the cache's mipmap chains and keeps the ones it makes. It fails as Render does.

Flutter: no counterpart

func (*Cache) RenderInto

func (c *Cache) RenderInto(dst *image.RGBA, scene *ui.Scene, region image.Rectangle) error

RenderInto is the function RenderInto that uses the cache's mipmap chains and keeps the ones it makes. It fails as RenderInto does.

Flutter: no counterpart

func (*Cache) Stats

func (c *Cache) Stats() CacheStats

Stats returns what the cache holds and has done.

Flutter: no counterpart

type CacheStats

type CacheStats struct {
	// Chains is the number of images whose mipmap chain the cache holds.
	Chains int
	// Bytes is the memory of their levels, without the images' own pixels.
	Bytes int
	// Built is how many chains the cache has started, Dropped how many it has dropped.
	Built, Dropped int
}

CacheStats is what a Cache holds and what it has done since it was made.

Flutter: no counterpart

type FillRule

type FillRule int

FillRule says which points are inside a shape whose outline crosses itself.

Flutter: ui/painting.dart PathFillType

const (
	// FillNonZero fills a point when the outline winds around it a number of
	// times other than zero.
	FillNonZero FillRule = iota
	// FillEvenOdd fills a point when a ray from it crosses the outline an odd
	// number of times.
	FillEvenOdd
)

The fill rules.

type ImageRasterizer

type ImageRasterizer struct{}

ImageRasterizer is the ui.Rasterizer of the software renderer: Picture.ToImage and Scene.ToImage use it to make images in headless tests.

Flutter: no counterpart

func (ImageRasterizer) RasterizeScene

func (ImageRasterizer) RasterizeScene(scene *ui.Scene, width, height int) (*ui.Image, error)

RasterizeScene draws the scene into a new image of width x height pixels.

type Mask

type Mask struct {
	// Rect is the area of the surface the mask covers.
	Rect image.Rectangle
	// Cov holds the coverage of each pixel of Rect, row by row from the top. The
	// renderer's own masks of a fill that covers its rectangle fully have none (At and
	// Sum are not used on them).
	Cov []float32
	// contains filtered or unexported fields
}

Mask is the coverage of a shape over a rectangle of pixels: 0 where the shape does not touch a pixel and 1 where it covers the pixel fully.

Flutter: no counterpart (SkMask)

func ClipMask

func ClipMask(path *ui.Path, m *ui.Matrix4, antiAlias bool, area image.Rectangle) *Mask

ClipMask returns the coverage of a clip shape: the path, filled by its fill type under the transform m, inside the area of the surface. Without antiAlias the coverage is all or nothing, sampled at the pixel centers. It returns nil when nothing is covered.

Flutter: no counterpart (SkClipStack)

func OpMask

func OpMask(op ui.DisplayOp, m *ui.Matrix4, area image.Rectangle) (*Mask, bool)

OpMask returns the coverage of the shape that a drawing operation makes, drawn under the transform m, inside the area of the surface: the same coverage Render paints with, anti-aliased or not as the operation's paint says. It works for the operations that draw a shape from an outline: paths, rectangles, rounded rectangles, superellipses, DRRects, ovals, circles, arcs, lines and points. It returns nil when nothing is covered, and false for any other operation. The operation's mask filter and blend mode do not apply.

This is what the GPU renderer rasterizes into its coverage atlas (SPEC §9.2).

Flutter: no counterpart (SkMask)

func Rasterize

func Rasterize(contours [][]ui.Offset, rule FillRule, clip image.Rectangle) *Mask

Rasterize computes the coverage of the area enclosed by the contours, each of which is closed implicitly, inside the clip rectangle. The coverage of a pixel is the exact area of the pixel the shape covers where only one edge crosses it; with several edges in one pixel it is the area under the fill rule applied to the accumulated winding. It returns nil when nothing is covered. Contours with a point that is not finite are skipped.

Flutter: no counterpart (Skia's SkScan_AntiPath)

func (*Mask) At

func (m *Mask) At(x, y int) float32

At returns the coverage of the pixel at x, y, or 0 outside the mask.

func (*Mask) Sum

func (m *Mask) Sum() float64

Sum returns the total coverage: the area of the shape in pixels.

type StrokeStyle

type StrokeStyle struct {
	// Width is the width of the stroke; it must be greater than 0.
	Width float64
	// Cap is the shape of the ends of open contours; StrokeCapUnspecified is
	// StrokeCapButt.
	Cap ui.StrokeCap
	// Join is the shape of the corners; StrokeJoinUnspecified is
	// StrokeJoinMiter.
	Join ui.StrokeJoin
	// MiterLimit is the longest miter, as a multiple of half the width, that a
	// miter join may have before it becomes a bevel; 0 is Flutter's default, 4.
	MiterLimit float64
	// Scale is how much a transform applied to the result magnifies lengths. It
	// only sets the number of segments used for round joins and caps; 0 is 1.
	Scale float64
}

StrokeStyle describes how a path is stroked. The units are those of the path.

Flutter: ui/painting.dart Paint.strokeWidth

Jump to

Keyboard shortcuts

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