Documentation
¶
Overview ¶
Package gpu defines the Renderer interface, flattens a ui.Scene into draw commands, and holds the glyph and path atlases shared by the renderers.
Flutter: the compositor and rasterizer (engine/src/flutter/flow and impeller).
Index ¶
- Constants
- func IsAxisAligned(m *ui.Matrix4) bool
- func OpPaint(op ui.DisplayOp) *ui.Paint
- func ShadowBounds(op ui.OpDrawShadow) (ui.Rect, bool)
- func ShapeBounds(op ui.DisplayOp) (ui.Rect, bool)
- type Atlas
- type AtlasEntry
- type AtlasStats
- type Clip
- type ClipShape
- type ClipShapeKind
- type Command
- type CommandKind
- type Damage
- type DamageTracker
- type DrawList
- type FlattenOpts
- type Renderer
- type Surface
- type SurfaceHandle
- type SurfaceKind
Constants ¶
const MaxAtlasTile = 256
MaxAtlasTile is the largest width or height of a tile of an Atlas; a bigger mask is cut into tiles.
Flutter: no counterpart
Variables ¶
This section is empty.
Functions ¶
func IsAxisAligned ¶
IsAxisAligned reports whether the transform keeps rectangles axis-aligned: it has no rotation by other than a multiple of 90 degrees, no skew and no perspective. A rotation off by less than a millionth (what float32 gives for a quarter turn) counts as none.
Flutter: no counterpart
func OpPaint ¶
OpPaint returns the paint that a drawing operation is drawn with, or nil for an operation that has none (clips, transforms, pictures, paragraphs, shadows, colors).
Flutter: no counterpart
func ShadowBounds ¶
func ShadowBounds(op ui.OpDrawShadow) (ui.Rect, bool)
ShadowBounds returns the rectangle, in the path's coordinates, that Canvas.drawShadow can change: the ambient shadow (the shape blurred in place) and the spot shadow (the shape grown about its center, moved down, and blurred), both reaching three sigma. It returns false when the bounds cannot be known (a path that is not finite).
Flutter: no counterpart
func ShapeBounds ¶
ShapeBounds returns the bounds of what a shape-drawing operation covers in its own coordinates, strokes included, and false for an operation that is not one of the shapes (rectangles, rounded rectangles, ovals, circles, arcs, paths, lines and points).
Flutter: no counterpart
Types ¶
type Atlas ¶
type Atlas[K comparable] struct { // contains filtered or unexported fields }
Atlas keeps track of where the 8-bit coverage tiles of a renderer's coverage atlas are (SPEC §9.1, "General paths"). The pages are squares of pageSize pixels that the renderer makes into textures. A page is cut into square slots of one size, so a freed slot is always reusable, and tiles are cached by key: the least recently used are evicted when the atlas is full, but never one that was used in the current frame, because the frame's draws still read it.
It does not touch the pixels; the renderer uploads a tile into its slot after Put. It is not safe for concurrent use.
Flutter: no counterpart (Skia's GrDrawOpAtlas)
func NewAtlas ¶
func NewAtlas[K comparable](pageSize, maxPages int) *Atlas[K]
NewAtlas makes an atlas of at most maxPages pages of pageSize pixels each. pageSize should be a multiple of MaxAtlasTile.
Flutter: no counterpart
func (*Atlas[K]) BeginFrame ¶
func (a *Atlas[K]) BeginFrame()
BeginFrame starts a frame: the tiles used from now on are protected from eviction until the next call.
Flutter: no counterpart
func (*Atlas[K]) Clear ¶
func (a *Atlas[K]) Clear()
Clear forgets every tile and every page.
Flutter: no counterpart
func (*Atlas[K]) Get ¶
func (a *Atlas[K]) Get(key K) *AtlasEntry[K]
Get returns the tile stored under key, or nil, and marks it used in this frame.
Flutter: no counterpart
func (*Atlas[K]) Pages ¶
Pages returns the number of pages made; the renderer keeps a texture for each.
Flutter: no counterpart
func (*Atlas[K]) Put ¶
func (a *Atlas[K]) Put(key K, w, h int) (*AtlasEntry[K], error)
Put stores a tile of w x h pixels under key and returns it; the caller uploads the pixels at (X, Y) of the page. A tile of no size is stored as an empty entry with no slot. The key must not be stored already. It fails with AtlasTileInvalid for a size that is negative or above MaxAtlasTile, and AtlasFull when every slot is in use in this frame and no page can be made.
Flutter: no counterpart
func (*Atlas[K]) Stats ¶
func (a *Atlas[K]) Stats() AtlasStats
Stats says what the atlas holds.
Flutter: no counterpart
type AtlasEntry ¶
type AtlasEntry[K comparable] struct { // Key is what the tile was stored under. Key K // Page is the index of the page the tile is on. Page int // X and Y are the top left corner of the tile's slot in the page, in pixels. X, Y int // W and H are the size of the tile's content, at the slot's corner. W, H int // Empty says that the tile holds nothing: it has no slot, and W and H are 0. // Storing the empty tiles keeps a renderer from rasterizing them again. Empty bool // OX and OY are free for the renderer to keep a tile's offset in; the atlas // does not use them. OX, OY int // contains filtered or unexported fields }
AtlasEntry is a tile of an Atlas: where it is, and how much of its slot it uses. An entry stays valid until the atlas evicts it, which only happens for entries that were not used in the current frame.
Flutter: no counterpart
type AtlasStats ¶
type AtlasStats struct {
// Pages is the number of pages made, Entries the number of tiles stored
// (including empty ones), and Evicted the number of tiles evicted so far.
Pages, Entries, Evicted int
}
AtlasStats says what an Atlas holds.
Flutter: no counterpart
type Clip ¶
type Clip struct {
// Bounds is the rectangle that everything drawn is cut to. Its edges are
// whole pixels, except for the edges of anti-aliased clips.
Bounds ui.Rect
// Shapes are the clips that are not folded into Bounds, in the order they were
// made. Treat the slice as read-only.
Shapes []ClipShape
}
Clip is the part of the surface that drawing may change. Bounds is a rectangle in pixels (whose edges are fractional when the clip is anti-aliased); Shapes narrow it further and are applied in order. A rectangle clip that the transform keeps axis-aligned is folded into Bounds, so that a renderer can use the scissor test; only the other shapes are listed.
Flutter: no counterpart
type ClipShape ¶
type ClipShape struct {
// Kind says which of the shape fields is used.
Kind ClipShapeKind
// Rect is the shape of ClipShapeRect.
Rect ui.Rect
// RRect is the shape of ClipShapeRRect.
RRect ui.RRect
// RSuperellipse is the shape of ClipShapeRSuperellipse.
RSuperellipse ui.RSuperellipse
// Path is the shape of ClipShapePath.
Path *ui.Path
// Difference says that the shape is cut out of the clip instead of being
// intersected with it.
Difference bool
// AntiAlias says whether the edge is smoothed.
AntiAlias bool
// Transform maps the shape to the surface.
Transform ui.Matrix4
}
ClipShape is a clip that is not a rectangle of pixels. The shape is in its own coordinates; Transform maps them to the surface.
Flutter: no counterpart
type ClipShapeKind ¶
type ClipShapeKind int
ClipShapeKind says what a ClipShape is.
Flutter: no counterpart
const ( // ClipShapeUnspecified is the zero value: not a shape. // // Flutter: no counterpart ClipShapeUnspecified ClipShapeKind = iota // ClipShapeRect is a rectangle that is not axis-aligned in the surface (the // transform rotates or skews it) or a rectangle that is subtracted // (Difference). // // Flutter: no counterpart ClipShapeRect // ClipShapeRRect is a rounded rectangle. // // Flutter: no counterpart ClipShapeRRect // ClipShapeRSuperellipse is a rounded superellipse. // // Flutter: no counterpart ClipShapeRSuperellipse // ClipShapePath is a path. // // Flutter: no counterpart ClipShapePath )
The kinds of clip shape.
type Command ¶
type Command struct {
// Kind says which fields are meaningful.
Kind CommandKind
// Op is the drawing operation of a CommandDraw, or the ui.OpSaveLayer of a
// CommandBeginLayer that a canvas made. Clips, transforms and Save are not
// commands: they are folded into Transform and Clip.
Op ui.DisplayOp
// Layer is the scene layer of a CommandBeginLayer that a scene made, or nil.
// Its Offset, if it has one, is already part of the transform of the commands
// inside the group.
Layer ui.Layer
// Transform maps the coordinates of Op to the surface's pixels. For a group it
// is the transform in effect where the group is composited.
Transform ui.Matrix4
// Clip is what may be drawn into. For CommandBeginLayer it is the clip the
// group is composited with, which for a clip layer with a save layer includes
// the layer's own shape.
Clip Clip
}
Command is one step of drawing, with the state it is drawn in. A renderer runs the commands of a DrawList in order.
Flutter: no counterpart
type CommandKind ¶
type CommandKind int
CommandKind says what a Command asks of a renderer.
Flutter: no counterpart
const ( // CommandKindUnspecified is the zero value: not a command. // // Flutter: no counterpart CommandKindUnspecified CommandKind = iota // CommandDraw draws one operation of a picture with the command's transform // and clip. // // Flutter: no counterpart CommandDraw // CommandBeginLayer starts a group that is drawn separately and composited at // the matching CommandEndLayer: a SaveLayer, or a scene layer that needs a // group (opacity, filters, masks, and clips with a save layer). // // Flutter: no counterpart CommandBeginLayer // CommandEndLayer ends the innermost group and composites it. // // Flutter: no counterpart CommandEndLayer )
The kinds of command.
type Damage ¶
type Damage struct {
// Full says that the whole surface may have changed; Rects is then empty.
Full bool
// Rects are the changed pixels, from the top left, when Full is false. There is
// none when the frame is the same as the one before it.
Rects []image.Rectangle
}
Damage is the part of a surface that a frame changed from the frame before it (SPEC §9.1, "Damage"): what a renderer tells the compositor when it presents.
Flutter: no counterpart (flutter::FrameDamage)
type DamageTracker ¶
type DamageTracker struct {
// contains filtered or unexported fields
}
DamageTracker finds what changed between the scenes of a surface. It divides the surface into tiles, and for each tile hashes what the scene draws there: every picture (by identity: a picture is immutable, and a layer that the framework did not repaint keeps its picture) with the transform it is drawn under, and the parameters of the layers around it (clips, opacity, filters). A tile whose hash differs from the last frame's is damaged. A picture that was recorded again is damaged even if it drew the same, and what the tracker cannot bound (a draw that fills the clip, an image filter on a layer, an unknown layer) damages the whole clip or the whole surface; it errs on the side of drawing more.
The tracker holds on to the last scene's pictures and parameters so that their addresses are not reused while they are compared. Use it on one thread.
Flutter: no counterpart (flutter::DiffContext)
func NewDamageTracker ¶
func NewDamageTracker() *DamageTracker
NewDamageTracker returns a tracker that has seen no frame, so that the first Update reports the whole surface.
Flutter: no counterpart
func (*DamageTracker) Invalidate ¶
func (t *DamageTracker) Invalidate()
Invalidate forgets the last frame: the next Update reports the whole surface. Call it when the pixels the compositor has are not the last frame's (the window lost its content, or a frame was drawn and not presented).
Flutter: no counterpart
func (*DamageTracker) Update ¶
func (t *DamageTracker) Update(scene *ui.Scene, w, h int) Damage
Update says what the scene changes from the scene given to the last call, for a surface of w x h pixels. The whole surface is reported for the first frame, after Invalidate, when the size changed, for the same scene again (a request to draw it once more means that the window needs all of it), and for a scene with something that depends on the pixels around it.
Flutter: no counterpart
type DrawList ¶
type DrawList struct {
// Commands are in drawing order; each CommandBeginLayer has a matching
// CommandEndLayer after it.
Commands []Command
}
DrawList is a scene flattened into the commands that draw it, in order.
Flutter: no counterpart (flutter::DisplayList of the whole layer tree)
func Flatten ¶
func Flatten(scene *ui.Scene, opts ...FlattenOpts) (*DrawList, error)
Flatten turns a scene into the list of commands that draws it. The layer tree and the pictures' operations are walked in painting order. Transforms and clips are folded into each command; layers that need a group become a pair of CommandBeginLayer and CommandEndLayer. Nothing is dropped: a renderer decides what it can draw. A clip that leaves nothing to draw does not remove the commands inside it; a renderer may skip a command whose Clip is empty.
It fails with FlattenSceneNil for a nil scene and FlattenLayerUnknown for a layer of a type it does not know.
Flutter: no counterpart (flutter::LayerTree::Preroll and Paint)
type FlattenOpts ¶
type FlattenOpts struct {
// Bounds is the surface in pixels; the clip starts as this rectangle. The zero
// value starts with an unbounded clip.
Bounds ui.Rect
// Boundary, when it is not nil, is asked about every ui.TransformLayer and
// ui.ContainerLayer (the layers Flatten folds into the commands under them),
// and a layer it answers true for becomes a group, so that a renderer can keep
// what the group draws for the next frame. The group is composited under the
// clip it is in, and what is inside it is drawn under a clip of whole pixels
// that has none of that clip's shapes, so that the group's pixels do not depend
// on them. The group's Command.Transform is the transform of its contents.
Boundary func(l ui.Layer) bool
}
FlattenOpts are the optional arguments of Flatten.
Flutter: no counterpart
type Renderer ¶
type Renderer interface {
// Attach starts drawing into a native surface. The first call creates the
// renderer's device.
Attach(SurfaceHandle) (Surface, error)
// Render draws the scene into the surface, at the given size in device pixels,
// and presents it. dpr is the device pixel ratio, which the scene's
// coordinates are already scaled by.
Render(s Surface, scene *ui.Scene, size ui.Size, dpr float32) error
// Snapshot draws the scene into a new image of the size, without a window:
// the work of Picture.ToImage and of the raster cache.
Snapshot(scene *ui.Scene, size ui.Size) (*image.RGBA, error)
// Close destroys every surface and the device.
Close() error
}
Renderer draws scenes. The GLES renderer (internal/gpu/gles) draws on the GPU; the software renderer (internal/gpu/soft) is the reference it is compared with. Only the UI thread calls a Renderer (SPEC §13).
Flutter: no counterpart (flutter::Rasterizer)
type Surface ¶
type Surface interface {
// Destroy releases the surface. It must be done before the native window is
// destroyed, and is safe to do twice.
Destroy()
}
Surface is a native drawing surface that a Renderer has attached to: the target that Render draws and presents into.
Flutter: no counterpart (flutter::Surface)
type SurfaceHandle ¶
type SurfaceHandle struct {
// Kind says how to read Display and Window.
Kind SurfaceKind
// Display is the native connection to the windowing system.
Display uintptr
// Window is the native window.
Window uintptr
}
SurfaceHandle identifies a native drawing surface. A platform backend creates it and only a GPU backend looks inside. Display and Window hold native addresses or IDs whose meaning depends on Kind; they are opaque to everyone else.
Flutter: no counterpart
type SurfaceKind ¶
type SurfaceKind string
SurfaceKind says which windowing system a SurfaceHandle belongs to, so that a GPU backend knows what Display and Window mean.
Flutter: no counterpart
const ( // SurfaceKindUnspecified is the zero value: no surface. // // Flutter: no counterpart SurfaceKindUnspecified SurfaceKind = "" // SurfaceKindWayland is a window of a Wayland compositor. Display is the // connection and Window the native window that the backend renders into. // // Flutter: no counterpart SurfaceKindWayland SurfaceKind = "wayland" // SurfaceKindX11 is a window of an X server. Display is the connection and // Window the window ID. // // Flutter: no counterpart SurfaceKindX11 SurfaceKind = "x11" // SurfaceKindFake is the surface of the scripted test platform. No GPU // backend renders into it. // // Flutter: no counterpart SurfaceKindFake SurfaceKind = "fake" )
The kinds of surface.
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
Package gles is the OpenGL ES 3.0 renderer.
|
Package gles is the OpenGL ES 3.0 renderer. |
|
Package soft is the pure-Go software rasterizer, used for golden tests and headless rendering.
|
Package soft is the pure-Go software rasterizer, used for golden tests and headless rendering. |
|
Package textdraw turns the drawing of a paragraph into ordinary drawing operations, for the renderers: each glyph is a path, drawn with its origin on a quarter of a pixel horizontally and on a pixel vertically, so that the coverage of a glyph at a size can be cached for the four subpixel positions (SPEC §9.1).
|
Package textdraw turns the drawing of a paragraph into ordinary drawing operations, for the renderers: each glyph is a path, drawn with its origin on a quarter of a pixel horizontally and on a pixel vertically, so that the coverage of a glyph at a size can be cached for the four subpixel positions (SPEC §9.1). |