Documentation
¶
Overview ¶
Package goskia is a Go binding to Skia's 2D graphics API via a C ABI shim.
Skia's C++ API cannot be called directly from cgo (name mangling), so this package links against libskia.a and exposes SkCanvas/SkSurface/SkPaint/SkPath through extern "C" trampolines. The dependency direction is deliberately one-way: goskia has NO dependency on any browser engine. An engine consumes it by implementing its own Canvas interface against this API.
STATUS: skeleton. This placeholder exists so the module is resolvable (`go mod download`) from day one — the lesson from the v8go fork, whose repo was created late and broke CI resolution. The C ABI shim and libskia.a distribution are being wired up; no drawing API is exported yet.
Index ¶
- Constants
- type Canvas
- func (c *Canvas) Clear(argb uint32)
- func (c *Canvas) ClipRRect(l, t, r, b float32, radii CornerRadii)
- func (c *Canvas) ClipRect(l, t, r, b float32)
- func (c *Canvas) DrawDRRect(ol, ot, or_, ob float32, outer CornerRadii, il, it, ir, ib float32, ...)
- func (c *Canvas) DrawImage(img *Image, x, y float32, p *Paint)
- func (c *Canvas) DrawImageRect(img *Image, sl, st, sr, sb, dl, dt, dr, db float32, p *Paint)
- func (c *Canvas) DrawPath(path *Path, p *Paint)
- func (c *Canvas) DrawRRect(l, t, r, b, rx, ry float32, p *Paint)
- func (c *Canvas) DrawRRectCorners(l, t, r, b float32, radii CornerRadii, p *Paint)
- func (c *Canvas) DrawRect(l, t, r, b float32, p *Paint)
- func (c *Canvas) Restore()
- func (c *Canvas) RestoreToCount(count int)
- func (c *Canvas) Save() int
- func (c *Canvas) SaveLayerAlpha(l, t, r, b float32, alpha uint8) int
- func (c *Canvas) Translate(dx, dy float32)
- type CornerRadii
- type Image
- type Paint
- type PaintStyle
- type Path
- type Surface
- func (s *Surface) Canvas() *Canvas
- func (s *Surface) Delete()
- func (s *Surface) Height() int
- func (s *Surface) ReadPixels() []byte
- func (s *Surface) ReadPixelsInto(dst []byte, rowBytes int) bool
- func (s *Surface) ReadPixelsRGBAInto(dst []byte, rowBytes int) bool
- func (s *Surface) SavePNG(path string) error
- func (s *Surface) Width() int
Constants ¶
const Version = "0.0.0-pre"
Version is the binding version. Pre-release until the first drawing subset (Surface/Canvas/DrawRect/Flush) lands and is golden-tested.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Canvas ¶
type Canvas struct {
// contains filtered or unexported fields
}
Canvas is the Skia drawing context for a Surface. Non-owning: the underlying SkCanvas is owned by the Surface, so a Canvas must not outlive its Surface.
func (*Canvas) Clear ¶
Clear replaces every pixel inside the clip with the colour, ignoring blending.
func (*Canvas) ClipRRect ¶
func (c *Canvas) ClipRRect(l, t, r, b float32, radii CornerRadii)
ClipRRect intersects the clip with a rounded rectangle, anti-aliased. This is what rounds an `overflow: hidden` box's children — a rectangular clip cannot.
func (*Canvas) DrawDRRect ¶
func (c *Canvas) DrawDRRect( ol, ot, or_, ob float32, outer CornerRadii, il, it, ir, ib float32, inner CornerRadii, p *Paint)
DrawDRRect fills the region between an outer and an inner rounded rect — a border ring in one call, with the corner geometry Skia derives rather than the caller approximating.
func (*Canvas) DrawImage ¶
DrawImage blits img with its top-left corner at (x, y). A nil paint is a plain source-over blit; a paint carries alpha (and, for A8 images, colour). Sampling is nearest — a consumer that wants filtering scales before upload.
func (*Canvas) DrawImageRect ¶
DrawImageRect blits the src rectangle of img onto the dst rectangle, scaling with nearest sampling if the two differ.
func (*Canvas) DrawRRect ¶
DrawRRect fills (or strokes, per p) a rounded rectangle over [l, t, r, b] with corner radii (rx, ry).
func (*Canvas) DrawRRectCorners ¶
func (c *Canvas) DrawRRectCorners(l, t, r, b float32, radii CornerRadii, p *Paint)
DrawRRectCorners fills (or strokes, per p) a rounded rectangle with independent corner radii.
func (*Canvas) RestoreToCount ¶
RestoreToCount pops until the stack is `count` deep.
func (*Canvas) SaveLayerAlpha ¶
SaveLayerAlpha begins an offscreen layer over bounds; the matching Restore composites it at alpha (0..255). This is group opacity: everything drawn inside blends normally with itself, and the *result* is faded as one.
type CornerRadii ¶
type CornerRadii [8]float32
CornerRadii is per-corner x/y radii in SkRRect order: upper-left, upper-right, lower-right, lower-left.
func Radii ¶
func Radii(upperLeft, upperRight, lowerRight, lowerLeft float32) CornerRadii
Radii builds a CornerRadii with circular corners.
type Image ¶
type Image struct {
// contains filtered or unexported fields
}
Image is an immutable raster image on the Skia side.
Both constructors copy: the Go slice is free the moment they return, and the Image can be drawn any number of times without touching Go memory again — which is what makes caching one per texture worthwhile for a consumer.
func NewImageA8 ¶
NewImageA8 copies an 8-bit coverage mask into an Image. An A8 image draws in the paint's colour — the glyph-mask and shadow-mask path.
func NewImageRGBA ¶
NewImageRGBA copies non-premultiplied RGBA8888 pixels into an Image.
Non-premultiplied because that is what image.RGBA-shaped callers hold; Skia premultiplies on draw. rowBytes is the source stride (width*4 for a tight slice).
type Paint ¶
type Paint struct {
// contains filtered or unexported fields
}
Paint holds Skia fill/stroke state. Heap-allocated in C; call Delete when done.
func NewPaint ¶
func NewPaint() *Paint
NewPaint constructs a default Paint (black fill, no anti-alias).
func (*Paint) SetAntiAlias ¶
SetAntiAlias toggles edge anti-aliasing.
func (*Paint) SetColor ¶
SetColor sets the paint color in Skia's 0xAARRGGBB order (e.g. 0xFFFF0000 = opaque red).
func (*Paint) SetStrokeWidth ¶
SetStrokeWidth sets the stroke width; only meaningful after SetStyle(PaintStroke).
func (*Paint) SetStyle ¶
func (p *Paint) SetStyle(style PaintStyle)
SetStyle sets the paint to fill or stroke geometry.
type PaintStyle ¶
type PaintStyle int
PaintStyle selects fill vs. stroke. Values match SkPaint::Style ordering (kFill_Style=0, kStroke_Style=1) as exposed by the C shim.
const ( PaintFill PaintStyle = 0 PaintStroke PaintStyle = 1 )
type Path ¶
type Path struct {
// contains filtered or unexported fields
}
Path wraps an in-progress Skia path. In m150, path construction lives on SkPathBuilder; the C shim holds one and snapshots it to an immutable SkPath at DrawPath time. Delete when done (the builder is heap-allocated in C).
func (*Path) Close ¶
func (p *Path) Close()
Close closes the current contour with a line back to its MoveTo point.
type Surface ¶
type Surface struct {
// contains filtered or unexported fields
}
Surface is a CPU-backed Skia drawing target.
func NewRasterSurface ¶
NewRasterSurface creates a CPU-backed N32-premul surface width x height.
func (*Surface) Canvas ¶
Canvas returns the surface's drawing context. Non-owning: the Canvas dies with the Surface. Cached: repeated calls return the same Canvas.
func (*Surface) ReadPixels ¶
ReadPixels copies the whole surface into a new width*height*4 byte slice (N32 premul). Returns nil on failure.
func (*Surface) ReadPixelsInto ¶
ReadPixelsInto copies the whole surface into dst (N32 premul, width*height*4 bytes) without allocating. Reports success. The allocating ReadPixels stays for callers that want a fresh slice; a per-frame reader reuses one buffer through this instead.
func (*Surface) ReadPixelsRGBAInto ¶ added in v0.1.1
ReadPixelsRGBAInto copies the whole surface into dst as straight (non-premultiplied) RGBA — the layout image.RGBA uses — rather than the surface's own N32 premultiplied BGRA. Same buffer requirements as ReadPixelsInto; reports success.
Skia does the swizzle and the unpremultiply during the read, which is why this exists: a caller doing it afterwards pays a second pass over the whole window and needs a staging buffer to do it in.
Directories
¶
| Path | Synopsis |
|---|---|
|
Command fetch-libskia downloads the pinned rust-skia prebuilt libskia.a for the current platform into deps/<GOOS>_<GOARCH>/, checksum-verified against a pinned SHA-256.
|
Command fetch-libskia downloads the pinned rust-skia prebuilt libskia.a for the current platform into deps/<GOOS>_<GOARCH>/, checksum-verified against a pinned SHA-256. |