Documentation
¶
Overview ¶
Package canvas2d is the last renderer of the web (SPEC §9.6): it draws each frame with the software renderer (internal/gpu/soft) and puts the image into the page's 2D canvas with putImageData, so that an app shows even where neither WebGPU nor WebGL 2 works. A frame crosses into JavaScript in one js.CopyBytesToJS.
The drawing and the composition over the background are plain Go (renderer.go) and run under scripts/test-wasm.sh and the normal tests; the canvas is touched only in the files that carry the js tag.
Flutter: no counterpart (Flutter web's last resort is CanvasKit or Skwasm).
Index ¶
- type Options
- type Presenter
- type Renderer
- func (r *Renderer) Attach(h gpu.SurfaceHandle) (gpu.Surface, error)
- func (r *Renderer) Close() error
- func (r *Renderer) Render(s gpu.Surface, scene *ui.Scene, size ui.Size, dpr float32) error
- func (r *Renderer) RenderCapture(s gpu.Surface, scene *ui.Scene, size ui.Size, _ float32) (*image.RGBA, error)
- func (r *Renderer) Snapshot(scene *ui.Scene, size ui.Size) (*image.RGBA, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Options ¶
type Options struct {
// Background is what shows where the scene draws nothing. A canvas of the page is
// opaque, so only the color's red, green and blue count; the zero value is black.
Background ui.Color
}
Options are the optional parameters of NewRenderer.
Flutter: no counterpart
type Presenter ¶
type Presenter interface {
// Present shows img, an opaque image, in the canvas that the handle names, and sets
// the canvas's size to the image's if it differs. It must not keep img.
Present(h gpu.SurfaceHandle, img *image.RGBA) error
// Release forgets the canvas of the handle.
Release(h gpu.SurfaceHandle)
}
Presenter shows a finished frame in the canvas of a surface. The js build's Presenter puts it there with putImageData; tests give one that records the frames.
Flutter: no counterpart
type Renderer ¶
type Renderer struct {
// contains filtered or unexported fields
}
Renderer is a gpu.Renderer that draws with soft and presents through a Presenter.
Flutter: no counterpart
func NewRenderer ¶
NewRenderer makes a renderer that presents through p. More than one options value panics with MultipleOptions.
Flutter: no counterpart
func (*Renderer) Attach ¶
Attach starts drawing into the canvas that the handle names, which must be of kind gpu.SurfaceKindWeb. It fails with SurfaceKindUnsupported for another kind and with RendererClosed after Close.
Flutter: no counterpart
func (*Renderer) Close ¶
Close stops the renderer; its surfaces are destroyed. It is safe to call twice.
Flutter: no counterpart
func (*Renderer) Render ¶
Render draws the scene into the surface at the size in device pixels and presents it. A nil scene draws the background only. The scene's coordinates are already in device pixels, so dpr is not used.
Flutter: no counterpart