@rive-app/webgl2-threads 2.48.0 → 2.49.1

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/rive.wasm CHANGED
Binary file
@@ -46,6 +46,9 @@ export interface RiveCanvas {
46
46
  RenderPaintStyle: typeof RenderPaintStyle;
47
47
  StrokeCap: typeof StrokeCap;
48
48
  StrokeJoin: typeof StrokeJoin;
49
+ StrokePosition: typeof StrokePosition;
50
+ ImageFilter: typeof ImageFilter;
51
+ ImageWrap: typeof ImageWrap;
49
52
  decodeAudio: DecodeAudio;
50
53
  decodeImage: DecodeImage;
51
54
  decodeFont: DecodeFont;
@@ -73,6 +76,23 @@ export interface RiveCanvas {
73
76
  */
74
77
  makeDeferredSession?(): DeferredSession | undefined;
75
78
 
79
+ /**
80
+ * @experimental Lets deferred renderers replay on one worker shared by the
81
+ * page. Only in the threaded webgl2 build; call it before loading files, so
82
+ * their images reach the worker too.
83
+ *
84
+ * @returns false where the browser cannot draw WebGL2 on a transferred canvas
85
+ */
86
+ enableReplayWorker?(): boolean;
87
+
88
+ /**
89
+ * @internal Settles once the replay worker's device caps reach the page, so
90
+ * scripts read truthful features before any canvas reaches the worker.
91
+ *
92
+ * @returns undefined when nothing replays on the worker
93
+ */
94
+ awaitReplayCaps?(): Promise<void> | undefined;
95
+
76
96
  /**
77
97
  * Loads a Rive file for the runtime and returns a Rive-specific File class
78
98
  *
@@ -203,6 +223,18 @@ export interface RendererOptions {
203
223
  * converted to clockwise on a best-effort basis
204
224
  */
205
225
  inkbleed?: boolean;
226
+ /**
227
+ * @experimental (webgl2-threads only) Hands the canvas to the replay worker,
228
+ * once `enableReplayWorker()` has succeeded. The renderer then replays only
229
+ * deferred sessions. A canvas handed over before keeps going to the worker.
230
+ */
231
+ replayWorker?: boolean;
232
+ /**
233
+ * @experimental (webgl2-threads only) Called when the replay worker
234
+ * restores the renderer's lost context, so an idle instance still draws
235
+ * and notices it.
236
+ */
237
+ onContextRestored?: () => void;
206
238
  }
207
239
 
208
240
  /**
@@ -277,6 +309,22 @@ export declare class RendererWrapper {
277
309
  * @returns false if inkbleed was requested but the canvas context does not support it
278
310
  */
279
311
  setInkbleed?(enabled: boolean): boolean;
312
+ /**
313
+ * @experimental Present on renderers whose canvas is on the replay worker,
314
+ * which can only draw deferred sessions.
315
+ */
316
+ replaysOnWorker?(): boolean;
317
+ /**
318
+ * @experimental False while the replay worker has yet to take the canvas, or
319
+ * is as many frames behind as it queues. Skip the frame rather than record it.
320
+ */
321
+ acceptsFrame?(): boolean;
322
+ /**
323
+ * @experimental True once the replay worker's context was lost and restored.
324
+ * What it held is gone, so the renderer and the file's session must be
325
+ * recreated.
326
+ */
327
+ contextRestored?(): boolean;
280
328
  }
281
329
 
282
330
  export declare class RenderPathWrapper {
@@ -304,11 +352,15 @@ export declare class RenderPathWrapper {
304
352
  close(): void;
305
353
  }
306
354
 
355
+ export declare class RenderImageWrapper {
356
+ }
357
+
307
358
  export declare class RenderPaintWrapper {
308
359
  color(value: number): void;
309
360
  thickness(value: number): void;
310
361
  join(value: StrokeJoin): void;
311
362
  cap(value: StrokeCap): void;
363
+ strokePosition(value: StrokePosition): void;
312
364
  blendMode(value: BlendMode): void;
313
365
  style(value: RenderPaintStyle): void;
314
366
  linearGradient(sx: number, sy: number, ex: number, ey: number): void;
@@ -323,6 +375,19 @@ export declare class RenderPaintWrapper {
323
375
  tx: number,
324
376
  ty: number,
325
377
  ): void;
378
+
379
+ modulatedImage(
380
+ image: RenderImage,
381
+ filter: ImageFilter,
382
+ wrapX: ImageWrap,
383
+ wrapY: ImageWrap,
384
+ xx: number,
385
+ xy: number,
386
+ yx: number,
387
+ yy: number,
388
+ tx: number,
389
+ ty: number,
390
+ ): void;
326
391
  }
327
392
 
328
393
  /**
@@ -352,6 +417,8 @@ export declare class RenderPath extends RenderPathWrapper { }
352
417
 
353
418
  export declare class RenderPaint extends RenderPaintWrapper { }
354
419
 
420
+ export declare class RenderImage extends RenderImageWrapper { }
421
+
355
422
  /////////////////////
356
423
  // CANVAS RENDERER //
357
424
  /////////////////////
@@ -1212,7 +1279,7 @@ export declare class StateMachineInstance {
1212
1279
 
1213
1280
  /**
1214
1281
  * The selected text of the focused element, or an empty string when nothing with a
1215
- * selection is focused. Used to fill the clipboard on copy/cut. An obscured field
1282
+ * selection is focused. Used to fill the clipboard on copy/cut. An obscured field
1216
1283
  * (i.e. a password) reports empty string.
1217
1284
  */
1218
1285
  selectedText(): string;
@@ -1541,6 +1608,23 @@ export enum BlendMode {
1541
1608
  luminosity = 28,
1542
1609
  }
1543
1610
 
1611
+ export enum ImageFilter {
1612
+ bilinear,
1613
+ nearest,
1614
+ }
1615
+
1616
+ export enum ImageWrap {
1617
+ clamp,
1618
+ repeat,
1619
+ mirror,
1620
+ }
1621
+
1622
+ export enum StrokePosition {
1623
+ inside,
1624
+ center,
1625
+ outside,
1626
+ }
1627
+
1544
1628
  ///////////
1545
1629
  // UTILS //
1546
1630
  ///////////
Binary file
package/rive_threads.wasm CHANGED
Binary file
@@ -10,6 +10,10 @@ export declare class RuntimeLoader {
10
10
  private static wasmBinary;
11
11
  private static wasmThreadsURL;
12
12
  private static triedThreads;
13
+ private static parallelParts;
14
+ private static replayWorker;
15
+ private static replayCapsArrived;
16
+ private static readonly replayCapsTimeoutMs;
13
17
  private static errorCallbackQueue;
14
18
  private constructor();
15
19
  /**
@@ -23,6 +27,12 @@ export declare class RuntimeLoader {
23
27
  private static loadUnthreaded;
24
28
  static getInstance(callback: RuntimeCallback, onError?: (error: Error) => void): void;
25
29
  static awaitInstance(): Promise<rc.RiveCanvas>;
30
+ /**
31
+ * @internal Resolves once the replay worker's device caps reach the page,
32
+ * so scripts init against them. Null when there is nothing left to wait
33
+ * for, which keeps every later instance's load synchronous.
34
+ */
35
+ static awaitReplayCaps(): Promise<void> | null;
26
36
  static setWasmUrl(url: string): void;
27
37
  static getWasmUrl(): string;
28
38
  /**
@@ -43,6 +53,29 @@ export declare class RuntimeLoader {
43
53
  */
44
54
  static setWasmThreadsUrl(url: string | null): void;
45
55
  static getWasmThreadsUrl(): string | null;
56
+ /**
57
+ * Sets how many parts a script's parallel call gets on a page that runs
58
+ * the threaded build, the page's thread and one worker thread for each
59
+ * other part. 1 turns parallel calls off, and null leaves the runtime's
60
+ * default of one part per core, up to 8. Set it before the first file
61
+ * loads.
62
+ */
63
+ static setParallelParts(parts: number | null): void;
64
+ static getParallelParts(): number | null;
65
+ private static applyParallelParts;
66
+ /**
67
+ * @experimental When the threaded build loads, instances with
68
+ * `enableGPUCanvas` hand their canvas to one worker that replays every
69
+ * instance's frames while the page records the next ones. Pass `false`
70
+ * before the runtime loads to keep replay on the page's thread; a single
71
+ * instance can opt out with `useReplayWorker: false`. Pages where the
72
+ * browser cannot draw WebGL2 on a transferred canvas stay on the page's
73
+ * thread regardless.
74
+ *
75
+ * True by default.
76
+ */
77
+ static setReplayWorker(enabled: boolean): void;
78
+ static getReplayWorker(): boolean;
46
79
  static setWasmBinary(value: ArrayBuffer | null): void;
47
80
  static getWasmBinary(): ArrayBuffer | null;
48
81
  }