react-native-wgpu 0.1.0 → 0.1.3
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 +221 -13
- package/android/CMakeLists.txt +15 -1
- package/android/build.gradle +0 -18
- package/android/cpp/AndroidPlatformContext.h +132 -0
- package/android/cpp/cpp-adapter.cpp +70 -4
- package/android/src/main/java/com/webgpu/WebGPUModule.java +69 -21
- package/android/src/main/java/com/webgpu/WebGPUView.java +63 -8
- package/android/src/main/java/com/webgpu/WebGPUViewManager.java +5 -6
- package/android/src/newarch/{WgpuViewManagerSpec.java → com/webgpu/WebGPUViewManagerSpec.java} +5 -5
- package/android/src/oldarch/com/webgpu/NativeWebGPUModuleSpec.java +23 -0
- package/android/src/oldarch/{WebGPUViewManagerSpec.java → com/webgpu/WebGPUViewManagerSpec.java} +1 -1
- package/cpp/{Logger.h → WGPULogger.h} +13 -6
- package/cpp/dawn/webgpu.h +9 -0
- package/cpp/dawn/webgpu_cpp.h +95 -43
- package/cpp/dawn/webgpu_cpp_print.h +6 -0
- package/cpp/dawn/wire/client/webgpu_cpp.h +80 -43
- package/cpp/jsi/RNFHybridObject.cpp +1 -1
- package/cpp/jsi/RNFHybridObject.h +4 -4
- package/cpp/jsi/RNFJSIConverter.h +204 -17
- package/cpp/rnwgpu/ArrayBuffer.h +72 -0
- package/cpp/rnwgpu/PlatformContext.h +29 -0
- package/cpp/rnwgpu/RNWebGPUManager.cpp +13 -11
- package/cpp/rnwgpu/RNWebGPUManager.h +9 -1
- package/cpp/rnwgpu/SurfaceRegistry.h +36 -0
- package/cpp/rnwgpu/api/AsyncRunner.h +30 -0
- package/cpp/rnwgpu/api/Canvas.h +55 -0
- package/cpp/rnwgpu/api/Convertors.h +765 -0
- package/cpp/rnwgpu/api/External.h +12 -0
- package/cpp/rnwgpu/api/GPU.cpp +81 -23
- package/cpp/rnwgpu/api/GPU.h +24 -6
- package/cpp/rnwgpu/api/GPUAdapter.cpp +138 -24
- package/cpp/rnwgpu/api/GPUAdapter.h +24 -5
- package/cpp/rnwgpu/api/GPUAdapterInfo.h +19 -7
- package/cpp/rnwgpu/api/GPUBindGroup.cpp +3 -0
- package/cpp/rnwgpu/api/GPUBindGroup.h +11 -4
- package/cpp/rnwgpu/api/GPUBindGroupLayout.h +11 -4
- package/cpp/rnwgpu/api/GPUBuffer.cpp +82 -7
- package/cpp/rnwgpu/api/GPUBuffer.h +44 -8
- package/cpp/rnwgpu/api/GPUCanvasContext.cpp +63 -0
- package/cpp/rnwgpu/api/GPUCanvasContext.h +51 -8
- package/cpp/rnwgpu/api/GPUCommandBuffer.h +11 -4
- package/cpp/rnwgpu/api/GPUCommandEncoder.cpp +177 -0
- package/cpp/rnwgpu/api/GPUCommandEncoder.h +75 -3
- package/cpp/rnwgpu/api/GPUCompilationInfo.h +65 -8
- package/cpp/rnwgpu/api/GPUCompilationMessage.h +6 -4
- package/cpp/rnwgpu/api/GPUComputePassEncoder.cpp +58 -0
- package/cpp/rnwgpu/api/GPUComputePassEncoder.h +49 -3
- package/cpp/rnwgpu/api/GPUComputePipeline.cpp +11 -0
- package/cpp/rnwgpu/api/GPUComputePipeline.h +18 -3
- package/cpp/rnwgpu/api/GPUDevice.cpp +330 -3
- package/cpp/rnwgpu/api/GPUDevice.h +119 -5
- package/cpp/rnwgpu/api/GPUDeviceLostInfo.cpp +6 -0
- package/cpp/rnwgpu/api/GPUDeviceLostInfo.h +14 -7
- package/cpp/rnwgpu/api/GPUError.h +42 -0
- package/cpp/rnwgpu/api/GPUExtent3D.h +69 -0
- package/cpp/rnwgpu/api/GPUExternalTexture.h +11 -4
- package/cpp/rnwgpu/api/GPUFeatures.h +221 -0
- package/cpp/rnwgpu/api/GPUOrigin2D.h +59 -0
- package/cpp/rnwgpu/api/GPUOrigin3D.h +66 -0
- package/cpp/rnwgpu/api/GPUPipelineLayout.h +11 -4
- package/cpp/rnwgpu/api/GPUQuerySet.cpp +11 -0
- package/cpp/rnwgpu/api/GPUQuerySet.h +19 -5
- package/cpp/rnwgpu/api/GPUQueue.cpp +153 -0
- package/cpp/rnwgpu/api/GPUQueue.h +45 -4
- package/cpp/rnwgpu/api/GPURenderBundle.h +11 -4
- package/cpp/rnwgpu/api/GPURenderBundleEncoder.cpp +128 -0
- package/cpp/rnwgpu/api/GPURenderBundleEncoder.h +72 -3
- package/cpp/rnwgpu/api/GPURenderPassEncoder.cpp +161 -0
- package/cpp/rnwgpu/api/GPURenderPassEncoder.h +93 -3
- package/cpp/rnwgpu/api/GPURenderPipeline.cpp +13 -0
- package/cpp/rnwgpu/api/GPURenderPipeline.h +18 -3
- package/cpp/rnwgpu/api/GPUSampler.h +11 -4
- package/cpp/rnwgpu/api/GPUShaderModule.cpp +39 -0
- package/cpp/rnwgpu/api/GPUShaderModule.h +23 -4
- package/cpp/rnwgpu/api/GPUSupportedLimits.cpp +133 -0
- package/cpp/rnwgpu/api/GPUSupportedLimits.h +128 -4
- package/cpp/rnwgpu/api/GPUTexture.cpp +47 -0
- package/cpp/rnwgpu/api/GPUTexture.h +38 -4
- package/cpp/rnwgpu/api/GPUTextureView.h +11 -4
- package/cpp/rnwgpu/api/ImageBitmap.h +34 -0
- package/cpp/rnwgpu/api/RNWebGPU.h +100 -0
- package/cpp/rnwgpu/api/WebGPUCanvasContextFactory.h +59 -0
- package/cpp/rnwgpu/api/descriptors/GPUBindGroupDescriptor.h +31 -43
- package/cpp/rnwgpu/api/descriptors/GPUBindGroupEntry.h +40 -31
- package/cpp/rnwgpu/api/descriptors/GPUBindGroupLayoutDescriptor.h +24 -32
- package/cpp/rnwgpu/api/descriptors/GPUBindGroupLayoutEntry.h +56 -49
- package/cpp/rnwgpu/api/descriptors/GPUBlendComponent.h +27 -20
- package/cpp/rnwgpu/api/descriptors/GPUBlendState.h +23 -31
- package/cpp/rnwgpu/api/descriptors/GPUBufferBinding.h +25 -36
- package/cpp/rnwgpu/api/descriptors/GPUBufferBindingLayout.h +25 -25
- package/cpp/rnwgpu/api/descriptors/GPUBufferDescriptor.h +26 -46
- package/cpp/rnwgpu/api/descriptors/GPUCanvasConfiguration.h +31 -53
- package/cpp/rnwgpu/api/descriptors/GPUColor.h +72 -0
- package/cpp/rnwgpu/api/descriptors/GPUColorTargetState.h +27 -33
- package/cpp/rnwgpu/api/descriptors/GPUCommandBufferDescriptor.h +51 -0
- package/cpp/rnwgpu/api/descriptors/GPUCommandEncoderDescriptor.h +51 -0
- package/cpp/rnwgpu/api/descriptors/GPUComputePassDescriptor.h +24 -25
- package/cpp/rnwgpu/api/descriptors/GPUComputePassTimestampWrites.h +25 -42
- package/cpp/rnwgpu/api/descriptors/GPUComputePipelineDescriptor.h +32 -42
- package/cpp/rnwgpu/api/descriptors/GPUDepthStencilState.h +58 -76
- package/cpp/rnwgpu/api/descriptors/GPUDeviceDescriptor.h +38 -30
- package/cpp/rnwgpu/api/descriptors/GPUExternalTextureBindingLayout.h +11 -11
- package/cpp/rnwgpu/api/descriptors/GPUExternalTextureDescriptor.h +43 -34
- package/cpp/rnwgpu/api/descriptors/GPUFragmentState.h +39 -46
- package/cpp/rnwgpu/api/descriptors/GPUImageCopyBuffer.h +29 -45
- package/cpp/rnwgpu/api/descriptors/GPUImageCopyExternalImage.h +32 -31
- package/cpp/rnwgpu/api/descriptors/GPUImageCopyTexture.h +32 -36
- package/cpp/rnwgpu/api/descriptors/GPUImageCopyTextureTagged.h +42 -44
- package/cpp/rnwgpu/api/descriptors/GPUImageDataLayout.h +24 -34
- package/cpp/rnwgpu/api/descriptors/GPUMultisampleState.h +24 -32
- package/cpp/rnwgpu/api/descriptors/GPUPipelineLayoutDescriptor.h +25 -35
- package/cpp/rnwgpu/api/descriptors/GPUPrimitiveState.h +35 -26
- package/cpp/rnwgpu/api/descriptors/GPUProgrammableStage.h +29 -35
- package/cpp/rnwgpu/api/descriptors/GPUQuerySetDescriptor.h +23 -43
- package/cpp/rnwgpu/api/descriptors/GPUQueueDescriptor.h +49 -0
- package/cpp/rnwgpu/api/descriptors/GPURenderBundleDescriptor.h +51 -0
- package/cpp/rnwgpu/api/descriptors/GPURenderBundleEncoderDescriptor.h +41 -57
- package/cpp/rnwgpu/api/descriptors/GPURenderPassColorAttachment.h +42 -61
- package/cpp/rnwgpu/api/descriptors/GPURenderPassDepthStencilAttachment.h +54 -66
- package/cpp/rnwgpu/api/descriptors/GPURenderPassDescriptor.h +52 -55
- package/cpp/rnwgpu/api/descriptors/GPURenderPassTimestampWrites.h +25 -42
- package/cpp/rnwgpu/api/descriptors/GPURenderPipelineDescriptor.h +60 -56
- package/cpp/rnwgpu/api/descriptors/GPURequestAdapterOptions.h +21 -20
- package/cpp/rnwgpu/api/descriptors/GPUSamplerBindingLayout.h +17 -14
- package/cpp/rnwgpu/api/descriptors/GPUSamplerDescriptor.h +63 -63
- package/cpp/rnwgpu/api/descriptors/GPUShaderModuleCompilationHint.h +28 -27
- package/cpp/rnwgpu/api/descriptors/GPUShaderModuleDescriptor.h +28 -49
- package/cpp/rnwgpu/api/descriptors/GPUStencilFaceState.h +32 -23
- package/cpp/rnwgpu/api/descriptors/GPUStorageTextureBindingLayout.h +27 -29
- package/cpp/rnwgpu/api/descriptors/GPUTextureBindingLayout.h +27 -20
- package/cpp/rnwgpu/api/descriptors/GPUTextureDescriptor.h +49 -76
- package/cpp/rnwgpu/api/descriptors/GPUTextureViewDescriptor.h +48 -64
- package/cpp/rnwgpu/api/descriptors/GPUUncapturedErrorEventInit.h +29 -31
- package/cpp/rnwgpu/api/descriptors/GPUVertexAttribute.h +23 -44
- package/cpp/rnwgpu/api/descriptors/GPUVertexBufferLayout.h +30 -36
- package/cpp/rnwgpu/api/descriptors/GPUVertexState.h +39 -38
- package/cpp/rnwgpu/api/descriptors/Unions.h +57 -2
- package/ios/IOSPlatformContext.h +19 -0
- package/ios/IOSPlatformContext.mm +68 -0
- package/ios/MetalView.h +10 -0
- package/ios/MetalView.mm +27 -0
- package/ios/SurfaceUtils.h +13 -0
- package/ios/SurfaceUtils.mm +24 -0
- package/ios/WebGPUModule.h +8 -7
- package/ios/WebGPUModule.mm +47 -14
- package/ios/WebGPUView.h +6 -3
- package/ios/WebGPUView.mm +36 -24
- package/ios/WebGPUViewComponentDescriptor.h +61 -0
- package/ios/WebGPUViewManager.mm +6 -4
- package/lib/commonjs/Canvas.js +47 -0
- package/lib/commonjs/Canvas.js.map +1 -0
- package/lib/commonjs/{WebGPUNativeModule.js → NativeWebGPUModule.js} +1 -1
- package/lib/commonjs/{WebGPUNativeModule.js.map → NativeWebGPUModule.js.map} +1 -1
- package/lib/commonjs/WebGPUView.js +2 -0
- package/lib/commonjs/WebGPUView.js.map +1 -0
- package/lib/commonjs/WebGPUViewNativeComponent.js.map +1 -1
- package/lib/commonjs/index.js +183 -19
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/utils.js +39 -0
- package/lib/commonjs/utils.js.map +1 -0
- package/lib/module/Canvas.js +40 -0
- package/lib/module/Canvas.js.map +1 -0
- package/lib/module/{WebGPUNativeModule.js → NativeWebGPUModule.js} +1 -1
- package/lib/module/NativeWebGPUModule.js.map +1 -0
- package/lib/module/WebGPUView.js +2 -0
- package/lib/module/WebGPUView.js.map +1 -0
- package/lib/module/WebGPUViewNativeComponent.js.map +1 -1
- package/lib/module/index.js +158 -6
- package/lib/module/index.js.map +1 -1
- package/lib/module/utils.js +31 -0
- package/lib/module/utils.js.map +1 -0
- package/lib/typescript/example/src/Triangle/triangle.d.ts +3 -0
- package/lib/typescript/example/src/Triangle/triangle.d.ts.map +1 -0
- package/lib/typescript/example/src/Wireframe/Shaders.d.ts +3 -0
- package/lib/typescript/example/src/Wireframe/Shaders.d.ts.map +1 -0
- package/lib/typescript/example/src/Wireframe/models.d.ts +29 -0
- package/lib/typescript/example/src/Wireframe/models.d.ts.map +1 -0
- package/lib/typescript/example/src/components/DrawingContext.d.ts +13 -0
- package/lib/typescript/example/src/components/DrawingContext.d.ts.map +1 -0
- package/lib/typescript/example/src/components/cube.d.ts +7 -0
- package/lib/typescript/example/src/components/cube.d.ts.map +1 -0
- package/lib/typescript/example/src/components/meshes/sphere.d.ts +12 -0
- package/lib/typescript/example/src/components/meshes/sphere.d.ts.map +1 -0
- package/lib/typescript/example/src/components/meshes/teapot.d.ts +6 -0
- package/lib/typescript/example/src/components/meshes/teapot.d.ts.map +1 -0
- package/lib/typescript/example/src/components/meshes/utils.d.ts +10 -0
- package/lib/typescript/example/src/components/meshes/utils.d.ts.map +1 -0
- package/lib/typescript/jest.config.d.ts +4 -0
- package/lib/typescript/lib/commonjs/Canvas.d.ts +4 -0
- package/lib/typescript/lib/commonjs/Canvas.d.ts.map +1 -0
- package/lib/typescript/lib/commonjs/{WebGPUNativeModule.d.ts → NativeWebGPUModule.d.ts} +1 -1
- package/lib/typescript/lib/commonjs/NativeWebGPUModule.d.ts.map +1 -0
- package/lib/typescript/lib/commonjs/WebGPUView.d.ts +1 -0
- package/lib/typescript/lib/commonjs/WebGPUView.d.ts.map +1 -0
- package/lib/typescript/lib/commonjs/index.d.ts +0 -2
- package/lib/typescript/lib/commonjs/utils.d.ts +5 -0
- package/lib/typescript/lib/commonjs/utils.d.ts.map +1 -0
- package/lib/typescript/lib/module/Canvas.d.ts +2 -0
- package/lib/typescript/lib/module/Canvas.d.ts.map +1 -0
- package/lib/typescript/lib/module/{WebGPUNativeModule.d.ts → NativeWebGPUModule.d.ts} +1 -1
- package/lib/typescript/lib/module/NativeWebGPUModule.d.ts.map +1 -0
- package/lib/typescript/lib/module/WebGPUView.d.ts +1 -0
- package/lib/typescript/lib/module/WebGPUView.d.ts.map +1 -0
- package/lib/typescript/lib/module/index.d.ts +3 -3
- package/lib/typescript/lib/module/utils.d.ts +3 -0
- package/lib/typescript/lib/module/utils.d.ts.map +1 -0
- package/lib/typescript/src/Canvas.d.ts +29 -0
- package/lib/typescript/src/Canvas.d.ts.map +1 -0
- package/lib/typescript/src/{WebGPUNativeModule.d.ts → NativeWebGPUModule.d.ts} +2 -1
- package/lib/typescript/src/NativeWebGPUModule.d.ts.map +1 -0
- package/lib/typescript/src/WebGPUView.d.ts +1 -0
- package/lib/typescript/src/WebGPUView.d.ts.map +1 -0
- package/lib/typescript/src/WebGPUViewNativeComponent.d.ts +2 -1
- package/lib/typescript/src/WebGPUViewNativeComponent.d.ts.map +1 -1
- package/lib/typescript/src/index.d.ts +3 -7
- package/lib/typescript/src/index.d.ts.map +1 -1
- package/lib/typescript/src/utils.d.ts +7 -0
- package/lib/typescript/src/utils.d.ts.map +1 -0
- 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/dawn.json +4597 -0
- package/libs/ios/arm64_iphoneos/libwebgpu_dawn.a +0 -0
- package/libs/ios/arm64_iphonesimulator/libwebgpu_dawn.a +0 -0
- package/libs/ios/libwebgpu_dawn.a +0 -0
- package/libs/ios/libwebgpu_dawn.xcframework/Info.plist +44 -0
- package/libs/ios/libwebgpu_dawn.xcframework/ios-arm64/libwebgpu_dawn.a +0 -0
- package/libs/ios/libwebgpu_dawn.xcframework/ios-arm64_x86_64-simulator/libwebgpu_dawn.a +0 -0
- package/libs/ios/x86_64_iphonesimulator/libwebgpu_dawn.a +0 -0
- package/package.json +25 -8
- package/{react-native-webgpu.podspec → react-native-wgpu.podspec} +6 -9
- package/src/Canvas.tsx +73 -0
- package/src/{WebGPUNativeModule.ts → NativeWebGPUModule.ts} +1 -0
- package/src/WebGPUView.tsx +0 -0
- package/src/WebGPUViewNativeComponent.ts +2 -1
- package/src/index.tsx +191 -8
- package/src/utils.ts +40 -0
- package/android/src/main/AndroidManifestNew.xml +0 -2
- package/cpp/rnwgpu/MutableBuffer.h +0 -48
- package/cpp/rnwgpu/api/GPUUncapturedErrorEvent.h +0 -33
- package/cpp/rnwgpu/api/descriptors/GPUColorDict.h +0 -81
- package/cpp/rnwgpu/api/descriptors/GPUExtent3DDict.h +0 -76
- package/cpp/rnwgpu/api/descriptors/GPUExtent3DDictStrict.h +0 -91
- package/cpp/rnwgpu/api/descriptors/GPUOrigin2DDict.h +0 -61
- package/cpp/rnwgpu/api/descriptors/GPUOrigin2DDictStrict.h +0 -75
- package/cpp/rnwgpu/api/descriptors/GPUOrigin3DDict.h +0 -71
- package/cpp/rnwgpu/api/descriptors/GPUPipelineErrorInit.h +0 -54
- package/cpp/rnwgpu/api/descriptors/GPURenderPassLayout.h +0 -83
- package/ios/RNFAppleLogger.mm +0 -22
- package/ios/Utils.h +0 -5
- package/ios/Utils.m +0 -26
- package/lib/module/WebGPUNativeModule.js.map +0 -1
- package/lib/typescript/lib/commonjs/WebGPUNativeModule.d.ts.map +0 -1
- package/lib/typescript/lib/module/WebGPUNativeModule.d.ts.map +0 -1
- package/lib/typescript/scripts/build/copy-artifacts.d.ts +0 -2
- package/lib/typescript/scripts/build/copy-artifacts.d.ts.map +0 -1
- package/lib/typescript/scripts/build/dawn.d.ts +0 -2
- package/lib/typescript/scripts/build/dawn.d.ts.map +0 -1
- package/lib/typescript/scripts/build/util.d.ts +0 -13
- package/lib/typescript/scripts/build/util.d.ts.map +0 -1
- package/lib/typescript/scripts/codegen/codegen.d.ts +0 -2
- package/lib/typescript/scripts/codegen/codegen.d.ts.map +0 -1
- package/lib/typescript/scripts/codegen/model/dawn.d.ts +0 -2
- package/lib/typescript/scripts/codegen/model/dawn.d.ts.map +0 -1
- package/lib/typescript/scripts/codegen/model/model.d.ts +0 -8
- package/lib/typescript/scripts/codegen/model/model.d.ts.map +0 -1
- package/lib/typescript/scripts/codegen/templates/Descriptor.d.ts +0 -4
- package/lib/typescript/scripts/codegen/templates/Descriptor.d.ts.map +0 -1
- package/lib/typescript/scripts/codegen/templates/Enum.d.ts +0 -3
- package/lib/typescript/scripts/codegen/templates/Enum.d.ts.map +0 -1
- package/lib/typescript/scripts/codegen/templates/HybridObject.d.ts +0 -3
- package/lib/typescript/scripts/codegen/templates/HybridObject.d.ts.map +0 -1
- package/lib/typescript/scripts/codegen/templates/Unions.d.ts +0 -6
- package/lib/typescript/scripts/codegen/templates/Unions.d.ts.map +0 -1
- package/lib/typescript/scripts/codegen/templates/common.d.ts +0 -9
- package/lib/typescript/scripts/codegen/templates/common.d.ts.map +0 -1
- package/lib/typescript/scripts/codegen/util.d.ts +0 -2
- package/lib/typescript/scripts/codegen/util.d.ts.map +0 -1
- package/lib/typescript/src/WebGPUNativeModule.d.ts.map +0 -1
|
@@ -1,30 +1,41 @@
|
|
|
1
1
|
#pragma once
|
|
2
2
|
|
|
3
|
+
#include <map>
|
|
3
4
|
#include <memory>
|
|
4
5
|
#include <string>
|
|
6
|
+
#include <variant>
|
|
7
|
+
#include <vector>
|
|
5
8
|
|
|
6
9
|
#include "webgpu/webgpu_cpp.h"
|
|
7
10
|
|
|
8
|
-
#include "Logger.h"
|
|
9
11
|
#include "RNFJSIConverter.h"
|
|
10
|
-
#include
|
|
12
|
+
#include "WGPULogger.h"
|
|
13
|
+
|
|
14
|
+
#include "GPUShaderModule.h"
|
|
15
|
+
#include "GPUVertexBufferLayout.h"
|
|
16
|
+
#include "RNFHybridObject.h"
|
|
11
17
|
|
|
12
18
|
namespace jsi = facebook::jsi;
|
|
19
|
+
namespace m = margelo;
|
|
13
20
|
|
|
14
21
|
namespace rnwgpu {
|
|
15
22
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
std::string
|
|
23
|
+
struct GPUVertexState {
|
|
24
|
+
std::optional<std::vector<
|
|
25
|
+
std::variant<std::nullptr_t, std::shared_ptr<GPUVertexBufferLayout>>>>
|
|
26
|
+
buffers; // Iterable<GPUVertexBufferLayout | null>
|
|
27
|
+
std::shared_ptr<GPUShaderModule> module; // GPUShaderModule
|
|
28
|
+
std::optional<std::string> entryPoint; // string
|
|
29
|
+
std::optional<std::map<std::string, double>>
|
|
30
|
+
constants; // Record< string, GPUPipelineConstantValue >
|
|
23
31
|
};
|
|
32
|
+
|
|
24
33
|
} // namespace rnwgpu
|
|
25
34
|
|
|
26
35
|
namespace margelo {
|
|
27
36
|
|
|
37
|
+
using namespace rnwgpu; // NOLINT(build/namespaces)
|
|
38
|
+
|
|
28
39
|
template <> struct JSIConverter<std::shared_ptr<rnwgpu::GPUVertexState>> {
|
|
29
40
|
static std::shared_ptr<rnwgpu::GPUVertexState>
|
|
30
41
|
fromJSI(jsi::Runtime &runtime, const jsi::Value &arg, bool outOfBounds) {
|
|
@@ -32,46 +43,36 @@ template <> struct JSIConverter<std::shared_ptr<rnwgpu::GPUVertexState>> {
|
|
|
32
43
|
if (!outOfBounds && arg.isObject()) {
|
|
33
44
|
auto value = arg.getObject(runtime);
|
|
34
45
|
if (value.hasProperty(runtime, "buffers")) {
|
|
35
|
-
auto
|
|
46
|
+
auto prop = value.getProperty(runtime, "buffers");
|
|
47
|
+
result->buffers = JSIConverter<std::optional<std::vector<std::variant<
|
|
48
|
+
std::nullptr_t, std::shared_ptr<GPUVertexBufferLayout>>>>>::
|
|
49
|
+
fromJSI(runtime, prop, false);
|
|
36
50
|
}
|
|
37
51
|
if (value.hasProperty(runtime, "module")) {
|
|
38
|
-
auto
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
"Property GPUVertexState::module is required");
|
|
43
|
-
}
|
|
44
|
-
} else {
|
|
45
|
-
throw std::runtime_error(
|
|
46
|
-
"Property GPUVertexState::module is not defined");
|
|
52
|
+
auto prop = value.getProperty(runtime, "module");
|
|
53
|
+
result->module =
|
|
54
|
+
JSIConverter<std::shared_ptr<GPUShaderModule>>::fromJSI(
|
|
55
|
+
runtime, prop, false);
|
|
47
56
|
}
|
|
48
57
|
if (value.hasProperty(runtime, "entryPoint")) {
|
|
49
|
-
auto
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
auto str = entryPoint.asString(runtime).utf8(runtime);
|
|
53
|
-
result->entryPoint = str;
|
|
54
|
-
result->_instance.entryPoint = result->entryPoint.c_str();
|
|
55
|
-
}
|
|
58
|
+
auto prop = value.getProperty(runtime, "entryPoint");
|
|
59
|
+
result->entryPoint = JSIConverter<std::optional<std::string>>::fromJSI(
|
|
60
|
+
runtime, prop, false);
|
|
56
61
|
}
|
|
57
62
|
if (value.hasProperty(runtime, "constants")) {
|
|
58
|
-
auto
|
|
63
|
+
auto prop = value.getProperty(runtime, "constants");
|
|
64
|
+
result->constants =
|
|
65
|
+
JSIConverter<std::optional<std::map<std::string, double>>>::fromJSI(
|
|
66
|
+
runtime, prop, false);
|
|
59
67
|
}
|
|
60
68
|
}
|
|
61
|
-
|
|
62
|
-
result->_instance.buffers);
|
|
63
|
-
rnwgpu::Logger::logToConsole("GPUVertexState::module = %f",
|
|
64
|
-
result->_instance.module);
|
|
65
|
-
rnwgpu::Logger::logToConsole("GPUVertexState::entryPoint = %f",
|
|
66
|
-
result->_instance.entryPoint);
|
|
67
|
-
rnwgpu::Logger::logToConsole("GPUVertexState::constants = %f",
|
|
68
|
-
result->_instance.constants);
|
|
69
|
+
|
|
69
70
|
return result;
|
|
70
71
|
}
|
|
71
72
|
static jsi::Value toJSI(jsi::Runtime &runtime,
|
|
72
73
|
std::shared_ptr<rnwgpu::GPUVertexState> arg) {
|
|
73
|
-
|
|
74
|
-
return jsi::Value::null();
|
|
74
|
+
throw std::runtime_error("Invalid GPUVertexState::toJSI()");
|
|
75
75
|
}
|
|
76
76
|
};
|
|
77
|
-
|
|
77
|
+
|
|
78
|
+
} // namespace margelo
|
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
|
|
3
3
|
#include <string>
|
|
4
4
|
|
|
5
|
-
#include "
|
|
6
|
-
|
|
5
|
+
#include "External.h"
|
|
7
6
|
#include "RNFEnumMapper.h"
|
|
7
|
+
#include "webgpu/webgpu_cpp.h"
|
|
8
8
|
|
|
9
9
|
namespace margelo {
|
|
10
10
|
namespace EnumMapper {
|
|
@@ -1641,5 +1641,60 @@ static void convertEnumToJSUnion(wgpu::VertexStepMode inEnum,
|
|
|
1641
1641
|
}
|
|
1642
1642
|
}
|
|
1643
1643
|
|
|
1644
|
+
static void convertJSUnionToEnum(const std::string &inUnion,
|
|
1645
|
+
rnwgpu::PredefinedColorSpace *outEnum) {
|
|
1646
|
+
if (inUnion == "display-p3") {
|
|
1647
|
+
*outEnum = rnwgpu::PredefinedColorSpace::DisplayP3;
|
|
1648
|
+
} else if (inUnion == "srgb") {
|
|
1649
|
+
*outEnum = rnwgpu::PredefinedColorSpace::Srgb;
|
|
1650
|
+
} else {
|
|
1651
|
+
throw invalidUnion(inUnion);
|
|
1652
|
+
}
|
|
1653
|
+
}
|
|
1654
|
+
|
|
1655
|
+
static void convertEnumToJSUnion(rnwgpu::PredefinedColorSpace inEnum,
|
|
1656
|
+
std::string *outUnion) {
|
|
1657
|
+
switch (inEnum) {
|
|
1658
|
+
case rnwgpu::PredefinedColorSpace::DisplayP3:
|
|
1659
|
+
*outUnion = "display-p3";
|
|
1660
|
+
break;
|
|
1661
|
+
case rnwgpu::PredefinedColorSpace::Srgb:
|
|
1662
|
+
*outUnion = "srgb";
|
|
1663
|
+
break;
|
|
1664
|
+
default:
|
|
1665
|
+
throw invalidEnum(inEnum);
|
|
1666
|
+
}
|
|
1667
|
+
}
|
|
1668
|
+
|
|
1669
|
+
static void convertJSUnionToEnum(const std::string &inUnion,
|
|
1670
|
+
rnwgpu::PremultiplyAlpha *outEnum) {
|
|
1671
|
+
if (inUnion == "none") {
|
|
1672
|
+
*outEnum = rnwgpu::PremultiplyAlpha::None;
|
|
1673
|
+
} else if (inUnion == "default") {
|
|
1674
|
+
*outEnum = rnwgpu::PremultiplyAlpha::Default;
|
|
1675
|
+
} else if (inUnion == "premultiply") {
|
|
1676
|
+
*outEnum = rnwgpu::PremultiplyAlpha::Premultiply;
|
|
1677
|
+
} else {
|
|
1678
|
+
throw invalidUnion(inUnion);
|
|
1679
|
+
}
|
|
1680
|
+
}
|
|
1681
|
+
|
|
1682
|
+
static void convertEnumToJSUnion(rnwgpu::PremultiplyAlpha inEnum,
|
|
1683
|
+
std::string *outUnion) {
|
|
1684
|
+
switch (inEnum) {
|
|
1685
|
+
case rnwgpu::PremultiplyAlpha::None:
|
|
1686
|
+
*outUnion = "none";
|
|
1687
|
+
break;
|
|
1688
|
+
case rnwgpu::PremultiplyAlpha::Default:
|
|
1689
|
+
*outUnion = "default";
|
|
1690
|
+
break;
|
|
1691
|
+
case rnwgpu::PremultiplyAlpha::Premultiply:
|
|
1692
|
+
*outUnion = "premultiply";
|
|
1693
|
+
break;
|
|
1694
|
+
default:
|
|
1695
|
+
throw invalidEnum(inEnum);
|
|
1696
|
+
}
|
|
1697
|
+
}
|
|
1698
|
+
|
|
1644
1699
|
} // namespace EnumMapper
|
|
1645
1700
|
} // namespace margelo
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
#pragma once
|
|
2
|
+
|
|
3
|
+
#include "PlatformContext.h"
|
|
4
|
+
|
|
5
|
+
namespace rnwgpu {
|
|
6
|
+
|
|
7
|
+
class IOSPlatformContext : public PlatformContext {
|
|
8
|
+
public:
|
|
9
|
+
IOSPlatformContext() = default;
|
|
10
|
+
~IOSPlatformContext() = default;
|
|
11
|
+
|
|
12
|
+
wgpu::Surface makeSurface(wgpu::Instance instance, void *surface, int width,
|
|
13
|
+
int height) override;
|
|
14
|
+
|
|
15
|
+
ImageData createImageBitmap(std::string blobId, double offset,
|
|
16
|
+
double size) override;
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
} // namespace rnwgpu
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
#include "IOSPlatformContext.h"
|
|
2
|
+
|
|
3
|
+
#import <React/RCTBlobManager.h>
|
|
4
|
+
#import <React/RCTBridge+Private.h>
|
|
5
|
+
#import <ReactCommon/RCTTurboModule.h>
|
|
6
|
+
|
|
7
|
+
#include "RNWebGPUManager.h"
|
|
8
|
+
#include "WebGPUModule.h"
|
|
9
|
+
|
|
10
|
+
namespace rnwgpu {
|
|
11
|
+
|
|
12
|
+
wgpu::Surface IOSPlatformContext::makeSurface(wgpu::Instance instance,
|
|
13
|
+
void *surface, int width,
|
|
14
|
+
int height) {
|
|
15
|
+
wgpu::SurfaceDescriptorFromMetalLayer metalSurfaceDesc;
|
|
16
|
+
metalSurfaceDesc.layer = surface;
|
|
17
|
+
wgpu::SurfaceDescriptor surfaceDescriptor;
|
|
18
|
+
surfaceDescriptor.nextInChain = &metalSurfaceDesc;
|
|
19
|
+
return instance.CreateSurface(&surfaceDescriptor);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
ImageData IOSPlatformContext::createImageBitmap(std::string blobId,
|
|
23
|
+
double offset, double size) {
|
|
24
|
+
RCTBlobManager *blobManager =
|
|
25
|
+
[[RCTBridge currentBridge] moduleForClass:RCTBlobManager.class];
|
|
26
|
+
NSData *blobData =
|
|
27
|
+
[blobManager resolve:[NSString stringWithUTF8String:blobId.c_str()]
|
|
28
|
+
offset:(long)offset
|
|
29
|
+
size:(long)size];
|
|
30
|
+
|
|
31
|
+
if (!blobData) {
|
|
32
|
+
throw std::runtime_error("Couldn't retrive blob data");
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
UIImage *image = [UIImage imageWithData:blobData];
|
|
36
|
+
if (!image) {
|
|
37
|
+
throw std::runtime_error("Couldn't decode image");
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
CGImageRef cgImage = image.CGImage;
|
|
41
|
+
size_t width = CGImageGetWidth(cgImage);
|
|
42
|
+
size_t height = CGImageGetHeight(cgImage);
|
|
43
|
+
size_t bitsPerComponent = 8;
|
|
44
|
+
size_t bytesPerRow = width * 4;
|
|
45
|
+
std::vector<uint8_t> imageData(height * bytesPerRow);
|
|
46
|
+
|
|
47
|
+
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
|
|
48
|
+
CGContextRef context = CGBitmapContextCreate(
|
|
49
|
+
imageData.data(), width, height, bitsPerComponent, bytesPerRow,
|
|
50
|
+
colorSpace, kCGImageAlphaPremultipliedLast | kCGBitmapByteOrder32Big);
|
|
51
|
+
|
|
52
|
+
CGContextDrawImage(context, CGRectMake(0, 0, width, height), cgImage);
|
|
53
|
+
|
|
54
|
+
// Now imageData contains a copy of the bitmap data
|
|
55
|
+
|
|
56
|
+
CGContextRelease(context);
|
|
57
|
+
CGColorSpaceRelease(colorSpace);
|
|
58
|
+
|
|
59
|
+
// Use the copied data
|
|
60
|
+
ImageData result;
|
|
61
|
+
result.width = static_cast<int>(width);
|
|
62
|
+
result.height = static_cast<int>(height);
|
|
63
|
+
result.data = imageData;
|
|
64
|
+
result.format = wgpu::TextureFormat::RGBA8Unorm;
|
|
65
|
+
return result;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
} // namespace rnwgpu
|
package/ios/MetalView.h
ADDED
package/ios/MetalView.mm
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
#import "MetalView.h"
|
|
2
|
+
#import "SurfaceUtils.h"
|
|
3
|
+
#import "webgpu_cpp.h"
|
|
4
|
+
#import <React/RCTViewManager.h>
|
|
5
|
+
|
|
6
|
+
@implementation MetalView {
|
|
7
|
+
BOOL _isConfigured;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
+ (Class)layerClass {
|
|
11
|
+
return [CAMetalLayer class];
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
// Paper only method
|
|
15
|
+
- (void)reactSetFrame:(CGRect)frame {
|
|
16
|
+
[super reactSetFrame:frame];
|
|
17
|
+
if (!_isConfigured) {
|
|
18
|
+
[SurfaceUtils configureSurface:self.layer
|
|
19
|
+
size:self.frame.size
|
|
20
|
+
contextId:[_contextId intValue]];
|
|
21
|
+
_isConfigured = YES;
|
|
22
|
+
} else {
|
|
23
|
+
[SurfaceUtils updateSurface:[_contextId intValue] size:self.frame.size];
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
@end
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
#import "SurfaceUtils.h"
|
|
2
|
+
#import "MetalView.h"
|
|
3
|
+
#import "WebGPUModule.h"
|
|
4
|
+
#import "WebGPUView.h"
|
|
5
|
+
|
|
6
|
+
// TODO: to delete now
|
|
7
|
+
@implementation SurfaceUtils
|
|
8
|
+
|
|
9
|
+
+ (void)configureSurface:(CALayer *)layer
|
|
10
|
+
size:(CGSize)size
|
|
11
|
+
contextId:(int)contextId {
|
|
12
|
+
std::shared_ptr<rnwgpu::RNWebGPUManager> manager = [WebGPUModule getManager];
|
|
13
|
+
CGFloat scaleFactor = [UIScreen mainScreen].scale;
|
|
14
|
+
void *nativeSurface = (__bridge void *)layer;
|
|
15
|
+
manager->surfacesRegistry.addSurface(contextId, nativeSurface, size.width,
|
|
16
|
+
size.height);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
+ (void)updateSurface:(int)contextId size:(CGSize)size {
|
|
20
|
+
std::shared_ptr<rnwgpu::RNWebGPUManager> manager = [WebGPUModule getManager];
|
|
21
|
+
manager->surfacesRegistry.updateSurface(contextId, size.width, size.height);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
@end
|
package/ios/WebGPUModule.h
CHANGED
|
@@ -1,18 +1,19 @@
|
|
|
1
1
|
#pragma once
|
|
2
2
|
|
|
3
|
+
#import "RNWebGPUManager.h"
|
|
3
4
|
#import <React/RCTBridgeModule.h>
|
|
4
5
|
#import <React/RCTEventEmitter.h>
|
|
5
6
|
|
|
6
|
-
|
|
7
|
+
#ifdef RCT_NEW_ARCH_ENABLED
|
|
8
|
+
#import <RNWgpuViewSpec/RNWgpuViewSpec.h>
|
|
9
|
+
@interface WebGPUModule : RCTEventEmitter <NativeWebGPUModuleSpec>
|
|
10
|
+
#else
|
|
11
|
+
@interface WebGPUModule : RCTEventEmitter <RCTBridgeModule>
|
|
12
|
+
#endif
|
|
7
13
|
|
|
8
14
|
@property(nonatomic, weak) RCTBridge *bridge;
|
|
9
15
|
@property(nonatomic, weak) RCTModuleRegistry *moduleRegistry;
|
|
10
16
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
#ifdef RCT_NEW_ARCH_ENABLED
|
|
14
|
-
#import <rnwebgpu/rnwebgpu.h>
|
|
17
|
+
+ (std::shared_ptr<rnwgpu::RNWebGPUManager>)getManager;
|
|
15
18
|
|
|
16
|
-
@interface WebGPUModule () <WebGPUModuleSpec>
|
|
17
19
|
@end
|
|
18
|
-
#endif
|
package/ios/WebGPUModule.mm
CHANGED
|
@@ -1,24 +1,25 @@
|
|
|
1
1
|
#import "WebGPUModule.h"
|
|
2
|
+
#import "GPUCanvasContext.h"
|
|
3
|
+
#include "IOSPlatformContext.h"
|
|
4
|
+
|
|
2
5
|
#import <React/RCTBridge+Private.h>
|
|
3
6
|
#import <React/RCTLog.h>
|
|
7
|
+
#import <React/RCTUIManagerUtils.h>
|
|
4
8
|
#import <ReactCommon/RCTTurboModule.h>
|
|
5
|
-
|
|
6
|
-
#
|
|
7
|
-
#include "RNWebGPUManager.h"
|
|
9
|
+
#import <jsi/jsi.h>
|
|
10
|
+
#import <memory>
|
|
8
11
|
|
|
9
12
|
namespace jsi = facebook::jsi;
|
|
10
13
|
namespace react = facebook::react;
|
|
11
14
|
|
|
12
|
-
@implementation WebGPUModule
|
|
13
|
-
rnwgpu::RNWebGPUManager *_webgpuManager;
|
|
14
|
-
}
|
|
15
|
+
@implementation WebGPUModule
|
|
15
16
|
|
|
16
17
|
RCT_EXPORT_MODULE(WebGPUModule)
|
|
17
18
|
|
|
18
|
-
|
|
19
|
+
static std::shared_ptr<rnwgpu::RNWebGPUManager> webgpuManager;
|
|
19
20
|
|
|
20
|
-
|
|
21
|
-
return
|
|
21
|
+
+ (std::shared_ptr<rnwgpu::RNWebGPUManager>)getManager {
|
|
22
|
+
return webgpuManager;
|
|
22
23
|
}
|
|
23
24
|
|
|
24
25
|
#pragma Setup and invalidation
|
|
@@ -31,11 +32,15 @@ RCT_EXPORT_MODULE(WebGPUModule)
|
|
|
31
32
|
// if (_webgpuManager != nil) {
|
|
32
33
|
// [_webgpuManager invalidate];
|
|
33
34
|
// }
|
|
34
|
-
|
|
35
|
+
webgpuManager = nil;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
- (std::shared_ptr<rnwgpu::RNWebGPUManager>)getManager {
|
|
39
|
+
return webgpuManager;
|
|
35
40
|
}
|
|
36
41
|
|
|
37
42
|
RCT_EXPORT_BLOCKING_SYNCHRONOUS_METHOD(install) {
|
|
38
|
-
if (
|
|
43
|
+
if (webgpuManager != nil) {
|
|
39
44
|
// Already initialized, ignore call.
|
|
40
45
|
return @true;
|
|
41
46
|
}
|
|
@@ -61,16 +66,44 @@ RCT_EXPORT_BLOCKING_SYNCHRONOUS_METHOD(install) {
|
|
|
61
66
|
if (!jsInvoker) {
|
|
62
67
|
jsInvoker = cxxBridge.jsCallInvoker;
|
|
63
68
|
}
|
|
69
|
+
std::shared_ptr<rnwgpu::PlatformContext> platformContext =
|
|
70
|
+
std::make_shared<rnwgpu::IOSPlatformContext>();
|
|
64
71
|
// TODO: remove allocation here
|
|
65
|
-
|
|
72
|
+
webgpuManager = std::make_shared<rnwgpu::RNWebGPUManager>(runtime, jsInvoker,
|
|
73
|
+
platformContext);
|
|
74
|
+
return @true;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
RCT_EXPORT_BLOCKING_SYNCHRONOUS_METHOD(createSurfaceContext
|
|
78
|
+
: (double)contextId) {
|
|
79
|
+
int contextIdInt = contextId;
|
|
80
|
+
RCTCxxBridge *cxxBridge = (RCTCxxBridge *)self.bridge;
|
|
81
|
+
auto runtime = (jsi::Runtime *)cxxBridge.runtime;
|
|
82
|
+
auto webGPUContextRegistry = runtime->global().getPropertyAsObject(
|
|
83
|
+
*runtime, "__WebGPUContextRegistry");
|
|
84
|
+
auto canvas = webgpuManager->surfacesRegistry.getSurface(contextIdInt);
|
|
85
|
+
if (webGPUContextRegistry.hasProperty(*runtime,
|
|
86
|
+
std::to_string(contextIdInt).c_str())) {
|
|
87
|
+
// Context already exists, just update width/height
|
|
88
|
+
auto prop =
|
|
89
|
+
webGPUContextRegistry
|
|
90
|
+
.getPropertyAsObject(*runtime, std::to_string(contextIdInt).c_str())
|
|
91
|
+
.asHostObject<rnwgpu::Canvas>(*runtime);
|
|
92
|
+
prop->setWidth(canvas->getWidth());
|
|
93
|
+
prop->setHeight(canvas->getHeight());
|
|
94
|
+
return @true;
|
|
95
|
+
}
|
|
96
|
+
webGPUContextRegistry.setProperty(
|
|
97
|
+
*runtime, std::to_string(contextIdInt).c_str(),
|
|
98
|
+
facebook::jsi::Object::createFromHostObject(*runtime, canvas));
|
|
99
|
+
|
|
66
100
|
return @true;
|
|
67
101
|
}
|
|
68
102
|
|
|
69
103
|
#ifdef RCT_NEW_ARCH_ENABLED
|
|
70
104
|
- (std::shared_ptr<facebook::react::TurboModule>)getTurboModule:
|
|
71
105
|
(const facebook::react::ObjCTurboModule::InitParams &)params {
|
|
72
|
-
|
|
73
|
-
return std::make_shared<facebook::react::NativeSkiaModuleSpecJSI>(params);
|
|
106
|
+
return std::make_shared<facebook::react::NativeWebGPUModuleSpecJSI>(params);
|
|
74
107
|
}
|
|
75
108
|
#endif
|
|
76
109
|
|
package/ios/WebGPUView.h
CHANGED
|
@@ -1,13 +1,16 @@
|
|
|
1
|
-
// This guard prevent this file to be compiled in the old architecture.
|
|
2
1
|
#ifdef RCT_NEW_ARCH_ENABLED
|
|
2
|
+
#pragma once
|
|
3
|
+
|
|
4
|
+
#import "MetalView.h"
|
|
3
5
|
#import <React/RCTViewComponentView.h>
|
|
4
6
|
#import <UIKit/UIKit.h>
|
|
5
7
|
|
|
6
|
-
#pragma once
|
|
7
|
-
|
|
8
8
|
NS_ASSUME_NONNULL_BEGIN
|
|
9
9
|
|
|
10
10
|
@interface WebGPUView : RCTViewComponentView
|
|
11
|
+
+ (void)registerMetalView:(MetalView *)metalView
|
|
12
|
+
withContextId:(NSNumber *)contextId;
|
|
13
|
+
+ (bool)isContextRegisterd:(NSNumber *)contextId;
|
|
11
14
|
@end
|
|
12
15
|
|
|
13
16
|
NS_ASSUME_NONNULL_END
|
package/ios/WebGPUView.mm
CHANGED
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
#ifdef RCT_NEW_ARCH_ENABLED
|
|
2
2
|
#import "WebGPUView.h"
|
|
3
3
|
|
|
4
|
-
#import <react/renderer/components/
|
|
5
|
-
#import <react/renderer/components/
|
|
6
|
-
#import <react/renderer/components/
|
|
7
|
-
#import <react/renderer/components/RNWebGPUViewSpec/RCTComponentViewHelpers.h>
|
|
4
|
+
#import <react/renderer/components/RNWgpuViewSpec/EventEmitters.h>
|
|
5
|
+
#import <react/renderer/components/RNWgpuViewSpec/Props.h>
|
|
6
|
+
#import <react/renderer/components/RNWgpuViewSpec/RCTComponentViewHelpers.h>
|
|
8
7
|
|
|
8
|
+
#import "MetalView.h"
|
|
9
9
|
#import "RCTFabricComponentsPlugins.h"
|
|
10
10
|
#import "Utils.h"
|
|
11
|
+
#import "WebGPUModule.h"
|
|
12
|
+
#import "WebGPUViewComponentDescriptor.h"
|
|
11
13
|
|
|
12
14
|
using namespace facebook::react;
|
|
13
15
|
|
|
@@ -16,40 +18,50 @@ using namespace facebook::react;
|
|
|
16
18
|
@end
|
|
17
19
|
|
|
18
20
|
@implementation WebGPUView {
|
|
19
|
-
|
|
21
|
+
NSNumber *_contextId;
|
|
20
22
|
}
|
|
21
23
|
|
|
24
|
+
static NSMutableDictionary<NSNumber *, MetalView *> *metalViewRegistry =
|
|
25
|
+
[NSMutableDictionary new];
|
|
26
|
+
|
|
22
27
|
+ (ComponentDescriptorProvider)componentDescriptorProvider {
|
|
23
|
-
return concreteComponentDescriptorProvider<
|
|
28
|
+
return concreteComponentDescriptorProvider<WebGPUViewComponentDescriptor>();
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
+ (void)registerMetalView:(MetalView *)metalView
|
|
32
|
+
withContextId:(NSNumber *)contextId {
|
|
33
|
+
metalViewRegistry[contextId] = metalView;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
+ (bool)isContextRegisterd:(NSNumber *)contextId {
|
|
37
|
+
return metalViewRegistry[contextId] != nil;
|
|
24
38
|
}
|
|
25
39
|
|
|
26
40
|
- (instancetype)initWithFrame:(CGRect)frame {
|
|
27
41
|
if (self = [super initWithFrame:frame]) {
|
|
28
|
-
static const auto defaultProps = std::make_shared<const
|
|
42
|
+
static const auto defaultProps = std::make_shared<const WebGPUViewProps>();
|
|
29
43
|
_props = defaultProps;
|
|
30
|
-
|
|
31
|
-
_view = [[UIView alloc] init];
|
|
32
|
-
|
|
33
|
-
self.contentView = _view;
|
|
34
44
|
}
|
|
35
45
|
|
|
36
46
|
return self;
|
|
37
47
|
}
|
|
38
48
|
|
|
39
|
-
- (void)
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
*std::static_pointer_cast<WebGPUViewProps const>(props);
|
|
45
|
-
|
|
46
|
-
if (oldViewProps.color != newViewProps.color) {
|
|
47
|
-
NSString *colorToConvert =
|
|
48
|
-
[[NSString alloc] initWithUTF8String:newViewProps.color.c_str()];
|
|
49
|
-
[_view setBackgroundColor:[Utils hexStringToColor:colorToConvert]];
|
|
50
|
-
}
|
|
49
|
+
- (void)prepareForRecycle {
|
|
50
|
+
[super prepareForRecycle];
|
|
51
|
+
self.contentView = nil;
|
|
52
|
+
[metalViewRegistry removeObjectForKey:_contextId];
|
|
53
|
+
}
|
|
51
54
|
|
|
52
|
-
|
|
55
|
+
- (void)updateLayoutMetrics:
|
|
56
|
+
(const facebook::react::LayoutMetrics &)layoutMetrics
|
|
57
|
+
oldLayoutMetrics:
|
|
58
|
+
(const facebook::react::LayoutMetrics &)oldLayoutMetrics {
|
|
59
|
+
[super updateLayoutMetrics:layoutMetrics oldLayoutMetrics:oldLayoutMetrics];
|
|
60
|
+
if (!self.contentView) {
|
|
61
|
+
const auto &props =
|
|
62
|
+
*std::static_pointer_cast<WebGPUViewProps const>(_props);
|
|
63
|
+
self.contentView = metalViewRegistry[@(props.contextId)];
|
|
64
|
+
}
|
|
53
65
|
}
|
|
54
66
|
|
|
55
67
|
Class<RCTComponentViewProtocol> WebGPUViewCls(void) { return WebGPUView.class; }
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
#ifdef RCT_NEW_ARCH_ENABLED
|
|
2
|
+
|
|
3
|
+
#pragma once
|
|
4
|
+
|
|
5
|
+
#include <react/debug/react_native_assert.h>
|
|
6
|
+
#include <react/renderer/components/RNWgpuViewSpec/ShadowNodes.h>
|
|
7
|
+
#include <react/renderer/components/view/ConcreteViewShadowNode.h>
|
|
8
|
+
#include <react/renderer/core/ConcreteComponentDescriptor.h>
|
|
9
|
+
#include <react/renderer/core/LayoutContext.h>
|
|
10
|
+
|
|
11
|
+
#import "MetalView.h"
|
|
12
|
+
#import "SurfaceUtils.h"
|
|
13
|
+
#import "WebGPUView.h"
|
|
14
|
+
|
|
15
|
+
namespace facebook {
|
|
16
|
+
namespace react {
|
|
17
|
+
|
|
18
|
+
class WebGPUViewCustomShadowNode final : public WebGPUViewShadowNode {
|
|
19
|
+
|
|
20
|
+
public:
|
|
21
|
+
using ConcreteViewShadowNode::ConcreteViewShadowNode;
|
|
22
|
+
|
|
23
|
+
void layout(LayoutContext layoutContext) override {
|
|
24
|
+
YogaLayoutableShadowNode::layout(layoutContext);
|
|
25
|
+
configureSurface();
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
void configureSurface() {
|
|
29
|
+
const auto &viewProps =
|
|
30
|
+
*std::static_pointer_cast<WebGPUViewProps const>(props_);
|
|
31
|
+
if ([WebGPUView isContextRegisterd:@(viewProps.contextId)]) {
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
__block MetalView *metalView;
|
|
35
|
+
__block CALayer *layer;
|
|
36
|
+
dispatch_sync(dispatch_get_main_queue(), ^{
|
|
37
|
+
metalView = [[MetalView alloc] init];
|
|
38
|
+
layer = metalView.layer;
|
|
39
|
+
});
|
|
40
|
+
[WebGPUView registerMetalView:metalView
|
|
41
|
+
withContextId:@(viewProps.contextId)];
|
|
42
|
+
|
|
43
|
+
// TODO: use physical size
|
|
44
|
+
float width = layoutMetrics_.frame.size.width;
|
|
45
|
+
float height = layoutMetrics_.frame.size.height;
|
|
46
|
+
[SurfaceUtils configureSurface:layer
|
|
47
|
+
size:CGSizeMake(width, height)
|
|
48
|
+
contextId:viewProps.contextId];
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
class WebGPUViewComponentDescriptor final
|
|
53
|
+
: public ConcreteComponentDescriptor<WebGPUViewCustomShadowNode> {
|
|
54
|
+
public:
|
|
55
|
+
using ConcreteComponentDescriptor::ConcreteComponentDescriptor;
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
} // namespace react
|
|
59
|
+
} // namespace facebook
|
|
60
|
+
|
|
61
|
+
#endif // RCT_NEW_ARCH_ENABLED
|
package/ios/WebGPUViewManager.mm
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
#import "MetalView.h"
|
|
1
2
|
#import "RCTBridge.h"
|
|
2
|
-
#import "
|
|
3
|
+
#import "WebGPUModule.h"
|
|
3
4
|
#import <React/RCTUIManager.h>
|
|
4
5
|
#import <React/RCTViewManager.h>
|
|
5
6
|
|
|
@@ -11,11 +12,12 @@
|
|
|
11
12
|
RCT_EXPORT_MODULE(WebGPUView)
|
|
12
13
|
|
|
13
14
|
- (UIView *)view {
|
|
14
|
-
return [
|
|
15
|
+
return [MetalView new];
|
|
15
16
|
}
|
|
16
17
|
|
|
17
|
-
RCT_CUSTOM_VIEW_PROPERTY(
|
|
18
|
-
|
|
18
|
+
RCT_CUSTOM_VIEW_PROPERTY(contextId, NSNumber, UIView) {
|
|
19
|
+
NSNumber *contextId = [RCTConvert NSNumber:json];
|
|
20
|
+
[(MetalView *)view setContextId:contextId];
|
|
19
21
|
}
|
|
20
22
|
|
|
21
23
|
@end
|