@yft-design/engine 0.0.11 → 0.0.12

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.
@@ -61,7 +61,7 @@ export class SceneRenderer {
61
61
  this.host = host;
62
62
  this.sources = sources;
63
63
  this.text = text;
64
- this.gpu = new SharedGpuPainters(host.gl);
64
+ this.gpu = new SharedGpuPainters(host.gl, host.renderEpoch);
65
65
  this.shadow = new ShadowPainter(host);
66
66
  // 手势窗/settle 统一底座(批次372 方向二第一刀):三画家共享同一实例——
67
67
  // 单次 vpt 写点只排一个定时器、settle 只补一帧、跨画家窗口恒同步
@@ -18,6 +18,7 @@
18
18
  * 线性矩阵 + rs,平移由 quad 承担。模糊/着色/合成全是 FBO pass——替换的是
19
19
  * CPU 路径最贵的 canvas filter drop-shadow 逐层重绘。
20
20
  */
21
+ import type { RenderEpoch } from './renderEpoch';
21
22
  import type { PsdDropShadowDecl, PsdSolidFillDecl } from '../core/psdEffects';
22
23
  import type { RGBA } from '../core/color';
23
24
  import type { SceneNode, SourceRect } from '../model/scene';
@@ -30,8 +31,19 @@ export interface GpuShadowLayer {
30
31
  blur: number;
31
32
  }
32
33
  export declare class GpuFxPainter {
34
+ private readonly epoch?;
33
35
  /** 场景空间源纹理缓存(canvas 直出;签名 = 内容 + 线性矩阵 + rs + 尺寸) */
34
36
  private sources;
37
+ /** 在世源纹理/产物 RT 登记册(批次 392):WeakMap 不可枚举——两口径失效
38
+ * 真删靠此册(原「纹理句柄交 GC 终结」弃管在字体迟到失效(context 活着)
39
+ * = GL 滞留至真实 context loss;低频有界的旧取舍按 375 结构论证收口)。
40
+ * 范围=两 WeakMap 族(maskRt/scratch/meshBufs 为 context-lost 专属资源,
41
+ * 随上下文销毁,不入册) */
42
+ private readonly liveSrcTexes;
43
+ private readonly liveTargetRts;
44
+ /** 纪元(批次 392):sigBase 组重建删除已被保留式快照引用的产物时 bump
45
+ * (缺省 undefined = 直构单测独立口径,等价旧行为) */
46
+ constructor(epoch?: RenderEpoch | undefined);
35
47
  /** 节点烘焙目标(一节点多产物——投影/多个填充并存,按产物签名分槽;
36
48
  * sigBase 变化整组重建。曾用单槽 WeakMap:shadow 与 fill 互相删除刚烘好的
37
49
  * 纹理(双效果对象成片假红) */
@@ -57,11 +69,11 @@ export declare class GpuFxPainter {
57
69
  * matrix,sigBase 不变)。仅清两族烘焙缓存;程序/clip 蒙版/VBO 与字体
58
70
  * 无关不动(对比 invalidate() 的 context-lost 全量口径)。纹理句柄交 GC
59
71
  * 终结(psdBakes 整删同语义,字体加载事件低频有界)。 */
60
- invalidateTextDerivedBakes(): void;
72
+ invalidateTextDerivedBakes(gl: WebGL2RenderingContext): void;
61
73
  /** context restored 后失效(P6-2 恢复链):程序/RenderTarget/MSAA 缓冲/VBO
62
74
  * 随上下文销毁,签名缓存按 sig 命中死句柄——程序置空触发重编译、缓存清空
63
75
  * 触发重建(slot/allocTarget 路径) */
64
- invalidate(): void;
76
+ invalidate(gl: WebGL2RenderingContext): void;
65
77
  private compile;
66
78
  private ensurePrograms;
67
79
  private ensureTarget;
@@ -109,8 +109,21 @@ void main() {
109
109
  outColor = (a + b + c + d) * 0.25;
110
110
  }`;
111
111
  export class GpuFxPainter {
112
+ epoch;
112
113
  /** 场景空间源纹理缓存(canvas 直出;签名 = 内容 + 线性矩阵 + rs + 尺寸) */
113
114
  sources = new WeakMap();
115
+ /** 在世源纹理/产物 RT 登记册(批次 392):WeakMap 不可枚举——两口径失效
116
+ * 真删靠此册(原「纹理句柄交 GC 终结」弃管在字体迟到失效(context 活着)
117
+ * = GL 滞留至真实 context loss;低频有界的旧取舍按 375 结构论证收口)。
118
+ * 范围=两 WeakMap 族(maskRt/scratch/meshBufs 为 context-lost 专属资源,
119
+ * 随上下文销毁,不入册) */
120
+ liveSrcTexes = new Set();
121
+ liveTargetRts = new Set();
122
+ /** 纪元(批次 392):sigBase 组重建删除已被保留式快照引用的产物时 bump
123
+ * (缺省 undefined = 直构单测独立口径,等价旧行为) */
124
+ constructor(epoch) {
125
+ this.epoch = epoch;
126
+ }
114
127
  /** 节点烘焙目标(一节点多产物——投影/多个填充并存,按产物签名分槽;
115
128
  * sigBase 变化整组重建。曾用单槽 WeakMap:shadow 与 fill 互相删除刚烘好的
116
129
  * 纹理(双效果对象成片假红) */
@@ -122,7 +135,9 @@ export class GpuFxPainter {
122
135
  for (const rt of group.map.values()) {
123
136
  gl.deleteFramebuffer(rt.fb);
124
137
  gl.deleteTexture(rt.tex);
138
+ this.liveTargetRts.delete(rt);
125
139
  }
140
+ this.epoch?.bump('fx-slot-group-rebuild');
126
141
  group = undefined;
127
142
  }
128
143
  if (!group) {
@@ -141,10 +156,12 @@ export class GpuFxPainter {
141
156
  if (rt) {
142
157
  gl.deleteFramebuffer(rt.fb);
143
158
  gl.deleteTexture(rt.tex);
159
+ this.liveTargetRts.delete(rt);
144
160
  }
145
161
  rt = this.allocTarget(gl, w, h);
146
162
  if (!rt)
147
163
  return null;
164
+ this.liveTargetRts.add(rt);
148
165
  group.map.set(key, rt);
149
166
  return rt;
150
167
  }
@@ -167,14 +184,27 @@ export class GpuFxPainter {
167
184
  * matrix,sigBase 不变)。仅清两族烘焙缓存;程序/clip 蒙版/VBO 与字体
168
185
  * 无关不动(对比 invalidate() 的 context-lost 全量口径)。纹理句柄交 GC
169
186
  * 终结(psdBakes 整删同语义,字体加载事件低频有界)。 */
170
- invalidateTextDerivedBakes() {
187
+ invalidateTextDerivedBakes(gl) {
188
+ for (const tex of this.liveSrcTexes) {
189
+ if (gl.isTexture(tex))
190
+ gl.deleteTexture(tex);
191
+ }
192
+ this.liveSrcTexes.clear();
193
+ for (const rt of this.liveTargetRts) {
194
+ if (gl.isTexture(rt.tex))
195
+ gl.deleteTexture(rt.tex);
196
+ if (gl.isFramebuffer(rt.fb))
197
+ gl.deleteFramebuffer(rt.fb);
198
+ }
199
+ this.liveTargetRts.clear();
171
200
  this.sources = new WeakMap();
172
201
  this.targets = new WeakMap();
173
202
  }
174
203
  /** context restored 后失效(P6-2 恢复链):程序/RenderTarget/MSAA 缓冲/VBO
175
204
  * 随上下文销毁,签名缓存按 sig 命中死句柄——程序置空触发重编译、缓存清空
176
205
  * 触发重建(slot/allocTarget 路径) */
177
- invalidate() {
206
+ invalidate(gl) {
207
+ this.invalidateTextDerivedBakes(gl);
178
208
  this.maskProg = null;
179
209
  this.downProg = null;
180
210
  this.blurProg = null;
@@ -184,8 +214,6 @@ export class GpuFxPainter {
184
214
  this.maskRt = null;
185
215
  this.maskMsaa = null;
186
216
  this.scratch = [];
187
- this.sources = new WeakMap();
188
- this.targets = new WeakMap();
189
217
  this.meshBufs = new WeakMap();
190
218
  }
191
219
  compile(gl, fs, vs = VERT_TRI) {
@@ -375,6 +403,7 @@ export class GpuFxPainter {
375
403
  // 死句柄守卫(批次 342,slot 同注):外部删除过的缓存句柄按 miss 重传
376
404
  if (src && (src.sig !== sig || !gl.isTexture(src.tex))) {
377
405
  gl.deleteTexture(src.tex);
406
+ this.liveSrcTexes.delete(src.tex);
378
407
  src = undefined;
379
408
  }
380
409
  if (!src) {
@@ -387,6 +416,7 @@ export class GpuFxPainter {
387
416
  gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR);
388
417
  gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
389
418
  gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
419
+ this.liveSrcTexes.add(tex);
390
420
  src = { sig, tex, w: cw, h: ch };
391
421
  this.sources.set(node, src);
392
422
  }
@@ -20,8 +20,10 @@
20
20
  * box 核与 skia 的偶数宽半像素相位亚像素级差。
21
21
  */
22
22
  import { type ShadowDecl } from '../core/shadow';
23
+ import type { RenderEpoch } from './renderEpoch';
23
24
  import { type SceneNode } from '../model/scene';
24
25
  export declare class GpuShadowBaker {
26
+ private readonly epoch?;
25
27
  /** 剪影场景空间纹理缓存(canvas 栅格化直出;签名不含平移——拖拽零重栅格化) */
26
28
  private silhouettes;
27
29
  /** 节点最终烘焙目标(签名与剪影同基:平移全帧复用,旋转/缩放/内容变化重跑 passes) */
@@ -30,9 +32,19 @@ export declare class GpuShadowBaker {
30
32
  private finalProg;
31
33
  private b1;
32
34
  private b2;
33
- /** context restored 后失效(P6-2 恢复链):程序/RenderTarget 随上下文销毁,
34
- * 签名缓存会按 sig 命中死句柄——程序置空触发重编译、缓存清空触发重烘 */
35
- invalidate(): void;
35
+ /** 在世纹理/RenderTarget 登记册(批次 392):WeakMap 不可枚举——invalidate
36
+ * 真删靠此册(原整换弃管在字体迟到失效(context 活着)= GL 滞留至真实
37
+ * context loss,批次 375 消灭的泄漏类在 GPU 路径的补口) */
38
+ private readonly liveRts;
39
+ private readonly liveSilTexes;
40
+ /** 纪元(批次 392):sig 变化删除已被保留式快照引用的烘焙产物时 bump——
41
+ * 今天「sig 变化 ⇒ 节点染脏 ⇒ 不进保留式重放」是偶然安全,接线后结构性
42
+ * 安全(缺省 undefined = 直构单测独立口径,等价旧行为) */
43
+ constructor(epoch?: RenderEpoch | undefined);
44
+ /** 失效(context lost 恢复与字体迟到两口径同调):登记册真删(isTexture/
45
+ * isFramebuffer 守卫——context 恢复路径句柄属已死上下文,甄别跳过)+
46
+ * 程序/RenderTarget 置空触发重编译重烘。bump 由调用方 ShadowPainter 统一 */
47
+ invalidate(gl: WebGL2RenderingContext): void;
36
48
  private compile;
37
49
  private ensurePrograms;
38
50
  private ensureTarget;
@@ -84,6 +84,7 @@ const bakeSig = (node, decl, w, h) => {
84
84
  /** 声明缓存键(数值化,规避浮点串噪声) */
85
85
  const shadowKeyOf = (decl) => [decl.rgba.join(','), decl.blur, decl.offsetX, decl.offsetY, decl.nonScaling ? 1 : 0].join('|');
86
86
  export class GpuShadowBaker {
87
+ epoch;
87
88
  /** 剪影场景空间纹理缓存(canvas 栅格化直出;签名不含平移——拖拽零重栅格化) */
88
89
  silhouettes = new WeakMap();
89
90
  /** 节点最终烘焙目标(签名与剪影同基:平移全帧复用,旋转/缩放/内容变化重跑 passes) */
@@ -92,9 +93,33 @@ export class GpuShadowBaker {
92
93
  finalProg = null;
93
94
  b1 = null;
94
95
  b2 = null;
95
- /** context restored 后失效(P6-2 恢复链):程序/RenderTarget 随上下文销毁,
96
- * 签名缓存会按 sig 命中死句柄——程序置空触发重编译、缓存清空触发重烘 */
97
- invalidate() {
96
+ /** 在世纹理/RenderTarget 登记册(批次 392):WeakMap 不可枚举——invalidate
97
+ * 真删靠此册(原整换弃管在字体迟到失效(context 活着)= GL 滞留至真实
98
+ * context loss,批次 375 消灭的泄漏类在 GPU 路径的补口) */
99
+ liveRts = new Set();
100
+ liveSilTexes = new Set();
101
+ /** 纪元(批次 392):sig 变化删除已被保留式快照引用的烘焙产物时 bump——
102
+ * 今天「sig 变化 ⇒ 节点染脏 ⇒ 不进保留式重放」是偶然安全,接线后结构性
103
+ * 安全(缺省 undefined = 直构单测独立口径,等价旧行为) */
104
+ constructor(epoch) {
105
+ this.epoch = epoch;
106
+ }
107
+ /** 失效(context lost 恢复与字体迟到两口径同调):登记册真删(isTexture/
108
+ * isFramebuffer 守卫——context 恢复路径句柄属已死上下文,甄别跳过)+
109
+ * 程序/RenderTarget 置空触发重编译重烘。bump 由调用方 ShadowPainter 统一 */
110
+ invalidate(gl) {
111
+ for (const rt of this.liveRts) {
112
+ if (gl.isTexture(rt.tex))
113
+ gl.deleteTexture(rt.tex);
114
+ if (gl.isFramebuffer(rt.fb))
115
+ gl.deleteFramebuffer(rt.fb);
116
+ }
117
+ this.liveRts.clear();
118
+ for (const tex of this.liveSilTexes) {
119
+ if (gl.isTexture(tex))
120
+ gl.deleteTexture(tex);
121
+ }
122
+ this.liveSilTexes.clear();
98
123
  this.blurProg = null;
99
124
  this.finalProg = null;
100
125
  this.b1 = null;
@@ -145,6 +170,7 @@ export class GpuShadowBaker {
145
170
  if (rt) {
146
171
  gl.deleteFramebuffer(rt.fb);
147
172
  gl.deleteTexture(rt.tex);
173
+ this.liveRts.delete(rt);
148
174
  }
149
175
  const tex = gl.createTexture();
150
176
  if (!tex)
@@ -163,13 +189,17 @@ export class GpuShadowBaker {
163
189
  gl.bindFramebuffer(gl.FRAMEBUFFER, fb);
164
190
  gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, tex, 0);
165
191
  gl.bindFramebuffer(gl.FRAMEBUFFER, null);
166
- return { fb, tex, w, h };
192
+ const created = { fb, tex, w, h };
193
+ this.liveRts.add(created);
194
+ return created;
167
195
  }
168
196
  /** 剪影场景空间纹理:canvas 栅格化(线性矩阵居中)→ 上传(v0=顶行画布口径) */
169
197
  silhouette(gl, node, sig, w, h) {
170
198
  let sil = this.silhouettes.get(node);
171
199
  if (sil && sil.sig !== sig) {
172
200
  gl.deleteTexture(sil.tex);
201
+ this.liveSilTexes.delete(sil.tex);
202
+ this.epoch?.bump('gpu-shadow-silhouette-rebake');
173
203
  sil = undefined;
174
204
  }
175
205
  if (!sil) {
@@ -185,6 +215,7 @@ export class GpuShadowBaker {
185
215
  const tex = createTexture2D(gl, canvas);
186
216
  if (!tex)
187
217
  return null;
218
+ this.liveSilTexes.add(tex);
188
219
  sil = { sig, tex, w, h };
189
220
  this.silhouettes.set(node, sil);
190
221
  }
@@ -225,6 +256,8 @@ export class GpuShadowBaker {
225
256
  if (entry && entry.sig !== sig) {
226
257
  gl.deleteFramebuffer(entry.rt.fb);
227
258
  gl.deleteTexture(entry.rt.tex);
259
+ this.liveRts.delete(entry.rt);
260
+ this.epoch?.bump('gpu-shadow-rebake');
228
261
  entry = undefined;
229
262
  }
230
263
  if (!entry) {
@@ -13,7 +13,7 @@ export declare class ShadowPainter {
13
13
  render(node: SceneNode): void;
14
14
  /** 失效(context lost 与字体迟到同口径):烘焙真删(批次 375——Canvas 回退
15
15
  * 路径自建纹理经登记册出清,原整换 WeakMap 弃管 = GL 滞留至 context loss;
16
- * GPU 路径纹理归 gpuShadowBaker 自管,维持其既有弃管口径)+ 纪元 bump
16
+ * GPU 路径纹理经批次 392 登记册同真删)+ 纪元 bump
17
17
  * (真删后保留式快照若持引用——重放死句柄即阴影消失,经纪元入门链) */
18
18
  invalidate(): void;
19
19
  }
@@ -47,7 +47,7 @@ export class ShadowPainter {
47
47
  const sig = [shadowKey(decl), node.raw.type, node.matrix.join(','), node.dims.x, node.dims.y, content, animVersion].join(';');
48
48
  if (isGpuShadowEnabled()) {
49
49
  if (!this.gpuShadowBaker)
50
- this.gpuShadowBaker = new GpuShadowBaker();
50
+ this.gpuShadowBaker = new GpuShadowBaker(this.host.renderEpoch);
51
51
  const bake = this.gpuShadowBaker.render(this.host.gl, node, decl, this.host.canvasEl.width, this.host.canvasEl.height);
52
52
  if (bake)
53
53
  this.host.batch.pushQuad([1, 0, 0, 1, node.matrix[4], node.matrix[5]], bake.w, bake.h, [1, 1, 1, node.renderOpacity], bake.tex);
@@ -80,7 +80,7 @@ export class ShadowPainter {
80
80
  }
81
81
  /** 失效(context lost 与字体迟到同口径):烘焙真删(批次 375——Canvas 回退
82
82
  * 路径自建纹理经登记册出清,原整换 WeakMap 弃管 = GL 滞留至 context loss;
83
- * GPU 路径纹理归 gpuShadowBaker 自管,维持其既有弃管口径)+ 纪元 bump
83
+ * GPU 路径纹理经批次 392 登记册同真删)+ 纪元 bump
84
84
  * (真删后保留式快照若持引用——重放死句柄即阴影消失,经纪元入门链) */
85
85
  invalidate() {
86
86
  for (const tex of this.liveTexes)
@@ -88,6 +88,6 @@ export class ShadowPainter {
88
88
  this.liveTexes.clear();
89
89
  this.shadowBakes = new WeakMap();
90
90
  this.host.renderEpoch?.bump('shadow-bake-invalidate');
91
- this.gpuShadowBaker?.invalidate();
91
+ this.gpuShadowBaker?.invalidate(this.host.gl);
92
92
  }
93
93
  }
@@ -9,12 +9,14 @@
9
9
  */
10
10
  import { GpuFxPainter } from './gpuFx';
11
11
  import { GpuImageFilterChain } from './gpuImageFilters';
12
+ import type { RenderEpoch } from './renderEpoch';
12
13
  export declare class SharedGpuPainters {
13
14
  private readonly gl;
15
+ private readonly epoch?;
14
16
  private fxPainter;
15
17
  private filterChain;
16
- constructor(gl: WebGL2RenderingContext);
17
- /** PS 图层样式画家(惰性;clipMask/PSD 效果共用) */
18
+ constructor(gl: WebGL2RenderingContext, epoch?: RenderEpoch | undefined);
19
+ /** PS 图层样式画家(惰性;clipMask/PSD 效果共用;纪元接入批次 392) */
18
20
  get fx(): GpuFxPainter;
19
21
  /** 图片滤镜 GL 链(惰性;图片分支/Mask clipImage 读回共用) */
20
22
  get filters(): GpuImageFilterChain;
@@ -11,15 +11,17 @@ import { GpuFxPainter } from './gpuFx';
11
11
  import { GpuImageFilterChain } from './gpuImageFilters';
12
12
  export class SharedGpuPainters {
13
13
  gl;
14
+ epoch;
14
15
  fxPainter = null;
15
16
  filterChain = null;
16
- constructor(gl) {
17
+ constructor(gl, epoch) {
17
18
  this.gl = gl;
19
+ this.epoch = epoch;
18
20
  }
19
- /** PS 图层样式画家(惰性;clipMask/PSD 效果共用) */
21
+ /** PS 图层样式画家(惰性;clipMask/PSD 效果共用;纪元接入批次 392) */
20
22
  get fx() {
21
23
  if (!this.fxPainter)
22
- this.fxPainter = new GpuFxPainter();
24
+ this.fxPainter = new GpuFxPainter(this.epoch);
23
25
  return this.fxPainter;
24
26
  }
25
27
  /** 图片滤镜 GL 链(惰性;图片分支/Mask clipImage 读回共用) */
@@ -30,11 +32,11 @@ export class SharedGpuPainters {
30
32
  }
31
33
  /** context lost 恢复:程序/RT/签名缓存全失效(实例保留,走惰性重建) */
32
34
  invalidate() {
33
- this.fxPainter?.invalidate();
35
+ this.fxPainter?.invalidate(this.gl);
34
36
  this.filterChain?.invalidate();
35
37
  }
36
38
  /** 字体迟到失效:仅 fx 的文本派生源/目标缓存 */
37
39
  invalidateTextDerivedBakes() {
38
- this.fxPainter?.invalidateTextDerivedBakes();
40
+ this.fxPainter?.invalidateTextDerivedBakes(this.gl);
39
41
  }
40
42
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yft-design/engine",
3
- "version": "0.0.11",
3
+ "version": "0.0.12",
4
4
  "description": "yft-design 的 WebGL2 画布引擎:接受 fabric toObject 格式 JSON,输出 GL 画布 / 位图(任意倍率 FBO 读回)/ SVG(纯数据序列化器)",
5
5
  "repository": {
6
6
  "type": "git",