engine

package
v1.17.11 Latest Latest
Warning

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

Go to latest
Published: Nov 22, 2026 License: BSD-3-Clause Imports: 32 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 engine wires the platform, the renderer and the text layout into the contracts of package ui, and owns the run loop.

Flutter: the engine (engine/src/flutter/shell), which has no Dart library.

Index

Constants

View Source
const (
	// GamepadsAuto (the empty value is the same) starts the gamepad service with the app, so that a pad moves the focus of every
	// app, but the service only reads: nothing is written to a pad until the app uses package gamepad.
	GamepadsAuto = "auto"
	// GamepadsOnDemand starts nothing until the app first uses package gamepad; until then there are no pad key events.
	GamepadsOnDemand = "ondemand"
	// GamepadsOff never starts the service: there are no pads and no pad key events.
	GamepadsOff = "off"
)

The modes of Config.Gamepads.

View Source
const (
	// ScreenshotEnv names the file to save the window content to. When it is set,
	// the app saves a PNG of its window and exits with code 0.
	ScreenshotEnv = "GLUTTER_SCREENSHOT"
	// ScreenshotAfterEnv delays the capture by a duration such as "500ms", to
	// catch an animation midway.
	ScreenshotAfterEnv = "GLUTTER_SCREENSHOT_AFTER"
)

Environment variables of the self-capture used for proof screenshots (docs/IMPLEMENTATION.md, proof method B).

View Source
const DamageEnv = "GLUTTER_DAMAGE"

DamageEnv is the environment variable that, set to "0", stops the GPU renderer from telling the compositor what changed in a frame, as Config.DisableDamage does.

Flutter: no counterpart

View Source
const DecorationsEnv = "GLUTTER_DECORATIONS"

DecorationsEnv is the environment variable that chooses how the title bar of the first window is made: "auto" (the default), "app", or "libdecor" (libdecor even where the compositor has title bars of its own, to try it).

Flutter: no counterpart

View Source
const FrameStatsEnv = "GLUTTER_FRAME_STATS"

FrameStatsEnv is the environment variable that, set to "1", makes the engine log a line every second with the frames it drew: how many, the average and the worst time to build and to draw a frame, and how many took longer than 1/60 s. scripts/perf.sh reads it.

Flutter: no counterpart

View Source
const GamepadsEnv = "GLUTTER_GAMEPADS"

GamepadsEnv is the environment variable that sets the gamepad mode of a run: "auto", "ondemand" or "off". It overrides Config.Gamepads, so a user can turn the pads off for one run of any app (SPEC §28.2, "Decided in step 36.1").

View Source
const RasterCacheEnv = "GLUTTER_RASTER_CACHE"

RasterCacheEnv is the environment variable that, set to "0", turns off the raster cache of the GPU renderer, as Config.DisableRasterCache does.

Flutter: no counterpart

View Source
const RendererEnv = "GLUTTER_RENDERER"

RendererEnv is the environment variable that chooses the renderer, as Config.Renderer does (SPEC §9.6): "auto" (the default), or the name of a renderer. Linux has "vulkan", "gles" and "soft"; the web has "webgpu", "webgl" and "soft"; Windows has "d3d12" and "soft".

Flutter: no counterpart

Variables

This section is empty.

Functions

func PlatformConfiguration

func PlatformConfiguration(s platform.Settings) ui.PlatformConfiguration

PlatformConfiguration turns the platform's settings into the dispatcher's. The engine does it for every OnSettings; tests of the layers above use it to stand in for the engine.

Flutter: no counterpart

func Run

func Run(ctx context.Context, cfg Config) (err error)

Run connects to the display (Wayland or X11, SPEC §6.3 rule 5), opens the first window and draws it, and runs the event loop on the calling goroutine, which must be the UI thread. It returns nil when ctx is cancelled or the last window is closed; a ctx that ended before the call returns nil at once, before it connects to the display. When GLUTTER_SCREENSHOT is set it saves a PNG of the window and returns (see Screenshot).

Errors come back unchanged: NoDisplay, BackendUnknown, the backend's own (WaylandConnectFailed, X11OpenDisplayFailed, LibraryLoadFailed, ...), the renderer's (EGLLoadFailed, EGLNoConfig, GLES3Unsupported, ...) and the screenshot's.

The engine owns a ui.PlatformDispatcher: it reports the views, the input, the settings, the lifecycle and the frames to it, and draws the scenes that the framework renders into a view. A frame the framework did not render into draws the previous scene again, because the platform needs one presented frame for each frame it asks for (platform.Window.RequestFrame).

Flutter: engine/src/flutter/shell (the shell that runs an app)

func SystemFontMatcher

func SystemFontMatcher(ctx context.Context, log *slog.Logger) text.Matcher

SystemFontMatcher returns the font matcher of the machine: libfontconfig, so that the family names, the user's UI font, and the emoji, CJK and per-language preferences follow the fontconfig settings, as Flutter's Linux engine does. It returns nil, and logs why, when fontconfig is not there; the text.Collection then scans the font directories.

Flutter: no counterpart

Types

type Config

type Config struct {
	// Backend, when not empty, is "wayland" or "x11" and overrides the
	// GLUTTER_BACKEND environment variable.
	Backend string
	// Renderer, when not empty, is "auto", or the name of the renderer to use
	// ("vulkan", "gles" or "soft" on Linux, "d3d12" or "soft" on Windows), and overrides the GLUTTER_RENDERER environment
	// variable. Empty means "auto": the first candidate of the OS that presents its
	// first frame. A renderer asked for by name never falls back (SPEC §9.6).
	Renderer string
	// Window is the first window. The zero value gets platform.DefaultWindowConfig
	// with the title "Glutter".
	Window platform.WindowConfig
	// Logger gets the engine's log; slog.Default() when nil.
	Logger *slog.Logger
	// Getenv reads the environment (backend choice, self-capture); os.Getenv when
	// nil.
	Getenv func(string) string
	// ShaderCacheDir is the directory of the shader cache (the program binaries of GLES and the pipeline
	// cache of Vulkan, SPEC §9.7); the default is $XDG_CACHE_HOME/glutter/shaders. GLUTTER_SHADER_CACHE=0 turns
	// the cache off whatever this says.
	ShaderCacheDir string
	// QuitOnLastWindowClosed says that Run returns when the last window is closed. None means true, as on
	// Linux and Windows. On macOS, false keeps the app running in the Dock without a window, which is the
	// convention of an app with a tray icon and of a document app (SPEC §29.4); other platforms ignore it.
	QuitOnLastWindowClosed foundation.Opt[bool]
	// ShmFill is a development aid: on Wayland the window draws a solid color
	// through wl_shm and never asks the engine for a frame. X11 has no such mode.
	ShmFill bool
	// Hooks watch the engine.
	Hooks Hooks
	// Scene, when set, makes the scene each frame draws, with the GPU renderer.
	// Without it the window is filled with a development color.
	Scene SceneFunc
	// SkipUnsupported makes the renderer leave out what it cannot draw yet instead
	// of ending Run with GLNotImplemented; the log says what was left out.
	SkipUnsupported bool
	// DisableRasterCache turns off the raster cache of the GPU renderer (the layers
	// that RepaintBoundary retains for three frames are drawn as textures). The
	// GLUTTER_RASTER_CACHE environment variable set to "0" does the same.
	DisableRasterCache bool
	// DisableDamage stops the GPU renderer from telling the compositor which part of
	// the window changed (eglSwapBuffersWithDamage). GLUTTER_DAMAGE set to "0" does
	// the same.
	DisableDamage bool
	// Gamepads is the gamepad mode: "auto" (the default, also when empty), "ondemand" or "off" (GamepadsAuto, GamepadsOnDemand and
	// GamepadsOff). GLUTTER_GAMEPADS overrides it. A value that is no mode is GamepadsModeUnknown (SPEC §28.2).
	Gamepads string
	// Start, when set, is called once on the UI thread, after the first window
	// exists and the dispatcher knows its view, the settings and the displays,
	// and before the event loop runs. The framework attaches itself to the
	// dispatcher here (its callbacks, then ScheduleFrame). An error ends Run
	// with that error. Start replaces Scene: a Scene is drawn only when Start is
	// nil.
	Start func(d *ui.PlatformDispatcher) error
	// Stop, when set, is called once on the UI thread when the event loop has ended and the renderer and the
	// device are still open: the framework takes its widgets down here, so that what their states hold (the
	// resources of a GPU view) is released before the device is closed. It is called even when the loop ended
	// with an error, and not when Start failed.
	Stop func()
	// contains filtered or unexported fields
}

Config tells Run what to do.

Flutter: no counterpart

type Hooks

type Hooks struct {
	// Window is called once, when the first window exists, with the window and a
	// function that ends Run.
	Window func(win platform.Window, stop func())
	// Key gets each key event.
	Key func(ui.KeyData)
	// Pointer gets each batch of pointer data.
	Pointer func([]ui.PointerData)
	// Metrics gets the size and scale of the window when they change.
	Metrics func(view ui.ViewID, metrics platform.ViewMetrics)
}

Hooks let a development example watch the engine and take part in it, until the framework does. Every hook is optional, and is called on the UI thread.

Flutter: no counterpart

type SceneFunc

type SceneFunc func(size ui.Size, dpr float64) *ui.Scene

SceneFunc makes the scene of a frame. It gets the size of the window in physical pixels and its device pixel ratio, and is called on the UI thread for each frame the window draws.

Flutter: no counterpart (the framework's PlatformDispatcher.onDrawFrame)

type Screenshot

type Screenshot struct {
	// contains filtered or unexported fields
}

Screenshot is a pending capture of the window content to a PNG file.

Flutter: no counterpart

func ScreenshotFromEnv

func ScreenshotFromEnv(getenv func(string) string) (*Screenshot, error)

ScreenshotFromEnv reads GLUTTER_SCREENSHOT and GLUTTER_SCREENSHOT_AFTER with getenv (os.Getenv in an app). It returns nil when no capture is asked for. A delay that is not a non-negative duration fails with ScreenshotAfterInvalid.

Flutter: no counterpart

func (*Screenshot) After

func (s *Screenshot) After() time.Duration

After returns how long to wait, after the first frame was presented, before capturing.

Flutter: no counterpart

func (*Screenshot) Encode

func (s *Screenshot) Encode(img *image.RGBA) ([]byte, error)

Encode returns img as a PNG. It fails with ScreenshotWriteFailed. A platform that cannot write files hands the bytes to the host instead of calling Save (platform.ScreenshotPoster).

Flutter: no counterpart

func (*Screenshot) Path

func (s *Screenshot) Path() string

Path returns the file the PNG is written to.

Flutter: no counterpart

func (*Screenshot) Save

func (s *Screenshot) Save(img *image.RGBA) error

Save writes img to the file as a PNG, creating the directory if needed, and logs the path. It fails with ScreenshotWriteFailed.

Flutter: no counterpart

Jump to

Keyboard shortcuts

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