@shopify/react-native-skia 2.6.2 → 2.6.3-next.2

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.
Files changed (346) hide show
  1. package/android/CMakeLists.txt +8 -4
  2. package/android/build.gradle +22 -3
  3. package/android/cpp/rnskia-android/RNSkAndroidPlatformContext.h +62 -0
  4. package/android/src/paper/java/com/facebook/react/viewmanagers/SkiaWebGPUViewManagerDelegate.java +35 -0
  5. package/android/src/paper/java/com/facebook/react/viewmanagers/SkiaWebGPUViewManagerInterface.java +17 -0
  6. package/apple/RNSkApplePlatformContext.h +2 -0
  7. package/apple/RNSkApplePlatformContext.mm +71 -0
  8. package/apple/RNWebGPUAppleNativeBuffer.mm +33 -0
  9. package/cpp/api/JsiNativeBuffer.h +9 -1
  10. package/cpp/api/JsiSkAnimatedImage.h +1 -1
  11. package/cpp/api/JsiSkAnimatedImageFactory.h +1 -1
  12. package/cpp/api/JsiSkApi.h +3 -3
  13. package/cpp/api/JsiSkCanvas.h +34 -1
  14. package/cpp/api/JsiSkColor.h +1 -1
  15. package/cpp/api/JsiSkDataFactory.h +2 -2
  16. package/cpp/api/JsiSkFont.h +1 -1
  17. package/cpp/api/JsiSkFontMgr.h +1 -1
  18. package/cpp/api/JsiSkHostObjects.h +3 -3
  19. package/cpp/api/JsiSkImage.h +15 -7
  20. package/cpp/api/JsiSkImageFactory.h +2 -2
  21. package/cpp/api/JsiSkPath.h +1 -1
  22. package/cpp/api/JsiSkPathFactory.h +1 -1
  23. package/cpp/api/JsiSkSkottie.h +1 -1
  24. package/cpp/api/JsiSkSurface.h +18 -6
  25. package/cpp/api/JsiSkTypeface.h +1 -1
  26. package/cpp/api/JsiSkTypefaceFontProvider.h +1 -1
  27. package/cpp/api/JsiSkiaContext.h +2 -2
  28. package/cpp/api/JsiTextureInfo.h +1 -1
  29. package/cpp/api/JsiVideo.h +2 -2
  30. package/cpp/api/recorder/Convertor.h +1 -1
  31. package/cpp/api/recorder/Drawings.h +1 -1
  32. package/cpp/api/recorder/JsiRecorder.h +4 -4
  33. package/cpp/api/recorder/RNRecorder.h +1 -1
  34. package/cpp/api/third_party/SkottieUtils.cpp +1 -1
  35. package/cpp/api/third_party/base64.cpp +1 -1
  36. package/cpp/jsi/JsiHostObject.cpp +5 -7
  37. package/cpp/jsi/JsiPromises.h +1 -1
  38. package/cpp/jsi/ViewProperty.h +1 -1
  39. package/cpp/rnskia/RNDawnContext.h +13 -0
  40. package/cpp/rnskia/RNDawnUtils.h +11 -1
  41. package/cpp/rnskia/RNSkJsiViewApi.h +2 -2
  42. package/cpp/rnskia/RNSkManager.cpp +88 -2
  43. package/cpp/rnskia/RNSkPictureView.h +4 -4
  44. package/cpp/rnskia/RNSkPlatformContext.h +7 -0
  45. package/cpp/rnskia/RNSkView.h +9 -6
  46. package/cpp/rnwgpu/ArrayBuffer.h +51 -7
  47. package/cpp/rnwgpu/api/AppleNativeBuffer.h +22 -0
  48. package/cpp/rnwgpu/api/Convertors.h +33 -11
  49. package/cpp/rnwgpu/api/GPU.cpp +0 -3
  50. package/cpp/rnwgpu/api/GPUAdapter.cpp +37 -7
  51. package/cpp/rnwgpu/api/GPUBuffer.h +1 -1
  52. package/cpp/rnwgpu/api/GPUDevice.cpp +84 -6
  53. package/cpp/rnwgpu/api/GPUDevice.h +12 -0
  54. package/cpp/rnwgpu/api/GPUExternalTexture.cpp +139 -0
  55. package/cpp/rnwgpu/api/GPUExternalTexture.h +52 -2
  56. package/cpp/rnwgpu/api/GPUQueue.cpp +50 -45
  57. package/cpp/rnwgpu/api/GPUShaderModule.cpp +1 -1
  58. package/cpp/rnwgpu/api/GPUSharedFence.cpp +80 -0
  59. package/cpp/rnwgpu/api/GPUSharedFence.h +53 -0
  60. package/cpp/rnwgpu/api/GPUSharedTextureMemory.cpp +135 -0
  61. package/cpp/rnwgpu/api/GPUSharedTextureMemory.h +75 -0
  62. package/cpp/rnwgpu/api/ImageBitmap.h +62 -0
  63. package/cpp/rnwgpu/api/NativeBufferUtils.h +87 -0
  64. package/cpp/rnwgpu/api/descriptors/GPUBindGroupEntry.h +4 -1
  65. package/cpp/rnwgpu/api/descriptors/GPUCanvasConfiguration.h +1 -1
  66. package/cpp/rnwgpu/api/descriptors/GPUDawnTogglesDescriptor.h +56 -0
  67. package/cpp/rnwgpu/api/descriptors/GPUDeviceDescriptor.h +10 -0
  68. package/cpp/rnwgpu/api/descriptors/GPUExternalTextureDescriptor.h +43 -24
  69. package/cpp/rnwgpu/api/descriptors/GPUImageCopyExternalImage.h +9 -9
  70. package/cpp/rnwgpu/api/descriptors/GPUImageCopyTexture.h +1 -1
  71. package/cpp/rnwgpu/api/descriptors/GPUImageCopyTextureTagged.h +2 -2
  72. package/cpp/rnwgpu/api/descriptors/GPUSharedFenceDescriptor.h +58 -0
  73. package/cpp/rnwgpu/api/descriptors/GPUSharedFenceState.h +51 -0
  74. package/cpp/rnwgpu/api/descriptors/GPUSharedTextureMemoryDescriptor.h +73 -0
  75. package/cpp/rnwgpu/api/descriptors/GPUTextureDescriptor.h +1 -1
  76. package/cpp/rnwgpu/api/descriptors/GPUUncapturedErrorEventInit.h +1 -1
  77. package/cpp/skia/include/android/GrAHardwareBufferUtils.h +1 -1
  78. package/cpp/skia/include/android/SkAndroidFrameworkUtils.h +1 -1
  79. package/cpp/skia/include/android/SkAnimatedImage.h +1 -1
  80. package/cpp/skia/include/codec/SkCodec.h +0 -8
  81. package/cpp/skia/include/codec/SkEncodedOrigin.h +1 -1
  82. package/cpp/skia/include/codec/SkPngRustDecoder.h +1 -1
  83. package/cpp/skia/include/core/SkBitmap.h +2 -8
  84. package/cpp/skia/include/core/SkCPURecorder.h +3 -1
  85. package/cpp/skia/include/core/SkCanvasVirtualEnforcer.h +1 -1
  86. package/cpp/skia/include/core/SkColorType.h +5 -3
  87. package/cpp/skia/include/core/SkContourMeasure.h +1 -1
  88. package/cpp/skia/include/core/SkCoverageMode.h +1 -1
  89. package/cpp/skia/include/core/SkCubicMap.h +1 -1
  90. package/cpp/skia/include/core/SkExecutor.h +1 -1
  91. package/cpp/skia/include/core/SkFont.h +15 -0
  92. package/cpp/skia/include/core/SkFontArguments.h +6 -1
  93. package/cpp/skia/include/core/SkFontMetrics.h +1 -1
  94. package/cpp/skia/include/core/SkFontMgr.h +36 -1
  95. package/cpp/skia/include/core/SkFontParameters.h +1 -1
  96. package/cpp/skia/include/core/SkFontScanner.h +1 -1
  97. package/cpp/skia/include/core/SkFontTypes.h +1 -1
  98. package/cpp/skia/include/core/SkM44.h +1 -1
  99. package/cpp/skia/include/core/SkMilestone.h +1 -1
  100. package/cpp/skia/include/core/SkOpenTypeSVGDecoder.h +1 -1
  101. package/cpp/skia/include/core/SkPathBuilder.h +10 -4
  102. package/cpp/skia/include/core/SkPathIter.h +1 -1
  103. package/cpp/skia/include/core/SkPathTypes.h +1 -1
  104. package/cpp/skia/include/core/SkPixelRef.h +4 -1
  105. package/cpp/skia/include/core/SkRecorder.h +2 -1
  106. package/cpp/skia/include/core/SkRegion.h +17 -6
  107. package/cpp/skia/include/core/SkSamplingOptions.h +1 -1
  108. package/cpp/skia/include/core/SkSerialProcs.h +8 -1
  109. package/cpp/skia/include/core/SkShader.h +3 -5
  110. package/cpp/skia/include/core/SkSpan.h +1 -1
  111. package/cpp/skia/include/core/SkStream.h +1 -1
  112. package/cpp/skia/include/core/SkStrikeRef.h +80 -0
  113. package/cpp/skia/include/core/SkTileMode.h +1 -1
  114. package/cpp/skia/include/core/SkVertices.h +1 -1
  115. package/cpp/skia/include/core/SkYUVAPixmaps.h +3 -5
  116. package/cpp/skia/include/docs/SkPDFDocument.h +1 -1
  117. package/cpp/skia/include/docs/SkXPSDocument.h +1 -1
  118. package/cpp/skia/include/effects/SkGradient.h +1 -1
  119. package/cpp/skia/include/effects/SkHighContrastFilter.h +1 -1
  120. package/cpp/skia/include/effects/SkRuntimeEffect.h +2 -2
  121. package/cpp/skia/include/effects/SkShaderMaskFilter.h +1 -1
  122. package/cpp/skia/include/effects/SkTrimPathEffect.h +1 -1
  123. package/cpp/skia/include/encode/SkEncoder.h +1 -1
  124. package/cpp/skia/include/encode/SkJpegEncoder.h +1 -1
  125. package/cpp/skia/include/encode/SkPngEncoder.h +1 -1
  126. package/cpp/skia/include/encode/SkPngRustEncoder.h +1 -1
  127. package/cpp/skia/include/encode/SkWebpEncoder.h +1 -1
  128. package/cpp/skia/include/gpu/GpuTypes.h +2 -0
  129. package/cpp/skia/include/gpu/MutableTextureState.h +1 -1
  130. package/cpp/skia/include/gpu/ganesh/GrBackendSemaphore.h +1 -1
  131. package/cpp/skia/include/gpu/ganesh/GrBackendSurface.h +6 -62
  132. package/cpp/skia/include/gpu/ganesh/GrContextThreadSafeProxy.h +1 -1
  133. package/cpp/skia/include/gpu/ganesh/GrDirectContext.h +1 -1
  134. package/cpp/skia/include/gpu/ganesh/GrDriverBugWorkarounds.h +1 -1
  135. package/cpp/skia/include/gpu/ganesh/GrRecordingContext.h +2 -1
  136. package/cpp/skia/include/gpu/ganesh/mock/GrMockBackendSurface.h +59 -0
  137. package/cpp/skia/include/gpu/ganesh/mock/GrMockTypes.h +1 -1
  138. package/cpp/skia/include/gpu/ganesh/mtl/GrMtlBackendContext.h +1 -1
  139. package/cpp/skia/include/gpu/ganesh/mtl/GrMtlTypes.h +1 -1
  140. package/cpp/skia/include/gpu/ganesh/vk/GrBackendDrawableInfo.h +1 -1
  141. package/cpp/skia/include/gpu/graphite/Context.h +12 -5
  142. package/cpp/skia/include/gpu/graphite/GraphiteTypes.h +6 -0
  143. package/cpp/skia/include/gpu/graphite/Image.h +82 -9
  144. package/cpp/skia/include/gpu/graphite/PrecompileContext.h +7 -2
  145. package/cpp/skia/include/gpu/graphite/Recorder.h +6 -4
  146. package/cpp/skia/include/gpu/graphite/precompile/PrecompileColorFilter.h +11 -1
  147. package/cpp/skia/include/gpu/graphite/precompile/PrecompileShader.h +1 -0
  148. package/cpp/skia/include/gpu/graphite/vk/VulkanGraphiteTypes.h +1 -1
  149. package/cpp/skia/include/gpu/mtl/MtlMemoryAllocator.h +1 -1
  150. package/cpp/skia/include/gpu/vk/VulkanExtensions.h +1 -1
  151. package/cpp/skia/include/gpu/vk/VulkanMemoryAllocator.h +1 -1
  152. package/cpp/skia/include/gpu/vk/VulkanTypes.h +1 -1
  153. package/cpp/skia/include/ports/SkCFObject.h +1 -1
  154. package/cpp/skia/include/ports/SkFontMgr_Fontations.h +1 -1
  155. package/cpp/skia/include/ports/SkFontMgr_android_ndk.h +1 -1
  156. package/cpp/skia/include/ports/SkFontMgr_data.h +1 -1
  157. package/cpp/skia/include/ports/SkFontMgr_fuchsia.h +1 -1
  158. package/cpp/skia/include/ports/SkFontMgr_mac_ct.h +1 -1
  159. package/cpp/skia/include/ports/SkFontScanner_Fontations.h +1 -1
  160. package/cpp/skia/include/ports/SkFontScanner_FreeType.h +1 -1
  161. package/cpp/skia/include/ports/SkTypeface_fontations.h +1 -1
  162. package/cpp/skia/include/private/SkExif.h +1 -1
  163. package/cpp/skia/include/private/SkGainmapInfo.h +1 -1
  164. package/cpp/skia/include/private/SkGainmapShader.h +1 -1
  165. package/cpp/skia/include/private/SkHdrMetadata.h +21 -0
  166. package/cpp/skia/include/private/SkJpegGainmapEncoder.h +1 -1
  167. package/cpp/skia/include/private/SkPixelStorage.h +37 -0
  168. package/cpp/skia/include/private/SkXmp.h +1 -1
  169. package/cpp/skia/include/private/base/SkAssert.h +6 -5
  170. package/cpp/skia/include/private/base/SkContainers.h +1 -1
  171. package/cpp/skia/include/private/base/SkFeatures.h +30 -30
  172. package/cpp/skia/include/private/base/SkLog.h +1 -7
  173. package/cpp/skia/include/private/base/SkLogPriority.h +4 -5
  174. package/cpp/skia/include/private/base/SkMacros.h +1 -1
  175. package/cpp/skia/include/private/base/SkMalloc.h +1 -1
  176. package/cpp/skia/include/private/base/SkSafe32.h +1 -1
  177. package/cpp/skia/include/private/base/SkSpan_impl.h +1 -1
  178. package/cpp/skia/include/private/base/SkTDArray.h +13 -1
  179. package/cpp/skia/include/private/base/SkTPin.h +1 -1
  180. package/cpp/skia/include/private/base/SkTo.h +1 -1
  181. package/cpp/skia/include/private/chromium/GrVkSecondaryCBDrawContext.h +1 -1
  182. package/cpp/skia/include/private/chromium/SkChromeRemoteGlyphCache.h +1 -1
  183. package/cpp/skia/include/private/chromium/SkCodecsICCProfileChromium.h +52 -0
  184. package/cpp/skia/include/private/chromium/SkExifChromium.h +26 -0
  185. package/cpp/skia/include/private/gpu/ganesh/GrContext_Base.h +1 -1
  186. package/cpp/skia/include/private/gpu/ganesh/GrImageContext.h +1 -1
  187. package/cpp/skia/include/private/gpu/ganesh/GrTypesPriv.h +2 -1
  188. package/cpp/skia/include/private/gpu/vk/SkiaVulkan.h +1 -1
  189. package/cpp/skia/include/sksl/SkSLDebugTrace.h +1 -1
  190. package/cpp/skia/include/third_party/vulkan/vulkan/vk_icd.h +41 -51
  191. package/cpp/skia/include/third_party/vulkan/vulkan/vk_layer.h +42 -53
  192. package/cpp/skia/include/third_party/vulkan/vulkan/vk_platform.h +2 -1
  193. package/cpp/skia/include/third_party/vulkan/vulkan/vk_video/vulkan_video_codec_av1std.h +158 -154
  194. package/cpp/skia/include/third_party/vulkan/vulkan/vk_video/vulkan_video_codec_av1std_decode.h +68 -65
  195. package/cpp/skia/include/third_party/vulkan/vulkan/vk_video/vulkan_video_codec_av1std_encode.h +90 -87
  196. package/cpp/skia/include/third_party/vulkan/vulkan/vk_video/vulkan_video_codec_h264std.h +9 -9
  197. package/cpp/skia/include/third_party/vulkan/vulkan/vk_video/vulkan_video_codec_h264std_decode.h +2 -2
  198. package/cpp/skia/include/third_party/vulkan/vulkan/vk_video/vulkan_video_codec_h264std_encode.h +82 -79
  199. package/cpp/skia/include/third_party/vulkan/vulkan/vk_video/vulkan_video_codec_h265std.h +24 -24
  200. package/cpp/skia/include/third_party/vulkan/vulkan/vk_video/vulkan_video_codec_h265std_decode.h +2 -2
  201. package/cpp/skia/include/third_party/vulkan/vulkan/vk_video/vulkan_video_codec_h265std_encode.h +95 -96
  202. package/cpp/skia/include/third_party/vulkan/vulkan/vk_video/vulkan_video_codec_vp9std.h +151 -0
  203. package/cpp/skia/include/third_party/vulkan/vulkan/vk_video/vulkan_video_codec_vp9std_decode.h +68 -0
  204. package/cpp/skia/include/third_party/vulkan/vulkan/vk_video/vulkan_video_codecs_common.h +1 -1
  205. package/cpp/skia/include/third_party/vulkan/vulkan/vulkan.h +5 -1
  206. package/cpp/skia/include/third_party/vulkan/vulkan/vulkan_android.h +7 -1
  207. package/cpp/skia/include/third_party/vulkan/vulkan/vulkan_beta.h +291 -158
  208. package/cpp/skia/include/third_party/vulkan/vulkan/vulkan_core.h +13174 -10113
  209. package/cpp/skia/include/third_party/vulkan/vulkan/vulkan_directfb.h +23 -19
  210. package/cpp/skia/include/third_party/vulkan/vulkan/vulkan_fuchsia.h +159 -165
  211. package/cpp/skia/include/third_party/vulkan/vulkan/vulkan_ggp.h +22 -19
  212. package/cpp/skia/include/third_party/vulkan/vulkan/vulkan_ios.h +3 -1
  213. package/cpp/skia/include/third_party/vulkan/vulkan/vulkan_macos.h +3 -1
  214. package/cpp/skia/include/third_party/vulkan/vulkan/vulkan_metal.h +94 -88
  215. package/cpp/skia/include/third_party/vulkan/vulkan/vulkan_ohos.h +120 -0
  216. package/cpp/skia/include/third_party/vulkan/vulkan/vulkan_screen.h +55 -51
  217. package/cpp/skia/include/third_party/vulkan/vulkan/vulkan_vi.h +18 -15
  218. package/cpp/skia/include/third_party/vulkan/vulkan/vulkan_wayland.h +23 -19
  219. package/cpp/skia/include/third_party/vulkan/vulkan/vulkan_win32.h +31 -1
  220. package/cpp/skia/include/third_party/vulkan/vulkan/vulkan_xcb.h +5 -1
  221. package/cpp/skia/include/third_party/vulkan/vulkan/vulkan_xlib.h +27 -27
  222. package/cpp/skia/include/third_party/vulkan/vulkan/vulkan_xlib_xrandr.h +20 -16
  223. package/cpp/skia/include/utils/SkEventTracer.h +6 -1
  224. package/cpp/skia/include/utils/SkOrderedFontMgr.h +1 -1
  225. package/cpp/skia/include/utils/SkShadowUtils.h +1 -1
  226. package/cpp/skia/include/utils/SkTextUtils.h +1 -1
  227. package/cpp/skia/modules/jsonreader/SkJSONReader.cpp +20 -4
  228. package/cpp/skia/modules/skcms/src/Transform_inl.h +11 -15
  229. package/cpp/skia/modules/skcms/src/skcms_public.h +2 -0
  230. package/cpp/skia/modules/skottie/include/ExternalLayer.h +1 -1
  231. package/cpp/skia/modules/skottie/include/Skottie.h +1 -1
  232. package/cpp/skia/modules/skottie/include/SkottieProperty.h +1 -1
  233. package/cpp/skia/modules/skottie/include/SlotManager.h +1 -1
  234. package/cpp/skia/modules/skottie/include/TextShaper.h +1 -1
  235. package/cpp/skia/modules/skottie/src/SkottieValue.h +1 -1
  236. package/cpp/skia/modules/skottie/src/animator/Animator.h +1 -1
  237. package/cpp/skia/modules/skottie/src/text/Font.h +1 -1
  238. package/cpp/skia/modules/skottie/src/text/TextAdapter.h +1 -1
  239. package/cpp/skia/modules/skottie/src/text/TextAnimator.h +3 -2
  240. package/cpp/skia/modules/skottie/src/text/TextValue.h +1 -1
  241. package/cpp/skia/modules/skparagraph/include/DartTypes.h +1 -1
  242. package/cpp/skia/modules/skparagraph/include/FontArguments.h +1 -1
  243. package/cpp/skia/modules/skparagraph/include/FontCollection.h +5 -1
  244. package/cpp/skia/modules/skparagraph/include/Metrics.h +1 -1
  245. package/cpp/skia/modules/skparagraph/include/Paragraph.h +1 -1
  246. package/cpp/skia/modules/skparagraph/include/ParagraphBuilder.h +1 -1
  247. package/cpp/skia/modules/skparagraph/include/ParagraphCache.h +1 -1
  248. package/cpp/skia/modules/skparagraph/include/ParagraphPainter.h +1 -1
  249. package/cpp/skia/modules/skparagraph/include/ParagraphStyle.h +12 -5
  250. package/cpp/skia/modules/skparagraph/include/TextShadow.h +1 -1
  251. package/cpp/skia/modules/skparagraph/include/TextStyle.h +1 -1
  252. package/cpp/skia/modules/skparagraph/include/TypefaceFontProvider.h +1 -1
  253. package/cpp/skia/modules/sksg/include/SkSGClipEffect.h +1 -1
  254. package/cpp/skia/modules/sksg/include/SkSGColorFilter.h +1 -1
  255. package/cpp/skia/modules/sksg/include/SkSGDraw.h +1 -1
  256. package/cpp/skia/modules/sksg/include/SkSGEffectNode.h +1 -1
  257. package/cpp/skia/modules/sksg/include/SkSGGeometryEffect.h +1 -1
  258. package/cpp/skia/modules/sksg/include/SkSGGeometryNode.h +1 -1
  259. package/cpp/skia/modules/sksg/include/SkSGGradient.h +1 -1
  260. package/cpp/skia/modules/sksg/include/SkSGGroup.h +1 -1
  261. package/cpp/skia/modules/sksg/include/SkSGImage.h +1 -1
  262. package/cpp/skia/modules/sksg/include/SkSGInvalidationController.h +1 -1
  263. package/cpp/skia/modules/sksg/include/SkSGMaskEffect.h +1 -1
  264. package/cpp/skia/modules/sksg/include/SkSGMerge.h +1 -1
  265. package/cpp/skia/modules/sksg/include/SkSGNode.h +1 -1
  266. package/cpp/skia/modules/sksg/include/SkSGOpacityEffect.h +1 -1
  267. package/cpp/skia/modules/sksg/include/SkSGPaint.h +1 -1
  268. package/cpp/skia/modules/sksg/include/SkSGPath.h +1 -1
  269. package/cpp/skia/modules/sksg/include/SkSGPlane.h +1 -1
  270. package/cpp/skia/modules/sksg/include/SkSGRect.h +1 -1
  271. package/cpp/skia/modules/sksg/include/SkSGRenderEffect.h +1 -1
  272. package/cpp/skia/modules/sksg/include/SkSGRenderNode.h +1 -1
  273. package/cpp/skia/modules/sksg/include/SkSGScene.h +1 -1
  274. package/cpp/skia/modules/sksg/include/SkSGText.h +1 -1
  275. package/cpp/skia/modules/sksg/include/SkSGTransform.h +1 -1
  276. package/cpp/skia/modules/skshaper/include/SkShaper_coretext.h +8 -1
  277. package/cpp/skia/modules/svg/include/SkSVGFe.h +1 -1
  278. package/cpp/skia/modules/svg/include/SkSVGFeBlend.h +1 -1
  279. package/cpp/skia/modules/svg/include/SkSVGFeColorMatrix.h +1 -1
  280. package/cpp/skia/modules/svg/include/SkSVGFeComponentTransfer.h +1 -1
  281. package/cpp/skia/modules/svg/include/SkSVGFeComposite.h +1 -1
  282. package/cpp/skia/modules/svg/include/SkSVGFeDisplacementMap.h +1 -1
  283. package/cpp/skia/modules/svg/include/SkSVGFeFlood.h +1 -1
  284. package/cpp/skia/modules/svg/include/SkSVGFeGaussianBlur.h +1 -1
  285. package/cpp/skia/modules/svg/include/SkSVGFeImage.h +1 -1
  286. package/cpp/skia/modules/svg/include/SkSVGFeLightSource.h +1 -1
  287. package/cpp/skia/modules/svg/include/SkSVGFeLighting.h +1 -1
  288. package/cpp/skia/modules/svg/include/SkSVGFeMerge.h +1 -1
  289. package/cpp/skia/modules/svg/include/SkSVGFeMorphology.h +1 -1
  290. package/cpp/skia/modules/svg/include/SkSVGFeOffset.h +1 -1
  291. package/cpp/skia/modules/svg/include/SkSVGFeTurbulence.h +1 -1
  292. package/cpp/skia/modules/svg/include/SkSVGFilter.h +1 -1
  293. package/cpp/skia/modules/svg/include/SkSVGFilterContext.h +1 -1
  294. package/cpp/skia/modules/svg/include/SkSVGGradient.h +1 -1
  295. package/cpp/skia/modules/svg/include/SkSVGImage.h +1 -1
  296. package/cpp/skia/modules/svg/include/SkSVGMask.h +1 -1
  297. package/cpp/skia/modules/svg/include/SkSVGOpenTypeSVGDecoder.h +1 -1
  298. package/cpp/skia/modules/svg/include/SkSVGPattern.h +1 -1
  299. package/cpp/skia/modules/svg/include/SkSVGRadialGradient.h +1 -1
  300. package/cpp/skia/modules/svg/include/SkSVGText.h +1 -1
  301. package/cpp/skia/modules/svg/include/SkSVGUse.h +1 -1
  302. package/cpp/skia/src/base/SkAutoLocaleSetter.h +94 -0
  303. package/cpp/skia/src/base/SkUTF.h +1 -1
  304. package/lib/commonjs/skia/types/NativeBuffer/NativeBufferFactory.d.ts +10 -1
  305. package/lib/commonjs/skia/types/NativeBuffer/NativeBufferFactory.js.map +1 -1
  306. package/lib/commonjs/skia/types/WebGPU.d.ts +153 -0
  307. package/lib/commonjs/skia/types/WebGPU.js +6 -0
  308. package/lib/commonjs/skia/types/WebGPU.js.map +1 -0
  309. package/lib/commonjs/skia/types/index.d.ts +1 -0
  310. package/lib/commonjs/skia/types/index.js +11 -0
  311. package/lib/commonjs/skia/types/index.js.map +1 -1
  312. package/lib/commonjs/skia/web/JsiSkNativeBufferFactory.d.ts +1 -0
  313. package/lib/commonjs/skia/web/JsiSkNativeBufferFactory.js +19 -0
  314. package/lib/commonjs/skia/web/JsiSkNativeBufferFactory.js.map +1 -1
  315. package/lib/commonjs/skia/web/JsiSkPath.js.map +1 -1
  316. package/lib/module/skia/types/NativeBuffer/NativeBufferFactory.d.ts +10 -1
  317. package/lib/module/skia/types/NativeBuffer/NativeBufferFactory.js.map +1 -1
  318. package/lib/module/skia/types/WebGPU.d.ts +153 -0
  319. package/lib/module/skia/types/WebGPU.js +2 -0
  320. package/lib/module/skia/types/WebGPU.js.map +1 -0
  321. package/lib/module/skia/types/index.d.ts +1 -0
  322. package/lib/module/skia/types/index.js +1 -0
  323. package/lib/module/skia/types/index.js.map +1 -1
  324. package/lib/module/skia/web/JsiSkNativeBufferFactory.d.ts +1 -0
  325. package/lib/module/skia/web/JsiSkNativeBufferFactory.js +19 -0
  326. package/lib/module/skia/web/JsiSkNativeBufferFactory.js.map +1 -1
  327. package/lib/module/skia/web/JsiSkPath.js.map +1 -1
  328. package/lib/module/web/LoadSkiaWeb.js +1 -2
  329. package/lib/module/web/LoadSkiaWeb.js.map +1 -1
  330. package/lib/typescript/lib/commonjs/skia/types/WebGPU.d.ts +1 -0
  331. package/lib/typescript/lib/commonjs/skia/web/JsiSkNativeBufferFactory.d.ts +1 -0
  332. package/lib/typescript/lib/module/skia/types/WebGPU.d.ts +1 -0
  333. package/lib/typescript/lib/module/skia/types/index.d.ts +1 -0
  334. package/lib/typescript/lib/module/skia/web/JsiSkNativeBufferFactory.d.ts +1 -0
  335. package/lib/typescript/src/skia/types/NativeBuffer/NativeBufferFactory.d.ts +10 -1
  336. package/lib/typescript/src/skia/types/WebGPU.d.ts +153 -0
  337. package/lib/typescript/src/skia/types/index.d.ts +1 -0
  338. package/lib/typescript/src/skia/web/JsiSkNativeBufferFactory.d.ts +1 -0
  339. package/package.json +18 -15
  340. package/react-native-skia.podspec +59 -7
  341. package/src/skia/types/NativeBuffer/NativeBufferFactory.ts +10 -1
  342. package/src/skia/types/WebGPU.ts +186 -0
  343. package/src/skia/types/index.ts +1 -0
  344. package/src/skia/web/JsiSkNativeBufferFactory.ts +20 -0
  345. package/src/skia/web/JsiSkPath.ts +8 -2
  346. package/scripts/install-libs.js +0 -133
@@ -136,9 +136,6 @@ std::unordered_set<std::string> GPU::getWgslLanguageFeatures() {
136
136
  case wgpu::WGSLLanguageFeatureName::BufferView:
137
137
  name = "buffer_view";
138
138
  break;
139
- case wgpu::WGSLLanguageFeatureName::FilteringParameters:
140
- name = "filtering_parameters";
141
- break;
142
139
  case wgpu::WGSLLanguageFeatureName::SwizzleAssignment:
143
140
  name = "swizzle_assignment";
144
141
  break;
@@ -109,13 +109,39 @@ async::AsyncTaskHandle GPUAdapter::requestDevice(
109
109
  deviceLostBinding,
110
110
  creationRuntime](const async::AsyncTaskHandle::ResolveFunction &resolve,
111
111
  const async::AsyncTaskHandle::RejectFunction &reject) {
112
- (void)descriptor;
112
+ // Build a local mutable copy so we can chain Dawn's device toggles.
113
+ // The toggle name strings are owned by `descriptor` (captured above),
114
+ // and the const char* / DawnTogglesDescriptor locals live for the
115
+ // whole synchronous RequestDevice call below, which is when Dawn reads
116
+ // the chained struct.
117
+ wgpu::DeviceDescriptor deviceDesc = aDescriptor;
118
+ wgpu::DawnTogglesDescriptor toggles{};
119
+ std::vector<const char *> enabledToggles;
120
+ std::vector<const char *> disabledToggles;
121
+ if (descriptor.has_value() && descriptor.value()->dawnToggles) {
122
+ const auto &dawnToggles = descriptor.value()->dawnToggles.value();
123
+ if (dawnToggles->enabledToggles) {
124
+ for (const auto &t : dawnToggles->enabledToggles.value()) {
125
+ enabledToggles.push_back(t.c_str());
126
+ }
127
+ toggles.enabledToggleCount = enabledToggles.size();
128
+ toggles.enabledToggles = enabledToggles.data();
129
+ }
130
+ if (dawnToggles->disabledToggles) {
131
+ for (const auto &t : dawnToggles->disabledToggles.value()) {
132
+ disabledToggles.push_back(t.c_str());
133
+ }
134
+ toggles.disabledToggleCount = disabledToggles.size();
135
+ toggles.disabledToggles = disabledToggles.data();
136
+ }
137
+ deviceDesc.nextInChain = &toggles;
138
+ }
113
139
  _instance.RequestDevice(
114
- &aDescriptor, wgpu::CallbackMode::AllowProcessEvents,
140
+ &deviceDesc, wgpu::CallbackMode::AllowProcessEvents,
115
141
  [asyncRunner = _async, resolve, reject, label, creationRuntime,
116
142
  deviceLostBinding](wgpu::RequestDeviceStatus status,
117
143
  wgpu::Device device,
118
- wgpu::StringView message) mutable {
144
+ wgpu::StringView message) {
119
145
  if (message.length) {
120
146
  fprintf(stderr, "%s", message.data);
121
147
  }
@@ -128,10 +154,13 @@ async::AsyncTaskHandle GPUAdapter::requestDevice(
128
154
  return;
129
155
  }
130
156
 
157
+ // SetLoggingCallback is a repeatable callback (no callback mode),
158
+ // which rejects capturing lambdas. Pass the runtime pointer
159
+ // through Dawn's userdata argument instead of capturing it.
131
160
  device.SetLoggingCallback(
132
- [creationRuntime](wgpu::LoggingType type,
133
- wgpu::StringView msg) {
134
- if (creationRuntime == nullptr) {
161
+ [](wgpu::LoggingType type, wgpu::StringView msg,
162
+ jsi::Runtime *runtime) {
163
+ if (runtime == nullptr) {
135
164
  return;
136
165
  }
137
166
  const char *logLevel = "";
@@ -157,7 +186,8 @@ async::AsyncTaskHandle GPUAdapter::requestDevice(
157
186
  fprintf(stderr, "%s: %.*s\n", logLevel,
158
187
  static_cast<int>(msg.length), msg.data);
159
188
  }
160
- });
189
+ },
190
+ creationRuntime);
161
191
 
162
192
  auto deviceHost = std::make_shared<GPUDevice>(std::move(device),
163
193
  asyncRunner, label);
@@ -14,7 +14,7 @@
14
14
 
15
15
  #include "webgpu/webgpu_cpp.h"
16
16
 
17
- #include "ArrayBuffer.h"
17
+ #include "rnwgpu/ArrayBuffer.h"
18
18
 
19
19
  namespace rnwgpu {
20
20
 
@@ -7,6 +7,7 @@
7
7
  #include <vector>
8
8
 
9
9
  #include "Convertors.h"
10
+ #include "NativeBufferUtils.h"
10
11
  #include "jsi2/JSIConverter.h"
11
12
 
12
13
  #include "GPUFeatures.h"
@@ -234,8 +235,83 @@ std::shared_ptr<GPUPipelineLayout> GPUDevice::createPipelineLayout(
234
235
 
235
236
  std::shared_ptr<GPUExternalTexture> GPUDevice::importExternalTexture(
236
237
  std::shared_ptr<GPUExternalTextureDescriptor> descriptor) {
237
- throw std::runtime_error(
238
- "GPUDevice::importExternalTexture(): Not implemented");
238
+ // The import / begin-access / descriptor-build logic, plus the matching
239
+ // EndAccess, all live on GPUExternalTexture so the begin/end lifecycle stays
240
+ // in one translation unit (see GPUExternalTexture.cpp).
241
+ return GPUExternalTexture::Create(_instance, std::move(descriptor));
242
+ }
243
+
244
+ std::shared_ptr<GPUSharedTextureMemory> GPUDevice::importSharedTextureMemory(
245
+ std::shared_ptr<GPUSharedTextureMemoryDescriptor> descriptor) {
246
+ if (!descriptor || descriptor->handle == 0) {
247
+ throw std::runtime_error(
248
+ "GPUDevice::importSharedTextureMemory(): handle must be a non-null "
249
+ "native buffer pointer (from Skia.NativeBuffer.MakeFromImage)");
250
+ }
251
+ void *bufferPtr =
252
+ reinterpret_cast<void *>(static_cast<uintptr_t>(descriptor->handle));
253
+ std::string label = descriptor->label.value_or("");
254
+
255
+ auto memory = importNativeBufferAsSharedTextureMemory(
256
+ _instance, bufferPtr, label, /*outWidth=*/nullptr, /*outHeight=*/nullptr);
257
+ if (memory == nullptr) {
258
+ throw std::runtime_error(
259
+ "GPUDevice::importSharedTextureMemory(): ImportSharedTextureMemory "
260
+ "returned null - is the 'shared-texture-memory-iosurface' (Apple) or "
261
+ "'shared-texture-memory-ahardware-buffer' (Android) feature enabled on "
262
+ "the device?");
263
+ }
264
+ return std::make_shared<GPUSharedTextureMemory>(std::move(memory),
265
+ std::move(label));
266
+ }
267
+
268
+ std::shared_ptr<GPUSharedFence> GPUDevice::importSharedFence(
269
+ std::shared_ptr<GPUSharedFenceDescriptor> descriptor) {
270
+ if (!descriptor || descriptor->handle == nullptr) {
271
+ throw std::runtime_error("GPUDevice::importSharedFence(): handle must be a "
272
+ "non-null native handle");
273
+ }
274
+
275
+ wgpu::SharedFenceDescriptor desc{};
276
+ std::string label = descriptor->label.value_or("");
277
+ if (!label.empty()) {
278
+ desc.label = wgpu::StringView(label.c_str(), label.size());
279
+ }
280
+
281
+ // The chained platform descriptor must outlive the synchronous
282
+ // ImportSharedFence() below; declare them all and chain the matching one.
283
+ wgpu::SharedFenceMTLSharedEventDescriptor mtlDesc{};
284
+ wgpu::SharedFenceSyncFDDescriptor syncFdDesc{};
285
+ wgpu::SharedFenceVkSemaphoreOpaqueFDDescriptor vkFdDesc{};
286
+
287
+ const std::string &type = descriptor->type;
288
+ if (type == "mtl-shared-event") {
289
+ // handle is an id<MTLSharedEvent> pointer.
290
+ mtlDesc.sharedEvent = descriptor->handle;
291
+ desc.nextInChain = &mtlDesc;
292
+ } else if (type == "sync-fd") {
293
+ // handle is an OS file descriptor.
294
+ syncFdDesc.handle =
295
+ static_cast<int>(reinterpret_cast<uintptr_t>(descriptor->handle));
296
+ desc.nextInChain = &syncFdDesc;
297
+ } else if (type == "vk-semaphore-opaque-fd") {
298
+ vkFdDesc.handle =
299
+ static_cast<int>(reinterpret_cast<uintptr_t>(descriptor->handle));
300
+ desc.nextInChain = &vkFdDesc;
301
+ } else {
302
+ throw std::runtime_error(
303
+ "GPUDevice::importSharedFence(): unsupported fence type '" + type +
304
+ "' (expected 'mtl-shared-event', 'sync-fd' or "
305
+ "'vk-semaphore-opaque-fd')");
306
+ }
307
+
308
+ auto fence = _instance.ImportSharedFence(&desc);
309
+ if (fence == nullptr) {
310
+ throw std::runtime_error(
311
+ "GPUDevice::importSharedFence(): ImportSharedFence returned null - is "
312
+ "the matching 'shared-fence-*' feature enabled on the device?");
313
+ }
314
+ return std::make_shared<GPUSharedFence>(std::move(fence), std::move(label));
239
315
  }
240
316
 
241
317
  async::AsyncTaskHandle GPUDevice::createComputePipelineAsync(
@@ -262,7 +338,7 @@ async::AsyncTaskHandle GPUDevice::createComputePipelineAsync(
262
338
  &desc, wgpu::CallbackMode::AllowProcessEvents,
263
339
  [pipelineHolder, resolve,
264
340
  reject](wgpu::CreatePipelineAsyncStatus status,
265
- wgpu::ComputePipeline pipeline, const char *msg) mutable {
341
+ wgpu::ComputePipeline pipeline, wgpu::StringView msg) {
266
342
  if (status == wgpu::CreatePipelineAsyncStatus::Success && pipeline) {
267
343
  pipelineHolder->_instance = pipeline;
268
344
  resolve([pipelineHolder](jsi::Runtime &runtime) mutable {
@@ -271,7 +347,8 @@ async::AsyncTaskHandle GPUDevice::createComputePipelineAsync(
271
347
  });
272
348
  } else {
273
349
  std::string error =
274
- msg ? std::string(msg) : "Failed to create compute pipeline";
350
+ msg.length ? std::string(msg.data, msg.length)
351
+ : "Failed to create compute pipeline";
275
352
  reject(std::move(error));
276
353
  }
277
354
  });
@@ -303,7 +380,7 @@ async::AsyncTaskHandle GPUDevice::createRenderPipelineAsync(
303
380
  &desc, wgpu::CallbackMode::AllowProcessEvents,
304
381
  [pipelineHolder, resolve,
305
382
  reject](wgpu::CreatePipelineAsyncStatus status,
306
- wgpu::RenderPipeline pipeline, const char *msg) mutable {
383
+ wgpu::RenderPipeline pipeline, wgpu::StringView msg) {
307
384
  if (status == wgpu::CreatePipelineAsyncStatus::Success && pipeline) {
308
385
  pipelineHolder->_instance = pipeline;
309
386
  resolve([pipelineHolder](jsi::Runtime &runtime) mutable {
@@ -312,7 +389,8 @@ async::AsyncTaskHandle GPUDevice::createRenderPipelineAsync(
312
389
  });
313
390
  } else {
314
391
  std::string error =
315
- msg ? std::string(msg) : "Failed to create render pipeline";
392
+ msg.length ? std::string(msg.data, msg.length)
393
+ : "Failed to create render pipeline";
316
394
  reject(std::move(error));
317
395
  }
318
396
  });
@@ -37,6 +37,8 @@
37
37
  #include "GPURenderPipeline.h"
38
38
  #include "GPUSampler.h"
39
39
  #include "GPUShaderModule.h"
40
+ #include "GPUSharedFence.h"
41
+ #include "GPUSharedTextureMemory.h"
40
42
  #include "GPUSupportedLimits.h"
41
43
  #include "GPUTexture.h"
42
44
  #include "descriptors/GPUBindGroupDescriptor.h"
@@ -51,6 +53,8 @@
51
53
  #include "descriptors/GPURenderPipelineDescriptor.h"
52
54
  #include "descriptors/GPUSamplerDescriptor.h"
53
55
  #include "descriptors/GPUShaderModuleDescriptor.h"
56
+ #include "descriptors/GPUSharedFenceDescriptor.h"
57
+ #include "descriptors/GPUSharedTextureMemoryDescriptor.h"
54
58
  #include "descriptors/GPUTextureDescriptor.h"
55
59
 
56
60
  namespace rnwgpu {
@@ -120,6 +124,10 @@ public:
120
124
  std::optional<std::shared_ptr<GPUSamplerDescriptor>> descriptor);
121
125
  std::shared_ptr<GPUExternalTexture> importExternalTexture(
122
126
  std::shared_ptr<GPUExternalTextureDescriptor> descriptor);
127
+ std::shared_ptr<GPUSharedTextureMemory> importSharedTextureMemory(
128
+ std::shared_ptr<GPUSharedTextureMemoryDescriptor> descriptor);
129
+ std::shared_ptr<GPUSharedFence>
130
+ importSharedFence(std::shared_ptr<GPUSharedFenceDescriptor> descriptor);
123
131
  std::shared_ptr<GPUBindGroupLayout> createBindGroupLayout(
124
132
  std::shared_ptr<GPUBindGroupLayoutDescriptor> descriptor);
125
133
  std::shared_ptr<GPUPipelineLayout>
@@ -173,6 +181,10 @@ public:
173
181
  &GPUDevice::createSampler);
174
182
  installMethod(runtime, prototype, "importExternalTexture",
175
183
  &GPUDevice::importExternalTexture);
184
+ installMethod(runtime, prototype, "importSharedTextureMemory",
185
+ &GPUDevice::importSharedTextureMemory);
186
+ installMethod(runtime, prototype, "importSharedFence",
187
+ &GPUDevice::importSharedFence);
176
188
  installMethod(runtime, prototype, "createBindGroupLayout",
177
189
  &GPUDevice::createBindGroupLayout);
178
190
  installMethod(runtime, prototype, "createPipelineLayout",
@@ -0,0 +1,139 @@
1
+ #include "GPUExternalTexture.h"
2
+
3
+ #include <cmath>
4
+ #include <memory>
5
+ #include <string>
6
+ #include <utility>
7
+
8
+ #include "NativeBufferUtils.h"
9
+ #include "descriptors/GPUExternalTextureDescriptor.h"
10
+
11
+ namespace rnwgpu {
12
+
13
+ // Identity gamut (same primaries) as a 3x3 column-major matrix.
14
+ static const float kIdentityGamutMatrix[9] = {
15
+ 1.0f, 0.0f, 0.0f, //
16
+ 0.0f, 1.0f, 0.0f, //
17
+ 0.0f, 0.0f, 1.0f, //
18
+ };
19
+
20
+ // Identity transfer (y = x). The native buffers produced by Skia's NativeBuffer
21
+ // API are single-plane BGRA/RGBA already in the render target's color space, so
22
+ // no conversion is wanted. Dawn dereferences the transfer-function arrays
23
+ // unconditionally (ComputeExternalTextureParams), so these must be non-null.
24
+ static const float kIdentityTransferParams[7] = {
25
+ 1.0f, // G
26
+ 1.0f, // A
27
+ 0.0f, // B
28
+ 0.0f, // C
29
+ 0.0f, // D
30
+ 0.0f, // E
31
+ 0.0f, // F
32
+ };
33
+
34
+ // Map a rotation in degrees (0 / 90 / 180 / 270) to Dawn's enum. Anything that
35
+ // isn't a clean multiple of 90 snaps to the nearest quadrant; Dawn only
36
+ // supports those four steps for external textures.
37
+ static wgpu::ExternalTextureRotation toExternalTextureRotation(double degrees) {
38
+ int quadrant = static_cast<int>(std::lround(degrees / 90.0));
39
+ quadrant = ((quadrant % 4) + 4) % 4;
40
+ switch (quadrant) {
41
+ case 1:
42
+ return wgpu::ExternalTextureRotation::Rotate90Degrees;
43
+ case 2:
44
+ return wgpu::ExternalTextureRotation::Rotate180Degrees;
45
+ case 3:
46
+ return wgpu::ExternalTextureRotation::Rotate270Degrees;
47
+ default:
48
+ return wgpu::ExternalTextureRotation::Rotate0Degrees;
49
+ }
50
+ }
51
+
52
+ std::shared_ptr<GPUExternalTexture> GPUExternalTexture::Create(
53
+ wgpu::Device device,
54
+ std::shared_ptr<GPUExternalTextureDescriptor> descriptor) {
55
+ if (!descriptor || descriptor->source == 0) {
56
+ throw std::runtime_error(
57
+ "GPUExternalTexture::Create(): descriptor.source (a native buffer "
58
+ "pointer from Skia.NativeBuffer.MakeFromImage) is required");
59
+ }
60
+ void *bufferPtr =
61
+ reinterpret_cast<void *>(static_cast<uintptr_t>(descriptor->source));
62
+ std::string label = descriptor->label.value_or("external-texture");
63
+
64
+ // 1. Import the native buffer as SharedTextureMemory and read its dimensions.
65
+ uint32_t width = 0;
66
+ uint32_t height = 0;
67
+ wgpu::SharedTextureMemory memory = importNativeBufferAsSharedTextureMemory(
68
+ device, bufferPtr, label, &width, &height);
69
+ if (memory == nullptr) {
70
+ throw std::runtime_error(
71
+ "GPUExternalTexture::Create(): ImportSharedTextureMemory returned "
72
+ "null");
73
+ }
74
+
75
+ // 2. Create the texture from the surface (Dawn picks the single-plane
76
+ // BGRA/RGBA format).
77
+ auto texture = memory.CreateTexture();
78
+ if (texture == nullptr) {
79
+ throw std::runtime_error(
80
+ "GPUExternalTexture::Create(): CreateTexture returned null");
81
+ }
82
+
83
+ // 3. Begin access. The matching EndAccess runs when the GPUExternalTexture is
84
+ // destroyed (explicitly via destroy() or at GC).
85
+ wgpu::SharedTextureMemoryBeginAccessDescriptor begin{};
86
+ begin.initialized = true;
87
+ begin.concurrentRead = false;
88
+ #if defined(__ANDROID__)
89
+ // Dawn's Vulkan backend requires the acquired VkImageLayout to be chained.
90
+ // UNDEFINED (= 0) on both ends is the canonical "no prior GPU producer"
91
+ // pattern (matches GPUSharedTextureMemory::beginAccess).
92
+ wgpu::SharedTextureMemoryVkImageLayoutBeginState vkBegin{};
93
+ vkBegin.oldLayout = 0;
94
+ vkBegin.newLayout = 0;
95
+ begin.nextInChain = &vkBegin;
96
+ #endif
97
+ if (!memory.BeginAccess(texture, &begin)) {
98
+ throw std::runtime_error(
99
+ "GPUExternalTexture::Create(): BeginAccess failed");
100
+ }
101
+
102
+ // 4. Single-plane view (the whole BGRA/RGBA surface).
103
+ auto plane0 = texture.CreateView();
104
+
105
+ // 5. Build the ExternalTextureDescriptor. The surface is already RGB in the
106
+ // target color space, so pass it through with identity transfer/gamut.
107
+ wgpu::ExternalTextureDescriptor extDesc{};
108
+ if (!label.empty()) {
109
+ extDesc.label = wgpu::StringView(label.c_str(), label.size());
110
+ }
111
+ extDesc.plane0 = plane0;
112
+ extDesc.gamutConversionMatrix = kIdentityGamutMatrix;
113
+ extDesc.srcTransferFunctionParameters = kIdentityTransferParams;
114
+ extDesc.dstTransferFunctionParameters = kIdentityTransferParams;
115
+ extDesc.cropOrigin = {0, 0};
116
+ extDesc.cropSize = {width, height};
117
+ extDesc.apparentSize = {width, height};
118
+ extDesc.mirrored = descriptor->mirrored.value_or(false);
119
+ extDesc.rotation =
120
+ toExternalTextureRotation(descriptor->rotation.value_or(0));
121
+
122
+ auto external = device.CreateExternalTexture(&extDesc);
123
+ if (external == nullptr) {
124
+ wgpu::SharedTextureMemoryEndAccessState state{};
125
+ #if defined(__ANDROID__)
126
+ wgpu::SharedTextureMemoryVkImageLayoutEndState vkEnd{};
127
+ state.nextInChain = &vkEnd;
128
+ #endif
129
+ (void)memory.EndAccess(texture, &state);
130
+ throw std::runtime_error(
131
+ "GPUExternalTexture::Create(): CreateExternalTexture returned null");
132
+ }
133
+
134
+ return std::make_shared<GPUExternalTexture>(
135
+ std::move(external), std::move(memory), std::move(texture),
136
+ std::move(label));
137
+ }
138
+
139
+ } // namespace rnwgpu
@@ -1,6 +1,8 @@
1
1
  #pragma once
2
2
 
3
+ #include <memory>
3
4
  #include <string>
5
+ #include <utility>
4
6
 
5
7
  #include "descriptors/Unions.h"
6
8
 
@@ -12,16 +14,61 @@ namespace rnwgpu {
12
14
 
13
15
  namespace jsi = facebook::jsi;
14
16
 
17
+ struct GPUExternalTextureDescriptor;
18
+
15
19
  class GPUExternalTexture : public NativeObject<GPUExternalTexture> {
16
20
  public:
17
21
  static constexpr const char *CLASS_NAME = "GPUExternalTexture";
18
22
 
19
- explicit GPUExternalTexture(wgpu::ExternalTexture instance, std::string label)
20
- : NativeObject(CLASS_NAME), _instance(instance), _label(label) {}
23
+ // Import a native buffer (via descriptor.source, a CVPixelBufferRef /
24
+ // AHardwareBuffer* from Skia's NativeBuffer API) as a GPUExternalTexture on
25
+ // `device`: imports the native surface as SharedTextureMemory, begins access,
26
+ // and wraps the resulting wgpu::ExternalTexture together with the resources
27
+ // whose lifetime it owns. The matching EndAccess runs in destroy() / the
28
+ // destructor. Defined in GPUExternalTexture.cpp.
29
+ static std::shared_ptr<GPUExternalTexture>
30
+ Create(wgpu::Device device,
31
+ std::shared_ptr<GPUExternalTextureDescriptor> descriptor);
32
+
33
+ // Construct from an already-built wgpu::ExternalTexture plus the underlying
34
+ // shared-memory resources we need to keep alive. The wrapper takes ownership
35
+ // of the SharedTextureMemory + Texture and calls EndAccess on destruction so
36
+ // the producer (the native buffer's surface) can reclaim it.
37
+ GPUExternalTexture(wgpu::ExternalTexture instance,
38
+ wgpu::SharedTextureMemory memory, wgpu::Texture texture,
39
+ std::string label)
40
+ : NativeObject(CLASS_NAME), _instance(std::move(instance)),
41
+ _memory(std::move(memory)), _texture(std::move(texture)),
42
+ _label(std::move(label)) {}
43
+
44
+ ~GPUExternalTexture() override { destroy(); }
21
45
 
22
46
  public:
23
47
  std::string getBrand() { return CLASS_NAME; }
24
48
 
49
+ // End the shared-memory access window and release the underlying resources.
50
+ // Idempotent: safe to call more than once, and the destructor calls it as a
51
+ // garbage-collection fallback. Call it right after the queue.submit() that
52
+ // sampled this texture (never before): a GPUExternalTexture's access window
53
+ // is owned by this wrapper's lifetime, not by submit, so without an explicit
54
+ // destroy() the producer's surface stays claimed until GC runs. EndAccess is
55
+ // the designed post-submit call: Dawn keeps the texture alive for in-flight
56
+ // GPU work via the fences it returns.
57
+ void destroy() {
58
+ if (_memory && _texture) {
59
+ wgpu::SharedTextureMemoryEndAccessState state{};
60
+ #if defined(__ANDROID__)
61
+ // Dawn's Vulkan backend requires the released VkImageLayout to be chained
62
+ // (matches BeginAccess in GPUExternalTexture::Create).
63
+ wgpu::SharedTextureMemoryVkImageLayoutEndState vkEnd{};
64
+ state.nextInChain = &vkEnd;
65
+ #endif
66
+ (void)_memory.EndAccess(_texture, &state);
67
+ }
68
+ _texture = nullptr;
69
+ _memory = nullptr;
70
+ }
71
+
25
72
  std::string getLabel() { return _label; }
26
73
  void setLabel(const std::string &label) {
27
74
  _label = label;
@@ -33,12 +80,15 @@ public:
33
80
  installGetterSetter(runtime, prototype, "label",
34
81
  &GPUExternalTexture::getLabel,
35
82
  &GPUExternalTexture::setLabel);
83
+ installMethod(runtime, prototype, "destroy", &GPUExternalTexture::destroy);
36
84
  }
37
85
 
38
86
  inline const wgpu::ExternalTexture get() { return _instance; }
39
87
 
40
88
  private:
41
89
  wgpu::ExternalTexture _instance;
90
+ wgpu::SharedTextureMemory _memory;
91
+ wgpu::Texture _texture;
42
92
  std::string _label;
43
93
  };
44
94
 
@@ -1,5 +1,6 @@
1
1
  #include "GPUQueue.h"
2
2
 
3
+ #include <cstring>
3
4
  #include <limits>
4
5
  #include <memory>
5
6
  #include <vector>
@@ -103,51 +104,55 @@ void GPUQueue::copyExternalImageToTexture(
103
104
  std::shared_ptr<GPUImageCopyExternalImage> source,
104
105
  std::shared_ptr<GPUImageCopyTextureTagged> destination,
105
106
  std::shared_ptr<GPUExtent3D> size) {
106
- // wgpu::TexelCopyTextureInfo dst{};
107
- // wgpu::TexelCopyBufferLayout layout{};
108
- // wgpu::Extent3D sz{};
109
- // Convertor conv;
110
- // uint32_t bytesPerPixel =
111
- // source->source->getSize() /
112
- // (source->source->getWidth() * source->source->getHeight());
113
- // auto dataLayout = std::make_shared<GPUImageDataLayout>(GPUImageDataLayout{
114
- // std::optional<double>{0.0},
115
- // std::optional<double>{
116
- // static_cast<double>(bytesPerPixel * source->source->getWidth())},
117
- // std::optional<double>{static_cast<double>(source->source->getHeight())}});
118
- // if (!conv(dst.aspect, destination->aspect) ||
119
- // !conv(dst.mipLevel, destination->mipLevel) ||
120
- // !conv(dst.origin, destination->origin) ||
121
- // !conv(dst.texture, destination->texture) ||
122
- // !conv(layout, dataLayout) || //
123
- // !conv(sz, size)) {
124
- // throw std::runtime_error("Invalid input for GPUQueue::writeTexture()");
125
- // }
126
- //
127
- // if (source->flipY.value_or(false)) {
128
- // // Calculate the row size and total size
129
- // uint32_t rowSize = bytesPerPixel * source->source->getWidth();
130
- // uint32_t totalSize = source->source->getSize();
131
- //
132
- // // Create a new buffer for the flipped data
133
- // std::vector<uint8_t> flippedData(totalSize);
134
- //
135
- // // Flip the data vertically
136
- // for (uint32_t row = 0; row < source->source->getHeight(); ++row) {
137
- // std::memcpy(flippedData.data() +
138
- // (source->source->getHeight() - 1 - row) * rowSize,
139
- // static_cast<const uint8_t *>(source->source->getData()) +
140
- // row * rowSize,
141
- // rowSize);
142
- // }
143
- // // Use the flipped data for writing to texture
144
- // _instance.WriteTexture(&dst, flippedData.data(), totalSize, &layout,
145
- // &sz);
146
- // } else {
147
- //
148
- // _instance.WriteTexture(&dst, source->source->getData(),
149
- // source->source->getSize(), &layout, &sz);
150
- // }
107
+ if (!source || source->source == nullptr) {
108
+ throw std::runtime_error("GPUQueue::copyExternalImageToTexture(): "
109
+ "source.source (ImageBitmap) is required");
110
+ }
111
+ // ImageBitmap holds decoded, row-major RGBA8 pixels. We upload them with
112
+ // WriteTexture (a CPU staging copy) rather than a GPU blit; that is enough
113
+ // for the common "decode an image, sample it" path and avoids needing a
114
+ // source GPUTexture.
115
+ const auto &pixels = source->source->data();
116
+ auto width = static_cast<uint32_t>(source->source->getWidth());
117
+ auto height = static_cast<uint32_t>(source->source->getHeight());
118
+ if (pixels.empty() || width == 0 || height == 0) {
119
+ throw std::runtime_error("GPUQueue::copyExternalImageToTexture(): "
120
+ "ImageBitmap has no pixels (was it closed?)");
121
+ }
122
+ auto bytesPerPixel = static_cast<uint32_t>(
123
+ pixels.size() / (static_cast<size_t>(width) * height));
124
+ uint32_t rowSize = bytesPerPixel * width;
125
+
126
+ wgpu::TexelCopyTextureInfo dst{};
127
+ wgpu::TexelCopyBufferLayout layout{};
128
+ wgpu::Extent3D sz{};
129
+ Convertor conv;
130
+ auto dataLayout = std::make_shared<GPUImageDataLayout>(
131
+ GPUImageDataLayout{std::optional<double>{0.0},
132
+ std::optional<double>{static_cast<double>(rowSize)},
133
+ std::optional<double>{static_cast<double>(height)}});
134
+ if (!conv(dst.aspect, destination->aspect) ||
135
+ !conv(dst.mipLevel, destination->mipLevel) ||
136
+ !conv(dst.origin, destination->origin) ||
137
+ !conv(dst.texture, destination->texture) || !conv(layout, dataLayout) ||
138
+ !conv(sz, size)) {
139
+ throw std::runtime_error(
140
+ "Invalid input for GPUQueue::copyExternalImageToTexture()");
141
+ }
142
+
143
+ if (source->flipY.value_or(false)) {
144
+ // Flip rows so the image is uploaded bottom-up (matches the WebGPU
145
+ // copyExternalImageToTexture flipY semantics).
146
+ std::vector<uint8_t> flippedData(pixels.size());
147
+ for (uint32_t row = 0; row < height; ++row) {
148
+ std::memcpy(flippedData.data() + (height - 1 - row) * rowSize,
149
+ pixels.data() + row * rowSize, rowSize);
150
+ }
151
+ _instance.WriteTexture(&dst, flippedData.data(), flippedData.size(),
152
+ &layout, &sz);
153
+ } else {
154
+ _instance.WriteTexture(&dst, pixels.data(), pixels.size(), &layout, &sz);
155
+ }
151
156
  }
152
157
 
153
158
  void GPUQueue::writeTexture(std::shared_ptr<GPUImageCopyTexture> destination,
@@ -18,7 +18,7 @@ async::AsyncTaskHandle GPUShaderModule::getCompilationInfo() {
18
18
  wgpu::CallbackMode::AllowProcessEvents,
19
19
  [result, resolve,
20
20
  reject](wgpu::CompilationInfoRequestStatus status,
21
- const wgpu::CompilationInfo *compilationInfo) mutable {
21
+ const wgpu::CompilationInfo *compilationInfo) {
22
22
  if (status != wgpu::CompilationInfoRequestStatus::Success ||
23
23
  compilationInfo == nullptr) {
24
24
  reject("Failed to get compilation info");