react-native-wgpu 0.2.9 → 0.3.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.
- package/README.md +155 -69
- package/android/CMakeLists.txt +4 -5
- package/android/build.gradle +7 -18
- package/android/src/main/java/com/webgpu/WebGPUViewPackage.java +34 -10
- package/apple/MetalView.mm +0 -19
- package/apple/WebGPUModule.h +1 -9
- package/apple/WebGPUModule.mm +0 -3
- package/apple/WebGPUView.h +0 -3
- package/apple/WebGPUView.mm +0 -2
- package/cpp/WGPULogger.h +10 -0
- package/cpp/dawn/dawn_proc_table.h +1 -1
- package/cpp/dawn/webgpu.h +4855 -0
- package/cpp/dawn/webgpu_cpp.h +10168 -0
- package/cpp/dawn/wire/client/webgpu.h +354 -0
- package/cpp/dawn/wire/client/webgpu_cpp.h +10343 -0
- package/cpp/dawn/wire/client/webgpu_cpp_print.h +2715 -0
- package/cpp/jsi/RNFJSIConverter.h +17 -59
- package/cpp/rnwgpu/RNWebGPUManager.cpp +1 -9
- package/cpp/rnwgpu/api/GPU.cpp +51 -26
- package/cpp/rnwgpu/api/GPU.h +5 -18
- package/cpp/rnwgpu/api/GPUAdapter.cpp +75 -54
- package/cpp/rnwgpu/api/GPUAdapter.h +6 -6
- package/cpp/rnwgpu/api/GPUAdapterInfo.h +0 -1
- package/cpp/rnwgpu/api/GPUBindGroup.h +1 -3
- package/cpp/rnwgpu/api/GPUBindGroupLayout.h +1 -3
- package/cpp/rnwgpu/api/GPUBuffer.cpp +35 -32
- package/cpp/rnwgpu/api/GPUBuffer.h +9 -7
- package/cpp/rnwgpu/api/GPUCanvasContext.cpp +5 -1
- package/cpp/rnwgpu/api/GPUCanvasContext.h +0 -2
- package/cpp/rnwgpu/api/GPUCommandBuffer.h +1 -3
- package/cpp/rnwgpu/api/GPUCommandEncoder.h +1 -3
- package/cpp/rnwgpu/api/GPUCompilationInfo.h +0 -2
- package/cpp/rnwgpu/api/GPUCompilationMessage.h +1 -3
- package/cpp/rnwgpu/api/GPUComputePassEncoder.h +1 -3
- package/cpp/rnwgpu/api/GPUComputePipeline.h +1 -3
- package/cpp/rnwgpu/api/GPUDevice.cpp +183 -128
- package/cpp/rnwgpu/api/GPUDevice.h +22 -21
- package/cpp/rnwgpu/api/GPUDeviceLostInfo.h +1 -3
- package/cpp/rnwgpu/api/GPUExternalTexture.h +1 -3
- package/cpp/rnwgpu/api/GPUPipelineLayout.h +1 -3
- package/cpp/rnwgpu/api/GPUQuerySet.h +1 -3
- package/cpp/rnwgpu/api/GPUQueue.cpp +19 -8
- package/cpp/rnwgpu/api/GPUQueue.h +7 -6
- package/cpp/rnwgpu/api/GPURenderBundle.h +1 -3
- package/cpp/rnwgpu/api/GPURenderBundleEncoder.h +1 -3
- package/cpp/rnwgpu/api/GPURenderPassEncoder.h +1 -3
- package/cpp/rnwgpu/api/GPURenderPipeline.h +1 -3
- package/cpp/rnwgpu/api/GPUSampler.h +1 -3
- package/cpp/rnwgpu/api/GPUShaderModule.cpp +42 -28
- package/cpp/rnwgpu/api/GPUShaderModule.h +6 -6
- package/cpp/rnwgpu/api/GPUSupportedLimits.h +1 -3
- package/cpp/rnwgpu/api/GPUTexture.h +1 -3
- package/cpp/rnwgpu/api/GPUTextureView.h +1 -3
- package/cpp/rnwgpu/api/RNWebGPU.h +1 -7
- package/cpp/rnwgpu/async/AsyncDispatcher.h +28 -0
- package/cpp/rnwgpu/async/AsyncRunner.cpp +215 -0
- package/cpp/rnwgpu/async/AsyncRunner.h +53 -0
- package/cpp/rnwgpu/async/AsyncTaskHandle.cpp +181 -0
- package/cpp/rnwgpu/async/AsyncTaskHandle.h +55 -0
- package/cpp/rnwgpu/async/JSIMicrotaskDispatcher.cpp +23 -0
- package/cpp/rnwgpu/async/JSIMicrotaskDispatcher.h +22 -0
- package/cpp/webgpu/webgpu.h +5 -4827
- package/cpp/webgpu/webgpu_cpp.h +5 -10140
- package/cpp/{dawn/native/WebGPUBackend.h → webgpu/webgpu_cpp_print.h} +4 -20
- package/lib/commonjs/Canvas.js +6 -66
- package/lib/commonjs/Canvas.js.map +1 -1
- package/lib/commonjs/hooks.js +6 -42
- package/lib/commonjs/hooks.js.map +1 -1
- package/lib/module/Canvas.js +7 -67
- package/lib/module/Canvas.js.map +1 -1
- package/lib/module/hooks.js +5 -40
- package/lib/module/hooks.js.map +1 -1
- package/lib/typescript/lib/commonjs/hooks.d.ts +1 -5
- package/lib/typescript/lib/commonjs/hooks.d.ts.map +1 -1
- package/lib/typescript/lib/module/Canvas.d.ts.map +1 -1
- package/lib/typescript/lib/module/hooks.d.ts +1 -5
- package/lib/typescript/lib/module/hooks.d.ts.map +1 -1
- package/lib/typescript/src/Canvas.d.ts +0 -1
- package/lib/typescript/src/Canvas.d.ts.map +1 -1
- package/lib/typescript/src/hooks.d.ts +2 -7
- package/lib/typescript/src/hooks.d.ts.map +1 -1
- package/libs/android/arm64-v8a/libwebgpu_dawn.so +0 -0
- package/libs/android/armeabi-v7a/libwebgpu_dawn.so +0 -0
- package/libs/android/x86/libwebgpu_dawn.so +0 -0
- package/libs/android/x86_64/libwebgpu_dawn.so +0 -0
- package/libs/apple/libwebgpu_dawn.xcframework/Info.plist +5 -35
- package/libs/apple/libwebgpu_dawn.xcframework/ios-arm64/libwebgpu_dawn.a +0 -0
- package/libs/apple/libwebgpu_dawn.xcframework/ios-arm64_x86_64-simulator/libwebgpu_dawn.a +0 -0
- package/libs/apple/libwebgpu_dawn.xcframework/macos-arm64_x86_64/libwebgpu_dawn.a +0 -0
- package/package.json +4 -3
- package/react-native-wgpu.podspec +12 -16
- package/src/Canvas.tsx +8 -69
- package/src/hooks.tsx +14 -48
- package/android/cpp/platform/ThreadUtils.cpp +0 -41
- package/android/src/oldarch/com/webgpu/NativeWebGPUModuleSpec.java +0 -23
- package/android/src/oldarch/com/webgpu/WebGPUViewManagerSpec.java +0 -12
- package/apple/WebGPUViewManager.mm +0 -24
- package/apple/platform/ThreadUtils.cpp +0 -34
- package/cpp/dawn/dawn_proc.h +0 -50
- package/cpp/dawn/dawn_thread_dispatch_proc.h +0 -47
- package/cpp/dawn/native/D3D11Backend.h +0 -77
- package/cpp/dawn/native/D3D12Backend.h +0 -68
- package/cpp/dawn/native/D3DBackend.h +0 -56
- package/cpp/dawn/native/MetalBackend.h +0 -56
- package/cpp/dawn/platform/DawnPlatform.h +0 -167
- package/cpp/dawn/platform/dawn_platform_export.h +0 -49
- package/cpp/platform/ThreadUtils.h +0 -30
- package/cpp/rnwgpu/api/AsyncRunner.h +0 -30
- package/cpp/threading/CallInvokerDispatcher.h +0 -37
- package/cpp/threading/Dispatcher.cpp +0 -55
- package/cpp/threading/Dispatcher.h +0 -93
- package/cpp/threading/ThreadPool.cpp +0 -88
- package/cpp/threading/ThreadPool.h +0 -53
- package/cpp/webgpu/webgpu_glfw.h +0 -88
- package/lib/typescript/src/__tests__/Alpha.spec.d.ts +0 -2
- package/lib/typescript/src/__tests__/Alpha.spec.d.ts.map +0 -1
- package/lib/typescript/src/__tests__/ArrayBuffer.spec.d.ts +0 -2
- package/lib/typescript/src/__tests__/ArrayBuffer.spec.d.ts.map +0 -1
- package/lib/typescript/src/__tests__/Buffer.spec.d.ts +0 -2
- package/lib/typescript/src/__tests__/Buffer.spec.d.ts.map +0 -1
- package/lib/typescript/src/__tests__/ComputeShader.spec.d.ts +0 -2
- package/lib/typescript/src/__tests__/ComputeShader.spec.d.ts.map +0 -1
- package/lib/typescript/src/__tests__/Constants.spec.d.ts +0 -2
- package/lib/typescript/src/__tests__/Constants.spec.d.ts.map +0 -1
- package/lib/typescript/src/__tests__/Device.spec.d.ts +0 -2
- package/lib/typescript/src/__tests__/Device.spec.d.ts.map +0 -1
- package/lib/typescript/src/__tests__/ErrorScope.spec.d.ts +0 -2
- package/lib/typescript/src/__tests__/ErrorScope.spec.d.ts.map +0 -1
- package/lib/typescript/src/__tests__/ExternalTexture.spec.d.ts +0 -2
- package/lib/typescript/src/__tests__/ExternalTexture.spec.d.ts.map +0 -1
- package/lib/typescript/src/__tests__/GPU.spec.d.ts +0 -2
- package/lib/typescript/src/__tests__/GPU.spec.d.ts.map +0 -1
- package/lib/typescript/src/__tests__/ImageData.spec.d.ts +0 -2
- package/lib/typescript/src/__tests__/ImageData.spec.d.ts.map +0 -1
- package/lib/typescript/src/__tests__/Shaders.spec.d.ts +0 -2
- package/lib/typescript/src/__tests__/Shaders.spec.d.ts.map +0 -1
- package/lib/typescript/src/__tests__/Texture.spec.d.ts +0 -2
- package/lib/typescript/src/__tests__/Texture.spec.d.ts.map +0 -1
- package/lib/typescript/src/__tests__/components/Wireframe/Shaders.d.ts +0 -3
- package/lib/typescript/src/__tests__/components/Wireframe/Shaders.d.ts.map +0 -1
- package/lib/typescript/src/__tests__/components/Wireframe/models.d.ts +0 -29
- package/lib/typescript/src/__tests__/components/Wireframe/models.d.ts.map +0 -1
- package/lib/typescript/src/__tests__/components/Wireframe/utils.d.ts +0 -5
- package/lib/typescript/src/__tests__/components/Wireframe/utils.d.ts.map +0 -1
- package/lib/typescript/src/__tests__/components/cube.d.ts +0 -7
- package/lib/typescript/src/__tests__/components/cube.d.ts.map +0 -1
- package/lib/typescript/src/__tests__/components/meshes/mesh.d.ts +0 -22
- package/lib/typescript/src/__tests__/components/meshes/mesh.d.ts.map +0 -1
- package/lib/typescript/src/__tests__/components/meshes/sphere.d.ts +0 -12
- package/lib/typescript/src/__tests__/components/meshes/sphere.d.ts.map +0 -1
- package/lib/typescript/src/__tests__/components/meshes/stanfordDragon.d.ts +0 -7
- package/lib/typescript/src/__tests__/components/meshes/stanfordDragon.d.ts.map +0 -1
- package/lib/typescript/src/__tests__/components/meshes/stanfordDragonData.d.ts +0 -6
- package/lib/typescript/src/__tests__/components/meshes/stanfordDragonData.d.ts.map +0 -1
- package/lib/typescript/src/__tests__/components/meshes/teapot.d.ts +0 -6
- package/lib/typescript/src/__tests__/components/meshes/teapot.d.ts.map +0 -1
- package/lib/typescript/src/__tests__/components/meshes/utils.d.ts +0 -10
- package/lib/typescript/src/__tests__/components/meshes/utils.d.ts.map +0 -1
- package/lib/typescript/src/__tests__/components/triangle.d.ts +0 -3
- package/lib/typescript/src/__tests__/components/triangle.d.ts.map +0 -1
- package/lib/typescript/src/__tests__/config.d.ts +0 -3
- package/lib/typescript/src/__tests__/config.d.ts.map +0 -1
- package/lib/typescript/src/__tests__/demos/ABuffer.spec.d.ts +0 -2
- package/lib/typescript/src/__tests__/demos/ABuffer.spec.d.ts.map +0 -1
- package/lib/typescript/src/__tests__/demos/Blur.spec.d.ts +0 -2
- package/lib/typescript/src/__tests__/demos/Blur.spec.d.ts.map +0 -1
- package/lib/typescript/src/__tests__/demos/Cube.spec.d.ts +0 -2
- package/lib/typescript/src/__tests__/demos/Cube.spec.d.ts.map +0 -1
- package/lib/typescript/src/__tests__/demos/FractalCube.spec.d.ts +0 -2
- package/lib/typescript/src/__tests__/demos/FractalCube.spec.d.ts.map +0 -1
- package/lib/typescript/src/__tests__/demos/OcclusionQuery.spec.d.ts +0 -2
- package/lib/typescript/src/__tests__/demos/OcclusionQuery.spec.d.ts.map +0 -1
- package/lib/typescript/src/__tests__/demos/RenderBundles.spec.d.ts +0 -2
- package/lib/typescript/src/__tests__/demos/RenderBundles.spec.d.ts.map +0 -1
- package/lib/typescript/src/__tests__/demos/Triangle.spec.d.ts +0 -2
- package/lib/typescript/src/__tests__/demos/Triangle.spec.d.ts.map +0 -1
- package/lib/typescript/src/__tests__/demos/Wireframe.spec.d.ts +0 -2
- package/lib/typescript/src/__tests__/demos/Wireframe.spec.d.ts.map +0 -1
- package/lib/typescript/src/__tests__/globalSetup.d.ts +0 -3
- package/lib/typescript/src/__tests__/globalSetup.d.ts.map +0 -1
- package/lib/typescript/src/__tests__/globalTeardown.d.ts +0 -3
- package/lib/typescript/src/__tests__/globalTeardown.d.ts.map +0 -1
- package/lib/typescript/src/__tests__/setup.d.ts +0 -63
- package/lib/typescript/src/__tests__/setup.d.ts.map +0 -1
- package/libs/apple/arm64_iphoneos/libwebgpu_dawn.a +0 -0
- package/libs/apple/arm64_iphonesimulator/libwebgpu_dawn.a +0 -0
- package/libs/apple/arm64_xros/libwebgpu_dawn.a +0 -0
- package/libs/apple/arm64_xrsimulator/libwebgpu_dawn.a +0 -0
- package/libs/apple/iphonesimulator/libwebgpu_dawn.a +0 -0
- package/libs/apple/libwebgpu_dawn.xcframework/xros-arm64/libwebgpu_dawn.a +0 -0
- package/libs/apple/libwebgpu_dawn.xcframework/xros-arm64-simulator/libwebgpu_dawn.a +0 -0
- package/libs/apple/universal_macosx/libwebgpu_dawn.a +0 -0
- package/libs/apple/x86_64_iphonesimulator/libwebgpu_dawn.a +0 -0
- package/libs/dawn.json +0 -4670
- package/src/__tests__/Alpha.spec.ts +0 -28
- package/src/__tests__/ArrayBuffer.spec.ts +0 -76
- package/src/__tests__/Buffer.spec.ts +0 -357
- package/src/__tests__/ComputeShader.spec.ts +0 -375
- package/src/__tests__/Constants.spec.ts +0 -89
- package/src/__tests__/Device.spec.ts +0 -84
- package/src/__tests__/ErrorScope.spec.ts +0 -92
- package/src/__tests__/ExternalTexture.spec.ts +0 -284
- package/src/__tests__/GPU.spec.ts +0 -272
- package/src/__tests__/ImageData.spec.ts +0 -26
- package/src/__tests__/Shaders.spec.ts +0 -232
- package/src/__tests__/Texture.spec.ts +0 -197
- package/src/__tests__/assets/Di-3d.png +0 -0
- package/src/__tests__/components/Wireframe/Shaders.ts +0 -138
- package/src/__tests__/components/Wireframe/models.ts +0 -113
- package/src/__tests__/components/Wireframe/utils.ts +0 -22
- package/src/__tests__/components/cube.ts +0 -51
- package/src/__tests__/components/meshes/mesh.ts +0 -96
- package/src/__tests__/components/meshes/sphere.ts +0 -103
- package/src/__tests__/components/meshes/stanfordDragon.ts +0 -44
- package/src/__tests__/components/meshes/stanfordDragonData.ts +0 -5
- package/src/__tests__/components/meshes/teapot.ts +0 -13
- package/src/__tests__/components/meshes/utils.ts +0 -235
- package/src/__tests__/components/triangle.ts +0 -17
- package/src/__tests__/config.ts +0 -2
- package/src/__tests__/demos/ABuffer.spec.ts +0 -890
- package/src/__tests__/demos/Blur.spec.ts +0 -398
- package/src/__tests__/demos/Cube.spec.ts +0 -929
- package/src/__tests__/demos/FractalCube.spec.ts +0 -240
- package/src/__tests__/demos/OcclusionQuery.spec.ts +0 -376
- package/src/__tests__/demos/RenderBundles.spec.ts +0 -580
- package/src/__tests__/demos/Triangle.spec.ts +0 -266
- package/src/__tests__/demos/Wireframe.spec.ts +0 -188
- package/src/__tests__/globalSetup.ts +0 -45
- package/src/__tests__/globalTeardown.ts +0 -11
- package/src/__tests__/setup.ts +0 -423
- package/src/__tests__/snapshots/abuffer.png +0 -0
- package/src/__tests__/snapshots/asteroid.png +0 -0
- package/src/__tests__/snapshots/blur.png +0 -0
- package/src/__tests__/snapshots/buffer.png +0 -0
- package/src/__tests__/snapshots/constant-triangle.png +0 -0
- package/src/__tests__/snapshots/cube.png +0 -0
- package/src/__tests__/snapshots/f.png +0 -0
- package/src/__tests__/snapshots/f2.png +0 -0
- package/src/__tests__/snapshots/fractal-cubes.png +0 -0
- package/src/__tests__/snapshots/instanced-cubes.png +0 -0
- package/src/__tests__/snapshots/occlusion-query.png +0 -0
- package/src/__tests__/snapshots/ref.png +0 -0
- package/src/__tests__/snapshots/semi-opaque-cyan.png +0 -0
- package/src/__tests__/snapshots/texture.png +0 -0
- package/src/__tests__/snapshots/textured-cube.png +0 -0
- package/src/__tests__/snapshots/triangle-msaa.png +0 -0
- package/src/__tests__/snapshots/triangle.png +0 -0
- package/src/__tests__/snapshots/two-cube.png +0 -0
|
@@ -25,25 +25,9 @@
|
|
|
25
25
|
// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
26
26
|
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
27
27
|
|
|
28
|
-
#ifndef
|
|
29
|
-
#define
|
|
28
|
+
#ifndef INCLUDE_WEBGPU_WEBGPU_CPP_PRINT_H_
|
|
29
|
+
#define INCLUDE_WEBGPU_WEBGPU_CPP_PRINT_H_
|
|
30
30
|
|
|
31
|
-
#include
|
|
31
|
+
#include "dawn/webgpu_cpp_print.h"
|
|
32
32
|
|
|
33
|
-
#
|
|
34
|
-
|
|
35
|
-
namespace dawn::native::webgpu {
|
|
36
|
-
|
|
37
|
-
using CaptureStream = std::ostream;
|
|
38
|
-
|
|
39
|
-
// Starts a capture on the given device.
|
|
40
|
-
DAWN_NATIVE_EXPORT void StartCapture(WGPUDevice device,
|
|
41
|
-
CaptureStream& commandStream,
|
|
42
|
-
CaptureStream& contentStream);
|
|
43
|
-
|
|
44
|
-
// Ends a capture on the given device.
|
|
45
|
-
DAWN_NATIVE_EXPORT void EndCapture(WGPUDevice device);
|
|
46
|
-
|
|
47
|
-
} // namespace dawn::native::webgpu
|
|
48
|
-
|
|
49
|
-
#endif // INCLUDE_DAWN_NATIVE_WEBGPUBACKEND_H_
|
|
33
|
+
#endif // INCLUDE_WEBGPU_WEBGPU_CPP_PRINT_H_
|
package/lib/commonjs/Canvas.js
CHANGED
|
@@ -13,94 +13,34 @@ let CONTEXT_COUNTER = 1;
|
|
|
13
13
|
function generateContextId() {
|
|
14
14
|
return CONTEXT_COUNTER++;
|
|
15
15
|
}
|
|
16
|
-
const useSizeFabric = ref => {
|
|
17
|
-
const [size, setSize] = (0, _react.useState)(null);
|
|
18
|
-
(0, _react.useLayoutEffect)(() => {
|
|
19
|
-
if (!ref.current) {
|
|
20
|
-
throw new Error("Canvas ref is null");
|
|
21
|
-
}
|
|
22
|
-
ref.current.measureInWindow((_x, _y, width, height) => {
|
|
23
|
-
setSize({
|
|
24
|
-
width,
|
|
25
|
-
height
|
|
26
|
-
});
|
|
27
|
-
});
|
|
28
|
-
}, [ref]);
|
|
29
|
-
return {
|
|
30
|
-
size,
|
|
31
|
-
onLayout: undefined
|
|
32
|
-
};
|
|
33
|
-
};
|
|
34
|
-
const useSizePaper = _ref => {
|
|
35
|
-
const [size, setSize] = (0, _react.useState)(null);
|
|
36
|
-
const onLayout = (0, _react.useCallback)(({
|
|
37
|
-
nativeEvent: {
|
|
38
|
-
layout: {
|
|
39
|
-
width,
|
|
40
|
-
height
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
}) => {
|
|
44
|
-
if (size === null) {
|
|
45
|
-
setSize({
|
|
46
|
-
width,
|
|
47
|
-
height
|
|
48
|
-
});
|
|
49
|
-
}
|
|
50
|
-
}, [size]);
|
|
51
|
-
return {
|
|
52
|
-
size,
|
|
53
|
-
onLayout
|
|
54
|
-
};
|
|
55
|
-
};
|
|
56
16
|
const Canvas = exports.Canvas = /*#__PURE__*/(0, _react.forwardRef)(({
|
|
57
17
|
onLayout: _onLayout,
|
|
58
18
|
transparent,
|
|
59
19
|
...props
|
|
60
20
|
}, ref) => {
|
|
61
21
|
const viewRef = (0, _react.useRef)(null);
|
|
62
|
-
const FABRIC = RNWebGPU.fabric;
|
|
63
|
-
const useSize = FABRIC ? useSizeFabric : useSizePaper;
|
|
64
22
|
const [contextId, _] = (0, _react.useState)(() => generateContextId());
|
|
65
|
-
const cb = (0, _react.useRef)();
|
|
66
|
-
const {
|
|
67
|
-
size,
|
|
68
|
-
onLayout
|
|
69
|
-
} = useSize(viewRef);
|
|
70
|
-
(0, _react.useEffect)(() => {
|
|
71
|
-
if (size && cb.current) {
|
|
72
|
-
cb.current();
|
|
73
|
-
}
|
|
74
|
-
}, [size]);
|
|
75
23
|
(0, _react.useImperativeHandle)(ref, () => ({
|
|
76
24
|
getContextId: () => contextId,
|
|
77
25
|
getNativeSurface: () => {
|
|
78
|
-
if (size === null) {
|
|
79
|
-
throw new Error("[WebGPU] Canvas size is not available yet");
|
|
80
|
-
}
|
|
81
26
|
return RNWebGPU.getNativeSurface(contextId);
|
|
82
27
|
},
|
|
83
|
-
whenReady(callback) {
|
|
84
|
-
if (size === null) {
|
|
85
|
-
cb.current = callback;
|
|
86
|
-
} else {
|
|
87
|
-
callback();
|
|
88
|
-
}
|
|
89
|
-
},
|
|
90
28
|
getContext(contextName) {
|
|
91
29
|
if (contextName !== "webgpu") {
|
|
92
30
|
throw new Error(`[WebGPU] Unsupported context: ${contextName}`);
|
|
93
31
|
}
|
|
94
|
-
if (
|
|
95
|
-
throw new Error("[WebGPU]
|
|
32
|
+
if (!viewRef.current) {
|
|
33
|
+
throw new Error("[WebGPU] Cannot get context before mount");
|
|
96
34
|
}
|
|
35
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
36
|
+
// @ts-expect-error
|
|
37
|
+
const size = viewRef.current.unstable_getBoundingClientRect();
|
|
97
38
|
return RNWebGPU.MakeWebGPUCanvasContext(contextId, size.width, size.height);
|
|
98
39
|
}
|
|
99
40
|
}));
|
|
100
41
|
return /*#__PURE__*/React.createElement(_reactNative.View, _extends({
|
|
101
42
|
collapsable: false,
|
|
102
|
-
ref: viewRef
|
|
103
|
-
onLayout: onLayout
|
|
43
|
+
ref: viewRef
|
|
104
44
|
}, props), /*#__PURE__*/React.createElement(_WebGPUViewNativeComponent.default, {
|
|
105
45
|
style: {
|
|
106
46
|
flex: 1
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_reactNative","require","_react","_WebGPUViewNativeComponent","_interopRequireDefault","e","__esModule","default","_extends","Object","assign","bind","n","arguments","length","t","r","hasOwnProperty","call","apply","CONTEXT_COUNTER","generateContextId","
|
|
1
|
+
{"version":3,"names":["_reactNative","require","_react","_WebGPUViewNativeComponent","_interopRequireDefault","e","__esModule","default","_extends","Object","assign","bind","n","arguments","length","t","r","hasOwnProperty","call","apply","CONTEXT_COUNTER","generateContextId","Canvas","exports","forwardRef","onLayout","_onLayout","transparent","props","ref","viewRef","useRef","contextId","_","useState","useImperativeHandle","getContextId","getNativeSurface","RNWebGPU","getContext","contextName","Error","current","size","unstable_getBoundingClientRect","MakeWebGPUCanvasContext","width","height","React","createElement","View","collapsable","style","flex"],"sourceRoot":"../../src","sources":["Canvas.tsx"],"m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AAS,CAAC;IAC7C,CAAC;IACDO,UAAUA,CAACC,WAAqB,EAA0B;MACxD,IAAIA,WAAW,KAAK,QAAQ,EAAE;QAC5B,MAAM,IAAIC,KAAK,CAAC,iCAAiCD,WAAW,EAAE,CAAC;MACjE;MACA,IAAI,CAACV,OAAO,CAACY,OAAO,EAAE;QACpB,MAAM,IAAID,KAAK,CAAC,0CAA0C,CAAC;MAC7D;MACA;MACA;MACA,MAAME,IAAI,GAAGb,OAAO,CAACY,OAAO,CAACE,8BAA8B,CAAC,CAAC;MAC7D,OAAON,QAAQ,CAACO,uBAAuB,CACrCb,SAAS,EACTW,IAAI,CAACG,KAAK,EACVH,IAAI,CAACI,MACP,CAAC;IACH;EACF,CAAC,CAAC,CAAC;EACH,oBACEC,KAAA,CAAAC,aAAA,CAACjD,YAAA,CAAAkD,IAAI,EAAA1C,QAAA;IAAC2C,WAAW,EAAE,KAAM;IAACtB,GAAG,EAAEC;EAAQ,GAAKF,KAAK,gBAC/CoB,KAAA,CAAAC,aAAA,CAAC9C,0BAAA,CAAAI,OAAgB;IACf6C,KAAK,EAAE;MAAEC,IAAI,EAAE;IAAE,CAAE;IACnBrB,SAAS,EAAEA,SAAU;IACrBL,WAAW,EAAE,CAAC,CAACA;EAAY,CAC5B,CACG,CAAC;AAEX,CAAC,CAAC","ignoreList":[]}
|
package/lib/commonjs/hooks.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.warnIfNotHardwareAccelerated = exports.useSurface = exports.useMainDevice = exports.
|
|
6
|
+
exports.warnIfNotHardwareAccelerated = exports.useSurface = exports.useMainDevice = exports.useDevice = exports.useCanvasRef = exports.GPUDeviceProvider = void 0;
|
|
7
7
|
var _react = require("react");
|
|
8
8
|
const warnIfNotHardwareAccelerated = adapter => {
|
|
9
9
|
// Check if adapter is a fallback adapter using the new GPUAdapterInfo API
|
|
@@ -29,11 +29,12 @@ const GPUDeviceProvider = ({
|
|
|
29
29
|
};
|
|
30
30
|
exports.GPUDeviceProvider = GPUDeviceProvider;
|
|
31
31
|
const useSurface = () => {
|
|
32
|
+
const ref = (0, _react.useRef)(null);
|
|
32
33
|
const [surface, setSurface] = (0, _react.useState)(null);
|
|
33
|
-
|
|
34
|
+
(0, _react.useLayoutEffect)(() => {
|
|
34
35
|
const sur = ref.current.getNativeSurface();
|
|
35
36
|
setSurface(sur);
|
|
36
|
-
});
|
|
37
|
+
}, []);
|
|
37
38
|
return {
|
|
38
39
|
ref,
|
|
39
40
|
surface
|
|
@@ -48,6 +49,8 @@ const useMainDevice = () => {
|
|
|
48
49
|
return ctx;
|
|
49
50
|
};
|
|
50
51
|
exports.useMainDevice = useMainDevice;
|
|
52
|
+
const useCanvasRef = () => (0, _react.useRef)(null);
|
|
53
|
+
exports.useCanvasRef = useCanvasRef;
|
|
51
54
|
const useDevice = (adapterOptions, deviceDescriptor) => {
|
|
52
55
|
const [state, setState] = (0, _react.useState)(null);
|
|
53
56
|
(0, _react.useEffect)(() => {
|
|
@@ -76,43 +79,4 @@ const useDevice = (adapterOptions, deviceDescriptor) => {
|
|
|
76
79
|
};
|
|
77
80
|
};
|
|
78
81
|
exports.useDevice = useDevice;
|
|
79
|
-
const useGPUContext = () => {
|
|
80
|
-
const [context, setContext] = (0, _react.useState)(null);
|
|
81
|
-
const ref = useCanvasEffect(() => {
|
|
82
|
-
const ctx = ref.current.getContext("webgpu");
|
|
83
|
-
setContext(ctx);
|
|
84
|
-
});
|
|
85
|
-
return {
|
|
86
|
-
ref,
|
|
87
|
-
context
|
|
88
|
-
};
|
|
89
|
-
};
|
|
90
|
-
exports.useGPUContext = useGPUContext;
|
|
91
|
-
const useCanvasEffect = effect => {
|
|
92
|
-
const unsub = (0, _react.useRef)(null);
|
|
93
|
-
const ref = (0, _react.useRef)(null);
|
|
94
|
-
(0, _react.useEffect)(() => {
|
|
95
|
-
if (!ref.current || !ref.current.whenReady) {
|
|
96
|
-
throw new Error("The reference is not assigned to a WebGPU Canvas");
|
|
97
|
-
}
|
|
98
|
-
ref.current.whenReady(async () => {
|
|
99
|
-
const sub = effect();
|
|
100
|
-
if (sub) {
|
|
101
|
-
unsub.current = sub;
|
|
102
|
-
}
|
|
103
|
-
});
|
|
104
|
-
return () => {
|
|
105
|
-
if (unsub.current) {
|
|
106
|
-
if (unsub.current instanceof Promise) {
|
|
107
|
-
unsub.current.then(sub => sub && sub());
|
|
108
|
-
} else {
|
|
109
|
-
unsub.current();
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
};
|
|
113
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
114
|
-
}, []);
|
|
115
|
-
return ref;
|
|
116
|
-
};
|
|
117
|
-
exports.useCanvasEffect = useCanvasEffect;
|
|
118
82
|
//# sourceMappingURL=hooks.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_react","require","warnIfNotHardwareAccelerated","adapter","info","isFallbackAdapter","console","warn","exports","DeviceContext","createContext","GPUDeviceProvider","children","adapterOptions","deviceDescriptor","state","useDevice","device","React","createElement","Provider","value","useSurface","surface","setSurface","useState","
|
|
1
|
+
{"version":3,"names":["_react","require","warnIfNotHardwareAccelerated","adapter","info","isFallbackAdapter","console","warn","exports","DeviceContext","createContext","GPUDeviceProvider","children","adapterOptions","deviceDescriptor","state","useDevice","device","React","createElement","Provider","value","useSurface","ref","useRef","surface","setSurface","useState","useLayoutEffect","sur","current","getNativeSurface","useMainDevice","ctx","useContext","Error","useCanvasRef","setState","useEffect","navigator","gpu","requestAdapter","requestDevice"],"sourceRoot":"../../src","sources":["hooks.tsx"],"mappings":";;;;;;AACA,IAAAA,MAAA,GAAAC,OAAA;AAWO,MAAMC,4BAA4B,GAAIC,OAAmB,IAAK;EACnE;EACA;EACA,IAAIA,OAAO,CAACC,IAAI,IAAID,OAAO,CAACC,IAAI,CAACC,iBAAiB,EAAE;IAClDC,OAAO,CAAC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AAGA,CAAA,KAAM,IAAAZ,aAAM,EAAY,IAAI,CAAC;AAAChB,OAAA,CAAA4B,YAAA,GAAAA,YAAA;AAEnD,MAAMpB,SAAS,GAAGA,CACvBH,cAAyC,EACzCC,gBAAsC,KACnC;EACH,MAAM,CAACC,KAAK,EAAEsB,QAAQ,CAAC,GAAG,IAAAV,eAAQ,EAAuB,IAAI,CAAC;EAC9D,IAAAW,gBAAS,EAAC,MAAM;IACd,CAAC,YAAY;MACX,IAAI,CAACvB,KAAK,EAAE;QACV,MAAMZ,OAAO,GAAG,MAAMoC,SAAS,CAACC,GAAG,CAACC,cAAc,CAAC5B,cAAc,CAAC;QAClE,IAAI,CAACV,OAAO,EAAE;UACZ,MAAM,IAAIgC,KAAK,CAAC,kCAAkC,CAAC;QACrD;QACAjC,4BAA4B,CAACC,OAAO,CAAC;QACrC,MAAMc,MAAM,GAAG,MAAMd,OAAO,CAACuC,aAAa,CAAC5B,gBAAgB,CAAC;QAC5D,IAAI,CAACG,MAAM,EAAE;UACX,MAAM,IAAIkB,KAAK,CAAC,iCAAiC,CAAC;QACpD;QACAE,QAAQ,CAAC;UAAElC,OAAO;UAAEc;QAAO,CAAC,CAAC;QAC7B;MACF;IACF,CAAC,EAAE,CAAC;EACN,CAAC,EAAE,CAACJ,cAAc,EAAEC,gBAAgB,EAAEC,KAAK,CAAC,CAAC;EAC7C,OAAO;IAAEZ,OAAO,EAAEY,KAAK,EAAEZ,OAAO,IAAI,IAAI;IAAEc,MAAM,EAAEF,KAAK,EAAEE,MAAM,IAAI;EAAK,CAAC;AAC3E,CAAC;AAACT,OAAA,CAAAQ,SAAA,GAAAA,SAAA","ignoreList":[]}
|
package/lib/module/Canvas.js
CHANGED
|
@@ -1,99 +1,39 @@
|
|
|
1
1
|
function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
|
|
2
2
|
import { View } from "react-native";
|
|
3
|
-
import { forwardRef,
|
|
3
|
+
import { forwardRef, useImperativeHandle, useRef, useState } from "react";
|
|
4
4
|
import WebGPUNativeView from "./WebGPUViewNativeComponent";
|
|
5
5
|
let CONTEXT_COUNTER = 1;
|
|
6
6
|
function generateContextId() {
|
|
7
7
|
return CONTEXT_COUNTER++;
|
|
8
8
|
}
|
|
9
|
-
const useSizeFabric = ref => {
|
|
10
|
-
const [size, setSize] = useState(null);
|
|
11
|
-
useLayoutEffect(() => {
|
|
12
|
-
if (!ref.current) {
|
|
13
|
-
throw new Error("Canvas ref is null");
|
|
14
|
-
}
|
|
15
|
-
ref.current.measureInWindow((_x, _y, width, height) => {
|
|
16
|
-
setSize({
|
|
17
|
-
width,
|
|
18
|
-
height
|
|
19
|
-
});
|
|
20
|
-
});
|
|
21
|
-
}, [ref]);
|
|
22
|
-
return {
|
|
23
|
-
size,
|
|
24
|
-
onLayout: undefined
|
|
25
|
-
};
|
|
26
|
-
};
|
|
27
|
-
const useSizePaper = _ref => {
|
|
28
|
-
const [size, setSize] = useState(null);
|
|
29
|
-
const onLayout = useCallback(({
|
|
30
|
-
nativeEvent: {
|
|
31
|
-
layout: {
|
|
32
|
-
width,
|
|
33
|
-
height
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
}) => {
|
|
37
|
-
if (size === null) {
|
|
38
|
-
setSize({
|
|
39
|
-
width,
|
|
40
|
-
height
|
|
41
|
-
});
|
|
42
|
-
}
|
|
43
|
-
}, [size]);
|
|
44
|
-
return {
|
|
45
|
-
size,
|
|
46
|
-
onLayout
|
|
47
|
-
};
|
|
48
|
-
};
|
|
49
9
|
export const Canvas = /*#__PURE__*/forwardRef(({
|
|
50
10
|
onLayout: _onLayout,
|
|
51
11
|
transparent,
|
|
52
12
|
...props
|
|
53
13
|
}, ref) => {
|
|
54
14
|
const viewRef = useRef(null);
|
|
55
|
-
const FABRIC = RNWebGPU.fabric;
|
|
56
|
-
const useSize = FABRIC ? useSizeFabric : useSizePaper;
|
|
57
15
|
const [contextId, _] = useState(() => generateContextId());
|
|
58
|
-
const cb = useRef();
|
|
59
|
-
const {
|
|
60
|
-
size,
|
|
61
|
-
onLayout
|
|
62
|
-
} = useSize(viewRef);
|
|
63
|
-
useEffect(() => {
|
|
64
|
-
if (size && cb.current) {
|
|
65
|
-
cb.current();
|
|
66
|
-
}
|
|
67
|
-
}, [size]);
|
|
68
16
|
useImperativeHandle(ref, () => ({
|
|
69
17
|
getContextId: () => contextId,
|
|
70
18
|
getNativeSurface: () => {
|
|
71
|
-
if (size === null) {
|
|
72
|
-
throw new Error("[WebGPU] Canvas size is not available yet");
|
|
73
|
-
}
|
|
74
19
|
return RNWebGPU.getNativeSurface(contextId);
|
|
75
20
|
},
|
|
76
|
-
whenReady(callback) {
|
|
77
|
-
if (size === null) {
|
|
78
|
-
cb.current = callback;
|
|
79
|
-
} else {
|
|
80
|
-
callback();
|
|
81
|
-
}
|
|
82
|
-
},
|
|
83
21
|
getContext(contextName) {
|
|
84
22
|
if (contextName !== "webgpu") {
|
|
85
23
|
throw new Error(`[WebGPU] Unsupported context: ${contextName}`);
|
|
86
24
|
}
|
|
87
|
-
if (
|
|
88
|
-
throw new Error("[WebGPU]
|
|
25
|
+
if (!viewRef.current) {
|
|
26
|
+
throw new Error("[WebGPU] Cannot get context before mount");
|
|
89
27
|
}
|
|
28
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
29
|
+
// @ts-expect-error
|
|
30
|
+
const size = viewRef.current.unstable_getBoundingClientRect();
|
|
90
31
|
return RNWebGPU.MakeWebGPUCanvasContext(contextId, size.width, size.height);
|
|
91
32
|
}
|
|
92
33
|
}));
|
|
93
34
|
return /*#__PURE__*/React.createElement(View, _extends({
|
|
94
35
|
collapsable: false,
|
|
95
|
-
ref: viewRef
|
|
96
|
-
onLayout: onLayout
|
|
36
|
+
ref: viewRef
|
|
97
37
|
}, props), /*#__PURE__*/React.createElement(WebGPUNativeView, {
|
|
98
38
|
style: {
|
|
99
39
|
flex: 1
|
package/lib/module/Canvas.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["View","forwardRef","
|
|
1
|
+
{"version":3,"names":["View","forwardRef","useImperativeHandle","useRef","useState","WebGPUNativeView","CONTEXT_COUNTER","generateContextId","Canvas","onLayout","_onLayout","transparent","props","ref","viewRef","contextId","_","getContextId","getNativeSurface","RNWebGPU","getContext","contextName","Error","current","size","unstable_getBoundingClientRect","MakeWebGPUCanvasContext","width","height","React","createElement","_extends","collapsable","style","flex"],"sourceRoot":"../../src","sources":["Canvas.tsx"],"mappings":";AACA,SAASA,IAAI,QAAQ,cAAc;AACnC,SAASC,UAAU,EAAEC,mBAAmB,EAAEC,MAAM,EAAEC,QAAQ,QAAQ,OAAO;AAEzE,OAAOC,gBAAgB,MAAM,6BAA6B;AAE1D,IAAIC,eAAe,GAAG,CAAC;AACvB,SAASC,iBAAiBA,CAAA,EAAG;EAC3B,OAAOD,eAAe,EAAE;AAC1B;AAqCA,OAAO,MAAME,MAAM,gBAAGP,UAAU,CAG9B,CAAC;EAAEQ,QAAQ,EAAEC,SAAS;EAAEC,WAAW;EAAE,GAAGC;AAAM,CAAC,EAAEC,GAAG,KAAK;EACzD,MAAMC,OAAO,GAAGX,MAAM,CAAC,IAAI,CAAC;EAC5B,MAAM,CAACY,SAAS,EAAEC,CAAC,CAAC,GAAGZ,QAAQ,CAAC,MAAMG,iBAAiB,CAAC,CAAC,CAAC;EAC1DL,mBAAmB,CAACW,GAAG,EAAE,OAAO;IAC9BI,YAAY,EAAEA,CAAA,KAAMF,SAAS;IAC7BG,gBAAgB,EAAEA,CAAA,KAAM;MACtB,OAAOC,QAAQ,CAACD,gBAAgB,CAACH,SAAS,CAAC;IAC7C,CAAC;IACDK,UAAUA,CAACC,WAAqB,EAA0B;MACxD,IAAIA,WAAW,KAAK,QAAQ,EAAE;QAC5B,MAAM,IAAIC,KAAK,CAAC,iCAAiCD,WAAW,EAAE,CAAC;MACjE;MACA,IAAI,CAACP,OAAO,CAACS,OAAO,EAAE;QACpB,MAAM,IAAID,KAAK,CAAC,0CAA0C,CAAC;MAC7D;MACA;MACA;MACA,MAAME,IAAI,GAAGV,OAAO,CAACS,OAAO,CAACE,8BAA8B,CAAC,CAAC;MAC7D,OAAON,QAAQ,CAACO,uBAAuB,CACrCX,SAAS,EACTS,IAAI,CAACG,KAAK,EACVH,IAAI,CAACI,MACP,CAAC;IACH;EACF,CAAC,CAAC,CAAC;EACH,oBACEC,KAAA,CAAAC,aAAA,CAAC9B,IAAI,EAAA+B,QAAA;IAACC,WAAW,EAAE,KAAM;IAACnB,GAAG,EAAEC;EAAQ,GAAKF,KAAK,gBAC/CiB,KAAA,CAAAC,aAAA,CAACzB,gBAAgB;IACf4B,KAAK,EAAE;MAAEC,IAAI,EAAE;IAAE,CAAE;IACnBnB,SAAS,EAAEA,SAAU;IACrBJ,WAAW,EAAE,CAAC,CAACA;EAAY,CAC5B,CACG,CAAC;AAEX,CAAC,CAAC","ignoreList":[]}
|
package/lib/module/hooks.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { createContext, useContext, useEffect, useRef, useState } from "react";
|
|
1
|
+
import { createContext, useContext, useEffect, useLayoutEffect, useRef, useState } from "react";
|
|
2
2
|
export const warnIfNotHardwareAccelerated = adapter => {
|
|
3
3
|
// Check if adapter is a fallback adapter using the new GPUAdapterInfo API
|
|
4
4
|
// Note: isFallbackAdapter was moved from GPUAdapter to GPUAdapterInfo in Chrome 140
|
|
@@ -21,11 +21,12 @@ export const GPUDeviceProvider = ({
|
|
|
21
21
|
}, children);
|
|
22
22
|
};
|
|
23
23
|
export const useSurface = () => {
|
|
24
|
+
const ref = useRef(null);
|
|
24
25
|
const [surface, setSurface] = useState(null);
|
|
25
|
-
|
|
26
|
+
useLayoutEffect(() => {
|
|
26
27
|
const sur = ref.current.getNativeSurface();
|
|
27
28
|
setSurface(sur);
|
|
28
|
-
});
|
|
29
|
+
}, []);
|
|
29
30
|
return {
|
|
30
31
|
ref,
|
|
31
32
|
surface
|
|
@@ -38,6 +39,7 @@ export const useMainDevice = () => {
|
|
|
38
39
|
}
|
|
39
40
|
return ctx;
|
|
40
41
|
};
|
|
42
|
+
export const useCanvasRef = () => useRef(null);
|
|
41
43
|
export const useDevice = (adapterOptions, deviceDescriptor) => {
|
|
42
44
|
const [state, setState] = useState(null);
|
|
43
45
|
useEffect(() => {
|
|
@@ -65,41 +67,4 @@ export const useDevice = (adapterOptions, deviceDescriptor) => {
|
|
|
65
67
|
device: state?.device ?? null
|
|
66
68
|
};
|
|
67
69
|
};
|
|
68
|
-
export const useGPUContext = () => {
|
|
69
|
-
const [context, setContext] = useState(null);
|
|
70
|
-
const ref = useCanvasEffect(() => {
|
|
71
|
-
const ctx = ref.current.getContext("webgpu");
|
|
72
|
-
setContext(ctx);
|
|
73
|
-
});
|
|
74
|
-
return {
|
|
75
|
-
ref,
|
|
76
|
-
context
|
|
77
|
-
};
|
|
78
|
-
};
|
|
79
|
-
export const useCanvasEffect = effect => {
|
|
80
|
-
const unsub = useRef(null);
|
|
81
|
-
const ref = useRef(null);
|
|
82
|
-
useEffect(() => {
|
|
83
|
-
if (!ref.current || !ref.current.whenReady) {
|
|
84
|
-
throw new Error("The reference is not assigned to a WebGPU Canvas");
|
|
85
|
-
}
|
|
86
|
-
ref.current.whenReady(async () => {
|
|
87
|
-
const sub = effect();
|
|
88
|
-
if (sub) {
|
|
89
|
-
unsub.current = sub;
|
|
90
|
-
}
|
|
91
|
-
});
|
|
92
|
-
return () => {
|
|
93
|
-
if (unsub.current) {
|
|
94
|
-
if (unsub.current instanceof Promise) {
|
|
95
|
-
unsub.current.then(sub => sub && sub());
|
|
96
|
-
} else {
|
|
97
|
-
unsub.current();
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
};
|
|
101
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
102
|
-
}, []);
|
|
103
|
-
return ref;
|
|
104
|
-
};
|
|
105
70
|
//# sourceMappingURL=hooks.js.map
|
package/lib/module/hooks.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["createContext","useContext","useEffect","useRef","useState","warnIfNotHardwareAccelerated","adapter","info","isFallbackAdapter","console","warn","DeviceContext","GPUDeviceProvider","children","adapterOptions","deviceDescriptor","state","useDevice","device","React","createElement","Provider","value","useSurface","
|
|
1
|
+
{"version":3,"names":["createContext","useContext","useEffect","useLayoutEffect","useRef","useState","warnIfNotHardwareAccelerated","adapter","info","isFallbackAdapter","console","warn","DeviceContext","GPUDeviceProvider","children","adapterOptions","deviceDescriptor","state","useDevice","device","React","createElement","Provider","value","useSurface","ref","surface","setSurface","sur","current","getNativeSurface","useMainDevice","ctx","Error","useCanvasRef","setState","navigator","gpu","requestAdapter","requestDevice"],"sourceRoot":"../../src","sources":["hooks.tsx"],"mappings":"AACA,SACEA,aAAa,EACbC,UAAU,EACVC,SAAS,EACTC,eAAe,EACfC,MAAM,EACNC,QAAQ,QACH,OAAO;AAId,OAAO,MAAMC,4BAA4B,GAAIC,OAAmB,IAAK;EACnE;EACA;EACA,IAAIA,OAAO,CAACC,IAAI,IAAID,OAAO,CAACC,IAAI,CAACC,iBAAiB,EAAE;IAClDC,OAAO,CAACC,IAAI,CACV,wIACF,CAAC;EACH;AACF,CAAC;AAOD,MAAMC,aAAa,gBAAGZ,aAAa,CAAuB,IAAI,CAAC;AAQ/D,OAAO,MAAMa,iBAAiB,GAAGA,CAAC;EAChCC,QAAQ;EACRC,cAAc;EACdC;AACmB,CAAC,KAAK;EACzB,MAAMC,KAAK,GAAGC,SAAS,CAACH,cAAc,EAAEC,gBAAgB,CAAC;EACzD,IAAI,CAACC,KAAK,CAACE,MAAM,EAAE;IACjB,OAAO,IAAI;EACb;EACA,oBACEC,KAAA,CAAAC,aAAA,CAACT,aAAa,CAACU,QAAQ;IAACC,KAAK,EAAEN;EAAM,GAAEH,QA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AAIc,KAAK,CAAC,iCAAiC,CAAC;QACpD;QACAE,QAAQ,CAAC;UAAE5B,OAAO;UAAEY;QAAO,CAAC,CAAC;QAC7B;MACF;IACF,CAAC,EAAE,CAAC;EACN,CAAC,EAAE,CAACJ,cAAc,EAAEC,gBAAgB,EAAEC,KAAK,CAAC,CAAC;EAC7C,OAAO;IAAEV,OAAO,EAAEU,KAAK,EAAEV,OAAO,IAAI,IAAI;IAAEY,MAAM,EAAEF,KAAK,EAAEE,MAAM,IAAI;EAAK,CAAC;AAC3E,CAAC","ignoreList":[]}
|
|
@@ -10,14 +10,10 @@ export function useSurface(): {
|
|
|
10
10
|
surface: null;
|
|
11
11
|
};
|
|
12
12
|
export function useMainDevice(): never;
|
|
13
|
+
export function useCanvasRef(): _react.MutableRefObject<null>;
|
|
13
14
|
export function useDevice(adapterOptions: any, deviceDescriptor: any): {
|
|
14
15
|
adapter: any;
|
|
15
16
|
device: any;
|
|
16
17
|
};
|
|
17
|
-
export function useGPUContext(): {
|
|
18
|
-
ref: _react.MutableRefObject<null>;
|
|
19
|
-
context: null;
|
|
20
|
-
};
|
|
21
|
-
export function useCanvasEffect(effect: any): _react.MutableRefObject<null>;
|
|
22
18
|
import _react = require("react");
|
|
23
19
|
//# sourceMappingURL=hooks.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hooks.d.ts","sourceRoot":"","sources":["../../../commonjs/hooks.js"],"names":[],"mappings":";AAOA,iEAMC;AAGD;;;;2GAYC;AAED;;;
|
|
1
|
+
{"version":3,"file":"hooks.d.ts","sourceRoot":"","sources":["../../../commonjs/hooks.js"],"names":[],"mappings":";AAOA,iEAMC;AAGD;;;;2GAYC;AAED;;;EAWC;AAED,uCAMC;AAED,8DAAmD;AAEnD;;;EA0BC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Canvas.d.ts","sourceRoot":"","sources":["../../../module/Canvas.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"Canvas.d.ts","sourceRoot":"","sources":["../../../module/Canvas.js"],"names":[],"mappings":"AAQA,mGAmCG"}
|
|
@@ -9,13 +9,9 @@ export function useSurface(): {
|
|
|
9
9
|
surface: null;
|
|
10
10
|
};
|
|
11
11
|
export function useMainDevice(): never;
|
|
12
|
+
export function useCanvasRef(): import("react").MutableRefObject<null>;
|
|
12
13
|
export function useDevice(adapterOptions: any, deviceDescriptor: any): {
|
|
13
14
|
adapter: any;
|
|
14
15
|
device: any;
|
|
15
16
|
};
|
|
16
|
-
export function useGPUContext(): {
|
|
17
|
-
ref: import("react").MutableRefObject<null>;
|
|
18
|
-
context: null;
|
|
19
|
-
};
|
|
20
|
-
export function useCanvasEffect(effect: any): import("react").MutableRefObject<null>;
|
|
21
17
|
//# sourceMappingURL=hooks.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hooks.d.ts","sourceRoot":"","sources":["../../../module/hooks.js"],"names":[],"mappings":"AACO,iEAMN;AAEM;;;;6HAYN;AACM;;;
|
|
1
|
+
{"version":3,"file":"hooks.d.ts","sourceRoot":"","sources":["../../../module/hooks.js"],"names":[],"mappings":"AACO,iEAMN;AAEM;;;;6HAYN;AACM;;;EAWN;AACM,uCAMN;AACM,uEAAuC;AACvC;;;EA0BN"}
|
|
@@ -24,7 +24,6 @@ export interface CanvasRef {
|
|
|
24
24
|
getContextId: () => number;
|
|
25
25
|
getContext(contextName: "webgpu"): RNCanvasContext | null;
|
|
26
26
|
getNativeSurface: () => NativeCanvas;
|
|
27
|
-
whenReady: (callback: () => void) => void;
|
|
28
27
|
}
|
|
29
28
|
export declare const Canvas: import("react").ForwardRefExoticComponent<ViewProps & {
|
|
30
29
|
transparent?: boolean;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Canvas.d.ts","sourceRoot":"","sources":["../../../src/Canvas.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,
|
|
1
|
+
{"version":3,"file":"Canvas.d.ts","sourceRoot":"","sources":["../../../src/Canvas.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAW9C,OAAO,CAAC,MAAM,CAAC;IACb,IAAI,QAAQ,EAAE;QACZ,GAAG,EAAE,GAAG,CAAC;QACT,MAAM,EAAE,OAAO,CAAC;QAChB,gBAAgB,EAAE,CAAC,SAAS,EAAE,MAAM,KAAK,YAAY,CAAC;QACtD,uBAAuB,EAAE,CACvB,SAAS,EAAE,MAAM,EACjB,KAAK,EAAE,MAAM,EACb,MAAM,EAAE,MAAM,KACX,eAAe,CAAC;QACrB,YAAY,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,eAAe,GAAG,WAAW,KAAK,MAAM,CAAC;QACvE,iBAAiB,EAAE,OAAO,iBAAiB,CAAC;KAC7C,CAAC;CACH;AAED,KAAK,cAAc,GAAG,MAAM,CAAC;AAE7B,MAAM,WAAW,YAAY;IAC3B,OAAO,EAAE,cAAc,CAAC;IACxB,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,WAAW,EAAE,MAAM,CAAC;IACpB,YAAY,EAAE,MAAM,CAAC;CACtB;AAED,MAAM,MAAM,eAAe,GAAG,gBAAgB,GAAG;IAC/C,OAAO,EAAE,MAAM,IAAI,CAAC;CACrB,CAAC;AAEF,MAAM,WAAW,SAAS;IACxB,YAAY,EAAE,MAAM,MAAM,CAAC;IAC3B,UAAU,CAAC,WAAW,EAAE,QAAQ,GAAG,eAAe,GAAG,IAAI,CAAC;IAC1D,gBAAgB,EAAE,MAAM,YAAY,CAAC;CACtC;AAED,eAAO,MAAM,MAAM;kBAEW,OAAO;6CAmCnC,CAAC"}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import type { ReactNode } from "react";
|
|
2
|
-
import type {
|
|
3
|
-
type Unsubscribe = () => void;
|
|
2
|
+
import type { CanvasRef, NativeCanvas } from "./Canvas";
|
|
4
3
|
export declare const warnIfNotHardwareAccelerated: (adapter: GPUAdapter) => void;
|
|
5
4
|
interface DeviceContext {
|
|
6
5
|
device: GPUDevice | null;
|
|
@@ -18,14 +17,10 @@ export declare const useSurface: () => {
|
|
|
18
17
|
surface: NativeCanvas | null;
|
|
19
18
|
};
|
|
20
19
|
export declare const useMainDevice: () => DeviceContext;
|
|
20
|
+
export declare const useCanvasRef: () => import("react").RefObject<CanvasRef>;
|
|
21
21
|
export declare const useDevice: (adapterOptions?: GPURequestAdapterOptions, deviceDescriptor?: GPUDeviceDescriptor) => {
|
|
22
22
|
adapter: GPUAdapter | null;
|
|
23
23
|
device: GPUDevice | null;
|
|
24
24
|
};
|
|
25
|
-
export declare const useGPUContext: () => {
|
|
26
|
-
ref: import("react").RefObject<CanvasRef>;
|
|
27
|
-
context: RNCanvasContext | null;
|
|
28
|
-
};
|
|
29
|
-
export declare const useCanvasEffect: (effect: () => void | Unsubscribe | Promise<Unsubscribe | void> | Promise<void>) => import("react").RefObject<CanvasRef>;
|
|
30
25
|
export {};
|
|
31
26
|
//# sourceMappingURL=hooks.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hooks.d.ts","sourceRoot":"","sources":["../../../src/hooks.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"hooks.d.ts","sourceRoot":"","sources":["../../../src/hooks.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAUvC,OAAO,KAAK,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAExD,eAAO,MAAM,4BAA4B,GAAI,SAAS,UAAU,SAQ/D,CAAC;AAEF,UAAU,aAAa;IACrB,MAAM,EAAE,SAAS,GAAG,IAAI,CAAC;IACzB,OAAO,EAAE,UAAU,GAAG,IAAI,CAAC;CAC5B;AAED,QAAA,MAAM,aAAa,+CAA4C,CAAC;AAEhE,UAAU,mBAAmB;IAC3B,QAAQ,CAAC,EAAE,SAAS,GAAG,SAAS,EAAE,CAAC;IACnC,cAAc,CAAC,EAAE,wBAAwB,CAAC;IAC1C,gBAAgB,CAAC,EAAE,mBAAmB,CAAC;CACxC;AAED,eAAO,MAAM,iBAAiB,GAAI,iDAI/B,mBAAmB,uCAQrB,CAAC;AAEF,eAAO,MAAM,UAAU;;;CAQtB,CAAC;AAEF,eAAO,MAAM,aAAa,qBAMzB,CAAC;AAEF,eAAO,MAAM,YAAY,4CAAgC,CAAC;AAE1D,eAAO,MAAM,SAAS,GACpB,iBAAiB,wBAAwB,EACzC,mBAAmB,mBAAmB;;;CAqBvC,CAAC"}
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
@@ -8,22 +8,7 @@
|
|
|
8
8
|
<key>BinaryPath</key>
|
|
9
9
|
<string>libwebgpu_dawn.a</string>
|
|
10
10
|
<key>LibraryIdentifier</key>
|
|
11
|
-
<string>
|
|
12
|
-
<key>LibraryPath</key>
|
|
13
|
-
<string>libwebgpu_dawn.a</string>
|
|
14
|
-
<key>SupportedArchitectures</key>
|
|
15
|
-
<array>
|
|
16
|
-
<string>arm64</string>
|
|
17
|
-
<string>x86_64</string>
|
|
18
|
-
</array>
|
|
19
|
-
<key>SupportedPlatform</key>
|
|
20
|
-
<string>macos</string>
|
|
21
|
-
</dict>
|
|
22
|
-
<dict>
|
|
23
|
-
<key>BinaryPath</key>
|
|
24
|
-
<string>libwebgpu_dawn.a</string>
|
|
25
|
-
<key>LibraryIdentifier</key>
|
|
26
|
-
<string>xros-arm64</string>
|
|
11
|
+
<string>ios-arm64</string>
|
|
27
12
|
<key>LibraryPath</key>
|
|
28
13
|
<string>libwebgpu_dawn.a</string>
|
|
29
14
|
<key>SupportedArchitectures</key>
|
|
@@ -31,7 +16,7 @@
|
|
|
31
16
|
<string>arm64</string>
|
|
32
17
|
</array>
|
|
33
18
|
<key>SupportedPlatform</key>
|
|
34
|
-
<string>
|
|
19
|
+
<string>ios</string>
|
|
35
20
|
</dict>
|
|
36
21
|
<dict>
|
|
37
22
|
<key>BinaryPath</key>
|
|
@@ -54,31 +39,16 @@
|
|
|
54
39
|
<key>BinaryPath</key>
|
|
55
40
|
<string>libwebgpu_dawn.a</string>
|
|
56
41
|
<key>LibraryIdentifier</key>
|
|
57
|
-
<string>
|
|
58
|
-
<key>LibraryPath</key>
|
|
59
|
-
<string>libwebgpu_dawn.a</string>
|
|
60
|
-
<key>SupportedArchitectures</key>
|
|
61
|
-
<array>
|
|
62
|
-
<string>arm64</string>
|
|
63
|
-
</array>
|
|
64
|
-
<key>SupportedPlatform</key>
|
|
65
|
-
<string>ios</string>
|
|
66
|
-
</dict>
|
|
67
|
-
<dict>
|
|
68
|
-
<key>BinaryPath</key>
|
|
69
|
-
<string>libwebgpu_dawn.a</string>
|
|
70
|
-
<key>LibraryIdentifier</key>
|
|
71
|
-
<string>xros-arm64-simulator</string>
|
|
42
|
+
<string>macos-arm64_x86_64</string>
|
|
72
43
|
<key>LibraryPath</key>
|
|
73
44
|
<string>libwebgpu_dawn.a</string>
|
|
74
45
|
<key>SupportedArchitectures</key>
|
|
75
46
|
<array>
|
|
76
47
|
<string>arm64</string>
|
|
48
|
+
<string>x86_64</string>
|
|
77
49
|
</array>
|
|
78
50
|
<key>SupportedPlatform</key>
|
|
79
|
-
<string>
|
|
80
|
-
<key>SupportedPlatformVariant</key>
|
|
81
|
-
<string>simulator</string>
|
|
51
|
+
<string>macos</string>
|
|
82
52
|
</dict>
|
|
83
53
|
</array>
|
|
84
54
|
<key>CFBundlePackageType</key>
|
|
Binary file
|