canvastest

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Nov 28, 2026 License: Apache-2.0 Imports: 14 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 canvastest holds drawings that exercise a canvas player, and what their pixels must show, so each backend's tests check their player the same way: they draw each Sample on white at twice its points and run its probes.

Index

Constants

View Source
const (
	// SDFShader thresholds a signed distance field's red channel, read
	// smoothly from image0, at 0.5 less Outline, with an edge a pixel wide
	// whatever the scale: a glyph of SDF text in Color.
	SDFShader = `` /* 500-byte string literal not displayed */

	// SolidShader fills with Color.
	SolidShader = `package main

var Color vec4

func Fragment(dst vec4, pos vec2) vec4 {
	return vec4(Color.rgb*Color.a, Color.a)
}
`
	// UVShader goes from blue at the rectangle's left to red at its right.
	UVShader = `package main

func Fragment(dst vec4, pos vec2) vec4 {
	u := pos.x / rectSize().x
	return vec4(u, 0, 1-u, 1)
}
`
)

The programs the shading sample draws with, which a backend's test compiles (shader.CompileFragment) and passes to Shading.

View Source
const ResolutionPixels = ResolutionSize * Scale / 2

ResolutionPixels is how many pixels a side of Resolution's backing store has at Scale.

View Source
const ResolutionSize = 8

ResolutionSize is the side, in points, of the canvas Resolution draws.

View Source
const Scale = 2

Scale is the pixels a point the samples are drawn at.

View Source
const ShadingWidth, ShadingHeight = 300, 200

The shading sample's size in points.

View Source
const TintWidth, TintHeight = 160, 120

Variables

View Source
var TintSpriteSize = driver.Size{Width: tintSpriteWidth, Height: tintSpriteHeight}

TintSpriteSize is the sprite's size in points, for an offscreen image of it.

Functions

func CacheSources added in v0.2.0

func CacheSources(n int) []driver.ImageSource

CacheSources returns n tiny red images for cache-pressure tests, distinct from each other and from any it returned before: each PNG carries a number of its own in a text chunk, so they draw alike but their bytes, and so their keys, differ.

func CheckResolution

func CheckResolution(img image.Image, at image.Point, sampling driver.ImageSampling) []string

CheckResolution returns what img, Resolution's drawing stretched over ResolutionSize × Scale pixels from at, gets wrong: nearest, each square fills its 2 × 2 pixels with its color; smooth, most pixels inside blend two squares' colors.

func CheckShading

func CheckShading(img image.Image, origin driver.Point, scale float32) []string

CheckShading returns the probes a capture fails, the sample drawn on white with its top left corner at origin in points and scale pixels a point.

func CheckTintSample

func CheckTintSample(img image.Image, origin driver.Point, scale float32) []string

CheckTintSample compares the drawing to its reference fills, in the captured color space.

func Checkerboard

func Checkerboard(width, height int) *image.RGBA

Checkerboard has one texel per square, with black in its top left.

func Differ

func Differ(a, b *image.RGBA) (int, image.Point)

Differ counts the pixels of a and b that differ by more than anti-aliasing may, and returns the first.

func DrawAtlasSampling

func DrawAtlasSampling(d *driver.Drawing, src driver.ImageSource, size float32)

DrawAtlasSampling draws the same four sampling squares through DrawAtlas.

func DrawSampling

func DrawSampling(d *driver.Drawing, src driver.ImageSource, size float32)

DrawSampling draws a 16×16 checkerboard in four squares. The left side uses the default and restored smooth filter. The right side uses nearest before and after saving a different filter.

func DrawShading

func DrawShading(d *driver.Drawing, p ShadingPaints)

DrawShading draws an SDF disc from an atlas at 1x, 4x and turned, again with other uniforms, and rectangles shaded among other ops, under a clip, an alpha, an operator and transforms, which ShadingProbes check.

func DrawTintSample

func DrawTintSample(d *driver.Drawing, src driver.ImageSource, width, height float32)

DrawTintSample records tinted, cropped and original draws of src over a solid backdrop.

func DrawTintSprite

func DrawTintSprite(d *driver.Drawing)

DrawTintSprite draws the sprite's stripes into an offscreen image TintSpriteSize large.

func Logo(root string) []byte

Logo reads the gallery's logo, which the image sample draws, from the module's root given as a path from the test's directory.

func RedPNG added in v0.2.0

func RedPNG() []byte

RedPNG is a tiny red PNG.

func Resolution

func Resolution(text driver.TextEngine, sampling driver.ImageSampling) *driver.Drawing

Resolution draws a checkerboard of 1-point squares, ResolutionSize on a side with black in its top left, at a ResolutionScale of 0.5 stretched with sampling: at Scale, each square is one pixel of the backing store and two of the view.

func SDFDisc

func SDFDisc() *image.RGBA

SDFDisc is a 32 by 32 signed distance field of a disc 10 texels in radius at its center, in its red channel: 0.5 on the edge, a texel adding 1/16 inside.

func SamplingDifference

func SamplingDifference(img image.Image, at image.Point, ref *image.RGBA, scale int, tolerance uint8) (image.Point, bool)

SamplingDifference returns the first pixel different from the source texel it should duplicate at the given integer scale.

func TintOffscreenSource

func TintOffscreenSource(d *driver.Drawing, id uint64) driver.ImageSource

TintOffscreenSource makes the sprite as an offscreen canvas drawn by DrawTintSprite.

func TintPixelsSource

func TintPixelsSource() driver.ImageSource

TintPixelsSource makes the sprite as a pixel buffer, a point a pixel.

func TintSource

func TintSource() (driver.ImageSource, error)

TintSource makes the sprite as an encoded PNG.

Types

type Probe

type Probe struct {
	X, Y float64
	What string
	OK   func(c color.RGBA) bool
	W, H float64
	All  bool
}

Probe is a point, or a rectangle when W and H are set, in points, and what its pixel must be: some pixel of the rectangle, or all of them with All.

func ShadingProbes

func ShadingProbes() []Probe

ShadingProbes are what DrawShading must show over white.

type Sample

type Sample struct {
	Name          string
	Width, Height int // points
	Drawing       *driver.Drawing
	Probes        []Probe
}

Sample is a drawing and the pixels it must make.

func AtlasSampling

func AtlasSampling(text driver.TextEngine) *Sample

AtlasSampling checks DrawAtlas against the same nearest texel reference.

func Samples

func Samples(text driver.TextEngine, logo []byte) []*Sample

Samples returns the drawings, recorded with the platform's text engine as a canvas's are, logo being an image the last one draws.

func Sampling

func Sampling(text driver.TextEngine) *Sample

Sampling checks every pixel of two nearest draws at 8× and looks for blended pixels in the corresponding smooth draws.

func Shading

func Shading(text driver.TextEngine, sdf, solid, uv *driver.ShaderProgram) *Sample

Shading draws through programs compiled from SDFShader, SolidShader and UVShader (DrawShading).

func Split

func Split(text driver.TextEngine) []*Sample

Split returns drawings whose static part (driver.CanvasSplit) is long, each with a bound argument: a chart's area, line and bars under a clip and a shadow, then a ring, which keeps the path it builds, and a bar filled with the path the static part left. A backend that keeps a static part checks that playing the ops after it over the part's pixels draws what a full replay does.

func (*Sample) Check

func (s *Sample) Check(img *image.RGBA) []string

Check returns the probes of s that img fails, img being s drawn at Scale on white.

type ShadingPaints

type ShadingPaints struct {
	SDF   func(color [4]float64, outline float64) driver.ShaderPaint
	Solid func(color [4]float64) driver.ShaderPaint
	UV    func() driver.ShaderPaint
}

ShadingPaints makes the shading sample's paints: SDFShader's in a straight color with an outline, SolidShader's in a straight color, and UVShader's.

Jump to

Keyboard shortcuts

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