@shopify/react-native-skia 2.4.15 → 2.4.17
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/android/CMakeLists.txt +69 -0
- package/android/src/main/java/com/shopify/reactnative/skia/SkiaBaseView.java +19 -7
- package/android/src/main/java/com/shopify/reactnative/skia/SkiaBaseViewManager.java +7 -0
- package/apple/RNSkApplePlatformContext.mm +4 -0
- package/cpp/api/JsiSkApi.h +31 -0
- package/cpp/api/JsiSkImageFactory.h +69 -1
- package/cpp/api/JsiSkImageFilter.h +1 -0
- package/cpp/api/JsiSkPath.h +1 -1
- package/cpp/jsi/RuntimeAwareCache.h +0 -2
- package/cpp/jsi2/EnumMapper.h +45 -0
- package/cpp/jsi2/JSIConverter.h +468 -0
- package/cpp/jsi2/NativeObject.h +598 -0
- package/cpp/jsi2/Promise.cpp +44 -0
- package/cpp/jsi2/Promise.h +35 -0
- package/cpp/rnskia/RNDawnContext.h +114 -0
- package/cpp/rnskia/RNSkManager.cpp +41 -1
- package/cpp/rnwgpu/ArrayBuffer.h +68 -0
- package/cpp/rnwgpu/api/Convertors.h +761 -0
- package/cpp/rnwgpu/api/External.h +12 -0
- package/cpp/rnwgpu/api/GPU.cpp +129 -0
- package/cpp/rnwgpu/api/GPU.h +57 -0
- package/cpp/rnwgpu/api/GPUAdapter.cpp +178 -0
- package/cpp/rnwgpu/api/GPUAdapter.h +59 -0
- package/cpp/rnwgpu/api/GPUAdapterInfo.h +57 -0
- package/cpp/rnwgpu/api/GPUBindGroup.cpp +3 -0
- package/cpp/rnwgpu/api/GPUBindGroup.h +51 -0
- package/cpp/rnwgpu/api/GPUBindGroupLayout.h +52 -0
- package/cpp/rnwgpu/api/GPUBuffer.cpp +97 -0
- package/cpp/rnwgpu/api/GPUBuffer.h +87 -0
- package/cpp/rnwgpu/api/GPUCommandBuffer.h +45 -0
- package/cpp/rnwgpu/api/GPUCommandEncoder.cpp +179 -0
- package/cpp/rnwgpu/api/GPUCommandEncoder.h +111 -0
- package/cpp/rnwgpu/api/GPUCompilationInfo.h +79 -0
- package/cpp/rnwgpu/api/GPUCompilationMessage.h +36 -0
- package/cpp/rnwgpu/api/GPUComputePassEncoder.cpp +60 -0
- package/cpp/rnwgpu/api/GPUComputePassEncoder.h +85 -0
- package/cpp/rnwgpu/api/GPUComputePipeline.cpp +12 -0
- package/cpp/rnwgpu/api/GPUComputePipeline.h +60 -0
- package/cpp/rnwgpu/api/GPUDevice.cpp +434 -0
- package/cpp/rnwgpu/api/GPUDevice.h +174 -0
- package/cpp/rnwgpu/api/GPUDeviceLostInfo.cpp +7 -0
- package/cpp/rnwgpu/api/GPUDeviceLostInfo.h +40 -0
- package/cpp/rnwgpu/api/GPUError.h +35 -0
- package/cpp/rnwgpu/api/GPUExtent3D.h +66 -0
- package/cpp/rnwgpu/api/GPUExternalTexture.h +45 -0
- package/cpp/rnwgpu/api/GPUFeatures.h +212 -0
- package/cpp/rnwgpu/api/GPUInternalError.h +31 -0
- package/cpp/rnwgpu/api/GPUOrigin2D.h +55 -0
- package/cpp/rnwgpu/api/GPUOrigin3D.h +62 -0
- package/cpp/rnwgpu/api/GPUOutOfMemoryError.h +33 -0
- package/cpp/rnwgpu/api/GPUPipelineLayout.h +45 -0
- package/cpp/rnwgpu/api/GPUQuerySet.cpp +11 -0
- package/cpp/rnwgpu/api/GPUQuerySet.h +73 -0
- package/cpp/rnwgpu/api/GPUQueue.cpp +169 -0
- package/cpp/rnwgpu/api/GPUQueue.h +84 -0
- package/cpp/rnwgpu/api/GPURenderBundle.h +44 -0
- package/cpp/rnwgpu/api/GPURenderBundleEncoder.cpp +131 -0
- package/cpp/rnwgpu/api/GPURenderBundleEncoder.h +110 -0
- package/cpp/rnwgpu/api/GPURenderPassEncoder.cpp +165 -0
- package/cpp/rnwgpu/api/GPURenderPassEncoder.h +130 -0
- package/cpp/rnwgpu/api/GPURenderPipeline.cpp +13 -0
- package/cpp/rnwgpu/api/GPURenderPipeline.h +61 -0
- package/cpp/rnwgpu/api/GPUSampler.h +44 -0
- package/cpp/rnwgpu/api/GPUShaderModule.cpp +51 -0
- package/cpp/rnwgpu/api/GPUShaderModule.h +66 -0
- package/cpp/rnwgpu/api/GPUSupportedLimits.cpp +129 -0
- package/cpp/rnwgpu/api/GPUSupportedLimits.h +131 -0
- package/cpp/rnwgpu/api/GPUTexture.cpp +47 -0
- package/cpp/rnwgpu/api/GPUTexture.h +150 -0
- package/cpp/rnwgpu/api/GPUTextureView.h +44 -0
- package/cpp/rnwgpu/api/GPUValidationError.h +32 -0
- package/cpp/rnwgpu/api/descriptors/GPUBindGroupDescriptor.h +64 -0
- package/cpp/rnwgpu/api/descriptors/GPUBindGroupEntry.h +71 -0
- package/cpp/rnwgpu/api/descriptors/GPUBindGroupLayoutDescriptor.h +56 -0
- package/cpp/rnwgpu/api/descriptors/GPUBindGroupLayoutEntry.h +97 -0
- package/cpp/rnwgpu/api/descriptors/GPUBlendComponent.h +57 -0
- package/cpp/rnwgpu/api/descriptors/GPUBlendState.h +52 -0
- package/cpp/rnwgpu/api/descriptors/GPUBufferBinding.h +56 -0
- package/cpp/rnwgpu/api/descriptors/GPUBufferBindingLayout.h +56 -0
- package/cpp/rnwgpu/api/descriptors/GPUBufferDescriptor.h +59 -0
- package/cpp/rnwgpu/api/descriptors/GPUBufferUsage.h +39 -0
- package/cpp/rnwgpu/api/descriptors/GPUColor.h +66 -0
- package/cpp/rnwgpu/api/descriptors/GPUColorTargetState.h +58 -0
- package/cpp/rnwgpu/api/descriptors/GPUColorWrite.h +29 -0
- package/cpp/rnwgpu/api/descriptors/GPUCommandBufferDescriptor.h +45 -0
- package/cpp/rnwgpu/api/descriptors/GPUCommandEncoderDescriptor.h +45 -0
- package/cpp/rnwgpu/api/descriptors/GPUComputePassDescriptor.h +56 -0
- package/cpp/rnwgpu/api/descriptors/GPUComputePassTimestampWrites.h +58 -0
- package/cpp/rnwgpu/api/descriptors/GPUComputePipelineDescriptor.h +67 -0
- package/cpp/rnwgpu/api/descriptors/GPUDepthStencilState.h +103 -0
- package/cpp/rnwgpu/api/descriptors/GPUDeviceDescriptor.h +99 -0
- package/cpp/rnwgpu/api/descriptors/GPUExternalTextureBindingLayout.h +38 -0
- package/cpp/rnwgpu/api/descriptors/GPUExternalTextureDescriptor.h +71 -0
- package/cpp/rnwgpu/api/descriptors/GPUFragmentState.h +73 -0
- package/cpp/rnwgpu/api/descriptors/GPUImageCopyBuffer.h +62 -0
- package/cpp/rnwgpu/api/descriptors/GPUImageCopyExternalImage.h +62 -0
- package/cpp/rnwgpu/api/descriptors/GPUImageCopyTexture.h +65 -0
- package/cpp/rnwgpu/api/descriptors/GPUImageCopyTextureTagged.h +81 -0
- package/cpp/rnwgpu/api/descriptors/GPUImageDataLayout.h +54 -0
- package/cpp/rnwgpu/api/descriptors/GPUMapMode.h +22 -0
- package/cpp/rnwgpu/api/descriptors/GPUMultisampleState.h +54 -0
- package/cpp/rnwgpu/api/descriptors/GPUPipelineLayoutDescriptor.h +57 -0
- package/cpp/rnwgpu/api/descriptors/GPUPrimitiveState.h +69 -0
- package/cpp/rnwgpu/api/descriptors/GPUProgrammableStage.h +61 -0
- package/cpp/rnwgpu/api/descriptors/GPUQuerySetDescriptor.h +55 -0
- package/cpp/rnwgpu/api/descriptors/GPUQueueDescriptor.h +43 -0
- package/cpp/rnwgpu/api/descriptors/GPURenderBundleDescriptor.h +45 -0
- package/cpp/rnwgpu/api/descriptors/GPURenderBundleEncoderDescriptor.h +80 -0
- package/cpp/rnwgpu/api/descriptors/GPURenderPassColorAttachment.h +81 -0
- package/cpp/rnwgpu/api/descriptors/GPURenderPassDepthStencilAttachment.h +101 -0
- package/cpp/rnwgpu/api/descriptors/GPURenderPassDescriptor.h +92 -0
- package/cpp/rnwgpu/api/descriptors/GPURenderPassTimestampWrites.h +58 -0
- package/cpp/rnwgpu/api/descriptors/GPURenderPipelineDescriptor.h +103 -0
- package/cpp/rnwgpu/api/descriptors/GPURequestAdapterOptions.h +51 -0
- package/cpp/rnwgpu/api/descriptors/GPUSamplerBindingLayout.h +45 -0
- package/cpp/rnwgpu/api/descriptors/GPUSamplerDescriptor.h +110 -0
- package/cpp/rnwgpu/api/descriptors/GPUShaderModuleCompilationHint.h +60 -0
- package/cpp/rnwgpu/api/descriptors/GPUShaderModuleDescriptor.h +62 -0
- package/cpp/rnwgpu/api/descriptors/GPUShaderStage.h +25 -0
- package/cpp/rnwgpu/api/descriptors/GPUStencilFaceState.h +64 -0
- package/cpp/rnwgpu/api/descriptors/GPUStorageTextureBindingLayout.h +59 -0
- package/cpp/rnwgpu/api/descriptors/GPUTextureBindingLayout.h +59 -0
- package/cpp/rnwgpu/api/descriptors/GPUTextureDescriptor.h +91 -0
- package/cpp/rnwgpu/api/descriptors/GPUTextureUsage.h +29 -0
- package/cpp/rnwgpu/api/descriptors/GPUTextureViewDescriptor.h +91 -0
- package/cpp/rnwgpu/api/descriptors/GPUUncapturedErrorEventInit.h +64 -0
- package/cpp/rnwgpu/api/descriptors/GPUVertexAttribute.h +53 -0
- package/cpp/rnwgpu/api/descriptors/GPUVertexBufferLayout.h +62 -0
- package/cpp/rnwgpu/api/descriptors/GPUVertexState.h +73 -0
- package/cpp/rnwgpu/api/descriptors/Unions.h +1984 -0
- package/cpp/rnwgpu/async/AsyncDispatcher.h +28 -0
- package/cpp/rnwgpu/async/AsyncRunner.cpp +181 -0
- package/cpp/rnwgpu/async/AsyncRunner.h +56 -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/lib/commonjs/Platform/Platform.web.js +1 -2
- package/lib/commonjs/Platform/Platform.web.js.map +1 -1
- package/lib/commonjs/external/reanimated/buffers.js.map +1 -1
- package/lib/commonjs/external/reanimated/interpolators.d.ts +1 -4
- package/lib/commonjs/renderer/Canvas.js +4 -3
- package/lib/commonjs/renderer/Canvas.js.map +1 -1
- package/lib/commonjs/renderer/components/Group.js +1 -2
- package/lib/commonjs/renderer/components/Group.js.map +1 -1
- package/lib/commonjs/renderer/components/shapes/FitBox.js +1 -2
- package/lib/commonjs/renderer/components/shapes/FitBox.js.map +1 -1
- package/lib/commonjs/skia/types/ContourMeasure.js.map +1 -1
- package/lib/commonjs/skia/types/Image/ImageFactory.d.ts +20 -0
- package/lib/commonjs/skia/types/Image/ImageFactory.js.map +1 -1
- package/lib/commonjs/skia/types/RuntimeEffect/RuntimeEffect.js.map +1 -1
- package/lib/commonjs/skia/types/Skia.d.ts +17 -0
- package/lib/commonjs/skia/types/Skia.js.map +1 -1
- package/lib/commonjs/skia/web/JsiSkImageFactory.d.ts +2 -0
- package/lib/commonjs/skia/web/JsiSkImageFactory.js +6 -0
- package/lib/commonjs/skia/web/JsiSkImageFactory.js.map +1 -1
- package/lib/commonjs/skia/web/JsiSkParagraphStyle.js +2 -2
- package/lib/commonjs/skia/web/JsiSkParagraphStyle.js.map +1 -1
- package/lib/commonjs/skia/web/JsiSkia.js +6 -0
- package/lib/commonjs/skia/web/JsiSkia.js.map +1 -1
- package/lib/commonjs/sksg/Recorder/commands/ColorFilters.js.map +1 -1
- package/lib/commonjs/sksg/Recorder/commands/ImageFilters.js.map +1 -1
- package/lib/commonjs/sksg/Recorder/commands/PathEffects.js.map +1 -1
- package/lib/commonjs/sksg/Recorder/commands/Shaders.js.map +1 -1
- package/lib/commonjs/specs/SkiaPictureViewNativeComponent.d.ts +2 -0
- package/lib/commonjs/specs/SkiaPictureViewNativeComponent.js +2 -0
- package/lib/commonjs/specs/SkiaPictureViewNativeComponent.js.map +1 -1
- package/lib/commonjs/views/SkiaPictureView.web.js +4 -4
- package/lib/commonjs/views/SkiaPictureView.web.js.map +1 -1
- package/lib/commonjs/web/WithSkiaWeb.js +1 -2
- package/lib/commonjs/web/WithSkiaWeb.js.map +1 -1
- package/lib/module/external/reanimated/buffers.js.map +1 -1
- package/lib/module/external/reanimated/interpolators.d.ts +1 -4
- package/lib/module/renderer/Canvas.js +3 -1
- package/lib/module/renderer/Canvas.js.map +1 -1
- package/lib/module/skia/types/ContourMeasure.js.map +1 -1
- package/lib/module/skia/types/Image/ImageFactory.d.ts +20 -0
- package/lib/module/skia/types/Image/ImageFactory.js.map +1 -1
- package/lib/module/skia/types/RuntimeEffect/RuntimeEffect.js.map +1 -1
- package/lib/module/skia/types/Skia.d.ts +17 -0
- package/lib/module/skia/types/Skia.js.map +1 -1
- package/lib/module/skia/web/JsiSkImageFactory.d.ts +2 -0
- package/lib/module/skia/web/JsiSkImageFactory.js +6 -0
- package/lib/module/skia/web/JsiSkImageFactory.js.map +1 -1
- package/lib/module/skia/web/JsiSkParagraphStyle.js +2 -2
- package/lib/module/skia/web/JsiSkParagraphStyle.js.map +1 -1
- package/lib/module/skia/web/JsiSkia.js +6 -0
- package/lib/module/skia/web/JsiSkia.js.map +1 -1
- package/lib/module/sksg/Recorder/commands/ColorFilters.js.map +1 -1
- package/lib/module/sksg/Recorder/commands/ImageFilters.js.map +1 -1
- package/lib/module/sksg/Recorder/commands/PathEffects.js.map +1 -1
- package/lib/module/sksg/Recorder/commands/Shaders.js.map +1 -1
- package/lib/module/specs/SkiaPictureViewNativeComponent.d.ts +2 -0
- package/lib/module/specs/SkiaPictureViewNativeComponent.js +4 -0
- package/lib/module/specs/SkiaPictureViewNativeComponent.js.map +1 -1
- package/lib/module/views/SkiaPictureView.web.js +3 -2
- package/lib/module/views/SkiaPictureView.web.js.map +1 -1
- package/lib/typescript/lib/commonjs/skia/web/JsiSkImageFactory.d.ts +2 -0
- package/lib/typescript/lib/commonjs/skia/web/JsiSkia.d.ts +2 -0
- package/lib/typescript/lib/module/renderer/Canvas.d.ts +1 -1
- package/lib/typescript/lib/module/skia/Skia.web.d.ts +2 -0
- package/lib/typescript/lib/module/skia/web/JsiSkImageFactory.d.ts +2 -0
- package/lib/typescript/lib/module/skia/web/JsiSkia.d.ts +2 -0
- package/lib/typescript/lib/module/views/SkiaPictureView.d.ts +1 -1
- package/lib/typescript/src/external/reanimated/interpolators.d.ts +1 -4
- package/lib/typescript/src/skia/types/Image/ImageFactory.d.ts +20 -0
- package/lib/typescript/src/skia/types/Skia.d.ts +17 -0
- package/lib/typescript/src/skia/web/JsiSkImageFactory.d.ts +2 -0
- package/lib/typescript/src/specs/SkiaPictureViewNativeComponent.d.ts +2 -0
- package/package.json +20 -16
- package/react-native-skia.podspec +52 -13
- package/scripts/install-skia.mjs +99 -48
- package/src/external/reanimated/buffers.ts +1 -1
- package/src/renderer/Canvas.tsx +3 -2
- package/src/skia/types/ContourMeasure.tsx +1 -2
- package/src/skia/types/Image/ImageFactory.ts +22 -0
- package/src/skia/types/RuntimeEffect/RuntimeEffect.ts +1 -2
- package/src/skia/types/Skia.ts +17 -0
- package/src/skia/web/JsiSkImageFactory.ts +8 -0
- package/src/skia/web/JsiSkia.ts +6 -0
- package/src/sksg/Recorder/commands/ColorFilters.ts +3 -2
- package/src/sksg/Recorder/commands/ImageFilters.ts +3 -2
- package/src/sksg/Recorder/commands/PathEffects.ts +3 -2
- package/src/sksg/Recorder/commands/Shaders.ts +3 -2
- package/src/specs/SkiaPictureViewNativeComponent.ts +7 -0
- package/src/views/SkiaPictureView.web.tsx +4 -1
|
@@ -0,0 +1,468 @@
|
|
|
1
|
+
#pragma once
|
|
2
|
+
|
|
3
|
+
#include <memory>
|
|
4
|
+
#include <vector>
|
|
5
|
+
#include <string>
|
|
6
|
+
#include <utility>
|
|
7
|
+
#include <type_traits>
|
|
8
|
+
#include <limits>
|
|
9
|
+
#include <variant>
|
|
10
|
+
#include <map>
|
|
11
|
+
#include <unordered_set>
|
|
12
|
+
|
|
13
|
+
#include <jsi/jsi.h>
|
|
14
|
+
|
|
15
|
+
#include "EnumMapper.h"
|
|
16
|
+
#include "Promise.h"
|
|
17
|
+
|
|
18
|
+
#ifdef SK_GRAPHITE
|
|
19
|
+
#include "rnwgpu/api/descriptors/Unions.h"
|
|
20
|
+
#include "rnwgpu/async/AsyncTaskHandle.h"
|
|
21
|
+
#endif
|
|
22
|
+
|
|
23
|
+
// This number is the maximum integer that can be represented exactly as a double
|
|
24
|
+
#define MAX_SAFE_INTEGER static_cast<uint64_t>(9007199254740991)
|
|
25
|
+
|
|
26
|
+
#if __has_include(<cxxabi.h>)
|
|
27
|
+
#include <cxxabi.h>
|
|
28
|
+
#endif
|
|
29
|
+
|
|
30
|
+
namespace rnwgpu {
|
|
31
|
+
|
|
32
|
+
namespace jsi = facebook::jsi;
|
|
33
|
+
|
|
34
|
+
// Unknown type (error)
|
|
35
|
+
template <typename ArgType, typename Enable = void> struct JSIConverter {
|
|
36
|
+
static ArgType fromJSI(jsi::Runtime&, const jsi::Value&, bool outOfBound) {
|
|
37
|
+
static_assert(always_false<ArgType>::value, "This type is not supported by the JSIConverter!");
|
|
38
|
+
return ArgType();
|
|
39
|
+
}
|
|
40
|
+
static jsi::Value toJSI(jsi::Runtime&, ArgType) {
|
|
41
|
+
static_assert(always_false<ArgType>::value, "This type is not supported by the JSIConverter!");
|
|
42
|
+
return jsi::Value::undefined();
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
private:
|
|
46
|
+
template <typename> struct always_false : std::false_type {};
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
// int <> number
|
|
50
|
+
template <> struct JSIConverter<int> {
|
|
51
|
+
static int fromJSI(jsi::Runtime&, const jsi::Value& arg, bool outOfBound) {
|
|
52
|
+
return static_cast<int>(arg.asNumber());
|
|
53
|
+
}
|
|
54
|
+
static jsi::Value toJSI(jsi::Runtime&, int arg) {
|
|
55
|
+
return jsi::Value(arg);
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
// double <> number
|
|
60
|
+
template <> struct JSIConverter<double> {
|
|
61
|
+
static double fromJSI(jsi::Runtime&, const jsi::Value& arg, bool outOfBound) {
|
|
62
|
+
return arg.asNumber();
|
|
63
|
+
}
|
|
64
|
+
static jsi::Value toJSI(jsi::Runtime&, double arg) {
|
|
65
|
+
return jsi::Value(arg);
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
// float <> number
|
|
70
|
+
template <> struct JSIConverter<float> {
|
|
71
|
+
static float fromJSI(jsi::Runtime&, const jsi::Value& arg, bool outOfBound) {
|
|
72
|
+
return static_cast<float>(arg.asNumber());
|
|
73
|
+
}
|
|
74
|
+
static jsi::Value toJSI(jsi::Runtime&, float arg) {
|
|
75
|
+
return jsi::Value(static_cast<double>(arg));
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
template <> struct JSIConverter<std::nullptr_t> {
|
|
80
|
+
static std::nullptr_t fromJSI(jsi::Runtime&, const jsi::Value& arg, bool outOfBound) {
|
|
81
|
+
return nullptr;
|
|
82
|
+
}
|
|
83
|
+
static jsi::Value toJSI(jsi::Runtime&, std::nullptr_t arg) {
|
|
84
|
+
return jsi::Value::null();
|
|
85
|
+
}
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
template <typename T>
|
|
89
|
+
struct JSIConverter<T, std::enable_if_t<!std::is_same_v<T, uint64_t> && std::is_same_v<T, size_t>>> {
|
|
90
|
+
static size_t fromJSI(jsi::Runtime& runtime, const jsi::Value& arg, bool outOfBound) {
|
|
91
|
+
if (arg.isNumber()) {
|
|
92
|
+
double value = arg.asNumber();
|
|
93
|
+
return static_cast<size_t>(value);
|
|
94
|
+
} else {
|
|
95
|
+
return arg.asBigInt(runtime).asInt64(runtime);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
static jsi::Value toJSI(jsi::Runtime& runtime, size_t arg) {
|
|
100
|
+
return jsi::Value(static_cast<double>(arg));
|
|
101
|
+
}
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
// uint32_t <> double
|
|
105
|
+
template <> struct JSIConverter<uint32_t> {
|
|
106
|
+
static double fromJSI(jsi::Runtime& runtime, const jsi::Value& arg, bool outOfBound) {
|
|
107
|
+
double value = arg.asNumber();
|
|
108
|
+
return static_cast<uint32_t>(value);
|
|
109
|
+
}
|
|
110
|
+
static jsi::Value toJSI(jsi::Runtime& runtime, uint32_t arg) {
|
|
111
|
+
return jsi::Value(static_cast<double>(arg));
|
|
112
|
+
}
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
// uint64_t <> BigInt
|
|
116
|
+
template <> struct JSIConverter<uint64_t> {
|
|
117
|
+
static uint64_t fromJSI(jsi::Runtime& runtime, const jsi::Value& arg, bool outOfBound) {
|
|
118
|
+
if (arg.isNumber()) {
|
|
119
|
+
double value = arg.asNumber();
|
|
120
|
+
if (value < 0 || value > MAX_SAFE_INTEGER) {
|
|
121
|
+
throw jsi::JSError(runtime, "Number out of range for uint64_t");
|
|
122
|
+
}
|
|
123
|
+
return static_cast<uint64_t>(value);
|
|
124
|
+
} else {
|
|
125
|
+
return arg.asBigInt(runtime).getUint64(runtime);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
static jsi::Value toJSI(jsi::Runtime& runtime, uint64_t arg) {
|
|
130
|
+
if (arg <= MAX_SAFE_INTEGER) {
|
|
131
|
+
return jsi::Value(static_cast<double>(arg));
|
|
132
|
+
} else {
|
|
133
|
+
throw jsi::JSError(runtime, "Number too large to be represented as a double");
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
};
|
|
137
|
+
|
|
138
|
+
template <> struct JSIConverter<void *> {
|
|
139
|
+
static void* fromJSI(jsi::Runtime& runtime, const jsi::Value& arg, bool outOfBound) {
|
|
140
|
+
return reinterpret_cast<void *>(arg.asBigInt(runtime).getUint64(runtime));
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
static jsi::Value toJSI(jsi::Runtime& runtime, void* arg) {
|
|
144
|
+
return jsi::BigInt::fromUint64(runtime, reinterpret_cast<uint64_t>(arg));
|
|
145
|
+
}
|
|
146
|
+
};
|
|
147
|
+
|
|
148
|
+
// bool <> boolean
|
|
149
|
+
template <> struct JSIConverter<bool> {
|
|
150
|
+
static bool fromJSI(jsi::Runtime&, const jsi::Value& arg, bool outOfBound) {
|
|
151
|
+
return arg.asBool();
|
|
152
|
+
}
|
|
153
|
+
static jsi::Value toJSI(jsi::Runtime&, bool arg) {
|
|
154
|
+
return jsi::Value(arg);
|
|
155
|
+
}
|
|
156
|
+
};
|
|
157
|
+
|
|
158
|
+
// std::string <> string
|
|
159
|
+
template <> struct JSIConverter<std::string> {
|
|
160
|
+
static std::string fromJSI(jsi::Runtime& runtime, const jsi::Value& arg, bool outOfBound) {
|
|
161
|
+
return arg.asString(runtime).utf8(runtime);
|
|
162
|
+
}
|
|
163
|
+
static jsi::Value toJSI(jsi::Runtime& runtime, const std::string& arg) {
|
|
164
|
+
return jsi::String::createFromUtf8(runtime, arg);
|
|
165
|
+
}
|
|
166
|
+
};
|
|
167
|
+
|
|
168
|
+
// std::optional<T> <> T | undefined
|
|
169
|
+
template <typename TInner> struct JSIConverter<std::optional<TInner>> {
|
|
170
|
+
static std::optional<TInner> fromJSI(jsi::Runtime& runtime, const jsi::Value& arg, bool outOfBound) {
|
|
171
|
+
if (outOfBound || arg.isUndefined()) {
|
|
172
|
+
return {};
|
|
173
|
+
} else {
|
|
174
|
+
return JSIConverter<TInner>::fromJSI(runtime, std::move(arg), outOfBound);
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
static jsi::Value toJSI(jsi::Runtime& runtime, const std::optional<TInner>& arg) {
|
|
178
|
+
if (arg == std::nullopt) {
|
|
179
|
+
return jsi::Value::undefined();
|
|
180
|
+
} else {
|
|
181
|
+
return JSIConverter<TInner>::toJSI(runtime, arg.value());
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
};
|
|
185
|
+
|
|
186
|
+
// Enum <> Union
|
|
187
|
+
template <typename TEnum> struct JSIConverter<TEnum, std::enable_if_t<std::is_enum<TEnum>::value>> {
|
|
188
|
+
static TEnum fromJSI(jsi::Runtime& runtime, const jsi::Value& arg, bool outOfBound) {
|
|
189
|
+
std::string string = arg.asString(runtime).utf8(runtime);
|
|
190
|
+
TEnum outEnum;
|
|
191
|
+
EnumMapper::convertJSUnionToEnum(string, &outEnum);
|
|
192
|
+
return outEnum;
|
|
193
|
+
}
|
|
194
|
+
static jsi::Value toJSI(jsi::Runtime& runtime, const TEnum& arg) {
|
|
195
|
+
std::string outUnion;
|
|
196
|
+
EnumMapper::convertEnumToJSUnion(arg, &outUnion);
|
|
197
|
+
return jsi::String::createFromUtf8(runtime, outUnion);
|
|
198
|
+
}
|
|
199
|
+
};
|
|
200
|
+
|
|
201
|
+
#ifdef SK_GRAPHITE
|
|
202
|
+
// AsyncTaskHandle <> Promise
|
|
203
|
+
template <> struct JSIConverter<rnwgpu::async::AsyncTaskHandle> {
|
|
204
|
+
static rnwgpu::async::AsyncTaskHandle fromJSI(jsi::Runtime&, const jsi::Value&, bool) {
|
|
205
|
+
throw std::runtime_error("Cannot convert a Promise to AsyncTaskHandle on the native side.");
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
static jsi::Value toJSI(jsi::Runtime& runtime, rnwgpu::async::AsyncTaskHandle&& handle) {
|
|
209
|
+
return rnwgpu::Promise::createPromise(runtime, [handle = std::move(handle)](jsi::Runtime& runtime,
|
|
210
|
+
std::shared_ptr<rnwgpu::Promise> promise) mutable {
|
|
211
|
+
if (!handle.valid()) {
|
|
212
|
+
promise->resolve(jsi::Value::undefined());
|
|
213
|
+
return;
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
handle.attachPromise(promise);
|
|
217
|
+
});
|
|
218
|
+
}
|
|
219
|
+
};
|
|
220
|
+
#endif
|
|
221
|
+
|
|
222
|
+
// std::map<std::string, T> <> Record<string, T>
|
|
223
|
+
template <typename ValueType> struct JSIConverter<std::map<std::string, ValueType>> {
|
|
224
|
+
static std::map<std::string, ValueType> fromJSI(jsi::Runtime& runtime, const jsi::Value& arg, bool outOfBound) {
|
|
225
|
+
jsi::Object object = arg.asObject(runtime);
|
|
226
|
+
jsi::Array propertyNames = object.getPropertyNames(runtime);
|
|
227
|
+
size_t length = propertyNames.size(runtime);
|
|
228
|
+
|
|
229
|
+
std::map<std::string, ValueType> map;
|
|
230
|
+
for (size_t i = 0; i < length; ++i) {
|
|
231
|
+
std::string key = propertyNames.getValueAtIndex(runtime, i).asString(runtime).utf8(runtime);
|
|
232
|
+
jsi::Value value = object.getProperty(runtime, key.c_str());
|
|
233
|
+
map.emplace(key, JSIConverter<ValueType>::fromJSI(runtime, value, outOfBound));
|
|
234
|
+
}
|
|
235
|
+
return map;
|
|
236
|
+
}
|
|
237
|
+
static jsi::Value toJSI(jsi::Runtime& runtime, const std::map<std::string, ValueType>& map) {
|
|
238
|
+
jsi::Object object(runtime);
|
|
239
|
+
for (const auto& pair : map) {
|
|
240
|
+
jsi::Value value = JSIConverter<ValueType>::toJSI(runtime, pair.second);
|
|
241
|
+
jsi::String key = jsi::String::createFromUtf8(runtime, pair.first);
|
|
242
|
+
object.setProperty(runtime, key, std::move(value));
|
|
243
|
+
}
|
|
244
|
+
return object;
|
|
245
|
+
}
|
|
246
|
+
};
|
|
247
|
+
|
|
248
|
+
|
|
249
|
+
// std::vector<T> <> T[]
|
|
250
|
+
template <typename ElementType> struct JSIConverter<std::vector<ElementType>> {
|
|
251
|
+
static std::vector<ElementType> fromJSI(jsi::Runtime& runtime, const jsi::Value& arg, bool outOfBound) {
|
|
252
|
+
jsi::Array array = arg.asObject(runtime).asArray(runtime);
|
|
253
|
+
size_t length = array.size(runtime);
|
|
254
|
+
|
|
255
|
+
std::vector<ElementType> vector;
|
|
256
|
+
vector.reserve(length);
|
|
257
|
+
for (size_t i = 0; i < length; ++i) {
|
|
258
|
+
jsi::Value elementValue = array.getValueAtIndex(runtime, i);
|
|
259
|
+
vector.emplace_back(JSIConverter<ElementType>::fromJSI(runtime, elementValue, outOfBound));
|
|
260
|
+
}
|
|
261
|
+
return vector;
|
|
262
|
+
}
|
|
263
|
+
static jsi::Value toJSI(jsi::Runtime& runtime, const std::vector<ElementType>& vector) {
|
|
264
|
+
jsi::Array array(runtime, vector.size());
|
|
265
|
+
for (size_t i = 0; i < vector.size(); i++) {
|
|
266
|
+
jsi::Value value = JSIConverter<ElementType>::toJSI(runtime, vector[i]);
|
|
267
|
+
array.setValueAtIndex(runtime, i, std::move(value));
|
|
268
|
+
}
|
|
269
|
+
return array;
|
|
270
|
+
}
|
|
271
|
+
};
|
|
272
|
+
|
|
273
|
+
// NativeState <> {}
|
|
274
|
+
template <typename T> struct is_shared_ptr_to_native_state : std::false_type {};
|
|
275
|
+
|
|
276
|
+
template <typename T> struct is_shared_ptr_to_native_state<std::shared_ptr<T>> : std::is_base_of<jsi::NativeState, T> {};
|
|
277
|
+
|
|
278
|
+
template <typename T> struct JSIConverter<T, std::enable_if_t<is_shared_ptr_to_native_state<T>::value>> {
|
|
279
|
+
using TPointee = typename T::element_type;
|
|
280
|
+
|
|
281
|
+
#if DEBUG
|
|
282
|
+
inline static std::string getFriendlyTypename() {
|
|
283
|
+
std::string name = std::string(typeid(TPointee).name());
|
|
284
|
+
#if __has_include(<cxxabi.h>)
|
|
285
|
+
int status = 0;
|
|
286
|
+
char* demangled_name = abi::__cxa_demangle(name.c_str(), NULL, NULL, &status);
|
|
287
|
+
if (status == 0) {
|
|
288
|
+
name = demangled_name;
|
|
289
|
+
std::free(demangled_name);
|
|
290
|
+
}
|
|
291
|
+
#endif
|
|
292
|
+
return name;
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
inline static std::string invalidTypeErrorMessage(const std::string& typeDescription, const std::string& reason) {
|
|
296
|
+
return "Cannot convert \"" + typeDescription + "\" to NativeState<" + getFriendlyTypename() + ">! " + reason;
|
|
297
|
+
}
|
|
298
|
+
#endif
|
|
299
|
+
|
|
300
|
+
static T fromJSI(jsi::Runtime& runtime, const jsi::Value& arg, bool outOfBound) {
|
|
301
|
+
#if DEBUG
|
|
302
|
+
if (arg.isUndefined()) {
|
|
303
|
+
[[unlikely]];
|
|
304
|
+
throw jsi::JSError(runtime, invalidTypeErrorMessage("undefined", "It is undefined!"));
|
|
305
|
+
}
|
|
306
|
+
if (!arg.isObject()) {
|
|
307
|
+
[[unlikely]];
|
|
308
|
+
std::string stringRepresentation = arg.toString(runtime).utf8(runtime);
|
|
309
|
+
throw jsi::JSError(runtime, invalidTypeErrorMessage(stringRepresentation, "It is not an object!"));
|
|
310
|
+
}
|
|
311
|
+
#endif
|
|
312
|
+
jsi::Object object = arg.getObject(runtime);
|
|
313
|
+
#if DEBUG
|
|
314
|
+
if (!object.hasNativeState<TPointee>(runtime)) {
|
|
315
|
+
[[unlikely]];
|
|
316
|
+
std::string stringRepresentation = arg.toString(runtime).utf8(runtime);
|
|
317
|
+
throw jsi::JSError(runtime, invalidTypeErrorMessage(stringRepresentation, "It is a different NativeState<T>!"));
|
|
318
|
+
}
|
|
319
|
+
#endif
|
|
320
|
+
return object.getNativeState<TPointee>(runtime);
|
|
321
|
+
}
|
|
322
|
+
private:
|
|
323
|
+
// SFINAE helper to detect if T has a IsNativeObject marker type
|
|
324
|
+
template <typename U, typename = typename U::IsNativeObject>
|
|
325
|
+
static std::true_type hasNativeObjectMarker(int);
|
|
326
|
+
template <typename U>
|
|
327
|
+
static std::false_type hasNativeObjectMarker(...);
|
|
328
|
+
|
|
329
|
+
// Type trait for detection
|
|
330
|
+
static constexpr bool is_native_object = decltype(hasNativeObjectMarker<TPointee>(0))::value;
|
|
331
|
+
|
|
332
|
+
public:
|
|
333
|
+
static jsi::Value toJSI(jsi::Runtime& runtime, const T& arg) {
|
|
334
|
+
#if DEBUG
|
|
335
|
+
if (arg == nullptr) {
|
|
336
|
+
[[unlikely]];
|
|
337
|
+
throw jsi::JSError(runtime, "Cannot convert nullptr to NativeState<" + getFriendlyTypename() + ">!");
|
|
338
|
+
}
|
|
339
|
+
#endif
|
|
340
|
+
// Check if the type is a NativeObject (has IsNativeObject marker)
|
|
341
|
+
// Use TPointee::create() if it's a NativeObject, otherwise fall back to plain setNativeState
|
|
342
|
+
if constexpr (is_native_object) {
|
|
343
|
+
return TPointee::create(runtime, arg);
|
|
344
|
+
} else {
|
|
345
|
+
jsi::Object object(runtime);
|
|
346
|
+
object.setNativeState(runtime, arg);
|
|
347
|
+
return object;
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
};
|
|
351
|
+
|
|
352
|
+
|
|
353
|
+
template <typename O, typename T>
|
|
354
|
+
struct JSIConverter<std::variant<std::vector<T>, std::shared_ptr<O>>> {
|
|
355
|
+
using Target = std::variant<std::vector<T>, std::shared_ptr<O>>;
|
|
356
|
+
|
|
357
|
+
static Target fromJSI(jsi::Runtime &runtime, const jsi::Value &arg,
|
|
358
|
+
bool outOfBound) {
|
|
359
|
+
if (arg.isObject()) {
|
|
360
|
+
auto object = arg.getObject(runtime);
|
|
361
|
+
if (object.isArray(runtime)) {
|
|
362
|
+
return Target(
|
|
363
|
+
JSIConverter<std::vector<T>>::fromJSI(runtime, arg, outOfBound));
|
|
364
|
+
}
|
|
365
|
+
throw std::runtime_error("Invalid variant type expected array");
|
|
366
|
+
}
|
|
367
|
+
return Target(
|
|
368
|
+
JSIConverter<std::shared_ptr<O>>::fromJSI(runtime, arg, outOfBound));
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
static jsi::Value toJSI(jsi::Runtime &, Target arg) {
|
|
372
|
+
return jsi::Value::null();
|
|
373
|
+
}
|
|
374
|
+
};
|
|
375
|
+
|
|
376
|
+
template <typename O>
|
|
377
|
+
struct JSIConverter<std::variant<std::nullptr_t, std::shared_ptr<O>>> {
|
|
378
|
+
using Target = std::variant<std::nullptr_t, std::shared_ptr<O>>;
|
|
379
|
+
|
|
380
|
+
static Target fromJSI(jsi::Runtime &runtime, const jsi::Value &arg,
|
|
381
|
+
bool outOfBound) {
|
|
382
|
+
if (arg.isNull()) {
|
|
383
|
+
return Target(nullptr);
|
|
384
|
+
}
|
|
385
|
+
return Target(
|
|
386
|
+
JSIConverter<std::shared_ptr<O>>::fromJSI(runtime, arg, outOfBound));
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
static jsi::Value toJSI(jsi::Runtime &runtime, Target arg) {
|
|
390
|
+
if (std::holds_alternative<std::nullptr_t>(arg)) {
|
|
391
|
+
return jsi::Value::null();
|
|
392
|
+
}
|
|
393
|
+
return JSIConverter<std::shared_ptr<O>>::toJSI(
|
|
394
|
+
runtime, std::get<std::shared_ptr<O>>(arg));
|
|
395
|
+
}
|
|
396
|
+
};
|
|
397
|
+
|
|
398
|
+
template <typename O>
|
|
399
|
+
struct JSIConverter<std::variant<std::nullptr_t, O>,
|
|
400
|
+
std::enable_if_t<std::is_enum_v<O>>> {
|
|
401
|
+
using Target = std::variant<std::nullptr_t, O>;
|
|
402
|
+
|
|
403
|
+
static Target fromJSI(jsi::Runtime &runtime, const jsi::Value &arg,
|
|
404
|
+
bool outOfBound) {
|
|
405
|
+
if (arg.isNull()) {
|
|
406
|
+
return Target(nullptr);
|
|
407
|
+
} else if (arg.isNumber()) {
|
|
408
|
+
return Target(static_cast<O>(arg.asNumber()));
|
|
409
|
+
}
|
|
410
|
+
return Target(JSIConverter<O>::fromJSI(runtime, arg, outOfBound));
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
static jsi::Value toJSI(jsi::Runtime &runtime, Target arg) {
|
|
414
|
+
if (std::holds_alternative<std::nullptr_t>(arg)) {
|
|
415
|
+
return jsi::Value::null();
|
|
416
|
+
}
|
|
417
|
+
return JSIConverter<O>::toJSI(runtime, std::get<O>(arg));
|
|
418
|
+
}
|
|
419
|
+
};
|
|
420
|
+
|
|
421
|
+
// TODO: careful std::variant<O, std::nullptr_t> doesn't overload
|
|
422
|
+
// std::variant<std::nullptr_t, 0> (order's matter)
|
|
423
|
+
// variant<nullptr_t, numeric>
|
|
424
|
+
template <typename O>
|
|
425
|
+
struct JSIConverter<
|
|
426
|
+
std::variant<O, std::nullptr_t>,
|
|
427
|
+
std::enable_if_t<std::is_arithmetic_v<O> || std::is_enum_v<O>>> {
|
|
428
|
+
using Target = std::variant<O, std::nullptr_t>;
|
|
429
|
+
static Target fromJSI(jsi::Runtime &runtime, const jsi::Value &arg,
|
|
430
|
+
bool outOfBound) {
|
|
431
|
+
if (arg.isNull()) {
|
|
432
|
+
return Target(nullptr);
|
|
433
|
+
}
|
|
434
|
+
if (arg.isNumber()) {
|
|
435
|
+
return Target(static_cast<O>(arg.asNumber()));
|
|
436
|
+
}
|
|
437
|
+
throw jsi::JSError(runtime, "Expected null or number");
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
static jsi::Value toJSI(jsi::Runtime &runtime, Target arg) {
|
|
441
|
+
if (std::holds_alternative<std::nullptr_t>(arg)) {
|
|
442
|
+
return jsi::Value::null();
|
|
443
|
+
}
|
|
444
|
+
return jsi::Value(static_cast<double>(std::get<O>(arg)));
|
|
445
|
+
}
|
|
446
|
+
};
|
|
447
|
+
|
|
448
|
+
template <>
|
|
449
|
+
struct JSIConverter<std::unordered_set<std::string>> {
|
|
450
|
+
using Target = std::unordered_set<std::string>;
|
|
451
|
+
static Target fromJSI(jsi::Runtime &runtime, const jsi::Value &arg,
|
|
452
|
+
bool outOfBound) {
|
|
453
|
+
throw jsi::JSError(runtime, "JSIConverter<std::unordered_set<std::string>>::fromJSI not implemented");
|
|
454
|
+
}
|
|
455
|
+
|
|
456
|
+
static jsi::Value toJSI(jsi::Runtime &runtime, Target arg) {
|
|
457
|
+
auto setConstructor = runtime.global().getPropertyAsFunction(runtime, "Set");
|
|
458
|
+
auto set = setConstructor.callAsConstructor(runtime).asObject(runtime);
|
|
459
|
+
auto add = set.getPropertyAsFunction(runtime, "add");
|
|
460
|
+
for (const auto& value : arg) {
|
|
461
|
+
jsi::Value jsiValue = JSIConverter<std::string>::toJSI(runtime, value);
|
|
462
|
+
add.callWithThis(runtime, set, jsiValue);
|
|
463
|
+
}
|
|
464
|
+
return std::move(set);
|
|
465
|
+
}
|
|
466
|
+
};
|
|
467
|
+
|
|
468
|
+
} // namespace rnwgpu
|