react-native-wgpu 0.1.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/LICENSE +20 -0
- package/README.md +31 -0
- package/android/CMakeLists.txt +74 -0
- package/android/build.gradle +166 -0
- package/android/cpp/cpp-adapter.cpp +12 -0
- package/android/gradle.properties +5 -0
- package/android/src/main/AndroidManifest.xml +3 -0
- package/android/src/main/AndroidManifestNew.xml +2 -0
- package/android/src/main/java/com/webgpu/WebGPUModule.java +39 -0
- package/android/src/main/java/com/webgpu/WebGPUView.java +24 -0
- package/android/src/main/java/com/webgpu/WebGPUViewManager.java +31 -0
- package/android/src/main/java/com/webgpu/WebGPUViewPackage.java +26 -0
- package/android/src/newarch/WgpuViewManagerSpec.java +24 -0
- package/android/src/oldarch/WebGPUViewManagerSpec.java +11 -0
- package/cpp/Logger.h +82 -0
- package/cpp/dawn/dawn_proc_table.h +308 -0
- package/cpp/dawn/webgpu.h +4201 -0
- package/cpp/dawn/webgpu_cpp.h +8985 -0
- package/cpp/dawn/webgpu_cpp_print.h +2460 -0
- package/cpp/dawn/wire/client/webgpu.h +339 -0
- package/cpp/dawn/wire/client/webgpu_cpp.h +9140 -0
- package/cpp/jsi/RNFEnumMapper.h +49 -0
- package/cpp/jsi/RNFHybridObject.cpp +145 -0
- package/cpp/jsi/RNFHybridObject.h +162 -0
- package/cpp/jsi/RNFJSIConverter.h +412 -0
- package/cpp/jsi/RNFJSIHelper.h +49 -0
- package/cpp/jsi/RNFPointerHolder.h +95 -0
- package/cpp/jsi/RNFPromise.cpp +45 -0
- package/cpp/jsi/RNFPromise.h +38 -0
- package/cpp/jsi/RNFRuntimeCache.cpp +57 -0
- package/cpp/jsi/RNFRuntimeCache.h +79 -0
- package/cpp/jsi/RNFWorkletRuntimeCollector.h +43 -0
- package/cpp/jsi/RNFWorkletRuntimeRegistry.cpp +11 -0
- package/cpp/jsi/RNFWorkletRuntimeRegistry.h +44 -0
- package/cpp/rnwgpu/MutableBuffer.h +48 -0
- package/cpp/rnwgpu/RNWebGPUManager.cpp +60 -0
- package/cpp/rnwgpu/RNWebGPUManager.h +30 -0
- package/cpp/rnwgpu/api/GPU.cpp +40 -0
- package/cpp/rnwgpu/api/GPU.h +43 -0
- package/cpp/rnwgpu/api/GPUAdapter.cpp +33 -0
- package/cpp/rnwgpu/api/GPUAdapter.h +40 -0
- package/cpp/rnwgpu/api/GPUAdapterInfo.h +33 -0
- package/cpp/rnwgpu/api/GPUBindGroup.h +38 -0
- package/cpp/rnwgpu/api/GPUBindGroupLayout.h +39 -0
- package/cpp/rnwgpu/api/GPUBuffer.cpp +16 -0
- package/cpp/rnwgpu/api/GPUBuffer.h +44 -0
- package/cpp/rnwgpu/api/GPUCanvasContext.h +33 -0
- package/cpp/rnwgpu/api/GPUCommandBuffer.h +38 -0
- package/cpp/rnwgpu/api/GPUCommandEncoder.h +38 -0
- package/cpp/rnwgpu/api/GPUCompilationInfo.h +33 -0
- package/cpp/rnwgpu/api/GPUCompilationMessage.h +33 -0
- package/cpp/rnwgpu/api/GPUComputePassEncoder.h +40 -0
- package/cpp/rnwgpu/api/GPUComputePipeline.h +39 -0
- package/cpp/rnwgpu/api/GPUDevice.cpp +12 -0
- package/cpp/rnwgpu/api/GPUDevice.h +45 -0
- package/cpp/rnwgpu/api/GPUDeviceLostInfo.h +33 -0
- package/cpp/rnwgpu/api/GPUExternalTexture.h +39 -0
- package/cpp/rnwgpu/api/GPUPipelineLayout.h +38 -0
- package/cpp/rnwgpu/api/GPUQuerySet.h +38 -0
- package/cpp/rnwgpu/api/GPUQueue.h +38 -0
- package/cpp/rnwgpu/api/GPURenderBundle.h +38 -0
- package/cpp/rnwgpu/api/GPURenderBundleEncoder.h +40 -0
- package/cpp/rnwgpu/api/GPURenderPassEncoder.h +40 -0
- package/cpp/rnwgpu/api/GPURenderPipeline.h +38 -0
- package/cpp/rnwgpu/api/GPUSampler.h +38 -0
- package/cpp/rnwgpu/api/GPUShaderModule.h +38 -0
- package/cpp/rnwgpu/api/GPUSupportedLimits.h +33 -0
- package/cpp/rnwgpu/api/GPUTexture.h +38 -0
- package/cpp/rnwgpu/api/GPUTextureView.h +38 -0
- package/cpp/rnwgpu/api/GPUUncapturedErrorEvent.h +33 -0
- package/cpp/rnwgpu/api/descriptors/GPUBindGroupDescriptor.h +81 -0
- package/cpp/rnwgpu/api/descriptors/GPUBindGroupEntry.h +67 -0
- package/cpp/rnwgpu/api/descriptors/GPUBindGroupLayoutDescriptor.h +69 -0
- package/cpp/rnwgpu/api/descriptors/GPUBindGroupLayoutEntry.h +95 -0
- package/cpp/rnwgpu/api/descriptors/GPUBlendComponent.h +56 -0
- package/cpp/rnwgpu/api/descriptors/GPUBlendState.h +65 -0
- package/cpp/rnwgpu/api/descriptors/GPUBufferBinding.h +72 -0
- package/cpp/rnwgpu/api/descriptors/GPUBufferBindingLayout.h +62 -0
- package/cpp/rnwgpu/api/descriptors/GPUBufferDescriptor.h +85 -0
- package/cpp/rnwgpu/api/descriptors/GPUBufferUsage.h +43 -0
- package/cpp/rnwgpu/api/descriptors/GPUCanvasConfiguration.h +93 -0
- package/cpp/rnwgpu/api/descriptors/GPUColorDict.h +81 -0
- package/cpp/rnwgpu/api/descriptors/GPUColorTargetState.h +69 -0
- package/cpp/rnwgpu/api/descriptors/GPUColorWrite.h +31 -0
- package/cpp/rnwgpu/api/descriptors/GPUComputePassDescriptor.h +62 -0
- package/cpp/rnwgpu/api/descriptors/GPUComputePassTimestampWrites.h +80 -0
- package/cpp/rnwgpu/api/descriptors/GPUComputePipelineDescriptor.h +82 -0
- package/cpp/rnwgpu/api/descriptors/GPUDepthStencilState.h +126 -0
- package/cpp/rnwgpu/api/descriptors/GPUDeviceDescriptor.h +69 -0
- package/cpp/rnwgpu/api/descriptors/GPUExtent3DDict.h +76 -0
- package/cpp/rnwgpu/api/descriptors/GPUExtent3DDictStrict.h +91 -0
- package/cpp/rnwgpu/api/descriptors/GPUExternalTextureBindingLayout.h +44 -0
- package/cpp/rnwgpu/api/descriptors/GPUExternalTextureDescriptor.h +75 -0
- package/cpp/rnwgpu/api/descriptors/GPUFragmentState.h +85 -0
- package/cpp/rnwgpu/api/descriptors/GPUImageCopyBuffer.h +83 -0
- package/cpp/rnwgpu/api/descriptors/GPUImageCopyExternalImage.h +66 -0
- package/cpp/rnwgpu/api/descriptors/GPUImageCopyTexture.h +74 -0
- package/cpp/rnwgpu/api/descriptors/GPUImageCopyTextureTagged.h +88 -0
- package/cpp/rnwgpu/api/descriptors/GPUImageDataLayout.h +70 -0
- package/cpp/rnwgpu/api/descriptors/GPUMapMode.h +25 -0
- package/cpp/rnwgpu/api/descriptors/GPUMultisampleState.h +68 -0
- package/cpp/rnwgpu/api/descriptors/GPUOrigin2DDict.h +61 -0
- package/cpp/rnwgpu/api/descriptors/GPUOrigin2DDictStrict.h +75 -0
- package/cpp/rnwgpu/api/descriptors/GPUOrigin3DDict.h +71 -0
- package/cpp/rnwgpu/api/descriptors/GPUPipelineErrorInit.h +54 -0
- package/cpp/rnwgpu/api/descriptors/GPUPipelineLayoutDescriptor.h +72 -0
- package/cpp/rnwgpu/api/descriptors/GPUPrimitiveState.h +66 -0
- package/cpp/rnwgpu/api/descriptors/GPUProgrammableStage.h +72 -0
- package/cpp/rnwgpu/api/descriptors/GPUQuerySetDescriptor.h +81 -0
- package/cpp/rnwgpu/api/descriptors/GPURenderBundleEncoderDescriptor.h +102 -0
- package/cpp/rnwgpu/api/descriptors/GPURenderPassColorAttachment.h +105 -0
- package/cpp/rnwgpu/api/descriptors/GPURenderPassDepthStencilAttachment.h +118 -0
- package/cpp/rnwgpu/api/descriptors/GPURenderPassDescriptor.h +100 -0
- package/cpp/rnwgpu/api/descriptors/GPURenderPassLayout.h +83 -0
- package/cpp/rnwgpu/api/descriptors/GPURenderPassTimestampWrites.h +80 -0
- package/cpp/rnwgpu/api/descriptors/GPURenderPipelineDescriptor.h +104 -0
- package/cpp/rnwgpu/api/descriptors/GPURequestAdapterOptions.h +56 -0
- package/cpp/rnwgpu/api/descriptors/GPUSamplerBindingLayout.h +48 -0
- package/cpp/rnwgpu/api/descriptors/GPUSamplerDescriptor.h +116 -0
- package/cpp/rnwgpu/api/descriptors/GPUShaderModuleCompilationHint.h +64 -0
- package/cpp/rnwgpu/api/descriptors/GPUShaderModuleDescriptor.h +88 -0
- package/cpp/rnwgpu/api/descriptors/GPUShaderStage.h +27 -0
- package/cpp/rnwgpu/api/descriptors/GPUStencilFaceState.h +61 -0
- package/cpp/rnwgpu/api/descriptors/GPUStorageTextureBindingLayout.h +67 -0
- package/cpp/rnwgpu/api/descriptors/GPUTextureBindingLayout.h +58 -0
- package/cpp/rnwgpu/api/descriptors/GPUTextureDescriptor.h +123 -0
- package/cpp/rnwgpu/api/descriptors/GPUTextureUsage.h +40 -0
- package/cpp/rnwgpu/api/descriptors/GPUTextureViewDescriptor.h +113 -0
- package/cpp/rnwgpu/api/descriptors/GPUUncapturedErrorEventInit.h +71 -0
- package/cpp/rnwgpu/api/descriptors/GPUVertexAttribute.h +80 -0
- package/cpp/rnwgpu/api/descriptors/GPUVertexBufferLayout.h +73 -0
- package/cpp/rnwgpu/api/descriptors/GPUVertexState.h +77 -0
- package/cpp/rnwgpu/api/descriptors/Unions.h +1645 -0
- package/cpp/webgpu/webgpu.h +33 -0
- package/cpp/webgpu/webgpu_cpp.h +33 -0
- package/cpp/webgpu/webgpu_cpp_chained_struct.h +55 -0
- package/cpp/webgpu/webgpu_enum_class_bitmasks.h +161 -0
- package/ios/RNFAppleLogger.mm +22 -0
- package/ios/Utils.h +5 -0
- package/ios/Utils.m +26 -0
- package/ios/WebGPUModule.h +18 -0
- package/ios/WebGPUModule.mm +77 -0
- package/ios/WebGPUView.h +15 -0
- package/ios/WebGPUView.mm +58 -0
- package/ios/WebGPUViewManager.mm +21 -0
- package/lib/commonjs/WebGPUNativeModule.js +10 -0
- package/lib/commonjs/WebGPUNativeModule.js.map +1 -0
- package/lib/commonjs/WebGPUViewNativeComponent.js +11 -0
- package/lib/commonjs/WebGPUViewNativeComponent.js.map +1 -0
- package/lib/commonjs/index.js +45 -0
- package/lib/commonjs/index.js.map +1 -0
- package/lib/module/WebGPUNativeModule.js +4 -0
- package/lib/module/WebGPUNativeModule.js.map +1 -0
- package/lib/module/WebGPUViewNativeComponent.js +4 -0
- package/lib/module/WebGPUViewNativeComponent.js.map +1 -0
- package/lib/module/index.js +9 -0
- package/lib/module/index.js.map +1 -0
- package/lib/typescript/babel.config.d.ts +2 -0
- package/lib/typescript/babel.config.d.ts.map +1 -0
- package/lib/typescript/jest.config.d.ts +5 -0
- package/lib/typescript/jest.config.d.ts.map +1 -0
- package/lib/typescript/lib/commonjs/WebGPUNativeModule.d.ts +5 -0
- package/lib/typescript/lib/commonjs/WebGPUNativeModule.d.ts.map +1 -0
- package/lib/typescript/lib/commonjs/WebGPUViewNativeComponent.d.ts +4 -0
- package/lib/typescript/lib/commonjs/WebGPUViewNativeComponent.d.ts.map +1 -0
- package/lib/typescript/lib/commonjs/index.d.ts +5 -0
- package/lib/typescript/lib/commonjs/index.d.ts.map +1 -0
- package/lib/typescript/lib/module/WebGPUNativeModule.d.ts +3 -0
- package/lib/typescript/lib/module/WebGPUNativeModule.d.ts.map +1 -0
- package/lib/typescript/lib/module/WebGPUViewNativeComponent.d.ts +4 -0
- package/lib/typescript/lib/module/WebGPUViewNativeComponent.d.ts.map +1 -0
- package/lib/typescript/lib/module/index.d.ts +5 -0
- package/lib/typescript/lib/module/index.d.ts.map +1 -0
- package/lib/typescript/scripts/build/copy-artifacts.d.ts +2 -0
- package/lib/typescript/scripts/build/copy-artifacts.d.ts.map +1 -0
- package/lib/typescript/scripts/build/dawn.d.ts +2 -0
- package/lib/typescript/scripts/build/dawn.d.ts.map +1 -0
- package/lib/typescript/scripts/build/util.d.ts +13 -0
- package/lib/typescript/scripts/build/util.d.ts.map +1 -0
- package/lib/typescript/scripts/codegen/codegen.d.ts +2 -0
- package/lib/typescript/scripts/codegen/codegen.d.ts.map +1 -0
- package/lib/typescript/scripts/codegen/model/dawn.d.ts +2 -0
- package/lib/typescript/scripts/codegen/model/dawn.d.ts.map +1 -0
- package/lib/typescript/scripts/codegen/model/model.d.ts +8 -0
- package/lib/typescript/scripts/codegen/model/model.d.ts.map +1 -0
- package/lib/typescript/scripts/codegen/templates/Descriptor.d.ts +4 -0
- package/lib/typescript/scripts/codegen/templates/Descriptor.d.ts.map +1 -0
- package/lib/typescript/scripts/codegen/templates/Enum.d.ts +3 -0
- package/lib/typescript/scripts/codegen/templates/Enum.d.ts.map +1 -0
- package/lib/typescript/scripts/codegen/templates/HybridObject.d.ts +3 -0
- package/lib/typescript/scripts/codegen/templates/HybridObject.d.ts.map +1 -0
- package/lib/typescript/scripts/codegen/templates/Unions.d.ts +6 -0
- package/lib/typescript/scripts/codegen/templates/Unions.d.ts.map +1 -0
- package/lib/typescript/scripts/codegen/templates/common.d.ts +9 -0
- package/lib/typescript/scripts/codegen/templates/common.d.ts.map +1 -0
- package/lib/typescript/scripts/codegen/util.d.ts +2 -0
- package/lib/typescript/scripts/codegen/util.d.ts.map +1 -0
- package/lib/typescript/src/WebGPUNativeModule.d.ts +7 -0
- package/lib/typescript/src/WebGPUNativeModule.d.ts.map +1 -0
- package/lib/typescript/src/WebGPUViewNativeComponent.d.ts +8 -0
- package/lib/typescript/src/WebGPUViewNativeComponent.d.ts.map +1 -0
- package/lib/typescript/src/index.d.ts +9 -0
- package/lib/typescript/src/index.d.ts.map +1 -0
- package/package.json +120 -0
- package/react-native-webgpu.podspec +56 -0
- package/src/WebGPUNativeModule.ts +9 -0
- package/src/WebGPUViewNativeComponent.ts +9 -0
- package/src/index.tsx +13 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 William Candillon
|
|
4
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
5
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
6
|
+
in the Software without restriction, including without limitation the rights
|
|
7
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
8
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
9
|
+
furnished to do so, subject to the following conditions:
|
|
10
|
+
|
|
11
|
+
The above copyright notice and this permission notice shall be included in all
|
|
12
|
+
copies or substantial portions of the Software.
|
|
13
|
+
|
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
15
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
16
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
17
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
18
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
19
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
20
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
# react-native-wgpu
|
|
2
|
+
|
|
3
|
+
React Native WebGPU
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```sh
|
|
8
|
+
npm install react-native-wgpu
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
```js
|
|
14
|
+
import { WgpuView } from "react-native-wgpu";
|
|
15
|
+
|
|
16
|
+
// ...
|
|
17
|
+
|
|
18
|
+
<WgpuView color="tomato" />
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## Contributing
|
|
22
|
+
|
|
23
|
+
See the [contributing guide](CONTRIBUTING.md) to learn how to contribute to the repository and the development workflow.
|
|
24
|
+
|
|
25
|
+
## License
|
|
26
|
+
|
|
27
|
+
MIT
|
|
28
|
+
|
|
29
|
+
---
|
|
30
|
+
|
|
31
|
+
Made with [create-react-native-library](https://github.com/callstack/react-native-builder-bob)
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
cmake_minimum_required(VERSION 3.4.1)
|
|
2
|
+
project(RNWGPU)
|
|
3
|
+
|
|
4
|
+
set (CMAKE_VERBOSE_MAKEFILE ON)
|
|
5
|
+
set (CMAKE_CXX_STANDARD 17)
|
|
6
|
+
|
|
7
|
+
set (PACKAGE_NAME "react-native-webgpu")
|
|
8
|
+
|
|
9
|
+
#link_directories(../libs/android/${ANDROID_ABI}/)
|
|
10
|
+
|
|
11
|
+
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
|
|
12
|
+
add_definitions(-DDEBUG=1)
|
|
13
|
+
endif()
|
|
14
|
+
|
|
15
|
+
if(RNF_ENABLE_LOGS)
|
|
16
|
+
add_definitions(-DRNF_ENABLE_LOGS=1)
|
|
17
|
+
else()
|
|
18
|
+
add_definitions(-DRNF_ENABLE_LOGS=0)
|
|
19
|
+
endif()
|
|
20
|
+
|
|
21
|
+
set (WEBGPU_LIBS_PATH "${CMAKE_CURRENT_SOURCE_DIR}/../libs/android/${ANDROID_ABI}")
|
|
22
|
+
|
|
23
|
+
find_package(ReactAndroid REQUIRED CONFIG)
|
|
24
|
+
find_package(fbjni REQUIRED CONFIG)
|
|
25
|
+
|
|
26
|
+
add_library(${PACKAGE_NAME} SHARED
|
|
27
|
+
./cpp/cpp-adapter.cpp
|
|
28
|
+
../cpp/rnwgpu/api/GPU.cpp
|
|
29
|
+
../cpp/rnwgpu/api/GPUAdapter.cpp
|
|
30
|
+
../cpp/rnwgpu/api/GPUDevice.cpp
|
|
31
|
+
../cpp/rnwgpu/api/GPUBuffer.cpp
|
|
32
|
+
../cpp/rnwgpu/RNWebGPUManager.cpp
|
|
33
|
+
../cpp/jsi/RNFPromise.cpp
|
|
34
|
+
../cpp/jsi/RNFHybridObject.cpp
|
|
35
|
+
../cpp/jsi/RNFRuntimeCache.cpp
|
|
36
|
+
../cpp/jsi/RNFWorkletRuntimeRegistry.cpp
|
|
37
|
+
)
|
|
38
|
+
|
|
39
|
+
target_include_directories(
|
|
40
|
+
${PACKAGE_NAME}
|
|
41
|
+
PRIVATE
|
|
42
|
+
|
|
43
|
+
"${NODE_MODULES_DIR}/react-native/ReactCommon/callinvoker"
|
|
44
|
+
"${NODE_MODULES_DIR}/react-native/ReactCommon/jsi"
|
|
45
|
+
"${NODE_MODULES_DIR}/react-native/ReactCommon"
|
|
46
|
+
"${NODE_MODULES_DIR}/react-native/ReactCommon/react/nativemodule/core"
|
|
47
|
+
"${NODE_MODULES_DIR}/react-native/ReactCommon/runtimeexecutor"
|
|
48
|
+
"${NODE_MODULES_DIR}/react-native/ReactAndroid/src/main/jni"
|
|
49
|
+
"${NODE_MODULES_DIR}/react-native/ReactAndroid/src/main/java/com/facebook/react/turbomodule/core/jni"
|
|
50
|
+
|
|
51
|
+
../cpp
|
|
52
|
+
../cpp/rnwgpu
|
|
53
|
+
../cpp/rnwgpu/api
|
|
54
|
+
../cpp/rnwgpu/api/descriptors
|
|
55
|
+
../cpp/jsi
|
|
56
|
+
../cpp/webgpu
|
|
57
|
+
|
|
58
|
+
${libfbjni_include_DIRS}
|
|
59
|
+
)
|
|
60
|
+
|
|
61
|
+
add_library(webgpu_dawn SHARED IMPORTED)
|
|
62
|
+
set_property(TARGET webgpu_dawn PROPERTY IMPORTED_LOCATION "${WEBGPU_LIBS_PATH}/libwebgpu_dawn.so")
|
|
63
|
+
|
|
64
|
+
# Link
|
|
65
|
+
target_link_libraries(
|
|
66
|
+
${PACKAGE_NAME}
|
|
67
|
+
${FBJNI_LIBRARY}
|
|
68
|
+
log
|
|
69
|
+
jnigraphics
|
|
70
|
+
android
|
|
71
|
+
fbjni::fbjni
|
|
72
|
+
ReactAndroid::jsi
|
|
73
|
+
webgpu_dawn
|
|
74
|
+
)
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
import java.nio.file.Paths
|
|
2
|
+
|
|
3
|
+
buildscript {
|
|
4
|
+
repositories {
|
|
5
|
+
google()
|
|
6
|
+
mavenCentral()
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
dependencies {
|
|
10
|
+
classpath "com.android.tools.build:gradle:7.2.1"
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
def reactNativeArchitectures() {
|
|
15
|
+
def value = rootProject.getProperties().get("reactNativeArchitectures")
|
|
16
|
+
return value ? value.split(",") : ["armeabi-v7a", "x86", "x86_64", "arm64-v8a"]
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
def isNewArchitectureEnabled() {
|
|
20
|
+
return rootProject.hasProperty("newArchEnabled") && rootProject.getProperty("newArchEnabled") == "true"
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
apply plugin: "com.android.library"
|
|
24
|
+
|
|
25
|
+
if (isNewArchitectureEnabled()) {
|
|
26
|
+
apply plugin: "com.facebook.react"
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
static def findNodeModules(baseDir) {
|
|
30
|
+
// Check if we are building the example app:
|
|
31
|
+
// Check if ../FabricExample/node_modules exists
|
|
32
|
+
def exampleAppPath = Paths.get(baseDir.toString(), "..", "FabricExample")
|
|
33
|
+
def exampleNodeModulesPath = Paths.get(exampleAppPath.toString(), "node_modules")
|
|
34
|
+
if (exampleNodeModulesPath.toFile().exists()) {
|
|
35
|
+
return exampleNodeModulesPath.toAbsolutePath()
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
def basePath = baseDir.toPath().normalize()
|
|
39
|
+
// Node's module resolution algorithm searches up to the root directory,
|
|
40
|
+
// after which the base path will be null
|
|
41
|
+
while (basePath) {
|
|
42
|
+
def nodeModulesPath = Paths.get(basePath.toString(), "node_modules")
|
|
43
|
+
def reactNativePath = Paths.get(nodeModulesPath.toString(), "react-native")
|
|
44
|
+
if (nodeModulesPath.toFile().exists() && reactNativePath.toFile().exists()) {
|
|
45
|
+
return nodeModulesPath.toString()
|
|
46
|
+
}
|
|
47
|
+
basePath = basePath.getParent()
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
throw new GradleException("react-native-filament: Failed to find node_modules/ path!")
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
def nodeModules = findNodeModules(projectDir)
|
|
54
|
+
|
|
55
|
+
def getExtOrDefault(name) {
|
|
56
|
+
return rootProject.ext.has(name) ? rootProject.ext.get(name) : project.properties["Wgpu_" + name]
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
def getExtOrIntegerDefault(name) {
|
|
60
|
+
return rootProject.ext.has(name) ? rootProject.ext.get(name) : (project.properties["Wgpu_" + name]).toInteger()
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
def supportsNamespace() {
|
|
64
|
+
def parsed = com.android.Version.ANDROID_GRADLE_PLUGIN_VERSION.tokenize('.')
|
|
65
|
+
def major = parsed[0].toInteger()
|
|
66
|
+
def minor = parsed[1].toInteger()
|
|
67
|
+
|
|
68
|
+
// Namespace support was added in 7.3.0
|
|
69
|
+
return (major == 7 && minor >= 3) || major >= 8
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
android {
|
|
73
|
+
if (supportsNamespace()) {
|
|
74
|
+
namespace "com.wgpu"
|
|
75
|
+
|
|
76
|
+
sourceSets {
|
|
77
|
+
main {
|
|
78
|
+
manifest.srcFile "src/main/AndroidManifestNew.xml"
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
compileSdkVersion getExtOrIntegerDefault("compileSdkVersion")
|
|
84
|
+
|
|
85
|
+
defaultConfig {
|
|
86
|
+
minSdkVersion getExtOrIntegerDefault("minSdkVersion")
|
|
87
|
+
targetSdkVersion getExtOrIntegerDefault("targetSdkVersion")
|
|
88
|
+
buildConfigField "boolean", "IS_NEW_ARCHITECTURE_ENABLED", isNewArchitectureEnabled().toString()
|
|
89
|
+
externalNativeBuild {
|
|
90
|
+
cmake {
|
|
91
|
+
cppFlags "-fexceptions", "-frtti", "-std=c++1y", "-DONANDROID"
|
|
92
|
+
abiFilters (*reactNativeArchitectures())
|
|
93
|
+
arguments '-DANDROID_STL=c++_shared',
|
|
94
|
+
"-DNODE_MODULES_DIR=${nodeModules}"
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
packagingOptions {
|
|
100
|
+
exclude "lib/arm64-v8a/libjsi.so"
|
|
101
|
+
exclude "lib/x86_64/libjsi.so"
|
|
102
|
+
exclude "lib/x86/libjsi.so"
|
|
103
|
+
exclude "lib/armeabi-v7a/libjsi.so"
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
buildFeatures {
|
|
107
|
+
buildConfig true
|
|
108
|
+
prefab true
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
buildTypes {
|
|
112
|
+
release {
|
|
113
|
+
minifyEnabled false
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
lintOptions {
|
|
118
|
+
disable "GradleCompatible"
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
compileOptions {
|
|
122
|
+
sourceCompatibility JavaVersion.VERSION_1_8
|
|
123
|
+
targetCompatibility JavaVersion.VERSION_1_8
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
sourceSets {
|
|
127
|
+
main {
|
|
128
|
+
if (isNewArchitectureEnabled()) {
|
|
129
|
+
java.srcDirs += [
|
|
130
|
+
"src/newarch",
|
|
131
|
+
// This is needed to build Kotlin project with NewArch enabled
|
|
132
|
+
"${project.buildDir}/generated/source/codegen/java"
|
|
133
|
+
]
|
|
134
|
+
} else {
|
|
135
|
+
java.srcDirs += ["src/oldarch"]
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
externalNativeBuild {
|
|
141
|
+
cmake {
|
|
142
|
+
path file('CMakeLists.txt')
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
repositories {
|
|
148
|
+
mavenCentral()
|
|
149
|
+
google()
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
|
|
153
|
+
dependencies {
|
|
154
|
+
// For < 0.71, this will be from the local maven repo
|
|
155
|
+
// For > 0.71, this will be replaced by `com.facebook.react:react-android:$version` by react gradle plugin
|
|
156
|
+
//noinspection GradleDynamicVersion
|
|
157
|
+
implementation "com.facebook.react:react-native:+"
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
if (isNewArchitectureEnabled()) {
|
|
161
|
+
react {
|
|
162
|
+
jsRootDir = file("../src/")
|
|
163
|
+
libraryName = "WgpuView"
|
|
164
|
+
codegenJavaPackageName = "com.wgpu"
|
|
165
|
+
}
|
|
166
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
#include "Logger.h"
|
|
2
|
+
#include "RNWebGPUManager.h"
|
|
3
|
+
#include <fbjni/fbjni.h>
|
|
4
|
+
#include <jni.h>
|
|
5
|
+
|
|
6
|
+
#define LOG_TAG "WebGPUModule"
|
|
7
|
+
|
|
8
|
+
extern "C" JNIEXPORT void JNICALL Java_com_webgpu_WebGPUModule_initializeNative(
|
|
9
|
+
JNIEnv *env, jobject /* this */, jlong jsRuntime, jobject jsInvokerHolder) {
|
|
10
|
+
auto runtime = reinterpret_cast<facebook::jsi::Runtime *>(jsRuntime);
|
|
11
|
+
auto manager = new rnwgpu::RNWebGPUManager(runtime, nullptr);
|
|
12
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
package com.webgpu;
|
|
2
|
+
|
|
3
|
+
import com.facebook.jni.HybridData;
|
|
4
|
+
import com.facebook.proguard.annotations.DoNotStrip;
|
|
5
|
+
import com.facebook.react.bridge.ReactApplicationContext;
|
|
6
|
+
import com.facebook.react.bridge.ReactContextBaseJavaModule;
|
|
7
|
+
import com.facebook.react.bridge.JavaScriptContextHolder;
|
|
8
|
+
import com.facebook.react.bridge.ReactMethod;
|
|
9
|
+
import com.facebook.react.common.annotations.FrameworkAPI;
|
|
10
|
+
import com.facebook.react.turbomodule.core.CallInvokerHolderImpl;
|
|
11
|
+
import com.facebook.react.turbomodule.core.interfaces.CallInvokerHolder;
|
|
12
|
+
|
|
13
|
+
@FrameworkAPI public class WebGPUModule extends ReactContextBaseJavaModule {
|
|
14
|
+
static {
|
|
15
|
+
System.loadLibrary("react-native-webgpu"); // Load the C++ library
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
public WebGPUModule(ReactApplicationContext reactContext) {
|
|
19
|
+
super(reactContext);
|
|
20
|
+
// Initialize the C++ module
|
|
21
|
+
initialize();
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
@Override
|
|
25
|
+
public String getName() {
|
|
26
|
+
return "WebGPUModule";
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
@ReactMethod(isBlockingSynchronousMethod = true)
|
|
30
|
+
public void install() {
|
|
31
|
+
ReactApplicationContext context = getReactApplicationContext();
|
|
32
|
+
JavaScriptContextHolder jsContext = context.getJavaScriptContextHolder();
|
|
33
|
+
CallInvokerHolder callInvokerHolder = context.getCatalystInstance().getJSCallInvokerHolder();
|
|
34
|
+
initializeNative(jsContext.get(), (CallInvokerHolderImpl) callInvokerHolder);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
@DoNotStrip
|
|
38
|
+
private native void initializeNative(long jsRuntime, CallInvokerHolderImpl jsInvoker);
|
|
39
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
package com.webgpu;
|
|
2
|
+
|
|
3
|
+
import androidx.annotation.Nullable;
|
|
4
|
+
|
|
5
|
+
import android.content.Context;
|
|
6
|
+
import android.util.AttributeSet;
|
|
7
|
+
|
|
8
|
+
import android.view.View;
|
|
9
|
+
|
|
10
|
+
public class WebGPUView extends View {
|
|
11
|
+
|
|
12
|
+
public WebGPUView(Context context) {
|
|
13
|
+
super(context);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
public WebGPUView(Context context, @Nullable AttributeSet attrs) {
|
|
17
|
+
super(context, attrs);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
public WebGPUView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
|
|
21
|
+
super(context, attrs, defStyleAttr);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
package com.webgpu;
|
|
2
|
+
|
|
3
|
+
import android.graphics.Color;
|
|
4
|
+
|
|
5
|
+
import androidx.annotation.Nullable;
|
|
6
|
+
|
|
7
|
+
import com.facebook.react.module.annotations.ReactModule;
|
|
8
|
+
import com.facebook.react.uimanager.ThemedReactContext;
|
|
9
|
+
import com.facebook.react.uimanager.annotations.ReactProp;
|
|
10
|
+
|
|
11
|
+
@ReactModule(name = WebGPUViewManager.NAME)
|
|
12
|
+
public class WebGPUViewManager extends WebGPUViewManagerSpec<WebGPUView> {
|
|
13
|
+
|
|
14
|
+
public static final String NAME = "WebGPUView";
|
|
15
|
+
|
|
16
|
+
@Override
|
|
17
|
+
public String getName() {
|
|
18
|
+
return NAME;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
@Override
|
|
22
|
+
public WebGPUView createViewInstance(ThemedReactContext context) {
|
|
23
|
+
return new WebGPUView(context);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
@Override
|
|
27
|
+
@ReactProp(name = "color")
|
|
28
|
+
public void setColor(WebGPUView view, @Nullable String color) {
|
|
29
|
+
view.setBackgroundColor(Color.parseColor(color));
|
|
30
|
+
}
|
|
31
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
|
|
2
|
+
package com.webgpu;
|
|
3
|
+
|
|
4
|
+
import com.facebook.react.ReactPackage;
|
|
5
|
+
import com.facebook.react.bridge.NativeModule;
|
|
6
|
+
import com.facebook.react.bridge.ReactApplicationContext;
|
|
7
|
+
import com.facebook.react.uimanager.ViewManager;
|
|
8
|
+
|
|
9
|
+
import java.util.ArrayList;
|
|
10
|
+
import java.util.Arrays;
|
|
11
|
+
import java.util.List;
|
|
12
|
+
|
|
13
|
+
public class WebGPUViewPackage implements ReactPackage {
|
|
14
|
+
@Override
|
|
15
|
+
public List<ViewManager> createViewManagers(ReactApplicationContext reactContext) {
|
|
16
|
+
List<ViewManager> viewManagers = new ArrayList<>();
|
|
17
|
+
viewManagers.add(new WebGPUViewManager());
|
|
18
|
+
return viewManagers;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
@Override
|
|
23
|
+
public List<NativeModule> createNativeModules(ReactApplicationContext reactContext) {
|
|
24
|
+
return Arrays.asList(new WebGPUModule(reactContext));
|
|
25
|
+
}
|
|
26
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
package com.webgpu;
|
|
2
|
+
|
|
3
|
+
import android.view.View;
|
|
4
|
+
|
|
5
|
+
import androidx.annotation.Nullable;
|
|
6
|
+
|
|
7
|
+
import com.facebook.react.uimanager.SimpleViewManager;
|
|
8
|
+
import com.facebook.react.uimanager.ViewManagerDelegate;
|
|
9
|
+
import com.facebook.react.viewmanagers.WgpuViewManagerDelegate;
|
|
10
|
+
import com.facebook.react.viewmanagers.WgpuViewManagerInterface;
|
|
11
|
+
|
|
12
|
+
public abstract class WgpuViewManagerSpec<T extends View> extends SimpleViewManager<T> implements WgpuViewManagerInterface<T> {
|
|
13
|
+
private final ViewManagerDelegate<T> mDelegate;
|
|
14
|
+
|
|
15
|
+
public WgpuViewManagerSpec() {
|
|
16
|
+
mDelegate = new WgpuViewManagerDelegate(this);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
@Nullable
|
|
20
|
+
@Override
|
|
21
|
+
protected ViewManagerDelegate<T> getDelegate() {
|
|
22
|
+
return mDelegate;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
package com.webgpu;
|
|
2
|
+
|
|
3
|
+
import android.view.View;
|
|
4
|
+
|
|
5
|
+
import androidx.annotation.Nullable;
|
|
6
|
+
|
|
7
|
+
import com.facebook.react.uimanager.SimpleViewManager;
|
|
8
|
+
|
|
9
|
+
public abstract class WebGPUViewManagerSpec<T extends View> extends SimpleViewManager<T> {
|
|
10
|
+
public abstract void setColor(T view, @Nullable String value);
|
|
11
|
+
}
|
package/cpp/Logger.h
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Created by Christian Falch on 26/08/2021.
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
#pragma once
|
|
6
|
+
|
|
7
|
+
#include <jsi/jsi.h>
|
|
8
|
+
#include <string>
|
|
9
|
+
|
|
10
|
+
#if defined(ANDROID) || defined(__ANDROID__)
|
|
11
|
+
#include <android/log.h>
|
|
12
|
+
#endif
|
|
13
|
+
|
|
14
|
+
#ifdef TARGET_OS_IPHONE
|
|
15
|
+
#include <syslog.h>
|
|
16
|
+
#endif
|
|
17
|
+
|
|
18
|
+
namespace rnwgpu {
|
|
19
|
+
|
|
20
|
+
namespace jsi = facebook::jsi;
|
|
21
|
+
|
|
22
|
+
class Logger {
|
|
23
|
+
public:
|
|
24
|
+
/**
|
|
25
|
+
* Logs message to console
|
|
26
|
+
* @param message Message to be written out
|
|
27
|
+
*/
|
|
28
|
+
static void logToConsole(std::string message) {
|
|
29
|
+
#if defined(ANDROID) || defined(__ANDROID__)
|
|
30
|
+
__android_log_write(ANDROID_LOG_INFO, "RNSkia", message.c_str());
|
|
31
|
+
#endif
|
|
32
|
+
|
|
33
|
+
#ifdef TARGET_OS_IPHONE
|
|
34
|
+
syslog(LOG_ERR, "%s\n", message.c_str());
|
|
35
|
+
#endif
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Logs to console
|
|
40
|
+
* @param fmt Format string
|
|
41
|
+
* @param ... Arguments to format string
|
|
42
|
+
*/
|
|
43
|
+
static void logToConsole(const char *fmt, ...) {
|
|
44
|
+
va_list args;
|
|
45
|
+
va_start(args, fmt);
|
|
46
|
+
|
|
47
|
+
static char buffer[512];
|
|
48
|
+
vsnprintf(buffer, sizeof(buffer), fmt, args);
|
|
49
|
+
#if defined(ANDROID) || defined(__ANDROID__)
|
|
50
|
+
__android_log_write(ANDROID_LOG_INFO, "RNSkia", buffer);
|
|
51
|
+
#endif
|
|
52
|
+
#ifdef TARGET_OS_IPHONE
|
|
53
|
+
syslog(LOG_ERR, "RNSKIA: %s\n", buffer);
|
|
54
|
+
#endif
|
|
55
|
+
va_end(args);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
static void logToJavascriptConsole(jsi::Runtime &runtime,
|
|
59
|
+
const std::string &message) {
|
|
60
|
+
auto console = Logger::getJavascriptConsole(runtime).asObject(runtime);
|
|
61
|
+
auto log = console.getPropertyAsFunction(runtime, "log");
|
|
62
|
+
log.call(runtime, jsi::String::createFromUtf8(runtime, message));
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
static void warnToJavascriptConsole(jsi::Runtime &runtime,
|
|
66
|
+
const std::string &message) {
|
|
67
|
+
auto console = Logger::getJavascriptConsole(runtime).asObject(runtime);
|
|
68
|
+
auto warn = console.getPropertyAsFunction(runtime, "warn");
|
|
69
|
+
warn.call(runtime, jsi::String::createFromUtf8(runtime, message));
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
private:
|
|
73
|
+
static jsi::Value getJavascriptConsole(jsi::Runtime &runtime) {
|
|
74
|
+
auto console = runtime.global().getProperty(runtime, "console");
|
|
75
|
+
if (console.isUndefined() || console.isNull()) {
|
|
76
|
+
throw jsi::JSError(runtime, "Could not find console object.");
|
|
77
|
+
return jsi::Value::undefined();
|
|
78
|
+
}
|
|
79
|
+
return console;
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
} // namespace rnwgpu
|