@nativescript/canvas 2.0.0-alpha.20 → 2.0.0-alpha.21

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 (234) hide show
  1. package/Canvas/common.d.ts +2 -0
  2. package/Canvas/common.js +6 -0
  3. package/Canvas/common.js.map +1 -1
  4. package/Canvas/index.android.d.ts +0 -2
  5. package/Canvas/index.android.js +8 -22
  6. package/Canvas/index.android.js.map +1 -1
  7. package/Canvas/index.d.ts +7 -0
  8. package/Canvas/index.ios.d.ts +0 -2
  9. package/Canvas/index.ios.js +7 -26
  10. package/Canvas/index.ios.js.map +1 -1
  11. package/Canvas2D/CanvasGradient/index.d.ts +1 -3
  12. package/Canvas2D/CanvasGradient/index.js +1 -10
  13. package/Canvas2D/CanvasGradient/index.js.map +1 -1
  14. package/Canvas2D/CanvasPattern/index.d.ts +1 -3
  15. package/Canvas2D/CanvasPattern/index.js +1 -10
  16. package/Canvas2D/CanvasPattern/index.js.map +1 -1
  17. package/Canvas2D/CanvasRenderingContext2D/index.d.ts +0 -2
  18. package/Canvas2D/CanvasRenderingContext2D/index.js +120 -138
  19. package/Canvas2D/CanvasRenderingContext2D/index.js.map +1 -1
  20. package/Canvas2D/DOMMatrix/index.js +3 -3
  21. package/Canvas2D/DOMMatrix/index.js.map +1 -1
  22. package/Canvas2D/ImageData/index.js +5 -5
  23. package/Canvas2D/ImageData/index.js.map +1 -1
  24. package/Canvas2D/Path2D/index.d.ts +0 -2
  25. package/Canvas2D/Path2D/index.js +34 -39
  26. package/Canvas2D/Path2D/index.js.map +1 -1
  27. package/ImageAsset/index.d.ts +2 -2
  28. package/ImageAsset/index.js +33 -37
  29. package/ImageAsset/index.js.map +1 -1
  30. package/ImageBitmap/index.d.ts +0 -2
  31. package/ImageBitmap/index.js +23 -29
  32. package/ImageBitmap/index.js.map +1 -1
  33. package/SVG/SVG.js +1 -1
  34. package/TextDecoder/index.d.ts +0 -2
  35. package/TextDecoder/index.js +3 -12
  36. package/TextDecoder/index.js.map +1 -1
  37. package/TextEncoder/index.d.ts +0 -2
  38. package/TextEncoder/index.js +4 -13
  39. package/TextEncoder/index.js.map +1 -1
  40. package/WebGL/WebGLExtensions/index.d.ts +0 -9
  41. package/WebGL/WebGLExtensions/index.js +17 -74
  42. package/WebGL/WebGLExtensions/index.js.map +1 -1
  43. package/WebGL/WebGLRenderingContext/common.d.ts +0 -2
  44. package/WebGL/WebGLRenderingContext/common.js +0 -10
  45. package/WebGL/WebGLRenderingContext/common.js.map +1 -1
  46. package/WebGL/WebGLRenderingContext/index.js +159 -298
  47. package/WebGL/WebGLRenderingContext/index.js.map +1 -1
  48. package/WebGL2/WebGL2RenderingContext/index.js +107 -195
  49. package/WebGL2/WebGL2RenderingContext/index.js.map +1 -1
  50. package/angular/esm2020/index.mjs +5 -5
  51. package/angular/fesm2015/nativescript-canvas-angular.mjs +4 -4
  52. package/angular/fesm2015/nativescript-canvas-angular.mjs.map +1 -1
  53. package/angular/fesm2020/nativescript-canvas-angular.mjs +4 -4
  54. package/angular/fesm2020/nativescript-canvas-angular.mjs.map +1 -1
  55. package/index.js.map +1 -1
  56. package/package.json +1 -1
  57. package/platforms/android/canvas-release.aar +0 -0
  58. package/platforms/android/include.gradle +15 -0
  59. package/platforms/ios/CanvasNative.xcframework/ios-arm64/CanvasNative.framework/CanvasNative +0 -0
  60. package/platforms/ios/CanvasNative.xcframework/ios-arm64/CanvasNative.framework/Headers/CanvasNative-Swift.h +87 -57
  61. package/platforms/ios/CanvasNative.xcframework/ios-arm64/CanvasNative.framework/Headers/CanvasNative.h +10 -0
  62. package/platforms/ios/CanvasNative.xcframework/ios-arm64/CanvasNative.framework/Headers/canvas_ios.h +142 -0
  63. package/platforms/ios/CanvasNative.xcframework/ios-arm64/CanvasNative.framework/Headers/canvas_native.h +2589 -110
  64. package/platforms/ios/CanvasNative.xcframework/ios-arm64/CanvasNative.framework/Info.plist +0 -0
  65. package/platforms/ios/CanvasNative.xcframework/ios-arm64/CanvasNative.framework/Modules/CanvasNative.swiftmodule/Project/arm64-apple-ios.swiftsourceinfo +0 -0
  66. package/platforms/ios/CanvasNative.xcframework/ios-arm64/CanvasNative.framework/Modules/CanvasNative.swiftmodule/arm64-apple-ios.abi.json +1174 -89
  67. package/platforms/ios/CanvasNative.xcframework/ios-arm64/CanvasNative.framework/Modules/CanvasNative.swiftmodule/arm64-apple-ios.private.swiftinterface +2 -2
  68. package/platforms/ios/CanvasNative.xcframework/ios-arm64/CanvasNative.framework/Modules/CanvasNative.swiftmodule/arm64-apple-ios.swiftdoc +0 -0
  69. package/platforms/ios/CanvasNative.xcframework/ios-arm64/CanvasNative.framework/Modules/CanvasNative.swiftmodule/arm64-apple-ios.swiftinterface +2 -2
  70. package/platforms/ios/CanvasNative.xcframework/ios-arm64/dSYMs/CanvasNative.framework.dSYM/Contents/Resources/DWARF/CanvasNative +0 -0
  71. package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/CanvasNative +0 -0
  72. package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/Headers/CanvasNative-Swift.h +174 -114
  73. package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/Headers/CanvasNative.h +10 -0
  74. package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/Headers/canvas_ios.h +142 -0
  75. package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/Headers/canvas_native.h +2589 -110
  76. package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/Info.plist +0 -0
  77. package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/Modules/CanvasNative.swiftmodule/Project/arm64-apple-ios-simulator.swiftsourceinfo +0 -0
  78. package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/Modules/CanvasNative.swiftmodule/Project/x86_64-apple-ios-simulator.swiftsourceinfo +0 -0
  79. package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/Modules/CanvasNative.swiftmodule/arm64-apple-ios-simulator.abi.json +1174 -89
  80. package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/Modules/CanvasNative.swiftmodule/arm64-apple-ios-simulator.private.swiftinterface +2 -2
  81. package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/Modules/CanvasNative.swiftmodule/arm64-apple-ios-simulator.swiftdoc +0 -0
  82. package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/Modules/CanvasNative.swiftmodule/arm64-apple-ios-simulator.swiftinterface +2 -2
  83. package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/Modules/CanvasNative.swiftmodule/x86_64-apple-ios-simulator.abi.json +1174 -89
  84. package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/Modules/CanvasNative.swiftmodule/x86_64-apple-ios-simulator.private.swiftinterface +2 -2
  85. package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/Modules/CanvasNative.swiftmodule/x86_64-apple-ios-simulator.swiftdoc +0 -0
  86. package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/Modules/CanvasNative.swiftmodule/x86_64-apple-ios-simulator.swiftinterface +2 -2
  87. package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/CanvasNative.framework/_CodeSignature/CodeResources +42 -31
  88. package/platforms/ios/CanvasNative.xcframework/ios-arm64_x86_64-simulator/dSYMs/CanvasNative.framework.dSYM/Contents/Resources/DWARF/CanvasNative +0 -0
  89. package/platforms/ios/Podfile +3 -0
  90. package/platforms/ios/build.xcconfig +3 -3
  91. package/platforms/ios/src/CanvasModule.h +0 -2
  92. package/platforms/ios/src/CanvasModule.mm +4 -4
  93. package/platforms/ios/src/NSOperationQueueWrapper.h +11 -0
  94. package/platforms/ios/src/NSOperationQueueWrapper.mm +74 -0
  95. package/platforms/ios/src/cpp/Caches.cpp +35 -0
  96. package/platforms/ios/src/cpp/Caches.h +186 -0
  97. package/platforms/ios/src/cpp/CanvasJSIModule.cpp +1582 -0
  98. package/platforms/ios/src/cpp/CanvasJSIModule.h +7 -34
  99. package/platforms/ios/src/cpp/Common.h +30 -0
  100. package/platforms/ios/src/cpp/ConcurrentMap.h +54 -0
  101. package/platforms/ios/src/cpp/Helpers.h +304 -38
  102. package/platforms/ios/src/cpp/ImageAssetImpl.cpp +802 -0
  103. package/platforms/ios/src/cpp/ImageAssetImpl.h +44 -12
  104. package/platforms/ios/src/cpp/ImageBitmapImpl.cpp +189 -0
  105. package/platforms/ios/src/cpp/ImageBitmapImpl.h +22 -16
  106. package/platforms/ios/src/cpp/JSICallback.h +61 -5
  107. package/platforms/ios/src/cpp/JSIReadFileCallback.h +86 -6
  108. package/platforms/ios/src/cpp/JSIRuntime.cpp +21 -0
  109. package/platforms/ios/src/cpp/JSIRuntime.h +7 -0
  110. package/platforms/ios/src/cpp/OneByteStringResource.cpp +25 -0
  111. package/platforms/ios/src/cpp/OneByteStringResource.h +21 -0
  112. package/platforms/ios/src/cpp/RafImpl.cpp +8 -0
  113. package/platforms/ios/src/cpp/RafImpl.h +11 -8
  114. package/platforms/ios/src/cpp/TextDecoderImpl.cpp +188 -0
  115. package/platforms/ios/src/cpp/TextDecoderImpl.h +20 -14
  116. package/platforms/ios/src/cpp/TextEncoderImpl.cpp +139 -0
  117. package/platforms/ios/src/cpp/TextEncoderImpl.h +20 -11
  118. package/platforms/ios/src/cpp/canvas2d/CanvasGradient.cpp +71 -0
  119. package/platforms/ios/src/cpp/canvas2d/CanvasGradient.h +27 -13
  120. package/platforms/ios/src/cpp/canvas2d/CanvasPattern.cpp +89 -0
  121. package/platforms/ios/src/cpp/canvas2d/CanvasPattern.h +26 -13
  122. package/platforms/ios/src/cpp/canvas2d/CanvasRenderingContext2DImpl.cpp +2402 -0
  123. package/platforms/ios/src/cpp/canvas2d/CanvasRenderingContext2DImpl.h +264 -21
  124. package/platforms/ios/src/cpp/canvas2d/ImageDataImpl.cpp +203 -0
  125. package/platforms/ios/src/cpp/canvas2d/ImageDataImpl.h +26 -12
  126. package/platforms/ios/src/cpp/canvas2d/MatrixImpl.cpp +800 -0
  127. package/platforms/ios/src/cpp/canvas2d/MatrixImpl.h +172 -13
  128. package/platforms/ios/src/cpp/canvas2d/Path2D.cpp +449 -0
  129. package/platforms/ios/src/cpp/canvas2d/Path2D.h +41 -12
  130. package/platforms/ios/src/cpp/canvas2d/TextMetricsImpl.cpp +253 -0
  131. package/platforms/ios/src/cpp/canvas2d/TextMetricsImpl.h +50 -12
  132. package/platforms/ios/src/cpp/gl.h +57 -7
  133. package/platforms/ios/src/cpp/gl3stub.c +425 -0
  134. package/platforms/ios/src/cpp/gl3stub.h +665 -0
  135. package/platforms/ios/src/cpp/gles3jni.h +37 -0
  136. package/platforms/ios/src/cpp/include/robin_hood.h +2544 -0
  137. package/platforms/ios/src/cpp/webgl/WebGLActiveInfoImpl.cpp +93 -0
  138. package/platforms/ios/src/cpp/webgl/WebGLActiveInfoImpl.h +33 -13
  139. package/platforms/ios/src/cpp/webgl/WebGLBuffer.h +41 -6
  140. package/platforms/ios/src/cpp/webgl/WebGLFramebuffer.h +46 -10
  141. package/platforms/ios/src/cpp/webgl/WebGLProgram.h +40 -5
  142. package/platforms/ios/src/cpp/webgl/WebGLRenderbuffer.h +40 -6
  143. package/platforms/ios/src/cpp/webgl/WebGLRenderingContext.cpp +6691 -0
  144. package/platforms/ios/src/cpp/webgl/WebGLRenderingContext.h +261 -390
  145. package/platforms/ios/src/cpp/webgl/{WebGLRenderingContextBase.mm → WebGLRenderingContextBase.cpp} +17 -16
  146. package/platforms/ios/src/cpp/webgl/WebGLRenderingContextBase.h +15 -36
  147. package/platforms/ios/src/cpp/webgl/WebGLShader.h +40 -6
  148. package/platforms/ios/src/cpp/webgl/WebGLShaderPrecisionFormatImpl.cpp +50 -0
  149. package/platforms/ios/src/cpp/webgl/WebGLShaderPrecisionFormatImpl.h +66 -11
  150. package/platforms/ios/src/cpp/webgl/WebGLTexture.h +40 -6
  151. package/platforms/ios/src/cpp/webgl/WebGLUniformLocation.h +44 -8
  152. package/platforms/ios/src/cpp/webgl/extensions/ANGLE_instanced_arraysImpl.cpp +126 -0
  153. package/platforms/ios/src/cpp/webgl/extensions/ANGLE_instanced_arraysImpl.h +25 -12
  154. package/platforms/ios/src/cpp/webgl/extensions/EXT_blend_minmaxImpl.cpp +35 -0
  155. package/platforms/ios/src/cpp/webgl/extensions/EXT_blend_minmaxImpl.h +25 -5
  156. package/platforms/ios/src/cpp/webgl/extensions/EXT_color_buffer_half_floatImpl.cpp +41 -0
  157. package/platforms/ios/src/cpp/webgl/extensions/EXT_color_buffer_half_floatImpl.h +25 -5
  158. package/platforms/ios/src/cpp/webgl/extensions/EXT_disjoint_timer_queryImpl.cpp +323 -0
  159. package/platforms/ios/src/cpp/webgl/extensions/EXT_disjoint_timer_queryImpl.h +47 -13
  160. package/platforms/ios/src/cpp/webgl/extensions/EXT_sRGBImpl.h +49 -6
  161. package/platforms/ios/src/cpp/webgl/extensions/EXT_shader_texture_lodImpl.h +37 -15
  162. package/platforms/ios/src/cpp/webgl/extensions/EXT_texture_filter_anisotropicImpl.h +47 -6
  163. package/platforms/ios/src/cpp/webgl/extensions/OES_element_index_uintImpl.h +49 -6
  164. package/platforms/ios/src/cpp/webgl/extensions/OES_fbo_render_mipmap.h +36 -15
  165. package/platforms/ios/src/cpp/webgl/extensions/OES_standard_derivativesImpl.h +44 -6
  166. package/platforms/ios/src/cpp/webgl/extensions/OES_texture_floatImpl.h +38 -15
  167. package/platforms/ios/src/cpp/webgl/extensions/OES_texture_float_linearImpl.h +37 -16
  168. package/platforms/ios/src/cpp/webgl/extensions/OES_texture_half_floatImpl.h +41 -6
  169. package/platforms/ios/src/cpp/webgl/extensions/OES_texture_half_float_linearImpl.h +40 -16
  170. package/platforms/ios/src/cpp/webgl/extensions/OES_vertex_array_objectImpl.cpp +102 -0
  171. package/platforms/ios/src/cpp/webgl/extensions/OES_vertex_array_objectImpl.h +69 -14
  172. package/platforms/ios/src/cpp/webgl/extensions/WEBGL_color_buffer_floatImpl.h +51 -8
  173. package/platforms/ios/src/cpp/webgl/extensions/WEBGL_compressed_texture_atcImpl.h +49 -6
  174. package/platforms/ios/src/cpp/webgl/extensions/WEBGL_compressed_texture_etc1Impl.h +49 -8
  175. package/platforms/ios/src/cpp/webgl/extensions/WEBGL_compressed_texture_etcImpl.h +76 -6
  176. package/platforms/ios/src/cpp/webgl/extensions/WEBGL_compressed_texture_pvrtcImpl.h +57 -6
  177. package/platforms/ios/src/cpp/webgl/extensions/WEBGL_compressed_texture_s3tcImpl.h +53 -6
  178. package/platforms/ios/src/cpp/webgl/extensions/WEBGL_compressed_texture_s3tc_srgbImpl.h +59 -6
  179. package/platforms/ios/src/cpp/webgl/extensions/WEBGL_depth_textureImpl.h +46 -6
  180. package/platforms/ios/src/cpp/webgl/extensions/WEBGL_draw_buffersImpl.cpp +43 -0
  181. package/platforms/ios/src/cpp/webgl/extensions/WEBGL_draw_buffersImpl.h +126 -14
  182. package/platforms/ios/src/cpp/webgl/extensions/WEBGL_lose_contextImpl.cpp +32 -0
  183. package/platforms/ios/src/cpp/webgl/extensions/WEBGL_lose_contextImpl.h +61 -12
  184. package/platforms/ios/src/cpp/webgl2/WebGL2RenderingContext.cpp +4517 -0
  185. package/platforms/ios/src/cpp/webgl2/WebGL2RenderingContext.h +139 -343
  186. package/platforms/ios/src/cpp/webgl2/WebGLQuery.h +40 -4
  187. package/platforms/ios/src/cpp/webgl2/WebGLSampler.h +42 -3
  188. package/platforms/ios/src/cpp/webgl2/WebGLSyncImpl.h +44 -11
  189. package/platforms/ios/src/cpp/webgl2/WebGLTransformFeedback.h +42 -4
  190. package/platforms/ios/src/cpp/webgl2/WebGLVertexArrayObject.h +43 -4
  191. package/platforms/ios/src/module.modulemap +1 -0
  192. package/platforms/ios/src/cpp/CanvasJSIModule.mm +0 -1105
  193. package/platforms/ios/src/cpp/ImageAssetImpl.mm +0 -417
  194. package/platforms/ios/src/cpp/ImageBitmapImpl.mm +0 -126
  195. package/platforms/ios/src/cpp/RafImpl.mm +0 -10
  196. package/platforms/ios/src/cpp/TextDecoderImpl.mm +0 -97
  197. package/platforms/ios/src/cpp/TextEncoderImpl.mm +0 -60
  198. package/platforms/ios/src/cpp/VecMutableBuffer.h +0 -46
  199. package/platforms/ios/src/cpp/canvas-cxx/src/lib.rs.cc +0 -6156
  200. package/platforms/ios/src/cpp/canvas-cxx/src/lib.rs.h +0 -2867
  201. package/platforms/ios/src/cpp/canvas2d/CanvasGradient.mm +0 -42
  202. package/platforms/ios/src/cpp/canvas2d/CanvasPattern.mm +0 -49
  203. package/platforms/ios/src/cpp/canvas2d/CanvasRenderingContext2DImpl.mm +0 -1972
  204. package/platforms/ios/src/cpp/canvas2d/ImageDataImpl.mm +0 -68
  205. package/platforms/ios/src/cpp/canvas2d/MatrixImpl.mm +0 -149
  206. package/platforms/ios/src/cpp/canvas2d/Path2D.mm +0 -335
  207. package/platforms/ios/src/cpp/canvas2d/TextMetricsImpl.mm +0 -68
  208. package/platforms/ios/src/cpp/rust/cxx.cc +0 -793
  209. package/platforms/ios/src/cpp/rust/cxx.h +0 -1111
  210. package/platforms/ios/src/cpp/webgl/WebGLActiveInfoImpl.mm +0 -39
  211. package/platforms/ios/src/cpp/webgl/WebGLRenderingContext.mm +0 -5958
  212. package/platforms/ios/src/cpp/webgl/WebGLShaderPrecisionFormatImpl.mm +0 -40
  213. package/platforms/ios/src/cpp/webgl/extensions/ANGLE_instanced_arraysImpl.mm +0 -108
  214. package/platforms/ios/src/cpp/webgl/extensions/EXT_blend_minmaxImpl.mm +0 -28
  215. package/platforms/ios/src/cpp/webgl/extensions/EXT_color_buffer_half_floatImpl.mm +0 -42
  216. package/platforms/ios/src/cpp/webgl/extensions/EXT_disjoint_timer_queryImpl.mm +0 -295
  217. package/platforms/ios/src/cpp/webgl/extensions/EXT_sRGBImpl.mm +0 -40
  218. package/platforms/ios/src/cpp/webgl/extensions/EXT_texture_filter_anisotropicImpl.mm +0 -37
  219. package/platforms/ios/src/cpp/webgl/extensions/OES_element_index_uintImpl.mm +0 -28
  220. package/platforms/ios/src/cpp/webgl/extensions/OES_standard_derivativesImpl.mm +0 -31
  221. package/platforms/ios/src/cpp/webgl/extensions/OES_texture_half_floatImpl.mm +0 -28
  222. package/platforms/ios/src/cpp/webgl/extensions/OES_vertex_array_objectImpl.mm +0 -127
  223. package/platforms/ios/src/cpp/webgl/extensions/WEBGL_color_buffer_floatImpl.mm +0 -45
  224. package/platforms/ios/src/cpp/webgl/extensions/WEBGL_compressed_texture_atcImpl.mm +0 -45
  225. package/platforms/ios/src/cpp/webgl/extensions/WEBGL_compressed_texture_etc1Impl.mm +0 -31
  226. package/platforms/ios/src/cpp/webgl/extensions/WEBGL_compressed_texture_etcImpl.mm +0 -70
  227. package/platforms/ios/src/cpp/webgl/extensions/WEBGL_compressed_texture_pvrtcImpl.mm +0 -47
  228. package/platforms/ios/src/cpp/webgl/extensions/WEBGL_compressed_texture_s3tcImpl.mm +0 -46
  229. package/platforms/ios/src/cpp/webgl/extensions/WEBGL_compressed_texture_s3tc_srgbImpl.mm +0 -49
  230. package/platforms/ios/src/cpp/webgl/extensions/WEBGL_depth_textureImpl.mm +0 -30
  231. package/platforms/ios/src/cpp/webgl/extensions/WEBGL_draw_buffersImpl.mm +0 -177
  232. package/platforms/ios/src/cpp/webgl/extensions/WEBGL_lose_contextImpl.mm +0 -64
  233. package/platforms/ios/src/cpp/webgl2/WebGL2RenderingContext.mm +0 -4551
  234. /package/platforms/ios/src/cpp/{OnRafCallback.mm → OnRafCallback.cpp} +0 -0
@@ -1,1105 +0,0 @@
1
- //
2
- // Created by Osei Fortune on 25/02/2023.
3
- //
4
-
5
- #include "CanvasJSIModule.h"
6
- #include "JSICallback.h"
7
- #include "Helpers.h"
8
- #include "JSIReadFileCallback.h"
9
- #include <NativeScript/JSIRuntime.h>
10
-
11
- void CanvasJSIModule::install(facebook::jsi::Runtime &jsiRuntime) {
12
- auto canvas_module = facebook::jsi::Object(jsiRuntime);
13
-
14
- CREATE_FUNC("readFile", canvas_module, 2,
15
- ([](jsi::Runtime &runtime, const jsi::Value &thisValue,
16
- const jsi::Value *arguments, size_t count) -> jsi::Value {
17
-
18
- auto current_queue = NSOperationQueue.currentQueue;
19
-
20
- auto file = arguments[0].asString(runtime).utf8(runtime);
21
-
22
-
23
- auto cbFunc = std::make_shared<jsi::Value>(
24
- runtime, arguments[1]);
25
-
26
- auto jsi_callback = new JSIReadFileCallback(
27
- std::shared_ptr<jsi::Value>(
28
- cbFunc));
29
-
30
-
31
- auto queue = [NSOperationQueue new];
32
- [queue addOperationWithBlock:^{
33
-
34
-
35
- bool done = false;
36
- auto ret = canvas_native_helper_read_file(
37
- rust::Str(file.c_str()));
38
-
39
- if (!canvas_native_helper_read_file_has_error(*ret)) {
40
- auto buf = canvas_native_helper_read_file_get_data(
41
- std::move(ret));
42
-
43
- auto vec_buffer = std::make_shared<VecMutableBuffer<uint8_t>>(
44
- std::move(buf));
45
-
46
- jsi_callback->data_ = std::make_shared<jsi::Value>(runtime, jsi::ArrayBuffer(
47
- runtime,
48
- vec_buffer));
49
- done = true;
50
- } else {
51
- auto error = canvas_native_helper_read_file_get_error(
52
- *ret);
53
-
54
- jsi_callback->data_ = std::make_shared<jsi::Value>(runtime,jsi::String::createFromAscii(
55
- runtime,
56
- error.c_str()));
57
- }
58
-
59
-
60
-
61
-
62
- [current_queue addOperationWithBlock:^{
63
-
64
-
65
- auto func = jsi_callback->value_->asObject(
66
- runtime).asFunction(
67
- runtime);
68
-
69
-
70
-
71
- if (done) {
72
- auto buf = jsi_callback->data_->asObject(runtime).getArrayBuffer(runtime);
73
- func.call(runtime, {jsi::Value::null(), std::move(buf)});
74
- } else {
75
- auto error = jsi_callback->data_->asString(runtime);
76
- func.call(runtime, {std::move(error), jsi::Value::null()});
77
- }
78
-
79
- delete static_cast<JSIReadFileCallback *>(jsi_callback);
80
-
81
-
82
- }];
83
- }];
84
-
85
- return jsi::Value::undefined();
86
- }
87
-
88
- )
89
-
90
- );
91
-
92
-
93
- CREATE_FUNC("ImageData", canvas_module, 4,
94
- ([](jsi::Runtime &runtime, const jsi::Value &thisValue,
95
- const jsi::Value *arguments, size_t count) -> jsi::Value {
96
-
97
- if (arguments[0].isNumber()) {
98
- auto image_data = canvas_native_context_create_image_data(
99
- (int32_t) arguments[0].asNumber(),
100
- (int32_t) arguments[1].asNumber());
101
- auto object = std::make_shared<ImageDataImpl>(std::move(image_data));
102
- return jsi::Object::createFromHostObject(runtime, std::move(object));
103
- } else if (arguments[0].isObject()) {
104
- auto arrayObject = arguments[0].asObject(runtime);
105
- auto array = arrayObject.getTypedArray(runtime);
106
- auto buf = GetTypedArrayData<const uint8_t>(runtime, array);
107
-
108
- auto image_data = canvas_native_context_create_image_data_with_data(
109
- (int32_t) arguments[1].asNumber(),
110
- (int32_t) arguments[2].asNumber(), buf);
111
- auto object = std::make_shared<ImageDataImpl>(std::move(image_data));
112
- return jsi::Object::createFromHostObject(runtime, std::move(object));
113
- }
114
- // TODO throw ?
115
- return jsi::Value::undefined();
116
- })
117
-
118
- );
119
-
120
-
121
- CREATE_FUNC("ImageAsset", canvas_module, 0,
122
- ([](jsi::Runtime &runtime, const jsi::Value &thisValue,
123
- const jsi::Value *arguments, size_t count) -> jsi::Value {
124
-
125
- auto asset = canvas_native_image_asset_create();
126
- auto object = std::make_shared<ImageAssetImpl>(std::move(asset));
127
- return jsi::Object::createFromHostObject(runtime, std::move(object));
128
- })
129
-
130
- );
131
-
132
- CREATE_FUNC("DOMMatrix", canvas_module, 1,
133
- ([](jsi::Runtime &runtime, const jsi::Value &thisValue,
134
- const jsi::Value *arguments, size_t count) -> jsi::Value {
135
-
136
- if (count > 0) {
137
- if (arguments[0].isObject()) {
138
- auto initObject = arguments[0].asObject(runtime);
139
- if (initObject.isArray(runtime)) {
140
- auto init = initObject.getArray(runtime);
141
- auto size = init.size(runtime);
142
- if (size == 6) {
143
- auto matrix = canvas_native_matrix_create();
144
- rust::Vec<float> buf;
145
- buf.reserve(size);
146
- for (int i = 0; i < size; i++) {
147
- auto item = init.getValueAtIndex(runtime, i).asNumber();
148
- buf.emplace_back((float) item);
149
- }
150
- rust::Slice<const float> slice(buf.data(), buf.size());
151
-
152
- canvas_native_matrix_update(*matrix, slice);
153
-
154
- auto object = std::make_shared<MatrixImpl>(std::move(matrix));
155
- return jsi::Object::createFromHostObject(runtime,
156
- std::move(object));
157
- }
158
-
159
- if (size == 16) {
160
- auto matrix = canvas_native_matrix_create();
161
- std::array<float, 16> buf;
162
-
163
- for (int i = 0; i < size; i++) {
164
- auto item = init.getValueAtIndex(runtime, i).asNumber();
165
- buf[i] = (float) item;
166
- }
167
- canvas_native_matrix_update_3d(*matrix, buf);
168
-
169
- auto object = std::make_shared<MatrixImpl>(std::move(matrix));
170
- return jsi::Object::createFromHostObject(runtime,
171
- std::move(object));
172
- }
173
- }
174
- }
175
- } else {
176
- auto matrix = canvas_native_matrix_create();
177
- auto object = std::make_shared<MatrixImpl>(std::move(matrix));
178
- return jsi::Object::createFromHostObject(runtime, std::move(object));
179
- }
180
- return jsi::Value::undefined();
181
- })
182
-
183
- );
184
-
185
- CREATE_FUNC("Path2D", canvas_module, 1,
186
- [](jsi::Runtime &runtime, const jsi::Value &thisValue,
187
- const jsi::Value *arguments, size_t count) -> jsi::Value {
188
-
189
- if (count > 0) {
190
- auto obj = &arguments[0];
191
- if (obj->isString()) {
192
- auto d = obj->asString(runtime).utf8(runtime);
193
- auto path = canvas_native_path_create_with_str(
194
- rust::Str(d.c_str()));
195
- auto object = std::make_shared<Path2D>(std::move(path));
196
- return jsi::Object::createFromHostObject(runtime, std::move(object));
197
- } else if (obj->isObject()) {
198
- auto path_to_copy = getHostObject<Path2D>(runtime, arguments[0]);
199
- if (path_to_copy != nullptr) {
200
- auto path = canvas_native_path_create_with_path(
201
- path_to_copy->GetPath());
202
- auto object = std::make_shared<Path2D>(std::move(path));
203
- return jsi::Object::createFromHostObject(runtime,
204
- std::move(object));
205
- }
206
- }
207
- } else {
208
- auto path = canvas_native_path_create();
209
- auto object = std::make_shared<Path2D>(std::move(path));
210
- return jsi::Object::createFromHostObject(runtime, std::move(object));
211
- }
212
- return jsi::Value::undefined();
213
- }
214
-
215
- );
216
-
217
- CREATE_FUNC("TextEncoder", canvas_module, 1,
218
- [](jsi::Runtime &runtime, const jsi::Value &thisValue,
219
- const jsi::Value *arguments, size_t count) -> jsi::Value {
220
- if (count == 1 && !arguments[0].isString()) {
221
- auto arg = arguments[0].toString(runtime).utf8(runtime);
222
- std::string error = "Failed to construct 'TextEncoder': The encoding label provided (" +
223
- arg + "') is invalid";
224
-
225
- throw jsi::JSINativeException(error);
226
- }
227
-
228
- std::string encoding("utf-8");
229
- if (count == 1) {
230
- encoding = arguments[0].asString(runtime).utf8(runtime);
231
- }
232
- auto encoder = canvas_native_text_encoder_create(
233
- rust::Str(encoding.c_str()));
234
- auto shared_encoder = std::make_shared<TextEncoderImpl>(std::move(encoder));
235
- return jsi::Object::createFromHostObject(runtime, shared_encoder);
236
- }
237
-
238
- );
239
-
240
- CREATE_FUNC("TextDecoder", canvas_module, 1,
241
- [](jsi::Runtime &runtime, const jsi::Value &thisValue,
242
- const jsi::Value *arguments, size_t count) -> jsi::Value {
243
- if (count == 1 && !arguments[0].isString()) {
244
- auto arg = arguments[0].toString(runtime).utf8(runtime);
245
- throw jsi::JSINativeException(
246
- "Failed to construct 'TextDecoder': The encoding label provided (" +
247
- arg + "') is invalid");
248
- }
249
-
250
- std::string encoding("utf-8");
251
- if (count == 1) {
252
- encoding = arguments[0].asString(runtime).utf8(runtime);
253
- }
254
- auto encoder = canvas_native_text_decoder_create(
255
- rust::Str(encoding.c_str()));
256
- auto shared_decoder = std::make_shared<TextDecoderImpl>(std::move(encoder));
257
- return jsi::Object::createFromHostObject(runtime, shared_decoder);
258
- }
259
-
260
- );
261
-
262
-
263
- CREATE_FUNC("createImageBitmap", canvas_module, 5,
264
- [](jsi::Runtime &runtime, const jsi::Value &thisValue,
265
- const jsi::Value *arguments, size_t count) -> jsi::Value {
266
-
267
- auto image = &arguments[0];
268
- auto sx_or_options = &arguments[1];
269
- auto sy = &arguments[2];
270
- auto sw = &arguments[3];
271
- auto sh = &arguments[4];
272
-
273
- auto len = count;
274
- auto cb = &arguments[count - 1];
275
- len = len - 1;
276
-
277
- if (len == 1 && !image->isObject() ||
278
- image->asObject(runtime).isFunction(runtime)) {
279
- throw jsi::JSINativeException("Illegal constructor");
280
- }
281
-
282
- Options options;
283
-
284
- if (len == 0) {
285
- throw jsi::JSINativeException("Illegal constructor");
286
- }
287
-
288
- if (!cb->isObject() && !cb->asObject(runtime).isFunction(runtime)) {
289
- throw jsi::JSINativeException("Illegal constructor");
290
- }
291
-
292
-
293
- if (image->isNull() || image->isUndefined()) {
294
- auto error = jsi::String::createFromAscii(
295
- runtime,
296
- "Failed to load image");
297
- cb->asObject(runtime).asFunction(runtime).call(runtime,
298
- {std::move(error),
299
- jsi::Value::null()});
300
- return jsi::Value::undefined();
301
- }
302
-
303
- if (len >= 4 && (sw->isNumber() && sw->asNumber() == 0)) {
304
- auto error = jsi::String::createFromAscii(runtime,
305
- "Failed to execute 'createImageBitmap' : The crop rect width is 0");
306
- cb->asObject(runtime).asFunction(runtime).call(runtime, {std::move(error),
307
- jsi::Value::undefined()});
308
- return jsi::Value::undefined();
309
- }
310
- if (len >= 5 && (sh->isNumber() && sh->asNumber() == 0)) {
311
- auto error = jsi::String::createFromAscii(runtime,
312
- "Failed to execute 'createImageBitmap' : The crop rect height is 0");
313
- cb->asObject(runtime).asFunction(runtime).call(runtime, {std::move(error),
314
- jsi::Value::undefined()});
315
- return jsi::Value::undefined();
316
- }
317
-
318
- auto current_queue = NSOperationQueue.currentQueue;
319
-
320
- if (arguments[0].isObject()) {
321
- auto imageObject = arguments[0].asObject(runtime);
322
- auto isArrayBuffer = imageObject.isArrayBuffer(runtime);
323
- auto isTypedArray = imageObject.isTypedArray(runtime);
324
- if (isArrayBuffer || isTypedArray) {
325
-
326
- if (len == 1 || len == 2) {
327
- if (len == 2) {
328
- options = ImageBitmapImpl::HandleOptions(runtime, arguments[1]);
329
- }
330
-
331
- auto asset = canvas_native_image_asset_create();
332
-
333
- auto shared_asset = canvas_native_image_asset_shared_clone(*asset);
334
-
335
-
336
- auto ret = std::make_shared<ImageBitmapImpl>(
337
- std::move(asset));
338
-
339
- auto cbFunc = std::make_shared<jsi::Value>(
340
- runtime, arguments[count - 1]);
341
-
342
- auto jsi_callback = new JSICallback(
343
- std::shared_ptr<jsi::Value>(
344
- cbFunc));
345
-
346
- jsi_callback->data_ = ret;
347
-
348
- auto ab = std::make_shared<jsi::Value>(runtime,
349
- std::move(arguments[0]));
350
-
351
- if (isArrayBuffer) {
352
- auto queue = [NSOperationQueue new];
353
- [queue addOperationWithBlock:^{
354
-
355
-
356
- auto arrayBuffer = ab->asObject(
357
- runtime).getArrayBuffer(runtime);
358
-
359
- auto data = arrayBuffer.data(runtime);
360
- auto size = arrayBuffer.size(runtime);
361
-
362
-
363
- auto done = canvas_native_image_bitmap_create_from_encoded_bytes_with_output(
364
- rust::Slice<const uint8_t>(data, size),
365
- options.flipY,
366
- options.premultiplyAlpha,
367
- options.colorSpaceConversion,
368
- options.resizeQuality,
369
- options.resizeWidth,
370
- options.resizeHeight, ret->GetImageAsset());
371
-
372
-
373
- [current_queue addOperationWithBlock:^{
374
-
375
-
376
- auto func = jsi_callback->value_->asObject(
377
- runtime).asFunction(
378
- runtime);
379
-
380
- if (done) {
381
-
382
- func.call(runtime, {jsi::Value::null(),
383
- jsi::Object::createFromHostObject(
384
- runtime,
385
- std::move(
386
- jsi_callback->data_))});
387
-
388
- } else {
389
-
390
- auto error = jsi::String::createFromAscii(runtime,
391
- "Failed to load image");
392
- func.call(runtime,
393
- {std::move(
394
- error),
395
- jsi::Value::null()});
396
-
397
- }
398
-
399
- delete static_cast<JSICallback *>(jsi_callback);
400
-
401
-
402
- }];
403
- }];
404
-
405
- return jsi::Value::undefined();
406
- }
407
-
408
- if (isTypedArray) {
409
-
410
- auto queue = [NSOperationQueue new];
411
- [queue addOperationWithBlock:^{
412
-
413
- auto array = ab->asObject(runtime).getTypedArray(
414
- runtime);
415
- auto data = GetTypedArrayData<const uint8_t>(
416
- runtime, array);
417
-
418
- auto done = canvas_native_image_bitmap_create_from_encoded_bytes_with_output(
419
- data,
420
- options.flipY,
421
- options.premultiplyAlpha,
422
- options.colorSpaceConversion,
423
- options.resizeQuality,
424
- options.resizeWidth,
425
- options.resizeHeight,
426
- ret->GetImageAsset());
427
-
428
-
429
- [current_queue addOperationWithBlock:^{
430
-
431
-
432
-
433
-
434
- auto func = jsi_callback->value_->asObject(
435
- runtime).asFunction(
436
- runtime);
437
-
438
-
439
-
440
- if (done) {
441
-
442
- func.call(runtime, {jsi::Value::null(),
443
- jsi::Object::createFromHostObject(
444
- runtime,
445
- std::move(
446
- jsi_callback->data_))});
447
-
448
- } else {
449
-
450
- auto error = jsi::String::createFromAscii(runtime,
451
- "Failed to load image");
452
- func.call(runtime,
453
- {std::move(
454
- error),
455
- jsi::Value::null()});
456
-
457
- }
458
-
459
-
460
-
461
-
462
- delete static_cast<JSICallback *>(jsi_callback);
463
- }];
464
- }];
465
-
466
- }
467
-
468
-
469
- return jsi::Value::undefined();
470
- } else if (len == 5 || len == 6) {
471
-
472
- auto cbFunc = std::make_shared<jsi::Value>(
473
- runtime, arguments[count - 1]);
474
-
475
- if (len == 6) {
476
- options = ImageBitmapImpl::HandleOptions(runtime, arguments[5]);
477
- }
478
-
479
- auto asset = canvas_native_image_asset_create();
480
-
481
- auto shared_asset = canvas_native_image_asset_shared_clone(*asset);
482
-
483
- auto ret = std::make_shared<ImageBitmapImpl>(
484
- std::move(asset));
485
-
486
- auto jsi_callback = new JSICallback(
487
- std::shared_ptr<jsi::Value>(
488
- cbFunc));
489
-
490
- jsi_callback->data_ = std::move(ret);
491
-
492
- auto ab = std::make_shared<jsi::Value>(runtime,
493
- std::move(arguments[0]));
494
-
495
-
496
- if (isArrayBuffer) {
497
-
498
- auto queue = [NSOperationQueue new];
499
- [queue addOperationWithBlock:^{
500
-
501
-
502
- auto arrayBuffer = ab->asObject(
503
- runtime).getArrayBuffer(runtime);
504
-
505
- auto data = arrayBuffer.data(runtime);
506
- auto size = arrayBuffer.size(runtime);
507
-
508
- auto done = canvas_native_image_bitmap_create_from_encoded_bytes_src_rect_with_output(
509
- rust::Slice<const uint8_t>(data, size),
510
- (float) sx_or_options->asNumber(),
511
- (float) sy->asNumber(),
512
- (float) sw->asNumber(),
513
- (float) sh->asNumber(),
514
- options.flipY,
515
- options.premultiplyAlpha,
516
- options.colorSpaceConversion,
517
- options.resizeQuality,
518
- options.resizeWidth,
519
- options.resizeHeight, ret->GetImageAsset());
520
-
521
-
522
- [current_queue addOperationWithBlock:^{
523
-
524
- auto func = jsi_callback->value_->asObject(
525
- runtime).asFunction(
526
- runtime);
527
-
528
-
529
- if (done) {
530
-
531
- func.call(runtime, {jsi::Value::null(),
532
- jsi::Object::createFromHostObject(
533
- runtime,
534
- std::move(
535
- jsi_callback->data_))});
536
-
537
- } else {
538
-
539
- auto error = jsi::String::createFromAscii(runtime,
540
- "Failed to load image");
541
- func.call(runtime,
542
- {std::move(
543
- error),
544
- jsi::Value::null()});
545
-
546
- }
547
-
548
-
549
-
550
-
551
- delete static_cast<JSICallback *>(jsi_callback);
552
- }];
553
- }];
554
-
555
-
556
- return jsi::Value::undefined();
557
- }
558
-
559
- if (isTypedArray) {
560
-
561
- auto queue = [NSOperationQueue new];
562
- [queue addOperationWithBlock:^{
563
-
564
- auto array = ab->asObject(runtime).getTypedArray(
565
- runtime);
566
- auto data = GetTypedArrayData<const uint8_t>(
567
- runtime, array);
568
-
569
- auto done = canvas_native_image_bitmap_create_from_encoded_bytes_src_rect_with_output(
570
- data,
571
- (float) sx_or_options->asNumber(),
572
- (float) sy->asNumber(),
573
- (float) sw->asNumber(),
574
- (float) sh->asNumber(),
575
- options.flipY,
576
- options.premultiplyAlpha,
577
- options.colorSpaceConversion,
578
- options.resizeQuality,
579
- options.resizeWidth,
580
- options.resizeHeight, ret->GetImageAsset());
581
-
582
- [current_queue addOperationWithBlock:^{
583
-
584
-
585
-
586
-
587
- auto func = jsi_callback->value_->asObject(
588
- runtime).asFunction(
589
- runtime);
590
-
591
-
592
- if (done) {
593
-
594
- func.call(runtime, {jsi::Value::null(),
595
- jsi::Object::createFromHostObject(
596
- runtime,
597
- std::move(
598
- jsi_callback->data_))});
599
-
600
- } else {
601
-
602
- auto error = jsi::String::createFromAscii(runtime,
603
- "Failed to load image");
604
- func.call(runtime,
605
- {std::move(
606
- error),
607
- jsi::Value::null()});
608
-
609
- }
610
-
611
-
612
- delete static_cast<JSICallback *>(jsi_callback);
613
- }];
614
- }];
615
-
616
- }
617
-
618
-
619
-
620
- return jsi::Value::undefined();
621
- }
622
- }
623
- }
624
-
625
-
626
- auto image_asset = getHostObject<ImageAssetImpl>(
627
- runtime, arguments[0]);
628
-
629
- auto image_bitmap = getHostObject<ImageBitmapImpl>(
630
- runtime, arguments[0]);
631
-
632
- if (len == 1 || len == 2) {
633
- if (len == 2) {
634
- options = ImageBitmapImpl::HandleOptions(runtime, arguments[1]);
635
- }
636
-
637
-
638
- auto ret = canvas_native_image_bitmap_create_from_asset(
639
- image_asset != nullptr ? image_asset->GetImageAsset()
640
- : image_bitmap->GetImageAsset(),
641
- options.flipY,
642
- options.premultiplyAlpha,
643
- options.colorSpaceConversion,
644
- options.resizeQuality,
645
- options.resizeWidth,
646
- options.resizeHeight);
647
-
648
-
649
- auto bitmap = std::make_shared<ImageBitmapImpl>(std::move(ret));
650
-
651
- auto bitmap_object = jsi::Object::createFromHostObject(runtime, bitmap);
652
-
653
- cb->asObject(runtime).asFunction(runtime).call(runtime, {jsi::Value::null(),
654
- std::move(
655
- bitmap_object)});
656
-
657
- return jsi::Value::undefined();
658
- } else if (len == 5 || len == 6) {
659
-
660
- if (len == 6) {
661
- options = ImageBitmapImpl::HandleOptions(runtime, arguments[5]);
662
- }
663
-
664
- auto ret = canvas_native_image_bitmap_create_from_asset_src_rect(
665
- image_asset != nullptr ? image_asset->GetImageAsset()
666
- : image_bitmap->GetImageAsset(),
667
- (float) sx_or_options->asNumber(),
668
- (float) sy->asNumber(),
669
- (float) sw->asNumber(),
670
- (float) sh->asNumber(),
671
- options.flipY,
672
- options.premultiplyAlpha,
673
- options.colorSpaceConversion,
674
- options.resizeQuality,
675
- options.resizeWidth,
676
- options.resizeHeight);
677
-
678
- auto bitmap = std::make_shared<ImageBitmapImpl>(std::move(ret));
679
-
680
- auto bitmap_object = jsi::Object::createFromHostObject(runtime, bitmap);
681
-
682
- cb->asObject(runtime).asFunction(runtime).call(runtime, {jsi::Value::null(),
683
- std::move(
684
- bitmap_object)});
685
-
686
- return jsi::Value::undefined();
687
- }
688
-
689
-
690
- return jsi::Value::undefined();
691
- }
692
-
693
- );
694
-
695
- CREATE_FUNC("create2DContext", canvas_module, 9,
696
- [](jsi::Runtime &runtime, const jsi::Value &thisValue,
697
- const jsi::Value *arguments, size_t count) -> jsi::Value {
698
- auto context = getPointerValue(runtime, arguments[0]);
699
- auto width = (float) arguments[1].asNumber();
700
- auto height = (float) arguments[2].asNumber();
701
- auto density = (float) arguments[3].asNumber();
702
- auto samples = (int) arguments[4].asNumber();
703
- auto alpha = (bool) arguments[5].asBool();
704
- auto font_color = (int) arguments[6].asNumber();
705
- auto ppi = (float) arguments[7].asNumber();
706
- auto direction = (int) arguments[8].asNumber();
707
-
708
- auto context_2d = canvas_native_context_create_gl(width, height, density,
709
- context,
710
- samples, alpha,
711
- font_color, ppi, direction);
712
-
713
- auto ret = std::make_shared<CanvasRenderingContext2DImpl>(
714
- std::move(context_2d));
715
-
716
- return jsi::Object::createFromHostObject(runtime, ret);
717
- }
718
-
719
- );
720
-
721
- CREATE_FUNC("create2DContextWithPointer", canvas_module, 1,
722
- [](jsi::Runtime &runtime, const jsi::Value &thisValue,
723
- const jsi::Value *arguments, size_t count) -> jsi::Value {
724
- auto pointer = getPointerValue(runtime, arguments[0]);
725
-
726
- auto context_2d = canvas_native_context_create_with_pointer(pointer);
727
-
728
- auto ret = std::make_shared<CanvasRenderingContext2DImpl>(
729
- std::move(context_2d));
730
-
731
- return jsi::Object::createFromHostObject(runtime, ret);
732
- }
733
-
734
- );
735
-
736
- CREATE_FUNC("createWebGLContext", canvas_module, 7,
737
- [](jsi::Runtime &runtime, const jsi::Value &thisValue,
738
- const jsi::Value *arguments, size_t count) -> jsi::Value {
739
-
740
- if (arguments[0].isObject()) {
741
- auto config = arguments[0].asObject(runtime);
742
- std::string version("none");
743
- auto alpha = true;
744
- auto antialias = true;
745
- auto depth = true;
746
- auto fail_if_major_performance_caveat = false;
747
- std::string power_preference("default");
748
- auto premultiplied_alpha = true;
749
- auto preserve_drawing_buffer = false;
750
- auto stencil = false;
751
- auto desynchronized = false;
752
- auto xr_compatible = false;
753
-
754
-
755
- auto versionValue = config.getProperty(runtime, "version");
756
- if (versionValue.isString()) {
757
- version = versionValue.asString(runtime).utf8(runtime);
758
- }
759
-
760
- auto alphaValue = config.getProperty(runtime, "alpha");
761
- if (alphaValue.isBool()) {
762
- alpha = alphaValue.asBool();
763
- }
764
-
765
- auto antialiasValue = config.getProperty(runtime, "antialias");
766
- if (antialiasValue.isBool()) {
767
- antialias = antialiasValue.asBool();
768
- }
769
-
770
- auto failIfMajorPerformanceCaveatValue = config.getProperty(runtime,
771
- "failIfMajorPerformanceCaveat");
772
- if (failIfMajorPerformanceCaveatValue.isBool()) {
773
- fail_if_major_performance_caveat = failIfMajorPerformanceCaveatValue.asBool();
774
- }
775
-
776
- auto powerPreferenceValue = config.getProperty(runtime, "powerPreference");
777
- if (powerPreferenceValue.isString()) {
778
- power_preference = powerPreferenceValue.asString(runtime).utf8(runtime);
779
- }
780
-
781
- auto premultipliedAlphaValue = config.getProperty(runtime,
782
- "premultipliedAlpha");
783
- if (premultipliedAlphaValue.isBool()) {
784
- premultiplied_alpha = premultipliedAlphaValue.asBool();
785
- }
786
-
787
- auto preserveDrawingBufferValue = config.getProperty(runtime,
788
- "preserveDrawingBuffer");
789
- if (preserveDrawingBufferValue.isBool()) {
790
- preserve_drawing_buffer = preserveDrawingBufferValue.asBool();
791
- }
792
-
793
- auto stencilValue = config.getProperty(runtime, "stencil");
794
- if (stencilValue.isBool()) {
795
- stencil = stencilValue.asBool();
796
- }
797
-
798
- auto desynchronizedValue = config.getProperty(runtime, "desynchronized");
799
- if (desynchronizedValue.isBool()) {
800
- desynchronized = desynchronizedValue.asBool();
801
- }
802
-
803
- auto xrCompatibleValue = config.getProperty(
804
- runtime,
805
- "xrCompatible");
806
- if (xrCompatibleValue.isBool()) {
807
- xr_compatible = xrCompatibleValue.asBool();
808
- }
809
-
810
- if (version !=
811
- "v1") {
812
- return jsi::Value::undefined();
813
- } else {
814
- if (count == 6) {
815
- auto context = getPointerValue(runtime, arguments[1]);
816
- // auto density = arguments[2].asNumber();
817
- // auto fontColor = arguments[3].asNumber();
818
- // auto ppi = arguments[4].asNumber();
819
- // auto direction = arguments[5].asNumber();
820
- auto ctx = canvas_native_webgl_create(
821
- context,
822
- rust::Str(
823
- version.c_str()),
824
- alpha,
825
- antialias,
826
- depth,
827
- fail_if_major_performance_caveat,
828
- rust::Str(
829
- power_preference.c_str()),
830
- premultiplied_alpha,
831
- preserve_drawing_buffer,
832
- stencil,
833
- desynchronized,
834
- xr_compatible
835
- );
836
-
837
- auto renderingContext = std::make_shared<WebGLRenderingContext>(
838
- std::move(ctx));
839
-
840
- return jsi::Object::createFromHostObject(
841
- runtime, renderingContext);
842
-
843
- } else if (count == 7) {
844
- auto width = arguments[1].asNumber();
845
- auto height = arguments[2].asNumber();
846
- // auto density = arguments[3].asNumber();
847
- // auto fontColor = arguments[4].asNumber();
848
- // auto ppi = arguments[5].asNumber();
849
- // auto direction = arguments[6].asNumber();
850
- auto ctx = canvas_native_webgl_create_no_window(
851
- (int32_t) width,
852
- (int32_t) height,
853
- rust::Str(
854
- version.c_str()),
855
- alpha,
856
- antialias,
857
- depth,
858
- fail_if_major_performance_caveat,
859
- rust::Str(
860
- power_preference.c_str()),
861
- premultiplied_alpha,
862
- preserve_drawing_buffer,
863
- stencil,
864
- desynchronized,
865
- xr_compatible,
866
- false
867
- );
868
-
869
- auto renderingContext = std::make_shared<WebGLRenderingContext>(
870
- std::move(ctx));
871
-
872
- return jsi::Object::createFromHostObject(
873
- runtime, renderingContext);
874
-
875
- } else {
876
- auto width = (int32_t) arguments[1].asNumber();
877
- auto height = (int32_t) arguments[2].asNumber();
878
-
879
- auto ctx = canvas_native_webgl_create_no_window(
880
- width,
881
- height,
882
- rust::Str(
883
- version.c_str()),
884
- alpha,
885
- antialias,
886
- depth,
887
- fail_if_major_performance_caveat,
888
- rust::Str(
889
- power_preference.c_str()),
890
- premultiplied_alpha,
891
- preserve_drawing_buffer,
892
- stencil,
893
- desynchronized,
894
- xr_compatible,
895
- false
896
- );
897
-
898
- auto renderingContext = std::make_shared<WebGLRenderingContext>(
899
- std::move(
900
- ctx));
901
-
902
-
903
- return jsi::Object::createFromHostObject(
904
- runtime,
905
- renderingContext);
906
- }
907
-
908
- }
909
- }
910
-
911
-
912
- return jsi::Value::undefined();
913
- }
914
-
915
- );
916
-
917
- CREATE_FUNC("createWebGL2Context", canvas_module, 7,
918
- [](jsi::Runtime &runtime, const jsi::Value &thisValue,
919
- const jsi::Value *arguments, size_t count) -> jsi::Value {
920
-
921
- if (arguments[0].isObject()) {
922
- auto config = arguments[0].asObject(runtime);
923
- std::string version("none");
924
- auto alpha = true;
925
- auto antialias = true;
926
- auto depth = true;
927
- auto fail_if_major_performance_caveat = false;
928
- std::string power_preference("default");
929
- auto premultiplied_alpha = true;
930
- auto preserve_drawing_buffer = false;
931
- auto stencil = false;
932
- auto desynchronized = false;
933
- auto xr_compatible = false;
934
-
935
-
936
- auto versionValue = config.getProperty(runtime, "version");
937
- if (versionValue.isString()) {
938
- version = versionValue.asString(runtime).utf8(runtime);
939
- }
940
-
941
- auto alphaValue = config.getProperty(runtime, "alpha");
942
- if (alphaValue.isBool()) {
943
- alpha = alphaValue.asBool();
944
- }
945
-
946
- auto antialiasValue = config.getProperty(runtime, "antialias");
947
- if (antialiasValue.isBool()) {
948
- antialias = antialiasValue.asBool();
949
- }
950
-
951
- auto failIfMajorPerformanceCaveatValue = config.getProperty(runtime,
952
- "failIfMajorPerformanceCaveat");
953
- if (failIfMajorPerformanceCaveatValue.isBool()) {
954
- fail_if_major_performance_caveat = failIfMajorPerformanceCaveatValue.asBool();
955
- }
956
-
957
- auto powerPreferenceValue = config.getProperty(runtime, "powerPreference");
958
- if (powerPreferenceValue.isString()) {
959
- power_preference = powerPreferenceValue.asString(runtime).utf8(runtime);
960
- }
961
-
962
- auto premultipliedAlphaValue = config.getProperty(runtime,
963
- "premultipliedAlpha");
964
- if (premultipliedAlphaValue.isBool()) {
965
- premultiplied_alpha = premultipliedAlphaValue.asBool();
966
- }
967
-
968
- auto preserveDrawingBufferValue = config.getProperty(runtime,
969
- "preserveDrawingBuffer");
970
- if (preserveDrawingBufferValue.isBool()) {
971
- preserve_drawing_buffer = preserveDrawingBufferValue.asBool();
972
- }
973
-
974
- auto stencilValue = config.getProperty(runtime, "stencil");
975
- if (stencilValue.isBool()) {
976
- stencil = stencilValue.asBool();
977
- }
978
-
979
- auto desynchronizedValue = config.getProperty(runtime, "desynchronized");
980
- if (desynchronizedValue.isBool()) {
981
- desynchronized = desynchronizedValue.asBool();
982
- }
983
-
984
- auto xrCompatibleValue = config.getProperty(
985
- runtime,
986
- "xrCompatible");
987
- if (xrCompatibleValue.isBool()) {
988
- xr_compatible = xrCompatibleValue.asBool();
989
- }
990
-
991
- if (version !=
992
- "v2") {
993
- return jsi::Value::undefined();
994
- } else {
995
- if (count == 6) {
996
- auto context = getPointerValue(runtime, arguments[1]);
997
- // auto density = arguments[2].asNumber();
998
- // auto fontColor = arguments[3].asNumber();
999
- // auto ppi = arguments[4].asNumber();
1000
- // auto direction = arguments[5].asNumber();
1001
- auto ctx = canvas_native_webgl_create(
1002
- context,
1003
- rust::Str(
1004
- version.c_str()),
1005
- alpha,
1006
- antialias,
1007
- depth,
1008
- fail_if_major_performance_caveat,
1009
- rust::Str(
1010
- power_preference.c_str()),
1011
- premultiplied_alpha,
1012
- preserve_drawing_buffer,
1013
- stencil,
1014
- desynchronized,
1015
- xr_compatible
1016
- );
1017
-
1018
- auto renderingContext = std::make_shared<WebGL2RenderingContext>(
1019
- std::move(ctx), WebGLRenderingVersion::V2);
1020
-
1021
- return jsi::Object::createFromHostObject(
1022
- runtime, renderingContext);
1023
-
1024
- } else if (count ==
1025
- 7) {
1026
- auto width = arguments[1].asNumber();
1027
- auto height = arguments[2].asNumber();
1028
- // auto density = arguments[3].asNumber();
1029
- // auto fontColor = arguments[4].asNumber();
1030
- // auto ppi = arguments[5].asNumber();
1031
- // auto direction = arguments[6].asNumber();
1032
- auto ctx = canvas_native_webgl_create_no_window(
1033
- (int32_t) width,
1034
- (int32_t) height,
1035
- rust::Str(
1036
- version.c_str()),
1037
- alpha,
1038
- antialias,
1039
- depth,
1040
- fail_if_major_performance_caveat,
1041
- rust::Str(
1042
- power_preference.c_str()),
1043
- premultiplied_alpha,
1044
- preserve_drawing_buffer,
1045
- stencil,
1046
- desynchronized,
1047
- xr_compatible,
1048
- false
1049
- );
1050
- auto renderingContext = std::make_shared<WebGL2RenderingContext>(
1051
- std::move(
1052
- ctx), WebGLRenderingVersion::V2);
1053
-
1054
- return jsi::Object::createFromHostObject(
1055
- runtime,
1056
- renderingContext);
1057
-
1058
- } else {
1059
- auto width = (int32_t) arguments[1].asNumber();
1060
- auto height = (int32_t) arguments[2].asNumber();
1061
- auto ctx = canvas_native_webgl_create_no_window(
1062
- width,
1063
- height,
1064
- rust::Str(
1065
- version.c_str()),
1066
- alpha,
1067
- antialias,
1068
- depth,
1069
- fail_if_major_performance_caveat,
1070
- rust::Str(
1071
- power_preference.c_str()),
1072
- premultiplied_alpha,
1073
- preserve_drawing_buffer,
1074
- stencil,
1075
- desynchronized,
1076
- xr_compatible,
1077
- false
1078
- );
1079
-
1080
- auto renderingContext = std::make_shared<WebGL2RenderingContext>(
1081
- std::move(
1082
- ctx), WebGLRenderingVersion::V2);
1083
-
1084
- return jsi::Object::createFromHostObject(
1085
- runtime,
1086
- renderingContext);
1087
- }
1088
- }
1089
- }
1090
-
1091
- return jsi::Value::undefined();
1092
- }
1093
-
1094
- );
1095
-
1096
- auto global = jsiRuntime.global();
1097
-
1098
- if (!global.
1099
- hasProperty(jsiRuntime,
1100
- "CanvasJSIModule")) {
1101
- global.
1102
- setProperty(jsiRuntime,
1103
- "CanvasJSIModule", canvas_module);
1104
- }
1105
- }