@egret/runtime 0.0.0-stage → 7.0.1-rc.3
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/LICENSE +201 -0
- package/NOTICE +21 -0
- package/README.md +70 -2
- package/README.zh-CN.md +71 -0
- package/dist/AssetLease.d.ts +23 -0
- package/dist/AssetLease.js +69 -0
- package/dist/AssetManager.d.ts +56 -0
- package/dist/AssetManager.js +451 -0
- package/dist/AssetRef.d.ts +20 -0
- package/dist/AssetRef.js +32 -0
- package/dist/Bitmap.d.ts +40 -0
- package/dist/Bitmap.js +545 -0
- package/dist/ByteReader.d.ts +30 -0
- package/dist/ByteReader.js +177 -0
- package/dist/ByteWriter.d.ts +29 -0
- package/dist/ByteWriter.js +180 -0
- package/dist/CancellationController.d.ts +10 -0
- package/dist/CancellationController.js +66 -0
- package/dist/DisplayObject.d.ts +89 -0
- package/dist/DisplayObject.js +340 -0
- package/dist/DisplayObjectContainer.d.ts +28 -0
- package/dist/DisplayObjectContainer.js +226 -0
- package/dist/EgretError.d.ts +11 -0
- package/dist/EgretError.js +36 -0
- package/dist/Event.d.ts +45 -0
- package/dist/Event.js +84 -0
- package/dist/EventDispatcher.d.ts +24 -0
- package/dist/EventDispatcher.js +178 -0
- package/dist/Graphics.d.ts +106 -0
- package/dist/Graphics.js +504 -0
- package/dist/Mesh2D.d.ts +27 -0
- package/dist/Mesh2D.js +200 -0
- package/dist/NineSliceBitmap.d.ts +24 -0
- package/dist/NineSliceBitmap.js +164 -0
- package/dist/NineSliceGeometry2D.d.ts +18 -0
- package/dist/NineSliceGeometry2D.js +126 -0
- package/dist/Scope.d.ts +18 -0
- package/dist/Scope.js +133 -0
- package/dist/SequencePlayer.d.ts +12 -0
- package/dist/SequencePlayer.js +69 -0
- package/dist/Sprite.d.ts +8 -0
- package/dist/Sprite.js +12 -0
- package/dist/Stage.d.ts +14 -0
- package/dist/Stage.js +31 -0
- package/dist/Texture.d.ts +29 -0
- package/dist/Texture.js +177 -0
- package/dist/assetManagerOwnerState.d.ts +36 -0
- package/dist/assetManagerOwnerState.js +115 -0
- package/dist/assetState.d.ts +44 -0
- package/dist/assetState.js +2 -0
- package/dist/atlasFrameLayout.d.ts +21 -0
- package/dist/atlasFrameLayout.js +48 -0
- package/dist/bitmapDisplayState.d.ts +24 -0
- package/dist/bitmapDisplayState.js +22 -0
- package/dist/coordinateInverse.d.ts +4 -0
- package/dist/coordinateInverse.js +107 -0
- package/dist/diagnostics.d.ts +4 -0
- package/dist/diagnostics.js +13 -0
- package/dist/displayBounds.d.ts +9 -0
- package/dist/displayBounds.js +181 -0
- package/dist/displayCoordinates.d.ts +8 -0
- package/dist/displayCoordinates.js +81 -0
- package/dist/displayHitState.d.ts +18 -0
- package/dist/displayHitState.js +97 -0
- package/dist/displayHitTest.d.ts +8 -0
- package/dist/displayHitTest.js +219 -0
- package/dist/displayInputOperations.d.ts +12 -0
- package/dist/displayInputOperations.js +71 -0
- package/dist/displayTransform.d.ts +5 -0
- package/dist/displayTransform.js +38 -0
- package/dist/displayTreeState.d.ts +90 -0
- package/dist/displayTreeState.js +450 -0
- package/dist/displayVisualState.d.ts +74 -0
- package/dist/displayVisualState.js +140 -0
- package/dist/errorHelp.d.ts +14 -0
- package/dist/errorHelp.js +432 -0
- package/dist/errorHelpZh.d.ts +5 -0
- package/dist/errorHelpZh.js +340 -0
- package/dist/graphicsFill.d.ts +37 -0
- package/dist/graphicsFill.js +302 -0
- package/dist/graphicsShape.d.ts +144 -0
- package/dist/graphicsShape.js +755 -0
- package/dist/index.d.ts +50 -0
- package/dist/index.js +28 -0
- package/dist/input/PointerRouter.d.ts +4 -0
- package/dist/input/PointerRouter.js +453 -0
- package/dist/input/index.d.ts +3 -0
- package/dist/input/index.js +3 -0
- package/dist/input/types.d.ts +58 -0
- package/dist/input/types.js +3 -0
- package/dist/meshCaptureSnapshot.d.ts +5 -0
- package/dist/meshCaptureSnapshot.js +13 -0
- package/dist/meshDisplayState.d.ts +18 -0
- package/dist/meshDisplayState.js +21 -0
- package/dist/ownership.d.ts +75 -0
- package/dist/ownership.js +157 -0
- package/dist/paragraph/Paragraph.d.ts +13 -0
- package/dist/paragraph/Paragraph.js +193 -0
- package/dist/paragraph/ParagraphCache.d.ts +5 -0
- package/dist/paragraph/ParagraphCache.js +354 -0
- package/dist/paragraph/geometry.d.ts +4 -0
- package/dist/paragraph/geometry.js +180 -0
- package/dist/paragraph/index.d.ts +3 -0
- package/dist/paragraph/index.js +3 -0
- package/dist/paragraph/request.d.ts +6 -0
- package/dist/paragraph/request.js +191 -0
- package/dist/paragraph/types.d.ts +183 -0
- package/dist/paragraph/types.js +2 -0
- package/dist/preparedDisplaySubtree.d.ts +7 -0
- package/dist/preparedDisplaySubtree.js +205 -0
- package/dist/renderEffect.d.ts +47 -0
- package/dist/renderEffect.js +87 -0
- package/dist/sequenceClip.d.ts +42 -0
- package/dist/sequenceClip.js +196 -0
- package/dist/sharedFrameCapture.d.ts +24 -0
- package/dist/sharedFrameCapture.js +1069 -0
- package/dist/spriteSheet.d.ts +34 -0
- package/dist/spriteSheet.js +321 -0
- package/dist/srgbBytes.d.ts +3 -0
- package/dist/srgbBytes.js +64 -0
- package/dist/text/TextField.d.ts +13 -0
- package/dist/text/TextField.js +261 -0
- package/dist/text/TextRasterCache.d.ts +5 -0
- package/dist/text/TextRasterCache.js +1191 -0
- package/dist/text/budget.d.ts +51 -0
- package/dist/text/budget.js +116 -0
- package/dist/text/index.d.ts +4 -0
- package/dist/text/index.js +3 -0
- package/dist/text/plan.d.ts +16 -0
- package/dist/text/plan.js +238 -0
- package/dist/text/request.d.ts +44 -0
- package/dist/text/request.js +303 -0
- package/dist/text/types.d.ts +179 -0
- package/dist/text/types.js +2 -0
- package/dist/textDisplayState.d.ts +21 -0
- package/dist/textDisplayState.js +27 -0
- package/dist/ui/displayCommit.d.ts +43 -0
- package/dist/ui/displayCommit.js +376 -0
- package/dist/ui/editing.d.ts +3 -0
- package/dist/ui/editing.js +3 -0
- package/dist/ui/heightIndex.d.ts +35 -0
- package/dist/ui/heightIndex.js +295 -0
- package/dist/ui/index.d.ts +6 -0
- package/dist/ui/index.js +6 -0
- package/dist/ui/layout.d.ts +9 -0
- package/dist/ui/layout.js +349 -0
- package/dist/ui/managedState.d.ts +12 -0
- package/dist/ui/managedState.js +44 -0
- package/dist/ui/textEditState.d.ts +4 -0
- package/dist/ui/textEditState.js +206 -0
- package/dist/ui/textEditTypes.d.ts +48 -0
- package/dist/ui/textEditTypes.js +2 -0
- package/dist/ui/types.d.ts +99 -0
- package/dist/ui/types.js +2 -0
- package/package.json +44 -4
|
@@ -0,0 +1,1069 @@
|
|
|
1
|
+
import { createSharedMaterial2D, isSharedGeometry2D, isTexturedGeometry2D } from '@egret/contracts';
|
|
2
|
+
import { assertLive, childAtOf, childCountOf, isDisplayNode, isStageRoot, parentOf } from './displayTreeState.js';
|
|
3
|
+
import { engineOf } from './ownership.js';
|
|
4
|
+
import { finite, visualOf } from './displayVisualState.js';
|
|
5
|
+
import { composeDisplayTransform } from './displayTransform.js';
|
|
6
|
+
import { bitmapCaptureState, readBitmapImage, readBitmapSource } from './Bitmap.js';
|
|
7
|
+
import { readMeshState } from './meshDisplayState.js';
|
|
8
|
+
import { SHAPE_PAGE, SHAPE_REGION, resolveShape } from './graphicsShape.js';
|
|
9
|
+
import { readMeshCaptureImage } from './meshCaptureSnapshot.js';
|
|
10
|
+
import { assertTextFieldScope, readTextFieldState } from './textDisplayState.js';
|
|
11
|
+
import { EgretError } from './EgretError.js';
|
|
12
|
+
function nodeCapture() {
|
|
13
|
+
return {
|
|
14
|
+
parentMatrix: undefined,
|
|
15
|
+
x: 0,
|
|
16
|
+
y: 0,
|
|
17
|
+
scaleX: 0,
|
|
18
|
+
scaleY: 0,
|
|
19
|
+
rotation: 0,
|
|
20
|
+
skewX: 0,
|
|
21
|
+
skewY: 0,
|
|
22
|
+
anchorOffsetX: 0,
|
|
23
|
+
anchorOffsetY: 0,
|
|
24
|
+
matrix: undefined,
|
|
25
|
+
clipSource: undefined,
|
|
26
|
+
clipMatrix: undefined,
|
|
27
|
+
clipAbove: undefined,
|
|
28
|
+
clipChain: null,
|
|
29
|
+
primitives: undefined,
|
|
30
|
+
rectsMatrix: undefined,
|
|
31
|
+
rects: [],
|
|
32
|
+
bitmap: undefined,
|
|
33
|
+
bitmapMatrix: undefined,
|
|
34
|
+
bitmapDomain: undefined,
|
|
35
|
+
bitmapRect: undefined,
|
|
36
|
+
regionOf: undefined,
|
|
37
|
+
region: undefined,
|
|
38
|
+
regionHash: 0,
|
|
39
|
+
commands: [],
|
|
40
|
+
restChanges: -1,
|
|
41
|
+
restParentAlpha: 0,
|
|
42
|
+
restClips: undefined,
|
|
43
|
+
restInherited: undefined,
|
|
44
|
+
restOrdinal: 0,
|
|
45
|
+
restOccurrence: 0,
|
|
46
|
+
restCount: 0,
|
|
47
|
+
restUnits: 0,
|
|
48
|
+
restChildless: false,
|
|
49
|
+
restAlpha: 0,
|
|
50
|
+
restMaterial: undefined,
|
|
51
|
+
restMaterialIndex: -1,
|
|
52
|
+
restTableMaterial: undefined,
|
|
53
|
+
restRegionIndex: -1,
|
|
54
|
+
restTableRegion: undefined
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
const is = Object.is;
|
|
58
|
+
const freeze = Object.freeze;
|
|
59
|
+
const defaultMaterial = createSharedMaterial2D({});
|
|
60
|
+
// The material of a shape's image fill: the node's own, sampling the image as a whole page that repeats or is held at its edge.
|
|
61
|
+
const shapeFillMaterials = new WeakMap();
|
|
62
|
+
function shapeFillMaterial(base, repeat) {
|
|
63
|
+
let pair = shapeFillMaterials.get(base);
|
|
64
|
+
if (pair === undefined)
|
|
65
|
+
shapeFillMaterials.set(base, (pair = [undefined, undefined]));
|
|
66
|
+
const address = repeat ? 'repeat' : 'clamp-to-edge';
|
|
67
|
+
return (pair[repeat ? 0 : 1] ??= createSharedMaterial2D({
|
|
68
|
+
light: base.light,
|
|
69
|
+
dark: base.dark,
|
|
70
|
+
blend: base.blend,
|
|
71
|
+
samplingDomain: 'page',
|
|
72
|
+
filter: base.filter,
|
|
73
|
+
addressU: address,
|
|
74
|
+
addressV: address,
|
|
75
|
+
minFilter: base.minFilter,
|
|
76
|
+
magFilter: base.magFilter
|
|
77
|
+
}));
|
|
78
|
+
}
|
|
79
|
+
const glows = new WeakMap();
|
|
80
|
+
function effectGlow(settings) {
|
|
81
|
+
if (glows.has(settings))
|
|
82
|
+
return glows.get(settings);
|
|
83
|
+
const g = settings.glow, o = settings.outline;
|
|
84
|
+
const value = g !== undefined
|
|
85
|
+
? freeze({
|
|
86
|
+
kind: 'glow',
|
|
87
|
+
color: g.color,
|
|
88
|
+
alpha: g.alpha ?? 1,
|
|
89
|
+
spread: g.blur ?? 6,
|
|
90
|
+
strength: g.strength ?? 2,
|
|
91
|
+
inner: g.inner === true,
|
|
92
|
+
knockout: g.knockout === true,
|
|
93
|
+
offsetX: g.offsetX ?? 0,
|
|
94
|
+
offsetY: g.offsetY ?? 0
|
|
95
|
+
})
|
|
96
|
+
: o !== undefined
|
|
97
|
+
? freeze({
|
|
98
|
+
kind: 'outline',
|
|
99
|
+
color: o.color,
|
|
100
|
+
alpha: o.alpha ?? 1,
|
|
101
|
+
spread: o.width,
|
|
102
|
+
strength: 1,
|
|
103
|
+
inner: false,
|
|
104
|
+
knockout: false,
|
|
105
|
+
offsetX: 0,
|
|
106
|
+
offsetY: 0
|
|
107
|
+
})
|
|
108
|
+
: undefined;
|
|
109
|
+
glows.set(settings, value);
|
|
110
|
+
return value;
|
|
111
|
+
}
|
|
112
|
+
const identity = freeze({ a: 1, b: 0, c: 0, d: 1, tx: 0, ty: 0 });
|
|
113
|
+
function debit(used, count, limit, code = 'FRAME_BUDGET_EXCEEDED') {
|
|
114
|
+
if (!Number.isSafeInteger(count) || count < 0 || count > limit - used)
|
|
115
|
+
throw new EgretError(code);
|
|
116
|
+
return used + count;
|
|
117
|
+
}
|
|
118
|
+
/** Call-local logical charges are independent of visibility and actual allocation. */
|
|
119
|
+
class CaptureBudget {
|
|
120
|
+
capture;
|
|
121
|
+
nodes = 0;
|
|
122
|
+
units = 0;
|
|
123
|
+
triangles = 0;
|
|
124
|
+
geometryBytes = 0;
|
|
125
|
+
sourceBytes = 0;
|
|
126
|
+
canonicalBytes = 0;
|
|
127
|
+
commands = 0;
|
|
128
|
+
clipReferences = 0;
|
|
129
|
+
// Header plus all five empty table arrays are charged even for a clear-only frame.
|
|
130
|
+
metadata = 256 + 5 * 24;
|
|
131
|
+
geometryOwners = new Set();
|
|
132
|
+
sourceOwners = new Set();
|
|
133
|
+
clipOwners = new Set();
|
|
134
|
+
/** `capture` is the number of the capture this budget is for. */
|
|
135
|
+
constructor(capture) {
|
|
136
|
+
this.capture = capture;
|
|
137
|
+
}
|
|
138
|
+
node() {
|
|
139
|
+
this.nodes = debit(this.nodes, 1, 65536);
|
|
140
|
+
}
|
|
141
|
+
authoring(count) {
|
|
142
|
+
this.units = debit(this.units, count, 65536);
|
|
143
|
+
}
|
|
144
|
+
geometry(value) {
|
|
145
|
+
if (!isTexturedGeometry2D(value) && !isSharedGeometry2D(value))
|
|
146
|
+
throw new EgretError('MESH_GEOMETRY_INVALID');
|
|
147
|
+
this.triangles = debit(this.triangles, value.triangleCount, 65536);
|
|
148
|
+
if (this.geometryOwners.has(value))
|
|
149
|
+
return;
|
|
150
|
+
// A frame's table of geometries is as long as its table of regions. What they cost is held by the triangles and bytes above.
|
|
151
|
+
debit(this.geometryOwners.size, 1, 4096);
|
|
152
|
+
this.geometryBytes = debit(this.geometryBytes, value.logicalByteLength, 16777216);
|
|
153
|
+
this.geometryOwners.add(value);
|
|
154
|
+
}
|
|
155
|
+
source(value) {
|
|
156
|
+
if (this.sourceOwners.has(value))
|
|
157
|
+
return;
|
|
158
|
+
debit(this.sourceOwners.size, 1, 64, 'FRAME_IMAGE_BUDGET');
|
|
159
|
+
// 64 MiB of distinct pages in one frame. A Host may be configured to admit less.
|
|
160
|
+
const source = debit(this.sourceBytes, value.byteLength, 67108864, 'FRAME_IMAGE_BUDGET');
|
|
161
|
+
const canonical = debit(this.canonicalBytes, value.byteLength, 67108864, 'FRAME_IMAGE_BUDGET');
|
|
162
|
+
this.sourceBytes = source;
|
|
163
|
+
this.canonicalBytes = canonical;
|
|
164
|
+
this.sourceOwners.add(value);
|
|
165
|
+
}
|
|
166
|
+
metadataBytes(bytes) {
|
|
167
|
+
this.metadata = debit(this.metadata, bytes, 33554432);
|
|
168
|
+
}
|
|
169
|
+
emission(clips, barrier) {
|
|
170
|
+
const count = barrier ? 0 : (clips?.depth ?? 0);
|
|
171
|
+
this.commands = debit(this.commands, 1, 65536);
|
|
172
|
+
this.clipReferences = debit(this.clipReferences, count, 262144);
|
|
173
|
+
this.metadataBytes(8 + (barrier ? 64 : 192 + 24 + 8 * count));
|
|
174
|
+
if (!barrier && clips !== undefined && clips.charged !== this.capture) {
|
|
175
|
+
for (let cursor = clips; cursor !== undefined; cursor = cursor.previous) {
|
|
176
|
+
if (this.clipOwners.has(cursor.clip))
|
|
177
|
+
continue;
|
|
178
|
+
this.metadataBytes(80);
|
|
179
|
+
this.clipOwners.add(cursor.clip);
|
|
180
|
+
}
|
|
181
|
+
clips.charged = this.capture;
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
/**
|
|
185
|
+
* The charges of `count` draws under one clip chain, as `emission` makes them one by one: all of them, or
|
|
186
|
+
* none and false when one would not fit, so that the draws are then charged one by one and refuse where they do.
|
|
187
|
+
*/
|
|
188
|
+
draws(count, clips) {
|
|
189
|
+
const depth = clips?.depth ?? 0;
|
|
190
|
+
let owners = 0;
|
|
191
|
+
if (clips !== undefined && clips.charged !== this.capture)
|
|
192
|
+
for (let cursor = clips; cursor !== undefined; cursor = cursor.previous)
|
|
193
|
+
if (!this.clipOwners.has(cursor.clip))
|
|
194
|
+
owners++;
|
|
195
|
+
const references = count * depth, bytes = count * (8 + 192 + 24 + 8 * depth) + 80 * owners;
|
|
196
|
+
if (count > 65536 - this.commands || references > 262144 - this.clipReferences || bytes > 33554432 - this.metadata)
|
|
197
|
+
return false;
|
|
198
|
+
this.commands += count;
|
|
199
|
+
this.clipReferences += references;
|
|
200
|
+
this.metadata += bytes;
|
|
201
|
+
if (clips !== undefined && clips.charged !== this.capture) {
|
|
202
|
+
for (let cursor = clips; cursor !== undefined; cursor = cursor.previous)
|
|
203
|
+
this.clipOwners.add(cursor.clip);
|
|
204
|
+
clips.charged = this.capture;
|
|
205
|
+
}
|
|
206
|
+
return true;
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
const liveTree = { count: childCountOf, child: childAtOf, parent: parentOf };
|
|
210
|
+
// Every capture has a number of its own, which it leaves on each node it visits.
|
|
211
|
+
let captures = 0;
|
|
212
|
+
/** The checks of one node, and its state. `capture` is the number of this capture: a node it has left that number on was visited before. */
|
|
213
|
+
function checkNode(node, parent, engine, capture, tree) {
|
|
214
|
+
if (!isDisplayNode(node))
|
|
215
|
+
throw new EgretError('DISPLAY_TREE_INVARIANT');
|
|
216
|
+
const state = visualOf(node);
|
|
217
|
+
if (state.seenBy === capture || tree.parent(node) !== parent)
|
|
218
|
+
throw new EgretError('DISPLAY_TREE_INVARIANT');
|
|
219
|
+
assertLive(node);
|
|
220
|
+
if (engineOf(node) !== engine)
|
|
221
|
+
throw new EgretError('ENGINE_MISMATCH');
|
|
222
|
+
state.seenBy = capture;
|
|
223
|
+
return state;
|
|
224
|
+
}
|
|
225
|
+
function checkedMatrix(matrix) {
|
|
226
|
+
if (!finite(matrix.a) ||
|
|
227
|
+
!finite(matrix.b) ||
|
|
228
|
+
!finite(matrix.c) ||
|
|
229
|
+
!finite(matrix.d) ||
|
|
230
|
+
!finite(matrix.tx) ||
|
|
231
|
+
!finite(matrix.ty))
|
|
232
|
+
throw new EgretError('FRAME_TRANSFORM_INVALID');
|
|
233
|
+
return freeze(matrix);
|
|
234
|
+
}
|
|
235
|
+
function point(matrix, x, y) {
|
|
236
|
+
if (!finite(x) ||
|
|
237
|
+
!finite(y) ||
|
|
238
|
+
!finite(matrix.a * x + matrix.c * y + matrix.tx) ||
|
|
239
|
+
!finite(matrix.b * x + matrix.d * y + matrix.ty))
|
|
240
|
+
throw new EgretError('FRAME_TRANSFORM_INVALID');
|
|
241
|
+
}
|
|
242
|
+
/** The checks of `rectangle`: the four corners of `rect` placed by `matrix` are finite. */
|
|
243
|
+
function checkRectangle(matrix, rect) {
|
|
244
|
+
const right = rect.x + rect.width, bottom = rect.y + rect.height;
|
|
245
|
+
if (!finite(right) || !finite(bottom))
|
|
246
|
+
throw new EgretError('FRAME_TRANSFORM_INVALID');
|
|
247
|
+
point(matrix, rect.x, rect.y);
|
|
248
|
+
point(matrix, right, rect.y);
|
|
249
|
+
point(matrix, right, bottom);
|
|
250
|
+
point(matrix, rect.x, bottom);
|
|
251
|
+
}
|
|
252
|
+
function rectangle(matrix, rect) {
|
|
253
|
+
checkRectangle(matrix, rect);
|
|
254
|
+
return freeze({ x: rect.x, y: rect.y, width: rect.width, height: rect.height });
|
|
255
|
+
}
|
|
256
|
+
function referencedTuples(matrix, geometry) {
|
|
257
|
+
const shared = isSharedGeometry2D(geometry);
|
|
258
|
+
for (let offset = 0; offset < geometry.indexCount; offset++) {
|
|
259
|
+
const index = geometry.indices[offset];
|
|
260
|
+
point(matrix, geometry.positions[2 * index], geometry.positions[2 * index + 1]);
|
|
261
|
+
const u = geometry.uvs[2 * index], v = geometry.uvs[2 * index + 1];
|
|
262
|
+
if (!finite(u) || !finite(v))
|
|
263
|
+
throw new EgretError('FRAME_TRANSFORM_INVALID');
|
|
264
|
+
for (let component = 0; component < 4; component++) {
|
|
265
|
+
const value = geometry.lightColors[4 * index + component];
|
|
266
|
+
if (!finite(value) || value < 0 || value > 1)
|
|
267
|
+
throw new EgretError('FRAME_TRANSFORM_INVALID');
|
|
268
|
+
}
|
|
269
|
+
if (shared)
|
|
270
|
+
for (let component = 0; component < 3; component++) {
|
|
271
|
+
const value = geometry.darkColors[3 * index + component];
|
|
272
|
+
if (!finite(value) || value < 0 || value > 1)
|
|
273
|
+
throw new EgretError('FRAME_TRANSFORM_INVALID');
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
// GPU page-q and periodic precision admission belongs to Host preparation.
|
|
277
|
+
}
|
|
278
|
+
const noClips = freeze([]);
|
|
279
|
+
/** Draws under one clip chain share one frozen list; draws under none share the empty one. */
|
|
280
|
+
function flattenClips(chain) {
|
|
281
|
+
if (chain === undefined)
|
|
282
|
+
return noClips;
|
|
283
|
+
if (chain.flat !== undefined)
|
|
284
|
+
return chain.flat;
|
|
285
|
+
const result = new Array(chain.depth);
|
|
286
|
+
for (let cursor = chain; cursor !== undefined; cursor = cursor.previous)
|
|
287
|
+
result[cursor.depth - 1] = cursor.clip;
|
|
288
|
+
return (chain.flat = freeze(result));
|
|
289
|
+
}
|
|
290
|
+
function materialKey(material) {
|
|
291
|
+
const light = material.light, dark = material.dark;
|
|
292
|
+
return (light[0] +
|
|
293
|
+
',' +
|
|
294
|
+
light[1] +
|
|
295
|
+
',' +
|
|
296
|
+
light[2] +
|
|
297
|
+
',' +
|
|
298
|
+
light[3] +
|
|
299
|
+
';' +
|
|
300
|
+
dark[0] +
|
|
301
|
+
',' +
|
|
302
|
+
dark[1] +
|
|
303
|
+
',' +
|
|
304
|
+
dark[2] +
|
|
305
|
+
';' +
|
|
306
|
+
material.blend +
|
|
307
|
+
';' +
|
|
308
|
+
material.samplingDomain +
|
|
309
|
+
';' +
|
|
310
|
+
material.filter +
|
|
311
|
+
';' +
|
|
312
|
+
material.addressU +
|
|
313
|
+
';' +
|
|
314
|
+
material.addressV +
|
|
315
|
+
';' +
|
|
316
|
+
material.regionIsolation +
|
|
317
|
+
';' +
|
|
318
|
+
material.mipLevel +
|
|
319
|
+
';' +
|
|
320
|
+
material.minFilter +
|
|
321
|
+
';' +
|
|
322
|
+
material.magFilter +
|
|
323
|
+
';' +
|
|
324
|
+
material.maxAnisotropy);
|
|
325
|
+
}
|
|
326
|
+
/** Two numbers that print the same: equal, or both not a number. Either zero prints as "0". */
|
|
327
|
+
function sameNumber(a, b) {
|
|
328
|
+
return a === b || (a !== a && b !== b);
|
|
329
|
+
}
|
|
330
|
+
/** Regions with the same nine numbers get the same value; the table compares the numbers themselves. */
|
|
331
|
+
function regionHash(region) {
|
|
332
|
+
const packed = region.packed;
|
|
333
|
+
let hash = packed.x | 0;
|
|
334
|
+
hash = Math.imul(hash, 31) + (packed.y | 0);
|
|
335
|
+
hash = Math.imul(hash, 31) + (packed.width | 0);
|
|
336
|
+
hash = Math.imul(hash, 31) + (packed.height | 0);
|
|
337
|
+
hash = Math.imul(hash, 31) + (region.logicalWidth | 0);
|
|
338
|
+
hash = Math.imul(hash, 31) + (region.logicalHeight | 0);
|
|
339
|
+
hash = Math.imul(hash, 31) + (region.trimX | 0);
|
|
340
|
+
hash = Math.imul(hash, 31) + (region.trimY | 0);
|
|
341
|
+
return (Math.imul(hash, 31) + (region.quarterTurn | 0)) | 0;
|
|
342
|
+
}
|
|
343
|
+
function sameRegion(recorded, value) {
|
|
344
|
+
const a = recorded.packed, b = value.packed;
|
|
345
|
+
return (sameNumber(a.x, b.x) &&
|
|
346
|
+
sameNumber(a.y, b.y) &&
|
|
347
|
+
sameNumber(a.width, b.width) &&
|
|
348
|
+
sameNumber(a.height, b.height) &&
|
|
349
|
+
sameNumber(recorded.logicalWidth, value.logicalWidth) &&
|
|
350
|
+
sameNumber(recorded.logicalHeight, value.logicalHeight) &&
|
|
351
|
+
sameNumber(recorded.trimX, value.trimX) &&
|
|
352
|
+
sameNumber(recorded.trimY, value.trimY) &&
|
|
353
|
+
sameNumber(recorded.quarterTurn, value.quarterTurn));
|
|
354
|
+
}
|
|
355
|
+
function plainRegion(sourceRect) {
|
|
356
|
+
return {
|
|
357
|
+
packed: sourceRect,
|
|
358
|
+
logicalWidth: sourceRect.width,
|
|
359
|
+
logicalHeight: sourceRect.height,
|
|
360
|
+
trimX: 0,
|
|
361
|
+
trimY: 0,
|
|
362
|
+
quarterTurn: 0
|
|
363
|
+
};
|
|
364
|
+
}
|
|
365
|
+
function bitmapRegion(bitmap) {
|
|
366
|
+
if (bitmap.viewRegion !== null)
|
|
367
|
+
return bitmap.viewRegion;
|
|
368
|
+
const layout = bitmap.layout;
|
|
369
|
+
if (layout === undefined)
|
|
370
|
+
return plainRegion(bitmap.sourceRect);
|
|
371
|
+
// This is a new-profile representation boundary, after current entitlement.
|
|
372
|
+
// Legacy atlas commits/captures retain their broader safe-integer dimensions.
|
|
373
|
+
if (layout.sourceWidth > 1048576 ||
|
|
374
|
+
layout.sourceHeight > 1048576 ||
|
|
375
|
+
layout.trimX > 1048576 ||
|
|
376
|
+
layout.trimY > 1048576) {
|
|
377
|
+
throw new EgretError('FRAME_PROFILE_METADATA_UNSUPPORTED');
|
|
378
|
+
}
|
|
379
|
+
return {
|
|
380
|
+
packed: bitmap.sourceRect,
|
|
381
|
+
logicalWidth: layout.sourceWidth,
|
|
382
|
+
logicalHeight: layout.sourceHeight,
|
|
383
|
+
trimX: layout.trimX,
|
|
384
|
+
trimY: layout.trimY,
|
|
385
|
+
quarterTurn: layout.packedRotation === 0 ? 0 : 1
|
|
386
|
+
};
|
|
387
|
+
}
|
|
388
|
+
function bitmapRect(bitmap, material) {
|
|
389
|
+
if (material.samplingDomain === 'region')
|
|
390
|
+
return { x: 0, y: 0, width: bitmap.width, height: bitmap.height };
|
|
391
|
+
const view = bitmap.viewRegion, layout = bitmap.layout;
|
|
392
|
+
const turn = view?.quarterTurn ?? (layout?.packedRotation === 90 ? 1 : 0);
|
|
393
|
+
return {
|
|
394
|
+
x: view?.trimX ?? layout?.trimX ?? 0,
|
|
395
|
+
y: view?.trimY ?? layout?.trimY ?? 0,
|
|
396
|
+
width: turn === 1 || turn === 3 ? bitmap.sourceRect.height : bitmap.sourceRect.width,
|
|
397
|
+
height: turn === 1 || turn === 3 ? bitmap.sourceRect.width : bitmap.sourceRect.height
|
|
398
|
+
};
|
|
399
|
+
}
|
|
400
|
+
/**
|
|
401
|
+
* Iterative capture. All mutable owners stay inside this invocation, except what each node keeps of its own
|
|
402
|
+
* derived records.
|
|
403
|
+
*/
|
|
404
|
+
export function collectSharedFrameContent(stage) {
|
|
405
|
+
return captureSharedContent(stage, bitmapCaptureState, liveTree, true);
|
|
406
|
+
}
|
|
407
|
+
/** The same capture with nothing kept read or written: every record is derived anew. Never forwarded by a package root. */
|
|
408
|
+
export function collectFreshSharedFrameContent(stage) {
|
|
409
|
+
return captureSharedContent(stage, bitmapCaptureState);
|
|
410
|
+
}
|
|
411
|
+
/** Runtime-private fixed Bitmap assembly; never forwarded by a package root. */
|
|
412
|
+
export function collectPreparedSharedFrameContent(stage, view) {
|
|
413
|
+
return captureSharedContent(stage, view.read);
|
|
414
|
+
}
|
|
415
|
+
/** Private single-edge overlay; ordinary capture always uses the unchanged live readers. */
|
|
416
|
+
export function collectSubtreeSharedFrameContent(stage, target, candidate) {
|
|
417
|
+
const tree = {
|
|
418
|
+
count: node => (node === target ? 1 : childCountOf(node)),
|
|
419
|
+
child: (node, index) => (node === target ? (index === 0 ? candidate : undefined) : childAtOf(node, index)),
|
|
420
|
+
parent: node => (node === candidate ? target : parentOf(node))
|
|
421
|
+
};
|
|
422
|
+
return captureSharedContent(stage, bitmapCaptureState, tree);
|
|
423
|
+
}
|
|
424
|
+
/**
|
|
425
|
+
* One walk of the whole tree. Each node is first admitted: counted, checked and charged whether or not it is
|
|
426
|
+
* drawn. A node that is drawn then contributes its commands. A refusal of visible content does not end the
|
|
427
|
+
* walk: the rest of the tree is still admitted, because an admission refusal anywhere outranks it, and the
|
|
428
|
+
* first refusal of visible content is reported only once the whole tree has been admitted.
|
|
429
|
+
*/
|
|
430
|
+
function captureSharedContent(stage, readBitmap, tree = liveTree, keeping = false) {
|
|
431
|
+
if (!isStageRoot(stage))
|
|
432
|
+
throw new EgretError('FRAME_STAGE_INVALID');
|
|
433
|
+
const engine = engineOf(stage);
|
|
434
|
+
engine.assertOpen();
|
|
435
|
+
// Captures are numbered from one; a node or a clip chain that no capture has reached holds zero.
|
|
436
|
+
const capture = ++captures, budget = new CaptureBudget(capture);
|
|
437
|
+
const commands = [], pages = [], regions = [];
|
|
438
|
+
const materials = [], geometries = [];
|
|
439
|
+
const pageIndexes = new Map(), regionIndexes = new Map();
|
|
440
|
+
// The value each region of the table was made from: a kept value met again is that region, with no number compared.
|
|
441
|
+
const regionValues = [];
|
|
442
|
+
const materialIndexes = new Map(), materialObjects = new Map(), geometryIndexes = new Map();
|
|
443
|
+
const stack = [];
|
|
444
|
+
let nextOccurrence = 0, nextBoundary = 0, refused = false, refusal;
|
|
445
|
+
function materialIndex(material) {
|
|
446
|
+
// The same object within one capture has the same complete value, so its key is built once.
|
|
447
|
+
const known = materialObjects.get(material);
|
|
448
|
+
if (known !== undefined)
|
|
449
|
+
return known;
|
|
450
|
+
const key = materialKey(material), found = materialIndexes.get(key);
|
|
451
|
+
if (found !== undefined) {
|
|
452
|
+
materialObjects.set(material, found);
|
|
453
|
+
return found;
|
|
454
|
+
}
|
|
455
|
+
debit(materials.length, 1, 256);
|
|
456
|
+
budget.metadataBytes(192 + 8);
|
|
457
|
+
const index = materials.length;
|
|
458
|
+
materials.push(material);
|
|
459
|
+
materialIndexes.set(key, index);
|
|
460
|
+
materialObjects.set(material, index);
|
|
461
|
+
return index;
|
|
462
|
+
}
|
|
463
|
+
function regionIndex(image, value, hash = regionHash(value)) {
|
|
464
|
+
const owner = regionIndexes.get(image), bucket = owner?.get(hash);
|
|
465
|
+
if (bucket !== undefined)
|
|
466
|
+
for (let position = 0; position < bucket.length; position++) {
|
|
467
|
+
const candidate = bucket[position];
|
|
468
|
+
if (regionValues[candidate] === value || sameRegion(regions[candidate], value))
|
|
469
|
+
return candidate;
|
|
470
|
+
}
|
|
471
|
+
// 4,096 distinct regions in one frame. A Host may be configured to admit fewer.
|
|
472
|
+
debit(regions.length, 1, 4096, 'FRAME_IMAGE_BUDGET');
|
|
473
|
+
let pageIndex = pageIndexes.get(image);
|
|
474
|
+
if (pageIndex === undefined) {
|
|
475
|
+
budget.metadataBytes(96 + 8);
|
|
476
|
+
pageIndex = pages.length;
|
|
477
|
+
pages.push(freeze({
|
|
478
|
+
source: image,
|
|
479
|
+
sourceRepresentation: 'egret.srgb-straight-rgba8/1',
|
|
480
|
+
canonicalRepresentation: 'egret.alpha8-capped-srgb-pma8/1'
|
|
481
|
+
}));
|
|
482
|
+
pageIndexes.set(image, pageIndex);
|
|
483
|
+
}
|
|
484
|
+
budget.metadataBytes(128 + 8);
|
|
485
|
+
const packed = freeze({
|
|
486
|
+
x: value.packed.x,
|
|
487
|
+
y: value.packed.y,
|
|
488
|
+
width: value.packed.width,
|
|
489
|
+
height: value.packed.height
|
|
490
|
+
});
|
|
491
|
+
const index = regions.length;
|
|
492
|
+
regions.push(freeze({
|
|
493
|
+
pageIndex,
|
|
494
|
+
packed,
|
|
495
|
+
logicalWidth: value.logicalWidth,
|
|
496
|
+
logicalHeight: value.logicalHeight,
|
|
497
|
+
trimX: value.trimX,
|
|
498
|
+
trimY: value.trimY,
|
|
499
|
+
quarterTurn: value.quarterTurn
|
|
500
|
+
}));
|
|
501
|
+
regionValues.push(value);
|
|
502
|
+
const entries = owner ?? new Map();
|
|
503
|
+
if (bucket === undefined)
|
|
504
|
+
entries.set(hash, [index]);
|
|
505
|
+
else
|
|
506
|
+
bucket.push(index);
|
|
507
|
+
if (owner === undefined)
|
|
508
|
+
regionIndexes.set(image, entries);
|
|
509
|
+
return index;
|
|
510
|
+
}
|
|
511
|
+
function geometryIndex(geometry) {
|
|
512
|
+
const found = geometryIndexes.get(geometry);
|
|
513
|
+
if (found !== undefined)
|
|
514
|
+
return found;
|
|
515
|
+
budget.metadataBytes(8);
|
|
516
|
+
const index = geometries.length;
|
|
517
|
+
geometries.push(geometry);
|
|
518
|
+
geometryIndexes.set(geometry, index);
|
|
519
|
+
return index;
|
|
520
|
+
}
|
|
521
|
+
function barrier(reason, pair) {
|
|
522
|
+
budget.emission(undefined, true);
|
|
523
|
+
commands.push(freeze({
|
|
524
|
+
kind: 'barrier',
|
|
525
|
+
ordinal: commands.length,
|
|
526
|
+
occurrenceId: pair.occurrenceId,
|
|
527
|
+
boundaryId: pair.boundaryId,
|
|
528
|
+
reason
|
|
529
|
+
}));
|
|
530
|
+
}
|
|
531
|
+
function open(reason) {
|
|
532
|
+
const pair = { occurrenceId: nextOccurrence++, boundaryId: nextBoundary++ };
|
|
533
|
+
barrier(reason, pair);
|
|
534
|
+
return pair;
|
|
535
|
+
}
|
|
536
|
+
function close(explicit, clip, effect) {
|
|
537
|
+
if (effect !== undefined)
|
|
538
|
+
barrier('effect-exit', effect);
|
|
539
|
+
if (clip !== undefined)
|
|
540
|
+
barrier('clip-exit', clip);
|
|
541
|
+
if (explicit !== undefined)
|
|
542
|
+
barrier('explicit-exit', explicit);
|
|
543
|
+
}
|
|
544
|
+
function empty(occurrenceId) {
|
|
545
|
+
barrier('empty', { occurrenceId, boundaryId: nextBoundary++ });
|
|
546
|
+
}
|
|
547
|
+
function push(node, drawn, matrix, alpha, clips, material, explicit, clip, effect) {
|
|
548
|
+
stack.push({
|
|
549
|
+
node,
|
|
550
|
+
children: tree.count(node),
|
|
551
|
+
nextChild: 0,
|
|
552
|
+
drawn,
|
|
553
|
+
matrix,
|
|
554
|
+
alpha,
|
|
555
|
+
clips,
|
|
556
|
+
material,
|
|
557
|
+
explicit,
|
|
558
|
+
clip,
|
|
559
|
+
effect
|
|
560
|
+
});
|
|
561
|
+
}
|
|
562
|
+
/** The commands of one drawn node. Returns false when the node and everything below it are not drawn. */
|
|
563
|
+
function draw(node, state, primitives, primitiveCount, bitmap, mesh, text, shape, parentMatrix, parentAlpha, inheritedClips, inheritedMaterial) {
|
|
564
|
+
const firstOrdinal = commands.length, firstOccurrence = nextOccurrence;
|
|
565
|
+
const explicit = state.renderBoundary === 'isolate' ? open('explicit-enter') : undefined;
|
|
566
|
+
const alpha = parentAlpha * state.alpha;
|
|
567
|
+
if (!state.visible || state.alpha === 0 || alpha === 0) {
|
|
568
|
+
close(explicit, undefined);
|
|
569
|
+
return false;
|
|
570
|
+
}
|
|
571
|
+
if (!finite(alpha))
|
|
572
|
+
throw new EgretError('FRAME_TRANSFORM_INVALID');
|
|
573
|
+
const material = state.sharedMaterial ?? inheritedMaterial;
|
|
574
|
+
let kept = keeping ? state.sharedCapture : undefined;
|
|
575
|
+
let matrix;
|
|
576
|
+
if (kept !== undefined &&
|
|
577
|
+
kept.parentMatrix === parentMatrix &&
|
|
578
|
+
is(kept.x, state.x) &&
|
|
579
|
+
is(kept.y, state.y) &&
|
|
580
|
+
is(kept.scaleX, state.scaleX) &&
|
|
581
|
+
is(kept.scaleY, state.scaleY) &&
|
|
582
|
+
is(kept.rotation, state.rotation) &&
|
|
583
|
+
is(kept.skewX, state.skewX) &&
|
|
584
|
+
is(kept.skewY, state.skewY) &&
|
|
585
|
+
is(kept.anchorOffsetX, state.anchorOffsetX) &&
|
|
586
|
+
is(kept.anchorOffsetY, state.anchorOffsetY))
|
|
587
|
+
matrix = kept.matrix;
|
|
588
|
+
else {
|
|
589
|
+
matrix = checkedMatrix(composeDisplayTransform(parentMatrix, state));
|
|
590
|
+
if (keeping) {
|
|
591
|
+
if (kept === undefined)
|
|
592
|
+
state.sharedCapture = kept = nodeCapture();
|
|
593
|
+
kept.parentMatrix = parentMatrix;
|
|
594
|
+
kept.x = state.x;
|
|
595
|
+
kept.y = state.y;
|
|
596
|
+
kept.scaleX = state.scaleX;
|
|
597
|
+
kept.scaleY = state.scaleY;
|
|
598
|
+
kept.rotation = state.rotation;
|
|
599
|
+
kept.skewX = state.skewX;
|
|
600
|
+
kept.skewY = state.skewY;
|
|
601
|
+
kept.anchorOffsetX = state.anchorOffsetX;
|
|
602
|
+
kept.anchorOffsetY = state.anchorOffsetY;
|
|
603
|
+
kept.matrix = matrix;
|
|
604
|
+
}
|
|
605
|
+
}
|
|
606
|
+
let clips = inheritedClips, clip;
|
|
607
|
+
if (state.clipRect !== undefined) {
|
|
608
|
+
let chain;
|
|
609
|
+
if (kept !== undefined &&
|
|
610
|
+
kept.clipSource === state.clipRect &&
|
|
611
|
+
kept.clipMatrix === matrix &&
|
|
612
|
+
kept.clipAbove === clips)
|
|
613
|
+
chain = kept.clipChain;
|
|
614
|
+
else {
|
|
615
|
+
const rect = rectangle(matrix, state.clipRect);
|
|
616
|
+
chain =
|
|
617
|
+
rect.width === 0 || rect.height === 0
|
|
618
|
+
? null
|
|
619
|
+
: {
|
|
620
|
+
previous: clips,
|
|
621
|
+
clip: freeze({ matrix, rect }),
|
|
622
|
+
depth: (clips?.depth ?? 0) + 1,
|
|
623
|
+
flat: undefined,
|
|
624
|
+
charged: 0
|
|
625
|
+
};
|
|
626
|
+
if (kept !== undefined) {
|
|
627
|
+
kept.clipSource = state.clipRect;
|
|
628
|
+
kept.clipMatrix = matrix;
|
|
629
|
+
kept.clipAbove = clips;
|
|
630
|
+
kept.clipChain = chain;
|
|
631
|
+
}
|
|
632
|
+
}
|
|
633
|
+
clip = open('clip-enter');
|
|
634
|
+
if (chain === null) {
|
|
635
|
+
close(explicit, clip);
|
|
636
|
+
return false;
|
|
637
|
+
}
|
|
638
|
+
clips = chain;
|
|
639
|
+
}
|
|
640
|
+
let effect;
|
|
641
|
+
if (state.renderEffect !== undefined) {
|
|
642
|
+
const settings = state.renderEffect, mask = settings.alphaMask;
|
|
643
|
+
let maskPageIndex;
|
|
644
|
+
if (mask !== undefined) {
|
|
645
|
+
assertLive(mask);
|
|
646
|
+
if (engineOf(mask) !== engine)
|
|
647
|
+
throw new EgretError('ENGINE_MISMATCH');
|
|
648
|
+
const binding = readBitmap(mask);
|
|
649
|
+
if (!binding)
|
|
650
|
+
throw new EgretError('DISPLAY_EFFECT_MASK_INVALID');
|
|
651
|
+
const image = readBitmapImage(binding.lease).image, region = bitmapRegion(binding), packed = region.packed;
|
|
652
|
+
if (packed.x !== 0 ||
|
|
653
|
+
packed.y !== 0 ||
|
|
654
|
+
packed.width !== image.width ||
|
|
655
|
+
packed.height !== image.height ||
|
|
656
|
+
region.quarterTurn !== 0 ||
|
|
657
|
+
region.trimX !== 0 ||
|
|
658
|
+
region.trimY !== 0 ||
|
|
659
|
+
region.logicalWidth !== image.width ||
|
|
660
|
+
region.logicalHeight !== image.height)
|
|
661
|
+
throw new EgretError('DISPLAY_EFFECT_MASK_UNSUPPORTED');
|
|
662
|
+
budget.source(image);
|
|
663
|
+
maskPageIndex = regions[regionIndex(image, region)].pageIndex;
|
|
664
|
+
}
|
|
665
|
+
effect = { occurrenceId: nextOccurrence++, boundaryId: nextBoundary++ };
|
|
666
|
+
const glow = effectGlow(settings);
|
|
667
|
+
budget.emission(undefined, true);
|
|
668
|
+
budget.metadataBytes(128 + 80 * (clips?.depth ?? 0));
|
|
669
|
+
commands.push(freeze({
|
|
670
|
+
kind: 'barrier',
|
|
671
|
+
ordinal: commands.length,
|
|
672
|
+
...effect,
|
|
673
|
+
reason: 'effect-enter',
|
|
674
|
+
effect: freeze({
|
|
675
|
+
blurRadius: settings.blurRadius ?? 0,
|
|
676
|
+
maskPageIndex,
|
|
677
|
+
maskRect: settings.maskRect,
|
|
678
|
+
matrix,
|
|
679
|
+
clips: flattenClips(clips),
|
|
680
|
+
...(settings.colorMatrix === undefined ? {} : { colorMatrix: settings.colorMatrix }),
|
|
681
|
+
...(glow === undefined ? {} : { glow })
|
|
682
|
+
})
|
|
683
|
+
}));
|
|
684
|
+
// Parent clips apply to the composited result, not intermediate blur taps.
|
|
685
|
+
clips = undefined;
|
|
686
|
+
}
|
|
687
|
+
// The place of the next command among those this node gives, and whether it has given draws alone.
|
|
688
|
+
let given = 0, plain = explicit === undefined &&
|
|
689
|
+
clip === undefined &&
|
|
690
|
+
effect === undefined &&
|
|
691
|
+
mesh === undefined &&
|
|
692
|
+
text === undefined &&
|
|
693
|
+
shape === undefined;
|
|
694
|
+
// The places in the tables of the material and the region of its draws.
|
|
695
|
+
let usedMaterial = -1, usedRegion = -1;
|
|
696
|
+
let rects;
|
|
697
|
+
// A rectangle's value is its primitive's own; only its checks depend on the matrix. The kept values of the same
|
|
698
|
+
// primitives are given again, each checked under a matrix it was not checked under.
|
|
699
|
+
let rectsChecked = true;
|
|
700
|
+
if (kept !== undefined && primitiveCount !== 0) {
|
|
701
|
+
if (kept.primitives !== primitives) {
|
|
702
|
+
kept.primitives = primitives;
|
|
703
|
+
kept.rectsMatrix = matrix;
|
|
704
|
+
kept.rects = [];
|
|
705
|
+
}
|
|
706
|
+
else if (kept.rectsMatrix !== matrix)
|
|
707
|
+
rectsChecked = false;
|
|
708
|
+
rects = kept.rects;
|
|
709
|
+
}
|
|
710
|
+
for (let index = 0; index < primitiveCount; index++) {
|
|
711
|
+
const primitive = primitives[index], occurrenceId = nextOccurrence++;
|
|
712
|
+
let rect = rects?.[index];
|
|
713
|
+
if (rect === undefined) {
|
|
714
|
+
rect = rectangle(matrix, primitive.rect);
|
|
715
|
+
if (rects !== undefined)
|
|
716
|
+
rects[index] = rect;
|
|
717
|
+
}
|
|
718
|
+
else if (!rectsChecked)
|
|
719
|
+
checkRectangle(matrix, rect);
|
|
720
|
+
const effective = alpha * primitive.alpha;
|
|
721
|
+
if (rect.width === 0 || rect.height === 0 || effective === 0) {
|
|
722
|
+
empty(occurrenceId);
|
|
723
|
+
plain = false;
|
|
724
|
+
continue;
|
|
725
|
+
}
|
|
726
|
+
budget.emission(clips, false);
|
|
727
|
+
const material2 = materialIndex(material), flat = flattenClips(clips), last = kept?.commands[given];
|
|
728
|
+
usedMaterial = material2;
|
|
729
|
+
if (last !== undefined &&
|
|
730
|
+
last.kind === 'rect' &&
|
|
731
|
+
last.ordinal === commands.length &&
|
|
732
|
+
last.occurrenceId === occurrenceId &&
|
|
733
|
+
last.materialIndex === material2 &&
|
|
734
|
+
last.matrix === matrix &&
|
|
735
|
+
is(last.opacity, alpha) &&
|
|
736
|
+
last.clips === flat &&
|
|
737
|
+
last.rect === rect &&
|
|
738
|
+
last.fillColor === primitive.color &&
|
|
739
|
+
last.fillAlpha === primitive.alpha)
|
|
740
|
+
commands.push(last);
|
|
741
|
+
else {
|
|
742
|
+
const command = freeze({
|
|
743
|
+
kind: 'rect',
|
|
744
|
+
ordinal: commands.length,
|
|
745
|
+
occurrenceId,
|
|
746
|
+
materialIndex: material2,
|
|
747
|
+
matrix,
|
|
748
|
+
opacity: alpha,
|
|
749
|
+
clips: flat,
|
|
750
|
+
rect,
|
|
751
|
+
fillColor: primitive.color,
|
|
752
|
+
fillAlpha: primitive.alpha
|
|
753
|
+
});
|
|
754
|
+
commands.push(command);
|
|
755
|
+
if (kept !== undefined)
|
|
756
|
+
kept.commands[given] = command;
|
|
757
|
+
}
|
|
758
|
+
given++;
|
|
759
|
+
}
|
|
760
|
+
// Only once every kept rectangle has been checked under it does the matrix become theirs.
|
|
761
|
+
if (!rectsChecked)
|
|
762
|
+
kept.rectsMatrix = matrix;
|
|
763
|
+
if (shape !== undefined)
|
|
764
|
+
for (const part of shape.parts) {
|
|
765
|
+
// A node's shapes are geometries of coloured triangles in the place of its rectangles, each over the one white
|
|
766
|
+
// pixel or over the image it is filled with. An image is sampled as a whole page, repeating or held at its edge.
|
|
767
|
+
const occurrenceId = nextOccurrence++, fill = part.bitmap;
|
|
768
|
+
referencedTuples(matrix, part.geometry);
|
|
769
|
+
let image = SHAPE_PAGE, region = SHAPE_REGION, drawn = material;
|
|
770
|
+
if (fill !== undefined) {
|
|
771
|
+
const snapshot = readMeshCaptureImage({ lease: fill.lease });
|
|
772
|
+
image = snapshot.image;
|
|
773
|
+
region = plainRegion(snapshot.sourceRect);
|
|
774
|
+
drawn = shapeFillMaterial(material, fill.repeat);
|
|
775
|
+
}
|
|
776
|
+
budget.source(image);
|
|
777
|
+
const sharedRegionIndex = regionIndex(image, region), sharedGeometryIndex = geometryIndex(part.geometry);
|
|
778
|
+
budget.emission(clips, false);
|
|
779
|
+
commands.push(freeze({
|
|
780
|
+
kind: 'mesh',
|
|
781
|
+
ordinal: commands.length,
|
|
782
|
+
occurrenceId,
|
|
783
|
+
materialIndex: materialIndex(drawn),
|
|
784
|
+
matrix,
|
|
785
|
+
opacity: alpha,
|
|
786
|
+
clips: flattenClips(clips),
|
|
787
|
+
regionIndex: sharedRegionIndex,
|
|
788
|
+
geometryIndex: sharedGeometryIndex
|
|
789
|
+
}));
|
|
790
|
+
}
|
|
791
|
+
if (bitmap !== undefined) {
|
|
792
|
+
const occurrenceId = nextOccurrence++;
|
|
793
|
+
let rect;
|
|
794
|
+
if (kept !== undefined &&
|
|
795
|
+
kept.bitmap === bitmap &&
|
|
796
|
+
kept.bitmapMatrix === matrix &&
|
|
797
|
+
kept.bitmapDomain === material.samplingDomain)
|
|
798
|
+
rect = kept.bitmapRect;
|
|
799
|
+
else if (kept !== undefined &&
|
|
800
|
+
kept.bitmap === bitmap &&
|
|
801
|
+
kept.bitmapDomain === material.samplingDomain &&
|
|
802
|
+
kept.bitmapRect !== undefined) {
|
|
803
|
+
// The same bitmap in the same domain has the same rectangle; it is checked under the new matrix.
|
|
804
|
+
rect = kept.bitmapRect;
|
|
805
|
+
checkRectangle(matrix, rect);
|
|
806
|
+
kept.bitmapMatrix = matrix;
|
|
807
|
+
}
|
|
808
|
+
else {
|
|
809
|
+
rect = rectangle(matrix, bitmapRect(bitmap, material));
|
|
810
|
+
if (kept !== undefined) {
|
|
811
|
+
kept.bitmap = bitmap;
|
|
812
|
+
kept.bitmapMatrix = matrix;
|
|
813
|
+
kept.bitmapDomain = material.samplingDomain;
|
|
814
|
+
kept.bitmapRect = rect;
|
|
815
|
+
}
|
|
816
|
+
}
|
|
817
|
+
const snapshot = readBitmapImage(bitmap.lease);
|
|
818
|
+
let region, hash;
|
|
819
|
+
if (kept !== undefined && kept.regionOf === bitmap) {
|
|
820
|
+
region = kept.region;
|
|
821
|
+
hash = kept.regionHash;
|
|
822
|
+
}
|
|
823
|
+
else {
|
|
824
|
+
region = bitmapRegion(bitmap);
|
|
825
|
+
hash = regionHash(region);
|
|
826
|
+
if (kept !== undefined) {
|
|
827
|
+
kept.regionOf = bitmap;
|
|
828
|
+
kept.region = region;
|
|
829
|
+
kept.regionHash = hash;
|
|
830
|
+
}
|
|
831
|
+
}
|
|
832
|
+
budget.source(snapshot.image);
|
|
833
|
+
const sharedRegionIndex = regionIndex(snapshot.image, region, hash);
|
|
834
|
+
budget.emission(clips, false);
|
|
835
|
+
const material2 = materialIndex(material), flat = flattenClips(clips), last = kept?.commands[given];
|
|
836
|
+
usedMaterial = material2;
|
|
837
|
+
usedRegion = sharedRegionIndex;
|
|
838
|
+
if (last !== undefined &&
|
|
839
|
+
last.kind === 'image' &&
|
|
840
|
+
last.ordinal === commands.length &&
|
|
841
|
+
last.occurrenceId === occurrenceId &&
|
|
842
|
+
last.materialIndex === material2 &&
|
|
843
|
+
last.matrix === matrix &&
|
|
844
|
+
is(last.opacity, alpha) &&
|
|
845
|
+
last.clips === flat &&
|
|
846
|
+
last.rect === rect &&
|
|
847
|
+
last.regionIndex === sharedRegionIndex)
|
|
848
|
+
commands.push(last);
|
|
849
|
+
else {
|
|
850
|
+
const command = freeze({
|
|
851
|
+
kind: 'image',
|
|
852
|
+
ordinal: commands.length,
|
|
853
|
+
occurrenceId,
|
|
854
|
+
materialIndex: material2,
|
|
855
|
+
matrix,
|
|
856
|
+
opacity: alpha,
|
|
857
|
+
clips: flat,
|
|
858
|
+
rect,
|
|
859
|
+
regionIndex: sharedRegionIndex
|
|
860
|
+
});
|
|
861
|
+
commands.push(command);
|
|
862
|
+
if (kept !== undefined)
|
|
863
|
+
kept.commands[given] = command;
|
|
864
|
+
}
|
|
865
|
+
given++;
|
|
866
|
+
}
|
|
867
|
+
if (mesh !== undefined) {
|
|
868
|
+
const occurrenceId = nextOccurrence++, snapshot = readMeshCaptureImage(mesh);
|
|
869
|
+
if (mesh.regionOnly && material.samplingDomain !== 'region')
|
|
870
|
+
throw new EgretError('SHARED_MATERIAL_UNSUPPORTED');
|
|
871
|
+
referencedTuples(matrix, mesh.geometry);
|
|
872
|
+
budget.source(snapshot.image);
|
|
873
|
+
if (mesh.geometry.indexCount === 0)
|
|
874
|
+
empty(occurrenceId);
|
|
875
|
+
else {
|
|
876
|
+
const sharedRegionIndex = regionIndex(snapshot.image, mesh.viewRegion ?? plainRegion(mesh.sourceRect));
|
|
877
|
+
const sharedGeometryIndex = geometryIndex(mesh.geometry);
|
|
878
|
+
budget.emission(clips, false);
|
|
879
|
+
commands.push(freeze({
|
|
880
|
+
kind: 'mesh',
|
|
881
|
+
ordinal: commands.length,
|
|
882
|
+
occurrenceId,
|
|
883
|
+
materialIndex: materialIndex(material),
|
|
884
|
+
matrix,
|
|
885
|
+
opacity: alpha,
|
|
886
|
+
clips: flattenClips(clips),
|
|
887
|
+
regionIndex: sharedRegionIndex,
|
|
888
|
+
geometryIndex: sharedGeometryIndex
|
|
889
|
+
}));
|
|
890
|
+
}
|
|
891
|
+
}
|
|
892
|
+
if (text !== undefined) {
|
|
893
|
+
assertTextFieldScope(text.scope);
|
|
894
|
+
const committed = text.committed;
|
|
895
|
+
if (committed !== undefined) {
|
|
896
|
+
const occurrenceId = nextOccurrence++;
|
|
897
|
+
if (committed.lease === undefined || committed.raster === undefined || committed.sourceRect === undefined)
|
|
898
|
+
empty(occurrenceId);
|
|
899
|
+
else {
|
|
900
|
+
const rect = rectangle(matrix, committed.raster), snapshot = readBitmapImage(committed.lease);
|
|
901
|
+
budget.source(snapshot.image);
|
|
902
|
+
if (rect.width === 0 || rect.height === 0)
|
|
903
|
+
empty(occurrenceId);
|
|
904
|
+
else {
|
|
905
|
+
const sharedRegionIndex = regionIndex(snapshot.image, snapshot.viewRegion ?? plainRegion(committed.sourceRect));
|
|
906
|
+
budget.emission(clips, false);
|
|
907
|
+
commands.push(freeze({
|
|
908
|
+
kind: 'image',
|
|
909
|
+
ordinal: commands.length,
|
|
910
|
+
occurrenceId,
|
|
911
|
+
materialIndex: materialIndex(material),
|
|
912
|
+
matrix,
|
|
913
|
+
opacity: alpha,
|
|
914
|
+
clips: flattenClips(clips),
|
|
915
|
+
rect,
|
|
916
|
+
regionIndex: sharedRegionIndex
|
|
917
|
+
}));
|
|
918
|
+
}
|
|
919
|
+
}
|
|
920
|
+
}
|
|
921
|
+
}
|
|
922
|
+
// A node that gave draws alone may rest in the next frame: this is everything those draws were derived from.
|
|
923
|
+
if (kept !== undefined) {
|
|
924
|
+
if (plain) {
|
|
925
|
+
kept.restChanges = state.changes;
|
|
926
|
+
kept.restParentAlpha = parentAlpha;
|
|
927
|
+
kept.restClips = inheritedClips;
|
|
928
|
+
kept.restInherited = inheritedMaterial;
|
|
929
|
+
kept.restOrdinal = firstOrdinal;
|
|
930
|
+
kept.restOccurrence = firstOccurrence;
|
|
931
|
+
kept.restCount = given;
|
|
932
|
+
kept.restUnits = primitiveCount + (bitmap === undefined ? 0 : 1);
|
|
933
|
+
kept.restAlpha = alpha;
|
|
934
|
+
kept.restMaterial = material;
|
|
935
|
+
kept.restMaterialIndex = usedMaterial;
|
|
936
|
+
kept.restTableMaterial = usedMaterial < 0 ? undefined : materials[usedMaterial];
|
|
937
|
+
kept.restRegionIndex = usedRegion;
|
|
938
|
+
kept.restTableRegion = usedRegion < 0 ? undefined : regionValues[usedRegion];
|
|
939
|
+
}
|
|
940
|
+
else
|
|
941
|
+
kept.restChanges = -1;
|
|
942
|
+
}
|
|
943
|
+
push(node, true, matrix, alpha, clips, material, explicit, clip, effect);
|
|
944
|
+
if (kept !== undefined && plain)
|
|
945
|
+
kept.restChildless = stack[stack.length - 1].children === 0;
|
|
946
|
+
return true;
|
|
947
|
+
}
|
|
948
|
+
/**
|
|
949
|
+
* The commands of a node at rest, given again. False when a table does not hold its material, or the region
|
|
950
|
+
* of the image its lease now names, at their places yet, when its lease cannot be read, or when the charges
|
|
951
|
+
* of its draws do not fit: nothing has then been done, and the node is drawn as if it had not rested.
|
|
952
|
+
*/
|
|
953
|
+
function rest(node, kept) {
|
|
954
|
+
const count = kept.restCount, clips = kept.restClips;
|
|
955
|
+
if (count !== 0) {
|
|
956
|
+
if (materials[kept.restMaterialIndex] !== kept.restTableMaterial)
|
|
957
|
+
return false;
|
|
958
|
+
const place = kept.restRegionIndex;
|
|
959
|
+
if (place >= 0) {
|
|
960
|
+
let image;
|
|
961
|
+
try {
|
|
962
|
+
image = readBitmapSource(kept.bitmap.lease);
|
|
963
|
+
}
|
|
964
|
+
catch {
|
|
965
|
+
return false;
|
|
966
|
+
}
|
|
967
|
+
// The region of the table at that place is the node's region of this image: the command names the place alone.
|
|
968
|
+
const region = regions[place];
|
|
969
|
+
if (region === undefined ||
|
|
970
|
+
pages[region.pageIndex].source !== image ||
|
|
971
|
+
(regionValues[place] !== kept.restTableRegion && !sameRegion(region, kept.region)))
|
|
972
|
+
return false;
|
|
973
|
+
}
|
|
974
|
+
if (!budget.draws(count, clips))
|
|
975
|
+
return false;
|
|
976
|
+
const given = kept.commands;
|
|
977
|
+
for (let index = 0; index < count; index++)
|
|
978
|
+
commands.push(given[index]);
|
|
979
|
+
nextOccurrence += count;
|
|
980
|
+
}
|
|
981
|
+
if (!kept.restChildless)
|
|
982
|
+
push(node, true, kept.matrix, kept.restAlpha, clips, kept.restMaterial, undefined, undefined, undefined);
|
|
983
|
+
return true;
|
|
984
|
+
}
|
|
985
|
+
function enter(node, parent, drawn, parentMatrix, parentAlpha, inheritedClips, inheritedMaterial) {
|
|
986
|
+
// Admission: every node, in walk order, independent of visibility.
|
|
987
|
+
budget.node();
|
|
988
|
+
const state = checkNode(node, parent, engine, capture, tree);
|
|
989
|
+
const kept = keeping && drawn && !refused ? state.sharedCapture : undefined;
|
|
990
|
+
// At rest, the node is a sprite or a bitmap as it was, with as many primitives: its units are those it had.
|
|
991
|
+
const resting = kept !== undefined &&
|
|
992
|
+
kept.restChanges === state.changes &&
|
|
993
|
+
kept.parentMatrix === parentMatrix &&
|
|
994
|
+
is(kept.restParentAlpha, parentAlpha) &&
|
|
995
|
+
kept.restClips === inheritedClips &&
|
|
996
|
+
kept.restInherited === inheritedMaterial &&
|
|
997
|
+
kept.restOrdinal === commands.length &&
|
|
998
|
+
kept.restOccurrence === nextOccurrence;
|
|
999
|
+
if (resting) {
|
|
1000
|
+
budget.authoring(kept.restUnits);
|
|
1001
|
+
if (rest(node, kept))
|
|
1002
|
+
return;
|
|
1003
|
+
}
|
|
1004
|
+
const primitives = state.primitives, primitiveCount = primitives.length;
|
|
1005
|
+
const bitmap = readBitmap(node), mesh = resting ? undefined : readMeshState(node), text = resting ? undefined : readTextFieldState(node);
|
|
1006
|
+
const shape = state.shape === undefined ? undefined : resolveShape(state.shape);
|
|
1007
|
+
if (!resting) {
|
|
1008
|
+
budget.authoring(primitiveCount);
|
|
1009
|
+
if (bitmap !== undefined)
|
|
1010
|
+
budget.authoring(1);
|
|
1011
|
+
if (mesh !== undefined) {
|
|
1012
|
+
budget.authoring(1);
|
|
1013
|
+
budget.geometry(mesh.geometry);
|
|
1014
|
+
}
|
|
1015
|
+
if (shape !== undefined)
|
|
1016
|
+
for (const part of shape.parts) {
|
|
1017
|
+
budget.authoring(1);
|
|
1018
|
+
budget.geometry(part.geometry);
|
|
1019
|
+
}
|
|
1020
|
+
if (text?.committed !== undefined)
|
|
1021
|
+
budget.authoring(1);
|
|
1022
|
+
}
|
|
1023
|
+
if (drawn && !refused) {
|
|
1024
|
+
try {
|
|
1025
|
+
if (draw(node, state, primitives, primitiveCount, bitmap, mesh, text, shape, parentMatrix, parentAlpha, inheritedClips, inheritedMaterial))
|
|
1026
|
+
return;
|
|
1027
|
+
}
|
|
1028
|
+
catch (cause) {
|
|
1029
|
+
refused = true;
|
|
1030
|
+
refusal = cause;
|
|
1031
|
+
}
|
|
1032
|
+
}
|
|
1033
|
+
push(node, false, identity, 0, undefined, defaultMaterial, undefined, undefined, undefined);
|
|
1034
|
+
}
|
|
1035
|
+
enter(stage, undefined, true, identity, 1, undefined, defaultMaterial);
|
|
1036
|
+
while (stack.length !== 0) {
|
|
1037
|
+
const cursor = stack[stack.length - 1];
|
|
1038
|
+
if (cursor.nextChild === cursor.children) {
|
|
1039
|
+
if (cursor.drawn && !refused) {
|
|
1040
|
+
try {
|
|
1041
|
+
close(cursor.explicit, cursor.clip, cursor.effect);
|
|
1042
|
+
}
|
|
1043
|
+
catch (cause) {
|
|
1044
|
+
refused = true;
|
|
1045
|
+
refusal = cause;
|
|
1046
|
+
}
|
|
1047
|
+
}
|
|
1048
|
+
stack.pop();
|
|
1049
|
+
continue;
|
|
1050
|
+
}
|
|
1051
|
+
const child = tree.child(cursor.node, cursor.nextChild++);
|
|
1052
|
+
if (child === undefined)
|
|
1053
|
+
throw new EgretError('DISPLAY_TREE_INVARIANT');
|
|
1054
|
+
enter(child, cursor.node, cursor.drawn, cursor.matrix, cursor.alpha, cursor.clips, cursor.material);
|
|
1055
|
+
}
|
|
1056
|
+
// The whole tree is admitted. This is where the visible pass used to begin.
|
|
1057
|
+
engine.assertOpen();
|
|
1058
|
+
if (refused)
|
|
1059
|
+
throw refusal;
|
|
1060
|
+
engine.assertOpen();
|
|
1061
|
+
return freeze({
|
|
1062
|
+
commands: freeze(commands),
|
|
1063
|
+
pages: freeze(pages),
|
|
1064
|
+
regions: freeze(regions),
|
|
1065
|
+
materials: freeze(materials),
|
|
1066
|
+
geometries: freeze(geometries)
|
|
1067
|
+
});
|
|
1068
|
+
}
|
|
1069
|
+
//# sourceMappingURL=sharedFrameCapture.js.map
|