Documentation
¶
Overview ¶
Package compositor stitches the chrome layer, the page texture and an optional alpha overlay into one RGBA frame.
Layers (bottom to top):
- page: a tall RGBA texture (the whole document, or a capped prefix) painted once per page change, shown in the viewport rectangle. Scrolling just moves a window over it, so scrolling never calls the engine and costs one memcpy. Outside the viewport (and below a short page) the background colour shows.
- chrome: window-sized premultiplied RGBA painted from the chrome page with a transparent canvas. Where the chrome draws nothing (the `#viewport` hole) the page shows through; anything the chrome draws over the hole (omnibox dropdown, find bar, toasts, popovers) is alpha-blended on top of the page.
- overlay: a premultiplied-alpha surface (the agent overlay) blended over the result with a global opacity for fades.
Damage tracking is exact: SetChrome/SetPage diff the new pixels against the old ones and only the bounding box of real changes is recomposed and handed to Present. Compose allocates nothing in steady state.
All coordinates are device pixels. Callers convert from logical pixels with the window scale.
Index ¶
- type Compositor
- func (c *Compositor) ChromeAlphaAt(x, y int) uint8
- func (c *Compositor) Compose() (*image.RGBA, image.Rectangle)
- func (c *Compositor) CopyFrame() *image.RGBA
- func (c *Compositor) Dirty() bool
- func (c *Compositor) Frame() *image.RGBA
- func (c *Compositor) Gen() int
- func (c *Compositor) Invalidate(r image.Rectangle)
- func (c *Compositor) PageHeight() int
- func (c *Compositor) RecordPaint(kind string, d time.Duration)
- func (c *Compositor) Resize(w, h int, scale float64)
- func (c *Compositor) Scroll() (pos, max int)
- func (c *Compositor) ScrollTo(y int) bool
- func (c *Compositor) SetBackground(col color.RGBA)
- func (c *Compositor) SetChrome(src *image.RGBA) (spare *image.RGBA)
- func (c *Compositor) SetDocHeight(h int)
- func (c *Compositor) SetOverlay(img *image.RGBA, at image.Point, alpha uint8)
- func (c *Compositor) SetPage(src *image.RGBA) (spare *image.RGBA)
- func (c *Compositor) SetScrollbar(a uint8)
- func (c *Compositor) SetViewport(r image.Rectangle)
- func (c *Compositor) Size() (w, h int, scale float64)
- func (c *Compositor) SnapshotPage(dst *image.RGBA) (*image.RGBA, int)
- func (c *Compositor) SnapshotWindow(dst *image.RGBA) (*image.RGBA, int)
- func (c *Compositor) Stats() Stats
- func (c *Compositor) Viewport() image.Rectangle
- type Percentiles
- type Scroller
- type Stats
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Compositor ¶
type Compositor struct {
// contains filtered or unexported fields
}
Compositor is safe for concurrent use; every method takes one mutex, held only for pixel copies.
func New ¶
func New(w, h int, scale float64) *Compositor
New returns a compositor for a w x h device-pixel window.
func (*Compositor) ChromeAlphaAt ¶
func (c *Compositor) ChromeAlphaAt(x, y int) uint8
ChromeAlphaAt returns the chrome layer's opacity at a device pixel (0 where the chrome draws nothing, so the page is visible and gets the pointer).
func (*Compositor) Compose ¶
func (c *Compositor) Compose() (*image.RGBA, image.Rectangle)
Compose redraws the damaged region of the frame and returns the frame and the damage rectangle (empty when nothing changed). The frame is only valid until the next call that mutates the compositor, so Present must copy it (shell.Window.Present is documented not to retain it).
func (*Compositor) CopyFrame ¶
func (c *Compositor) CopyFrame() *image.RGBA
CopyFrame returns a copy of the current frame.
func (*Compositor) Dirty ¶
func (c *Compositor) Dirty() bool
Dirty reports whether Compose has work to do.
func (*Compositor) Frame ¶
func (c *Compositor) Frame() *image.RGBA
Frame returns the last composed frame (for screenshots).
func (*Compositor) Gen ¶
func (c *Compositor) Gen() int
Gen counts the frames composed with real damage. A capture source compares it with the value it saw last and resends its previous frame when nothing changed instead of converting identical pixels again.
func (*Compositor) Invalidate ¶
func (c *Compositor) Invalidate(r image.Rectangle)
Invalidate marks a region (or everything, when empty) as needing recompose.
func (*Compositor) PageHeight ¶
func (c *Compositor) PageHeight() int
PageHeight is the texture height in device px (0 without a page).
func (*Compositor) RecordPaint ¶
func (c *Compositor) RecordPaint(kind string, d time.Duration)
RecordPaint stores how long an external paint (kind "chrome" or "page") took, so Stats can report it next to the compose time.
func (*Compositor) Resize ¶
func (c *Compositor) Resize(w, h int, scale float64)
Resize changes the window size (device px) and scale; everything is damaged and the chrome must be repainted by the caller.
func (*Compositor) Scroll ¶
func (c *Compositor) Scroll() (pos, max int)
Scroll returns the scroll offset and its maximum (device px).
func (*Compositor) ScrollTo ¶
func (c *Compositor) ScrollTo(y int) bool
ScrollTo sets the scroll offset; it reports whether the view moved.
func (*Compositor) SetBackground ¶
func (c *Compositor) SetBackground(col color.RGBA)
SetBackground sets the colour shown below the end of a short page.
func (*Compositor) SetChrome ¶
func (c *Compositor) SetChrome(src *image.RGBA) (spare *image.RGBA)
SetChrome installs new chrome pixels (premultiplied RGBA, transparent where the chrome draws nothing). The compositor takes ownership of src and returns its previous buffer for reuse (nil on the first call or a size change). Damage becomes the bounding box of the pixels that actually changed.
func (*Compositor) SetDocHeight ¶
func (c *Compositor) SetDocHeight(h int)
SetDocHeight tells the compositor the full document height (device px). The page texture may be shorter (it is painted ahead of the scroll position); the scroll range follows the document.
func (*Compositor) SetOverlay ¶
SetOverlay shows img at position at with global opacity alpha (0..255). img must be premultiplied RGBA. A nil img or alpha 0 hides the overlay. The surface is referenced, not copied; call it again after mutating it.
func (*Compositor) SetPage ¶
func (c *Compositor) SetPage(src *image.RGBA) (spare *image.RGBA)
SetPage installs new page pixels (the whole document or a prefix). The compositor takes ownership and returns the previous texture for reuse. Damage is the changed part of the visible window.
func (*Compositor) SetScrollbar ¶
func (c *Compositor) SetScrollbar(a uint8)
SetScrollbar sets the overlay scrollbar opacity (0 hides it).
func (*Compositor) SetViewport ¶
func (c *Compositor) SetViewport(r image.Rectangle)
SetViewport sets the hole rectangle (device px).
func (*Compositor) Size ¶
func (c *Compositor) Size() (w, h int, scale float64)
Size returns the device-pixel size.
func (*Compositor) SnapshotPage ¶
SnapshotPage copies what the viewport shows of the page texture, at the current scroll position, without the chrome and its popovers drawn over it. It is the "this tab" source: a permission prompt or the site-info popover never ends up in a shared tab.
func (*Compositor) SnapshotWindow ¶
SnapshotWindow copies the last composed frame (chrome, page and overlay: the whole browser window) into dst, allocating when dst is nil or the wrong size, and returns it with the generation it shows.
func (*Compositor) Stats ¶
func (c *Compositor) Stats() Stats
Stats returns timing over the last 256 samples of each series.
func (*Compositor) Viewport ¶
func (c *Compositor) Viewport() image.Rectangle
Viewport returns the current hole.
type Percentiles ¶
Percentiles summarises a set of durations.
type Scroller ¶
type Scroller struct {
Pos, Target float64 // device px
Max float64
// Tau is the easing time constant in seconds (smaller = snappier).
Tau float64
// Smooth false jumps straight to the target.
Smooth bool
}
Scroller turns wheel input into smooth, pixel-based motion with easing. It only needs ticking while Animating() is true, so a still page costs no CPU.
type Stats ¶
type Stats struct {
Frames int
Compose Percentiles
Paint map[string]Percentiles
}
Stats is the frame timing report (`sweef gui --stats`).