@nativescript/canvas 2.0.0-beta.9 → 2.0.0-rc.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 (454) hide show
  1. package/Canvas/common.d.ts +15 -24
  2. package/Canvas/common.js +147 -203
  3. package/Canvas/common.js.map +1 -1
  4. package/Canvas/index.android.d.ts +13 -15
  5. package/Canvas/index.android.js +152 -151
  6. package/Canvas/index.android.js.map +1 -1
  7. package/Canvas/index.d.ts +23 -11
  8. package/Canvas/index.ios.d.ts +14 -6
  9. package/Canvas/index.ios.js +213 -124
  10. package/Canvas/index.ios.js.map +1 -1
  11. package/Canvas/utils.d.ts +3 -0
  12. package/Canvas/utils.js +85 -0
  13. package/Canvas/utils.js.map +1 -0
  14. package/Canvas2D/CanvasRenderingContext2D/index.d.ts +4 -2
  15. package/Canvas2D/CanvasRenderingContext2D/index.js +79 -85
  16. package/Canvas2D/CanvasRenderingContext2D/index.js.map +1 -1
  17. package/Canvas2D/DOMMatrix/index.d.ts +14 -0
  18. package/Canvas2D/DOMMatrix/index.js +62 -0
  19. package/Canvas2D/DOMMatrix/index.js.map +1 -1
  20. package/Canvas2D/ImageData/index.js +4 -6
  21. package/Canvas2D/ImageData/index.js.map +1 -1
  22. package/Canvas2D/Path2D/index.js.map +1 -1
  23. package/Dom/Dom.js +8 -1
  24. package/Dom/Dom.js.map +1 -1
  25. package/Dom/Group.d.ts +1 -2
  26. package/Dom/Group.js.map +1 -1
  27. package/Dom/Image.d.ts +4 -1
  28. package/Dom/Image.js +15 -2
  29. package/Dom/Image.js.map +1 -1
  30. package/Dom/Paint.d.ts +1 -1
  31. package/Dom/Paint.js.map +1 -1
  32. package/Dom/Text.js.map +1 -1
  33. package/Dom/shaders/LinearGradient.js.map +1 -1
  34. package/Dom/shaders/TwoPointConicalGradient.js.map +1 -1
  35. package/Dom/shapes/Atlas.js.map +1 -1
  36. package/Dom/shapes/Circle.js.map +1 -1
  37. package/Dom/shapes/Line.js.map +1 -1
  38. package/Dom/shapes/Oval.js.map +1 -1
  39. package/Dom/shapes/Path.d.ts +1 -1
  40. package/Dom/shapes/Path.js.map +1 -1
  41. package/Dom/shapes/Rect.js.map +1 -1
  42. package/Dom/shapes/RoundedRect.js.map +1 -1
  43. package/Dom/shapes/index.js.map +1 -1
  44. package/Fonts/FontFace.android.d.ts +46 -0
  45. package/Fonts/FontFace.android.js +197 -0
  46. package/Fonts/FontFace.android.js.map +1 -0
  47. package/Fonts/FontFace.ios.d.ts +45 -0
  48. package/Fonts/FontFace.ios.js +169 -0
  49. package/Fonts/FontFace.ios.js.map +1 -0
  50. package/Fonts/FontFaceSet.android.d.ts +31 -0
  51. package/Fonts/FontFaceSet.android.js +119 -0
  52. package/Fonts/FontFaceSet.android.js.map +1 -0
  53. package/Fonts/FontFaceSet.ios.d.ts +31 -0
  54. package/Fonts/FontFaceSet.ios.js +109 -0
  55. package/Fonts/FontFaceSet.ios.js.map +1 -0
  56. package/Fonts/index.d.ts +2 -0
  57. package/Fonts/index.js +3 -0
  58. package/Fonts/index.js.map +1 -0
  59. package/ImageAsset/index.d.ts +8 -3
  60. package/ImageAsset/index.js +206 -11
  61. package/ImageAsset/index.js.map +1 -1
  62. package/ImageBitmap/index.js +110 -23
  63. package/ImageBitmap/index.js.map +1 -1
  64. package/README.md +62 -3
  65. package/TextDecoder/index.js +3 -3
  66. package/TextDecoder/index.js.map +1 -1
  67. package/TextEncoder/index.js +3 -3
  68. package/TextEncoder/index.js.map +1 -1
  69. package/WebGL/WebGLExtensions/index.js +5 -5
  70. package/WebGL/WebGLExtensions/index.js.map +1 -1
  71. package/WebGL/WebGLRenderingContext/common.d.ts +1 -1
  72. package/WebGL/WebGLRenderingContext/common.js.map +1 -1
  73. package/WebGL/WebGLRenderingContext/index.d.ts +1 -0
  74. package/WebGL/WebGLRenderingContext/index.js +144 -46
  75. package/WebGL/WebGLRenderingContext/index.js.map +1 -1
  76. package/WebGL2/WebGL2RenderingContext/index.d.ts +1 -0
  77. package/WebGL2/WebGL2RenderingContext/index.js +7 -8
  78. package/WebGL2/WebGL2RenderingContext/index.js.map +1 -1
  79. package/WebGPU/Constants.d.ts +36 -0
  80. package/WebGPU/Constants.js +42 -0
  81. package/WebGPU/Constants.js.map +1 -0
  82. package/WebGPU/Errors.d.ts +18 -0
  83. package/WebGPU/Errors.js +21 -0
  84. package/WebGPU/Errors.js.map +1 -0
  85. package/WebGPU/GPU.d.ts +13 -0
  86. package/WebGPU/GPU.js +36 -0
  87. package/WebGPU/GPU.js.map +1 -0
  88. package/WebGPU/GPUAdapter.d.ts +26 -0
  89. package/WebGPU/GPUAdapter.js +93 -0
  90. package/WebGPU/GPUAdapter.js.map +1 -0
  91. package/WebGPU/GPUAdapterInfo.d.ts +9 -0
  92. package/WebGPU/GPUAdapterInfo.js +24 -0
  93. package/WebGPU/GPUAdapterInfo.js.map +1 -0
  94. package/WebGPU/GPUBindGroup.d.ts +6 -0
  95. package/WebGPU/GPUBindGroup.js +15 -0
  96. package/WebGPU/GPUBindGroup.js.map +1 -0
  97. package/WebGPU/GPUBindGroupLayout.d.ts +6 -0
  98. package/WebGPU/GPUBindGroupLayout.js +15 -0
  99. package/WebGPU/GPUBindGroupLayout.js.map +1 -0
  100. package/WebGPU/GPUBuffer.d.ts +15 -0
  101. package/WebGPU/GPUBuffer.js +66 -0
  102. package/WebGPU/GPUBuffer.js.map +1 -0
  103. package/WebGPU/GPUCanvasContext.d.ts +42 -0
  104. package/WebGPU/GPUCanvasContext.js +149 -0
  105. package/WebGPU/GPUCanvasContext.js.map +1 -0
  106. package/WebGPU/GPUCommandBuffer.d.ts +6 -0
  107. package/WebGPU/GPUCommandBuffer.js +15 -0
  108. package/WebGPU/GPUCommandBuffer.js.map +1 -0
  109. package/WebGPU/GPUCommandEncoder.d.ts +35 -0
  110. package/WebGPU/GPUCommandEncoder.js +163 -0
  111. package/WebGPU/GPUCommandEncoder.js.map +1 -0
  112. package/WebGPU/GPUComputePassEncoder.d.ts +17 -0
  113. package/WebGPU/GPUComputePassEncoder.js +53 -0
  114. package/WebGPU/GPUComputePassEncoder.js.map +1 -0
  115. package/WebGPU/GPUComputePipeline.d.ts +8 -0
  116. package/WebGPU/GPUComputePipeline.js +19 -0
  117. package/WebGPU/GPUComputePipeline.js.map +1 -0
  118. package/WebGPU/GPUDevice.d.ts +111 -0
  119. package/WebGPU/GPUDevice.js +341 -0
  120. package/WebGPU/GPUDevice.js.map +1 -0
  121. package/WebGPU/GPUDeviceLostInfo.d.ts +1 -0
  122. package/WebGPU/GPUDeviceLostInfo.js +10 -0
  123. package/WebGPU/GPUDeviceLostInfo.js.map +1 -0
  124. package/WebGPU/GPUExternalTexture.d.ts +6 -0
  125. package/WebGPU/GPUExternalTexture.js +15 -0
  126. package/WebGPU/GPUExternalTexture.js.map +1 -0
  127. package/WebGPU/GPUPipelineLayout.d.ts +6 -0
  128. package/WebGPU/GPUPipelineLayout.js +15 -0
  129. package/WebGPU/GPUPipelineLayout.js.map +1 -0
  130. package/WebGPU/GPUQuerySet.d.ts +6 -0
  131. package/WebGPU/GPUQuerySet.js +15 -0
  132. package/WebGPU/GPUQuerySet.js.map +1 -0
  133. package/WebGPU/GPUQueue.d.ts +15 -0
  134. package/WebGPU/GPUQueue.js +128 -0
  135. package/WebGPU/GPUQueue.js.map +1 -0
  136. package/WebGPU/GPURenderBundle.d.ts +6 -0
  137. package/WebGPU/GPURenderBundle.js +15 -0
  138. package/WebGPU/GPURenderBundle.js.map +1 -0
  139. package/WebGPU/GPURenderBundleEncoder.d.ts +22 -0
  140. package/WebGPU/GPURenderBundleEncoder.js +65 -0
  141. package/WebGPU/GPURenderBundleEncoder.js.map +1 -0
  142. package/WebGPU/GPURenderPassEncoder.d.ts +33 -0
  143. package/WebGPU/GPURenderPassEncoder.js +106 -0
  144. package/WebGPU/GPURenderPassEncoder.js.map +1 -0
  145. package/WebGPU/GPURenderPipeline.d.ts +8 -0
  146. package/WebGPU/GPURenderPipeline.js +19 -0
  147. package/WebGPU/GPURenderPipeline.js.map +1 -0
  148. package/WebGPU/GPUSampler.d.ts +6 -0
  149. package/WebGPU/GPUSampler.js +15 -0
  150. package/WebGPU/GPUSampler.js.map +1 -0
  151. package/WebGPU/GPUShaderModule.d.ts +6 -0
  152. package/WebGPU/GPUShaderModule.js +15 -0
  153. package/WebGPU/GPUShaderModule.js.map +1 -0
  154. package/WebGPU/GPUTexture.d.ts +18 -0
  155. package/WebGPU/GPUTexture.js +47 -0
  156. package/WebGPU/GPUTexture.js.map +1 -0
  157. package/WebGPU/GPUTextureView.d.ts +6 -0
  158. package/WebGPU/GPUTextureView.js +15 -0
  159. package/WebGPU/GPUTextureView.js.map +1 -0
  160. package/WebGPU/Interfaces.d.ts +246 -0
  161. package/WebGPU/Interfaces.js +2 -0
  162. package/WebGPU/Interfaces.js.map +1 -0
  163. package/WebGPU/Types.d.ts +47 -0
  164. package/WebGPU/Types.js +2 -0
  165. package/WebGPU/Types.js.map +1 -0
  166. package/WebGPU/Utils.d.ts +7 -0
  167. package/WebGPU/Utils.js +301 -0
  168. package/WebGPU/Utils.js.map +1 -0
  169. package/WebGPU/index.d.ts +28 -0
  170. package/WebGPU/index.js +29 -0
  171. package/WebGPU/index.js.map +1 -0
  172. package/angular/{esm2020 → esm2022}/index.mjs +5 -5
  173. package/angular/{fesm2015 → fesm2022}/nativescript-canvas-angular.mjs +4 -4
  174. package/angular/{fesm2015 → fesm2022}/nativescript-canvas-angular.mjs.map +1 -1
  175. package/angular/package.json +4 -10
  176. package/common.d.ts +0 -3
  177. package/common.js +1 -5
  178. package/common.js.map +1 -1
  179. package/helpers.js.map +1 -1
  180. package/index.d.ts +4 -2
  181. package/index.js +37 -3
  182. package/index.js.map +1 -1
  183. package/package.json +2 -5
  184. package/platforms/android/canvas-release.aar +0 -0
  185. package/platforms/ios/CanvasNative.xcframework/ios-arm64/CanvasNative.framework/CanvasNative +0 -0
  186. package/platforms/ios/CanvasNative.xcframework/ios-arm64/CanvasNative.framework/Headers/CanvasNative-Swift.h +194 -56
  187. package/platforms/ios/CanvasNative.xcframework/ios-arm64/CanvasNative.framework/Headers/CanvasNative.h +1 -0
  188. package/platforms/ios/CanvasNative.xcframework/ios-arm64/CanvasNative.framework/Headers/NSCMTLView.h +32 -0
  189. package/platforms/ios/CanvasNative.xcframework/ios-arm64/CanvasNative.framework/Headers/canvas_ios.h +152 -151
  190. package/platforms/ios/CanvasNative.xcframework/ios-arm64/CanvasNative.framework/Headers/canvas_native.h +2901 -411
  191. package/platforms/ios/CanvasNative.xcframework/ios-arm64/CanvasNative.framework/Info.plist +0 -0
  192. package/platforms/ios/CanvasNative.xcframework/ios-arm64/CanvasNative.framework/Modules/CanvasNative.swiftmodule/Project/arm64-apple-ios.swiftsourceinfo +0 -0
  193. package/platforms/ios/CanvasNative.xcframework/ios-arm64/CanvasNative.framework/Modules/CanvasNative.swiftmodule/arm64-apple-ios.abi.json +10901 -8099
  194. package/platforms/ios/CanvasNative.xcframework/ios-arm64/CanvasNative.framework/Modules/CanvasNative.swiftmodule/arm64-apple-ios.private.swiftinterface +259 -52
  195. package/platforms/ios/CanvasNative.xcframework/ios-arm64/CanvasNative.framework/Modules/CanvasNative.swiftmodule/arm64-apple-ios.swiftdoc +0 -0
  196. package/platforms/ios/CanvasNative.xcframework/ios-arm64/CanvasNative.framework/Modules/CanvasNative.swiftmodule/arm64-apple-ios.swiftinterface +259 -52
  197. package/platforms/ios/CanvasNative.xcframework/ios-arm64/CanvasNative.framework/fonts/Noto_Serif_CJK/NotoSerifTC-Black.ttf +0 -0
  198. package/platforms/ios/CanvasNative.xcframework/ios-arm64/CanvasNative.framework/fonts/Noto_Serif_CJK/NotoSerifTC-Bold.ttf +0 -0
  199. package/platforms/ios/CanvasNative.xcframework/ios-arm64/CanvasNative.framework/fonts/Noto_Serif_CJK/NotoSerifTC-ExtraBold.ttf +0 -0
  200. package/platforms/ios/CanvasNative.xcframework/ios-arm64/CanvasNative.framework/fonts/Noto_Serif_CJK/NotoSerifTC-ExtraLight.ttf +0 -0
  201. package/platforms/ios/CanvasNative.xcframework/ios-arm64/CanvasNative.framework/fonts/Noto_Serif_CJK/NotoSerifTC-Light.ttf +0 -0
  202. package/platforms/ios/CanvasNative.xcframework/ios-arm64/CanvasNative.framework/fonts/Noto_Serif_CJK/NotoSerifTC-Medium.ttf +0 -0
  203. package/platforms/ios/CanvasNative.xcframework/ios-arm64/CanvasNative.framework/fonts/Noto_Serif_CJK/NotoSerifTC-Regular.ttf +0 -0
  204. package/platforms/ios/CanvasNative.xcframework/ios-arm64/CanvasNative.framework/fonts/Noto_Serif_CJK/NotoSerifTC-SemiBold.ttf +0 -0
  205. package/platforms/ios/CanvasNative.xcframework/ios-arm64/CanvasNative.framework/fonts/STIXTwoMath/STIXTwoMath-Regular.ttf +0 -0
  206. package/platforms/ios/CanvasNative.xcframework/ios-arm64/CanvasNative.framework/fonts/STIXTwoMath/STIXTwoText-Bold.ttf +0 -0
  207. package/platforms/ios/CanvasNative.xcframework/ios-arm64/CanvasNative.framework/fonts/STIXTwoMath/STIXTwoText-BoldItalic.ttf +0 -0
  208. package/platforms/ios/CanvasNative.xcframework/ios-arm64/CanvasNative.framework/fonts/STIXTwoMath/STIXTwoText-Italic.ttf +0 -0
  209. package/platforms/ios/CanvasNative.xcframework/ios-arm64/CanvasNative.framework/fonts/STIXTwoMath/STIXTwoText-Medium.ttf +0 -0
  210. package/platforms/ios/CanvasNative.xcframework/ios-arm64/CanvasNative.framework/fonts/STIXTwoMath/STIXTwoText-MediumItalic.ttf +0 -0
  211. package/platforms/ios/CanvasNative.xcframework/ios-arm64/CanvasNative.framework/fonts/STIXTwoMath/STIXTwoText-Regular.ttf +0 -0
  212. package/platforms/ios/CanvasNative.xcframework/ios-arm64/CanvasNative.framework/fonts/STIXTwoMath/STIXTwoText-SemiBold.ttf +0 -0
  213. package/platforms/ios/CanvasNative.xcframework/ios-arm64/CanvasNative.framework/fonts/STIXTwoMath/STIXTwoText-SemiBoldItalic.ttf +0 -0
  214. package/platforms/ios/CanvasNative.xcframework/ios-arm64/dSYMs/CanvasNative.framework.dSYM/Contents/Resources/DWARF/CanvasNative +0 -0
  215. package/platforms/ios/CanvasNative.xcframework/ios-arm64/dSYMs/CanvasNative.framework.dSYM/Contents/Resources/Relocations/aarch64/CanvasNative.yml +994 -663
  216. package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/CanvasNative +0 -0
  217. package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/Headers/CanvasNative-Swift.h +388 -112
  218. package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/Headers/CanvasNative.h +1 -0
  219. package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/Headers/NSCMTLView.h +32 -0
  220. package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/Headers/canvas_ios.h +152 -151
  221. package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/Headers/canvas_native.h +2901 -411
  222. package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/Info.plist +0 -0
  223. package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/Modules/CanvasNative.swiftmodule/Project/arm64-apple-ios-simulator.swiftsourceinfo +0 -0
  224. package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/Modules/CanvasNative.swiftmodule/Project/x86_64-apple-ios-simulator.swiftsourceinfo +0 -0
  225. package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/Modules/CanvasNative.swiftmodule/arm64-apple-ios-simulator.abi.json +10901 -8099
  226. package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/Modules/CanvasNative.swiftmodule/arm64-apple-ios-simulator.private.swiftinterface +259 -52
  227. package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/Modules/CanvasNative.swiftmodule/arm64-apple-ios-simulator.swiftdoc +0 -0
  228. package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/Modules/CanvasNative.swiftmodule/arm64-apple-ios-simulator.swiftinterface +259 -52
  229. package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/Modules/CanvasNative.swiftmodule/x86_64-apple-ios-simulator.abi.json +10901 -8099
  230. package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/Modules/CanvasNative.swiftmodule/x86_64-apple-ios-simulator.private.swiftinterface +259 -52
  231. package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/Modules/CanvasNative.swiftmodule/x86_64-apple-ios-simulator.swiftdoc +0 -0
  232. package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/Modules/CanvasNative.swiftmodule/x86_64-apple-ios-simulator.swiftinterface +259 -52
  233. package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/_CodeSignature/CodeResources +143 -33
  234. package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/fonts/Noto_Serif_CJK/NotoSerifTC-Black.ttf +0 -0
  235. package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/fonts/Noto_Serif_CJK/NotoSerifTC-Bold.ttf +0 -0
  236. package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/fonts/Noto_Serif_CJK/NotoSerifTC-ExtraBold.ttf +0 -0
  237. package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/fonts/Noto_Serif_CJK/NotoSerifTC-ExtraLight.ttf +0 -0
  238. package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/fonts/Noto_Serif_CJK/NotoSerifTC-Light.ttf +0 -0
  239. package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/fonts/Noto_Serif_CJK/NotoSerifTC-Medium.ttf +0 -0
  240. package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/fonts/Noto_Serif_CJK/NotoSerifTC-Regular.ttf +0 -0
  241. package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/fonts/Noto_Serif_CJK/NotoSerifTC-SemiBold.ttf +0 -0
  242. package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/fonts/STIXTwoMath/STIXTwoMath-Regular.ttf +0 -0
  243. package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/fonts/STIXTwoMath/STIXTwoText-Bold.ttf +0 -0
  244. package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/fonts/STIXTwoMath/STIXTwoText-BoldItalic.ttf +0 -0
  245. package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/fonts/STIXTwoMath/STIXTwoText-Italic.ttf +0 -0
  246. package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/fonts/STIXTwoMath/STIXTwoText-Medium.ttf +0 -0
  247. package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/fonts/STIXTwoMath/STIXTwoText-MediumItalic.ttf +0 -0
  248. package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/fonts/STIXTwoMath/STIXTwoText-Regular.ttf +0 -0
  249. package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/fonts/STIXTwoMath/STIXTwoText-SemiBold.ttf +0 -0
  250. package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/fonts/STIXTwoMath/STIXTwoText-SemiBoldItalic.ttf +0 -0
  251. package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/dSYMs/CanvasNative.framework.dSYM/Contents/Resources/DWARF/CanvasNative +0 -0
  252. package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/dSYMs/CanvasNative.framework.dSYM/Contents/Resources/Relocations/aarch64/CanvasNative.yml +993 -662
  253. package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/dSYMs/CanvasNative.framework.dSYM/Contents/Resources/Relocations/x86_64/CanvasNative.yml +1037 -641
  254. package/platforms/ios/build.xcconfig +3 -1
  255. package/platforms/ios/src/NSOperationQueueWrapper.h +3 -1
  256. package/platforms/ios/src/NSOperationQueueWrapper.mm +41 -9
  257. package/platforms/ios/src/cpp/AsyncCallback.h +214 -0
  258. package/platforms/ios/src/cpp/Caches.h +69 -1
  259. package/platforms/ios/src/cpp/CanvasJSIModule.cpp +647 -1166
  260. package/platforms/ios/src/cpp/CanvasJSIModule.h +11 -1
  261. package/platforms/ios/src/cpp/Helpers.h +2 -129
  262. package/platforms/ios/src/cpp/ImageAssetImpl.cpp +600 -437
  263. package/platforms/ios/src/cpp/ImageAssetImpl.h +18 -10
  264. package/platforms/ios/src/cpp/ImageBitmapImpl.cpp +63 -6
  265. package/platforms/ios/src/cpp/ImageBitmapImpl.h +12 -4
  266. package/platforms/ios/src/cpp/JSIReadFileCallback.h +4 -4
  267. package/platforms/ios/src/cpp/NativeType.h +87 -0
  268. package/platforms/ios/src/cpp/ObjectWrapperImpl.h +50 -0
  269. package/platforms/ios/src/cpp/OneByteStringResource.cpp +2 -2
  270. package/platforms/ios/src/cpp/PromiseCallback.h +197 -0
  271. package/platforms/ios/src/cpp/RafImpl.h +2 -2
  272. package/platforms/ios/src/cpp/TextDecoderImpl.cpp +0 -6
  273. package/platforms/ios/src/cpp/TextDecoderImpl.h +3 -3
  274. package/platforms/ios/src/cpp/TextEncoderImpl.cpp +1 -1
  275. package/platforms/ios/src/cpp/TextEncoderImpl.h +3 -3
  276. package/platforms/ios/src/cpp/canvas2d/CanvasGradient.h +8 -7
  277. package/platforms/ios/src/cpp/canvas2d/CanvasPattern.cpp +1 -11
  278. package/platforms/ios/src/cpp/canvas2d/CanvasPattern.h +3 -3
  279. package/platforms/ios/src/cpp/canvas2d/CanvasRenderingContext2DImpl.cpp +193 -90
  280. package/platforms/ios/src/cpp/canvas2d/CanvasRenderingContext2DImpl.h +77 -23
  281. package/platforms/ios/src/cpp/canvas2d/ImageDataImpl.cpp +5 -6
  282. package/platforms/ios/src/cpp/canvas2d/ImageDataImpl.h +4 -4
  283. package/platforms/ios/src/cpp/canvas2d/MatrixImpl.cpp +409 -3
  284. package/platforms/ios/src/cpp/canvas2d/MatrixImpl.h +29 -2
  285. package/platforms/ios/src/cpp/canvas2d/Path2D.cpp +6 -3
  286. package/platforms/ios/src/cpp/canvas2d/Path2D.h +7 -7
  287. package/platforms/ios/src/cpp/canvas2d/TextMetricsImpl.h +3 -3
  288. package/platforms/ios/src/cpp/webgl/WebGLActiveInfoImpl.h +1 -1
  289. package/platforms/ios/src/cpp/webgl/WebGLBuffer.h +1 -1
  290. package/platforms/ios/src/cpp/webgl/WebGLFramebuffer.h +1 -1
  291. package/platforms/ios/src/cpp/webgl/WebGLProgram.h +3 -3
  292. package/platforms/ios/src/cpp/webgl/WebGLRenderbuffer.h +3 -3
  293. package/platforms/ios/src/cpp/webgl/WebGLRenderingContext.cpp +247 -160
  294. package/platforms/ios/src/cpp/webgl/WebGLRenderingContext.h +1 -1
  295. package/platforms/ios/src/cpp/webgl/WebGLRenderingContextBase.cpp +6 -6
  296. package/platforms/ios/src/cpp/webgl/WebGLShader.h +1 -1
  297. package/platforms/ios/src/cpp/webgl/WebGLShaderPrecisionFormatImpl.h +5 -5
  298. package/platforms/ios/src/cpp/webgl/WebGLTexture.h +3 -2
  299. package/platforms/ios/src/cpp/webgl/WebGLUniformLocation.h +2 -2
  300. package/platforms/ios/src/cpp/webgl/extensions/ANGLE_instanced_arraysImpl.h +1 -1
  301. package/platforms/ios/src/cpp/webgl/extensions/EXT_blend_minmaxImpl.h +1 -1
  302. package/platforms/ios/src/cpp/webgl/extensions/EXT_color_buffer_half_floatImpl.h +1 -1
  303. package/platforms/ios/src/cpp/webgl/extensions/EXT_disjoint_timer_queryImpl.h +1 -1
  304. package/platforms/ios/src/cpp/webgl/extensions/EXT_sRGBImpl.h +1 -1
  305. package/platforms/ios/src/cpp/webgl/extensions/EXT_shader_texture_lodImpl.h +1 -1
  306. package/platforms/ios/src/cpp/webgl/extensions/EXT_texture_filter_anisotropicImpl.h +1 -1
  307. package/platforms/ios/src/cpp/webgl/extensions/OES_element_index_uintImpl.h +2 -2
  308. package/platforms/ios/src/cpp/webgl/extensions/OES_fbo_render_mipmap.h +5 -5
  309. package/platforms/ios/src/cpp/webgl/extensions/OES_standard_derivativesImpl.h +1 -1
  310. package/platforms/ios/src/cpp/webgl/extensions/OES_texture_floatImpl.h +1 -1
  311. package/platforms/ios/src/cpp/webgl/extensions/OES_texture_float_linearImpl.h +1 -1
  312. package/platforms/ios/src/cpp/webgl/extensions/OES_texture_half_floatImpl.h +1 -1
  313. package/platforms/ios/src/cpp/webgl/extensions/OES_texture_half_float_linearImpl.h +1 -1
  314. package/platforms/ios/src/cpp/webgl/extensions/OES_vertex_array_objectImpl.h +1 -1
  315. package/platforms/ios/src/cpp/webgl/extensions/WEBGL_color_buffer_floatImpl.h +1 -1
  316. package/platforms/ios/src/cpp/webgl/extensions/WEBGL_compressed_texture_atcImpl.h +1 -1
  317. package/platforms/ios/src/cpp/webgl/extensions/WEBGL_compressed_texture_etc1Impl.h +1 -1
  318. package/platforms/ios/src/cpp/webgl/extensions/WEBGL_compressed_texture_etcImpl.h +2 -2
  319. package/platforms/ios/src/cpp/webgl/extensions/WEBGL_compressed_texture_pvrtcImpl.h +1 -1
  320. package/platforms/ios/src/cpp/webgl/extensions/WEBGL_compressed_texture_s3tcImpl.h +1 -1
  321. package/platforms/ios/src/cpp/webgl/extensions/WEBGL_compressed_texture_s3tc_srgbImpl.h +1 -1
  322. package/platforms/ios/src/cpp/webgl/extensions/WEBGL_depth_textureImpl.h +1 -1
  323. package/platforms/ios/src/cpp/webgl/extensions/WEBGL_draw_buffersImpl.h +1 -1
  324. package/platforms/ios/src/cpp/webgl/extensions/WEBGL_lose_contextImpl.h +1 -1
  325. package/platforms/ios/src/cpp/webgl2/WebGL2RenderingContext.cpp +1067 -960
  326. package/platforms/ios/src/cpp/webgl2/WebGL2RenderingContext.h +1 -1
  327. package/platforms/ios/src/cpp/webgl2/WebGLQuery.h +1 -1
  328. package/platforms/ios/src/cpp/webgl2/WebGLSampler.h +1 -1
  329. package/platforms/ios/src/cpp/webgl2/WebGLSyncImpl.h +1 -1
  330. package/platforms/ios/src/cpp/webgl2/WebGLTransformFeedback.h +1 -1
  331. package/platforms/ios/src/cpp/webgl2/WebGLVertexArrayObject.h +2 -2
  332. package/platforms/ios/src/cpp/webgpu/GPUAdapterImpl.cpp +371 -0
  333. package/platforms/ios/src/cpp/webgpu/GPUAdapterImpl.h +63 -0
  334. package/platforms/ios/src/cpp/webgpu/GPUAdapterInfoImpl.cpp +174 -0
  335. package/platforms/ios/src/cpp/webgpu/GPUAdapterInfoImpl.h +58 -0
  336. package/platforms/ios/src/cpp/webgpu/GPUBindGroupImpl.cpp +79 -0
  337. package/platforms/ios/src/cpp/webgpu/GPUBindGroupImpl.h +48 -0
  338. package/platforms/ios/src/cpp/webgpu/GPUBindGroupLayoutImpl.cpp +79 -0
  339. package/platforms/ios/src/cpp/webgpu/GPUBindGroupLayoutImpl.h +48 -0
  340. package/platforms/ios/src/cpp/webgpu/GPUBufferImpl.cpp +277 -0
  341. package/platforms/ios/src/cpp/webgpu/GPUBufferImpl.h +63 -0
  342. package/platforms/ios/src/cpp/webgpu/GPUCanvasContextImpl.cpp +379 -0
  343. package/platforms/ios/src/cpp/webgpu/GPUCanvasContextImpl.h +57 -0
  344. package/platforms/ios/src/cpp/webgpu/GPUCommandBufferImpl.cpp +81 -0
  345. package/platforms/ios/src/cpp/webgpu/GPUCommandBufferImpl.h +48 -0
  346. package/platforms/ios/src/cpp/webgpu/GPUCommandEncoderImpl.cpp +1217 -0
  347. package/platforms/ios/src/cpp/webgpu/GPUCommandEncoderImpl.h +73 -0
  348. package/platforms/ios/src/cpp/webgpu/GPUComputePassEncoderImpl.cpp +293 -0
  349. package/platforms/ios/src/cpp/webgpu/GPUComputePassEncoderImpl.h +65 -0
  350. package/platforms/ios/src/cpp/webgpu/GPUComputePipelineImpl.cpp +109 -0
  351. package/platforms/ios/src/cpp/webgpu/GPUComputePipelineImpl.h +51 -0
  352. package/platforms/ios/src/cpp/webgpu/GPUDeviceImpl.cpp +3701 -0
  353. package/platforms/ios/src/cpp/webgpu/GPUDeviceImpl.h +97 -0
  354. package/platforms/ios/src/cpp/webgpu/GPUImpl.cpp +200 -0
  355. package/platforms/ios/src/cpp/webgpu/GPUImpl.h +55 -0
  356. package/platforms/ios/src/cpp/webgpu/GPULabel.h +33 -0
  357. package/platforms/ios/src/cpp/webgpu/GPUPipelineLayoutImpl.cpp +80 -0
  358. package/platforms/ios/src/cpp/webgpu/GPUPipelineLayoutImpl.h +49 -0
  359. package/platforms/ios/src/cpp/webgpu/GPUQuerySetImpl.cpp +136 -0
  360. package/platforms/ios/src/cpp/webgpu/GPUQuerySetImpl.h +55 -0
  361. package/platforms/ios/src/cpp/webgpu/GPUQueueImpl.cpp +605 -0
  362. package/platforms/ios/src/cpp/webgpu/GPUQueueImpl.h +59 -0
  363. package/platforms/ios/src/cpp/webgpu/GPURenderBundleEncoderImpl.cpp +501 -0
  364. package/platforms/ios/src/cpp/webgpu/GPURenderBundleEncoderImpl.h +74 -0
  365. package/platforms/ios/src/cpp/webgpu/GPURenderBundleImpl.cpp +78 -0
  366. package/platforms/ios/src/cpp/webgpu/GPURenderBundleImpl.h +48 -0
  367. package/platforms/ios/src/cpp/webgpu/GPURenderPassEncoderImpl.cpp +723 -0
  368. package/platforms/ios/src/cpp/webgpu/GPURenderPassEncoderImpl.h +92 -0
  369. package/platforms/ios/src/cpp/webgpu/GPURenderPipelineImpl.cpp +109 -0
  370. package/platforms/ios/src/cpp/webgpu/GPURenderPipelineImpl.h +52 -0
  371. package/platforms/ios/src/cpp/webgpu/GPUSamplerImpl.cpp +79 -0
  372. package/platforms/ios/src/cpp/webgpu/GPUSamplerImpl.h +48 -0
  373. package/platforms/ios/src/cpp/webgpu/GPUShaderModuleImpl.cpp +80 -0
  374. package/platforms/ios/src/cpp/webgpu/GPUShaderModuleImpl.h +48 -0
  375. package/platforms/ios/src/cpp/webgpu/GPUSupportedLimitsImpl.cpp +1304 -0
  376. package/platforms/ios/src/cpp/webgpu/GPUSupportedLimitsImpl.h +288 -0
  377. package/platforms/ios/src/cpp/webgpu/GPUTextureImpl.cpp +386 -0
  378. package/platforms/ios/src/cpp/webgpu/GPUTextureImpl.h +77 -0
  379. package/platforms/ios/src/cpp/webgpu/GPUTextureViewImpl.cpp +79 -0
  380. package/platforms/ios/src/cpp/webgpu/GPUTextureViewImpl.h +48 -0
  381. package/platforms/ios/src/cpp/webgpu/GPUUtils.h +756 -0
  382. package/react/index.d.ts +1 -1
  383. package/utils.d.ts +1 -1
  384. package/utils.js.map +1 -1
  385. package/SVG/Circle.d.ts +0 -11
  386. package/SVG/Circle.js +0 -21
  387. package/SVG/Circle.js.map +0 -1
  388. package/SVG/ClipPath.d.ts +0 -4
  389. package/SVG/ClipPath.js +0 -9
  390. package/SVG/ClipPath.js.map +0 -1
  391. package/SVG/Defs.d.ts +0 -4
  392. package/SVG/Defs.js +0 -9
  393. package/SVG/Defs.js.map +0 -1
  394. package/SVG/Ellipse.d.ts +0 -13
  395. package/SVG/Ellipse.js +0 -26
  396. package/SVG/Ellipse.js.map +0 -1
  397. package/SVG/G.d.ts +0 -7
  398. package/SVG/G.js +0 -9
  399. package/SVG/G.js.map +0 -1
  400. package/SVG/Image.d.ts +0 -11
  401. package/SVG/Image.js +0 -40
  402. package/SVG/Image.js.map +0 -1
  403. package/SVG/Line.d.ts +0 -13
  404. package/SVG/Line.js +0 -26
  405. package/SVG/Line.js.map +0 -1
  406. package/SVG/LinearGradient.d.ts +0 -10
  407. package/SVG/LinearGradient.js +0 -13
  408. package/SVG/LinearGradient.js.map +0 -1
  409. package/SVG/Path.d.ts +0 -7
  410. package/SVG/Path.js +0 -14
  411. package/SVG/Path.js.map +0 -1
  412. package/SVG/Pattern.d.ts +0 -4
  413. package/SVG/Pattern.js +0 -9
  414. package/SVG/Pattern.js.map +0 -1
  415. package/SVG/Polygon.d.ts +0 -7
  416. package/SVG/Polygon.js +0 -14
  417. package/SVG/Polygon.js.map +0 -1
  418. package/SVG/Polyline.d.ts +0 -7
  419. package/SVG/Polyline.js +0 -14
  420. package/SVG/Polyline.js.map +0 -1
  421. package/SVG/Rect.d.ts +0 -8
  422. package/SVG/Rect.js +0 -13
  423. package/SVG/Rect.js.map +0 -1
  424. package/SVG/SVG.d.ts +0 -32
  425. package/SVG/SVG.js +0 -204
  426. package/SVG/SVG.js.map +0 -1
  427. package/SVG/SVGItem.d.ts +0 -5
  428. package/SVG/SVGItem.js +0 -8
  429. package/SVG/SVGItem.js.map +0 -1
  430. package/SVG/Stop.d.ts +0 -5
  431. package/SVG/Stop.js +0 -9
  432. package/SVG/Stop.js.map +0 -1
  433. package/SVG/Symbol.d.ts +0 -4
  434. package/SVG/Symbol.js +0 -9
  435. package/SVG/Symbol.js.map +0 -1
  436. package/SVG/Text.d.ts +0 -14
  437. package/SVG/Text.js +0 -26
  438. package/SVG/Text.js.map +0 -1
  439. package/SVG/Use.d.ts +0 -4
  440. package/SVG/Use.js +0 -9
  441. package/SVG/Use.js.map +0 -1
  442. package/SVG/index.d.ts +0 -18
  443. package/SVG/index.js +0 -19
  444. package/SVG/index.js.map +0 -1
  445. package/angular/fesm2020/nativescript-canvas-angular.mjs +0 -24
  446. package/angular/fesm2020/nativescript-canvas-angular.mjs.map +0 -1
  447. package/platforms/ios/src/cpp/PerIsolateData.cpp +0 -49
  448. package/platforms/ios/src/cpp/PerIsolateData.h +0 -54
  449. package/platforms/ios/src/cpp/URLImpl.cpp +0 -464
  450. package/platforms/ios/src/cpp/URLImpl.h +0 -121
  451. package/typings/objc!CanvasNative.d.ts +0 -2038
  452. package/typings/objc!CanvasNative.js +0 -1
  453. package/typings/objc!CanvasNative.js.map +0 -1
  454. /package/angular/{esm2020 → esm2022}/nativescript-canvas-angular.mjs +0 -0
@@ -7,7 +7,121 @@
7
7
  #include "JSIRuntime.h"
8
8
  #include "JSIReadFileCallback.h"
9
9
  #include "Helpers.h"
10
- #include "PerIsolateData.h"
10
+
11
+ struct GLOptions {
12
+ int32_t version;
13
+ bool alpha;
14
+ bool antialias;
15
+ bool depth;
16
+ bool failIfMajorPerformanceCaveat;
17
+ int32_t powerPreference;
18
+ bool premultipliedAlpha;
19
+ bool preserveDrawingBuffer;
20
+ bool stencil;
21
+ bool desynchronized;
22
+ bool xrCompatible;
23
+
24
+ public:
25
+ GLOptions() {
26
+ this->version = 0;
27
+ this->alpha = true;
28
+ this->antialias = true;
29
+ this->depth = true;
30
+ this->failIfMajorPerformanceCaveat = false;
31
+ this->powerPreference = 0;
32
+ this->premultipliedAlpha = true;
33
+ this->preserveDrawingBuffer = false;
34
+ this->stencil = false;
35
+ this->desynchronized = false;
36
+ this->xrCompatible = false;
37
+ }
38
+
39
+ void parseGLOptions(const v8::FunctionCallbackInfo<v8::Value> &args) {
40
+ auto configValue = args[0];
41
+
42
+ if (!(!configValue->IsNullOrUndefined() && configValue->IsObject())) {
43
+ return;
44
+ }
45
+
46
+ auto isolate = args.GetIsolate();
47
+ auto context = isolate->GetCurrentContext();
48
+ auto config = configValue.As<v8::Object>();
49
+
50
+ v8::Local<v8::Value> versionValue;
51
+
52
+ config->Get(context, ConvertToV8String(isolate, "version")).ToLocal(&versionValue);
53
+
54
+ if (!versionValue.IsEmpty() && versionValue->IsInt32()) {
55
+ versionValue->Int32Value(context).To(&this->version);
56
+ }
57
+
58
+ v8::Local<v8::Value> alphaValue;
59
+
60
+ config->Get(context, ConvertToV8String(isolate, "alpha")).ToLocal(&alphaValue);
61
+ if (!alphaValue.IsEmpty() && alphaValue->IsBoolean()) {
62
+ this->alpha = alphaValue->BooleanValue(isolate);
63
+ }
64
+
65
+ v8::Local<v8::Value> antialiasValue;
66
+ config->Get(context, ConvertToV8String(isolate, "antialias")).ToLocal(
67
+ &antialiasValue);
68
+ if (!antialiasValue.IsEmpty() && antialiasValue->IsBoolean()) {
69
+ this->antialias = antialiasValue->BooleanValue(isolate);
70
+ }
71
+
72
+ v8::Local<v8::Value> failIfMajorPerformanceCaveatValue;
73
+ config->Get(context, ConvertToV8String(isolate, "failIfMajorPerformanceCaveat")).ToLocal(
74
+ &failIfMajorPerformanceCaveatValue);
75
+ if (!failIfMajorPerformanceCaveatValue.IsEmpty() &&
76
+ failIfMajorPerformanceCaveatValue->IsBoolean()) {
77
+ this->failIfMajorPerformanceCaveat = failIfMajorPerformanceCaveatValue->BooleanValue(
78
+ isolate);
79
+ }
80
+
81
+ v8::Local<v8::Value> powerPreferenceValue;
82
+ config->Get(context, ConvertToV8String(isolate, "powerPreference")).ToLocal(
83
+ &powerPreferenceValue);
84
+ if (!powerPreferenceValue.IsEmpty() && powerPreferenceValue->IsInt32()) {
85
+ powerPreferenceValue->Int32Value(context).To(&this->powerPreference);
86
+ }
87
+
88
+ v8::Local<v8::Value> premultipliedAlphaValue;
89
+ config->Get(context,
90
+ ConvertToV8String(isolate, "premultipliedAlpha")).ToLocal(
91
+ &premultipliedAlphaValue);
92
+ if (!premultipliedAlphaValue.IsEmpty() && premultipliedAlphaValue->IsBoolean()) {
93
+ this->premultipliedAlpha = premultipliedAlphaValue->BooleanValue(isolate);
94
+ }
95
+
96
+ v8::Local<v8::Value> preserveDrawingBufferValue;
97
+ config->Get(context,
98
+ ConvertToV8String(isolate, "preserveDrawingBuffer")).ToLocal(
99
+ &preserveDrawingBufferValue);
100
+ if (!preserveDrawingBufferValue.IsEmpty() && preserveDrawingBufferValue->IsBoolean()) {
101
+ this->preserveDrawingBuffer = preserveDrawingBufferValue->BooleanValue(isolate);
102
+ }
103
+
104
+ v8::Local<v8::Value> stencilValue;
105
+ config->Get(context, ConvertToV8String(isolate, "stencil")).ToLocal(&stencilValue);
106
+ if (!stencilValue.IsEmpty() && stencilValue->IsBoolean()) {
107
+ this->stencil = stencilValue->BooleanValue(isolate);
108
+ }
109
+
110
+ v8::Local<v8::Value> desynchronizedValue;
111
+ config->Get(context, ConvertToV8String(isolate, "desynchronized")).ToLocal(
112
+ &desynchronizedValue);
113
+ if (!desynchronizedValue.IsEmpty() && desynchronizedValue->IsBoolean()) {
114
+ this->desynchronized = desynchronizedValue->BooleanValue(isolate);
115
+ }
116
+
117
+ v8::Local<v8::Value> xrCompatibleValue;
118
+ config->Get(context, ConvertToV8String(isolate, "xrCompatible")).ToLocal(
119
+ &xrCompatibleValue);
120
+ if (!xrCompatibleValue.IsEmpty() && xrCompatibleValue->IsBoolean()) {
121
+ this->xrCompatible = xrCompatibleValue->BooleanValue(isolate);
122
+ }
123
+ }
124
+ };
11
125
 
12
126
  void CanvasJSIModule::install(v8::Isolate *isolate) {
13
127
 
@@ -31,51 +145,66 @@ void CanvasJSIModule::install(v8::Isolate *isolate) {
31
145
  Path2D::Init(canvasMod, isolate);
32
146
  ImageDataImpl::Init(canvasMod, isolate);
33
147
  ImageAssetImpl::Init(canvasMod, isolate);
148
+ ImageBitmapImpl::Init(canvasMod, isolate);
34
149
  CanvasGradient::Init(canvasMod, isolate);
35
150
  CanvasPattern::Init(canvasMod, isolate);
36
151
  MatrixImpl::Init(canvasMod, isolate);
37
152
  TextMetricsImpl::Init(canvasMod, isolate);
38
- URLImpl::Init(canvasMod, isolate);
39
153
 
40
- // always use the last slot
41
- auto lastSlot = isolate->GetNumberOfDataSlots() - 1;
42
- auto data = new PerIsolateData(isolate);
43
- isolate->SetData(lastSlot, data);
44
154
 
45
- v8Global->Set(context, ConvertToV8String(isolate, "CanvasModule"), canvasMod);
155
+ GPUImpl::Init(canvasMod, isolate);
156
+ GPUSupportedLimitsImpl::Init(canvasMod, isolate);
157
+ GPUDeviceImpl::Init(canvasMod, isolate);
158
+ GPUQueueImpl::Init(canvasMod, isolate);
159
+
160
+ v8Global->Set(context, ConvertToV8String(isolate, "CanvasModule"), canvasMod).FromJust();
46
161
  canvasMod->Set(context, ConvertToV8String(isolate, "create2DContext"),
47
162
  v8::FunctionTemplate::New(isolate, &Create2DContext)->GetFunction(
48
- context).ToLocalChecked());
163
+ context).ToLocalChecked()).FromJust();
49
164
  canvasMod->Set(context, ConvertToV8String(isolate, "createImageBitmap"),
50
165
  v8::FunctionTemplate::New(isolate, &CreateImageBitmap)->GetFunction(
51
- context).ToLocalChecked());
166
+ context).ToLocalChecked()).FromJust();
52
167
  canvasMod->Set(context, ConvertToV8String(isolate, "create2DContextWithPointer"),
53
168
  v8::FunctionTemplate::New(isolate, &Create2DContextWithPointer)->GetFunction(
54
- context).ToLocalChecked());
169
+ context).ToLocalChecked()).FromJust();
170
+
171
+ canvasMod->Set(context, ConvertToV8String(isolate, "createWebGPUContextWithPointer"),
172
+ v8::FunctionTemplate::New(isolate,
173
+ &CreateWebGPUContextWithPointer)->GetFunction(
174
+ context).ToLocalChecked()).FromJust();
175
+
176
+
55
177
  canvasMod->Set(context, ConvertToV8String(isolate, "readFile"),
56
178
  v8::FunctionTemplate::New(isolate, &ReadFile)->GetFunction(
57
- context).ToLocalChecked());
179
+ context).ToLocalChecked()).FromJust();
180
+
181
+ canvasMod->Set(context, ConvertToV8String(isolate, "getMime"),
182
+ v8::FunctionTemplate::New(isolate, &GetMime)->GetFunction(
183
+ context).ToLocalChecked()).FromJust();
58
184
 
59
185
  canvasMod->Set(context, ConvertToV8String(isolate, "createWebGLContext"),
60
186
  v8::FunctionTemplate::New(isolate, &CreateWebGLContext)->GetFunction(
61
- context).ToLocalChecked());
187
+ context).ToLocalChecked()).FromJust();
62
188
 
63
189
  canvasMod->Set(context, ConvertToV8String(isolate, "createWebGL2Context"),
64
190
  v8::FunctionTemplate::New(isolate, &CreateWebGL2Context)->GetFunction(
65
- context).ToLocalChecked());
191
+ context).ToLocalChecked()).FromJust();
66
192
 
67
193
 
68
194
  canvasMod->Set(context, ConvertToV8String(isolate, "__addFontFamily"),
69
195
  v8::FunctionTemplate::New(isolate, &AddFontFamily)->GetFunction(
70
- context).ToLocalChecked());
196
+ context).ToLocalChecked()).FromJust();
197
+
198
+ canvasMod->Set(context, ConvertToV8String(isolate, "__addFontData"),
199
+ v8::FunctionTemplate::New(isolate, &AddFontData)->GetFunction(
200
+ context).ToLocalChecked()).FromJust();
71
201
 
72
202
  global->Set(context,
73
- ConvertToV8String(isolate, "CanvasModule"), canvasMod);
203
+ ConvertToV8String(isolate, "CanvasModule"), canvasMod).FromJust();
74
204
 
75
205
  }
76
206
  }
77
207
 
78
-
79
208
  void CanvasJSIModule::AddFontFamily(const v8::FunctionCallbackInfo<v8::Value> &args) {
80
209
  auto isolate = args.GetIsolate();
81
210
  auto context = isolate->GetCurrentContext();
@@ -107,23 +236,55 @@ void CanvasJSIModule::AddFontFamily(const v8::FunctionCallbackInfo<v8::Value> &a
107
236
 
108
237
  }
109
238
 
239
+ void CanvasJSIModule::AddFontData(const v8::FunctionCallbackInfo<v8::Value> &args) {
240
+ auto isolate = args.GetIsolate();
241
+ auto context = isolate->GetCurrentContext();
242
+ auto aliasValue = args[0];
243
+ auto dataValue = args[1];
244
+
245
+ // todo improve
246
+ if (dataValue->IsArrayBuffer()) {
247
+
248
+ if (aliasValue->IsString()) {
249
+ auto alias = ConvertFromV8String(isolate, aliasValue);
250
+ auto data = dataValue.As<v8::ArrayBuffer>();
251
+ auto store = data->GetBackingStore();
252
+ canvas_native_font_add_family_with_bytes(alias.c_str(), (uint8_t *) store->Data(),
253
+ store->ByteLength());
254
+ } else {
255
+ auto data = dataValue.As<v8::ArrayBuffer>();
256
+ auto store = data->GetBackingStore();
257
+ canvas_native_font_add_family_with_bytes(nullptr, (uint8_t *) store->Data(),
258
+ store->ByteLength());
259
+ }
260
+
261
+ } else if (dataValue->IsTypedArray()) {
262
+
263
+ if (aliasValue->IsString()) {
264
+ auto alias = ConvertFromV8String(isolate, aliasValue);
265
+ auto data = dataValue.As<v8::TypedArray>();
266
+ auto buffer = data->Buffer();
267
+ auto store = buffer->GetBackingStore();
268
+ canvas_native_font_add_family_with_bytes(alias.c_str(), (uint8_t *) store->Data(),
269
+ store->ByteLength());
270
+ } else {
271
+ auto data = dataValue.As<v8::TypedArray>();
272
+ auto buffer = data->Buffer();
273
+ auto store = buffer->GetBackingStore();
274
+ canvas_native_font_add_family_with_bytes(nullptr, (uint8_t *) store->Data(),
275
+ store->ByteLength());
276
+ }
277
+
278
+ }
279
+
280
+ }
281
+
110
282
  void CanvasJSIModule::Create2DContext(const v8::FunctionCallbackInfo<v8::Value> &args) {
111
283
  auto isolate = args.GetIsolate();
112
284
  auto context = isolate->GetCurrentContext();
113
285
  auto ptr = args[0].As<v8::BigInt>()->Int64Value();
114
- auto width = (float) args[1]->NumberValue(context).ToChecked();
115
- auto height = (float) args[2]->NumberValue(context).ToChecked();
116
- auto density = (float) args[3]->NumberValue(context).ToChecked();
117
- auto samples = (int) args[4]->NumberValue(context).ToChecked();
118
- auto alpha = (bool) args[5]->BooleanValue(isolate);
119
- auto font_color = (int) args[6]->NumberValue(context).ToChecked();
120
- auto ppi = (float) args[7]->NumberValue(context).ToChecked();
121
- auto direction = (int) args[8]->NumberValue(context).ToChecked();
122
-
123
- auto context_2d = canvas_native_context_create_gl(width, height, density,
124
- ptr,
125
- samples, alpha,
126
- font_color, ppi, direction);
286
+
287
+ auto context_2d = static_cast<CanvasRenderingContext2D *>((void *) ptr);
127
288
 
128
289
  auto ret = CanvasRenderingContext2DImpl::NewInstance(isolate, new CanvasRenderingContext2DImpl(
129
290
  context_2d));
@@ -131,6 +292,32 @@ void CanvasJSIModule::Create2DContext(const v8::FunctionCallbackInfo<v8::Value>
131
292
  args.GetReturnValue().Set(ret);
132
293
  }
133
294
 
295
+
296
+ struct Rect {
297
+ float x;
298
+ float y;
299
+ float width;
300
+ float height;
301
+ };
302
+
303
+ struct ImageBitmapData {
304
+ char *error_;
305
+ const ImageAsset *asset_;
306
+ bool done_;
307
+ v8::Isolate *isolate_;
308
+ std::shared_ptr<v8::Persistent<v8::ArrayBufferView>> data_;
309
+
310
+ ~ImageBitmapData() {
311
+ if (error_ != nullptr) {
312
+ canvas_native_string_destroy(error_);
313
+ error_ = nullptr;
314
+ }
315
+
316
+ data_->Reset();
317
+ }
318
+ };
319
+
320
+
134
321
  void CanvasJSIModule::CreateImageBitmap(const v8::FunctionCallbackInfo<v8::Value> &args) {
135
322
  auto count = args.Length();
136
323
  auto isolate = args.GetIsolate();
@@ -165,7 +352,7 @@ void CanvasJSIModule::CreateImageBitmap(const v8::FunctionCallbackInfo<v8::Value
165
352
 
166
353
  if (image->IsNullOrUndefined()) {
167
354
  v8::Local<v8::Value> ret[2] = {ConvertToV8String(isolate, "Failed to load image"),
168
- v8::Undefined(isolate)};
355
+ v8::Null(isolate)};
169
356
 
170
357
  cb.As<v8::Function>()->Call(context, context->Global(), 2, ret);
171
358
  return;
@@ -175,7 +362,7 @@ void CanvasJSIModule::CreateImageBitmap(const v8::FunctionCallbackInfo<v8::Value
175
362
 
176
363
  v8::Local<v8::Value> ret[2] = {ConvertToV8String(isolate,
177
364
  "Failed to execute 'createImageBitmap' : The crop rect width is 0"),
178
- v8::Undefined(isolate)};
365
+ v8::Null(isolate)};
179
366
 
180
367
  cb.As<v8::Function>()->Call(context, context->Global(), 2, ret);
181
368
 
@@ -184,630 +371,140 @@ void CanvasJSIModule::CreateImageBitmap(const v8::FunctionCallbackInfo<v8::Value
184
371
  if (len >= 5 && (sh->IsNumber() && sh->IsNumber() == 0)) {
185
372
  v8::Local<v8::Value> ret[2] = {ConvertToV8String(isolate,
186
373
  "Failed to execute 'createImageBitmap' : The crop rect height is 0"),
187
- v8::Undefined(isolate)};
374
+ v8::Null(isolate)};
188
375
 
189
376
  cb.As<v8::Function>()->Call(context, context->Global(), 2, ret);
190
377
  return;
191
378
  }
192
379
 
193
-
194
380
  if (image->IsObject()) {
195
381
  auto imageObject = image.As<v8::Object>();
196
382
  auto isArrayBuffer = imageObject->IsArrayBuffer();
197
383
  auto IsArrayBufferView = imageObject->IsArrayBufferView();
198
- if (isArrayBuffer || IsArrayBufferView) {
384
+ std::optional<Rect> rect = std::nullopt;
199
385
 
200
- if (len == 1 || len == 2) {
386
+ if (isArrayBuffer || IsArrayBufferView) {
387
+ if ((len == 1 || len == 2) || (len == 5 || len == 6)) {
201
388
  if (len == 2) {
202
389
  options = ImageBitmapImpl::HandleOptions(isolate, args[1]);
203
390
  }
204
391
 
205
- auto asset = canvas_native_image_asset_create();
206
-
207
- auto shared_asset = canvas_native_image_asset_shared_clone(asset);
208
-
209
- auto ret = new ImageBitmapImpl(asset);
210
-
392
+ if (len == 6) {
393
+ options = ImageBitmapImpl::HandleOptions(isolate, args[5]);
394
+ }
211
395
 
212
396
  auto cbFunc = args[count - 1].As<v8::Function>();
213
- auto data = v8::External::New(isolate, ret);
214
-
215
- auto jsi_callback = new JSICallback(isolate, cbFunc, data);
216
-
217
-
218
- #ifdef __ANDROID__
219
- ALooper_addFd(jsi_callback->looper_,
220
- jsi_callback->fd_[0],
221
- ALOOPER_POLL_CALLBACK,
222
- ALOOPER_EVENT_INPUT,
223
- [](int fd, int events,
224
- void *data) {
225
- auto cb = static_cast<JSICallback *>(data);
226
- bool done;
227
- read(fd, &done,
228
- sizeof(bool));
229
-
230
-
231
- v8::Isolate *isolate = cb->isolate_;
232
- v8::Locker locker(isolate);
233
- v8::Isolate::Scope isolate_scope(isolate);
234
- v8::HandleScope handle_scope(isolate);
235
- v8::Local<v8::Function> callback = cb->callback_->Get(isolate);
236
- v8::Local<v8::External> cbData = cb->data_->Get(
237
- isolate).As<v8::External>();
238
- v8::Local<v8::Context> context = callback->GetCreationContextChecked();
239
- v8::Context::Scope context_scope(context);
240
-
241
- auto ret = ImageBitmapImpl::NewInstance(isolate, cbData);
242
-
243
- v8::Local<v8::Value> args[2];
244
-
245
- if (done) {
246
- args[0] = v8::Null(isolate);
247
- args[1] = ret;
248
-
249
- } else {
250
- args[0] = v8::Exception::Error(
251
- ConvertToV8String(isolate, "Failed to load image"));
252
- args[1] = v8::Null(isolate);
253
- }
254
-
255
-
256
- callback->Call(context, context->Global(), 2, args);
257
-
258
- delete static_cast<JSICallback *>(data);
259
- return 0;
260
- }, jsi_callback);
261
-
262
- ALooper_wake(jsi_callback->looper_);
263
397
 
264
398
  if (isArrayBuffer) {
265
399
  auto arrayBuffer = imageObject.As<v8::ArrayBuffer>();
266
- auto store = arrayBuffer->GetBackingStore();
267
- auto dataBuffer = (uint8_t *) store->Data();
268
- v8::Global<v8::ArrayBuffer> ab(isolate, arrayBuffer);
269
- std::thread thread(
270
- [&dataBuffer, jsi_callback, &options, store, shared_asset](
271
- v8::Global<v8::ArrayBuffer> ab, size_t size) {
272
-
273
-
274
- auto done = canvas_native_image_bitmap_create_from_encoded_bytes_with_output(
275
- dataBuffer, size,
276
- options.flipY,
277
- options.premultiplyAlpha,
278
- options.colorSpaceConversion,
279
- options.resizeQuality,
280
- options.resizeWidth,
281
- options.resizeHeight,
282
- shared_asset);
283
-
284
- canvas_native_image_asset_destroy(shared_asset);
285
-
286
- write(jsi_callback->fd_[1],
287
- &done,
288
- sizeof(bool));
289
-
290
-
291
- }, std::move(ab), arrayBuffer->ByteLength());
292
-
293
- thread.detach();
294
- return;
400
+ auto size = arrayBuffer->ByteLength();
401
+ imageObject = v8::Uint8Array::New(arrayBuffer, 0, size);
295
402
  }
296
403
 
297
-
298
404
  auto ta = imageObject.As<v8::ArrayBufferView>();
299
405
 
406
+ auto image_bitmap_async_data = new ImageBitmapData();
407
+ image_bitmap_async_data->isolate_ = isolate;
408
+ image_bitmap_async_data->data_ = std::make_shared<v8::Persistent<v8::ArrayBufferView>>(
409
+ isolate, ta);
300
410
 
301
- auto array = ta->Buffer();
302
- auto offset = ta->ByteOffset();
303
- auto size = ta->ByteLength();
304
- auto data_ptr = static_cast<uint8_t *>(array->GetBackingStore()->Data()) + offset;
305
-
306
-
307
- v8::Global<v8::ArrayBufferView> ab(isolate, ta);
308
-
309
- std::thread thread(
310
- [jsi_callback, &options, shared_asset, data_ptr, size](
311
- v8::Global<v8::ArrayBufferView> ab) {
312
-
313
- auto done = canvas_native_image_bitmap_create_from_encoded_bytes_with_output(
314
- data_ptr, size,
315
- options.flipY,
316
- options.premultiplyAlpha,
317
- options.colorSpaceConversion,
318
- options.resizeQuality,
319
- options.resizeWidth,
320
- options.resizeHeight,
321
- shared_asset);
322
-
323
- canvas_native_image_asset_destroy(shared_asset);
324
-
325
- write(jsi_callback->fd_[1],
326
- &done,
327
- sizeof(bool));
328
-
329
-
330
- }, std::move(ab));
331
- thread.detach();
332
-
333
- #endif
334
-
335
-
336
- #ifdef __APPLE__
337
-
338
- auto current_queue = new NSOperationQueueWrapper(true);
339
-
340
-
341
- if (isArrayBuffer) {
342
- auto arrayBuffer = imageObject.As<v8::ArrayBuffer>();
343
- auto store = arrayBuffer->GetBackingStore();
344
- auto dataBuffer = (uint8_t *) store->Data();
345
- v8::Global<v8::ArrayBuffer> ab(isolate, arrayBuffer);
346
-
347
- std::thread thread(
348
- [&dataBuffer, jsi_callback, &options, store, shared_asset, current_queue](
349
- v8::Global<v8::ArrayBuffer> ab, size_t size
350
- ) {
351
-
352
- auto done = canvas_native_image_bitmap_create_from_encoded_bytes_with_output(
353
- dataBuffer, size,
354
- options.flipY,
355
- options.premultiplyAlpha,
356
- options.colorSpaceConversion,
357
- options.resizeQuality,
358
- options.resizeWidth,
359
- options.resizeHeight,
360
- shared_asset);
361
-
362
- canvas_native_image_asset_destroy(shared_asset);
363
-
364
-
365
- auto main_task = [jsi_callback, current_queue, done]() {
366
-
411
+ auto callback = new AsyncCallback(isolate, cbFunc, [](bool done, void *data) {
412
+ if (data == nullptr) { return; }
413
+ auto async_data = static_cast<AsyncCallback *>(data);
414
+ auto func = async_data->inner_.get();
415
+ if (func != nullptr && func->isolate_ != nullptr) {
416
+ v8::Isolate *isolate = func->isolate_;
417
+ v8::Locker locker(isolate);
418
+ v8::Isolate::Scope isolate_scope(isolate);
419
+ v8::HandleScope handle_scope(isolate);
420
+ v8::Local<v8::Function> callback = func->callback_.Get(
421
+ isolate);
422
+ v8::Local<v8::Context> context = callback->GetCreationContextChecked();
423
+ v8::Context::Scope context_scope(context);
367
424
 
368
- v8::Isolate *isolate = jsi_callback->isolate_;
369
- v8::Locker locker(isolate);
370
- v8::Isolate::Scope isolate_scope(isolate);
371
- v8::HandleScope handle_scope(isolate);
372
- v8::Local<v8::Function> callback = jsi_callback->callback_->Get(isolate);
373
- v8::Local<v8::External> cbData = jsi_callback->data_->Get(
374
- isolate).As<v8::External>();
375
- v8::Local<v8::Context> context = callback->GetCreationContextChecked();
376
- v8::Context::Scope context_scope(context);
425
+ if (func->data != nullptr) {
426
+ auto asset_data = static_cast<ImageBitmapData *>(func->data);
377
427
 
378
- auto ret = ImageBitmapImpl::NewInstance(isolate, cbData);
428
+ auto bitmap = new ImageBitmapImpl(asset_data->asset_);
429
+ auto external = v8::External::New(isolate, bitmap);
379
430
 
380
- v8::Local<v8::Value> args[2];
431
+ auto ret = ImageBitmapImpl::NewInstance(isolate, external);
381
432
 
382
- if (done) {
383
- args[0] = v8::Null(isolate);
384
- args[1] = ret;
433
+ v8::Local<v8::Value> args[2] = {
434
+ v8::Null(isolate), ret};
385
435
 
386
- } else {
387
- args[0] = v8::Exception::Error(
388
- ConvertToV8String(isolate, "Failed to load image"));
389
- args[1] = v8::Null(isolate);
390
- }
391
436
 
437
+ callback->Call(context, context->Global(),
438
+ 2,
439
+ args); // ignore JS return value
392
440
 
393
- callback->Call(context, context->Global(), 2, args);
441
+ delete asset_data;
394
442
 
443
+ } else {
444
+ v8::Local<v8::Value> args[1] = {
445
+ v8::Null(isolate)};
395
446
 
396
- delete jsi_callback;
397
- delete current_queue;
398
-
399
- };
400
- current_queue->addOperation(main_task);
401
-
402
- }, std::move(ab), arrayBuffer->ByteLength());
403
-
404
- thread.detach();
405
-
406
- return;
407
- }
408
-
409
- auto ta = imageObject.As<v8::ArrayBufferView>();
447
+ callback->Call(context, context->Global(),
448
+ 1,
449
+ args); // ignore JS return value
450
+ }
410
451
 
452
+ }
453
+ delete static_cast<AsyncCallback *>(data);
454
+ });
411
455
 
412
- auto array = ta->Buffer();
456
+ callback->inner_->data = image_bitmap_async_data;
457
+ callback->prepare();
458
+ auto store = ta->Buffer()->GetBackingStore();
413
459
  auto offset = ta->ByteOffset();
414
- auto size = ta->ByteLength();
415
- auto data_ptr = static_cast<uint8_t *>(array->GetBackingStore()->Data()) + offset;
416
-
417
-
418
- v8::Global<v8::ArrayBufferView> ab(isolate, ta);
419
-
420
460
 
421
461
  std::thread thread(
422
- [jsi_callback, &options, shared_asset, data_ptr, size, current_queue](
423
- v8::Global<v8::ArrayBufferView> ab
424
- ) {
425
-
426
- auto done = canvas_native_image_bitmap_create_from_encoded_bytes_with_output(
427
- data_ptr, size,
428
- options.flipY,
429
- options.premultiplyAlpha,
430
- options.colorSpaceConversion,
431
- options.resizeQuality,
432
- options.resizeWidth,
433
- options.resizeHeight,
434
- shared_asset);
435
-
436
- canvas_native_image_asset_destroy(shared_asset);
437
-
438
- auto main_task = [jsi_callback, current_queue, done]() {
439
-
440
-
441
- v8::Isolate *isolate = jsi_callback->isolate_;
442
- v8::Locker locker(isolate);
443
- v8::Isolate::Scope isolate_scope(isolate);
444
- v8::HandleScope handle_scope(isolate);
445
- v8::Local<v8::Function> callback = jsi_callback->callback_->Get(isolate);
446
- v8::Local<v8::External> cbData = jsi_callback->data_->Get(
447
- isolate).As<v8::External>();
448
- v8::Local<v8::Context> context = callback->GetCreationContextChecked();
449
- v8::Context::Scope context_scope(context);
450
-
451
- auto ret = ImageBitmapImpl::NewInstance(isolate, cbData);
452
-
453
- v8::Local<v8::Value> args[2];
454
-
455
- if (done) {
456
- args[0] = v8::Null(isolate);
457
- args[1] = ret;
458
- } else {
459
- args[0] = v8::Exception::Error(
460
- ConvertToV8String(isolate, "Failed to load image"));
461
- args[1] = v8::Null(isolate);
462
- }
463
-
464
- callback->Call(context, context->Global(), 2, args);
465
-
466
-
467
- delete jsi_callback;
468
- delete current_queue;
469
-
470
- };
471
- current_queue->addOperation(main_task);
472
-
473
-
474
-
475
- }, std::move(ab));
476
- thread.detach();
477
-
478
- #endif
479
-
480
- return;
481
- } else if (len == 5 || len == 6) {
482
- auto asset = canvas_native_image_asset_create();
483
-
484
- auto shared_asset = canvas_native_image_asset_shared_clone(asset);
485
-
486
- auto ret = new ImageBitmapImpl(asset);
487
-
488
- auto cbFunc = args[count - 1].As<v8::Function>();
489
- auto data = v8::External::New(isolate, ret);
490
- if (len == 6) {
491
- options = ImageBitmapImpl::HandleOptions(isolate, args[5]);
492
- }
493
-
494
- auto jsi_callback = new JSICallback(isolate, cbFunc, data);
495
-
496
-
497
- #ifdef __ANDROID__
498
- ALooper_addFd(jsi_callback->looper_,
499
- jsi_callback->fd_[0],
500
- ALOOPER_POLL_CALLBACK,
501
- ALOOPER_EVENT_INPUT,
502
- [](int fd, int events,
503
- void *data) {
504
- auto cb = static_cast<JSICallback *>(data);
505
- bool done;
506
- read(fd, &done,
507
- sizeof(bool));
508
-
509
- v8::Isolate *isolate = cb->isolate_;
510
- v8::Locker locker(isolate);
511
- v8::Isolate::Scope isolate_scope(isolate);
512
- v8::HandleScope handle_scope(isolate);
513
- v8::Local<v8::Function> callback = cb->callback_->Get(isolate);
514
- v8::Local<v8::External> cbData = cb->data_->Get(
515
- isolate).As<v8::External>();
516
- v8::Local<v8::Context> context = callback->GetCreationContextChecked();
517
- v8::Context::Scope context_scope(context);
518
-
519
- auto ret = ImageBitmapImpl::NewInstance(isolate, cbData);
520
-
521
- v8::Local<v8::Value> args[2];
522
-
523
- if (done) {
524
- args[0] = v8::Null(isolate);
525
- args[1] = ret;
526
- } else {
527
- args[0] = v8::Exception::Error(
528
- ConvertToV8String(isolate, "Failed to load image"));
529
- args[1] = v8::Null(isolate);
530
- }
531
-
532
- callback->Call(context, context->Global(), 2, args);
533
-
534
- delete static_cast<JSICallback *>(data);
535
- return 0;
536
- }, jsi_callback);
537
-
538
- ALooper_wake(jsi_callback->looper_);
539
-
540
- auto bufferValue = args[0];
541
-
542
- if (isArrayBuffer) {
543
- auto arrayBuffer = bufferValue.As<v8::ArrayBuffer>();
544
- auto dataBuffer = (uint8_t *) arrayBuffer->GetBackingStore()->Data();
545
- v8::Global<v8::ArrayBuffer> ab(isolate, arrayBuffer);
546
- std::thread thread(
547
- [&dataBuffer, jsi_callback, &options, shared_asset](
548
- float sx_or_options,
549
- float sy,
550
- float sw,
551
- float sh,
552
- v8::Global<v8::ArrayBuffer> ab,
553
- size_t size
554
- ) {
555
-
556
- auto done = canvas_native_image_bitmap_create_from_encoded_bytes_src_rect_with_output(
557
- dataBuffer, size,
558
- sx_or_options,
559
- sy,
560
- sw,
561
- sh,
462
+ [callback, image_bitmap_async_data, offset, options, rect](
463
+ std::shared_ptr<v8::BackingStore> store) {
464
+
465
+ auto data = static_cast<uint8_t *>(store->Data()) + offset;
466
+ auto size = store->ByteLength();
467
+
468
+ auto asset = canvas_native_image_asset_create();
469
+ bool done;
470
+ if (rect.has_value()) {
471
+
472
+ done = canvas_native_image_bitmap_create_from_encoded_bytes_src_rect_with_output(
473
+ data, size,
474
+ rect.value().x,
475
+ rect.value().y,
476
+ rect.value().width,
477
+ rect.value().height,
562
478
  options.flipY,
563
479
  options.premultiplyAlpha,
564
480
  options.colorSpaceConversion,
565
481
  options.resizeQuality,
566
482
  options.resizeWidth,
567
- options.resizeHeight, shared_asset);
568
-
569
- canvas_native_image_asset_destroy(shared_asset);
570
-
571
-
572
- write(jsi_callback->fd_[1],
573
- &done,
574
- sizeof(bool));
575
-
576
- },
577
- (float) sx_or_options->NumberValue(context).ToChecked(),
578
- (float) sy->NumberValue(context).ToChecked(),
579
- (float) sw->NumberValue(context).ToChecked(),
580
- (float) sh->NumberValue(context).ToChecked(), std::move(ab),
581
- arrayBuffer->ByteLength());
582
-
583
- thread.detach();
584
-
585
- return;
586
- }
587
-
588
- auto ta = bufferValue.As<v8::ArrayBufferView>();
589
-
590
- auto array = ta->Buffer();
591
- auto offset = ta->ByteOffset();
592
- auto size = ta->ByteLength();
593
- auto data_ptr = static_cast<uint8_t *>(array->GetBackingStore()->Data()) + offset;
594
-
595
-
596
- v8::Global<v8::ArrayBufferView> ab(isolate, ta);
597
- std::thread thread(
598
- [jsi_callback, &options, shared_asset, data_ptr, size](
599
- float sx_or_options,
600
- float sy,
601
- float sw,
602
- float sh,
603
- v8::Global<v8::ArrayBufferView> ab
604
- ) {
605
-
606
- auto done = canvas_native_image_bitmap_create_from_encoded_bytes_src_rect_with_output(
607
- data_ptr, size,
608
- sx_or_options,
609
- sy,
610
- sw,
611
- sh,
612
- options.flipY,
613
- options.premultiplyAlpha,
614
- options.colorSpaceConversion,
615
- options.resizeQuality,
616
- options.resizeWidth,
617
- options.resizeHeight, shared_asset);
618
-
619
- canvas_native_image_asset_destroy(shared_asset);
620
-
621
-
622
- write(jsi_callback->fd_[1],
623
- &done,
624
- sizeof(bool));
625
-
626
- },
627
- (float) sx_or_options->NumberValue(context).ToChecked(),
628
- (float) sy->NumberValue(context).ToChecked(),
629
- (float) sw->NumberValue(context).ToChecked(),
630
- (float) sh->NumberValue(context).ToChecked(), std::move(ab));
631
- thread.detach();
632
-
633
- #endif
634
-
635
- #ifdef __APPLE__
636
-
637
- auto current_queue = new NSOperationQueueWrapper(true);
638
-
639
-
640
- auto bufferValue = args[0];
641
-
642
- if (isArrayBuffer) {
643
- auto arrayBuffer = bufferValue.As<v8::ArrayBuffer>();
644
- auto dataBuffer = (uint8_t *) arrayBuffer->GetBackingStore()->Data();
645
- v8::Global<v8::ArrayBuffer> ab(isolate, arrayBuffer);
646
- std::thread thread(
647
- [&dataBuffer, jsi_callback, &options, shared_asset, current_queue](
648
- float sx_or_options,
649
- float sy,
650
- float sw,
651
- float sh,
652
- v8::Global<v8::ArrayBuffer> ab,
653
- size_t size
654
- ) {
655
-
656
- auto done = canvas_native_image_bitmap_create_from_encoded_bytes_src_rect_with_output(
657
- dataBuffer, size,
658
- sx_or_options,
659
- sy,
660
- sw,
661
- sh,
483
+ options.resizeHeight, asset);
484
+ } else {
485
+ done = canvas_native_image_bitmap_create_from_encoded_bytes_with_output(
486
+ data, size,
662
487
  options.flipY,
663
488
  options.premultiplyAlpha,
664
489
  options.colorSpaceConversion,
665
490
  options.resizeQuality,
666
491
  options.resizeWidth,
667
- options.resizeHeight, shared_asset);
668
-
669
- canvas_native_image_asset_destroy(shared_asset);
670
-
671
-
672
- auto main_task = [jsi_callback, current_queue, done]() {
673
-
674
-
675
- v8::Isolate *isolate = jsi_callback->isolate_;
676
- v8::Locker locker(isolate);
677
- v8::Isolate::Scope isolate_scope(isolate);
678
- v8::HandleScope handle_scope(isolate);
679
- v8::Local<v8::Function> callback = jsi_callback->callback_->Get(isolate);
680
- v8::Local<v8::External> cbData = jsi_callback->data_->Get(
681
- isolate).As<v8::External>();
682
- v8::Local<v8::Context> context = callback->GetCreationContextChecked();
683
- v8::Context::Scope context_scope(context);
684
-
685
-
686
-
687
- auto ret = ImageBitmapImpl::NewInstance(isolate, cbData);
688
-
689
- v8::Local<v8::Value> args[2];
690
-
691
- if (done) {
692
- args[0] = v8::Null(isolate);
693
- args[1] = ret;
694
- } else {
695
- args[0] = v8::Exception::Error(
696
- ConvertToV8String(isolate, "Failed to load image"));
697
- args[1] = v8::Null(isolate);
698
- }
699
-
700
- callback->Call(context, context->Global(), 2, args);
701
-
702
-
703
- delete jsi_callback;
704
- delete current_queue;
705
-
706
- };
707
- current_queue->addOperation(main_task);
708
-
709
- },
710
- (float) sx_or_options->NumberValue(context).ToChecked(),
711
- (float) sy->NumberValue(context).ToChecked(),
712
- (float) sw->NumberValue(context).ToChecked(),
713
- (float) sh->NumberValue(context).ToChecked(),
714
- std::move(ab),
715
- arrayBuffer->ByteLength());
716
-
717
- thread.detach();
718
-
719
- return;
720
- }
721
-
722
- auto ta = bufferValue.As<v8::ArrayBufferView>();
723
-
724
- auto array = ta->Buffer();
725
- auto offset = ta->ByteOffset();
726
- auto size = ta->ByteLength();
727
- auto data_ptr = static_cast<uint8_t*>(array->GetBackingStore()->Data()) + offset;
728
-
729
-
730
-
731
- v8::Global<v8::ArrayBufferView> ab(isolate, ta);
732
- std::thread thread(
733
- [jsi_callback, &options, data_ptr, size, shared_asset, current_queue](
734
- float sx_or_options,
735
- float sy,
736
- float sw,
737
- float sh,
738
- v8::Global<v8::ArrayBufferView> ab
739
- ) {
740
-
741
- auto done = canvas_native_image_bitmap_create_from_encoded_bytes_src_rect_with_output(
742
- data_ptr, size,
743
- sx_or_options,
744
- sy,
745
- sw,
746
- sh,
747
- options.flipY,
748
- options.premultiplyAlpha,
749
- options.colorSpaceConversion,
750
- options.resizeQuality,
751
- options.resizeWidth,
752
- options.resizeHeight, shared_asset);
753
-
754
- canvas_native_image_asset_destroy(shared_asset);
755
-
756
- auto main_task = [jsi_callback, current_queue, done]() {
757
-
758
-
759
- v8::Isolate *isolate = jsi_callback->isolate_;
760
- v8::Locker locker(isolate);
761
- v8::Isolate::Scope isolate_scope(isolate);
762
- v8::HandleScope handle_scope(isolate);
763
- v8::Local<v8::Function> callback = jsi_callback->callback_->Get(isolate);
764
- v8::Local<v8::External> cbData = jsi_callback->data_->Get(
765
- isolate).As<v8::External>();
766
- v8::Local<v8::Context> context = callback->GetCreationContextChecked();
767
- v8::Context::Scope context_scope(context);
768
-
769
- auto ret = ImageBitmapImpl::NewInstance(isolate, cbData);
770
-
771
- v8::Local<v8::Value> args[2];
772
-
773
- if (done) {
774
- args[0] = v8::Null(isolate);
775
- args[1] = ret;
776
- } else {
777
- args[0] = v8::Exception::Error(
778
- ConvertToV8String(isolate, "Failed to load image"));
779
- args[1] = v8::Null(isolate);
780
- }
781
-
782
- callback->Call(context, context->Global(), 2, args);
783
-
784
-
785
- delete jsi_callback;
786
- delete current_queue;
787
-
788
- };
789
- current_queue->addOperation(main_task);
790
-
791
-
792
-
793
- },
794
- (float) sx_or_options->NumberValue(context).ToChecked(),
795
- (float) sy->NumberValue(context).ToChecked(),
796
- (float) sw->NumberValue(context).ToChecked(),
797
- (float) sh->NumberValue(context).ToChecked(), std::move(ab));
492
+ options.resizeHeight, asset);
493
+ }
494
+ if (callback != nullptr) {
495
+ image_bitmap_async_data->asset_ = asset;
496
+ callback->execute(done);
497
+ }
498
+
499
+ }, std::move(store));
798
500
  thread.detach();
799
501
 
800
-
801
-
802
- #endif
803
-
804
-
805
502
  return;
806
503
  }
807
504
  }
808
505
  }
809
506
 
810
- auto type = GetNativeType( image);
507
+ auto type = ObjectWrapperImpl::GetNativeType(image);
811
508
 
812
509
  if (len == 1 || len == 2) {
813
510
  if (len == 2) {
@@ -950,644 +647,428 @@ void CanvasJSIModule::Create2DContextWithPointer(const v8::FunctionCallbackInfo<
950
647
  args.GetReturnValue().Set(ret);
951
648
  }
952
649
 
650
+ struct FileData {
651
+ char *error_;
652
+ U8Buffer *data;
653
+
654
+ ~FileData() {
655
+ if (error_ != nullptr) {
656
+ canvas_native_string_destroy(error_);
657
+ error_ = nullptr;
658
+ }
659
+ }
660
+ };
661
+
953
662
  void CanvasJSIModule::ReadFile(const v8::FunctionCallbackInfo<v8::Value> &args) {
954
663
  auto isolate = args.GetIsolate();
955
664
  auto file = ConvertFromV8String(isolate, args[0]);
956
665
  auto cbFunc = args[1].As<v8::Function>();
957
666
 
958
- auto jsi_callback = new JSIReadFileCallback(isolate, cbFunc);
959
-
960
- #ifdef __ANDROID__
961
- ALooper_addFd(jsi_callback->looper_,
962
- jsi_callback->fd_[0],
963
- ALOOPER_POLL_CALLBACK,
964
- ALOOPER_EVENT_INPUT,
965
- [](int fd, int events,
966
- void *data) {
967
-
968
- auto cb = static_cast<JSIReadFileCallback *>(data);
969
- bool done;
970
- read(fd, &done,
971
- sizeof(bool));
972
-
973
- if (cb->data_ == nullptr) {
974
- return 1;
975
- }
976
-
977
- v8::Isolate *isolate = cb->isolate_;
978
- v8::Locker locker(isolate);
979
- v8::Isolate::Scope isolate_scope(isolate);
980
- v8::HandleScope handle_scope(isolate);
981
- v8::Local<v8::Function> callback = cb->callback_.Get(isolate);
982
- v8::Local<v8::Context> context = callback->GetCreationContextChecked();
983
- v8::Context::Scope context_scope(context);
984
-
985
- v8::Local<v8::Value> args[2];
986
-
987
- if (done) {
988
- args[0] = v8::Null(isolate);
989
-
990
- auto vec = cb->data_;
991
-
992
- auto buf = (void *) canvas_native_u8_buffer_get_bytes_mut(vec);
993
- auto size = (size_t) canvas_native_u8_buffer_get_length(vec);
994
-
995
- auto store = v8::ArrayBuffer::NewBackingStore(buf, size,
996
- [](void *data,
997
- size_t length,
998
- void *deleter_data) {
999
- if (deleter_data !=
1000
- nullptr) {
1001
- // a little extreme :'D
1002
- delete static_cast<JSIReadFileCallback *>(deleter_data);
1003
- }
1004
- },
1005
- data);
1006
-
1007
- args[1] = v8::ArrayBuffer::New(isolate, std::move(store));
1008
- } else {
1009
- auto error = cb->error_;
1010
- args[0] = v8::Exception::Error(ConvertToV8String(isolate, error));
1011
- args[1] = v8::Null(isolate);
1012
- }
1013
-
1014
- v8::TryCatch tc(isolate);
1015
- v8::Local<v8::Value> result;
1016
- if (!callback->Call(context, context->Global(), 2, args).ToLocal(
1017
- &result)) {
1018
- if (tc.HasCaught()) {
1019
-
1020
- v8::Local<v8::Value> stack;
1021
- bool success = tc.StackTrace(context).ToLocal(&stack);
1022
- if (!success || stack.IsEmpty()) {
1023
- if (!done) {
1024
- delete cb;
1025
- }
1026
- return 0;
1027
- }
1028
-
1029
- v8::Local<v8::String> stackV8Str;
1030
- success = stack->ToDetailString(context).ToLocal(&stackV8Str);
1031
- if (!success || stackV8Str.IsEmpty()) {
1032
- if (!done) {
1033
- delete cb;
1034
- }
1035
- return 0;
1036
- }
1037
- LogToConsole(ConvertFromV8String(isolate, stackV8Str));
1038
-
1039
- }
1040
- }
1041
-
1042
- if (!done) {
1043
- delete cb;
1044
- }
1045
- return 0;
1046
- }, jsi_callback);
1047
-
1048
- ALooper_wake(jsi_callback->looper_);
1049
-
1050
- std::thread thread(
1051
- [jsi_callback](const std::string &file) {
1052
- bool done = false;
1053
- auto ret = canvas_native_helper_read_file(file.c_str());
1054
-
1055
- if (!canvas_native_helper_read_file_has_error(ret)) {
1056
- auto buf = canvas_native_helper_read_file_get_data(ret);
667
+ auto callback = new AsyncCallback(isolate, cbFunc, [](bool done, void *data) {
668
+ if (data == nullptr) { return; }
669
+ auto async_data = static_cast<AsyncCallback *>(data);
670
+ auto func = async_data->inner_.get();
671
+ if (func != nullptr && func->isolate_ != nullptr) {
672
+ v8::Isolate *isolate = func->isolate_;
673
+ v8::Locker locker(isolate);
674
+ v8::Isolate::Scope isolate_scope(isolate);
675
+ v8::HandleScope handle_scope(isolate);
676
+ v8::Local<v8::Function> callback = func->callback_.Get(
677
+ isolate);
678
+ v8::Local<v8::Context> context = callback->GetCreationContextChecked();
679
+ v8::Context::Scope context_scope(context);
1057
680
 
1058
- jsi_callback->SetData(buf);
681
+ if (func->data != nullptr) {
682
+ auto file_data = static_cast<FileData *>(func->data);
683
+
684
+ v8::Local<v8::Value> args[2];
685
+
686
+ if (done) {
687
+ args[0] = v8::Null(isolate);
688
+
689
+ auto buf = canvas_native_u8_buffer_get_bytes_mut(file_data->data);
690
+ auto size = (size_t) canvas_native_u8_buffer_get_length(file_data->data);
691
+
692
+ auto store = v8::ArrayBuffer::NewBackingStore((void *) buf, size,
693
+ [](void *data,
694
+ size_t length,
695
+ void *deleter_data) {
696
+ if (deleter_data !=
697
+ nullptr) {
698
+ delete static_cast<FileData *>(deleter_data);
699
+
700
+ }
701
+ },
702
+ func->data);
703
+
704
+ auto ret = v8::Object::New(isolate);
705
+ auto buffer = v8::ArrayBuffer::New(isolate, std::move(store));
706
+ ret->Set(context, ConvertToV8String(isolate, "buffer"), buffer);
707
+ auto mime = canvas_native_helper_get_mime(buf, size);
708
+ if (mime != nullptr) {
709
+ if (mime->mime_type != nullptr) {
710
+ ret->Set(context, ConvertToV8String(isolate, "mime"),
711
+ ConvertToV8String(isolate, mime->mime_type));
712
+ }
713
+ if (mime->extension != nullptr) {
714
+ ret->Set(context, ConvertToV8String(isolate, "extension"),
715
+ ConvertToV8String(isolate, mime->extension));
716
+ }
717
+ canvas_native_helper_release_mime(mime);
718
+ }
1059
719
 
1060
- done = true;
720
+ args[1] = ret;
1061
721
  } else {
1062
- auto error = canvas_native_helper_read_file_get_error(ret);
1063
-
1064
- jsi_callback->SetError(const_cast<char *>(error));
722
+ auto error = file_data->error_;
723
+ args[0] = v8::Exception::Error(ConvertToV8String(isolate, error));
724
+ args[1] = v8::Null(isolate);
725
+ delete file_data;
1065
726
  }
1066
- canvas_native_helper_destroy(ret);
1067
-
1068
- write(jsi_callback->fd_[1],
1069
- &done,
1070
- sizeof(bool));
1071
-
1072
- }, std::move(file));
1073
-
1074
- thread.detach();
1075
-
1076
- #endif
1077
727
 
728
+ v8::TryCatch tc(isolate);
729
+ v8::Local<v8::Value> result;
730
+ if (!callback->Call(context, context->Global(), 2, args).ToLocal(
731
+ &result)) {
732
+ if (tc.HasCaught()) {
733
+
734
+ // v8::Local<v8::Value> stack;
735
+ // bool success = tc.StackTrace(context).ToLocal(&stack);
736
+ // if (!success || stack.IsEmpty()) {
737
+ // if (!done) {
738
+ // delete async_data;
739
+ // }
740
+ // return;
741
+ // }
742
+ //
743
+ // v8::Local<v8::String> stackV8Str;
744
+ // success = stack->ToDetailString(context).ToLocal(&stackV8Str);
745
+ // if (!success || stackV8Str.IsEmpty()) {
746
+ // if (!done) {
747
+ // delete async_data;
748
+ // }
749
+ // return;
750
+ // }
1078
751
 
1079
- #ifdef __APPLE__
1080
-
1081
- auto current_queue = new NSOperationQueueWrapper(true);
752
+ }
753
+ }
1082
754
 
1083
- auto queue = new NSOperationQueueWrapper(false);
755
+ delete async_data;
1084
756
 
1085
- auto task = [jsi_callback, current_queue, queue, file]() {
757
+ }
758
+ }
759
+ });
1086
760
 
761
+ callback->prepare();
1087
762
 
763
+ std::thread thread(
764
+ [callback, file]() {
765
+ bool done = false;
766
+ auto ret = canvas_native_helper_read_file(file.c_str());
1088
767
 
1089
- bool done = false;
1090
- auto ret = canvas_native_helper_read_file(file.c_str());
768
+ if (!canvas_native_helper_read_file_has_error(ret)) {
769
+ auto buf = canvas_native_helper_read_file_take_data(ret);
770
+ callback->inner_->data = new FileData{nullptr, buf};
771
+ done = true;
772
+ } else {
773
+ auto error = canvas_native_helper_read_file_get_error(ret);
774
+ callback->inner_->data = new FileData{const_cast<char *>(error), nullptr};
775
+ }
776
+ canvas_native_helper_release(ret);
777
+ callback->execute(done);
778
+ });
1091
779
 
1092
- if (!canvas_native_helper_read_file_has_error(ret)) {
1093
- auto buf = canvas_native_helper_read_file_get_data(ret);
780
+ thread.detach();
1094
781
 
1095
- jsi_callback->SetData(buf);
1096
782
 
1097
- done = true;
1098
- } else {
1099
- auto error = canvas_native_helper_read_file_get_error(ret);
783
+ }
1100
784
 
1101
- jsi_callback->SetError((char*)error);
1102
- }
1103
785
 
1104
- canvas_native_helper_destroy(ret);
786
+ void CanvasJSIModule::GetMime(const v8::FunctionCallbackInfo<v8::Value> &args) {
787
+ auto isolate = args.GetIsolate();
788
+ auto file = ConvertFromV8String(isolate, args[0]);
789
+ auto cbFunc = args[1].As<v8::Function>();
1105
790
 
1106
- auto main_task = [jsi_callback, current_queue, queue, done]() {
1107
791
 
1108
- v8::Isolate *isolate = jsi_callback->isolate_;
792
+ auto callback = new AsyncCallback(isolate, cbFunc, [](bool done, void *data) {
793
+ if (data == nullptr) { return; }
794
+ auto async_data = static_cast<AsyncCallback *>(data);
795
+ auto func = async_data->inner_.get();
796
+ if (func != nullptr && func->isolate_ != nullptr) {
797
+ v8::Isolate *isolate = func->isolate_;
1109
798
  v8::Locker locker(isolate);
1110
799
  v8::Isolate::Scope isolate_scope(isolate);
1111
800
  v8::HandleScope handle_scope(isolate);
1112
- v8::Local<v8::Function> callback = jsi_callback->callback_.Get(isolate);
801
+ v8::Local<v8::Function> callback = func->callback_.Get(
802
+ isolate);
1113
803
  v8::Local<v8::Context> context = callback->GetCreationContextChecked();
1114
804
  v8::Context::Scope context_scope(context);
1115
805
 
1116
- v8::Local<v8::Value> args[2];
1117
-
1118
- if (done) {
1119
- args[0] = v8::Null(isolate);
806
+ if (func->data != nullptr) {
807
+ auto file_data = static_cast<FileData *>(func->data);
1120
808
 
1121
- auto vec = jsi_callback->data_;
809
+ v8::Local<v8::Value> args[2];
1122
810
 
811
+ if (done) {
812
+ args[0] = v8::Null(isolate);
1123
813
 
1124
- auto buf = (void*)canvas_native_u8_buffer_get_bytes_mut(vec);
814
+ auto buf = (void *) canvas_native_u8_buffer_get_bytes_mut(file_data->data);
815
+ auto size = (size_t) canvas_native_u8_buffer_get_length(file_data->data);
1125
816
 
1126
- auto size = (size_t)canvas_native_u8_buffer_get_length(vec);
817
+ auto store = v8::ArrayBuffer::NewBackingStore(buf, size,
818
+ [](void *data,
819
+ size_t length,
820
+ void *deleter_data) {
821
+ if (deleter_data !=
822
+ nullptr) {
823
+ delete static_cast<FileData *>(deleter_data);
1127
824
 
1128
- auto store = v8::ArrayBuffer::NewBackingStore(buf, size,
1129
- [](void *data,
1130
- size_t length,
1131
- void *deleter_data) {
1132
- if (deleter_data !=
1133
- nullptr) {
1134
- // a little extreme :'D
1135
- delete static_cast<JSIReadFileCallback *>(deleter_data);
1136
- }
1137
- },
1138
- jsi_callback);
825
+ }
826
+ },
827
+ func->data);
1139
828
 
1140
- args[1] = v8::ArrayBuffer::New(isolate, std::move(store));
1141
- } else {
1142
- auto error = jsi_callback->error_;
1143
- args[0] = v8::Exception::Error(ConvertToV8String(isolate, error));
1144
- args[1] = v8::Null(isolate);
1145
- }
829
+ args[1] = v8::ArrayBuffer::New(isolate, std::move(store));
830
+ } else {
831
+ auto error = file_data->error_;
832
+ args[0] = v8::Exception::Error(ConvertToV8String(isolate, error));
833
+ args[1] = v8::Null(isolate);
834
+ delete file_data;
835
+ }
1146
836
 
1147
- v8::TryCatch tc(isolate);
1148
- v8::Local<v8::Value> result;
1149
- if (!callback->Call(context, context->Global(), 2, args).ToLocal(
1150
- &result)) {
1151
- if (tc.HasCaught()) {
1152
-
1153
- v8::Local<v8::Value> stack;
1154
- bool success = tc.StackTrace(context).ToLocal(&stack);
1155
- if (!success || stack.IsEmpty()) {
1156
- if (!done) {
1157
- delete jsi_callback;
1158
- }
1159
- return;
1160
- }
837
+ v8::TryCatch tc(isolate);
838
+ v8::Local<v8::Value> result;
839
+ if (!callback->Call(context, context->Global(), 2, args).ToLocal(
840
+ &result)) {
841
+ if (tc.HasCaught()) {
842
+
843
+ // v8::Local<v8::Value> stack;
844
+ // bool success = tc.StackTrace(context).ToLocal(&stack);
845
+ // if (!success || stack.IsEmpty()) {
846
+ // if (!done) {
847
+ // delete async_data;
848
+ // }
849
+ // return;
850
+ // }
851
+ //
852
+ // v8::Local<v8::String> stackV8Str;
853
+ // success = stack->ToDetailString(context).ToLocal(&stackV8Str);
854
+ // if (!success || stackV8Str.IsEmpty()) {
855
+ // if (!done) {
856
+ // delete async_data;
857
+ // }
858
+ // return;
859
+ // }
1161
860
 
1162
- v8::Local<v8::String> stackV8Str;
1163
- success = stack->ToDetailString(context).ToLocal(&stackV8Str);
1164
- if (!success || stackV8Str.IsEmpty()) {
1165
- if (!done) {
1166
- delete jsi_callback;
1167
- }
1168
- return;
1169
861
  }
1170
- LogToConsole(ConvertFromV8String(isolate, stackV8Str));
1171
-
1172
862
  }
1173
- }
1174
-
1175
- if (!done) {
1176
- delete jsi_callback;
1177
- }
1178
-
1179
- delete queue;
1180
- delete current_queue;
1181
-
1182
- };
1183
- current_queue->addOperation(main_task);
1184
- };
1185
-
1186
- queue->addOperation(task);
1187
- #endif
1188
863
 
864
+ delete async_data;
1189
865
 
1190
- }
1191
-
1192
- void CanvasJSIModule::CreateWebGLContext(const v8::FunctionCallbackInfo<v8::Value> &args) {
1193
- auto configValue = args[0];
1194
- auto isolate = args.GetIsolate();
1195
- auto context = isolate->GetCurrentContext();
1196
- if (!configValue->IsNullOrUndefined() && configValue->IsObject()) {
1197
- auto config = configValue.As<v8::Object>();
1198
- std::string version("none");
1199
- auto alpha = true;
1200
- auto antialias = true;
1201
- auto depth = true;
1202
- auto fail_if_major_performance_caveat = false;
1203
- std::string power_preference("default");
1204
- auto premultiplied_alpha = true;
1205
- auto preserve_drawing_buffer = false;
1206
- auto stencil = false;
1207
- auto desynchronized = false;
1208
- auto xr_compatible = false;
1209
-
1210
- auto last = isolate->GetNumberOfDataSlots() - 1;
1211
- auto data = isolate->GetData(last);
1212
-
1213
- if (data != nullptr) {
1214
- auto consts = static_cast<PerIsolateData *>(data);
1215
-
1216
- v8::Local<v8::Value> versionValue;
1217
-
1218
- config->Get(context, consts->VERSION_PERSISTENT->Get(isolate)).ToLocal(&versionValue);
1219
-
1220
- if (!versionValue.IsEmpty() && versionValue->IsString()) {
1221
- version = ConvertFromV8String(isolate, versionValue);
1222
- }
1223
-
1224
- v8::Local<v8::Value> alphaValue;
1225
-
1226
- config->Get(context, consts->ALPHA_PERSISTENT->Get(isolate)).ToLocal(&alphaValue);
1227
- if (!alphaValue.IsEmpty() && alphaValue->IsBoolean()) {
1228
- alpha = alphaValue->BooleanValue(isolate);
1229
- }
1230
-
1231
- v8::Local<v8::Value> antialiasValue;
1232
- config->Get(context, consts->ANTIALIAS_PERSISTENT->Get(isolate)).ToLocal(
1233
- &antialiasValue);
1234
- if (!antialiasValue.IsEmpty() && antialiasValue->IsBoolean()) {
1235
- antialias = antialiasValue->BooleanValue(isolate);
1236
866
  }
867
+ }
868
+ });
1237
869
 
1238
- v8::Local<v8::Value> failIfMajorPerformanceCaveatValue;
1239
- config->Get(context,
1240
- consts->FAIL_IF_MAJOR_PERFORMANCE_CAVEAT_PERSISTENT->Get(isolate)).ToLocal(
1241
- &failIfMajorPerformanceCaveatValue);
1242
- if (!failIfMajorPerformanceCaveatValue.IsEmpty() &&
1243
- failIfMajorPerformanceCaveatValue->IsBoolean()) {
1244
- fail_if_major_performance_caveat = failIfMajorPerformanceCaveatValue->BooleanValue(
1245
- isolate);
1246
- }
870
+ callback->prepare();
1247
871
 
1248
- v8::Local<v8::Value> powerPreferenceValue;
1249
- config->Get(context, consts->POWER_PREFERENCE_PERSISTENT->Get(isolate)).ToLocal(
1250
- &powerPreferenceValue);
1251
- if (!powerPreferenceValue.IsEmpty() && powerPreferenceValue->IsString()) {
1252
- power_preference = ConvertFromV8String(isolate, powerPreferenceValue);
1253
- }
872
+ std::thread thread(
873
+ [callback, file]() {
874
+ bool done = false;
875
+ auto ret = canvas_native_helper_read_file(file.c_str());
1254
876
 
1255
- v8::Local<v8::Value> premultipliedAlphaValue;
1256
- config->Get(context,
1257
- consts->PREMULTIPLIED_ALPHA_PERSISTENT->Get(isolate)).ToLocal(
1258
- &premultipliedAlphaValue);
1259
- if (!premultipliedAlphaValue.IsEmpty() && premultipliedAlphaValue->IsBoolean()) {
1260
- premultiplied_alpha = premultipliedAlphaValue->BooleanValue(isolate);
1261
- }
877
+ if (!canvas_native_helper_read_file_has_error(ret)) {
878
+ auto buf = canvas_native_helper_read_file_take_data(ret);
879
+ callback->inner_->data = new FileData{nullptr, buf};
880
+ done = true;
881
+ } else {
882
+ auto error = canvas_native_helper_read_file_get_error(ret);
883
+ callback->inner_->data = new FileData{const_cast<char *>(error), nullptr};
884
+ }
885
+ canvas_native_helper_release(ret);
886
+ callback->execute(done);
887
+ });
1262
888
 
1263
- v8::Local<v8::Value> preserveDrawingBufferValue;
1264
- config->Get(context,
1265
- consts->PRESERVE_DRAWING_BUFFER_PERSISTENT->Get(isolate)).ToLocal(
1266
- &preserveDrawingBufferValue);
1267
- if (!preserveDrawingBufferValue.IsEmpty() && preserveDrawingBufferValue->IsBoolean()) {
1268
- preserve_drawing_buffer = preserveDrawingBufferValue->BooleanValue(isolate);
1269
- }
889
+ thread.detach();
1270
890
 
1271
- v8::Local<v8::Value> stencilValue;
1272
- config->Get(context, consts->STENCIL_PERSISTENT->Get(isolate)).ToLocal(&stencilValue);
1273
- if (!stencilValue.IsEmpty() && stencilValue->IsBoolean()) {
1274
- stencil = stencilValue->BooleanValue(isolate);
1275
- }
1276
891
 
1277
- v8::Local<v8::Value> desynchronizedValue;
1278
- config->Get(context, consts->DESYNCHRONIZED_PERSISTENT->Get(isolate)).ToLocal(
1279
- &desynchronizedValue);
1280
- if (!desynchronizedValue.IsEmpty() && desynchronizedValue->IsBoolean()) {
1281
- desynchronized = desynchronizedValue->BooleanValue(isolate);
1282
- }
892
+ }
1283
893
 
1284
- v8::Local<v8::Value> xrCompatibleValue;
1285
- config->Get(context,
1286
- consts->XR_COMPATIBLE_PERSISTENT->Get(isolate)).ToLocal(&xrCompatibleValue);
1287
- if (!xrCompatibleValue.IsEmpty() && xrCompatibleValue->IsBoolean()) {
1288
- xr_compatible = xrCompatibleValue->BooleanValue(isolate);
1289
- }
1290
- }
1291
894
 
895
+ void CanvasJSIModule::CreateWebGLContext(const v8::FunctionCallbackInfo<v8::Value> &args) {
1292
896
 
1293
- if (version !=
1294
- "v1") {
1295
- args.GetReturnValue().SetNull();
1296
- return;
1297
- } else {
1298
- auto count = args.Length();
1299
- if (count == 6) {
1300
- auto ctx = args[1].As<v8::BigInt>()->Int64Value();
1301
- // auto density = args[2]->NumberValue(context).ToChecked();
1302
- // auto fontColor = args[3]->NumberValue(context).ToChecked();
1303
- // auto ppi = args[4]->NumberValue(context).ToChecked();
1304
- // auto direction = args[5]->NumberValue(context).ToChecked();
1305
- auto webgl = canvas_native_webgl_create(
1306
- ctx,
1307
- version.c_str(),
1308
- alpha,
1309
- antialias,
1310
- depth,
1311
- fail_if_major_performance_caveat,
1312
- power_preference.c_str(),
1313
- premultiplied_alpha,
1314
- preserve_drawing_buffer,
1315
- stencil,
1316
- desynchronized,
1317
- xr_compatible
1318
- );
1319
-
1320
- auto renderingContext = WebGLRenderingContext::NewInstance(isolate,
1321
- new WebGLRenderingContext(
1322
- webgl));
1323
-
1324
- args.GetReturnValue().Set(renderingContext);
1325
- return;
1326
- } else if (count == 7) {
1327
- auto width = args[1]->NumberValue(context).ToChecked();
1328
- auto height = args[2]->NumberValue(context).ToChecked();
1329
- // auto density = args[3]->NumberValue(context).ToChecked();
1330
- // auto fontColor = args[4]->NumberValue(context).ToChecked();
1331
- // auto ppi = args[5]->NumberValue(context).ToChecked();
1332
- // auto direction = args[6]->NumberValue(context).ToChecked();
1333
- auto ctx = canvas_native_webgl_create_no_window(
1334
- (int32_t) width,
1335
- (int32_t) height,
1336
- version.c_str(),
1337
- alpha,
1338
- antialias,
1339
- depth,
1340
- fail_if_major_performance_caveat,
1341
- power_preference.c_str(),
1342
- premultiplied_alpha,
1343
- preserve_drawing_buffer,
1344
- stencil,
1345
- desynchronized,
1346
- xr_compatible,
1347
- false
1348
- );
1349
-
1350
- auto renderingContext = WebGLRenderingContext::NewInstance(isolate,
1351
- new WebGLRenderingContext(
1352
- ctx));
1353
-
1354
- args.GetReturnValue().Set(renderingContext);
1355
- return;
897
+ auto options = GLOptions();
898
+ options.parseGLOptions(args);
1356
899
 
1357
- } else {
1358
- auto width = (int32_t) args[1]->NumberValue(context).ToChecked();
1359
- auto height = (int32_t) args[2]->NumberValue(context).ToChecked();
1360
-
1361
- auto ctx = canvas_native_webgl_create_no_window(
1362
- width,
1363
- height,
1364
- version.c_str(),
1365
- alpha,
1366
- antialias,
1367
- depth,
1368
- fail_if_major_performance_caveat,
1369
- power_preference.c_str(),
1370
- premultiplied_alpha,
1371
- preserve_drawing_buffer,
1372
- stencil,
1373
- desynchronized,
1374
- xr_compatible,
1375
- false
1376
- );
1377
-
1378
- auto renderingContext = WebGLRenderingContext::NewInstance(isolate,
1379
- new WebGLRenderingContext(
1380
- ctx));
1381
-
1382
- args.GetReturnValue().Set(renderingContext);
1383
- return;
1384
- }
1385
-
1386
- }
900
+ if (options.version != 1) {
901
+ args.GetReturnValue().SetNull();
902
+ return;
1387
903
  }
1388
- args.GetReturnValue().SetNull();
1389
- }
1390
904
 
1391
- void CanvasJSIModule::CreateWebGL2Context(const v8::FunctionCallbackInfo<v8::Value> &args) {
1392
- auto configValue = args[0];
1393
905
  auto isolate = args.GetIsolate();
1394
906
  auto context = isolate->GetCurrentContext();
1395
- if (!configValue->IsNullOrUndefined() && configValue->IsObject()) {
1396
- auto config = configValue.As<v8::Object>();
1397
- std::string version("none");
1398
- auto alpha = true;
1399
- auto antialias = true;
1400
- auto depth = true;
1401
- auto fail_if_major_performance_caveat = false;
1402
- std::string power_preference("default");
1403
- auto premultiplied_alpha = true;
1404
- auto preserve_drawing_buffer = false;
1405
- auto stencil = false;
1406
- auto desynchronized = false;
1407
- auto xr_compatible = false;
1408
-
1409
907
 
1410
- auto last = isolate->GetNumberOfDataSlots() - 1;
1411
- auto data = isolate->GetData(last);
1412
908
 
1413
- if (data != nullptr) {
1414
- auto consts = static_cast<PerIsolateData *>(data);
1415
-
1416
- v8::Local<v8::Value> versionValue;
1417
-
1418
- config->Get(context, consts->VERSION_PERSISTENT->Get(isolate)).ToLocal(&versionValue);
909
+ auto count = args.Length();
910
+ if (count == 6) {
911
+ auto ctx = args[1].As<v8::BigInt>()->Int64Value();
912
+ auto webgl = (WebGLState *) ctx;
1419
913
 
1420
- if (!versionValue.IsEmpty() && versionValue->IsString()) {
1421
- version = ConvertFromV8String(isolate, versionValue);
1422
- }
914
+ auto renderingContext = WebGLRenderingContext::NewInstance(isolate,
915
+ new WebGLRenderingContext(
916
+ webgl));
1423
917
 
1424
- v8::Local<v8::Value> alphaValue;
918
+ args.GetReturnValue().Set(renderingContext);
919
+ return;
920
+ } else if (count == 7) {
921
+ auto width = args[1]->NumberValue(context).ToChecked();
922
+ auto height = args[2]->NumberValue(context).ToChecked();
923
+ auto ctx = canvas_native_webgl_create_no_window(
924
+ (int32_t) width,
925
+ (int32_t) height,
926
+ options.version,
927
+ options.alpha,
928
+ options.antialias,
929
+ options.depth,
930
+ options.failIfMajorPerformanceCaveat,
931
+ options.powerPreference,
932
+ options.premultipliedAlpha,
933
+ options.preserveDrawingBuffer,
934
+ options.stencil,
935
+ options.desynchronized,
936
+ options.xrCompatible,
937
+ false
938
+ );
939
+
940
+ auto renderingContext = WebGLRenderingContext::NewInstance(isolate,
941
+ new WebGLRenderingContext(
942
+ ctx));
943
+
944
+ args.GetReturnValue().Set(renderingContext);
945
+ return;
1425
946
 
1426
- config->Get(context, consts->ALPHA_PERSISTENT->Get(isolate)).ToLocal(&alphaValue);
1427
- if (!alphaValue.IsEmpty() && alphaValue->IsBoolean()) {
1428
- alpha = alphaValue->BooleanValue(isolate);
1429
- }
947
+ } else {
948
+ auto width = (int32_t) args[1]->NumberValue(context).ToChecked();
949
+ auto height = (int32_t) args[2]->NumberValue(context).ToChecked();
950
+
951
+ auto ctx = canvas_native_webgl_create_no_window(
952
+ width,
953
+ height,
954
+ options.version,
955
+ options.alpha,
956
+ options.antialias,
957
+ options.depth,
958
+ options.failIfMajorPerformanceCaveat,
959
+ options.powerPreference,
960
+ options.premultipliedAlpha,
961
+ options.preserveDrawingBuffer,
962
+ options.stencil,
963
+ options.desynchronized,
964
+ options.xrCompatible,
965
+ false
966
+ );
967
+
968
+ auto renderingContext = WebGLRenderingContext::NewInstance(isolate,
969
+ new WebGLRenderingContext(
970
+ ctx));
971
+
972
+ args.GetReturnValue().Set(renderingContext);
973
+ return;
974
+ }
975
+ }
1430
976
 
1431
- v8::Local<v8::Value> antialiasValue;
1432
- config->Get(context, consts->ANTIALIAS_PERSISTENT->Get(isolate)).ToLocal(
1433
- &antialiasValue);
1434
- if (!antialiasValue.IsEmpty() && antialiasValue->IsBoolean()) {
1435
- antialias = antialiasValue->BooleanValue(isolate);
1436
- }
977
+ void CanvasJSIModule::CreateWebGL2Context(const v8::FunctionCallbackInfo<v8::Value> &args) {
1437
978
 
1438
- v8::Local<v8::Value> failIfMajorPerformanceCaveatValue;
1439
- config->Get(context,
1440
- consts->FAIL_IF_MAJOR_PERFORMANCE_CAVEAT_PERSISTENT->Get(isolate)).ToLocal(
1441
- &failIfMajorPerformanceCaveatValue);
1442
- if (!failIfMajorPerformanceCaveatValue.IsEmpty() &&
1443
- failIfMajorPerformanceCaveatValue->IsBoolean()) {
1444
- fail_if_major_performance_caveat = failIfMajorPerformanceCaveatValue->BooleanValue(
1445
- isolate);
1446
- }
1447
979
 
1448
- v8::Local<v8::Value> powerPreferenceValue;
1449
- config->Get(context, consts->POWER_PREFERENCE_PERSISTENT->Get(isolate)).ToLocal(
1450
- &powerPreferenceValue);
1451
- if (!powerPreferenceValue.IsEmpty() && powerPreferenceValue->IsString()) {
1452
- power_preference = ConvertFromV8String(isolate, powerPreferenceValue);
1453
- }
980
+ auto options = GLOptions();
981
+ options.parseGLOptions(args);
1454
982
 
1455
- v8::Local<v8::Value> premultipliedAlphaValue;
1456
- config->Get(context,
1457
- consts->PREMULTIPLIED_ALPHA_PERSISTENT->Get(isolate)).ToLocal(
1458
- &premultipliedAlphaValue);
1459
- if (!premultipliedAlphaValue.IsEmpty() && premultipliedAlphaValue->IsBoolean()) {
1460
- premultiplied_alpha = premultipliedAlphaValue->BooleanValue(isolate);
1461
- }
983
+ if (options.version != 2) {
984
+ args.GetReturnValue().SetNull();
985
+ return;
986
+ }
1462
987
 
1463
- v8::Local<v8::Value> preserveDrawingBufferValue;
1464
- config->Get(context,
1465
- consts->PRESERVE_DRAWING_BUFFER_PERSISTENT->Get(isolate)).ToLocal(
1466
- &preserveDrawingBufferValue);
1467
- if (!preserveDrawingBufferValue.IsEmpty() && preserveDrawingBufferValue->IsBoolean()) {
1468
- preserve_drawing_buffer = preserveDrawingBufferValue->BooleanValue(isolate);
1469
- }
1470
988
 
1471
- v8::Local<v8::Value> stencilValue;
1472
- config->Get(context, consts->STENCIL_PERSISTENT->Get(isolate)).ToLocal(&stencilValue);
1473
- if (!stencilValue.IsEmpty() && stencilValue->IsBoolean()) {
1474
- stencil = stencilValue->BooleanValue(isolate);
1475
- }
989
+ auto isolate = args.GetIsolate();
990
+ auto context = isolate->GetCurrentContext();
1476
991
 
1477
- v8::Local<v8::Value> desynchronizedValue;
1478
- config->Get(context, consts->DESYNCHRONIZED_PERSISTENT->Get(isolate)).ToLocal(
1479
- &desynchronizedValue);
1480
- if (!desynchronizedValue.IsEmpty() && desynchronizedValue->IsBoolean()) {
1481
- desynchronized = desynchronizedValue->BooleanValue(isolate);
1482
- }
1483
992
 
1484
- v8::Local<v8::Value> xrCompatibleValue;
1485
- config->Get(context,
1486
- consts->XR_COMPATIBLE_PERSISTENT->Get(isolate)).ToLocal(&xrCompatibleValue);
1487
- if (!xrCompatibleValue.IsEmpty() && xrCompatibleValue->IsBoolean()) {
1488
- xr_compatible = xrCompatibleValue->BooleanValue(isolate);
1489
- }
1490
- }
993
+ auto count = args.Length();
994
+ if (count == 6) {
995
+ auto ctx = args[1].As<v8::BigInt>()->Int64Value();
996
+ auto webgl = (WebGLState *) ctx;
997
+ auto renderingContext = WebGL2RenderingContext::NewInstance(isolate,
998
+ new WebGL2RenderingContext(
999
+ webgl,
1000
+ WebGLRenderingVersion::V2));
1001
+
1002
+ args.GetReturnValue().Set(renderingContext);
1003
+ return;
1491
1004
 
1005
+ } else if (count ==
1006
+ 7) {
1007
+ auto width = args[1]->NumberValue(context).ToChecked();
1008
+ auto height = args[2]->NumberValue(context).ToChecked();
1009
+ auto ctx = canvas_native_webgl_create_no_window(
1010
+ (int32_t) width,
1011
+ (int32_t) height,
1012
+ options.version,
1013
+ options.alpha,
1014
+ options.antialias,
1015
+ options.depth,
1016
+ options.failIfMajorPerformanceCaveat,
1017
+ options.powerPreference,
1018
+ options.premultipliedAlpha,
1019
+ options.preserveDrawingBuffer,
1020
+ options.stencil,
1021
+ options.desynchronized,
1022
+ options.xrCompatible,
1023
+ false
1024
+ );
1025
+ auto renderingContext = WebGL2RenderingContext::NewInstance(isolate,
1026
+ new WebGL2RenderingContext(
1027
+ ctx,
1028
+ WebGLRenderingVersion::V2));
1029
+
1030
+ args.GetReturnValue().Set(renderingContext);
1031
+ return;
1492
1032
 
1493
- if (version !=
1494
- "v2") {
1495
- args.GetReturnValue().SetNull();
1496
- return;
1497
- } else {
1498
- auto count = args.Length();
1499
- if (count == 6) {
1500
- auto ctx = args[1].As<v8::BigInt>()->Int64Value();
1501
- // auto density = args[2]->NumberValue(context).ToChecked();
1502
- // auto fontColor = args[3]->NumberValue(context).ToChecked();
1503
- // auto ppi = args[4]->NumberValue(context).ToChecked();
1504
- // auto direction = args[5]->NumberValue(context).ToChecked();
1505
-
1506
- auto webgl = canvas_native_webgl_create(
1507
- ctx,
1508
- version.c_str(),
1509
- alpha,
1510
- antialias,
1511
- depth,
1512
- fail_if_major_performance_caveat,
1513
- power_preference.c_str(),
1514
- premultiplied_alpha,
1515
- preserve_drawing_buffer,
1516
- stencil,
1517
- desynchronized,
1518
- xr_compatible
1519
- );
1520
-
1521
- auto renderingContext = WebGL2RenderingContext::NewInstance(isolate,
1522
- new WebGL2RenderingContext(
1523
- webgl,
1524
- WebGLRenderingVersion::V2));
1525
-
1526
- args.GetReturnValue().Set(renderingContext);
1527
- return;
1033
+ } else {
1034
+ auto width = (int32_t) args[1]->NumberValue(context).ToChecked();
1035
+ auto height = (int32_t) args[2]->NumberValue(context).ToChecked();
1036
+ auto ctx = canvas_native_webgl_create_no_window(
1037
+ width,
1038
+ height,
1039
+ options.version,
1040
+ options.alpha,
1041
+ options.antialias,
1042
+ options.depth,
1043
+ options.failIfMajorPerformanceCaveat,
1044
+ options.powerPreference,
1045
+ options.premultipliedAlpha,
1046
+ options.preserveDrawingBuffer,
1047
+ options.stencil,
1048
+ options.desynchronized,
1049
+ options.xrCompatible,
1050
+ false
1051
+ );
1052
+
1053
+ auto renderingContext = WebGL2RenderingContext::NewInstance(isolate,
1054
+ new WebGL2RenderingContext(
1055
+ ctx,
1056
+ WebGLRenderingVersion::V2));
1057
+
1058
+ args.GetReturnValue().Set(renderingContext);
1059
+ return;
1060
+ }
1061
+ }
1528
1062
 
1529
- } else if (count ==
1530
- 7) {
1531
- auto width = args[1]->NumberValue(context).ToChecked();
1532
- auto height = args[2]->NumberValue(context).ToChecked();
1533
- // auto density = args[3]->NumberValue(context).ToChecked();
1534
- // auto fontColor = args[4]->NumberValue(context).ToChecked();
1535
- // auto ppi = args[5]->NumberValue(context).ToChecked();
1536
- // auto direction = args[6]->NumberValue(context).ToChecked();
1537
- auto ctx = canvas_native_webgl_create_no_window(
1538
- (int32_t) width,
1539
- (int32_t) height,
1540
- version.c_str(),
1541
- alpha,
1542
- antialias,
1543
- depth,
1544
- fail_if_major_performance_caveat,
1545
- power_preference.c_str(),
1546
- premultiplied_alpha,
1547
- preserve_drawing_buffer,
1548
- stencil,
1549
- desynchronized,
1550
- xr_compatible,
1551
- false
1552
- );
1553
- auto renderingContext = WebGL2RenderingContext::NewInstance(isolate,
1554
- new WebGL2RenderingContext(
1555
- ctx,
1556
- WebGLRenderingVersion::V2));
1557
-
1558
- args.GetReturnValue().Set(renderingContext);
1559
- return;
1063
+ void
1064
+ CanvasJSIModule::CreateWebGPUContextWithPointer(const v8::FunctionCallbackInfo<v8::Value> &args) {
1065
+ auto isolate = args.GetIsolate();
1066
+ auto context = isolate->GetCurrentContext();
1067
+ auto ptr = args[0]->ToBigInt(context).ToLocalChecked()->Int64Value();
1560
1068
 
1561
- } else {
1562
- auto width = (int32_t) args[1]->NumberValue(context).ToChecked();
1563
- auto height = (int32_t) args[2]->NumberValue(context).ToChecked();
1564
- auto ctx = canvas_native_webgl_create_no_window(
1565
- width,
1566
- height,
1567
- version.c_str(),
1568
- alpha,
1569
- antialias,
1570
- depth,
1571
- fail_if_major_performance_caveat,
1572
- power_preference.c_str(),
1573
- premultiplied_alpha,
1574
- preserve_drawing_buffer,
1575
- stencil,
1576
- desynchronized,
1577
- xr_compatible,
1578
- false
1579
- );
1580
-
1581
- auto renderingContext = WebGL2RenderingContext::NewInstance(isolate,
1582
- new WebGL2RenderingContext(
1583
- ctx,
1584
- WebGLRenderingVersion::V2));
1585
-
1586
- args.GetReturnValue().Set(renderingContext);
1587
- return;
1588
- }
1589
- }
1590
- }
1069
+ auto wgpu = static_cast<CanvasGPUCanvasContext *>((void *) ptr);
1591
1070
 
1592
- args.GetReturnValue().SetNull();
1071
+ auto ret = GPUCanvasContextImpl::NewInstance(isolate, new GPUCanvasContextImpl(
1072
+ wgpu));
1073
+ args.GetReturnValue().Set(ret);
1593
1074
  }