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 ¶
- func EaseDuration(dist float64) float64
- 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) PageBand() (y0, y1 int)
- 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) SetPageAt(src *image.RGBA, originY int) (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
- func (s *Scroller) Animating() bool
- func (s *Scroller) EaseBy(dy float64)
- func (s *Scroller) EaseByAt(dy, now float64)
- func (s *Scroller) EaseTo(y float64)
- func (s *Scroller) EaseToAt(y, now float64)
- func (s *Scroller) Precise(dy float64)
- func (s *Scroller) PreciseAt(dy, now float64)
- func (s *Scroller) Reset(p float64)
- func (s *Scroller) ScrollTo(y float64, instant bool)
- func (s *Scroller) SetClock(f func() float64)
- func (s *Scroller) SetMax(m float64)
- func (s *Scroller) Stop()
- func (s *Scroller) Tick(dt float64) int
- func (s *Scroller) TickAt(now float64) int
- func (s *Scroller) TickNow() int
- func (s *Scroller) Wheel(dy float64)
- type Stats
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func EaseDuration ¶
EaseDuration is how long an eased move over dist px takes (seconds).
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) PageBand ¶
func (c *Compositor) PageBand() (y0, y1 int)
PageBand returns the document rows (device px) the page texture covers: [y0, y1).
func (*Compositor) PageHeight ¶
func (c *Compositor) PageHeight() int
PageHeight is the document row just below the last painted row, 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) SetPageAt ¶
SetPageAt installs src as the band of the document that starts at document row originY (device px). Rows outside the band show the background until a band that covers them is installed; scrolling never needs the band to start at the top of the page.
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 time constant in seconds of the spring (settle time is about 4 Tau; smaller is snappier).
Tau float64
// FlingTau is the decay time constant of a fling in seconds.
FlingTau float64
// Smooth false jumps straight to the target and never flings.
Smooth bool
// contains filtered or unexported fields
}
Scroller turns scroll input into smooth, pixel-based motion. It only needs ticking while Animating() is true, so a still page costs no CPU. Everything is in device pixels and time is passed in (seconds on any monotonic clock), so the physics is deterministic and testable.
Four kinds of motion, chosen by the input that starts them:
- Spring (a mouse-wheel notch, an arrow key): the target moves by the delta and the position follows it with a critically damped spring, so quick repeated input accumulates, keeps its speed from one notch to the next and never overshoots.
- Direct (a precision touchpad: precise pixel deltas): the position follows the fingers exactly. When the deltas stop and the last ones were fast, the gesture ends in a fling.
- Fling: the speed measured at the end of a direct gesture decays exponentially (Tau) until the view stops or reaches an edge.
- Ease (PageUp/PageDown/Space, Home/End, programmatic smooth scrolling, anchor jumps): a timed move along a cubic-bezier ease curve whose duration grows with the distance.
func (*Scroller) EaseBy ¶
EaseBy eases by dy from where the view is going (the target of a running ease or spring), so repeated page keys add up instead of restarting.
func (*Scroller) EaseTo ¶
EaseTo starts a timed move from the current position to y (clamped) along the standard ease curve. A move that is already running is retargeted from where it is.
func (*Scroller) Precise ¶
Precise applies a pixel-accurate delta from a precision touchpad: the view follows the fingers, and when they lift at speed the gesture continues as a fling.
func (*Scroller) ScrollTo ¶
ScrollTo sets the target absolutely (scrollbar drag, restore, programmatic jump). instant moves there at once; otherwise the move is a short eased one.
func (*Scroller) Stop ¶
func (s *Scroller) Stop()
Stop halts any motion where it is (a click, a key press, a touch down stops a fling).
func (*Scroller) Tick ¶
Tick advances a virtual clock by dt seconds and returns the integer position: the call for fixed-step callers and tests. Callers with real timestamps use TickAt.
type Stats ¶
type Stats struct {
Frames int
Blank int // frames that showed document rows the page texture did not cover yet
Compose Percentiles
Paint map[string]Percentiles
}
Stats is the frame timing report (`sweef gui --stats`).