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

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 -24
  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 +2391 -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 +6457 -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 +4380 -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
@@ -0,0 +1,2391 @@
1
+ //
2
+ // Created by Osei Fortune on 22/03/2022.
3
+ //
4
+
5
+ #include "CanvasRenderingContext2DImpl.h"
6
+ #include "Caches.h"
7
+ #include "OneByteStringResource.h"
8
+
9
+ CanvasRenderingContext2DImpl::CanvasRenderingContext2DImpl(
10
+ CanvasRenderingContext2D* context) : context_(context) {
11
+
12
+ auto ctx_ptr = reinterpret_cast<intptr_t>(reinterpret_cast<intptr_t *>(this));
13
+ auto raf_callback = new OnRafCallback(ctx_ptr, 0);
14
+ auto raf_callback_ptr = reinterpret_cast<intptr_t>(reinterpret_cast<intptr_t *>(raf_callback));
15
+ auto raf = canvas_native_raf_create(raf_callback_ptr, OnRafCallbackOnFrame);
16
+
17
+ this->SetRaf(std::make_shared<RafImpl>(raf_callback, raf_callback_ptr, raf));
18
+
19
+ auto _raf = this->GetRaf();
20
+
21
+ if (_raf != nullptr) {
22
+ canvas_native_raf_start(_raf->GetRaf());
23
+ }
24
+
25
+ }
26
+
27
+
28
+ void CanvasRenderingContext2DImpl::Init(v8::Local<v8::Object> canvasModule, v8::Isolate *isolate) {
29
+ v8::Locker locker(isolate);
30
+ v8::Isolate::Scope isolate_scope(isolate);
31
+ v8::HandleScope handle_scope(isolate);
32
+
33
+ auto ctor = GetCtor(isolate);
34
+ auto context = isolate->GetCurrentContext();
35
+ auto func = ctor->GetFunction(context).ToLocalChecked();
36
+
37
+ canvasModule->Set(context, ConvertToV8String(isolate, "CanvasRenderingContext2D"), func);
38
+ }
39
+
40
+ CanvasRenderingContext2DImpl *
41
+ CanvasRenderingContext2DImpl::GetPointer(const v8::Local<v8::Object> &object) {
42
+ auto ptr = object->GetInternalField(0).As<v8::External>()->Value();
43
+ if (ptr == nullptr) {
44
+ return nullptr;
45
+ }
46
+ return static_cast<CanvasRenderingContext2DImpl *>(ptr);
47
+ }
48
+
49
+ v8::Local<v8::FunctionTemplate> CanvasRenderingContext2DImpl::GetCtor(v8::Isolate *isolate) {
50
+ auto cache = Caches::Get(isolate);
51
+ auto ctor = cache->CanvasRenderingContext2DTmpl.get();
52
+ if (ctor != nullptr) {
53
+ return ctor->Get(isolate);
54
+ }
55
+
56
+ v8::Local<v8::FunctionTemplate> ctorTmpl = v8::FunctionTemplate::New(isolate);
57
+ ctorTmpl->InstanceTemplate()->SetInternalFieldCount(1);
58
+ ctorTmpl->SetClassName(ConvertToV8String(isolate, "CanvasRenderingContext2D"));
59
+
60
+ auto tmpl = ctorTmpl->InstanceTemplate();
61
+ tmpl->SetInternalFieldCount(1);
62
+
63
+ tmpl->Set(ConvertToV8String(isolate, "drawPoint"),
64
+ v8::FunctionTemplate::New(isolate, &DrawPoint));
65
+ tmpl->Set(ConvertToV8String(isolate, "drawPoints"),
66
+ v8::FunctionTemplate::New(isolate, &DrawPoints));
67
+ tmpl->Set(ConvertToV8String(isolate, "drawPaint"),
68
+ v8::FunctionTemplate::New(isolate, &DrawPaint));
69
+
70
+
71
+ tmpl->Set(ConvertToV8String(isolate, "__makeDirty"),
72
+ v8::FunctionTemplate::New(isolate, __MakeDirty));
73
+ tmpl->Set(ConvertToV8String(isolate, "__getPointer"),
74
+ v8::FunctionTemplate::New(isolate, __GetPointer));
75
+ tmpl->Set(ConvertToV8String(isolate, "__resize"), v8::FunctionTemplate::New(isolate, __Resize));
76
+
77
+ tmpl->SetAccessor(ConvertToV8String(isolate, "filter"), GetFilter, SetFilter);
78
+ tmpl->SetAccessor(ConvertToV8String(isolate, "font"), GetFont, SetFont);
79
+ tmpl->SetAccessor(ConvertToV8String(isolate, "globalAlpha"), GetGlobalAlpha, SetGlobalAlpha);
80
+ tmpl->SetAccessor(ConvertToV8String(isolate, "imageSmoothingEnabled"), GetImageSmoothingEnabled,
81
+ SetImageSmoothingEnabled);
82
+ tmpl->SetAccessor(ConvertToV8String(isolate, "imageSmoothingQuality"), GetImageSmoothingQuality,
83
+ SetImageSmoothingQuality);
84
+ tmpl->SetAccessor(ConvertToV8String(isolate, "lineDashOffset"), GetLineDashOffset,
85
+ SetLineDashOffset);
86
+ tmpl->SetAccessor(ConvertToV8String(isolate, "lineJoin"), GetLineJoin, SetLineJoin);
87
+ tmpl->SetAccessor(ConvertToV8String(isolate, "lineCap"), GetLineCap, SetLineCap);
88
+ tmpl->SetAccessor(ConvertToV8String(isolate, "miterLimit"), GetMiterLimit, SetMiterLimit);
89
+ tmpl->SetAccessor(ConvertToV8String(isolate, "shadowColor"), GetShadowColor, SetShadowColor);
90
+ tmpl->SetAccessor(ConvertToV8String(isolate, "shadowBlur"), GetShadowBlur, SetShadowBlur);
91
+ tmpl->SetAccessor(ConvertToV8String(isolate, "shadowOffsetX"), GetShadowOffsetX,
92
+ SetShadowOffsetX);
93
+ tmpl->SetAccessor(ConvertToV8String(isolate, "shadowOffsetY"), GetShadowOffsetY,
94
+ SetShadowOffsetY);
95
+ tmpl->SetAccessor(ConvertToV8String(isolate, "textAlign"), GetTextAlign, SetTextAlign);
96
+ tmpl->SetAccessor(ConvertToV8String(isolate, "globalCompositeOperation"),
97
+ GetGlobalCompositeOperation, SetGlobalCompositeOperation);
98
+ tmpl->SetAccessor(ConvertToV8String(isolate, "fillStyle"), GetFillStyle, SetFillStyle);
99
+ tmpl->SetAccessor(ConvertToV8String(isolate, "strokeStyle"), GetStrokeStyle, SetStrokeStyle);
100
+ tmpl->SetAccessor(ConvertToV8String(isolate, "lineWidth"), GetLineWidth, SetLineWidth);
101
+ tmpl->SetAccessor(ConvertToV8String(isolate, "lineDash"), GetLineDash, SetLineDash);
102
+
103
+
104
+ tmpl->Set(ConvertToV8String(isolate, "addHitRegion"),
105
+ v8::FunctionTemplate::New(isolate, &AddHitRegion));
106
+ tmpl->Set(ConvertToV8String(isolate, "arc"), v8::FunctionTemplate::New(isolate, &Arc));
107
+ tmpl->Set(ConvertToV8String(isolate, "arcTo"), v8::FunctionTemplate::New(isolate, &ArcTo));
108
+ tmpl->Set(ConvertToV8String(isolate, "beginPath"),
109
+ v8::FunctionTemplate::New(isolate, &BeginPath));
110
+ tmpl->Set(ConvertToV8String(isolate, "bezierCurveTo"),
111
+ v8::FunctionTemplate::New(isolate, &BezierCurveTo));
112
+ tmpl->Set(ConvertToV8String(isolate, "clearHitRegions"),
113
+ v8::FunctionTemplate::New(isolate, &ClearHitRegions));
114
+ tmpl->Set(ConvertToV8String(isolate, "clearRect"),
115
+ v8::FunctionTemplate::New(isolate, &ClearRect));
116
+ tmpl->Set(ConvertToV8String(isolate, "clip"), v8::FunctionTemplate::New(isolate, &Clip));
117
+ tmpl->Set(ConvertToV8String(isolate, "closePath"),
118
+ v8::FunctionTemplate::New(isolate, &ClosePath));
119
+ tmpl->Set(ConvertToV8String(isolate, "createImageData"),
120
+ v8::FunctionTemplate::New(isolate, &CreateImageData));
121
+ tmpl->Set(ConvertToV8String(isolate, "createPattern"),
122
+ v8::FunctionTemplate::New(isolate, &CreatePattern));
123
+ tmpl->Set(ConvertToV8String(isolate, "createLinearGradient"),
124
+ v8::FunctionTemplate::New(isolate, &CreateLinearGradient));
125
+ tmpl->Set(ConvertToV8String(isolate, "__createPatternWithNative"),
126
+ v8::FunctionTemplate::New(isolate, &__CreatePatternWithNative));
127
+ tmpl->Set(ConvertToV8String(isolate, "createRadialGradient"),
128
+ v8::FunctionTemplate::New(isolate, &CreateRadialGradient));
129
+ tmpl->Set(ConvertToV8String(isolate, "drawFocusIfNeeded"),
130
+ v8::FunctionTemplate::New(isolate, &DrawFocusIfNeeded));
131
+ tmpl->Set(ConvertToV8String(isolate, "drawImage"),
132
+ v8::FunctionTemplate::New(isolate, &DrawImage));
133
+ tmpl->Set(ConvertToV8String(isolate, "ellipse"), v8::FunctionTemplate::New(isolate, &Ellipse));
134
+ tmpl->Set(ConvertToV8String(isolate, "fill"), v8::FunctionTemplate::New(isolate, &Fill));
135
+ tmpl->Set(ConvertToV8String(isolate, "fillRect"),
136
+ v8::FunctionTemplate::New(isolate, &FillRect));
137
+ tmpl->Set(ConvertToV8String(isolate, "fillText"),
138
+ v8::FunctionTemplate::New(isolate, &FillText));
139
+ tmpl->Set(ConvertToV8String(isolate, "getImageData"),
140
+ v8::FunctionTemplate::New(isolate, &GetImageData));
141
+ tmpl->Set(ConvertToV8String(isolate, "getLineDash"),
142
+ v8::FunctionTemplate::New(isolate, &GetLineDash));
143
+ tmpl->Set(ConvertToV8String(isolate, "isPointInPath"),
144
+ v8::FunctionTemplate::New(isolate, &IsPointInPath));
145
+ tmpl->Set(ConvertToV8String(isolate, "isPointInStroke"),
146
+ v8::FunctionTemplate::New(isolate, &IsPointInStroke));
147
+ tmpl->Set(ConvertToV8String(isolate, "lineTo"), v8::FunctionTemplate::New(isolate, &LineTo));
148
+ tmpl->Set(ConvertToV8String(isolate, "measureText"),
149
+ v8::FunctionTemplate::New(isolate, &MeasureText));
150
+ tmpl->Set(ConvertToV8String(isolate, "moveTo"), v8::FunctionTemplate::New(isolate, &MoveTo));
151
+ tmpl->Set(ConvertToV8String(isolate, "putImageData"),
152
+ v8::FunctionTemplate::New(isolate, &PutImageData));
153
+ tmpl->Set(ConvertToV8String(isolate, "quadraticCurveTo"),
154
+ v8::FunctionTemplate::New(isolate, &QuadraticCurveTo));
155
+ tmpl->Set(ConvertToV8String(isolate, "roundRect"),
156
+ v8::FunctionTemplate::New(isolate, &RoundRect));
157
+ tmpl->Set(ConvertToV8String(isolate, "rect"), v8::FunctionTemplate::New(isolate, &Rect));
158
+ tmpl->Set(ConvertToV8String(isolate, "removeHitRegion"),
159
+ v8::FunctionTemplate::New(isolate, &RemoveHitRegion));
160
+ tmpl->Set(ConvertToV8String(isolate, "resetTransform"),
161
+ v8::FunctionTemplate::New(isolate, &ResetTransform));
162
+ tmpl->Set(ConvertToV8String(isolate, "restore"), v8::FunctionTemplate::New(isolate, &Restore));
163
+ tmpl->Set(ConvertToV8String(isolate, "rotate"), v8::FunctionTemplate::New(isolate, &Rotate));
164
+ tmpl->Set(ConvertToV8String(isolate, "save"), v8::FunctionTemplate::New(isolate, &Save));
165
+ tmpl->Set(ConvertToV8String(isolate, "scale"), v8::FunctionTemplate::New(isolate, &Scale));
166
+ tmpl->Set(ConvertToV8String(isolate, "scrollPathIntoView"),
167
+ v8::FunctionTemplate::New(isolate, &ScrollPathIntoView));
168
+ tmpl->Set(ConvertToV8String(isolate, "setLineDash"),
169
+ v8::FunctionTemplate::New(isolate, &SetLineDash));
170
+ tmpl->Set(ConvertToV8String(isolate, "setTransform"),
171
+ v8::FunctionTemplate::New(isolate, &SetTransform));
172
+ tmpl->Set(ConvertToV8String(isolate, "stroke"), v8::FunctionTemplate::New(isolate, &Stroke));
173
+ tmpl->Set(ConvertToV8String(isolate, "strokeRect"),
174
+ v8::FunctionTemplate::New(isolate, &StrokeRect));
175
+ tmpl->Set(ConvertToV8String(isolate, "strokeText"),
176
+ v8::FunctionTemplate::New(isolate, &StrokeText));
177
+ tmpl->Set(ConvertToV8String(isolate, "transform"),
178
+ v8::FunctionTemplate::New(isolate, &Transform));
179
+ tmpl->Set(ConvertToV8String(isolate, "translate"),
180
+ v8::FunctionTemplate::New(isolate, &Translate));
181
+ tmpl->Set(ConvertToV8String(isolate, "__toDataURL"),
182
+ v8::FunctionTemplate::New(isolate, &__ToDataURL));
183
+
184
+ cache->CanvasRenderingContext2DTmpl =
185
+ std::make_unique<v8::Persistent<v8::FunctionTemplate>>(isolate, ctorTmpl);
186
+ return ctorTmpl;
187
+ }
188
+
189
+ void CanvasRenderingContext2DImpl::SetRaf(std::shared_ptr<RafImpl> raf) {
190
+ this->raf_ = std::move(raf);
191
+ }
192
+
193
+ RafImpl *CanvasRenderingContext2DImpl::GetRaf() {
194
+ return this->raf_.get();
195
+ }
196
+
197
+ /* Non Standard 2D */
198
+
199
+ void CanvasRenderingContext2DImpl::DrawPoint(const v8::FunctionCallbackInfo<v8::Value> &args) {
200
+ CanvasRenderingContext2DImpl *ptr = GetPointer(args.This());
201
+ if (ptr == nullptr) {
202
+ return;
203
+ }
204
+
205
+ auto isolate = args.GetIsolate();
206
+ auto context = isolate->GetCurrentContext();
207
+
208
+ auto x = (float) args[0]->NumberValue(context).ToChecked();
209
+ auto y = (float) args[1]->NumberValue(context).ToChecked();
210
+
211
+ canvas_native_context_draw_point(
212
+ ptr->GetContext(), x, y);
213
+ ptr->UpdateInvalidateState();
214
+ }
215
+
216
+ void CanvasRenderingContext2DImpl::DrawPoints(const v8::FunctionCallbackInfo<v8::Value> &args) {
217
+ CanvasRenderingContext2DImpl *ptr = GetPointer(args.This());
218
+ if (ptr == nullptr) {
219
+ return;
220
+ }
221
+
222
+ auto isolate = args.GetIsolate();
223
+ auto context = isolate->GetCurrentContext();
224
+
225
+
226
+ auto mode = ConvertFromV8String(isolate, args[0]);
227
+ auto points = args[1].As<v8::Array>();
228
+ auto size = points->Length();
229
+
230
+
231
+ if ((size % 2) == 0) {
232
+ int32_t pointMode = -1;
233
+ if (mode == "points") {
234
+ pointMode = 0;
235
+ } else if (mode == "lines") {
236
+ pointMode = 1;
237
+ } else if (mode == "polygon") {
238
+ pointMode = 2;
239
+ }
240
+ if (pointMode == -1) {
241
+ return;
242
+ }
243
+ std::vector<float> store;
244
+ store.reserve(size);
245
+ int next = 0;
246
+ for (int i = 0; i < size; i++) {
247
+
248
+ auto object = points->Get(
249
+ context, i).ToLocalChecked().As<v8::Object>();
250
+
251
+ auto x = object->Get(context,
252
+ ConvertToV8String(isolate, "x")).ToLocalChecked()->NumberValue(
253
+ context).ToChecked();
254
+ auto y = object->Get(context,
255
+ ConvertToV8String(isolate, "y")).ToLocalChecked()->NumberValue(
256
+ context).ToChecked();
257
+ store[next] = (float) x;
258
+ store[next + 1] = (float) y;
259
+
260
+ next = i + 2;
261
+ }
262
+
263
+ canvas_native_context_draw_points(
264
+ ptr->GetContext(), pointMode,
265
+ store.data(),store.size());
266
+
267
+
268
+ ptr->UpdateInvalidateState();
269
+ }
270
+ }
271
+
272
+ void CanvasRenderingContext2DImpl::DrawPaint(const v8::FunctionCallbackInfo<v8::Value> &args) {
273
+ CanvasRenderingContext2DImpl *ptr = GetPointer(args.This());
274
+ if (ptr == nullptr) {
275
+ return;
276
+ }
277
+
278
+ auto isolate = args.GetIsolate();
279
+
280
+
281
+ auto color = ConvertFromV8String(isolate, args[0]);
282
+ canvas_native_context_draw_paint(
283
+ ptr->GetContext(), color.c_str());
284
+ ptr->UpdateInvalidateState();
285
+ }
286
+
287
+ /* Non Standard 2D */
288
+
289
+
290
+ void CanvasRenderingContext2DImpl::__MakeDirty(const v8::FunctionCallbackInfo<v8::Value> &args) {
291
+ CanvasRenderingContext2DImpl *ptr = GetPointer(args.This());
292
+ if (ptr == nullptr) {
293
+ return;
294
+ }
295
+ ptr->UpdateInvalidateState();
296
+ }
297
+
298
+ void CanvasRenderingContext2DImpl::__GetPointer(const v8::FunctionCallbackInfo<v8::Value> &args) {
299
+ CanvasRenderingContext2DImpl *ptr = GetPointer(args.This());
300
+ if (ptr == nullptr) {
301
+ args.GetReturnValue().SetEmptyString();
302
+ return;
303
+ }
304
+
305
+ auto isolate = args.GetIsolate();
306
+
307
+ auto pointer = (intptr_t *) ptr->GetContext();
308
+ auto ret = std::to_string((intptr_t) pointer);
309
+ args.GetReturnValue().Set(ConvertToV8String(isolate, ret));
310
+ }
311
+
312
+ void CanvasRenderingContext2DImpl::__Resize(const v8::FunctionCallbackInfo<v8::Value> &args) {
313
+ CanvasRenderingContext2DImpl *ptr = GetPointer(args.This());
314
+ if (ptr == nullptr) {
315
+ return;
316
+ }
317
+
318
+ auto isolate = args.GetIsolate();
319
+ auto context = isolate->GetCurrentContext();
320
+
321
+
322
+ auto width = args[0]->NumberValue(context).ToChecked();
323
+ auto height = args[1]->NumberValue(context).ToChecked();
324
+ canvas_native_context_resize(
325
+ ptr->GetContext(),
326
+ static_cast<float>(width),
327
+ static_cast<float>(height));
328
+ }
329
+
330
+
331
+ void CanvasRenderingContext2DImpl::GetFilter(v8::Local<v8::String> property,
332
+ const v8::PropertyCallbackInfo<v8::Value> &info) {
333
+ CanvasRenderingContext2DImpl *ptr = GetPointer(info.This());
334
+ if (ptr == nullptr) {
335
+ info.GetReturnValue().SetEmptyString();
336
+ return;
337
+ }
338
+ auto isolate = info.GetIsolate();
339
+ auto filter = canvas_native_context_get_filter(ptr->GetContext());
340
+ info.GetReturnValue().Set(ConvertToV8String(isolate, filter));
341
+ canvas_native_string_destroy((char*) filter);
342
+ }
343
+
344
+ void CanvasRenderingContext2DImpl::SetFilter(v8::Local<v8::String> property,
345
+ v8::Local<v8::Value> value,
346
+ const v8::PropertyCallbackInfo<void> &info) {
347
+ CanvasRenderingContext2DImpl *ptr = GetPointer(info.This());
348
+ if (ptr == nullptr) {
349
+ return;
350
+ }
351
+ auto isolate = info.GetIsolate();
352
+ auto val = ConvertFromV8String(isolate, value);
353
+ canvas_native_context_set_filter(ptr->GetContext(), val.c_str());
354
+ }
355
+
356
+ void CanvasRenderingContext2DImpl::GetFont(v8::Local<v8::String> property,
357
+ const v8::PropertyCallbackInfo<v8::Value> &info) {
358
+ CanvasRenderingContext2DImpl *ptr = GetPointer(info.This());
359
+ if (ptr == nullptr) {
360
+ info.GetReturnValue().SetEmptyString();
361
+ return;
362
+ }
363
+ auto isolate = info.GetIsolate();
364
+ auto font = canvas_native_context_get_font(ptr->GetContext());
365
+ info.GetReturnValue().Set(ConvertToV8String(isolate, font));
366
+
367
+ canvas_native_string_destroy((char*) font);
368
+ }
369
+
370
+ void CanvasRenderingContext2DImpl::SetFont(v8::Local<v8::String> property,
371
+ v8::Local<v8::Value> value,
372
+ const v8::PropertyCallbackInfo<void> &info) {
373
+ CanvasRenderingContext2DImpl *ptr = GetPointer(info.This());
374
+ if (ptr == nullptr) {
375
+ return;
376
+ }
377
+ auto isolate = info.GetIsolate();
378
+ auto val = ConvertFromV8String(isolate, value);
379
+ canvas_native_context_set_font(ptr->GetContext(), val.c_str());
380
+ }
381
+
382
+ void CanvasRenderingContext2DImpl::GetGlobalAlpha(v8::Local<v8::String> property,
383
+ const v8::PropertyCallbackInfo<v8::Value> &info) {
384
+ CanvasRenderingContext2DImpl *ptr = GetPointer(info.This());
385
+ if (ptr == nullptr) {
386
+ info.GetReturnValue().Set(1);
387
+ return;
388
+ }
389
+ auto alpha = canvas_native_context_get_global_alpha(ptr->GetContext());
390
+ info.GetReturnValue().Set((double) alpha);
391
+ }
392
+
393
+ void CanvasRenderingContext2DImpl::SetGlobalAlpha(v8::Local<v8::String> property,
394
+ v8::Local<v8::Value> value,
395
+ const v8::PropertyCallbackInfo<void> &info) {
396
+ CanvasRenderingContext2DImpl *ptr = GetPointer(info.This());
397
+ if (ptr == nullptr) {
398
+ return;
399
+ }
400
+ auto isolate = info.GetIsolate();
401
+ auto context = isolate->GetCurrentContext();
402
+ canvas_native_context_set_global_alpha(ptr->GetContext(),
403
+ (float) value->NumberValue(context).ToChecked());
404
+ }
405
+
406
+ void CanvasRenderingContext2DImpl::GetImageSmoothingEnabled(v8::Local<v8::String> property,
407
+ const v8::PropertyCallbackInfo<v8::Value> &info) {
408
+ CanvasRenderingContext2DImpl *ptr = GetPointer(info.This());
409
+ if (ptr == nullptr) {
410
+ info.GetReturnValue().Set(false);
411
+ return;
412
+ }
413
+ auto enabled = canvas_native_context_get_image_smoothing_enabled(ptr->GetContext());
414
+ info.GetReturnValue().Set(enabled);
415
+ }
416
+
417
+ void CanvasRenderingContext2DImpl::SetImageSmoothingEnabled(v8::Local<v8::String> property,
418
+ v8::Local<v8::Value> value,
419
+ const v8::PropertyCallbackInfo<void> &info) {
420
+ CanvasRenderingContext2DImpl *ptr = GetPointer(info.This());
421
+ if (ptr == nullptr) {
422
+ return;
423
+ }
424
+ auto isolate = info.GetIsolate();
425
+ canvas_native_context_set_image_smoothing_enabled(ptr->GetContext(),
426
+ value->BooleanValue(isolate));
427
+ }
428
+
429
+ void CanvasRenderingContext2DImpl::GetImageSmoothingQuality(v8::Local<v8::String> property,
430
+ const v8::PropertyCallbackInfo<v8::Value> &info) {
431
+ CanvasRenderingContext2DImpl *ptr = GetPointer(info.This());
432
+ if (ptr == nullptr) {
433
+ info.GetReturnValue().SetEmptyString();
434
+ return;
435
+ }
436
+ auto isolate = info.GetIsolate();
437
+ auto quality = canvas_native_context_get_image_smoothing_quality(ptr->GetContext());
438
+ info.GetReturnValue().Set(
439
+ ConvertToV8String(isolate, quality));
440
+
441
+ canvas_native_string_destroy((char*)quality);
442
+
443
+ }
444
+
445
+ void CanvasRenderingContext2DImpl::SetImageSmoothingQuality(v8::Local<v8::String> property,
446
+ v8::Local<v8::Value> value,
447
+ const v8::PropertyCallbackInfo<void> &info) {
448
+ CanvasRenderingContext2DImpl *ptr = GetPointer(info.This());
449
+ if (ptr == nullptr) {
450
+ return;
451
+ }
452
+ auto isolate = info.GetIsolate();
453
+ auto quality = ConvertFromV8String(isolate, value);
454
+ canvas_native_context_set_image_smoothing_quality(ptr->GetContext(), quality.c_str());
455
+ }
456
+
457
+ void CanvasRenderingContext2DImpl::GetLineDashOffset(v8::Local<v8::String> property,
458
+ const v8::PropertyCallbackInfo<v8::Value> &info) {
459
+ CanvasRenderingContext2DImpl *ptr = GetPointer(info.This());
460
+ if (ptr == nullptr) {
461
+ info.GetReturnValue().Set(0);
462
+ return;
463
+ }
464
+ auto offset = canvas_native_context_get_line_dash_offset(ptr->GetContext());
465
+ info.GetReturnValue().Set((double) offset);
466
+ }
467
+
468
+ void CanvasRenderingContext2DImpl::SetLineDashOffset(v8::Local<v8::String> property,
469
+ v8::Local<v8::Value> value,
470
+ const v8::PropertyCallbackInfo<void> &info) {
471
+ CanvasRenderingContext2DImpl *ptr = GetPointer(info.This());
472
+ if (ptr == nullptr) {
473
+ return;
474
+ }
475
+ auto isolate = info.GetIsolate();
476
+ auto context = isolate->GetCurrentContext();
477
+ canvas_native_context_set_line_dash_offset(ptr->GetContext(),
478
+ (float) value->NumberValue(context).ToChecked());
479
+ }
480
+
481
+
482
+ void CanvasRenderingContext2DImpl::GetLineJoin(v8::Local<v8::String> property,
483
+ const v8::PropertyCallbackInfo<v8::Value> &info) {
484
+ CanvasRenderingContext2DImpl *ptr = GetPointer(info.This());
485
+ if (ptr == nullptr) {
486
+ info.GetReturnValue().Set(0);
487
+ return;
488
+ }
489
+ auto isolate = info.GetIsolate();
490
+ auto join = canvas_native_context_get_line_join(ptr->GetContext());
491
+ info.GetReturnValue().Set(ConvertToV8String(isolate, join));
492
+
493
+ canvas_native_string_destroy((char*)join);
494
+ }
495
+
496
+ void CanvasRenderingContext2DImpl::SetLineJoin(v8::Local<v8::String> property,
497
+ v8::Local<v8::Value> value,
498
+ const v8::PropertyCallbackInfo<void> &info) {
499
+ CanvasRenderingContext2DImpl *ptr = GetPointer(info.This());
500
+ if (ptr == nullptr) {
501
+ return;
502
+ }
503
+ auto isolate = info.GetIsolate();
504
+ auto join = ConvertFromV8String(isolate, value);
505
+ canvas_native_context_set_line_join(ptr->GetContext(), join.c_str());
506
+ }
507
+
508
+ void CanvasRenderingContext2DImpl::GetLineCap(v8::Local<v8::String> property,
509
+ const v8::PropertyCallbackInfo<v8::Value> &info) {
510
+ CanvasRenderingContext2DImpl *ptr = GetPointer(info.This());
511
+ if (ptr == nullptr) {
512
+ info.GetReturnValue().Set(0);
513
+ return;
514
+ }
515
+ auto isolate = info.GetIsolate();
516
+ auto cap = canvas_native_context_get_line_cap(ptr->GetContext());
517
+ info.GetReturnValue().Set(ConvertToV8String(isolate, cap));
518
+
519
+ canvas_native_string_destroy((char*)cap);
520
+ }
521
+
522
+ void CanvasRenderingContext2DImpl::SetLineCap(v8::Local<v8::String> property,
523
+ v8::Local<v8::Value> value,
524
+ const v8::PropertyCallbackInfo<void> &info) {
525
+ CanvasRenderingContext2DImpl *ptr = GetPointer(info.This());
526
+ if (ptr == nullptr) {
527
+ return;
528
+ }
529
+ auto isolate = info.GetIsolate();
530
+ auto cap = ConvertFromV8String(isolate, value);
531
+ canvas_native_context_set_line_cap(ptr->GetContext(), cap.c_str());
532
+ }
533
+
534
+
535
+ void CanvasRenderingContext2DImpl::GetMiterLimit(v8::Local<v8::String> property,
536
+ const v8::PropertyCallbackInfo<v8::Value> &info) {
537
+ CanvasRenderingContext2DImpl *ptr = GetPointer(info.This());
538
+ if (ptr == nullptr) {
539
+ info.GetReturnValue().Set(0);
540
+ return;
541
+ }
542
+ auto limit = canvas_native_context_get_miter_limit(ptr->GetContext());
543
+ info.GetReturnValue().Set((double) limit);
544
+ }
545
+
546
+ void CanvasRenderingContext2DImpl::SetMiterLimit(v8::Local<v8::String> property,
547
+ v8::Local<v8::Value> value,
548
+ const v8::PropertyCallbackInfo<void> &info) {
549
+ CanvasRenderingContext2DImpl *ptr = GetPointer(info.This());
550
+ if (ptr == nullptr) {
551
+ return;
552
+ }
553
+ auto isolate = info.GetIsolate();
554
+ auto context = isolate->GetCurrentContext();
555
+ canvas_native_context_set_miter_limit(ptr->GetContext(),
556
+ (float) value->NumberValue(context).ToChecked());
557
+ }
558
+
559
+
560
+ void CanvasRenderingContext2DImpl::GetShadowColor(v8::Local<v8::String> property,
561
+ const v8::PropertyCallbackInfo<v8::Value> &info) {
562
+ CanvasRenderingContext2DImpl *ptr = GetPointer(info.This());
563
+ if (ptr == nullptr) {
564
+ info.GetReturnValue().Set(0);
565
+ return;
566
+ }
567
+ auto isolate = info.GetIsolate();
568
+ auto color = canvas_native_context_get_shadow_color(ptr->GetContext());
569
+ info.GetReturnValue().Set(ConvertToV8String(isolate, color));
570
+ canvas_native_string_destroy((char*) color);
571
+ }
572
+
573
+ void CanvasRenderingContext2DImpl::SetShadowColor(v8::Local<v8::String> property,
574
+ v8::Local<v8::Value> value,
575
+ const v8::PropertyCallbackInfo<void> &info) {
576
+ CanvasRenderingContext2DImpl *ptr = GetPointer(info.This());
577
+ if (ptr == nullptr) {
578
+ return;
579
+ }
580
+ auto isolate = info.GetIsolate();
581
+ auto color = ConvertFromV8String(isolate, value);
582
+ canvas_native_context_set_shadow_color(ptr->GetContext(), color.c_str());
583
+ }
584
+
585
+
586
+ void CanvasRenderingContext2DImpl::GetShadowBlur(v8::Local<v8::String> property,
587
+ const v8::PropertyCallbackInfo<v8::Value> &info) {
588
+ CanvasRenderingContext2DImpl *ptr = GetPointer(info.This());
589
+ if (ptr == nullptr) {
590
+ info.GetReturnValue().Set(0);
591
+ return;
592
+ }
593
+ auto blur = canvas_native_context_get_shadow_blur(ptr->GetContext());
594
+ info.GetReturnValue().Set((double) blur);
595
+ }
596
+
597
+ void CanvasRenderingContext2DImpl::SetShadowBlur(v8::Local<v8::String> property,
598
+ v8::Local<v8::Value> value,
599
+ const v8::PropertyCallbackInfo<void> &info) {
600
+ CanvasRenderingContext2DImpl *ptr = GetPointer(info.This());
601
+ if (ptr == nullptr) {
602
+ return;
603
+ }
604
+ auto isolate = info.GetIsolate();
605
+ auto context = isolate->GetCurrentContext();
606
+ canvas_native_context_set_shadow_blur(ptr->GetContext(),
607
+ (float) value->NumberValue(context).ToChecked());
608
+ }
609
+
610
+ void CanvasRenderingContext2DImpl::GetShadowOffsetX(v8::Local<v8::String> property,
611
+ const v8::PropertyCallbackInfo<v8::Value> &info) {
612
+ CanvasRenderingContext2DImpl *ptr = GetPointer(info.This());
613
+ if (ptr == nullptr) {
614
+ info.GetReturnValue().Set(0);
615
+ return;
616
+ }
617
+ auto x = canvas_native_context_get_shadow_offset_x(ptr->GetContext());
618
+ info.GetReturnValue().Set((double) x);
619
+ }
620
+
621
+ void CanvasRenderingContext2DImpl::SetShadowOffsetX(v8::Local<v8::String> property,
622
+ v8::Local<v8::Value> value,
623
+ const v8::PropertyCallbackInfo<void> &info) {
624
+ CanvasRenderingContext2DImpl *ptr = GetPointer(info.This());
625
+ if (ptr == nullptr) {
626
+ return;
627
+ }
628
+ auto isolate = info.GetIsolate();
629
+ auto context = isolate->GetCurrentContext();
630
+ canvas_native_context_set_shadow_offset_x(ptr->GetContext(),
631
+ (float) value->NumberValue(context).ToChecked());
632
+ }
633
+
634
+
635
+ void CanvasRenderingContext2DImpl::GetShadowOffsetY(v8::Local<v8::String> property,
636
+ const v8::PropertyCallbackInfo<v8::Value> &info) {
637
+ CanvasRenderingContext2DImpl *ptr = GetPointer(info.This());
638
+ if (ptr == nullptr) {
639
+ info.GetReturnValue().Set(0);
640
+ return;
641
+ }
642
+ auto y = canvas_native_context_get_shadow_offset_y(ptr->GetContext());
643
+ info.GetReturnValue().Set((double) y);
644
+ }
645
+
646
+ void CanvasRenderingContext2DImpl::SetShadowOffsetY(v8::Local<v8::String> property,
647
+ v8::Local<v8::Value> value,
648
+ const v8::PropertyCallbackInfo<void> &info) {
649
+ CanvasRenderingContext2DImpl *ptr = GetPointer(info.This());
650
+ if (ptr == nullptr) {
651
+ return;
652
+ }
653
+ auto isolate = info.GetIsolate();
654
+ auto context = isolate->GetCurrentContext();
655
+ canvas_native_context_set_shadow_offset_y(ptr->GetContext(),
656
+ (float) value->NumberValue(context).ToChecked());
657
+ }
658
+
659
+
660
+ void CanvasRenderingContext2DImpl::GetTextAlign(v8::Local<v8::String> property,
661
+ const v8::PropertyCallbackInfo<v8::Value> &info) {
662
+ CanvasRenderingContext2DImpl *ptr = GetPointer(info.This());
663
+ if (ptr == nullptr) {
664
+ info.GetReturnValue().Set(0);
665
+ return;
666
+ }
667
+ auto isolate = info.GetIsolate();
668
+ auto alignment = canvas_native_context_get_text_align(ptr->GetContext());
669
+ info.GetReturnValue().Set(
670
+ ConvertToV8String(isolate, alignment));
671
+ canvas_native_string_destroy((char*) alignment);
672
+ }
673
+
674
+ void CanvasRenderingContext2DImpl::SetTextAlign(v8::Local<v8::String> property,
675
+ v8::Local<v8::Value> value,
676
+ const v8::PropertyCallbackInfo<void> &info) {
677
+ CanvasRenderingContext2DImpl *ptr = GetPointer(info.This());
678
+ if (ptr == nullptr) {
679
+ return;
680
+ }
681
+ auto isolate = info.GetIsolate();
682
+ auto alignment = ConvertFromV8String(isolate, value);
683
+ canvas_native_context_set_text_align(ptr->GetContext(), alignment.c_str());
684
+ }
685
+
686
+
687
+ void CanvasRenderingContext2DImpl::GetGlobalCompositeOperation(v8::Local<v8::String> property,
688
+ const v8::PropertyCallbackInfo<v8::Value> &info) {
689
+ CanvasRenderingContext2DImpl *ptr = GetPointer(info.This());
690
+ if (ptr == nullptr) {
691
+ info.GetReturnValue().Set(0);
692
+ return;
693
+ }
694
+ auto operation = canvas_native_context_get_global_composition(ptr->GetContext());
695
+ info.GetReturnValue().Set(
696
+ ConvertToV8String(info.GetIsolate(), operation));
697
+
698
+ canvas_native_string_destroy((char*) operation);
699
+ }
700
+
701
+ void CanvasRenderingContext2DImpl::SetGlobalCompositeOperation(v8::Local<v8::String> property,
702
+ v8::Local<v8::Value> value,
703
+ const v8::PropertyCallbackInfo<void> &info) {
704
+ CanvasRenderingContext2DImpl *ptr = GetPointer(info.This());
705
+ if (ptr == nullptr) {
706
+ return;
707
+ }
708
+ auto isolate = info.GetIsolate();
709
+ auto operation = ConvertFromV8String(isolate, value);
710
+ canvas_native_context_set_global_composition(ptr->GetContext(), operation.c_str());
711
+ }
712
+
713
+
714
+ void CanvasRenderingContext2DImpl::GetFillStyle(v8::Local<v8::String> property,
715
+ const v8::PropertyCallbackInfo<v8::Value> &info) {
716
+ CanvasRenderingContext2DImpl *ptr = GetPointer(info.This());
717
+ if (ptr == nullptr) {
718
+ info.GetReturnValue().Set(0);
719
+ return;
720
+ }
721
+ auto isolate = info.GetIsolate();
722
+
723
+ PaintStyleType type = canvas_native_context_get_current_fill_style_type(ptr->GetContext());
724
+
725
+ switch (type) {
726
+ case PaintStyleType::PaintStyleTypeColor: {
727
+ auto color = canvas_native_paint_style_get_current_fill_color_string(
728
+ ptr->GetContext());
729
+
730
+
731
+ auto value = new OneByteStringResource((char*)color);
732
+ auto ret = v8::String::NewExternalOneByte(isolate, value);
733
+ info.GetReturnValue().Set(ret.ToLocalChecked());
734
+
735
+ //info.GetReturnValue().Set(ConvertToV8String(isolate, color.c_str()));
736
+ break;
737
+ }
738
+ case PaintStyleType::PaintStyleTypeGradient: {
739
+ auto style = CanvasGradient::NewInstance(isolate, new CanvasGradient(
740
+ canvas_native_context_get_fill_style(ptr->GetContext())));
741
+
742
+ info.GetReturnValue().Set(style);
743
+
744
+ break;
745
+ }
746
+ case PaintStyleType::PaintStyleTypePattern: {
747
+ auto style = CanvasPattern::NewInstance(isolate, new CanvasPattern(
748
+ canvas_native_context_get_fill_style(ptr->GetContext())));
749
+
750
+ info.GetReturnValue().Set(style);
751
+ break;
752
+ }
753
+ case PaintStyleType::PaintStyleTypeNone: {
754
+ info.GetReturnValue().SetUndefined();
755
+ break;
756
+ }
757
+ }
758
+
759
+ }
760
+
761
+ void CanvasRenderingContext2DImpl::SetFillStyle(v8::Local<v8::String> property,
762
+ v8::Local<v8::Value> value,
763
+ const v8::PropertyCallbackInfo<void> &info) {
764
+ CanvasRenderingContext2DImpl *ptr = GetPointer(info.This());
765
+ if (ptr == nullptr) {
766
+ return;
767
+ }
768
+ auto isolate = info.GetIsolate();
769
+ auto context = isolate->GetCurrentContext();
770
+
771
+ if (value->IsString()) {
772
+ auto style = ConvertFromV8String(isolate, value);
773
+ canvas_native_paint_style_set_fill_color_with_c_string(ptr->GetContext(),
774
+ style.c_str());
775
+ } else if (value->IsObject()) {
776
+
777
+ auto type = GetNativeType(isolate, value);
778
+
779
+ switch (type) {
780
+ case NativeType::CanvasGradient: {
781
+ auto gradient = CanvasGradient::GetPointer(value.As<v8::Object>());
782
+ canvas_native_context_set_fill_style(ptr->GetContext(),
783
+ gradient->GetPaintStyle());
784
+ }
785
+ break;
786
+ case NativeType::CanvasPattern: {
787
+ auto pattern = CanvasPattern::GetPointer(value.As<v8::Object>());
788
+ canvas_native_context_set_fill_style(ptr->GetContext(),
789
+ pattern->GetPaintStyle());
790
+ }
791
+ break;
792
+ default:
793
+ // noop
794
+ break;
795
+ }
796
+ }
797
+ }
798
+
799
+ void CanvasRenderingContext2DImpl::GetStrokeStyle(v8::Local<v8::String> property,
800
+ const v8::PropertyCallbackInfo<v8::Value> &info) {
801
+ CanvasRenderingContext2DImpl *ptr = GetPointer(info.This());
802
+ if (ptr == nullptr) {
803
+ info.GetReturnValue().SetUndefined();
804
+ return;
805
+ }
806
+ auto isolate = info.GetIsolate();
807
+
808
+ PaintStyleType type = canvas_native_context_get_current_stroke_style_type(ptr->GetContext());
809
+
810
+ switch (type) {
811
+ case PaintStyleType::PaintStyleTypeColor: {
812
+ auto color = canvas_native_paint_style_get_current_stroke_color_string(
813
+ ptr->GetContext());
814
+
815
+ auto value = new OneByteStringResource((char*) color);
816
+ auto ret = v8::String::NewExternalOneByte(isolate, value);
817
+ info.GetReturnValue().Set(ret.ToLocalChecked());
818
+
819
+ //info.GetReturnValue().Set(ConvertToV8String(isolate, color.c_str()));
820
+ break;
821
+ }
822
+ case PaintStyleType::PaintStyleTypeGradient: {
823
+ auto style = CanvasGradient::NewInstance(isolate, new CanvasGradient(
824
+ canvas_native_context_get_stroke_style(ptr->GetContext())));
825
+
826
+ info.GetReturnValue().Set(style);
827
+
828
+ break;
829
+ }
830
+ case PaintStyleType::PaintStyleTypePattern: {
831
+ auto style = CanvasPattern::NewInstance(isolate, new CanvasPattern(
832
+ canvas_native_context_get_stroke_style(ptr->GetContext())));
833
+
834
+ info.GetReturnValue().Set(style);
835
+ break;
836
+ }
837
+ case PaintStyleType::PaintStyleTypeNone: {
838
+ info.GetReturnValue().SetUndefined();
839
+ break;
840
+ }
841
+ }
842
+
843
+ }
844
+
845
+
846
+ void CanvasRenderingContext2DImpl::SetStrokeStyle(v8::Local<v8::String> property,
847
+ v8::Local<v8::Value> value,
848
+ const v8::PropertyCallbackInfo<void> &info) {
849
+ CanvasRenderingContext2DImpl *ptr = GetPointer(info.This());
850
+ if (ptr == nullptr) {
851
+ return;
852
+ }
853
+ auto isolate = info.GetIsolate();
854
+ auto context = isolate->GetCurrentContext();
855
+
856
+ if (value->IsString()) {
857
+ auto style = ConvertFromV8String(isolate, value);
858
+ canvas_native_paint_style_set_stroke_color_with_c_string(ptr->GetContext(),
859
+ style.c_str());
860
+ } else if (value->IsObject()) {
861
+
862
+ auto type = GetNativeType(isolate, value);
863
+
864
+ switch (type) {
865
+ case NativeType::CanvasGradient: {
866
+ auto gradient = CanvasGradient::GetPointer(value.As<v8::Object>());
867
+ canvas_native_context_set_stroke_style(ptr->GetContext(),
868
+ gradient->GetPaintStyle());
869
+ }
870
+ break;
871
+ case NativeType::CanvasPattern: {
872
+ auto pattern = CanvasPattern::GetPointer(value.As<v8::Object>());
873
+ canvas_native_context_set_stroke_style(ptr->GetContext(),
874
+ pattern->GetPaintStyle());
875
+ }
876
+ break;
877
+ default:
878
+ break;
879
+ }
880
+ }
881
+ }
882
+
883
+
884
+ void CanvasRenderingContext2DImpl::GetLineWidth(v8::Local<v8::String> property,
885
+ const v8::PropertyCallbackInfo<v8::Value> &info) {
886
+ CanvasRenderingContext2DImpl *ptr = GetPointer(info.This());
887
+ if (ptr == nullptr) {
888
+ info.GetReturnValue().Set(0);
889
+ return;
890
+ }
891
+
892
+ auto lineWidth = canvas_native_context_get_line_width(ptr->GetContext());
893
+
894
+ info.GetReturnValue().Set((double) lineWidth);
895
+
896
+ }
897
+
898
+
899
+ void CanvasRenderingContext2DImpl::SetLineWidth(v8::Local<v8::String> property,
900
+ v8::Local<v8::Value> value,
901
+ const v8::PropertyCallbackInfo<void> &info) {
902
+ CanvasRenderingContext2DImpl *ptr = GetPointer(info.This());
903
+ if (ptr == nullptr) {
904
+ return;
905
+ }
906
+ auto isolate = info.GetIsolate();
907
+ auto context = isolate->GetCurrentContext();
908
+
909
+ auto lineWidth = (float) value->NumberValue(context).ToChecked();
910
+ canvas_native_context_set_line_width(ptr->GetContext(), lineWidth);
911
+ }
912
+
913
+ void CanvasRenderingContext2DImpl::GetLineDash(v8::Local<v8::String> property,
914
+ const v8::PropertyCallbackInfo<v8::Value> &info) {
915
+ CanvasRenderingContext2DImpl *ptr = GetPointer(info.This());
916
+ if (ptr == nullptr) {
917
+ info.GetReturnValue().Set(0);
918
+ return;
919
+ }
920
+
921
+ auto isolate = info.GetIsolate();
922
+ auto context = isolate->GetCurrentContext();
923
+
924
+ auto lineDash = canvas_native_context_get_line_dash(ptr->GetContext());
925
+ auto buf = canvas_native_f32_buffer_get_bytes(lineDash);
926
+ auto size = canvas_native_f32_buffer_get_length(lineDash);
927
+ auto ret = v8::Array::New(isolate, (int) size);
928
+ for (int i = 0; i < size; i++) {
929
+ auto item = buf[i];
930
+ ret->Set(context, i, v8::Number::New(isolate, (double) item));
931
+ }
932
+
933
+ }
934
+
935
+
936
+ void CanvasRenderingContext2DImpl::SetLineDash(v8::Local<v8::String> property,
937
+ v8::Local<v8::Value> value,
938
+ const v8::PropertyCallbackInfo<void> &info) {
939
+ CanvasRenderingContext2DImpl *ptr = GetPointer(info.This());
940
+ if (ptr == nullptr) {
941
+ return;
942
+ }
943
+ auto isolate = info.GetIsolate();
944
+ auto context = isolate->GetCurrentContext();
945
+
946
+ if (!value->IsNullOrUndefined() && value->IsObject()) {
947
+ auto lineDashObject = value.As<v8::Object>();
948
+ if (lineDashObject->IsArray()) {
949
+ auto lineDash = lineDashObject.As<v8::Array>();
950
+ auto size = lineDash->Length();
951
+ std::vector<float> dash;
952
+ dash.reserve(size);
953
+ for (int i = 0; i < size; ++i) {
954
+ auto val = lineDash->Get(context, i).ToLocalChecked();
955
+ dash[i] = (float) val->NumberValue(context).ToChecked();
956
+ }
957
+ canvas_native_context_set_line_dash(ptr->GetContext(), dash.data(),
958
+ dash.size());
959
+ }
960
+ }
961
+ }
962
+
963
+ void CanvasRenderingContext2DImpl::AddHitRegion(const v8::FunctionCallbackInfo<v8::Value> &args) {
964
+ // todo
965
+ // CanvasRenderingContext2DImpl *ptr = GetPointer(args.This());
966
+ // if (ptr == nullptr) {
967
+ // return;
968
+ // }
969
+ }
970
+
971
+ void CanvasRenderingContext2DImpl::Arc(const v8::FunctionCallbackInfo<v8::Value> &args) {
972
+ CanvasRenderingContext2DImpl *ptr = GetPointer(args.This());
973
+ if (ptr == nullptr) {
974
+ return;
975
+ }
976
+
977
+ auto isolate = args.GetIsolate();
978
+ auto context = isolate->GetCurrentContext();
979
+
980
+ auto anti_clockwise = false;
981
+ if (args.Length() == 6) {
982
+ anti_clockwise = args[5]->BooleanValue(isolate);
983
+ }
984
+ canvas_native_context_arc(
985
+ ptr->GetContext(),
986
+ static_cast<float>(args[0]->NumberValue(context).ToChecked()),
987
+ static_cast<float>(args[1]->NumberValue(context).ToChecked()),
988
+ static_cast<float>(args[2]->NumberValue(context).ToChecked()),
989
+ static_cast<float>(args[3]->NumberValue(context).ToChecked()),
990
+ static_cast<float>(args[4]->NumberValue(context).ToChecked()),
991
+ anti_clockwise
992
+ );
993
+ }
994
+
995
+ void CanvasRenderingContext2DImpl::ArcTo(const v8::FunctionCallbackInfo<v8::Value> &args) {
996
+ CanvasRenderingContext2DImpl *ptr = GetPointer(args.This());
997
+ if (ptr == nullptr) {
998
+ return;
999
+ }
1000
+
1001
+ auto isolate = args.GetIsolate();
1002
+ auto context = isolate->GetCurrentContext();
1003
+
1004
+ auto x1 = static_cast<float>(args[0]->NumberValue(context).ToChecked());
1005
+ auto y1 = static_cast<float>(args[1]->NumberValue(context).ToChecked());
1006
+ auto x2 = static_cast<float>(args[2]->NumberValue(context).ToChecked());
1007
+ auto y2 = static_cast<float>(args[3]->NumberValue(context).ToChecked());
1008
+ auto radius = static_cast<float>(args[4]->NumberValue(context).ToChecked());
1009
+ canvas_native_context_arc_to(
1010
+ ptr->GetContext(),
1011
+ x1,
1012
+ y1,
1013
+ x2,
1014
+ y2,
1015
+ radius
1016
+ );
1017
+ }
1018
+
1019
+ void CanvasRenderingContext2DImpl::BeginPath(const v8::FunctionCallbackInfo<v8::Value> &args) {
1020
+ CanvasRenderingContext2DImpl *ptr = GetPointer(args.This());
1021
+ if (ptr == nullptr) {
1022
+ return;
1023
+ }
1024
+
1025
+ canvas_native_context_begin_path(
1026
+ ptr->GetContext()
1027
+ );
1028
+ }
1029
+
1030
+ void CanvasRenderingContext2DImpl::BezierCurveTo(const v8::FunctionCallbackInfo<v8::Value> &args) {
1031
+ CanvasRenderingContext2DImpl *ptr = GetPointer(args.This());
1032
+ if (ptr == nullptr) {
1033
+ return;
1034
+ }
1035
+
1036
+ auto isolate = args.GetIsolate();
1037
+ auto context = isolate->GetCurrentContext();
1038
+
1039
+ canvas_native_context_bezier_curve_to(
1040
+ ptr->GetContext(),
1041
+ static_cast<float>(args[0]->NumberValue(context).ToChecked()),
1042
+ static_cast<float>(args[1]->NumberValue(context).ToChecked()),
1043
+ static_cast<float>(args[2]->NumberValue(context).ToChecked()),
1044
+ static_cast<float>(args[3]->NumberValue(context).ToChecked()),
1045
+ static_cast<float>(args[4]->NumberValue(context).ToChecked()),
1046
+ static_cast<float>(args[5]->NumberValue(context).ToChecked())
1047
+ );
1048
+ }
1049
+
1050
+ void
1051
+ CanvasRenderingContext2DImpl::ClearHitRegions(const v8::FunctionCallbackInfo<v8::Value> &args) {
1052
+ // TODO
1053
+ // CanvasRenderingContext2DImpl *ptr = GetPointer(args.This());
1054
+ // if (ptr == nullptr) {
1055
+ // return;
1056
+ // }
1057
+ }
1058
+
1059
+ void CanvasRenderingContext2DImpl::ClearRect(const v8::FunctionCallbackInfo<v8::Value> &args) {
1060
+ CanvasRenderingContext2DImpl *ptr = GetPointer(args.This());
1061
+ if (ptr == nullptr) {
1062
+ return;
1063
+ }
1064
+
1065
+ auto isolate = args.GetIsolate();
1066
+ auto context = isolate->GetCurrentContext();
1067
+
1068
+ canvas_native_context_clear_rect(
1069
+ ptr->GetContext(),
1070
+ static_cast<float>(args[0]->NumberValue(context).ToChecked()),
1071
+ static_cast<float>(args[1]->NumberValue(context).ToChecked()),
1072
+ static_cast<float>(args[2]->NumberValue(context).ToChecked()),
1073
+ static_cast<float>(args[3]->NumberValue(context).ToChecked())
1074
+ );
1075
+ ptr->UpdateInvalidateState();
1076
+ }
1077
+
1078
+ void CanvasRenderingContext2DImpl::Clip(const v8::FunctionCallbackInfo<v8::Value> &args) {
1079
+ CanvasRenderingContext2DImpl *ptr = GetPointer(args.This());
1080
+ if (ptr == nullptr) {
1081
+ return;
1082
+ }
1083
+
1084
+ auto isolate = args.GetIsolate();
1085
+
1086
+ if (args.Length() == 0) {
1087
+ std::string rule("nonzero");
1088
+ canvas_native_context_clip_rule(
1089
+ ptr->GetContext(), rule.c_str());
1090
+ } else if (args[0]->IsString()) {
1091
+ auto val = ConvertFromV8String(isolate, args[0]);
1092
+ canvas_native_context_clip_rule(
1093
+ ptr->GetContext(), val.c_str());
1094
+ }
1095
+ }
1096
+
1097
+ void CanvasRenderingContext2DImpl::ClosePath(const v8::FunctionCallbackInfo<v8::Value> &args) {
1098
+ CanvasRenderingContext2DImpl *ptr = GetPointer(args.This());
1099
+ if (ptr == nullptr) {
1100
+ return;
1101
+ }
1102
+
1103
+ canvas_native_context_close_path(
1104
+ ptr->GetContext());
1105
+ }
1106
+
1107
+ void
1108
+ CanvasRenderingContext2DImpl::CreateImageData(const v8::FunctionCallbackInfo<v8::Value> &args) {
1109
+ CanvasRenderingContext2DImpl *ptr = GetPointer(args.This());
1110
+ if (ptr == nullptr) {
1111
+ args.GetReturnValue().SetUndefined();
1112
+ return;
1113
+ }
1114
+
1115
+ auto isolate = args.GetIsolate();
1116
+ auto context = isolate->GetCurrentContext();
1117
+ auto count = args.Length();
1118
+ auto value = args[0];
1119
+ if (count == 1 && value->IsObject()) {
1120
+
1121
+ auto typeValue = GetNativeType(isolate, value);
1122
+
1123
+ if (typeValue == NativeType::ImageData) {
1124
+
1125
+ auto object = ImageDataImpl::GetPointer(value.As<v8::Object>());
1126
+
1127
+ auto width = canvas_native_image_data_get_width(
1128
+ object->GetImageData());
1129
+ auto height = canvas_native_image_data_get_height(
1130
+ object->GetImageData());
1131
+ auto data = new ImageDataImpl(
1132
+ canvas_native_image_data_create(
1133
+ width, height));
1134
+ auto ret = ImageDataImpl::GetCtor(isolate)->GetFunction(
1135
+ context).ToLocalChecked()->NewInstance(context).ToLocalChecked();
1136
+
1137
+ auto ext = v8::External::New(isolate, data);
1138
+
1139
+ ret->SetInternalField(0, ext);
1140
+
1141
+ SetNativeType(isolate, ret, NativeType::ImageData);
1142
+
1143
+ args.GetReturnValue().Set(ret);
1144
+
1145
+ return;
1146
+ }
1147
+
1148
+ } else if (count > 1) {
1149
+
1150
+ auto width = (int) args[0]->NumberValue(context).ToChecked();
1151
+ auto height = (int) args[1]->NumberValue(context).ToChecked();
1152
+ auto data = new ImageDataImpl(
1153
+ canvas_native_image_data_create(
1154
+ width, height));
1155
+
1156
+ auto ret = ImageDataImpl::GetCtor(isolate)->GetFunction(
1157
+ context).ToLocalChecked()->NewInstance(context).ToLocalChecked();
1158
+
1159
+ auto ext = v8::External::New(isolate, data);
1160
+
1161
+ ret->SetInternalField(0, ext);
1162
+
1163
+ SetNativeType(isolate, ret, NativeType::ImageData);
1164
+
1165
+ args.GetReturnValue().Set(ret);
1166
+ }
1167
+
1168
+ args.GetReturnValue().SetUndefined();
1169
+ }
1170
+
1171
+ void
1172
+ CanvasRenderingContext2DImpl::CreatePattern(const v8::FunctionCallbackInfo<v8::Value> &args) {
1173
+ CanvasRenderingContext2DImpl *ptr = GetPointer(args.This());
1174
+ if (ptr == nullptr) {
1175
+ args.GetReturnValue().SetNull();
1176
+ return;
1177
+ }
1178
+ auto isolate = args.GetIsolate();
1179
+
1180
+ if (args.Length() > 1) {
1181
+ auto value = args[0];
1182
+ auto valueType = GetNativeType(isolate, value);
1183
+
1184
+ switch (valueType) {
1185
+ case NativeType::ImageAsset: {
1186
+ auto image_asset = ImageAssetImpl::GetPointer(value.As<v8::Object>());
1187
+ if (image_asset != nullptr) {
1188
+ auto rep = ConvertFromV8String(isolate, args[1]);
1189
+ auto pattern = canvas_native_context_create_pattern_asset(
1190
+ ptr->GetContext(),
1191
+ image_asset->GetImageAsset(), rep.c_str());
1192
+ auto style_type = canvas_native_context_get_style_type(pattern);
1193
+ if (style_type ==
1194
+ PaintStyleType::PaintStyleTypeNone) {
1195
+ args.GetReturnValue().SetUndefined();
1196
+ canvas_native_paint_style_destroy(pattern);
1197
+ } else {
1198
+ auto data = CanvasPattern::NewInstance(isolate, new CanvasPattern(pattern));
1199
+ args.GetReturnValue().Set(data);
1200
+ }
1201
+ }
1202
+ return;
1203
+ }
1204
+ case NativeType::ImageBitmap: {
1205
+ auto image_bitmap = ImageBitmapImpl::GetPointer(value.As<v8::Object>());
1206
+ if (image_bitmap != nullptr) {
1207
+ auto rep = ConvertFromV8String(isolate, args[1]);
1208
+ auto pattern = canvas_native_context_create_pattern_asset(
1209
+ ptr->GetContext(),
1210
+ image_bitmap->GetImageAsset(), rep.c_str());
1211
+ auto style_type = canvas_native_context_get_style_type(pattern);
1212
+ if (style_type ==
1213
+ PaintStyleType::PaintStyleTypeNone) {
1214
+ args.GetReturnValue().SetUndefined();
1215
+ canvas_native_paint_style_destroy(pattern);
1216
+ } else {
1217
+ auto data = CanvasPattern::NewInstance(isolate, new CanvasPattern(pattern));
1218
+ args.GetReturnValue().Set(data);
1219
+ }
1220
+ }
1221
+ return;
1222
+ }
1223
+ case NativeType::CanvasRenderingContext2D: {
1224
+ auto canvas_2d = CanvasRenderingContext2DImpl::GetPointer(
1225
+ value.As<v8::Object>());
1226
+ if (canvas_2d != nullptr) {
1227
+ auto rep = ConvertFromV8String(isolate, args[1]);
1228
+ auto pattern = canvas_native_context_create_pattern_canvas2d(
1229
+ canvas_2d->GetContext(),
1230
+ ptr->GetContext(), rep.c_str());
1231
+ auto style_type = canvas_native_context_get_style_type(pattern);
1232
+ if (style_type ==
1233
+ PaintStyleType::PaintStyleTypeNone) {
1234
+ args.GetReturnValue().SetUndefined();
1235
+ canvas_native_paint_style_destroy(pattern);
1236
+ } else {
1237
+ auto data = CanvasPattern::NewInstance(isolate, new CanvasPattern(pattern));
1238
+ args.GetReturnValue().Set(data);
1239
+ }
1240
+ }
1241
+ return;
1242
+ }
1243
+ case NativeType::WebGLRenderingContextBase: {
1244
+ auto webgl = WebGLRenderingContextBase::GetPointer(value.As<v8::Object>());
1245
+ if (webgl != nullptr) {
1246
+ auto rep = ConvertFromV8String(isolate, args[1]);
1247
+ auto pattern = canvas_native_context_create_pattern_webgl(
1248
+ webgl->GetState(),
1249
+ ptr->GetContext(), rep.c_str());
1250
+ auto type = canvas_native_context_get_style_type(pattern);
1251
+ if (type ==
1252
+ PaintStyleType::PaintStyleTypeNone) {
1253
+ args.GetReturnValue().SetNull();
1254
+ canvas_native_paint_style_destroy(pattern);
1255
+ return;
1256
+ } else {
1257
+ auto ret = CanvasPattern::NewInstance(isolate, new CanvasPattern(
1258
+ pattern));
1259
+ args.GetReturnValue().Set(ret);
1260
+ return;
1261
+ }
1262
+ }
1263
+ return;
1264
+ }
1265
+ default:
1266
+ args.GetReturnValue().SetNull();
1267
+ return;
1268
+ }
1269
+
1270
+ return;
1271
+ }
1272
+
1273
+ args.GetReturnValue().SetNull();
1274
+ }
1275
+
1276
+ void
1277
+ CanvasRenderingContext2DImpl::CreateLinearGradient(
1278
+ const v8::FunctionCallbackInfo<v8::Value> &args) {
1279
+ CanvasRenderingContext2DImpl *ptr = GetPointer(args.This());
1280
+ if (ptr == nullptr) {
1281
+ args.GetReturnValue().SetUndefined();
1282
+ return;
1283
+ }
1284
+
1285
+ auto isolate = args.GetIsolate();
1286
+ auto context = isolate->GetCurrentContext();
1287
+
1288
+ if (args.Length() == 4) {
1289
+ auto x0 = static_cast<float>(args[0]->NumberValue(context).ToChecked());
1290
+ auto y0 = static_cast<float>(args[1]->NumberValue(context).ToChecked());
1291
+ auto x1 = static_cast<float>(args[2]->NumberValue(context).ToChecked());
1292
+ auto y1 = static_cast<float>(args[3]->NumberValue(context).ToChecked());
1293
+
1294
+ auto gradient = canvas_native_context_create_linear_gradient(
1295
+ ptr->GetContext(), x0, y0, x1,
1296
+ y1);
1297
+
1298
+ auto data = CanvasGradient::NewInstance(isolate, new CanvasGradient(
1299
+ gradient));
1300
+
1301
+ args.GetReturnValue().Set(data);
1302
+
1303
+ return;
1304
+ }
1305
+
1306
+ args.GetReturnValue().SetNull();
1307
+ }
1308
+
1309
+ void
1310
+ CanvasRenderingContext2DImpl::__CreatePatternWithNative(
1311
+ const v8::FunctionCallbackInfo<v8::Value> &args) {
1312
+ CanvasRenderingContext2DImpl *ptr = GetPointer(args.This());
1313
+ if (ptr == nullptr) {
1314
+ args.GetReturnValue().SetUndefined();
1315
+ return;
1316
+ }
1317
+
1318
+ auto isolate = args.GetIsolate();
1319
+ auto context = isolate->GetCurrentContext();
1320
+
1321
+
1322
+ auto pointer = args[0]->ToBigInt(context).ToLocalChecked();
1323
+
1324
+ auto pattern = canvas_native_pattern_from_ptr(pointer->Int64Value());
1325
+ auto type = canvas_native_context_get_style_type(pattern);
1326
+ if (type == PaintStyleType::PaintStyleTypeNone) {
1327
+ args.GetReturnValue().SetUndefined();
1328
+ canvas_native_paint_style_destroy(pattern);
1329
+ } else {
1330
+ auto data = CanvasPattern::NewInstance(isolate, new CanvasPattern(pattern));
1331
+
1332
+ args.GetReturnValue().Set(data);
1333
+ }
1334
+
1335
+ }
1336
+
1337
+ void
1338
+ CanvasRenderingContext2DImpl::CreateRadialGradient(
1339
+ const v8::FunctionCallbackInfo<v8::Value> &args) {
1340
+ CanvasRenderingContext2DImpl *ptr = GetPointer(args.This());
1341
+ if (ptr == nullptr) {
1342
+ args.GetReturnValue().SetNull();
1343
+ return;
1344
+ }
1345
+
1346
+ auto isolate = args.GetIsolate();
1347
+ auto context = isolate->GetCurrentContext();
1348
+
1349
+ if (args.Length() == 6) {
1350
+ auto x0 = static_cast<float>(args[0]->NumberValue(context).ToChecked());
1351
+ auto y0 = static_cast<float>(args[1]->NumberValue(context).ToChecked());
1352
+ auto r0 = static_cast<float>(args[2]->NumberValue(context).ToChecked());
1353
+ auto x1 = static_cast<float>(args[3]->NumberValue(context).ToChecked());
1354
+ auto y1 = static_cast<float>(args[4]->NumberValue(context).ToChecked());
1355
+ auto r1 = static_cast<float>(args[5]->NumberValue(context).ToChecked());
1356
+
1357
+ auto gradient = canvas_native_context_create_radial_gradient(
1358
+ ptr->GetContext(), x0, y0, r0,
1359
+ x1, y1, r1);
1360
+
1361
+ auto data = CanvasGradient::NewInstance(isolate, new CanvasGradient(
1362
+ std::move(gradient)));
1363
+
1364
+ args.GetReturnValue().Set(data);
1365
+ return;
1366
+ }
1367
+
1368
+ args.GetReturnValue().SetNull();
1369
+ }
1370
+
1371
+
1372
+ void
1373
+ CanvasRenderingContext2DImpl::DrawFocusIfNeeded(const v8::FunctionCallbackInfo<v8::Value> &args) {
1374
+ // TODO
1375
+ // CanvasRenderingContext2DImpl *ptr = GetPointer(args.This());
1376
+ // if (ptr == nullptr) {
1377
+ // return;
1378
+ // }
1379
+ }
1380
+
1381
+
1382
+ void
1383
+ CanvasRenderingContext2DImpl::DrawImage(const v8::FunctionCallbackInfo<v8::Value> &args) {
1384
+
1385
+ CanvasRenderingContext2DImpl *ptr = GetPointer(args.This());
1386
+ if (ptr == nullptr) {
1387
+ return;
1388
+ }
1389
+
1390
+ auto count = args.Length();
1391
+ auto value = args[0];
1392
+
1393
+ if (value->IsNullOrUndefined() || !value->IsObject()) {
1394
+ return;
1395
+ }
1396
+
1397
+ auto isolate = args.GetIsolate();
1398
+ auto context = isolate->GetCurrentContext();
1399
+ auto image = value.As<v8::Object>();
1400
+ auto imageType = GetNativeType(isolate, image);
1401
+ if (count == 3) {
1402
+ auto dx = static_cast<float>(args[1]->NumberValue(context).ToChecked());
1403
+ auto dy = static_cast<float>(args[2]->NumberValue(context).ToChecked());
1404
+
1405
+ switch (imageType) {
1406
+ case NativeType::ImageAsset: {
1407
+ auto image_asset = ImageAssetImpl::GetPointer(image);
1408
+
1409
+ if (image_asset != nullptr) {
1410
+ canvas_native_context_draw_image_dx_dy_asset(
1411
+ ptr->GetContext(),
1412
+ image_asset->GetImageAsset(),
1413
+ dx, dy);
1414
+ ptr->UpdateInvalidateState();
1415
+ }
1416
+ }
1417
+ break;
1418
+ case NativeType::ImageBitmap: {
1419
+ auto image_bitmap = ImageBitmapImpl::GetPointer(image);
1420
+ if (image_bitmap != nullptr) {
1421
+ canvas_native_context_draw_image_dx_dy_asset(
1422
+ ptr->GetContext(),
1423
+ image_bitmap->GetImageAsset(),
1424
+ dx, dy);
1425
+ ptr->UpdateInvalidateState();
1426
+ }
1427
+ }
1428
+ break;
1429
+ case NativeType::CanvasRenderingContext2D: {
1430
+ auto image_canvas = CanvasRenderingContext2DImpl::GetPointer(image);
1431
+ if (image_canvas != nullptr) {
1432
+ canvas_native_context_draw_image_dx_dy_context(
1433
+ ptr->GetContext(),
1434
+ image_canvas->GetContext(),
1435
+ dx, dy);
1436
+ ptr->UpdateInvalidateState();
1437
+ }
1438
+ }
1439
+ break;
1440
+ default:
1441
+ break;
1442
+ }
1443
+ } else if (count == 5) {
1444
+ auto dx = (float) args[1]->NumberValue(context).ToChecked();
1445
+ auto dy = (float) args[2]->NumberValue(context).ToChecked();
1446
+ auto dWidth = (float) args[3]->NumberValue(context).ToChecked();
1447
+ auto dHeight = (float) args[4]->NumberValue(context).ToChecked();
1448
+
1449
+ switch (imageType) {
1450
+ case NativeType::ImageAsset: {
1451
+ auto image_asset = ImageAssetImpl::GetPointer(image);
1452
+
1453
+ if (image_asset != nullptr) {
1454
+ canvas_native_context_draw_image_dx_dy_dw_dh_asset(
1455
+ ptr->GetContext(),
1456
+ image_asset->GetImageAsset(),
1457
+ dx, dy,
1458
+ dWidth,
1459
+ dHeight);
1460
+ ptr->UpdateInvalidateState();
1461
+ }
1462
+ }
1463
+ break;
1464
+ case NativeType::ImageBitmap: {
1465
+ auto image_bitmap = ImageBitmapImpl::GetPointer(image);
1466
+ if (image_bitmap != nullptr) {
1467
+ canvas_native_context_draw_image_dx_dy_dw_dh_asset(
1468
+ ptr->GetContext(),
1469
+ image_bitmap->GetImageAsset(),
1470
+ dx, dy,
1471
+ dWidth,
1472
+ dHeight);
1473
+ ptr->UpdateInvalidateState();
1474
+ }
1475
+ }
1476
+ break;
1477
+ case NativeType::CanvasRenderingContext2D: {
1478
+ auto image_canvas = CanvasRenderingContext2DImpl::GetPointer(image);
1479
+ if (image_canvas != nullptr) {
1480
+ canvas_native_context_draw_image_dx_dy_dw_dh_context(
1481
+ ptr->GetContext(),
1482
+ image_canvas->GetContext(),
1483
+ dx, dy,
1484
+ dWidth,
1485
+ dHeight);
1486
+ ptr->UpdateInvalidateState();
1487
+ }
1488
+ }
1489
+ break;
1490
+ default:
1491
+ break;
1492
+ }
1493
+
1494
+ } else if (count == 9) {
1495
+ auto sx = (float) args[1]->NumberValue(context).ToChecked();
1496
+ auto sy = (float) args[2]->NumberValue(context).ToChecked();
1497
+ auto sWidth = (float) args[3]->NumberValue(context).ToChecked();
1498
+ auto sHeight = (float) args[4]->NumberValue(context).ToChecked();
1499
+ auto dx = (float) args[5]->NumberValue(context).ToChecked();
1500
+ auto dy = (float) args[6]->NumberValue(context).ToChecked();
1501
+ auto dWidth = (float) args[7]->NumberValue(context).ToChecked();
1502
+ auto dHeight = (float) args[8]->NumberValue(context).ToChecked();
1503
+
1504
+ switch (imageType) {
1505
+ case NativeType::ImageAsset: {
1506
+ auto image_asset = ImageAssetImpl::GetPointer(image);
1507
+
1508
+ if (image_asset != nullptr) {
1509
+ canvas_native_context_draw_image_asset(
1510
+ ptr->GetContext(),
1511
+ image_asset->GetImageAsset(),
1512
+ sx,
1513
+ sy, sWidth, sHeight,
1514
+ dx,
1515
+ dy, dWidth, dHeight);
1516
+ ptr->UpdateInvalidateState();
1517
+ }
1518
+ }
1519
+ break;
1520
+ case NativeType::ImageBitmap: {
1521
+ auto image_bitmap = ImageBitmapImpl::GetPointer(image);
1522
+ if (image_bitmap != nullptr) {
1523
+ canvas_native_context_draw_image_asset(
1524
+ ptr->GetContext(),
1525
+ image_bitmap->GetImageAsset(),
1526
+ sx,
1527
+ sy, sWidth, sHeight,
1528
+ dx,
1529
+ dy, dWidth, dHeight);
1530
+ ptr->UpdateInvalidateState();
1531
+ }
1532
+ }
1533
+ break;
1534
+ case NativeType::CanvasRenderingContext2D: {
1535
+ auto image_canvas = CanvasRenderingContext2DImpl::GetPointer(image);
1536
+ if (image_canvas != nullptr) {
1537
+ canvas_native_context_draw_image_context(
1538
+ ptr->GetContext(),
1539
+ image_canvas->GetContext(),
1540
+ sx,
1541
+ sy, sWidth, sHeight,
1542
+ dx,
1543
+ dy, dWidth, dHeight);
1544
+ ptr->UpdateInvalidateState();
1545
+ }
1546
+ }
1547
+ break;
1548
+ default:
1549
+ break;
1550
+ }
1551
+ }
1552
+ }
1553
+
1554
+
1555
+ void
1556
+ CanvasRenderingContext2DImpl::Ellipse(const v8::FunctionCallbackInfo<v8::Value> &args) {
1557
+ CanvasRenderingContext2DImpl *ptr = GetPointer(args.This());
1558
+ if (ptr == nullptr) {
1559
+ return;
1560
+ }
1561
+ auto isolate = args.GetIsolate();
1562
+ auto context = isolate->GetCurrentContext();
1563
+
1564
+ if (args.Length() == 8) {
1565
+ auto x = static_cast<float>(args[0]->NumberValue(context).ToChecked());
1566
+ auto y = static_cast<float>(args[1]->NumberValue(context).ToChecked());
1567
+ auto radiusX = static_cast<float>(args[2]->NumberValue(context).ToChecked());
1568
+ auto radiusY = static_cast<float>(args[3]->NumberValue(context).ToChecked());
1569
+ auto rotation = static_cast<float>(args[4]->NumberValue(context).ToChecked());
1570
+ auto startAngle = static_cast<float>(args[5]->NumberValue(context).ToChecked());
1571
+ auto endAngle = static_cast<float>(args[6]->NumberValue(context).ToChecked());
1572
+ auto anticlockwise = false;
1573
+ if (args[7]->IsBoolean()) {
1574
+ anticlockwise = args[7]->BooleanValue(isolate);
1575
+ }
1576
+ canvas_native_context_ellipse(
1577
+ ptr->GetContext(), x, y,
1578
+ radiusX,
1579
+ radiusY, rotation,
1580
+ startAngle, endAngle,
1581
+ anticlockwise);
1582
+ }
1583
+ }
1584
+
1585
+ void
1586
+ CanvasRenderingContext2DImpl::Fill(const v8::FunctionCallbackInfo<v8::Value> &args) {
1587
+ CanvasRenderingContext2DImpl *ptr = GetPointer(args.This());
1588
+ if (ptr == nullptr) {
1589
+ return;
1590
+ }
1591
+ auto isolate = args.GetIsolate();
1592
+
1593
+ auto count = args.Length();
1594
+ auto value = args[0];
1595
+ if (count == 2) {
1596
+ auto type = GetNativeType(isolate, value.As<v8::Object>());
1597
+ if (type == NativeType::Path2D) {
1598
+ auto object = Path2D::GetPointer(value.As<v8::Object>());
1599
+
1600
+ if (object != nullptr) {
1601
+ auto data = ConvertFromV8String(isolate, args[1]);
1602
+ canvas_native_context_fill_with_path(
1603
+ ptr->GetContext(),
1604
+ object->GetPath(),
1605
+ data.c_str());
1606
+ ptr->UpdateInvalidateState();
1607
+ }
1608
+ }
1609
+
1610
+ } else if (count == 1) {
1611
+ if (value->IsString()) {
1612
+ auto rule = ConvertFromV8String(isolate, value);
1613
+ canvas_native_context_fill(
1614
+ ptr->GetContext(), rule.c_str());
1615
+ ptr->UpdateInvalidateState();
1616
+ } else if (value->IsObject()) {
1617
+ auto type = GetNativeType(isolate, value.As<v8::Object>());
1618
+ if (type == NativeType::Path2D) {
1619
+ auto object = Path2D::GetPointer(value.As<v8::Object>());
1620
+
1621
+ std::string rule("nonzero");
1622
+ canvas_native_context_fill_with_path(
1623
+ ptr->GetContext(),
1624
+ object->GetPath(),rule.c_str());
1625
+ ptr->UpdateInvalidateState();
1626
+ }
1627
+ }
1628
+ } else {
1629
+ std::string rule("nonzero");
1630
+ canvas_native_context_fill(
1631
+ ptr->GetContext(), rule.c_str());
1632
+ ptr->UpdateInvalidateState();
1633
+ }
1634
+ }
1635
+
1636
+ void
1637
+ CanvasRenderingContext2DImpl::FillRect(const v8::FunctionCallbackInfo<v8::Value> &args) {
1638
+ CanvasRenderingContext2DImpl *ptr = GetPointer(args.This());
1639
+ if (ptr == nullptr) {
1640
+ return;
1641
+ }
1642
+ auto isolate = args.GetIsolate();
1643
+ auto context = isolate->GetCurrentContext();
1644
+
1645
+ auto x = static_cast<float>(args[0]->NumberValue(context).ToChecked());
1646
+ auto y = static_cast<float>(args[1]->NumberValue(context).ToChecked());
1647
+ auto width = static_cast<float>(args[2]->NumberValue(context).ToChecked());
1648
+ auto height = static_cast<float>(args[3]->NumberValue(context).ToChecked());
1649
+ canvas_native_context_fill_rect(
1650
+ ptr->GetContext(), x, y, width,
1651
+ height);
1652
+ ptr->UpdateInvalidateState();
1653
+ }
1654
+
1655
+ void
1656
+ CanvasRenderingContext2DImpl::FillText(const v8::FunctionCallbackInfo<v8::Value> &args) {
1657
+ CanvasRenderingContext2DImpl *ptr = GetPointer(args.This());
1658
+ if (ptr == nullptr) {
1659
+ return;
1660
+ }
1661
+ auto isolate = args.GetIsolate();
1662
+ auto context = isolate->GetCurrentContext();
1663
+
1664
+ auto text = ConvertFromV8String(isolate, args[0]);
1665
+
1666
+ auto x = static_cast<float>(args[1]->NumberValue(context).ToChecked());
1667
+ auto y = static_cast<float>(args[2]->NumberValue(context).ToChecked());
1668
+ float width = -1;
1669
+ if (args[3]->IsNumber()) {
1670
+ width = static_cast<float>(args[3]->NumberValue(context).ToChecked());
1671
+ }
1672
+ canvas_native_context_fill_text(
1673
+ ptr->GetContext(), text.c_str(), x,
1674
+ y, width);
1675
+ ptr->UpdateInvalidateState();
1676
+
1677
+ }
1678
+
1679
+ void
1680
+ CanvasRenderingContext2DImpl::GetImageData(const v8::FunctionCallbackInfo<v8::Value> &args) {
1681
+ CanvasRenderingContext2DImpl *ptr = GetPointer(args.This());
1682
+ if (ptr == nullptr) {
1683
+ args.GetReturnValue().SetUndefined();
1684
+ return;
1685
+ }
1686
+ auto isolate = args.GetIsolate();
1687
+ auto context = isolate->GetCurrentContext();
1688
+
1689
+
1690
+ if (args.Length() == 4) {
1691
+ auto sx = static_cast<float>(args[0]->NumberValue(context).ToChecked());
1692
+ auto sy = static_cast<float>(args[1]->NumberValue(context).ToChecked());
1693
+ auto sw = static_cast<float>(args[2]->NumberValue(context).ToChecked());
1694
+ auto sh = static_cast<float>(args[3]->NumberValue(context).ToChecked());
1695
+ auto imageData = canvas_native_context_get_image_data(
1696
+ ptr->GetContext(), sx, sy, sw,
1697
+ sh);
1698
+
1699
+ auto data = new ImageDataImpl(
1700
+ std::move(imageData));
1701
+
1702
+ auto ret = ImageDataImpl::GetCtor(isolate)->GetFunction(
1703
+ context).ToLocalChecked()->NewInstance(context).ToLocalChecked();
1704
+
1705
+ auto ext = v8::External::New(isolate, data);
1706
+
1707
+ ret->SetInternalField(0, ext);
1708
+
1709
+ SetNativeType(isolate, ret, NativeType::ImageData);
1710
+
1711
+ args.GetReturnValue().Set(ret);
1712
+ return;
1713
+ }
1714
+
1715
+ args.GetReturnValue().SetUndefined();
1716
+
1717
+
1718
+ }
1719
+
1720
+ void
1721
+ CanvasRenderingContext2DImpl::GetLineDash(const v8::FunctionCallbackInfo<v8::Value> &args) {
1722
+ CanvasRenderingContext2DImpl *ptr = GetPointer(args.This());
1723
+
1724
+ auto isolate = args.GetIsolate();
1725
+
1726
+ if (ptr == nullptr) {
1727
+ auto ret = v8::Array::New(isolate);
1728
+ args.GetReturnValue().Set(ret);
1729
+ return;
1730
+ }
1731
+ auto context = isolate->GetCurrentContext();
1732
+
1733
+
1734
+ auto dash = canvas_native_context_get_line_dash(
1735
+ ptr->GetContext());
1736
+ auto buf = canvas_native_f32_buffer_get_bytes(dash);
1737
+ auto size = canvas_native_f32_buffer_get_length(dash);
1738
+ auto array = v8::Array::New(isolate, (int) size);
1739
+ for (int i = 0; i < size; ++i) {
1740
+ array->Set(context, i,
1741
+ v8::Number::New(isolate,
1742
+ (double) buf[i]));
1743
+ }
1744
+
1745
+ args.GetReturnValue().Set(array);
1746
+ }
1747
+
1748
+ void
1749
+ CanvasRenderingContext2DImpl::IsPointInPath(const v8::FunctionCallbackInfo<v8::Value> &args) {
1750
+ CanvasRenderingContext2DImpl *ptr = GetPointer(args.This());
1751
+
1752
+ auto isolate = args.GetIsolate();
1753
+ auto context = isolate->GetCurrentContext();
1754
+ auto count = args.Length();
1755
+
1756
+ if (count == 2) {
1757
+ auto x = static_cast<float>(args[0]->NumberValue(context).ToChecked());
1758
+ auto y = static_cast<float>(args[1]->NumberValue(context).ToChecked());
1759
+ std::string rule("nonzero");
1760
+ auto ret = canvas_native_context_is_point_in_path(
1761
+ ptr->GetContext(), x, y, rule.c_str());
1762
+ args.GetReturnValue().Set(ret);
1763
+ return;
1764
+ } else if (count == 3 &&
1765
+ args[2]->IsString()) {
1766
+ auto x = static_cast<float>(args[0]->NumberValue(context).ToChecked());
1767
+ auto y = static_cast<float>(args[1]->NumberValue(context).ToChecked());
1768
+ auto rule = ConvertFromV8String(isolate, args[2]);
1769
+ auto ret = canvas_native_context_is_point_in_path(
1770
+ ptr->GetContext(), x, y, rule.c_str());
1771
+ args.GetReturnValue().Set(ret);
1772
+ return;
1773
+ } else if (count == 4 &&
1774
+ args[0]->IsObject() &&
1775
+ args[3]->IsString()) {
1776
+
1777
+
1778
+ auto value = args[0];
1779
+ auto typeValue = GetPrivateValue(isolate, value.As<v8::Object>(),
1780
+ ConvertToV8String(isolate, "__type"));
1781
+
1782
+ if (!typeValue.IsEmpty()) {
1783
+ auto type = (NativeType) typeValue->Int32Value(context).ToChecked();
1784
+ if (type == NativeType::Path2D) {
1785
+ auto path = Path2D::GetPointer(value.As<v8::Object>());
1786
+ auto x = static_cast<float>(args[1]->NumberValue(context).ToChecked());
1787
+ auto y = static_cast<float>(args[2]->NumberValue(context).ToChecked());
1788
+ auto rule = ConvertFromV8String(isolate, args[3]);
1789
+
1790
+
1791
+ if (path != nullptr) {
1792
+ auto ret = canvas_native_context_is_point_in_path_with_path(
1793
+ ptr->GetContext(),
1794
+ path->GetPath(), x, y, rule.c_str());
1795
+ args.GetReturnValue().Set(ret);
1796
+ return;
1797
+ }
1798
+ }
1799
+ }
1800
+
1801
+ }
1802
+
1803
+
1804
+ args.GetReturnValue().Set(false);
1805
+ }
1806
+
1807
+ void
1808
+ CanvasRenderingContext2DImpl::IsPointInStroke(const v8::FunctionCallbackInfo<v8::Value> &args) {
1809
+ CanvasRenderingContext2DImpl *ptr = GetPointer(args.This());
1810
+
1811
+ auto isolate = args.GetIsolate();
1812
+ auto context = isolate->GetCurrentContext();
1813
+ auto count = args.Length();
1814
+
1815
+
1816
+ if (count == 2) {
1817
+ auto x = static_cast<float>(args[0]->NumberValue(context).ToChecked());
1818
+ auto y = static_cast<float>(args[1]->NumberValue(context).ToChecked());
1819
+ auto ret = canvas_native_context_is_point_in_stroke(
1820
+ ptr->GetContext(), x, y);
1821
+
1822
+ args.GetReturnValue().Set(ret);
1823
+ return;
1824
+ } else if (count == 3 &&
1825
+ args[0]->IsObject()) {
1826
+
1827
+
1828
+ auto value = args[0];
1829
+ auto typeValue = GetPrivateValue(isolate, value.As<v8::Object>(),
1830
+ ConvertToV8String(isolate, "__type"));
1831
+
1832
+ if (!typeValue.IsEmpty()) {
1833
+ auto type = (NativeType) typeValue->Int32Value(context).ToChecked();
1834
+ if (type == NativeType::Path2D) {
1835
+ auto path = Path2D::GetPointer(value.As<v8::Object>());
1836
+ auto x = static_cast<float>(args[1]->NumberValue(context).ToChecked());
1837
+ auto y = static_cast<float>(args[2]->NumberValue(context).ToChecked());
1838
+ auto rule = ConvertFromV8String(isolate, args[3]);
1839
+
1840
+
1841
+ if (path != nullptr) {
1842
+ auto ret = canvas_native_context_is_point_in_stroke_with_path(
1843
+ ptr->GetContext(),
1844
+ path->GetPath(), x, y);
1845
+ args.GetReturnValue().Set(ret);
1846
+ return;
1847
+ }
1848
+ }
1849
+ }
1850
+ }
1851
+
1852
+ args.GetReturnValue().Set(false);
1853
+ }
1854
+
1855
+ void
1856
+ CanvasRenderingContext2DImpl::LineTo(const v8::FunctionCallbackInfo<v8::Value> &args) {
1857
+ CanvasRenderingContext2DImpl *ptr = GetPointer(args.This());
1858
+
1859
+ auto isolate = args.GetIsolate();
1860
+ auto context = isolate->GetCurrentContext();
1861
+
1862
+ if (args.Length() > 1) {
1863
+ auto x = static_cast<float>(args[0]->NumberValue(context).ToChecked());
1864
+ auto y = static_cast<float>(args[1]->NumberValue(context).ToChecked());
1865
+ canvas_native_context_line_to(
1866
+ ptr->GetContext(), x, y);
1867
+ }
1868
+ }
1869
+
1870
+ void
1871
+ CanvasRenderingContext2DImpl::MeasureText(const v8::FunctionCallbackInfo<v8::Value> &args) {
1872
+ CanvasRenderingContext2DImpl *ptr = GetPointer(args.This());
1873
+
1874
+ auto isolate = args.GetIsolate();
1875
+ auto context = isolate->GetCurrentContext();
1876
+
1877
+ auto text = ConvertFromV8String(isolate, args[0]);
1878
+
1879
+ auto metrics = canvas_native_context_measure_text(
1880
+ ptr->GetContext(), text.c_str());
1881
+
1882
+ auto data = new TextMetricsImpl(
1883
+ std::move(metrics));
1884
+
1885
+ auto ret = TextMetricsImpl::GetCtor(isolate)->GetFunction(
1886
+ context).ToLocalChecked()->NewInstance(context).ToLocalChecked();
1887
+
1888
+ auto ext = v8::External::New(isolate, data);
1889
+
1890
+ ret->SetInternalField(0, ext);
1891
+
1892
+ SetNativeType(isolate, ret, NativeType::TextMetrics);
1893
+
1894
+ args.GetReturnValue().Set(ret);
1895
+
1896
+ }
1897
+
1898
+ void
1899
+ CanvasRenderingContext2DImpl::MoveTo(const v8::FunctionCallbackInfo<v8::Value> &args) {
1900
+ CanvasRenderingContext2DImpl *ptr = GetPointer(args.This());
1901
+
1902
+ auto isolate = args.GetIsolate();
1903
+ auto context = isolate->GetCurrentContext();
1904
+
1905
+ if (args.Length() > 1) {
1906
+ auto x = static_cast<float>(args[0]->NumberValue(context).ToChecked());
1907
+ auto y = static_cast<float>(args[1]->NumberValue(context).ToChecked());
1908
+ canvas_native_context_move_to(
1909
+ ptr->GetContext(), x, y);
1910
+ }
1911
+ }
1912
+
1913
+ void
1914
+ CanvasRenderingContext2DImpl::PutImageData(const v8::FunctionCallbackInfo<v8::Value> &args) {
1915
+ CanvasRenderingContext2DImpl *ptr = GetPointer(args.This());
1916
+
1917
+ auto isolate = args.GetIsolate();
1918
+ auto context = isolate->GetCurrentContext();
1919
+
1920
+
1921
+ auto value = args[0];
1922
+ auto typeValue = GetPrivateValue(isolate, value.As<v8::Object>(),
1923
+ ConvertToV8String(isolate, "__type"));
1924
+ auto count = args.Length();
1925
+ if (!typeValue.IsEmpty()) {
1926
+ auto type = (NativeType) typeValue->Int32Value(context).ToChecked();
1927
+ if (type == NativeType::ImageData) {
1928
+
1929
+
1930
+ auto imageData = ImageDataImpl::GetPointer(value.As<v8::Object>());
1931
+ if (count == 3) {
1932
+ auto dx = static_cast<float>(args[1]->NumberValue(context).ToChecked());
1933
+ auto dy = static_cast<float>(args[2]->NumberValue(context).ToChecked());
1934
+ float dirtyX = 0;
1935
+ float dirtyY = 0;
1936
+ auto dirtyWidth = (float) canvas_native_image_data_get_width(
1937
+ imageData->GetImageData());
1938
+ auto dirtyHeight = (float) canvas_native_image_data_get_height(
1939
+ imageData->GetImageData());
1940
+ canvas_native_context_put_image_data(
1941
+ ptr->GetContext(),
1942
+ imageData->GetImageData(), dx,
1943
+ dy, dirtyX, dirtyY,
1944
+ dirtyWidth, dirtyHeight);
1945
+ ptr->UpdateInvalidateState();
1946
+ } else if (count == 7) {
1947
+ auto dx = static_cast<float>(args[1]->NumberValue(context).ToChecked());
1948
+ auto dy = static_cast<float>(args[2]->NumberValue(context).ToChecked());
1949
+ auto dirtyX = static_cast<float>(args[3]->NumberValue(context).ToChecked());
1950
+ auto dirtyY = static_cast<float>(args[4]->NumberValue(context).ToChecked());
1951
+ auto dirtyWidth = static_cast<float>(args[5]->NumberValue(context).ToChecked());
1952
+ auto dirtyHeight = static_cast<float>(args[6]->NumberValue(context).ToChecked());
1953
+ canvas_native_context_put_image_data(
1954
+ ptr->GetContext(),
1955
+ imageData->GetImageData(), dx,
1956
+ dy, dirtyX, dirtyY,
1957
+ dirtyWidth, dirtyHeight);
1958
+ ptr->UpdateInvalidateState();
1959
+ }
1960
+ }
1961
+ }
1962
+
1963
+ }
1964
+
1965
+ void
1966
+ CanvasRenderingContext2DImpl::QuadraticCurveTo(const v8::FunctionCallbackInfo<v8::Value> &args) {
1967
+ CanvasRenderingContext2DImpl *ptr = GetPointer(args.This());
1968
+
1969
+ auto isolate = args.GetIsolate();
1970
+ auto context = isolate->GetCurrentContext();
1971
+
1972
+ if (args.Length() == 4) {
1973
+ auto cpx = static_cast<float>(args[0]->NumberValue(context).ToChecked());
1974
+ auto cpy = static_cast<float>(args[1]->NumberValue(context).ToChecked());
1975
+ auto x = static_cast<float>(args[2]->NumberValue(context).ToChecked());
1976
+ auto y = static_cast<float>(args[3]->NumberValue(context).ToChecked());
1977
+ canvas_native_context_quadratic_curve_to(
1978
+ ptr->GetContext(), cpx, cpy,
1979
+ x, y);
1980
+ }
1981
+
1982
+ }
1983
+
1984
+ void
1985
+ CanvasRenderingContext2DImpl::RoundRect(const v8::FunctionCallbackInfo<v8::Value> &args) {
1986
+ CanvasRenderingContext2DImpl *ptr = GetPointer(args.This());
1987
+
1988
+ auto isolate = args.GetIsolate();
1989
+ auto context = isolate->GetCurrentContext();
1990
+
1991
+ if (args.Length() == 5) {
1992
+ auto x = static_cast<float>(args[0]->NumberValue(context).ToChecked());
1993
+ auto y = static_cast<float>(args[1]->NumberValue(context).ToChecked());
1994
+ auto width = static_cast<float>(args[2]->NumberValue(context).ToChecked());
1995
+ auto height = static_cast<float>(args[3]->NumberValue(context).ToChecked());
1996
+ if (args[4]->IsObject()) {
1997
+ auto radii = args[4];
1998
+ if (radii->IsArray()) {
1999
+ auto array = radii.As<v8::Array>();
2000
+ auto size = array->Length();
2001
+ if (size > 1) {
2002
+ std::vector<float> store;
2003
+ store.reserve(size);
2004
+ for (int i = 0;
2005
+ i < size; i++) {
2006
+ store[i] = (float) array->Get(
2007
+ context,
2008
+ i).ToLocalChecked()->NumberValue(context).ToChecked();
2009
+ }
2010
+
2011
+
2012
+ canvas_native_context_round_rect(
2013
+ ptr->GetContext(),
2014
+ x, y,
2015
+ width,
2016
+ height, store.data(), store.size());
2017
+
2018
+ }
2019
+ }
2020
+ } else {
2021
+ auto radii = (float) args[4]->NumberValue(context).ToChecked();
2022
+ canvas_native_context_round_rect_tl_tr_br_bl(
2023
+ ptr->GetContext(), x, y,
2024
+ width,
2025
+ height, radii, radii,
2026
+ radii, radii);
2027
+
2028
+ }
2029
+ }
2030
+
2031
+ }
2032
+
2033
+ void
2034
+ CanvasRenderingContext2DImpl::Rect(const v8::FunctionCallbackInfo<v8::Value> &args) {
2035
+ CanvasRenderingContext2DImpl *ptr = GetPointer(args.This());
2036
+
2037
+ auto isolate = args.GetIsolate();
2038
+ auto context = isolate->GetCurrentContext();
2039
+
2040
+ if (args.Length() == 4) {
2041
+ auto x = static_cast<float>(args[0]->NumberValue(context).ToChecked());
2042
+ auto y = static_cast<float>(args[1]->NumberValue(context).ToChecked());
2043
+ auto width = static_cast<float>(args[2]->NumberValue(context).ToChecked());
2044
+ auto height = static_cast<float>(args[3]->NumberValue(context).ToChecked());
2045
+ canvas_native_context_rect(
2046
+ ptr->GetContext(), x, y,
2047
+ width,
2048
+ height);
2049
+ }
2050
+
2051
+ }
2052
+
2053
+ void
2054
+ CanvasRenderingContext2DImpl::RemoveHitRegion(const v8::FunctionCallbackInfo<v8::Value> &args) {
2055
+ // CanvasRenderingContext2DImpl *ptr = GetPointer(args.This());
2056
+ }
2057
+
2058
+ void
2059
+ CanvasRenderingContext2DImpl::ResetTransform(const v8::FunctionCallbackInfo<v8::Value> &args) {
2060
+ CanvasRenderingContext2DImpl *ptr = GetPointer(args.This());
2061
+ if (ptr == nullptr) {
2062
+ return;
2063
+ }
2064
+
2065
+ canvas_native_context_reset_transform(
2066
+ ptr->GetContext());
2067
+ }
2068
+
2069
+ void
2070
+ CanvasRenderingContext2DImpl::Restore(const v8::FunctionCallbackInfo<v8::Value> &args) {
2071
+ CanvasRenderingContext2DImpl *ptr = GetPointer(args.This());
2072
+ if (ptr == nullptr) {
2073
+ return;
2074
+ }
2075
+
2076
+ canvas_native_context_restore(
2077
+ ptr->GetContext());
2078
+ }
2079
+
2080
+ void
2081
+ CanvasRenderingContext2DImpl::Rotate(const v8::FunctionCallbackInfo<v8::Value> &args) {
2082
+ CanvasRenderingContext2DImpl *ptr = GetPointer(args.This());
2083
+
2084
+ auto isolate = args.GetIsolate();
2085
+ auto context = isolate->GetCurrentContext();
2086
+
2087
+ auto value = args[0];
2088
+
2089
+ if (args.Length() == 1 && value->IsNumber()) {
2090
+ canvas_native_context_rotate(
2091
+ ptr->GetContext(),
2092
+ (float) args[0]->NumberValue(context).ToChecked());
2093
+ }
2094
+ }
2095
+
2096
+ void
2097
+ CanvasRenderingContext2DImpl::Save(const v8::FunctionCallbackInfo<v8::Value> &args) {
2098
+ CanvasRenderingContext2DImpl *ptr = GetPointer(args.This());
2099
+ if (ptr == nullptr) {
2100
+ return;
2101
+ }
2102
+
2103
+ canvas_native_context_save(
2104
+ ptr->GetContext());
2105
+ }
2106
+
2107
+ void
2108
+ CanvasRenderingContext2DImpl::Scale(const v8::FunctionCallbackInfo<v8::Value> &args) {
2109
+ CanvasRenderingContext2DImpl *ptr = GetPointer(args.This());
2110
+
2111
+ auto isolate = args.GetIsolate();
2112
+ auto context = isolate->GetCurrentContext();
2113
+
2114
+ if (args.Length() == 2) {
2115
+ auto x = static_cast<float>(args[0]->NumberValue(context).ToChecked());
2116
+ auto y = static_cast<float>(args[1]->NumberValue(context).ToChecked());
2117
+ canvas_native_context_scale(
2118
+ ptr->GetContext(), x, y);
2119
+ }
2120
+ }
2121
+
2122
+ void
2123
+ CanvasRenderingContext2DImpl::ScrollPathIntoView(const v8::FunctionCallbackInfo<v8::Value> &args) {
2124
+ // CanvasRenderingContext2DImpl *ptr = GetPointer(args.This());
2125
+ }
2126
+
2127
+ void
2128
+ CanvasRenderingContext2DImpl::SetLineDash(const v8::FunctionCallbackInfo<v8::Value> &args) {
2129
+ CanvasRenderingContext2DImpl *ptr = GetPointer(args.This());
2130
+
2131
+ auto isolate = args.GetIsolate();
2132
+ auto context = isolate->GetCurrentContext();
2133
+
2134
+ auto value = args[0];
2135
+
2136
+ if (args.Length() == 1 &&
2137
+ args[0]->IsObject()) {
2138
+ if (value->IsArray()) {
2139
+ auto segments = value.As<v8::Array>();
2140
+ auto len = segments->Length();
2141
+ std::vector<float> data;
2142
+ for (int i = 0; i < len; ++i) {
2143
+ auto item = segments->Get(
2144
+ context, i).ToLocalChecked()->NumberValue(context).ToChecked();
2145
+ data.push_back(
2146
+ static_cast<float>(item));
2147
+ }
2148
+
2149
+ canvas_native_context_set_line_dash(
2150
+ ptr->GetContext(), data.data(), data.size());
2151
+ }
2152
+ }
2153
+ }
2154
+
2155
+ void
2156
+ CanvasRenderingContext2DImpl::SetTransform(const v8::FunctionCallbackInfo<v8::Value> &args) {
2157
+ CanvasRenderingContext2DImpl *ptr = GetPointer(args.This());
2158
+
2159
+ auto isolate = args.GetIsolate();
2160
+ auto context = isolate->GetCurrentContext();
2161
+
2162
+ auto count = args.Length();
2163
+ auto value = args[0];
2164
+ if (count == 1 && value->IsObject()) {
2165
+
2166
+ auto typeValue = GetPrivateValue(isolate, value.As<v8::Object>(),
2167
+ ConvertToV8String(isolate, "__type"));
2168
+
2169
+ if (!typeValue.IsEmpty()) {
2170
+ auto type = (NativeType) typeValue->Int32Value(context).ToChecked();
2171
+
2172
+ if (type == NativeType::Matrix) {
2173
+ auto matrix = MatrixImpl::GetPointer(value.As<v8::Object>());
2174
+ if (matrix != nullptr) {
2175
+ canvas_native_context_set_transform_matrix(
2176
+ ptr->GetContext(),
2177
+ matrix->GetMatrix());
2178
+ }
2179
+ }
2180
+
2181
+ }
2182
+ } else if (count == 6) {
2183
+ auto a = static_cast<float>(args[0]->NumberValue(context).ToChecked());
2184
+ auto b = static_cast<float>(args[1]->NumberValue(context).ToChecked());
2185
+ auto c = static_cast<float>(args[2]->NumberValue(context).ToChecked());
2186
+ auto d = static_cast<float>(args[3]->NumberValue(context).ToChecked());
2187
+ auto e = static_cast<float>(args[4]->NumberValue(context).ToChecked());
2188
+ auto f = static_cast<float>(args[5]->NumberValue(context).ToChecked());
2189
+ canvas_native_context_set_transform(
2190
+ ptr->GetContext(), a, b, c, d,
2191
+ e,
2192
+ f);
2193
+ }
2194
+ }
2195
+
2196
+ void
2197
+ CanvasRenderingContext2DImpl::Stroke(const v8::FunctionCallbackInfo<v8::Value> &args) {
2198
+ CanvasRenderingContext2DImpl *ptr = GetPointer(args.This());
2199
+
2200
+ auto isolate = args.GetIsolate();
2201
+
2202
+ auto value = args[0];
2203
+ auto type = GetNativeType(isolate, value);
2204
+ if (type == NativeType::Path2D) {
2205
+ auto path = Path2D::GetPointer(value.As<v8::Object>());
2206
+ if (path != nullptr) {
2207
+ canvas_native_context_stroke_with_path(
2208
+ ptr->GetContext(),
2209
+ path->GetPath());
2210
+ ptr->UpdateInvalidateState();
2211
+ }
2212
+ } else {
2213
+ canvas_native_context_stroke(
2214
+ ptr->GetContext());
2215
+ ptr->UpdateInvalidateState();
2216
+ }
2217
+ }
2218
+
2219
+ void
2220
+ CanvasRenderingContext2DImpl::StrokeRect(const v8::FunctionCallbackInfo<v8::Value> &args) {
2221
+ CanvasRenderingContext2DImpl *ptr = GetPointer(args.This());
2222
+
2223
+ auto isolate = args.GetIsolate();
2224
+ auto context = isolate->GetCurrentContext();
2225
+
2226
+ if (args.Length() == 4) {
2227
+ auto x = static_cast<float>(args[0]->NumberValue(context).ToChecked());
2228
+ auto y = static_cast<float>(args[1]->NumberValue(context).ToChecked());
2229
+ auto width = static_cast<float>(args[2]->NumberValue(context).ToChecked());
2230
+ auto height = static_cast<float>(args[3]->NumberValue(context).ToChecked());
2231
+ canvas_native_context_stroke_rect(
2232
+ ptr->GetContext(), x, y,
2233
+ width,
2234
+ height);
2235
+ ptr->UpdateInvalidateState();
2236
+ }
2237
+ }
2238
+
2239
+ void
2240
+ CanvasRenderingContext2DImpl::StrokeText(const v8::FunctionCallbackInfo<v8::Value> &args) {
2241
+ CanvasRenderingContext2DImpl *ptr = GetPointer(args.This());
2242
+
2243
+ auto isolate = args.GetIsolate();
2244
+ auto context = isolate->GetCurrentContext();
2245
+
2246
+ auto count = args.Length();
2247
+ if (count >= 3) {
2248
+ auto text = ConvertFromV8String(isolate, args[0]);
2249
+ auto x = static_cast<float>(args[1]->NumberValue(context).ToChecked());
2250
+ auto y = static_cast<float>(args[2]->NumberValue(context).ToChecked());
2251
+ float maxWidth = -1;
2252
+
2253
+ if (count > 3) {
2254
+ maxWidth = static_cast<float>(args[3]->NumberValue(context).ToChecked());
2255
+ }
2256
+
2257
+ canvas_native_context_stroke_text(
2258
+ ptr->GetContext(), text.c_str(),
2259
+ x, y, maxWidth);
2260
+ ptr->UpdateInvalidateState();
2261
+ }
2262
+ }
2263
+
2264
+ void
2265
+ CanvasRenderingContext2DImpl::Transform(const v8::FunctionCallbackInfo<v8::Value> &args) {
2266
+ CanvasRenderingContext2DImpl *ptr = GetPointer(args.This());
2267
+
2268
+ auto isolate = args.GetIsolate();
2269
+ auto context = isolate->GetCurrentContext();
2270
+
2271
+
2272
+ if (args.Length() == 6) {
2273
+ auto a = static_cast<float>(args[0]->NumberValue(context).ToChecked());
2274
+ auto b = static_cast<float>(args[1]->NumberValue(context).ToChecked());
2275
+ auto c = static_cast<float>(args[2]->NumberValue(context).ToChecked());
2276
+ auto d = static_cast<float>(args[3]->NumberValue(context).ToChecked());
2277
+ auto e = static_cast<float>(args[4]->NumberValue(context).ToChecked());
2278
+ auto f = static_cast<float>(args[5]->NumberValue(context).ToChecked());
2279
+ canvas_native_context_transform(
2280
+ ptr->GetContext(), a, b, c, d,
2281
+ e,
2282
+ f);
2283
+ }
2284
+ }
2285
+
2286
+ void
2287
+ CanvasRenderingContext2DImpl::Translate(const v8::FunctionCallbackInfo<v8::Value> &args) {
2288
+ CanvasRenderingContext2DImpl *ptr = GetPointer(args.This());
2289
+
2290
+ auto isolate = args.GetIsolate();
2291
+ auto context = isolate->GetCurrentContext();
2292
+
2293
+
2294
+ if (args.Length() == 2) {
2295
+ auto x = static_cast<float>(args[0]->NumberValue(context).ToChecked());
2296
+ auto y = static_cast<float>(args[1]->NumberValue(context).ToChecked());
2297
+ canvas_native_context_translate(
2298
+ ptr->GetContext(), x, y);
2299
+ }
2300
+ }
2301
+
2302
+ void
2303
+ CanvasRenderingContext2DImpl::__ToDataURL(const v8::FunctionCallbackInfo<v8::Value> &args) {
2304
+ CanvasRenderingContext2DImpl *ptr = GetPointer(args.This());
2305
+
2306
+ auto isolate = args.GetIsolate();
2307
+ auto context = isolate->GetCurrentContext();
2308
+
2309
+
2310
+ std::string type("image/png");
2311
+ int quality = 92;
2312
+ if (args[0]->IsString()) {
2313
+ type = ConvertFromV8String(isolate, args[0]);
2314
+ }
2315
+
2316
+
2317
+ if (args[1]->IsNumber()) {
2318
+ quality = (int) args[1]->NumberValue(context).ToChecked();
2319
+ }
2320
+
2321
+
2322
+ auto data = canvas_native_to_data_url(
2323
+ ptr->GetContext(), type.c_str(),
2324
+ quality);
2325
+
2326
+ auto value = new OneByteStringResource((char*)data);
2327
+ auto ret = v8::String::NewExternalOneByte(isolate, value);
2328
+ args.GetReturnValue().Set(ret.ToLocalChecked());
2329
+
2330
+ // args.GetReturnValue().Set(ConvertToV8String(isolate, data.c_str()));
2331
+ }
2332
+
2333
+ CanvasRenderingContext2DImpl::~CanvasRenderingContext2DImpl() {
2334
+ auto raf = this->raf_.get();
2335
+ if (raf != nullptr) {
2336
+ canvas_native_raf_stop(raf->GetRaf());
2337
+ }
2338
+
2339
+ canvas_native_context_destroy(this->GetContext());
2340
+ this->context_ = nullptr;
2341
+ }
2342
+
2343
+ void CanvasRenderingContext2DImpl::UpdateInvalidateState() {
2344
+ auto raf = this->GetRaf();
2345
+ if (raf != nullptr) {
2346
+ if (!canvas_native_raf_get_started(raf->GetRaf())) {
2347
+ canvas_native_raf_start(raf->GetRaf());
2348
+ }
2349
+ }
2350
+
2351
+ auto state = this->GetInvalidateState();
2352
+ this->SetInvalidateState((int) state | (int) InvalidateState::InvalidateStatePending);
2353
+ }
2354
+
2355
+ InvalidateState CanvasRenderingContext2DImpl::GetInvalidateState() const {
2356
+ return (InvalidateState)
2357
+ this->invalidateState_;
2358
+ }
2359
+
2360
+ void CanvasRenderingContext2DImpl::SetInvalidateState(InvalidateState state) {
2361
+ this->invalidateState_ = (int) state;
2362
+ }
2363
+
2364
+ void CanvasRenderingContext2DImpl::SetInvalidateState(int state) {
2365
+ this->invalidateState_ = state;
2366
+ }
2367
+
2368
+
2369
+ void CanvasRenderingContext2DImpl::Flush() {
2370
+ auto state = (int) this->GetInvalidateState() & (int) InvalidateState::InvalidateStatePending;
2371
+ if (state == (int) InvalidateState::InvalidateStatePending) {
2372
+ this->SetInvalidateState(InvalidateState::InvalidateStateInvalidating);
2373
+ // canvas_native_context_flush(ptr->GetContext());
2374
+ canvas_native_context_render(this->GetContext());
2375
+ // canvas_native_context_gl_make_current(ptr->GetContext());
2376
+ // canvas_native_context_gl_swap_buffers(ptr->GetContext());
2377
+ this->SetInvalidateState(InvalidateState::InvalidateStateNone);
2378
+ }
2379
+ }
2380
+
2381
+ void CanvasRenderingContext2DImpl::Flush(intptr_t context) {
2382
+ auto ctx = reinterpret_cast<CanvasRenderingContext2DImpl *>(reinterpret_cast<intptr_t *>(context));
2383
+ if (ctx != nullptr) {
2384
+ ctx->Flush();
2385
+ }
2386
+ }
2387
+
2388
+
2389
+ CanvasRenderingContext2D* CanvasRenderingContext2DImpl::GetContext() {
2390
+ return this->context_;
2391
+ }