@nativescript/canvas 2.0.0-beta.8 → 2.0.0-webgpu.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (284) hide show
  1. package/Canvas/common.d.ts +23 -15
  2. package/Canvas/common.js +125 -56
  3. package/Canvas/common.js.map +1 -1
  4. package/Canvas/index.android.d.ts +5 -7
  5. package/Canvas/index.android.js +61 -133
  6. package/Canvas/index.android.js.map +1 -1
  7. package/Canvas/index.d.ts +4 -1
  8. package/Canvas/index.ios.d.ts +6 -6
  9. package/Canvas/index.ios.js +75 -85
  10. package/Canvas/index.ios.js.map +1 -1
  11. package/Canvas2D/CanvasRenderingContext2D/index.d.ts +1 -1
  12. package/Canvas2D/CanvasRenderingContext2D/index.js +8 -11
  13. package/Canvas2D/CanvasRenderingContext2D/index.js.map +1 -1
  14. package/Canvas2D/DOMMatrix/index.d.ts +14 -0
  15. package/Canvas2D/DOMMatrix/index.js +62 -0
  16. package/Canvas2D/DOMMatrix/index.js.map +1 -1
  17. package/Canvas2D/ImageData/index.js +4 -6
  18. package/Canvas2D/ImageData/index.js.map +1 -1
  19. package/ImageAsset/index.d.ts +1 -0
  20. package/ImageAsset/index.js +49 -0
  21. package/ImageAsset/index.js.map +1 -1
  22. package/WebGL/WebGLRenderingContext/index.d.ts +1 -0
  23. package/WebGL/WebGLRenderingContext/index.js +104 -14
  24. package/WebGL/WebGLRenderingContext/index.js.map +1 -1
  25. package/WebGL2/WebGL2RenderingContext/index.d.ts +1 -0
  26. package/WebGL2/WebGL2RenderingContext/index.js +2 -3
  27. package/WebGL2/WebGL2RenderingContext/index.js.map +1 -1
  28. package/WebGPU/Constants.d.ts +36 -0
  29. package/WebGPU/Constants.js +42 -0
  30. package/WebGPU/Constants.js.map +1 -0
  31. package/WebGPU/Errors.d.ts +18 -0
  32. package/WebGPU/Errors.js +21 -0
  33. package/WebGPU/Errors.js.map +1 -0
  34. package/WebGPU/GPU.d.ts +13 -0
  35. package/WebGPU/GPU.js +35 -0
  36. package/WebGPU/GPU.js.map +1 -0
  37. package/WebGPU/GPUAdapter.d.ts +23 -0
  38. package/WebGPU/GPUAdapter.js +62 -0
  39. package/WebGPU/GPUAdapter.js.map +1 -0
  40. package/WebGPU/GPUAdapterInfo.d.ts +9 -0
  41. package/WebGPU/GPUAdapterInfo.js +24 -0
  42. package/WebGPU/GPUAdapterInfo.js.map +1 -0
  43. package/WebGPU/GPUBindGroup.d.ts +5 -0
  44. package/WebGPU/GPUBindGroup.js +12 -0
  45. package/WebGPU/GPUBindGroup.js.map +1 -0
  46. package/WebGPU/GPUBindGroupLayout.d.ts +5 -0
  47. package/WebGPU/GPUBindGroupLayout.js +12 -0
  48. package/WebGPU/GPUBindGroupLayout.js.map +1 -0
  49. package/WebGPU/GPUBuffer.d.ts +15 -0
  50. package/WebGPU/GPUBuffer.js +54 -0
  51. package/WebGPU/GPUBuffer.js.map +1 -0
  52. package/WebGPU/GPUCanvasContext.d.ts +33 -0
  53. package/WebGPU/GPUCanvasContext.js +67 -0
  54. package/WebGPU/GPUCanvasContext.js.map +1 -0
  55. package/WebGPU/GPUCommandBuffer.d.ts +5 -0
  56. package/WebGPU/GPUCommandBuffer.js +12 -0
  57. package/WebGPU/GPUCommandBuffer.js.map +1 -0
  58. package/WebGPU/GPUCommandEncoder.d.ts +41 -0
  59. package/WebGPU/GPUCommandEncoder.js +105 -0
  60. package/WebGPU/GPUCommandEncoder.js.map +1 -0
  61. package/WebGPU/GPUComputePassEncoder.d.ts +16 -0
  62. package/WebGPU/GPUComputePassEncoder.js +50 -0
  63. package/WebGPU/GPUComputePassEncoder.js.map +1 -0
  64. package/WebGPU/GPUComputePipeline.d.ts +7 -0
  65. package/WebGPU/GPUComputePipeline.js +16 -0
  66. package/WebGPU/GPUComputePipeline.js.map +1 -0
  67. package/WebGPU/GPUDevice.d.ts +173 -0
  68. package/WebGPU/GPUDevice.js +381 -0
  69. package/WebGPU/GPUDevice.js.map +1 -0
  70. package/WebGPU/GPUDeviceLostInfo.d.ts +1 -0
  71. package/WebGPU/GPUDeviceLostInfo.js +10 -0
  72. package/WebGPU/GPUDeviceLostInfo.js.map +1 -0
  73. package/WebGPU/GPUExternalTexture.d.ts +5 -0
  74. package/WebGPU/GPUExternalTexture.js +12 -0
  75. package/WebGPU/GPUExternalTexture.js.map +1 -0
  76. package/WebGPU/GPUPipelineLayout.d.ts +5 -0
  77. package/WebGPU/GPUPipelineLayout.js +12 -0
  78. package/WebGPU/GPUPipelineLayout.js.map +1 -0
  79. package/WebGPU/GPUQuerySet.d.ts +5 -0
  80. package/WebGPU/GPUQuerySet.js +12 -0
  81. package/WebGPU/GPUQuerySet.js.map +1 -0
  82. package/WebGPU/GPUQueue.d.ts +14 -0
  83. package/WebGPU/GPUQueue.js +77 -0
  84. package/WebGPU/GPUQueue.js.map +1 -0
  85. package/WebGPU/GPURenderBundle.d.ts +5 -0
  86. package/WebGPU/GPURenderBundle.js +12 -0
  87. package/WebGPU/GPURenderBundle.js.map +1 -0
  88. package/WebGPU/GPURenderBundleEncoder.d.ts +20 -0
  89. package/WebGPU/GPURenderBundleEncoder.js +61 -0
  90. package/WebGPU/GPURenderBundleEncoder.js.map +1 -0
  91. package/WebGPU/GPURenderPassEncoder.d.ts +29 -0
  92. package/WebGPU/GPURenderPassEncoder.js +94 -0
  93. package/WebGPU/GPURenderPassEncoder.js.map +1 -0
  94. package/WebGPU/GPURenderPipeline.d.ts +7 -0
  95. package/WebGPU/GPURenderPipeline.js +16 -0
  96. package/WebGPU/GPURenderPipeline.js.map +1 -0
  97. package/WebGPU/GPUSampler.d.ts +5 -0
  98. package/WebGPU/GPUSampler.js +12 -0
  99. package/WebGPU/GPUSampler.js.map +1 -0
  100. package/WebGPU/GPUShaderModule.d.ts +6 -0
  101. package/WebGPU/GPUShaderModule.js +15 -0
  102. package/WebGPU/GPUShaderModule.js.map +1 -0
  103. package/WebGPU/GPUTexture.d.ts +16 -0
  104. package/WebGPU/GPUTexture.js +41 -0
  105. package/WebGPU/GPUTexture.js.map +1 -0
  106. package/WebGPU/GPUTextureView.d.ts +5 -0
  107. package/WebGPU/GPUTextureView.js +12 -0
  108. package/WebGPU/GPUTextureView.js.map +1 -0
  109. package/WebGPU/Interfaces.d.ts +155 -0
  110. package/WebGPU/Interfaces.js +2 -0
  111. package/WebGPU/Interfaces.js.map +1 -0
  112. package/WebGPU/Types.d.ts +39 -0
  113. package/WebGPU/Types.js +2 -0
  114. package/WebGPU/Types.js.map +1 -0
  115. package/WebGPU/Utils.d.ts +1 -0
  116. package/WebGPU/Utils.js +75 -0
  117. package/WebGPU/Utils.js.map +1 -0
  118. package/WebGPU/index.d.ts +28 -0
  119. package/WebGPU/index.js +29 -0
  120. package/WebGPU/index.js.map +1 -0
  121. package/index.d.ts +1 -1
  122. package/index.js +22 -1
  123. package/index.js.map +1 -1
  124. package/package.json +1 -4
  125. package/platforms/android/canvas-release.aar +0 -0
  126. package/platforms/ios/CanvasNative.xcframework/ios-arm64/CanvasNative.framework/CanvasNative +0 -0
  127. package/platforms/ios/CanvasNative.xcframework/ios-arm64/CanvasNative.framework/Headers/CanvasNative-Swift.h +23 -23
  128. package/platforms/ios/CanvasNative.xcframework/ios-arm64/CanvasNative.framework/Headers/canvas_ios.h +47 -8
  129. package/platforms/ios/CanvasNative.xcframework/ios-arm64/CanvasNative.framework/Headers/canvas_native.h +2280 -103
  130. package/platforms/ios/CanvasNative.xcframework/ios-arm64/CanvasNative.framework/Info.plist +0 -0
  131. package/platforms/ios/CanvasNative.xcframework/ios-arm64/CanvasNative.framework/Modules/CanvasNative.swiftmodule/Project/arm64-apple-ios.swiftsourceinfo +0 -0
  132. package/platforms/ios/CanvasNative.xcframework/ios-arm64/CanvasNative.framework/Modules/CanvasNative.swiftmodule/arm64-apple-ios.abi.json +1564 -3814
  133. package/platforms/ios/CanvasNative.xcframework/ios-arm64/CanvasNative.framework/Modules/CanvasNative.swiftmodule/arm64-apple-ios.private.swiftinterface +27 -34
  134. package/platforms/ios/CanvasNative.xcframework/ios-arm64/CanvasNative.framework/Modules/CanvasNative.swiftmodule/arm64-apple-ios.swiftdoc +0 -0
  135. package/platforms/ios/CanvasNative.xcframework/ios-arm64/CanvasNative.framework/Modules/CanvasNative.swiftmodule/arm64-apple-ios.swiftinterface +27 -34
  136. package/platforms/ios/CanvasNative.xcframework/ios-arm64/dSYMs/CanvasNative.framework.dSYM/Contents/Resources/DWARF/CanvasNative +0 -0
  137. package/platforms/ios/CanvasNative.xcframework/ios-arm64/dSYMs/CanvasNative.framework.dSYM/Contents/Resources/Relocations/aarch64/CanvasNative.yml +602 -664
  138. package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/CanvasNative +0 -0
  139. package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/Headers/CanvasNative-Swift.h +46 -46
  140. package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/Headers/canvas_ios.h +47 -8
  141. package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/Headers/canvas_native.h +2280 -103
  142. package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/Info.plist +0 -0
  143. package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/Modules/CanvasNative.swiftmodule/Project/arm64-apple-ios-simulator.swiftsourceinfo +0 -0
  144. package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/Modules/CanvasNative.swiftmodule/Project/x86_64-apple-ios-simulator.swiftsourceinfo +0 -0
  145. package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/Modules/CanvasNative.swiftmodule/arm64-apple-ios-simulator.abi.json +1564 -3814
  146. package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/Modules/CanvasNative.swiftmodule/arm64-apple-ios-simulator.private.swiftinterface +27 -34
  147. package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/Modules/CanvasNative.swiftmodule/arm64-apple-ios-simulator.swiftdoc +0 -0
  148. package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/Modules/CanvasNative.swiftmodule/arm64-apple-ios-simulator.swiftinterface +27 -34
  149. package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/Modules/CanvasNative.swiftmodule/x86_64-apple-ios-simulator.abi.json +1564 -3814
  150. package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/Modules/CanvasNative.swiftmodule/x86_64-apple-ios-simulator.private.swiftinterface +27 -34
  151. package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/Modules/CanvasNative.swiftmodule/x86_64-apple-ios-simulator.swiftdoc +0 -0
  152. package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/Modules/CanvasNative.swiftmodule/x86_64-apple-ios-simulator.swiftinterface +27 -34
  153. package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/_CodeSignature/CodeResources +31 -31
  154. package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/dSYMs/CanvasNative.framework.dSYM/Contents/Resources/DWARF/CanvasNative +0 -0
  155. package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/dSYMs/CanvasNative.framework.dSYM/Contents/Resources/Relocations/aarch64/CanvasNative.yml +604 -663
  156. package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/dSYMs/CanvasNative.framework.dSYM/Contents/Resources/Relocations/x86_64/CanvasNative.yml +638 -642
  157. package/platforms/ios/build.xcconfig +3 -1
  158. package/platforms/ios/src/cpp/Caches.h +69 -1
  159. package/platforms/ios/src/cpp/CanvasJSIModule.cpp +320 -395
  160. package/platforms/ios/src/cpp/CanvasJSIModule.h +7 -1
  161. package/platforms/ios/src/cpp/Helpers.h +43 -8
  162. package/platforms/ios/src/cpp/ImageAssetImpl.cpp +35 -37
  163. package/platforms/ios/src/cpp/ImageAssetImpl.h +14 -10
  164. package/platforms/ios/src/cpp/ImageBitmapImpl.cpp +2 -2
  165. package/platforms/ios/src/cpp/ImageBitmapImpl.h +1 -1
  166. package/platforms/ios/src/cpp/canvas2d/CanvasPattern.cpp +0 -10
  167. package/platforms/ios/src/cpp/canvas2d/CanvasRenderingContext2DImpl.cpp +41 -4
  168. package/platforms/ios/src/cpp/canvas2d/MatrixImpl.cpp +409 -3
  169. package/platforms/ios/src/cpp/canvas2d/MatrixImpl.h +27 -0
  170. package/platforms/ios/src/cpp/webgl/WebGLRenderingContext.cpp +131 -149
  171. package/platforms/ios/src/cpp/webgl2/WebGL2RenderingContext.cpp +1766 -1659
  172. package/platforms/ios/src/cpp/webgpu/GPUAdapterImpl.cpp +302 -0
  173. package/platforms/ios/src/cpp/webgpu/GPUAdapterImpl.h +63 -0
  174. package/platforms/ios/src/cpp/webgpu/GPUAdapterInfoImpl.cpp +174 -0
  175. package/platforms/ios/src/cpp/webgpu/GPUAdapterInfoImpl.h +58 -0
  176. package/platforms/ios/src/cpp/webgpu/GPUBindGroupImpl.cpp +53 -0
  177. package/platforms/ios/src/cpp/webgpu/GPUBindGroupImpl.h +45 -0
  178. package/platforms/ios/src/cpp/webgpu/GPUBindGroupLayoutImpl.cpp +53 -0
  179. package/platforms/ios/src/cpp/webgpu/GPUBindGroupLayoutImpl.h +45 -0
  180. package/platforms/ios/src/cpp/webgpu/GPUBufferImpl.cpp +229 -0
  181. package/platforms/ios/src/cpp/webgpu/GPUBufferImpl.h +59 -0
  182. package/platforms/ios/src/cpp/webgpu/GPUCanvasContextImpl.cpp +317 -0
  183. package/platforms/ios/src/cpp/webgpu/GPUCanvasContextImpl.h +55 -0
  184. package/platforms/ios/src/cpp/webgpu/GPUCommandBufferImpl.cpp +54 -0
  185. package/platforms/ios/src/cpp/webgpu/GPUCommandBufferImpl.h +45 -0
  186. package/platforms/ios/src/cpp/webgpu/GPUCommandEncoderImpl.cpp +1087 -0
  187. package/platforms/ios/src/cpp/webgpu/GPUCommandEncoderImpl.h +69 -0
  188. package/platforms/ios/src/cpp/webgpu/GPUComputePassEncoderImpl.cpp +260 -0
  189. package/platforms/ios/src/cpp/webgpu/GPUComputePassEncoderImpl.h +62 -0
  190. package/platforms/ios/src/cpp/webgpu/GPUComputePipelineImpl.cpp +84 -0
  191. package/platforms/ios/src/cpp/webgpu/GPUComputePipelineImpl.h +49 -0
  192. package/platforms/ios/src/cpp/webgpu/GPUDeviceImpl.cpp +2741 -0
  193. package/platforms/ios/src/cpp/webgpu/GPUDeviceImpl.h +95 -0
  194. package/platforms/ios/src/cpp/webgpu/GPUImpl.cpp +186 -0
  195. package/platforms/ios/src/cpp/webgpu/GPUImpl.h +55 -0
  196. package/platforms/ios/src/cpp/webgpu/GPUPipelineLayoutImpl.cpp +54 -0
  197. package/platforms/ios/src/cpp/webgpu/GPUPipelineLayoutImpl.h +46 -0
  198. package/platforms/ios/src/cpp/webgpu/GPUQuerySetImpl.cpp +137 -0
  199. package/platforms/ios/src/cpp/webgpu/GPUQuerySetImpl.h +55 -0
  200. package/platforms/ios/src/cpp/webgpu/GPUQueueImpl.cpp +521 -0
  201. package/platforms/ios/src/cpp/webgpu/GPUQueueImpl.h +56 -0
  202. package/platforms/ios/src/cpp/webgpu/GPURenderBundleEncoderImpl.cpp +469 -0
  203. package/platforms/ios/src/cpp/webgpu/GPURenderBundleEncoderImpl.h +71 -0
  204. package/platforms/ios/src/cpp/webgpu/GPURenderBundleImpl.cpp +53 -0
  205. package/platforms/ios/src/cpp/webgpu/GPURenderBundleImpl.h +45 -0
  206. package/platforms/ios/src/cpp/webgpu/GPURenderPassEncoderImpl.cpp +653 -0
  207. package/platforms/ios/src/cpp/webgpu/GPURenderPassEncoderImpl.h +85 -0
  208. package/platforms/ios/src/cpp/webgpu/GPURenderPipelineImpl.cpp +84 -0
  209. package/platforms/ios/src/cpp/webgpu/GPURenderPipelineImpl.h +49 -0
  210. package/platforms/ios/src/cpp/webgpu/GPUSamplerImpl.cpp +53 -0
  211. package/platforms/ios/src/cpp/webgpu/GPUSamplerImpl.h +45 -0
  212. package/platforms/ios/src/cpp/webgpu/GPUShaderModuleImpl.cpp +56 -0
  213. package/platforms/ios/src/cpp/webgpu/GPUShaderModuleImpl.h +45 -0
  214. package/platforms/ios/src/cpp/webgpu/GPUSupportedLimitsImpl.cpp +1304 -0
  215. package/platforms/ios/src/cpp/webgpu/GPUSupportedLimitsImpl.h +288 -0
  216. package/platforms/ios/src/cpp/webgpu/GPUTextureImpl.cpp +360 -0
  217. package/platforms/ios/src/cpp/webgpu/GPUTextureImpl.h +75 -0
  218. package/platforms/ios/src/cpp/webgpu/GPUTextureViewImpl.cpp +53 -0
  219. package/platforms/ios/src/cpp/webgpu/GPUTextureViewImpl.h +45 -0
  220. package/platforms/ios/src/cpp/webgpu/GPUUtils.h +178 -0
  221. package/SVG/Circle.d.ts +0 -11
  222. package/SVG/Circle.js +0 -21
  223. package/SVG/Circle.js.map +0 -1
  224. package/SVG/ClipPath.d.ts +0 -4
  225. package/SVG/ClipPath.js +0 -9
  226. package/SVG/ClipPath.js.map +0 -1
  227. package/SVG/Defs.d.ts +0 -4
  228. package/SVG/Defs.js +0 -9
  229. package/SVG/Defs.js.map +0 -1
  230. package/SVG/Ellipse.d.ts +0 -13
  231. package/SVG/Ellipse.js +0 -26
  232. package/SVG/Ellipse.js.map +0 -1
  233. package/SVG/G.d.ts +0 -7
  234. package/SVG/G.js +0 -9
  235. package/SVG/G.js.map +0 -1
  236. package/SVG/Image.d.ts +0 -11
  237. package/SVG/Image.js +0 -40
  238. package/SVG/Image.js.map +0 -1
  239. package/SVG/Line.d.ts +0 -13
  240. package/SVG/Line.js +0 -26
  241. package/SVG/Line.js.map +0 -1
  242. package/SVG/LinearGradient.d.ts +0 -10
  243. package/SVG/LinearGradient.js +0 -13
  244. package/SVG/LinearGradient.js.map +0 -1
  245. package/SVG/Path.d.ts +0 -7
  246. package/SVG/Path.js +0 -14
  247. package/SVG/Path.js.map +0 -1
  248. package/SVG/Pattern.d.ts +0 -4
  249. package/SVG/Pattern.js +0 -9
  250. package/SVG/Pattern.js.map +0 -1
  251. package/SVG/Polygon.d.ts +0 -7
  252. package/SVG/Polygon.js +0 -14
  253. package/SVG/Polygon.js.map +0 -1
  254. package/SVG/Polyline.d.ts +0 -7
  255. package/SVG/Polyline.js +0 -14
  256. package/SVG/Polyline.js.map +0 -1
  257. package/SVG/Rect.d.ts +0 -8
  258. package/SVG/Rect.js +0 -13
  259. package/SVG/Rect.js.map +0 -1
  260. package/SVG/SVG.d.ts +0 -32
  261. package/SVG/SVG.js +0 -204
  262. package/SVG/SVG.js.map +0 -1
  263. package/SVG/SVGItem.d.ts +0 -5
  264. package/SVG/SVGItem.js +0 -8
  265. package/SVG/SVGItem.js.map +0 -1
  266. package/SVG/Stop.d.ts +0 -5
  267. package/SVG/Stop.js +0 -9
  268. package/SVG/Stop.js.map +0 -1
  269. package/SVG/Symbol.d.ts +0 -4
  270. package/SVG/Symbol.js +0 -9
  271. package/SVG/Symbol.js.map +0 -1
  272. package/SVG/Text.d.ts +0 -14
  273. package/SVG/Text.js +0 -26
  274. package/SVG/Text.js.map +0 -1
  275. package/SVG/Use.d.ts +0 -4
  276. package/SVG/Use.js +0 -9
  277. package/SVG/Use.js.map +0 -1
  278. package/SVG/index.d.ts +0 -18
  279. package/SVG/index.js +0 -19
  280. package/SVG/index.js.map +0 -1
  281. package/platforms/ios/src/cpp/PerIsolateData.cpp +0 -49
  282. package/platforms/ios/src/cpp/PerIsolateData.h +0 -54
  283. package/platforms/ios/src/cpp/URLImpl.cpp +0 -464
  284. package/platforms/ios/src/cpp/URLImpl.h +0 -121
@@ -0,0 +1,469 @@
1
+ //
2
+ // Created by Osei Fortune on 17/07/2024.
3
+ //
4
+
5
+ #include "GPURenderBundleEncoderImpl.h"
6
+ #include "Caches.h"
7
+ #include "GPURenderPipelineImpl.h"
8
+ #include "GPUBufferImpl.h"
9
+ #include "GPURenderBundleImpl.h"
10
+ #include "GPUBindGroupImpl.h"
11
+
12
+ GPURenderBundleEncoderImpl::GPURenderBundleEncoderImpl(const CanvasGPURenderBundleEncoder *encoder)
13
+ : encoder_(
14
+ encoder) {}
15
+
16
+ const CanvasGPURenderBundleEncoder *GPURenderBundleEncoderImpl::GetEncoder() {
17
+ return this->encoder_;
18
+ }
19
+
20
+
21
+ void GPURenderBundleEncoderImpl::Init(v8::Local<v8::Object> canvasModule, v8::Isolate *isolate) {
22
+ v8::Locker locker(isolate);
23
+ v8::Isolate::Scope isolate_scope(isolate);
24
+ v8::HandleScope handle_scope(isolate);
25
+
26
+ auto ctor = GetCtor(isolate);
27
+ auto context = isolate->GetCurrentContext();
28
+ auto func = ctor->GetFunction(context).ToLocalChecked();
29
+
30
+ canvasModule->Set(context, ConvertToV8String(isolate, "GPURenderBundleEncoder"),
31
+ func).FromJust();
32
+ }
33
+
34
+ GPURenderBundleEncoderImpl *
35
+ GPURenderBundleEncoderImpl::GetPointer(const v8::Local<v8::Object> &object) {
36
+ auto ptr = object->GetAlignedPointerFromInternalField(0);
37
+ if (ptr == nullptr) {
38
+ return nullptr;
39
+ }
40
+ return static_cast<GPURenderBundleEncoderImpl *>(ptr);
41
+ }
42
+
43
+ v8::Local<v8::FunctionTemplate> GPURenderBundleEncoderImpl::GetCtor(v8::Isolate *isolate) {
44
+ auto cache = Caches::Get(isolate);
45
+ auto ctor = cache->GPURenderBundleEncoderTmpl.get();
46
+ if (ctor != nullptr) {
47
+ return ctor->Get(isolate);
48
+ }
49
+
50
+ v8::Local<v8::FunctionTemplate> ctorTmpl = v8::FunctionTemplate::New(isolate);
51
+ ctorTmpl->InstanceTemplate()->SetInternalFieldCount(2);
52
+ ctorTmpl->SetClassName(ConvertToV8String(isolate, "GPURenderBundleEncoder"));
53
+
54
+ auto tmpl = ctorTmpl->InstanceTemplate();
55
+ tmpl->SetInternalFieldCount(2);
56
+
57
+ tmpl->Set(
58
+ ConvertToV8String(isolate, "draw"),
59
+ v8::FunctionTemplate::New(isolate, &Draw));
60
+
61
+ tmpl->Set(
62
+ ConvertToV8String(isolate, "drawIndexed"),
63
+ v8::FunctionTemplate::New(isolate, &DrawIndexed));
64
+
65
+ tmpl->Set(
66
+ ConvertToV8String(isolate, "drawIndexedIndirect"),
67
+ v8::FunctionTemplate::New(isolate, &DrawIndexedIndirect));
68
+
69
+ tmpl->Set(
70
+ ConvertToV8String(isolate, "drawIndirect"),
71
+ v8::FunctionTemplate::New(isolate, &DrawIndirect));
72
+
73
+
74
+ tmpl->Set(
75
+ ConvertToV8String(isolate, "finish"),
76
+ v8::FunctionTemplate::New(isolate, &Finish));
77
+
78
+ tmpl->Set(
79
+ ConvertToV8String(isolate, "insertDebugMarker"),
80
+ v8::FunctionTemplate::New(isolate, &InsertDebugMarker));
81
+
82
+ tmpl->Set(
83
+ ConvertToV8String(isolate, "popDebugGroup"),
84
+ v8::FunctionTemplate::New(isolate, &PopDebugGroup));
85
+
86
+ tmpl->Set(
87
+ ConvertToV8String(isolate, "pushDebugGroup"),
88
+ v8::FunctionTemplate::New(isolate, &PushDebugGroup));
89
+
90
+ tmpl->Set(
91
+ ConvertToV8String(isolate, "setBindGroup"),
92
+ v8::FunctionTemplate::New(isolate, &SetBindGroup));
93
+
94
+ tmpl->Set(
95
+ ConvertToV8String(isolate, "setIndexBuffer"),
96
+ v8::FunctionTemplate::New(isolate, &SetIndexBuffer));
97
+
98
+ tmpl->Set(
99
+ ConvertToV8String(isolate, "setPipeline"),
100
+ v8::FunctionTemplate::New(isolate, &SetPipeline));
101
+
102
+ tmpl->Set(
103
+ ConvertToV8String(isolate, "setVertexBuffer"),
104
+ v8::FunctionTemplate::New(isolate, &SetVertexBuffer));
105
+
106
+
107
+ cache->GPURenderBundleEncoderTmpl =
108
+ std::make_unique<v8::Persistent<v8::FunctionTemplate>>(isolate, ctorTmpl);
109
+ return ctorTmpl;
110
+ }
111
+
112
+ void GPURenderBundleEncoderImpl::Draw(const v8::FunctionCallbackInfo<v8::Value> &args) {
113
+ auto *ptr = GetPointer(args.This());
114
+ if (ptr == nullptr) {
115
+ return;
116
+ }
117
+
118
+ auto vertexCountVal = args[0];
119
+ auto instanceCountVal = args[1];
120
+ uint32_t instanceCount = 1;
121
+ uint32_t firstVertex = 0;
122
+ uint32_t firstInstance = 0;
123
+ auto firstVertexVal = args[2];
124
+ auto firstInstanceVal = args[3];
125
+
126
+ if (vertexCountVal->IsUint32()) {
127
+ auto vertexCount = vertexCountVal.As<v8::Uint32>()->Value();
128
+
129
+
130
+ if (instanceCountVal->IsUint32()) {
131
+ instanceCount = instanceCountVal.As<v8::Uint32>()->Value();
132
+ }
133
+
134
+ if (firstVertexVal->IsUint32()) {
135
+ firstVertex = firstVertexVal.As<v8::Uint32>()->Value();
136
+ }
137
+
138
+ if (firstInstanceVal->IsUint32()) {
139
+ firstInstance = firstInstanceVal.As<v8::Uint32>()->Value();
140
+ }
141
+
142
+ canvas_native_webgpu_render_bundle_encoder_draw(ptr->GetEncoder(), vertexCount,
143
+ instanceCount,
144
+ firstVertex, firstInstance);
145
+
146
+ }
147
+ }
148
+
149
+ void GPURenderBundleEncoderImpl::DrawIndexed(const v8::FunctionCallbackInfo<v8::Value> &args) {
150
+ auto *ptr = GetPointer(args.This());
151
+ if (ptr == nullptr) {
152
+ return;
153
+ }
154
+
155
+ auto isolate = args.GetIsolate();
156
+ auto context = isolate->GetCurrentContext();
157
+
158
+
159
+ uint32_t instanceCount = 1;
160
+ uint32_t firstIndex = 0;
161
+ int32_t baseVertex = 0;
162
+ uint32_t firstInstance = 0;
163
+
164
+
165
+ auto indexCountVal = args[0];
166
+ auto firstIndexVal = args[1];
167
+ auto baseVertexVal = args[2];
168
+ auto firstInstanceVal = args[3];
169
+
170
+ if (indexCountVal->IsUint32()) {
171
+
172
+
173
+ if (firstIndexVal->IsUint32()) {
174
+ firstIndex = firstIndexVal.As<v8::Uint32>()->Value();
175
+ }
176
+
177
+ if (baseVertexVal->IsInt32()) {
178
+ baseVertex = baseVertexVal.As<v8::Int32>()->Value();
179
+ }
180
+
181
+ if (firstInstanceVal->IsUint32()) {
182
+ firstInstance = firstInstanceVal.As<v8::Uint32>()->Value();
183
+ }
184
+
185
+ canvas_native_webgpu_render_bundle_encoder_draw_indexed(ptr->GetEncoder(),
186
+ indexCountVal->Uint32Value(
187
+ context).FromJust(),
188
+ instanceCount, firstIndex,
189
+ baseVertex,
190
+ firstInstance);
191
+ }
192
+
193
+
194
+ }
195
+
196
+ void
197
+ GPURenderBundleEncoderImpl::DrawIndexedIndirect(const v8::FunctionCallbackInfo<v8::Value> &args) {
198
+ auto *ptr = GetPointer(args.This());
199
+ if (ptr == nullptr) {
200
+ return;
201
+ }
202
+
203
+ auto isolate = args.GetIsolate();
204
+ auto context = isolate->GetCurrentContext();
205
+
206
+ auto indirectBufferVal = args[0];
207
+ auto indirectOffsetVal = args[1];
208
+
209
+
210
+ auto indirectBufferType = GetNativeType(indirectBufferVal);
211
+
212
+ if (indirectBufferType == NativeType::GPUBuffer) {
213
+ auto indirectBuffer = GPUBufferImpl::GetPointer(indirectBufferVal.As<v8::Object>());
214
+ uint64_t offset = (uint64_t) indirectOffsetVal->NumberValue(context).FromJust();
215
+ canvas_native_webgpu_render_bundle_encoder_draw_indexed_indirect(ptr->GetEncoder(),
216
+ indirectBuffer->GetGPUBuffer(),
217
+ offset);
218
+ }
219
+
220
+
221
+ }
222
+
223
+ void
224
+ GPURenderBundleEncoderImpl::DrawIndirect(const v8::FunctionCallbackInfo<v8::Value> &args) {
225
+ auto *ptr = GetPointer(args.This());
226
+ if (ptr == nullptr) {
227
+ return;
228
+ }
229
+
230
+ auto isolate = args.GetIsolate();
231
+ auto context = isolate->GetCurrentContext();
232
+
233
+ auto indirectBufferVal = args[0];
234
+ auto indirectOffsetVal = args[1];
235
+
236
+
237
+ auto indirectBufferType = GetNativeType(indirectBufferVal);
238
+
239
+ if (indirectBufferType == NativeType::GPUBuffer) {
240
+ auto indirectBuffer = GPUBufferImpl::GetPointer(indirectBufferVal.As<v8::Object>());
241
+ uint64_t offset = (uint64_t) indirectOffsetVal->NumberValue(context).FromJust();
242
+ canvas_native_webgpu_render_bundle_encoder_draw_indirect(ptr->GetEncoder(),
243
+ indirectBuffer->GetGPUBuffer(),
244
+ offset);
245
+ }
246
+
247
+
248
+ }
249
+
250
+ void GPURenderBundleEncoderImpl::Finish(const v8::FunctionCallbackInfo<v8::Value> &args) {
251
+ auto *ptr = GetPointer(args.This());
252
+ if (ptr == nullptr) {
253
+ return;
254
+ }
255
+
256
+ auto isolate = args.GetIsolate();
257
+ auto context = isolate->GetCurrentContext();
258
+
259
+ char *label = nullptr;
260
+ v8::Local<v8::Value> labelVal;
261
+
262
+ auto optionsVal = args[0];
263
+
264
+ if (optionsVal->IsObject()) {
265
+ auto options = optionsVal.As<v8::Object>();
266
+ options->Get(context, ConvertToV8String(isolate, "label")).ToLocal(&labelVal);
267
+
268
+ if (!labelVal.IsEmpty() && labelVal->IsString()) {
269
+ label = *v8::String::Utf8Value(isolate, labelVal);
270
+ }
271
+ }
272
+
273
+
274
+ auto bundle = canvas_native_webgpu_render_bundle_encoder_finish(ptr->GetEncoder(), label);
275
+
276
+ if (bundle != nullptr) {
277
+ auto ret = GPURenderBundleImpl::NewInstance(isolate, new GPURenderBundleImpl(bundle));
278
+ args.GetReturnValue().Set(ret);
279
+ return;
280
+ }
281
+
282
+ args.GetReturnValue().SetUndefined();
283
+ }
284
+
285
+ void
286
+ GPURenderBundleEncoderImpl::InsertDebugMarker(const v8::FunctionCallbackInfo<v8::Value> &args) {
287
+ auto *ptr = GetPointer(args.This());
288
+ if (ptr == nullptr) {
289
+ return;
290
+ }
291
+
292
+ auto isolate = args.GetIsolate();
293
+
294
+ auto markerLabelVal = args[0];
295
+ if (markerLabelVal->IsString()) {
296
+ auto markerLabel = ConvertFromV8String(isolate, markerLabelVal);
297
+ canvas_native_webgpu_render_bundle_encoder_insert_debug_marker(ptr->GetEncoder(),
298
+ markerLabel.c_str());
299
+ }
300
+ }
301
+
302
+ void GPURenderBundleEncoderImpl::PopDebugGroup(const v8::FunctionCallbackInfo<v8::Value> &args) {
303
+ auto *ptr = GetPointer(args.This());
304
+ if (ptr == nullptr) {
305
+ return;
306
+ }
307
+
308
+ canvas_native_webgpu_render_bundle_encoder_pop_debug_group(ptr->GetEncoder());
309
+ }
310
+
311
+ void GPURenderBundleEncoderImpl::PushDebugGroup(const v8::FunctionCallbackInfo<v8::Value> &args) {
312
+ auto *ptr = GetPointer(args.This());
313
+ if (ptr == nullptr) {
314
+ return;
315
+ }
316
+
317
+ auto isolate = args.GetIsolate();
318
+
319
+ auto groupLabelVal = args[0];
320
+ if (groupLabelVal->IsString()) {
321
+ auto groupLabel = ConvertFromV8String(isolate, groupLabelVal);
322
+ canvas_native_webgpu_render_bundle_encoder_push_debug_group(ptr->GetEncoder(),
323
+ groupLabel.c_str());
324
+ }
325
+ }
326
+
327
+ void GPURenderBundleEncoderImpl::SetBindGroup(const v8::FunctionCallbackInfo<v8::Value> &args) {
328
+ auto *ptr = GetPointer(args.This());
329
+ if (ptr == nullptr) {
330
+ return;
331
+ }
332
+
333
+ auto isolate = args.GetIsolate();
334
+ auto context = isolate->GetCurrentContext();
335
+
336
+ auto indexVal = args[0];
337
+ auto bindGroupVal = args[1];
338
+ auto dynamicOffsets = args[2];
339
+ auto dynamicOffsetsStart = args[3];
340
+ auto dynamicOffsetsLength = args[4];
341
+
342
+ auto type = GetNativeType(bindGroupVal);
343
+
344
+ if (type == NativeType::GPUBindGroup) {
345
+ auto index = indexVal->Uint32Value(context).FromJust();
346
+ auto bindGroup = GPUBindGroupImpl::GetPointer(bindGroupVal.As<v8::Object>());
347
+
348
+ if (dynamicOffsets->IsUint8Array()) {
349
+ auto buf = dynamicOffsets.As<v8::Uint32Array>();
350
+ auto buffer = buf->Buffer();
351
+ auto store = buffer->GetBackingStore();
352
+ auto offset = buf->ByteOffset();
353
+ auto data = static_cast<uint8_t *>(buffer->GetBackingStore()->Data()) + offset;
354
+ auto size = buf->Length();
355
+ auto start = (size_t) dynamicOffsetsStart->NumberValue(context).FromJust();
356
+ auto offset_length = (size_t) dynamicOffsetsLength->NumberValue(context).FromJust();
357
+ canvas_native_webgpu_render_bundle_encoder_set_bind_group(ptr->GetEncoder(), index,
358
+ bindGroup->GetBindGroup(),
359
+ static_cast<const uint32_t *>(static_cast<void *>(data)),
360
+ size, start, offset_length);
361
+ } else {
362
+ canvas_native_webgpu_render_bundle_encoder_set_bind_group(ptr->GetEncoder(), index,
363
+ bindGroup->GetBindGroup(),
364
+ nullptr, 0, 0, 0);
365
+ }
366
+ }
367
+
368
+ }
369
+
370
+ void GPURenderBundleEncoderImpl::SetIndexBuffer(const v8::FunctionCallbackInfo<v8::Value> &args) {
371
+ auto *ptr = GetPointer(args.This());
372
+ if (ptr == nullptr) {
373
+ return;
374
+ }
375
+
376
+ auto isolate = args.GetIsolate();
377
+ auto context = isolate->GetCurrentContext();
378
+
379
+ auto bufferVal = args[0];
380
+ auto indexFormatVal = args[1];
381
+ int64_t offset = -1;
382
+ int64_t size = -1;
383
+ auto offsetVal = args[2];
384
+ auto sizeVal = args[3];
385
+
386
+ auto type = GetNativeType(bufferVal);
387
+
388
+ if (type == NativeType::GPURenderBundleEncoder) {
389
+ auto buffer = GPUBufferImpl::GetPointer(bufferVal.As<v8::Object>());
390
+ auto indexFormat = ConvertFromV8String(isolate, indexFormatVal);
391
+ if (offsetVal->IsNumber()) {
392
+ offset = (int64_t) offsetVal.As<v8::Number>()->Value();
393
+ }
394
+
395
+ if (sizeVal->IsNumber()) {
396
+ size = (int64_t) sizeVal.As<v8::Number>()->Value();
397
+ }
398
+
399
+ if (indexFormat == "uint16") {
400
+ canvas_native_webgpu_render_bundle_encoder_set_index_buffer(ptr->GetEncoder(),
401
+ buffer->GetGPUBuffer(),
402
+ CanvasIndexFormatUint16,
403
+ offset,
404
+ size);
405
+ } else if (indexFormat == "uint32") {
406
+ canvas_native_webgpu_render_bundle_encoder_set_index_buffer(ptr->GetEncoder(),
407
+ buffer->GetGPUBuffer(),
408
+ CanvasIndexFormatUint32,
409
+ offset,
410
+ size);
411
+ }
412
+
413
+
414
+ }
415
+ }
416
+
417
+ void GPURenderBundleEncoderImpl::SetPipeline(const v8::FunctionCallbackInfo<v8::Value> &args) {
418
+ auto *ptr = GetPointer(args.This());
419
+ if (ptr == nullptr) {
420
+ return;
421
+ }
422
+
423
+ auto pipelineVal = args[0];
424
+ if (pipelineVal->IsObject()) {
425
+ auto pipeline = GPURenderPipelineImpl::GetPointer(pipelineVal.As<v8::Object>());
426
+ if (pipeline != nullptr) {
427
+ canvas_native_webgpu_render_bundle_encoder_set_pipeline(ptr->GetEncoder(),
428
+ pipeline->GetGPUPipeline());
429
+ }
430
+ }
431
+ }
432
+
433
+ void GPURenderBundleEncoderImpl::SetVertexBuffer(const v8::FunctionCallbackInfo<v8::Value> &args) {
434
+ auto *ptr = GetPointer(args.This());
435
+ if (ptr == nullptr) {
436
+ return;
437
+ }
438
+
439
+ auto slotVal = args[0];
440
+ auto bufferVal = args[1];
441
+ int64_t offset = -1;
442
+ int64_t size = -1;
443
+ auto offsetVal = args[2];
444
+ auto sizeVal = args[3];
445
+
446
+ if (slotVal->IsUint32() && bufferVal->IsObject()) {
447
+ auto slot = slotVal.As<v8::Uint32>()->Value();
448
+ auto buffer = GPUBufferImpl::GetPointer(bufferVal.As<v8::Object>());
449
+ if (buffer == nullptr) {
450
+ // todo throw ??
451
+ return;
452
+ }
453
+
454
+ if (offsetVal->IsNumber()) {
455
+ offset = (int64_t) offsetVal.As<v8::Number>()->Value();
456
+ }
457
+
458
+ if (sizeVal->IsNumber()) {
459
+ size = (int64_t) sizeVal.As<v8::Number>()->Value();
460
+ }
461
+
462
+ canvas_native_webgpu_render_bundle_encoder_set_vertex_buffer(ptr->GetEncoder(), slot,
463
+ buffer->GetGPUBuffer(), offset,
464
+ size);
465
+
466
+ }
467
+ }
468
+
469
+
@@ -0,0 +1,71 @@
1
+ //
2
+ // Created by Osei Fortune on 17/07/2024.
3
+ //
4
+
5
+ #ifndef CANVAS_ANDROID_GPURENDERBUNDLEENCODERIMPL_H
6
+ #define CANVAS_ANDROID_GPURENDERBUNDLEENCODERIMPL_H
7
+
8
+ #include "Common.h"
9
+ #include "Helpers.h"
10
+ #include "ObjectWrapperImpl.h"
11
+
12
+ class GPURenderBundleEncoderImpl : ObjectWrapperImpl {
13
+
14
+ public:
15
+ explicit GPURenderBundleEncoderImpl(const CanvasGPURenderBundleEncoder *encoder);
16
+
17
+ ~GPURenderBundleEncoderImpl() {
18
+ canvas_native_webgpu_render_bundle_encoder_release(this->GetEncoder());
19
+ }
20
+
21
+ const CanvasGPURenderBundleEncoder *GetEncoder();
22
+
23
+ static void Init(v8::Local<v8::Object> canvasModule, v8::Isolate *isolate);
24
+
25
+ static GPURenderBundleEncoderImpl *GetPointer(const v8::Local<v8::Object> &object);
26
+
27
+ static v8::Local<v8::FunctionTemplate> GetCtor(v8::Isolate *isolate);
28
+
29
+ static v8::Local<v8::Object>
30
+ NewInstance(v8::Isolate *isolate, GPURenderBundleEncoderImpl *encoder) {
31
+ auto context = isolate->GetCurrentContext();
32
+ v8::EscapableHandleScope scope(isolate);
33
+ auto object = GPURenderBundleEncoderImpl::GetCtor(isolate)->GetFunction(
34
+ context).ToLocalChecked()->NewInstance(context).ToLocalChecked();
35
+ SetNativeType(object, NativeType::GPURenderBundleEncoder);
36
+ object->SetAlignedPointerInInternalField(0, encoder);
37
+ encoder->BindFinalizer(isolate, object);
38
+ return scope.Escape(object);
39
+ }
40
+
41
+ static void Draw(const v8::FunctionCallbackInfo<v8::Value> &args);
42
+
43
+ static void DrawIndexed(const v8::FunctionCallbackInfo<v8::Value> &args);
44
+
45
+ static void DrawIndexedIndirect(const v8::FunctionCallbackInfo<v8::Value> &args);
46
+
47
+ static void DrawIndirect(const v8::FunctionCallbackInfo<v8::Value> &args);
48
+
49
+ static void Finish(const v8::FunctionCallbackInfo<v8::Value> &args);
50
+
51
+ static void InsertDebugMarker(const v8::FunctionCallbackInfo<v8::Value> &args);
52
+
53
+ static void PopDebugGroup(const v8::FunctionCallbackInfo<v8::Value> &args);
54
+
55
+ static void PushDebugGroup(const v8::FunctionCallbackInfo<v8::Value> &args);
56
+
57
+ static void SetBindGroup(const v8::FunctionCallbackInfo<v8::Value> &args);
58
+
59
+ static void SetIndexBuffer(const v8::FunctionCallbackInfo<v8::Value> &args);
60
+
61
+ static void SetPipeline(const v8::FunctionCallbackInfo<v8::Value> &args);
62
+
63
+ static void SetVertexBuffer(const v8::FunctionCallbackInfo<v8::Value> &args);
64
+
65
+
66
+ private:
67
+ const CanvasGPURenderBundleEncoder *encoder_;
68
+ };
69
+
70
+
71
+ #endif //CANVAS_ANDROID_GPURENDERBUNDLEENCODERIMPL_H
@@ -0,0 +1,53 @@
1
+ //
2
+ // Created by Osei Fortune on 18/07/2024.
3
+ //
4
+
5
+ #include "GPURenderBundleImpl.h"
6
+ #include "Caches.h"
7
+
8
+ GPURenderBundleImpl::GPURenderBundleImpl(const CanvasGPURenderBundle *bundle) : bundle_(
9
+ bundle) {}
10
+
11
+ const CanvasGPURenderBundle *GPURenderBundleImpl::GetBundle() {
12
+ return this->bundle_;
13
+ }
14
+
15
+
16
+ void GPURenderBundleImpl::Init(v8::Local<v8::Object> canvasModule, v8::Isolate *isolate) {
17
+ v8::Locker locker(isolate);
18
+ v8::Isolate::Scope isolate_scope(isolate);
19
+ v8::HandleScope handle_scope(isolate);
20
+
21
+ auto ctor = GetCtor(isolate);
22
+ auto context = isolate->GetCurrentContext();
23
+ auto func = ctor->GetFunction(context).ToLocalChecked();
24
+
25
+ canvasModule->Set(context, ConvertToV8String(isolate, "GPURenderBundle"), func).FromJust();;
26
+ }
27
+
28
+ GPURenderBundleImpl *GPURenderBundleImpl::GetPointer(const v8::Local<v8::Object> &object) {
29
+ auto ptr = object->GetAlignedPointerFromInternalField(0);
30
+ if (ptr == nullptr) {
31
+ return nullptr;
32
+ }
33
+ return static_cast<GPURenderBundleImpl *>(ptr);
34
+ }
35
+
36
+ v8::Local<v8::FunctionTemplate> GPURenderBundleImpl::GetCtor(v8::Isolate *isolate) {
37
+ auto cache = Caches::Get(isolate);
38
+ auto ctor = cache->GPURenderBundleTmpl.get();
39
+ if (ctor != nullptr) {
40
+ return ctor->Get(isolate);
41
+ }
42
+
43
+ v8::Local<v8::FunctionTemplate> ctorTmpl = v8::FunctionTemplate::New(isolate);
44
+ ctorTmpl->InstanceTemplate()->SetInternalFieldCount(2);
45
+ ctorTmpl->SetClassName(ConvertToV8String(isolate, "GPURenderBundle"));
46
+
47
+ auto tmpl = ctorTmpl->InstanceTemplate();
48
+ tmpl->SetInternalFieldCount(2);
49
+
50
+ cache->GPURenderBundleTmpl =
51
+ std::make_unique<v8::Persistent<v8::FunctionTemplate>>(isolate, ctorTmpl);
52
+ return ctorTmpl;
53
+ }
@@ -0,0 +1,45 @@
1
+ //
2
+ // Created by Osei Fortune on 18/07/2024.
3
+ //
4
+
5
+ #ifndef CANVAS_ANDROID_GPURENDERBUNDLEIMPL_H
6
+ #define CANVAS_ANDROID_GPURENDERBUNDLEIMPL_H
7
+
8
+ #include "Common.h"
9
+ #include "Helpers.h"
10
+ #include "ObjectWrapperImpl.h"
11
+
12
+ class GPURenderBundleImpl : ObjectWrapperImpl {
13
+ public:
14
+ explicit GPURenderBundleImpl(const CanvasGPURenderBundle *bundle);
15
+
16
+ ~GPURenderBundleImpl() {
17
+ canvas_native_webgpu_render_bundle_release(this->bundle_);
18
+ }
19
+
20
+ const CanvasGPURenderBundle *GetBundle();
21
+
22
+ static void Init(v8::Local<v8::Object> canvasModule, v8::Isolate *isolate);
23
+
24
+ static GPURenderBundleImpl *GetPointer(const v8::Local<v8::Object> &object);
25
+
26
+ static v8::Local<v8::FunctionTemplate> GetCtor(v8::Isolate *isolate);
27
+
28
+ static v8::Local<v8::Object> NewInstance(v8::Isolate *isolate, GPURenderBundleImpl *bundle) {
29
+ auto context = isolate->GetCurrentContext();
30
+ v8::EscapableHandleScope scope(isolate);
31
+ auto object = GPURenderBundleImpl::GetCtor(isolate)->GetFunction(
32
+ context).ToLocalChecked()->NewInstance(context).ToLocalChecked();
33
+ SetNativeType(object, NativeType::GPURenderBundle);
34
+ object->SetAlignedPointerInInternalField(0, bundle);
35
+ bundle->BindFinalizer(isolate, object);
36
+ return scope.Escape(object);
37
+ }
38
+
39
+
40
+ private:
41
+ const CanvasGPURenderBundle *bundle_;
42
+ };
43
+
44
+
45
+ #endif //CANVAS_ANDROID_GPURENDERBUNDLEIMPL_H