@nativescript/canvas 2.0.0-webgpu.2 → 2.0.0-webgpu.20

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 (250) hide show
  1. package/Canvas/common.d.ts +3 -4
  2. package/Canvas/common.js +35 -125
  3. package/Canvas/common.js.map +1 -1
  4. package/Canvas/index.android.d.ts +0 -1
  5. package/Canvas/index.android.js +45 -38
  6. package/Canvas/index.android.js.map +1 -1
  7. package/Canvas/index.d.ts +11 -3
  8. package/Canvas/index.ios.js +49 -40
  9. package/Canvas/index.ios.js.map +1 -1
  10. package/Canvas/utils.d.ts +3 -0
  11. package/Canvas/utils.js +85 -0
  12. package/Canvas/utils.js.map +1 -0
  13. package/Canvas2D/CanvasRenderingContext2D/index.d.ts +1 -0
  14. package/Canvas2D/CanvasRenderingContext2D/index.js +1 -0
  15. package/Canvas2D/CanvasRenderingContext2D/index.js.map +1 -1
  16. package/Dom/Group.d.ts +1 -2
  17. package/Dom/Group.js.map +1 -1
  18. package/Dom/Image.js +0 -1
  19. package/Dom/Image.js.map +1 -1
  20. package/Dom/Paint.d.ts +1 -1
  21. package/Dom/shapes/Path.d.ts +1 -1
  22. package/ImageAsset/index.js +77 -33
  23. package/ImageAsset/index.js.map +1 -1
  24. package/ImageBitmap/index.js +107 -20
  25. package/ImageBitmap/index.js.map +1 -1
  26. package/README.md +2 -4
  27. package/WebGL/WebGLRenderingContext/index.js +73 -31
  28. package/WebGL/WebGLRenderingContext/index.js.map +1 -1
  29. package/WebGL2/WebGL2RenderingContext/index.js +4 -4
  30. package/WebGL2/WebGL2RenderingContext/index.js.map +1 -1
  31. package/WebGPU/GPU.js +4 -3
  32. package/WebGPU/GPU.js.map +1 -1
  33. package/WebGPU/GPUAdapter.d.ts +6 -3
  34. package/WebGPU/GPUAdapter.js +31 -0
  35. package/WebGPU/GPUAdapter.js.map +1 -1
  36. package/WebGPU/GPUBindGroup.d.ts +1 -0
  37. package/WebGPU/GPUBindGroup.js +3 -0
  38. package/WebGPU/GPUBindGroup.js.map +1 -1
  39. package/WebGPU/GPUBindGroupLayout.d.ts +1 -0
  40. package/WebGPU/GPUBindGroupLayout.js +3 -0
  41. package/WebGPU/GPUBindGroupLayout.js.map +1 -1
  42. package/WebGPU/GPUBuffer.js +10 -2
  43. package/WebGPU/GPUBuffer.js.map +1 -1
  44. package/WebGPU/GPUCanvasContext.d.ts +3 -2
  45. package/WebGPU/GPUCanvasContext.js +52 -10
  46. package/WebGPU/GPUCanvasContext.js.map +1 -1
  47. package/WebGPU/GPUCommandBuffer.d.ts +1 -0
  48. package/WebGPU/GPUCommandBuffer.js +3 -0
  49. package/WebGPU/GPUCommandBuffer.js.map +1 -1
  50. package/WebGPU/GPUCommandEncoder.d.ts +3 -9
  51. package/WebGPU/GPUCommandEncoder.js +94 -41
  52. package/WebGPU/GPUCommandEncoder.js.map +1 -1
  53. package/WebGPU/GPUComputePassEncoder.d.ts +1 -0
  54. package/WebGPU/GPUComputePassEncoder.js +3 -0
  55. package/WebGPU/GPUComputePassEncoder.js.map +1 -1
  56. package/WebGPU/GPUComputePipeline.d.ts +1 -0
  57. package/WebGPU/GPUComputePipeline.js +3 -0
  58. package/WebGPU/GPUComputePipeline.js.map +1 -1
  59. package/WebGPU/GPUDevice.d.ts +17 -79
  60. package/WebGPU/GPUDevice.js +72 -91
  61. package/WebGPU/GPUDevice.js.map +1 -1
  62. package/WebGPU/GPUExternalTexture.d.ts +1 -0
  63. package/WebGPU/GPUExternalTexture.js +3 -0
  64. package/WebGPU/GPUExternalTexture.js.map +1 -1
  65. package/WebGPU/GPUPipelineLayout.d.ts +1 -0
  66. package/WebGPU/GPUPipelineLayout.js +3 -0
  67. package/WebGPU/GPUPipelineLayout.js.map +1 -1
  68. package/WebGPU/GPUQuerySet.d.ts +1 -0
  69. package/WebGPU/GPUQuerySet.js +3 -0
  70. package/WebGPU/GPUQuerySet.js.map +1 -1
  71. package/WebGPU/GPUQueue.d.ts +1 -0
  72. package/WebGPU/GPUQueue.js +45 -7
  73. package/WebGPU/GPUQueue.js.map +1 -1
  74. package/WebGPU/GPURenderBundle.d.ts +1 -0
  75. package/WebGPU/GPURenderBundle.js +3 -0
  76. package/WebGPU/GPURenderBundle.js.map +1 -1
  77. package/WebGPU/GPURenderBundleEncoder.d.ts +4 -2
  78. package/WebGPU/GPURenderBundleEncoder.js +7 -3
  79. package/WebGPU/GPURenderBundleEncoder.js.map +1 -1
  80. package/WebGPU/GPURenderPassEncoder.d.ts +2 -1
  81. package/WebGPU/GPURenderPassEncoder.js +5 -2
  82. package/WebGPU/GPURenderPassEncoder.js.map +1 -1
  83. package/WebGPU/GPURenderPipeline.d.ts +1 -0
  84. package/WebGPU/GPURenderPipeline.js +3 -0
  85. package/WebGPU/GPURenderPipeline.js.map +1 -1
  86. package/WebGPU/GPUSampler.d.ts +1 -0
  87. package/WebGPU/GPUSampler.js +3 -0
  88. package/WebGPU/GPUSampler.js.map +1 -1
  89. package/WebGPU/GPUShaderModule.d.ts +1 -1
  90. package/WebGPU/GPUShaderModule.js +2 -2
  91. package/WebGPU/GPUShaderModule.js.map +1 -1
  92. package/WebGPU/GPUTexture.d.ts +1 -0
  93. package/WebGPU/GPUTexture.js +3 -0
  94. package/WebGPU/GPUTexture.js.map +1 -1
  95. package/WebGPU/GPUTextureView.d.ts +1 -0
  96. package/WebGPU/GPUTextureView.js +3 -0
  97. package/WebGPU/GPUTextureView.js.map +1 -1
  98. package/WebGPU/Interfaces.d.ts +94 -4
  99. package/WebGPU/Types.d.ts +9 -1
  100. package/WebGPU/Utils.d.ts +6 -0
  101. package/WebGPU/Utils.js +221 -0
  102. package/WebGPU/Utils.js.map +1 -1
  103. package/angular/esm2022/index.mjs +4 -4
  104. package/angular/fesm2022/nativescript-canvas-angular.mjs +4 -4
  105. package/angular/package.json +20 -0
  106. package/package.json +1 -3
  107. package/platforms/android/canvas-release.aar +0 -0
  108. package/platforms/ios/CanvasNative.xcframework/ios-arm64/CanvasNative.framework/CanvasNative +0 -0
  109. package/platforms/ios/CanvasNative.xcframework/ios-arm64/CanvasNative.framework/Headers/CanvasNative-Swift.h +9 -0
  110. package/platforms/ios/CanvasNative.xcframework/ios-arm64/CanvasNative.framework/Headers/canvas_ios.h +7 -0
  111. package/platforms/ios/CanvasNative.xcframework/ios-arm64/CanvasNative.framework/Headers/canvas_native.h +224 -61
  112. package/platforms/ios/CanvasNative.xcframework/ios-arm64/CanvasNative.framework/Info.plist +0 -0
  113. package/platforms/ios/CanvasNative.xcframework/ios-arm64/CanvasNative.framework/Modules/CanvasNative.swiftmodule/Project/arm64-apple-ios.swiftsourceinfo +0 -0
  114. package/platforms/ios/CanvasNative.xcframework/ios-arm64/CanvasNative.framework/Modules/CanvasNative.swiftmodule/arm64-apple-ios.abi.json +6871 -5995
  115. package/platforms/ios/CanvasNative.xcframework/ios-arm64/CanvasNative.framework/Modules/CanvasNative.swiftmodule/arm64-apple-ios.private.swiftinterface +7 -0
  116. package/platforms/ios/CanvasNative.xcframework/ios-arm64/CanvasNative.framework/Modules/CanvasNative.swiftmodule/arm64-apple-ios.swiftinterface +7 -0
  117. package/platforms/ios/CanvasNative.xcframework/ios-arm64/dSYMs/CanvasNative.framework.dSYM/Contents/Resources/DWARF/CanvasNative +0 -0
  118. package/platforms/ios/CanvasNative.xcframework/ios-arm64/dSYMs/CanvasNative.framework.dSYM/Contents/Resources/Relocations/aarch64/CanvasNative.yml +656 -644
  119. package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/CanvasNative +0 -0
  120. package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/Headers/CanvasNative-Swift.h +18 -0
  121. package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/Headers/canvas_ios.h +7 -0
  122. package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/Headers/canvas_native.h +224 -61
  123. package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/Info.plist +0 -0
  124. package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/Modules/CanvasNative.swiftmodule/Project/arm64-apple-ios-simulator.swiftsourceinfo +0 -0
  125. package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/Modules/CanvasNative.swiftmodule/Project/x86_64-apple-ios-simulator.swiftsourceinfo +0 -0
  126. package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/Modules/CanvasNative.swiftmodule/arm64-apple-ios-simulator.abi.json +6871 -5995
  127. package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/Modules/CanvasNative.swiftmodule/arm64-apple-ios-simulator.private.swiftinterface +7 -0
  128. package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/Modules/CanvasNative.swiftmodule/arm64-apple-ios-simulator.swiftinterface +7 -0
  129. package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/Modules/CanvasNative.swiftmodule/x86_64-apple-ios-simulator.abi.json +6871 -5995
  130. package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/Modules/CanvasNative.swiftmodule/x86_64-apple-ios-simulator.private.swiftinterface +7 -0
  131. package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/Modules/CanvasNative.swiftmodule/x86_64-apple-ios-simulator.swiftinterface +7 -0
  132. package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/_CodeSignature/CodeResources +27 -27
  133. package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/dSYMs/CanvasNative.framework.dSYM/Contents/Resources/DWARF/CanvasNative +0 -0
  134. package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/dSYMs/CanvasNative.framework.dSYM/Contents/Resources/Relocations/aarch64/CanvasNative.yml +658 -646
  135. package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/dSYMs/CanvasNative.framework.dSYM/Contents/Resources/Relocations/x86_64/CanvasNative.yml +696 -684
  136. package/platforms/ios/src/NSOperationQueueWrapper.h +3 -1
  137. package/platforms/ios/src/NSOperationQueueWrapper.mm +41 -9
  138. package/platforms/ios/src/cpp/AsyncCallback.h +214 -0
  139. package/platforms/ios/src/cpp/CanvasJSIModule.cpp +123 -47
  140. package/platforms/ios/src/cpp/Helpers.h +2 -164
  141. package/platforms/ios/src/cpp/ImageAssetImpl.cpp +18 -26
  142. package/platforms/ios/src/cpp/ImageAssetImpl.h +3 -3
  143. package/platforms/ios/src/cpp/ImageBitmapImpl.cpp +60 -3
  144. package/platforms/ios/src/cpp/ImageBitmapImpl.h +12 -4
  145. package/platforms/ios/src/cpp/NativeType.h +87 -0
  146. package/platforms/ios/src/cpp/ObjectWrapperImpl.h +50 -0
  147. package/platforms/ios/src/cpp/PromiseCallback.h +197 -0
  148. package/platforms/ios/src/cpp/canvas2d/CanvasGradient.h +7 -6
  149. package/platforms/ios/src/cpp/canvas2d/CanvasPattern.cpp +1 -1
  150. package/platforms/ios/src/cpp/canvas2d/CanvasPattern.h +1 -1
  151. package/platforms/ios/src/cpp/canvas2d/CanvasRenderingContext2DImpl.cpp +6 -6
  152. package/platforms/ios/src/cpp/canvas2d/CanvasRenderingContext2DImpl.h +18 -13
  153. package/platforms/ios/src/cpp/canvas2d/ImageDataImpl.cpp +2 -2
  154. package/platforms/ios/src/cpp/canvas2d/ImageDataImpl.h +1 -1
  155. package/platforms/ios/src/cpp/canvas2d/MatrixImpl.cpp +10 -10
  156. package/platforms/ios/src/cpp/canvas2d/Path2D.cpp +6 -3
  157. package/platforms/ios/src/cpp/canvas2d/Path2D.h +5 -5
  158. package/platforms/ios/src/cpp/webgl/WebGLActiveInfoImpl.h +1 -1
  159. package/platforms/ios/src/cpp/webgl/WebGLBuffer.h +1 -1
  160. package/platforms/ios/src/cpp/webgl/WebGLFramebuffer.h +1 -1
  161. package/platforms/ios/src/cpp/webgl/WebGLProgram.h +3 -3
  162. package/platforms/ios/src/cpp/webgl/WebGLRenderbuffer.h +3 -3
  163. package/platforms/ios/src/cpp/webgl/WebGLRenderingContext.cpp +106 -1
  164. package/platforms/ios/src/cpp/webgl/WebGLRenderingContext.h +1 -1
  165. package/platforms/ios/src/cpp/webgl/WebGLShader.h +1 -1
  166. package/platforms/ios/src/cpp/webgl/WebGLShaderPrecisionFormatImpl.h +5 -5
  167. package/platforms/ios/src/cpp/webgl/WebGLTexture.h +3 -2
  168. package/platforms/ios/src/cpp/webgl/WebGLUniformLocation.h +2 -2
  169. package/platforms/ios/src/cpp/webgl/extensions/ANGLE_instanced_arraysImpl.h +1 -1
  170. package/platforms/ios/src/cpp/webgl/extensions/EXT_blend_minmaxImpl.h +1 -1
  171. package/platforms/ios/src/cpp/webgl/extensions/EXT_color_buffer_half_floatImpl.h +1 -1
  172. package/platforms/ios/src/cpp/webgl/extensions/EXT_disjoint_timer_queryImpl.h +1 -1
  173. package/platforms/ios/src/cpp/webgl/extensions/EXT_sRGBImpl.h +1 -1
  174. package/platforms/ios/src/cpp/webgl/extensions/EXT_shader_texture_lodImpl.h +1 -1
  175. package/platforms/ios/src/cpp/webgl/extensions/EXT_texture_filter_anisotropicImpl.h +1 -1
  176. package/platforms/ios/src/cpp/webgl/extensions/OES_element_index_uintImpl.h +2 -2
  177. package/platforms/ios/src/cpp/webgl/extensions/OES_fbo_render_mipmap.h +5 -5
  178. package/platforms/ios/src/cpp/webgl/extensions/OES_standard_derivativesImpl.h +1 -1
  179. package/platforms/ios/src/cpp/webgl/extensions/OES_texture_floatImpl.h +1 -1
  180. package/platforms/ios/src/cpp/webgl/extensions/OES_texture_float_linearImpl.h +1 -1
  181. package/platforms/ios/src/cpp/webgl/extensions/OES_texture_half_floatImpl.h +1 -1
  182. package/platforms/ios/src/cpp/webgl/extensions/OES_texture_half_float_linearImpl.h +1 -1
  183. package/platforms/ios/src/cpp/webgl/extensions/OES_vertex_array_objectImpl.h +1 -1
  184. package/platforms/ios/src/cpp/webgl/extensions/WEBGL_color_buffer_floatImpl.h +1 -1
  185. package/platforms/ios/src/cpp/webgl/extensions/WEBGL_compressed_texture_atcImpl.h +1 -1
  186. package/platforms/ios/src/cpp/webgl/extensions/WEBGL_compressed_texture_etc1Impl.h +1 -1
  187. package/platforms/ios/src/cpp/webgl/extensions/WEBGL_compressed_texture_etcImpl.h +2 -2
  188. package/platforms/ios/src/cpp/webgl/extensions/WEBGL_compressed_texture_pvrtcImpl.h +1 -1
  189. package/platforms/ios/src/cpp/webgl/extensions/WEBGL_compressed_texture_s3tcImpl.h +1 -1
  190. package/platforms/ios/src/cpp/webgl/extensions/WEBGL_compressed_texture_s3tc_srgbImpl.h +1 -1
  191. package/platforms/ios/src/cpp/webgl/extensions/WEBGL_depth_textureImpl.h +1 -1
  192. package/platforms/ios/src/cpp/webgl/extensions/WEBGL_draw_buffersImpl.h +1 -1
  193. package/platforms/ios/src/cpp/webgl/extensions/WEBGL_lose_contextImpl.h +1 -1
  194. package/platforms/ios/src/cpp/webgl2/WebGL2RenderingContext.h +1 -1
  195. package/platforms/ios/src/cpp/webgl2/WebGLQuery.h +1 -1
  196. package/platforms/ios/src/cpp/webgl2/WebGLSampler.h +1 -1
  197. package/platforms/ios/src/cpp/webgl2/WebGLSyncImpl.h +1 -1
  198. package/platforms/ios/src/cpp/webgl2/WebGLTransformFeedback.h +1 -1
  199. package/platforms/ios/src/cpp/webgl2/WebGLVertexArrayObject.h +2 -2
  200. package/platforms/ios/src/cpp/webgpu/GPUAdapterImpl.cpp +142 -73
  201. package/platforms/ios/src/cpp/webgpu/GPUAdapterImpl.h +1 -1
  202. package/platforms/ios/src/cpp/webgpu/GPUAdapterInfoImpl.cpp +1 -1
  203. package/platforms/ios/src/cpp/webgpu/GPUAdapterInfoImpl.h +1 -1
  204. package/platforms/ios/src/cpp/webgpu/GPUBindGroupImpl.cpp +32 -6
  205. package/platforms/ios/src/cpp/webgpu/GPUBindGroupImpl.h +5 -2
  206. package/platforms/ios/src/cpp/webgpu/GPUBindGroupLayoutImpl.cpp +27 -1
  207. package/platforms/ios/src/cpp/webgpu/GPUBindGroupLayoutImpl.h +4 -1
  208. package/platforms/ios/src/cpp/webgpu/GPUBufferImpl.cpp +80 -32
  209. package/platforms/ios/src/cpp/webgpu/GPUBufferImpl.h +8 -4
  210. package/platforms/ios/src/cpp/webgpu/GPUCanvasContextImpl.cpp +11 -5
  211. package/platforms/ios/src/cpp/webgpu/GPUCanvasContextImpl.h +1 -1
  212. package/platforms/ios/src/cpp/webgpu/GPUCommandBufferImpl.cpp +29 -2
  213. package/platforms/ios/src/cpp/webgpu/GPUCommandBufferImpl.h +4 -1
  214. package/platforms/ios/src/cpp/webgpu/GPUCommandEncoderImpl.cpp +101 -106
  215. package/platforms/ios/src/cpp/webgpu/GPUCommandEncoderImpl.h +5 -1
  216. package/platforms/ios/src/cpp/webgpu/GPUComputePassEncoderImpl.cpp +42 -14
  217. package/platforms/ios/src/cpp/webgpu/GPUComputePassEncoderImpl.h +4 -1
  218. package/platforms/ios/src/cpp/webgpu/GPUComputePipelineImpl.cpp +26 -1
  219. package/platforms/ios/src/cpp/webgpu/GPUComputePipelineImpl.h +3 -1
  220. package/platforms/ios/src/cpp/webgpu/GPUDeviceImpl.cpp +1683 -733
  221. package/platforms/ios/src/cpp/webgpu/GPUDeviceImpl.h +3 -1
  222. package/platforms/ios/src/cpp/webgpu/GPUImpl.cpp +53 -39
  223. package/platforms/ios/src/cpp/webgpu/GPUImpl.h +2 -2
  224. package/platforms/ios/src/cpp/webgpu/GPULabel.h +33 -0
  225. package/platforms/ios/src/cpp/webgpu/GPUPipelineLayoutImpl.cpp +27 -1
  226. package/platforms/ios/src/cpp/webgpu/GPUPipelineLayoutImpl.h +8 -5
  227. package/platforms/ios/src/cpp/webgpu/GPUQuerySetImpl.cpp +2 -3
  228. package/platforms/ios/src/cpp/webgpu/GPUQuerySetImpl.h +2 -2
  229. package/platforms/ios/src/cpp/webgpu/GPUQueueImpl.cpp +88 -36
  230. package/platforms/ios/src/cpp/webgpu/GPUQueueImpl.h +4 -1
  231. package/platforms/ios/src/cpp/webgpu/GPURenderBundleEncoderImpl.cpp +43 -14
  232. package/platforms/ios/src/cpp/webgpu/GPURenderBundleEncoderImpl.h +4 -1
  233. package/platforms/ios/src/cpp/webgpu/GPURenderBundleImpl.cpp +26 -1
  234. package/platforms/ios/src/cpp/webgpu/GPURenderBundleImpl.h +4 -1
  235. package/platforms/ios/src/cpp/webgpu/GPURenderPassEncoderImpl.cpp +32 -6
  236. package/platforms/ios/src/cpp/webgpu/GPURenderPassEncoderImpl.h +4 -1
  237. package/platforms/ios/src/cpp/webgpu/GPURenderPipelineImpl.cpp +26 -1
  238. package/platforms/ios/src/cpp/webgpu/GPURenderPipelineImpl.h +4 -1
  239. package/platforms/ios/src/cpp/webgpu/GPUSamplerImpl.cpp +27 -1
  240. package/platforms/ios/src/cpp/webgpu/GPUSamplerImpl.h +5 -2
  241. package/platforms/ios/src/cpp/webgpu/GPUShaderModuleImpl.cpp +25 -1
  242. package/platforms/ios/src/cpp/webgpu/GPUShaderModuleImpl.h +5 -2
  243. package/platforms/ios/src/cpp/webgpu/GPUSupportedLimitsImpl.cpp +2 -2
  244. package/platforms/ios/src/cpp/webgpu/GPUSupportedLimitsImpl.h +2 -2
  245. package/platforms/ios/src/cpp/webgpu/GPUTextureImpl.cpp +34 -8
  246. package/platforms/ios/src/cpp/webgpu/GPUTextureImpl.h +6 -4
  247. package/platforms/ios/src/cpp/webgpu/GPUTextureViewImpl.cpp +27 -1
  248. package/platforms/ios/src/cpp/webgpu/GPUTextureViewImpl.h +5 -2
  249. package/platforms/ios/src/cpp/webgpu/GPUUtils.h +511 -0
  250. package/utils.d.ts +1 -1
@@ -4,7 +4,7 @@
4
4
 
5
5
  #include "GPUAdapterImpl.h"
6
6
  #include "Caches.h"
7
-
7
+ #include "GPULabel.h"
8
8
  GPUAdapterImpl::GPUAdapterImpl(const CanvasGPUAdapter *adapter) : adapter_(adapter) {}
9
9
 
10
10
  const CanvasGPUAdapter *GPUAdapterImpl::GetGPUAdapter() {
@@ -61,7 +61,6 @@ v8::Local<v8::FunctionTemplate> GPUAdapterImpl::GetCtor(v8::Isolate *isolate) {
61
61
  GetLimits
62
62
  );
63
63
 
64
-
65
64
  tmpl->Set(
66
65
  ConvertToV8String(isolate, "requestAdapterInfo"),
67
66
  v8::FunctionTemplate::New(isolate, &RequestAdapterInfo));
@@ -90,19 +89,19 @@ GPUAdapterImpl::GetFeatures(v8::Local<v8::Name> name,
90
89
 
91
90
  auto len = canvas_native_string_buffer_get_length(features);
92
91
 
93
- auto map = v8::Map::New(isolate);
92
+ auto set = v8::Set::New(isolate);
94
93
  for (int i = 0; i < len; ++i) {
95
94
  auto item = canvas_native_string_buffer_get_value_at(features, i);
96
95
  if (item != nullptr) {
97
- auto keyValue = ConvertToV8OneByteString(isolate, (char *) item);
98
- map->Set(context, keyValue, keyValue);
96
+ auto keyValue = ConvertToV8String(isolate, (char *) item);
97
+ set->Add(context, keyValue);
99
98
  canvas_native_string_destroy(item);
100
99
  }
101
100
 
102
101
  }
103
102
  canvas_native_string_buffer_release(features);
104
103
 
105
- info.GetReturnValue().Set(map);
104
+ info.GetReturnValue().Set(set);
106
105
 
107
106
  return;
108
107
  }
@@ -158,6 +157,27 @@ void GPUAdapterImpl::RequestAdapterInfo(const v8::FunctionCallbackInfo<v8::Value
158
157
 
159
158
  }
160
159
 
160
+ struct RequestData {
161
+ char *error_;
162
+ const CanvasGPUDevice *device_;
163
+ char **required_features_data_;
164
+ size_t required_features_data_size;
165
+
166
+ ~RequestData() {
167
+ if (required_features_data_ != nullptr) {
168
+ for (size_t i = 0; i < required_features_data_size; ++i) {
169
+ delete[] required_features_data_[i];
170
+ }
171
+ delete[] required_features_data_;
172
+ }
173
+
174
+ if (error_ != nullptr) {
175
+ canvas_native_string_destroy(error_);
176
+ error_ = nullptr;
177
+ }
178
+ }
179
+ };
180
+
161
181
  void GPUAdapterImpl::RequestDevice(const v8::FunctionCallbackInfo<v8::Value> &args) {
162
182
  GPUAdapterImpl *ptr = GetPointer(args.This());
163
183
  auto isolate = args.GetIsolate();
@@ -170,9 +190,9 @@ void GPUAdapterImpl::RequestDevice(const v8::FunctionCallbackInfo<v8::Value> &ar
170
190
  return;
171
191
  }
172
192
 
173
- v8::Global<v8::Function> func(isolate, cb.As<v8::Function>());
193
+ auto func = cb.As<v8::Function>();
174
194
 
175
- std::string label;
195
+ GPULabel label;
176
196
 
177
197
  std::vector<std::string> required_features_buf;
178
198
 
@@ -183,10 +203,9 @@ void GPUAdapterImpl::RequestDevice(const v8::FunctionCallbackInfo<v8::Value> &ar
183
203
  v8::Local<v8::Value> labelValue;
184
204
  options->Get(context, ConvertToV8String(isolate, "label")).ToLocal(
185
205
  &labelValue);
206
+
207
+ label = GPULabel(isolate, labelValue);
186
208
 
187
- if (!labelValue.IsEmpty() && labelValue->IsString()) {
188
- label = ConvertFromV8String(isolate, labelValue);
189
- }
190
209
 
191
210
  v8::Local<v8::Value> requiredFeaturesValue;
192
211
 
@@ -194,11 +213,9 @@ void GPUAdapterImpl::RequestDevice(const v8::FunctionCallbackInfo<v8::Value> &ar
194
213
  &requiredFeaturesValue);
195
214
 
196
215
 
197
- if (!requiredFeaturesValue.IsEmpty() && requiredFeaturesValue->IsSet()) {
198
- v8::Local<v8::Set> requiredFeaturesSet = requiredFeaturesValue.As<v8::Set>();
199
- v8::Local<v8::Array> requiredFeatures = requiredFeaturesSet->AsArray();
216
+ if (!requiredFeaturesValue.IsEmpty() && requiredFeaturesValue->IsArray()) {
217
+ v8::Local<v8::Array> requiredFeatures = requiredFeaturesValue.As<v8::Array>();
200
218
  auto len = requiredFeatures->Length();
201
-
202
219
  for (int i = 0; i < len; i++) {
203
220
  auto item = requiredFeatures->Get(context, i);
204
221
  if (!item.IsEmpty()) {
@@ -210,7 +227,6 @@ void GPUAdapterImpl::RequestDevice(const v8::FunctionCallbackInfo<v8::Value> &ar
210
227
  }
211
228
  }
212
229
 
213
-
214
230
  v8::Local<v8::Value> limitsValue;
215
231
 
216
232
  options->Get(context, ConvertToV8String(isolate, "requiredLimits")).ToLocal(
@@ -228,75 +244,128 @@ void GPUAdapterImpl::RequestDevice(const v8::FunctionCallbackInfo<v8::Value> &ar
228
244
  size_t required_features_data_length = required_features_buf.size();
229
245
 
230
246
  if (required_features_data_length > 0) {
231
- required_features_data = new char *[required_features_data_length + 1];
247
+ required_features_data = new char *[required_features_data_length];
232
248
 
233
249
  for (size_t i = 0; i < required_features_data_length; ++i) {
234
- std::strcpy(required_features_data[i], required_features_buf[i].c_str());
250
+ required_features_data[i] = new char[required_features_buf[i].size() + 1];
251
+ auto src = required_features_buf[i].c_str();
252
+ std::strcpy(required_features_data[i], src);
235
253
  }
236
254
  }
237
255
 
238
-
239
256
  auto callback = new AsyncCallback{
240
257
  isolate,
241
- std::move(func),
242
- static_cast<void *>(required_features_data)
258
+ func,
259
+ [](bool done, void *data) {
260
+ if (data != nullptr) {
261
+ auto async_data = static_cast<AsyncCallback *>(data);
262
+ auto func = async_data->inner_.get();
263
+ if (func != nullptr && func->isolate_ != nullptr) {
264
+ v8::Isolate *isolate = func->isolate_;
265
+ v8::Locker locker(isolate);
266
+ v8::Isolate::Scope isolate_scope(isolate);
267
+ v8::HandleScope handle_scope(isolate);
268
+ v8::Local<v8::Function> callback = func->callback_.Get(
269
+ isolate);
270
+ v8::Local<v8::Context> context = callback->GetCreationContextChecked();
271
+ v8::Context::Scope context_scope(context);
272
+
273
+ RequestData *requestData = nullptr;
274
+ if (func->data != nullptr) {
275
+ requestData = static_cast<RequestData *>(func->data);
276
+ }
277
+
278
+ if (requestData == nullptr) {
279
+ // Should never happen
280
+ v8::Local<v8::Value> args[1] = {
281
+ v8::Exception::Error(
282
+ ConvertToV8String(isolate, "Internal Error"))};
283
+
284
+ callback->Call(context, context->Global(),
285
+ 1,
286
+ args); // ignore JS return value
287
+ delete static_cast<AsyncCallback *>(data);
288
+
289
+ return;
290
+ }
291
+
292
+ if (requestData->error_ != nullptr) {
293
+ v8::Local<v8::Value> args[1] = {
294
+ v8::Exception::Error(
295
+ ConvertToV8String(isolate,
296
+ requestData->error_))};
297
+
298
+ callback->Call(context, context->Global(),
299
+ 1,
300
+ args); // ignore JS return value
301
+
302
+
303
+ } else {
304
+
305
+ auto impl = new GPUDeviceImpl(requestData->device_);
306
+ auto ret = GPUDeviceImpl::NewInstance(
307
+ isolate, impl);
308
+
309
+ v8::Local<v8::Value> args[2] = {
310
+ v8::Null(isolate), ret};
311
+
312
+
313
+ callback->Call(context, context->Global(),
314
+ 2,
315
+ args); // ignore JS return value
316
+ }
317
+
318
+ if (requestData != nullptr) {
319
+ delete requestData;
320
+ requestData = nullptr;
321
+ }
322
+
323
+ delete static_cast<AsyncCallback *>(data);
324
+ }
325
+ }
326
+ }
243
327
  };
244
328
 
245
- canvas_native_webgpu_adapter_request_device(ptr->GetGPUAdapter(),
246
- label.empty() ? nullptr : label.c_str(),
247
- required_features_data, required_features_data_length,
248
- limits,
249
- [](char *error, const CanvasGPUDevice *device, void *data) {
250
- if (data != nullptr) {
251
- auto func = static_cast<AsyncCallback *>(data);
252
- if (func->isolate != nullptr) {
253
- v8::Isolate *isolate = func->isolate;
254
- v8::Locker locker(isolate);
255
- v8::Isolate::Scope isolate_scope(isolate);
256
- v8::HandleScope handle_scope(isolate);
257
- v8::Local<v8::Function> callback = func->callback.Get(
258
- isolate);
259
- v8::Local<v8::Context> context = callback->GetCreationContextChecked();
260
- v8::Context::Scope context_scope(context);
261
-
262
- if (func->data != nullptr) {
263
- delete[] static_cast<char **>(func->data);
264
- func->data = nullptr;
265
- }
266
-
267
- if (error != nullptr) {
268
- v8::Local<v8::Value> args[1] = {
269
- v8::Exception::Error(
270
- ConvertToV8String(isolate,
271
- error))};
272
-
273
- canvas_native_string_destroy(error);
274
-
275
- callback->Call(context, context->Global(),
276
- 1,
277
- args); // ignore JS return value
278
- delete static_cast<AsyncCallback *>(data);
279
- } else {
329
+ auto inner = callback->inner_.get();
280
330
 
281
- auto impl = new GPUDeviceImpl(device);
282
- auto ret = GPUDeviceImpl::NewInstance(
283
- isolate, impl);
284
-
285
-
286
- v8::Local<v8::Value> args[2] = {
287
- v8::Null(isolate), ret};
288
-
289
-
290
- callback->Call(context, context->Global(),
291
- 2,
292
- args); // ignore JS return value
331
+ if (required_features_data != nullptr) {
332
+ inner->data = new RequestData{
333
+ nullptr,
334
+ nullptr,
335
+ required_features_data,
336
+ required_features_data_length
337
+ };
338
+ }
293
339
 
294
- delete static_cast<AsyncCallback *>(data);
340
+ callback->prepare();
295
341
 
342
+ canvas_native_webgpu_adapter_request_device(ptr->GetGPUAdapter(),
343
+ *label,
344
+ required_features_data,
345
+ required_features_data_length,
346
+ limits,
347
+ [](char *error, const CanvasGPUDevice *device,
348
+ void *data) {
349
+ if (data != nullptr) {
350
+ auto async_data = static_cast<AsyncCallback *>(data);
351
+ auto inner = async_data->inner_.get();
352
+ if (inner != nullptr) {
353
+ if (inner->data == nullptr) {
354
+ inner->data = new RequestData{
355
+ error,
356
+ device
357
+ };
358
+ } else {
359
+ auto request_data = static_cast<RequestData *>(inner->data);
360
+ request_data->error_ = error;
361
+ request_data->device_ = device;
362
+ delete request_data->required_features_data_;
363
+ request_data->required_features_data_ = nullptr;
364
+ }
365
+
366
+ async_data->execute(true);
367
+ }
296
368
  }
297
- }
298
- }
299
- }, callback);
300
-
369
+ }, callback);
301
370
 
302
371
  }
@@ -33,7 +33,7 @@ public:
33
33
  v8::EscapableHandleScope scope(isolate);
34
34
  auto object = GPUAdapterImpl::GetCtor(isolate)->GetFunction(
35
35
  context).ToLocalChecked()->NewInstance(context).ToLocalChecked();
36
- SetNativeType(object, NativeType::GPUAdapter);
36
+ SetNativeType(adapter, NativeType::GPUAdapter);
37
37
  object->SetAlignedPointerInInternalField(0, adapter);
38
38
  adapter->BindFinalizer(isolate, object);
39
39
  return scope.Escape(object);
@@ -21,7 +21,7 @@ void GPUAdapterInfoImpl::Init(v8::Local<v8::Object> canvasModule, v8::Isolate *i
21
21
  auto context = isolate->GetCurrentContext();
22
22
  auto func = ctor->GetFunction(context).ToLocalChecked();
23
23
 
24
- canvasModule->Set(context, ConvertToV8String(isolate, "GPUAdapterInfo"), func).FromJust();;
24
+ canvasModule->Set(context, ConvertToV8String(isolate, "GPUAdapterInfo"), func).FromJust();
25
25
  }
26
26
 
27
27
  GPUAdapterInfoImpl *GPUAdapterInfoImpl::GetPointer(const v8::Local<v8::Object> &object) {
@@ -30,7 +30,7 @@ public:
30
30
  v8::EscapableHandleScope scope(isolate);
31
31
  auto object = GPUAdapterInfoImpl::GetCtor(isolate)->GetFunction(
32
32
  context).ToLocalChecked()->NewInstance(context).ToLocalChecked();
33
- SetNativeType(object, NativeType::GPUAdapterInfo);
33
+ SetNativeType(info, NativeType::GPUAdapterInfo);
34
34
  object->SetAlignedPointerInInternalField(0, info);
35
35
  info->BindFinalizer(isolate, object);
36
36
  return scope.Escape(object);
@@ -13,7 +13,7 @@ const CanvasGPUBindGroup *GPUBindGroupImpl::GetBindGroup() {
13
13
  }
14
14
 
15
15
 
16
- void GPUBindGroupImpl::Init(v8::Local <v8::Object> canvasModule, v8::Isolate *isolate) {
16
+ void GPUBindGroupImpl::Init(v8::Local<v8::Object> canvasModule, v8::Isolate *isolate) {
17
17
  v8::Locker locker(isolate);
18
18
  v8::Isolate::Scope isolate_scope(isolate);
19
19
  v8::HandleScope handle_scope(isolate);
@@ -22,10 +22,10 @@ void GPUBindGroupImpl::Init(v8::Local <v8::Object> canvasModule, v8::Isolate *is
22
22
  auto context = isolate->GetCurrentContext();
23
23
  auto func = ctor->GetFunction(context).ToLocalChecked();
24
24
 
25
- canvasModule->Set(context, ConvertToV8String(isolate, "GPUBindGroup"), func).FromJust();;
25
+ canvasModule->Set(context, ConvertToV8String(isolate, "GPUBindGroup"), func).FromJust();
26
26
  }
27
27
 
28
- GPUBindGroupImpl *GPUBindGroupImpl::GetPointer(const v8::Local <v8::Object> &object) {
28
+ GPUBindGroupImpl *GPUBindGroupImpl::GetPointer(const v8::Local<v8::Object> &object) {
29
29
  auto ptr = object->GetAlignedPointerFromInternalField(0);
30
30
  if (ptr == nullptr) {
31
31
  return nullptr;
@@ -33,21 +33,47 @@ GPUBindGroupImpl *GPUBindGroupImpl::GetPointer(const v8::Local <v8::Object> &obj
33
33
  return static_cast<GPUBindGroupImpl *>(ptr);
34
34
  }
35
35
 
36
- v8::Local <v8::FunctionTemplate> GPUBindGroupImpl::GetCtor(v8::Isolate *isolate) {
36
+ v8::Local<v8::FunctionTemplate> GPUBindGroupImpl::GetCtor(v8::Isolate *isolate) {
37
37
  auto cache = Caches::Get(isolate);
38
38
  auto ctor = cache->GPUBindGroupTmpl.get();
39
39
  if (ctor != nullptr) {
40
40
  return ctor->Get(isolate);
41
41
  }
42
42
 
43
- v8::Local <v8::FunctionTemplate> ctorTmpl = v8::FunctionTemplate::New(isolate);
43
+ v8::Local<v8::FunctionTemplate> ctorTmpl = v8::FunctionTemplate::New(isolate);
44
44
  ctorTmpl->InstanceTemplate()->SetInternalFieldCount(2);
45
45
  ctorTmpl->SetClassName(ConvertToV8String(isolate, "GPUBindGroup"));
46
46
 
47
47
  auto tmpl = ctorTmpl->InstanceTemplate();
48
48
  tmpl->SetInternalFieldCount(2);
49
49
 
50
+ tmpl->SetLazyDataProperty(
51
+ ConvertToV8String(isolate, "label"),
52
+ GetLabel
53
+ );
54
+
50
55
  cache->GPUBindGroupTmpl =
51
- std::make_unique < v8::Persistent < v8::FunctionTemplate >> (isolate, ctorTmpl);
56
+ std::make_unique<v8::Persistent<v8::FunctionTemplate >>(isolate, ctorTmpl);
52
57
  return ctorTmpl;
53
58
  }
59
+
60
+
61
+ void
62
+ GPUBindGroupImpl::GetLabel(v8::Local<v8::Name> name,
63
+ const v8::PropertyCallbackInfo<v8::Value> &info) {
64
+ auto ptr = GetPointer(info.This());
65
+ if (ptr != nullptr) {
66
+ auto label = canvas_native_webgpu_bind_group_get_label(ptr->group_);
67
+ if (label == nullptr) {
68
+ info.GetReturnValue().SetEmptyString();
69
+ return;
70
+ }
71
+ info.GetReturnValue().Set(
72
+ ConvertToV8String(info.GetIsolate(), label)
73
+ );
74
+ canvas_native_string_destroy(label);
75
+ return;
76
+ }
77
+
78
+ info.GetReturnValue().SetEmptyString();
79
+ }
@@ -11,7 +11,7 @@
11
11
 
12
12
  class GPUBindGroupImpl : ObjectWrapperImpl {
13
13
  public:
14
- GPUBindGroupImpl(const CanvasGPUBindGroup *group);
14
+ explicit GPUBindGroupImpl(const CanvasGPUBindGroup *group);
15
15
 
16
16
  ~GPUBindGroupImpl() {
17
17
  canvas_native_webgpu_bind_group_release(this->GetBindGroup());
@@ -31,12 +31,15 @@ public:
31
31
  v8::EscapableHandleScope scope(isolate);
32
32
  auto object = GPUBindGroupImpl::GetCtor(isolate)->GetFunction(
33
33
  context).ToLocalChecked()->NewInstance(context).ToLocalChecked();
34
- SetNativeType(object, NativeType::GPUBindGroup);
34
+ SetNativeType(groupLayout, NativeType::GPUBindGroup);
35
35
  object->SetAlignedPointerInInternalField(0, groupLayout);
36
36
  groupLayout->BindFinalizer(isolate, object);
37
37
  return scope.Escape(object);
38
38
  }
39
39
 
40
+ static void GetLabel(v8::Local<v8::Name> name,
41
+ const v8::PropertyCallbackInfo<v8::Value> &info);
42
+
40
43
  private:
41
44
  const CanvasGPUBindGroup *group_;
42
45
  };
@@ -22,7 +22,7 @@ void GPUBindGroupLayoutImpl::Init(v8::Local<v8::Object> canvasModule, v8::Isolat
22
22
  auto context = isolate->GetCurrentContext();
23
23
  auto func = ctor->GetFunction(context).ToLocalChecked();
24
24
 
25
- canvasModule->Set(context, ConvertToV8String(isolate, "GPUBindGroupLayout"), func).FromJust();;
25
+ canvasModule->Set(context, ConvertToV8String(isolate, "GPUBindGroupLayout"), func).FromJust();
26
26
  }
27
27
 
28
28
  GPUBindGroupLayoutImpl *GPUBindGroupLayoutImpl::GetPointer(const v8::Local<v8::Object> &object) {
@@ -47,7 +47,33 @@ v8::Local<v8::FunctionTemplate> GPUBindGroupLayoutImpl::GetCtor(v8::Isolate *iso
47
47
  auto tmpl = ctorTmpl->InstanceTemplate();
48
48
  tmpl->SetInternalFieldCount(2);
49
49
 
50
+ tmpl->SetLazyDataProperty(
51
+ ConvertToV8String(isolate, "label"),
52
+ GetLabel
53
+ );
54
+
50
55
  cache->GPUBindGroupLayoutTmpl =
51
56
  std::make_unique<v8::Persistent<v8::FunctionTemplate>>(isolate, ctorTmpl);
52
57
  return ctorTmpl;
53
58
  }
59
+
60
+
61
+ void
62
+ GPUBindGroupLayoutImpl::GetLabel(v8::Local<v8::Name> name,
63
+ const v8::PropertyCallbackInfo<v8::Value> &info) {
64
+ auto ptr = GetPointer(info.This());
65
+ if (ptr != nullptr) {
66
+ auto label = canvas_native_webgpu_bind_group_layout_get_label(ptr->groupLayout_);
67
+ if (label == nullptr) {
68
+ info.GetReturnValue().SetEmptyString();
69
+ return;
70
+ }
71
+ info.GetReturnValue().Set(
72
+ ConvertToV8String(info.GetIsolate(), label)
73
+ );
74
+ canvas_native_string_destroy(label);
75
+ return;
76
+ }
77
+
78
+ info.GetReturnValue().SetEmptyString();
79
+ }
@@ -31,12 +31,15 @@ public:
31
31
  v8::EscapableHandleScope scope(isolate);
32
32
  auto object = GPUBindGroupLayoutImpl::GetCtor(isolate)->GetFunction(
33
33
  context).ToLocalChecked()->NewInstance(context).ToLocalChecked();
34
- SetNativeType(object, NativeType::GPUBindGroupLayout);
34
+ SetNativeType(groupLayout, NativeType::GPUBindGroupLayout);
35
35
  object->SetAlignedPointerInInternalField(0, groupLayout);
36
36
  groupLayout->BindFinalizer(isolate, object);
37
37
  return scope.Escape(object);
38
38
  }
39
39
 
40
+ static void GetLabel(v8::Local<v8::Name> name,
41
+ const v8::PropertyCallbackInfo<v8::Value> &info);
42
+
40
43
  private:
41
44
  const CanvasGPUBindGroupLayout *groupLayout_;
42
45
  };
@@ -21,7 +21,7 @@ void GPUBufferImpl::Init(v8::Local<v8::Object> canvasModule, v8::Isolate *isolat
21
21
  auto context = isolate->GetCurrentContext();
22
22
  auto func = ctor->GetFunction(context).ToLocalChecked();
23
23
 
24
- canvasModule->Set(context, ConvertToV8String(isolate, "GPUBuffer"), func).FromJust();;
24
+ canvasModule->Set(context, ConvertToV8String(isolate, "GPUBuffer"), func).FromJust();
25
25
  }
26
26
 
27
27
  GPUBufferImpl *GPUBufferImpl::GetPointer(const v8::Local<v8::Object> &object) {
@@ -75,6 +75,11 @@ v8::Local<v8::FunctionTemplate> GPUBufferImpl::GetCtor(v8::Isolate *isolate) {
75
75
  ConvertToV8String(isolate, "getMappedRange"),
76
76
  v8::FunctionTemplate::New(isolate, &GetMappedRange));
77
77
 
78
+ tmpl->SetLazyDataProperty(
79
+ ConvertToV8String(isolate, "label"),
80
+ GetLabel
81
+ );
82
+
78
83
 
79
84
  cache->GPUBufferTmpl =
80
85
  std::make_unique<v8::Persistent<v8::FunctionTemplate>>(isolate, ctorTmpl);
@@ -127,12 +132,17 @@ void GPUBufferImpl::UnMap(const v8::FunctionCallbackInfo<v8::Value> &args) {
127
132
  canvas_native_webgpu_buffer_unmap(ptr->GetGPUBuffer());
128
133
  }
129
134
 
135
+ struct MapAsyncData {
136
+ enum CanvasGPUErrorType type;
137
+ char* error;
138
+ };
130
139
 
131
140
  void GPUBufferImpl::MapAsync(const v8::FunctionCallbackInfo<v8::Value> &args) {
132
141
  GPUBufferImpl *ptr = GetPointer(args.This());
133
142
  if (ptr == nullptr) {
134
143
  return;
135
144
  }
145
+
136
146
  auto isolate = args.GetIsolate();
137
147
  auto context = isolate->GetCurrentContext();
138
148
  auto mode = args[0]->Int32Value(context).ToChecked();
@@ -154,42 +164,59 @@ void GPUBufferImpl::MapAsync(const v8::FunctionCallbackInfo<v8::Value> &args) {
154
164
  auto resolver = v8::Promise::Resolver::New(isolate->GetCurrentContext()).ToLocalChecked();
155
165
  args.GetReturnValue().Set(resolver->GetPromise());
156
166
 
157
- v8::Global<v8::Promise::Resolver> promise(isolate, resolver);
158
167
  auto callback = new PromiseCallback{
159
168
  isolate,
160
- std::move(promise)
169
+ resolver,
170
+ [](bool done, void *data){
171
+ auto async_data = static_cast<PromiseCallback *>(data);
172
+ auto func = async_data->inner_.get();
173
+ if (func != nullptr && func->isolate_ != nullptr) {
174
+ v8::Isolate *isolate = func->isolate_;
175
+ v8::Locker locker(isolate);
176
+ v8::Isolate::Scope isolate_scope(
177
+ isolate);
178
+ v8::HandleScope handle_scope(
179
+ isolate);
180
+ v8::Local<v8::Promise::Resolver> callback = func->callback_.Get(
181
+ isolate);
182
+ v8::Local<v8::Context> context = callback->GetCreationContextChecked();
183
+ v8::Context::Scope context_scope(
184
+ context);
185
+
186
+
187
+ if (func->data == nullptr) {
188
+ callback->Resolve(context, v8::Undefined(isolate));
189
+ } else {
190
+ auto errorData = static_cast<MapAsyncData*>(func->data);
191
+ callback->Reject(context,
192
+ v8::Exception::Error(
193
+ ConvertToV8String(
194
+ isolate,
195
+ errorData->error)));
196
+ canvas_native_string_destroy(
197
+ errorData->error);
198
+ delete errorData;
199
+ func->data = nullptr;
200
+ }
201
+ }
202
+ delete static_cast<PromiseCallback *>(data);
203
+ }
161
204
  };
162
- canvas_native_webgpu_buffer_map_async(ptr->GetGPUBuffer(), (GPUMapMode) mode, offset, size,
163
- [](char *error, void *data) {
205
+ callback->prepare();
206
+
207
+
208
+ canvas_native_webgpu_buffer_map_async(ptr->GetGPUBuffer(), mode == 1 ? GPUMapMode::GPUMapModeRead : GPUMapMode::GPUMapModeWrite, offset, size,
209
+ [](enum CanvasGPUErrorType type, char *error, void *data) {
164
210
  if (data != nullptr) {
165
- auto func = static_cast<PromiseCallback *>(data);
166
- if (func->isolate != nullptr) {
167
- v8::Isolate *isolate = func->isolate;
168
- v8::Locker locker(isolate);
169
- v8::Isolate::Scope isolate_scope(
170
- isolate);
171
- v8::HandleScope handle_scope(
172
- isolate);
173
- v8::Local<v8::Promise::Resolver> callback = func->callback.Get(
174
- isolate);
175
- v8::Local<v8::Context> context = callback->GetCreationContextChecked();
176
- v8::Context::Scope context_scope(
177
- context);
178
-
179
- auto ret = v8::Object::New(
180
- isolate);
181
- if (error == nullptr) {
182
- callback->Resolve(context, ret);
183
- } else {
184
- callback->Reject(context,
185
- v8::Exception::Error(
186
- ConvertToV8String(
187
- isolate,
188
- error)));
189
- canvas_native_string_destroy(
190
- error);
211
+ auto async_data = static_cast<PromiseCallback *>(data);
212
+ auto inner = async_data->inner_.get();
213
+ if (inner != nullptr) {
214
+ if(error != nullptr){
215
+ inner->data = new MapAsyncData {
216
+ type, error
217
+ };
191
218
  }
192
- delete static_cast<PromiseCallback *>(data);
219
+ async_data->execute(true);
193
220
  }
194
221
  }
195
222
  }, callback);
@@ -227,3 +254,24 @@ void GPUBufferImpl::GetMappedRange(const v8::FunctionCallbackInfo<v8::Value> &ar
227
254
  args.GetReturnValue().Set(ab);
228
255
  }
229
256
  }
257
+
258
+
259
+ void
260
+ GPUBufferImpl::GetLabel(v8::Local<v8::Name> name,
261
+ const v8::PropertyCallbackInfo<v8::Value> &info) {
262
+ auto ptr = GetPointer(info.This());
263
+ if (ptr != nullptr) {
264
+ auto label = canvas_native_webgpu_buffer_get_label(ptr->buffer_);
265
+ if (label == nullptr) {
266
+ info.GetReturnValue().SetEmptyString();
267
+ return;
268
+ }
269
+ info.GetReturnValue().Set(
270
+ ConvertToV8String(info.GetIsolate(), label)
271
+ );
272
+ canvas_native_string_destroy(label);
273
+ return;
274
+ }
275
+
276
+ info.GetReturnValue().SetEmptyString();
277
+ }