@shopify/react-native-skia 2.10.0 → 2.10.1
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 +7 -41
- package/android/build.gradle +33 -0
- package/android/src/main/java/com/shopify/reactnative/skia/RNSkiaPackage.java +1 -2
- package/cpp/api/JsiNativeBuffer.h +14 -20
- package/cpp/api/JsiSkAnimatedImage.h +13 -16
- package/cpp/api/JsiSkAnimatedImageFactory.h +9 -7
- package/cpp/api/JsiSkApi.h +94 -90
- package/cpp/api/JsiSkCanvas.h +108 -251
- package/cpp/api/JsiSkColorFilterFactory.h +45 -63
- package/cpp/api/JsiSkContourMeasure.h +19 -29
- package/cpp/api/JsiSkContourMeasureIter.h +6 -6
- package/cpp/api/JsiSkConverters.h +410 -0
- package/cpp/api/JsiSkDataFactory.h +9 -15
- package/cpp/api/JsiSkFont.h +99 -180
- package/cpp/api/JsiSkFontMgr.h +19 -21
- package/cpp/api/JsiSkFontMgrFactory.h +4 -5
- package/cpp/api/JsiSkImage.h +66 -66
- package/cpp/api/JsiSkImageFactory.h +66 -63
- package/cpp/api/JsiSkImageFilterFactory.h +354 -608
- package/cpp/api/JsiSkImageInfo.h +10 -13
- package/cpp/api/JsiSkMaskFilterFactory.h +8 -11
- package/cpp/api/JsiSkMatrix.h +36 -73
- package/cpp/api/JsiSkNativeObjects.h +60 -92
- package/cpp/api/JsiSkPaint.h +73 -131
- package/cpp/api/JsiSkParagraph.h +36 -53
- package/cpp/api/JsiSkParagraphBuilder.h +36 -64
- package/cpp/api/JsiSkParagraphBuilderFactory.h +11 -16
- package/cpp/api/JsiSkPath.h +216 -349
- package/cpp/api/JsiSkPathBuilder.h +133 -269
- package/cpp/api/JsiSkPathBuilderFactory.h +11 -11
- package/cpp/api/JsiSkPathEffectFactory.h +52 -72
- package/cpp/api/JsiSkPathFactory.h +129 -195
- package/cpp/api/JsiSkPicture.h +12 -18
- package/cpp/api/JsiSkPictureRecorder.h +14 -15
- package/cpp/api/JsiSkPoint.h +4 -4
- package/cpp/api/JsiSkRRect.h +7 -8
- package/cpp/api/JsiSkRSXform.h +10 -23
- package/cpp/api/JsiSkRect.h +23 -31
- package/cpp/api/JsiSkRuntimeEffect.h +67 -83
- package/cpp/api/JsiSkRuntimeEffectFactory.h +6 -10
- package/cpp/api/JsiSkRuntimeShaderBuilder.h +5 -14
- package/cpp/api/JsiSkSVG.h +4 -4
- package/cpp/api/JsiSkShaderFactory.h +153 -225
- package/cpp/api/JsiSkSkottie.h +104 -126
- package/cpp/api/JsiSkSurface.h +11 -14
- package/cpp/api/JsiSkSurfaceFactory.h +6 -7
- package/cpp/api/JsiSkTextBlobFactory.h +31 -54
- package/cpp/api/JsiSkTypeface.h +8 -12
- package/cpp/api/JsiSkTypefaceFactory.h +9 -7
- package/cpp/api/JsiSkTypefaceFontProvider.h +22 -23
- package/cpp/api/JsiSkTypefaceFontProviderFactory.h +5 -6
- package/cpp/api/JsiSkVertices.h +6 -8
- package/cpp/api/JsiSkiaContext.h +10 -11
- package/cpp/api/JsiVideo.h +31 -71
- package/cpp/jsi/JSIConverter.h +0 -31
- package/cpp/jsi/NativeObject.h +11 -6
- package/cpp/rnskia/RNDawnContext.h +18 -2
- package/cpp/rnskia/RNDawnInterop.cpp +19 -0
- package/cpp/rnskia/RNDawnUtils.h +18 -1
- package/cpp/rnskia/RNSkManager.cpp +5 -162
- package/cpp/skia/include/gpu/ganesh/GrDriverBugWorkaroundsAutogen.h +2 -0
- package/lib/commonjs/mock/index.js +0 -1
- package/lib/commonjs/mock/index.js.map +1 -1
- package/lib/commonjs/skia/types/Image/ImageFactory.d.ts +15 -6
- package/lib/commonjs/skia/types/Image/ImageFactory.js.map +1 -1
- package/lib/commonjs/skia/types/Skia.d.ts +5 -15
- package/lib/commonjs/skia/types/Skia.js.map +1 -1
- package/lib/commonjs/skia/types/index.d.ts +0 -1
- package/lib/commonjs/skia/types/index.js +0 -11
- package/lib/commonjs/skia/types/index.js.map +1 -1
- package/lib/commonjs/skia/web/JsiSkImageFactory.d.ts +2 -2
- package/lib/commonjs/skia/web/JsiSkImageFactory.js +2 -2
- package/lib/commonjs/skia/web/JsiSkImageFactory.js.map +1 -1
- package/lib/commonjs/skia/web/JsiSkia.js +1 -4
- package/lib/commonjs/skia/web/JsiSkia.js.map +1 -1
- package/lib/commonjs/views/index.d.ts +0 -1
- package/lib/commonjs/views/index.js +0 -11
- package/lib/commonjs/views/index.js.map +1 -1
- package/lib/module/mock/index.js +0 -1
- package/lib/module/mock/index.js.map +1 -1
- package/lib/module/skia/types/Image/ImageFactory.d.ts +15 -6
- package/lib/module/skia/types/Image/ImageFactory.js.map +1 -1
- package/lib/module/skia/types/Skia.d.ts +5 -15
- package/lib/module/skia/types/Skia.js.map +1 -1
- package/lib/module/skia/types/index.d.ts +0 -1
- package/lib/module/skia/types/index.js +0 -1
- package/lib/module/skia/types/index.js.map +1 -1
- package/lib/module/skia/web/JsiSkImageFactory.d.ts +2 -2
- package/lib/module/skia/web/JsiSkImageFactory.js +2 -2
- package/lib/module/skia/web/JsiSkImageFactory.js.map +1 -1
- package/lib/module/skia/web/JsiSkia.js +1 -4
- package/lib/module/skia/web/JsiSkia.js.map +1 -1
- package/lib/module/views/index.d.ts +0 -1
- package/lib/module/views/index.js +0 -1
- package/lib/module/views/index.js.map +1 -1
- package/lib/typescript/lib/commonjs/mock/index.d.ts +0 -1
- package/lib/typescript/lib/commonjs/skia/web/JsiSkImageFactory.d.ts +2 -2
- package/lib/typescript/lib/commonjs/skia/web/JsiSkia.d.ts +1 -2
- package/lib/typescript/lib/module/mock/index.d.ts +0 -2
- package/lib/typescript/lib/module/skia/Skia.web.d.ts +1 -2
- package/lib/typescript/lib/module/skia/types/index.d.ts +0 -1
- package/lib/typescript/lib/module/skia/web/JsiSkImageFactory.d.ts +2 -2
- package/lib/typescript/lib/module/skia/web/JsiSkia.d.ts +1 -2
- package/lib/typescript/lib/module/views/index.d.ts +0 -1
- package/lib/typescript/src/skia/types/Image/ImageFactory.d.ts +15 -6
- package/lib/typescript/src/skia/types/Skia.d.ts +5 -15
- package/lib/typescript/src/skia/types/index.d.ts +0 -1
- package/lib/typescript/src/skia/web/JsiSkImageFactory.d.ts +2 -2
- package/lib/typescript/src/views/index.d.ts +0 -1
- package/package.json +3 -4
- package/react-native-skia.podspec +38 -4
- package/src/mock/index.ts +0 -1
- package/src/skia/types/Image/ImageFactory.ts +15 -6
- package/src/skia/types/Skia.ts +5 -15
- package/src/skia/types/index.ts +0 -1
- package/src/skia/web/JsiSkImageFactory.ts +3 -3
- package/src/skia/web/JsiSkia.ts +2 -5
- package/src/views/index.ts +0 -1
- package/android/cpp/jni/JniWebGPUView.cpp +0 -112
- package/android/cpp/rnskia-android/SkiaPlatformContext.h +0 -26
- package/android/src/main/java/com/shopify/reactnative/skia/WebGPUSurfaceView.java +0 -43
- package/android/src/main/java/com/shopify/reactnative/skia/WebGPUTextureView.java +0 -50
- package/android/src/main/java/com/shopify/reactnative/skia/WebGPUView.java +0 -98
- package/android/src/main/java/com/shopify/reactnative/skia/WebGPUViewAPI.java +0 -19
- package/android/src/main/java/com/shopify/reactnative/skia/WebGPUViewManager.java +0 -58
- package/apple/RNWebGPUAppleNativeBuffer.mm +0 -33
- package/apple/SkiaPlatformContext.h +0 -20
- package/apple/SkiaPlatformContext.mm +0 -21
- package/apple/SkiaWebGPUView.mm +0 -81
- package/apple/WebGPUMetalView.mm +0 -136
- package/cpp/rnwgpu/ArrayBuffer.h +0 -116
- package/cpp/rnwgpu/Canvas.h +0 -52
- package/cpp/rnwgpu/PlatformContext.h +0 -18
- package/cpp/rnwgpu/SurfaceRegistry.h +0 -605
- package/cpp/rnwgpu/api/AppleNativeBuffer.h +0 -22
- package/cpp/rnwgpu/api/Convertors.h +0 -783
- package/cpp/rnwgpu/api/External.h +0 -12
- package/cpp/rnwgpu/api/GPU.cpp +0 -162
- package/cpp/rnwgpu/api/GPU.h +0 -60
- package/cpp/rnwgpu/api/GPUAdapter.cpp +0 -239
- package/cpp/rnwgpu/api/GPUAdapter.h +0 -60
- package/cpp/rnwgpu/api/GPUAdapterInfo.h +0 -57
- package/cpp/rnwgpu/api/GPUBindGroup.cpp +0 -3
- package/cpp/rnwgpu/api/GPUBindGroup.h +0 -51
- package/cpp/rnwgpu/api/GPUBindGroupLayout.h +0 -52
- package/cpp/rnwgpu/api/GPUBuffer.cpp +0 -107
- package/cpp/rnwgpu/api/GPUBuffer.h +0 -88
- package/cpp/rnwgpu/api/GPUCanvasContext.cpp +0 -75
- package/cpp/rnwgpu/api/GPUCanvasContext.h +0 -70
- package/cpp/rnwgpu/api/GPUCommandBuffer.h +0 -45
- package/cpp/rnwgpu/api/GPUCommandEncoder.cpp +0 -179
- package/cpp/rnwgpu/api/GPUCommandEncoder.h +0 -111
- package/cpp/rnwgpu/api/GPUCompilationInfo.h +0 -79
- package/cpp/rnwgpu/api/GPUCompilationMessage.h +0 -36
- package/cpp/rnwgpu/api/GPUComputePassEncoder.cpp +0 -60
- package/cpp/rnwgpu/api/GPUComputePassEncoder.h +0 -85
- package/cpp/rnwgpu/api/GPUComputePipeline.cpp +0 -12
- package/cpp/rnwgpu/api/GPUComputePipeline.h +0 -60
- package/cpp/rnwgpu/api/GPUDevice.cpp +0 -613
- package/cpp/rnwgpu/api/GPUDevice.h +0 -258
- package/cpp/rnwgpu/api/GPUDeviceLostInfo.cpp +0 -7
- package/cpp/rnwgpu/api/GPUDeviceLostInfo.h +0 -40
- package/cpp/rnwgpu/api/GPUError.h +0 -35
- package/cpp/rnwgpu/api/GPUExtent3D.h +0 -66
- package/cpp/rnwgpu/api/GPUExternalTexture.cpp +0 -139
- package/cpp/rnwgpu/api/GPUExternalTexture.h +0 -95
- package/cpp/rnwgpu/api/GPUFeatures.h +0 -203
- package/cpp/rnwgpu/api/GPUInternalError.h +0 -31
- package/cpp/rnwgpu/api/GPUOrigin2D.h +0 -55
- package/cpp/rnwgpu/api/GPUOrigin3D.h +0 -62
- package/cpp/rnwgpu/api/GPUOutOfMemoryError.h +0 -33
- package/cpp/rnwgpu/api/GPUPipelineLayout.h +0 -45
- package/cpp/rnwgpu/api/GPUQuerySet.cpp +0 -11
- package/cpp/rnwgpu/api/GPUQuerySet.h +0 -73
- package/cpp/rnwgpu/api/GPUQueue.cpp +0 -179
- package/cpp/rnwgpu/api/GPUQueue.h +0 -84
- package/cpp/rnwgpu/api/GPURenderBundle.h +0 -44
- package/cpp/rnwgpu/api/GPURenderBundleEncoder.cpp +0 -131
- package/cpp/rnwgpu/api/GPURenderBundleEncoder.h +0 -110
- package/cpp/rnwgpu/api/GPURenderPassEncoder.cpp +0 -165
- package/cpp/rnwgpu/api/GPURenderPassEncoder.h +0 -130
- package/cpp/rnwgpu/api/GPURenderPipeline.cpp +0 -13
- package/cpp/rnwgpu/api/GPURenderPipeline.h +0 -61
- package/cpp/rnwgpu/api/GPUSampler.h +0 -44
- package/cpp/rnwgpu/api/GPUShaderModule.cpp +0 -56
- package/cpp/rnwgpu/api/GPUShaderModule.h +0 -66
- package/cpp/rnwgpu/api/GPUSharedFence.cpp +0 -80
- package/cpp/rnwgpu/api/GPUSharedFence.h +0 -53
- package/cpp/rnwgpu/api/GPUSharedTextureMemory.cpp +0 -135
- package/cpp/rnwgpu/api/GPUSharedTextureMemory.h +0 -75
- package/cpp/rnwgpu/api/GPUSupportedLimits.cpp +0 -129
- package/cpp/rnwgpu/api/GPUSupportedLimits.h +0 -131
- package/cpp/rnwgpu/api/GPUTexture.cpp +0 -47
- package/cpp/rnwgpu/api/GPUTexture.h +0 -162
- package/cpp/rnwgpu/api/GPUTextureView.h +0 -44
- package/cpp/rnwgpu/api/GPUUncapturedErrorEvent.h +0 -60
- package/cpp/rnwgpu/api/GPUValidationError.h +0 -32
- package/cpp/rnwgpu/api/ImageBitmap.h +0 -62
- package/cpp/rnwgpu/api/NativeBufferUtils.h +0 -87
- package/cpp/rnwgpu/api/RNWebGPU.h +0 -82
- package/cpp/rnwgpu/api/WebGPUConstants.h +0 -36
- package/cpp/rnwgpu/api/descriptors/GPUBindGroupDescriptor.h +0 -64
- package/cpp/rnwgpu/api/descriptors/GPUBindGroupEntry.h +0 -78
- package/cpp/rnwgpu/api/descriptors/GPUBindGroupLayoutDescriptor.h +0 -56
- package/cpp/rnwgpu/api/descriptors/GPUBindGroupLayoutEntry.h +0 -97
- package/cpp/rnwgpu/api/descriptors/GPUBlendComponent.h +0 -57
- package/cpp/rnwgpu/api/descriptors/GPUBlendState.h +0 -52
- package/cpp/rnwgpu/api/descriptors/GPUBufferBinding.h +0 -56
- package/cpp/rnwgpu/api/descriptors/GPUBufferBindingLayout.h +0 -56
- package/cpp/rnwgpu/api/descriptors/GPUBufferDescriptor.h +0 -59
- package/cpp/rnwgpu/api/descriptors/GPUBufferUsage.h +0 -39
- package/cpp/rnwgpu/api/descriptors/GPUCanvasConfiguration.h +0 -76
- package/cpp/rnwgpu/api/descriptors/GPUColor.h +0 -66
- package/cpp/rnwgpu/api/descriptors/GPUColorTargetState.h +0 -58
- package/cpp/rnwgpu/api/descriptors/GPUColorWrite.h +0 -29
- package/cpp/rnwgpu/api/descriptors/GPUCommandBufferDescriptor.h +0 -45
- package/cpp/rnwgpu/api/descriptors/GPUCommandEncoderDescriptor.h +0 -45
- package/cpp/rnwgpu/api/descriptors/GPUComputePassDescriptor.h +0 -56
- package/cpp/rnwgpu/api/descriptors/GPUComputePassTimestampWrites.h +0 -58
- package/cpp/rnwgpu/api/descriptors/GPUComputePipelineDescriptor.h +0 -67
- package/cpp/rnwgpu/api/descriptors/GPUDawnTogglesDescriptor.h +0 -56
- package/cpp/rnwgpu/api/descriptors/GPUDepthStencilState.h +0 -103
- package/cpp/rnwgpu/api/descriptors/GPUDeviceDescriptor.h +0 -109
- package/cpp/rnwgpu/api/descriptors/GPUExternalTextureBindingLayout.h +0 -38
- package/cpp/rnwgpu/api/descriptors/GPUExternalTextureDescriptor.h +0 -90
- package/cpp/rnwgpu/api/descriptors/GPUFragmentState.h +0 -73
- package/cpp/rnwgpu/api/descriptors/GPUImageCopyBuffer.h +0 -62
- package/cpp/rnwgpu/api/descriptors/GPUImageCopyExternalImage.h +0 -63
- package/cpp/rnwgpu/api/descriptors/GPUImageCopyTexture.h +0 -65
- package/cpp/rnwgpu/api/descriptors/GPUImageCopyTextureTagged.h +0 -81
- package/cpp/rnwgpu/api/descriptors/GPUImageDataLayout.h +0 -54
- package/cpp/rnwgpu/api/descriptors/GPUMapMode.h +0 -22
- package/cpp/rnwgpu/api/descriptors/GPUMultisampleState.h +0 -54
- package/cpp/rnwgpu/api/descriptors/GPUPipelineLayoutDescriptor.h +0 -57
- package/cpp/rnwgpu/api/descriptors/GPUPrimitiveState.h +0 -69
- package/cpp/rnwgpu/api/descriptors/GPUProgrammableStage.h +0 -61
- package/cpp/rnwgpu/api/descriptors/GPUQuerySetDescriptor.h +0 -55
- package/cpp/rnwgpu/api/descriptors/GPUQueueDescriptor.h +0 -43
- package/cpp/rnwgpu/api/descriptors/GPURenderBundleDescriptor.h +0 -45
- package/cpp/rnwgpu/api/descriptors/GPURenderBundleEncoderDescriptor.h +0 -80
- package/cpp/rnwgpu/api/descriptors/GPURenderPassColorAttachment.h +0 -81
- package/cpp/rnwgpu/api/descriptors/GPURenderPassDepthStencilAttachment.h +0 -101
- package/cpp/rnwgpu/api/descriptors/GPURenderPassDescriptor.h +0 -92
- package/cpp/rnwgpu/api/descriptors/GPURenderPassTimestampWrites.h +0 -58
- package/cpp/rnwgpu/api/descriptors/GPURenderPipelineDescriptor.h +0 -103
- package/cpp/rnwgpu/api/descriptors/GPURequestAdapterOptions.h +0 -51
- package/cpp/rnwgpu/api/descriptors/GPUSamplerBindingLayout.h +0 -45
- package/cpp/rnwgpu/api/descriptors/GPUSamplerDescriptor.h +0 -110
- package/cpp/rnwgpu/api/descriptors/GPUShaderModuleCompilationHint.h +0 -60
- package/cpp/rnwgpu/api/descriptors/GPUShaderModuleDescriptor.h +0 -62
- package/cpp/rnwgpu/api/descriptors/GPUShaderStage.h +0 -25
- package/cpp/rnwgpu/api/descriptors/GPUSharedFenceDescriptor.h +0 -58
- package/cpp/rnwgpu/api/descriptors/GPUSharedFenceState.h +0 -51
- package/cpp/rnwgpu/api/descriptors/GPUSharedTextureMemoryDescriptor.h +0 -73
- package/cpp/rnwgpu/api/descriptors/GPUStencilFaceState.h +0 -64
- package/cpp/rnwgpu/api/descriptors/GPUStorageTextureBindingLayout.h +0 -59
- package/cpp/rnwgpu/api/descriptors/GPUTextureBindingLayout.h +0 -59
- package/cpp/rnwgpu/api/descriptors/GPUTextureDescriptor.h +0 -91
- package/cpp/rnwgpu/api/descriptors/GPUTextureUsage.h +0 -29
- package/cpp/rnwgpu/api/descriptors/GPUTextureViewDescriptor.h +0 -91
- package/cpp/rnwgpu/api/descriptors/GPUUncapturedErrorEventInit.h +0 -64
- package/cpp/rnwgpu/api/descriptors/GPUVertexAttribute.h +0 -53
- package/cpp/rnwgpu/api/descriptors/GPUVertexBufferLayout.h +0 -62
- package/cpp/rnwgpu/api/descriptors/GPUVertexState.h +0 -73
- package/cpp/rnwgpu/api/descriptors/Unions.h +0 -1969
- package/cpp/rnwgpu/async/AsyncTaskHandle.cpp +0 -213
- package/cpp/rnwgpu/async/AsyncTaskHandle.h +0 -58
- package/cpp/rnwgpu/async/RuntimeContext.cpp +0 -199
- package/cpp/rnwgpu/async/RuntimeContext.h +0 -134
- package/lib/commonjs/skia/types/WebGPU.d.ts +0 -184
- package/lib/commonjs/skia/types/WebGPU.js +0 -105
- package/lib/commonjs/skia/types/WebGPU.js.map +0 -1
- package/lib/commonjs/specs/WebGPUViewNativeComponent.d.ts +0 -8
- package/lib/commonjs/specs/WebGPUViewNativeComponent.js +0 -10
- package/lib/commonjs/specs/WebGPUViewNativeComponent.js.map +0 -1
- package/lib/commonjs/specs/WebGPUViewNativeComponent.web.d.ts +0 -8
- package/lib/commonjs/specs/WebGPUViewNativeComponent.web.js +0 -103
- package/lib/commonjs/specs/WebGPUViewNativeComponent.web.js.map +0 -1
- package/lib/commonjs/specs/utils.d.ts +0 -1
- package/lib/commonjs/specs/utils.js +0 -11
- package/lib/commonjs/specs/utils.js.map +0 -1
- package/lib/commonjs/views/WebGPUCanvas.d.ts +0 -33
- package/lib/commonjs/views/WebGPUCanvas.js +0 -79
- package/lib/commonjs/views/WebGPUCanvas.js.map +0 -1
- package/lib/commonjs/views/WebGPUCanvas.web.d.ts +0 -23
- package/lib/commonjs/views/WebGPUCanvas.web.js +0 -20
- package/lib/commonjs/views/WebGPUCanvas.web.js.map +0 -1
- package/lib/module/skia/types/WebGPU.d.ts +0 -184
- package/lib/module/skia/types/WebGPU.js +0 -99
- package/lib/module/skia/types/WebGPU.js.map +0 -1
- package/lib/module/specs/WebGPUViewNativeComponent.d.ts +0 -8
- package/lib/module/specs/WebGPUViewNativeComponent.js +0 -4
- package/lib/module/specs/WebGPUViewNativeComponent.js.map +0 -1
- package/lib/module/specs/WebGPUViewNativeComponent.web.d.ts +0 -8
- package/lib/module/specs/WebGPUViewNativeComponent.web.js +0 -96
- package/lib/module/specs/WebGPUViewNativeComponent.web.js.map +0 -1
- package/lib/module/specs/utils.d.ts +0 -1
- package/lib/module/specs/utils.js +0 -5
- package/lib/module/specs/utils.js.map +0 -1
- package/lib/module/views/WebGPUCanvas.d.ts +0 -33
- package/lib/module/views/WebGPUCanvas.js +0 -70
- package/lib/module/views/WebGPUCanvas.js.map +0 -1
- package/lib/module/views/WebGPUCanvas.web.d.ts +0 -23
- package/lib/module/views/WebGPUCanvas.web.js +0 -12
- package/lib/module/views/WebGPUCanvas.web.js.map +0 -1
- package/lib/typescript/lib/commonjs/skia/types/WebGPU.d.ts +0 -2
- package/lib/typescript/lib/commonjs/specs/WebGPUViewNativeComponent.d.ts +0 -4
- package/lib/typescript/lib/commonjs/specs/WebGPUViewNativeComponent.web.d.ts +0 -3
- package/lib/typescript/lib/commonjs/specs/utils.d.ts +0 -2
- package/lib/typescript/lib/commonjs/views/WebGPUCanvas.d.ts +0 -6
- package/lib/typescript/lib/commonjs/views/WebGPUCanvas.web.d.ts +0 -6
- package/lib/typescript/lib/module/skia/types/WebGPU.d.ts +0 -31
- package/lib/typescript/lib/module/specs/WebGPUViewNativeComponent.d.ts +0 -2
- package/lib/typescript/lib/module/specs/WebGPUViewNativeComponent.web.d.ts +0 -2
- package/lib/typescript/lib/module/specs/utils.d.ts +0 -1
- package/lib/typescript/lib/module/views/WebGPUCanvas.d.ts +0 -7
- package/lib/typescript/lib/module/views/WebGPUCanvas.web.d.ts +0 -8
- package/lib/typescript/src/skia/types/WebGPU.d.ts +0 -184
- package/lib/typescript/src/specs/WebGPUViewNativeComponent.d.ts +0 -8
- package/lib/typescript/src/specs/WebGPUViewNativeComponent.web.d.ts +0 -8
- package/lib/typescript/src/specs/utils.d.ts +0 -1
- package/lib/typescript/src/views/WebGPUCanvas.d.ts +0 -33
- package/lib/typescript/src/views/WebGPUCanvas.web.d.ts +0 -23
- package/src/skia/types/WebGPU.ts +0 -226
- package/src/specs/WebGPUViewNativeComponent.ts +0 -11
- package/src/specs/WebGPUViewNativeComponent.web.ts +0 -110
- package/src/specs/utils.ts +0 -4
- package/src/views/WebGPUCanvas.tsx +0 -125
- package/src/views/WebGPUCanvas.web.tsx +0 -36
|
@@ -1,605 +0,0 @@
|
|
|
1
|
-
#pragma once
|
|
2
|
-
|
|
3
|
-
#include <algorithm>
|
|
4
|
-
#include <functional>
|
|
5
|
-
#include <memory>
|
|
6
|
-
#include <mutex>
|
|
7
|
-
#include <shared_mutex>
|
|
8
|
-
#include <stdexcept>
|
|
9
|
-
#include <unordered_map>
|
|
10
|
-
#include <utility>
|
|
11
|
-
#include <vector>
|
|
12
|
-
|
|
13
|
-
#include "webgpu/webgpu_cpp.h"
|
|
14
|
-
|
|
15
|
-
#ifdef __APPLE__
|
|
16
|
-
#include "rnskia/RNMetalLayerColorSpace.h"
|
|
17
|
-
|
|
18
|
-
namespace dawn::native::metal {
|
|
19
|
-
void WaitForCommandsToBeScheduled(WGPUDevice device);
|
|
20
|
-
} // namespace dawn::native::metal
|
|
21
|
-
#endif
|
|
22
|
-
|
|
23
|
-
namespace rnwgpu {
|
|
24
|
-
|
|
25
|
-
struct NativeInfo {
|
|
26
|
-
void *nativeSurface;
|
|
27
|
-
int width;
|
|
28
|
-
int height;
|
|
29
|
-
};
|
|
30
|
-
|
|
31
|
-
struct Size {
|
|
32
|
-
int width;
|
|
33
|
-
int height;
|
|
34
|
-
};
|
|
35
|
-
|
|
36
|
-
// Invoked with the platform's native surface pointer once SurfaceInfo is done
|
|
37
|
-
// with it, so the platform can drop the reference it acquired on our behalf
|
|
38
|
-
// (ANativeWindow_release on Android, CFBridgingRelease of the retained
|
|
39
|
-
// CAMetalLayer on Apple platforms). May run on any thread.
|
|
40
|
-
using NativeSurfaceReleaser = std::function<void(void *)>;
|
|
41
|
-
|
|
42
|
-
// Bridges the asynchronous native surface lifecycle (surfaces appear and
|
|
43
|
-
// disappear on the platform UI thread) with the synchronous WebGPU canvas API
|
|
44
|
-
// (the JS render loop must always be able to acquire a texture).
|
|
45
|
-
//
|
|
46
|
-
// Ownership & threading model:
|
|
47
|
-
// - A registry entry is created on first use (by whichever of JS/native gets
|
|
48
|
-
// there first) and lives exactly as long as its JS Canvas: contextIds are
|
|
49
|
-
// never reused. It is removed by the native view's teardown (WebGPUMetalView
|
|
50
|
-
// dealloc / WebGPUViewManager.onDropViewInstance) when a surface is
|
|
51
|
-
// attached, or by RNWebGPU.destroyContext (the Canvas unmount cleanup) when
|
|
52
|
-
// none ever was — see RNWebGPU::destroyContext for why the split. Surface
|
|
53
|
-
// destruction alone (backgrounding, TextureView teardown) never removes an
|
|
54
|
-
// entry; it only detaches the surface.
|
|
55
|
-
// - Attaching a surface is LATCHED: the UI thread stores it as pending
|
|
56
|
-
// (attachSurface) and it is adopted at the next frame boundary — start of
|
|
57
|
-
// getCurrentTexture or end of presentFrame — on whichever thread renders
|
|
58
|
-
// (main JS, Reanimated UI, or a worklet runtime). This preserves Dawn
|
|
59
|
-
// surface thread-affinity and guarantees a surface is never swapped in the
|
|
60
|
-
// middle of a frame. For contexts that are not actively rendering, the
|
|
61
|
-
// platform view schedules applyPendingAttach on the JS thread instead (see
|
|
62
|
-
// flushPendingSurfaceTransition in WebGPUMetalView / JniWebGPUView).
|
|
63
|
-
// - Detaching (switchToOffscreen) is IMMEDIATE, because the platform destroys
|
|
64
|
-
// the surface as soon as its callback returns. A configured context falls
|
|
65
|
-
// back to rendering into an offscreen texture, so a running render loop
|
|
66
|
-
// keeps working; the in-flight frame, if any, is dropped at present(). When
|
|
67
|
-
// a new surface attaches, the latest offscreen frame is blitted onto it so
|
|
68
|
-
// content appears without waiting for the next render — the same mechanism
|
|
69
|
-
// that gives a fast time-to-first-frame when rendering starts before the
|
|
70
|
-
// native surface exists.
|
|
71
|
-
class SurfaceInfo {
|
|
72
|
-
public:
|
|
73
|
-
SurfaceInfo(wgpu::Instance gpu, int width, int height)
|
|
74
|
-
: _gpu(std::move(gpu)), _width(width), _height(height) {}
|
|
75
|
-
|
|
76
|
-
~SurfaceInfo() {
|
|
77
|
-
// Drop the Dawn objects before releasing the native surfaces they borrow.
|
|
78
|
-
_surface = nullptr;
|
|
79
|
-
_pendingSurface = nullptr;
|
|
80
|
-
_texture = nullptr;
|
|
81
|
-
if (_pendingReleaser && _pendingNativeSurface) {
|
|
82
|
-
_pendingReleaser(_pendingNativeSurface);
|
|
83
|
-
}
|
|
84
|
-
if (_releaser && _nativeSurface) {
|
|
85
|
-
_releaser(_nativeSurface);
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
// --- Platform UI thread ---------------------------------------------------
|
|
90
|
-
|
|
91
|
-
// Store a newly created on-screen surface. It becomes active at the next
|
|
92
|
-
// frame boundary (applyPendingAttach); callers should follow up with
|
|
93
|
-
// flushPendingSurfaceTransition so contexts that are not currently rendering
|
|
94
|
-
// also pick it up.
|
|
95
|
-
void attachSurface(void *nativeSurface, wgpu::Surface surface,
|
|
96
|
-
NativeSurfaceReleaser releaser) {
|
|
97
|
-
void *replacedSurface = nullptr;
|
|
98
|
-
NativeSurfaceReleaser replacedReleaser;
|
|
99
|
-
{
|
|
100
|
-
std::unique_lock<std::shared_mutex> lock(_mutex);
|
|
101
|
-
if (_hasPendingAttach) {
|
|
102
|
-
// Replaced before it was ever adopted.
|
|
103
|
-
replacedSurface = _pendingNativeSurface;
|
|
104
|
-
replacedReleaser = std::move(_pendingReleaser);
|
|
105
|
-
}
|
|
106
|
-
_hasPendingAttach = true;
|
|
107
|
-
_pendingNativeSurface = nativeSurface;
|
|
108
|
-
_pendingSurface = std::move(surface);
|
|
109
|
-
_pendingReleaser = std::move(releaser);
|
|
110
|
-
}
|
|
111
|
-
if (replacedReleaser && replacedSurface) {
|
|
112
|
-
replacedReleaser(replacedSurface);
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
// The platform surface is being destroyed: detach immediately. If the
|
|
117
|
-
// context is configured, rendering continues into an offscreen texture whose
|
|
118
|
-
// content is blitted to the next attached surface; present() no-ops until
|
|
119
|
-
// then. Safe to call when already offscreen.
|
|
120
|
-
void switchToOffscreen() { detach(/* createFallbackTexture = */ true); }
|
|
121
|
-
|
|
122
|
-
// Detach without creating the offscreen fallback: used when the context is
|
|
123
|
-
// being destroyed and nothing will consume further frames.
|
|
124
|
-
void detachSurface() { detach(/* createFallbackTexture = */ false); }
|
|
125
|
-
|
|
126
|
-
// Reflects native view layout changes. Does not resize the drawing buffer:
|
|
127
|
-
// that tracks canvas.width/height (like on the web), see
|
|
128
|
-
// GPUCanvasContext::getCurrentTexture.
|
|
129
|
-
void resize(int newWidth, int newHeight) {
|
|
130
|
-
std::unique_lock<std::shared_mutex> lock(_mutex);
|
|
131
|
-
_width = newWidth;
|
|
132
|
-
_height = newHeight;
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
// --- Frame boundary (rendering thread, or the JS thread via
|
|
136
|
-
// flushPendingSurfaceTransition) -------------------------------------------
|
|
137
|
-
|
|
138
|
-
// Adopt a pending surface if no frame is in flight: configure it and, if
|
|
139
|
-
// frames were rendered offscreen, blit the most recent one onto it and
|
|
140
|
-
// present it, so content shows up without waiting for the render loop.
|
|
141
|
-
// Safe to call from any thread; no-ops when there is nothing pending.
|
|
142
|
-
//
|
|
143
|
-
// supersedeInFlightFrame is set by the rendering thread when it starts a new
|
|
144
|
-
// frame: a previous frame that never presented is abandoned and must not
|
|
145
|
-
// block adoption. The flush path (other threads) leaves it false so it never
|
|
146
|
-
// swaps the surface under a frame that is genuinely in flight.
|
|
147
|
-
void applyPendingAttach(bool supersedeInFlightFrame = false) {
|
|
148
|
-
bool presentBlit = false;
|
|
149
|
-
uint64_t blitEpoch = 0;
|
|
150
|
-
wgpu::Device device = nullptr;
|
|
151
|
-
void *replacedSurface = nullptr;
|
|
152
|
-
NativeSurfaceReleaser replacedReleaser;
|
|
153
|
-
{
|
|
154
|
-
std::unique_lock<std::shared_mutex> lock(_mutex);
|
|
155
|
-
if (supersedeInFlightFrame) {
|
|
156
|
-
_frameInFlight = false;
|
|
157
|
-
_acquiredFromSurface = false;
|
|
158
|
-
}
|
|
159
|
-
if (!_hasPendingAttach || _frameInFlight) {
|
|
160
|
-
return;
|
|
161
|
-
}
|
|
162
|
-
// Attach over attach without a detach in between: replace. Ownership
|
|
163
|
-
// tracks the native window pointer, not the Dawn surface handle (which
|
|
164
|
-
// can be null if surface creation failed).
|
|
165
|
-
replacedSurface = _nativeSurface;
|
|
166
|
-
replacedReleaser = std::move(_releaser);
|
|
167
|
-
_surface = std::move(_pendingSurface);
|
|
168
|
-
_nativeSurface = _pendingNativeSurface;
|
|
169
|
-
_releaser = std::move(_pendingReleaser);
|
|
170
|
-
_hasPendingAttach = false;
|
|
171
|
-
_pendingNativeSurface = nullptr;
|
|
172
|
-
_frameEpoch++;
|
|
173
|
-
|
|
174
|
-
// _surface can be null here when Dawn surface creation failed for a
|
|
175
|
-
// valid native window; the context then just keeps rendering offscreen.
|
|
176
|
-
if (_config.device != nullptr && _surface) {
|
|
177
|
-
bool blit = _texture != nullptr;
|
|
178
|
-
// The blit needs CopyDst on the surface. Configure with a widened
|
|
179
|
-
// copy while keeping _config at the usage the user asked for, so any
|
|
180
|
-
// later reconfigure drops the extra flag again.
|
|
181
|
-
wgpu::SurfaceConfiguration config = _config;
|
|
182
|
-
if (blit) {
|
|
183
|
-
config.usage |= wgpu::TextureUsage::CopyDst;
|
|
184
|
-
}
|
|
185
|
-
_surface.Configure(&config);
|
|
186
|
-
#ifdef __APPLE__
|
|
187
|
-
RNSkia::applyCAMetalLayerColorSpace(_nativeSurface, _config.format);
|
|
188
|
-
#endif
|
|
189
|
-
if (blit) {
|
|
190
|
-
presentBlit = blitOffscreenToSurfaceLocked();
|
|
191
|
-
device = _config.device;
|
|
192
|
-
// Consumed either way; on failure the next frame renders fresh.
|
|
193
|
-
_texture = nullptr;
|
|
194
|
-
blitEpoch = _frameEpoch;
|
|
195
|
-
}
|
|
196
|
-
}
|
|
197
|
-
}
|
|
198
|
-
if (replacedReleaser && replacedSurface) {
|
|
199
|
-
replacedReleaser(replacedSurface);
|
|
200
|
-
}
|
|
201
|
-
if (presentBlit) {
|
|
202
|
-
#ifdef __APPLE__
|
|
203
|
-
if (device) {
|
|
204
|
-
dawn::native::metal::WaitForCommandsToBeScheduled(device.Get());
|
|
205
|
-
}
|
|
206
|
-
#endif
|
|
207
|
-
std::unique_lock<std::shared_mutex> lock(_mutex);
|
|
208
|
-
// Present only if the blitted texture is still the surface's current
|
|
209
|
-
// one. The epoch changes on any acquire, present, configure, detach, or
|
|
210
|
-
// adoption, so a frame that started - even one that already completed -
|
|
211
|
-
// or any other transition while we were unlocked skips this present
|
|
212
|
-
// (their newer content stands; presenting here would be a Dawn
|
|
213
|
-
// present-without-acquire error).
|
|
214
|
-
if (_surface && !_frameInFlight && _frameEpoch == blitEpoch) {
|
|
215
|
-
_surface.Present();
|
|
216
|
-
}
|
|
217
|
-
}
|
|
218
|
-
}
|
|
219
|
-
|
|
220
|
-
// --- Rendering thread
|
|
221
|
-
// -------------------------------------------------------
|
|
222
|
-
|
|
223
|
-
void configure(wgpu::SurfaceConfiguration &newConfig,
|
|
224
|
-
std::vector<wgpu::TextureFormat> viewFormats) {
|
|
225
|
-
applyPendingAttach(/* supersedeInFlightFrame = */ true);
|
|
226
|
-
std::unique_lock<std::shared_mutex> lock(_mutex);
|
|
227
|
-
_viewFormats = std::move(viewFormats);
|
|
228
|
-
_config = newConfig;
|
|
229
|
-
// The caller's viewFormats storage dies with the call; point the stored
|
|
230
|
-
// configuration at our own copy.
|
|
231
|
-
_config.viewFormats = _viewFormats.empty() ? nullptr : _viewFormats.data();
|
|
232
|
-
_config.viewFormatCount = _viewFormats.size();
|
|
233
|
-
// The drawing buffer starts at the canvas size. Clamp so a canvas that has
|
|
234
|
-
// not been laid out yet (0x0) configures instead of erroring.
|
|
235
|
-
_config.width = std::max(1, _width);
|
|
236
|
-
_config.height = std::max(1, _height);
|
|
237
|
-
_config.presentMode = wgpu::PresentMode::Fifo;
|
|
238
|
-
_texture = nullptr;
|
|
239
|
-
_frameEpoch++;
|
|
240
|
-
_configureLocked();
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
// Resize the drawing buffer (canvas.width/height changed).
|
|
244
|
-
void reconfigure(int newWidth, int newHeight) {
|
|
245
|
-
std::unique_lock<std::shared_mutex> lock(_mutex);
|
|
246
|
-
if (_config.device == nullptr) {
|
|
247
|
-
return;
|
|
248
|
-
}
|
|
249
|
-
_config.width = std::max(1, newWidth);
|
|
250
|
-
_config.height = std::max(1, newHeight);
|
|
251
|
-
_texture = nullptr;
|
|
252
|
-
_frameEpoch++;
|
|
253
|
-
_configureLocked();
|
|
254
|
-
}
|
|
255
|
-
|
|
256
|
-
void unconfigure() {
|
|
257
|
-
std::unique_lock<std::shared_mutex> lock(_mutex);
|
|
258
|
-
if (_surface) {
|
|
259
|
-
_surface.Unconfigure();
|
|
260
|
-
}
|
|
261
|
-
_texture = nullptr;
|
|
262
|
-
_config = {};
|
|
263
|
-
_viewFormats.clear();
|
|
264
|
-
_acquiredFromSurface = false;
|
|
265
|
-
_frameEpoch++;
|
|
266
|
-
}
|
|
267
|
-
|
|
268
|
-
bool isConfigured() {
|
|
269
|
-
std::shared_lock<std::shared_mutex> lock(_mutex);
|
|
270
|
-
return _config.device != nullptr;
|
|
271
|
-
}
|
|
272
|
-
|
|
273
|
-
// True while a native view owns a surface for this context (attached or
|
|
274
|
-
// pending adoption). Used to decide which side retires the registry entry:
|
|
275
|
-
// the native view's teardown when a surface exists, the JS Canvas cleanup
|
|
276
|
-
// otherwise (see RNWebGPU::destroyContext).
|
|
277
|
-
bool hasNativeSurface() {
|
|
278
|
-
std::shared_lock<std::shared_mutex> lock(_mutex);
|
|
279
|
-
return _nativeSurface != nullptr || _hasPendingAttach;
|
|
280
|
-
}
|
|
281
|
-
|
|
282
|
-
// Returns the texture for the current frame: the surface's swapchain texture
|
|
283
|
-
// when a surface is attached and healthy, an offscreen texture otherwise.
|
|
284
|
-
// Never returns null; throws when called before configure().
|
|
285
|
-
wgpu::Texture getCurrentTexture() {
|
|
286
|
-
// Start-of-frame boundary; a new acquire supersedes any previous frame
|
|
287
|
-
// that never presented.
|
|
288
|
-
applyPendingAttach(/* supersedeInFlightFrame = */ true);
|
|
289
|
-
std::unique_lock<std::shared_mutex> lock(_mutex);
|
|
290
|
-
if (_config.device == nullptr) {
|
|
291
|
-
throw std::runtime_error(
|
|
292
|
-
"[WebGPU] getCurrentTexture() called on a canvas context that is "
|
|
293
|
-
"not configured; call context.configure() first");
|
|
294
|
-
}
|
|
295
|
-
_frameInFlight = true;
|
|
296
|
-
_acquiredFromSurface = false;
|
|
297
|
-
_frameEpoch++;
|
|
298
|
-
if (_surface) {
|
|
299
|
-
auto texture = acquireSurfaceTextureLocked();
|
|
300
|
-
if (texture) {
|
|
301
|
-
_acquiredFromSurface = true;
|
|
302
|
-
return texture;
|
|
303
|
-
}
|
|
304
|
-
// The surface is transiently unusable (e.g. mid-resize, lost while
|
|
305
|
-
// backgrounding): fall back to an offscreen texture so the render loop
|
|
306
|
-
// survives; this frame is simply not presented.
|
|
307
|
-
}
|
|
308
|
-
if (!_texture) {
|
|
309
|
-
_texture = createOffscreenTextureLocked();
|
|
310
|
-
}
|
|
311
|
-
return _texture;
|
|
312
|
-
}
|
|
313
|
-
|
|
314
|
-
// Present the current frame. Runs synchronously on the thread that did
|
|
315
|
-
// getCurrentTexture/submit (main JS, Reanimated UI, or a worklet runtime),
|
|
316
|
-
// preserving Dawn surface thread-affinity. Frames whose texture was not
|
|
317
|
-
// acquired from the attached surface (offscreen, detached mid-frame, or
|
|
318
|
-
// acquire failure) are dropped. This is also the end-of-frame boundary: it
|
|
319
|
-
// adopts a surface that attached while the frame was in flight.
|
|
320
|
-
void presentFrame() {
|
|
321
|
-
#ifdef __APPLE__
|
|
322
|
-
// Ensure command buffers are scheduled before presenting. Read the device
|
|
323
|
-
// under a shared lock, then wait without holding it (the wait can block).
|
|
324
|
-
wgpu::Device device;
|
|
325
|
-
{
|
|
326
|
-
std::shared_lock<std::shared_mutex> lock(_mutex);
|
|
327
|
-
device = _config.device;
|
|
328
|
-
}
|
|
329
|
-
if (device) {
|
|
330
|
-
dawn::native::metal::WaitForCommandsToBeScheduled(device.Get());
|
|
331
|
-
}
|
|
332
|
-
#endif
|
|
333
|
-
{
|
|
334
|
-
std::unique_lock<std::shared_mutex> lock(_mutex);
|
|
335
|
-
if (_surface && _acquiredFromSurface) {
|
|
336
|
-
_surface.Present();
|
|
337
|
-
}
|
|
338
|
-
_acquiredFromSurface = false;
|
|
339
|
-
_frameInFlight = false;
|
|
340
|
-
_frameEpoch++;
|
|
341
|
-
}
|
|
342
|
-
applyPendingAttach();
|
|
343
|
-
}
|
|
344
|
-
|
|
345
|
-
NativeInfo getNativeInfo() {
|
|
346
|
-
std::shared_lock<std::shared_mutex> lock(_mutex);
|
|
347
|
-
// A surface that is still pending adoption is the one callers should see.
|
|
348
|
-
void *native = _hasPendingAttach ? _pendingNativeSurface : _nativeSurface;
|
|
349
|
-
return {.nativeSurface = native, .width = _width, .height = _height};
|
|
350
|
-
}
|
|
351
|
-
|
|
352
|
-
Size getSize() {
|
|
353
|
-
std::shared_lock<std::shared_mutex> lock(_mutex);
|
|
354
|
-
return {.width = _width, .height = _height};
|
|
355
|
-
}
|
|
356
|
-
|
|
357
|
-
wgpu::SurfaceConfiguration getConfig() {
|
|
358
|
-
std::shared_lock<std::shared_mutex> lock(_mutex);
|
|
359
|
-
return _config;
|
|
360
|
-
}
|
|
361
|
-
|
|
362
|
-
private:
|
|
363
|
-
void detach(bool createFallbackTexture) {
|
|
364
|
-
void *releasedSurfaces[2] = {nullptr, nullptr};
|
|
365
|
-
NativeSurfaceReleaser releasers[2];
|
|
366
|
-
{
|
|
367
|
-
std::unique_lock<std::shared_mutex> lock(_mutex);
|
|
368
|
-
// The platform is tearing surfaces down; a not-yet-adopted attach is
|
|
369
|
-
// stale, cancel it.
|
|
370
|
-
if (_hasPendingAttach) {
|
|
371
|
-
_hasPendingAttach = false;
|
|
372
|
-
_pendingSurface = nullptr;
|
|
373
|
-
releasedSurfaces[0] = _pendingNativeSurface;
|
|
374
|
-
releasers[0] = std::move(_pendingReleaser);
|
|
375
|
-
_pendingNativeSurface = nullptr;
|
|
376
|
-
}
|
|
377
|
-
if (_surface) {
|
|
378
|
-
if (createFallbackTexture && _config.device != nullptr) {
|
|
379
|
-
_texture = createOffscreenTextureLocked();
|
|
380
|
-
}
|
|
381
|
-
_surface = nullptr;
|
|
382
|
-
// The in-flight frame (if any) rendered into the destroyed surface;
|
|
383
|
-
// presentFrame() must not present it.
|
|
384
|
-
_acquiredFromSurface = false;
|
|
385
|
-
}
|
|
386
|
-
_frameEpoch++;
|
|
387
|
-
// Window ownership is independent of the Dawn surface handle (which can
|
|
388
|
-
// be null if surface creation failed): always return the window.
|
|
389
|
-
releasedSurfaces[1] = _nativeSurface;
|
|
390
|
-
releasers[1] = std::move(_releaser);
|
|
391
|
-
_nativeSurface = nullptr;
|
|
392
|
-
}
|
|
393
|
-
// Release outside the lock: the platform may do real work here.
|
|
394
|
-
for (int i = 0; i < 2; i++) {
|
|
395
|
-
if (releasers[i] && releasedSurfaces[i]) {
|
|
396
|
-
releasers[i](releasedSurfaces[i]);
|
|
397
|
-
}
|
|
398
|
-
}
|
|
399
|
-
}
|
|
400
|
-
|
|
401
|
-
// All *Locked helpers below require _mutex to be held exclusively.
|
|
402
|
-
|
|
403
|
-
wgpu::Texture createOffscreenTextureLocked() {
|
|
404
|
-
wgpu::TextureDescriptor descriptor;
|
|
405
|
-
// Union with the user's usage so offscreen frames stay compatible with
|
|
406
|
-
// whatever they configured (e.g. CopySrc readbacks). RenderAttachment |
|
|
407
|
-
// CopySrc | TextureBinding is what the fallback itself needs (rendering,
|
|
408
|
-
// the attach blit, sampling).
|
|
409
|
-
descriptor.usage = _config.usage | wgpu::TextureUsage::RenderAttachment |
|
|
410
|
-
wgpu::TextureUsage::CopySrc |
|
|
411
|
-
wgpu::TextureUsage::TextureBinding;
|
|
412
|
-
descriptor.format = _config.format;
|
|
413
|
-
descriptor.size.width = std::max(1u, _config.width);
|
|
414
|
-
descriptor.size.height = std::max(1u, _config.height);
|
|
415
|
-
descriptor.viewFormats = _config.viewFormats;
|
|
416
|
-
descriptor.viewFormatCount = _config.viewFormatCount;
|
|
417
|
-
return _config.device.CreateTexture(&descriptor);
|
|
418
|
-
}
|
|
419
|
-
|
|
420
|
-
// Acquire the surface's current texture, reconfiguring once when the surface
|
|
421
|
-
// reports it is stale (rotation, resize, coming back from background).
|
|
422
|
-
wgpu::Texture acquireSurfaceTextureLocked() {
|
|
423
|
-
wgpu::SurfaceTexture surfaceTexture;
|
|
424
|
-
_surface.GetCurrentTexture(&surfaceTexture);
|
|
425
|
-
if (!isAcquireSuccess(surfaceTexture)) {
|
|
426
|
-
if (surfaceTexture.status ==
|
|
427
|
-
wgpu::SurfaceGetCurrentTextureStatus::Error) {
|
|
428
|
-
return nullptr;
|
|
429
|
-
}
|
|
430
|
-
_surface.Configure(&_config);
|
|
431
|
-
_surface.GetCurrentTexture(&surfaceTexture);
|
|
432
|
-
if (!isAcquireSuccess(surfaceTexture)) {
|
|
433
|
-
return nullptr;
|
|
434
|
-
}
|
|
435
|
-
}
|
|
436
|
-
return surfaceTexture.texture;
|
|
437
|
-
}
|
|
438
|
-
|
|
439
|
-
static bool isAcquireSuccess(const wgpu::SurfaceTexture &surfaceTexture) {
|
|
440
|
-
return (surfaceTexture.status ==
|
|
441
|
-
wgpu::SurfaceGetCurrentTextureStatus::SuccessOptimal ||
|
|
442
|
-
surfaceTexture.status ==
|
|
443
|
-
wgpu::SurfaceGetCurrentTextureStatus::SuccessSuboptimal) &&
|
|
444
|
-
surfaceTexture.texture != nullptr;
|
|
445
|
-
}
|
|
446
|
-
|
|
447
|
-
// Copy the last offscreen frame onto the freshly attached surface. Returns
|
|
448
|
-
// true when the copy was submitted and the surface should be presented.
|
|
449
|
-
bool blitOffscreenToSurfaceLocked() {
|
|
450
|
-
wgpu::SurfaceTexture surfaceTexture;
|
|
451
|
-
_surface.GetCurrentTexture(&surfaceTexture);
|
|
452
|
-
if (!isAcquireSuccess(surfaceTexture)) {
|
|
453
|
-
return false;
|
|
454
|
-
}
|
|
455
|
-
|
|
456
|
-
wgpu::TexelCopyTextureInfo source = {};
|
|
457
|
-
source.texture = _texture;
|
|
458
|
-
wgpu::TexelCopyTextureInfo destination = {};
|
|
459
|
-
destination.texture = surfaceTexture.texture;
|
|
460
|
-
|
|
461
|
-
// The offscreen frame and the new surface can disagree on size (e.g. the
|
|
462
|
-
// device rotated while detached); copy the shared region.
|
|
463
|
-
wgpu::Extent3D size = {
|
|
464
|
-
std::min(_texture.GetWidth(), surfaceTexture.texture.GetWidth()),
|
|
465
|
-
std::min(_texture.GetHeight(), surfaceTexture.texture.GetHeight()), 1};
|
|
466
|
-
|
|
467
|
-
wgpu::CommandEncoderDescriptor encoderDescriptor;
|
|
468
|
-
wgpu::CommandEncoder encoder =
|
|
469
|
-
_config.device.CreateCommandEncoder(&encoderDescriptor);
|
|
470
|
-
encoder.CopyTextureToTexture(&source, &destination, &size);
|
|
471
|
-
wgpu::CommandBuffer commands = encoder.Finish();
|
|
472
|
-
_config.device.GetQueue().Submit(1, &commands);
|
|
473
|
-
return true;
|
|
474
|
-
}
|
|
475
|
-
|
|
476
|
-
void _configureLocked() {
|
|
477
|
-
if (_surface) {
|
|
478
|
-
_surface.Configure(&_config);
|
|
479
|
-
#ifdef __APPLE__
|
|
480
|
-
RNSkia::applyCAMetalLayerColorSpace(_nativeSurface, _config.format);
|
|
481
|
-
#endif
|
|
482
|
-
} else {
|
|
483
|
-
_texture = createOffscreenTextureLocked();
|
|
484
|
-
}
|
|
485
|
-
}
|
|
486
|
-
|
|
487
|
-
mutable std::shared_mutex _mutex;
|
|
488
|
-
// Attached on-screen surface (null while offscreen).
|
|
489
|
-
void *_nativeSurface = nullptr;
|
|
490
|
-
wgpu::Surface _surface = nullptr;
|
|
491
|
-
NativeSurfaceReleaser _releaser;
|
|
492
|
-
// Offscreen fallback drawing buffer.
|
|
493
|
-
wgpu::Texture _texture = nullptr;
|
|
494
|
-
// Surface attached by the UI thread, awaiting adoption at a frame boundary.
|
|
495
|
-
bool _hasPendingAttach = false;
|
|
496
|
-
void *_pendingNativeSurface = nullptr;
|
|
497
|
-
wgpu::Surface _pendingSurface = nullptr;
|
|
498
|
-
NativeSurfaceReleaser _pendingReleaser;
|
|
499
|
-
// Frame state: set by getCurrentTexture, cleared by presentFrame.
|
|
500
|
-
bool _frameInFlight = false;
|
|
501
|
-
bool _acquiredFromSurface = false;
|
|
502
|
-
// Bumped on every acquire, present, configure/reconfigure/unconfigure,
|
|
503
|
-
// adoption, and detach. The deferred blit-present in applyPendingAttach
|
|
504
|
-
// revalidates against it so it never presents a texture that stopped being
|
|
505
|
-
// the surface's current one while the lock was released.
|
|
506
|
-
uint64_t _frameEpoch = 0;
|
|
507
|
-
// device == nullptr means "not configured". _viewFormats owns the storage
|
|
508
|
-
// that _config.viewFormats points at.
|
|
509
|
-
wgpu::SurfaceConfiguration _config;
|
|
510
|
-
std::vector<wgpu::TextureFormat> _viewFormats;
|
|
511
|
-
// Keeps the Dawn instance alive for as long as any canvas exists.
|
|
512
|
-
wgpu::Instance _gpu;
|
|
513
|
-
// Native view size in dp (surfaced as clientWidth/clientHeight on the JS
|
|
514
|
-
// canvas).
|
|
515
|
-
int _width;
|
|
516
|
-
int _height;
|
|
517
|
-
};
|
|
518
|
-
|
|
519
|
-
class SurfaceRegistry {
|
|
520
|
-
public:
|
|
521
|
-
static SurfaceRegistry &getInstance() {
|
|
522
|
-
static SurfaceRegistry instance;
|
|
523
|
-
return instance;
|
|
524
|
-
}
|
|
525
|
-
|
|
526
|
-
SurfaceRegistry(const SurfaceRegistry &) = delete;
|
|
527
|
-
SurfaceRegistry &operator=(const SurfaceRegistry &) = delete;
|
|
528
|
-
|
|
529
|
-
std::shared_ptr<SurfaceInfo> getSurfaceInfo(int id) {
|
|
530
|
-
std::shared_lock<std::shared_mutex> lock(_mutex);
|
|
531
|
-
auto it = _registry.find(id);
|
|
532
|
-
if (it != _registry.end()) {
|
|
533
|
-
return it->second;
|
|
534
|
-
}
|
|
535
|
-
return nullptr;
|
|
536
|
-
}
|
|
537
|
-
|
|
538
|
-
void removeSurfaceInfo(int id) {
|
|
539
|
-
std::unique_lock<std::shared_mutex> lock(_mutex);
|
|
540
|
-
_registry.erase(id);
|
|
541
|
-
}
|
|
542
|
-
|
|
543
|
-
std::shared_ptr<SurfaceInfo>
|
|
544
|
-
getSurfaceInfoOrCreate(int id, wgpu::Instance gpu, int width, int height) {
|
|
545
|
-
std::unique_lock<std::shared_mutex> lock(_mutex);
|
|
546
|
-
return getSurfaceInfoOrCreateLocked(id, gpu, width, height);
|
|
547
|
-
}
|
|
548
|
-
|
|
549
|
-
// Find-or-create + attach as one atomic step under the registry lock, so it
|
|
550
|
-
// serializes with removeSurfaceInfoIfDetached: an attach can never land on
|
|
551
|
-
// an entry that a concurrent destroyContext is erasing (it either marks the
|
|
552
|
-
// entry attached before the check, or re-creates the entry after the
|
|
553
|
-
// erase). Lock order is registry -> SurfaceInfo, matching every other path.
|
|
554
|
-
std::shared_ptr<SurfaceInfo> attachSurface(int id, wgpu::Instance gpu,
|
|
555
|
-
int width, int height,
|
|
556
|
-
void *nativeSurface,
|
|
557
|
-
wgpu::Surface surface,
|
|
558
|
-
NativeSurfaceReleaser releaser) {
|
|
559
|
-
std::unique_lock<std::shared_mutex> lock(_mutex);
|
|
560
|
-
auto info = getSurfaceInfoOrCreateLocked(id, gpu, width, height);
|
|
561
|
-
info->attachSurface(nativeSurface, std::move(surface), std::move(releaser));
|
|
562
|
-
return info;
|
|
563
|
-
}
|
|
564
|
-
|
|
565
|
-
// Erase the entry only if no native surface is attached or pending; the
|
|
566
|
-
// atomic counterpart of attachSurface above (see RNWebGPU::destroyContext
|
|
567
|
-
// for the ownership split this implements).
|
|
568
|
-
void removeSurfaceInfoIfDetached(int id) {
|
|
569
|
-
std::unique_lock<std::shared_mutex> lock(_mutex);
|
|
570
|
-
auto it = _registry.find(id);
|
|
571
|
-
if (it == _registry.end() || it->second->hasNativeSurface()) {
|
|
572
|
-
return;
|
|
573
|
-
}
|
|
574
|
-
_registry.erase(it);
|
|
575
|
-
}
|
|
576
|
-
|
|
577
|
-
// Drops all entries. Called when the RN instance tears down (dev reload):
|
|
578
|
-
// JS context ids restart from scratch, so surviving entries would alias new
|
|
579
|
-
// canvases onto dead surfaces.
|
|
580
|
-
void clear() {
|
|
581
|
-
std::unique_lock<std::shared_mutex> lock(_mutex);
|
|
582
|
-
_registry.clear();
|
|
583
|
-
}
|
|
584
|
-
|
|
585
|
-
private:
|
|
586
|
-
SurfaceRegistry() = default;
|
|
587
|
-
|
|
588
|
-
std::shared_ptr<SurfaceInfo> getSurfaceInfoOrCreateLocked(int id,
|
|
589
|
-
wgpu::Instance gpu,
|
|
590
|
-
int width,
|
|
591
|
-
int height) {
|
|
592
|
-
auto it = _registry.find(id);
|
|
593
|
-
if (it != _registry.end()) {
|
|
594
|
-
return it->second;
|
|
595
|
-
}
|
|
596
|
-
auto info = std::make_shared<SurfaceInfo>(gpu, width, height);
|
|
597
|
-
_registry[id] = info;
|
|
598
|
-
return info;
|
|
599
|
-
}
|
|
600
|
-
|
|
601
|
-
mutable std::shared_mutex _mutex;
|
|
602
|
-
std::unordered_map<int, std::shared_ptr<SurfaceInfo>> _registry;
|
|
603
|
-
};
|
|
604
|
-
|
|
605
|
-
} // namespace rnwgpu
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
#pragma once
|
|
2
|
-
|
|
3
|
-
#if defined(__APPLE__)
|
|
4
|
-
|
|
5
|
-
#include <cstdint>
|
|
6
|
-
|
|
7
|
-
namespace rnwgpu {
|
|
8
|
-
|
|
9
|
-
// Extract the backing IOSurface and dimensions from a CVPixelBufferRef pointer
|
|
10
|
-
// (the value Skia's NativeBuffer.MakeFromImage returns on Apple). The returned
|
|
11
|
-
// IOSurfaceRef is owned by the CVPixelBuffer; the caller must keep the
|
|
12
|
-
// CVPixelBuffer alive while the IOSurface is in use. Returns nullptr (and
|
|
13
|
-
// leaves the out-params at 0) if the buffer has no IOSurface.
|
|
14
|
-
//
|
|
15
|
-
// Defined in apple/RNWebGPUAppleNativeBuffer.mm (Objective-C++ so it can use
|
|
16
|
-
// CoreVideo, which isn't available from the cpp/ translation units).
|
|
17
|
-
void *GetIOSurfaceFromNativeBuffer(void *cvPixelBuffer, uint32_t *outWidth,
|
|
18
|
-
uint32_t *outHeight);
|
|
19
|
-
|
|
20
|
-
} // namespace rnwgpu
|
|
21
|
-
|
|
22
|
-
#endif // __APPLE__
|