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
- Variables
- func CacheSources(n int) []driver.ImageSource
- func CheckResolution(img image.Image, at image.Point, sampling driver.ImageSampling) []string
- func CheckShading(img image.Image, origin driver.Point, scale float32) []string
- func CheckTintSample(img image.Image, origin driver.Point, scale float32) []string
- func Checkerboard(width, height int) *image.RGBA
- func Differ(a, b *image.RGBA) (int, image.Point)
- func DrawAtlasSampling(d *driver.Drawing, src driver.ImageSource, size float32)
- func DrawSampling(d *driver.Drawing, src driver.ImageSource, size float32)
- func DrawShading(d *driver.Drawing, p ShadingPaints)
- func DrawTintSample(d *driver.Drawing, src driver.ImageSource, width, height float32)
- func DrawTintSprite(d *driver.Drawing)
- func Logo(root string) []byte
- func RedPNG() []byte
- func Resolution(text driver.TextEngine, sampling driver.ImageSampling) *driver.Drawing
- func SDFDisc() *image.RGBA
- func SamplingDifference(img image.Image, at image.Point, ref *image.RGBA, scale int, tolerance uint8) (image.Point, bool)
- func TintOffscreenSource(d *driver.Drawing, id uint64) driver.ImageSource
- func TintPixelsSource() driver.ImageSource
- func TintSource() (driver.ImageSource, error)
- type Probe
- type Sample
- type ShadingPaints
Constants ¶
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.
const ResolutionPixels = ResolutionSize * Scale / 2
ResolutionPixels is how many pixels a side of Resolution's backing store has at Scale.
const ResolutionSize = 8
ResolutionSize is the side, in points, of the canvas Resolution draws.
const Scale = 2
Scale is the pixels a point the samples are drawn at.
const ShadingWidth, ShadingHeight = 300, 200
The shading sample's size in points.
const TintWidth, TintHeight = 160, 120
Variables ¶
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 ¶
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 ¶
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 ¶
CheckTintSample compares the drawing to its reference fills, in the captured color space.
func Checkerboard ¶
Checkerboard has one texel per square, with black in its top left.
func Differ ¶
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 ¶
DrawTintSprite draws the sprite's stripes into an offscreen image TintSpriteSize large.
func Logo ¶
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 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 ¶
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 ¶
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.
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.