react-native-webgpu 0.15.2 → 0.16.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.
Files changed (73) hide show
  1. package/android/CMakeLists.txt +5 -0
  2. package/android/build.gradle +11 -1
  3. package/android/cpp/cpp-adapter.cpp +109 -11
  4. package/android/src/main/java/com/webgpu/SurfaceFrameRateVote.java +97 -85
  5. package/android/src/main/java/com/webgpu/WebGPUView.java +97 -42
  6. package/apple/ApplePlatformContext.h +1 -0
  7. package/cpp/jsi/JSICache.cpp +2 -0
  8. package/cpp/jsi/NativeObject.h +81 -17
  9. package/cpp/rnwgpu/RNWebGPUManager.cpp +51 -41
  10. package/cpp/rnwgpu/RNWebGPUManager.h +10 -0
  11. package/cpp/rnwgpu/SurfaceRegistry.h +4 -4
  12. package/cpp/rnwgpu/api/GPUDevice.cpp +96 -0
  13. package/cpp/rnwgpu/api/GPUDevice.h +22 -0
  14. package/cpp/rnwgpu/api/GPUError.h +1 -0
  15. package/cpp/rnwgpu/api/GPUExtent2D.h +56 -0
  16. package/cpp/rnwgpu/api/GPUExternalTexture.cpp +32 -408
  17. package/cpp/rnwgpu/api/GPUExternalTexture.h +12 -37
  18. package/cpp/rnwgpu/api/GPUInternalError.h +1 -0
  19. package/cpp/rnwgpu/api/GPUNativeBufferExternalTexture.h +60 -0
  20. package/cpp/rnwgpu/api/GPUNativeBufferTexture.h +52 -0
  21. package/cpp/rnwgpu/api/GPUNativeBufferWrapper.cpp +144 -0
  22. package/cpp/rnwgpu/api/GPUNativeBufferWrapper.h +143 -0
  23. package/cpp/rnwgpu/api/GPUOutOfMemoryError.h +1 -0
  24. package/cpp/rnwgpu/api/GPUQueue.h +1 -0
  25. package/cpp/rnwgpu/api/GPUSharedFence.h +1 -0
  26. package/cpp/rnwgpu/api/GPUSharedTextureMemory.cpp +12 -44
  27. package/cpp/rnwgpu/api/GPUSharedTextureMemory.h +1 -0
  28. package/cpp/rnwgpu/api/GPUUncapturedErrorEvent.h +1 -0
  29. package/cpp/rnwgpu/api/GPUValidationError.h +1 -0
  30. package/cpp/rnwgpu/api/NativeFrameImport.cpp +638 -0
  31. package/cpp/rnwgpu/api/NativeFrameImport.h +86 -0
  32. package/cpp/rnwgpu/api/VideoFrame.h +21 -7
  33. package/cpp/rnwgpu/api/descriptors/GPUExternalTextureDescriptor.h +153 -1
  34. package/cpp/rnwgpu/api/descriptors/GPUNativeBufferTextureDescriptor.h +55 -0
  35. package/cpp/rnwgpu/async/RuntimeContext.cpp +1 -0
  36. package/lib/commonjs/Canvas.js +51 -0
  37. package/lib/commonjs/Canvas.js.map +1 -1
  38. package/lib/commonjs/external/reanimated/registerWebGPUForReanimated.js.map +1 -1
  39. package/lib/commonjs/index.js.map +1 -1
  40. package/lib/commonjs/install.js +26 -7
  41. package/lib/commonjs/install.js.map +1 -1
  42. package/lib/module/Canvas.js +51 -0
  43. package/lib/module/Canvas.js.map +1 -1
  44. package/lib/module/external/reanimated/registerWebGPUForReanimated.js.map +1 -1
  45. package/lib/module/index.js.map +1 -1
  46. package/lib/module/install.js +26 -7
  47. package/lib/module/install.js.map +1 -1
  48. package/lib/typescript/lib/commonjs/Canvas.d.ts.map +1 -1
  49. package/lib/typescript/lib/commonjs/install.d.ts +10 -7
  50. package/lib/typescript/lib/commonjs/install.d.ts.map +1 -1
  51. package/lib/typescript/lib/module/Canvas.d.ts.map +1 -1
  52. package/lib/typescript/lib/module/install.d.ts.map +1 -1
  53. package/lib/typescript/src/Canvas.d.ts +20 -35
  54. package/lib/typescript/src/Canvas.d.ts.map +1 -1
  55. package/lib/typescript/src/external/reanimated/registerWebGPUForReanimated.d.ts +1 -0
  56. package/lib/typescript/src/external/reanimated/registerWebGPUForReanimated.d.ts.map +1 -1
  57. package/lib/typescript/src/index.d.ts +4 -2
  58. package/lib/typescript/src/index.d.ts.map +1 -1
  59. package/lib/typescript/src/install.d.ts +10 -7
  60. package/lib/typescript/src/install.d.ts.map +1 -1
  61. package/lib/typescript/src/types.d.ts +34 -1
  62. package/lib/typescript/src/types.d.ts.map +1 -1
  63. package/package.json +6 -5
  64. package/plugin/build/index.js +2 -1
  65. package/plugin/build/setMinSdkVersion.d.ts +9 -0
  66. package/plugin/build/setMinSdkVersion.js +25 -0
  67. package/plugin/build/withMinSdkVersion.d.ts +11 -0
  68. package/plugin/build/withMinSdkVersion.js +20 -0
  69. package/src/Canvas.tsx +74 -40
  70. package/src/external/reanimated/registerWebGPUForReanimated.ts +4 -0
  71. package/src/index.tsx +24 -0
  72. package/src/install.ts +26 -7
  73. package/src/types.ts +98 -1
@@ -0,0 +1,86 @@
1
+ #pragma once
2
+
3
+ #include <cstdint>
4
+ #include <string>
5
+ #include <vector>
6
+
7
+ #include "webgpu/webgpu_cpp.h"
8
+
9
+ #include "PlatformContext.h"
10
+
11
+ namespace rnwgpu {
12
+
13
+ struct GPUExternalTextureDescriptor;
14
+
15
+ // The steps of importing a native frame (an IOSurface on Apple platforms, an
16
+ // AHardwareBuffer on Android) into Dawn, shared by importExternalTexture(),
17
+ // importSharedTextureMemory() and the native buffer wrappers of
18
+ // createNativeBufferTexture() / createNativeBufferExternalTexture(): the
19
+ // import, the access window around each use, and the external texture that
20
+ // samples a YUV frame as RGB. The same steps as Dawn's own Android layer
21
+ // (tools/android/webgpu, GPUImportedAHB.cpp), so a JS caller can follow its
22
+ // import-once, begin/end-per-frame recipe. Each step throws with the cause,
23
+ // prefixed with `caller`, the entry point the message names.
24
+ namespace native_frame {
25
+
26
+ // Import the frame's buffer as shared texture memory.
27
+ wgpu::SharedTextureMemory importMemory(const wgpu::Device &device,
28
+ const VideoFrameHandle &frame,
29
+ const std::string &label,
30
+ const char *caller);
31
+
32
+ // Begin an access to `texture`: Dawn's GPU work on it waits for each fence to
33
+ // reach its signaled value first. `initialized` declares whether the buffer
34
+ // holds pixels to keep (true for a frame a producer wrote). Exclusive access.
35
+ // On Vulkan an initialized image is acquired in the GENERAL layout (an
36
+ // UNDEFINED one lets the driver discard the frame on the transition), an
37
+ // uninitialized one in UNDEFINED.
38
+ void beginAccess(const wgpu::SharedTextureMemory &memory,
39
+ const wgpu::Texture &texture, bool initialized,
40
+ const std::vector<wgpu::SharedFence> &fences,
41
+ const std::vector<uint64_t> &signaledValues,
42
+ const char *caller);
43
+
44
+ // End the access. `state` receives the fences Dawn produced: each signals once
45
+ // the GPU work of the access is done.
46
+ void endAccess(const wgpu::SharedTextureMemory &memory,
47
+ const wgpu::Texture &texture,
48
+ wgpu::SharedTextureMemoryEndAccessState *state,
49
+ const char *caller);
50
+
51
+ // End the access and drop its fences, for the paths that release the import
52
+ // right after: Dawn keeps the texture alive for in-flight GPU work on its own.
53
+ void endAccess(const wgpu::SharedTextureMemory &memory,
54
+ const wgpu::Texture &texture);
55
+
56
+ // The acquire fence of the frame as a shared fence (Android: the sync fd its
57
+ // producer signals once it has written the buffer), or null when the frame
58
+ // has none. On a device without shared-fence-sync-fd the fence is waited for
59
+ // on the CPU instead, and null is returned.
60
+ wgpu::SharedFence importAcquireFence(const wgpu::Device &device,
61
+ const VideoFrameHandle &frame);
62
+
63
+ // The external texture that samples `texture`, created from the buffer of
64
+ // `frame`, as RGB: a YUV frame is converted with the color space of the frame
65
+ // (overridden by the descriptor's sourceColorSpace), and the descriptor's
66
+ // crop, rotation and mirroring apply.
67
+ wgpu::ExternalTexture createExternalTexture(
68
+ const wgpu::Device &device, const wgpu::SharedTextureMemory &memory,
69
+ const wgpu::Texture &texture, const VideoFrameHandle &frame,
70
+ const GPUExternalTextureDescriptor &descriptor, const std::string &label,
71
+ const char *caller);
72
+
73
+ // The fences of an end-access state as one: on Android their sync fds are
74
+ // merged into a single one (what Dawn's Android layer hands back from
75
+ // endAccess), on Apple platforms the device's shared event at the largest
76
+ // value. False when the state has no fence (or, on Android, only signaled
77
+ // ones). Throws if the fences cannot be merged into one: Android fences that
78
+ // are not sync fds, Apple fences on different shared events.
79
+ bool mergeFences(const wgpu::Device &device,
80
+ const wgpu::SharedTextureMemoryEndAccessState &state,
81
+ wgpu::SharedFence *fence, uint64_t *signaledValue,
82
+ const char *caller);
83
+
84
+ } // namespace native_frame
85
+
86
+ } // namespace rnwgpu
@@ -20,13 +20,13 @@ namespace jsi = facebook::jsi;
20
20
  // object stays alive until the JS object is GC'd (or release() is called).
21
21
  class VideoFrame : public NativeObject<VideoFrame> {
22
22
  public:
23
- // JS-facing brand. installConstructor() exposes this as globalThis[CLASS_NAME]
24
- // and keys the NativeObjectRegistry / worklet serializer off it, so it must
25
- // NOT be "VideoFrame": that would install our constructor over the WebCodecs
26
- // `VideoFrame` global and shadow it at runtime. "NativeVideoFrame" matches the
27
- // public TypeScript type (see src/types.ts) and keeps the two namespaces
28
- // distinct. The C++ class stays `VideoFrame` for brevity; only the brand is
29
- // namespaced.
23
+ // JS-facing brand. installConstructor() exposes this as
24
+ // globalThis[CLASS_NAME] and keys the NativeObjectRegistry / worklet
25
+ // serializer off it, so it must NOT be "VideoFrame": that would install our
26
+ // constructor over the WebCodecs `VideoFrame` global and shadow it at
27
+ // runtime. "NativeVideoFrame" matches the public TypeScript type (see
28
+ // src/types.ts) and keeps the two namespaces distinct. The C++ class stays
29
+ // `VideoFrame` for brevity; only the brand is namespaced.
30
30
  static constexpr const char *CLASS_NAME = "NativeVideoFrame";
31
31
 
32
32
  explicit VideoFrame(VideoFrameHandle handle)
@@ -47,6 +47,18 @@ public:
47
47
  return _handle.pixelFormat == VideoPixelFormat::NV12 ? "nv12" : "bgra8";
48
48
  }
49
49
 
50
+ // The sync fd the producer of the frame signals once it has written the
51
+ // buffer (Android), as a BigInt, or null when the frame has none (Apple
52
+ // platforms, a released frame). Borrowed: the frame closes it on release(),
53
+ // and importSharedFence() duplicates it.
54
+ jsi::Value getAcquireFenceFd(jsi::Runtime &runtime) {
55
+ if (_handle.handle == nullptr || _handle.acquireFenceFd < 0) {
56
+ return jsi::Value::null();
57
+ }
58
+ return jsi::BigInt::fromUint64(
59
+ runtime, static_cast<uint64_t>(_handle.acquireFenceFd));
60
+ }
61
+
50
62
  // Direct access to the underlying handle, for use by importExternalTexture /
51
63
  // importSharedTextureMemory inside the C++ layer (not exposed to JS).
52
64
  const VideoFrameHandle &handle() const { return _handle; }
@@ -67,6 +79,8 @@ public:
67
79
  installGetter(runtime, prototype, "pixelFormat",
68
80
  &VideoFrame::getPixelFormat);
69
81
  installMethod(runtime, prototype, "release", &VideoFrame::release);
82
+ installGetter(runtime, prototype, "acquireFenceFd",
83
+ &VideoFrame::getAcquireFenceFd);
70
84
  }
71
85
 
72
86
  private:
@@ -2,10 +2,13 @@
2
2
 
3
3
  #include <memory>
4
4
  #include <optional>
5
+ #include <stdexcept>
5
6
  #include <string>
6
7
 
7
8
  #include "webgpu/webgpu_cpp.h"
8
9
 
10
+ #include "GPUExtent2D.h"
11
+ #include "GPUOrigin2D.h"
9
12
  #include "JSIConverter.h"
10
13
  #include "VideoFrame.h"
11
14
 
@@ -16,7 +19,9 @@ namespace rnwgpu {
16
19
  // Mirror of GPUExternalTextureDescriptor from the WebGPU spec, but with our
17
20
  // VideoFrame as the (only) supported source. `colorSpace` is the spec member:
18
21
  // the color space of the RGB the shader samples, "srgb" (the default) or
19
- // "display-p3"; the frame's own color space comes with the frame.
22
+ // "display-p3"; the frame's own color space comes with the frame, and
23
+ // `sourceColorSpace` overrides the members of it the caller knows better (a
24
+ // buffer wrapped from another library carries none).
20
25
  //
21
26
  // `rotation` / `mirrored` are a non-spec extension: camera frames (e.g. from
22
27
  // VisionCamera) arrive in the sensor's native orientation, which differs
@@ -24,14 +29,138 @@ namespace rnwgpu {
24
29
  // ExternalTextureDescriptor can bake a rotation + horizontal mirror into the
25
30
  // sampling transform, so the shader sees an upright frame without any extra
26
31
  // passes. `rotation` is in degrees and must be one of 0 / 90 / 180 / 270.
32
+ // `cropOrigin` / `cropSize` select the part of the frame the external texture
33
+ // shows (Dawn's cropOrigin / cropSize), the whole frame by default.
34
+ //
35
+ // createNativeBufferExternalTexture() takes the same descriptor without a
36
+ // source: the frame is its first argument.
27
37
  struct GPUExternalTextureDescriptor {
28
38
  std::shared_ptr<VideoFrame> source;
29
39
  std::optional<std::string> label;
30
40
  std::optional<std::string> colorSpace;
41
+ std::optional<VideoFrameColorSpace> sourceColorSpace;
31
42
  std::optional<double> rotation;
32
43
  std::optional<bool> mirrored;
44
+ std::optional<std::shared_ptr<GPUOrigin2D>> cropOrigin;
45
+ std::optional<std::shared_ptr<GPUExtent2D>> cropSize;
33
46
  };
34
47
 
48
+ namespace external_texture_color_space {
49
+
50
+ // The JS names of the members of a source color space, the Dawn enums
51
+ // spelled the way the frame producers report them (see
52
+ // NativeVideoFrameColorSpace in src/types.ts).
53
+ inline wgpu::ColorSpaceYCbCrMatrixDawn parseMatrix(const std::string &name) {
54
+ if (name == "identity") {
55
+ return wgpu::ColorSpaceYCbCrMatrixDawn::Identity;
56
+ }
57
+ if (name == "rec601") {
58
+ return wgpu::ColorSpaceYCbCrMatrixDawn::Rec601;
59
+ }
60
+ if (name == "rec709") {
61
+ return wgpu::ColorSpaceYCbCrMatrixDawn::Rec709;
62
+ }
63
+ if (name == "rec2020") {
64
+ return wgpu::ColorSpaceYCbCrMatrixDawn::Rec2020;
65
+ }
66
+ throw std::runtime_error("sourceColorSpace.matrix: unknown value '" + name +
67
+ "' (expected 'identity', 'rec601', 'rec709' or "
68
+ "'rec2020')");
69
+ }
70
+
71
+ inline wgpu::ColorSpaceYCbCrRangeDawn parseRange(const std::string &name) {
72
+ if (name == "identity") {
73
+ return wgpu::ColorSpaceYCbCrRangeDawn::Identity;
74
+ }
75
+ if (name == "narrow") {
76
+ return wgpu::ColorSpaceYCbCrRangeDawn::Narrow;
77
+ }
78
+ if (name == "full") {
79
+ return wgpu::ColorSpaceYCbCrRangeDawn::Full;
80
+ }
81
+ throw std::runtime_error("sourceColorSpace.range: unknown value '" + name +
82
+ "' (expected 'identity', 'narrow' or 'full')");
83
+ }
84
+
85
+ inline wgpu::ColorSpacePrimariesDawn parsePrimaries(const std::string &name) {
86
+ if (name == "srgb") {
87
+ return wgpu::ColorSpacePrimariesDawn::SRGB;
88
+ }
89
+ if (name == "rec709") {
90
+ return wgpu::ColorSpacePrimariesDawn::Rec709;
91
+ }
92
+ if (name == "rec601") {
93
+ return wgpu::ColorSpacePrimariesDawn::Rec601;
94
+ }
95
+ if (name == "rec2020") {
96
+ return wgpu::ColorSpacePrimariesDawn::Rec2020;
97
+ }
98
+ if (name == "display-p3") {
99
+ return wgpu::ColorSpacePrimariesDawn::DisplayP3;
100
+ }
101
+ throw std::runtime_error("sourceColorSpace.primaries: unknown value '" +
102
+ name +
103
+ "' (expected 'srgb', 'rec709', 'rec601', "
104
+ "'rec2020' or 'display-p3')");
105
+ }
106
+
107
+ inline wgpu::ColorSpaceTransferDawn parseTransfer(const std::string &name) {
108
+ if (name == "identity") {
109
+ return wgpu::ColorSpaceTransferDawn::Identity;
110
+ }
111
+ if (name == "srgb") {
112
+ return wgpu::ColorSpaceTransferDawn::SRGB;
113
+ }
114
+ if (name == "display-p3") {
115
+ return wgpu::ColorSpaceTransferDawn::DisplayP3;
116
+ }
117
+ if (name == "smpte-170m") {
118
+ return wgpu::ColorSpaceTransferDawn::SMPTE_170M;
119
+ }
120
+ if (name == "hlg") {
121
+ return wgpu::ColorSpaceTransferDawn::HLG;
122
+ }
123
+ if (name == "pq") {
124
+ return wgpu::ColorSpaceTransferDawn::PQ;
125
+ }
126
+ if (name == "bt-1886") {
127
+ return wgpu::ColorSpaceTransferDawn::BT_1886;
128
+ }
129
+ throw std::runtime_error("sourceColorSpace.transfer: unknown value '" + name +
130
+ "' (expected 'identity', 'srgb', 'display-p3', "
131
+ "'smpte-170m', 'hlg', 'pq' or 'bt-1886')");
132
+ }
133
+
134
+ inline VideoFrameColorSpace parse(jsi::Runtime &runtime,
135
+ const jsi::Object &value) {
136
+ VideoFrameColorSpace colorSpace;
137
+ auto member = [&](const char *name) -> std::optional<std::string> {
138
+ if (!value.hasProperty(runtime, name)) {
139
+ return std::nullopt;
140
+ }
141
+ auto prop = value.getProperty(runtime, name);
142
+ if (!prop.isString()) {
143
+ return std::nullopt;
144
+ }
145
+ return prop.asString(runtime).utf8(runtime);
146
+ };
147
+ if (auto matrix = member("matrix")) {
148
+ colorSpace.matrix = parseMatrix(*matrix);
149
+ }
150
+ if (auto range = member("range")) {
151
+ colorSpace.range = parseRange(*range);
152
+ }
153
+ if (auto primaries = member("primaries")) {
154
+ colorSpace.primaries = parsePrimaries(*primaries);
155
+ }
156
+ if (auto transfer = member("transfer")) {
157
+ colorSpace.transfer = parseTransfer(*transfer);
158
+ }
159
+ return colorSpace;
160
+ }
161
+
162
+ } // namespace external_texture_color_space
163
+
35
164
  } // namespace rnwgpu
36
165
 
37
166
  namespace rnwgpu {
@@ -64,6 +193,13 @@ struct JSIConverter<std::shared_ptr<rnwgpu::GPUExternalTextureDescriptor>> {
64
193
  result->colorSpace = prop.asString(runtime).utf8(runtime);
65
194
  }
66
195
  }
196
+ if (value.hasProperty(runtime, "sourceColorSpace")) {
197
+ auto prop = value.getProperty(runtime, "sourceColorSpace");
198
+ if (prop.isObject()) {
199
+ result->sourceColorSpace = external_texture_color_space::parse(
200
+ runtime, prop.getObject(runtime));
201
+ }
202
+ }
67
203
  if (value.hasProperty(runtime, "rotation")) {
68
204
  auto prop = value.getProperty(runtime, "rotation");
69
205
  if (prop.isNumber()) {
@@ -76,6 +212,22 @@ struct JSIConverter<std::shared_ptr<rnwgpu::GPUExternalTextureDescriptor>> {
76
212
  result->mirrored = prop.getBool();
77
213
  }
78
214
  }
215
+ if (value.hasProperty(runtime, "cropOrigin")) {
216
+ auto prop = value.getProperty(runtime, "cropOrigin");
217
+ if (prop.isObject()) {
218
+ result->cropOrigin =
219
+ JSIConverter<std::shared_ptr<GPUOrigin2D>>::fromJSI(runtime, prop,
220
+ false);
221
+ }
222
+ }
223
+ if (value.hasProperty(runtime, "cropSize")) {
224
+ auto prop = value.getProperty(runtime, "cropSize");
225
+ if (prop.isObject()) {
226
+ result->cropSize =
227
+ JSIConverter<std::shared_ptr<GPUExtent2D>>::fromJSI(runtime, prop,
228
+ false);
229
+ }
230
+ }
79
231
  }
80
232
  return result;
81
233
  }
@@ -0,0 +1,55 @@
1
+ #pragma once
2
+
3
+ #include <memory>
4
+ #include <optional>
5
+ #include <stdexcept>
6
+ #include <string>
7
+
8
+ #include "webgpu/webgpu_cpp.h"
9
+
10
+ #include "JSIConverter.h"
11
+
12
+ namespace jsi = facebook::jsi;
13
+
14
+ namespace rnwgpu {
15
+
16
+ // The options of GPUDevice.createNativeBufferTexture(): the usage of the
17
+ // texture (the usages the buffer allows by default, as
18
+ // GPUSharedTextureMemory.createTexture() without a descriptor) and a label.
19
+ struct GPUNativeBufferTextureDescriptor {
20
+ std::optional<double> usage;
21
+ std::optional<std::string> label;
22
+ };
23
+
24
+ template <>
25
+ struct JSIConverter<std::shared_ptr<rnwgpu::GPUNativeBufferTextureDescriptor>> {
26
+ static std::shared_ptr<rnwgpu::GPUNativeBufferTextureDescriptor>
27
+ fromJSI(jsi::Runtime &runtime, const jsi::Value &arg, bool outOfBounds) {
28
+ auto result = std::make_shared<rnwgpu::GPUNativeBufferTextureDescriptor>();
29
+ if (!outOfBounds && arg.isObject()) {
30
+ auto value = arg.getObject(runtime);
31
+ if (value.hasProperty(runtime, "usage")) {
32
+ auto prop = value.getProperty(runtime, "usage");
33
+ if (prop.isNumber()) {
34
+ result->usage = prop.asNumber();
35
+ }
36
+ }
37
+ if (value.hasProperty(runtime, "label")) {
38
+ auto prop = value.getProperty(runtime, "label");
39
+ if (!prop.isUndefined()) {
40
+ result->label = JSIConverter<std::optional<std::string>>::fromJSI(
41
+ runtime, prop, false);
42
+ }
43
+ }
44
+ }
45
+ return result;
46
+ }
47
+ static jsi::Value
48
+ toJSI(jsi::Runtime & /*runtime*/,
49
+ std::shared_ptr<rnwgpu::GPUNativeBufferTextureDescriptor> /*arg*/) {
50
+ throw std::runtime_error(
51
+ "Invalid GPUNativeBufferTextureDescriptor::toJSI()");
52
+ }
53
+ };
54
+
55
+ } // namespace rnwgpu
@@ -3,6 +3,7 @@
3
3
  #include <memory>
4
4
  #include <stdexcept>
5
5
  #include <utility>
6
+ #include <vector>
6
7
 
7
8
  #include <ReactCommon/CallInvoker.h>
8
9
 
@@ -14,10 +14,57 @@ let CONTEXT_COUNTER = 1;
14
14
  function generateContextId() {
15
15
  return CONTEXT_COUNTER++;
16
16
  }
17
+
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
+
17
24
  // Anything else reaching the native component would hit the generated
18
25
  // string-enum parser, which aborts on unknown values.
19
26
  const resolveSurfaceType = surfaceType => surfaceType === "SurfaceView" || surfaceType === "TextureView" || surfaceType === "HardwareBufferView" ? surfaceType : "auto";
20
27
 
28
+ // The props the Android backing view is chosen from when the canvas mounts.
29
+
30
+ // The backing view the props select, see WebGPUView.resolveKind().
31
+ const resolveKind = ({
32
+ opaque,
33
+ android
34
+ }) => {
35
+ const surfaceType = resolveSurfaceType(android?.surfaceType);
36
+ if (surfaceType !== "auto") {
37
+ return surfaceType;
38
+ }
39
+ return opaque ? "SurfaceView" : "TextureView";
40
+ };
41
+ const warnIgnored = prop => console.warn(`Ignoring a change of ${prop} on a mounted canvas: the backing view is ` + "chosen when the canvas mounts. Remount the canvas (give it a new key) " + "to change it.");
42
+
43
+ // Warns, in development on Android, about a change of these props that the
44
+ // native view ignores: the backing view is chosen from them when the canvas
45
+ // mounts (see WebGPUView.java, whose setters these rules mirror). The native
46
+ // side only says so in logcat, which is not where a JS developer looks.
47
+ const useBackingViewWarning = props => {
48
+ const mount = (0, _react.useRef)(props);
49
+ const prev = (0, _react.useRef)(props);
50
+ (0, _react.useEffect)(() => {
51
+ if (__DEV__ && _reactNative.Platform.OS === "android") {
52
+ const {
53
+ current: before
54
+ } = prev;
55
+ if (resolveSurfaceType(before.android?.surfaceType) !== resolveSurfaceType(props.android?.surfaceType)) {
56
+ warnIgnored("android.surfaceType");
57
+ }
58
+ // Only a SurfaceView has a z-order of its own, which Android 11 and
59
+ // later changes in place.
60
+ if (!!before.android?.zOrderOnTop !== !!props.android?.zOrderOnTop && resolveKind(mount.current) === "SurfaceView" && Number(_reactNative.Platform.Version) < 30) {
61
+ warnIgnored("android.zOrderOnTop");
62
+ }
63
+ }
64
+ prev.current = props;
65
+ });
66
+ };
67
+
21
68
  // A view measured relative to itself gets its layout size, without the
22
69
  // transforms getBoundingClientRect() includes; measureLayout() calls back
23
70
  // synchronously on the new architecture. On the web react-native-web measures
@@ -55,6 +102,10 @@ const Canvas = ({
55
102
  }) => {
56
103
  const viewRef = (0, _react.useRef)(null);
57
104
  const [contextId, _] = (0, _react.useState)(() => generateContextId());
105
+ useBackingViewWarning({
106
+ opaque,
107
+ android
108
+ });
58
109
  // Retire the native registry entry for this contextId on unmount. When a
59
110
  // native surface is still attached, this is a no-op and the native view's
60
111
  // own teardown retires the entry instead — which keeps StrictMode's
@@ -1 +1 @@
1
- {"version":3,"names":["_react","_interopRequireWildcard","require","_reactNative","_WebGPUViewNativeComponent","_interopRequireDefault","e","__esModule","default","t","WeakMap","r","n","o","i","f","__proto__","has","get","set","hasOwnProperty","call","Object","defineProperty","getOwnPropertyDescriptor","_extends","assign","bind","arguments","length","apply","CONTEXT_COUNTER","generateContextId","resolveSurfaceType","surfaceType","measureLayout","view","Platform","OS","clientWidth","clientHeight","width","height","size","_left","_top","Canvas","opaque","android","ref","props","viewRef","useRef","contextId","_","useState","useEffect","RNWebGPU","destroyContext","useImperativeHandle","getContextId","getNativeSurface","getContext","contextName","Error","current","MakeWebGPUCanvasContext","createElement","View","collapsable","style","flex","androidSurfaceType","androidZOrderOnTop","zOrderOnTop","exports"],"sourceRoot":"../../src","sources":["Canvas.tsx"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,uBAAA,CAAAC,OAAA;AAEA,IAAAC,YAAA,GAAAD,OAAA;AAEA,IAAAE,0BAAA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U;IACrBN,MAAM,EAAEA,MAAO;IACfyB,kBAAkB,EAAEvC,kBAAkB,CAACe,OAAO,EAAEd,WAAW,CAAE;IAC7DuC,kBAAkB,EAAE,CAAC,CAACzB,OAAO,EAAE0B;EAAY,CAC5C,CACG,CAAC;AAEX,CAAC;AAACC,OAAA,CAAA7B,MAAA,GAAAA,MAAA","ignoreList":[]}
1
+ {"version":3,"names":["_react","_interopRequireWildcard","require","_reactNative","_WebGPUViewNativeComponent","_interopRequireDefault","e","__esModule","default","t","WeakMap","r","n","o","i","f","__proto__","has","get","set","hasOwnProperty","call","Object","defineProperty","getOwnPropertyDescriptor","_extends","assign","bind","arguments","length","apply","CONTEXT_COUNTER","generateContextId","resolveSurfaceType","surfaceType","resolveKind","opaque","android","warnIgnored","prop","console","warn","useBackingViewWarning","props","mount","useRef","prev","useEffect","__DEV__","Platform","OS","current","before","zOrderOnTop","Number","Version","measureLayout","view","clientWidth","clientHeight","width","height","size","_left","_top","Canvas","ref","viewRef","contextId","_","useState","RNWebGPU","destroyContext","useImperativeHandle","getContextId","getNativeSurface","getContext","contextName","Error","MakeWebGPUCanvasContext","createElement","View","collapsable","style","flex","androidSurfaceType","androidZOrderOnTop","exports"],"sourceRoot":"../../src","sources":["Canvas.tsx"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,uBAAA,CAAAC,OAAA;AAEA,IAAAC,YAAA,GAAAD,OAAA;AAGA,IAAAE,0BAAA,GAAAC,sBAAA,CAAAH,OAAA;AAA2D,SAAAG,uBAAAC,CAAA,WAAAA,CAAA,IAAAA,CAAA,CAAAC,UAAA,GAAAD,CAAA,KAAAE,OAAA,EAAAF,CAAA;AAAA,SAAAL,wBAAAK,CAAA,EAAAG,CAAA,6BAAAC,OAAA,MAAAC,CAAA,OAAAD,OAAA,IAAAE,CAAA,OAAAF,OAAA,YAAAT,uBAAA,YAAAA,CAAAK,CAAA,EAAAG,CAAA,SAAAA,CAAA,IAAAH,CAAA,IAAAA,CAAA,CAAAC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A","ignoreList":[]}
@@ -1 +1 @@
1
- {"version":3,"names":["isRegistered","registerWebGPUForReanimated","helpers","globalThis","__webgpuWorkletHelpers","undefined","registerCustomSerializable","require","name","determine","value","isNativeObject","pack","box","unpack","boxed","unbox","exports"],"sourceRoot":"../../../../src","sources":["external/reanimated/registerWebGPUForReanimated.ts"],"mappings":";;;;;;AAAA;AACA;AACA;AACA;AACA;AACA;;AAkBA,IAAIA,YAAY,GAAG,KAAK;;AAExB;AACA;AACA;AACA;AACA;AACA;AACO,MAAMC,2BAA2B,GAAGA,CAAA,KAAM;EAC/C,IAAID,YAAY,EAAE;IAChB;EACF;EACAA,YAAY,GAAG,IAAI;EAEnB,MAAME,OAAO,GAAGC,UAAU,CAACC,sBAAsB;EACjD,IAAIF,OAAO,KAAKG,SAAS,EAAE;IACzB;IACA;EACF;EAEA,IAAI;IACF,MAAM;MAAEC;IAA2B,CAAC,GAAGC,OAAO,CAAC,uBAAuB,CAAC;IAEvED,0BAA0B,CAAC;MACzBE,IAAI,EAAE,QAAQ;MACdC,SAAS,EAAGC,KAAa,IAAsB;QAC7C,SAAS;;QACT,OAAOR,OAAO,CAACS,cAAc,CAACD,KAAK,CAAC;MACtC,CAAC;MACDE,IAAI,EAAGF,KAAa,IAAK;QACvB,SAAS;;QACT,OAAOR,OAAO,CAACW,GAAG,CAACH,KAAK,CAAC;MAC3B,CAAC;MACDI,MAAM,EAAGC,KAAwB,IAAK;QACpC,SAAS;;QACT,OAAOA,KAAK,CAACC,KAAK,CAAC,CAAC;MACtB;IACF,CAAC,CAAC;EACJ,CAAC,CAAC,MAAM;IACN;EAAA;AAEJ,CAAC;AAACC,OAAA,CAAAhB,2BAAA,GAAAA,2BAAA","ignoreList":[]}
1
+ {"version":3,"names":["isRegistered","registerWebGPUForReanimated","helpers","globalThis","__webgpuWorkletHelpers","undefined","registerCustomSerializable","require","name","determine","value","isNativeObject","pack","box","unpack","boxed","unbox","exports"],"sourceRoot":"../../../../src","sources":["external/reanimated/registerWebGPUForReanimated.ts"],"mappings":";;;;;;AAAA;AACA;AACA;AACA;AACA;AACA;;AAsBA,IAAIA,YAAY,GAAG,KAAK;;AAExB;AACA;AACA;AACA;AACA;AACA;AACO,MAAMC,2BAA2B,GAAGA,CAAA,KAAM;EAC/C,IAAID,YAAY,EAAE;IAChB;EACF;EACAA,YAAY,GAAG,IAAI;EAEnB,MAAME,OAAO,GAAGC,UAAU,CAACC,sBAAsB;EACjD,IAAIF,OAAO,KAAKG,SAAS,EAAE;IACzB;IACA;EACF;EAEA,IAAI;IACF,MAAM;MAAEC;IAA2B,CAAC,GAAGC,OAAO,CAAC,uBAAuB,CAAC;IAEvED,0BAA0B,CAAC;MACzBE,IAAI,EAAE,QAAQ;MACdC,SAAS,EAAGC,KAAa,IAAsB;QAC7C,SAAS;;QACT,OAAOR,OAAO,CAACS,cAAc,CAACD,KAAK,CAAC;MACtC,CAAC;MACDE,IAAI,EAAGF,KAAa,IAAK;QACvB,SAAS;;QACT,OAAOR,OAAO,CAACW,GAAG,CAACH,KAAK,CAAC;MAC3B,CAAC;MACDI,MAAM,EAAGC,KAAwB,IAAK;QACpC,SAAS;;QACT,OAAOA,KAAK,CAACC,KAAK,CAAC,CAAC;MACtB;IACF,CAAC,CAAC;EACJ,CAAC,CAAC,MAAM;IACN;EAAA;AAEJ,CAAC;AAACC,OAAA,CAAAhB,2BAAA,GAAAA,2BAAA","ignoreList":[]}
@@ -1 +1 @@
1
- {"version":3,"names":["require","_main","Object","keys","forEach","key","prototype","hasOwnProperty","call","_exportNames","exports","defineProperty","enumerable","get","_constants","_install"],"sourceRoot":"../../src","sources":["index.tsx"],"mappings":";;;;;;;;;;;;;;AAQAA,OAAA;AAmBA,IAAAC,KAAA,GAAAD,OAAA;AAAAE,MAAA,CAAAC,IAAA,CAAAF,KAAA,EAAAG,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAH,MAAA,CAAAI,SAAA,CAAAC,cAAA,CAAAC,IAAA,CAAAC,YAAA,EAAAJ,GAAA;EAAA,IAAAA,GAAA,IAAAK,OAAA,IAAAA,OAAA,CAAAL,GAAA,MAAAJ,KAAA,CAAAI,GAAA;EAAAH,MAAA,CAAAS,cAAA,CAAAD,OAAA,EAAAL,GAAA;IAAAO,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAZ,KAAA,CAAAI,GAAA;IAAA;EAAA;AAAA;AACA,IAAAS,UAAA,GAAAd,OAAA;AAAAE,MAAA,CAAAC,IAAA,CAAAW,UAAA,EAAAV,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAH,MAAA,CAAAI,SAAA,CAAAC,cAAA,CAAAC,IAAA,CAAAC,YAAA,EAAAJ,GAAA;EAAA,IAAAA,GAAA,IAAAK,OAAA,IAAAA,OAAA,CAAAL,GAAA,MAAAS,UAAA,CAAAT,GAAA;EAAAH,MAAA,CAAAS,cAAA,CAAAD,OAAA,EAAAL,GAAA;IAAAO,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAC,UAAA,CAAAT,GAAA;IAAA;EAAA;AAAA;AACA,IAAAU,QAAA,GAAAf,OAAA","ignoreList":[]}
1
+ {"version":3,"names":["require","_main","Object","keys","forEach","key","prototype","hasOwnProperty","call","_exportNames","exports","defineProperty","enumerable","get","_constants","_install"],"sourceRoot":"../../src","sources":["index.tsx"],"mappings":";;;;;;;;;;;;;;AAQAA,OAAA;AAuBA,IAAAC,KAAA,GAAAD,OAAA;AAAAE,MAAA,CAAAC,IAAA,CAAAF,KAAA,EAAAG,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAH,MAAA,CAAAI,SAAA,CAAAC,cAAA,CAAAC,IAAA,CAAAC,YAAA,EAAAJ,GAAA;EAAA,IAAAA,GAAA,IAAAK,OAAA,IAAAA,OAAA,CAAAL,GAAA,MAAAJ,KAAA,CAAAI,GAAA;EAAAH,MAAA,CAAAS,cAAA,CAAAD,OAAA,EAAAL,GAAA;IAAAO,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAZ,KAAA,CAAAI,GAAA;IAAA;EAAA;AAAA;AACA,IAAAS,UAAA,GAAAd,OAAA;AAAAE,MAAA,CAAAC,IAAA,CAAAW,UAAA,EAAAV,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAH,MAAA,CAAAI,SAAA,CAAAC,cAAA,CAAAC,IAAA,CAAAC,YAAA,EAAAJ,GAAA;EAAA,IAAAA,GAAA,IAAAK,OAAA,IAAAA,OAAA,CAAAL,GAAA,MAAAS,UAAA,CAAAT,GAAA;EAAAH,MAAA,CAAAS,cAAA,CAAAD,OAAA,EAAAL,GAAA;IAAAO,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAC,UAAA,CAAAT,GAAA;IAAA;EAAA;AAAA;AACA,IAAAU,QAAA,GAAAf,OAAA","ignoreList":[]}
@@ -28,14 +28,25 @@ const constants = {
28
28
  // runtime installs the GPU prototype there.
29
29
  const gpu = typeof RNWebGPU === "undefined" ? undefined : RNWebGPU.gpu;
30
30
 
31
+ // The native half of the worklet serializer (see registerWebGPUForReanimated),
32
+ // read from the main runtime like `gpu` above and captured into the worklet
33
+ // closure: worklets hands a HostObject to every runtime by reference, so it is
34
+ // callable on the target runtime without installing anything there. Its
35
+ // installConstructors() installs the WebGPU class constructors on the runtime
36
+ // that calls it. Undefined on web and node, where the native module is not
37
+ // installed.
38
+ const helpers = globalThis.__webgpuWorkletHelpers;
39
+
31
40
  /**
32
41
  * Install WebGPU on the runtime that calls it.
33
42
  *
34
43
  * The native module sets up WebGPU on the main JS runtime, but worklet
35
44
  * runtimes (Reanimated UI, dedicated worklet runtimes, Vision Camera frame
36
- * processors) start without it: `navigator.gpu` and the flag constants
45
+ * processors) start without it: `navigator.gpu`, the flag constants
37
46
  * (`GPUBufferUsage`, `GPUTextureUsage`, `GPUShaderStage`, `GPUColorWrite`,
38
- * `GPUMapMode`) are all `undefined` there.
47
+ * `GPUMapMode`) and the class constructors (`GPUBuffer`, `GPUTexture`,
48
+ * `GPURenderBundleEncoder`, ...) are all `undefined` there. Without the
49
+ * constructors, `instanceof` against a WebGPU class throws a ReferenceError.
39
50
  *
40
51
  * Call `installWebGPU()` once at the top of a worklet to make them available:
41
52
  *
@@ -64,12 +75,13 @@ const gpu = typeof RNWebGPU === "undefined" ? undefined : RNWebGPU.gpu;
64
75
  * Observe those on a device created on the main JS thread.
65
76
  *
66
77
  * Everything is captured into the worklet by closure: the constants like a
67
- * shader string would be, and the GPU object through the Worklets custom
78
+ * shader string would be, the GPU object through the Worklets custom
68
79
  * serializer, which installs the native prototypes on the target runtime when
69
- * it crosses. Promises returned by `requestAdapter`/`requestDevice` settle on
70
- * the calling runtime (each runtime gets its own async pump). Calling it on a
71
- * runtime that already has the globals (e.g. the main JS runtime) is a safe
72
- * no-op.
80
+ * it crosses, and the native helper that installs the class constructors,
81
+ * which worklets hands to every runtime by reference. Promises returned by
82
+ * `requestAdapter`/`requestDevice` settle on the calling runtime (each
83
+ * runtime gets its own async pump). Calling it on a runtime that already has
84
+ * the globals (e.g. the main JS runtime) is a safe no-op.
73
85
  */
74
86
  const installWebGPU = () => {
75
87
  "worklet";
@@ -91,6 +103,13 @@ const installWebGPU = () => {
91
103
  nav.gpu = gpu;
92
104
  }
93
105
  }
106
+ // The class constructors, so `instanceof` works against any WebGPU class on
107
+ // this runtime (three.js checks `pass instanceof GPURenderBundleEncoder` on
108
+ // every render, for instance). Unboxing an object installs only its own
109
+ // class; this installs the rest and skips the ones already there.
110
+ if (helpers !== undefined) {
111
+ helpers.installConstructors();
112
+ }
94
113
  };
95
114
  exports.installWebGPU = installWebGPU;
96
115
  //# sourceMappingURL=install.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["_constants","require","constants","GPUBufferUsage","GPUTextureUsage","GPUShaderStage","GPUColorWrite","GPUMapMode","gpu","RNWebGPU","undefined","installWebGPU","g","globalThis","key","value","Object","entries","nav","navigator","userAgent","exports"],"sourceRoot":"../../src","sources":["install.ts"],"mappings":";;;;;;AACA,IAAAA,UAAA,GAAAC,OAAA;AADA;;AASA;AACA;AACA;AACA;AACA,MAAMC,SAAS,GAAG;EAChBC,cAAc,EAAdA,yBAAc;EACdC,eAAe,EAAfA,0BAAe;EACfC,cAAc,EAAdA,yBAAc;EACdC,aAAa,EAAbA,wBAAa;EACbC,UAAU,EAAVA;AACF,CAAC;;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAMC,GAAoB,GACxB,OAAOC,QAAQ,KAAK,WAAW,GAAGC,SAAS,GAAGD,QAAQ,CAACD,GAAG;;AAE5D;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,MAAMG,aAAa,GAAGA,CAAA,KAAM;EACjC,SAAS;;EACT,MAAMC,CAAC,GAAGC,UAAgD;EAC1D,KAAK,MAAM,CAACC,GAAG,EAAEC,KAAK,CAAC,IAAIC,MAAM,CAACC,OAAO,CAACf,SAAS,CAAC,EAAE;IACpD,IAAIU,CAAC,CAACE,GAAG,CAAC,KAAKJ,SAAS,EAAE;MACxBE,CAAC,CAACE,GAAG,CAAC,GAAGC,KAAK;IAChB;EACF;EACA,IAAIP,GAAG,KAAKE,SAAS,EAAE;IACrB,MAAMQ,GAAG,GAAGN,CAAC,CAACO,SAA0D;IACxE,IAAID,GAAG,KAAKR,SAAS,EAAE;MACrBE,CAAC,CAACO,SAAS,GAAG;QAAEX,GAAG;QAAEY,SAAS,EAAE;MAAe,CAAC;IAClD,CAAC,MAAM,IAAIF,GAAG,CAACV,GAAG,KAAKE,SAAS,EAAE;MAChCQ,GAAG,CAACV,GAAG,GAAGA,GAAG;IACf;EACF;AACF,CAAC;AAACa,OAAA,CAAAV,aAAA,GAAAA,aAAA","ignoreList":[]}
1
+ {"version":3,"names":["_constants","require","constants","GPUBufferUsage","GPUTextureUsage","GPUShaderStage","GPUColorWrite","GPUMapMode","gpu","RNWebGPU","undefined","helpers","globalThis","__webgpuWorkletHelpers","installWebGPU","g","key","value","Object","entries","nav","navigator","userAgent","installConstructors","exports"],"sourceRoot":"../../src","sources":["install.ts"],"mappings":";;;;;;AACA,IAAAA,UAAA,GAAAC,OAAA;AADA;;AASA;AACA;AACA;AACA;AACA,MAAMC,SAAS,GAAG;EAChBC,cAAc,EAAdA,yBAAc;EACdC,eAAe,EAAfA,0BAAe;EACfC,cAAc,EAAdA,yBAAc;EACdC,aAAa,EAAbA,wBAAa;EACbC,UAAU,EAAVA;AACF,CAAC;;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAMC,GAAoB,GACxB,OAAOC,QAAQ,KAAK,WAAW,GAAGC,SAAS,GAAGD,QAAQ,CAACD,GAAG;;AAE5D;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAMG,OAAO,GAAGC,UAAU,CAACC,sBAAsB;;AAEjD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,MAAMC,aAAa,GAAGA,CAAA,KAAM;EACjC,SAAS;;EACT,MAAMC,CAAC,GAAGH,UAAgD;EAC1D,KAAK,MAAM,CAACI,GAAG,EAAEC,KAAK,CAAC,IAAIC,MAAM,CAACC,OAAO,CAACjB,SAAS,CAAC,EAAE;IACpD,IAAIa,CAAC,CAACC,GAAG,CAAC,KAAKN,SAAS,EAAE;MACxBK,CAAC,CAACC,GAAG,CAAC,GAAGC,KAAK;IAChB;EACF;EACA,IAAIT,GAAG,KAAKE,SAAS,EAAE;IACrB,MAAMU,GAAG,GAAGL,CAAC,CAACM,SAA0D;IACxE,IAAID,GAAG,KAAKV,SAAS,EAAE;MACrBK,CAAC,CAACM,SAAS,GAAG;QAAEb,GAAG;QAAEc,SAAS,EAAE;MAAe,CAAC;IAClD,CAAC,MAAM,IAAIF,GAAG,CAACZ,GAAG,KAAKE,SAAS,EAAE;MAChCU,GAAG,CAACZ,GAAG,GAAGA,GAAG;IACf;EACF;EACA;EACA;EACA;EACA;EACA,IAAIG,OAAO,KAAKD,SAAS,EAAE;IACzBC,OAAO,CAACY,mBAAmB,CAAC,CAAC;EAC/B;AACF,CAAC;AAACC,OAAA,CAAAV,aAAA,GAAAA,aAAA","ignoreList":[]}