@shopify/react-native-skia 0.1.234 → 0.1.236

Sign up to get free protection for your applications and to get access to all the features.
Files changed (262) hide show
  1. package/cpp/api/JsiSkTypefaceFactory.h +2 -1
  2. package/cpp/skia/include/android/AHardwareBufferUtils.h +23 -0
  3. package/cpp/skia/include/android/GrAHardwareBufferUtils.h +2 -0
  4. package/cpp/skia/include/android/graphite/SurfaceAndroid.h +59 -0
  5. package/cpp/skia/include/codec/SkAvifDecoder.h +1 -1
  6. package/cpp/skia/include/codec/SkBmpDecoder.h +1 -1
  7. package/cpp/skia/include/codec/SkCodec.h +21 -3
  8. package/cpp/skia/include/codec/SkGifDecoder.h +1 -1
  9. package/cpp/skia/include/codec/SkIcoDecoder.h +1 -1
  10. package/cpp/skia/include/codec/SkJpegDecoder.h +1 -1
  11. package/cpp/skia/include/codec/SkJpegxlDecoder.h +1 -1
  12. package/cpp/skia/include/codec/SkPngDecoder.h +1 -1
  13. package/cpp/skia/include/codec/SkRawDecoder.h +1 -1
  14. package/cpp/skia/include/codec/SkWbmpDecoder.h +1 -1
  15. package/cpp/skia/include/codec/SkWebpDecoder.h +1 -1
  16. package/cpp/skia/include/config/SkUserConfig.h +3 -1
  17. package/cpp/skia/include/core/SkCanvas.h +66 -37
  18. package/cpp/skia/include/core/SkColorFilter.h +5 -2
  19. package/cpp/skia/include/core/SkContourMeasure.h +1 -0
  20. package/cpp/skia/include/core/SkDocument.h +1 -0
  21. package/cpp/skia/include/core/SkFont.h +14 -24
  22. package/cpp/skia/include/core/SkFontArguments.h +1 -1
  23. package/cpp/skia/include/core/SkFontMetrics.h +1 -1
  24. package/cpp/skia/include/core/SkFontMgr.h +0 -7
  25. package/cpp/skia/include/core/SkGraphics.h +13 -0
  26. package/cpp/skia/include/core/SkMesh.h +9 -13
  27. package/cpp/skia/include/core/SkMilestone.h +1 -1
  28. package/cpp/skia/include/core/SkPathMeasure.h +2 -0
  29. package/cpp/skia/include/core/SkSerialProcs.h +29 -11
  30. package/cpp/skia/include/core/SkSize.h +3 -3
  31. package/cpp/skia/include/core/SkStream.h +3 -13
  32. package/cpp/skia/include/core/SkSurface.h +6 -3
  33. package/cpp/skia/include/core/SkSurfaceProps.h +2 -4
  34. package/cpp/skia/include/core/SkTraceMemoryDump.h +15 -0
  35. package/cpp/skia/include/core/SkTypeface.h +8 -56
  36. package/cpp/skia/include/core/SkTypes.h +8 -0
  37. package/cpp/skia/include/core/SkVertices.h +1 -1
  38. package/cpp/skia/include/docs/SkMultiPictureDocument.h +53 -0
  39. package/cpp/skia/include/docs/SkPDFDocument.h +11 -0
  40. package/cpp/skia/include/effects/SkGradientShader.h +9 -0
  41. package/cpp/skia/include/effects/SkRuntimeEffect.h +3 -7
  42. package/cpp/skia/include/gpu/GrBackendSemaphore.h +33 -47
  43. package/cpp/skia/include/gpu/GrBackendSurface.h +2 -3
  44. package/cpp/skia/include/gpu/GrContextOptions.h +0 -6
  45. package/cpp/skia/include/gpu/GrContextThreadSafeProxy.h +44 -28
  46. package/cpp/skia/include/gpu/GrDirectContext.h +12 -31
  47. package/cpp/skia/include/gpu/GrTypes.h +1 -16
  48. package/cpp/skia/include/gpu/MutableTextureState.h +35 -80
  49. package/cpp/skia/include/gpu/ShaderErrorHandler.h +11 -1
  50. package/cpp/skia/include/gpu/ganesh/SkImageGanesh.h +2 -2
  51. package/cpp/skia/include/gpu/ganesh/SkSurfaceGanesh.h +1 -1
  52. package/cpp/skia/include/gpu/ganesh/gl/GrGLDirectContext.h +3 -2
  53. package/cpp/skia/include/gpu/ganesh/vk/GrVkBackendSemaphore.h +20 -0
  54. package/cpp/skia/include/gpu/ganesh/vk/GrVkDirectContext.h +30 -0
  55. package/cpp/skia/include/gpu/gl/GrGLFunctions.h +1 -1
  56. package/cpp/skia/include/gpu/gl/GrGLInterface.h +2 -0
  57. package/cpp/skia/include/gpu/gl/glx/GrGLMakeGLXInterface.h +6 -0
  58. package/cpp/skia/include/gpu/graphite/BackendSemaphore.h +3 -3
  59. package/cpp/skia/include/gpu/graphite/BackendTexture.h +39 -27
  60. package/cpp/skia/include/gpu/graphite/Context.h +39 -13
  61. package/cpp/skia/include/gpu/graphite/ContextOptions.h +2 -0
  62. package/cpp/skia/include/gpu/graphite/GraphiteTypes.h +2 -1
  63. package/cpp/skia/include/gpu/graphite/Image.h +106 -87
  64. package/cpp/skia/include/gpu/graphite/Recorder.h +24 -3
  65. package/cpp/skia/include/gpu/graphite/Surface.h +7 -2
  66. package/cpp/skia/include/gpu/graphite/dawn/DawnBackendContext.h +41 -2
  67. package/cpp/skia/include/gpu/graphite/dawn/DawnTypes.h +11 -6
  68. package/cpp/skia/include/gpu/graphite/mtl/MtlGraphiteTypes.h +1 -2
  69. package/cpp/skia/include/gpu/graphite/vk/VulkanGraphiteTypes.h +6 -6
  70. package/cpp/skia/include/gpu/mock/GrMockTypes.h +1 -0
  71. package/cpp/skia/include/gpu/vk/GrVkBackendContext.h +1 -1
  72. package/cpp/skia/include/gpu/vk/GrVkTypes.h +1 -44
  73. package/cpp/skia/include/gpu/vk/VulkanExtensions.h +1 -1
  74. package/cpp/skia/include/gpu/vk/VulkanMutableTextureState.h +25 -0
  75. package/cpp/skia/include/gpu/vk/VulkanTypes.h +44 -0
  76. package/cpp/skia/include/ports/SkFontConfigInterface.h +3 -6
  77. package/cpp/skia/include/private/SkEncodedInfo.h +5 -0
  78. package/cpp/skia/include/private/SkExif.h +102 -0
  79. package/cpp/skia/include/private/SkGainmapInfo.h +11 -1
  80. package/cpp/skia/include/private/base/SkAssert.h +16 -0
  81. package/cpp/skia/include/private/base/SkDeque.h +2 -7
  82. package/cpp/skia/include/private/base/SkLoadUserConfig.h +1 -1
  83. package/cpp/skia/include/private/base/SkTArray.h +69 -28
  84. package/cpp/skia/include/private/base/SkThreadAnnotations.h +18 -5
  85. package/cpp/skia/include/private/chromium/GrSurfaceCharacterization.h +26 -30
  86. package/cpp/skia/include/private/chromium/GrVkSecondaryCBDrawContext.h +4 -3
  87. package/cpp/skia/include/private/chromium/SkImageChromium.h +1 -1
  88. package/cpp/skia/include/private/gpu/ganesh/GrTypesPriv.h +8 -6
  89. package/cpp/skia/include/private/gpu/graphite/ContextOptionsPriv.h +29 -0
  90. package/cpp/skia/include/private/gpu/graphite/DawnTypesPriv.h +12 -9
  91. package/cpp/skia/include/private/gpu/graphite/VulkanGraphiteTypesPriv.h +16 -11
  92. package/cpp/skia/include/third_party/vulkan/vulkan/vk_platform.h +2 -2
  93. package/cpp/skia/include/third_party/vulkan/vulkan/vk_video/vulkan_video_codec_h264std.h +312 -0
  94. package/cpp/skia/include/third_party/vulkan/vulkan/vk_video/vulkan_video_codec_h264std_decode.h +77 -0
  95. package/cpp/skia/include/third_party/vulkan/vulkan/vk_video/vulkan_video_codec_h265std.h +446 -0
  96. package/cpp/skia/include/third_party/vulkan/vulkan/vk_video/vulkan_video_codec_h265std_decode.h +67 -0
  97. package/cpp/skia/include/third_party/vulkan/vulkan/vk_video/vulkan_video_codecs_common.h +36 -0
  98. package/cpp/skia/include/third_party/vulkan/vulkan/vulkan.h +9 -2
  99. package/cpp/skia/include/third_party/vulkan/vulkan/vulkan_android.h +31 -3
  100. package/cpp/skia/include/third_party/vulkan/vulkan/vulkan_core.h +10624 -5716
  101. package/cpp/skia/include/third_party/vulkan/vulkan/vulkan_ios.h +2 -1
  102. package/cpp/skia/include/third_party/vulkan/vulkan/vulkan_macos.h +2 -1
  103. package/cpp/skia/include/third_party/vulkan/vulkan/vulkan_win32.h +28 -1
  104. package/cpp/skia/include/third_party/vulkan/vulkan/vulkan_xcb.h +2 -1
  105. package/cpp/skia/include/utils/mac/SkCGUtils.h +23 -11
  106. package/cpp/skia/modules/skcms/skcms.h +2 -410
  107. package/cpp/skia/modules/skcms/src/Transform_inl.h +831 -704
  108. package/cpp/skia/modules/skcms/src/skcms_Transform.h +161 -0
  109. package/cpp/skia/modules/skcms/src/skcms_internals.h +136 -0
  110. package/cpp/skia/modules/skcms/src/skcms_public.h +404 -0
  111. package/cpp/skia/modules/skparagraph/include/FontArguments.h +1 -1
  112. package/cpp/skia/modules/skparagraph/include/FontCollection.h +2 -0
  113. package/cpp/skia/modules/skparagraph/include/Paragraph.h +2 -2
  114. package/cpp/skia/modules/skparagraph/include/TextStyle.h +4 -3
  115. package/cpp/skia/modules/skparagraph/include/TypefaceFontProvider.h +1 -3
  116. package/cpp/skia/modules/skresources/include/SkResources.h +28 -17
  117. package/cpp/skia/modules/skunicode/include/SkUnicode.h +12 -0
  118. package/cpp/skia/modules/svg/include/SkSVGDOM.h +4 -1
  119. package/cpp/skia/modules/svg/include/SkSVGRenderContext.h +4 -1
  120. package/cpp/skia/src/base/SkUTF.h +7 -0
  121. package/cpp/skia/src/core/SkTHash.h +20 -8
  122. package/lib/commonjs/dom/nodes/JsiSkDOM.d.ts +3 -2
  123. package/lib/commonjs/dom/nodes/JsiSkDOM.js +56 -57
  124. package/lib/commonjs/dom/nodes/JsiSkDOM.js.map +1 -1
  125. package/lib/commonjs/external/reanimated/index.d.ts +1 -0
  126. package/lib/commonjs/external/reanimated/index.js +13 -0
  127. package/lib/commonjs/external/reanimated/index.js.map +1 -1
  128. package/lib/commonjs/external/reanimated/interpolators.js +13 -1
  129. package/lib/commonjs/external/reanimated/interpolators.js.map +1 -1
  130. package/lib/commonjs/external/reanimated/moduleWrapper.d.ts +1 -0
  131. package/lib/commonjs/external/reanimated/moduleWrapper.js +5 -3
  132. package/lib/commonjs/external/reanimated/moduleWrapper.js.map +1 -1
  133. package/lib/commonjs/external/reanimated/textures.d.ts +5 -0
  134. package/lib/commonjs/external/reanimated/textures.js +52 -0
  135. package/lib/commonjs/external/reanimated/textures.js.map +1 -0
  136. package/lib/commonjs/headless/index.js +1 -1
  137. package/lib/commonjs/headless/index.js.map +1 -1
  138. package/lib/commonjs/mock/index.js +3 -0
  139. package/lib/commonjs/mock/index.js.map +1 -1
  140. package/lib/commonjs/renderer/Canvas.js +1 -1
  141. package/lib/commonjs/renderer/Canvas.js.map +1 -1
  142. package/lib/commonjs/renderer/Container.d.ts +1 -1
  143. package/lib/commonjs/renderer/Container.js +2 -1
  144. package/lib/commonjs/renderer/Container.js.map +1 -1
  145. package/lib/commonjs/renderer/Offscreen.d.ts +1 -0
  146. package/lib/commonjs/renderer/Offscreen.js +18 -5
  147. package/lib/commonjs/renderer/Offscreen.js.map +1 -1
  148. package/lib/commonjs/renderer/Reconciler.d.ts +1 -1
  149. package/lib/commonjs/renderer/Reconciler.js +7 -4
  150. package/lib/commonjs/renderer/Reconciler.js.map +1 -1
  151. package/lib/commonjs/skia/types/Matrix4.d.ts +2 -2
  152. package/lib/commonjs/skia/types/Matrix4.js.map +1 -1
  153. package/lib/commonjs/skia/types/Shader/Shader.d.ts +1 -1
  154. package/lib/commonjs/skia/types/Shader/Shader.js.map +1 -1
  155. package/lib/module/dom/nodes/JsiSkDOM.d.ts +3 -2
  156. package/lib/module/dom/nodes/JsiSkDOM.js +56 -56
  157. package/lib/module/dom/nodes/JsiSkDOM.js.map +1 -1
  158. package/lib/module/external/reanimated/index.d.ts +1 -0
  159. package/lib/module/external/reanimated/index.js +1 -0
  160. package/lib/module/external/reanimated/index.js.map +1 -1
  161. package/lib/module/external/reanimated/interpolators.js +13 -1
  162. package/lib/module/external/reanimated/interpolators.js.map +1 -1
  163. package/lib/module/external/reanimated/moduleWrapper.d.ts +1 -0
  164. package/lib/module/external/reanimated/moduleWrapper.js +3 -2
  165. package/lib/module/external/reanimated/moduleWrapper.js.map +1 -1
  166. package/lib/module/external/reanimated/textures.d.ts +5 -0
  167. package/lib/module/external/reanimated/textures.js +35 -0
  168. package/lib/module/external/reanimated/textures.js.map +1 -0
  169. package/lib/module/headless/index.js +1 -1
  170. package/lib/module/headless/index.js.map +1 -1
  171. package/lib/module/mock/index.js +3 -0
  172. package/lib/module/mock/index.js.map +1 -1
  173. package/lib/module/renderer/Canvas.js +1 -1
  174. package/lib/module/renderer/Canvas.js.map +1 -1
  175. package/lib/module/renderer/Container.d.ts +1 -1
  176. package/lib/module/renderer/Container.js +2 -1
  177. package/lib/module/renderer/Container.js.map +1 -1
  178. package/lib/module/renderer/Offscreen.d.ts +1 -0
  179. package/lib/module/renderer/Offscreen.js +11 -3
  180. package/lib/module/renderer/Offscreen.js.map +1 -1
  181. package/lib/module/renderer/Reconciler.d.ts +1 -1
  182. package/lib/module/renderer/Reconciler.js +7 -4
  183. package/lib/module/renderer/Reconciler.js.map +1 -1
  184. package/lib/module/skia/types/Matrix4.d.ts +2 -2
  185. package/lib/module/skia/types/Matrix4.js.map +1 -1
  186. package/lib/module/skia/types/Shader/Shader.d.ts +1 -1
  187. package/lib/module/skia/types/Shader/Shader.js.map +1 -1
  188. package/lib/typescript/src/dom/nodes/JsiSkDOM.d.ts +3 -2
  189. package/lib/typescript/src/external/reanimated/index.d.ts +1 -0
  190. package/lib/typescript/src/external/reanimated/moduleWrapper.d.ts +1 -0
  191. package/lib/typescript/src/external/reanimated/textures.d.ts +5 -0
  192. package/lib/typescript/src/renderer/Container.d.ts +1 -1
  193. package/lib/typescript/src/renderer/Offscreen.d.ts +1 -0
  194. package/lib/typescript/src/renderer/Reconciler.d.ts +1 -1
  195. package/lib/typescript/src/skia/types/Matrix4.d.ts +2 -2
  196. package/lib/typescript/src/skia/types/Shader/Shader.d.ts +1 -1
  197. package/libs/android/arm64-v8a/libskia.a +0 -0
  198. package/libs/android/arm64-v8a/libskottie.a +0 -0
  199. package/libs/android/arm64-v8a/libskparagraph.a +0 -0
  200. package/libs/android/arm64-v8a/libsksg.a +0 -0
  201. package/libs/android/arm64-v8a/libskshaper.a +0 -0
  202. package/libs/android/arm64-v8a/libskunicode.a +0 -0
  203. package/libs/android/arm64-v8a/libsvg.a +0 -0
  204. package/libs/android/armeabi-v7a/libskia.a +0 -0
  205. package/libs/android/armeabi-v7a/libskottie.a +0 -0
  206. package/libs/android/armeabi-v7a/libskparagraph.a +0 -0
  207. package/libs/android/armeabi-v7a/libsksg.a +0 -0
  208. package/libs/android/armeabi-v7a/libskshaper.a +0 -0
  209. package/libs/android/armeabi-v7a/libskunicode.a +0 -0
  210. package/libs/android/armeabi-v7a/libsvg.a +0 -0
  211. package/libs/android/x86/libskia.a +0 -0
  212. package/libs/android/x86/libskottie.a +0 -0
  213. package/libs/android/x86/libskparagraph.a +0 -0
  214. package/libs/android/x86/libsksg.a +0 -0
  215. package/libs/android/x86/libskshaper.a +0 -0
  216. package/libs/android/x86/libskunicode.a +0 -0
  217. package/libs/android/x86/libsvg.a +0 -0
  218. package/libs/android/x86_64/libskia.a +0 -0
  219. package/libs/android/x86_64/libskottie.a +0 -0
  220. package/libs/android/x86_64/libskparagraph.a +0 -0
  221. package/libs/android/x86_64/libsksg.a +0 -0
  222. package/libs/android/x86_64/libskshaper.a +0 -0
  223. package/libs/android/x86_64/libskunicode.a +0 -0
  224. package/libs/android/x86_64/libsvg.a +0 -0
  225. package/libs/ios/libskia.xcframework/ios-arm64_arm64e/libskia.a +0 -0
  226. package/libs/ios/libskia.xcframework/ios-arm64_arm64e_x86_64-simulator/libskia.a +0 -0
  227. package/libs/ios/libskottie.xcframework/ios-arm64_arm64e/libskottie.a +0 -0
  228. package/libs/ios/libskottie.xcframework/ios-arm64_arm64e_x86_64-simulator/libskottie.a +0 -0
  229. package/libs/ios/libskparagraph.xcframework/ios-arm64_arm64e/libskparagraph.a +0 -0
  230. package/libs/ios/libskparagraph.xcframework/ios-arm64_arm64e_x86_64-simulator/libskparagraph.a +0 -0
  231. package/libs/ios/libsksg.xcframework/ios-arm64_arm64e/libsksg.a +0 -0
  232. package/libs/ios/libsksg.xcframework/ios-arm64_arm64e_x86_64-simulator/libsksg.a +0 -0
  233. package/libs/ios/libskshaper.xcframework/Info.plist +5 -5
  234. package/libs/ios/libskshaper.xcframework/ios-arm64_arm64e/libskshaper.a +0 -0
  235. package/libs/ios/libskshaper.xcframework/ios-arm64_arm64e_x86_64-simulator/libskshaper.a +0 -0
  236. package/libs/ios/libskunicode.xcframework/ios-arm64_arm64e/libskunicode.a +0 -0
  237. package/libs/ios/libskunicode.xcframework/ios-arm64_arm64e_x86_64-simulator/libskunicode.a +0 -0
  238. package/libs/ios/libsvg.xcframework/Info.plist +5 -5
  239. package/libs/ios/libsvg.xcframework/ios-arm64_arm64e/libsvg.a +0 -0
  240. package/libs/ios/libsvg.xcframework/ios-arm64_arm64e_x86_64-simulator/libsvg.a +0 -0
  241. package/package.json +1 -1
  242. package/src/dom/nodes/JsiSkDOM.ts +55 -56
  243. package/src/external/reanimated/index.ts +1 -0
  244. package/src/external/reanimated/interpolators.ts +15 -2
  245. package/src/external/reanimated/moduleWrapper.ts +1 -0
  246. package/src/external/reanimated/textures.tsx +50 -0
  247. package/src/headless/index.ts +1 -1
  248. package/src/mock/index.ts +3 -0
  249. package/src/renderer/Canvas.tsx +1 -1
  250. package/src/renderer/Container.tsx +3 -2
  251. package/src/renderer/Offscreen.tsx +12 -3
  252. package/src/renderer/Reconciler.tsx +5 -2
  253. package/src/skia/types/Matrix4.ts +2 -2
  254. package/src/skia/types/Shader/Shader.ts +6 -1
  255. package/cpp/skia/include/gpu/GrSurfaceInfo.h +0 -142
  256. package/cpp/skia/include/private/gpu/ganesh/GrGLTypesPriv.h +0 -107
  257. package/cpp/skia/include/private/gpu/ganesh/GrMockTypesPriv.h +0 -32
  258. package/cpp/skia/include/private/gpu/ganesh/GrMtlTypesPriv.h +0 -83
  259. package/cpp/skia/include/private/gpu/ganesh/GrVkTypesPriv.h +0 -47
  260. package/cpp/skia/include/private/gpu/vk/VulkanTypesPriv.h +0 -57
  261. package/cpp/skia/include/utils/SkBase64.h +0 -53
  262. package/cpp/skia/modules/skcms/skcms_internal.h +0 -56
@@ -2,3 +2,4 @@ export * from "./useAnimatedImageValue";
2
2
  export * from "./useDerivedValueOnJS";
3
3
  export * from "./renderHelpers";
4
4
  export * from "./interpolators";
5
+ export * from "./textures";
@@ -87,8 +87,20 @@ export const usePathInterpolation = (
87
87
  input: number[],
88
88
  outputRange: SkPath[],
89
89
  options?: ExtrapolationType
90
- ) =>
91
- useInterpolator(
90
+ ) => {
91
+ // Check if all paths in outputRange are interpolable
92
+ const allPathsInterpolable = outputRange
93
+ .slice(1)
94
+ .every((path) => outputRange[0].isInterpolatable(path));
95
+ if (!allPathsInterpolable) {
96
+ // Handle the case where not all paths are interpolable
97
+ // For example, throw an error or return early
98
+ throw new Error(
99
+ `Not all paths in the output range are interpolable.
100
+ See: https://shopify.github.io/react-native-skia/docs/animations/hooks#usepathinterpolation`
101
+ );
102
+ }
103
+ return useInterpolator(
92
104
  () => Skia.Path.Make(),
93
105
  value,
94
106
  interpolatePaths,
@@ -96,6 +108,7 @@ export const usePathInterpolation = (
96
108
  outputRange,
97
109
  options
98
110
  );
111
+ };
99
112
 
100
113
  export const useVectorInterpolation = (
101
114
  value: SharedValue<number>,
@@ -63,6 +63,7 @@ export const stopMapper: (mapperID: number) => void =
63
63
  Reanimated2?.stopMapper || throwOnMissingReanimated;
64
64
 
65
65
  export const runOnJS = Reanimated2?.runOnJS || throwOnMissingReanimated;
66
+ export const runOnUI = Reanimated2?.runOnUI || throwOnMissingReanimated;
66
67
 
67
68
  export const useAnimatedReaction: <T>(
68
69
  prepare: () => T,
@@ -0,0 +1,50 @@
1
+ import { useEffect, useMemo } from "react";
2
+ import type { ReactElement } from "react";
3
+ import type { SharedValue } from "react-native-reanimated";
4
+
5
+ import { Skia } from "../../skia";
6
+ import type { SkImage, SkPicture, SkSize } from "../../skia/types";
7
+ import { drawAsPicture } from "../../renderer/Offscreen";
8
+
9
+ import { runOnUI, useSharedValue } from "./moduleWrapper";
10
+
11
+ // TODO: We're not sure yet why PixelRatio is not needed here.
12
+ const pd = 1; //Platform.PixelRatio;
13
+
14
+ const createTexture = (
15
+ texture: SharedValue<SkImage | null>,
16
+ picture: SkPicture,
17
+ size: SkSize
18
+ ) => {
19
+ "worklet";
20
+ const surface = Skia.Surface.MakeOffscreen(
21
+ size.width * pd,
22
+ size.height * pd
23
+ )!;
24
+ const canvas = surface.getCanvas();
25
+ // see comment above
26
+ //canvas.save();
27
+ //canvas.scale(pd, pd);
28
+ canvas.drawPicture(picture);
29
+ //canvas.restore();
30
+ surface.flush();
31
+ texture.value = surface.makeImageSnapshot();
32
+ };
33
+
34
+ export const useTextureValue = (element: ReactElement, size: SkSize) => {
35
+ const picture = useMemo(() => {
36
+ return drawAsPicture(element);
37
+ }, [element]);
38
+ return useTextureValueFromPicture(picture, size);
39
+ };
40
+
41
+ export const useTextureValueFromPicture = (
42
+ picture: SkPicture,
43
+ size: SkSize
44
+ ) => {
45
+ const texture = useSharedValue<SkImage | null>(null);
46
+ useEffect(() => {
47
+ runOnUI(createTexture)(texture, picture, size);
48
+ }, [texture, picture, size]);
49
+ return texture;
50
+ };
@@ -25,7 +25,7 @@ export const makeOffscreenSurface = (width: number, height: number) => {
25
25
  };
26
26
 
27
27
  export const drawOffscreen = (surface: SkSurface, element: ReactNode) => {
28
- const root = new SkiaRoot(Skia);
28
+ const root = new SkiaRoot(Skia, false);
29
29
  root.render(element);
30
30
  const canvas = surface.getCanvas();
31
31
  const ctx = new JsiDrawingContext(Skia, canvas);
package/src/mock/index.ts CHANGED
@@ -31,9 +31,12 @@ export const Mock = (CanvasKit: CanvasKit) => {
31
31
  // Reanimated hooks
32
32
  useClock: NoopSharedValue,
33
33
  usePathInterpolation: NoopSharedValue,
34
+ useTextureValue: NoopSharedValue,
35
+ useTextureValueFromPicture: NoopSharedValue,
34
36
  useRawData: Noop,
35
37
  useData: Noop,
36
38
  useFont: () => Skia.Font(undefined, 0),
39
+ useFonts: Noop,
37
40
  useTypeface: () => null,
38
41
  useImage: () => null,
39
42
  useSVG: () => null,
@@ -75,7 +75,7 @@ export const Canvas = forwardRef<SkiaDomView, CanvasProps>(
75
75
  }, [innerRef]);
76
76
 
77
77
  const root = useMemo(
78
- () => new SkiaRoot(Skia, redraw, getNativeId),
78
+ () => new SkiaRoot(Skia, NATIVE_DOM, redraw, getNativeId),
79
79
  [redraw, getNativeId]
80
80
  );
81
81
 
@@ -13,9 +13,10 @@ export class Container {
13
13
  constructor(
14
14
  Skia: Skia,
15
15
  public redraw: () => void = () => {},
16
- public getNativeId: () => number = () => 0
16
+ public getNativeId: () => number = () => 0,
17
+ native: boolean
17
18
  ) {
18
- this.Sk = new JsiSkDOM({ Skia });
19
+ this.Sk = new JsiSkDOM({ Skia }, native);
19
20
  this._root = this.Sk.Group();
20
21
  }
21
22
 
@@ -10,15 +10,24 @@ export const drawAsImage = (
10
10
  width: number,
11
11
  height: number
12
12
  ) => {
13
+ const picture = drawAsPicture(element);
13
14
  const surface = Skia.Surface.MakeOffscreen(width, height);
14
15
  if (!surface) {
15
16
  throw new Error("Could not create offscreen surface");
16
17
  }
17
18
  const canvas = surface.getCanvas();
18
- const root = new SkiaRoot(Skia);
19
+ canvas.drawPicture(picture);
20
+ surface.flush();
21
+ return surface.makeImageSnapshot();
22
+ };
23
+
24
+ export const drawAsPicture = (element: ReactElement) => {
25
+ const recorder = Skia.PictureRecorder();
26
+ const canvas = recorder.beginRecording();
27
+ const root = new SkiaRoot(Skia, false);
19
28
  root.render(element);
20
29
  const ctx = new JsiDrawingContext(Skia, canvas);
21
30
  root.dom.render(ctx);
22
- surface.flush();
23
- return surface.makeImageSnapshot();
31
+ const picture = recorder.finishRecordingAsPicture();
32
+ return picture;
24
33
  };
@@ -21,10 +21,11 @@ export class SkiaRoot {
21
21
 
22
22
  constructor(
23
23
  Skia: Skia,
24
+ native = false,
24
25
  redraw: () => void = () => {},
25
26
  getNativeId: () => number = () => 0
26
27
  ) {
27
- this.container = new Container(Skia, redraw, getNativeId);
28
+ this.container = new Container(Skia, redraw, getNativeId, native);
28
29
  this.root = skiaReconciler.createContainer(
29
30
  this.container,
30
31
  0,
@@ -45,7 +46,9 @@ export class SkiaRoot {
45
46
  }
46
47
 
47
48
  unmount() {
48
- skiaReconciler.updateContainer(null, this.root, null, () => {});
49
+ skiaReconciler.updateContainer(null, this.root, null, () => {
50
+ hostDebug("unmountContainer");
51
+ });
49
52
  }
50
53
 
51
54
  get dom() {
@@ -356,13 +356,13 @@ export const convertToColumnMajor = (rowMajorMatrix: Matrix4) => {
356
356
  colMajorMatrix[col * size + row] = rowMajorMatrix[row * size + col];
357
357
  }
358
358
  }
359
- return colMajorMatrix;
359
+ return colMajorMatrix as unknown as Matrix4;
360
360
  };
361
361
 
362
362
  /**
363
363
  * @worklet
364
364
  */
365
- export const convertToAffineMatrix = (m4: number[]) => {
365
+ export const convertToAffineMatrix = (m4: Matrix4) => {
366
366
  "worklet";
367
367
  // Extracting the relevant components from the 4x4 matrix
368
368
  const a = m4[0]; // Scale X
@@ -7,7 +7,12 @@ export const isShader = (obj: SkJSIInstance<string> | null): obj is SkShader =>
7
7
 
8
8
  export type SkShader = SkJSIInstance<"Shader">;
9
9
 
10
- export type Uniform = number | Vector | Float32Array | Uniform[];
10
+ export type Uniform =
11
+ | number
12
+ | Vector
13
+ | Float32Array
14
+ | readonly Uniform[]
15
+ | Uniform[];
11
16
 
12
17
  export interface Uniforms {
13
18
  [name: string]: Uniform;
@@ -1,142 +0,0 @@
1
- /*
2
- * Copyright 2021 Google LLC
3
- *
4
- * Use of this source code is governed by a BSD-style license that can be
5
- * found in the LICENSE file.
6
- */
7
-
8
- #ifndef GrSurfaceInfo_DEFINED
9
- #define GrSurfaceInfo_DEFINED
10
-
11
- #include "include/gpu/GrTypes.h"
12
-
13
- #ifdef SK_GL
14
- #include "include/private/gpu/ganesh/GrGLTypesPriv.h"
15
- #endif
16
- #ifdef SK_VULKAN
17
- #include "include/private/gpu/ganesh/GrVkTypesPriv.h"
18
- #endif
19
- #ifdef SK_DIRECT3D
20
- #include "include/private/gpu/ganesh/GrD3DTypesMinimal.h"
21
- struct GrD3DSurfaceInfo;
22
- #endif
23
- #ifdef SK_METAL
24
- #include "include/private/gpu/ganesh/GrMtlTypesPriv.h"
25
- #endif
26
- #include "include/private/gpu/ganesh/GrMockTypesPriv.h"
27
-
28
- class GrSurfaceInfo {
29
- public:
30
- GrSurfaceInfo() {}
31
- #ifdef SK_GL
32
- GrSurfaceInfo(const GrGLSurfaceInfo& glInfo)
33
- : fBackend(GrBackendApi::kOpenGL)
34
- , fValid(true)
35
- , fSampleCount(glInfo.fSampleCount)
36
- , fLevelCount(glInfo.fLevelCount)
37
- , fProtected(glInfo.fProtected)
38
- , fGLSpec(glInfo) {}
39
- #endif
40
- #ifdef SK_VULKAN
41
- GrSurfaceInfo(const GrVkSurfaceInfo& vkInfo)
42
- : fBackend(GrBackendApi::kVulkan)
43
- , fValid(true)
44
- , fSampleCount(vkInfo.fSampleCount)
45
- , fLevelCount(vkInfo.fLevelCount)
46
- , fProtected(vkInfo.fProtected)
47
- , fVkSpec(vkInfo) {}
48
- #endif
49
- #ifdef SK_DIRECT3D
50
- GrSurfaceInfo(const GrD3DSurfaceInfo& d3dInfo);
51
- #endif
52
- #ifdef SK_METAL
53
- GrSurfaceInfo(const GrMtlSurfaceInfo& mtlInfo)
54
- : fBackend(GrBackendApi::kMetal)
55
- , fValid(true)
56
- , fSampleCount(mtlInfo.fSampleCount)
57
- , fLevelCount(mtlInfo.fLevelCount)
58
- , fProtected(mtlInfo.fProtected)
59
- , fMtlSpec(mtlInfo) {}
60
- #endif
61
- GrSurfaceInfo(const GrMockSurfaceInfo& mockInfo)
62
- : fBackend(GrBackendApi::kMock)
63
- , fValid(true)
64
- , fSampleCount(mockInfo.fSampleCount)
65
- , fLevelCount(mockInfo.fLevelCount)
66
- , fProtected(mockInfo.fProtected)
67
- , fMockSpec(mockInfo) {}
68
-
69
- ~GrSurfaceInfo();
70
- GrSurfaceInfo(const GrSurfaceInfo&) = default;
71
-
72
- bool isValid() const { return fValid; }
73
- GrBackendApi backend() const { return fBackend; }
74
-
75
- uint32_t numSamples() const { return fSampleCount; }
76
- uint32_t numMipLevels() const { return fLevelCount; }
77
- GrProtected isProtected() const { return fProtected; }
78
-
79
- #ifdef SK_GL
80
- bool getGLSurfaceInfo(GrGLSurfaceInfo* info) const {
81
- if (!this->isValid() || fBackend != GrBackendApi::kOpenGL) {
82
- return false;
83
- }
84
- *info = GrGLTextureSpecToSurfaceInfo(fGLSpec, fSampleCount, fLevelCount, fProtected);
85
- return true;
86
- }
87
- #endif
88
- #ifdef SK_VULKAN
89
- bool getVkSurfaceInfo(GrVkSurfaceInfo* info) const {
90
- if (!this->isValid() || fBackend != GrBackendApi::kVulkan) {
91
- return false;
92
- }
93
- *info = GrVkImageSpecToSurfaceInfo(fVkSpec, fSampleCount, fLevelCount, fProtected);
94
- return true;
95
- }
96
- #endif
97
- #ifdef SK_DIRECT3D
98
- bool getD3DSurfaceInfo(GrD3DSurfaceInfo*) const;
99
- #endif
100
- #ifdef SK_METAL
101
- bool getMtlSurfaceInfo(GrMtlSurfaceInfo* info) const {
102
- if (!this->isValid() || fBackend != GrBackendApi::kMetal) {
103
- return false;
104
- }
105
- *info = GrMtlTextureSpecToSurfaceInfo(fMtlSpec, fSampleCount, fLevelCount, fProtected);
106
- return true;
107
- }
108
- #endif
109
- bool getMockSurfaceInfo(GrMockSurfaceInfo* info) const {
110
- if (!this->isValid() || fBackend != GrBackendApi::kMock) {
111
- return false;
112
- }
113
- *info = GrMockTextureSpecToSurfaceInfo(fMockSpec, fSampleCount, fLevelCount, fProtected);
114
- return true;
115
- }
116
-
117
- private:
118
- GrBackendApi fBackend = GrBackendApi::kMock;
119
- bool fValid = false;
120
-
121
- uint32_t fSampleCount = 1;
122
- uint32_t fLevelCount = 0;
123
- GrProtected fProtected = GrProtected::kNo;
124
-
125
- union {
126
- #ifdef SK_GL
127
- GrGLTextureSpec fGLSpec;
128
- #endif
129
- #ifdef SK_VULKAN
130
- GrVkImageSpec fVkSpec;
131
- #endif
132
- #ifdef SK_DIRECT3D
133
- GrD3DTextureResourceSpecHolder fD3DSpec;
134
- #endif
135
- #ifdef SK_METAL
136
- GrMtlTextureSpec fMtlSpec;
137
- #endif
138
- GrMockTextureSpec fMockSpec;
139
- };
140
- };
141
-
142
- #endif
@@ -1,107 +0,0 @@
1
- /*
2
- * Copyright 2019 Google LLC
3
- *
4
- * Use of this source code is governed by a BSD-style license that can be
5
- * found in the LICENSE file.
6
- */
7
-
8
- #include "include/core/SkRefCnt.h"
9
- #include "include/gpu/gl/GrGLTypes.h"
10
-
11
- #ifndef GrGLTypesPriv_DEFINED
12
- #define GrGLTypesPriv_DEFINED
13
-
14
- // TODO(b/293490566) Move this to src/ after GrSurfaceInfo.h has been decoupled from GL
15
-
16
- static constexpr int kGrGLColorFormatCount = static_cast<int>(GrGLFormat::kLastColorFormat) + 1;
17
-
18
- class GrGLTextureParameters : public SkNVRefCnt<GrGLTextureParameters> {
19
- public:
20
- // We currently consider texture parameters invalid on all textures
21
- // GrContext::resetContext(). We use this type to track whether instances of
22
- // GrGLTextureParameters were updated before or after the most recent resetContext(). At 10
23
- // resets / frame and 60fps a 64bit timestamp will overflow in about a billion years.
24
- // TODO: Require clients to use GrBackendTexture::glTextureParametersModified() to invalidate
25
- // texture parameters and get rid of timestamp checking.
26
- using ResetTimestamp = uint64_t;
27
-
28
- // This initializes the params to have an expired timestamp. They'll be considered invalid the
29
- // first time the texture is used unless set() is called.
30
- GrGLTextureParameters() = default;
31
-
32
- // This is texture parameter state that is overridden when a non-zero sampler object is bound.
33
- struct SamplerOverriddenState {
34
- SamplerOverriddenState();
35
- void invalidate();
36
-
37
- GrGLenum fMinFilter;
38
- GrGLenum fMagFilter;
39
- GrGLenum fWrapS;
40
- GrGLenum fWrapT;
41
- GrGLfloat fMinLOD;
42
- GrGLfloat fMaxLOD;
43
- GrGLfloat fMaxAniso;
44
- // We always want the border color to be transparent black, so no need to store 4 floats.
45
- // Just track if it's been invalidated and no longer the default
46
- bool fBorderColorInvalid;
47
- };
48
-
49
- // Texture parameter state that is not overridden by a bound sampler object.
50
- struct NonsamplerState {
51
- NonsamplerState();
52
- void invalidate();
53
-
54
- GrGLint fBaseMipMapLevel;
55
- GrGLint fMaxMipmapLevel;
56
- bool fSwizzleIsRGBA;
57
- };
58
-
59
- void invalidate();
60
-
61
- ResetTimestamp resetTimestamp() const { return fResetTimestamp; }
62
- const SamplerOverriddenState& samplerOverriddenState() const { return fSamplerOverriddenState; }
63
- const NonsamplerState& nonsamplerState() const { return fNonsamplerState; }
64
-
65
- // SamplerOverriddenState is optional because we don't track it when we're using sampler
66
- // objects.
67
- void set(const SamplerOverriddenState* samplerState,
68
- const NonsamplerState& nonsamplerState,
69
- ResetTimestamp currTimestamp);
70
-
71
- private:
72
- static constexpr ResetTimestamp kExpiredTimestamp = 0;
73
-
74
- SamplerOverriddenState fSamplerOverriddenState;
75
- NonsamplerState fNonsamplerState;
76
- ResetTimestamp fResetTimestamp = kExpiredTimestamp;
77
- };
78
-
79
- class GrGLBackendTextureInfo {
80
- public:
81
- GrGLBackendTextureInfo(const GrGLTextureInfo& info, sk_sp<GrGLTextureParameters> params)
82
- : fInfo(info), fParams(params) {}
83
- const GrGLTextureInfo& info() const { return fInfo; }
84
- GrGLTextureParameters* parameters() const { return fParams.get(); }
85
- sk_sp<GrGLTextureParameters> refParameters() const { return fParams; }
86
-
87
- bool isProtected() const { return fInfo.isProtected(); }
88
-
89
- private:
90
- GrGLTextureInfo fInfo;
91
- sk_sp<GrGLTextureParameters> fParams; // not const because we might call invalidate() on it.
92
- };
93
-
94
- struct GrGLTextureSpec {
95
- GrGLTextureSpec() : fTarget(0), fFormat(0) {}
96
- GrGLTextureSpec(const GrGLSurfaceInfo& info) : fTarget(info.fTarget), fFormat(info.fFormat) {}
97
-
98
- GrGLenum fTarget;
99
- GrGLenum fFormat;
100
- };
101
-
102
- GrGLSurfaceInfo GrGLTextureSpecToSurfaceInfo(const GrGLTextureSpec& glSpec,
103
- uint32_t sampleCount,
104
- uint32_t levelCount,
105
- skgpu::Protected isProtected);
106
-
107
- #endif
@@ -1,32 +0,0 @@
1
- /*
2
- * Copyright 2021 Google LLC
3
- *
4
- * Use of this source code is governed by a BSD-style license that can be
5
- * found in the LICENSE file.
6
- */
7
-
8
- #ifndef GrMockTypesPriv_DEFINED
9
- #define GrMockTypesPriv_DEFINED
10
-
11
- #include "include/core/SkTextureCompressionType.h"
12
- #include "include/gpu/mock/GrMockTypes.h"
13
-
14
- struct GrMockTextureSpec {
15
- GrMockTextureSpec()
16
- : fColorType(GrColorType::kUnknown)
17
- , fCompressionType(SkTextureCompressionType::kNone) {}
18
- GrMockTextureSpec(const GrMockSurfaceInfo& info)
19
- : fColorType(info.fColorType)
20
- , fCompressionType(info.fCompressionType) {}
21
-
22
- GrColorType fColorType = GrColorType::kUnknown;
23
- SkTextureCompressionType fCompressionType = SkTextureCompressionType::kNone;
24
- };
25
-
26
- GrMockSurfaceInfo GrMockTextureSpecToSurfaceInfo(const GrMockTextureSpec& mockSpec,
27
- uint32_t sampleCount,
28
- uint32_t levelCount,
29
- GrProtected isProtected);
30
-
31
- #endif
32
-
@@ -1,83 +0,0 @@
1
- /*
2
- * Copyright 2021 Google Inc.
3
- *
4
- * Use of this source code is governed by a BSD-style license that can be
5
- * found in the LICENSE file.
6
- */
7
-
8
- #ifndef GrMtlTypesPriv_DEFINED
9
- #define GrMtlTypesPriv_DEFINED
10
-
11
- #include "include/gpu/GrTypes.h"
12
- #include "include/gpu/mtl/GrMtlTypes.h"
13
-
14
- ///////////////////////////////////////////////////////////////////////////////
15
-
16
- #ifdef __APPLE__
17
-
18
- #include <TargetConditionals.h>
19
-
20
- #if defined(SK_BUILD_FOR_MAC)
21
- #if __MAC_OS_X_VERSION_MAX_ALLOWED >= 130000
22
- #define GR_METAL_SDK_VERSION 300
23
- #elif __MAC_OS_X_VERSION_MAX_ALLOWED >= 120000
24
- #define GR_METAL_SDK_VERSION 240
25
- #elif __MAC_OS_X_VERSION_MAX_ALLOWED >= 110000
26
- #define GR_METAL_SDK_VERSION 230
27
- #elif __MAC_OS_X_VERSION_MAX_ALLOWED >= 101500
28
- #define GR_METAL_SDK_VERSION 220
29
- #elif __MAC_OS_X_VERSION_MAX_ALLOWED >= 101400
30
- #define GR_METAL_SDK_VERSION 210
31
- #else
32
- #error Must use at least 10.14 SDK to build Metal backend for MacOS
33
- #endif
34
- #else
35
- #if __IPHONE_OS_VERSION_MAX_ALLOWED >= 160000 || __TV_OS_VERSION_MAX_ALLOWED >= 160000
36
- #define GR_METAL_SDK_VERSION 300
37
- #elif __IPHONE_OS_VERSION_MAX_ALLOWED >= 150000 || __TV_OS_VERSION_MAX_ALLOWED >= 150000
38
- #define GR_METAL_SDK_VERSION 240
39
- #elif __IPHONE_OS_VERSION_MAX_ALLOWED >= 140000 || __TV_OS_VERSION_MAX_ALLOWED >= 140000
40
- #define GR_METAL_SDK_VERSION 230
41
- #elif __IPHONE_OS_VERSION_MAX_ALLOWED >= 130000 || __TV_OS_VERSION_MAX_ALLOWED >= 130000
42
- #define GR_METAL_SDK_VERSION 220
43
- #elif __IPHONE_OS_VERSION_MAX_ALLOWED >= 120000 || __TV_OS_VERSION_MAX_ALLOWED >= 120000
44
- #define GR_METAL_SDK_VERSION 210
45
- #else
46
- #error Must use at least 12.00 SDK to build Metal backend for iOS
47
- #endif
48
- #endif
49
-
50
- #if __has_feature(objc_arc) && __has_attribute(objc_externally_retained)
51
- #define GR_NORETAIN __attribute__((objc_externally_retained))
52
- #define GR_NORETAIN_BEGIN \
53
- _Pragma("clang attribute push (__attribute__((objc_externally_retained)), apply_to=any(function,objc_method))")
54
- #define GR_NORETAIN_END _Pragma("clang attribute pop")
55
- #else
56
- #define GR_NORETAIN
57
- #define GR_NORETAIN_BEGIN
58
- #define GR_NORETAIN_END
59
- #endif
60
-
61
- struct GrMtlTextureSpec {
62
- GrMtlTextureSpec()
63
- : fFormat(0)
64
- , fUsage(0)
65
- , fStorageMode(0) {}
66
- GrMtlTextureSpec(const GrMtlSurfaceInfo& info)
67
- : fFormat(info.fFormat)
68
- , fUsage(info.fUsage)
69
- , fStorageMode(info.fStorageMode) {}
70
-
71
- GrMTLPixelFormat fFormat;
72
- GrMTLTextureUsage fUsage;
73
- GrMTLStorageMode fStorageMode;
74
- };
75
-
76
- GrMtlSurfaceInfo GrMtlTextureSpecToSurfaceInfo(const GrMtlTextureSpec& mtlSpec,
77
- uint32_t sampleCount,
78
- uint32_t levelCount,
79
- skgpu::Protected isProtected);
80
-
81
- #endif // __APPLE__
82
-
83
- #endif // GrMtlTypesPriv_DEFINED
@@ -1,47 +0,0 @@
1
- /*
2
- * Copyright 2018 Google Inc.
3
- *
4
- * Use of this source code is governed by a BSD-style license that can be
5
- * found in the LICENSE file.
6
- */
7
-
8
- #ifndef GrVkTypesPriv_DEFINED
9
- #define GrVkTypesPriv_DEFINED
10
-
11
- #include "include/core/SkRefCnt.h"
12
- #include "include/gpu/vk/GrVkTypes.h"
13
-
14
- namespace skgpu {
15
- class MutableTextureStateRef;
16
- }
17
-
18
- GrVkImageInfo GrVkImageInfoWithMutableState(const GrVkImageInfo&,
19
- const skgpu::MutableTextureStateRef*);
20
-
21
- struct GrVkImageSpec {
22
- GrVkImageSpec()
23
- : fImageTiling(VK_IMAGE_TILING_OPTIMAL)
24
- , fFormat(VK_FORMAT_UNDEFINED)
25
- , fImageUsageFlags(0)
26
- , fSharingMode(VK_SHARING_MODE_EXCLUSIVE) {}
27
-
28
- GrVkImageSpec(const GrVkSurfaceInfo& info)
29
- : fImageTiling(info.fImageTiling)
30
- , fFormat(info.fFormat)
31
- , fImageUsageFlags(info.fImageUsageFlags)
32
- , fYcbcrConversionInfo(info.fYcbcrConversionInfo)
33
- , fSharingMode(info.fSharingMode) {}
34
-
35
- VkImageTiling fImageTiling;
36
- VkFormat fFormat;
37
- VkImageUsageFlags fImageUsageFlags;
38
- GrVkYcbcrConversionInfo fYcbcrConversionInfo;
39
- VkSharingMode fSharingMode;
40
- };
41
-
42
- GrVkSurfaceInfo GrVkImageSpecToSurfaceInfo(const GrVkImageSpec& vkSpec,
43
- uint32_t sampleCount,
44
- uint32_t levelCount,
45
- skgpu::Protected isProtected);
46
-
47
- #endif