Help us shape the future of Go! Take the 2026 Go Developer Survey

renderstate

package
v0.1.7 Latest Latest
Warning

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

Go to latest
Published: Oct 30, 2026 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Overview

Package renderstate 管理单次绘制的资源预算、诊断聚合与报告快照。 每份 Budget 由一次同步遍历持有;缓存中的预算仅用于读取已完成的用量。

Index

Constants

View Source
const (
	// MaxCompositeExpansions 限制一次遍历的复合图元展开总数。
	MaxCompositeExpansions = 10000
	// MaxCompositeResourceExpansions 限制同一复合资源的重复展开。
	MaxCompositeResourceExpansions = 256
	// MaxPatternTiles 限制一次遍历的底纹图块总数。
	MaxPatternTiles = 100000
	// MaxOffscreenPixels 限制一次遍历累计分配的离屏像素。
	MaxOffscreenPixels = 200000000
)
View Source
const MaxDiagnostics = 128

MaxDiagnostics 限制一份报告保留的诊断条目数,超出后只累计 Dropped。

Variables

This section is empty.

Functions

This section is empty.

Types

type Budget

type Budget struct {
	Report               *ReportBuilder
	ObjectID, ResourceID models.StID
	// contains filtered or unexported fields
}

Budget 保存本次遍历的额度及诊断位置。Report 为 nil 时不收集报告。 ObjectID 和 ResourceID 由调用方在进入、退出图元时保存和恢复。

func (*Budget) AddUsage

func (b *Budget) AddUsage(usage *Budget)

AddUsage 在 CanReuse 通过且缓存内容已绘制后累加用量。 不更新报告统计;收集逐图元报告时,调用方应直接遍历而非复用缓存表面。

func (*Budget) AllowComposite

func (b *Budget) AllowComposite(resourceID models.StID) bool

AllowComposite 在展开前累计复合图元用量,超限时保留已消费额度。

func (*Budget) AllowOffscreenPixels

func (b *Budget) AllowOffscreenPixels(width, height, dpi float64) bool

AllowOffscreenPixels 在分配前按毫米尺寸和 DPI 累计离屏像素。

func (*Budget) AllowPatternTiles

func (b *Budget) AllowPatternTiles(count int) bool

AllowPatternTiles 在绘制前累计图块数。

func (*Budget) CanReuse

func (b *Budget) CanReuse(usage *Budget) bool

CanReuse 判断缓存内容的用量能否计入当前剩余额度,不修改任一预算。

func (*Budget) CompositeCount

func (b *Budget) CompositeCount(resource models.StID) int

CompositeCount 返回指定复合资源已展开的次数。

func (*Budget) Diagnose

func (b *Budget) Diagnose(code, message string, resource models.StID)

Diagnose 按原因、对象与资源合并计数,并限制诊断条目及消息长度。

func (*Budget) HasUsage

func (b *Budget) HasUsage() bool

HasUsage 判断本次遍历是否已消费资源预算。

func (*Budget) ReportLimit

func (b *Budget) ReportLimit(flag Limit, reason string, attrs ...any)

ReportLimit 对每种拒绝原因仅输出一次 Debug 日志,报告仍按诊断事件累计次数。

func (*Budget) Reset

func (b *Budget) Reset()

Reset 清空用量、诊断位置与报告关联,复用资源计数表。

func (*Budget) Usage

func (b *Budget) Usage() Stats

Usage 返回当前资源用量的独立值;图元访问数由报告统计,不计入此处。

type Diagnostic

type Diagnostic struct {
	Code       string
	Message    string
	ObjectID   models.StID
	ResourceID models.StID
	Count      int
}

Diagnostic 是一次绘制中的可恢复问题;同一原因、对象和资源会合并计数。

type Limit

type Limit uint8

Limit 标识日志去重所用的预算拒绝原因。

const (

	// LimitPatternTiles 也用于平铺计划在分配前发现索引或数量超限的情况。
	LimitPatternTiles Limit
)

type Report

type Report struct {
	PageID      models.StID
	Stats       Stats
	Diagnostics []Diagnostic
	// Dropped 是超过条目上限后未保存的诊断事件数。
	Dropped int
}

Report 是单次绘制的独立快照,不记录到共享文档或全局日志处理器。

type ReportBuilder

type ReportBuilder struct {
	Report
	// contains filtered or unexported fields
}

ReportBuilder 聚合单次绘制的诊断,零值可用。

func (*ReportBuilder) Snapshot

func (r *ReportBuilder) Snapshot() Report

Snapshot 返回独立的报告副本,调用方修改诊断切片不会污染聚合器。

type Stats

type Stats struct {
	ObjectsVisited      int
	CompositeExpansions int
	PatternTiles        int
	OffscreenPixels     float64
}

Stats 统计绘制遍历和计入预算的工作,离屏重画重复计数。 它不是静态图元总数或内存峰值;OffscreenPixels 仅包含计入渲染预算的离屏像素。

Jump to

Keyboard shortcuts

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