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