type Surface struct {
// bitmap IDs of the tiles are base+index
// tile edge in pixels
}
Surface is a retained, opaque BGRA picture that changes in place: a remote
desktop, a video frame, a canvas an application paints pixels into. A Bitmap
is immutable, so changing one pixel of a large Bitmap means a new Version and
a new upload of every byte. A Surface keeps its pixels in square tiles, each
its own Bitmap with its own Version, so Update uploads only the tiles the
changed rectangle touches. A 1920x1080 picture is about 8 MB; a 64x64 patch of
it stages 256 KB.
A Surface is not safe for concurrent use. Update runs on the goroutine that
paints, and the pixel source is copied before Update returns, so the caller
may keep writing to it.
Methods
Draw#
func (surface *Surface) Draw(canvas *Canvas, bounds Rect)
Draw paints the whole picture scaled to bounds. Each tile's edges are rounded
to whole pixels on the way, so neighbours meet exactly at any scale: no seam
of the background shows between them and no pixel is drawn twice.
Resize#
func (surface *Surface) Resize(width, height int)
Resize makes the picture width x height pixels and clears it to opaque
black. A size that is not positive, or too large to address, empties it.
Size#
func (surface *Surface) Size() (width, height int)
Size is the picture's width and height in pixels, zero before Resize.
Update#
func (surface *Surface) Update(x, y, width, height int, pix []byte, stride int)
Update copies a width x height rectangle of BGRA pixels, whose top-left
corner is at (x, y) of the picture, from pix, whose rows are stride bytes
apart and start at pix[0]. The alpha byte is set to opaque, so a source whose
fourth byte is padding (RFB, RDP, most capture APIs) can be passed as it is.
The part of the rectangle outside the picture is ignored. Only the tiles it
touches get a new Version.