@yft-design/engine 0.0.6 → 0.0.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -473,8 +473,10 @@ export class EngineCanvas {
473
473
  // 批次 46:消费上一帧图集 settle 上报的 family(排版/度量/烘焙失效)——
474
474
  // 必须在 markFrame 前:settle 触发点在渲染中途,失效只能延到帧外的安全位
475
475
  this.fontInvalidation.consumePendingSettle();
476
- // 帧界推进(P6-2 纹理内存预算):纹理缓存 LRU 帧界保护与图集页回收的结算边界
477
- this.textures.markFrame();
476
+ // 帧界推进(P6-2 纹理内存预算):纹理缓存 LRU 帧界保护与图集页回收的结算边界。
477
+ // gestureActive:指针手势期冻结插入压力淘汰(思阳素材病型——保留式帧让活动
478
+ // 大图不 touch,拖动中烘焙插入会逐出大图引发 490MiB 级重传死循环)
479
+ this.textures.markFrame(this.pointerActive);
478
480
  this.glyphAtlas.markFrame();
479
481
  // 拖拽吸附帧率化结算(P5-2,main renderAll 入口同构):必须在场景渲染前——
480
482
  // 结算按「本帧最后一次 pointermove 的位置」计算并磁吸改位,改位计入本帧
@@ -866,6 +866,15 @@ export class TextNode extends SceneNode {
866
866
  * 字形/装饰线/背景高亮/光标/选区/阴影烘焙统一消费此口径。
867
867
  */
868
868
  get contentTopY() {
869
+ // 批次 370:位图态 dims=文档系位图 AABB(bitmapRect)——竖排/±90° 元素本地系
870
+ // 与文档系轴向互换(本地 Y=文档 X),而本值的消费面(编辑态字形/光标/选区/
871
+ // 划重点/剪影)全部工作在预旋本地系:块顶须锚排版内容高,位图盒高会把整块
872
+ // 沿本地 −Y(竖排=文档 +X)推出 (位图高−内容高)/2——「竖排 TextImage 进入
873
+ // 编辑向右偏移」报障根因。boxH 不进:位图态盒高是文档系值(存量解析形态),
874
+ // 且抬盒(width/height 属内容键)写入即转正脱离位图态——位图态无抬盒形态。
875
+ if (typeof this.raw.renderSrc === 'string') {
876
+ return -this.textLayout.height / 2;
877
+ }
869
878
  return -this.dims.y / 2;
870
879
  }
871
880
  /**
@@ -10,9 +10,12 @@
10
10
  * 工作集 vs 512MiB 预算,每帧强逐 ~280MB 再全量重传,帧渲染 2.5~5s 永不
11
11
  * 收敛;预算抬到覆盖工作集后同场景 3ms/帧——A/B 定谳)。孤儿/换页残留
12
12
  * 不再被 get 命中即沉到 LRU 头,下一次插入压力先逐它们,预算仍长期生效。
13
- * - **帧界保护**:渲染中插入路径不逐本帧取用条目(句柄可能已被批渲染器捕获
14
- * 进本帧实例数据,删了就是一帧死纹理渲染);工作集超预算允许留驻超额——
15
- * 颠簸 = 永不可用,留驻 = 一次性上传后稳定,是显式取舍
13
+ * - **帧界保护(插入压力三防线,批次 321 补丁)**:渲染中插入路径的淘汰依次
14
+ * 受 ①手势期冻结(markFrame(gestureActive))②近帧宽限(evictGraceFrames
15
+ * 帧内 touch 过的不逐——句柄可能已被批渲染器捕获,保留式帧让活动工作集
16
+ * 间歇不 touch)③代价感知(先逐 <32MiB 小条目,耗尽才动大条目)拦护;
17
+ * 全被拦下时允许留驻超额——颠簸 = 永不可用,留驻 = 一次性上传后稳定,
18
+ * 是显式取舍(细节见 evictIfNeeded 头注)
16
19
  * - 字节口径:宽×高×4(RGBA8),mipmap 源 ×4/3(三级以上链约数)
17
20
  *
18
21
  * Phase 4 动态源(动画 GIF 单帧缓冲 / HTMLVideoElement):
@@ -29,6 +32,9 @@ export interface GLTextureCacheOptions {
29
32
  budgetBytes?: number;
30
33
  /** 条数上限(防小纹理海量条目绕过字节预算);缺省 2048 */
31
34
  maxEntries?: number;
35
+ /** 插入压力淘汰的近帧宽限(帧数):lastFrame 距当前帧不足此值的条目跳过
36
+ * 淘汰。缺省 30。1 = 仅本帧(旧行为)。 */
37
+ evictGraceFrames?: number;
32
38
  }
33
39
  export interface TextureCacheStats {
34
40
  entries: number;
@@ -46,6 +52,8 @@ export declare class GLTextureCache {
46
52
  private readonly cache;
47
53
  private budgetBytes;
48
54
  private maxEntries;
55
+ private evictGraceFrames;
56
+ private gestureActive;
49
57
  private frameStamp;
50
58
  private frameTouches;
51
59
  private evictions;
@@ -55,8 +63,10 @@ export declare class GLTextureCache {
55
63
  /** 帧界推进(EngineCanvas.render 顶部调用):此后的取用都算「本帧」。
56
64
  * 批次 321:不再做预算强制结算——帧界强逐在工作集超预算时构成
57
65
  * 「逐出→重传」死循环(同头注),淘汰统一改由插入压力驱动
58
- * (get miss → evictIfNeeded);预算的长期收敛性由孤儿沉底 LRU 头保证 */
59
- markFrame(): void;
66
+ * (get miss → evictIfNeeded);预算的长期收敛性由孤儿沉底 LRU 头保证。
67
+ * gestureActive(指针手势进行中):本帧插入压力淘汰整体冻结(见
68
+ * evictIfNeeded 头注的手势期防线) */
69
+ markFrame(gestureActive?: boolean): void;
60
70
  /** 累计逐出计数(批次 223 重落保留式回退门):逐出删除纹理句柄会使快照命令
61
71
  * 里引用的句柄失效——计数变化即作废保留式快照走全量帧 */
62
72
  get evictionCount(): number;
@@ -65,11 +75,24 @@ export declare class GLTextureCache {
65
75
  get(source: TextureSource): WebGLTexture | null;
66
76
  /**
67
77
  * 预算淘汰(仅插入路径/setBudget 调用):从最旧端逐条淘汰到 reserveBytes
68
- * 可容纳。protectCurrentFrame=true(渲染中插入路径):本帧取用条目跳过——
69
- * 句柄可能已被批渲染器捕获进本帧实例数据;全被保护时允许临时超额(正确性
70
- * 优先)。false(setBudget 显式调压):强制淘汰——调用点在帧间,无批次持有句柄。
78
+ * 可容纳。protectCurrentFrame=true(渲染中插入路径)三道防线(思阳素材
79
+ * 431.9MiB PSD 拖动每步 2.2s 定谳后的批次 321 补丁——保留式帧只重推脏节点,
80
+ * 活动大图整段不 touch,插入压力会把刚用过的大图逐出,下一全量帧 490MiB
81
+ * 级重传):
82
+ * ① 手势期冻结——markFrame(gestureActive) 期间插入压力整体 no-op(拖动/
83
+ * 缩放/旋转中绝不逐出;烘焙小纹理持续插入照常,超额留驻=头注取舍);
84
+ * ② 近帧宽限——距当前帧不足 evictGraceFrames(缺省 30)的条目跳过:非
85
+ * 手势期的活动工作集(动画/编辑间歇 touch)不被插入压力逐出;真孤儿
86
+ * (远旧帧号沉底)照逐,预算长期收敛性不变;
87
+ * ③ 代价感知——先逐小条目(< BIG_ENTRY_BYTES),小条目耗尽才动大条目:
88
+ * 逐出恢复代价 ∝ 条目字节数(小纹理重传无感,全幅大图重传秒级),偶发
89
+ * 结算优先牺牲无感的小条目。
90
+ * 全被防线拦下时允许临时超额(正确性优先)。false(setBudget 显式调压):
91
+ * 强制淘汰——调用点在帧间,无批次持有句柄,三道防线均不适用。
71
92
  */
72
93
  private evictIfNeeded;
94
+ /** 从 LRU 最旧端逐一条目;allowBig=false 跳过大条目(代价感知第一轮) */
95
+ private evictOldestEligible;
73
96
  /**
74
97
  * 动态源内容更新后重传(GIF 换帧 / 视频新帧)。仅对已缓存源生效——
75
98
  * 未创建过的源由下一次 get() 全量上传;纹理对象不变,调用方无需重取。
@@ -10,9 +10,12 @@
10
10
  * 工作集 vs 512MiB 预算,每帧强逐 ~280MB 再全量重传,帧渲染 2.5~5s 永不
11
11
  * 收敛;预算抬到覆盖工作集后同场景 3ms/帧——A/B 定谳)。孤儿/换页残留
12
12
  * 不再被 get 命中即沉到 LRU 头,下一次插入压力先逐它们,预算仍长期生效。
13
- * - **帧界保护**:渲染中插入路径不逐本帧取用条目(句柄可能已被批渲染器捕获
14
- * 进本帧实例数据,删了就是一帧死纹理渲染);工作集超预算允许留驻超额——
15
- * 颠簸 = 永不可用,留驻 = 一次性上传后稳定,是显式取舍
13
+ * - **帧界保护(插入压力三防线,批次 321 补丁)**:渲染中插入路径的淘汰依次
14
+ * 受 ①手势期冻结(markFrame(gestureActive))②近帧宽限(evictGraceFrames
15
+ * 帧内 touch 过的不逐——句柄可能已被批渲染器捕获,保留式帧让活动工作集
16
+ * 间歇不 touch)③代价感知(先逐 <32MiB 小条目,耗尽才动大条目)拦护;
17
+ * 全被拦下时允许留驻超额——颠簸 = 永不可用,留驻 = 一次性上传后稳定,
18
+ * 是显式取舍(细节见 evictIfNeeded 头注)
16
19
  * - 字节口径:宽×高×4(RGBA8),mipmap 源 ×4/3(三级以上链约数)
17
20
  *
18
21
  * Phase 4 动态源(动画 GIF 单帧缓冲 / HTMLVideoElement):
@@ -25,11 +28,17 @@
25
28
  */
26
29
  const DEFAULT_BUDGET_BYTES = 512 * 1024 * 1024;
27
30
  const DEFAULT_MAX_ENTRIES = 2048;
31
+ const DEFAULT_EVICT_GRACE_FRAMES = 30;
32
+ /** 代价感知门槛:≥32MiB 的条目视为大条目,插入压力先耗尽小条目才逐它
33
+ * (全幅位图纹理逐出后全量重传是秒级,小烘焙纹理重传无感) */
34
+ const BIG_ENTRY_BYTES = 32 * 1024 * 1024;
28
35
  export class GLTextureCache {
29
36
  gl;
30
37
  cache = new Map();
31
38
  budgetBytes;
32
39
  maxEntries;
40
+ evictGraceFrames;
41
+ gestureActive = false;
33
42
  frameStamp = 0;
34
43
  frameTouches = 0;
35
44
  evictions = 0;
@@ -39,14 +48,18 @@ export class GLTextureCache {
39
48
  this.gl = gl;
40
49
  this.budgetBytes = options.budgetBytes ?? DEFAULT_BUDGET_BYTES;
41
50
  this.maxEntries = options.maxEntries ?? DEFAULT_MAX_ENTRIES;
51
+ this.evictGraceFrames = options.evictGraceFrames ?? DEFAULT_EVICT_GRACE_FRAMES;
42
52
  }
43
53
  /** 帧界推进(EngineCanvas.render 顶部调用):此后的取用都算「本帧」。
44
54
  * 批次 321:不再做预算强制结算——帧界强逐在工作集超预算时构成
45
55
  * 「逐出→重传」死循环(同头注),淘汰统一改由插入压力驱动
46
- * (get miss → evictIfNeeded);预算的长期收敛性由孤儿沉底 LRU 头保证 */
47
- markFrame() {
56
+ * (get miss → evictIfNeeded);预算的长期收敛性由孤儿沉底 LRU 头保证。
57
+ * gestureActive(指针手势进行中):本帧插入压力淘汰整体冻结(见
58
+ * evictIfNeeded 头注的手势期防线) */
59
+ markFrame(gestureActive = false) {
48
60
  this.frameStamp += 1;
49
61
  this.frameTouches = 0;
62
+ this.gestureActive = gestureActive;
50
63
  }
51
64
  /** 累计逐出计数(批次 223 重落保留式回退门):逐出删除纹理句柄会使快照命令
52
65
  * 里引用的句柄失效——计数变化即作废保留式快照走全量帧 */
@@ -105,30 +118,48 @@ export class GLTextureCache {
105
118
  }
106
119
  /**
107
120
  * 预算淘汰(仅插入路径/setBudget 调用):从最旧端逐条淘汰到 reserveBytes
108
- * 可容纳。protectCurrentFrame=true(渲染中插入路径):本帧取用条目跳过——
109
- * 句柄可能已被批渲染器捕获进本帧实例数据;全被保护时允许临时超额(正确性
110
- * 优先)。false(setBudget 显式调压):强制淘汰——调用点在帧间,无批次持有句柄。
121
+ * 可容纳。protectCurrentFrame=true(渲染中插入路径)三道防线(思阳素材
122
+ * 431.9MiB PSD 拖动每步 2.2s 定谳后的批次 321 补丁——保留式帧只重推脏节点,
123
+ * 活动大图整段不 touch,插入压力会把刚用过的大图逐出,下一全量帧 490MiB
124
+ * 级重传):
125
+ * ① 手势期冻结——markFrame(gestureActive) 期间插入压力整体 no-op(拖动/
126
+ * 缩放/旋转中绝不逐出;烘焙小纹理持续插入照常,超额留驻=头注取舍);
127
+ * ② 近帧宽限——距当前帧不足 evictGraceFrames(缺省 30)的条目跳过:非
128
+ * 手势期的活动工作集(动画/编辑间歇 touch)不被插入压力逐出;真孤儿
129
+ * (远旧帧号沉底)照逐,预算长期收敛性不变;
130
+ * ③ 代价感知——先逐小条目(< BIG_ENTRY_BYTES),小条目耗尽才动大条目:
131
+ * 逐出恢复代价 ∝ 条目字节数(小纹理重传无感,全幅大图重传秒级),偶发
132
+ * 结算优先牺牲无感的小条目。
133
+ * 全被防线拦下时允许临时超额(正确性优先)。false(setBudget 显式调压):
134
+ * 强制淘汰——调用点在帧间,无批次持有句柄,三道防线均不适用。
111
135
  */
112
136
  evictIfNeeded(reserveBytes, protectCurrentFrame) {
113
137
  if (this.disposed)
114
138
  return;
139
+ if (protectCurrentFrame && this.gestureActive)
140
+ return;
115
141
  while (this.trackedBytes + reserveBytes > this.budgetBytes || this.cache.size >= this.maxEntries) {
116
- let evicted = false;
117
- for (const [source, entry] of this.cache) {
118
- if (protectCurrentFrame && entry.lastFrame === this.frameStamp)
119
- continue;
120
- this.gl.deleteTexture(entry.tex);
121
- this.cache.delete(source);
122
- this.trackedBytes -= entry.bytes;
123
- this.evictions += 1;
124
- evicted = true;
125
- break;
126
- }
127
- // 无可逐条目(全被帧界保护,或缓存已空仍超预算——reserveBytes 本身超限)
142
+ const evicted = this.evictOldestEligible(protectCurrentFrame, false) || this.evictOldestEligible(protectCurrentFrame, true);
143
+ // 无可逐条目(全被宽限/尺寸防线拦下,或缓存已空仍超预算——reserveBytes 本身超限)
128
144
  if (!evicted)
129
145
  return;
130
146
  }
131
147
  }
148
+ /** 从 LRU 最旧端逐一条目;allowBig=false 跳过大条目(代价感知第一轮) */
149
+ evictOldestEligible(protectCurrentFrame, allowBig) {
150
+ for (const [source, entry] of this.cache) {
151
+ if (protectCurrentFrame && this.frameStamp - entry.lastFrame < this.evictGraceFrames)
152
+ continue;
153
+ if (!allowBig && entry.bytes >= BIG_ENTRY_BYTES)
154
+ continue;
155
+ this.gl.deleteTexture(entry.tex);
156
+ this.cache.delete(source);
157
+ this.trackedBytes -= entry.bytes;
158
+ this.evictions += 1;
159
+ return true;
160
+ }
161
+ return false;
162
+ }
132
163
  /**
133
164
  * 动态源内容更新后重传(GIF 换帧 / 视频新帧)。仅对已缓存源生效——
134
165
  * 未创建过的源由下一次 get() 全量上传;纹理对象不变,调用方无需重取。
@@ -7,6 +7,7 @@ import type { QuadBatch } from './QuadBatch';
7
7
  import type { MeshBatch } from './MeshBatch';
8
8
  import type { BatchOrder } from './batchOrder';
9
9
  import type { GLTextureCache } from './GLTextureCache';
10
+ import { SettleScheduler } from './settleScheduler';
10
11
  export interface SceneRendererHost {
11
12
  readonly gl: WebGL2RenderingContext;
12
13
  readonly batch: QuadBatch;
@@ -52,6 +53,10 @@ export declare class SceneRenderer {
52
53
  private readonly sources;
53
54
  private readonly text;
54
55
  readonly frame: FrameState;
56
+ /** 手势期帧预算调度底座(stale/settle 手势窗统一源,批次372 方向二第一刀):
57
+ * vpt 写点经 EngineCanvas→noteVptChange 汇入,三烘焙画家共享消费;后续
58
+ * 手势期排队任务策略(持截止时间/超预算让位)在此生长 */
59
+ readonly settle: SettleScheduler;
55
60
  /** 本帧是否全扁平(批次 223 重落保留式门):节点相位未触 FBO 隔离/混合路径
56
61
  * (renderIsolatedGroup/renderBlendedNode 置 false)——保留式快照只对
57
62
  * 扁平帧成立(隔离帧的命令重放缺少 FBO 边界语义)。场景相位前复位 */
@@ -82,7 +87,8 @@ export declare class SceneRenderer {
82
87
  /** 帧复位(EngineCanvas.render 开头,guard 之后调用):三态归零 + 本帧烘焙预算 */
83
88
  beginFrame(now: number): void;
84
89
  /** 视口变化通知(缩放/平移写点,2026-10-09 扩语义:描边/蒙版烘焙的栅格倍率
85
- * 与设备像素吸附都随 vpt 变化):stale 延迟重烘的手势窗口,语义见各画家 */
90
+ * 与设备像素吸附都随 vpt 变化):stale 延迟重烘的手势窗口——批次372 起
91
+ * 统一汇入 SettleScheduler(三画家消费同一窗口,语义见各画家头注) */
86
92
  noteVptChange(): void;
87
93
  /** 节点光栅蒙版纹理与屏幕 uv 摆放(组蒙版 + 形状族直挂蒙版——批次 178 泛化;
88
94
  * 无 mask/未加载返回 null。数学只依赖 raw.mask/dims/matrix,节点族无差) */
@@ -14,6 +14,7 @@ import { MaskBakeCache, maskSrcKey as maskClipSrcKey } from './maskRender';
14
14
  import { readTextureToCanvas } from './gpuImageFilters';
15
15
  import { ShadowPainter } from './shadowPainter';
16
16
  import { StrokePainter } from './strokePainter';
17
+ import { SettleScheduler } from './settleScheduler';
17
18
  import { ClipMaskPainter, clipDecl } from './clipMaskPainter';
18
19
  import { PsdEffectPainter, FX_BAKE_BUDGET_MS } from './psdEffectPainter';
19
20
  import { SharedGpuPainters } from './sharedGpuPainters';
@@ -25,6 +26,10 @@ export class SceneRenderer {
25
26
  sources;
26
27
  text;
27
28
  frame = { bakeDeadline: 0, bakeMore: false, animationActive: false };
29
+ /** 手势期帧预算调度底座(stale/settle 手势窗统一源,批次372 方向二第一刀):
30
+ * vpt 写点经 EngineCanvas→noteVptChange 汇入,三烘焙画家共享消费;后续
31
+ * 手势期排队任务策略(持截止时间/超预算让位)在此生长 */
32
+ settle;
28
33
  /** 本帧是否全扁平(批次 223 重落保留式门):节点相位未触 FBO 隔离/混合路径
29
34
  * (renderIsolatedGroup/renderBlendedNode 置 false)——保留式快照只对
30
35
  * 扁平帧成立(隔离帧的命令重放缺少 FBO 边界语义)。场景相位前复位 */
@@ -57,10 +62,13 @@ export class SceneRenderer {
57
62
  this.text = text;
58
63
  this.gpu = new SharedGpuPainters(host.gl);
59
64
  this.shadow = new ShadowPainter(host);
60
- this.stroke = new StrokePainter(host, this.frame);
65
+ // 手势窗/settle 统一底座(批次372 方向二第一刀):三画家共享同一实例——
66
+ // 单次 vpt 写点只排一个定时器、settle 只补一帧、跨画家窗口恒同步
67
+ this.settle = new SettleScheduler(() => this.host.requestRenderAll());
68
+ this.stroke = new StrokePainter(host, this.frame, this.settle);
61
69
  this.clip = new ClipMaskPainter(host, this.gpu);
62
- this.psd = new PsdEffectPainter(host, this.frame, this.gpu, () => this.puzzleBox);
63
- this.maskBake = new MaskBakeCache(host, this.frame);
70
+ this.psd = new PsdEffectPainter(host, this.frame, this.gpu, () => this.puzzleBox, this.settle);
71
+ this.maskBake = new MaskBakeCache(host, this.frame, this.settle);
64
72
  }
65
73
  /** 帧复位(EngineCanvas.render 开头,guard 之后调用):三态归零 + 本帧烘焙预算 */
66
74
  beginFrame(now) {
@@ -69,11 +77,10 @@ export class SceneRenderer {
69
77
  this.frame.bakeMore = false;
70
78
  }
71
79
  /** 视口变化通知(缩放/平移写点,2026-10-09 扩语义:描边/蒙版烘焙的栅格倍率
72
- * 与设备像素吸附都随 vpt 变化):stale 延迟重烘的手势窗口,语义见各画家 */
80
+ * 与设备像素吸附都随 vpt 变化):stale 延迟重烘的手势窗口——批次372 起
81
+ * 统一汇入 SettleScheduler(三画家消费同一窗口,语义见各画家头注) */
73
82
  noteVptChange() {
74
- this.psd.noteVptScaleChange();
75
- this.stroke.noteVptChange();
76
- this.maskBake.noteVptChange();
83
+ this.settle.noteInteraction();
77
84
  }
78
85
  /** 节点光栅蒙版纹理与屏幕 uv 摆放(组蒙版 + 形状族直挂蒙版——批次 178 泛化;
79
86
  * 无 mask/未加载返回 null。数学只依赖 raw.mask/dims/matrix,节点族无差) */
@@ -29,6 +29,7 @@
29
29
  * 烘焙,SceneExporter 按 bakeMore 多轮重渲兜底)。
30
30
  */
31
31
  import type { MaskNode } from '../model/scene';
32
+ import { SettleScheduler } from './settleScheduler';
32
33
  import type { FrameState, SceneRendererHost } from './SceneRenderer';
33
34
  /** base64 src 过大时取首尾特征作签名键(应用 maskSrcKey 同款;SceneRenderer 的
34
35
  * clipImage 滤镜读回缓存同源复用) */
@@ -71,15 +72,14 @@ export declare class MaskBakeCache {
71
72
  private readonly frame;
72
73
  /** 节点级烘焙缓存(WeakMap——节点删除后随 GC 回收;重烘前 deleteTexture 旧纹理) */
73
74
  private bakes;
74
- /** 最近一次视口写点时刻(stale 判定的手势窗口;-Infinity = 从未手势——
75
- * 0 会在钟起点被误判窗口内)与 settle 定时器 */
76
- private vptChangedAt;
77
- private settleTimer;
78
- constructor(host: SceneRendererHost, frame: FrameState);
75
+ /** 最近一次视口写点时刻(stale 判定的手势窗口)与 settle 定时器——统一
76
+ * 收敛至 SettleScheduler(批次372),见其头注 */
77
+ private readonly settle;
78
+ constructor(host: SceneRendererHost, frame: FrameState, settle?: SettleScheduler);
79
79
  /**
80
80
  * 视口变化通知(缩放/平移写点均调——蒙版烘焙只有 k=min(4,dpr×zoom×scaleBoost)
81
- * 随缩放变化,平移通知只顺延手势窗口,无害):记录时刻 + FX_SETTLE_MS settle
82
- * 定时器——持续手势期间零重烘焙(重烘+重传是重操作,卡手势不可接受),停止后
81
+ * 随缩放变化,平移通知只顺延手势窗口,无害):共享 SettleScheduler 记手势
82
+ * 窗口——持续手势期间零重烘焙(重烘+重传是重操作,卡手势不可接受),停止后
83
83
  * 由 settle 帧按每帧预算分帧补齐(frame.bakeDeadline/bakeMore)。与
84
84
  * StrokePainter.noteVptChange / PsdEffectPainter.noteVptScaleChange 同协议。
85
85
  */
@@ -29,7 +29,7 @@
29
29
  * 烘焙,SceneExporter 按 bakeMore 多轮重渲兜底)。
30
30
  */
31
31
  import { createTexture2D } from './textureUpload';
32
- import { FX_SETTLE_MS } from './psdEffectPainter';
32
+ import { SettleScheduler } from './settleScheduler';
33
33
  /** base64 src 过大时取首尾特征作签名键(应用 maskSrcKey 同款;SceneRenderer 的
34
34
  * clipImage 滤镜读回缓存同源复用) */
35
35
  export const maskSrcKey = (src) => {
@@ -157,29 +157,23 @@ export class MaskBakeCache {
157
157
  frame;
158
158
  /** 节点级烘焙缓存(WeakMap——节点删除后随 GC 回收;重烘前 deleteTexture 旧纹理) */
159
159
  bakes = new WeakMap();
160
- /** 最近一次视口写点时刻(stale 判定的手势窗口;-Infinity = 从未手势——
161
- * 0 会在钟起点被误判窗口内)与 settle 定时器 */
162
- vptChangedAt = -Infinity;
163
- settleTimer = null;
164
- constructor(host, frame) {
160
+ /** 最近一次视口写点时刻(stale 判定的手势窗口)与 settle 定时器——统一
161
+ * 收敛至 SettleScheduler(批次372),见其头注 */
162
+ settle;
163
+ constructor(host, frame, settle = new SettleScheduler(() => host.requestRenderAll())) {
165
164
  this.host = host;
166
165
  this.frame = frame;
166
+ this.settle = settle;
167
167
  }
168
168
  /**
169
169
  * 视口变化通知(缩放/平移写点均调——蒙版烘焙只有 k=min(4,dpr×zoom×scaleBoost)
170
- * 随缩放变化,平移通知只顺延手势窗口,无害):记录时刻 + FX_SETTLE_MS settle
171
- * 定时器——持续手势期间零重烘焙(重烘+重传是重操作,卡手势不可接受),停止后
170
+ * 随缩放变化,平移通知只顺延手势窗口,无害):共享 SettleScheduler 记手势
171
+ * 窗口——持续手势期间零重烘焙(重烘+重传是重操作,卡手势不可接受),停止后
172
172
  * 由 settle 帧按每帧预算分帧补齐(frame.bakeDeadline/bakeMore)。与
173
173
  * StrokePainter.noteVptChange / PsdEffectPainter.noteVptScaleChange 同协议。
174
174
  */
175
175
  noteVptChange() {
176
- this.vptChangedAt = performance.now();
177
- if (this.settleTimer !== null)
178
- clearTimeout(this.settleTimer);
179
- this.settleTimer = window.setTimeout(() => {
180
- this.settleTimer = null;
181
- this.host.requestRenderAll();
182
- }, FX_SETTLE_MS);
176
+ this.settle.noteInteraction();
183
177
  }
184
178
  /** 烘焙入口:sigBase+k 双命中直接复用;内容变化立即重烘;仅 k 变化走
185
179
  * stale 门(手势窗口/帧预算耗尽沿用旧烘焙,导出窗口恒新鲜) */
@@ -199,7 +193,7 @@ export class MaskBakeCache {
199
193
  // (逻辑尺寸不变,分辨率暂欠),settle 后补齐精确 k
200
194
  const now = performance.now();
201
195
  // 导出窗口(applyExportViewport 接管视口)不受手势门:k 换档立即新鲜烘焙
202
- const gesturing = !this.host.isExporting() && (now - this.vptChangedAt < FX_SETTLE_MS || this.settleTimer !== null);
196
+ const gesturing = !this.host.isExporting() && this.settle.isSettling(now);
203
197
  if (gesturing || now > this.frame.bakeDeadline) {
204
198
  this.frame.bakeMore = true;
205
199
  return cached;
@@ -1,10 +1,12 @@
1
1
  import { TextNode, type SceneNode } from '../model/scene';
2
2
  import { type PuzzleBox } from './puzzleClamp';
3
+ import { SettleScheduler } from './settleScheduler';
3
4
  import type { SharedGpuPainters } from './sharedGpuPainters';
4
5
  import type { FrameState, SceneRendererHost } from './SceneRenderer';
5
6
  /** PSD 烘焙分帧预算(每帧毫秒上限)与缩放 settle 窗口(beginFrame 侧共用) */
6
7
  export declare const FX_BAKE_BUDGET_MS = 6;
7
- export declare const FX_SETTLE_MS = 160;
8
+ /** settle 窗口常量随协议收敛迁至 SettleScheduler(批次372)——旧导入位保留转发 */
9
+ export { FX_SETTLE_MS } from './settleScheduler';
8
10
  export declare const bitmapFxNode: (node: TextNode) => TextNode;
9
11
  export declare class PsdEffectPainter {
10
12
  private readonly host;
@@ -16,13 +18,13 @@ export declare class PsdEffectPainter {
16
18
  * 矩阵/尺寸/源指纹(内容变化即失效重烘);bucket = 文本族缩放桶(仅它变化
17
19
  * 时走 stale 延迟重烘——跨桶烘焙是重操作,须避开缩放手势,见 noteVptScaleChange) */
18
20
  private psdBakes;
19
- /** 最近一次视口缩放变化时刻(stale 判定的手势窗口)与 settle 定时器 */
20
- private vptChangedAt;
21
- private fxSettleTimer;
22
- constructor(host: SceneRendererHost, frame: FrameState, gpu: SharedGpuPainters, getPuzzleBox: () => PuzzleBox | null);
21
+ /** 最近一次视口缩放变化时刻(stale 判定的手势窗口)与 settle 定时器——统一
22
+ * 收敛至 SettleScheduler(批次372),见其头注 */
23
+ private readonly settle;
24
+ constructor(host: SceneRendererHost, frame: FrameState, gpu: SharedGpuPainters, getPuzzleBox: () => PuzzleBox | null, settle?: SettleScheduler);
23
25
  /**
24
- * 视口缩放变化通知(文本特效 stale 重烘的手势窗口):记录时刻 + 160ms
25
- * settle 定时器——持续缩放期间零重烘焙(跨桶烘焙百毫秒级,卡手势不可接受),
26
+ * 视口缩放变化通知(文本特效 stale 重烘的手势窗口):共享 SettleScheduler
27
+ * 记手势窗口——持续缩放期间零重烘焙(跨桶烘焙百毫秒级,卡手势不可接受),
26
28
  * 停止后由 settle 帧按每帧预算分帧补齐(frame.bakeDeadline/bakeMore)。
27
29
  */
28
30
  noteVptScaleChange(): void;
@@ -24,9 +24,11 @@ import { pickZoomBucket } from './GlyphAtlas';
24
24
  import { bakePathEffectShadow, bakePsdShadow, bakePsdSolidFill, bakePsdStrokes, buildTextEffectSource, strokeSupersampleCap, imageFiltersSig } from './imageEffects';
25
25
  import { createTexture2D } from './textureUpload';
26
26
  import { clampQuadToPuzzleBox } from './puzzleClamp';
27
+ import { SettleScheduler } from './settleScheduler';
27
28
  /** PSD 烘焙分帧预算(每帧毫秒上限)与缩放 settle 窗口(beginFrame 侧共用) */
28
29
  export const FX_BAKE_BUDGET_MS = 6;
29
- export const FX_SETTLE_MS = 160;
30
+ /** settle 窗口常量随协议收敛迁至 SettleScheduler(批次372)——旧导入位保留转发 */
31
+ export { FX_SETTLE_MS } from './settleScheduler';
30
32
  /**
31
33
  * 位图态 fx 框架节点(批次 314 七补):PSD 效果的烘焙/铺放全链吃 node.matrix
32
34
  * (bake setTransform/签名/quad 铺放),位图态框架矩阵=渲染 quad 同款本地系
@@ -67,28 +69,23 @@ export class PsdEffectPainter {
67
69
  * 矩阵/尺寸/源指纹(内容变化即失效重烘);bucket = 文本族缩放桶(仅它变化
68
70
  * 时走 stale 延迟重烘——跨桶烘焙是重操作,须避开缩放手势,见 noteVptScaleChange) */
69
71
  psdBakes = new WeakMap();
70
- /** 最近一次视口缩放变化时刻(stale 判定的手势窗口)与 settle 定时器 */
71
- vptChangedAt = 0;
72
- fxSettleTimer = null;
73
- constructor(host, frame, gpu, getPuzzleBox) {
72
+ /** 最近一次视口缩放变化时刻(stale 判定的手势窗口)与 settle 定时器——统一
73
+ * 收敛至 SettleScheduler(批次372),见其头注 */
74
+ settle;
75
+ constructor(host, frame, gpu, getPuzzleBox, settle = new SettleScheduler(() => host.requestRenderAll())) {
74
76
  this.host = host;
75
77
  this.frame = frame;
76
78
  this.gpu = gpu;
77
79
  this.getPuzzleBox = getPuzzleBox;
80
+ this.settle = settle;
78
81
  }
79
82
  /**
80
- * 视口缩放变化通知(文本特效 stale 重烘的手势窗口):记录时刻 + 160ms
81
- * settle 定时器——持续缩放期间零重烘焙(跨桶烘焙百毫秒级,卡手势不可接受),
83
+ * 视口缩放变化通知(文本特效 stale 重烘的手势窗口):共享 SettleScheduler
84
+ * 记手势窗口——持续缩放期间零重烘焙(跨桶烘焙百毫秒级,卡手势不可接受),
82
85
  * 停止后由 settle 帧按每帧预算分帧补齐(frame.bakeDeadline/bakeMore)。
83
86
  */
84
87
  noteVptScaleChange() {
85
- this.vptChangedAt = performance.now();
86
- if (this.fxSettleTimer !== null)
87
- clearTimeout(this.fxSettleTimer);
88
- this.fxSettleTimer = window.setTimeout(() => {
89
- this.fxSettleTimer = null;
90
- this.host.requestRenderAll();
91
- }, FX_SETTLE_MS);
88
+ this.settle.noteInteraction();
92
89
  }
93
90
  render(node, phase) {
94
91
  // 路径族(P3-5c):只有 dropShadow[] 多层投影(PathCommon.renderShadow);
@@ -167,7 +164,7 @@ export class PsdEffectPainter {
167
164
  // (SceneExporter 按 bakeMore 多轮重渲兜底——2026-10-09 描边接入 stale
168
165
  // 协议时一并收口:此前缩放后 160ms 内导出会吃到手势期 stale 特效)
169
166
  const now = performance.now();
170
- const zooming = !this.host.isExporting() && (now - this.vptChangedAt < FX_SETTLE_MS || this.fxSettleTimer !== null);
167
+ const zooming = !this.host.isExporting() && this.settle.isSettling(now);
171
168
  if (zooming || now > this.frame.bakeDeadline) {
172
169
  this.frame.bakeMore = true;
173
170
  this.renderPsdBakeQuads(fxNode, bake, phase);
@@ -0,0 +1,34 @@
1
+ /**
2
+ * 手势期帧预算调度器——烘焙族 stale/settle 手势窗的统一底座
3
+ * (docs/2026-10-13_webgl2-render-jank-causes-and-watchlist.md §6.3 方向二第一刀)。
4
+ *
5
+ * 此前三份同样的协议态各自为政(StrokePainter/PsdEffectPainter/MaskBakeCache
6
+ * 各持 vptChangedAt + settle 定时器)——本模块收敛为单一窗口源:
7
+ * - noteInteraction():视口写点(缩放/平移/吸附翻转)记录时刻 + 顺延 settle
8
+ * 定时器(FX_SETTLE_MS),停手后触发恰好一次补帧渲染(requestRenderAll);
9
+ * - isSettling():手势窗口判定(最近 FX_SETTLE_MS 内有交互或定时器在途),
10
+ * 画家消费位与 isExporting 门(导出窗口不受手势门)组合使用;
11
+ * - 画家构造参数可选注入(缺省自建——单测直构等价旧独立窗口;SceneRenderer
12
+ * 注入共享实例——单次 vpt 写点只排一个定时器/settle 只补一帧,跨画家窗口
13
+ * 恒同步)。lastInteractionAt 取 -Infinity 初始化(0 会在钟起点被误判窗口
14
+ * 内——PsdEffectPainter 旧 0 初始化的隐患随统一收口)。
15
+ *
16
+ * 后续手势期帧预算策略(排队任务持截止时间、超预算让位)在此底座上生长;
17
+ * 现有每帧烘焙预算(FrameState.bakeDeadline/bakeMore)语义不变。
18
+ */
19
+ /** 缩放/平移 settle 窗口(最后一次交互后多少毫秒视为停手) */
20
+ export declare const FX_SETTLE_MS = 160;
21
+ export declare class SettleScheduler {
22
+ private readonly requestRender;
23
+ /** 最近一次交互时刻(-Infinity = 从未交互) */
24
+ private lastInteractionAt;
25
+ private settleTimer;
26
+ constructor(requestRender: () => void);
27
+ /** 交互通知(视口写点):记录时刻 + 顺延 settle 定时器(持续手势期零补帧) */
28
+ noteInteraction(): void;
29
+ /** 手势窗口判定:最近 FX_SETTLE_MS 内有交互或 settle 定时器仍在途 */
30
+ isSettling(now?: number): boolean;
31
+ /** 丢弃未决 settle(定时器不再触发补帧,且彻底出窗——teardown 后消费方
32
+ * 的 isSettling 判定不再看到残留手势窗口) */
33
+ dispose(): void;
34
+ }
@@ -0,0 +1,51 @@
1
+ /**
2
+ * 手势期帧预算调度器——烘焙族 stale/settle 手势窗的统一底座
3
+ * (docs/2026-10-13_webgl2-render-jank-causes-and-watchlist.md §6.3 方向二第一刀)。
4
+ *
5
+ * 此前三份同样的协议态各自为政(StrokePainter/PsdEffectPainter/MaskBakeCache
6
+ * 各持 vptChangedAt + settle 定时器)——本模块收敛为单一窗口源:
7
+ * - noteInteraction():视口写点(缩放/平移/吸附翻转)记录时刻 + 顺延 settle
8
+ * 定时器(FX_SETTLE_MS),停手后触发恰好一次补帧渲染(requestRenderAll);
9
+ * - isSettling():手势窗口判定(最近 FX_SETTLE_MS 内有交互或定时器在途),
10
+ * 画家消费位与 isExporting 门(导出窗口不受手势门)组合使用;
11
+ * - 画家构造参数可选注入(缺省自建——单测直构等价旧独立窗口;SceneRenderer
12
+ * 注入共享实例——单次 vpt 写点只排一个定时器/settle 只补一帧,跨画家窗口
13
+ * 恒同步)。lastInteractionAt 取 -Infinity 初始化(0 会在钟起点被误判窗口
14
+ * 内——PsdEffectPainter 旧 0 初始化的隐患随统一收口)。
15
+ *
16
+ * 后续手势期帧预算策略(排队任务持截止时间、超预算让位)在此底座上生长;
17
+ * 现有每帧烘焙预算(FrameState.bakeDeadline/bakeMore)语义不变。
18
+ */
19
+ /** 缩放/平移 settle 窗口(最后一次交互后多少毫秒视为停手) */
20
+ export const FX_SETTLE_MS = 160;
21
+ export class SettleScheduler {
22
+ requestRender;
23
+ /** 最近一次交互时刻(-Infinity = 从未交互) */
24
+ lastInteractionAt = -Infinity;
25
+ settleTimer = null;
26
+ constructor(requestRender) {
27
+ this.requestRender = requestRender;
28
+ }
29
+ /** 交互通知(视口写点):记录时刻 + 顺延 settle 定时器(持续手势期零补帧) */
30
+ noteInteraction() {
31
+ this.lastInteractionAt = performance.now();
32
+ if (this.settleTimer !== null)
33
+ clearTimeout(this.settleTimer);
34
+ this.settleTimer = window.setTimeout(() => {
35
+ this.settleTimer = null;
36
+ this.requestRender();
37
+ }, FX_SETTLE_MS);
38
+ }
39
+ /** 手势窗口判定:最近 FX_SETTLE_MS 内有交互或 settle 定时器仍在途 */
40
+ isSettling(now = performance.now()) {
41
+ return now - this.lastInteractionAt < FX_SETTLE_MS || this.settleTimer !== null;
42
+ }
43
+ /** 丢弃未决 settle(定时器不再触发补帧,且彻底出窗——teardown 后消费方
44
+ * 的 isSettling 判定不再看到残留手势窗口) */
45
+ dispose() {
46
+ if (this.settleTimer !== null)
47
+ clearTimeout(this.settleTimer);
48
+ this.settleTimer = null;
49
+ this.lastInteractionAt = -Infinity;
50
+ }
51
+ }
@@ -1,22 +1,23 @@
1
1
  import type { SceneNode } from '../model/scene';
2
+ import { SettleScheduler } from './settleScheduler';
2
3
  import type { FrameState, SceneRendererHost } from './SceneRenderer';
3
4
  export declare class StrokePainter {
4
5
  private readonly host;
5
6
  private readonly frame;
7
+ /** 手势窗/settle 底座(SceneRenderer 注入共享实例;缺省自建=独立窗口) */
8
+ private readonly settle;
6
9
  /** 描边烘焙缓存(P3-2,场景空间):sigBase = 声明 + 矩阵 + 几何源(type/path/
7
10
  * points/rx)+ 尺寸(内容变化即失效立即重烘);k = 光栅 scale(zoom×dpr)——
8
11
  * 仅它或吸附 lx/ly 翻转变化时走 stale 延迟重烘(重烘+重传是重操作,须避开
9
12
  * 缩放/平移手势,见 noteVptChange)。lx/ly = 对齐后铺放左上角(snapped 时随
10
13
  * vpt 平移跨半像素界翻转同样延迟重烘,sceneW/H 供确定性重算) */
11
14
  private strokeBakes;
12
- /** 最近一次视口写点时刻(stale 判定的手势窗口;-Infinity = 从未手势——
13
- * 0 会在钟起点被误判窗口内)与 settle 定时器 */
14
- private vptChangedAt;
15
- private strokeSettleTimer;
16
- constructor(host: SceneRendererHost, frame: FrameState);
15
+ /** 最近一次视口写点时刻(stale 判定的手势窗口)与 settle 定时器——统一
16
+ * 收敛至 SettleScheduler(批次372),见其头注 */
17
+ constructor(host: SceneRendererHost, frame: FrameState, settle?: SettleScheduler);
17
18
  /**
18
19
  * 视口变化通知(缩放/平移写点均调——描边的光栅 scale 与设备像素吸附都随
19
- * vpt 变化):记录时刻 + FX_SETTLE_MS settle 定时器——持续手势期间零重烘焙
20
+ * vpt 变化):共享 SettleScheduler 记手势窗口——持续手势期间零重烘焙
20
21
  * (重烘+重传是重操作,卡手势不可接受),停止后由 settle 帧按每帧预算分帧
21
22
  * 补齐(frame.bakeDeadline/bakeMore)。与 PsdEffectPainter.noteVptScaleChange
22
23
  * 同协议(其注释含协议全貌)。
@@ -23,39 +23,34 @@ import { strokeKey } from '../core/stroke';
23
23
  import { strokeSdfParams } from './strokeSdf';
24
24
  import { bakeNodeStroke, strokeSnapOrigin } from './strokeBake';
25
25
  import { createTexture2D } from './textureUpload';
26
- import { FX_SETTLE_MS } from './psdEffectPainter';
26
+ import { SettleScheduler } from './settleScheduler';
27
27
  export class StrokePainter {
28
28
  host;
29
29
  frame;
30
+ /** 手势窗/settle 底座(SceneRenderer 注入共享实例;缺省自建=独立窗口) */
31
+ settle;
30
32
  /** 描边烘焙缓存(P3-2,场景空间):sigBase = 声明 + 矩阵 + 几何源(type/path/
31
33
  * points/rx)+ 尺寸(内容变化即失效立即重烘);k = 光栅 scale(zoom×dpr)——
32
34
  * 仅它或吸附 lx/ly 翻转变化时走 stale 延迟重烘(重烘+重传是重操作,须避开
33
35
  * 缩放/平移手势,见 noteVptChange)。lx/ly = 对齐后铺放左上角(snapped 时随
34
36
  * vpt 平移跨半像素界翻转同样延迟重烘,sceneW/H 供确定性重算) */
35
37
  strokeBakes = new WeakMap();
36
- /** 最近一次视口写点时刻(stale 判定的手势窗口;-Infinity = 从未手势——
37
- * 0 会在钟起点被误判窗口内)与 settle 定时器 */
38
- vptChangedAt = -Infinity;
39
- strokeSettleTimer = null;
40
- constructor(host, frame) {
38
+ /** 最近一次视口写点时刻(stale 判定的手势窗口)与 settle 定时器——统一
39
+ * 收敛至 SettleScheduler(批次372),见其头注 */
40
+ constructor(host, frame, settle = new SettleScheduler(() => host.requestRenderAll())) {
41
41
  this.host = host;
42
42
  this.frame = frame;
43
+ this.settle = settle;
43
44
  }
44
45
  /**
45
46
  * 视口变化通知(缩放/平移写点均调——描边的光栅 scale 与设备像素吸附都随
46
- * vpt 变化):记录时刻 + FX_SETTLE_MS settle 定时器——持续手势期间零重烘焙
47
+ * vpt 变化):共享 SettleScheduler 记手势窗口——持续手势期间零重烘焙
47
48
  * (重烘+重传是重操作,卡手势不可接受),停止后由 settle 帧按每帧预算分帧
48
49
  * 补齐(frame.bakeDeadline/bakeMore)。与 PsdEffectPainter.noteVptScaleChange
49
50
  * 同协议(其注释含协议全貌)。
50
51
  */
51
52
  noteVptChange() {
52
- this.vptChangedAt = performance.now();
53
- if (this.strokeSettleTimer !== null)
54
- clearTimeout(this.strokeSettleTimer);
55
- this.strokeSettleTimer = window.setTimeout(() => {
56
- this.strokeSettleTimer = null;
57
- this.host.requestRenderAll();
58
- }, FX_SETTLE_MS);
53
+ this.settle.noteInteraction();
59
54
  }
60
55
  render(node) {
61
56
  const decl = node.strokeDecl;
@@ -88,7 +83,7 @@ export class StrokePainter {
88
83
  if (bake.k !== k || (snap && (snap.lx !== bake.lx || snap.ly !== bake.ly))) {
89
84
  const now = performance.now();
90
85
  // 导出窗口(applyExportViewport 接管视口)不受手势门:k 换档立即新鲜烘焙
91
- const gesturing = !this.host.isExporting() && (now - this.vptChangedAt < FX_SETTLE_MS || this.strokeSettleTimer !== null);
86
+ const gesturing = !this.host.isExporting() && this.settle.isSettling(now);
92
87
  if (gesturing || now > this.frame.bakeDeadline) {
93
88
  this.frame.bakeMore = true;
94
89
  this.host.batch.pushQuad([1, 0, 0, 1, bake.lx + bake.w / 2, bake.ly + bake.h / 2], bake.w, bake.h, [1, 1, 1, node.renderOpacity], bake.tex);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yft-design/engine",
3
- "version": "0.0.6",
3
+ "version": "0.0.8",
4
4
  "description": "yft-design 的 WebGL2 画布引擎:接受 fabric toObject 格式 JSON,输出 GL 画布 / 位图(任意倍率 FBO 读回)/ SVG(纯数据序列化器)",
5
5
  "repository": {
6
6
  "type": "git",