@shopify/react-native-skia 2.9.1-next.1 → 2.10.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/android/CMakeLists.txt +1 -5
- package/android/cpp/jni/JniWebGPUView.cpp +52 -7
- package/android/src/main/java/com/shopify/reactnative/skia/WebGPUSurfaceView.java +3 -1
- package/android/src/main/java/com/shopify/reactnative/skia/WebGPUTextureView.java +11 -5
- package/android/src/main/java/com/shopify/reactnative/skia/WebGPUView.java +10 -7
- package/android/src/main/java/com/shopify/reactnative/skia/WebGPUViewAPI.java +7 -2
- package/android/src/main/java/com/shopify/reactnative/skia/WebGPUViewManager.java +1 -1
- package/apple/WebGPUMetalView.mm +49 -6
- package/cpp/api/JsiNativeBuffer.h +15 -10
- package/cpp/api/JsiSkAnimatedImage.h +21 -19
- package/cpp/api/JsiSkAnimatedImageFactory.h +13 -14
- package/cpp/api/JsiSkApi.h +246 -92
- package/cpp/api/JsiSkCanvas.h +76 -58
- package/cpp/api/JsiSkColor.h +7 -5
- package/cpp/api/JsiSkColorFilter.h +15 -8
- package/cpp/api/JsiSkColorFilterFactory.h +45 -45
- package/cpp/api/JsiSkContourMeasure.h +24 -21
- package/cpp/api/JsiSkContourMeasureIter.h +18 -21
- package/cpp/api/JsiSkData.h +13 -7
- package/cpp/api/JsiSkDataFactory.h +22 -21
- package/cpp/api/JsiSkFont.h +56 -44
- package/cpp/api/JsiSkFontMgr.h +22 -13
- package/cpp/api/JsiSkFontMgrFactory.h +12 -10
- package/cpp/api/JsiSkFontStyle.h +14 -12
- package/cpp/api/JsiSkImage.h +45 -34
- package/cpp/api/JsiSkImageFactory.h +47 -52
- package/cpp/api/JsiSkImageFilter.h +21 -11
- package/cpp/api/JsiSkImageFilterFactory.h +96 -96
- package/cpp/api/JsiSkImageInfo.h +22 -19
- package/cpp/api/JsiSkMaskFilter.h +21 -11
- package/cpp/api/JsiSkMaskFilterFactory.h +16 -13
- package/cpp/api/JsiSkMatrix.h +31 -31
- package/cpp/api/JsiSkNativeObjects.h +419 -0
- package/cpp/api/JsiSkPaint.h +59 -39
- package/cpp/api/JsiSkParagraph.h +39 -32
- package/cpp/api/JsiSkParagraphBuilder.h +24 -21
- package/cpp/api/JsiSkParagraphBuilderFactory.h +13 -12
- package/cpp/api/JsiSkParagraphStyle.h +20 -10
- package/cpp/api/JsiSkPath.h +95 -70
- package/cpp/api/JsiSkPathBuilder.h +83 -67
- package/cpp/api/JsiSkPathBuilderFactory.h +16 -17
- package/cpp/api/JsiSkPathEffect.h +21 -11
- package/cpp/api/JsiSkPathEffectFactory.h +33 -32
- package/cpp/api/JsiSkPathFactory.h +79 -103
- package/cpp/api/JsiSkPicture.h +24 -13
- package/cpp/api/JsiSkPictureFactory.h +21 -26
- package/cpp/api/JsiSkPictureRecorder.h +21 -22
- package/cpp/api/JsiSkPoint.h +19 -22
- package/cpp/api/JsiSkRRect.h +22 -29
- package/cpp/api/JsiSkRSXform.h +26 -30
- package/cpp/api/JsiSkRect.h +28 -30
- package/cpp/api/JsiSkRuntimeEffect.h +39 -30
- package/cpp/api/JsiSkRuntimeEffectFactory.h +12 -12
- package/cpp/api/JsiSkRuntimeShaderBuilder.h +25 -18
- package/cpp/api/JsiSkSVG.h +13 -13
- package/cpp/api/JsiSkSVGFactory.h +17 -20
- package/cpp/api/JsiSkShader.h +15 -8
- package/cpp/api/JsiSkShaderFactory.h +41 -48
- package/cpp/api/JsiSkSkottie.h +49 -39
- package/cpp/api/JsiSkStrutStyle.h +18 -8
- package/cpp/api/JsiSkSurface.h +24 -24
- package/cpp/api/JsiSkSurfaceFactory.h +15 -16
- package/cpp/api/JsiSkTextBlob.h +15 -8
- package/cpp/api/JsiSkTextBlobFactory.h +25 -28
- package/cpp/api/JsiSkTextStyle.h +34 -24
- package/cpp/api/JsiSkTypeface.h +19 -12
- package/cpp/api/JsiSkTypefaceFactory.h +12 -12
- package/cpp/api/JsiSkTypefaceFontProvider.h +30 -25
- package/cpp/api/JsiSkTypefaceFontProviderFactory.h +14 -12
- package/cpp/api/JsiSkVertices.h +21 -18
- package/cpp/api/JsiSkiaContext.h +17 -17
- package/cpp/api/JsiSkottieFactory.h +16 -17
- package/cpp/api/JsiVideo.h +27 -25
- package/cpp/api/recorder/Convertor.h +31 -61
- package/cpp/api/recorder/DataTypes.h +8 -16
- package/cpp/api/recorder/JsiRecorder.h +83 -55
- package/cpp/api/recorder/RNRecorder.h +1 -1
- package/cpp/jsi/BoxedNativeObject.h +146 -0
- package/cpp/{jsi2 → jsi}/EnumMapper.h +4 -1
- package/cpp/{jsi2 → jsi}/NativeObject.h +120 -146
- package/cpp/jsi/RuntimeAwareCache.cpp +1 -1
- package/cpp/jsi/RuntimeAwareCache.h +26 -8
- package/cpp/jsi/ViewProperty.h +5 -11
- package/cpp/rnskia/RNSkJsiViewApi.h +20 -11
- package/cpp/rnskia/RNSkManager.cpp +29 -25
- package/cpp/rnskia/RNSkPictureView.h +1 -1
- package/cpp/rnwgpu/ArrayBuffer.h +5 -6
- package/cpp/rnwgpu/Canvas.h +4 -2
- package/cpp/rnwgpu/SurfaceRegistry.h +469 -131
- package/cpp/rnwgpu/api/GPU.cpp +4 -4
- package/cpp/rnwgpu/api/GPU.h +1 -1
- package/cpp/rnwgpu/api/GPUAdapter.cpp +12 -6
- package/cpp/rnwgpu/api/GPUAdapter.h +5 -4
- package/cpp/rnwgpu/api/GPUAdapterInfo.h +1 -1
- package/cpp/rnwgpu/api/GPUBindGroup.h +1 -1
- package/cpp/rnwgpu/api/GPUBindGroupLayout.h +1 -1
- package/cpp/rnwgpu/api/GPUBuffer.cpp +12 -2
- package/cpp/rnwgpu/api/GPUBuffer.h +4 -3
- package/cpp/rnwgpu/api/GPUCanvasContext.cpp +33 -19
- package/cpp/rnwgpu/api/GPUCanvasContext.h +4 -2
- package/cpp/rnwgpu/api/GPUCommandBuffer.h +1 -1
- package/cpp/rnwgpu/api/GPUCommandEncoder.h +1 -1
- package/cpp/rnwgpu/api/GPUCompilationInfo.h +1 -1
- package/cpp/rnwgpu/api/GPUCompilationMessage.h +1 -1
- package/cpp/rnwgpu/api/GPUComputePassEncoder.h +1 -1
- package/cpp/rnwgpu/api/GPUComputePipeline.h +1 -1
- package/cpp/rnwgpu/api/GPUDevice.cpp +38 -24
- package/cpp/rnwgpu/api/GPUDevice.h +12 -10
- package/cpp/rnwgpu/api/GPUDeviceLostInfo.h +1 -1
- package/cpp/rnwgpu/api/GPUError.h +1 -1
- package/cpp/rnwgpu/api/GPUExtent3D.h +1 -1
- package/cpp/rnwgpu/api/GPUExternalTexture.h +1 -1
- package/cpp/rnwgpu/api/GPUInternalError.h +1 -1
- package/cpp/rnwgpu/api/GPUOrigin2D.h +1 -1
- package/cpp/rnwgpu/api/GPUOrigin3D.h +1 -1
- package/cpp/rnwgpu/api/GPUOutOfMemoryError.h +1 -1
- package/cpp/rnwgpu/api/GPUPipelineLayout.h +1 -1
- package/cpp/rnwgpu/api/GPUQuerySet.h +1 -1
- package/cpp/rnwgpu/api/GPUQueue.cpp +6 -2
- package/cpp/rnwgpu/api/GPUQueue.h +4 -4
- package/cpp/rnwgpu/api/GPURenderBundle.h +1 -1
- package/cpp/rnwgpu/api/GPURenderBundleEncoder.h +1 -1
- package/cpp/rnwgpu/api/GPURenderPassEncoder.h +1 -1
- package/cpp/rnwgpu/api/GPURenderPipeline.h +1 -1
- package/cpp/rnwgpu/api/GPUSampler.h +1 -1
- package/cpp/rnwgpu/api/GPUShaderModule.cpp +8 -3
- package/cpp/rnwgpu/api/GPUShaderModule.h +4 -4
- package/cpp/rnwgpu/api/GPUSharedFence.h +1 -1
- package/cpp/rnwgpu/api/GPUSharedTextureMemory.h +1 -1
- package/cpp/rnwgpu/api/GPUSupportedLimits.h +1 -1
- package/cpp/rnwgpu/api/GPUTexture.h +1 -1
- package/cpp/rnwgpu/api/GPUTextureView.h +1 -1
- package/cpp/rnwgpu/api/GPUUncapturedErrorEvent.h +1 -1
- package/cpp/rnwgpu/api/GPUValidationError.h +1 -1
- package/cpp/rnwgpu/api/ImageBitmap.h +1 -1
- package/cpp/rnwgpu/api/RNWebGPU.h +21 -1
- package/cpp/rnwgpu/api/descriptors/GPUBindGroupDescriptor.h +1 -1
- package/cpp/rnwgpu/api/descriptors/GPUBindGroupEntry.h +1 -1
- package/cpp/rnwgpu/api/descriptors/GPUBindGroupLayoutDescriptor.h +1 -1
- package/cpp/rnwgpu/api/descriptors/GPUBindGroupLayoutEntry.h +1 -1
- package/cpp/rnwgpu/api/descriptors/GPUBlendComponent.h +1 -1
- package/cpp/rnwgpu/api/descriptors/GPUBlendState.h +1 -1
- package/cpp/rnwgpu/api/descriptors/GPUBufferBinding.h +1 -1
- package/cpp/rnwgpu/api/descriptors/GPUBufferBindingLayout.h +1 -1
- package/cpp/rnwgpu/api/descriptors/GPUBufferDescriptor.h +1 -1
- package/cpp/rnwgpu/api/descriptors/GPUCanvasConfiguration.h +1 -1
- package/cpp/rnwgpu/api/descriptors/GPUColor.h +1 -1
- package/cpp/rnwgpu/api/descriptors/GPUColorTargetState.h +1 -1
- package/cpp/rnwgpu/api/descriptors/GPUCommandBufferDescriptor.h +1 -1
- package/cpp/rnwgpu/api/descriptors/GPUCommandEncoderDescriptor.h +1 -1
- package/cpp/rnwgpu/api/descriptors/GPUComputePassDescriptor.h +1 -1
- package/cpp/rnwgpu/api/descriptors/GPUComputePassTimestampWrites.h +1 -1
- package/cpp/rnwgpu/api/descriptors/GPUComputePipelineDescriptor.h +1 -1
- package/cpp/rnwgpu/api/descriptors/GPUDawnTogglesDescriptor.h +1 -1
- package/cpp/rnwgpu/api/descriptors/GPUDepthStencilState.h +1 -1
- package/cpp/rnwgpu/api/descriptors/GPUDeviceDescriptor.h +1 -1
- package/cpp/rnwgpu/api/descriptors/GPUExternalTextureBindingLayout.h +1 -1
- package/cpp/rnwgpu/api/descriptors/GPUExternalTextureDescriptor.h +1 -1
- package/cpp/rnwgpu/api/descriptors/GPUFragmentState.h +1 -1
- package/cpp/rnwgpu/api/descriptors/GPUImageCopyBuffer.h +1 -1
- package/cpp/rnwgpu/api/descriptors/GPUImageCopyExternalImage.h +1 -1
- package/cpp/rnwgpu/api/descriptors/GPUImageCopyTexture.h +1 -1
- package/cpp/rnwgpu/api/descriptors/GPUImageCopyTextureTagged.h +1 -1
- package/cpp/rnwgpu/api/descriptors/GPUImageDataLayout.h +1 -1
- package/cpp/rnwgpu/api/descriptors/GPUMultisampleState.h +1 -1
- package/cpp/rnwgpu/api/descriptors/GPUPipelineLayoutDescriptor.h +1 -1
- package/cpp/rnwgpu/api/descriptors/GPUPrimitiveState.h +1 -1
- package/cpp/rnwgpu/api/descriptors/GPUProgrammableStage.h +1 -1
- package/cpp/rnwgpu/api/descriptors/GPUQuerySetDescriptor.h +1 -1
- package/cpp/rnwgpu/api/descriptors/GPUQueueDescriptor.h +1 -1
- package/cpp/rnwgpu/api/descriptors/GPURenderBundleDescriptor.h +1 -1
- package/cpp/rnwgpu/api/descriptors/GPURenderBundleEncoderDescriptor.h +1 -1
- package/cpp/rnwgpu/api/descriptors/GPURenderPassColorAttachment.h +1 -1
- package/cpp/rnwgpu/api/descriptors/GPURenderPassDepthStencilAttachment.h +1 -1
- package/cpp/rnwgpu/api/descriptors/GPURenderPassDescriptor.h +1 -1
- package/cpp/rnwgpu/api/descriptors/GPURenderPassTimestampWrites.h +1 -1
- package/cpp/rnwgpu/api/descriptors/GPURenderPipelineDescriptor.h +1 -1
- package/cpp/rnwgpu/api/descriptors/GPURequestAdapterOptions.h +1 -1
- package/cpp/rnwgpu/api/descriptors/GPUSamplerBindingLayout.h +1 -1
- package/cpp/rnwgpu/api/descriptors/GPUSamplerDescriptor.h +1 -1
- package/cpp/rnwgpu/api/descriptors/GPUShaderModuleCompilationHint.h +1 -1
- package/cpp/rnwgpu/api/descriptors/GPUShaderModuleDescriptor.h +1 -1
- package/cpp/rnwgpu/api/descriptors/GPUSharedFenceDescriptor.h +1 -1
- package/cpp/rnwgpu/api/descriptors/GPUSharedFenceState.h +1 -1
- package/cpp/rnwgpu/api/descriptors/GPUSharedTextureMemoryDescriptor.h +1 -1
- package/cpp/rnwgpu/api/descriptors/GPUStencilFaceState.h +1 -1
- package/cpp/rnwgpu/api/descriptors/GPUStorageTextureBindingLayout.h +1 -1
- package/cpp/rnwgpu/api/descriptors/GPUTextureBindingLayout.h +1 -1
- package/cpp/rnwgpu/api/descriptors/GPUTextureDescriptor.h +1 -1
- package/cpp/rnwgpu/api/descriptors/GPUTextureViewDescriptor.h +1 -1
- package/cpp/rnwgpu/api/descriptors/GPUUncapturedErrorEventInit.h +1 -1
- package/cpp/rnwgpu/api/descriptors/GPUVertexAttribute.h +1 -1
- package/cpp/rnwgpu/api/descriptors/GPUVertexBufferLayout.h +1 -1
- package/cpp/rnwgpu/api/descriptors/GPUVertexState.h +1 -1
- package/cpp/rnwgpu/api/descriptors/Unions.h +1 -1
- package/cpp/rnwgpu/async/AsyncTaskHandle.cpp +20 -21
- package/cpp/rnwgpu/async/RuntimeContext.cpp +5 -0
- package/cpp/rnwgpu/async/RuntimeContext.h +15 -2
- package/lib/commonjs/external/reanimated/renderHelpers.d.ts +15 -0
- package/lib/commonjs/external/reanimated/renderHelpers.js +30 -1
- package/lib/commonjs/external/reanimated/renderHelpers.js.map +1 -1
- package/lib/commonjs/skia/NativeSetup.js +4 -0
- package/lib/commonjs/skia/NativeSetup.js.map +1 -1
- package/lib/commonjs/skia/SkiaWorkletSerialization.d.ts +1 -0
- package/lib/commonjs/skia/SkiaWorkletSerialization.js +66 -0
- package/lib/commonjs/skia/SkiaWorkletSerialization.js.map +1 -0
- package/lib/commonjs/sksg/Container.native.js +20 -1
- package/lib/commonjs/sksg/Container.native.js.map +1 -1
- package/lib/commonjs/views/WebGPUCanvas.d.ts +1 -0
- package/lib/commonjs/views/WebGPUCanvas.js +13 -0
- package/lib/commonjs/views/WebGPUCanvas.js.map +1 -1
- package/lib/module/external/reanimated/renderHelpers.d.ts +15 -0
- package/lib/module/external/reanimated/renderHelpers.js +29 -0
- package/lib/module/external/reanimated/renderHelpers.js.map +1 -1
- package/lib/module/skia/NativeSetup.js +4 -0
- package/lib/module/skia/NativeSetup.js.map +1 -1
- package/lib/module/skia/SkiaWorkletSerialization.d.ts +1 -0
- package/lib/module/skia/SkiaWorkletSerialization.js +59 -0
- package/lib/module/skia/SkiaWorkletSerialization.js.map +1 -0
- package/lib/module/sksg/Container.native.js +21 -2
- package/lib/module/sksg/Container.native.js.map +1 -1
- package/lib/module/views/WebGPUCanvas.d.ts +1 -0
- package/lib/module/views/WebGPUCanvas.js +14 -1
- package/lib/module/views/WebGPUCanvas.js.map +1 -1
- package/lib/typescript/lib/commonjs/external/reanimated/renderHelpers.d.ts +2 -0
- package/lib/typescript/lib/commonjs/skia/SkiaWorkletSerialization.d.ts +2 -0
- package/lib/typescript/lib/module/external/reanimated/renderHelpers.d.ts +15 -0
- package/lib/typescript/lib/module/skia/SkiaWorkletSerialization.d.ts +1 -0
- package/lib/typescript/src/external/reanimated/renderHelpers.d.ts +15 -0
- package/lib/typescript/src/skia/SkiaWorkletSerialization.d.ts +1 -0
- package/lib/typescript/src/views/WebGPUCanvas.d.ts +1 -0
- package/package.json +12 -8
- package/react-native-skia.podspec +1 -2
- package/src/external/reanimated/renderHelpers.ts +30 -0
- package/src/skia/NativeSetup.ts +5 -0
- package/src/skia/SkiaWorkletSerialization.ts +67 -0
- package/src/sksg/Container.native.ts +40 -2
- package/src/views/WebGPUCanvas.tsx +17 -1
- package/cpp/api/JsiSkHostObjects.h +0 -257
- package/cpp/dawn/include/dawn/dawn_proc.h +0 -53
- package/cpp/dawn/include/dawn/dawn_proc_table.h +0 -330
- package/cpp/dawn/include/dawn/dawn_thread_dispatch_proc.h +0 -47
- package/cpp/dawn/include/dawn/dawn_version.h +0 -41
- package/cpp/dawn/include/dawn/native/D3D11Backend.h +0 -65
- package/cpp/dawn/include/dawn/native/D3D12Backend.h +0 -86
- package/cpp/dawn/include/dawn/native/D3DBackend.h +0 -56
- package/cpp/dawn/include/dawn/native/DawnNative.h +0 -369
- package/cpp/dawn/include/dawn/native/MetalBackend.h +0 -56
- package/cpp/dawn/include/dawn/native/NullBackend.h +0 -39
- package/cpp/dawn/include/dawn/native/OpenGLBackend.h +0 -89
- package/cpp/dawn/include/dawn/native/VulkanBackend.h +0 -183
- package/cpp/dawn/include/dawn/native/WebGPUBackend.h +0 -49
- package/cpp/dawn/include/dawn/native/dawn_native_export.h +0 -49
- package/cpp/dawn/include/dawn/platform/DawnPlatform.h +0 -210
- package/cpp/dawn/include/dawn/platform/dawn_platform_export.h +0 -49
- package/cpp/dawn/include/dawn/replay/Replay.h +0 -99
- package/cpp/dawn/include/dawn/replay/dawn_replay_export.h +0 -49
- package/cpp/dawn/include/dawn/webgpu_cpp_print.h +0 -2844
- package/cpp/dawn/include/tint/tint.h +0 -90
- package/cpp/dawn/include/webgpu/webgpu.h +0 -4987
- package/cpp/dawn/include/webgpu/webgpu_cpp.h +0 -10080
- package/cpp/dawn/include/webgpu/webgpu_cpp_chained_struct.h +0 -57
- package/cpp/dawn/include/webgpu/webgpu_enum_class_bitmasks.h +0 -161
- package/cpp/dawn/include/webgpu/webgpu_glfw.h +0 -88
- package/cpp/jsi/JsiHostObject.cpp +0 -137
- package/cpp/jsi/JsiHostObject.h +0 -385
- package/cpp/skia/src/gpu/graphite/ContextOptionsPriv.h +0 -45
- package/cpp/skia/src/gpu/graphite/ResourceTypes.h +0 -360
- package/cpp/skia/src/gpu/graphite/TextureProxyView.h +0 -105
- package/libs/.graphite +0 -1
- /package/cpp/{jsi2 → jsi}/JSIConverter.h +0 -0
- /package/cpp/{jsi2 → jsi}/Promise.cpp +0 -0
- /package/cpp/{jsi2 → jsi}/Promise.h +0 -0
|
@@ -51,12 +51,9 @@ std::shared_ptr<SkRect> processRect(jsi::Runtime &runtime,
|
|
|
51
51
|
const jsi::Value &value) {
|
|
52
52
|
if (value.isObject()) {
|
|
53
53
|
auto object = value.asObject(runtime);
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
if (ptr != nullptr) {
|
|
58
|
-
return ptr->getObject();
|
|
59
|
-
}
|
|
54
|
+
auto ptr = tryGetJsiObject<JsiSkRect>(runtime, object);
|
|
55
|
+
if (ptr != nullptr) {
|
|
56
|
+
return ptr->getObject();
|
|
60
57
|
} else if (object.hasProperty(runtime, "x") &&
|
|
61
58
|
object.hasProperty(runtime, "y") &&
|
|
62
59
|
object.hasProperty(runtime, "width") &&
|
|
@@ -88,12 +85,9 @@ std::shared_ptr<SkRRect> processRRect(jsi::Runtime &runtime,
|
|
|
88
85
|
const jsi::Value &value) {
|
|
89
86
|
if (value.isObject()) {
|
|
90
87
|
auto object = value.asObject(runtime);
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
if (ptr != nullptr) {
|
|
95
|
-
return ptr->getObject();
|
|
96
|
-
}
|
|
88
|
+
auto ptr = tryGetJsiObject<JsiSkRRect>(runtime, object);
|
|
89
|
+
if (ptr != nullptr) {
|
|
90
|
+
return ptr->getObject();
|
|
97
91
|
} else if (object.hasProperty(runtime, "rect") &&
|
|
98
92
|
object.hasProperty(runtime, "rx") &&
|
|
99
93
|
object.hasProperty(runtime, "ry")) {
|
|
@@ -136,10 +130,8 @@ std::shared_ptr<SkPath> processPath(jsi::Runtime &runtime,
|
|
|
136
130
|
} else {
|
|
137
131
|
throw std::runtime_error("Could not parse path from string.");
|
|
138
132
|
}
|
|
139
|
-
} else
|
|
140
|
-
|
|
141
|
-
auto ptr = std::dynamic_pointer_cast<JsiSkPath>(
|
|
142
|
-
value.asObject(runtime).asHostObject(runtime));
|
|
133
|
+
} else {
|
|
134
|
+
auto ptr = tryGetJsiObject<JsiSkPath>(runtime, value);
|
|
143
135
|
if (ptr != nullptr) {
|
|
144
136
|
return std::make_shared<SkPath>(ptr->getObject()->snapshot());
|
|
145
137
|
}
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
#include <vector>
|
|
7
7
|
|
|
8
8
|
#include "api/JsiSkCanvas.h"
|
|
9
|
-
#include "api/
|
|
9
|
+
#include "api/JsiSkNativeObjects.h"
|
|
10
10
|
#include "api/JsiSkPicture.h"
|
|
11
11
|
|
|
12
12
|
#include "DrawingCtx.h"
|
|
@@ -19,11 +19,14 @@ namespace RNSkia {
|
|
|
19
19
|
|
|
20
20
|
namespace jsi = facebook::jsi;
|
|
21
21
|
|
|
22
|
-
class JsiRecorder
|
|
22
|
+
class JsiRecorder
|
|
23
|
+
: public JsiSkWrappingSharedPtrNativeObject<JsiRecorder, Recorder> {
|
|
23
24
|
public:
|
|
25
|
+
static constexpr const char *CLASS_NAME = "Recorder";
|
|
26
|
+
|
|
24
27
|
JsiRecorder(std::shared_ptr<RNSkPlatformContext> context)
|
|
25
|
-
:
|
|
26
|
-
|
|
28
|
+
: JsiSkWrappingSharedPtrNativeObject<JsiRecorder, Recorder>(
|
|
29
|
+
std::move(context), std::make_shared<Recorder>()) {
|
|
27
30
|
getObject()->_context = getContext();
|
|
28
31
|
}
|
|
29
32
|
|
|
@@ -61,7 +64,8 @@ public:
|
|
|
61
64
|
|
|
62
65
|
// Get the JsiSkPicture from the argument
|
|
63
66
|
auto pictureObject = arguments[0].asObject(runtime);
|
|
64
|
-
auto pictureHostObject =
|
|
67
|
+
auto pictureHostObject =
|
|
68
|
+
tryGetJsiObject<JsiSkPicture>(runtime, pictureObject);
|
|
65
69
|
if (!pictureHostObject) {
|
|
66
70
|
throw jsi::JSError(runtime, "Invalid Picture object provided to play()");
|
|
67
71
|
}
|
|
@@ -302,65 +306,89 @@ public:
|
|
|
302
306
|
return jsi::Value::undefined();
|
|
303
307
|
}
|
|
304
308
|
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
309
|
+
static void definePrototype(jsi::Runtime &runtime, jsi::Object &prototype) {
|
|
310
|
+
installCommon(runtime, prototype);
|
|
311
|
+
installHostMethod(runtime, prototype, "saveGroup", &JsiRecorder::saveGroup);
|
|
312
|
+
installHostMethod(runtime, prototype, "restoreGroup",
|
|
313
|
+
&JsiRecorder::restoreGroup);
|
|
314
|
+
installHostMethod(runtime, prototype, "savePaint", &JsiRecorder::savePaint);
|
|
315
|
+
installHostMethod(runtime, prototype, "restorePaint",
|
|
316
|
+
&JsiRecorder::restorePaint);
|
|
317
|
+
installHostMethod(runtime, prototype, "restorePaintDeclaration",
|
|
318
|
+
&JsiRecorder::restorePaintDeclaration);
|
|
319
|
+
installHostMethod(runtime, prototype, "materializePaint",
|
|
320
|
+
&JsiRecorder::materializePaint);
|
|
321
|
+
installHostMethod(runtime, prototype, "pushPathEffect",
|
|
322
|
+
&JsiRecorder::pushPathEffect);
|
|
323
|
+
installHostMethod(runtime, prototype, "pushImageFilter",
|
|
324
|
+
&JsiRecorder::pushImageFilter);
|
|
325
|
+
installHostMethod(runtime, prototype, "pushColorFilter",
|
|
326
|
+
&JsiRecorder::pushColorFilter);
|
|
327
|
+
installHostMethod(runtime, prototype, "pushShader",
|
|
328
|
+
&JsiRecorder::pushShader);
|
|
329
|
+
installHostMethod(runtime, prototype, "pushBlurMaskFilter",
|
|
330
|
+
&JsiRecorder::pushBlurMaskFilter);
|
|
331
|
+
installHostMethod(runtime, prototype, "composePathEffect",
|
|
332
|
+
&JsiRecorder::composePathEffect);
|
|
333
|
+
installHostMethod(runtime, prototype, "composeColorFilter",
|
|
334
|
+
&JsiRecorder::composeColorFilter);
|
|
335
|
+
installHostMethod(runtime, prototype, "composeImageFilter",
|
|
336
|
+
&JsiRecorder::composeImageFilter);
|
|
337
|
+
installHostMethod(runtime, prototype, "saveCTM", &JsiRecorder::saveCTM);
|
|
338
|
+
installHostMethod(runtime, prototype, "restoreCTM",
|
|
339
|
+
&JsiRecorder::restoreCTM);
|
|
340
|
+
installHostMethod(runtime, prototype, "drawPaint", &JsiRecorder::drawPaint);
|
|
341
|
+
installHostMethod(runtime, prototype, "saveLayer", &JsiRecorder::saveLayer);
|
|
342
|
+
installHostMethod(runtime, prototype, "saveBackdropFilter",
|
|
343
|
+
&JsiRecorder::saveBackdropFilter);
|
|
344
|
+
installHostMethod(runtime, prototype, "drawBox", &JsiRecorder::drawBox);
|
|
345
|
+
installHostMethod(runtime, prototype, "drawImage", &JsiRecorder::drawImage);
|
|
346
|
+
installHostMethod(runtime, prototype, "drawCircle",
|
|
347
|
+
&JsiRecorder::drawCircle);
|
|
348
|
+
installHostMethod(runtime, prototype, "drawPoints",
|
|
349
|
+
&JsiRecorder::drawPoints);
|
|
350
|
+
installHostMethod(runtime, prototype, "drawPath", &JsiRecorder::drawPath);
|
|
351
|
+
installHostMethod(runtime, prototype, "drawRect", &JsiRecorder::drawRect);
|
|
352
|
+
installHostMethod(runtime, prototype, "drawRRect", &JsiRecorder::drawRRect);
|
|
353
|
+
installHostMethod(runtime, prototype, "drawOval", &JsiRecorder::drawOval);
|
|
354
|
+
installHostMethod(runtime, prototype, "drawLine", &JsiRecorder::drawLine);
|
|
355
|
+
installHostMethod(runtime, prototype, "drawPatch", &JsiRecorder::drawPatch);
|
|
356
|
+
installHostMethod(runtime, prototype, "drawVertices",
|
|
357
|
+
&JsiRecorder::drawVertices);
|
|
358
|
+
installHostMethod(runtime, prototype, "drawDiffRect",
|
|
359
|
+
&JsiRecorder::drawDiffRect);
|
|
360
|
+
installHostMethod(runtime, prototype, "drawText", &JsiRecorder::drawText);
|
|
361
|
+
installHostMethod(runtime, prototype, "drawTextPath",
|
|
362
|
+
&JsiRecorder::drawTextPath);
|
|
363
|
+
installHostMethod(runtime, prototype, "drawTextBlob",
|
|
364
|
+
&JsiRecorder::drawTextBlob);
|
|
365
|
+
installHostMethod(runtime, prototype, "drawGlyphs",
|
|
366
|
+
&JsiRecorder::drawGlyphs);
|
|
367
|
+
installHostMethod(runtime, prototype, "drawPicture",
|
|
368
|
+
&JsiRecorder::drawPicture);
|
|
369
|
+
installHostMethod(runtime, prototype, "drawImageSVG",
|
|
370
|
+
&JsiRecorder::drawImageSVG);
|
|
371
|
+
installHostMethod(runtime, prototype, "drawParagraph",
|
|
372
|
+
&JsiRecorder::drawParagraph);
|
|
373
|
+
installHostMethod(runtime, prototype, "drawAtlas", &JsiRecorder::drawAtlas);
|
|
374
|
+
installHostMethod(runtime, prototype, "drawSkottie",
|
|
375
|
+
&JsiRecorder::drawSkottie);
|
|
376
|
+
installHostMethod(runtime, prototype, "play", &JsiRecorder::play);
|
|
377
|
+
installHostMethod(runtime, prototype, "applyUpdates",
|
|
378
|
+
&JsiRecorder::applyUpdates);
|
|
379
|
+
installHostMethod(runtime, prototype, "reset", &JsiRecorder::reset);
|
|
380
|
+
}
|
|
350
381
|
|
|
351
382
|
// This has no basis in reality but since since these are private long-lived
|
|
352
383
|
// objects, we think it is more than fine.
|
|
353
|
-
size_t getMemoryPressure()
|
|
354
|
-
|
|
355
|
-
std::string getObjectType() const override { return "JsiRecorder"; }
|
|
384
|
+
size_t getMemoryPressure() override { return 5 * 1024 * 1024; }
|
|
356
385
|
|
|
357
386
|
static const jsi::HostFunctionType
|
|
358
387
|
createCtor(std::shared_ptr<RNSkPlatformContext> context) {
|
|
359
388
|
return JSI_HOST_FUNCTION_LAMBDA {
|
|
360
389
|
// Return the newly constructed object
|
|
361
390
|
auto recorder = std::make_shared<JsiRecorder>(std::move(context));
|
|
362
|
-
return
|
|
363
|
-
context);
|
|
391
|
+
return makeJsiObject(runtime, std::move(recorder));
|
|
364
392
|
};
|
|
365
393
|
}
|
|
366
394
|
};
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
#pragma once
|
|
2
|
+
|
|
3
|
+
#include <functional>
|
|
4
|
+
#include <memory>
|
|
5
|
+
#include <mutex>
|
|
6
|
+
#include <stdexcept>
|
|
7
|
+
#include <string>
|
|
8
|
+
#include <unordered_map>
|
|
9
|
+
#include <utility>
|
|
10
|
+
#include <vector>
|
|
11
|
+
|
|
12
|
+
#include <jsi/jsi.h>
|
|
13
|
+
|
|
14
|
+
namespace RNJsi {
|
|
15
|
+
|
|
16
|
+
namespace jsi = facebook::jsi;
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Registry mapping a NativeObject class brand (CLASS_NAME) to a reconstructor
|
|
20
|
+
* that can recreate a fully functional JS object (prototype + native state)
|
|
21
|
+
* on any runtime. This is what enables native objects (Skia and WebGPU) to
|
|
22
|
+
* travel between the React Native runtime and secondary runtimes (Reanimated
|
|
23
|
+
* worklets) via BoxedNativeObject.
|
|
24
|
+
*/
|
|
25
|
+
class BoxedNativeObjectRegistry {
|
|
26
|
+
public:
|
|
27
|
+
using Reconstructor = std::function<jsi::Value(
|
|
28
|
+
jsi::Runtime &, std::shared_ptr<jsi::NativeState>)>;
|
|
29
|
+
|
|
30
|
+
static BoxedNativeObjectRegistry &getInstance() {
|
|
31
|
+
static BoxedNativeObjectRegistry instance;
|
|
32
|
+
return instance;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
void registerClass(const std::string &brand, Reconstructor reconstructor) {
|
|
36
|
+
std::lock_guard<std::mutex> lock(_mutex);
|
|
37
|
+
// Brands are the unboxing key and must be unique process-wide; a silent
|
|
38
|
+
// overwrite would make one class unbox into another's reconstructor.
|
|
39
|
+
if (_reconstructors.count(brand) > 0) {
|
|
40
|
+
throw std::runtime_error("Duplicate native object brand registered: " +
|
|
41
|
+
brand);
|
|
42
|
+
}
|
|
43
|
+
_reconstructors[brand] = std::move(reconstructor);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
jsi::Value reconstruct(jsi::Runtime &runtime, const std::string &brand,
|
|
47
|
+
std::shared_ptr<jsi::NativeState> state) {
|
|
48
|
+
Reconstructor reconstructor;
|
|
49
|
+
{
|
|
50
|
+
std::lock_guard<std::mutex> lock(_mutex);
|
|
51
|
+
auto it = _reconstructors.find(brand);
|
|
52
|
+
if (it == _reconstructors.end()) {
|
|
53
|
+
throw jsi::JSError(runtime,
|
|
54
|
+
"No native class registered for brand: " + brand);
|
|
55
|
+
}
|
|
56
|
+
reconstructor = it->second;
|
|
57
|
+
}
|
|
58
|
+
return reconstructor(runtime, std::move(state));
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
private:
|
|
62
|
+
BoxedNativeObjectRegistry() = default;
|
|
63
|
+
std::mutex _mutex;
|
|
64
|
+
std::unordered_map<std::string, Reconstructor> _reconstructors;
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* HostObject bridge used to move NativeObjects between runtimes.
|
|
69
|
+
*
|
|
70
|
+
* NativeObject-based values are plain JS objects carrying jsi::NativeState;
|
|
71
|
+
* worklets cannot serialize their prototype, so they are "boxed" into this
|
|
72
|
+
* HostObject (which worklets pass across runtimes by reference) and unboxed
|
|
73
|
+
* on the target runtime, where the prototype is re-installed from the class
|
|
74
|
+
* registry. See registerCustomSerializable in
|
|
75
|
+
* src/skia/SkiaWorkletSerialization.ts.
|
|
76
|
+
*/
|
|
77
|
+
class BoxedNativeObject : public jsi::HostObject {
|
|
78
|
+
public:
|
|
79
|
+
BoxedNativeObject(std::shared_ptr<jsi::NativeState> state, std::string brand)
|
|
80
|
+
: _state(std::move(state)), _brand(std::move(brand)) {}
|
|
81
|
+
|
|
82
|
+
jsi::Value get(jsi::Runtime &runtime, const jsi::PropNameID &name) override {
|
|
83
|
+
auto propName = name.utf8(runtime);
|
|
84
|
+
if (propName == "unbox") {
|
|
85
|
+
auto state = _state;
|
|
86
|
+
auto brand = _brand;
|
|
87
|
+
return jsi::Function::createFromHostFunction(
|
|
88
|
+
runtime, jsi::PropNameID::forUtf8(runtime, "unbox"), 0,
|
|
89
|
+
[state, brand](jsi::Runtime &rt, const jsi::Value &,
|
|
90
|
+
const jsi::Value *, size_t) -> jsi::Value {
|
|
91
|
+
return BoxedNativeObjectRegistry::getInstance().reconstruct(
|
|
92
|
+
rt, brand, state);
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
if (propName == "__boxedNativeObject") {
|
|
96
|
+
return jsi::Value(true);
|
|
97
|
+
}
|
|
98
|
+
if (propName == "__brand") {
|
|
99
|
+
return jsi::String::createFromUtf8(runtime, _brand);
|
|
100
|
+
}
|
|
101
|
+
return jsi::Value::undefined();
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
void set(jsi::Runtime &runtime, const jsi::PropNameID &,
|
|
105
|
+
const jsi::Value &) override {
|
|
106
|
+
throw jsi::JSError(runtime, "Boxed native objects are read-only");
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
std::vector<jsi::PropNameID> getPropertyNames(jsi::Runtime &rt) override {
|
|
110
|
+
std::vector<jsi::PropNameID> names;
|
|
111
|
+
names.reserve(3);
|
|
112
|
+
names.push_back(jsi::PropNameID::forUtf8(rt, "unbox"));
|
|
113
|
+
names.push_back(jsi::PropNameID::forUtf8(rt, "__boxedNativeObject"));
|
|
114
|
+
names.push_back(jsi::PropNameID::forUtf8(rt, "__brand"));
|
|
115
|
+
return names;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
private:
|
|
119
|
+
std::shared_ptr<jsi::NativeState> _state;
|
|
120
|
+
std::string _brand;
|
|
121
|
+
};
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* Boxes a NativeObject-backed JS value so it can be serialized by worklets
|
|
125
|
+
* and unboxed on another runtime.
|
|
126
|
+
*/
|
|
127
|
+
inline jsi::Value boxNativeObject(jsi::Runtime &runtime,
|
|
128
|
+
const jsi::Value &value) {
|
|
129
|
+
if (!value.isObject()) {
|
|
130
|
+
throw jsi::JSError(runtime, "box() expects a native object");
|
|
131
|
+
}
|
|
132
|
+
auto object = value.asObject(runtime);
|
|
133
|
+
if (!object.hasNativeState(runtime)) {
|
|
134
|
+
throw jsi::JSError(runtime, "box() expects a native object");
|
|
135
|
+
}
|
|
136
|
+
auto brand = object.getProperty(runtime, "__typename__");
|
|
137
|
+
if (!brand.isString()) {
|
|
138
|
+
throw jsi::JSError(runtime, "box() expects a native object");
|
|
139
|
+
}
|
|
140
|
+
return jsi::Object::createFromHostObject(
|
|
141
|
+
runtime, std::make_shared<BoxedNativeObject>(
|
|
142
|
+
object.getNativeState(runtime),
|
|
143
|
+
brand.asString(runtime).utf8(runtime)));
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
} // namespace RNJsi
|
|
@@ -12,7 +12,10 @@ namespace EnumMapper {
|
|
|
12
12
|
// outEnum)`
|
|
13
13
|
// 2. `static void convertEnumToJSUnion(Enum inEnum, std::string* outUnion)`
|
|
14
14
|
|
|
15
|
-
|
|
15
|
+
// inline (not static): this header is now included by every TU via
|
|
16
|
+
// NativeObject.h, and an unused file-scope static would trip
|
|
17
|
+
// -Werror=unused-function in non-Graphite builds.
|
|
18
|
+
inline std::runtime_error invalidUnion(const std::string &passedUnion) {
|
|
16
19
|
return std::runtime_error(
|
|
17
20
|
"Cannot convert JS Value to Enum: Invalid Union value passed! (\"" +
|
|
18
21
|
std::string(passedUnion) + "\")");
|