cache

package
v1.5.0 Latest Latest
Warning

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

Go to latest
Published: Nov 25, 2026 License: BSD-3-Clause Imports: 13 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

Index

Constants

This section is empty.

Variables

View Source
var (
	ValidDuration = 1 * time.Minute

	// CleanHooks are additional cleanup functions called during each Clean() cycle.
	// Used to allow packages like painter to register cache sweeps without circular imports.
	CleanHooks []func()
)
View Source
var NoTexture = TextureType(0)
View Source
var RenderDeferredImage = func(core.CanvasObject) {}

RenderDeferredImage draws what a canvas.Image put off, at the image's size: the SVG it did not rasterize while it was not on screen (#1137), or a File or Resource set with no Refresh after it (#1298). It does nothing for any other object. The painters call it before they read an image's pixels; canvas sets it.

Functions

func CachedRenderer

func CachedRenderer(wid core.Widget) (core.WidgetRenderer, bool)

CachedRenderer looks up the cached render implementation for a widget If a renderer does not exist in the cache, it returns nil, false.

func Clean

func Clean(canvasRefreshed bool)

Clean run cache clean task, it should be called on paint events.

func CleanCanvas

func CleanCanvas(canvas core.Canvas)

CleanCanvas performs a complete remove of all the objects that belong to the specified canvas. Usually used to free all objects from a closing window. Also sweeps any expired renderers to avoid GPU resource leaks from widgets whose canvas entries expired before the canvas was closed.

func DeleteOverride added in v1.3.0

func DeleteOverride(o core.CanvasObject)

DeleteOverride removes one entry's theme scope. When the entry is an anchor (a widget or container the scope was applied to), the part of the walk it owns goes with it: the primitives its renderer reached would otherwise stay in the map for the life of the process once the subtree is dropped. The renderer cleanup paths go through here.

func DeleteTextTexturesFor

func DeleteTextTexturesFor(canvas core.Canvas)

DeleteTextTexturesFor deletes all text textures for the given canvas.

func DeleteTexture

func DeleteTexture(obj core.CanvasObject)

DeleteTexture deletes the texture from the cache map.

func DestroyRenderer

func DestroyRenderer(wid core.Widget)

DestroyRenderer frees a render implementation for a widget. This is typically for internal use only.

func GetCanvasForObject

func GetCanvasForObject(obj core.CanvasObject) core.Canvas

GetCanvasForObject returns the canvas for the specified object.

func GetFontMetrics

func GetFontMetrics(text string, fontSize float32, style bellui.TextStyle, source bellui.Resource) (size geo.Size, base float32)

GetFontMetrics looks up a calculated size and baseline required for the specified text parameters.

func GetSvg

func GetSvg(name string, o core.CanvasObject, w int, h int) *image.NRGBA

GetSvg gets svg image from cache if it exists.

func IsRendered

func IsRendered(wid core.Widget) bool

IsRendered returns true of the widget currently has a renderer. One will be created the first time a widget is shown but may be removed after it is hidden.

func IsValid

func IsValid(texture TextureType) bool

IsValid will return true if the passed texture is potentially a texture.

func NoteSelectableMode added in v1.2.0

func NoteSelectableMode(mode bellui.SelectableMode)

NoteSelectableMode records that a canvas's selectable mode was set to mode. Every canvas implementation calls it from SetSelectableMode.

func OverriddenObjects added in v1.3.0

func OverriddenObjects() int

OverriddenObjects returns the objects that currently hold a theme override scope. Tests and benchmarks use it to assert that an overridden subtree that is built and then dropped releases its entries (#741).

func OverrideTheme

func OverrideTheme(o core.CanvasObject, th bellui.Theme)

OverrideTheme allows an app to specify that a single object should use a different theme to the app. This should be used sparingly to avoid a jarring user experience. If the object is a container it will theme the children, if it is a canvas primitive it will do nothing.

Since: 1.0

func OverrideThemeFor added in v1.3.0

func OverrideThemeFor(o core.CanvasObject, th bellui.Theme, owner core.Widget)

OverrideThemeFor is OverrideTheme for a scope that owner keeps, replacing the scope owner kept before. The scope lives while owner has a renderer; when it has none, from the start or once its renderer is destroyed, the expiry sweep releases the scope after ValidDuration. Without an owner, a container's part of the scope would stay until its window closed, since a container has no renderer whose destruction releases it (#1065).

func OverrideThemeMatchingScope

func OverrideThemeMatchingScope(o, parent core.CanvasObject) bool

func PeekRenderer added in v1.3.0

func PeekRenderer(wid core.Widget) (core.WidgetRenderer, bool)

PeekRenderer is CachedRenderer without marking the renderer as in use: a walk that only reads the tree (the direction cache's, #749) must not keep the renderers of a subtree that left its window from expiring.

func RangeExpiredTexturesFor

func RangeExpiredTexturesFor(canvas core.Canvas, f func(core.CanvasObject))

RangeExpiredTexturesFor range over the expired textures for the specified canvas.

Note: If this is used to free textures, then it should be called inside a current gl context to ensure textures are deleted from gl.

func RangeTexturesFor

func RangeTexturesFor(canvas core.Canvas, f func(core.CanvasObject))

RangeTexturesFor range over the textures for the specified canvas. It will not return the texture for a `canvas.Text` as their render lifecycle is handled separately.

Note: If this is used to free textures, then it should be called inside a current gl context to ensure textures are deleted from gl.

func RegisterExtendedBy added in v1.3.0

func RegisterExtendedBy(f func(wid core.Widget) core.Widget)

RegisterExtendedBy adds f, which returns the widget wid's base widget was extended by, or nil when wid has no base widget or it was never extended.

func ReleaseObject added in v1.3.0

func ReleaseObject(obj core.CanvasObject, c core.Canvas)

ReleaseObject drops what the caches hold for obj on canvas c, as CleanCanvas does for every object of a closing canvas: its canvas-map entry and, for a widget, its renderer. A canvas calls it for content it replaced and no longer shows, which would otherwise stay until a Clean after a paint a minute later, and an idle app makes no such paint (#1075). An object the map gives to another canvas is shown there, and is left alone.

func ReleaseUnkept added in v1.3.0

func ReleaseUnkept(c core.Canvas, keep func(core.CanvasObject) bool) []core.CanvasObject

ReleaseUnkept releases, as ReleaseObject does, what the caches hold for every object keep does not report, except what the canvas map gives to a canvas other than c (#1075). c calls it when it has replaced content, with keep reporting what its trees still hold: the objects of the replaced content are then let go of at once, where a Clean waits for a paint a minute later. That includes what a widget holds outside its renderer's objects, which no walk from the replaced root reaches, such as the rows a list keeps for reuse or the buttons tabs measure.

A renderer whose widget no canvas has registered goes too: a widget the app keeps off screen, such as a pop-up it shows again, then gets a new renderer when it is next shown, as it does today after ValidDuration unshown.

It returns the objects it released, for c to free their GPU memory (#1082).

func RenderedWidgets added in v1.2.0

func RenderedWidgets() map[core.Widget]struct{}

RenderedWidgets returns the widgets that currently have a cached renderer. Tests and benchmarks use it to release, at the end, the renderers they created: a test canvas never registers its objects, so closing a test window leaves them cached for ValidDuration, and a benchmark that builds a large widget per run piled them up by the gigabyte (#508).

func Renderer

func Renderer(wid core.Widget) core.WidgetRenderer

Renderer looks up the render implementation for a widget. If one does not exist, it creates and caches a renderer for the widget. If two goroutines race to create the renderer, the loser's renderer is destroyed to prevent leaks.

func ResetThemeCaches

func ResetThemeCaches()

ResetThemeCaches clears all the svg and text size cache maps

func ResetWrapperWarningsForTests added in v1.3.0

func ResetWrapperWarningsForTests(t interface{ Cleanup(func()) })

ResetWrapperWarningsForTests clears the once-per-type set behind the wrapper warning, and clears it again when the test ends.

func SelectableModeSet added in v1.2.0

func SelectableModeSet() bool

SelectableModeSet reports whether any canvas may be in a selectable mode other than bellui.SelectablePerWidget.

func SetCanvasForObject

func SetCanvasForObject(obj core.CanvasObject, c core.Canvas, setup func())

SetCanvasForObject sets the canvas for the specified object. The passed function will be called if the item was not previously attached to this canvas. An object registered to another canvas is moved to this one: it is shown here now, so refreshes and focus must reach this canvas (#448).

func SetClockForTests added in v1.3.0

func SetClockForTests(t interface{ Cleanup(func()) }, now func() time.Time)

SetClockForTests makes now the clock Clean reads, takes a sample from it, and forgets when Clean last ran, so that the next Clean runs. The wall clock comes back when the test ends. It lets a test paint past ValidDuration without waiting for it.

func SetFontMetrics

func SetFontMetrics(text string, fontSize float32, style bellui.TextStyle, source bellui.Resource, size geo.Size, base float32)

SetFontMetrics stores a calculated font size and baseline for parameters that were missing from the cache.

func SetSvg

func SetSvg(name string, o core.CanvasObject, pix *image.NRGBA, w int, h int)

SetSvg sets a svg into the cache map.

func SetTextTexture

func SetTextTexture(ent FontCacheEntry, texture TextureType, canvas core.Canvas, free func())

SetTextTexture sets cached texture for a text run.

func SetTexture

func SetTexture(obj core.CanvasObject, texture TextureType, canvas core.Canvas)

SetTexture sets cached texture.

func ThemeCacheGeneration

func ThemeCacheGeneration() uint64

ThemeCacheGeneration returns a counter bumped each time the theme/font caches are reset (ResetThemeCaches). A widget-level measurement memo compares this against the generation it was built under and drops itself when it differs, so it stays consistent with the authoritative global metrics cache (pre-rebrand tracker #896).

func WidgetScopeID

func WidgetScopeID(o core.CanvasObject) string

func WidgetTheme

func WidgetTheme(o core.CanvasObject) bellui.Theme

Types

type CanvasRegistration added in v1.2.0

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

CanvasRegistration is the entry the canvas map holds for an object, as RegisterCanvasForObject returns it. A walk that keeps it can skip the map lookup while Current reports true (#487).

func RegisterCanvasForObject added in v1.2.0

func RegisterCanvasForObject(obj core.CanvasObject, c core.Canvas, setup func()) CanvasRegistration

RegisterCanvasForObject is SetCanvasForObject, and returns the entry the map holds for obj afterwards.

func (CanvasRegistration) Current added in v1.2.0

func (r CanvasRegistration) Current(c core.Canvas) bool

Current reports whether the entry still maps its object to c and has not expired. Such an entry cannot have been deleted: Clean deletes only entries that expired before the clock sample it cuts off at, which is never later than the one read here, CleanCanvas only the entries of a canvas being closed, whose walks end with it, and ReleaseObject expires the entry it deletes. Nor replaced: moving an object to another canvas expires the entry it replaces.

type FontCacheEntry

type FontCacheEntry struct {
	Canvas core.Canvas
	Color  color.Color
	// contains filtered or unexported fields
}

FontCacheEntry is the cache key for rendered text textures.

func NewFontCacheEntry

func NewFontCacheEntry(text string, fontSize float32, style bellui.TextStyle, source string, canvas core.Canvas, col color.Color) FontCacheEntry

NewFontCacheEntry builds a FontCacheEntry from a text object's properties.

type TextureType

type TextureType = uint32

TextureType is an opaque WebGPU texture handle under the `webgpu` build: a uint32 registry key into the webgpu painter's texture table (internal/painter/ webgpu/texture.go), used uniformly on every platform (desktop/wasm/mobile) instead of the GL-specific gl.Texture types. The desktop GL path already used uint32 here, so this only changes wasm/mobile webgpu builds.

func GetTextTexture

func GetTextTexture(ent FontCacheEntry) (TextureType, bool)

GetTextTexture gets cached texture for a text run.

func GetTexture

func GetTexture(obj core.CanvasObject) (TextureType, bool)

GetTexture gets cached texture.

Jump to

Keyboard shortcuts

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