@yft-design/engine 0.0.0-stage → 0.0.2
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.
- package/README.md +39 -2
- package/assets/images/greyfloral.png +0 -0
- package/assets/images/honey_im_subtle.png +0 -0
- package/assets/images/nasty_fabric.png +0 -0
- package/assets/images/retina_wood.png +0 -0
- package/assets/images/rotate.png +0 -0
- package/dist/EngineCanvas.d.ts +500 -0
- package/dist/EngineCanvas.js +927 -0
- package/dist/core/canvasPerf.d.ts +23 -0
- package/dist/core/canvasPerf.js +170 -0
- package/dist/core/color.d.ts +52 -0
- package/dist/core/color.js +107 -0
- package/dist/core/distanceField.d.ts +15 -0
- package/dist/core/distanceField.js +92 -0
- package/dist/core/events.d.ts +34 -0
- package/dist/core/events.js +52 -0
- package/dist/core/gradient.d.ts +97 -0
- package/dist/core/gradient.js +175 -0
- package/dist/core/imageFilters.d.ts +150 -0
- package/dist/core/imageFilters.js +330 -0
- package/dist/core/mat2d.d.ts +151 -0
- package/dist/core/mat2d.js +241 -0
- package/dist/core/pathData.d.ts +53 -0
- package/dist/core/pathData.js +926 -0
- package/dist/core/pattern.d.ts +38 -0
- package/dist/core/pattern.js +40 -0
- package/dist/core/point.d.ts +59 -0
- package/dist/core/point.js +119 -0
- package/dist/core/psdEffects.d.ts +126 -0
- package/dist/core/psdEffects.js +158 -0
- package/dist/core/roundedRect.d.ts +62 -0
- package/dist/core/roundedRect.js +163 -0
- package/dist/core/shadow.d.ts +51 -0
- package/dist/core/shadow.js +47 -0
- package/dist/core/snap.d.ts +232 -0
- package/dist/core/snap.js +793 -0
- package/dist/core/stroke.d.ts +41 -0
- package/dist/core/stroke.js +44 -0
- package/dist/core/triangulate.d.ts +24 -0
- package/dist/core/triangulate.js +118 -0
- package/dist/debug/canvasInspection.d.ts +92 -0
- package/dist/debug/canvasInspection.js +113 -0
- package/dist/debug/pixelDiff.d.ts +22 -0
- package/dist/debug/pixelDiff.js +64 -0
- package/dist/debug/seed.d.ts +473 -0
- package/dist/debug/seed.js +3803 -0
- package/dist/decoders/gif2sprite.d.ts +9 -0
- package/dist/decoders/gif2sprite.js +84 -0
- package/dist/decoders/webp2sprite.d.ts +22 -0
- package/dist/decoders/webp2sprite.js +133 -0
- package/dist/engineFlag.d.ts +72 -0
- package/dist/engineFlag.js +86 -0
- package/dist/export/SceneExporter.d.ts +92 -0
- package/dist/export/SceneExporter.js +280 -0
- package/dist/export/glExport.d.ts +66 -0
- package/dist/export/glExport.js +79 -0
- package/dist/export/svgExport.d.ts +277 -0
- package/dist/export/svgExport.js +1790 -0
- package/dist/index.d.ts +52 -0
- package/dist/index.js +48 -0
- package/dist/interact/animationPlayback.d.ts +125 -0
- package/dist/interact/animationPlayback.js +344 -0
- package/dist/interact/canvasInteractions.d.ts +50 -0
- package/dist/interact/canvasInteractions.js +150 -0
- package/dist/interact/cropSession.d.ts +123 -0
- package/dist/interact/cropSession.js +526 -0
- package/dist/interact/dblClick.d.ts +51 -0
- package/dist/interact/dblClick.js +106 -0
- package/dist/interact/expandSession.d.ts +107 -0
- package/dist/interact/expandSession.js +281 -0
- package/dist/interact/hotkeyActions.d.ts +16 -0
- package/dist/interact/hotkeyActions.js +41 -0
- package/dist/interact/pathSession.d.ts +141 -0
- package/dist/interact/pathSession.js +480 -0
- package/dist/interact/pointer.d.ts +106 -0
- package/dist/interact/pointer.js +1594 -0
- package/dist/interact/pointerTablePuzzle.d.ts +100 -0
- package/dist/interact/pointerTablePuzzle.js +358 -0
- package/dist/interact/pointerTransform.d.ts +86 -0
- package/dist/interact/pointerTransform.js +440 -0
- package/dist/interact/pointerTypes.d.ts +577 -0
- package/dist/interact/pointerTypes.js +96 -0
- package/dist/interact/snapGuide.d.ts +127 -0
- package/dist/interact/snapGuide.js +376 -0
- package/dist/interact/tableCellEditing.d.ts +61 -0
- package/dist/interact/tableCellEditing.js +198 -0
- package/dist/interact/tableInteraction.d.ts +55 -0
- package/dist/interact/tableInteraction.js +212 -0
- package/dist/interact/textEditing.d.ts +77 -0
- package/dist/interact/textEditing.js +410 -0
- package/dist/interact/warpFacade.d.ts +36 -0
- package/dist/interact/warpFacade.js +51 -0
- package/dist/interact/warpSession.d.ts +191 -0
- package/dist/interact/warpSession.js +582 -0
- package/dist/interact/wheelScroll.d.ts +62 -0
- package/dist/interact/wheelScroll.js +72 -0
- package/dist/model/alphaHit.d.ts +59 -0
- package/dist/model/alphaHit.js +262 -0
- package/dist/model/animation.d.ts +228 -0
- package/dist/model/animation.js +510 -0
- package/dist/model/arcLayout.d.ts +54 -0
- package/dist/model/arcLayout.js +307 -0
- package/dist/model/arcTextTransform.d.ts +7 -0
- package/dist/model/arcTextTransform.js +87 -0
- package/dist/model/compatEvents.d.ts +135 -0
- package/dist/model/compatEvents.js +73 -0
- package/dist/model/compatObject.d.ts +716 -0
- package/dist/model/compatObject.js +1579 -0
- package/dist/model/cropEdit.d.ts +118 -0
- package/dist/model/cropEdit.js +497 -0
- package/dist/model/document.d.ts +294 -0
- package/dist/model/document.js +572 -0
- package/dist/model/expandEdit.d.ts +93 -0
- package/dist/model/expandEdit.js +161 -0
- package/dist/model/fabricPrimitives.d.ts +156 -0
- package/dist/model/fabricPrimitives.js +9 -0
- package/dist/model/filler.d.ts +53 -0
- package/dist/model/filler.js +1 -0
- package/dist/model/groupAssemble.d.ts +7 -0
- package/dist/model/groupAssemble.js +98 -0
- package/dist/model/groupChildMove.d.ts +46 -0
- package/dist/model/groupChildMove.js +145 -0
- package/dist/model/groupResize.d.ts +78 -0
- package/dist/model/groupResize.js +108 -0
- package/dist/model/handles.d.ts +40 -0
- package/dist/model/handles.js +29 -0
- package/dist/model/imageMaskBake.d.ts +75 -0
- package/dist/model/imageMaskBake.js +136 -0
- package/dist/model/lineConstruct.d.ts +13 -0
- package/dist/model/lineConstruct.js +79 -0
- package/dist/model/maskCropEdit.d.ts +64 -0
- package/dist/model/maskCropEdit.js +90 -0
- package/dist/model/pathBackground.d.ts +51 -0
- package/dist/model/pathBackground.js +196 -0
- package/dist/model/pathConstruct.d.ts +27 -0
- package/dist/model/pathConstruct.js +55 -0
- package/dist/model/pathEdit.d.ts +114 -0
- package/dist/model/pathEdit.js +378 -0
- package/dist/model/puzzleEdit.d.ts +136 -0
- package/dist/model/puzzleEdit.js +742 -0
- package/dist/model/puzzleLayout.d.ts +91 -0
- package/dist/model/puzzleLayout.js +143 -0
- package/dist/model/scene.d.ts +1004 -0
- package/dist/model/scene.js +2841 -0
- package/dist/model/schema.d.ts +290 -0
- package/dist/model/schema.js +13 -0
- package/dist/model/shapePath.d.ts +14 -0
- package/dist/model/shapePath.js +136 -0
- package/dist/model/tableEdit.d.ts +196 -0
- package/dist/model/tableEdit.js +751 -0
- package/dist/model/tableFacade.d.ts +6 -0
- package/dist/model/tableFacade.js +808 -0
- package/dist/model/tableLayout.d.ts +85 -0
- package/dist/model/tableLayout.js +193 -0
- package/dist/model/textLayout.d.ts +357 -0
- package/dist/model/textLayout.js +822 -0
- package/dist/render/GLBlend.d.ts +40 -0
- package/dist/render/GLBlend.js +270 -0
- package/dist/render/GLContext.d.ts +25 -0
- package/dist/render/GLContext.js +48 -0
- package/dist/render/GLIsolate.d.ts +46 -0
- package/dist/render/GLIsolate.js +188 -0
- package/dist/render/GLTextureCache.d.ts +86 -0
- package/dist/render/GLTextureCache.js +187 -0
- package/dist/render/GlyphAtlas.d.ts +151 -0
- package/dist/render/GlyphAtlas.js +404 -0
- package/dist/render/MeshBatch.d.ts +123 -0
- package/dist/render/MeshBatch.js +416 -0
- package/dist/render/QuadBatch.d.ts +138 -0
- package/dist/render/QuadBatch.js +490 -0
- package/dist/render/SceneRenderer.d.ts +186 -0
- package/dist/render/SceneRenderer.js +700 -0
- package/dist/render/SourceManager.d.ts +121 -0
- package/dist/render/SourceManager.js +505 -0
- package/dist/render/TextRenderer.d.ts +140 -0
- package/dist/render/TextRenderer.js +795 -0
- package/dist/render/arcText.d.ts +40 -0
- package/dist/render/arcText.js +187 -0
- package/dist/render/batchOrder.d.ts +105 -0
- package/dist/render/batchOrder.js +168 -0
- package/dist/render/blendMode.d.ts +35 -0
- package/dist/render/blendMode.js +142 -0
- package/dist/render/clipMaskPainter.d.ts +17 -0
- package/dist/render/clipMaskPainter.js +121 -0
- package/dist/render/fontInvalidation.d.ts +25 -0
- package/dist/render/fontInvalidation.js +77 -0
- package/dist/render/fontInvalidationController.d.ts +76 -0
- package/dist/render/fontInvalidationController.js +114 -0
- package/dist/render/frameOverlay.d.ts +62 -0
- package/dist/render/frameOverlay.js +124 -0
- package/dist/render/framePipeline.d.ts +99 -0
- package/dist/render/framePipeline.js +95 -0
- package/dist/render/gpuFilterPasses.d.ts +25 -0
- package/dist/render/gpuFilterPasses.js +883 -0
- package/dist/render/gpuFx.d.ts +136 -0
- package/dist/render/gpuFx.js +614 -0
- package/dist/render/gpuImageFilters.d.ts +59 -0
- package/dist/render/gpuImageFilters.js +289 -0
- package/dist/render/gpuShadow.d.ts +52 -0
- package/dist/render/gpuShadow.js +289 -0
- package/dist/render/gradientRamp.d.ts +45 -0
- package/dist/render/gradientRamp.js +74 -0
- package/dist/render/imageEffects.d.ts +123 -0
- package/dist/render/imageEffects.js +390 -0
- package/dist/render/maskRender.d.ts +92 -0
- package/dist/render/maskRender.js +224 -0
- package/dist/render/progressiveLoad.d.ts +45 -0
- package/dist/render/progressiveLoad.js +86 -0
- package/dist/render/psdEffectPainter.d.ts +34 -0
- package/dist/render/psdEffectPainter.js +309 -0
- package/dist/render/puzzleClamp.d.ts +28 -0
- package/dist/render/puzzleClamp.js +30 -0
- package/dist/render/retainedFrame.d.ts +85 -0
- package/dist/render/retainedFrame.js +193 -0
- package/dist/render/ruler.d.ts +90 -0
- package/dist/render/ruler.js +287 -0
- package/dist/render/scrollText.d.ts +65 -0
- package/dist/render/scrollText.js +261 -0
- package/dist/render/selectionOverlay.d.ts +318 -0
- package/dist/render/selectionOverlay.js +921 -0
- package/dist/render/shaders.d.ts +38 -0
- package/dist/render/shaders.js +314 -0
- package/dist/render/shadowBake.d.ts +43 -0
- package/dist/render/shadowBake.js +202 -0
- package/dist/render/shadowPainter.d.ts +13 -0
- package/dist/render/shadowPainter.js +80 -0
- package/dist/render/sharedGpuPainters.d.ts +25 -0
- package/dist/render/sharedGpuPainters.js +40 -0
- package/dist/render/sourceHydration.d.ts +12 -0
- package/dist/render/sourceHydration.js +48 -0
- package/dist/render/strokeBake.d.ts +85 -0
- package/dist/render/strokeBake.js +515 -0
- package/dist/render/strokePainter.d.ts +28 -0
- package/dist/render/strokePainter.js +119 -0
- package/dist/render/strokeSdf.d.ts +35 -0
- package/dist/render/strokeSdf.js +74 -0
- package/dist/render/svgRaster.d.ts +46 -0
- package/dist/render/svgRaster.js +71 -0
- package/dist/render/tableOverlay.d.ts +38 -0
- package/dist/render/tableOverlay.js +233 -0
- package/dist/render/textHighlight.d.ts +117 -0
- package/dist/render/textHighlight.js +380 -0
- package/dist/render/textureUpload.d.ts +18 -0
- package/dist/render/textureUpload.js +26 -0
- package/dist/render/verticalText.d.ts +38 -0
- package/dist/render/verticalText.js +63 -0
- package/dist/render/warpText.d.ts +58 -0
- package/dist/render/warpText.js +380 -0
- package/dist/render/workspaceBackdrop.d.ts +35 -0
- package/dist/render/workspaceBackdrop.js +71 -0
- package/dist/render/workspaceChecker.d.ts +54 -0
- package/dist/render/workspaceChecker.js +170 -0
- package/dist/render/workspaceGlow.d.ts +51 -0
- package/dist/render/workspaceGlow.js +171 -0
- package/package.json +44 -3
|
@@ -0,0 +1,309 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* PSD 效果渲染画家(从 SceneRenderer 拆出)。
|
|
3
|
+
*
|
|
4
|
+
* PSD 效果(P3-5a 图片族 + 文本族统一管线):dropShadow 烘焙 quad 垫在内容
|
|
5
|
+
* 之下(main drawShadows/_renderTextDropShadow 在内容渲染之前)、solidFill/
|
|
6
|
+
* stroke 层盖在内容之上(drawFills/drawStrokes 与 _renderTextStroke 在后)。
|
|
7
|
+
* 文本走「剪影 → 位图算子」统一管线(buildTextEffectSource 换源),与 main
|
|
8
|
+
* 活文本的逐字矢量路径(_renderChar effect 分支)为 AA 级近似等价——描边三
|
|
9
|
+
* 对齐即位图三区间(outside≡线宽×2+补填充 / inside≡×2+source-atop /
|
|
10
|
+
* center≡居中)。路径族(P3-5c)只有 dropShadow。签名 = 效果声明 + 矩阵/
|
|
11
|
+
* 尺寸 + 源指纹(图片 src / 文本内容+字体面),变化才重烘焙;与原生 shadow
|
|
12
|
+
* 字段可共存(原生先画——fabric 语义,PSD 随后)。
|
|
13
|
+
*
|
|
14
|
+
* 帧级烘焙预算/续帧标记(frame.bakeDeadline/bakeMore)挂在共享的 FrameState
|
|
15
|
+
* 上(EngineCanvas.render 每帧 beginFrame 复位)——渲染尾部分帧摊销协议
|
|
16
|
+
* 不变,见 SceneRenderer 头注。
|
|
17
|
+
*/
|
|
18
|
+
import { parsePsdEffects, psdEffectsKey } from '../core/psdEffects';
|
|
19
|
+
import { composeMatrix, multiply } from '../core/mat2d';
|
|
20
|
+
import { isGpuPsdFillEnabled, isGpuPsdShadowEnabled } from '../engineFlag';
|
|
21
|
+
import { AnimatedNode, MaskNode, TextNode, isTextBitmapState } from '../model/scene';
|
|
22
|
+
import { pickZoomBucket } from './GlyphAtlas';
|
|
23
|
+
import { bakePathEffectShadow, bakePsdShadow, bakePsdSolidFill, bakePsdStrokes, buildTextEffectSource, strokeSupersampleCap, imageFiltersSig } from './imageEffects';
|
|
24
|
+
import { createTexture2D } from './textureUpload';
|
|
25
|
+
import { clampQuadToPuzzleBox } from './puzzleClamp';
|
|
26
|
+
/** PSD 烘焙分帧预算(每帧毫秒上限)与缩放 settle 窗口(beginFrame 侧共用) */
|
|
27
|
+
export const FX_BAKE_BUDGET_MS = 6;
|
|
28
|
+
export const FX_SETTLE_MS = 160;
|
|
29
|
+
/**
|
|
30
|
+
* 位图态 fx 框架节点(批次 314 七补):PSD 效果的烘焙/铺放全链吃 node.matrix
|
|
31
|
+
* (bake setTransform/签名/quad 铺放),位图态框架矩阵=渲染 quad 同款本地系
|
|
32
|
+
* 组合 node.matrix∘translate(renderRect.x,y)∘rotate(-angle)(PSD 图层像素=
|
|
33
|
+
* 文档系轴对齐,元素矩阵的旋转须就地逆旋——与 SceneRenderer 位图分支同式)。
|
|
34
|
+
* 原型 shim 只覆写 matrix 读位,其余成员全继承(instanceof 族判定/raw/dims
|
|
35
|
+
* 语义不变;dims 位图态本就=bitmapRect w/h);矩阵 getter 每访问即时组合——
|
|
36
|
+
* 拖拽每帧改 node.matrix,不得吃建 shim 时的陈旧值。WeakMap 记忆化 shim 本体
|
|
37
|
+
* ——GPU fx 画家按 node 记缓存,逐帧新 shim 会击穿缓存恒重烘。
|
|
38
|
+
*/
|
|
39
|
+
const bitmapFxShims = new WeakMap();
|
|
40
|
+
export const bitmapFxNode = (node) => {
|
|
41
|
+
let shim = bitmapFxShims.get(node);
|
|
42
|
+
if (!shim) {
|
|
43
|
+
shim = Object.create(node);
|
|
44
|
+
Object.defineProperty(shim, 'matrix', {
|
|
45
|
+
get: () => {
|
|
46
|
+
const r = node.bitmapRect;
|
|
47
|
+
let m = node.matrix;
|
|
48
|
+
if (r.x !== 0 || r.y !== 0)
|
|
49
|
+
m = multiply(m, [1, 0, 0, 1, r.x, r.y]);
|
|
50
|
+
if (r.angle)
|
|
51
|
+
m = multiply(m, composeMatrix({ angle: -r.angle }));
|
|
52
|
+
return m;
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
bitmapFxShims.set(node, shim);
|
|
56
|
+
}
|
|
57
|
+
return shim;
|
|
58
|
+
};
|
|
59
|
+
export class PsdEffectPainter {
|
|
60
|
+
host;
|
|
61
|
+
frame;
|
|
62
|
+
gpu;
|
|
63
|
+
/** 拼图布局盒实时读取(递归状态归 SceneRenderer,效果层铺放钳制共用) */
|
|
64
|
+
getPuzzleBox;
|
|
65
|
+
/** PSD 效果烘焙缓存(P3-5a 图片族 + 文本族统一管线):sigBase = 效果声明 +
|
|
66
|
+
* 矩阵/尺寸/源指纹(内容变化即失效重烘);bucket = 文本族缩放桶(仅它变化
|
|
67
|
+
* 时走 stale 延迟重烘——跨桶烘焙是重操作,须避开缩放手势,见 noteVptScaleChange) */
|
|
68
|
+
psdBakes = new WeakMap();
|
|
69
|
+
/** 最近一次视口缩放变化时刻(stale 判定的手势窗口)与 settle 定时器 */
|
|
70
|
+
vptChangedAt = 0;
|
|
71
|
+
fxSettleTimer = null;
|
|
72
|
+
constructor(host, frame, gpu, getPuzzleBox) {
|
|
73
|
+
this.host = host;
|
|
74
|
+
this.frame = frame;
|
|
75
|
+
this.gpu = gpu;
|
|
76
|
+
this.getPuzzleBox = getPuzzleBox;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* 视口缩放变化通知(文本特效 stale 重烘的手势窗口):记录时刻 + 160ms
|
|
80
|
+
* settle 定时器——持续缩放期间零重烘焙(跨桶烘焙百毫秒级,卡手势不可接受),
|
|
81
|
+
* 停止后由 settle 帧按每帧预算分帧补齐(frame.bakeDeadline/bakeMore)。
|
|
82
|
+
*/
|
|
83
|
+
noteVptScaleChange() {
|
|
84
|
+
this.vptChangedAt = performance.now();
|
|
85
|
+
if (this.fxSettleTimer !== null)
|
|
86
|
+
clearTimeout(this.fxSettleTimer);
|
|
87
|
+
this.fxSettleTimer = window.setTimeout(() => {
|
|
88
|
+
this.fxSettleTimer = null;
|
|
89
|
+
this.host.requestRenderAll();
|
|
90
|
+
}, FX_SETTLE_MS);
|
|
91
|
+
}
|
|
92
|
+
render(node, phase) {
|
|
93
|
+
// 路径族(P3-5c):只有 dropShadow[] 多层投影(PathCommon.renderShadow);
|
|
94
|
+
// solidFill/stroke 效果是图片/文本族语义(renderFillImage/drawStrokes 吃源位图)
|
|
95
|
+
const isTextFx = node.isTextType && node instanceof TextNode;
|
|
96
|
+
// 位图态文本(批次 314 七补):效果源=renderSrc 位图(图层位图不含烘焙
|
|
97
|
+
// 特效——数值探针实证),编辑会话中(editingNode)与位图未就绪(无
|
|
98
|
+
// imageEl)回落字形剪影源——与渲染层同源分派,效果层始终贴内容
|
|
99
|
+
const isBitmapText = isTextFx && isTextBitmapState(node) && node !== this.host.editingNode && !!node.imageEl;
|
|
100
|
+
// Mask PSD effects(B1(余) 收尾片):drawShadows/drawFills/drawStrokes 的
|
|
101
|
+
// 蒙版链——投影垫底(形状源)、填充/描边盖合成层(应用 render() 覆写序)
|
|
102
|
+
const isMaskFx = node instanceof MaskNode;
|
|
103
|
+
if (!node.isImageType && node.raw.type !== 'Path' && !isTextFx && !isMaskFx)
|
|
104
|
+
return;
|
|
105
|
+
if (phase === 'above' && !node.isImageType && !isTextFx && !isMaskFx)
|
|
106
|
+
return;
|
|
107
|
+
// 位图源未就绪不烘焙也不入缓存(批次 177 修复):首帧 imageEl 尚未装载时
|
|
108
|
+
// paintSource 为 null,fills/strokes 全空——空 bake 按签名永久缓存后,装载
|
|
109
|
+
// 完成也不再重烘,颜色叠加整层丢失(15.psd 背景拷贝层白图裸奔实证)。
|
|
110
|
+
// 此处直接返回,装载 settle 触发的下一帧重走完整烘焙
|
|
111
|
+
if (node.isImageType && !(node instanceof AnimatedNode) && !node.imageEl)
|
|
112
|
+
return;
|
|
113
|
+
const decls = parsePsdEffects(node.raw.effects, isTextFx ? { text: true } : {});
|
|
114
|
+
if (!decls)
|
|
115
|
+
return;
|
|
116
|
+
const cropSig = node.cropRect ? `${node.cropRect.sx},${node.cropRect.sy},${node.cropRect.sw},${node.cropRect.sh}` : '';
|
|
117
|
+
// 位图态指纹=renderSrc(七补):装载在途→就绪、位图换源、转正(renderSrc
|
|
118
|
+
// 删除回字形口径)三类迁移都翻签名触发重烘,杜绝陈旧烘焙
|
|
119
|
+
const srcFingerprint = isBitmapText
|
|
120
|
+
? `bmp:${node.raw.renderSrc}`
|
|
121
|
+
: isTextFx
|
|
122
|
+
? JSON.stringify([
|
|
123
|
+
node.raw.text,
|
|
124
|
+
node.raw.styles,
|
|
125
|
+
node.raw.fontFamily,
|
|
126
|
+
node.raw.fontSize,
|
|
127
|
+
node.raw.fontWeight,
|
|
128
|
+
node.raw.fontStyle,
|
|
129
|
+
node.raw.lineHeight,
|
|
130
|
+
node.raw.charSpacing,
|
|
131
|
+
node.raw.textAlign,
|
|
132
|
+
node.raw.paragraph ?? null
|
|
133
|
+
])
|
|
134
|
+
: typeof node.raw.src === 'string'
|
|
135
|
+
? `${node.raw.src}|${cropSig}${imageFiltersSig(node)}`
|
|
136
|
+
: cropSig;
|
|
137
|
+
const animVersion = node instanceof AnimatedNode ? `v${node.contentVersion}` : '';
|
|
138
|
+
// 缩放桶(文本族):特效层随字形图集同桶重烘焙——1× 烘焙在放大态被 GPU
|
|
139
|
+
// 拉伸发糊(文字本体跨桶重栅格化保持清晰,效果层必须同步;有效缩放同
|
|
140
|
+
// 字形管线 = zoom×dpr×对象 worldScale,表格/嵌套组放大不糊);描边另乘 2
|
|
141
|
+
// 保持 EDT 环边的 AA 超采样(受 strokeSupersampleCap 面积预算封顶)。
|
|
142
|
+
// 图片/路径族维持 1×(位图重采样本就随 zoom)——位图态文本同图片族口径
|
|
143
|
+
//(源是位图非字形,桶升无清晰度收益)。
|
|
144
|
+
const fxRs = isTextFx && !isBitmapText ? Math.max(1, pickZoomBucket(this.host.zoom * this.host.dpr * Math.max(node.worldScale.x, node.worldScale.y))) : 1;
|
|
145
|
+
// 位图态框架节点(七补):matrix 换位图 quad 的本地系组合矩阵(rect 偏移
|
|
146
|
+
// +逆旋),烘焙 setTransform/签名/quad 铺放全链经 shim 换框;缓存键恒用
|
|
147
|
+
// 真实 node(psdBakes/psdFxShims 各自记忆化,身份稳定)
|
|
148
|
+
const fxNode = isBitmapText ? bitmapFxNode(node) : node;
|
|
149
|
+
const sigBase = [psdEffectsKey(decls), fxNode.matrix.join(','), fxNode.dims.x, fxNode.dims.y, srcFingerprint, animVersion].join(';');
|
|
150
|
+
let bake = this.psdBakes.get(node);
|
|
151
|
+
if (bake && bake.sigBase !== sigBase) {
|
|
152
|
+
// 内容/声明/矩阵变化:立即重烘(正确性优先,编辑场景单节点可承受)
|
|
153
|
+
if (bake.shadow)
|
|
154
|
+
this.host.gl.deleteTexture(bake.shadow.tex);
|
|
155
|
+
for (const f of bake.fills)
|
|
156
|
+
this.host.gl.deleteTexture(f.tex);
|
|
157
|
+
for (const s of bake.strokes)
|
|
158
|
+
this.host.gl.deleteTexture(s.tex);
|
|
159
|
+
bake = undefined;
|
|
160
|
+
}
|
|
161
|
+
if (bake && bake.bucket !== fxRs) {
|
|
162
|
+
// 仅桶差异:跨桶烘焙是重操作(百毫秒级)——缩放手势窗口内与帧预算耗尽
|
|
163
|
+
// 时沿用 stale 烘焙(略糊但几何不变,quad 是场景空间、与 zoom 无关),
|
|
164
|
+
// settle(160ms 无缩放)后按每帧预算逐节点补齐。导出窗口
|
|
165
|
+
// (applyExportViewport 接管视口)不受手势门:桶换档立即新鲜烘焙
|
|
166
|
+
// (SceneExporter 按 bakeMore 多轮重渲兜底——2026-10-09 描边接入 stale
|
|
167
|
+
// 协议时一并收口:此前缩放后 160ms 内导出会吃到手势期 stale 特效)
|
|
168
|
+
const now = performance.now();
|
|
169
|
+
const zooming = !this.host.isExporting() && (now - this.vptChangedAt < FX_SETTLE_MS || this.fxSettleTimer !== null);
|
|
170
|
+
if (zooming || now > this.frame.bakeDeadline) {
|
|
171
|
+
this.frame.bakeMore = true;
|
|
172
|
+
this.renderPsdBakeQuads(fxNode, bake, phase);
|
|
173
|
+
return;
|
|
174
|
+
}
|
|
175
|
+
if (bake.shadow)
|
|
176
|
+
this.host.gl.deleteTexture(bake.shadow.tex);
|
|
177
|
+
for (const f of bake.fills)
|
|
178
|
+
this.host.gl.deleteTexture(f.tex);
|
|
179
|
+
for (const s of bake.strokes)
|
|
180
|
+
this.host.gl.deleteTexture(s.tex);
|
|
181
|
+
bake = undefined;
|
|
182
|
+
}
|
|
183
|
+
if (!bake) {
|
|
184
|
+
const gl = this.host.gl;
|
|
185
|
+
// 统一剪影源:图片/动画 = 元素、文本 = 本地空间字形剪影画布(描边用
|
|
186
|
+
// ×2 超采样分辨率,投影/填充用桶分辨率);位图态文本=图层位图(七补,
|
|
187
|
+
// 各算子把源拉伸到 dims 铺放——位图纵横比恒同,scale 差异被拉伸吸收);
|
|
188
|
+
// Path 无源(走路径投影)
|
|
189
|
+
const imageSource = node instanceof MaskNode ? node.imageEl : node instanceof AnimatedNode ? node.paintSource : node.isImageType ? node.imageEl : isBitmapText ? node.imageEl : null;
|
|
190
|
+
const rs = imageSource ? 1 : fxRs;
|
|
191
|
+
// 描边超采样:下限 2(1× 显示下的 EDT 环边 AA),随桶升(放大态清晰),
|
|
192
|
+
// 受面积预算封顶(单节点烘焙时长上限)
|
|
193
|
+
const ss = imageSource ? 1 : Math.min(Math.max(2, fxRs), strokeSupersampleCap(node));
|
|
194
|
+
const paintSource = imageSource ?? (isTextFx ? buildTextEffectSource(node, rs) : null);
|
|
195
|
+
const strokeSource = imageSource ?? (isTextFx ? buildTextEffectSource(node, ss) : null);
|
|
196
|
+
// 裁剪源子矩形(B1):仅静态位图源(imageEl)有值——文本剪影/动画帧恒 null
|
|
197
|
+
const sourceRect = imageSource ? node.cropRect : null;
|
|
198
|
+
// GPU 化批次 1b/2(GpuFxPainter,PS 图层样式模型——默认关):投影/纯色填充
|
|
199
|
+
// 走 FBO pass(源 canvas 直出同栅格器 + box 模糊 + 填色合成);门禁未过前
|
|
200
|
+
// 回退 CPU 烘焙。渐变叠加与描边(EDT)恒走 CPU。fx 与 clipPath 蒙版共用
|
|
201
|
+
// 一个画家实例(SharedGpuPainters,防双实例重复占显存)
|
|
202
|
+
const fx = isGpuPsdShadowEnabled() || isGpuPsdFillEnabled() ? this.gpu.fx : null;
|
|
203
|
+
const pathMode = !paintSource && !isMaskFx;
|
|
204
|
+
let shadow = null;
|
|
205
|
+
if (isGpuPsdShadowEnabled() && fx) {
|
|
206
|
+
const baked = fx.bakeDropShadows(gl, fxNode, decls.dropShadows, {
|
|
207
|
+
source: paintSource,
|
|
208
|
+
sourceRect,
|
|
209
|
+
rs,
|
|
210
|
+
pathMode,
|
|
211
|
+
sig: sigBase,
|
|
212
|
+
viewportW: this.host.canvasEl.width,
|
|
213
|
+
viewportH: this.host.canvasEl.height
|
|
214
|
+
});
|
|
215
|
+
if (baked)
|
|
216
|
+
shadow = { tex: baked.tex, w: baked.w / rs, h: baked.h / rs };
|
|
217
|
+
}
|
|
218
|
+
if (!shadow) {
|
|
219
|
+
const shadowResult = paintSource ? bakePsdShadow(fxNode, decls.dropShadows, paintSource, rs, sourceRect) : bakePathEffectShadow(node, decls.dropShadows);
|
|
220
|
+
if (shadowResult) {
|
|
221
|
+
const tex = createTexture2D(gl, shadowResult.canvas, { mipmap: true });
|
|
222
|
+
if (tex) {
|
|
223
|
+
// quad 铺放尺寸 = 场景单位(rasterScale>1 时画布像素 ≠ 场景尺寸)
|
|
224
|
+
shadow = { tex, w: shadowResult.quadW, h: shadowResult.quadH };
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
const fills = [];
|
|
229
|
+
if (paintSource) {
|
|
230
|
+
for (const fillDecl of decls.solidFills) {
|
|
231
|
+
// 渐变叠加(fillType 1)恒 CPU——GPU 配方待 decl 空间映射进 shader;
|
|
232
|
+
// 裁剪图(B1)也回落 CPU——uploadLocalSource 整源 texImage2D 上传,
|
|
233
|
+
// GPU 采样无 UV 子矩形支持,裁剪窗口语义待 shader 侧跟进
|
|
234
|
+
if (isGpuPsdFillEnabled() && fx && fillDecl.kind === 'solid' && !sourceRect) {
|
|
235
|
+
const cw = Math.max(1, Math.ceil(fxNode.dims.x * rs));
|
|
236
|
+
const ch = Math.max(1, Math.ceil(fxNode.dims.y * rs));
|
|
237
|
+
const srcTex = fx.uploadLocalSource(gl, fxNode, paintSource, `${sigBase}|fillsrc`, cw, ch);
|
|
238
|
+
const tex = srcTex ? fx.bakeSolidFill(gl, fxNode, fillDecl, srcTex, cw, ch, sigBase, `fill${fills.length}`, this.host.canvasEl.width, this.host.canvasEl.height) : null;
|
|
239
|
+
if (tex) {
|
|
240
|
+
fills.push({ tex, dx: fillDecl.offset.x, dy: fillDecl.offset.y });
|
|
241
|
+
continue;
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
const fillCanvas = bakePsdSolidFill(fxNode, fillDecl, paintSource, rs, sourceRect);
|
|
245
|
+
if (!fillCanvas)
|
|
246
|
+
continue;
|
|
247
|
+
const tex = createTexture2D(gl, fillCanvas);
|
|
248
|
+
if (!tex)
|
|
249
|
+
continue;
|
|
250
|
+
fills.push({ tex, dx: fillDecl.offset.x, dy: fillDecl.offset.y });
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
// 描边层(绘制序——倒序烘焙);纹理参数与填充层一致(parity 恒等缩放下采样)。
|
|
254
|
+
// 文本不垫源副本(副本与真字形 AA 曲线不同会双叠加深边缘,见 bakePsdStrokes 头注);
|
|
255
|
+
// 位图态同不垫(GL 位图 quad 垫底即内容副本,再垫=半透明位图双叠)且
|
|
256
|
+
// halfTexelBand 关闭——位图源是栅格 alpha(图片族 EDT 整数区间 parity),
|
|
257
|
+
// 非矢量 strokeText 参考面
|
|
258
|
+
const strokes = [];
|
|
259
|
+
if (strokeSource) {
|
|
260
|
+
for (const entry of bakePsdStrokes(fxNode, decls.strokes, strokeSource, !isTextFx && !isMaskFx, ss, sourceRect, isTextFx && !isBitmapText)) {
|
|
261
|
+
const tex = createTexture2D(gl, entry.canvas);
|
|
262
|
+
if (!tex)
|
|
263
|
+
continue;
|
|
264
|
+
strokes.push({ tex, w: entry.quadW, h: entry.quadH, dx: entry.dx, dy: entry.dy });
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
bake = { sigBase, bucket: fxRs, shadow, fills, strokes };
|
|
268
|
+
this.psdBakes.set(node, bake);
|
|
269
|
+
}
|
|
270
|
+
this.renderPsdBakeQuads(fxNode, bake, phase);
|
|
271
|
+
}
|
|
272
|
+
/** 烘焙缓存的 quad 铺放(stale 命中与新烘焙共用出口) */
|
|
273
|
+
renderPsdBakeQuads(node, bake, phase) {
|
|
274
|
+
const opacity = node.renderOpacity;
|
|
275
|
+
// Mask 口径(B1(余) 收尾片):应用 drawShadows/drawFills 不乘对象 opacity
|
|
276
|
+
// (drawStrokes 才乘——其注释明言覆写 render 绕过 _setOpacity 须自行对齐),
|
|
277
|
+
// 引擎按同口径:投影/填充层恒 1、描边层 ×opacity
|
|
278
|
+
const isMaskFx = node instanceof MaskNode;
|
|
279
|
+
const layerOpacity = isMaskFx ? 1 : opacity;
|
|
280
|
+
if (phase === 'below') {
|
|
281
|
+
if (bake.shadow) {
|
|
282
|
+
const m = node.matrix;
|
|
283
|
+
// 场景空间烘焙 quad(线性恒等平移)不进拼图钳制——拼图内 Mask 的投影
|
|
284
|
+
// 溢出布局盒属极端组合,登记为已知近似
|
|
285
|
+
this.host.batch.pushQuad([1, 0, 0, 1, m[4], m[5]], bake.shadow.w, bake.shadow.h, [1, 1, 1, layerOpacity], bake.shadow.tex);
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
else {
|
|
289
|
+
// 填充层:本地空间 w×h,对象矩阵铺放(main drawFills 顺序)+ 效果层偏移
|
|
290
|
+
// (文本族 offsetEnable;图片族恒 0)
|
|
291
|
+
for (const f of bake.fills) {
|
|
292
|
+
const q = clampQuadToPuzzleBox(this.getPuzzleBox(), node, node.dims.x, node.dims.y, f.dx, f.dy);
|
|
293
|
+
if (q)
|
|
294
|
+
this.host.batch.pushQuad(q.matrix, q.w, q.h, [1, 1, 1, layerOpacity], f.tex, q.uv);
|
|
295
|
+
}
|
|
296
|
+
// 描边层最后(main drawObject 覆写:fills 后 drawStrokes);quad 中心相对
|
|
297
|
+
// 对象中心偏移 (dx,dy)(main 的 drawImage(-w/2-off) 同义 + 效果层偏移)
|
|
298
|
+
for (const s of bake.strokes) {
|
|
299
|
+
const q = clampQuadToPuzzleBox(this.getPuzzleBox(), node, s.w, s.h, s.dx, s.dy);
|
|
300
|
+
if (q)
|
|
301
|
+
this.host.batch.pushQuad(q.matrix, q.w, q.h, [1, 1, 1, opacity], s.tex, q.uv);
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
/** 失效(context lost 与字体迟到同口径):烘焙整删——GPU 画家侧缓存由 SharedGpuPainters 失效 */
|
|
306
|
+
invalidate() {
|
|
307
|
+
this.psdBakes = new WeakMap();
|
|
308
|
+
}
|
|
309
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 拼图布局盒内钳制(从 SceneRenderer 拆出的纯函数)。
|
|
3
|
+
*
|
|
4
|
+
* 布局盒状态(递归进/出拼图子树时压栈/恢复)仍归 SceneRenderer 持有;
|
|
5
|
+
* 本模块只做「quad 本地盒 ∩ 布局盒」的几何计算——SceneRenderer 的图片/蒙版
|
|
6
|
+
* 分支与 PsdEffectPainter 的效果层铺放共用。
|
|
7
|
+
*/
|
|
8
|
+
import type { Mat } from '../core/mat2d';
|
|
9
|
+
import type { SceneNode } from '../model/scene';
|
|
10
|
+
/** 拼图布局盒(组本地中心系半宽高;null = 不在拼图子树) */
|
|
11
|
+
export interface PuzzleBox {
|
|
12
|
+
hw: number;
|
|
13
|
+
hh: number;
|
|
14
|
+
}
|
|
15
|
+
/** 钳制后的 quad 铺放(矩阵 + 尺寸 + UV 子矩形) */
|
|
16
|
+
export interface PuzzleClampedQuad {
|
|
17
|
+
matrix: Mat;
|
|
18
|
+
w: number;
|
|
19
|
+
h: number;
|
|
20
|
+
uv: [number, number, number, number];
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* 拼图布局盒内钳制(fabric 组缓存裁剪对齐):quad 本地盒 ∩ 布局盒 → 子 quad +
|
|
24
|
+
* UV 子矩形(内容映射不变,仅裁可视区)。完全出界返回 null(不画);块带
|
|
25
|
+
* 旋转/缩放或不在拼图子树时原样返回。命中/选框仍走整块——fabric 缓存只裁
|
|
26
|
+
* 绘制不裁命中。offX/offY = quad 中心相对块中心的本地偏移(效果层 dx/dy)
|
|
27
|
+
*/
|
|
28
|
+
export declare const clampQuadToPuzzleBox: (box: PuzzleBox | null, node: SceneNode, w: number, h: number, offX?: number, offY?: number) => PuzzleClampedQuad | null;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { multiply } from '../core/mat2d';
|
|
2
|
+
/**
|
|
3
|
+
* 拼图布局盒内钳制(fabric 组缓存裁剪对齐):quad 本地盒 ∩ 布局盒 → 子 quad +
|
|
4
|
+
* UV 子矩形(内容映射不变,仅裁可视区)。完全出界返回 null(不画);块带
|
|
5
|
+
* 旋转/缩放或不在拼图子树时原样返回。命中/选框仍走整块——fabric 缓存只裁
|
|
6
|
+
* 绘制不裁命中。offX/offY = quad 中心相对块中心的本地偏移(效果层 dx/dy)
|
|
7
|
+
*/
|
|
8
|
+
export const clampQuadToPuzzleBox = (box, node, w, h, offX = 0, offY = 0) => {
|
|
9
|
+
const raw = node.raw;
|
|
10
|
+
const baseMatrix = offX || offY ? multiply(node.matrix, [1, 0, 0, 1, offX, offY]) : node.matrix;
|
|
11
|
+
if (!box || raw.angle || (raw.scaleX ?? 1) !== 1 || (raw.scaleY ?? 1) !== 1) {
|
|
12
|
+
// AB2
|
|
13
|
+
return { matrix: baseMatrix, w, h, uv: [0, 0, 1, 1] };
|
|
14
|
+
}
|
|
15
|
+
const cx = (raw.left ?? 0) + offX;
|
|
16
|
+
const cy = (raw.top ?? 0) + offY;
|
|
17
|
+
const x0 = Math.max(cx - w / 2, -box.hw);
|
|
18
|
+
const x1 = Math.min(cx + w / 2, box.hw);
|
|
19
|
+
const y0 = Math.max(cy - h / 2, -box.hh);
|
|
20
|
+
const y1 = Math.min(cy + h / 2, box.hh);
|
|
21
|
+
if (!(x1 - x0 > 0) || !(y1 - y0 > 0))
|
|
22
|
+
return null;
|
|
23
|
+
const uv = [(x0 - (cx - w / 2)) / w, (y0 - (cy - h / 2)) / h, (x1 - (cx - w / 2)) / w, (y1 - (cy - h / 2)) / h];
|
|
24
|
+
// 中心平移进矩阵(quad 恒以矩阵原点居中铺放)
|
|
25
|
+
const dx = (x0 + x1) / 2 - cx;
|
|
26
|
+
const dy = (y0 + y1) / 2 - cy;
|
|
27
|
+
const m = baseMatrix;
|
|
28
|
+
const matrix = [m[0], m[1], m[2], m[3], m[0] * dx + m[2] * dy + m[4], m[1] * dx + m[3] * dy + m[5]];
|
|
29
|
+
return { matrix, w: x1 - x0, h: y1 - y0, uv };
|
|
30
|
+
};
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 保留式场景帧控制器(批次 223 重落)。
|
|
3
|
+
*
|
|
4
|
+
* 全量扁平帧后把「命令表 + 两批槽位表/总量」快照留驻;后续帧门链全过时只对
|
|
5
|
+
* 脏集节点做槽位原位重推(rewind → 重推 → 计数契约校验),然后重放缓照命令
|
|
6
|
+
* 表——万级场景节点相位从每帧 O(n) 收敛为 O(dirty),干净节点的 GPU 内容跨帧
|
|
7
|
+
* 留驻。门链宁可慢不可错:结构版本/vpt/dpr/画布尺寸/纹理逐出/图集世代/
|
|
8
|
+
* 会话态/渐进装载/编辑态/动画/烘焙续帧任一在即全量帧。
|
|
9
|
+
*
|
|
10
|
+
* 图集世代门是重落的核心修复:GlyphAtlas.reset()(页上限触顶/字体迟到)删除
|
|
11
|
+
* 全部页纹理但不染脏任何节点——快照命令表持有页纹理活引用,重放死句柄 = 文本
|
|
12
|
+
* 整层不绘制(模板 273 文本消失回归的根因,理论自愈链「脏文本节点无槽位→回退
|
|
13
|
+
* 全量」对纹理级失效天然失明)。纹理级失效天然是全量帧信号,经世代/逐出计数
|
|
14
|
+
* 入门链而非逐节点染脏。
|
|
15
|
+
*
|
|
16
|
+
* 逃逸门:?retained=0 / localStorage('engine.retained'='0')(engineFlag)。
|
|
17
|
+
* 诊断日志:?retainedDebug=1——快照收录/门链回退理由/图集 reset 调用栈。
|
|
18
|
+
*/
|
|
19
|
+
import type { EngineDocument } from '../model/document';
|
|
20
|
+
import type { Mat } from '../core/mat2d';
|
|
21
|
+
import type { BatchOrder } from './batchOrder';
|
|
22
|
+
import type { GLTextureCache } from './GLTextureCache';
|
|
23
|
+
import type { GlyphAtlas } from './GlyphAtlas';
|
|
24
|
+
import type { MeshBatch } from './MeshBatch';
|
|
25
|
+
import type { QuadBatch } from './QuadBatch';
|
|
26
|
+
import type { SceneRenderer } from './SceneRenderer';
|
|
27
|
+
/** 宿主结构面(OverlayTailHost 同款先例:EngineCanvas 经结构化接入——
|
|
28
|
+
* 私有控制器不落公开 API,相位内成员仍受结构检查) */
|
|
29
|
+
export interface RetainedFrameHost {
|
|
30
|
+
readonly doc: EngineDocument;
|
|
31
|
+
readonly vpt: Mat;
|
|
32
|
+
readonly dpr: number;
|
|
33
|
+
readonly canvasEl: HTMLCanvasElement;
|
|
34
|
+
readonly batch: QuadBatch;
|
|
35
|
+
readonly meshBatch: MeshBatch;
|
|
36
|
+
readonly batchOrder: BatchOrder;
|
|
37
|
+
readonly renderer: SceneRenderer;
|
|
38
|
+
readonly textures: GLTextureCache;
|
|
39
|
+
readonly glyphAtlas: GlyphAtlas;
|
|
40
|
+
readonly progressiveLoad: {
|
|
41
|
+
readonly limit: number;
|
|
42
|
+
};
|
|
43
|
+
readonly cropSessionController: {
|
|
44
|
+
readonly active: boolean;
|
|
45
|
+
};
|
|
46
|
+
readonly expandSessionController: {
|
|
47
|
+
readonly active: boolean;
|
|
48
|
+
};
|
|
49
|
+
readonly pathSessionController: {
|
|
50
|
+
readonly active: boolean;
|
|
51
|
+
};
|
|
52
|
+
readonly warpSessionController: {
|
|
53
|
+
readonly active: boolean;
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
export declare class RetainedFrameController {
|
|
57
|
+
private readonly host;
|
|
58
|
+
private retained;
|
|
59
|
+
/** 上帧动画活动/烘焙续帧(门):动画节点逐帧自变(tick 在覆写层有脏标记,
|
|
60
|
+
* 但 mask 动态 clip 在渲染期 tick——干净节点被跳过即冻结);烘焙续帧完成
|
|
61
|
+
* 前推入的是暂态内容——两者在即全量帧 */
|
|
62
|
+
private lastFrameAnimated;
|
|
63
|
+
private lastFrameBakeMore;
|
|
64
|
+
/** 诊断:门链回退理由只在状态翻转时打点(防 rAF 级刷屏) */
|
|
65
|
+
private lastGateReason;
|
|
66
|
+
constructor(host: RetainedFrameHost);
|
|
67
|
+
/**
|
|
68
|
+
* 保留式帧尝试(render 节点相位入口):门链全过时按脏集原位重推 + 重放
|
|
69
|
+
* 快照命令表。返回 false = 任一门失败或重推异常(调用方回退全量遍历,
|
|
70
|
+
* 本帧缓冲被全量重写覆盖,无残留语义)。flatFrame 每相位复位(重落修正:
|
|
71
|
+
* 223 原版只在保留路径复位,隔离帧后快照会被永久禁用——保守方向的性能缺陷)。
|
|
72
|
+
*/
|
|
73
|
+
tryRetainedFrame(): boolean;
|
|
74
|
+
/** 全量扁平帧的快照收录(render 节点相位 flushAll 后调用) */
|
|
75
|
+
captureSnapshot(): void;
|
|
76
|
+
/** 帧尾记录(render 尾部调用):上帧动画/烘焙续帧态供下一帧门链 */
|
|
77
|
+
noteFrameRendered(): void;
|
|
78
|
+
/** 快照作废(越界使用):FBO 导出(SceneExporter 复用 host 主批缓冲覆写内容)
|
|
79
|
+
* 与 context 恢复(rebuild 后纹理句柄全死)前置调用 */
|
|
80
|
+
invalidate(): void;
|
|
81
|
+
dispose(): void;
|
|
82
|
+
private gateFail;
|
|
83
|
+
private gateOk;
|
|
84
|
+
private logDebug;
|
|
85
|
+
}
|
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 保留式场景帧控制器(批次 223 重落)。
|
|
3
|
+
*
|
|
4
|
+
* 全量扁平帧后把「命令表 + 两批槽位表/总量」快照留驻;后续帧门链全过时只对
|
|
5
|
+
* 脏集节点做槽位原位重推(rewind → 重推 → 计数契约校验),然后重放缓照命令
|
|
6
|
+
* 表——万级场景节点相位从每帧 O(n) 收敛为 O(dirty),干净节点的 GPU 内容跨帧
|
|
7
|
+
* 留驻。门链宁可慢不可错:结构版本/vpt/dpr/画布尺寸/纹理逐出/图集世代/
|
|
8
|
+
* 会话态/渐进装载/编辑态/动画/烘焙续帧任一在即全量帧。
|
|
9
|
+
*
|
|
10
|
+
* 图集世代门是重落的核心修复:GlyphAtlas.reset()(页上限触顶/字体迟到)删除
|
|
11
|
+
* 全部页纹理但不染脏任何节点——快照命令表持有页纹理活引用,重放死句柄 = 文本
|
|
12
|
+
* 整层不绘制(模板 273 文本消失回归的根因,理论自愈链「脏文本节点无槽位→回退
|
|
13
|
+
* 全量」对纹理级失效天然失明)。纹理级失效天然是全量帧信号,经世代/逐出计数
|
|
14
|
+
* 入门链而非逐节点染脏。
|
|
15
|
+
*
|
|
16
|
+
* 逃逸门:?retained=0 / localStorage('engine.retained'='0')(engineFlag)。
|
|
17
|
+
* 诊断日志:?retainedDebug=1——快照收录/门链回退理由/图集 reset 调用栈。
|
|
18
|
+
*/
|
|
19
|
+
import { isRetainedDebugEnabled, isRetainedFrameEnabled } from '../engineFlag';
|
|
20
|
+
export class RetainedFrameController {
|
|
21
|
+
host;
|
|
22
|
+
retained = null;
|
|
23
|
+
/** 上帧动画活动/烘焙续帧(门):动画节点逐帧自变(tick 在覆写层有脏标记,
|
|
24
|
+
* 但 mask 动态 clip 在渲染期 tick——干净节点被跳过即冻结);烘焙续帧完成
|
|
25
|
+
* 前推入的是暂态内容——两者在即全量帧 */
|
|
26
|
+
lastFrameAnimated = false;
|
|
27
|
+
lastFrameBakeMore = false;
|
|
28
|
+
/** 诊断:门链回退理由只在状态翻转时打点(防 rAF 级刷屏) */
|
|
29
|
+
lastGateReason = null;
|
|
30
|
+
constructor(host) {
|
|
31
|
+
this.host = host;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* 保留式帧尝试(render 节点相位入口):门链全过时按脏集原位重推 + 重放
|
|
35
|
+
* 快照命令表。返回 false = 任一门失败或重推异常(调用方回退全量遍历,
|
|
36
|
+
* 本帧缓冲被全量重写覆盖,无残留语义)。flatFrame 每相位复位(重落修正:
|
|
37
|
+
* 223 原版只在保留路径复位,隔离帧后快照会被永久禁用——保守方向的性能缺陷)。
|
|
38
|
+
*/
|
|
39
|
+
tryRetainedFrame() {
|
|
40
|
+
const { host } = this;
|
|
41
|
+
host.renderer.flatFrame = true;
|
|
42
|
+
if (!isRetainedFrameEnabled())
|
|
43
|
+
return this.gateFail('flag-off');
|
|
44
|
+
const rf = this.retained;
|
|
45
|
+
if (!rf)
|
|
46
|
+
return this.gateFail('no-snapshot');
|
|
47
|
+
if (this.lastFrameAnimated)
|
|
48
|
+
return this.gateFail('animating');
|
|
49
|
+
if (this.lastFrameBakeMore)
|
|
50
|
+
return this.gateFail('bake-continue');
|
|
51
|
+
if (host.cropSessionController.active || host.expandSessionController.active || host.pathSessionController.active || host.warpSessionController.active)
|
|
52
|
+
return this.gateFail('session');
|
|
53
|
+
if (host.progressiveLoad.limit >= 0 && host.progressiveLoad.limit < host.doc.nodes.length)
|
|
54
|
+
return this.gateFail('progressive');
|
|
55
|
+
if (host.doc.editingNode)
|
|
56
|
+
return this.gateFail('editing');
|
|
57
|
+
if (rf.structureVersion !== host.doc.structureVersion)
|
|
58
|
+
return this.gateFail('structure');
|
|
59
|
+
if (rf.vptKey !== host.vpt.join(','))
|
|
60
|
+
return this.gateFail('vpt');
|
|
61
|
+
if (rf.dpr !== host.dpr || rf.sizeKey !== `${host.canvasEl.width}x${host.canvasEl.height}`)
|
|
62
|
+
return this.gateFail('surface');
|
|
63
|
+
if (rf.evictions !== host.textures.evictionCount)
|
|
64
|
+
return this.gateFail('texture-evict');
|
|
65
|
+
// 图集世代门(重落核心修复):reset 删全部页纹理零染脏——重放死句柄即
|
|
66
|
+
// 文本整层消失;世代不等回退全量帧重栅格化
|
|
67
|
+
if (rf.atlasGeneration !== host.glyphAtlas.generation)
|
|
68
|
+
return this.gateFail('atlas-generation');
|
|
69
|
+
const snap = rf.snap;
|
|
70
|
+
const dirty = host.doc.renderDirty;
|
|
71
|
+
for (const node of dirty) {
|
|
72
|
+
// 参考线无场景槽位(frameOverlay 通道)——纯跳过
|
|
73
|
+
if (node.isReferenceLine)
|
|
74
|
+
continue;
|
|
75
|
+
const qs = snap.quadSlots.get(node);
|
|
76
|
+
const ms = snap.meshSlots.get(node);
|
|
77
|
+
// 无槽位:新可见/上帧隐藏/TextRenderer 等无 owner 推送——结构序变化,
|
|
78
|
+
// 回退全量(理论自愈链的入口:脏而无槽位必全量)
|
|
79
|
+
if (!qs && !ms)
|
|
80
|
+
return this.gateFail('no-slot');
|
|
81
|
+
const qBefore = host.batch.instanceTotal;
|
|
82
|
+
const mBefore = host.meshBatch.vertexTotal;
|
|
83
|
+
if (qs)
|
|
84
|
+
host.batch.rewindToSlot(qs.start);
|
|
85
|
+
if (ms)
|
|
86
|
+
host.meshBatch.rewindToSlot(ms.start);
|
|
87
|
+
host.renderer.renderSceneNode(node);
|
|
88
|
+
// 计数契约:有槽位 → 恰好落在槽位区间;无槽位 → 该批不前进(防止新增
|
|
89
|
+
// 网格/quad 内容静默从 0 位覆写他人区域)
|
|
90
|
+
if (host.batch.instanceTotal !== (qs ? qs.start + qs.count : qBefore))
|
|
91
|
+
return this.gateFail('contract-quad');
|
|
92
|
+
if (host.meshBatch.vertexTotal !== (ms ? ms.start + ms.count : mBefore))
|
|
93
|
+
return this.gateFail('contract-mesh');
|
|
94
|
+
// 重推命中隔离/混合路径 → 全量
|
|
95
|
+
if (!host.renderer.flatFrame)
|
|
96
|
+
return this.gateFail('isolated');
|
|
97
|
+
// 批次 300 守卫(批次 301 收窄口径):重推期命令出现快照没有的纹理/
|
|
98
|
+
// 渐变引用 = 换纹理类新写入(滤镜换 GPU 链输出纹理等),「脏帧重写不
|
|
99
|
+
// 产生新绘制」前提被破坏——继续走 discardRecorded + replaySnapshot 会把
|
|
100
|
+
// 画面钉在上一个观感(用户报障「点滤镜先停在之前状态之后才生效」根因)。
|
|
101
|
+
// 懒出清的等价命令(纹理/渐变同快照,带描边形状重推的常态)不触发——
|
|
102
|
+
// 批次 300 原口径 hasRecordedCommands 连等价命令也打成 gateFail,拖拽
|
|
103
|
+
// 热路径整族退化全量帧。宁可慢不可错:新颖引用立即回退全量帧
|
|
104
|
+
if (host.batchOrder.hasNovelPaintReferences(snap))
|
|
105
|
+
return this.gateFail('repush-commands');
|
|
106
|
+
}
|
|
107
|
+
// 批次 321 复检:重推期(renderSceneNode)新纹理插入可触发预算淘汰
|
|
108
|
+
// (get miss → evictIfNeeded),被逐句柄若在快照命令表里(干净节点的
|
|
109
|
+
// 纹理),重放即整帧消失。入口门读数在重推前——计数已变即整体回退
|
|
110
|
+
// 全量帧(调用方全量重写覆盖本帧缓冲,无残留语义)
|
|
111
|
+
if (rf.evictions !== host.textures.evictionCount)
|
|
112
|
+
return this.gateFail('texture-evict-late');
|
|
113
|
+
host.batch.restoreTotals(snap.quadTotal);
|
|
114
|
+
host.meshBatch.restoreTotals(snap.meshTotal);
|
|
115
|
+
host.batchOrder.discardRecorded();
|
|
116
|
+
host.batchOrder.replaySnapshot(snap);
|
|
117
|
+
this.gateOk();
|
|
118
|
+
return true;
|
|
119
|
+
}
|
|
120
|
+
/** 全量扁平帧的快照收录(render 节点相位 flushAll 后调用) */
|
|
121
|
+
captureSnapshot() {
|
|
122
|
+
const { host } = this;
|
|
123
|
+
if (!isRetainedFrameEnabled()) {
|
|
124
|
+
this.retained = null;
|
|
125
|
+
return;
|
|
126
|
+
}
|
|
127
|
+
const flat = host.renderer.flatFrame;
|
|
128
|
+
const sessions = host.cropSessionController.active || host.expandSessionController.active || host.pathSessionController.active || host.warpSessionController.active;
|
|
129
|
+
const progressive = host.progressiveLoad.limit >= 0 && host.progressiveLoad.limit < host.doc.nodes.length;
|
|
130
|
+
// 门校验(会话态/渐进中/编辑态/非扁平不建——隔离帧命令缺 FBO 边界语义)
|
|
131
|
+
if (!flat || sessions || progressive || host.doc.editingNode) {
|
|
132
|
+
this.retained = null;
|
|
133
|
+
this.logDebug(`snapshot 跳过(flat=${flat} sessions=${sessions} progressive=${progressive} editing=${host.doc.editingNode !== null})`);
|
|
134
|
+
return;
|
|
135
|
+
}
|
|
136
|
+
const snap = host.batchOrder.retained;
|
|
137
|
+
this.retained = snap
|
|
138
|
+
? {
|
|
139
|
+
snap,
|
|
140
|
+
structureVersion: host.doc.structureVersion,
|
|
141
|
+
vptKey: host.vpt.join(','),
|
|
142
|
+
dpr: host.dpr,
|
|
143
|
+
sizeKey: `${host.canvasEl.width}x${host.canvasEl.height}`,
|
|
144
|
+
evictions: host.textures.evictionCount,
|
|
145
|
+
atlasGeneration: host.glyphAtlas.generation
|
|
146
|
+
}
|
|
147
|
+
: null;
|
|
148
|
+
if (snap && isRetainedDebugEnabled()) {
|
|
149
|
+
const atlas = host.glyphAtlas.stats();
|
|
150
|
+
console.info('[retained] 快照收录', {
|
|
151
|
+
commands: snap.commands.length,
|
|
152
|
+
quadSlots: snap.quadSlots.size,
|
|
153
|
+
meshSlots: snap.meshSlots.size,
|
|
154
|
+
structureVersion: host.doc.structureVersion,
|
|
155
|
+
atlasPages: atlas.pages,
|
|
156
|
+
atlasGeneration: atlas.generation,
|
|
157
|
+
evictions: host.textures.evictionCount
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
/** 帧尾记录(render 尾部调用):上帧动画/烘焙续帧态供下一帧门链 */
|
|
162
|
+
noteFrameRendered() {
|
|
163
|
+
this.lastFrameAnimated = this.host.renderer.frame.animationActive;
|
|
164
|
+
this.lastFrameBakeMore = this.host.renderer.frame.bakeMore;
|
|
165
|
+
}
|
|
166
|
+
/** 快照作废(越界使用):FBO 导出(SceneExporter 复用 host 主批缓冲覆写内容)
|
|
167
|
+
* 与 context 恢复(rebuild 后纹理句柄全死)前置调用 */
|
|
168
|
+
invalidate() {
|
|
169
|
+
this.retained = null;
|
|
170
|
+
}
|
|
171
|
+
dispose() {
|
|
172
|
+
this.retained = null;
|
|
173
|
+
}
|
|
174
|
+
gateFail(reason) {
|
|
175
|
+
if (this.lastGateReason !== reason) {
|
|
176
|
+
this.lastGateReason = reason;
|
|
177
|
+
if (isRetainedDebugEnabled())
|
|
178
|
+
console.info('[retained] 门链回退:', reason);
|
|
179
|
+
}
|
|
180
|
+
return false;
|
|
181
|
+
}
|
|
182
|
+
gateOk() {
|
|
183
|
+
if (this.lastGateReason !== null) {
|
|
184
|
+
this.lastGateReason = null;
|
|
185
|
+
if (isRetainedDebugEnabled())
|
|
186
|
+
console.info('[retained] 保留式帧恢复生效');
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
logDebug(message) {
|
|
190
|
+
if (isRetainedDebugEnabled())
|
|
191
|
+
console.info('[retained]', message);
|
|
192
|
+
}
|
|
193
|
+
}
|