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

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