@shopify/react-native-skia 0.1.172 → 0.1.173

Sign up to get free protection for your applications and to get access to all the features.
Files changed (311) 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 +38 -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/JsiSkSurface.d.ts +1 -0
  153. package/lib/commonjs/skia/web/JsiSkSurface.js +4 -0
  154. package/lib/commonjs/skia/web/JsiSkSurface.js.map +1 -1
  155. package/lib/commonjs/skia/web/JsiSkSurfaceFactory.d.ts +2 -1
  156. package/lib/commonjs/skia/web/JsiSkSurfaceFactory.js +21 -1
  157. package/lib/commonjs/skia/web/JsiSkSurfaceFactory.js.map +1 -1
  158. package/lib/commonjs/views/SkiaBaseWebView.js +6 -4
  159. package/lib/commonjs/views/SkiaBaseWebView.js.map +1 -1
  160. package/lib/commonjs/views/SkiaDomView.web.js +3 -14
  161. package/lib/commonjs/views/SkiaDomView.web.js.map +1 -1
  162. package/lib/commonjs/views/SkiaPictureView.web.js +0 -7
  163. package/lib/commonjs/views/SkiaPictureView.web.js.map +1 -1
  164. package/lib/commonjs/views/SkiaView.web.js +0 -7
  165. package/lib/commonjs/views/SkiaView.web.js.map +1 -1
  166. package/lib/module/dom/nodes/DrawingNode.js +5 -1
  167. package/lib/module/dom/nodes/DrawingNode.js.map +1 -1
  168. package/lib/module/dom/nodes/JsiSkDOM.d.ts +33 -34
  169. package/lib/module/dom/nodes/LayerNode.js +13 -7
  170. package/lib/module/dom/nodes/LayerNode.js.map +1 -1
  171. package/lib/module/dom/nodes/Node.d.ts +6 -11
  172. package/lib/module/dom/nodes/Node.js +8 -25
  173. package/lib/module/dom/nodes/Node.js.map +1 -1
  174. package/lib/module/dom/nodes/PaintContext.js.map +1 -1
  175. package/lib/module/dom/nodes/PaintNode.d.ts +3 -3
  176. package/lib/module/dom/nodes/PaintNode.js +32 -15
  177. package/lib/module/dom/nodes/PaintNode.js.map +1 -1
  178. package/lib/module/dom/nodes/RenderNode.d.ts +2 -3
  179. package/lib/module/dom/nodes/RenderNode.js +20 -187
  180. package/lib/module/dom/nodes/RenderNode.js.map +1 -1
  181. package/lib/module/dom/nodes/drawings/BackdropFilterNode.d.ts +1 -1
  182. package/lib/module/dom/nodes/drawings/BackdropFilterNode.js +23 -4
  183. package/lib/module/dom/nodes/drawings/BackdropFilterNode.js.map +1 -1
  184. package/lib/module/dom/nodes/drawings/Box.d.ts +3 -1
  185. package/lib/module/dom/nodes/drawings/Box.js +3 -0
  186. package/lib/module/dom/nodes/drawings/Box.js.map +1 -1
  187. package/lib/module/dom/nodes/paint/BlendNode.d.ts +3 -7
  188. package/lib/module/dom/nodes/paint/BlendNode.js +15 -46
  189. package/lib/module/dom/nodes/paint/BlendNode.js.map +1 -1
  190. package/lib/module/dom/nodes/paint/ColorFilters.d.ts +10 -11
  191. package/lib/module/dom/nodes/paint/ColorFilters.js +29 -43
  192. package/lib/module/dom/nodes/paint/ColorFilters.js.map +1 -1
  193. package/lib/module/dom/nodes/paint/ImageFilters.d.ts +11 -11
  194. package/lib/module/dom/nodes/paint/ImageFilters.js +48 -41
  195. package/lib/module/dom/nodes/paint/ImageFilters.js.map +1 -1
  196. package/lib/module/dom/nodes/paint/MaskFilters.d.ts +3 -3
  197. package/lib/module/dom/nodes/paint/MaskFilters.js +3 -2
  198. package/lib/module/dom/nodes/paint/MaskFilters.js.map +1 -1
  199. package/lib/module/dom/nodes/paint/PathEffects.d.ts +15 -18
  200. package/lib/module/dom/nodes/paint/PathEffects.js +29 -72
  201. package/lib/module/dom/nodes/paint/PathEffects.js.map +1 -1
  202. package/lib/module/dom/nodes/paint/Shaders.d.ts +11 -12
  203. package/lib/module/dom/nodes/paint/Shaders.js +28 -18
  204. package/lib/module/dom/nodes/paint/Shaders.js.map +1 -1
  205. package/lib/module/dom/types/DeclarationContext.d.ts +29 -0
  206. package/lib/module/dom/types/DeclarationContext.js +107 -0
  207. package/lib/module/dom/types/DeclarationContext.js.map +1 -0
  208. package/lib/module/dom/types/DrawingContext.d.ts +18 -1
  209. package/lib/module/dom/types/DrawingContext.js +322 -1
  210. package/lib/module/dom/types/DrawingContext.js.map +1 -1
  211. package/lib/module/dom/types/Node.d.ts +4 -10
  212. package/lib/module/dom/types/Node.js.map +1 -1
  213. package/lib/module/dom/types/SkDOM.d.ts +22 -23
  214. package/lib/module/dom/types/SkDOM.js.map +1 -1
  215. package/lib/module/dom/types/index.d.ts +1 -0
  216. package/lib/module/dom/types/index.js +1 -0
  217. package/lib/module/dom/types/index.js.map +1 -1
  218. package/lib/module/index.d.ts +1 -0
  219. package/lib/module/index.js +1 -0
  220. package/lib/module/index.js.map +1 -1
  221. package/lib/module/renderer/Canvas.js +3 -3
  222. package/lib/module/renderer/Canvas.js.map +1 -1
  223. package/lib/module/renderer/DrawingContext.d.ts +4 -3
  224. package/lib/module/renderer/DrawingContext.js.map +1 -1
  225. package/lib/module/renderer/HostComponents.d.ts +35 -35
  226. package/lib/module/renderer/HostComponents.js.map +1 -1
  227. package/lib/module/renderer/HostConfig.js +1 -0
  228. package/lib/module/renderer/HostConfig.js.map +1 -1
  229. package/lib/module/renderer/Offscreen.d.ts +2 -0
  230. package/lib/module/renderer/Offscreen.js +19 -0
  231. package/lib/module/renderer/Offscreen.js.map +1 -0
  232. package/lib/module/renderer/Reconciler.js +0 -1
  233. package/lib/module/renderer/Reconciler.js.map +1 -1
  234. package/lib/module/skia/types/Surface/Surface.d.ts +4 -0
  235. package/lib/module/skia/types/Surface/Surface.js.map +1 -1
  236. package/lib/module/skia/types/Surface/SurfaceFactory.d.ts +6 -0
  237. package/lib/module/skia/types/Surface/SurfaceFactory.js.map +1 -1
  238. package/lib/module/skia/web/JsiSkSurface.d.ts +1 -0
  239. package/lib/module/skia/web/JsiSkSurface.js +4 -0
  240. package/lib/module/skia/web/JsiSkSurface.js.map +1 -1
  241. package/lib/module/skia/web/JsiSkSurfaceFactory.d.ts +2 -1
  242. package/lib/module/skia/web/JsiSkSurfaceFactory.js +21 -1
  243. package/lib/module/skia/web/JsiSkSurfaceFactory.js.map +1 -1
  244. package/lib/module/views/SkiaBaseWebView.js +6 -4
  245. package/lib/module/views/SkiaBaseWebView.js.map +1 -1
  246. package/lib/module/views/SkiaDomView.web.js +2 -11
  247. package/lib/module/views/SkiaDomView.web.js.map +1 -1
  248. package/lib/module/views/SkiaPictureView.web.js +0 -5
  249. package/lib/module/views/SkiaPictureView.web.js.map +1 -1
  250. package/lib/module/views/SkiaView.web.js +0 -5
  251. package/lib/module/views/SkiaView.web.js.map +1 -1
  252. package/lib/typescript/src/dom/nodes/JsiSkDOM.d.ts +33 -34
  253. package/lib/typescript/src/dom/nodes/Node.d.ts +6 -11
  254. package/lib/typescript/src/dom/nodes/PaintNode.d.ts +3 -3
  255. package/lib/typescript/src/dom/nodes/RenderNode.d.ts +2 -3
  256. package/lib/typescript/src/dom/nodes/drawings/BackdropFilterNode.d.ts +1 -1
  257. package/lib/typescript/src/dom/nodes/drawings/Box.d.ts +3 -1
  258. package/lib/typescript/src/dom/nodes/paint/BlendNode.d.ts +3 -7
  259. package/lib/typescript/src/dom/nodes/paint/ColorFilters.d.ts +10 -11
  260. package/lib/typescript/src/dom/nodes/paint/ImageFilters.d.ts +11 -11
  261. package/lib/typescript/src/dom/nodes/paint/MaskFilters.d.ts +3 -3
  262. package/lib/typescript/src/dom/nodes/paint/PathEffects.d.ts +15 -18
  263. package/lib/typescript/src/dom/nodes/paint/Shaders.d.ts +11 -12
  264. package/lib/typescript/src/dom/types/DeclarationContext.d.ts +29 -0
  265. package/lib/typescript/src/dom/types/DrawingContext.d.ts +18 -1
  266. package/lib/typescript/src/dom/types/Node.d.ts +4 -10
  267. package/lib/typescript/src/dom/types/SkDOM.d.ts +22 -23
  268. package/lib/typescript/src/dom/types/index.d.ts +1 -0
  269. package/lib/typescript/src/index.d.ts +1 -0
  270. package/lib/typescript/src/renderer/DrawingContext.d.ts +4 -3
  271. package/lib/typescript/src/renderer/HostComponents.d.ts +35 -35
  272. package/lib/typescript/src/renderer/Offscreen.d.ts +2 -0
  273. package/lib/typescript/src/skia/types/Surface/Surface.d.ts +4 -0
  274. package/lib/typescript/src/skia/types/Surface/SurfaceFactory.d.ts +6 -0
  275. package/lib/typescript/src/skia/web/JsiSkSurface.d.ts +1 -0
  276. package/lib/typescript/src/skia/web/JsiSkSurfaceFactory.d.ts +2 -1
  277. package/package.json +1 -1
  278. package/src/dom/nodes/DrawingNode.ts +5 -1
  279. package/src/dom/nodes/LayerNode.ts +13 -11
  280. package/src/dom/nodes/Node.ts +18 -41
  281. package/src/dom/nodes/PaintContext.ts +1 -0
  282. package/src/dom/nodes/PaintNode.ts +28 -18
  283. package/src/dom/nodes/RenderNode.ts +25 -183
  284. package/src/dom/nodes/drawings/BackdropFilterNode.ts +18 -11
  285. package/src/dom/nodes/drawings/Box.ts +6 -4
  286. package/src/dom/nodes/paint/BlendNode.ts +16 -63
  287. package/src/dom/nodes/paint/ColorFilters.ts +32 -55
  288. package/src/dom/nodes/paint/ImageFilters.ts +58 -53
  289. package/src/dom/nodes/paint/MaskFilters.ts +5 -7
  290. package/src/dom/nodes/paint/PathEffects.ts +37 -90
  291. package/src/dom/nodes/paint/Shaders.ts +31 -29
  292. package/src/dom/types/DeclarationContext.ts +105 -0
  293. package/src/dom/types/DrawingContext.ts +304 -1
  294. package/src/dom/types/Node.ts +4 -20
  295. package/src/dom/types/SkDOM.ts +22 -43
  296. package/src/dom/types/index.ts +1 -0
  297. package/src/index.ts +1 -0
  298. package/src/renderer/Canvas.tsx +3 -3
  299. package/src/renderer/DrawingContext.ts +4 -5
  300. package/src/renderer/HostComponents.ts +34 -53
  301. package/src/renderer/HostConfig.ts +1 -0
  302. package/src/renderer/Offscreen.tsx +24 -0
  303. package/src/renderer/Reconciler.tsx +0 -1
  304. package/src/skia/types/Surface/Surface.ts +5 -0
  305. package/src/skia/types/Surface/SurfaceFactory.ts +7 -0
  306. package/src/skia/web/JsiSkSurface.ts +4 -0
  307. package/src/skia/web/JsiSkSurfaceFactory.ts +21 -2
  308. package/src/views/SkiaBaseWebView.tsx +6 -2
  309. package/src/views/SkiaDomView.web.tsx +2 -13
  310. package/src/views/SkiaPictureView.web.tsx +0 -7
  311. package/src/views/SkiaView.web.tsx +0 -7
@@ -56,6 +56,7 @@ add_library(
56
56
  "${PROJECT_SOURCE_DIR}/cpp/rnskia/RNSkDispatchQueue.cpp"
57
57
 
58
58
  "${PROJECT_SOURCE_DIR}/cpp/rnskia/dom/base/DrawingContext.cpp"
59
+ "${PROJECT_SOURCE_DIR}/cpp/rnskia/dom/base/ConcatablePaint.cpp"
59
60
 
60
61
  "${PROJECT_SOURCE_DIR}/cpp/api/third_party/CSSColorParser.cpp"
61
62
 
@@ -7,6 +7,7 @@
7
7
 
8
8
  #include <JniPlatformContext.h>
9
9
  #include <RNSkPlatformContext.h>
10
+ #include <SkiaOpenGLRenderer.h>
10
11
 
11
12
  namespace RNSkia {
12
13
  namespace jsi = facebook::jsi;
@@ -36,6 +37,10 @@ public:
36
37
  _jniPlatformContext->raiseError(err);
37
38
  }
38
39
 
40
+ sk_sp<SkSurface> makeOffscreenSurface(int width, int height) override {
41
+ return MakeOffscreenGLSurface(width, height);
42
+ }
43
+
39
44
  void startDrawLoop() override { _jniPlatformContext->startDrawLoop(); }
40
45
 
41
46
  void stopDrawLoop() override { _jniPlatformContext->stopDrawLoop(); }
@@ -6,6 +6,112 @@
6
6
 
7
7
  namespace RNSkia {
8
8
  /** Static members */
9
+ sk_sp<SkSurface> MakeOffscreenGLSurface(int width, int height) {
10
+ EGLDisplay eglDisplay = eglGetDisplay(EGL_DEFAULT_DISPLAY);
11
+ if (eglDisplay == EGL_NO_DISPLAY) {
12
+ RNSkLogger::logToConsole("eglGetdisplay failed : %i", glGetError());
13
+ return nullptr;
14
+ }
15
+
16
+ EGLint major;
17
+ EGLint minor;
18
+ if (!eglInitialize(eglDisplay, &major, &minor)) {
19
+ RNSkLogger::logToConsole("eglInitialize failed : %i", glGetError());
20
+ return nullptr;
21
+ }
22
+
23
+ EGLint att[] = {EGL_RENDERABLE_TYPE,
24
+ EGL_OPENGL_ES2_BIT,
25
+ EGL_SURFACE_TYPE,
26
+ EGL_PBUFFER_BIT,
27
+ EGL_ALPHA_SIZE,
28
+ 8,
29
+ EGL_BLUE_SIZE,
30
+ 8,
31
+ EGL_GREEN_SIZE,
32
+ 8,
33
+ EGL_RED_SIZE,
34
+ 8,
35
+ EGL_DEPTH_SIZE,
36
+ 0,
37
+ EGL_STENCIL_SIZE,
38
+ 0,
39
+ EGL_NONE};
40
+
41
+ EGLint numConfigs;
42
+ EGLConfig eglConfig;
43
+ eglConfig = 0;
44
+ if (!eglChooseConfig(eglDisplay, att, &eglConfig, 1, &numConfigs) ||
45
+ numConfigs == 0) {
46
+ RNSkLogger::logToConsole("Failed to choose a config %d\n", eglGetError());
47
+ return nullptr;
48
+ }
49
+
50
+ EGLint contextAttribs[] = {EGL_CONTEXT_CLIENT_VERSION, 2, EGL_NONE};
51
+
52
+ EGLContext eglContext =
53
+ eglCreateContext(eglDisplay, eglConfig, NULL, contextAttribs);
54
+
55
+ if (eglContext == EGL_NO_CONTEXT) {
56
+ RNSkLogger::logToConsole("eglCreateContext failed: %d\n", eglGetError());
57
+ return nullptr;
58
+ }
59
+
60
+ const EGLint offScreenSurfaceAttribs[] = {EGL_WIDTH, width, EGL_HEIGHT,
61
+ height, EGL_NONE};
62
+ EGLSurface eglSurface =
63
+ eglCreatePbufferSurface(eglDisplay, eglConfig, offScreenSurfaceAttribs);
64
+ if (!eglMakeCurrent(eglDisplay, eglSurface, eglSurface, eglContext)) {
65
+ RNSkLogger::logToConsole("eglMakeCurrent failed: %d\n", eglGetError());
66
+ return nullptr;
67
+ }
68
+ GLint buffer;
69
+ glGetIntegerv(GL_FRAMEBUFFER_BINDING, &buffer);
70
+
71
+ GLint stencil;
72
+ glGetIntegerv(GL_STENCIL_BITS, &stencil);
73
+
74
+ GLint samples;
75
+ glGetIntegerv(GL_SAMPLES, &samples);
76
+
77
+ // Create the Skia backend context
78
+ auto backendInterface = GrGLMakeNativeInterface();
79
+ auto grContext = GrDirectContext::MakeGL(backendInterface);
80
+ if (grContext == nullptr) {
81
+ RNSkLogger::logToConsole("GrDirectContext::MakeGL failed");
82
+ return nullptr;
83
+ }
84
+ auto maxSamples =
85
+ grContext->maxSurfaceSampleCountForColorType(kRGBA_8888_SkColorType);
86
+
87
+ if (samples > maxSamples)
88
+ samples = maxSamples;
89
+
90
+ GrGLFramebufferInfo fbInfo;
91
+ fbInfo.fFBOID = buffer;
92
+ fbInfo.fFormat = 0x8058;
93
+
94
+ auto renderTarget =
95
+ GrBackendRenderTarget(width, height, samples, stencil, fbInfo);
96
+
97
+ struct OffscreenRenderContext {
98
+ EGLDisplay display;
99
+ EGLSurface surface;
100
+ };
101
+ auto ctx = new OffscreenRenderContext({eglDisplay, eglSurface});
102
+
103
+ auto surface = SkSurface::MakeFromBackendRenderTarget(
104
+ grContext.get(), renderTarget, kBottomLeft_GrSurfaceOrigin,
105
+ kRGBA_8888_SkColorType, nullptr, nullptr,
106
+ [](void *addr) {
107
+ auto ctx = reinterpret_cast<OffscreenRenderContext *>(addr);
108
+ eglDestroySurface(ctx->display, ctx->surface);
109
+ delete ctx;
110
+ },
111
+ reinterpret_cast<void *>(ctx));
112
+ return surface;
113
+ }
114
+
9
115
  std::shared_ptr<OpenGLDrawingContext>
10
116
  SkiaOpenGLRenderer::getThreadDrawingContext() {
11
117
  auto threadId = std::this_thread::get_id();
@@ -57,13 +163,8 @@ void SkiaOpenGLRenderer::run(const std::function<void(SkCanvas *)> &cb,
57
163
  // during rendering.
58
164
  getThreadDrawingContext()->skContext->resetContext();
59
165
 
60
- // Clear with transparent
61
- glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
62
- glClear(GL_COLOR_BUFFER_BIT);
63
-
64
166
  // Draw picture into surface
65
167
  cb(_skSurface->getCanvas());
66
-
67
168
  // Flush
68
169
  _skSurface->flushAndSubmit();
69
170
 
@@ -26,6 +26,8 @@
26
26
  #pragma clang diagnostic pop
27
27
 
28
28
  namespace RNSkia {
29
+ sk_sp<SkSurface> MakeOffscreenGLSurface(int width, int height);
30
+
29
31
  using OpenGLDrawingContext = struct {
30
32
  EGLContext glContext;
31
33
  EGLDisplay glDisplay;
@@ -127,4 +129,4 @@ private:
127
129
 
128
130
  std::atomic<RenderState> _renderState = {RenderState::Initializing};
129
131
  };
130
- } // namespace RNSkia
132
+ } // namespace RNSkia
@@ -40,6 +40,11 @@ public:
40
40
  std::make_shared<JsiSkCanvas>(getContext(), getObject()->getCanvas()));
41
41
  }
42
42
 
43
+ JSI_HOST_FUNCTION(flush) {
44
+ getObject()->flush();
45
+ return jsi::Value::undefined();
46
+ }
47
+
43
48
  JSI_HOST_FUNCTION(makeImageSnapshot) {
44
49
  sk_sp<SkImage> image;
45
50
  if (count == 1) {
@@ -55,7 +60,8 @@ public:
55
60
 
56
61
  JSI_EXPORT_PROPERTY_GETTERS(JSI_EXPORT_PROP_GET(JsiSkSurface, __typename__))
57
62
  JSI_EXPORT_FUNCTIONS(JSI_EXPORT_FUNC(JsiSkSurface, getCanvas),
58
- JSI_EXPORT_FUNC(JsiSkSurface, makeImageSnapshot))
63
+ JSI_EXPORT_FUNC(JsiSkSurface, makeImageSnapshot),
64
+ JSI_EXPORT_FUNC(JsiSkSurface, flush))
59
65
 
60
66
  /**
61
67
  Returns the underlying object from a host object of this type
@@ -12,7 +12,6 @@
12
12
  #pragma clang diagnostic push
13
13
  #pragma clang diagnostic ignored "-Wdocumentation"
14
14
 
15
- #include "SkImage.h"
16
15
  #include "SkSurface.h"
17
16
 
18
17
  #pragma clang diagnostic pop
@@ -35,7 +34,21 @@ public:
35
34
  std::make_shared<JsiSkSurface>(getContext(), std::move(surface)));
36
35
  }
37
36
 
38
- JSI_EXPORT_FUNCTIONS(JSI_EXPORT_FUNC(JsiSkSurfaceFactory, Make))
37
+ JSI_HOST_FUNCTION(MakeOffscreen) {
38
+ auto width = static_cast<int>(arguments[0].asNumber());
39
+ auto height = static_cast<int>(arguments[1].asNumber());
40
+ auto context = getContext();
41
+ auto surface = context->makeOffscreenSurface(width, height);
42
+ if (surface == nullptr) {
43
+ return jsi::Value::null();
44
+ }
45
+ return jsi::Object::createFromHostObject(
46
+ runtime,
47
+ std::make_shared<JsiSkSurface>(getContext(), std::move(surface)));
48
+ }
49
+
50
+ JSI_EXPORT_FUNCTIONS(JSI_EXPORT_FUNC(JsiSkSurfaceFactory, Make),
51
+ JSI_EXPORT_FUNC(JsiSkSurfaceFactory, MakeOffscreen))
39
52
 
40
53
  explicit JsiSkSurfaceFactory(std::shared_ptr<RNSkPlatformContext> context)
41
54
  : JsiSkHostObject(std::move(context)) {}
@@ -79,14 +79,12 @@ void RNSkDomRenderer::renderCanvas(SkCanvas *canvas, float scaledWidth,
79
79
  _renderTimingInfo.beginTiming();
80
80
 
81
81
  auto pd = _platformContext->getPixelDensity();
82
-
82
+ canvas->clear(SK_ColorTRANSPARENT);
83
83
  canvas->save();
84
84
  canvas->scale(pd, pd);
85
85
 
86
86
  if (_drawingContext == nullptr) {
87
- auto paint = std::make_shared<SkPaint>();
88
- paint->setAntiAlias(true);
89
- _drawingContext = std::make_shared<DrawingContext>(paint);
87
+ _drawingContext = std::make_shared<DrawingContext>();
90
88
 
91
89
  _drawingContext->setRequestRedraw([weakSelf = weak_from_this()]() {
92
90
  auto self = weakSelf.lock();
@@ -197,11 +197,14 @@ void RNSkJsRenderer::drawInJsiCanvas(std::shared_ptr<JsiSkCanvas> jsiCanvas,
197
197
  if (_drawCallback != nullptr && skCanvas != nullptr) {
198
198
  // Make sure to scale correctly
199
199
  auto pd = _platformContext->getPixelDensity();
200
+ skCanvas->clear(SK_ColorTRANSPARENT);
200
201
  skCanvas->save();
201
202
  skCanvas->scale(pd, pd);
202
203
 
203
204
  // Call draw function.
204
205
  callJsDrawCallback(jsiCanvas, width / pd, height / pd, time);
206
+
207
+ skCanvas->restore();
205
208
  }
206
209
  }
207
210
 
@@ -72,10 +72,13 @@ private:
72
72
  canvasProvider->renderToCanvas([=](SkCanvas *canvas) {
73
73
  // Make sure to scale correctly
74
74
  auto pd = _platformContext->getPixelDensity();
75
+ canvas->clear(SK_ColorTRANSPARENT);
75
76
  canvas->save();
76
77
  canvas->scale(pd, pd);
77
78
 
78
79
  canvas->drawPicture(_picture->getObject());
80
+
81
+ canvas->restore();
79
82
  });
80
83
  }
81
84
 
@@ -15,6 +15,7 @@
15
15
  #pragma clang diagnostic ignored "-Wdocumentation"
16
16
 
17
17
  #include "SkStream.h"
18
+ #include "SkSurface.h"
18
19
 
19
20
  #pragma clang diagnostic pop
20
21
 
@@ -109,6 +110,14 @@ public:
109
110
  */
110
111
  virtual void raiseError(const std::exception &err) = 0;
111
112
 
113
+ /**
114
+ * Creates an offscreen surface
115
+ * @param width
116
+ * @param height
117
+ * @return sk_sp<SkSurface>
118
+ */
119
+ virtual sk_sp<SkSurface> makeOffscreenSurface(int width, int height) = 0;
120
+
112
121
  /**
113
122
  * Raises an exception on the platform. This function does not necessarily
114
123
  * throw an exception and stop execution, so it is important to stop execution
@@ -2,6 +2,7 @@
2
2
 
3
3
  /* Enable output of dom trees and paint contexts */
4
4
  #define SKIA_DOM_DEBUG 0
5
+ #define SKIA_DOM_DEBUG_VERBOSE 0
5
6
 
6
7
  #include <memory>
7
8
 
@@ -0,0 +1,117 @@
1
+ #include "ConcatablePaint.h"
2
+
3
+ #include "DeclarationContext.h"
4
+ #include "JsiDomNode.h"
5
+ #include "PaintProps.h"
6
+
7
+ namespace RNSkia {
8
+
9
+ ConcatablePaint::ConcatablePaint(
10
+ DeclarationContext *declarationContext, PaintProps *paintProps,
11
+ const std::vector<std::shared_ptr<JsiDomNode>> &children)
12
+ : _declarationContext(declarationContext), _paintProps(paintProps),
13
+ _children(children) {
14
+
15
+ auto hasPropertyValues = _paintProps->getColor()->isSet() ||
16
+ _paintProps->getStrokeWidth()->isSet() ||
17
+ _paintProps->getBlendMode()->isSet() ||
18
+ _paintProps->getStyle()->isSet() ||
19
+ _paintProps->getStrokeJoin()->isSet() ||
20
+ _paintProps->getStrokeCap()->isSet() ||
21
+ _paintProps->getStrokeMiter()->isSet() ||
22
+ _paintProps->getOpacity()->isSet() ||
23
+ _paintProps->getAntiAlias()->isSet();
24
+
25
+ _declarationContext->save();
26
+
27
+ for (auto &child : _children) {
28
+ child->decorateContext(_declarationContext);
29
+ }
30
+
31
+ _imageFilter = declarationContext->getImageFilters()->popAsOne();
32
+ _colorFilter = declarationContext->getColorFilters()->popAsOne();
33
+ _shader = declarationContext->getShaders()->pop();
34
+ _maskFilter = declarationContext->getMaskFilters()->pop();
35
+ _pathEffect = declarationContext->getPathEffects()->popAsOne();
36
+
37
+ _declarationContext->restore();
38
+
39
+ _isEmpty = !hasPropertyValues && _imageFilter == nullptr &&
40
+ _colorFilter == nullptr && _shader == nullptr &&
41
+ _maskFilter == nullptr && _pathEffect == nullptr;
42
+ }
43
+
44
+ bool ConcatablePaint::isEmpty() { return _isEmpty; }
45
+
46
+ void ConcatablePaint::concatTo(std::shared_ptr<SkPaint> paint) {
47
+
48
+ if (_paintProps->getOpacity()->isSet()) {
49
+ paint->setAlphaf(paint->getAlphaf() *
50
+ _paintProps->getOpacity()->value().getAsNumber());
51
+ }
52
+
53
+ if (_paintProps->getColor()->isSet()) {
54
+ auto currentOpacity = paint->getAlphaf();
55
+ paint->setShader(nullptr);
56
+ paint->setColor(*_paintProps->getColor()->getDerivedValue());
57
+ paint->setAlphaf(paint->getAlphaf() * currentOpacity);
58
+ }
59
+
60
+ if (_paintProps->getStrokeWidth()->isSet()) {
61
+ paint->setStrokeWidth(_paintProps->getStrokeWidth()->value().getAsNumber());
62
+ }
63
+
64
+ if (_paintProps->getBlendMode()->isSet()) {
65
+ paint->setBlendMode(*_paintProps->getBlendMode()->getDerivedValue());
66
+ }
67
+
68
+ if (_paintProps->getStyle()->isSet()) {
69
+ auto styleValue = _paintProps->getStyle()->value().getAsString();
70
+ if (styleValue == "stroke") {
71
+ paint->setStyle(SkPaint::Style::kStroke_Style);
72
+ } else if (styleValue == "fill") {
73
+ paint->setStyle(SkPaint::Style::kFill_Style);
74
+ } else {
75
+ throw std::runtime_error(styleValue +
76
+ " is not a valud value for the style property.");
77
+ }
78
+ }
79
+
80
+ if (_paintProps->getStrokeJoin()->isSet()) {
81
+ paint->setStrokeJoin(*_paintProps->getStrokeJoin()->getDerivedValue());
82
+ }
83
+
84
+ if (_paintProps->getStrokeCap()->isSet()) {
85
+ paint->setStrokeCap(*_paintProps->getStrokeCap()->getDerivedValue());
86
+ }
87
+
88
+ if (_paintProps->getStrokeMiter()->isSet()) {
89
+ paint->setStrokeMiter(_paintProps->getStrokeMiter()->value().getAsNumber());
90
+ }
91
+
92
+ if (_paintProps->getAntiAlias()->isSet()) {
93
+ paint->setAntiAlias(_paintProps->getAntiAlias()->value().getAsBool());
94
+ }
95
+
96
+ if (_imageFilter) {
97
+ paint->setImageFilter(_imageFilter);
98
+ }
99
+
100
+ if (_colorFilter) {
101
+ paint->setColorFilter(_colorFilter);
102
+ }
103
+
104
+ if (_shader) {
105
+ paint->setShader(_shader);
106
+ }
107
+
108
+ if (_maskFilter) {
109
+ paint->setMaskFilter(_maskFilter);
110
+ }
111
+
112
+ if (_pathEffect) {
113
+ paint->setPathEffect(_pathEffect);
114
+ }
115
+ }
116
+
117
+ } // namespace RNSkia
@@ -0,0 +1,49 @@
1
+ #pragma once
2
+
3
+ #include <memory>
4
+ #include <vector>
5
+
6
+ #pragma clang diagnostic push
7
+ #pragma clang diagnostic ignored "-Wdocumentation"
8
+
9
+ #include <SkColorFilter.h>
10
+ #include <SkImageFilter.h>
11
+ #include <SkMaskFilter.h>
12
+ #include <SkPaint.h>
13
+ #include <SkPathEffect.h>
14
+ #include <SkShader.h>
15
+
16
+ #pragma clang diagnostic pop
17
+
18
+ namespace RNSkia {
19
+
20
+ class JsiDomNode;
21
+ class PaintProps;
22
+ class DeclarationContext;
23
+
24
+ /**
25
+ Class for concatenating SkPaint objects.
26
+ */
27
+ class ConcatablePaint {
28
+ public:
29
+ ConcatablePaint(DeclarationContext *context, PaintProps *paintProps,
30
+ const std::vector<std::shared_ptr<JsiDomNode>> &children);
31
+
32
+ void concatTo(std::shared_ptr<SkPaint> paint);
33
+ bool isEmpty();
34
+
35
+ private:
36
+ DeclarationContext *_declarationContext;
37
+ const std::vector<std::shared_ptr<JsiDomNode>> _children;
38
+ PaintProps *_paintProps;
39
+
40
+ bool _isEmpty{true};
41
+
42
+ sk_sp<SkImageFilter> _imageFilter;
43
+ sk_sp<SkColorFilter> _colorFilter;
44
+ sk_sp<SkPathEffect> _pathEffect;
45
+ sk_sp<SkMaskFilter> _maskFilter;
46
+ sk_sp<SkShader> _shader;
47
+ };
48
+
49
+ } // namespace RNSkia
@@ -0,0 +1,88 @@
1
+ #pragma once
2
+
3
+ #include <algorithm>
4
+ #include <numeric>
5
+ #include <stack>
6
+ #include <utility>
7
+ #include <vector>
8
+
9
+ #pragma clang diagnostic push
10
+ #pragma clang diagnostic ignored "-Wdocumentation"
11
+
12
+ #include <SkRefCnt.h>
13
+
14
+ #pragma clang diagnostic pop
15
+
16
+ namespace RNSkia {
17
+
18
+ /**
19
+ Small container for shaders, filters, masks and effects
20
+ */
21
+ template <typename T> class Declaration {
22
+ public:
23
+ // Pushes to the stack
24
+ void push(T el) { _elements.push(el); }
25
+
26
+ // Clears and returns all elements
27
+ std::vector<T> popAll() { return popMultiple(_elements.size()); }
28
+
29
+ // Pops the number of items up to limit
30
+ std::vector<T> popMultiple(size_t limit) {
31
+ auto size = std::min(limit, _elements.size());
32
+ std::vector<T> tmp;
33
+ tmp.reserve(size);
34
+ for (size_t i = 0; i < size; ++i) {
35
+ tmp.push_back(_elements.top());
36
+ _elements.pop();
37
+ }
38
+ return tmp;
39
+ }
40
+
41
+ T pop() {
42
+ if (_elements.size() == 0) {
43
+ return nullptr;
44
+ }
45
+ auto tmp = _elements.top();
46
+ _elements.pop();
47
+ return tmp;
48
+ }
49
+
50
+ // Clears and returns through reducer function in reversed order
51
+ T popAsOne(std::function<T(T inner, T outer)> composer) {
52
+ auto tmp = popAll();
53
+ // std::reverse(std::begin(tmp), std::end(tmp));
54
+ return std::accumulate(std::begin(tmp), std::end(tmp),
55
+ static_cast<T>(nullptr), [=](T inner, T outer) {
56
+ if (inner == nullptr) {
57
+ return outer;
58
+ }
59
+ return composer(inner, outer);
60
+ });
61
+ }
62
+
63
+ // Returns the size of the elements
64
+ size_t size() { return _elements.size(); }
65
+
66
+ protected:
67
+ std::stack<T> _elements;
68
+ };
69
+
70
+ /**
71
+ Small container for shaders, filters, masks and effects
72
+ */
73
+ template <typename T> class ComposableDeclaration : public Declaration<T> {
74
+ public:
75
+ /**
76
+ Constructor
77
+ */
78
+ explicit ComposableDeclaration(std::function<T(T inner, T outer)> composer)
79
+ : Declaration<T>(), _composer(composer) {}
80
+
81
+ // Clears and returns through reducer function in reversed order
82
+ T popAsOne() { return Declaration<T>::popAsOne(_composer); }
83
+
84
+ private:
85
+ std::function<T(T inner, T outer)> _composer;
86
+ };
87
+
88
+ } // namespace RNSkia
@@ -0,0 +1,79 @@
1
+ #pragma once
2
+
3
+ #include "Declaration.h"
4
+
5
+ #include <memory>
6
+ #include <stack>
7
+ #include <vector>
8
+
9
+ #pragma clang diagnostic push
10
+ #pragma clang diagnostic ignored "-Wdocumentation"
11
+
12
+ #include <SkColorFilter.h>
13
+ #include <SkImageFilter.h>
14
+ #include <SkImageFilters.h>
15
+ #include <SkMaskFilter.h>
16
+ #include <SkPaint.h>
17
+ #include <SkPathEffect.h>
18
+ #include <SkShader.h>
19
+
20
+ #pragma clang diagnostic pop
21
+
22
+ namespace RNSkia {
23
+
24
+ class DeclarationContext {
25
+ public:
26
+ DeclarationContext() { save(); }
27
+
28
+ Declaration<sk_sp<SkShader>> *getShaders() { return &_shaders.top(); }
29
+ ComposableDeclaration<sk_sp<SkImageFilter>> *getImageFilters() {
30
+ return &_imageFilters.top();
31
+ }
32
+ ComposableDeclaration<sk_sp<SkColorFilter>> *getColorFilters() {
33
+ return &_colorFilters.top();
34
+ }
35
+ ComposableDeclaration<sk_sp<SkPathEffect>> *getPathEffects() {
36
+ return &_pathEffects.top();
37
+ }
38
+ Declaration<sk_sp<SkMaskFilter>> *getMaskFilters() {
39
+ return &_maskFilters.top();
40
+ }
41
+ Declaration<std::shared_ptr<SkPaint>> *getPaints() { return &_paints.top(); }
42
+
43
+ void save() {
44
+ _paints.emplace();
45
+ _shaders.emplace();
46
+ _imageFilters.emplace(
47
+ [](sk_sp<SkImageFilter> inner, sk_sp<SkImageFilter> outer) {
48
+ return SkImageFilters::Compose(outer, inner);
49
+ });
50
+ _colorFilters.emplace(
51
+ [](sk_sp<SkColorFilter> inner, sk_sp<SkColorFilter> outer) {
52
+ return SkColorFilters::Compose(outer, inner);
53
+ });
54
+ _pathEffects.emplace(
55
+ [](sk_sp<SkPathEffect> inner, sk_sp<SkPathEffect> outer) {
56
+ return SkPathEffect::MakeCompose(outer, inner);
57
+ });
58
+ _maskFilters.emplace();
59
+ }
60
+
61
+ void restore() {
62
+ _shaders.pop();
63
+ _imageFilters.pop();
64
+ _colorFilters.pop();
65
+ _pathEffects.pop();
66
+ _maskFilters.pop();
67
+ _paints.pop();
68
+ }
69
+
70
+ private:
71
+ std::stack<Declaration<sk_sp<SkShader>>> _shaders;
72
+ std::stack<ComposableDeclaration<sk_sp<SkImageFilter>>> _imageFilters;
73
+ std::stack<ComposableDeclaration<sk_sp<SkColorFilter>>> _colorFilters;
74
+ std::stack<ComposableDeclaration<sk_sp<SkPathEffect>>> _pathEffects;
75
+ std::stack<Declaration<sk_sp<SkMaskFilter>>> _maskFilters;
76
+ std::stack<Declaration<std::shared_ptr<SkPaint>>> _paints;
77
+ };
78
+
79
+ } // namespace RNSkia