compositor

package
v0.1.0-alpha.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 14, 2026 License: Apache-2.0 Imports: 7 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package compositor stitches the chrome layer, the page texture and an optional alpha overlay into one RGBA frame.

Layers (bottom to top):

  1. 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.
  2. 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.
  3. 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

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

func (c *Compositor) SetOverlay(img *image.RGBA, at image.Point, alpha uint8)

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

func (c *Compositor) SnapshotPage(dst *image.RGBA) (*image.RGBA, int)

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

func (c *Compositor) SnapshotWindow(dst *image.RGBA) (*image.RGBA, int)

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

type Percentiles struct {
	N             int
	P50, P99, Max time.Duration
}

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.

func NewScroller

func NewScroller() *Scroller

NewScroller returns a smooth scroller.

func (*Scroller) Animating

func (s *Scroller) Animating() bool

Animating reports whether Tick still has movement to do.

func (*Scroller) Reset

func (s *Scroller) Reset(p float64)

Reset puts both position and target at p.

func (*Scroller) ScrollTo

func (s *Scroller) ScrollTo(y float64, instant bool)

ScrollTo sets the target absolutely (keyboard, scrollbar drag).

func (*Scroller) SetMax

func (s *Scroller) SetMax(m float64)

SetMax updates the scroll range and clamps.

func (*Scroller) Tick

func (s *Scroller) Tick(dt float64) int

Tick advances by dt seconds and returns the integer position.

func (*Scroller) Wheel

func (s *Scroller) Wheel(dy float64)

Wheel adds a pixel delta (positive = scroll down).

type Stats

type Stats struct {
	Frames  int
	Compose Percentiles
	Paint   map[string]Percentiles
}

Stats is the frame timing report (`sweef gui --stats`).

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL