@swf2es/web 0.1.28 → 0.1.30

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/src/meter.ts ADDED
@@ -0,0 +1,498 @@
1
+ // The performance meter the element shows over its player, off until the
2
+ // viewer turns it on (the context menu's "Show stats", or the page,
3
+ // through `performanceMeter`): twice a second, the SWF's frames played a
4
+ // second against its frame rate, the player's ms in a frame (its scripts
5
+ // and its drawing, as the frame listener tells them), the draws of a frame
6
+ // the player drew and the WebGL calls that made them, the JS heap where the
7
+ // browser tells it (Chromium's performance.memory), and the WebAssembly
8
+ // memories behind the player. Off, it costs nothing: it is not even made
9
+ // until first shown, and once hidden it hears no frames, keeps no timer and
10
+ // leaves the context its own functions.
11
+ import type { FrameStats } from "./playback.js";
12
+
13
+ interface MemoryInfo {
14
+ usedJSHeapSize: number;
15
+ }
16
+
17
+ type GL = WebGLRenderingContext | WebGL2RenderingContext;
18
+
19
+ /**
20
+ * Its look, which a page may give its own through custom properties on the
21
+ * element (font, color, background, border, muted, the labels' colour, and
22
+ * opacity, the background's, 0.7 by default, which multiplies a background's
23
+ * own alpha), as the demo site gives its
24
+ * theme's; by default the browser's light or dark colours, as the context
25
+ * menu's. The background lets the SWF show through; a halo of it around
26
+ * each figure keeps the figures readable over white text or busy content.
27
+ * No backdrop blur: blurring a canvas that changes every frame costs the
28
+ * GPU every frame.
29
+ */
30
+ export const METER_STYLE =
31
+ " .meter { --swf2es-meter-fill: var(--swf2es-meter-background, Canvas);" +
32
+ " position: absolute; top: 6px; left: 6px; z-index: 3; display: grid;" +
33
+ " grid-template-columns: max-content max-content; gap: 0 8px; box-sizing: border-box;" +
34
+ " max-width: calc(100% - 12px); max-height: calc(100% - 12px); overflow: hidden;" +
35
+ " margin: 0; padding: 3px 7px;" +
36
+ " font: var(--swf2es-meter-font, 11px/1.35 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace);" +
37
+ " font-variant-numeric: tabular-nums; color-scheme: light dark;" +
38
+ " color: var(--swf2es-meter-color, CanvasText);" +
39
+ " background: color-mix(in srgb, var(--swf2es-meter-fill)" +
40
+ " clamp(0%, calc(var(--swf2es-meter-opacity, 0.7) * 100%), 100%), transparent);" +
41
+ " border: 1px solid color-mix(in srgb, var(--swf2es-meter-border, GrayText) 50%, transparent);" +
42
+ " border-radius: 4px;" +
43
+ " text-shadow: 1px 0 0 var(--swf2es-meter-fill), -1px 0 0 var(--swf2es-meter-fill)," +
44
+ " 0 1px 0 var(--swf2es-meter-fill), 0 -1px 0 var(--swf2es-meter-fill)," +
45
+ " 0 0 2px var(--swf2es-meter-fill);" +
46
+ " pointer-events: none; user-select: none }" +
47
+ " .meter[data-corner$=right] { left: auto; right: 6px }" +
48
+ " .meter[data-corner^=bottom] { top: auto; bottom: 6px }" +
49
+ " .meter[hidden], .meter > div[hidden] { display: none }" +
50
+ " .meter > div { display: contents }" +
51
+ " .meter dt { color: var(--swf2es-meter-muted, color-mix(in srgb, CanvasText 70%, Canvas)) }" +
52
+ " .meter dd { margin: 0; text-align: right }" +
53
+ // High contrast drops text-shadow, the halo the figures need over a box the SWF shows through.
54
+ " @media (forced-colors: active) { .meter { --swf2es-meter-opacity: 1 } }";
55
+
56
+ /** Each figure's name, in the dd's `data-figure`, and its label. */
57
+ const FIGURES = [
58
+ ["fps", "fps"],
59
+ ["frame", "frame"],
60
+ ["sub-draws", "sub-draws"],
61
+ ["gl-calls", "GL calls"],
62
+ ["heap", "JS heap"],
63
+ ["codegen", "codegen"],
64
+ ["native", "native"],
65
+ ] as const;
66
+
67
+ /**
68
+ * The draw functions counted, each with where its count of draws is: -1 for
69
+ * one, else the index of its last argument, a multi-draw's drawcount.
70
+ */
71
+ const DRAWS: [string, number][] = [
72
+ ["drawArrays", -1],
73
+ ["drawElements", -1],
74
+ ["drawArraysInstanced", -1],
75
+ ["drawElementsInstanced", -1],
76
+ ];
77
+ const MULTI_DRAWS: [string, number][] = [
78
+ ["multiDrawArraysWEBGL", 5],
79
+ ["multiDrawElementsWEBGL", 6],
80
+ ["multiDrawArraysInstancedWEBGL", 7],
81
+ ["multiDrawElementsInstancedWEBGL", 8],
82
+ ];
83
+
84
+ /** The calls of the loop kept: a second's at 500 a second, more than any display's rate. */
85
+ const KEPT = 512;
86
+ /** The span the figures cover, and how often they are shown, in ms. */
87
+ const SPAN = 1000;
88
+ const EVERY = 500;
89
+ const MB = 1024 * 1024;
90
+ /** Where the viewer's choice is kept for every element of the origin, "1" for on. */
91
+ const STORED = "swf2es.performanceMeter";
92
+ /** Where the viewer's choice of corner is kept, likewise. */
93
+ const STORED_CORNER = "swf2es.performanceMeterCorner";
94
+
95
+ /** The element's corners the meter may sit in, in the order the context menu moves it through. */
96
+ export const METER_CORNERS = ["top-left", "top-right", "bottom-left", "bottom-right"] as const;
97
+ export type MeterCorner = (typeof METER_CORNERS)[number];
98
+
99
+ export function isMeterCorner(value: unknown): value is MeterCorner {
100
+ return METER_CORNERS.includes(value as MeterCorner);
101
+ }
102
+
103
+ /** The corner after `corner`, the first after the last. */
104
+ export function nextCorner(corner: MeterCorner): MeterCorner {
105
+ return METER_CORNERS[(METER_CORNERS.indexOf(corner) + 1) % METER_CORNERS.length];
106
+ }
107
+
108
+ /** The viewer's corner as last kept: top-left where none is, or storage is refused. */
109
+ export function storedCorner(): MeterCorner {
110
+ try {
111
+ const corner = localStorage.getItem(STORED_CORNER);
112
+ return isMeterCorner(corner) ? corner : "top-left";
113
+ } catch {
114
+ return "top-left";
115
+ }
116
+ }
117
+
118
+ export function storeCorner(corner: MeterCorner): void {
119
+ try {
120
+ if (corner === "top-left") {
121
+ localStorage.removeItem(STORED_CORNER);
122
+ } else {
123
+ localStorage.setItem(STORED_CORNER, corner);
124
+ }
125
+ } catch {
126
+ // Kept for this page alone.
127
+ }
128
+ }
129
+
130
+ /** The viewer's choice as last kept: off where none is, or storage is refused. */
131
+ export function storedMeter(): boolean {
132
+ try {
133
+ return localStorage.getItem(STORED) === "1";
134
+ } catch {
135
+ return false;
136
+ }
137
+ }
138
+
139
+ export function storeMeter(on: boolean): void {
140
+ try {
141
+ if (on) {
142
+ localStorage.setItem(STORED, "1");
143
+ } else {
144
+ localStorage.removeItem(STORED);
145
+ }
146
+ } catch {
147
+ // Kept for this page alone.
148
+ }
149
+ }
150
+
151
+ /**
152
+ * The draw calls made on a context, counted by wrapping its draw functions
153
+ * only while the meter shows: off, and before a context is given, the
154
+ * context has its own functions back, its canvas none of the counter's
155
+ * listeners, and the count costs nothing. A multi-draw is one call and the
156
+ * draws it makes, as the GPU sees them. The renderer counts neither itself.
157
+ */
158
+ class DrawCounter {
159
+ draws = 0;
160
+ calls = 0;
161
+ private gl: GL | null = null;
162
+ private shown = false;
163
+ private readonly restores: (() => void)[] = [];
164
+
165
+ /** Count `gl`'s draws, while shown; null for none. */
166
+ attach(gl: GL | null): void {
167
+ if (gl === this.gl) {
168
+ return;
169
+ }
170
+
171
+ this.listen(false);
172
+ this.unwrap();
173
+ this.gl = gl;
174
+ if (this.shown) {
175
+ this.listen(true);
176
+ this.wrap();
177
+ }
178
+ }
179
+
180
+ show(shown: boolean): void {
181
+ if (shown === this.shown) {
182
+ return;
183
+ }
184
+
185
+ this.shown = shown;
186
+ this.listen(shown);
187
+ if (shown) {
188
+ this.wrap();
189
+ } else {
190
+ this.unwrap();
191
+ }
192
+ }
193
+
194
+ /** Hear the context lost and given back, or no longer. */
195
+ private listen(on: boolean): void {
196
+ const canvas = this.gl?.canvas;
197
+ if (!canvas) {
198
+ return;
199
+ }
200
+
201
+ if (on) {
202
+ canvas.addEventListener("webglcontextlost", this.lost);
203
+ canvas.addEventListener("webglcontextrestored", this.restored);
204
+ } else {
205
+ canvas.removeEventListener("webglcontextlost", this.lost);
206
+ canvas.removeEventListener("webglcontextrestored", this.restored);
207
+ }
208
+ }
209
+
210
+ private readonly lost = () => this.unwrap();
211
+ // The renderer's own listener, added before this one, has fetched the extensions anew.
212
+ private readonly restored = () => this.wrap();
213
+
214
+ private wrap(): void {
215
+ const gl = this.gl;
216
+ this.unwrap();
217
+ if (!gl || !this.shown || gl.isContextLost()) {
218
+ return;
219
+ }
220
+
221
+ for (const [name, drawcount] of DRAWS) {
222
+ this.patch(gl, name, drawcount);
223
+ }
224
+
225
+ const multi = gl.getExtension("WEBGL_multi_draw");
226
+ if (multi) {
227
+ for (const [name, drawcount] of MULTI_DRAWS) {
228
+ this.patch(multi, name, drawcount);
229
+ }
230
+ }
231
+ }
232
+
233
+ private unwrap(): void {
234
+ for (const restore of this.restores.splice(0)) {
235
+ restore();
236
+ }
237
+ }
238
+
239
+ /**
240
+ * Wrap `target[name]`, to be put back as it was, a property of its own or
241
+ * its prototype's: with as many arguments as the widest multi-draw takes,
242
+ * the rest undefined, which WebGL ignores, so that a draw allocates no
243
+ * array of its arguments.
244
+ */
245
+ private patch(target: object, name: string, drawcount: number): void {
246
+ const functions = target as Record<string, unknown>;
247
+ const original = functions[name] as (...args: unknown[]) => unknown;
248
+ if (typeof original !== "function") {
249
+ return;
250
+ }
251
+
252
+ const own = Object.getOwnPropertyDescriptor(target, name);
253
+ functions[name] = (
254
+ a: unknown,
255
+ b: unknown,
256
+ c: unknown,
257
+ d: unknown,
258
+ e: unknown,
259
+ f: unknown,
260
+ g: unknown,
261
+ h: unknown,
262
+ i: unknown,
263
+ ) => {
264
+ this.calls++;
265
+ this.draws +=
266
+ drawcount === 5
267
+ ? (f as number)
268
+ : drawcount === 6
269
+ ? (g as number)
270
+ : drawcount === 7
271
+ ? (h as number)
272
+ : drawcount === 8
273
+ ? (i as number)
274
+ : 1;
275
+ return original.call(target, a, b, c, d, e, f, g, h, i);
276
+ };
277
+ this.restores.push(() => {
278
+ if (own) {
279
+ Object.defineProperty(target, name, own);
280
+ } else {
281
+ delete functions[name];
282
+ }
283
+ });
284
+ }
285
+ }
286
+
287
+ export class PerformanceMeter {
288
+ private readonly root: HTMLDListElement;
289
+ private readonly cells = new Map<string, HTMLElement>();
290
+ private shown = false;
291
+ /** Whether a player plays, whose frames the meter hears. */
292
+ private playing = false;
293
+ private timer: ReturnType<typeof setInterval> | undefined;
294
+ private readonly counter = new DrawCounter();
295
+ /** The loop's last KEPT calls, a ring: each one's time, frames played, and ms (-1 for no work). */
296
+ private readonly times = new Float64Array(KEPT);
297
+ private readonly frames = new Float64Array(KEPT);
298
+ private readonly costs = new Float64Array(KEPT);
299
+ private readonly sorted = new Float64Array(KEPT);
300
+ private next = 0;
301
+ private count = 0;
302
+ /** When the calls counted began: shown, or a SWF started, whichever came last. */
303
+ private since = 0;
304
+ /** The SWF's frame rate as of the last call, 0 before one. */
305
+ private rate = 0;
306
+ /** The draws, and the calls that made them, of the frames that drew since the last showing. */
307
+ private draws = 0;
308
+ private calls = 0;
309
+ private drawnFrames = 0;
310
+
311
+ /** Shown in `parent`, the element's shadow root; `memory` is the element's wasmMemory. */
312
+ constructor(
313
+ parent: Node,
314
+ private readonly memory: () => { codegen: number; native: number },
315
+ ) {
316
+ this.root = document.createElement("dl");
317
+ this.root.className = "meter";
318
+ this.root.dataset.corner = "top-left";
319
+ this.root.hidden = true;
320
+ this.root.setAttribute("aria-label", "Performance");
321
+ for (const [name, label] of FIGURES) {
322
+ const row = document.createElement("div");
323
+ const dt = document.createElement("dt");
324
+ dt.textContent = label;
325
+ const dd = document.createElement("dd");
326
+ dd.dataset.figure = name;
327
+ dd.textContent = "–";
328
+ row.append(dt, dd);
329
+ this.root.append(row);
330
+ this.cells.set(name, dd);
331
+ }
332
+
333
+ parent.appendChild(this.root);
334
+ }
335
+
336
+ /** Put the meter in `corner` of the element. */
337
+ place(corner: MeterCorner): void {
338
+ this.root.dataset.corner = corner;
339
+ }
340
+
341
+ /** Show the meter and measure, or hide it and stop. */
342
+ show(on: boolean): void {
343
+ if (on === this.shown) {
344
+ return;
345
+ }
346
+
347
+ this.shown = on;
348
+ this.root.hidden = !on;
349
+ this.counter.show(on);
350
+ if (on) {
351
+ this.reset();
352
+ }
353
+
354
+ this.tick();
355
+ }
356
+
357
+ /** A player begun, drawing with `gl`, or none playing: what was counted before is let go. */
358
+ attach(gl: GL | null, playing: boolean): void {
359
+ this.counter.attach(gl);
360
+ this.playing = playing;
361
+ this.reset();
362
+ this.tick();
363
+ }
364
+
365
+ /** The timer runs while the meter shows a player's figures; it shows them at once as it starts. */
366
+ private tick(): void {
367
+ const run = this.shown && this.playing;
368
+ if (run && this.timer === undefined) {
369
+ this.timer = setInterval(this.update, EVERY);
370
+ } else if (!run && this.timer !== undefined) {
371
+ clearInterval(this.timer);
372
+ this.timer = undefined;
373
+ }
374
+
375
+ if (this.shown) {
376
+ this.update();
377
+ }
378
+ }
379
+
380
+ private reset(): void {
381
+ this.next = this.count = 0;
382
+ this.since = performance.now();
383
+ this.rate = 0;
384
+ this.counter.draws = this.counter.calls = 0;
385
+ this.draws = this.calls = this.drawnFrames = 0;
386
+ this.text("sub-draws", "–");
387
+ this.text("gl-calls", "–");
388
+ }
389
+
390
+ /** Each call of the player's loop, kept in the ring without allocating. */
391
+ readonly heard = (stats: FrameStats): void => {
392
+ const i = this.next;
393
+ this.next = i + 1 === KEPT ? 0 : i + 1;
394
+ if (this.count < KEPT) {
395
+ this.count++;
396
+ }
397
+
398
+ this.times[i] = stats.time;
399
+ this.frames[i] = stats.frames;
400
+ this.costs[i] = stats.frames > 0 || stats.drew ? stats.play + stats.draw : -1;
401
+ this.rate = stats.frameRate;
402
+ // What the context was asked since the last call belongs to the frame this one drew.
403
+ if (stats.drew && this.counter.calls > 0) {
404
+ this.draws += this.counter.draws;
405
+ this.calls += this.counter.calls;
406
+ this.drawnFrames++;
407
+ }
408
+
409
+ this.counter.draws = this.counter.calls = 0;
410
+ };
411
+
412
+ private readonly update = () => {
413
+ const now = performance.now();
414
+ const from = Math.max(now - SPAN, this.since);
415
+ let played = 0;
416
+ let working = 0;
417
+ // From the newest back, to the span's start.
418
+ for (let k = 0, i = this.next; k < this.count; k++) {
419
+ i = i === 0 ? KEPT - 1 : i - 1;
420
+ if (this.times[i] < from) {
421
+ break;
422
+ }
423
+
424
+ played += this.frames[i];
425
+ if (this.costs[i] >= 0) {
426
+ this.insert(working++, this.costs[i]);
427
+ }
428
+ }
429
+
430
+ const span = now - from;
431
+ const playing = this.playing && this.rate > 0;
432
+ this.text(
433
+ "fps",
434
+ playing && span >= EVERY / 2
435
+ ? `${((played * 1000) / span).toFixed(1)} / ${rateText(this.rate)}`
436
+ : "–",
437
+ );
438
+ this.text(
439
+ "frame",
440
+ playing && working > 0
441
+ ? `${median(this.sorted, working).toFixed(1)} ms, max ${this.sorted[working - 1].toFixed(1)}`
442
+ : "–",
443
+ );
444
+ // A still stage draws nothing: the last frame drawn stands.
445
+ if (this.drawnFrames > 0) {
446
+ this.text("sub-draws", String(Math.round(this.draws / this.drawnFrames)));
447
+ this.text("gl-calls", String(Math.round(this.calls / this.drawnFrames)));
448
+ }
449
+
450
+ const heap = (performance as { memory?: MemoryInfo }).memory;
451
+ const heapRow = this.cells.get("heap")?.parentElement;
452
+ if (heapRow) {
453
+ heapRow.hidden = !heap;
454
+ }
455
+
456
+ if (heap) {
457
+ this.text("heap", megabytes(heap.usedJSHeapSize));
458
+ }
459
+
460
+ const wasm = this.memory();
461
+ this.text("codegen", wasm.codegen > 0 ? megabytes(wasm.codegen) : "–");
462
+ this.text("native", megabytes(wasm.native));
463
+ this.draws = this.calls = this.drawnFrames = 0;
464
+ };
465
+
466
+ private text(figure: string, text: string): void {
467
+ const cell = this.cells.get(figure);
468
+ if (cell && cell.textContent !== text) {
469
+ cell.textContent = text;
470
+ }
471
+ }
472
+
473
+ /** Put `cost` among the first `n` sorted, by insertion: a second's few hundred, twice a second. */
474
+ private insert(n: number, cost: number): void {
475
+ const sorted = this.sorted;
476
+ let j = n;
477
+ while (j > 0 && sorted[j - 1] > cost) {
478
+ sorted[j] = sorted[j - 1];
479
+ j--;
480
+ }
481
+
482
+ sorted[j] = cost;
483
+ }
484
+ }
485
+
486
+ function median(sorted: Float64Array, n: number): number {
487
+ const middle = n >> 1;
488
+ return n % 2 === 1 ? sorted[middle] : (sorted[middle - 1] + sorted[middle]) / 2;
489
+ }
490
+
491
+ /** A frame rate as a SWF declares it, whole or to the hundredth: its 8.8 fixed point. */
492
+ function rateText(rate: number): string {
493
+ return `${Number.isInteger(rate) ? rate : Number(rate.toFixed(2))} fps`;
494
+ }
495
+
496
+ function megabytes(bytes: number): string {
497
+ return `${(bytes / MB).toFixed(bytes < 10 * MB ? 1 : 0)} MB`;
498
+ }
package/src/playback.ts CHANGED
@@ -31,7 +31,52 @@ export interface Look {
31
31
  bgcolor: number | null;
32
32
  }
33
33
 
34
+ /**
35
+ * What the player did in one call of its loop, as a frame listener hears it
36
+ * (`Swf2esPlayerElement.frameListener`): a call each animation frame, or
37
+ * from the timer that plays a hidden page's frames.
38
+ */
39
+ export interface FrameStats {
40
+ /** The call's time, by performance.now()'s clock: the animation frame's, or the timer's. */
41
+ time: number;
42
+ /** The SWF's frames it played: none where the display's frame fell between two of the SWF's. */
43
+ frames: number;
44
+ /** The SWF's frame rate as it played them, which a script may change. */
45
+ frameRate: number;
46
+ /** The ms the frames took: their scripts, events, timeline and sound, the SWF's own work. */
47
+ play: number;
48
+ /**
49
+ * The ms the rest of the call took on the CPU where it drew: drawing the stage, the GPU's own
50
+ * work aside, and the little before it (the text input's focus kept, the samples chosen anew
51
+ * for a changed quality); 0 where it did not draw.
52
+ */
53
+ draw: number;
54
+ /** Whether it drew the stage: a coarse clock may time a short drawing as 0 ms. */
55
+ drew: boolean;
56
+ /** Whether it was an animation frame, which draws, rather than the timer, which never does. */
57
+ shown: boolean;
58
+ }
59
+
60
+ /** Hears what the player did in each call of its loop, given the same object each time. */
61
+ export type FrameListener = (stats: FrameStats) => void;
62
+
34
63
  export class Playback {
64
+ /**
65
+ * Told after every call of the loop, while set: one listener, which
66
+ * another replaces; unset, the loop measures nothing for it. Its time is
67
+ * not the player's: the frames' pacing counts only the frames' own.
68
+ */
69
+ onFrame: FrameListener | null = null;
70
+ /** What onFrame hears, filled anew for each call. */
71
+ private readonly stats: FrameStats = {
72
+ time: 0,
73
+ frames: 0,
74
+ frameRate: 0,
75
+ play: 0,
76
+ draw: 0,
77
+ drew: false,
78
+ shown: false,
79
+ };
35
80
  private frame = 0;
36
81
  private last: number | null = null;
37
82
  /**
@@ -195,7 +240,11 @@ export class Playback {
195
240
  }
196
241
  };
197
242
 
198
- private step(now: number, show: boolean): void {
243
+ private step(at: number, show: boolean): void {
244
+ // The timer reads performance.now() as it runs; an animation frame's time is when the frame
245
+ // began, which may be before a timer's call just ahead of it. Its time so goes no further back
246
+ // than the last call's, and the player is never handed time going backwards.
247
+ const now = this.last === null ? at : Math.max(at, this.last);
199
248
  const dt = this.last === null ? 0 : now - this.last;
200
249
  this.last = now;
201
250
  // Moved to a display of another density, or zoomed: drawn anew for its pixels.
@@ -204,8 +253,9 @@ export class Playback {
204
253
  }
205
254
 
206
255
  const start = performance.now();
256
+ let played = 0;
207
257
  try {
208
- this.player.advance(dt, this.busy);
258
+ played = this.player.advance(dt, this.busy);
209
259
  } catch (error) {
210
260
  this.report(error);
211
261
  }
@@ -218,8 +268,46 @@ export class Playback {
218
268
  this.requality();
219
269
  }
220
270
 
271
+ let drew = false;
221
272
  if (show && (this.player.changes !== this.drawn || this.dirty)) {
222
273
  this.draw();
274
+ drew = true;
275
+ }
276
+
277
+ // A frame played and not drawn still settles what a draw would for its scripts.
278
+ if (!drew && played > 0) {
279
+ this.player.undrawn();
280
+ }
281
+
282
+ // A frame's script may have destroyed the player: there is nothing left to tell of.
283
+ if (this.onFrame && !this.destroyed) {
284
+ this.told(this.onFrame, now, played, start, drew, show);
285
+ }
286
+ }
287
+
288
+ /** Tell `listener` of the call that began at `start`, its frames' part `this.busy`. */
289
+ private told(
290
+ listener: FrameListener,
291
+ now: number,
292
+ frames: number,
293
+ start: number,
294
+ drew: boolean,
295
+ shown: boolean,
296
+ ): void {
297
+ const end = performance.now();
298
+ const stats = this.stats;
299
+ stats.time = now;
300
+ stats.frames = frames;
301
+ stats.frameRate = this.player.frameRate;
302
+ stats.play = this.busy;
303
+ stats.draw = drew ? end - start - this.busy : 0;
304
+ stats.drew = drew;
305
+ stats.shown = shown;
306
+ // A listener that throws is the page's error, not the loop's: the loop goes on.
307
+ try {
308
+ listener(stats);
309
+ } catch (error) {
310
+ reportError(error);
223
311
  }
224
312
  }
225
313
 
@@ -277,6 +365,7 @@ export class Playback {
277
365
  this.dirty = false;
278
366
  this.view.background = background;
279
367
  this.view.transparent = clear;
368
+ this.view.highlight = this.player.focusHighlight();
280
369
  // A frame played that changed nothing drawn is left as it shows: no frame for the browser to
281
370
  // composite, as Flash repaints nothing of a still stage. What the host changed draws anew.
282
371
  if (forced || !this.view.unchanged(this.player.stage)) {