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

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 (126) hide show
  1. package/angular/package.json +20 -0
  2. package/package.json +1 -3
  3. package/platforms/android/canvas-release.aar +0 -0
  4. package/platforms/ios/CanvasNative.xcframework/Info.plist +5 -5
  5. package/platforms/ios/CanvasNative.xcframework/ios-arm64/CanvasNative.framework/CanvasNative +0 -0
  6. package/platforms/ios/CanvasNative.xcframework/ios-arm64/CanvasNative.framework/Modules/CanvasNative.swiftmodule/Project/arm64-apple-ios.swiftsourceinfo +0 -0
  7. package/platforms/ios/CanvasNative.xcframework/ios-arm64/CanvasNative.framework/Modules/CanvasNative.swiftmodule/arm64-apple-ios.abi.json +6577 -5995
  8. package/platforms/ios/CanvasNative.xcframework/ios-arm64/CanvasNative.framework/Modules/CanvasNative.swiftmodule/arm64-apple-ios.swiftdoc +0 -0
  9. package/platforms/ios/CanvasNative.xcframework/ios-arm64/CanvasNative.framework/NSCCanvas.nib +0 -0
  10. package/platforms/ios/CanvasNative.xcframework/ios-arm64/dSYMs/CanvasNative.framework.dSYM/Contents/Resources/DWARF/CanvasNative +0 -0
  11. package/platforms/ios/CanvasNative.xcframework/ios-arm64/dSYMs/CanvasNative.framework.dSYM/Contents/Resources/Relocations/aarch64/CanvasNative.yml +132 -132
  12. package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/CanvasNative +0 -0
  13. package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/Modules/CanvasNative.swiftmodule/Project/arm64-apple-ios-simulator.swiftsourceinfo +0 -0
  14. package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/Modules/CanvasNative.swiftmodule/Project/x86_64-apple-ios-simulator.swiftsourceinfo +0 -0
  15. package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/Modules/CanvasNative.swiftmodule/arm64-apple-ios-simulator.abi.json +6577 -5995
  16. package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/Modules/CanvasNative.swiftmodule/arm64-apple-ios-simulator.swiftdoc +0 -0
  17. package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/Modules/CanvasNative.swiftmodule/x86_64-apple-ios-simulator.abi.json +6577 -5995
  18. package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/Modules/CanvasNative.swiftmodule/x86_64-apple-ios-simulator.swiftdoc +0 -0
  19. package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/NSCCanvas.nib +0 -0
  20. package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/dSYMs/CanvasNative.framework.dSYM/Contents/Resources/DWARF/CanvasNative +0 -0
  21. package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/dSYMs/CanvasNative.framework.dSYM/Contents/Resources/Relocations/aarch64/CanvasNative.yml +646 -646
  22. package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/dSYMs/CanvasNative.framework.dSYM/Contents/Resources/Relocations/x86_64/CanvasNative.yml +684 -684
  23. package/platforms/ios/src/NSOperationQueueWrapper.h +2 -0
  24. package/platforms/ios/src/cpp/AsyncCallback.h +206 -0
  25. package/platforms/ios/src/cpp/CanvasJSIModule.cpp +1 -1
  26. package/platforms/ios/src/cpp/Helpers.h +2 -164
  27. package/platforms/ios/src/cpp/ImageAssetImpl.cpp +2 -2
  28. package/platforms/ios/src/cpp/ImageBitmapImpl.h +2 -1
  29. package/platforms/ios/src/cpp/NativeType.h +87 -0
  30. package/platforms/ios/src/cpp/ObjectWrapperImpl.h +50 -0
  31. package/platforms/ios/src/cpp/PromiseCallback.h +198 -0
  32. package/platforms/ios/src/cpp/canvas2d/CanvasGradient.h +7 -6
  33. package/platforms/ios/src/cpp/canvas2d/CanvasPattern.cpp +1 -1
  34. package/platforms/ios/src/cpp/canvas2d/CanvasPattern.h +1 -1
  35. package/platforms/ios/src/cpp/canvas2d/CanvasRenderingContext2DImpl.cpp +5 -5
  36. package/platforms/ios/src/cpp/canvas2d/CanvasRenderingContext2DImpl.h +15 -10
  37. package/platforms/ios/src/cpp/canvas2d/ImageDataImpl.cpp +2 -2
  38. package/platforms/ios/src/cpp/canvas2d/ImageDataImpl.h +1 -1
  39. package/platforms/ios/src/cpp/canvas2d/MatrixImpl.cpp +10 -10
  40. package/platforms/ios/src/cpp/canvas2d/Path2D.cpp +6 -3
  41. package/platforms/ios/src/cpp/webgl/WebGLActiveInfoImpl.h +1 -1
  42. package/platforms/ios/src/cpp/webgl/WebGLBuffer.h +1 -1
  43. package/platforms/ios/src/cpp/webgl/WebGLFramebuffer.h +1 -1
  44. package/platforms/ios/src/cpp/webgl/WebGLProgram.h +3 -3
  45. package/platforms/ios/src/cpp/webgl/WebGLRenderbuffer.h +3 -3
  46. package/platforms/ios/src/cpp/webgl/WebGLRenderingContext.h +1 -1
  47. package/platforms/ios/src/cpp/webgl/WebGLShader.h +1 -1
  48. package/platforms/ios/src/cpp/webgl/WebGLShaderPrecisionFormatImpl.h +5 -5
  49. package/platforms/ios/src/cpp/webgl/WebGLTexture.h +3 -2
  50. package/platforms/ios/src/cpp/webgl/WebGLUniformLocation.h +2 -2
  51. package/platforms/ios/src/cpp/webgl/extensions/ANGLE_instanced_arraysImpl.h +1 -1
  52. package/platforms/ios/src/cpp/webgl/extensions/EXT_blend_minmaxImpl.h +1 -1
  53. package/platforms/ios/src/cpp/webgl/extensions/EXT_color_buffer_half_floatImpl.h +1 -1
  54. package/platforms/ios/src/cpp/webgl/extensions/EXT_disjoint_timer_queryImpl.h +1 -1
  55. package/platforms/ios/src/cpp/webgl/extensions/EXT_sRGBImpl.h +1 -1
  56. package/platforms/ios/src/cpp/webgl/extensions/EXT_shader_texture_lodImpl.h +1 -1
  57. package/platforms/ios/src/cpp/webgl/extensions/EXT_texture_filter_anisotropicImpl.h +1 -1
  58. package/platforms/ios/src/cpp/webgl/extensions/OES_element_index_uintImpl.h +2 -2
  59. package/platforms/ios/src/cpp/webgl/extensions/OES_fbo_render_mipmap.h +5 -5
  60. package/platforms/ios/src/cpp/webgl/extensions/OES_standard_derivativesImpl.h +1 -1
  61. package/platforms/ios/src/cpp/webgl/extensions/OES_texture_floatImpl.h +1 -1
  62. package/platforms/ios/src/cpp/webgl/extensions/OES_texture_float_linearImpl.h +1 -1
  63. package/platforms/ios/src/cpp/webgl/extensions/OES_texture_half_floatImpl.h +1 -1
  64. package/platforms/ios/src/cpp/webgl/extensions/OES_texture_half_float_linearImpl.h +1 -1
  65. package/platforms/ios/src/cpp/webgl/extensions/OES_vertex_array_objectImpl.h +1 -1
  66. package/platforms/ios/src/cpp/webgl/extensions/WEBGL_color_buffer_floatImpl.h +1 -1
  67. package/platforms/ios/src/cpp/webgl/extensions/WEBGL_compressed_texture_atcImpl.h +1 -1
  68. package/platforms/ios/src/cpp/webgl/extensions/WEBGL_compressed_texture_etc1Impl.h +1 -1
  69. package/platforms/ios/src/cpp/webgl/extensions/WEBGL_compressed_texture_etcImpl.h +2 -2
  70. package/platforms/ios/src/cpp/webgl/extensions/WEBGL_compressed_texture_pvrtcImpl.h +1 -1
  71. package/platforms/ios/src/cpp/webgl/extensions/WEBGL_compressed_texture_s3tcImpl.h +1 -1
  72. package/platforms/ios/src/cpp/webgl/extensions/WEBGL_compressed_texture_s3tc_srgbImpl.h +1 -1
  73. package/platforms/ios/src/cpp/webgl/extensions/WEBGL_depth_textureImpl.h +1 -1
  74. package/platforms/ios/src/cpp/webgl/extensions/WEBGL_draw_buffersImpl.h +1 -1
  75. package/platforms/ios/src/cpp/webgl/extensions/WEBGL_lose_contextImpl.h +1 -1
  76. package/platforms/ios/src/cpp/webgl2/WebGL2RenderingContext.h +1 -1
  77. package/platforms/ios/src/cpp/webgl2/WebGLQuery.h +1 -1
  78. package/platforms/ios/src/cpp/webgl2/WebGLSampler.h +1 -1
  79. package/platforms/ios/src/cpp/webgl2/WebGLSyncImpl.h +1 -1
  80. package/platforms/ios/src/cpp/webgl2/WebGLTransformFeedback.h +1 -1
  81. package/platforms/ios/src/cpp/webgl2/WebGLVertexArrayObject.h +2 -2
  82. package/platforms/ios/src/cpp/webgpu/GPUAdapterImpl.cpp +123 -57
  83. package/platforms/ios/src/cpp/webgpu/GPUAdapterImpl.h +1 -1
  84. package/platforms/ios/src/cpp/webgpu/GPUAdapterInfoImpl.cpp +1 -1
  85. package/platforms/ios/src/cpp/webgpu/GPUAdapterInfoImpl.h +1 -1
  86. package/platforms/ios/src/cpp/webgpu/GPUBindGroupImpl.cpp +1 -1
  87. package/platforms/ios/src/cpp/webgpu/GPUBindGroupImpl.h +1 -1
  88. package/platforms/ios/src/cpp/webgpu/GPUBindGroupLayoutImpl.cpp +1 -1
  89. package/platforms/ios/src/cpp/webgpu/GPUBindGroupLayoutImpl.h +1 -1
  90. package/platforms/ios/src/cpp/webgpu/GPUBufferImpl.cpp +44 -30
  91. package/platforms/ios/src/cpp/webgpu/GPUBufferImpl.h +4 -4
  92. package/platforms/ios/src/cpp/webgpu/GPUCanvasContextImpl.h +1 -1
  93. package/platforms/ios/src/cpp/webgpu/GPUCommandBufferImpl.cpp +1 -1
  94. package/platforms/ios/src/cpp/webgpu/GPUCommandBufferImpl.h +1 -1
  95. package/platforms/ios/src/cpp/webgpu/GPUCommandEncoderImpl.cpp +30 -31
  96. package/platforms/ios/src/cpp/webgpu/GPUCommandEncoderImpl.h +1 -1
  97. package/platforms/ios/src/cpp/webgpu/GPUComputePassEncoderImpl.cpp +1 -1
  98. package/platforms/ios/src/cpp/webgpu/GPUComputePassEncoderImpl.h +1 -1
  99. package/platforms/ios/src/cpp/webgpu/GPUComputePipelineImpl.cpp +1 -1
  100. package/platforms/ios/src/cpp/webgpu/GPUComputePipelineImpl.h +1 -1
  101. package/platforms/ios/src/cpp/webgpu/GPUDeviceImpl.cpp +93 -66
  102. package/platforms/ios/src/cpp/webgpu/GPUDeviceImpl.h +1 -1
  103. package/platforms/ios/src/cpp/webgpu/GPUImpl.cpp +52 -39
  104. package/platforms/ios/src/cpp/webgpu/GPUImpl.h +1 -1
  105. package/platforms/ios/src/cpp/webgpu/GPUPipelineLayoutImpl.cpp +1 -1
  106. package/platforms/ios/src/cpp/webgpu/GPUPipelineLayoutImpl.h +5 -4
  107. package/platforms/ios/src/cpp/webgpu/GPUQuerySetImpl.cpp +1 -1
  108. package/platforms/ios/src/cpp/webgpu/GPUQuerySetImpl.h +1 -1
  109. package/platforms/ios/src/cpp/webgpu/GPUQueueImpl.cpp +38 -23
  110. package/platforms/ios/src/cpp/webgpu/GPUQueueImpl.h +1 -1
  111. package/platforms/ios/src/cpp/webgpu/GPURenderBundleEncoderImpl.h +1 -1
  112. package/platforms/ios/src/cpp/webgpu/GPURenderBundleImpl.cpp +1 -1
  113. package/platforms/ios/src/cpp/webgpu/GPURenderBundleImpl.h +1 -1
  114. package/platforms/ios/src/cpp/webgpu/GPURenderPassEncoderImpl.cpp +1 -1
  115. package/platforms/ios/src/cpp/webgpu/GPURenderPassEncoderImpl.h +1 -1
  116. package/platforms/ios/src/cpp/webgpu/GPURenderPipelineImpl.cpp +1 -1
  117. package/platforms/ios/src/cpp/webgpu/GPURenderPipelineImpl.h +1 -1
  118. package/platforms/ios/src/cpp/webgpu/GPUSamplerImpl.cpp +1 -1
  119. package/platforms/ios/src/cpp/webgpu/GPUSamplerImpl.h +1 -1
  120. package/platforms/ios/src/cpp/webgpu/GPUShaderModuleImpl.cpp +1 -1
  121. package/platforms/ios/src/cpp/webgpu/GPUShaderModuleImpl.h +2 -2
  122. package/platforms/ios/src/cpp/webgpu/GPUSupportedLimitsImpl.cpp +2 -2
  123. package/platforms/ios/src/cpp/webgpu/GPUSupportedLimitsImpl.h +2 -2
  124. package/platforms/ios/src/cpp/webgpu/GPUTextureImpl.h +4 -4
  125. package/platforms/ios/src/cpp/webgpu/GPUTextureViewImpl.cpp +1 -1
  126. package/platforms/ios/src/cpp/webgpu/GPUTextureViewImpl.h +2 -2
@@ -38,7 +38,7 @@ void GPUDeviceImpl::Init(v8::Local<v8::Object> canvasModule, v8::Isolate *isolat
38
38
  auto context = isolate->GetCurrentContext();
39
39
  auto func = ctor->GetFunction(context).ToLocalChecked();
40
40
 
41
- canvasModule->Set(context, ConvertToV8String(isolate, "GPUDevice"), func).FromJust();;
41
+ canvasModule->Set(context, ConvertToV8String(isolate, "GPUDevice"), func).FromJust();
42
42
  }
43
43
 
44
44
  GPUDeviceImpl *GPUDeviceImpl::GetPointer(const v8::Local<v8::Object> &object) {
@@ -296,6 +296,11 @@ GPUDeviceImpl::GetQueue(v8::Local<v8::Name> name,
296
296
  }
297
297
 
298
298
 
299
+ struct LostData {
300
+ int32_t reason;
301
+ char *message;
302
+ };
303
+
299
304
  void
300
305
  GPUDeviceImpl::GetLost(v8::Local<v8::Name> name,
301
306
  const v8::PropertyCallbackInfo<v8::Value> &info) {
@@ -304,64 +309,84 @@ GPUDeviceImpl::GetLost(v8::Local<v8::Name> name,
304
309
  auto resolver = v8::Promise::Resolver::New(isolate->GetCurrentContext()).ToLocalChecked();
305
310
  info.GetReturnValue().Set(resolver->GetPromise());
306
311
  if (ptr != nullptr) {
307
- v8::Global<v8::Promise::Resolver> promise(isolate, resolver);
308
312
  auto callback = new PromiseCallback{
309
313
  isolate,
310
- std::move(promise)
314
+ resolver,
315
+ [](bool done, void *data) {
316
+ if (data != nullptr) {
317
+ auto async_data = static_cast<PromiseCallback *>(data);
318
+ auto func = async_data->inner_.get();
319
+ if (func != nullptr && func->isolate_ != nullptr) {
320
+ v8::Isolate *isolate = func->isolate_;
321
+ v8::Locker locker(isolate);
322
+ v8::Isolate::Scope isolate_scope(
323
+ isolate);
324
+ v8::HandleScope handle_scope(
325
+ isolate);
326
+ v8::Local<v8::Promise::Resolver> callback = func->callback_.Get(
327
+ isolate);
328
+ v8::Local<v8::Context> context = callback->GetCreationContextChecked();
329
+ v8::Context::Scope context_scope(
330
+ context);
331
+
332
+ auto ret = v8::Object::New(
333
+ isolate);
334
+ LostData *lostData = nullptr;
335
+ if (func->data != nullptr) {
336
+ lostData = static_cast<LostData *>(func->data);
337
+ }
338
+
339
+ if (lostData != nullptr) {
340
+
341
+ if (lostData->message != nullptr) {
342
+ ret->Set(context,
343
+ ConvertToV8String(
344
+ isolate,
345
+ "message"),
346
+ ConvertToV8String(
347
+ isolate,
348
+ lostData->message));
349
+ canvas_native_string_destroy(
350
+ lostData->message);
351
+ }
352
+
353
+ ret->Set(context,
354
+ ConvertToV8String(
355
+ isolate,
356
+ "reason"),
357
+ v8::Int32::New(isolate,
358
+ lostData->reason)).IsJust();
359
+ } else {
360
+ ret->Set(context,
361
+ ConvertToV8String(
362
+ isolate,
363
+ "message"),
364
+ v8::String::Empty(
365
+ isolate));
366
+ }
367
+
368
+ callback->Resolve(context, ret);
369
+ delete static_cast<PromiseCallback *>(data);
370
+ }
371
+ }
372
+ }
311
373
  };
312
374
 
375
+ callback->prepare();
376
+
313
377
  canvas_native_webgpu_device_set_lost_callback(ptr->GetGPUDevice(),
314
378
  [](int32_t reason, char *message,
315
379
  void *data) {
316
380
  if (data != nullptr) {
317
- auto func = static_cast<PromiseCallback *>(data);
318
- if (func->isolate != nullptr) {
319
- v8::Isolate *isolate = func->isolate;
320
- v8::Locker locker(isolate);
321
- v8::Isolate::Scope isolate_scope(
322
- isolate);
323
- v8::HandleScope handle_scope(
324
- isolate);
325
- v8::Local<v8::Promise::Resolver> callback = func->callback.Get(
326
- isolate);
327
- v8::Local<v8::Context> context = callback->GetCreationContextChecked();
328
- v8::Context::Scope context_scope(
329
- context);
330
-
331
- auto ret = v8::Object::New(
332
- isolate);
333
- if (message == nullptr) {
334
- ret->Set(context,
335
- ConvertToV8String(
336
- isolate,
337
- "message"),
338
- v8::String::Empty(
339
- isolate));
340
- } else {
341
- ret->Set(context,
342
- ConvertToV8String(
343
- isolate,
344
- "message"),
345
- ConvertToV8String(
346
- isolate,
347
- message));
348
- canvas_native_string_destroy(
349
- message);
350
- }
351
-
352
- ret->Set(context,
353
- ConvertToV8String(
354
- isolate,
355
- "reason"),
356
- v8::Int32::New(isolate,
357
- reason)).IsJust();
358
-
359
-
360
- callback->Resolve(context, ret);
361
- delete static_cast<PromiseCallback *>(data);
381
+ auto async_data = static_cast<PromiseCallback *>(data);
382
+ auto inner = async_data->inner_.get();
383
+ if (inner != nullptr) {
384
+ inner->data = new LostData{
385
+ reason, message
386
+ };
387
+ async_data->execute(true);
362
388
  }
363
389
  }
364
-
365
390
  }, callback);
366
391
  }
367
392
  }
@@ -469,8 +494,8 @@ void GPUDeviceImpl::CreateBindGroup(const v8::FunctionCallbackInfo<v8::Value> &a
469
494
  v8::Local<v8::Value> offsetVal;
470
495
 
471
496
  resourceObj->Get(context,
472
- ConvertToV8String(isolate,
473
- "offset")).ToLocal(
497
+ ConvertToV8String(isolate,
498
+ "offset")).ToLocal(
474
499
  &offsetVal);
475
500
  if (!offsetVal.IsEmpty() && offsetVal->IsNumber()) {
476
501
  offset = (int64_t) offsetVal->NumberValue(
@@ -481,7 +506,8 @@ void GPUDeviceImpl::CreateBindGroup(const v8::FunctionCallbackInfo<v8::Value> &a
481
506
 
482
507
  v8::Local<v8::Value> sizeVal;
483
508
  resourceObj->Get(context,
484
- ConvertToV8String(isolate, "size")).ToLocal(
509
+ ConvertToV8String(isolate,
510
+ "size")).ToLocal(
485
511
  &sizeVal);
486
512
  if (!sizeVal.IsEmpty() && sizeVal->IsNumber()) {
487
513
  size = (int64_t) sizeVal->NumberValue(
@@ -1437,7 +1463,7 @@ void GPUDeviceImpl::CreateRenderPipeline(const v8::FunctionCallbackInfo<v8::Valu
1437
1463
  &depthBiasClampVal);
1438
1464
 
1439
1465
  if (!depthBiasClampVal.IsEmpty() && depthBiasClampVal->IsNumber()) {
1440
- stencil->depth_bias_clamp = (float)depthBiasClampVal->NumberValue(context).FromJust();
1466
+ stencil->depth_bias_clamp = (float) depthBiasClampVal->NumberValue(context).FromJust();
1441
1467
  }
1442
1468
 
1443
1469
 
@@ -1446,7 +1472,7 @@ void GPUDeviceImpl::CreateRenderPipeline(const v8::FunctionCallbackInfo<v8::Valu
1446
1472
  &depthBiasSlopeScaleVal);
1447
1473
 
1448
1474
  if (!depthBiasSlopeScaleVal.IsEmpty() && depthBiasSlopeScaleVal->IsNumber()) {
1449
- stencil->depth_bias_slope_scale = (float)depthBiasSlopeScaleVal->NumberValue(
1475
+ stencil->depth_bias_slope_scale = (float) depthBiasSlopeScaleVal->NumberValue(
1450
1476
  context).FromJust();
1451
1477
  }
1452
1478
 
@@ -1897,7 +1923,7 @@ void GPUDeviceImpl::CreateRenderPipeline(const v8::FunctionCallbackInfo<v8::Valu
1897
1923
  v8::Local<v8::Value> cullModeValue;
1898
1924
 
1899
1925
  if (primitiveObj->Get(context, ConvertToV8String(isolate, "cullMode")).ToLocal(
1900
- &cullModeValue)) {
1926
+ &cullModeValue)) {
1901
1927
  if (cullModeValue->IsUint32()) {
1902
1928
  auto cullMode = cullModeValue.As<v8::Uint32>()->Value();
1903
1929
 
@@ -1932,7 +1958,7 @@ void GPUDeviceImpl::CreateRenderPipeline(const v8::FunctionCallbackInfo<v8::Valu
1932
1958
  v8::Local<v8::Value> frontFaceValue;
1933
1959
 
1934
1960
  if (primitiveObj->Get(context, ConvertToV8String(isolate, "frontFace")).ToLocal(
1935
- &frontFaceValue)) {
1961
+ &frontFaceValue)) {
1936
1962
  if (frontFaceValue->IsUint32()) {
1937
1963
  auto frontFace = frontFaceValue.As<v8::Uint32>()->Value();
1938
1964
  switch (frontFace) {
@@ -1959,7 +1985,7 @@ void GPUDeviceImpl::CreateRenderPipeline(const v8::FunctionCallbackInfo<v8::Valu
1959
1985
  v8::Local<v8::Value> stripIndexFormatValue;
1960
1986
 
1961
1987
  if (primitiveObj->Get(context, ConvertToV8String(isolate, "stripIndexFormat")).ToLocal(
1962
- &stripIndexFormatValue)) {
1988
+ &stripIndexFormatValue)) {
1963
1989
  if (stripIndexFormatValue->IsUint32()) {
1964
1990
  auto stripIndexFormat = stripIndexFormatValue.As<v8::Uint32>()->Value();
1965
1991
  switch (stripIndexFormat) {
@@ -2000,7 +2026,7 @@ void GPUDeviceImpl::CreateRenderPipeline(const v8::FunctionCallbackInfo<v8::Valu
2000
2026
  v8::Local<v8::Value> topologyValue;
2001
2027
 
2002
2028
  if (primitiveObj->Get(context, ConvertToV8String(isolate, "topology")).ToLocal(
2003
- &topologyValue)) {
2029
+ &topologyValue)) {
2004
2030
 
2005
2031
  if (topologyValue->IsUint32()) {
2006
2032
  auto topology = topologyValue.As<v8::Uint32>()->Value();
@@ -2262,7 +2288,7 @@ void GPUDeviceImpl::CreateRenderPipeline(const v8::FunctionCallbackInfo<v8::Valu
2262
2288
 
2263
2289
  }
2264
2290
 
2265
- if(descriptor.depth_stencil != nullptr){
2291
+ if (descriptor.depth_stencil != nullptr) {
2266
2292
  delete descriptor.depth_stencil;
2267
2293
  }
2268
2294
 
@@ -2492,7 +2518,8 @@ void GPUDeviceImpl::CreateShaderModule(const v8::FunctionCallbackInfo<v8::Value>
2492
2518
  v8::Local<v8::Value> codeVal;
2493
2519
 
2494
2520
  std::string code;
2495
- if (desc->Get(context, ConvertToV8String(isolate, "code")).ToLocal(&codeVal) && codeVal->IsString()) {
2521
+ if (desc->Get(context, ConvertToV8String(isolate, "code")).ToLocal(&codeVal) &&
2522
+ codeVal->IsString()) {
2496
2523
  code = ConvertFromV8String(isolate, codeVal);
2497
2524
  }
2498
2525
 
@@ -2541,15 +2568,15 @@ void GPUDeviceImpl::CreateTexture(const v8::FunctionCallbackInfo<v8::Value> &arg
2541
2568
  v8::Local<v8::Value> depthOrArrayLayersVal;
2542
2569
 
2543
2570
  if (options->Get(context, ConvertToV8String(isolate, "depthOrArrayLayers")).ToLocal(
2544
- &depthOrArrayLayersVal) && depthOrArrayLayersVal->IsUint32()) {
2571
+ &depthOrArrayLayersVal) && depthOrArrayLayersVal->IsUint32()) {
2545
2572
  descriptor.depthOrArrayLayers = depthOrArrayLayersVal.As<v8::Uint32>()->Value();
2546
2573
  }
2547
2574
 
2548
2575
 
2549
2576
  v8::Local<v8::Value> widthVal;
2550
2577
 
2551
- if ( options->Get(context, ConvertToV8String(isolate, "width")).ToLocal(
2552
- &widthVal) &&widthVal->IsUint32()) {
2578
+ if (options->Get(context, ConvertToV8String(isolate, "width")).ToLocal(
2579
+ &widthVal) && widthVal->IsUint32()) {
2553
2580
  descriptor.width = widthVal.As<v8::Uint32>()->Value();
2554
2581
  }
2555
2582
 
@@ -2557,7 +2584,7 @@ void GPUDeviceImpl::CreateTexture(const v8::FunctionCallbackInfo<v8::Value> &arg
2557
2584
  v8::Local<v8::Value> heightVal;
2558
2585
 
2559
2586
  if (options->Get(context, ConvertToV8String(isolate, "height")).ToLocal(
2560
- &heightVal) && heightVal->IsUint32()) {
2587
+ &heightVal) && heightVal->IsUint32()) {
2561
2588
  descriptor.height = heightVal.As<v8::Uint32>()->Value();
2562
2589
  }
2563
2590
 
@@ -2565,7 +2592,7 @@ void GPUDeviceImpl::CreateTexture(const v8::FunctionCallbackInfo<v8::Value> &arg
2565
2592
  v8::Local<v8::Value> usageVal;
2566
2593
 
2567
2594
  if (options->Get(context, ConvertToV8String(isolate, "usage")).ToLocal(
2568
- &usageVal) && usageVal->IsUint32()) {
2595
+ &usageVal) && usageVal->IsUint32()) {
2569
2596
  descriptor.usage = usageVal.As<v8::Uint32>()->Value();
2570
2597
  }
2571
2598
 
@@ -2610,7 +2637,7 @@ void GPUDeviceImpl::CreateTexture(const v8::FunctionCallbackInfo<v8::Value> &arg
2610
2637
  v8::Local<v8::Value> formatVal;
2611
2638
 
2612
2639
  if (options->Get(context, ConvertToV8String(isolate, "format")).ToLocal(
2613
- &formatVal) && formatVal->IsString()) {
2640
+ &formatVal) && formatVal->IsString()) {
2614
2641
  auto format = ConvertFromV8String(isolate, formatVal);
2615
2642
 
2616
2643
  // todo use enum
@@ -30,7 +30,7 @@ public:
30
30
  v8::EscapableHandleScope scope(isolate);
31
31
  auto object = GPUDeviceImpl::GetCtor(isolate)->GetFunction(
32
32
  context).ToLocalChecked()->NewInstance(context).ToLocalChecked();
33
- SetNativeType(object, NativeType::GPUDevice);
33
+ SetNativeType(device, NativeType::GPUDevice);
34
34
  object->SetAlignedPointerInInternalField(0, device);
35
35
  device->BindFinalizer(isolate, object);
36
36
  return scope.Escape(object);
@@ -20,7 +20,7 @@ void GPUImpl::Init(const v8::Local<v8::Object> &canvasModule, v8::Isolate *isola
20
20
  auto context = isolate->GetCurrentContext();
21
21
  auto func = ctor->GetFunction(context).ToLocalChecked();
22
22
 
23
- canvasModule->Set(context, ConvertToV8String(isolate, "GPU"), func).FromJust();;
23
+ canvasModule->Set(context, ConvertToV8String(isolate, "GPU"), func).FromJust();
24
24
  }
25
25
 
26
26
 
@@ -69,7 +69,7 @@ void GPUImpl::Ctor(const v8::FunctionCallbackInfo<v8::Value> &args) {
69
69
 
70
70
  ret->SetAlignedPointerInInternalField(0, object);
71
71
 
72
- SetNativeType(ret, NativeType::GPUInstance);
72
+ SetNativeType(object, NativeType::GPUInstance);
73
73
 
74
74
  object->BindFinalizer(isolate, ret);
75
75
 
@@ -122,49 +122,62 @@ void GPUImpl::RequestAdapter(const v8::FunctionCallbackInfo<v8::Value> &args) {
122
122
  }
123
123
  }
124
124
 
125
- v8::Global<v8::Function> func(isolate, args[1].As<v8::Function>());
125
+
126
126
  auto callback = new AsyncCallback{
127
127
  isolate,
128
- std::move(func)
128
+ args[1].As<v8::Function>(),
129
+ [](bool done, void *data) {
130
+ if (data != nullptr) {
131
+ auto async_data = static_cast<AsyncCallback *>(data);
132
+ auto func = async_data->inner_.get();
133
+ if (func != nullptr && func->isolate_ != nullptr) {
134
+ v8::Isolate *isolate = func->isolate_;
135
+ v8::Locker locker(isolate);
136
+ v8::Isolate::Scope isolate_scope(isolate);
137
+ v8::HandleScope handle_scope(isolate);
138
+ v8::Local<v8::Function> callback = func->callback_.Get(
139
+ isolate);
140
+ v8::Local<v8::Context> context = callback->GetCreationContextChecked();
141
+ v8::Context::Scope context_scope(context);
142
+
143
+ if (func->data != nullptr) {
144
+ auto impl = new GPUAdapterImpl(
145
+ static_cast<const CanvasGPUAdapter *>(func->data));
146
+ auto ret = GPUAdapterImpl::NewInstance(
147
+ isolate, impl);
148
+
149
+
150
+ v8::Local<v8::Value> args[2] = {
151
+ v8::Null(isolate), ret};
152
+
153
+
154
+ callback->Call(context, context->Global(),
155
+ 2,
156
+ args); // ignore JS return value
157
+
158
+ delete static_cast<AsyncCallback *>(data);
159
+ } else {
160
+ v8::Local<v8::Value> args[1] = {
161
+ v8::Null(isolate)};
162
+
163
+ callback->Call(context, context->Global(),
164
+ 1,
165
+ args); // ignore JS return value
166
+ delete static_cast<AsyncCallback *>(data);
167
+ }
168
+ }
169
+ }
170
+ }
129
171
  };
172
+ callback->prepare();
130
173
  canvas_native_webgpu_request_adapter(ptr->GetGPUInstance(), &opts,
131
174
  [](const CanvasGPUAdapter *adapter, void *data) {
132
175
  if (data != nullptr) {
133
- auto func = static_cast<AsyncCallback *>(data);
134
- if (func->isolate != nullptr) {
135
- v8::Isolate *isolate = func->isolate;
136
- v8::Locker locker(isolate);
137
- v8::Isolate::Scope isolate_scope(isolate);
138
- v8::HandleScope handle_scope(isolate);
139
- v8::Local<v8::Function> callback = func->callback.Get(
140
- isolate);
141
- v8::Local<v8::Context> context = callback->GetCreationContextChecked();
142
- v8::Context::Scope context_scope(context);
143
-
144
- if (adapter != nullptr) {
145
- auto impl = new GPUAdapterImpl(adapter);
146
- auto ret = GPUAdapterImpl::NewInstance(
147
- isolate, impl);
148
-
149
-
150
- v8::Local<v8::Value> args[2] = {
151
- v8::Null(isolate), ret};
152
-
153
-
154
- callback->Call(context, context->Global(),
155
- 2,
156
- args); // ignore JS return value
157
-
158
- delete static_cast<AsyncCallback *>(data);
159
- } else {
160
- v8::Local<v8::Value> args[1] = {
161
- v8::Null(isolate)};
162
-
163
- callback->Call(context, context->Global(),
164
- 1,
165
- args); // ignore JS return value
166
- delete static_cast<AsyncCallback *>(data);
167
- }
176
+ auto async_data = static_cast<AsyncCallback *>(data);
177
+ auto inner = async_data->inner_.get();
178
+ if (inner != nullptr) {
179
+ inner->data = (void *) adapter;
180
+ async_data->execute(true);
168
181
  }
169
182
  }
170
183
  }, callback);
@@ -37,7 +37,7 @@ public:
37
37
  v8::EscapableHandleScope scope(isolate);
38
38
  auto object = GPUImpl::GetCtor(isolate)->GetFunction(
39
39
  context).ToLocalChecked()->NewInstance(context).ToLocalChecked();
40
- SetNativeType(object, NativeType::GPUInstance);
40
+ SetNativeType(instance, NativeType::GPUInstance);
41
41
  object->SetAlignedPointerInInternalField(0, instance);
42
42
  instance->BindFinalizer(isolate, object);
43
43
  return scope.Escape(object);
@@ -22,7 +22,7 @@ void GPUPipelineLayoutImpl::Init(v8::Local<v8::Object> canvasModule, v8::Isolate
22
22
  auto context = isolate->GetCurrentContext();
23
23
  auto func = ctor->GetFunction(context).ToLocalChecked();
24
24
 
25
- canvasModule->Set(context, ConvertToV8String(isolate, "GPUPipelineLayout"), func).FromJust();;
25
+ canvasModule->Set(context, ConvertToV8String(isolate, "GPUPipelineLayout"), func).FromJust();
26
26
  }
27
27
 
28
28
  GPUPipelineLayoutImpl *GPUPipelineLayoutImpl::GetPointer(const v8::Local<v8::Object> &object) {
@@ -26,14 +26,15 @@ public:
26
26
 
27
27
  static v8::Local<v8::FunctionTemplate> GetCtor(v8::Isolate *isolate);
28
28
 
29
- static v8::Local<v8::Object> NewInstance(v8::Isolate *isolate, GPUPipelineLayoutImpl *device) {
29
+ static v8::Local<v8::Object>
30
+ NewInstance(v8::Isolate *isolate, GPUPipelineLayoutImpl *pipeline) {
30
31
  auto context = isolate->GetCurrentContext();
31
32
  v8::EscapableHandleScope scope(isolate);
32
33
  auto object = GPUPipelineLayoutImpl::GetCtor(isolate)->GetFunction(
33
34
  context).ToLocalChecked()->NewInstance(context).ToLocalChecked();
34
- SetNativeType(object, NativeType::GPUPipelineLayout);
35
- object->SetAlignedPointerInInternalField(0, device);
36
- device->BindFinalizer(isolate, object);
35
+ SetNativeType(pipeline, NativeType::GPUPipelineLayout);
36
+ object->SetAlignedPointerInInternalField(0, pipeline);
37
+ pipeline->BindFinalizer(isolate, object);
37
38
  return scope.Escape(object);
38
39
  }
39
40
 
@@ -21,7 +21,7 @@ void GPUQuerySetImpl::Init(v8::Local<v8::Object> canvasModule, v8::Isolate *isol
21
21
  auto context = isolate->GetCurrentContext();
22
22
  auto func = ctor->GetFunction(context).ToLocalChecked();
23
23
 
24
- canvasModule->Set(context, ConvertToV8String(isolate, "GPUQuerySet"), func).FromJust();;
24
+ canvasModule->Set(context, ConvertToV8String(isolate, "GPUQuerySet"), func).FromJust();
25
25
  }
26
26
 
27
27
  GPUQuerySetImpl *GPUQuerySetImpl::GetPointer(const v8::Local<v8::Object> &object) {
@@ -29,7 +29,7 @@ public:
29
29
  v8::EscapableHandleScope scope(isolate);
30
30
  auto object = GPUQuerySetImpl::GetCtor(isolate)->GetFunction(
31
31
  context).ToLocalChecked()->NewInstance(context).ToLocalChecked();
32
- SetNativeType(object, NativeType::GPUQuerySet);
32
+ SetNativeType(querySet, NativeType::GPUQuerySet);
33
33
  object->SetAlignedPointerInInternalField(0, querySet);
34
34
  querySet->BindFinalizer(isolate, object);
35
35
  return scope.Escape(object);
@@ -30,7 +30,7 @@ void GPUQueueImpl::Init(v8::Local<v8::Object> canvasModule, v8::Isolate *isolate
30
30
  auto context = isolate->GetCurrentContext();
31
31
  auto func = ctor->GetFunction(context).ToLocalChecked();
32
32
 
33
- canvasModule->Set(context, ConvertToV8String(isolate, "GPUQueue"), func).FromJust();;
33
+ canvasModule->Set(context, ConvertToV8String(isolate, "GPUQueue"), func).FromJust();
34
34
  }
35
35
 
36
36
  GPUQueueImpl *GPUQueueImpl::GetPointer(const v8::Local<v8::Object> &object) {
@@ -306,33 +306,48 @@ void GPUQueueImpl::SubmitWorkDone(const v8::FunctionCallbackInfo<v8::Value> &arg
306
306
  }
307
307
 
308
308
  auto isolate = args.GetIsolate();
309
+ auto cb = args[0].As<v8::Function>();
310
+ auto callback = new AsyncCallback(isolate, cb, [](bool done, void *data) {
311
+ if (data != nullptr) {
312
+ auto async_data = static_cast<AsyncCallback *>(data);
313
+ auto func = async_data->inner_.get();
314
+ if (func != nullptr && func->isolate_ != nullptr) {
315
+ v8::Isolate *isolate = func->isolate_;
316
+ v8::Locker locker(isolate);
317
+ v8::Isolate::Scope isolate_scope(
318
+ isolate);
319
+ v8::HandleScope handle_scope(
320
+ isolate);
321
+ v8::Local<v8::Function> callback = func->callback_.Get(
322
+ isolate);
323
+ v8::Local<v8::Context> context = callback->GetCreationContextChecked();
324
+ v8::Context::Scope context_scope(
325
+ context);
326
+
327
+ if (func->data != nullptr) {
328
+ // todo handle error
329
+ canvas_native_string_destroy(static_cast<char *>(func->data));
330
+ func->data = nullptr;
331
+ }
309
332
 
310
- auto cb = args[0];
311
- auto callback = new JSICallback(isolate, cb.As<v8::Function>());
312
-
313
- canvas_native_webgpu_queue_on_submitted_work_done(ptr->GetGPUQueue(),
314
- [](char *error, void *data) {
315
- auto cb = static_cast<JSICallback *>(data);
316
-
317
- v8::Isolate *isolate = cb->isolate_;
318
- v8::Locker locker(isolate);
319
- v8::Isolate::Scope isolate_scope(
320
- isolate);
321
- v8::HandleScope handle_scope(
322
- isolate);
323
- v8::Local<v8::Function> callback = cb->callback_->Get(
324
- isolate);
325
- v8::Local<v8::Context> context = callback->GetCreationContextChecked();
326
- v8::Context::Scope context_scope(
327
- context);
333
+ callback->Call(context,
334
+ context->Global(),
335
+ 0, nullptr);
328
336
 
337
+ delete static_cast<AsyncCallback *>(data);
338
+ }
329
339
 
330
- callback->Call(context,
331
- context->Global(),
332
- 0, nullptr);
340
+ }
341
+ });
333
342
 
343
+ callback->prepare();
334
344
 
335
- delete static_cast<JSICallback *>(data);
345
+ canvas_native_webgpu_queue_on_submitted_work_done(ptr->GetGPUQueue(),
346
+ [](char *error, void *data) {
347
+ if (data != nullptr) {
348
+ auto async_data = static_cast<AsyncCallback *>(data);
349
+ async_data->execute(true);
350
+ }
336
351
  },
337
352
  callback);
338
353
 
@@ -31,7 +31,7 @@ public:
31
31
  v8::EscapableHandleScope scope(isolate);
32
32
  auto object = GPUQueueImpl::GetCtor(isolate)->GetFunction(
33
33
  context).ToLocalChecked()->NewInstance(context).ToLocalChecked();
34
- SetNativeType(object, NativeType::GPUQueue);
34
+ SetNativeType(queue, NativeType::GPUQueue);
35
35
  object->SetAlignedPointerInInternalField(0, queue);
36
36
  queue->BindFinalizer(isolate, object);
37
37
  return scope.Escape(object);
@@ -32,7 +32,7 @@ public:
32
32
  v8::EscapableHandleScope scope(isolate);
33
33
  auto object = GPURenderBundleEncoderImpl::GetCtor(isolate)->GetFunction(
34
34
  context).ToLocalChecked()->NewInstance(context).ToLocalChecked();
35
- SetNativeType(object, NativeType::GPURenderBundleEncoder);
35
+ SetNativeType(encoder, NativeType::GPURenderBundleEncoder);
36
36
  object->SetAlignedPointerInInternalField(0, encoder);
37
37
  encoder->BindFinalizer(isolate, object);
38
38
  return scope.Escape(object);
@@ -22,7 +22,7 @@ void GPURenderBundleImpl::Init(v8::Local<v8::Object> canvasModule, v8::Isolate *
22
22
  auto context = isolate->GetCurrentContext();
23
23
  auto func = ctor->GetFunction(context).ToLocalChecked();
24
24
 
25
- canvasModule->Set(context, ConvertToV8String(isolate, "GPURenderBundle"), func).FromJust();;
25
+ canvasModule->Set(context, ConvertToV8String(isolate, "GPURenderBundle"), func).FromJust();
26
26
  }
27
27
 
28
28
  GPURenderBundleImpl *GPURenderBundleImpl::GetPointer(const v8::Local<v8::Object> &object) {
@@ -30,7 +30,7 @@ public:
30
30
  v8::EscapableHandleScope scope(isolate);
31
31
  auto object = GPURenderBundleImpl::GetCtor(isolate)->GetFunction(
32
32
  context).ToLocalChecked()->NewInstance(context).ToLocalChecked();
33
- SetNativeType(object, NativeType::GPURenderBundle);
33
+ SetNativeType(bundle, NativeType::GPURenderBundle);
34
34
  object->SetAlignedPointerInInternalField(0, bundle);
35
35
  bundle->BindFinalizer(isolate, object);
36
36
  return scope.Escape(object);
@@ -28,7 +28,7 @@ void GPURenderPassEncoderImpl::Init(v8::Local<v8::Object> canvasModule, v8::Isol
28
28
  auto func = ctor->GetFunction(context).ToLocalChecked();
29
29
 
30
30
  canvasModule->Set(context, ConvertToV8String(isolate, "GPURenderPassEncoder"),
31
- func).FromJust();;
31
+ func).FromJust();
32
32
  }
33
33
 
34
34
  GPURenderPassEncoderImpl *
@@ -32,7 +32,7 @@ public:
32
32
  v8::EscapableHandleScope scope(isolate);
33
33
  auto object = GPURenderPassEncoderImpl::GetCtor(isolate)->GetFunction(
34
34
  context).ToLocalChecked()->NewInstance(context).ToLocalChecked();
35
- SetNativeType(object, NativeType::GPURenderPassEncoder);
35
+ SetNativeType(encoder, NativeType::GPURenderPassEncoder);
36
36
  object->SetAlignedPointerInInternalField(0, encoder);
37
37
  encoder->BindFinalizer(isolate, object);
38
38
  return scope.Escape(object);
@@ -23,7 +23,7 @@ void GPURenderPipelineImpl::Init(v8::Local<v8::Object> canvasModule, v8::Isolate
23
23
  auto context = isolate->GetCurrentContext();
24
24
  auto func = ctor->GetFunction(context).ToLocalChecked();
25
25
 
26
- canvasModule->Set(context, ConvertToV8String(isolate, "GPURenderPipeline"), func).FromJust();;
26
+ canvasModule->Set(context, ConvertToV8String(isolate, "GPURenderPipeline"), func).FromJust();
27
27
  }
28
28
 
29
29
  GPURenderPipelineImpl *GPURenderPipelineImpl::GetPointer(const v8::Local<v8::Object> &object) {
@@ -31,7 +31,7 @@ public:
31
31
  v8::EscapableHandleScope scope(isolate);
32
32
  auto object = GPURenderPipelineImpl::GetCtor(isolate)->GetFunction(
33
33
  context).ToLocalChecked()->NewInstance(context).ToLocalChecked();
34
- SetNativeType(object, NativeType::GPURenderPipeline);
34
+ SetNativeType(pipeline, NativeType::GPURenderPipeline);
35
35
  object->SetAlignedPointerInInternalField(0, pipeline);
36
36
  pipeline->BindFinalizer(isolate, object);
37
37
  return scope.Escape(object);