@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
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_react","_interopRequireWildcard","require","_reactNative","_WebGPUViewNativeComponent","_interopRequireDefault","e","__esModule","default","t","WeakMap","r","n","o","i","f","__proto__","has","get","set","hasOwnProperty","call","Object","defineProperty","getOwnPropertyDescriptor","_extends","assign","bind","arguments","length","apply","CONTEXT_COUNTER","generateContextId","WebGPUCanvas","transparent","ref","props","viewRef","useRef","contextId","useState","useImperativeHandle","getContextId","getNativeSurface","
|
|
1
|
+
{"version":3,"names":["_react","_interopRequireWildcard","require","_reactNative","_WebGPUViewNativeComponent","_interopRequireDefault","e","__esModule","default","t","WeakMap","r","n","o","i","f","__proto__","has","get","set","hasOwnProperty","call","Object","defineProperty","getOwnPropertyDescriptor","_extends","assign","bind","arguments","length","apply","CONTEXT_COUNTER","generateContextId","WebGPUCanvas","transparent","ref","props","viewRef","useRef","contextId","useState","useEffect","RNWebGPU","destroyContext","useImperativeHandle","getContextId","getNativeSurface","Error","getContext","contextName","current","view","size","getBoundingClientRect","unstable_getBoundingClientRect","MakeWebGPUCanvasContext","width","height","Platform","OS","createElement","View","collapsable","style","flex","exports"],"sources":["WebGPUCanvas.tsx"],"sourcesContent":["import React, { useEffect, useImperativeHandle, useRef, useState } from \"react\";\nimport type { ViewProps } from \"react-native\";\nimport { View, Platform } from \"react-native\";\n\nimport WebGPUNativeView from \"../specs/WebGPUViewNativeComponent\";\n\nlet CONTEXT_COUNTER = 1;\nfunction generateContextId() {\n return CONTEXT_COUNTER++;\n}\n\ndeclare global {\n var RNWebGPU: {\n gpu: GPU;\n fabric: boolean;\n getNativeSurface: (contextId: number) => NativeCanvas;\n MakeWebGPUCanvasContext: (\n contextId: number,\n width: number,\n height: number\n ) => RNCanvasContext;\n // Retires a canvas context; called by the Canvas on unmount (the Canvas\n // owns the native registry entry for its contextId).\n destroyContext: (contextId: number) => void;\n };\n}\n\ntype SurfacePointer = bigint;\n\nexport interface NativeCanvas {\n surface: SurfacePointer;\n width: number;\n height: number;\n clientWidth: number;\n clientHeight: number;\n}\n\nexport type RNCanvasContext = GPUCanvasContext & {\n present: () => void;\n};\n\nexport interface WebGPUCanvasRef {\n getContextId: () => number;\n getContext(contextName: \"webgpu\"): RNCanvasContext | null;\n getNativeSurface: () => NativeCanvas;\n}\n\ninterface WebGPUCanvasProps extends ViewProps {\n transparent?: boolean;\n ref?: React.Ref<WebGPUCanvasRef>;\n}\n\nexport const WebGPUCanvas = ({\n transparent,\n ref,\n ...props\n}: WebGPUCanvasProps) => {\n const viewRef = useRef(null);\n const [contextId] = useState(() => generateContextId());\n\n // Retire the native registry entry for this contextId on unmount. When a\n // native surface is still attached, this is a no-op and the native view's\n // own teardown retires the entry instead — which keeps StrictMode's\n // simulated unmount (which re-runs effects without unmounting native views)\n // from orphaning a live surface.\n useEffect(() => {\n return () => {\n if (typeof RNWebGPU !== \"undefined\") {\n RNWebGPU.destroyContext(contextId);\n }\n };\n }, [contextId]);\n\n useImperativeHandle(ref, () => ({\n getContextId: () => contextId,\n getNativeSurface: () => {\n if (typeof RNWebGPU === \"undefined\") {\n throw new Error(\n \"[WebGPU] RNWebGPU is not available. Make sure SK_GRAPHITE is enabled.\"\n );\n }\n return RNWebGPU.getNativeSurface(contextId);\n },\n getContext(contextName: \"webgpu\"): RNCanvasContext | null {\n if (contextName !== \"webgpu\") {\n throw new Error(`[WebGPU] Unsupported context: ${contextName}`);\n }\n if (!viewRef.current) {\n throw new Error(\"[WebGPU] Cannot get context before mount\");\n }\n if (typeof RNWebGPU === \"undefined\") {\n throw new Error(\n \"[WebGPU] RNWebGPU is not available. Make sure SK_GRAPHITE is enabled.\"\n );\n }\n // getBoundingClientRect became stable in RN 0.83\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const view = viewRef.current as any;\n const size =\n \"getBoundingClientRect\" in view\n ? view.getBoundingClientRect()\n : view.unstable_getBoundingClientRect();\n return RNWebGPU.MakeWebGPUCanvasContext(\n contextId,\n size.width,\n size.height\n );\n },\n }));\n\n // WebGPU Canvas is not supported on web\n if (Platform.OS === \"web\") {\n return <View {...props} />;\n }\n\n return (\n <View collapsable={false} ref={viewRef} {...props}>\n <WebGPUNativeView\n style={{ flex: 1 }}\n contextId={contextId}\n transparent={!!transparent}\n />\n </View>\n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-1 +1,16 @@
|
|
|
1
1
|
export declare let HAS_REANIMATED_3: boolean;
|
|
2
|
+
/**
|
|
3
|
+
* True when the worklets-based Reanimated integration is available
|
|
4
|
+
* (Reanimated 4 with react-native-worklets providing
|
|
5
|
+
* registerCustomSerializable). Skia objects use the JSI NativeState pattern
|
|
6
|
+
* and can only be transferred to worklet runtimes through a custom
|
|
7
|
+
* serializer, so on native the Reanimated integration requires Reanimated 4 —
|
|
8
|
+
* Reanimated 3 is not supported.
|
|
9
|
+
*/
|
|
10
|
+
export declare let HAS_REANIMATED_4: boolean;
|
|
11
|
+
/**
|
|
12
|
+
* Major version of the installed react-native-reanimated package, or null if
|
|
13
|
+
* it is not installed. Used to give actionable diagnostics when the
|
|
14
|
+
* integration cannot be enabled.
|
|
15
|
+
*/
|
|
16
|
+
export declare let REANIMATED_VERSION_MAJOR: number | null;
|
|
@@ -1,4 +1,21 @@
|
|
|
1
1
|
export let HAS_REANIMATED_3 = false;
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* True when the worklets-based Reanimated integration is available
|
|
5
|
+
* (Reanimated 4 with react-native-worklets providing
|
|
6
|
+
* registerCustomSerializable). Skia objects use the JSI NativeState pattern
|
|
7
|
+
* and can only be transferred to worklet runtimes through a custom
|
|
8
|
+
* serializer, so on native the Reanimated integration requires Reanimated 4 —
|
|
9
|
+
* Reanimated 3 is not supported.
|
|
10
|
+
*/
|
|
11
|
+
export let HAS_REANIMATED_4 = false;
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Major version of the installed react-native-reanimated package, or null if
|
|
15
|
+
* it is not installed. Used to give actionable diagnostics when the
|
|
16
|
+
* integration cannot be enabled.
|
|
17
|
+
*/
|
|
18
|
+
export let REANIMATED_VERSION_MAJOR = null;
|
|
2
19
|
try {
|
|
3
20
|
// This logic is convoluted but necessary
|
|
4
21
|
// In most systems, `require("react-native-reanimated")` throws an error, all is well.
|
|
@@ -9,6 +26,18 @@ try {
|
|
|
9
26
|
if (reanimatedVersion && (reanimatedVersion >= "3.0.0" || reanimatedVersion.includes("3.0.0-"))) {
|
|
10
27
|
HAS_REANIMATED_3 = true;
|
|
11
28
|
}
|
|
29
|
+
const majorVersion = parseInt(reanimatedVersion.split(".")[0], 10);
|
|
30
|
+
if (!isNaN(majorVersion)) {
|
|
31
|
+
REANIMATED_VERSION_MAJOR = majorVersion;
|
|
32
|
+
}
|
|
33
|
+
if (majorVersion >= 4) {
|
|
34
|
+
try {
|
|
35
|
+
const worklets = require("react-native-worklets");
|
|
36
|
+
HAS_REANIMATED_4 = typeof worklets.registerCustomSerializable === "function";
|
|
37
|
+
} catch (e) {
|
|
38
|
+
// react-native-worklets not installed
|
|
39
|
+
}
|
|
40
|
+
}
|
|
12
41
|
} catch (e) {
|
|
13
42
|
// do nothing
|
|
14
43
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["HAS_REANIMATED_3","reanimatedVersion","require","version","includes","e"],"sources":["renderHelpers.ts"],"sourcesContent":["export let HAS_REANIMATED_3 = false;\n\ntry {\n // This logic is convoluted but necessary\n // In most systems, `require(\"react-native-reanimated\")` throws an error, all is well.\n // In webpack, in some configuration it will return an empty object.\n // So it will not throw an error and we need to check the version to know if it's there.\n const reanimatedVersion =\n require(\"react-native-reanimated/package.json\").version;\n require(\"react-native-reanimated\");\n if (\n reanimatedVersion &&\n (reanimatedVersion >= \"3.0.0\" || reanimatedVersion.includes(\"3.0.0-\"))\n ) {\n HAS_REANIMATED_3 = true;\n }\n} catch (e) {\n // do nothing\n}\n"],"mappings":"AAAA,OAAO,IAAIA,gBAAgB,GAAG,KAAK;AAEnC,IAAI;EACF;EACA;EACA;EACA;EACA,MAAMC,iBAAiB,GACrBC,OAAO,CAAC,sCAAsC,CAAC,CAACC,OAAO;EACzDD,OAAO,CAAC,yBAAyB,CAAC;EAClC,IACED,iBAAiB,KAChBA,iBAAiB,IAAI,OAAO,IAAIA,iBAAiB,CAACG,QAAQ,CAAC,QAAQ,CAAC,CAAC,EACtE;
|
|
1
|
+
{"version":3,"names":["HAS_REANIMATED_3","HAS_REANIMATED_4","REANIMATED_VERSION_MAJOR","reanimatedVersion","require","version","includes","majorVersion","parseInt","split","isNaN","worklets","registerCustomSerializable","e"],"sources":["renderHelpers.ts"],"sourcesContent":["export let HAS_REANIMATED_3 = false;\n\n/**\n * True when the worklets-based Reanimated integration is available\n * (Reanimated 4 with react-native-worklets providing\n * registerCustomSerializable). Skia objects use the JSI NativeState pattern\n * and can only be transferred to worklet runtimes through a custom\n * serializer, so on native the Reanimated integration requires Reanimated 4 —\n * Reanimated 3 is not supported.\n */\nexport let HAS_REANIMATED_4 = false;\n\n/**\n * Major version of the installed react-native-reanimated package, or null if\n * it is not installed. Used to give actionable diagnostics when the\n * integration cannot be enabled.\n */\nexport let REANIMATED_VERSION_MAJOR: number | null = null;\n\ntry {\n // This logic is convoluted but necessary\n // In most systems, `require(\"react-native-reanimated\")` throws an error, all is well.\n // In webpack, in some configuration it will return an empty object.\n // So it will not throw an error and we need to check the version to know if it's there.\n const reanimatedVersion =\n require(\"react-native-reanimated/package.json\").version;\n require(\"react-native-reanimated\");\n if (\n reanimatedVersion &&\n (reanimatedVersion >= \"3.0.0\" || reanimatedVersion.includes(\"3.0.0-\"))\n ) {\n HAS_REANIMATED_3 = true;\n }\n const majorVersion = parseInt(reanimatedVersion.split(\".\")[0], 10);\n if (!isNaN(majorVersion)) {\n REANIMATED_VERSION_MAJOR = majorVersion;\n }\n if (majorVersion >= 4) {\n try {\n const worklets = require(\"react-native-worklets\");\n HAS_REANIMATED_4 =\n typeof worklets.registerCustomSerializable === \"function\";\n } catch (e) {\n // react-native-worklets not installed\n }\n }\n} catch (e) {\n // do nothing\n}\n"],"mappings":"AAAA,OAAO,IAAIA,gBAAgB,GAAG,KAAK;;AAEnC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,IAAIC,gBAAgB,GAAG,KAAK;;AAEnC;AACA;AACA;AACA;AACA;AACA,OAAO,IAAIC,wBAAuC,GAAG,IAAI;AAEzD,IAAI;EACF;EACA;EACA;EACA;EACA,MAAMC,iBAAiB,GACrBC,OAAO,CAAC,sCAAsC,CAAC,CAACC,OAAO;EACzDD,OAAO,CAAC,yBAAyB,CAAC;EAClC,IACED,iBAAiB,KAChBA,iBAAiB,IAAI,OAAO,IAAIA,iBAAiB,CAACG,QAAQ,CAAC,QAAQ,CAAC,CAAC,EACtE;IACAN,gBAAgB,GAAG,IAAI;EACzB;EACA,MAAMO,YAAY,GAAGC,QAAQ,CAACL,iBAAiB,CAACM,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC;EAClE,IAAI,CAACC,KAAK,CAACH,YAAY,CAAC,EAAE;IACxBL,wBAAwB,GAAGK,YAAY;EACzC;EACA,IAAIA,YAAY,IAAI,CAAC,EAAE;IACrB,IAAI;MACF,MAAMI,QAAQ,GAAGP,OAAO,CAAC,uBAAuB,CAAC;MACjDH,gBAAgB,GACd,OAAOU,QAAQ,CAACC,0BAA0B,KAAK,UAAU;IAC7D,CAAC,CAAC,OAAOC,CAAC,EAAE;MACV;IAAA;EAEJ;AACF,CAAC,CAAC,OAAOA,CAAC,EAAE;EACV;AAAA","ignoreList":[]}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Platform } from "../Platform";
|
|
2
2
|
import NativeSkiaModule from "../specs/NativeSkiaModule";
|
|
3
|
+
import { registerSkiaWorkletSerialization } from "./SkiaWorkletSerialization";
|
|
3
4
|
if (Platform.OS !== "web" && global.SkiaApi == null) {
|
|
4
5
|
// Initialize RN Skia
|
|
5
6
|
const SkiaModule = NativeSkiaModule;
|
|
@@ -10,5 +11,8 @@ if (Platform.OS !== "web" && global.SkiaApi == null) {
|
|
|
10
11
|
if (result !== true) {
|
|
11
12
|
throw new Error(`Native Skia Module failed to correctly install JSI Bindings! Result: ${result}`);
|
|
12
13
|
}
|
|
14
|
+
// Skia objects use the JSI NativeState pattern and need a custom
|
|
15
|
+
// serializer to be transferable to worklet runtimes (Reanimated).
|
|
16
|
+
registerSkiaWorkletSerialization();
|
|
13
17
|
}
|
|
14
18
|
//# sourceMappingURL=NativeSetup.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["Platform","NativeSkiaModule","OS","global","SkiaApi","SkiaModule","install","Error","result"],"sources":["NativeSetup.ts"],"sourcesContent":["import { Platform } from \"../Platform\";\nimport NativeSkiaModule from \"../specs/NativeSkiaModule\";\n\nif (Platform.OS !== \"web\" && global.SkiaApi == null) {\n // Initialize RN Skia\n const SkiaModule = NativeSkiaModule;\n if (SkiaModule == null || typeof SkiaModule.install !== \"function\") {\n throw new Error(\n \"Native RNSkia Module cannot be found! Make sure you correctly \" +\n \"installed native dependencies and rebuilt your app.\"\n );\n }\n const result = SkiaModule.install();\n if (result !== true) {\n throw new Error(\n `Native Skia Module failed to correctly install JSI Bindings! Result: ${result}`\n );\n }\n}\n"],"mappings":"AAAA,SAASA,QAAQ,QAAQ,aAAa;AACtC,OAAOC,gBAAgB,MAAM,2BAA2B;AAExD,
|
|
1
|
+
{"version":3,"names":["Platform","NativeSkiaModule","registerSkiaWorkletSerialization","OS","global","SkiaApi","SkiaModule","install","Error","result"],"sources":["NativeSetup.ts"],"sourcesContent":["import { Platform } from \"../Platform\";\nimport NativeSkiaModule from \"../specs/NativeSkiaModule\";\n\nimport { registerSkiaWorkletSerialization } from \"./SkiaWorkletSerialization\";\n\nif (Platform.OS !== \"web\" && global.SkiaApi == null) {\n // Initialize RN Skia\n const SkiaModule = NativeSkiaModule;\n if (SkiaModule == null || typeof SkiaModule.install !== \"function\") {\n throw new Error(\n \"Native RNSkia Module cannot be found! Make sure you correctly \" +\n \"installed native dependencies and rebuilt your app.\"\n );\n }\n const result = SkiaModule.install();\n if (result !== true) {\n throw new Error(\n `Native Skia Module failed to correctly install JSI Bindings! Result: ${result}`\n );\n }\n // Skia objects use the JSI NativeState pattern and need a custom\n // serializer to be transferable to worklet runtimes (Reanimated).\n registerSkiaWorkletSerialization();\n}\n"],"mappings":"AAAA,SAASA,QAAQ,QAAQ,aAAa;AACtC,OAAOC,gBAAgB,MAAM,2BAA2B;AAExD,SAASC,gCAAgC,QAAQ,4BAA4B;AAE7E,IAAIF,QAAQ,CAACG,EAAE,KAAK,KAAK,IAAIC,MAAM,CAACC,OAAO,IAAI,IAAI,EAAE;EACnD;EACA,MAAMC,UAAU,GAAGL,gBAAgB;EACnC,IAAIK,UAAU,IAAI,IAAI,IAAI,OAAOA,UAAU,CAACC,OAAO,KAAK,UAAU,EAAE;IAClE,MAAM,IAAIC,KAAK,CACb,gEAAgE,GAC9D,qDACJ,CAAC;EACH;EACA,MAAMC,MAAM,GAAGH,UAAU,CAACC,OAAO,CAAC,CAAC;EACnC,IAAIE,MAAM,KAAK,IAAI,EAAE;IACnB,MAAM,IAAID,KAAK,CACb,wEAAwEC,MAAM,EAChF,CAAC;EACH;EACA;EACA;EACAP,gCAAgC,CAAC,CAAC;AACpC","ignoreList":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const registerSkiaWorkletSerialization: () => void;
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Skia and WebGPU API objects are implemented with the JSI NativeState
|
|
5
|
+
* pattern: plain JS objects with a shared prototype and native state
|
|
6
|
+
* attached. Worklets cannot serialize such objects by default (the prototype
|
|
7
|
+
* would be lost when moving them to another runtime), so we register a
|
|
8
|
+
* Custom Serializable that:
|
|
9
|
+
*
|
|
10
|
+
* - determine: detects native objects via the `__box` method installed on
|
|
11
|
+
* every Skia and WebGPU prototype (plain objects never reach the
|
|
12
|
+
* custom-serializable path, so this cannot misfire on user data).
|
|
13
|
+
* - pack: boxes the object into a HostObject wrapper that carries the native
|
|
14
|
+
* state and the class brand. HostObjects are transferred by reference.
|
|
15
|
+
* - unpack: unboxes on the target runtime, re-installing the class prototype
|
|
16
|
+
* there and re-attaching the same native state.
|
|
17
|
+
*
|
|
18
|
+
* See cpp/jsi/BoxedNativeObject.h for the native side.
|
|
19
|
+
*
|
|
20
|
+
* `react-native-worklets` (Reanimated 4) is required for this to work —
|
|
21
|
+
* without it, Skia and WebGPU objects cannot be captured in worklets or
|
|
22
|
+
* stored in shared values.
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
const determine = value => {
|
|
26
|
+
"worklet";
|
|
27
|
+
|
|
28
|
+
return typeof value.__box === "function";
|
|
29
|
+
};
|
|
30
|
+
const pack = value => {
|
|
31
|
+
"worklet";
|
|
32
|
+
|
|
33
|
+
return value.__box();
|
|
34
|
+
};
|
|
35
|
+
const unpack = packed => {
|
|
36
|
+
"worklet";
|
|
37
|
+
|
|
38
|
+
return packed.unbox();
|
|
39
|
+
};
|
|
40
|
+
export const registerSkiaWorkletSerialization = () => {
|
|
41
|
+
try {
|
|
42
|
+
const worklets = require("react-native-worklets");
|
|
43
|
+
if (typeof worklets.registerCustomSerializable === "function") {
|
|
44
|
+
worklets.registerCustomSerializable({
|
|
45
|
+
name: "ReactNativeSkia",
|
|
46
|
+
determine,
|
|
47
|
+
pack,
|
|
48
|
+
unpack
|
|
49
|
+
});
|
|
50
|
+
} else {
|
|
51
|
+
console.error("React Native Skia requires react-native-worklets >= 0.7.0 " + "(registerCustomSerializable) to use Skia objects inside worklets. " + "Please upgrade react-native-worklets and react-native-reanimated.");
|
|
52
|
+
}
|
|
53
|
+
} catch (e) {
|
|
54
|
+
// react-native-worklets is not installed. This is fine for apps that do
|
|
55
|
+
// not use Reanimated: Skia objects simply cannot be used inside worklets
|
|
56
|
+
// or shared values in this configuration.
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
//# sourceMappingURL=SkiaWorkletSerialization.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["determine","value","__box","pack","unpack","packed","unbox","registerSkiaWorkletSerialization","worklets","require","registerCustomSerializable","name","console","error","e"],"sources":["SkiaWorkletSerialization.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any */\n\n/**\n * Skia and WebGPU API objects are implemented with the JSI NativeState\n * pattern: plain JS objects with a shared prototype and native state\n * attached. Worklets cannot serialize such objects by default (the prototype\n * would be lost when moving them to another runtime), so we register a\n * Custom Serializable that:\n *\n * - determine: detects native objects via the `__box` method installed on\n * every Skia and WebGPU prototype (plain objects never reach the\n * custom-serializable path, so this cannot misfire on user data).\n * - pack: boxes the object into a HostObject wrapper that carries the native\n * state and the class brand. HostObjects are transferred by reference.\n * - unpack: unboxes on the target runtime, re-installing the class prototype\n * there and re-attaching the same native state.\n *\n * See cpp/jsi/BoxedNativeObject.h for the native side.\n *\n * `react-native-worklets` (Reanimated 4) is required for this to work —\n * without it, Skia and WebGPU objects cannot be captured in worklets or\n * stored in shared values.\n */\n\ninterface BoxedNativeObject {\n unbox: () => object;\n __boxedNativeObject: true;\n}\n\nconst determine = (value: object): value is object => {\n \"worklet\";\n return typeof (value as any).__box === \"function\";\n};\n\nconst pack = (value: object): BoxedNativeObject => {\n \"worklet\";\n return (value as any).__box();\n};\n\nconst unpack = (packed: BoxedNativeObject): object => {\n \"worklet\";\n return packed.unbox();\n};\n\nexport const registerSkiaWorkletSerialization = () => {\n try {\n const worklets = require(\"react-native-worklets\");\n if (typeof worklets.registerCustomSerializable === \"function\") {\n worklets.registerCustomSerializable({\n name: \"ReactNativeSkia\",\n determine,\n pack,\n unpack,\n });\n } else {\n console.error(\n \"React Native Skia requires react-native-worklets >= 0.7.0 \" +\n \"(registerCustomSerializable) to use Skia objects inside worklets. \" +\n \"Please upgrade react-native-worklets and react-native-reanimated.\"\n );\n }\n } catch (e) {\n // react-native-worklets is not installed. This is fine for apps that do\n // not use Reanimated: Skia objects simply cannot be used inside worklets\n // or shared values in this configuration.\n }\n};\n"],"mappings":"AAAA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAOA,MAAMA,SAAS,GAAIC,KAAa,IAAsB;EACpD,SAAS;;EACT,OAAO,OAAQA,KAAK,CAASC,KAAK,KAAK,UAAU;AACnD,CAAC;AAED,MAAMC,IAAI,GAAIF,KAAa,IAAwB;EACjD,SAAS;;EACT,OAAQA,KAAK,CAASC,KAAK,CAAC,CAAC;AAC/B,CAAC;AAED,MAAME,MAAM,GAAIC,MAAyB,IAAa;EACpD,SAAS;;EACT,OAAOA,MAAM,CAACC,KAAK,CAAC,CAAC;AACvB,CAAC;AAED,OAAO,MAAMC,gCAAgC,GAAGA,CAAA,KAAM;EACpD,IAAI;IACF,MAAMC,QAAQ,GAAGC,OAAO,CAAC,uBAAuB,CAAC;IACjD,IAAI,OAAOD,QAAQ,CAACE,0BAA0B,KAAK,UAAU,EAAE;MAC7DF,QAAQ,CAACE,0BAA0B,CAAC;QAClCC,IAAI,EAAE,iBAAiB;QACvBX,SAAS;QACTG,IAAI;QACJC;MACF,CAAC,CAAC;IACJ,CAAC,MAAM;MACLQ,OAAO,CAACC,KAAK,CACX,4DAA4D,GAC1D,oEAAoE,GACpE,mEACJ,CAAC;IACH;EACF,CAAC,CAAC,OAAOC,CAAC,EAAE;IACV;IACA;IACA;EAAA;AAEJ,CAAC","ignoreList":[]}
|
|
@@ -2,7 +2,7 @@ function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object
|
|
|
2
2
|
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
|
|
3
3
|
function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
4
4
|
import Rea from "../external/reanimated/ReanimatedProxy";
|
|
5
|
-
import { HAS_REANIMATED_3 } from "../external/reanimated/renderHelpers";
|
|
5
|
+
import { HAS_REANIMATED_3, HAS_REANIMATED_4, REANIMATED_VERSION_MAJOR } from "../external/reanimated/renderHelpers";
|
|
6
6
|
import { ReanimatedRecorder } from "./Recorder/ReanimatedRecorder";
|
|
7
7
|
import { Container, StaticContainer } from "./StaticContainer";
|
|
8
8
|
import { visit } from "./Recorder/Visitor";
|
|
@@ -73,10 +73,29 @@ class NativeReanimatedContainer extends Container {
|
|
|
73
73
|
}
|
|
74
74
|
}
|
|
75
75
|
}
|
|
76
|
+
let hasWarnedAboutReanimatedSupport = false;
|
|
77
|
+
const reanimatedSupportError = () => {
|
|
78
|
+
if (REANIMATED_VERSION_MAJOR !== null && REANIMATED_VERSION_MAJOR >= 4) {
|
|
79
|
+
return "React Native Skia requires react-native-worklets >= 0.7.0 for its " + "Reanimated integration on native platforms. Reanimated 4 is " + "installed, but react-native-worklets is missing or too old. " + "Please install or upgrade react-native-worklets.";
|
|
80
|
+
}
|
|
81
|
+
return "React Native Skia requires Reanimated 4 (react-native-worklets >= " + "0.7.0) for its Reanimated integration on native platforms. " + "Reanimated 3 is not supported anymore: Skia objects cannot be used " + "inside worklets or shared values with it. " + "Please upgrade to react-native-reanimated >= 4.0.0.";
|
|
82
|
+
};
|
|
76
83
|
export const createContainer = (Skia, nativeId) => {
|
|
77
|
-
if (
|
|
84
|
+
if (HAS_REANIMATED_4 && nativeId !== -1) {
|
|
78
85
|
return new NativeReanimatedContainer(Skia, nativeId);
|
|
79
86
|
} else {
|
|
87
|
+
if (HAS_REANIMATED_3 && !HAS_REANIMATED_4) {
|
|
88
|
+
const message = reanimatedSupportError();
|
|
89
|
+
if (__DEV__) {
|
|
90
|
+
// Fail loudly in development — a silent fallback to static rendering
|
|
91
|
+
// would only be noticed as frozen animations.
|
|
92
|
+
throw new Error(message);
|
|
93
|
+
}
|
|
94
|
+
if (!hasWarnedAboutReanimatedSupport) {
|
|
95
|
+
hasWarnedAboutReanimatedSupport = true;
|
|
96
|
+
console.error(`${message} Falling back to static rendering (animations will not run).`);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
80
99
|
return new StaticContainer(Skia, nativeId);
|
|
81
100
|
}
|
|
82
101
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["Rea","HAS_REANIMATED_3","ReanimatedRecorder","Container","StaticContainer","visit","SkiaViewApi","globalThis","nativeDrawOnscreen","nativeId","recorder","picture","play","setJsiProperty","NativeReanimatedContainer","constructor","Skia","_defineProperty","Picture","MakePicture","unmount","mapperId","stopMapper","redraw","unmounted","root","sharedValues","getSharedValues","sharedRecorder","getRecorder","runOnUI","length","startMapper","applyUpdates","createContainer"],"sources":["Container.native.ts"],"sourcesContent":["import Rea from \"../external/reanimated/ReanimatedProxy\";\nimport type { Skia, SkPicture } from \"../skia/types\";\nimport {
|
|
1
|
+
{"version":3,"names":["Rea","HAS_REANIMATED_3","HAS_REANIMATED_4","REANIMATED_VERSION_MAJOR","ReanimatedRecorder","Container","StaticContainer","visit","SkiaViewApi","globalThis","nativeDrawOnscreen","nativeId","recorder","picture","play","setJsiProperty","NativeReanimatedContainer","constructor","Skia","_defineProperty","Picture","MakePicture","unmount","mapperId","stopMapper","redraw","unmounted","root","sharedValues","getSharedValues","sharedRecorder","getRecorder","runOnUI","length","startMapper","applyUpdates","hasWarnedAboutReanimatedSupport","reanimatedSupportError","createContainer","message","__DEV__","Error","console","error"],"sources":["Container.native.ts"],"sourcesContent":["import Rea from \"../external/reanimated/ReanimatedProxy\";\nimport type { Skia, SkPicture } from \"../skia/types\";\nimport {\n HAS_REANIMATED_3,\n HAS_REANIMATED_4,\n REANIMATED_VERSION_MAJOR,\n} from \"../external/reanimated/renderHelpers\";\nimport type { JsiRecorder } from \"../skia/types/Recorder\";\n\nimport { ReanimatedRecorder } from \"./Recorder/ReanimatedRecorder\";\nimport { Container, StaticContainer } from \"./StaticContainer\";\nimport { visit } from \"./Recorder/Visitor\";\n\nimport \"../skia/NativeSetup\";\nimport \"../views/api\";\n\n// create local reference for `strictGlobal` option in Worklets\nconst { SkiaViewApi } = globalThis;\n\nconst nativeDrawOnscreen = (\n nativeId: number,\n recorder: JsiRecorder,\n picture: SkPicture\n) => {\n \"worklet\";\n\n //const start = performance.now();\n recorder.play(picture);\n //const end = performance.now();\n //console.log(\"Recording time: \", end - start);\n SkiaViewApi.setJsiProperty(nativeId, \"picture\", picture);\n};\n\nclass NativeReanimatedContainer extends Container {\n private mapperId: number | null = null;\n private picture: SkPicture;\n\n constructor(\n Skia: Skia,\n private nativeId: number\n ) {\n super(Skia);\n this.picture = Skia.Picture.MakePicture(null)!;\n }\n\n unmount() {\n super.unmount();\n if (this.mapperId !== null) {\n // The mapper closure retains the recorder and its resources (e.g.\n // images) on the UI runtime and keeps updating the picture of an\n // unmounted view — stop it or it leaks for the lifetime of the app.\n Rea.stopMapper(this.mapperId);\n this.mapperId = null;\n }\n }\n\n redraw() {\n if (this.mapperId !== null) {\n Rea.stopMapper(this.mapperId);\n this.mapperId = null;\n }\n if (this.unmounted) {\n return;\n }\n const recorder = new ReanimatedRecorder(this.Skia);\n const { nativeId, picture } = this;\n visit(recorder, this.root);\n const sharedValues = recorder.getSharedValues();\n const sharedRecorder = recorder.getRecorder();\n // Draw first frame\n Rea.runOnUI(() => {\n \"worklet\";\n nativeDrawOnscreen(nativeId, sharedRecorder, picture);\n })();\n // Animate\n if (sharedValues.length > 0) {\n this.mapperId = Rea.startMapper(() => {\n \"worklet\";\n sharedRecorder.applyUpdates(sharedValues);\n nativeDrawOnscreen(nativeId, sharedRecorder, picture);\n }, sharedValues);\n }\n }\n}\n\nlet hasWarnedAboutReanimatedSupport = false;\n\nconst reanimatedSupportError = () => {\n if (REANIMATED_VERSION_MAJOR !== null && REANIMATED_VERSION_MAJOR >= 4) {\n return (\n \"React Native Skia requires react-native-worklets >= 0.7.0 for its \" +\n \"Reanimated integration on native platforms. Reanimated 4 is \" +\n \"installed, but react-native-worklets is missing or too old. \" +\n \"Please install or upgrade react-native-worklets.\"\n );\n }\n return (\n \"React Native Skia requires Reanimated 4 (react-native-worklets >= \" +\n \"0.7.0) for its Reanimated integration on native platforms. \" +\n \"Reanimated 3 is not supported anymore: Skia objects cannot be used \" +\n \"inside worklets or shared values with it. \" +\n \"Please upgrade to react-native-reanimated >= 4.0.0.\"\n );\n};\n\nexport const createContainer = (Skia: Skia, nativeId: number) => {\n if (HAS_REANIMATED_4 && nativeId !== -1) {\n return new NativeReanimatedContainer(Skia, nativeId);\n } else {\n if (HAS_REANIMATED_3 && !HAS_REANIMATED_4) {\n const message = reanimatedSupportError();\n if (__DEV__) {\n // Fail loudly in development — a silent fallback to static rendering\n // would only be noticed as frozen animations.\n throw new Error(message);\n }\n if (!hasWarnedAboutReanimatedSupport) {\n hasWarnedAboutReanimatedSupport = true;\n console.error(\n `${message} Falling back to static rendering (animations will not run).`\n );\n }\n }\n return new StaticContainer(Skia, nativeId);\n }\n};\n"],"mappings":";;;AAAA,OAAOA,GAAG,MAAM,wCAAwC;AAExD,SACEC,gBAAgB,EAChBC,gBAAgB,EAChBC,wBAAwB,QACnB,sCAAsC;AAG7C,SAASC,kBAAkB,QAAQ,+BAA+B;AAClE,SAASC,SAAS,EAAEC,eAAe,QAAQ,mBAAmB;AAC9D,SAASC,KAAK,QAAQ,oBAAoB;AAE1C,OAAO,qBAAqB;AAC5B,OAAO,cAAc;;AAErB;AACA,MAAM;EAAEC;AAAY,CAAC,GAAGC,UAAU;AAElC,MAAMC,kBAAkB,GAAGA,CACzBC,QAAgB,EAChBC,QAAqB,EACrBC,OAAkB,KACf;EACH,SAAS;;EAET;EACAD,QAAQ,CAACE,IAAI,CAACD,OAAO,CAAC;EACtB;EACA;EACAL,WAAW,CAACO,cAAc,CAACJ,QAAQ,EAAE,SAAS,EAAEE,OAAO,CAAC;AAC1D,CAAC;AAED,MAAMG,yBAAyB,SAASX,SAAS,CAAC;EAIhDY,WAAWA,CACTC,IAAU,EACFP,QAAgB,EACxB;IACA,KAAK,CAACO,IAAI,CA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c,CAACK,YAAY,CAACP,YAAY,CAAC;QACzClB,kBAAkB,CAACC,QAAQ,EAAEmB,cAAc,EAAEjB,OAAO,CAAC;MACvD,CAAC,EAAEe,YAAY,CAAC;IAClB;EACF;AACF;AAEA,IAAIQ,+BAA+B,GAAG,KAAK;AAE3C,MAAMC,sBAAsB,GAAGA,CAAA,KAAM;EACnC,IAAIlC,wBAAwB,KAAK,IAAI,IAAIA,wBAAwB,IAAI,CAAC,EAAE;IACtE,OACE,oEAAoE,GACpE,8DAA8D,GAC9D,8DAA8D,GAC9D,kDAAkD;EAEtD;EACA,OACE,oEAAoE,GACpE,6DAA6D,GAC7D,qEAAqE,GACrE,4CAA4C,GAC5C,qDAAqD;AAEzD,CAAC;AAED,OAAO,MAAMmC,eAAe,GAAGA,CAACpB,IAAU,EAAEP,QAAgB,KAAK;EAC/D,IAAIT,gBAAgB,IAAIS,QAAQ,KAAK,CAAC,CAAC,EAAE;IACvC,OAAO,IAAIK,yBAAyB,CAACE,IAAI,EAAEP,QAAQ,CAAC;EACtD,CAAC,MAAM;IACL,IAAIV,gBAAgB,IAAI,CAACC,gBAAgB,EAAE;MACzC,MAAMqC,OAAO,GAAGF,sBAAsB,CAAC,CAAC;MACxC,IAAIG,OAAO,EAAE;QACX;QACA;QACA,MAAM,IAAIC,KAAK,CAACF,OAAO,CAAC;MAC1B;MACA,IAAI,CAACH,+BAA+B,EAAE;QACpCA,+BAA+B,GAAG,IAAI;QACtCM,OAAO,CAACC,KAAK,CACX,GAAGJ,OAAO,8DACZ,CAAC;MACH;IACF;IACA,OAAO,IAAIjC,eAAe,CAACY,IAAI,EAAEP,QAAQ,CAAC;EAC5C;AACF,CAAC","ignoreList":[]}
|
|
@@ -6,6 +6,7 @@ declare global {
|
|
|
6
6
|
fabric: boolean;
|
|
7
7
|
getNativeSurface: (contextId: number) => NativeCanvas;
|
|
8
8
|
MakeWebGPUCanvasContext: (contextId: number, width: number, height: number) => RNCanvasContext;
|
|
9
|
+
destroyContext: (contextId: number) => void;
|
|
9
10
|
};
|
|
10
11
|
}
|
|
11
12
|
type SurfacePointer = bigint;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
|
|
2
|
-
import React, { useImperativeHandle, useRef, useState } from "react";
|
|
2
|
+
import React, { useEffect, useImperativeHandle, useRef, useState } from "react";
|
|
3
3
|
import { View, Platform } from "react-native";
|
|
4
4
|
import WebGPUNativeView from "../specs/WebGPUViewNativeComponent";
|
|
5
5
|
let CONTEXT_COUNTER = 1;
|
|
@@ -13,6 +13,19 @@ export const WebGPUCanvas = ({
|
|
|
13
13
|
}) => {
|
|
14
14
|
const viewRef = useRef(null);
|
|
15
15
|
const [contextId] = useState(() => generateContextId());
|
|
16
|
+
|
|
17
|
+
// Retire the native registry entry for this contextId on unmount. When a
|
|
18
|
+
// native surface is still attached, this is a no-op and the native view's
|
|
19
|
+
// own teardown retires the entry instead — which keeps StrictMode's
|
|
20
|
+
// simulated unmount (which re-runs effects without unmounting native views)
|
|
21
|
+
// from orphaning a live surface.
|
|
22
|
+
useEffect(() => {
|
|
23
|
+
return () => {
|
|
24
|
+
if (typeof RNWebGPU !== "undefined") {
|
|
25
|
+
RNWebGPU.destroyContext(contextId);
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
}, [contextId]);
|
|
16
29
|
useImperativeHandle(ref, () => ({
|
|
17
30
|
getContextId: () => contextId,
|
|
18
31
|
getNativeSurface: () => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["React","useImperativeHandle","useRef","useState","View","Platform","WebGPUNativeView","CONTEXT_COUNTER","generateContextId","WebGPUCanvas","transparent","ref","props","viewRef","contextId","
|
|
1
|
+
{"version":3,"names":["React","useEffect","useImperativeHandle","useRef","useState","View","Platform","WebGPUNativeView","CONTEXT_COUNTER","generateContextId","WebGPUCanvas","transparent","ref","props","viewRef","contextId","RNWebGPU","destroyContext","getContextId","getNativeSurface","Error","getContext","contextName","current","view","size","getBoundingClientRect","unstable_getBoundingClientRect","MakeWebGPUCanvasContext","width","height","OS","createElement","_extends","collapsable","style","flex"],"sources":["WebGPUCanvas.tsx"],"sourcesContent":["import React, { useEffect, useImperativeHandle, useRef, useState } from \"react\";\nimport type { ViewProps } from \"react-native\";\nimport { View, Platform } from \"react-native\";\n\nimport WebGPUNativeView from \"../specs/WebGPUViewNativeComponent\";\n\nlet CONTEXT_COUNTER = 1;\nfunction generateContextId() {\n return CONTEXT_COUNTER++;\n}\n\ndeclare global {\n var RNWebGPU: {\n gpu: GPU;\n fabric: boolean;\n getNativeSurface: (contextId: number) => NativeCanvas;\n MakeWebGPUCanvasContext: (\n contextId: number,\n width: number,\n height: number\n ) => RNCanvasContext;\n // Retires a canvas context; called by the Canvas on unmount (the Canvas\n // owns the native registry entry for its contextId).\n destroyContext: (contextId: number) => void;\n };\n}\n\ntype SurfacePointer = bigint;\n\nexport interface NativeCanvas {\n surface: SurfacePointer;\n width: number;\n height: number;\n clientWidth: number;\n clientHeight: number;\n}\n\nexport type RNCanvasContext = GPUCanvasContext & {\n present: () => void;\n};\n\nexport interface WebGPUCanvasRef {\n getContextId: () => number;\n getContext(contextName: \"webgpu\"): RNCanvasContext | null;\n getNativeSurface: () => NativeCanvas;\n}\n\ninterface WebGPUCanvasProps extends ViewProps {\n transparent?: boolean;\n ref?: React.Ref<WebGPUCanvasRef>;\n}\n\nexport const WebGPUCanvas = ({\n transparent,\n ref,\n ...props\n}: WebGPUCanvasProps) => {\n const viewRef = useRef(null);\n const [contextId] = useState(() => generateContextId());\n\n // Retire the native registry entry for this contextId on unmount. When a\n // native surface is still attached, this is a no-op and the native view's\n // own teardown retires the entry instead — which keeps StrictMode's\n // simulated unmount (which re-runs effects without unmounting native views)\n // from orphaning a live surface.\n useEffect(() => {\n return () => {\n if (typeof RNWebGPU !== \"undefined\") {\n RNWebGPU.destroyContext(contextId);\n }\n };\n }, [contextId]);\n\n useImperativeHandle(ref, () => ({\n getContextId: () => contextId,\n getNativeSurface: () => {\n if (typeof RNWebGPU === \"undefined\") {\n throw new Error(\n \"[WebGPU] RNWebGPU is not available. Make sure SK_GRAPHITE is enabled.\"\n );\n }\n return RNWebGPU.getNativeSurface(contextId);\n },\n getContext(contextName: \"webgpu\"): RNCanvasContext | null {\n if (contextName !== \"webgpu\") {\n throw new Error(`[WebGPU] Unsupported context: ${contextName}`);\n }\n if (!viewRef.current) {\n throw new Error(\"[WebGPU] Cannot get context before mount\");\n }\n if (typeof RNWebGPU === \"undefined\") {\n throw new Error(\n \"[WebGPU] RNWebGPU is not available. Make sure SK_GRAPHITE is enabled.\"\n );\n }\n // getBoundingClientRect became stable in RN 0.83\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const view = viewRef.current as any;\n const size =\n \"getBoundingClientRect\" in view\n ? view.getBoundingClientRect()\n : view.unstable_getBoundingClientRect();\n return RNWebGPU.MakeWebGPUCanvasContext(\n contextId,\n size.width,\n size.height\n );\n },\n }));\n\n // WebGPU Canvas is not supported on web\n if (Platform.OS === \"web\") {\n return <View {...props} />;\n }\n\n return (\n <View collapsable={false} ref={viewRef} {...props}>\n <WebGPUNativeView\n style={{ flex: 1 }}\n contextId={contextId}\n transparent={!!transparent}\n />\n </View>\n );\n};\n"],"mappings":";AAAA,OAAOA,KAAK,IAAIC,SAAS,EAAEC,mBAAmB,EAAEC,MAAM,EAAEC,QAAQ,QAAQ,OAAO;AAE/E,SAASC,IAAI,EAAEC,QAAQ,QAAQ,cAAc;AAE7C,OAAOC,gBAAgB,MAAM,oCAAoC;AAEjE,IAAIC,eAAe,GAAG,CAAC;AACvB,SAASC,iBAAiBA,CAAA,EAAG;EAC3B,OAAOD,eAAe,EAAE;AAC1B;AA2CA,OAAO,MAAME,YAAY,GAAGA,CAAC;EAC3BC,WAAW;EAC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AAK,EACVJ,IAAI,CAACK,MACP,CAAC;IACH;EACF,CAAC,CAAC,CAAC;;EAEH;EACA,IAAIxB,QAAQ,CAACyB,EAAE,KAAK,KAAK,EAAE;IACzB,oBAAO/B,KAAA,CAAAgC,aAAA,CAAC3B,IAAI,EAAKQ,KAAQ,CAAC;EAC5B;EAEA,oBACEb,KAAA,CAAAgC,aAAA,CAAC3B,IAAI,EAAA4B,QAAA;IAACC,WAAW,EAAE,KAAM;IAACtB,GAAG,EAAEE;EAAQ,GAAKD,KAAK,gBAC/Cb,KAAA,CAAAgC,aAAA,CAACzB,gBAAgB;IACf4B,KAAK,EAAE;MAAEC,IAAI,EAAE;IAAE,CAAE;IACnBrB,SAAS,EAAEA,SAAU;IACrBJ,WAAW,EAAE,CAAC,CAACA;EAAY,CAC5B,CACG,CAAC;AAEX,CAAC","ignoreList":[]}
|
|
@@ -1 +1,16 @@
|
|
|
1
1
|
export let HAS_REANIMATED_3: boolean;
|
|
2
|
+
/**
|
|
3
|
+
* True when the worklets-based Reanimated integration is available
|
|
4
|
+
* (Reanimated 4 with react-native-worklets providing
|
|
5
|
+
* registerCustomSerializable). Skia objects use the JSI NativeState pattern
|
|
6
|
+
* and can only be transferred to worklet runtimes through a custom
|
|
7
|
+
* serializer, so on native the Reanimated integration requires Reanimated 4 —
|
|
8
|
+
* Reanimated 3 is not supported.
|
|
9
|
+
*/
|
|
10
|
+
export let HAS_REANIMATED_4: boolean;
|
|
11
|
+
/**
|
|
12
|
+
* Major version of the installed react-native-reanimated package, or null if
|
|
13
|
+
* it is not installed. Used to give actionable diagnostics when the
|
|
14
|
+
* integration cannot be enabled.
|
|
15
|
+
*/
|
|
16
|
+
export let REANIMATED_VERSION_MAJOR: null;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export function registerSkiaWorkletSerialization(): void;
|
|
@@ -1 +1,16 @@
|
|
|
1
1
|
export declare let HAS_REANIMATED_3: boolean;
|
|
2
|
+
/**
|
|
3
|
+
* True when the worklets-based Reanimated integration is available
|
|
4
|
+
* (Reanimated 4 with react-native-worklets providing
|
|
5
|
+
* registerCustomSerializable). Skia objects use the JSI NativeState pattern
|
|
6
|
+
* and can only be transferred to worklet runtimes through a custom
|
|
7
|
+
* serializer, so on native the Reanimated integration requires Reanimated 4 —
|
|
8
|
+
* Reanimated 3 is not supported.
|
|
9
|
+
*/
|
|
10
|
+
export declare let HAS_REANIMATED_4: boolean;
|
|
11
|
+
/**
|
|
12
|
+
* Major version of the installed react-native-reanimated package, or null if
|
|
13
|
+
* it is not installed. Used to give actionable diagnostics when the
|
|
14
|
+
* integration cannot be enabled.
|
|
15
|
+
*/
|
|
16
|
+
export declare let REANIMATED_VERSION_MAJOR: number | null;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const registerSkiaWorkletSerialization: () => void;
|
|
@@ -6,6 +6,7 @@ declare global {
|
|
|
6
6
|
fabric: boolean;
|
|
7
7
|
getNativeSurface: (contextId: number) => NativeCanvas;
|
|
8
8
|
MakeWebGPUCanvasContext: (contextId: number, width: number, height: number) => RNCanvasContext;
|
|
9
|
+
destroyContext: (contextId: number) => void;
|
|
9
10
|
};
|
|
10
11
|
}
|
|
11
12
|
type SurfacePointer = bigint;
|
package/package.json
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
"setup-skia-web": "scripts/setup-canvaskit.js"
|
|
9
9
|
},
|
|
10
10
|
"title": "React Native Skia",
|
|
11
|
-
"version": "2.
|
|
11
|
+
"version": "2.10.0",
|
|
12
12
|
"description": "High-performance React Native Graphics using Skia",
|
|
13
13
|
"main": "lib/module/index.js",
|
|
14
14
|
"react-native": "src/index.ts",
|
|
@@ -79,7 +79,8 @@
|
|
|
79
79
|
"peerDependencies": {
|
|
80
80
|
"react": ">=19.0",
|
|
81
81
|
"react-native": ">=0.78",
|
|
82
|
-
"react-native-reanimated": ">=
|
|
82
|
+
"react-native-reanimated": ">=4.0.0",
|
|
83
|
+
"react-native-worklets": ">=0.7.0"
|
|
83
84
|
},
|
|
84
85
|
"peerDependenciesMeta": {
|
|
85
86
|
"react-native": {
|
|
@@ -87,6 +88,9 @@
|
|
|
87
88
|
},
|
|
88
89
|
"react-native-reanimated": {
|
|
89
90
|
"optional": true
|
|
91
|
+
},
|
|
92
|
+
"react-native-worklets": {
|
|
93
|
+
"optional": true
|
|
90
94
|
}
|
|
91
95
|
},
|
|
92
96
|
"devDependencies": {
|
|
@@ -127,7 +131,7 @@
|
|
|
127
131
|
"rimraf": "3.0.2",
|
|
128
132
|
"semantic-release": "^24.1.0",
|
|
129
133
|
"semantic-release-yarn": "^3.0.2",
|
|
130
|
-
"tar": "^7.5.
|
|
134
|
+
"tar": "^7.5.19",
|
|
131
135
|
"ts-jest": "29.4.3",
|
|
132
136
|
"tsx": "^4.21.0",
|
|
133
137
|
"typescript": "^5.2.2",
|
|
@@ -135,9 +139,10 @@
|
|
|
135
139
|
},
|
|
136
140
|
"dependencies": {
|
|
137
141
|
"canvaskit-wasm": "0.41.0",
|
|
138
|
-
"react-native-skia-
|
|
139
|
-
"react-native-skia-
|
|
140
|
-
"react-native-skia-
|
|
142
|
+
"react-native-skia-android": "150.0.0",
|
|
143
|
+
"react-native-skia-apple-ios": "150.0.0",
|
|
144
|
+
"react-native-skia-apple-macos": "150.0.0",
|
|
145
|
+
"react-native-skia-apple-tvos": "150.0.0",
|
|
141
146
|
"react-reconciler": "0.31.0"
|
|
142
147
|
},
|
|
143
148
|
"graphiteDependencies": {
|
|
@@ -181,6 +186,5 @@
|
|
|
181
186
|
}
|
|
182
187
|
]
|
|
183
188
|
]
|
|
184
|
-
}
|
|
185
|
-
"stableVersion": "0.0.0"
|
|
189
|
+
}
|
|
186
190
|
}
|
|
@@ -155,8 +155,7 @@ Pod::Spec.new do |s|
|
|
|
155
155
|
'cpp/rnskia/RNDawnWindowContext.h',
|
|
156
156
|
'cpp/rnskia/RNDawnWindowContext.cpp',
|
|
157
157
|
'cpp/rnskia/RNImageProvider.h',
|
|
158
|
-
'cpp/rnwgpu/**/*.{h,cpp}'
|
|
159
|
-
'cpp/jsi2/**/*.{h,cpp}'
|
|
158
|
+
'cpp/rnwgpu/**/*.{h,cpp}'
|
|
160
159
|
]
|
|
161
160
|
s.exclude_files = graphite_exclusions unless use_graphite
|
|
162
161
|
|
|
@@ -1,5 +1,22 @@
|
|
|
1
1
|
export let HAS_REANIMATED_3 = false;
|
|
2
2
|
|
|
3
|
+
/**
|
|
4
|
+
* True when the worklets-based Reanimated integration is available
|
|
5
|
+
* (Reanimated 4 with react-native-worklets providing
|
|
6
|
+
* registerCustomSerializable). Skia objects use the JSI NativeState pattern
|
|
7
|
+
* and can only be transferred to worklet runtimes through a custom
|
|
8
|
+
* serializer, so on native the Reanimated integration requires Reanimated 4 —
|
|
9
|
+
* Reanimated 3 is not supported.
|
|
10
|
+
*/
|
|
11
|
+
export let HAS_REANIMATED_4 = false;
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Major version of the installed react-native-reanimated package, or null if
|
|
15
|
+
* it is not installed. Used to give actionable diagnostics when the
|
|
16
|
+
* integration cannot be enabled.
|
|
17
|
+
*/
|
|
18
|
+
export let REANIMATED_VERSION_MAJOR: number | null = null;
|
|
19
|
+
|
|
3
20
|
try {
|
|
4
21
|
// This logic is convoluted but necessary
|
|
5
22
|
// In most systems, `require("react-native-reanimated")` throws an error, all is well.
|
|
@@ -14,6 +31,19 @@ try {
|
|
|
14
31
|
) {
|
|
15
32
|
HAS_REANIMATED_3 = true;
|
|
16
33
|
}
|
|
34
|
+
const majorVersion = parseInt(reanimatedVersion.split(".")[0], 10);
|
|
35
|
+
if (!isNaN(majorVersion)) {
|
|
36
|
+
REANIMATED_VERSION_MAJOR = majorVersion;
|
|
37
|
+
}
|
|
38
|
+
if (majorVersion >= 4) {
|
|
39
|
+
try {
|
|
40
|
+
const worklets = require("react-native-worklets");
|
|
41
|
+
HAS_REANIMATED_4 =
|
|
42
|
+
typeof worklets.registerCustomSerializable === "function";
|
|
43
|
+
} catch (e) {
|
|
44
|
+
// react-native-worklets not installed
|
|
45
|
+
}
|
|
46
|
+
}
|
|
17
47
|
} catch (e) {
|
|
18
48
|
// do nothing
|
|
19
49
|
}
|
package/src/skia/NativeSetup.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { Platform } from "../Platform";
|
|
2
2
|
import NativeSkiaModule from "../specs/NativeSkiaModule";
|
|
3
3
|
|
|
4
|
+
import { registerSkiaWorkletSerialization } from "./SkiaWorkletSerialization";
|
|
5
|
+
|
|
4
6
|
if (Platform.OS !== "web" && global.SkiaApi == null) {
|
|
5
7
|
// Initialize RN Skia
|
|
6
8
|
const SkiaModule = NativeSkiaModule;
|
|
@@ -16,4 +18,7 @@ if (Platform.OS !== "web" && global.SkiaApi == null) {
|
|
|
16
18
|
`Native Skia Module failed to correctly install JSI Bindings! Result: ${result}`
|
|
17
19
|
);
|
|
18
20
|
}
|
|
21
|
+
// Skia objects use the JSI NativeState pattern and need a custom
|
|
22
|
+
// serializer to be transferable to worklet runtimes (Reanimated).
|
|
23
|
+
registerSkiaWorkletSerialization();
|
|
19
24
|
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Skia and WebGPU API objects are implemented with the JSI NativeState
|
|
5
|
+
* pattern: plain JS objects with a shared prototype and native state
|
|
6
|
+
* attached. Worklets cannot serialize such objects by default (the prototype
|
|
7
|
+
* would be lost when moving them to another runtime), so we register a
|
|
8
|
+
* Custom Serializable that:
|
|
9
|
+
*
|
|
10
|
+
* - determine: detects native objects via the `__box` method installed on
|
|
11
|
+
* every Skia and WebGPU prototype (plain objects never reach the
|
|
12
|
+
* custom-serializable path, so this cannot misfire on user data).
|
|
13
|
+
* - pack: boxes the object into a HostObject wrapper that carries the native
|
|
14
|
+
* state and the class brand. HostObjects are transferred by reference.
|
|
15
|
+
* - unpack: unboxes on the target runtime, re-installing the class prototype
|
|
16
|
+
* there and re-attaching the same native state.
|
|
17
|
+
*
|
|
18
|
+
* See cpp/jsi/BoxedNativeObject.h for the native side.
|
|
19
|
+
*
|
|
20
|
+
* `react-native-worklets` (Reanimated 4) is required for this to work —
|
|
21
|
+
* without it, Skia and WebGPU objects cannot be captured in worklets or
|
|
22
|
+
* stored in shared values.
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
interface BoxedNativeObject {
|
|
26
|
+
unbox: () => object;
|
|
27
|
+
__boxedNativeObject: true;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const determine = (value: object): value is object => {
|
|
31
|
+
"worklet";
|
|
32
|
+
return typeof (value as any).__box === "function";
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
const pack = (value: object): BoxedNativeObject => {
|
|
36
|
+
"worklet";
|
|
37
|
+
return (value as any).__box();
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
const unpack = (packed: BoxedNativeObject): object => {
|
|
41
|
+
"worklet";
|
|
42
|
+
return packed.unbox();
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
export const registerSkiaWorkletSerialization = () => {
|
|
46
|
+
try {
|
|
47
|
+
const worklets = require("react-native-worklets");
|
|
48
|
+
if (typeof worklets.registerCustomSerializable === "function") {
|
|
49
|
+
worklets.registerCustomSerializable({
|
|
50
|
+
name: "ReactNativeSkia",
|
|
51
|
+
determine,
|
|
52
|
+
pack,
|
|
53
|
+
unpack,
|
|
54
|
+
});
|
|
55
|
+
} else {
|
|
56
|
+
console.error(
|
|
57
|
+
"React Native Skia requires react-native-worklets >= 0.7.0 " +
|
|
58
|
+
"(registerCustomSerializable) to use Skia objects inside worklets. " +
|
|
59
|
+
"Please upgrade react-native-worklets and react-native-reanimated."
|
|
60
|
+
);
|
|
61
|
+
}
|
|
62
|
+
} catch (e) {
|
|
63
|
+
// react-native-worklets is not installed. This is fine for apps that do
|
|
64
|
+
// not use Reanimated: Skia objects simply cannot be used inside worklets
|
|
65
|
+
// or shared values in this configuration.
|
|
66
|
+
}
|
|
67
|
+
};
|