@shopify/react-native-skia 0.1.172 → 0.1.174

Sign up to get free protection for your applications and to get access to all the features.
Files changed (324) hide show
  1. package/android/CMakeLists.txt +1 -0
  2. package/android/cpp/rnskia-android/RNSkAndroidPlatformContext.h +5 -0
  3. package/android/cpp/rnskia-android/SkiaOpenGLRenderer.cpp +106 -5
  4. package/android/cpp/rnskia-android/SkiaOpenGLRenderer.h +3 -1
  5. package/cpp/api/JsiSkSurface.h +7 -1
  6. package/cpp/api/JsiSkSurfaceFactory.h +15 -2
  7. package/cpp/rnskia/RNSkDomView.cpp +2 -4
  8. package/cpp/rnskia/RNSkJsView.cpp +3 -0
  9. package/cpp/rnskia/RNSkPictureView.h +3 -0
  10. package/cpp/rnskia/RNSkPlatformContext.h +9 -0
  11. package/cpp/rnskia/dom/JsiDomApi.h +1 -0
  12. package/cpp/rnskia/dom/base/ConcatablePaint.cpp +117 -0
  13. package/cpp/rnskia/dom/base/ConcatablePaint.h +49 -0
  14. package/cpp/rnskia/dom/base/Declaration.h +88 -0
  15. package/cpp/rnskia/dom/base/DeclarationContext.h +79 -0
  16. package/cpp/rnskia/dom/base/DerivedNodeProp.h +25 -9
  17. package/cpp/rnskia/dom/base/DrawingContext.cpp +32 -186
  18. package/cpp/rnskia/dom/base/DrawingContext.h +45 -64
  19. package/cpp/rnskia/dom/base/JsiDomDeclarationNode.h +35 -106
  20. package/cpp/rnskia/dom/base/JsiDomDrawingNode.h +28 -9
  21. package/cpp/rnskia/dom/base/JsiDomNode.h +46 -17
  22. package/cpp/rnskia/dom/base/JsiDomRenderNode.h +81 -67
  23. package/cpp/rnskia/dom/base/NodeProp.h +12 -2
  24. package/cpp/rnskia/dom/base/NodePropsContainer.h +15 -16
  25. package/cpp/rnskia/dom/nodes/JsiBackdropFilterNode.h +22 -11
  26. package/cpp/rnskia/dom/nodes/JsiBlendNode.h +43 -59
  27. package/cpp/rnskia/dom/nodes/JsiBlurMaskNode.h +16 -17
  28. package/cpp/rnskia/dom/nodes/JsiBoxShadowNode.h +6 -5
  29. package/cpp/rnskia/dom/nodes/JsiColorFilterNodes.h +45 -69
  30. package/cpp/rnskia/dom/nodes/JsiGroupNode.h +1 -1
  31. package/cpp/rnskia/dom/nodes/JsiImageFilterNodes.h +121 -161
  32. package/cpp/rnskia/dom/nodes/JsiImageNode.h +1 -0
  33. package/cpp/rnskia/dom/nodes/JsiLayerNode.h +28 -18
  34. package/cpp/rnskia/dom/nodes/JsiPaintNode.h +82 -45
  35. package/cpp/rnskia/dom/nodes/JsiPathEffectNodes.h +68 -101
  36. package/cpp/rnskia/dom/nodes/JsiPathNode.h +3 -2
  37. package/cpp/rnskia/dom/nodes/JsiShaderNodes.h +150 -207
  38. package/cpp/rnskia/dom/props/BezierProps.h +4 -2
  39. package/cpp/rnskia/dom/props/BlendModeProp.h +4 -2
  40. package/cpp/rnskia/dom/props/BoxShadowProps.h +8 -10
  41. package/cpp/rnskia/dom/props/CircleProp.h +6 -5
  42. package/cpp/rnskia/dom/props/ClipProp.h +6 -4
  43. package/cpp/rnskia/dom/props/ColorProp.h +8 -4
  44. package/cpp/rnskia/dom/props/DrawingProp.h +5 -3
  45. package/cpp/rnskia/dom/props/FontProp.h +4 -2
  46. package/cpp/rnskia/dom/props/GlyphsProp.h +4 -2
  47. package/cpp/rnskia/dom/props/ImageProps.h +9 -6
  48. package/cpp/rnskia/dom/props/LayerProp.h +6 -4
  49. package/cpp/rnskia/dom/props/MatrixProp.h +4 -2
  50. package/cpp/rnskia/dom/props/NumbersProp.h +8 -4
  51. package/cpp/rnskia/dom/props/PaintProps.h +55 -92
  52. package/cpp/rnskia/dom/props/PathProp.h +4 -2
  53. package/cpp/rnskia/dom/props/PictureProp.h +4 -2
  54. package/cpp/rnskia/dom/props/PointProp.h +4 -2
  55. package/cpp/rnskia/dom/props/PointsProp.h +8 -4
  56. package/cpp/rnskia/dom/props/RRectProp.h +23 -16
  57. package/cpp/rnskia/dom/props/RadiusProp.h +4 -2
  58. package/cpp/rnskia/dom/props/RectProp.h +18 -12
  59. package/cpp/rnskia/dom/props/StrokeProps.h +8 -4
  60. package/cpp/rnskia/dom/props/SvgProp.h +4 -2
  61. package/cpp/rnskia/dom/props/TextBlobProp.h +10 -8
  62. package/cpp/rnskia/dom/props/TileModeProp.h +4 -2
  63. package/cpp/rnskia/dom/props/TransformProp.h +4 -2
  64. package/cpp/rnskia/dom/props/TransformsProps.h +5 -7
  65. package/cpp/rnskia/dom/props/UniformsProp.h +4 -2
  66. package/cpp/rnskia/dom/props/VertexModeProp.h +4 -2
  67. package/cpp/rnskia/dom/props/VerticesProps.h +7 -11
  68. package/ios/RNSkia-iOS/DisplayLink.mm +22 -24
  69. package/ios/RNSkia-iOS/RNSkMetalCanvasProvider.mm +53 -50
  70. package/ios/RNSkia-iOS/RNSkiOSPlatformContext.h +2 -0
  71. package/ios/RNSkia-iOS/RNSkiOSPlatformContext.mm +56 -25
  72. package/ios/RNSkia-iOS/SkiaDomViewManager.mm +17 -17
  73. package/ios/RNSkia-iOS/SkiaDrawViewManager.mm +17 -17
  74. package/ios/RNSkia-iOS/SkiaManager.mm +12 -10
  75. package/ios/RNSkia-iOS/SkiaMetalRenderer.h +5 -0
  76. package/ios/RNSkia-iOS/SkiaMetalRenderer.mm +53 -0
  77. package/ios/RNSkia-iOS/SkiaPictureViewManager.mm +17 -17
  78. package/ios/RNSkia-iOS/SkiaUIView.mm +63 -53
  79. package/ios/RNSkiaModule.mm +5 -7
  80. package/lib/commonjs/dom/nodes/DrawingNode.js +5 -1
  81. package/lib/commonjs/dom/nodes/DrawingNode.js.map +1 -1
  82. package/lib/commonjs/dom/nodes/JsiSkDOM.d.ts +33 -34
  83. package/lib/commonjs/dom/nodes/LayerNode.js +13 -6
  84. package/lib/commonjs/dom/nodes/LayerNode.js.map +1 -1
  85. package/lib/commonjs/dom/nodes/Node.d.ts +6 -11
  86. package/lib/commonjs/dom/nodes/Node.js +8 -26
  87. package/lib/commonjs/dom/nodes/Node.js.map +1 -1
  88. package/lib/commonjs/dom/nodes/PaintContext.js.map +1 -1
  89. package/lib/commonjs/dom/nodes/PaintNode.d.ts +3 -3
  90. package/lib/commonjs/dom/nodes/PaintNode.js +32 -15
  91. package/lib/commonjs/dom/nodes/PaintNode.js.map +1 -1
  92. package/lib/commonjs/dom/nodes/RenderNode.d.ts +2 -3
  93. package/lib/commonjs/dom/nodes/RenderNode.js +19 -187
  94. package/lib/commonjs/dom/nodes/RenderNode.js.map +1 -1
  95. package/lib/commonjs/dom/nodes/drawings/BackdropFilterNode.d.ts +1 -1
  96. package/lib/commonjs/dom/nodes/drawings/BackdropFilterNode.js +25 -7
  97. package/lib/commonjs/dom/nodes/drawings/BackdropFilterNode.js.map +1 -1
  98. package/lib/commonjs/dom/nodes/drawings/Box.d.ts +3 -1
  99. package/lib/commonjs/dom/nodes/drawings/Box.js +3 -0
  100. package/lib/commonjs/dom/nodes/drawings/Box.js.map +1 -1
  101. package/lib/commonjs/dom/nodes/paint/BlendNode.d.ts +3 -7
  102. package/lib/commonjs/dom/nodes/paint/BlendNode.js +16 -47
  103. package/lib/commonjs/dom/nodes/paint/BlendNode.js.map +1 -1
  104. package/lib/commonjs/dom/nodes/paint/ColorFilters.d.ts +10 -11
  105. package/lib/commonjs/dom/nodes/paint/ColorFilters.js +29 -43
  106. package/lib/commonjs/dom/nodes/paint/ColorFilters.js.map +1 -1
  107. package/lib/commonjs/dom/nodes/paint/ImageFilters.d.ts +11 -11
  108. package/lib/commonjs/dom/nodes/paint/ImageFilters.js +45 -42
  109. package/lib/commonjs/dom/nodes/paint/ImageFilters.js.map +1 -1
  110. package/lib/commonjs/dom/nodes/paint/MaskFilters.d.ts +3 -3
  111. package/lib/commonjs/dom/nodes/paint/MaskFilters.js +3 -2
  112. package/lib/commonjs/dom/nodes/paint/MaskFilters.js.map +1 -1
  113. package/lib/commonjs/dom/nodes/paint/PathEffects.d.ts +15 -18
  114. package/lib/commonjs/dom/nodes/paint/PathEffects.js +30 -72
  115. package/lib/commonjs/dom/nodes/paint/PathEffects.js.map +1 -1
  116. package/lib/commonjs/dom/nodes/paint/Shaders.d.ts +11 -12
  117. package/lib/commonjs/dom/nodes/paint/Shaders.js +28 -18
  118. package/lib/commonjs/dom/nodes/paint/Shaders.js.map +1 -1
  119. package/lib/commonjs/dom/types/DeclarationContext.d.ts +29 -0
  120. package/lib/commonjs/dom/types/DeclarationContext.js +118 -0
  121. package/lib/commonjs/dom/types/DeclarationContext.js.map +1 -0
  122. package/lib/commonjs/dom/types/DrawingContext.d.ts +18 -1
  123. package/lib/commonjs/dom/types/DrawingContext.js +330 -0
  124. package/lib/commonjs/dom/types/DrawingContext.js.map +1 -1
  125. package/lib/commonjs/dom/types/Node.d.ts +4 -10
  126. package/lib/commonjs/dom/types/Node.js.map +1 -1
  127. package/lib/commonjs/dom/types/SkDOM.d.ts +22 -23
  128. package/lib/commonjs/dom/types/SkDOM.js.map +1 -1
  129. package/lib/commonjs/dom/types/index.d.ts +1 -0
  130. package/lib/commonjs/dom/types/index.js +13 -0
  131. package/lib/commonjs/dom/types/index.js.map +1 -1
  132. package/lib/commonjs/index.d.ts +1 -0
  133. package/lib/commonjs/index.js +13 -0
  134. package/lib/commonjs/index.js.map +1 -1
  135. package/lib/commonjs/renderer/Canvas.js +3 -3
  136. package/lib/commonjs/renderer/Canvas.js.map +1 -1
  137. package/lib/commonjs/renderer/DrawingContext.d.ts +4 -3
  138. package/lib/commonjs/renderer/DrawingContext.js.map +1 -1
  139. package/lib/commonjs/renderer/HostComponents.d.ts +35 -35
  140. package/lib/commonjs/renderer/HostComponents.js.map +1 -1
  141. package/lib/commonjs/renderer/HostConfig.js +1 -0
  142. package/lib/commonjs/renderer/HostConfig.js.map +1 -1
  143. package/lib/commonjs/renderer/Offscreen.d.ts +2 -0
  144. package/lib/commonjs/renderer/Offscreen.js +31 -0
  145. package/lib/commonjs/renderer/Offscreen.js.map +1 -0
  146. package/lib/commonjs/renderer/Reconciler.js +0 -1
  147. package/lib/commonjs/renderer/Reconciler.js.map +1 -1
  148. package/lib/commonjs/skia/types/Surface/Surface.d.ts +4 -0
  149. package/lib/commonjs/skia/types/Surface/Surface.js.map +1 -1
  150. package/lib/commonjs/skia/types/Surface/SurfaceFactory.d.ts +6 -0
  151. package/lib/commonjs/skia/types/Surface/SurfaceFactory.js.map +1 -1
  152. package/lib/commonjs/skia/web/JsiSkDataFactory.js +0 -1
  153. package/lib/commonjs/skia/web/JsiSkDataFactory.js.map +1 -1
  154. package/lib/commonjs/skia/web/JsiSkImage.d.ts +1 -0
  155. package/lib/commonjs/skia/web/JsiSkImage.js +34 -3
  156. package/lib/commonjs/skia/web/JsiSkImage.js.map +1 -1
  157. package/lib/commonjs/skia/web/JsiSkSurface.d.ts +1 -0
  158. package/lib/commonjs/skia/web/JsiSkSurface.js +4 -0
  159. package/lib/commonjs/skia/web/JsiSkSurface.js.map +1 -1
  160. package/lib/commonjs/skia/web/JsiSkSurfaceFactory.d.ts +2 -1
  161. package/lib/commonjs/skia/web/JsiSkSurfaceFactory.js +21 -1
  162. package/lib/commonjs/skia/web/JsiSkSurfaceFactory.js.map +1 -1
  163. package/lib/commonjs/views/SkiaBaseWebView.js +14 -8
  164. package/lib/commonjs/views/SkiaBaseWebView.js.map +1 -1
  165. package/lib/commonjs/views/SkiaDomView.web.js +3 -14
  166. package/lib/commonjs/views/SkiaDomView.web.js.map +1 -1
  167. package/lib/commonjs/views/SkiaPictureView.web.js +0 -7
  168. package/lib/commonjs/views/SkiaPictureView.web.js.map +1 -1
  169. package/lib/commonjs/views/SkiaView.web.js +0 -7
  170. package/lib/commonjs/views/SkiaView.web.js.map +1 -1
  171. package/lib/module/dom/nodes/DrawingNode.js +5 -1
  172. package/lib/module/dom/nodes/DrawingNode.js.map +1 -1
  173. package/lib/module/dom/nodes/JsiSkDOM.d.ts +33 -34
  174. package/lib/module/dom/nodes/LayerNode.js +13 -7
  175. package/lib/module/dom/nodes/LayerNode.js.map +1 -1
  176. package/lib/module/dom/nodes/Node.d.ts +6 -11
  177. package/lib/module/dom/nodes/Node.js +8 -25
  178. package/lib/module/dom/nodes/Node.js.map +1 -1
  179. package/lib/module/dom/nodes/PaintContext.js.map +1 -1
  180. package/lib/module/dom/nodes/PaintNode.d.ts +3 -3
  181. package/lib/module/dom/nodes/PaintNode.js +32 -15
  182. package/lib/module/dom/nodes/PaintNode.js.map +1 -1
  183. package/lib/module/dom/nodes/RenderNode.d.ts +2 -3
  184. package/lib/module/dom/nodes/RenderNode.js +20 -187
  185. package/lib/module/dom/nodes/RenderNode.js.map +1 -1
  186. package/lib/module/dom/nodes/drawings/BackdropFilterNode.d.ts +1 -1
  187. package/lib/module/dom/nodes/drawings/BackdropFilterNode.js +23 -4
  188. package/lib/module/dom/nodes/drawings/BackdropFilterNode.js.map +1 -1
  189. package/lib/module/dom/nodes/drawings/Box.d.ts +3 -1
  190. package/lib/module/dom/nodes/drawings/Box.js +3 -0
  191. package/lib/module/dom/nodes/drawings/Box.js.map +1 -1
  192. package/lib/module/dom/nodes/paint/BlendNode.d.ts +3 -7
  193. package/lib/module/dom/nodes/paint/BlendNode.js +15 -46
  194. package/lib/module/dom/nodes/paint/BlendNode.js.map +1 -1
  195. package/lib/module/dom/nodes/paint/ColorFilters.d.ts +10 -11
  196. package/lib/module/dom/nodes/paint/ColorFilters.js +29 -43
  197. package/lib/module/dom/nodes/paint/ColorFilters.js.map +1 -1
  198. package/lib/module/dom/nodes/paint/ImageFilters.d.ts +11 -11
  199. package/lib/module/dom/nodes/paint/ImageFilters.js +48 -41
  200. package/lib/module/dom/nodes/paint/ImageFilters.js.map +1 -1
  201. package/lib/module/dom/nodes/paint/MaskFilters.d.ts +3 -3
  202. package/lib/module/dom/nodes/paint/MaskFilters.js +3 -2
  203. package/lib/module/dom/nodes/paint/MaskFilters.js.map +1 -1
  204. package/lib/module/dom/nodes/paint/PathEffects.d.ts +15 -18
  205. package/lib/module/dom/nodes/paint/PathEffects.js +29 -72
  206. package/lib/module/dom/nodes/paint/PathEffects.js.map +1 -1
  207. package/lib/module/dom/nodes/paint/Shaders.d.ts +11 -12
  208. package/lib/module/dom/nodes/paint/Shaders.js +28 -18
  209. package/lib/module/dom/nodes/paint/Shaders.js.map +1 -1
  210. package/lib/module/dom/types/DeclarationContext.d.ts +29 -0
  211. package/lib/module/dom/types/DeclarationContext.js +107 -0
  212. package/lib/module/dom/types/DeclarationContext.js.map +1 -0
  213. package/lib/module/dom/types/DrawingContext.d.ts +18 -1
  214. package/lib/module/dom/types/DrawingContext.js +322 -1
  215. package/lib/module/dom/types/DrawingContext.js.map +1 -1
  216. package/lib/module/dom/types/Node.d.ts +4 -10
  217. package/lib/module/dom/types/Node.js.map +1 -1
  218. package/lib/module/dom/types/SkDOM.d.ts +22 -23
  219. package/lib/module/dom/types/SkDOM.js.map +1 -1
  220. package/lib/module/dom/types/index.d.ts +1 -0
  221. package/lib/module/dom/types/index.js +1 -0
  222. package/lib/module/dom/types/index.js.map +1 -1
  223. package/lib/module/index.d.ts +1 -0
  224. package/lib/module/index.js +1 -0
  225. package/lib/module/index.js.map +1 -1
  226. package/lib/module/renderer/Canvas.js +3 -3
  227. package/lib/module/renderer/Canvas.js.map +1 -1
  228. package/lib/module/renderer/DrawingContext.d.ts +4 -3
  229. package/lib/module/renderer/DrawingContext.js.map +1 -1
  230. package/lib/module/renderer/HostComponents.d.ts +35 -35
  231. package/lib/module/renderer/HostComponents.js.map +1 -1
  232. package/lib/module/renderer/HostConfig.js +1 -0
  233. package/lib/module/renderer/HostConfig.js.map +1 -1
  234. package/lib/module/renderer/Offscreen.d.ts +2 -0
  235. package/lib/module/renderer/Offscreen.js +19 -0
  236. package/lib/module/renderer/Offscreen.js.map +1 -0
  237. package/lib/module/renderer/Reconciler.js +0 -1
  238. package/lib/module/renderer/Reconciler.js.map +1 -1
  239. package/lib/module/skia/types/Surface/Surface.d.ts +4 -0
  240. package/lib/module/skia/types/Surface/Surface.js.map +1 -1
  241. package/lib/module/skia/types/Surface/SurfaceFactory.d.ts +6 -0
  242. package/lib/module/skia/types/Surface/SurfaceFactory.js.map +1 -1
  243. package/lib/module/skia/web/JsiSkDataFactory.js +0 -1
  244. package/lib/module/skia/web/JsiSkDataFactory.js.map +1 -1
  245. package/lib/module/skia/web/JsiSkImage.d.ts +1 -0
  246. package/lib/module/skia/web/JsiSkImage.js +31 -3
  247. package/lib/module/skia/web/JsiSkImage.js.map +1 -1
  248. package/lib/module/skia/web/JsiSkSurface.d.ts +1 -0
  249. package/lib/module/skia/web/JsiSkSurface.js +4 -0
  250. package/lib/module/skia/web/JsiSkSurface.js.map +1 -1
  251. package/lib/module/skia/web/JsiSkSurfaceFactory.d.ts +2 -1
  252. package/lib/module/skia/web/JsiSkSurfaceFactory.js +21 -1
  253. package/lib/module/skia/web/JsiSkSurfaceFactory.js.map +1 -1
  254. package/lib/module/views/SkiaBaseWebView.js +14 -8
  255. package/lib/module/views/SkiaBaseWebView.js.map +1 -1
  256. package/lib/module/views/SkiaDomView.web.js +2 -11
  257. package/lib/module/views/SkiaDomView.web.js.map +1 -1
  258. package/lib/module/views/SkiaPictureView.web.js +0 -5
  259. package/lib/module/views/SkiaPictureView.web.js.map +1 -1
  260. package/lib/module/views/SkiaView.web.js +0 -5
  261. package/lib/module/views/SkiaView.web.js.map +1 -1
  262. package/lib/typescript/src/dom/nodes/JsiSkDOM.d.ts +33 -34
  263. package/lib/typescript/src/dom/nodes/Node.d.ts +6 -11
  264. package/lib/typescript/src/dom/nodes/PaintNode.d.ts +3 -3
  265. package/lib/typescript/src/dom/nodes/RenderNode.d.ts +2 -3
  266. package/lib/typescript/src/dom/nodes/drawings/BackdropFilterNode.d.ts +1 -1
  267. package/lib/typescript/src/dom/nodes/drawings/Box.d.ts +3 -1
  268. package/lib/typescript/src/dom/nodes/paint/BlendNode.d.ts +3 -7
  269. package/lib/typescript/src/dom/nodes/paint/ColorFilters.d.ts +10 -11
  270. package/lib/typescript/src/dom/nodes/paint/ImageFilters.d.ts +11 -11
  271. package/lib/typescript/src/dom/nodes/paint/MaskFilters.d.ts +3 -3
  272. package/lib/typescript/src/dom/nodes/paint/PathEffects.d.ts +15 -18
  273. package/lib/typescript/src/dom/nodes/paint/Shaders.d.ts +11 -12
  274. package/lib/typescript/src/dom/types/DeclarationContext.d.ts +29 -0
  275. package/lib/typescript/src/dom/types/DrawingContext.d.ts +18 -1
  276. package/lib/typescript/src/dom/types/Node.d.ts +4 -10
  277. package/lib/typescript/src/dom/types/SkDOM.d.ts +22 -23
  278. package/lib/typescript/src/dom/types/index.d.ts +1 -0
  279. package/lib/typescript/src/index.d.ts +1 -0
  280. package/lib/typescript/src/renderer/DrawingContext.d.ts +4 -3
  281. package/lib/typescript/src/renderer/HostComponents.d.ts +35 -35
  282. package/lib/typescript/src/renderer/Offscreen.d.ts +2 -0
  283. package/lib/typescript/src/skia/types/Surface/Surface.d.ts +4 -0
  284. package/lib/typescript/src/skia/types/Surface/SurfaceFactory.d.ts +6 -0
  285. package/lib/typescript/src/skia/web/JsiSkImage.d.ts +1 -0
  286. package/lib/typescript/src/skia/web/JsiSkSurface.d.ts +1 -0
  287. package/lib/typescript/src/skia/web/JsiSkSurfaceFactory.d.ts +2 -1
  288. package/package.json +1 -1
  289. package/src/dom/nodes/DrawingNode.ts +5 -1
  290. package/src/dom/nodes/LayerNode.ts +13 -11
  291. package/src/dom/nodes/Node.ts +18 -41
  292. package/src/dom/nodes/PaintContext.ts +1 -0
  293. package/src/dom/nodes/PaintNode.ts +28 -18
  294. package/src/dom/nodes/RenderNode.ts +25 -183
  295. package/src/dom/nodes/drawings/BackdropFilterNode.ts +18 -11
  296. package/src/dom/nodes/drawings/Box.ts +6 -4
  297. package/src/dom/nodes/paint/BlendNode.ts +16 -63
  298. package/src/dom/nodes/paint/ColorFilters.ts +32 -55
  299. package/src/dom/nodes/paint/ImageFilters.ts +58 -53
  300. package/src/dom/nodes/paint/MaskFilters.ts +5 -7
  301. package/src/dom/nodes/paint/PathEffects.ts +37 -90
  302. package/src/dom/nodes/paint/Shaders.ts +31 -29
  303. package/src/dom/types/DeclarationContext.ts +105 -0
  304. package/src/dom/types/DrawingContext.ts +304 -1
  305. package/src/dom/types/Node.ts +4 -20
  306. package/src/dom/types/SkDOM.ts +22 -43
  307. package/src/dom/types/index.ts +1 -0
  308. package/src/index.ts +1 -0
  309. package/src/renderer/Canvas.tsx +3 -3
  310. package/src/renderer/DrawingContext.ts +4 -5
  311. package/src/renderer/HostComponents.ts +34 -53
  312. package/src/renderer/HostConfig.ts +1 -0
  313. package/src/renderer/Offscreen.tsx +24 -0
  314. package/src/renderer/Reconciler.tsx +0 -1
  315. package/src/skia/types/Surface/Surface.ts +5 -0
  316. package/src/skia/types/Surface/SurfaceFactory.ts +7 -0
  317. package/src/skia/web/JsiSkDataFactory.ts +0 -1
  318. package/src/skia/web/JsiSkImage.ts +26 -2
  319. package/src/skia/web/JsiSkSurface.ts +4 -0
  320. package/src/skia/web/JsiSkSurfaceFactory.ts +21 -2
  321. package/src/views/SkiaBaseWebView.tsx +9 -2
  322. package/src/views/SkiaDomView.web.tsx +2 -13
  323. package/src/views/SkiaPictureView.web.tsx +0 -7
  324. package/src/views/SkiaView.web.tsx +0 -7
@@ -22,49 +22,27 @@
22
22
 
23
23
  namespace RNSkia {
24
24
 
25
- class JsiBaseImageFilterNode
26
- : public JsiDomDeclarationNode<JsiBaseImageFilterNode,
27
- sk_sp<SkImageFilter>> {
25
+ class JsiBaseImageFilterNode : public JsiDomDeclarationNode {
28
26
  public:
29
27
  JsiBaseImageFilterNode(std::shared_ptr<RNSkPlatformContext> context,
30
28
  const char *type)
31
- : JsiDomDeclarationNode<JsiBaseImageFilterNode, sk_sp<SkImageFilter>>(
32
- context, type) {}
29
+ : JsiDomDeclarationNode(context, type, DeclarationType::ImageFilter) {}
33
30
 
34
31
  protected:
35
- sk_sp<SkImageFilter> resolve(std::shared_ptr<JsiDomNode> child) override {
36
- auto imageFilterPtr =
37
- std::dynamic_pointer_cast<JsiBaseImageFilterNode>(child);
38
- if (imageFilterPtr) {
39
- return imageFilterPtr->getCurrent();
32
+ void composeAndPush(DeclarationContext *context, sk_sp<SkImageFilter> imgf1) {
33
+ context->save();
34
+ decorateChildren(context);
35
+ auto imgf2 = context->getImageFilters()->popAsOne();
36
+ auto cf = context->getColorFilters()->popAsOne();
37
+ context->restore();
38
+ if (cf != nullptr) {
39
+ imgf2 = SkImageFilters::Compose(imgf2,
40
+ SkImageFilters::ColorFilter(cf, nullptr));
40
41
  }
41
- auto shaderPtr = std::dynamic_pointer_cast<JsiBaseShaderNode>(child);
42
- if (shaderPtr) {
43
- return SkImageFilters::Shader(shaderPtr->getCurrent());
44
- }
45
- auto colorFilterPtr =
46
- std::dynamic_pointer_cast<JsiBaseColorFilterNode>(child);
47
- if (colorFilterPtr) {
48
- return SkImageFilters::ColorFilter(colorFilterPtr->getCurrent(), nullptr);
49
- }
50
- return nullptr;
51
- }
42
+ auto imgf =
43
+ imgf2 != nullptr ? SkImageFilters::Compose(imgf1, imgf2) : imgf1;
52
44
 
53
- void setImageFilter(DrawingContext *context, sk_sp<SkImageFilter> f) {
54
- set(context, f);
55
- }
56
-
57
- void set(DrawingContext *context, sk_sp<SkImageFilter> imageFilter) override {
58
- auto paint = context->getMutablePaint();
59
- if (paint->getImageFilter() != nullptr &&
60
- paint->getImageFilter() != getCurrent().get()) {
61
- paint->setImageFilter(
62
- SkImageFilters::Compose(paint->refImageFilter(), imageFilter));
63
- } else {
64
- paint->setImageFilter(imageFilter);
65
- }
66
-
67
- setCurrent(imageFilter);
45
+ context->getImageFilters()->push(imgf);
68
46
  }
69
47
  };
70
48
 
@@ -74,26 +52,23 @@ public:
74
52
  explicit JsiBlendImageFilterNode(std::shared_ptr<RNSkPlatformContext> context)
75
53
  : JsiBaseImageFilterNode(context, "skBlendImageFilter") {}
76
54
 
77
- protected:
78
- void decorate(DrawingContext *context) override {
79
-
80
- if (isChanged(context)) {
55
+ void decorate(DeclarationContext *context) override {
81
56
 
82
- if (getChildren().size() != 2) {
83
- throw std::runtime_error("Blend image filter needs two child nodes.");
84
- }
57
+ if (getChildren().size() != 2) {
58
+ throw std::runtime_error("Blend image filter needs two child nodes.");
59
+ }
85
60
 
86
- auto background = requireChild(0);
87
- auto foreground = requireChild(1);
61
+ auto background = context->getImageFilters()->pop();
62
+ auto foreground = context->getImageFilters()->pop();
88
63
 
89
- SkBlendMode blendMode = *_blendModeProp->getDerivedValue();
90
- setImageFilter(context,
91
- SkImageFilters::Blend(blendMode, background, foreground));
92
- }
64
+ SkBlendMode blendMode = *_blendModeProp->getDerivedValue();
65
+ composeAndPush(context,
66
+ SkImageFilters::Blend(blendMode, background, foreground));
93
67
  }
94
68
 
69
+ protected:
95
70
  void defineProperties(NodePropsContainer *container) override {
96
- JsiBaseDomDeclarationNode::defineProperties(container);
71
+ JsiDomDeclarationNode::defineProperties(container);
97
72
  _blendModeProp = container->defineProperty<BlendModeProp>("mode");
98
73
  _blendModeProp->require();
99
74
  }
@@ -110,49 +85,47 @@ public:
110
85
  std::shared_ptr<RNSkPlatformContext> context)
111
86
  : JsiBaseImageFilterNode(context, "skDropShadowImageFilter") {}
112
87
 
113
- protected:
114
- void decorate(DrawingContext *context) override {
115
- if (isChanged(context)) {
116
- auto color = _colorProp->getDerivedValue();
117
- auto dx = _dxProp->value().getAsNumber();
118
- auto dy = _dxProp->value().getAsNumber();
119
- auto blur = _blurProp->value().getAsNumber();
120
- auto input = optionalChild(0);
121
-
122
- auto inner = _innerProp->isSet() && _innerProp->value().getAsBool();
123
- auto shadowOnly =
124
- _shadowOnlyProp->isSet() && _shadowOnlyProp->value().getAsBool();
125
-
126
- if (inner) {
127
- auto srcGraphic = SkImageFilters::ColorFilter(
128
- SkColorFilters::Blend(SK_ColorBLACK, SkBlendMode::kDst), nullptr);
129
- auto srcAlpha = SkImageFilters::ColorFilter(
130
- SkColorFilters::Blend(SK_ColorBLACK, SkBlendMode::kSrcIn), nullptr);
131
- auto f1 = SkImageFilters::ColorFilter(
132
- SkColorFilters::Blend(*color, SkBlendMode::kSrcOut), nullptr);
133
- auto f2 = SkImageFilters::Offset(dx, dy, f1);
134
- auto f3 = SkImageFilters::Blur(blur, blur, SkTileMode::kDecal, f2);
135
- auto f4 = SkImageFilters::Blend(SkBlendMode::kSrcIn, srcAlpha, f3);
136
-
137
- setImageFilter(context, SkImageFilters::Compose(
138
- input ? input : nullptr,
139
- SkImageFilters::Blend(SkBlendMode::kSrcOver,
140
- srcGraphic, f4)));
141
-
142
- } else {
143
- setImageFilter(
144
- context,
145
- shadowOnly
146
- ? SkImageFilters::DropShadowOnly(dx, dy, blur, blur, *color,
147
- input ? input : nullptr)
148
- : SkImageFilters::DropShadow(dx, dy, blur, blur, *color,
149
- input ? input : nullptr));
150
- }
88
+ void decorate(DeclarationContext *context) override {
89
+
90
+ auto color = _colorProp->getDerivedValue();
91
+ auto dx = _dxProp->value().getAsNumber();
92
+ auto dy = _dyProp->value().getAsNumber();
93
+ auto blur = _blurProp->value().getAsNumber();
94
+ auto input = context->getImageFilters()->pop();
95
+
96
+ auto inner = _innerProp->isSet() && _innerProp->value().getAsBool();
97
+ auto shadowOnly =
98
+ _shadowOnlyProp->isSet() && _shadowOnlyProp->value().getAsBool();
99
+
100
+ if (inner) {
101
+ auto srcGraphic = SkImageFilters::ColorFilter(
102
+ SkColorFilters::Blend(SK_ColorBLACK, SkBlendMode::kDst), nullptr);
103
+ auto srcAlpha = SkImageFilters::ColorFilter(
104
+ SkColorFilters::Blend(SK_ColorBLACK, SkBlendMode::kSrcIn), nullptr);
105
+ auto f1 = SkImageFilters::ColorFilter(
106
+ SkColorFilters::Blend(*color, SkBlendMode::kSrcOut), nullptr);
107
+ auto f2 = SkImageFilters::Offset(dx, dy, f1);
108
+ auto f3 = SkImageFilters::Blur(blur, blur, SkTileMode::kDecal, f2);
109
+ auto f4 = SkImageFilters::Blend(SkBlendMode::kSrcIn, srcAlpha, f3);
110
+
111
+ composeAndPush(context, SkImageFilters::Compose(
112
+ input ? input : nullptr,
113
+ SkImageFilters::Blend(SkBlendMode::kSrcOver,
114
+ srcGraphic, f4)));
115
+
116
+ } else {
117
+ composeAndPush(
118
+ context,
119
+ shadowOnly ? SkImageFilters::DropShadowOnly(
120
+ dx, dy, blur, blur, *color, input ? input : nullptr)
121
+ : SkImageFilters::DropShadow(dx, dy, blur, blur, *color,
122
+ input ? input : nullptr));
151
123
  }
152
124
  }
153
125
 
126
+ protected:
154
127
  void defineProperties(NodePropsContainer *container) override {
155
- JsiBaseDomDeclarationNode::defineProperties(container);
128
+ JsiDomDeclarationNode::defineProperties(container);
156
129
  _dxProp = container->defineProperty<NodeProp>("dx");
157
130
  _dyProp = container->defineProperty<NodeProp>("dy");
158
131
  _blurProp = container->defineProperty<NodeProp>("blur");
@@ -184,27 +157,26 @@ public:
184
157
  std::shared_ptr<RNSkPlatformContext> context)
185
158
  : JsiBaseImageFilterNode(context, "skDisplacementMapImageFilter") {}
186
159
 
187
- protected:
188
- void decorate(DrawingContext *context) override {
189
- if (isChanged(context)) {
160
+ void decorate(DeclarationContext *context) override {
190
161
 
191
- auto channelX =
192
- getColorChannelFromStringValue(_channelXProp->value().getAsString());
193
- auto channelY =
194
- getColorChannelFromStringValue(_channelYProp->value().getAsString());
195
- auto scale = _scaleProp->value().getAsNumber();
162
+ auto channelX =
163
+ getColorChannelFromStringValue(_channelXProp->value().getAsString());
164
+ auto channelY =
165
+ getColorChannelFromStringValue(_channelYProp->value().getAsString());
166
+ auto scale = _scaleProp->value().getAsNumber();
196
167
 
197
- auto displacement = requireChild(0);
198
- auto color = optionalChild(1);
168
+ auto displacement = context->getImageFilters()->pop();
199
169
 
200
- setImageFilter(context, SkImageFilters::DisplacementMap(
201
- channelX, channelY, scale, displacement,
202
- color ? color : nullptr));
203
- }
170
+ auto color = context->getImageFilters()->pop();
171
+
172
+ composeAndPush(context, SkImageFilters::DisplacementMap(
173
+ channelX, channelY, scale, displacement,
174
+ color ? color : nullptr));
204
175
  }
205
176
 
177
+ protected:
206
178
  void defineProperties(NodePropsContainer *container) override {
207
- JsiBaseDomDeclarationNode::defineProperties(container);
179
+ JsiDomDeclarationNode::defineProperties(container);
208
180
  _channelXProp = container->defineProperty<NodeProp>("channelX");
209
181
  _channelYProp = container->defineProperty<NodeProp>("channelY");
210
182
  _scaleProp = container->defineProperty<NodeProp>("scale");
@@ -240,22 +212,19 @@ public:
240
212
  explicit JsiBlurImageFilterNode(std::shared_ptr<RNSkPlatformContext> context)
241
213
  : JsiBaseImageFilterNode(context, "skBlurImageFilter") {}
242
214
 
243
- protected:
244
- void decorate(DrawingContext *context) override {
245
- if (isChanged(context)) {
246
- auto input = optionalChild(0);
247
- setImageFilter(
248
- context, SkImageFilters::Blur(_blurProp->getDerivedValue()->x(),
249
- _blurProp->getDerivedValue()->y(),
250
- _tileModeProp->isSet()
251
- ? *_tileModeProp->getDerivedValue()
252
- : SkTileMode::kDecal,
253
- input ? input : nullptr));
254
- }
215
+ void decorate(DeclarationContext *context) override {
216
+ auto input = context->getImageFilters()->pop();
217
+ auto imageFilter = SkImageFilters::Blur(
218
+ _blurProp->getDerivedValue()->x(), _blurProp->getDerivedValue()->y(),
219
+ _tileModeProp->isSet() ? *_tileModeProp->getDerivedValue()
220
+ : SkTileMode::kDecal,
221
+ input);
222
+ composeAndPush(context, imageFilter);
255
223
  }
256
224
 
225
+ protected:
257
226
  void defineProperties(NodePropsContainer *container) override {
258
- JsiBaseDomDeclarationNode::defineProperties(container);
227
+ JsiDomDeclarationNode::defineProperties(container);
259
228
  _blurProp = container->defineProperty<RadiusProp>("blur");
260
229
  _tileModeProp = container->defineProperty<TileModeProp>("mode");
261
230
 
@@ -275,21 +244,18 @@ public:
275
244
  std::shared_ptr<RNSkPlatformContext> context)
276
245
  : JsiBaseImageFilterNode(context, "skOffsetImageFilter") {}
277
246
 
278
- protected:
279
- void decorate(DrawingContext *context) override {
280
- if (isChanged(context)) {
281
- auto input = optionalChild(0);
282
- if (getPropsContainer()->isChanged()) {
283
- setImageFilter(context,
284
- SkImageFilters::Offset(_xProp->value().getAsNumber(),
285
- _yProp->value().getAsNumber(),
286
- input ? input : nullptr));
287
- }
288
- }
247
+ void decorate(DeclarationContext *context) override {
248
+ decorateChildren(context);
249
+ auto input = context->getImageFilters()->pop();
250
+ composeAndPush(context,
251
+ SkImageFilters::Offset(_xProp->value().getAsNumber(),
252
+ _yProp->value().getAsNumber(),
253
+ input ? input : nullptr));
289
254
  }
290
255
 
256
+ protected:
291
257
  void defineProperties(NodePropsContainer *container) override {
292
- JsiBaseDomDeclarationNode::defineProperties(container);
258
+ JsiDomDeclarationNode::defineProperties(container);
293
259
  _xProp = container->defineProperty<NodeProp>("x");
294
260
  _yProp = container->defineProperty<NodeProp>("y");
295
261
 
@@ -312,26 +278,23 @@ public:
312
278
  std::shared_ptr<RNSkPlatformContext> context)
313
279
  : JsiBaseImageFilterNode(context, "skMorphologyImageFilter") {}
314
280
 
315
- protected:
316
- void decorate(DrawingContext *context) override {
317
- if (isChanged(context)) {
318
- auto op = getTypeFromStringValue(_operatorProp->value().getAsString());
319
- auto radius = _radiusProp->getDerivedValue();
320
- auto input = optionalChild(0);
321
-
322
- if (op == Type::Dilate) {
323
- setImageFilter(context,
324
- SkImageFilters::Dilate(radius->x(), radius->y(),
325
- input ? input : nullptr));
326
- } else {
327
- setImageFilter(context, SkImageFilters::Erode(radius->x(), radius->y(),
328
- input ? input : nullptr));
329
- }
281
+ void decorate(DeclarationContext *context) override {
282
+ auto op = getTypeFromStringValue(_operatorProp->value().getAsString());
283
+ auto radius = _radiusProp->getDerivedValue();
284
+ auto input = context->getImageFilters()->pop();
285
+
286
+ if (op == Type::Dilate) {
287
+ composeAndPush(context, SkImageFilters::Dilate(radius->x(), radius->y(),
288
+ input ? input : nullptr));
289
+ } else {
290
+ composeAndPush(context, SkImageFilters::Erode(radius->x(), radius->y(),
291
+ input ? input : nullptr));
330
292
  }
331
293
  }
332
294
 
295
+ protected:
333
296
  void defineProperties(NodePropsContainer *container) override {
334
- JsiBaseDomDeclarationNode::defineProperties(container);
297
+ JsiDomDeclarationNode::defineProperties(container);
335
298
  _operatorProp = container->defineProperty<NodeProp>("operator");
336
299
  _radiusProp = container->defineProperty<RadiusProp>("radius");
337
300
 
@@ -362,26 +325,23 @@ public:
362
325
  std::shared_ptr<RNSkPlatformContext> context)
363
326
  : JsiBaseImageFilterNode(context, "skRuntimeShaderImageFilter") {}
364
327
 
365
- protected:
366
- void decorate(DrawingContext *context) override {
367
- if (isChanged(context)) {
368
- auto source = _sourceProp->value().getAs<JsiSkRuntimeEffect>();
369
- if (source == nullptr) {
370
- throw std::runtime_error("Expected runtime effect when reading source "
371
- "property of RuntimeEffectImageFilter.");
372
- }
373
-
374
- auto builder = SkRuntimeShaderBuilder(source->getObject());
375
- auto input = optionalChild(0);
376
- _uniformsProp->processUniforms(builder);
377
-
378
- setImageFilter(context,
379
- SkImageFilters::RuntimeShader(builder, "", input));
328
+ void decorate(DeclarationContext *context) override {
329
+ auto source = _sourceProp->value().getAs<JsiSkRuntimeEffect>();
330
+ if (source == nullptr) {
331
+ throw std::runtime_error("Expected runtime effect when reading source "
332
+ "property of RuntimeEffectImageFilter.");
380
333
  }
334
+
335
+ auto builder = SkRuntimeShaderBuilder(source->getObject());
336
+ auto input = context->getImageFilters()->pop();
337
+ _uniformsProp->processUniforms(builder);
338
+
339
+ composeAndPush(context, SkImageFilters::RuntimeShader(builder, "", input));
381
340
  }
382
341
 
342
+ protected:
383
343
  void defineProperties(NodePropsContainer *container) override {
384
- JsiBaseDomDeclarationNode::defineProperties(container);
344
+ JsiDomDeclarationNode::defineProperties(container);
385
345
  _sourceProp = container->defineProperty<NodeProp>("source");
386
346
  _uniformsProp =
387
347
  container->defineProperty<UniformsProp>("uniforms", _sourceProp);
@@ -16,6 +16,7 @@ public:
16
16
  protected:
17
17
  void draw(DrawingContext *context) override {
18
18
  auto rects = _imageProps->getDerivedValue();
19
+
19
20
  context->getCanvas()->drawImageRect(
20
21
  _imageProps->getImage(), rects->src, rects->dst, SkSamplingOptions(),
21
22
  context->getPaint().get(), SkCanvas::kStrict_SrcRectConstraint);
@@ -18,38 +18,48 @@ public:
18
18
  protected:
19
19
  void renderNode(DrawingContext *context) override {
20
20
 
21
- bool isLayer = false;
21
+ auto hasLayer = false;
22
22
  auto children = getChildren();
23
- auto size = children.size();
24
23
 
25
24
  // Is the first children a layer?
26
- for (size_t i = 0; i < size; ++i) {
25
+ for (size_t i = 0; i < children.size(); ++i) {
27
26
  if (i == 0) {
28
27
  // Check for paint node as layer
29
- auto paintNode =
30
- std::dynamic_pointer_cast<JsiPaintNode>(children.at(i));
28
+ if (children.at(i)->getNodeClass() == NodeClass::DeclarationNode) {
29
+ auto declarationNode =
30
+ std::static_pointer_cast<JsiDomDeclarationNode>(children.at(i));
31
31
 
32
- if (paintNode != nullptr) {
33
- // Yes, it is a paint node - which we can use as a layer.
34
- isLayer = true;
35
- // Save canvas with the paint node's paint!
36
- context->getCanvas()->saveLayer(SkCanvas::SaveLayerRec(
37
- nullptr, paintNode->getPaint().get(), nullptr, 0));
32
+ if (declarationNode->getDeclarationType() == DeclarationType::Paint) {
33
+ // Yes, it is a paint node - which we can use as a layer.
34
+ auto declarationContext = context->getDeclarationContext();
35
+ auto layerNode =
36
+ std::static_pointer_cast<JsiDomDeclarationNode>(children.at(i));
38
37
 
39
- continue;
38
+ // Save canvas with the paint node's paint!
39
+ declarationContext->save();
40
+ layerNode->decorate(declarationContext);
41
+ auto paint = declarationContext->getPaints()->pop();
42
+ declarationContext->restore();
43
+
44
+ if (paint) {
45
+ hasLayer = true;
46
+ context->getCanvas()->saveLayer(
47
+ SkCanvas::SaveLayerRec(nullptr, paint.get(), nullptr, 0));
48
+ }
49
+
50
+ continue;
51
+ }
40
52
  }
41
53
  }
42
54
 
43
55
  // Render rest of the children
44
- auto renderNode =
45
- std::dynamic_pointer_cast<JsiDomRenderNode>(children.at(i));
46
-
47
- if (renderNode != nullptr) {
48
- renderNode->render(context);
56
+ if (children.at(i)->getNodeClass() == NodeClass::RenderNode) {
57
+ std::static_pointer_cast<JsiDomRenderNode>(children.at(i))
58
+ ->render(context);
49
59
  }
50
60
  }
51
61
 
52
- if (isLayer) {
62
+ if (hasLayer) {
53
63
  context->getCanvas()->restore();
54
64
  }
55
65
  }
@@ -7,72 +7,109 @@
7
7
 
8
8
  namespace RNSkia {
9
9
 
10
- // TODO: implement feature: A paint node has its own paint not inherited,
11
- // and when found the drawing node should render an extra time for
12
- // each paint node in its children.
13
-
14
- class JsiPaintNode : public JsiBaseDomDeclarationNode,
10
+ class JsiPaintNode : public JsiDomDeclarationNode,
15
11
  public JsiDomNodeCtor<JsiPaintNode> {
16
12
  public:
17
13
  explicit JsiPaintNode(std::shared_ptr<RNSkPlatformContext> context)
18
- : JsiBaseDomDeclarationNode(context, "skPaint") {}
19
-
20
- /**
21
- Returns a pointer to the local paint context in the paint node. This is a
22
- special case for declaration nodes since the Paint node has a bit different
23
- semantic than other declaration nodes.
24
- */
25
- DrawingContext *getDrawingContext() { return _localContext.get(); }
26
-
27
- /**
28
- We need to override the decorate node call to avoid letting children
29
- decorate before we have created our child context.
30
- */
31
- void decorateContext(DrawingContext *context) override {
32
- // A paint node should have its own local paint
33
- if (_localContext == nullptr) {
34
- _localContext = context->inheritContext("PaintNode");
14
+ : JsiDomDeclarationNode(context, "skPaint", DeclarationType::Paint) {}
15
+
16
+ void decorate(DeclarationContext *context) override {
17
+ auto paint = std::make_shared<SkPaint>();
18
+ paint->setAntiAlias(true);
19
+
20
+ if (_paintProps->getOpacity()->isSet()) {
21
+ paint->setAlphaf(paint->getAlphaf() *
22
+ _paintProps->getOpacity()->value().getAsNumber());
23
+ }
24
+
25
+ if (_paintProps->getColor()->isSet()) {
26
+ auto currentOpacity = paint->getAlphaf();
27
+ paint->setShader(nullptr);
28
+ paint->setColor(*_paintProps->getColor()->getDerivedValue());
29
+ paint->setAlphaf(paint->getAlphaf() * currentOpacity);
35
30
  }
36
31
 
37
- // ...and it should be a totally new paint, not inheriting from parent
38
- // paint.
39
- if (_localContext->isChanged()) {
40
- auto paint = std::make_shared<SkPaint>();
41
- paint->setAntiAlias(true);
42
- _localContext->setMutablePaint(paint);
32
+ if (_paintProps->getStrokeWidth()->isSet()) {
33
+ paint->setStrokeWidth(
34
+ _paintProps->getStrokeWidth()->value().getAsNumber());
43
35
  }
44
36
 
45
- // Let's decorate paint props
46
- _paintProps->decorate(_localContext.get());
37
+ if (_paintProps->getBlendMode()->isSet()) {
38
+ paint->setBlendMode(*_paintProps->getBlendMode()->getDerivedValue());
39
+ }
47
40
 
48
- // Materialize children who will now only change the paint node's paint
49
- for (auto &child : getChildren()) {
50
- auto decl = std::dynamic_pointer_cast<JsiBaseDomDeclarationNode>(child);
51
- if (decl != nullptr) {
52
- decl->decorateContext(_localContext.get());
41
+ if (_paintProps->getStyle()->isSet()) {
42
+ auto styleValue = _paintProps->getStyle()->value().getAsString();
43
+ if (styleValue == "stroke") {
44
+ paint->setStyle(SkPaint::Style::kStroke_Style);
45
+ } else if (styleValue == "fill") {
46
+ paint->setStyle(SkPaint::Style::kFill_Style);
47
+ } else {
48
+ throw std::runtime_error(
49
+ styleValue + " is not a valud value for the style property.");
53
50
  }
54
51
  }
55
- }
56
52
 
57
- std::shared_ptr<const SkPaint> getPaint() {
58
- return _localContext->getPaint();
53
+ if (_paintProps->getStrokeJoin()->isSet()) {
54
+ paint->setStrokeJoin(*_paintProps->getStrokeJoin()->getDerivedValue());
55
+ }
56
+
57
+ if (_paintProps->getStrokeCap()->isSet()) {
58
+ paint->setStrokeCap(*_paintProps->getStrokeCap()->getDerivedValue());
59
+ }
60
+
61
+ if (_paintProps->getStrokeMiter()->isSet()) {
62
+ paint->setStrokeMiter(
63
+ _paintProps->getStrokeMiter()->value().getAsNumber());
64
+ }
65
+
66
+ if (_paintProps->getAntiAlias()->isSet()) {
67
+ paint->setAntiAlias(_paintProps->getAntiAlias()->value().getAsBool());
68
+ }
69
+
70
+ context->save();
71
+ decorateChildren(context);
72
+
73
+ auto imageFilter = context->getImageFilters()->popAsOne();
74
+ auto colorFilter = context->getColorFilters()->popAsOne();
75
+ auto shader = context->getShaders()->pop();
76
+ auto maskFilter = context->getMaskFilters()->pop();
77
+ auto pathEffect = context->getPathEffects()->popAsOne();
78
+
79
+ context->restore();
80
+
81
+ if (imageFilter) {
82
+ paint->setImageFilter(imageFilter);
83
+ }
84
+
85
+ if (colorFilter) {
86
+ paint->setColorFilter(colorFilter);
87
+ }
88
+
89
+ if (shader) {
90
+ paint->setShader(shader);
91
+ }
92
+
93
+ if (maskFilter) {
94
+ paint->setMaskFilter(maskFilter);
95
+ }
96
+
97
+ if (pathEffect) {
98
+ paint->setPathEffect(pathEffect);
99
+ }
100
+
101
+ context->getPaints()->push(paint);
59
102
  }
60
103
 
61
104
  protected:
62
- void decorate(DrawingContext *context) override {}
63
-
64
105
  void defineProperties(NodePropsContainer *container) override {
65
- JsiBaseDomDeclarationNode::defineProperties(container);
106
+ JsiDomDeclarationNode::defineProperties(container);
66
107
 
67
108
  _paintProps = container->defineProperty<PaintProps>();
68
- _opacityProp = container->defineProperty<NodeProp>("opacity");
69
109
  }
70
110
 
71
111
  private:
72
- NodeProp *_opacityProp;
73
112
  PaintProps *_paintProps;
74
-
75
- std::shared_ptr<DrawingContext> _localContext;
76
113
  };
77
114
 
78
115
  } // namespace RNSkia