@shopify/react-native-skia 0.1.122 → 0.1.125

Sign up to get free protection for your applications and to get access to all the features.
Files changed (466) hide show
  1. package/android/CMakeLists.txt +6 -1
  2. package/android/build.gradle +1 -1
  3. package/android/cpp/jni/JniSkiaDrawView.cpp +14 -71
  4. package/android/cpp/jni/JniSkiaManager.cpp +1 -1
  5. package/android/cpp/jni/include/JniSkiaDrawView.h +18 -22
  6. package/android/cpp/jni/include/JniSkiaManager.h +4 -4
  7. package/android/cpp/rnskia-android/RNSkDrawViewImpl.cpp +68 -0
  8. package/android/cpp/rnskia-android/RNSkDrawViewImpl.h +48 -0
  9. package/android/cpp/{jni/include/JniPlatformContextWrapper.h → rnskia-android/RNSkPlatformContextImpl.h} +4 -4
  10. package/android/cpp/{jni → rnskia-android}/SkiaOpenGLRenderer.cpp +39 -54
  11. package/android/cpp/{jni/include → rnskia-android}/SkiaOpenGLRenderer.h +2 -31
  12. package/android/src/main/java/com/shopify/reactnative/skia/RNSkiaViewManager.java +1 -1
  13. package/android/src/main/java/com/shopify/reactnative/skia/SkiaDrawView.java +21 -28
  14. package/cpp/api/JsiSkApi.h +3 -1
  15. package/cpp/api/JsiSkCanvas.h +1 -1
  16. package/cpp/api/JsiSkColor.h +41 -7
  17. package/cpp/api/JsiSkColorFilterFactory.h +2 -1
  18. package/cpp/api/JsiSkImageFilter.h +0 -2
  19. package/cpp/api/JsiSkImageFilterFactory.h +37 -17
  20. package/cpp/api/JsiSkMatrix.h +44 -2
  21. package/cpp/api/JsiSkPaint.h +4 -7
  22. package/cpp/api/JsiSkRuntimeEffect.h +7 -0
  23. package/cpp/api/JsiSkRuntimeEffectFactory.h +3 -2
  24. package/cpp/api/JsiSkRuntimeShaderBuilder.h +70 -0
  25. package/cpp/api/JsiSkShaderFactory.h +2 -2
  26. package/cpp/api/JsiSkVertices.h +1 -1
  27. package/cpp/api/third_party/CSSColorParser.cpp +194 -0
  28. package/cpp/api/third_party/CSSColorParser.h +1 -191
  29. package/cpp/jsi/JsiSimpleValueWrapper.h +98 -0
  30. package/cpp/rnskia/RNSkAnimation.h +0 -2
  31. package/cpp/rnskia/RNSkDrawView.cpp +84 -126
  32. package/cpp/rnskia/RNSkDrawView.h +7 -37
  33. package/cpp/rnskia/RNSkJsiViewApi.h +8 -5
  34. package/cpp/rnskia/RNSkManager.cpp +2 -2
  35. package/cpp/rnskia/RNSkManager.h +2 -2
  36. package/cpp/rnskia/RNSkPlatformContext.h +1 -1
  37. package/cpp/rnskia/RNSkValueApi.h +6 -2
  38. package/cpp/rnskia/values/RNSkClockValue.h +18 -10
  39. package/cpp/rnskia/values/RNSkDerivedValue.h +12 -5
  40. package/cpp/rnskia/values/RNSkReadonlyValue.h +25 -17
  41. package/cpp/rnskia/values/RNSkValue.h +8 -3
  42. package/cpp/utils/RNSkTimingInfo.h +13 -1
  43. package/ios/RNSkia-iOS/PlatformContext.h +30 -4
  44. package/ios/RNSkia-iOS/RNSkDrawViewImpl.h +8 -10
  45. package/ios/RNSkia-iOS/RNSkDrawViewImpl.mm +25 -10
  46. package/ios/RNSkia-iOS/SkiaDrawView.mm +22 -20
  47. package/lib/commonjs/{values/animation → animation}/decay/decay.js +0 -0
  48. package/lib/commonjs/{values/animation → animation}/decay/decay.js.map +0 -0
  49. package/lib/commonjs/{values/animation → animation}/decay/index.js +0 -0
  50. package/lib/commonjs/{values/animation → animation}/decay/index.js.map +0 -0
  51. package/lib/commonjs/{values/animation → animation}/decay/runDecay.js +1 -1
  52. package/lib/commonjs/animation/decay/runDecay.js.map +1 -0
  53. package/lib/commonjs/{values/animation → animation}/decay/types.js +0 -0
  54. package/lib/commonjs/{values/animation → animation}/decay/types.js.map +0 -0
  55. package/lib/commonjs/{values/animation → animation}/functions/index.js +0 -0
  56. package/lib/commonjs/{values/animation → animation}/functions/index.js.map +0 -0
  57. package/lib/commonjs/animation/functions/interpolate.js +141 -0
  58. package/lib/commonjs/animation/functions/interpolate.js.map +1 -0
  59. package/lib/commonjs/animation/functions/interpolateColors.js +39 -0
  60. package/lib/commonjs/animation/functions/interpolateColors.js.map +1 -0
  61. package/lib/commonjs/{values/animation → animation}/index.js +0 -0
  62. package/lib/commonjs/{values/animation → animation}/index.js.map +0 -0
  63. package/lib/commonjs/{values/animation → animation}/spring/Spring.js +0 -0
  64. package/lib/commonjs/{values/animation → animation}/spring/Spring.js.map +0 -0
  65. package/lib/commonjs/{values/animation → animation}/spring/functions/index.js +0 -0
  66. package/lib/commonjs/{values/animation → animation}/spring/functions/index.js.map +0 -0
  67. package/lib/commonjs/{values/animation → animation}/spring/functions/spring.js +0 -0
  68. package/lib/commonjs/{values/animation → animation}/spring/functions/spring.js.map +0 -0
  69. package/lib/commonjs/{values/animation → animation}/spring/index.js +0 -0
  70. package/lib/commonjs/{values/animation → animation}/spring/index.js.map +0 -0
  71. package/lib/commonjs/{values/animation → animation}/spring/runSpring.js +0 -0
  72. package/lib/commonjs/animation/spring/runSpring.js.map +1 -0
  73. package/lib/commonjs/{values/animation → animation}/spring/types.js +0 -0
  74. package/lib/commonjs/{values/animation → animation}/spring/types.js.map +0 -0
  75. package/lib/commonjs/{values/animation → animation}/spring/useSpring.js +0 -0
  76. package/lib/commonjs/animation/spring/useSpring.js.map +1 -0
  77. package/lib/commonjs/{values/animation → animation}/timing/Easing.js +0 -0
  78. package/lib/commonjs/{values/animation → animation}/timing/Easing.js.map +0 -0
  79. package/lib/commonjs/{values/animation → animation}/timing/createTiming.js +1 -1
  80. package/lib/commonjs/animation/timing/createTiming.js.map +1 -0
  81. package/lib/commonjs/{values/animation → animation}/timing/functions/bezier.js +0 -0
  82. package/lib/commonjs/{values/animation → animation}/timing/functions/bezier.js.map +0 -0
  83. package/lib/commonjs/{values/animation → animation}/timing/functions/getResolvedParams.js +3 -3
  84. package/lib/commonjs/animation/timing/functions/getResolvedParams.js.map +1 -0
  85. package/lib/commonjs/{values/animation → animation}/timing/functions/index.js +0 -0
  86. package/lib/commonjs/{values/animation → animation}/timing/functions/index.js.map +0 -0
  87. package/lib/commonjs/{values/animation → animation}/timing/functions/timing.js +0 -0
  88. package/lib/commonjs/{values/animation → animation}/timing/functions/timing.js.map +1 -1
  89. package/lib/commonjs/{values/animation → animation}/timing/functions/types.js +0 -0
  90. package/lib/commonjs/{values/animation → animation}/timing/functions/types.js.map +0 -0
  91. package/lib/commonjs/{values/animation → animation}/timing/index.js +0 -0
  92. package/lib/commonjs/{values/animation → animation}/timing/index.js.map +0 -0
  93. package/lib/commonjs/{values/animation → animation}/timing/runTiming.js +0 -0
  94. package/lib/commonjs/animation/timing/runTiming.js.map +1 -0
  95. package/lib/commonjs/{values/animation → animation}/timing/useLoop.js +0 -0
  96. package/lib/commonjs/{values/animation → animation}/timing/useLoop.js.map +0 -0
  97. package/lib/commonjs/{values/animation → animation}/timing/useTiming.js +1 -1
  98. package/lib/commonjs/animation/timing/useTiming.js.map +1 -0
  99. package/lib/commonjs/{values/animation → animation}/types.js +0 -0
  100. package/lib/commonjs/{values/animation → animation}/types.js.map +0 -0
  101. package/lib/commonjs/index.js +13 -0
  102. package/lib/commonjs/index.js.map +1 -1
  103. package/lib/commonjs/renderer/Canvas.js +17 -8
  104. package/lib/commonjs/renderer/Canvas.js.map +1 -1
  105. package/lib/commonjs/renderer/components/Paint.js +1 -1
  106. package/lib/commonjs/renderer/components/Paint.js.map +1 -1
  107. package/lib/commonjs/renderer/components/colorFilters/BlendColor.js.map +1 -1
  108. package/lib/commonjs/renderer/components/colorFilters/Lerp.js +1 -1
  109. package/lib/commonjs/renderer/components/colorFilters/Lerp.js.map +1 -1
  110. package/lib/commonjs/renderer/components/imageFilters/InnerShadow.js +4 -2
  111. package/lib/commonjs/renderer/components/imageFilters/InnerShadow.js.map +1 -1
  112. package/lib/commonjs/renderer/components/imageFilters/RuntimeShader.js +37 -0
  113. package/lib/commonjs/renderer/components/imageFilters/RuntimeShader.js.map +1 -0
  114. package/lib/commonjs/renderer/components/imageFilters/index.js +13 -0
  115. package/lib/commonjs/renderer/components/imageFilters/index.js.map +1 -1
  116. package/lib/commonjs/renderer/components/shaders/Gradient.js +1 -1
  117. package/lib/commonjs/renderer/components/shaders/Gradient.js.map +1 -1
  118. package/lib/commonjs/renderer/components/shaders/Shader.js +2 -2
  119. package/lib/commonjs/renderer/components/shaders/Shader.js.map +1 -1
  120. package/lib/commonjs/renderer/components/shapes/Path.js +9 -1
  121. package/lib/commonjs/renderer/components/shapes/Path.js.map +1 -1
  122. package/lib/commonjs/renderer/processors/Circles.js +3 -2
  123. package/lib/commonjs/renderer/processors/Circles.js.map +1 -1
  124. package/lib/commonjs/renderer/processors/Font.js +1 -1
  125. package/lib/commonjs/renderer/processors/Font.js.map +1 -1
  126. package/lib/commonjs/renderer/processors/Paint.js +6 -1
  127. package/lib/commonjs/renderer/processors/Paint.js.map +1 -1
  128. package/lib/commonjs/renderer/processors/Rects.js +11 -21
  129. package/lib/commonjs/renderer/processors/Rects.js.map +1 -1
  130. package/lib/commonjs/renderer/processors/math/Matrix3.js +42 -63
  131. package/lib/commonjs/renderer/processors/math/Matrix3.js.map +1 -1
  132. package/lib/commonjs/renderer/processors/math/Vector.js +4 -5
  133. package/lib/commonjs/renderer/processors/math/Vector.js.map +1 -1
  134. package/lib/commonjs/skia/Color.js +14 -38
  135. package/lib/commonjs/skia/Color.js.map +1 -1
  136. package/lib/commonjs/skia/ImageFilter/ImageFilterFactory.js.map +1 -1
  137. package/lib/commonjs/skia/Matrix.js.map +1 -1
  138. package/lib/commonjs/skia/Paint/Paint.js +13 -1
  139. package/lib/commonjs/skia/Paint/Paint.js.map +1 -1
  140. package/lib/commonjs/skia/Paint/usePaint.js +2 -4
  141. package/lib/commonjs/skia/Paint/usePaint.js.map +1 -1
  142. package/lib/commonjs/skia/Shader/useShader.js +4 -1
  143. package/lib/commonjs/skia/Shader/useShader.js.map +1 -1
  144. package/lib/commonjs/skia/Skia.js +3 -43
  145. package/lib/commonjs/skia/Skia.js.map +1 -1
  146. package/lib/commonjs/skia/SkiaApi.js +4 -0
  147. package/lib/commonjs/skia/SkiaApi.js.map +1 -0
  148. package/lib/commonjs/values/api.js +4 -6
  149. package/lib/commonjs/values/api.js.map +1 -1
  150. package/lib/commonjs/values/api.web.js +18 -0
  151. package/lib/commonjs/values/api.web.js.map +1 -0
  152. package/lib/commonjs/values/index.js +0 -13
  153. package/lib/commonjs/values/index.js.map +1 -1
  154. package/lib/commonjs/values/web/RNSkAnimation.js +46 -0
  155. package/lib/commonjs/values/web/RNSkAnimation.js.map +1 -0
  156. package/lib/commonjs/values/web/RNSkClockValue.js +75 -0
  157. package/lib/commonjs/values/web/RNSkClockValue.js.map +1 -0
  158. package/lib/commonjs/values/web/RNSkDerivedValue.js +51 -0
  159. package/lib/commonjs/values/web/RNSkDerivedValue.js.map +1 -0
  160. package/lib/commonjs/values/web/RNSkReadonlyValue.js +45 -0
  161. package/lib/commonjs/values/web/RNSkReadonlyValue.js.map +1 -0
  162. package/lib/commonjs/values/web/RNSkValue.js +73 -0
  163. package/lib/commonjs/values/web/RNSkValue.js.map +1 -0
  164. package/lib/commonjs/values/web/api.js +31 -0
  165. package/lib/commonjs/values/web/api.js.map +1 -0
  166. package/lib/commonjs/values/web/index.js +19 -0
  167. package/lib/commonjs/values/web/index.js.map +1 -0
  168. package/lib/commonjs/views/SkiaView.js +13 -10
  169. package/lib/commonjs/views/SkiaView.js.map +1 -1
  170. package/lib/commonjs/views/api.js +11 -0
  171. package/lib/commonjs/views/api.js.map +1 -0
  172. package/lib/commonjs/views/types.js.map +1 -1
  173. package/lib/module/{values/animation → animation}/decay/decay.js +0 -0
  174. package/lib/module/{values/animation → animation}/decay/decay.js.map +0 -0
  175. package/lib/module/{values/animation → animation}/decay/index.js +0 -0
  176. package/lib/module/{values/animation → animation}/decay/index.js.map +0 -0
  177. package/lib/module/{values/animation → animation}/decay/runDecay.js +1 -1
  178. package/lib/module/animation/decay/runDecay.js.map +1 -0
  179. package/lib/module/{values/animation → animation}/decay/types.js +0 -0
  180. package/lib/module/{values/animation → animation}/decay/types.js.map +0 -0
  181. package/lib/module/{values/animation → animation}/functions/index.js +0 -0
  182. package/lib/module/{values/animation → animation}/functions/index.js.map +0 -0
  183. package/lib/module/animation/functions/interpolate.js +132 -0
  184. package/lib/module/animation/functions/interpolate.js.map +1 -0
  185. package/lib/module/animation/functions/interpolateColors.js +23 -0
  186. package/lib/module/animation/functions/interpolateColors.js.map +1 -0
  187. package/lib/module/{values/animation → animation}/index.js +0 -0
  188. package/lib/module/{values/animation → animation}/index.js.map +0 -0
  189. package/lib/module/{values/animation → animation}/spring/Spring.js +0 -0
  190. package/lib/module/{values/animation → animation}/spring/Spring.js.map +0 -0
  191. package/lib/module/{values/animation → animation}/spring/functions/index.js +0 -0
  192. package/lib/module/{values/animation → animation}/spring/functions/index.js.map +0 -0
  193. package/lib/module/{values/animation → animation}/spring/functions/spring.js +0 -0
  194. package/lib/module/{values/animation → animation}/spring/functions/spring.js.map +0 -0
  195. package/lib/module/{values/animation → animation}/spring/index.js +0 -0
  196. package/lib/module/{values/animation → animation}/spring/index.js.map +0 -0
  197. package/lib/module/{values/animation → animation}/spring/runSpring.js +0 -0
  198. package/lib/module/animation/spring/runSpring.js.map +1 -0
  199. package/lib/module/{values/animation → animation}/spring/types.js +0 -0
  200. package/lib/module/{values/animation → animation}/spring/types.js.map +0 -0
  201. package/lib/module/{values/animation → animation}/spring/useSpring.js +0 -0
  202. package/lib/module/animation/spring/useSpring.js.map +1 -0
  203. package/lib/module/{values/animation → animation}/timing/Easing.js +0 -0
  204. package/lib/module/{values/animation → animation}/timing/Easing.js.map +0 -0
  205. package/lib/module/{values/animation → animation}/timing/createTiming.js +1 -1
  206. package/lib/module/animation/timing/createTiming.js.map +1 -0
  207. package/lib/module/{values/animation → animation}/timing/functions/bezier.js +0 -0
  208. package/lib/module/{values/animation → animation}/timing/functions/bezier.js.map +0 -0
  209. package/lib/module/{values/animation → animation}/timing/functions/getResolvedParams.js +3 -3
  210. package/lib/module/animation/timing/functions/getResolvedParams.js.map +1 -0
  211. package/lib/module/{values/animation → animation}/timing/functions/index.js +0 -0
  212. package/lib/module/{values/animation → animation}/timing/functions/index.js.map +0 -0
  213. package/lib/module/{values/animation → animation}/timing/functions/timing.js +0 -0
  214. package/lib/module/{values/animation → animation}/timing/functions/timing.js.map +1 -1
  215. package/lib/module/{values/animation → animation}/timing/functions/types.js +0 -0
  216. package/lib/module/{values/animation → animation}/timing/functions/types.js.map +0 -0
  217. package/lib/module/{values/animation → animation}/timing/index.js +0 -0
  218. package/lib/module/{values/animation → animation}/timing/index.js.map +0 -0
  219. package/lib/module/{values/animation → animation}/timing/runTiming.js +0 -0
  220. package/lib/module/animation/timing/runTiming.js.map +1 -0
  221. package/lib/module/{values/animation → animation}/timing/useLoop.js +0 -0
  222. package/lib/module/{values/animation → animation}/timing/useLoop.js.map +0 -0
  223. package/lib/module/{values/animation → animation}/timing/useTiming.js +1 -1
  224. package/lib/module/animation/timing/useTiming.js.map +1 -0
  225. package/lib/module/{values/animation → animation}/types.js +0 -0
  226. package/lib/module/{values/animation → animation}/types.js.map +0 -0
  227. package/lib/module/index.js +1 -0
  228. package/lib/module/index.js.map +1 -1
  229. package/lib/module/renderer/Canvas.js +12 -6
  230. package/lib/module/renderer/Canvas.js.map +1 -1
  231. package/lib/module/renderer/components/Paint.js +2 -2
  232. package/lib/module/renderer/components/Paint.js.map +1 -1
  233. package/lib/module/renderer/components/colorFilters/BlendColor.js.map +1 -1
  234. package/lib/module/renderer/components/colorFilters/Lerp.js +1 -1
  235. package/lib/module/renderer/components/colorFilters/Lerp.js.map +1 -1
  236. package/lib/module/renderer/components/imageFilters/InnerShadow.js +3 -2
  237. package/lib/module/renderer/components/imageFilters/InnerShadow.js.map +1 -1
  238. package/lib/module/renderer/components/imageFilters/RuntimeShader.js +19 -0
  239. package/lib/module/renderer/components/imageFilters/RuntimeShader.js.map +1 -0
  240. package/lib/module/renderer/components/imageFilters/index.js +1 -0
  241. package/lib/module/renderer/components/imageFilters/index.js.map +1 -1
  242. package/lib/module/renderer/components/shaders/Gradient.js +2 -2
  243. package/lib/module/renderer/components/shaders/Gradient.js.map +1 -1
  244. package/lib/module/renderer/components/shaders/Shader.js +3 -2
  245. package/lib/module/renderer/components/shaders/Shader.js.map +1 -1
  246. package/lib/module/renderer/components/shapes/Path.js +9 -2
  247. package/lib/module/renderer/components/shapes/Path.js.map +1 -1
  248. package/lib/module/renderer/processors/Circles.js +3 -2
  249. package/lib/module/renderer/processors/Circles.js.map +1 -1
  250. package/lib/module/renderer/processors/Font.js +1 -1
  251. package/lib/module/renderer/processors/Font.js.map +1 -1
  252. package/lib/module/renderer/processors/Paint.js +6 -1
  253. package/lib/module/renderer/processors/Paint.js.map +1 -1
  254. package/lib/module/renderer/processors/Rects.js +9 -21
  255. package/lib/module/renderer/processors/Rects.js.map +1 -1
  256. package/lib/module/renderer/processors/math/Matrix3.js +52 -72
  257. package/lib/module/renderer/processors/math/Matrix3.js.map +1 -1
  258. package/lib/module/renderer/processors/math/Vector.js +3 -5
  259. package/lib/module/renderer/processors/math/Vector.js.map +1 -1
  260. package/lib/module/skia/Color.js +9 -25
  261. package/lib/module/skia/Color.js.map +1 -1
  262. package/lib/module/skia/ImageFilter/ImageFilterFactory.js.map +1 -1
  263. package/lib/module/skia/Matrix.js.map +1 -1
  264. package/lib/module/skia/Paint/Paint.js +6 -0
  265. package/lib/module/skia/Paint/Paint.js.map +1 -1
  266. package/lib/module/skia/Paint/usePaint.js +2 -3
  267. package/lib/module/skia/Paint/usePaint.js.map +1 -1
  268. package/lib/module/skia/Shader/useShader.js +4 -1
  269. package/lib/module/skia/Shader/useShader.js.map +1 -1
  270. package/lib/module/skia/Skia.js +2 -44
  271. package/lib/module/skia/Skia.js.map +1 -1
  272. package/lib/module/skia/SkiaApi.js +2 -0
  273. package/lib/module/skia/SkiaApi.js.map +1 -0
  274. package/lib/module/values/api.js +4 -6
  275. package/lib/module/values/api.js.map +1 -1
  276. package/lib/module/values/api.web.js +7 -0
  277. package/lib/module/values/api.web.js.map +1 -0
  278. package/lib/module/values/index.js +0 -1
  279. package/lib/module/values/index.js.map +1 -1
  280. package/lib/module/values/web/RNSkAnimation.js +36 -0
  281. package/lib/module/values/web/RNSkAnimation.js.map +1 -0
  282. package/lib/module/values/web/RNSkClockValue.js +65 -0
  283. package/lib/module/values/web/RNSkClockValue.js.map +1 -0
  284. package/lib/module/values/web/RNSkDerivedValue.js +41 -0
  285. package/lib/module/values/web/RNSkDerivedValue.js.map +1 -0
  286. package/lib/module/values/web/RNSkReadonlyValue.js +36 -0
  287. package/lib/module/values/web/RNSkReadonlyValue.js.map +1 -0
  288. package/lib/module/values/web/RNSkValue.js +63 -0
  289. package/lib/module/values/web/RNSkValue.js.map +1 -0
  290. package/lib/module/values/web/api.js +19 -0
  291. package/lib/module/values/web/api.js.map +1 -0
  292. package/lib/module/values/web/index.js +2 -0
  293. package/lib/module/values/web/index.js.map +1 -0
  294. package/lib/module/views/SkiaView.js +1 -3
  295. package/lib/module/views/SkiaView.js.map +1 -1
  296. package/lib/module/views/api.js +4 -0
  297. package/lib/module/views/api.js.map +1 -0
  298. package/lib/module/views/types.js.map +1 -1
  299. package/lib/typescript/src/{values/animation → animation}/decay/decay.d.ts +0 -0
  300. package/lib/typescript/src/{values/animation → animation}/decay/index.d.ts +0 -0
  301. package/lib/typescript/src/{values/animation → animation}/decay/runDecay.d.ts +2 -2
  302. package/lib/typescript/src/{values/animation → animation}/decay/types.d.ts +1 -1
  303. package/lib/typescript/src/{values/animation → animation}/functions/index.d.ts +0 -0
  304. package/lib/typescript/src/animation/functions/interpolate.d.ts +11 -0
  305. package/lib/typescript/src/animation/functions/interpolateColors.d.ts +3 -0
  306. package/lib/typescript/src/{values/animation → animation}/index.d.ts +0 -0
  307. package/lib/typescript/src/{values/animation → animation}/spring/Spring.d.ts +0 -0
  308. package/lib/typescript/src/{values/animation → animation}/spring/functions/index.d.ts +0 -0
  309. package/lib/typescript/src/{values/animation → animation}/spring/functions/spring.d.ts +0 -0
  310. package/lib/typescript/src/{values/animation → animation}/spring/index.d.ts +0 -0
  311. package/lib/typescript/src/{values/animation → animation}/spring/runSpring.d.ts +1 -1
  312. package/lib/typescript/src/{values/animation → animation}/spring/types.d.ts +0 -0
  313. package/lib/typescript/src/{values/animation → animation}/spring/useSpring.d.ts +1 -1
  314. package/lib/typescript/src/{values/animation → animation}/timing/Easing.d.ts +0 -0
  315. package/lib/typescript/src/{values/animation → animation}/timing/createTiming.d.ts +2 -2
  316. package/lib/typescript/src/{values/animation → animation}/timing/functions/bezier.d.ts +0 -0
  317. package/lib/typescript/src/{values/animation → animation}/timing/functions/getResolvedParams.d.ts +0 -0
  318. package/lib/typescript/src/{values/animation → animation}/timing/functions/index.d.ts +0 -0
  319. package/lib/typescript/src/{values/animation → animation}/timing/functions/timing.d.ts +1 -1
  320. package/lib/typescript/src/{values/animation → animation}/timing/functions/types.d.ts +0 -0
  321. package/lib/typescript/src/{values/animation → animation}/timing/index.d.ts +0 -0
  322. package/lib/typescript/src/{values/animation → animation}/timing/runTiming.d.ts +1 -1
  323. package/lib/typescript/src/{values/animation → animation}/timing/useLoop.d.ts +0 -0
  324. package/lib/typescript/src/{values/animation → animation}/timing/useTiming.d.ts +1 -1
  325. package/lib/typescript/src/{values/animation → animation}/types.d.ts +5 -5
  326. package/lib/typescript/src/index.d.ts +1 -0
  327. package/lib/typescript/src/renderer/Canvas.d.ts +6 -0
  328. package/lib/typescript/src/renderer/components/colorFilters/BlendColor.d.ts +1 -1
  329. package/lib/typescript/src/renderer/components/imageFilters/RuntimeShader.d.ts +7 -0
  330. package/lib/typescript/src/renderer/components/imageFilters/index.d.ts +1 -0
  331. package/lib/typescript/src/renderer/components/shaders/Gradient.d.ts +1 -1
  332. package/lib/typescript/src/renderer/components/shaders/Shader.d.ts +2 -2
  333. package/lib/typescript/src/renderer/components/shapes/Circle.d.ts +1 -4
  334. package/lib/typescript/src/renderer/components/shapes/Path.d.ts +3 -1
  335. package/lib/typescript/src/renderer/processors/Paint.d.ts +2 -1
  336. package/lib/typescript/src/renderer/processors/Rects.d.ts +9 -41
  337. package/lib/typescript/src/renderer/processors/math/Matrix3.d.ts +1 -5
  338. package/lib/typescript/src/renderer/processors/math/Vector.d.ts +5 -17
  339. package/lib/typescript/src/skia/Color.d.ts +8 -9
  340. package/lib/typescript/src/skia/ImageFilter/ImageFilterFactory.d.ts +16 -0
  341. package/lib/typescript/src/skia/Matrix.d.ts +7 -1
  342. package/lib/typescript/src/skia/Paint/Paint.d.ts +1 -0
  343. package/lib/typescript/src/skia/RuntimeEffect/RuntimeEffect.d.ts +2 -1
  344. package/lib/typescript/src/skia/RuntimeEffect/RuntimeEffectFactory.d.ts +2 -2
  345. package/lib/typescript/src/skia/Shader/useShader.d.ts +1 -1
  346. package/lib/typescript/src/skia/Skia.d.ts +28 -95
  347. package/lib/typescript/src/skia/SkiaApi.d.ts +71 -0
  348. package/lib/typescript/src/skia/Surface/Surface.d.ts +1 -1
  349. package/lib/typescript/src/skia/Surface/SurfaceFactory.d.ts +2 -2
  350. package/lib/typescript/src/values/api.d.ts +2 -25
  351. package/lib/typescript/src/values/api.web.d.ts +2 -0
  352. package/lib/typescript/src/values/index.d.ts +0 -1
  353. package/lib/typescript/src/values/types.d.ts +24 -1
  354. package/lib/typescript/src/values/web/RNSkAnimation.d.ts +9 -0
  355. package/lib/typescript/src/values/web/RNSkClockValue.d.ts +13 -0
  356. package/lib/typescript/src/values/web/RNSkDerivedValue.d.ts +9 -0
  357. package/lib/typescript/src/values/web/RNSkReadonlyValue.d.ts +11 -0
  358. package/lib/typescript/src/values/web/RNSkValue.d.ts +14 -0
  359. package/lib/typescript/src/values/web/api.d.ts +2 -0
  360. package/lib/typescript/src/values/web/index.d.ts +1 -0
  361. package/lib/typescript/src/views/SkiaView.d.ts +3 -36
  362. package/lib/typescript/src/views/api.d.ts +5 -0
  363. package/lib/typescript/src/views/types.d.ts +32 -0
  364. package/package.json +2 -2
  365. package/src/{values/animation → animation}/decay/decay.ts +0 -0
  366. package/src/{values/animation → animation}/decay/index.ts +0 -0
  367. package/src/{values/animation → animation}/decay/runDecay.ts +2 -2
  368. package/src/{values/animation → animation}/decay/types.ts +1 -1
  369. package/src/{values/animation → animation}/functions/index.ts +0 -0
  370. package/src/animation/functions/interpolate.ts +182 -0
  371. package/src/animation/functions/interpolateColors.ts +58 -0
  372. package/src/{values/animation → animation}/index.ts +0 -0
  373. package/src/{values/animation → animation}/spring/Spring.ts +0 -0
  374. package/src/{values/animation → animation}/spring/functions/index.ts +0 -0
  375. package/src/{values/animation → animation}/spring/functions/spring.ts +0 -0
  376. package/src/{values/animation → animation}/spring/index.ts +0 -0
  377. package/src/{values/animation → animation}/spring/runSpring.ts +1 -1
  378. package/src/{values/animation → animation}/spring/types.ts +0 -0
  379. package/src/{values/animation → animation}/spring/useSpring.ts +1 -1
  380. package/src/{values/animation → animation}/timing/Easing.ts +0 -0
  381. package/src/{values/animation → animation}/timing/createTiming.ts +2 -2
  382. package/src/{values/animation → animation}/timing/functions/__tests__/timing.spec.ts +0 -0
  383. package/src/{values/animation → animation}/timing/functions/bezier.ts +0 -0
  384. package/src/{values/animation → animation}/timing/functions/getResolvedParams.ts +2 -2
  385. package/src/{values/animation → animation}/timing/functions/index.ts +0 -0
  386. package/src/{values/animation → animation}/timing/functions/timing.ts +1 -1
  387. package/src/{values/animation → animation}/timing/functions/types.ts +0 -0
  388. package/src/{values/animation → animation}/timing/index.ts +0 -0
  389. package/src/{values/animation → animation}/timing/runTiming.ts +1 -1
  390. package/src/{values/animation → animation}/timing/useLoop.ts +0 -0
  391. package/src/{values/animation → animation}/timing/useTiming.ts +2 -2
  392. package/src/{values/animation → animation}/types.ts +5 -5
  393. package/src/index.ts +1 -0
  394. package/src/renderer/Canvas.tsx +13 -6
  395. package/src/renderer/components/Paint.tsx +2 -2
  396. package/src/renderer/components/colorFilters/BlendColor.tsx +1 -1
  397. package/src/renderer/components/colorFilters/Lerp.tsx +1 -1
  398. package/src/renderer/components/imageFilters/InnerShadow.tsx +4 -2
  399. package/src/renderer/components/imageFilters/RuntimeShader.tsx +23 -0
  400. package/src/renderer/components/imageFilters/index.ts +1 -0
  401. package/src/renderer/components/shaders/Gradient.ts +2 -4
  402. package/src/renderer/components/shaders/Shader.tsx +3 -3
  403. package/src/renderer/components/shapes/Path.tsx +11 -3
  404. package/src/renderer/processors/Circles.ts +2 -1
  405. package/src/renderer/processors/Font.ts +1 -1
  406. package/src/renderer/processors/Paint.ts +5 -0
  407. package/src/renderer/processors/Rects.ts +9 -14
  408. package/src/renderer/processors/math/Matrix3.ts +24 -105
  409. package/src/renderer/processors/math/Vector.ts +3 -2
  410. package/src/skia/Color.ts +13 -27
  411. package/src/skia/ImageFilter/ImageFilterFactory.ts +20 -0
  412. package/src/skia/Matrix.ts +8 -1
  413. package/src/skia/Paint/Paint.ts +7 -0
  414. package/src/skia/Paint/usePaint.ts +2 -4
  415. package/src/skia/RuntimeEffect/RuntimeEffect.ts +3 -1
  416. package/src/skia/RuntimeEffect/RuntimeEffectFactory.ts +2 -2
  417. package/src/skia/Shader/useShader.ts +4 -1
  418. package/src/skia/Skia.ts +4 -123
  419. package/src/skia/SkiaApi.ts +86 -0
  420. package/src/skia/Surface/Surface.ts +1 -1
  421. package/src/skia/Surface/SurfaceFactory.ts +2 -2
  422. package/src/values/api.ts +3 -42
  423. package/src/values/api.web.ts +5 -0
  424. package/src/values/index.ts +0 -1
  425. package/src/values/types.ts +30 -1
  426. package/src/values/web/RNSkAnimation.ts +33 -0
  427. package/src/values/web/RNSkClockValue.ts +58 -0
  428. package/src/values/web/RNSkDerivedValue.ts +38 -0
  429. package/src/values/web/RNSkReadonlyValue.ts +32 -0
  430. package/src/values/web/RNSkValue.ts +57 -0
  431. package/src/values/web/__tests__/RNSkAnimation.spec.ts +21 -0
  432. package/src/values/web/__tests__/RNSkDerivedValue.spec.ts +15 -0
  433. package/src/values/web/__tests__/RNSkReadonlyValue.spec.ts +8 -0
  434. package/src/values/web/__tests__/RNSkValue.spec.ts +11 -0
  435. package/src/values/web/api.ts +33 -0
  436. package/src/values/web/index.ts +1 -0
  437. package/src/views/SkiaView.tsx +3 -49
  438. package/src/views/api.ts +7 -0
  439. package/src/views/types.ts +40 -0
  440. package/lib/commonjs/values/animation/decay/runDecay.js.map +0 -1
  441. package/lib/commonjs/values/animation/functions/interpolate.js +0 -139
  442. package/lib/commonjs/values/animation/functions/interpolate.js.map +0 -1
  443. package/lib/commonjs/values/animation/functions/interpolateColors.js +0 -47
  444. package/lib/commonjs/values/animation/functions/interpolateColors.js.map +0 -1
  445. package/lib/commonjs/values/animation/spring/runSpring.js.map +0 -1
  446. package/lib/commonjs/values/animation/spring/useSpring.js.map +0 -1
  447. package/lib/commonjs/values/animation/timing/createTiming.js.map +0 -1
  448. package/lib/commonjs/values/animation/timing/functions/getResolvedParams.js.map +0 -1
  449. package/lib/commonjs/values/animation/timing/runTiming.js.map +0 -1
  450. package/lib/commonjs/values/animation/timing/useTiming.js.map +0 -1
  451. package/lib/module/values/animation/decay/runDecay.js.map +0 -1
  452. package/lib/module/values/animation/functions/interpolate.js +0 -132
  453. package/lib/module/values/animation/functions/interpolate.js.map +0 -1
  454. package/lib/module/values/animation/functions/interpolateColors.js +0 -32
  455. package/lib/module/values/animation/functions/interpolateColors.js.map +0 -1
  456. package/lib/module/values/animation/spring/runSpring.js.map +0 -1
  457. package/lib/module/values/animation/spring/useSpring.js.map +0 -1
  458. package/lib/module/values/animation/timing/createTiming.js.map +0 -1
  459. package/lib/module/values/animation/timing/functions/getResolvedParams.js.map +0 -1
  460. package/lib/module/values/animation/timing/runTiming.js.map +0 -1
  461. package/lib/module/values/animation/timing/useTiming.js.map +0 -1
  462. package/lib/typescript/scripts/install-npm.d.ts +0 -1
  463. package/lib/typescript/src/values/animation/functions/interpolate.d.ts +0 -7
  464. package/lib/typescript/src/values/animation/functions/interpolateColors.d.ts +0 -3
  465. package/src/values/animation/functions/interpolate.ts +0 -169
  466. package/src/values/animation/functions/interpolateColors.ts +0 -62
@@ -40,31 +40,13 @@ RNSkDrawView::RNSkDrawView(std::shared_ptr<RNSkPlatformContext> context)
40
40
  _platformContext(std::move(context)),
41
41
  _infoObject(std::make_shared<RNSkInfoObject>()),
42
42
  _jsDrawingLock(std::make_shared<std::timed_mutex>()),
43
- _gpuDrawingLock(std::make_shared<std::timed_mutex>())
43
+ _gpuDrawingLock(std::make_shared<std::timed_mutex>()),
44
+ _jsTimingInfo("SKIA/JS"),
45
+ _gpuTimingInfo("SKIA/GPU")
44
46
  {}
45
47
 
46
48
  RNSkDrawView::~RNSkDrawView() {
47
- #if LOG_ALL_DRAWING
48
- RNSkLogger::logToConsole("RNSkDrawView::~RNSkDrawView - %i", getNativeId());
49
- #endif
50
-
51
- _isInvalidated = true;
52
-
53
49
  endDrawingLoop();
54
-
55
- // Wait for the drawing locks
56
- if(!_jsDrawingLock->try_lock_for(1250ms)) {
57
- RNSkLogger::logToConsole("Warning: JS drawing is still locked for native view with id %i", _nativeId);
58
- }
59
-
60
- if(!_gpuDrawingLock->try_lock_for(1250ms)) {
61
- RNSkLogger::logToConsole("Warning: SKIA drawing is still locked for native view with id %i", _nativeId);
62
- }
63
-
64
- onInvalidated();
65
-
66
- _jsDrawingLock = nullptr;
67
- _gpuDrawingLock = nullptr;
68
50
  }
69
51
 
70
52
  void RNSkDrawView::setNativeId(size_t nativeId) {
@@ -84,63 +66,63 @@ void RNSkDrawView::setDrawCallback(std::shared_ptr<jsi::Function> callback) {
84
66
  // Reset timing info
85
67
  _jsTimingInfo.reset();
86
68
  _gpuTimingInfo.reset();
87
- _vsyncTimingInfo.reset();
88
-
89
- // Set up debug font/paints
90
- auto font = SkFont();
91
- font.setSize(14);
92
- auto paint = SkPaint();
93
- paint.setColor(SkColors::kRed);
94
69
 
95
70
  // Create draw drawCallback wrapper
96
71
  _drawCallback = std::make_shared<RNSkDrawCallback>(
97
- [this, paint = std::move(paint), font = std::move(font), callback = std::move(callback)](std::shared_ptr<JsiSkCanvas> canvas, int width,
98
- int height, double timestamp,
99
- std::shared_ptr<RNSkPlatformContext> context) {
100
-
101
- auto runtime = context->getJsRuntime();
102
-
103
- // Update info parameter
104
- _infoObject->beginDrawOperation(width, height, timestamp);
105
-
106
- // Set up arguments array
107
- std::vector<jsi::Value> args(2);
108
- args[0] = jsi::Object::createFromHostObject(*runtime, canvas);
109
- args[1] = jsi::Object::createFromHostObject(*runtime, _infoObject);
110
-
111
- // To be able to call the drawing function we'll wrap it once again
112
- callback->call(*runtime,
113
- static_cast<const jsi::Value *>(args.data()),
114
- (size_t)2);
115
-
116
- // Reset touches
117
- _infoObject->endDrawOperation();
118
-
119
- // Draw debug overlays
120
- if (_showDebugOverlay) {
121
-
122
- // Display average rendering timer
123
- auto jsAvg = _jsTimingInfo.getAverage();
124
- //auto jsFps = _jsTimingInfo.getFps();
125
-
126
- auto gpuAvg = _gpuTimingInfo.getAverage();
127
- //auto gpuFps = _gpuTimingInfo.getFps();
128
-
129
- auto total = jsAvg + gpuAvg;
130
-
131
- //auto vsyncFps = _vsyncTimingInfo.getFps();
132
-
133
- // Build string
134
- std::ostringstream stream;
135
- stream << "js: " << jsAvg << "ms gpu: " << gpuAvg << "ms " << " total: " << total << "ms";
136
- // stream << "js:" << jsAvg << "ms/" << jsFps << "fps " << "gpu:" << gpuAvg << "ms/" <<
137
- // gpuFps << "fps" << " total:" << total << "ms/" << vsyncFps << "fps";
138
-
139
- std::string debugString = stream.str();
140
-
141
- canvas->getCanvas()->drawSimpleText(
142
- debugString.c_str(), debugString.size(), SkTextEncoding::kUTF8, 8,
143
- 18, font, paint);
72
+ [weakSelf = weak_from_this(),
73
+ callback = std::move(callback)](std::shared_ptr<JsiSkCanvas> canvas,
74
+ int width,
75
+ int height,
76
+ double timestamp,
77
+ std::shared_ptr<RNSkPlatformContext> context) {
78
+
79
+ auto self = weakSelf.lock();
80
+ if(self) {
81
+ auto runtime = context->getJsRuntime();
82
+
83
+ // Update info parameter
84
+ self->_infoObject->beginDrawOperation(width, height, timestamp);
85
+
86
+ // Set up arguments array
87
+ std::vector<jsi::Value> args(2);
88
+ args[0] = jsi::Object::createFromHostObject(*runtime, canvas);
89
+ args[1] = jsi::Object::createFromHostObject(*runtime, self->_infoObject);
90
+
91
+ // To be able to call the drawing function we'll wrap it once again
92
+ callback->call(*runtime,
93
+ static_cast<const jsi::Value *>(args.data()),
94
+ (size_t)2);
95
+
96
+ // Reset touches
97
+ self->_infoObject->endDrawOperation();
98
+
99
+ // Draw debug overlays
100
+ if (self->_showDebugOverlay) {
101
+
102
+ // Display average rendering timer
103
+ auto jsAvg = self->_jsTimingInfo.getAverage();
104
+ //auto jsFps = _jsTimingInfo.getFps();
105
+
106
+ auto gpuAvg = self->_gpuTimingInfo.getAverage();
107
+ //auto gpuFps = _gpuTimingInfo.getFps();
108
+
109
+ auto total = jsAvg + gpuAvg;
110
+
111
+ // Build string
112
+ std::ostringstream stream;
113
+ stream << "js: " << jsAvg << "ms gpu: " << gpuAvg << "ms " << " total: " << total << "ms";
114
+
115
+ std::string debugString = stream.str();
116
+
117
+ // Set up debug font/paints
118
+ auto font = SkFont();
119
+ font.setSize(14);
120
+ auto paint = SkPaint();
121
+ paint.setColor(SkColors::kRed);
122
+ canvas->getCanvas()->drawSimpleText(
123
+ debugString.c_str(), debugString.size(), SkTextEncoding::kUTF8, 8,
124
+ 18, font, paint);
125
+ }
144
126
  }
145
127
  });
146
128
 
@@ -172,7 +154,7 @@ void RNSkDrawView::drawInCanvas(std::shared_ptr<JsiSkCanvas> canvas,
172
154
 
173
155
  sk_sp<SkImage> RNSkDrawView::makeImageSnapshot(std::shared_ptr<SkRect> bounds) {
174
156
  // Assert width/height
175
- auto surface = SkSurface::MakeRasterN32Premul(getWidth(), getHeight());
157
+ auto surface = SkSurface::MakeRasterN32Premul(getScaledWidth(), getScaledHeight());
176
158
  auto canvas = surface->getCanvas();
177
159
  auto jsiCanvas = std::make_shared<JsiSkCanvas>(_platformContext);
178
160
  jsiCanvas->setCanvas(canvas);
@@ -180,7 +162,7 @@ sk_sp<SkImage> RNSkDrawView::makeImageSnapshot(std::shared_ptr<SkRect> bounds) {
180
162
  milliseconds ms = duration_cast<milliseconds>(
181
163
  system_clock::now().time_since_epoch());
182
164
 
183
- drawInCanvas(jsiCanvas, getWidth(), getHeight(), ms.count() / 1000);
165
+ drawInCanvas(jsiCanvas, getScaledWidth(), getScaledHeight(), ms.count() / 1000);
184
166
 
185
167
  if(bounds != nullptr) {
186
168
  SkIRect b = SkIRect::MakeXYWH(bounds->x(), bounds->y(), bounds->width(), bounds->height());
@@ -196,10 +178,6 @@ void RNSkDrawView::updateTouchState(std::vector<RNSkTouchPoint>&& points) {
196
178
  }
197
179
 
198
180
  void RNSkDrawView::performDraw() {
199
- #if LOG_ALL_DRAWING
200
- RNSkLogger::logToConsole("RNSkDrawView::performDraw - %i", getNativeId());
201
- #endif
202
-
203
181
  // Start timing
204
182
  _jsTimingInfo.beginTiming();
205
183
 
@@ -207,7 +185,7 @@ void RNSkDrawView::performDraw() {
207
185
  // move the actual drawing onto the render thread later
208
186
  SkPictureRecorder recorder;
209
187
  SkRTreeFactory factory;
210
- SkCanvas* canvas = recorder.beginRecording(getWidth(), getHeight(), &factory);
188
+ SkCanvas* canvas = recorder.beginRecording(getScaledWidth(), getScaledHeight(), &factory);
211
189
  _jsiCanvas->setCanvas(canvas);
212
190
 
213
191
  // Get current milliseconds
@@ -216,7 +194,7 @@ void RNSkDrawView::performDraw() {
216
194
 
217
195
  try {
218
196
  // Perform the javascript drawing
219
- drawInCanvas(_jsiCanvas, getWidth(), getHeight(), ms.count() / 1000.0);
197
+ drawInCanvas(_jsiCanvas, getScaledWidth(), getScaledHeight(), ms.count() / 1000.0);
220
198
  } catch(...) {
221
199
  _jsTimingInfo.stopTiming();
222
200
  _jsDrawingLock->unlock();
@@ -234,37 +212,22 @@ void RNSkDrawView::performDraw() {
234
212
  // Post drawing message to the render thread where the picture recorded
235
213
  // will be sent to the GPU/backend for rendering to screen.
236
214
  auto gpuLock = _gpuDrawingLock;
237
- getPlatformContext()->runOnRenderThread([this, p = std::move(p), gpuLock]() {
238
-
239
- if(isInvalidated()) {
240
- gpuLock->unlock();
241
- return;
215
+ _platformContext->runOnRenderThread([weakSelf = weak_from_this(), p = std::move(p), gpuLock]() {
216
+ auto self = weakSelf.lock();
217
+ if (self) {
218
+ // Draw the picture recorded on the real GPU canvas
219
+ self->_gpuTimingInfo.beginTiming();
220
+ self->drawPicture(p);
221
+ self->_gpuTimingInfo.stopTiming();
242
222
  }
243
-
244
- _gpuTimingInfo.beginTiming();
245
-
246
- // Draw the picture recorded on the real GPU canvas
247
- if(_nativeDrawFunc != nullptr) {
248
- #if LOG_ALL_DRAWING
249
- RNSkLogger::logToConsole("RNSkDrawView::drawFrame - %i", getNativeId());
250
- #endif
251
- _nativeDrawFunc(p);
252
- } else {
253
- #if LOG_ALL_DRAWING
254
- RNSkLogger::logToConsole("RNSkDrawView::drawFrame - %i SKIPPING, draw func is null", getNativeId());
255
- #endif
256
- }
257
-
258
- _gpuTimingInfo.stopTiming();
259
-
260
223
  // Unlock GPU drawing
261
224
  gpuLock->unlock();
262
225
  });
263
226
  } else {
264
227
  #ifdef DEBUG
265
- static size_t framesSkipped = 0;
266
- printf("SKIA/GPU: Skipped frames: %lu\n", ++framesSkipped);
228
+ _gpuTimingInfo.markSkipped();
267
229
  #endif
230
+ // Request a new redraw since the last frame was skipped.
268
231
  requestRedraw();
269
232
  }
270
233
 
@@ -280,39 +243,34 @@ void RNSkDrawView::beginDrawingLoop() {
280
243
  if (_drawingLoopId != 0 || _nativeId == 0) {
281
244
  return;
282
245
  }
283
-
284
246
  // Set to zero to avoid calling beginDrawLoop before we return
285
- _drawingLoopId = _platformContext->beginDrawLoop(
286
- _nativeId, std::bind(&RNSkDrawView::drawLoopCallback, this, std::placeholders::_1));
247
+ _drawingLoopId = _platformContext->beginDrawLoop(_nativeId,
248
+ [weakSelf = weak_from_this()](bool invalidated) {
249
+ auto self = weakSelf.lock();
250
+ if(self) {
251
+ self->drawLoopCallback(invalidated);
252
+ }
253
+ });
287
254
  }
288
255
 
289
256
  void RNSkDrawView::drawLoopCallback(bool invalidated) {
290
- if(invalidated) {
291
- _isInvalidated = true;
292
- onInvalidated();
293
- #if LOG_ALL_DRAWING
294
- RNSkLogger::logToConsole("RNSkDrawView::onInvalidated - %i", getNativeId());
295
- #endif
296
- return;
297
- }
298
-
299
257
  if(_redrawRequestCounter > 0 || _drawingMode == RNSkDrawingMode::Continuous) {
300
258
  _redrawRequestCounter = 0;
301
259
 
302
- _vsyncTimingInfo.beginTiming();
303
-
304
260
  // We render on the javascript thread.
305
261
  if(_jsDrawingLock->try_lock()) {
306
- _platformContext->runOnJavascriptThread(std::bind(&RNSkDrawView::performDraw, this));
262
+ _platformContext->runOnJavascriptThread([weakSelf = weak_from_this()](){
263
+ auto self = weakSelf.lock();
264
+ if(self) {
265
+ self->performDraw();
266
+ }
267
+ });
307
268
  } else {
308
269
  #ifdef DEBUG
309
- static size_t framesSkipped = 0;
310
- printf("SKIA/JS: Skipped frames: %lu\n", ++framesSkipped);
270
+ _jsTimingInfo.markSkipped();
311
271
  #endif
312
272
  requestRedraw();
313
273
  }
314
-
315
- _vsyncTimingInfo.stopTiming();
316
274
  }
317
275
  }
318
276
 
@@ -20,8 +20,6 @@
20
20
 
21
21
  #pragma clang diagnostic pop
22
22
 
23
- #define LOG_ALL_DRAWING 0
24
-
25
23
  class SkPicture;
26
24
  class SkRect;
27
25
  class SkImage;
@@ -35,7 +33,7 @@ using RNSkDrawCallback =
35
33
 
36
34
  enum RNSkDrawingMode { Default, Continuous };
37
35
 
38
- class RNSkDrawView {
36
+ class RNSkDrawView: public std::enable_shared_from_this<RNSkDrawView> {
39
37
  public:
40
38
  /**
41
39
  * Constructor
@@ -45,7 +43,7 @@ public:
45
43
  /**
46
44
  Destructor
47
45
  */
48
- ~RNSkDrawView();
46
+ virtual ~RNSkDrawView();
49
47
 
50
48
  /**
51
49
  * Repaints the Skia view using the underlying context and the drawcallback.
@@ -96,33 +94,20 @@ public:
96
94
  sk_sp<SkImage> makeImageSnapshot(std::shared_ptr<SkRect> bounds);
97
95
 
98
96
  protected:
99
- void setNativeDrawFunc(std::function<void(const sk_sp<SkPicture>)> drawFunc) {
100
- if(!_gpuDrawingLock->try_lock_for(250ms)) {
101
- RNSkLogger::logToConsole("Could not lock drawing when clearing drawing function - %i", _nativeId);
102
- }
103
- _nativeDrawFunc = drawFunc;
104
- _gpuDrawingLock->unlock();
105
- }
106
-
107
97
  /**
108
98
  Returns the scaled width of the view
109
99
  */
110
- virtual int getWidth() { return -1; };
100
+ virtual float getScaledWidth() = 0;
111
101
 
112
102
  /**
113
103
  Returns the scaled height of the view
114
104
  */
115
- virtual int getHeight() { return -1; };
116
-
117
- /**
118
- Returns true if the view is invalidated
119
- */
120
- volatile bool isInvalidated() { return _isInvalidated; }
105
+ virtual float getScaledHeight() = 0;
121
106
 
122
107
  /**
123
- Override to be notified on invalidation
108
+ Override to render picture to GPU
124
109
  */
125
- virtual void onInvalidated() {}
110
+ virtual void drawPicture(const sk_sp<SkPicture> picture) = 0;
126
111
 
127
112
  /**
128
113
  * @return The platformcontext
@@ -210,12 +195,7 @@ private:
210
195
  /**
211
196
  Timing information for GPU rendering
212
197
  */
213
- RNSkTimingInfo _gpuTimingInfo;
214
-
215
- /**
216
- Measures vsync framerate
217
- */
218
- RNSkTimingInfo _vsyncTimingInfo;
198
+ RNSkTimingInfo _gpuTimingInfo;
219
199
 
220
200
  /**
221
201
  Redraw queue counter
@@ -227,16 +207,6 @@ private:
227
207
  */
228
208
  size_t _nativeId;
229
209
 
230
- /**
231
- Invalidation flag
232
- */
233
- std::atomic<bool> _isInvalidated = { false };
234
-
235
- /**
236
- Native draw handler
237
- */
238
- std::function<void(const sk_sp<SkPicture>)> _nativeDrawFunc;
239
-
240
210
  };
241
211
 
242
212
  } // namespace RNSkia
@@ -20,7 +20,7 @@ using CallbackInfo = struct CallbackInfo {
20
20
  view = nullptr;
21
21
  }
22
22
  std::shared_ptr<jsi::Function> drawCallback;
23
- RNSkDrawView *view;
23
+ std::shared_ptr<RNSkDrawView> view;
24
24
  };
25
25
 
26
26
  class RNSkJsiViewApi : public JsiHostObject {
@@ -105,7 +105,7 @@ public:
105
105
  sk_sp<SkImage> image;
106
106
  auto info = getEnsuredCallbackInfo(nativeId);
107
107
  if (info->view != nullptr) {
108
- if(count > 1 && !arguments[1].isUndefined() && arguments[1].isNull()) {
108
+ if(count > 1 && !arguments[1].isUndefined() && !arguments[1].isNull()) {
109
109
  auto rect = JsiSkRect::fromValue(runtime, arguments[1]);
110
110
  image = info->view->makeImageSnapshot(rect);
111
111
  } else {
@@ -226,7 +226,7 @@ public:
226
226
  * @param nativeId Id of view to register
227
227
  * @param view View to register
228
228
  */
229
- void registerSkiaDrawView(size_t nativeId, RNSkDrawView *view) {
229
+ void registerSkiaDrawView(size_t nativeId, std::shared_ptr<RNSkDrawView> view) {
230
230
  auto info = getEnsuredCallbackInfo(nativeId);
231
231
  info->view = view;
232
232
  if (info->drawCallback != nullptr) {
@@ -260,15 +260,18 @@ public:
260
260
  a valid view is set, the setDrawCallback method is called on the
261
261
  view (if a valid callback exists).
262
262
  */
263
- void setSkiaDrawView(size_t nativeId, RNSkDrawView *view) {
263
+ void setSkiaDrawView(size_t nativeId, std::shared_ptr<RNSkDrawView> view) {
264
264
  if (_callbackInfos.find(nativeId) == _callbackInfos.end()) {
265
265
  return;
266
266
  }
267
267
  auto info = getEnsuredCallbackInfo(nativeId);
268
- info->view = view;
269
268
  if (view != nullptr && info->drawCallback != nullptr) {
269
+ info->view = view;
270
270
  info->view->setNativeId(nativeId);
271
271
  info->view->setDrawCallback(info->drawCallback);
272
+ } else if(view == nullptr && info->drawCallback != nullptr) {
273
+ info->view->setDrawCallback(nullptr);
274
+ info->view = view;
272
275
  }
273
276
  }
274
277
 
@@ -45,7 +45,7 @@ void RNSkManager::invalidate() {
45
45
  _platformContext->invalidate();
46
46
  }
47
47
 
48
- void RNSkManager::registerSkiaDrawView(size_t nativeId, RNSkDrawView *view) {
48
+ void RNSkManager::registerSkiaDrawView(size_t nativeId, std::shared_ptr<RNSkDrawView> view) {
49
49
  if (!_isInvalidated && _viewApi != nullptr)
50
50
  _viewApi->registerSkiaDrawView(nativeId, view);
51
51
  }
@@ -55,7 +55,7 @@ void RNSkManager::unregisterSkiaDrawView(size_t nativeId) {
55
55
  _viewApi->unregisterSkiaDrawView(nativeId);
56
56
  }
57
57
 
58
- void RNSkManager::setSkiaDrawView(size_t nativeId, RNSkDrawView *view) {
58
+ void RNSkManager::setSkiaDrawView(size_t nativeId, std::shared_ptr<RNSkDrawView> view) {
59
59
  if (!_isInvalidated && _viewApi != nullptr)
60
60
  _viewApi->setSkiaDrawView(nativeId, view);
61
61
  }
@@ -41,7 +41,7 @@ public:
41
41
  * @param nativeId Native view id
42
42
  * @param view View to register
43
43
  */
44
- void registerSkiaDrawView(size_t nativeId, RNSkDrawView *view);
44
+ void registerSkiaDrawView(size_t nativeId, std::shared_ptr<RNSkDrawView> view);
45
45
 
46
46
  /**
47
47
  * Unregisters the RNSkDrawView from the list of registered views
@@ -54,7 +54,7 @@ public:
54
54
  Used when we want to remove a view without unregistering it
55
55
  - this happens typically on iOS.
56
56
  */
57
- void setSkiaDrawView(size_t nativeId, RNSkDrawView *view);
57
+ void setSkiaDrawView(size_t nativeId, std::shared_ptr<RNSkDrawView> view);
58
58
 
59
59
  /**
60
60
  * @return The platform context
@@ -43,7 +43,7 @@ public:
43
43
  /**
44
44
  * Destructor
45
45
  */
46
- ~RNSkPlatformContext() {
46
+ virtual ~RNSkPlatformContext() {
47
47
  invalidate();
48
48
  }
49
49
 
@@ -34,8 +34,12 @@ public:
34
34
  }
35
35
 
36
36
  JSI_HOST_FUNCTION(createDerivedValue) {
37
- return jsi::Object::createFromHostObject(runtime,
38
- std::make_shared<RNSkDerivedValue>(_platformContext, runtime, arguments, count));
37
+ // Creation and initialization is done in two steps to be able to use weak references when setting
38
+ // up dependencies - since weak_from_this needs our instance to be a shared_ptr before calling
39
+ // weak_from_this().
40
+ auto derivedValue = std::make_shared<RNSkDerivedValue>(_platformContext, runtime, arguments, count);
41
+ derivedValue->initializeDependencies(runtime, arguments, count);
42
+ return jsi::Object::createFromHostObject(runtime, derivedValue);
39
43
  }
40
44
 
41
45
  JSI_HOST_FUNCTION(createAnimation) {
@@ -32,7 +32,6 @@ public:
32
32
  size_t count) : RNSkReadonlyValue(platformContext),
33
33
  _runtime(runtime),
34
34
  _identifier(identifier) {
35
-
36
35
  // Start by updating to zero (start value)
37
36
  update(_runtime, static_cast<double>(0));
38
37
  }
@@ -72,8 +71,13 @@ public:
72
71
  _start += timeSinceStop;
73
72
 
74
73
  _state = RNSkClockState::Running;
75
- auto dispatch = std::bind(&RNSkClockValue::notifyUpdate, this, std::placeholders::_1);
76
- getContext()->beginDrawLoop(_identifier, dispatch);
74
+
75
+ getContext()->beginDrawLoop(_identifier, [weakSelf = weak_from_this()](bool invalidated){
76
+ auto self = weakSelf.lock();
77
+ if(self) {
78
+ std::dynamic_pointer_cast<RNSkClockValue>(self)->notifyUpdate(invalidated);
79
+ }
80
+ });
77
81
  }
78
82
 
79
83
  virtual void stopClock() {
@@ -103,12 +107,16 @@ protected:
103
107
  getContext()->runOnJavascriptThread(
104
108
  // To ensure that this shared_ptr instance is not deallocated before we are done
105
109
  // running the update lambda we pass a shared from this to the lambda scope.
106
- [self = shared_from_this(), this]() {
107
- if(_state == RNSkClockState::Running) {
108
- auto now = std::chrono::high_resolution_clock::now();
109
- auto deltaFromStart = std::chrono::duration_cast<std::chrono::milliseconds>(now - _start).count();
110
- tick(_runtime, static_cast<double>(deltaFromStart));
111
- }
110
+ [weakSelf = weak_from_this()]() {
111
+ auto self = weakSelf.lock();
112
+ if(self) {
113
+ auto selfClockValue = std::dynamic_pointer_cast<RNSkClockValue>(self);
114
+ if(selfClockValue->getState() == RNSkClockState::Running) {
115
+ auto now = std::chrono::high_resolution_clock::now();
116
+ auto deltaFromStart = std::chrono::duration_cast<std::chrono::milliseconds>(now - selfClockValue->_start).count();
117
+ selfClockValue->tick(selfClockValue->_runtime, static_cast<double>(deltaFromStart));
118
+ }
119
+ }
112
120
  });
113
121
  }
114
122
 
@@ -127,7 +135,7 @@ protected:
127
135
  size_t _identifier;
128
136
  std::chrono::time_point<std::chrono::steady_clock> _start;
129
137
  std::chrono::time_point<std::chrono::steady_clock> _stop;
130
- std::atomic<RNSkClockState> _state;
138
+ std::atomic<RNSkClockState> _state = { RNSkClockState::NotStarted };
131
139
  };
132
140
 
133
141
  }
@@ -39,6 +39,11 @@ public:
39
39
  jsi::detail::throwJSError(runtime, "Expected array of dependencies as second parameter");
40
40
  }
41
41
 
42
+ // Get callback for calculating result
43
+ _callback = std::make_shared<jsi::Function>(arguments[0].asObject(runtime).asFunction(runtime));
44
+ }
45
+
46
+ void initializeDependencies(jsi::Runtime &runtime, const jsi::Value *arguments, size_t count) {
42
47
  // Save dependencies
43
48
  std::vector<std::shared_ptr<RNSkReadonlyValue>> dependencies;
44
49
 
@@ -59,14 +64,16 @@ public:
59
64
  dependencies.push_back(value);
60
65
  }
61
66
 
62
- // Get callback for calculating result
63
- _callback = std::make_shared<jsi::Function>(arguments[0].asObject(runtime).asFunction(runtime));
64
-
65
67
  // register change handler on dependencies
66
68
  _unsubscribers.reserve(_unsubscribers.size() + size);
67
69
  for(const auto &dep: dependencies) {
68
- auto dispatcher = std::bind(&RNSkDerivedValue::dependencyUpdated, this, std::placeholders::_1);
69
- _unsubscribers.push_back(dep->addListener(dispatcher));
70
+ _unsubscribers.push_back(dep->addListener([weakSelf = weak_from_this()](jsi::Runtime& runtime) {
71
+ auto self = weakSelf.lock();
72
+ if(self) {
73
+ auto selfAsThis = std::dynamic_pointer_cast<RNSkDerivedValue>(self);
74
+ selfAsThis->dependencyUpdated(runtime);
75
+ }
76
+ }));
70
77
  }
71
78
 
72
79
  // Set initial value