react-native-webgpu 0.16.1 → 0.17.0

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 (46) hide show
  1. package/android/src/main/java/com/webgpu/BackingViewKind.java +38 -0
  2. package/android/src/main/java/com/webgpu/WebGPUSurfaceView.java +19 -2
  3. package/android/src/main/java/com/webgpu/WebGPUView.java +78 -76
  4. package/android/src/main/java/com/webgpu/WebGPUViewManager.java +13 -6
  5. package/cpp/jsi/NativeObject.h +42 -32
  6. package/cpp/rnwgpu/RNWebGPUManager.cpp +2 -5
  7. package/cpp/rnwgpu/api/GPUFeatures.h +1 -0
  8. package/cpp/rnwgpu/api/VideoFrame.h +2 -2
  9. package/lib/commonjs/Canvas.js +85 -39
  10. package/lib/commonjs/Canvas.js.map +1 -1
  11. package/lib/commonjs/WebGPUViewNativeComponent.js.map +1 -1
  12. package/lib/commonjs/WebGPUViewNativeComponent.web.js +3 -5
  13. package/lib/commonjs/WebGPUViewNativeComponent.web.js.map +1 -1
  14. package/lib/commonjs/mock.js +0 -1
  15. package/lib/commonjs/mock.js.map +1 -1
  16. package/lib/module/Canvas.js +85 -39
  17. package/lib/module/Canvas.js.map +1 -1
  18. package/lib/module/WebGPUViewNativeComponent.js.map +1 -1
  19. package/lib/module/WebGPUViewNativeComponent.web.js +3 -5
  20. package/lib/module/WebGPUViewNativeComponent.web.js.map +1 -1
  21. package/lib/module/mock.js +0 -1
  22. package/lib/module/mock.js.map +1 -1
  23. package/lib/typescript/lib/commonjs/Canvas.d.ts +1 -2
  24. package/lib/typescript/lib/commonjs/Canvas.d.ts.map +1 -1
  25. package/lib/typescript/lib/commonjs/WebGPUViewNativeComponent.web.d.ts.map +1 -1
  26. package/lib/typescript/lib/commonjs/mock.d.ts +1 -2
  27. package/lib/typescript/lib/commonjs/mock.d.ts.map +1 -1
  28. package/lib/typescript/lib/module/Canvas.d.ts +1 -2
  29. package/lib/typescript/lib/module/Canvas.d.ts.map +1 -1
  30. package/lib/typescript/lib/module/WebGPUViewNativeComponent.web.d.ts.map +1 -1
  31. package/lib/typescript/lib/module/mock.d.ts +1 -2
  32. package/lib/typescript/lib/module/mock.d.ts.map +1 -1
  33. package/lib/typescript/src/Canvas.d.ts +61 -29
  34. package/lib/typescript/src/Canvas.d.ts.map +1 -1
  35. package/lib/typescript/src/WebGPUViewNativeComponent.d.ts +3 -2
  36. package/lib/typescript/src/WebGPUViewNativeComponent.d.ts.map +1 -1
  37. package/lib/typescript/src/WebGPUViewNativeComponent.web.d.ts +3 -2
  38. package/lib/typescript/src/WebGPUViewNativeComponent.web.d.ts.map +1 -1
  39. package/lib/typescript/src/mock.d.ts +2 -2
  40. package/lib/typescript/src/mock.d.ts.map +1 -1
  41. package/package.json +3 -3
  42. package/src/Canvas.tsx +153 -77
  43. package/src/WebGPUViewNativeComponent.ts +6 -4
  44. package/src/WebGPUViewNativeComponent.web.ts +7 -5
  45. package/src/index.tsx +3 -3
  46. package/src/mock.ts +5 -7
@@ -1,6 +1,5 @@
1
- export function Canvas({ opaque, android, ref, ...props }: {
1
+ export function Canvas({ android, ref, ...props }: {
2
2
  [x: string]: any;
3
- opaque?: boolean | undefined;
4
3
  android: any;
5
4
  ref: any;
6
5
  }): React.CElement<import("react-native").ViewProps, View>;
@@ -1 +1 @@
1
- {"version":3,"file":"Canvas.d.ts","sourceRoot":"","sources":["../../../module/Canvas.js"],"names":[],"mappings":"AAwFO;;;;;2DAqDN;qBA3I8B,cAAc;kBAD2B,OAAO"}
1
+ {"version":3,"file":"Canvas.d.ts","sourceRoot":"","sources":["../../../module/Canvas.js"],"names":[],"mappings":"AA6IO;;;;2DA8CN;qBAzL8B,cAAc;kBAD2B,OAAO"}
@@ -1 +1 @@
1
- {"version":3,"file":"WebGPUViewNativeComponent.web.d.ts","sourceRoot":"","sources":["../../../module/WebGPUViewNativeComponent.web.js"],"names":[],"mappings":"AAIA,gHAyBC;kBA7BiB,OAAO"}
1
+ {"version":3,"file":"WebGPUViewNativeComponent.web.d.ts","sourceRoot":"","sources":["../../../module/WebGPUViewNativeComponent.web.js"],"names":[],"mappings":"AAIA,gHAuBC;kBA3BiB,OAAO"}
@@ -38,9 +38,8 @@ export namespace GPUMapMode {
38
38
  let READ: number;
39
39
  let WRITE: number;
40
40
  }
41
- export function Canvas({ opaque: _opaque, android: _android, ref, ...props }: {
41
+ export function Canvas({ android: _android, ref, ...props }: {
42
42
  [x: string]: any;
43
- opaque: any;
44
43
  android: any;
45
44
  ref: any;
46
45
  }): React.CElement<import("react-native").ViewProps, View>;
@@ -1 +1 @@
1
- {"version":3,"file":"mock.d.ts","sourceRoot":"","sources":["../../../module/mock.js"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAwEO;;;;;2DAcN;AACM,6DAA6C;AAC7C;;;EAGL;AACK,0DAAoD;AACpD;;;EAGL;AACK;;QAEe;AACf,uCAEN;AACM,mDAEN;AACM,mDAEN;AACM,2CAAqC;;IAEjC,4BAAW;;qBA7GD,cAAc;kBADjB,OAAO"}
1
+ {"version":3,"file":"mock.d.ts","sourceRoot":"","sources":["../../../module/mock.js"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAwEO;;;;2DAaN;AACM,6DAA6C;AAC7C;;;EAGL;AACK,0DAAoD;AACpD;;;EAGL;AACK;;QAEe;AACf,uCAEN;AACM,mDAEN;AACM,mDAEN;AACM,2CAAqC;;IAEjC,4BAAW;;qBA5GD,cAAc;kBADjB,OAAO"}
@@ -2,46 +2,78 @@ import React from "react";
2
2
  import type { ViewProps } from "react-native";
3
3
  import type { CanvasRef } from "./types";
4
4
  export type { CanvasRef, NativeCanvas, RNCanvasContext } from "./types";
5
- export type AndroidSurfaceType = "SurfaceView" | "TextureView" | "HardwareBufferView";
6
- /**
7
- * Android-only rendering options. They select the backing view, which is
8
- * chosen when the canvas mounts and kept: a later change is ignored, with a
9
- * warning in development. Remount the canvas, with a `key`, to change it.
10
- */
11
- export interface AndroidCanvasProps {
5
+ /** The Android view a canvas draws into, see {@link AndroidCanvasProps}. */
6
+ export type AndroidBackingView = "TextureView" | "SurfaceView" | "HardwareBufferView";
7
+ /** The options of a canvas backed by a `TextureView`, the default. */
8
+ export interface AndroidTextureViewProps {
12
9
  /**
13
- * Backing view. Defaults to `SurfaceView` when the canvas mounts opaque and
14
- * to `TextureView` otherwise; both composite correctly in React Native
15
- * stacking order without further flags. `HardwareBufferView` (Android 10+,
16
- * a plain View that draws each frame's AHardwareBuffer inline with no extra
17
- * copy) is opt-in and experimental; on older devices it uses `TextureView`.
18
- * Read once, at mount.
10
+ * A `TextureView`: a regular view, composited like any other (parent
11
+ * transforms, clipping, alpha and z-order apply), at the price of an extra
12
+ * texture copy and typically a frame of latency. The default.
19
13
  */
20
- surfaceType?: AndroidSurfaceType;
14
+ backingView?: "TextureView";
21
15
  /**
22
- * SurfaceView only: composite above every React Native view in the window,
23
- * ignoring `zIndex`. Ignored for TextureView. Defaults to false. Applied in
24
- * place on Android 11 and later; read once, at mount, before that.
16
+ * Declares that the canvas covers every pixel of its bounds, so the UI
17
+ * toolkit skips blending the view. Defaults to false. Applied in place.
25
18
  */
26
- zOrderOnTop?: boolean;
19
+ opaque?: boolean;
27
20
  }
28
- export interface CanvasProps extends ViewProps {
21
+ /** The options of a canvas backed by a `SurfaceView`. */
22
+ export interface AndroidSurfaceViewProps {
29
23
  /**
30
- * Defaults to true. Set to false to alpha-composite the canvas over the
31
- * views behind it (pair it with `alphaMode: "premultiplied"` and an alpha-0
32
- * clear color). Android and web only; on iOS `alphaMode` alone controls it.
33
- * On Android the backing view is chosen from it when the canvas mounts; a
34
- * later change updates that view in place.
24
+ * A `SurfaceView`: each frame goes to the system compositor as its own
25
+ * layer, the fastest path, with no extra copy. It is not view content:
26
+ * parent transforms, clipping, rounded corners and z-order with sibling
27
+ * views do not apply to it.
28
+ */
29
+ backingView: "SurfaceView";
30
+ /**
31
+ * Declares that the canvas covers every pixel of its bounds, so the
32
+ * compositor skips blending the layer and can show it through a hardware
33
+ * overlay. Defaults to true: a translucent `SurfaceView` blends against
34
+ * what is below the window, usually black, rather than the React Native
35
+ * views beneath it (pair it with `zOrderOnTop`). Applied in place.
35
36
  */
36
37
  opaque?: boolean;
37
38
  /**
38
- * Android-only rendering options. They select the backing view, which is
39
- * chosen when the canvas mounts and kept: a later change is ignored, with a
40
- * warning in development. Remount the canvas, with a `key`, to change it.
41
- * Ignored on iOS and web.
39
+ * Composite above every React Native view in the window, ignoring
40
+ * `zIndex`. Defaults to false. Applied in place on Android 11 and later;
41
+ * read once, at mount, before that.
42
+ */
43
+ zOrderOnTop?: boolean;
44
+ /**
45
+ * Composite above the other `SurfaceView`s below the window (video players,
46
+ * other canvases), while staying below the window itself. Defaults to
47
+ * false; `zOrderOnTop` takes precedence. Applied in place on Android 11 and
48
+ * later; read once, at mount, before that.
49
+ */
50
+ zOrderMediaOverlay?: boolean;
51
+ }
52
+ /** The options of a canvas backed by a `HardwareBufferView`. */
53
+ export interface AndroidHardwareBufferViewProps {
54
+ /**
55
+ * A plain view drawing each frame's `AHardwareBuffer` inline: composited
56
+ * like a `TextureView`, without its extra copy. Opt-in and experimental,
57
+ * on Android 10 and later; below that the canvas uses a `TextureView`,
58
+ * with a warning in development. Always composites with alpha.
59
+ */
60
+ backingView: "HardwareBufferView";
61
+ }
62
+ /**
63
+ * Android-only rendering options: the native view behind the canvas and its
64
+ * options. The view is created when the canvas mounts and kept: a change of
65
+ * `backingView` is ignored, with a warning in development; remount the canvas
66
+ * (with a `key`) to change it. `opaque` applies in place, and so do the
67
+ * z-order options on Android 11 and later. Ignored on iOS and web.
68
+ */
69
+ export type AndroidCanvasProps = AndroidTextureViewProps | AndroidSurfaceViewProps | AndroidHardwareBufferViewProps;
70
+ export interface CanvasProps extends ViewProps {
71
+ /**
72
+ * Android-only rendering options: the native view behind the canvas and its
73
+ * options, see {@link AndroidCanvasProps}. Ignored on iOS and web.
42
74
  */
43
75
  android?: AndroidCanvasProps;
44
76
  ref?: React.Ref<CanvasRef>;
45
77
  }
46
- export declare const Canvas: ({ opaque, android, ref, ...props }: CanvasProps) => React.JSX.Element;
78
+ export declare const Canvas: ({ android, ref, ...props }: CanvasProps) => React.JSX.Element;
47
79
  //# sourceMappingURL=Canvas.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"Canvas.d.ts","sourceRoot":"","sources":["../../../src/Canvas.tsx"],"names":[],"mappings":"AAAA,OAAO,KAA2D,MAAM,OAAO,CAAC;AAChF,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAG9C,OAAO,KAAK,EAAE,SAAS,EAAmB,MAAM,SAAS,CAAC;AAG1D,YAAY,EAAE,SAAS,EAAE,YAAY,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAOxE,MAAM,MAAM,kBAAkB,GAC5B,aAAa,GAAG,aAAa,GAAG,oBAAoB,CAAC;AAEvD;;;;GAIG;AACH,MAAM,WAAW,kBAAkB;IACjC;;;;;;;OAOG;IACH,WAAW,CAAC,EAAE,kBAAkB,CAAC;IACjC;;;;OAIG;IACH,WAAW,CAAC,EAAE,OAAO,CAAC;CACvB;AAED,MAAM,WAAW,WAAY,SAAQ,SAAS;IAC5C;;;;;;OAMG;IACH,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB;;;;;OAKG;IACH,OAAO,CAAC,EAAE,kBAAkB,CAAC;IAC7B,GAAG,CAAC,EAAE,KAAK,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;CAC5B;AAmFD,eAAO,MAAM,MAAM,GAAI,oCAKpB,WAAW,sBAqDb,CAAC"}
1
+ {"version":3,"file":"Canvas.d.ts","sourceRoot":"","sources":["../../../src/Canvas.tsx"],"names":[],"mappings":"AAAA,OAAO,KAA2D,MAAM,OAAO,CAAC;AAChF,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAG9C,OAAO,KAAK,EAAE,SAAS,EAAmB,MAAM,SAAS,CAAC;AAG1D,YAAY,EAAE,SAAS,EAAE,YAAY,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAOxE,4EAA4E;AAC5E,MAAM,MAAM,kBAAkB,GAC5B,aAAa,GAAG,aAAa,GAAG,oBAAoB,CAAC;AAEvD,sEAAsE;AACtE,MAAM,WAAW,uBAAuB;IACtC;;;;OAIG;IACH,WAAW,CAAC,EAAE,aAAa,CAAC;IAC5B;;;OAGG;IACH,MAAM,CAAC,EAAE,OAAO,CAAC;CAClB;AAED,yDAAyD;AACzD,MAAM,WAAW,uBAAuB;IACtC;;;;;OAKG;IACH,WAAW,EAAE,aAAa,CAAC;IAC3B;;;;;;OAMG;IACH,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB;;;;OAIG;IACH,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB;;;;;OAKG;IACH,kBAAkB,CAAC,EAAE,OAAO,CAAC;CAC9B;AAED,gEAAgE;AAChE,MAAM,WAAW,8BAA8B;IAC7C;;;;;OAKG;IACH,WAAW,EAAE,oBAAoB,CAAC;CACnC;AAED;;;;;;GAMG;AACH,MAAM,MAAM,kBAAkB,GAC1B,uBAAuB,GACvB,uBAAuB,GACvB,8BAA8B,CAAC;AAEnC,MAAM,WAAW,WAAY,SAAQ,SAAS;IAC5C;;;OAGG;IACH,OAAO,CAAC,EAAE,kBAAkB,CAAC;IAC7B,GAAG,CAAC,EAAE,KAAK,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;CAC5B;AAgID,eAAO,MAAM,MAAM,GAAI,4BAA4B,WAAW,sBAmD7D,CAAC"}
@@ -2,9 +2,10 @@ import type { Int32, WithDefault } from "react-native/Libraries/Types/CodegenTyp
2
2
  import type { ViewProps } from "react-native";
3
3
  export interface NativeProps extends ViewProps {
4
4
  contextId: Int32;
5
- opaque?: WithDefault<boolean, true>;
6
- androidSurfaceType?: WithDefault<"auto" | "SurfaceView" | "TextureView" | "HardwareBufferView", "auto">;
5
+ androidBackingView?: WithDefault<"TextureView" | "SurfaceView" | "HardwareBufferView", "TextureView">;
6
+ androidOpaque?: WithDefault<boolean, false>;
7
7
  androidZOrderOnTop?: WithDefault<boolean, false>;
8
+ androidZOrderMediaOverlay?: WithDefault<boolean, false>;
8
9
  }
9
10
  declare const _default: import("react-native").HostComponent<NativeProps>;
10
11
  export default _default;
@@ -1 +1 @@
1
- {"version":3,"file":"WebGPUViewNativeComponent.d.ts","sourceRoot":"","sources":["../../../src/WebGPUViewNativeComponent.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,KAAK,EACL,WAAW,EACZ,MAAM,2CAA2C,CAAC;AACnD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAE9C,MAAM,WAAW,WAAY,SAAQ,SAAS;IAC5C,SAAS,EAAE,KAAK,CAAC;IACjB,MAAM,CAAC,EAAE,WAAW,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;IACpC,kBAAkB,CAAC,EAAE,WAAW,CAC9B,MAAM,GAAG,aAAa,GAAG,aAAa,GAAG,oBAAoB,EAC7D,MAAM,CACP,CAAC;IACF,kBAAkB,CAAC,EAAE,WAAW,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;CAClD;;AAGD,wBAAiE"}
1
+ {"version":3,"file":"WebGPUViewNativeComponent.d.ts","sourceRoot":"","sources":["../../../src/WebGPUViewNativeComponent.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,KAAK,EACL,WAAW,EACZ,MAAM,2CAA2C,CAAC;AACnD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAE9C,MAAM,WAAW,WAAY,SAAQ,SAAS;IAC5C,SAAS,EAAE,KAAK,CAAC;IAEjB,kBAAkB,CAAC,EAAE,WAAW,CAC9B,aAAa,GAAG,aAAa,GAAG,oBAAoB,EACpD,aAAa,CACd,CAAC;IACF,aAAa,CAAC,EAAE,WAAW,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;IAC5C,kBAAkB,CAAC,EAAE,WAAW,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;IACjD,yBAAyB,CAAC,EAAE,WAAW,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;CACzD;;AAGD,wBAAiE"}
@@ -3,9 +3,10 @@ import type { Int32 } from "react-native/Libraries/Types/CodegenTypes";
3
3
  import type { ViewProps } from "react-native";
4
4
  export interface NativeProps extends ViewProps {
5
5
  contextId: Int32;
6
- opaque?: boolean;
7
- androidSurfaceType?: "auto" | "SurfaceView" | "TextureView";
6
+ androidBackingView?: "TextureView" | "SurfaceView" | "HardwareBufferView";
7
+ androidOpaque?: boolean;
8
8
  androidZOrderOnTop?: boolean;
9
+ androidZOrderMediaOverlay?: boolean;
9
10
  }
10
11
  export default function WebGPUViewNativeComponent(props: NativeProps): React.JSX.Element;
11
12
  //# sourceMappingURL=WebGPUViewNativeComponent.web.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"WebGPUViewNativeComponent.web.d.ts","sourceRoot":"","sources":["../../../src/WebGPUViewNativeComponent.web.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,2CAA2C,CAAC;AACvE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAI9C,MAAM,WAAW,WAAY,SAAQ,SAAS;IAC5C,SAAS,EAAE,KAAK,CAAC;IACjB,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,kBAAkB,CAAC,EAAE,MAAM,GAAG,aAAa,GAAG,aAAa,CAAC;IAC5D,kBAAkB,CAAC,EAAE,OAAO,CAAC;CAC9B;AAGD,MAAM,CAAC,OAAO,UAAU,yBAAyB,CAC/C,KAAK,EAAE,WAAW,GACjB,KAAK,CAAC,GAAG,CAAC,OAAO,CAuBnB"}
1
+ {"version":3,"file":"WebGPUViewNativeComponent.web.d.ts","sourceRoot":"","sources":["../../../src/WebGPUViewNativeComponent.web.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,2CAA2C,CAAC;AACvE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAI9C,MAAM,WAAW,WAAY,SAAQ,SAAS;IAC5C,SAAS,EAAE,KAAK,CAAC;IAEjB,kBAAkB,CAAC,EAAE,aAAa,GAAG,aAAa,GAAG,oBAAoB,CAAC;IAC1E,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,kBAAkB,CAAC,EAAE,OAAO,CAAC;IAC7B,yBAAyB,CAAC,EAAE,OAAO,CAAC;CACrC;AAGD,MAAM,CAAC,OAAO,UAAU,yBAAyB,CAC/C,KAAK,EAAE,WAAW,GACjB,KAAK,CAAC,GAAG,CAAC,OAAO,CAuBnB"}
@@ -8,8 +8,8 @@ export declare const GPUTextureUsage: GPUTextureUsage;
8
8
  export declare const GPUShaderStage: GPUShaderStage;
9
9
  export declare const GPUColorWrite: GPUColorWrite;
10
10
  export declare const GPUMapMode: GPUMapMode;
11
- export type { AndroidCanvasProps, AndroidSurfaceType, CanvasProps, CanvasRef, NativeCanvas, RNCanvasContext, } from "./Canvas";
12
- export declare const Canvas: ({ opaque: _opaque, android: _android, ref, ...props }: CanvasProps) => React.CElement<import("react-native").ViewProps, View>;
11
+ export type { AndroidBackingView, AndroidCanvasProps, AndroidHardwareBufferViewProps, AndroidSurfaceViewProps, AndroidTextureViewProps, CanvasProps, CanvasRef, NativeCanvas, RNCanvasContext, } from "./Canvas";
12
+ export declare const Canvas: ({ android: _android, ref, ...props }: CanvasProps) => React.CElement<import("react-native").ViewProps, View>;
13
13
  export declare const useCanvasRef: () => React.MutableRefObject<null>;
14
14
  export declare const useSurface: () => {
15
15
  ref: React.MutableRefObject<null>;
@@ -1 +1 @@
1
- {"version":3,"file":"mock.d.ts","sourceRoot":"","sources":["../../../src/mock.ts"],"names":[],"mappings":"AACA,OA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lib/commonjs/index",
6
6
  "module": "lib/module/index",
@@ -24,7 +24,7 @@
24
24
  "app.plugin.js",
25
25
  "plugin/build/**"
26
26
  ],
27
- "dawn": "chrome-m154a",
27
+ "dawn": "chrome-m157",
28
28
  "androidMinSdkVersion": 26,
29
29
  "scripts": {
30
30
  "test": "NODE_OPTIONS='--experimental-require-module' jest -i",
@@ -111,7 +111,7 @@
111
111
  "yargs": "^17.7.2"
112
112
  },
113
113
  "dependencies": {
114
- "react-native-webgpu-dawn": "154.3.0"
114
+ "react-native-webgpu-dawn": "157.0.0"
115
115
  },
116
116
  "peerDependencies": {
117
117
  "react": "*",
package/src/Canvas.tsx CHANGED
@@ -12,111 +12,194 @@ function generateContextId() {
12
12
  return CONTEXT_COUNTER++;
13
13
  }
14
14
 
15
- export type AndroidSurfaceType =
16
- "SurfaceView" | "TextureView" | "HardwareBufferView";
15
+ /** The Android view a canvas draws into, see {@link AndroidCanvasProps}. */
16
+ export type AndroidBackingView =
17
+ "TextureView" | "SurfaceView" | "HardwareBufferView";
17
18
 
18
- /**
19
- * Android-only rendering options. They select the backing view, which is
20
- * chosen when the canvas mounts and kept: a later change is ignored, with a
21
- * warning in development. Remount the canvas, with a `key`, to change it.
22
- */
23
- export interface AndroidCanvasProps {
19
+ /** The options of a canvas backed by a `TextureView`, the default. */
20
+ export interface AndroidTextureViewProps {
24
21
  /**
25
- * Backing view. Defaults to `SurfaceView` when the canvas mounts opaque and
26
- * to `TextureView` otherwise; both composite correctly in React Native
27
- * stacking order without further flags. `HardwareBufferView` (Android 10+,
28
- * a plain View that draws each frame's AHardwareBuffer inline with no extra
29
- * copy) is opt-in and experimental; on older devices it uses `TextureView`.
30
- * Read once, at mount.
22
+ * A `TextureView`: a regular view, composited like any other (parent
23
+ * transforms, clipping, alpha and z-order apply), at the price of an extra
24
+ * texture copy and typically a frame of latency. The default.
31
25
  */
32
- surfaceType?: AndroidSurfaceType;
26
+ backingView?: "TextureView";
33
27
  /**
34
- * SurfaceView only: composite above every React Native view in the window,
35
- * ignoring `zIndex`. Ignored for TextureView. Defaults to false. Applied in
36
- * place on Android 11 and later; read once, at mount, before that.
28
+ * Declares that the canvas covers every pixel of its bounds, so the UI
29
+ * toolkit skips blending the view. Defaults to false. Applied in place.
37
30
  */
38
- zOrderOnTop?: boolean;
31
+ opaque?: boolean;
39
32
  }
40
33
 
41
- export interface CanvasProps extends ViewProps {
34
+ /** The options of a canvas backed by a `SurfaceView`. */
35
+ export interface AndroidSurfaceViewProps {
42
36
  /**
43
- * Defaults to true. Set to false to alpha-composite the canvas over the
44
- * views behind it (pair it with `alphaMode: "premultiplied"` and an alpha-0
45
- * clear color). Android and web only; on iOS `alphaMode` alone controls it.
46
- * On Android the backing view is chosen from it when the canvas mounts; a
47
- * later change updates that view in place.
37
+ * A `SurfaceView`: each frame goes to the system compositor as its own
38
+ * layer, the fastest path, with no extra copy. It is not view content:
39
+ * parent transforms, clipping, rounded corners and z-order with sibling
40
+ * views do not apply to it.
41
+ */
42
+ backingView: "SurfaceView";
43
+ /**
44
+ * Declares that the canvas covers every pixel of its bounds, so the
45
+ * compositor skips blending the layer and can show it through a hardware
46
+ * overlay. Defaults to true: a translucent `SurfaceView` blends against
47
+ * what is below the window, usually black, rather than the React Native
48
+ * views beneath it (pair it with `zOrderOnTop`). Applied in place.
48
49
  */
49
50
  opaque?: boolean;
50
51
  /**
51
- * Android-only rendering options. They select the backing view, which is
52
- * chosen when the canvas mounts and kept: a later change is ignored, with a
53
- * warning in development. Remount the canvas, with a `key`, to change it.
54
- * Ignored on iOS and web.
52
+ * Composite above every React Native view in the window, ignoring
53
+ * `zIndex`. Defaults to false. Applied in place on Android 11 and later;
54
+ * read once, at mount, before that.
55
+ */
56
+ zOrderOnTop?: boolean;
57
+ /**
58
+ * Composite above the other `SurfaceView`s below the window (video players,
59
+ * other canvases), while staying below the window itself. Defaults to
60
+ * false; `zOrderOnTop` takes precedence. Applied in place on Android 11 and
61
+ * later; read once, at mount, before that.
62
+ */
63
+ zOrderMediaOverlay?: boolean;
64
+ }
65
+
66
+ /** The options of a canvas backed by a `HardwareBufferView`. */
67
+ export interface AndroidHardwareBufferViewProps {
68
+ /**
69
+ * A plain view drawing each frame's `AHardwareBuffer` inline: composited
70
+ * like a `TextureView`, without its extra copy. Opt-in and experimental,
71
+ * on Android 10 and later; below that the canvas uses a `TextureView`,
72
+ * with a warning in development. Always composites with alpha.
73
+ */
74
+ backingView: "HardwareBufferView";
75
+ }
76
+
77
+ /**
78
+ * Android-only rendering options: the native view behind the canvas and its
79
+ * options. The view is created when the canvas mounts and kept: a change of
80
+ * `backingView` is ignored, with a warning in development; remount the canvas
81
+ * (with a `key`) to change it. `opaque` applies in place, and so do the
82
+ * z-order options on Android 11 and later. Ignored on iOS and web.
83
+ */
84
+ export type AndroidCanvasProps =
85
+ | AndroidTextureViewProps
86
+ | AndroidSurfaceViewProps
87
+ | AndroidHardwareBufferViewProps;
88
+
89
+ export interface CanvasProps extends ViewProps {
90
+ /**
91
+ * Android-only rendering options: the native view behind the canvas and its
92
+ * options, see {@link AndroidCanvasProps}. Ignored on iOS and web.
55
93
  */
56
94
  android?: AndroidCanvasProps;
57
95
  ref?: React.Ref<CanvasRef>;
58
96
  }
59
97
 
98
+ // The union read as one bag of options; which of them apply to the view is
99
+ // decided below, as it is on the native side.
100
+ type AndroidOptions = Partial<{
101
+ backingView: AndroidBackingView;
102
+ opaque: boolean;
103
+ zOrderOnTop: boolean;
104
+ zOrderMediaOverlay: boolean;
105
+ }>;
106
+
107
+ const options = (android?: AndroidCanvasProps): AndroidOptions =>
108
+ (android ?? {}) as AndroidOptions;
109
+
60
110
  // Anything else reaching the native component would hit the generated
61
111
  // string-enum parser, which aborts on unknown values.
62
- const resolveSurfaceType = (
63
- surfaceType: AndroidSurfaceType | undefined,
64
- ): "auto" | AndroidSurfaceType =>
65
- surfaceType === "SurfaceView" ||
66
- surfaceType === "TextureView" ||
67
- surfaceType === "HardwareBufferView"
68
- ? surfaceType
69
- : "auto";
70
-
71
- // The props the Android backing view is chosen from when the canvas mounts.
72
- interface BackingViewProps {
73
- opaque: boolean;
74
- android?: AndroidCanvasProps;
75
- }
112
+ const resolveBackingView = (
113
+ android?: AndroidCanvasProps,
114
+ ): AndroidBackingView => {
115
+ const { backingView } = options(android);
116
+ return backingView === "SurfaceView" || backingView === "HardwareBufferView"
117
+ ? backingView
118
+ : "TextureView";
119
+ };
76
120
 
77
- // The backing view the props select, see WebGPUView.resolveKind().
78
- const resolveKind = ({ opaque, android }: BackingViewProps) => {
79
- const surfaceType = resolveSurfaceType(android?.surfaceType);
80
- if (surfaceType !== "auto") {
81
- return surfaceType;
121
+ // Whether the canvas composites as opaque, see BackingViewKind.resolveOpaque():
122
+ // a SurfaceView is opaque unless asked otherwise, a TextureView is translucent
123
+ // unless asked otherwise, and a HardwareBufferView always composites with
124
+ // alpha.
125
+ const resolveOpaque = (android?: AndroidCanvasProps): boolean => {
126
+ const { opaque } = options(android);
127
+ switch (resolveBackingView(android)) {
128
+ case "SurfaceView":
129
+ return opaque !== false;
130
+ case "TextureView":
131
+ return opaque === true;
132
+ case "HardwareBufferView":
133
+ return false;
82
134
  }
83
- return opaque ? "SurfaceView" : "TextureView";
84
135
  };
85
136
 
86
- const warnIgnored = (prop: string) =>
137
+ // The native props the `android` prop resolves to.
138
+ const androidNativeProps = (android?: AndroidCanvasProps) => {
139
+ const backingView = resolveBackingView(android);
140
+ const { zOrderOnTop, zOrderMediaOverlay } = options(android);
141
+ const surfaceView = backingView === "SurfaceView";
142
+ return {
143
+ androidBackingView: backingView,
144
+ androidOpaque: resolveOpaque(android),
145
+ androidZOrderOnTop: surfaceView && !!zOrderOnTop,
146
+ androidZOrderMediaOverlay: surfaceView && !!zOrderMediaOverlay,
147
+ };
148
+ };
149
+
150
+ const warnIgnoredChange = (prop: string) =>
87
151
  console.warn(
88
152
  `Ignoring a change of ${prop} on a mounted canvas: the backing view is ` +
89
153
  "chosen when the canvas mounts. Remount the canvas (give it a new key) " +
90
154
  "to change it.",
91
155
  );
92
156
 
93
- // Warns, in development on Android, about a change of these props that the
94
- // native view ignores: the backing view is chosen from them when the canvas
95
- // mounts (see WebGPUView.java, whose setters these rules mirror). The native
96
- // side only says so in logcat, which is not where a JS developer looks.
97
- const useBackingViewWarning = (props: BackingViewProps) => {
98
- const mount = useRef(props);
99
- const prev = useRef(props);
157
+ // Warns, in development on Android, about an option a mounting canvas asks
158
+ // for that the native view cannot honour, and about a change of these props
159
+ // that the native view ignores: the backing view is created from them when
160
+ // the canvas mounts (see WebGPUView.java, whose setters these rules mirror).
161
+ // The native side only says so in logcat, which is not where a JS developer
162
+ // looks.
163
+ const useBackingViewWarning = (android?: AndroidCanvasProps) => {
164
+ const mount = useRef(android);
165
+ const prev = useRef(android);
166
+ useEffect(() => {
167
+ if (
168
+ __DEV__ &&
169
+ Platform.OS === "android" &&
170
+ resolveBackingView(mount.current) === "HardwareBufferView" &&
171
+ Number(Platform.Version) < 29
172
+ ) {
173
+ console.warn(
174
+ "android.backingView: HardwareBufferView needs Android 10, the " +
175
+ "canvas uses a TextureView.",
176
+ );
177
+ }
178
+ }, []);
100
179
  useEffect(() => {
101
180
  if (__DEV__ && Platform.OS === "android") {
102
181
  const { current: before } = prev;
103
- if (
104
- resolveSurfaceType(before.android?.surfaceType) !==
105
- resolveSurfaceType(props.android?.surfaceType)
106
- ) {
107
- warnIgnored("android.surfaceType");
182
+ if (resolveBackingView(before) !== resolveBackingView(android)) {
183
+ warnIgnoredChange("android.backingView");
108
184
  }
109
185
  // Only a SurfaceView has a z-order of its own, which Android 11 and
110
186
  // later changes in place.
187
+ const zOrderAtMount =
188
+ resolveBackingView(mount.current) === "SurfaceView" &&
189
+ Number(Platform.Version) < 30;
190
+ const was = options(before);
191
+ const is = options(android);
192
+ if (zOrderAtMount && !!was.zOrderOnTop !== !!is.zOrderOnTop) {
193
+ warnIgnoredChange("android.zOrderOnTop");
194
+ }
111
195
  if (
112
- !!before.android?.zOrderOnTop !== !!props.android?.zOrderOnTop &&
113
- resolveKind(mount.current) === "SurfaceView" &&
114
- Number(Platform.Version) < 30
196
+ zOrderAtMount &&
197
+ !!was.zOrderMediaOverlay !== !!is.zOrderMediaOverlay
115
198
  ) {
116
- warnIgnored("android.zOrderOnTop");
199
+ warnIgnoredChange("android.zOrderMediaOverlay");
117
200
  }
118
201
  }
119
- prev.current = props;
202
+ prev.current = android;
120
203
  });
121
204
  };
122
205
 
@@ -138,15 +221,10 @@ const measureLayout = (view: View) => {
138
221
  return size;
139
222
  };
140
223
 
141
- export const Canvas = ({
142
- opaque = true,
143
- android,
144
- ref,
145
- ...props
146
- }: CanvasProps) => {
224
+ export const Canvas = ({ android, ref, ...props }: CanvasProps) => {
147
225
  const viewRef = useRef<View>(null);
148
226
  const [contextId, _] = useState(() => generateContextId());
149
- useBackingViewWarning({ opaque, android });
227
+ useBackingViewWarning(android);
150
228
  // Retire the native registry entry for this contextId on unmount. When a
151
229
  // native surface is still attached, this is a no-op and the native view's
152
230
  // own teardown retires the entry instead — which keeps StrictMode's
@@ -190,9 +268,7 @@ export const Canvas = ({
190
268
  <WebGPUNativeView
191
269
  style={{ flex: 1 }}
192
270
  contextId={contextId}
193
- opaque={opaque}
194
- androidSurfaceType={resolveSurfaceType(android?.surfaceType)}
195
- androidZOrderOnTop={!!android?.zOrderOnTop}
271
+ {...androidNativeProps(android)}
196
272
  />
197
273
  </View>
198
274
  );
@@ -7,12 +7,14 @@ import type { ViewProps } from "react-native";
7
7
 
8
8
  export interface NativeProps extends ViewProps {
9
9
  contextId: Int32;
10
- opaque?: WithDefault<boolean, true>;
11
- androidSurfaceType?: WithDefault<
12
- "auto" | "SurfaceView" | "TextureView" | "HardwareBufferView",
13
- "auto"
10
+ // The `android` prop, resolved (see Canvas.tsx)
11
+ androidBackingView?: WithDefault<
12
+ "TextureView" | "SurfaceView" | "HardwareBufferView",
13
+ "TextureView"
14
14
  >;
15
+ androidOpaque?: WithDefault<boolean, false>;
15
16
  androidZOrderOnTop?: WithDefault<boolean, false>;
17
+ androidZOrderMediaOverlay?: WithDefault<boolean, false>;
16
18
  }
17
19
 
18
20
  // eslint-disable-next-line import/no-default-export
@@ -7,9 +7,11 @@ import { contextIdToId } from "./utils";
7
7
 
8
8
  export interface NativeProps extends ViewProps {
9
9
  contextId: Int32;
10
- opaque?: boolean;
11
- androidSurfaceType?: "auto" | "SurfaceView" | "TextureView";
10
+ // The `android` prop, resolved: Android-only, never reaches the DOM
11
+ androidBackingView?: "TextureView" | "SurfaceView" | "HardwareBufferView";
12
+ androidOpaque?: boolean;
12
13
  androidZOrderOnTop?: boolean;
14
+ androidZOrderMediaOverlay?: boolean;
13
15
  }
14
16
 
15
17
  // eslint-disable-next-line import/no-default-export
@@ -19,9 +21,10 @@ export default function WebGPUViewNativeComponent(
19
21
  const {
20
22
  contextId,
21
23
  style,
22
- opaque = true,
23
- androidSurfaceType: _androidSurfaceType,
24
+ androidBackingView: _androidBackingView,
25
+ androidOpaque: _androidOpaque,
24
26
  androidZOrderOnTop: _androidZOrderOnTop,
27
+ androidZOrderMediaOverlay: _androidZOrderMediaOverlay,
25
28
  ...rest
26
29
  } = props;
27
30
 
@@ -34,7 +37,6 @@ export default function WebGPUViewNativeComponent(
34
37
  style: {
35
38
  ...styles.view,
36
39
  ...styles.flex1,
37
- ...(opaque ? { backgroundColor: "white" } : {}),
38
40
  ...(typeof style === "object" ? style : {}),
39
41
  },
40
42
  });
package/src/index.tsx CHANGED
@@ -159,9 +159,9 @@ declare global {
159
159
  // What is captured is what the platform renders for the view hierarchy
160
160
  // (iOS: UIView.drawViewHierarchyInRect; Android API 29+: HardwareRenderer
161
161
  // over the views' display lists, older: View.draw into a software canvas).
162
- // On Android, SurfaceView content (a WebGPU Canvas with the default
163
- // "SurfaceView" surfaceType, video players) is not part of the hierarchy and
164
- // comes out blank; use `android={{ surfaceType: "TextureView" }}` for a
162
+ // On Android, SurfaceView content (a WebGPU Canvas with
163
+ // `android={{ backingView: "SurfaceView" }}`, video players) is not part of
164
+ // the hierarchy and comes out blank; keep the default TextureView for a
165
165
  // canvas that must be captured.
166
166
  interface GPUQueue {
167
167
  drawElementImageToTexture(
package/src/mock.ts CHANGED
@@ -82,8 +82,11 @@ const NOT_AVAILABLE_UNDER_JEST =
82
82
  "is not available under Jest - react-native-webgpu has no native implementation in tests (see react-native-webgpu/jestSetup.js)";
83
83
 
84
84
  export type {
85
+ AndroidBackingView,
85
86
  AndroidCanvasProps,
86
- AndroidSurfaceType,
87
+ AndroidHardwareBufferViewProps,
88
+ AndroidSurfaceViewProps,
89
+ AndroidTextureViewProps,
87
90
  CanvasProps,
88
91
  CanvasRef,
89
92
  NativeCanvas,
@@ -91,12 +94,7 @@ export type {
91
94
  } from "./Canvas";
92
95
 
93
96
  // Strip the same props the real Canvas keeps off its outer View.
94
- export const Canvas = ({
95
- opaque: _opaque,
96
- android: _android,
97
- ref,
98
- ...props
99
- }: CanvasProps) => {
97
+ export const Canvas = ({ android: _android, ref, ...props }: CanvasProps) => {
100
98
  React.useImperativeHandle(ref, () => ({
101
99
  getContextId: () => -1,
102
100
  getContext: (_contextName: "webgpu"): RNCanvasContext | null => null,