@shopify/react-native-skia 2.12.0-next.1 → 2.12.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (202) hide show
  1. package/Package.swift +117 -0
  2. package/android/CMakeLists.txt +1 -2
  3. package/android/cpp/rnskia-android/RNSkAndroidPlatformContext.h +0 -10
  4. package/android/src/main/java/com/shopify/reactnative/skia/ViewScreenshotService.java +9 -12
  5. package/apple/RNSkApplePlatformContext.h +0 -3
  6. package/apple/RNSkApplePlatformContext.mm +0 -11
  7. package/cpp/api/JsiSkApi.h +0 -6
  8. package/cpp/api/JsiSkFont.h +5 -10
  9. package/cpp/api/JsiSkMatrix.h +4 -2
  10. package/cpp/api/JsiSkSVGFactory.h +4 -0
  11. package/cpp/api/recorder/Convertor.h +5 -2
  12. package/cpp/api/recorder/Drawings.h +13 -3
  13. package/cpp/api/recorder/ImageFilters.h +15 -1
  14. package/cpp/api/recorder/Paint.h +8 -1
  15. package/cpp/jsi/JSICache.cpp +99 -0
  16. package/cpp/jsi/JSICache.h +90 -0
  17. package/cpp/jsi/NativeObject.h +38 -87
  18. package/cpp/jsi/ViewProperty.h +0 -24
  19. package/cpp/rnskia/RNDawnContext.h +2 -1
  20. package/cpp/rnskia/RNDawnWindowContext.h +22 -0
  21. package/cpp/rnskia/RNSkManager.cpp +0 -6
  22. package/cpp/rnskia/RNSkPlatformContext.h +0 -3
  23. package/cpp/skia/include/core/RasterContext.h +25 -0
  24. package/cpp/skia/include/core/SkCanvas.h +0 -1
  25. package/cpp/skia/include/core/SkContext.h +62 -0
  26. package/cpp/skia/include/core/SkContextOptions.h +15 -0
  27. package/cpp/skia/include/core/SkMilestone.h +1 -1
  28. package/cpp/skia/include/core/SkPicture.h +36 -18
  29. package/cpp/skia/include/core/SkRecorder.h +8 -0
  30. package/cpp/skia/include/core/SkSerialProcs.h +2 -6
  31. package/cpp/skia/include/effects/SkImageFilters.h +15 -2
  32. package/cpp/skia/include/gpu/ganesh/GrDirectContext.h +73 -47
  33. package/cpp/skia/include/gpu/ganesh/SkSurfaceGanesh.h +7 -4
  34. package/cpp/skia/include/gpu/ganesh/d3d/GrD3DDirectContext.h +12 -0
  35. package/cpp/skia/include/gpu/ganesh/gl/GrGLDirectContext.h +11 -0
  36. package/cpp/skia/include/gpu/ganesh/mtl/GrMtlDirectContext.h +11 -0
  37. package/cpp/skia/include/gpu/ganesh/vk/GrVkDirectContext.h +13 -0
  38. package/cpp/skia/include/gpu/graphite/ContextOptions.h +6 -0
  39. package/cpp/skia/include/gpu/graphite/GraphiteTypes.h +5 -4
  40. package/cpp/skia/include/gpu/graphite/PrecompileContext.h +9 -1
  41. package/cpp/skia/include/gpu/graphite/Recorder.h +0 -2
  42. package/cpp/skia/include/gpu/graphite/Recording.h +3 -0
  43. package/cpp/skia/include/gpu/graphite/dawn/DawnBackendContext.h +8 -0
  44. package/cpp/skia/include/gpu/graphite/mtl/MtlBackendContext.h +11 -0
  45. package/cpp/skia/include/gpu/graphite/vk/VulkanGraphiteContext.h +11 -0
  46. package/cpp/skia/include/private/SkLog.h +1 -19
  47. package/cpp/skia/include/private/chromium/GrVkSecondaryCBDrawContext.h +2 -1
  48. package/cpp/skia/include/utils/SkLogHandler.h +53 -0
  49. package/cpp/skia/include/utils/SkNWayCanvas.h +1 -0
  50. package/cpp/skia/modules/skcms/src/Transform_inl.h +9 -10
  51. package/cpp/skia/modules/skcms/src/skcms_internals.h +8 -3
  52. package/cpp/skia/modules/skottie/include/SkottieProperty.h +2 -0
  53. package/cpp/skia/modules/skottie/include/TextShaper.h +1 -0
  54. package/cpp/skia/modules/skshaper/include/SkShaper.h +23 -1
  55. package/include/ReactNativeSkia.h +6 -0
  56. package/lib/commonjs/dom/nodes/datatypes/Rect.js +5 -1
  57. package/lib/commonjs/dom/nodes/datatypes/Rect.js.map +1 -1
  58. package/lib/commonjs/external/reanimated/useVideo.js +8 -2
  59. package/lib/commonjs/external/reanimated/useVideo.js.map +1 -1
  60. package/lib/commonjs/renderer/components/Mask.js +3 -9
  61. package/lib/commonjs/renderer/components/Mask.js.map +1 -1
  62. package/lib/commonjs/skia/types/JsiInstance.d.ts +1 -0
  63. package/lib/commonjs/skia/types/JsiInstance.js.map +1 -1
  64. package/lib/commonjs/skia/types/Matrix4.js +7 -2
  65. package/lib/commonjs/skia/types/Matrix4.js.map +1 -1
  66. package/lib/commonjs/skia/types/Skia.d.ts +1 -6
  67. package/lib/commonjs/skia/types/Skia.js.map +1 -1
  68. package/lib/commonjs/skia/web/JsiSkCanvas.js +4 -4
  69. package/lib/commonjs/skia/web/JsiSkCanvas.js.map +1 -1
  70. package/lib/commonjs/skia/web/JsiSkImage.js +6 -3
  71. package/lib/commonjs/skia/web/JsiSkImage.js.map +1 -1
  72. package/lib/commonjs/skia/web/JsiSkPathBuilder.d.ts +1 -1
  73. package/lib/commonjs/skia/web/JsiSkPathBuilder.js +2 -2
  74. package/lib/commonjs/skia/web/JsiSkPathBuilder.js.map +1 -1
  75. package/lib/commonjs/skia/web/JsiSkTextStyle.js +5 -5
  76. package/lib/commonjs/skia/web/JsiSkTextStyle.js.map +1 -1
  77. package/lib/commonjs/skia/web/JsiSkia.js +0 -3
  78. package/lib/commonjs/skia/web/JsiSkia.js.map +1 -1
  79. package/lib/commonjs/skia/web/JsiSkottieAnimation.js +8 -8
  80. package/lib/commonjs/skia/web/JsiSkottieAnimation.js.map +1 -1
  81. package/lib/commonjs/sksg/Recorder/DrawingContext.d.ts +1 -0
  82. package/lib/commonjs/sksg/Recorder/DrawingContext.js +15 -0
  83. package/lib/commonjs/sksg/Recorder/DrawingContext.js.map +1 -1
  84. package/lib/commonjs/sksg/Recorder/Player.js +1 -1
  85. package/lib/commonjs/sksg/Recorder/Player.js.map +1 -1
  86. package/lib/commonjs/sksg/Recorder/Visitor.js +6 -1
  87. package/lib/commonjs/sksg/Recorder/Visitor.js.map +1 -1
  88. package/lib/commonjs/sksg/Recorder/commands/Drawing.js +12 -9
  89. package/lib/commonjs/sksg/Recorder/commands/Drawing.js.map +1 -1
  90. package/lib/commonjs/sksg/Recorder/commands/ImageFilters.js +15 -1
  91. package/lib/commonjs/sksg/Recorder/commands/ImageFilters.js.map +1 -1
  92. package/lib/commonjs/sksg/Recorder/commands/Shaders.js +1 -1
  93. package/lib/commonjs/sksg/Recorder/commands/Shaders.js.map +1 -1
  94. package/lib/commonjs/views/SkiaPictureView.web.js +247 -57
  95. package/lib/commonjs/views/SkiaPictureView.web.js.map +1 -1
  96. package/lib/module/dom/nodes/datatypes/Rect.js +5 -1
  97. package/lib/module/dom/nodes/datatypes/Rect.js.map +1 -1
  98. package/lib/module/external/reanimated/useVideo.js +8 -2
  99. package/lib/module/external/reanimated/useVideo.js.map +1 -1
  100. package/lib/module/renderer/components/Mask.js +3 -9
  101. package/lib/module/renderer/components/Mask.js.map +1 -1
  102. package/lib/module/skia/types/JsiInstance.d.ts +1 -0
  103. package/lib/module/skia/types/JsiInstance.js.map +1 -1
  104. package/lib/module/skia/types/Matrix4.js +7 -2
  105. package/lib/module/skia/types/Matrix4.js.map +1 -1
  106. package/lib/module/skia/types/Skia.d.ts +1 -6
  107. package/lib/module/skia/types/Skia.js.map +1 -1
  108. package/lib/module/skia/web/JsiSkCanvas.js +4 -4
  109. package/lib/module/skia/web/JsiSkCanvas.js.map +1 -1
  110. package/lib/module/skia/web/JsiSkImage.js +6 -3
  111. package/lib/module/skia/web/JsiSkImage.js.map +1 -1
  112. package/lib/module/skia/web/JsiSkPathBuilder.d.ts +1 -1
  113. package/lib/module/skia/web/JsiSkPathBuilder.js +2 -2
  114. package/lib/module/skia/web/JsiSkPathBuilder.js.map +1 -1
  115. package/lib/module/skia/web/JsiSkTextStyle.js +5 -5
  116. package/lib/module/skia/web/JsiSkTextStyle.js.map +1 -1
  117. package/lib/module/skia/web/JsiSkia.js +0 -3
  118. package/lib/module/skia/web/JsiSkia.js.map +1 -1
  119. package/lib/module/skia/web/JsiSkottieAnimation.js +8 -8
  120. package/lib/module/skia/web/JsiSkottieAnimation.js.map +1 -1
  121. package/lib/module/sksg/Recorder/DrawingContext.d.ts +1 -0
  122. package/lib/module/sksg/Recorder/DrawingContext.js +15 -0
  123. package/lib/module/sksg/Recorder/DrawingContext.js.map +1 -1
  124. package/lib/module/sksg/Recorder/Player.js +1 -1
  125. package/lib/module/sksg/Recorder/Player.js.map +1 -1
  126. package/lib/module/sksg/Recorder/Visitor.js +6 -1
  127. package/lib/module/sksg/Recorder/Visitor.js.map +1 -1
  128. package/lib/module/sksg/Recorder/commands/Drawing.js +12 -9
  129. package/lib/module/sksg/Recorder/commands/Drawing.js.map +1 -1
  130. package/lib/module/sksg/Recorder/commands/ImageFilters.js +15 -1
  131. package/lib/module/sksg/Recorder/commands/ImageFilters.js.map +1 -1
  132. package/lib/module/sksg/Recorder/commands/Shaders.js +1 -1
  133. package/lib/module/sksg/Recorder/commands/Shaders.js.map +1 -1
  134. package/lib/module/views/SkiaPictureView.web.js +247 -57
  135. package/lib/module/views/SkiaPictureView.web.js.map +1 -1
  136. package/lib/typescript/lib/commonjs/skia/web/JsiSkPathBuilder.d.ts +1 -1
  137. package/lib/typescript/lib/commonjs/skia/web/JsiSkia.d.ts +0 -1
  138. package/lib/typescript/lib/commonjs/sksg/Recorder/DrawingContext.d.ts +1 -0
  139. package/lib/typescript/lib/module/skia/Skia.web.d.ts +0 -1
  140. package/lib/typescript/lib/module/skia/web/JsiSkPathBuilder.d.ts +1 -1
  141. package/lib/typescript/lib/module/skia/web/JsiSkia.d.ts +0 -1
  142. package/lib/typescript/lib/module/sksg/Recorder/DrawingContext.d.ts +1 -0
  143. package/lib/typescript/react-native.config.d.ts +3 -0
  144. package/lib/typescript/src/skia/types/JsiInstance.d.ts +1 -0
  145. package/lib/typescript/src/skia/types/Skia.d.ts +1 -6
  146. package/lib/typescript/src/skia/web/JsiSkPathBuilder.d.ts +1 -1
  147. package/lib/typescript/src/sksg/Recorder/DrawingContext.d.ts +1 -0
  148. package/package.json +13 -10
  149. package/react-native.config.js +5 -0
  150. package/src/dom/nodes/datatypes/Rect.ts +6 -1
  151. package/src/external/reanimated/useVideo.ts +7 -2
  152. package/src/renderer/components/Mask.tsx +10 -3
  153. package/src/skia/types/JsiInstance.ts +2 -0
  154. package/src/skia/types/Matrix4.ts +6 -2
  155. package/src/skia/types/Skia.ts +1 -7
  156. package/src/skia/web/JsiSkCanvas.ts +11 -6
  157. package/src/skia/web/JsiSkImage.ts +6 -3
  158. package/src/skia/web/JsiSkPathBuilder.ts +2 -2
  159. package/src/skia/web/JsiSkTextStyle.ts +20 -15
  160. package/src/skia/web/JsiSkia.ts +0 -4
  161. package/src/skia/web/JsiSkottieAnimation.ts +8 -8
  162. package/src/sksg/Recorder/DrawingContext.ts +15 -0
  163. package/src/sksg/Recorder/Player.ts +1 -1
  164. package/src/sksg/Recorder/Visitor.ts +9 -6
  165. package/src/sksg/Recorder/commands/Drawing.ts +12 -9
  166. package/src/sksg/Recorder/commands/ImageFilters.ts +20 -1
  167. package/src/sksg/Recorder/commands/Shaders.ts +1 -1
  168. package/src/views/SkiaPictureView.web.tsx +245 -57
  169. package/cpp/api/JsiSkiaContext.h +0 -94
  170. package/cpp/dawn/include/dawn/dawn_proc.h +0 -53
  171. package/cpp/dawn/include/dawn/dawn_proc_table.h +0 -330
  172. package/cpp/dawn/include/dawn/dawn_thread_dispatch_proc.h +0 -47
  173. package/cpp/dawn/include/dawn/dawn_version.h +0 -41
  174. package/cpp/dawn/include/dawn/native/D3D11Backend.h +0 -65
  175. package/cpp/dawn/include/dawn/native/D3D12Backend.h +0 -103
  176. package/cpp/dawn/include/dawn/native/D3DBackend.h +0 -56
  177. package/cpp/dawn/include/dawn/native/DawnNative.h +0 -368
  178. package/cpp/dawn/include/dawn/native/MetalBackend.h +0 -56
  179. package/cpp/dawn/include/dawn/native/NullBackend.h +0 -39
  180. package/cpp/dawn/include/dawn/native/OpenGLBackend.h +0 -89
  181. package/cpp/dawn/include/dawn/native/VulkanBackend.h +0 -183
  182. package/cpp/dawn/include/dawn/native/WebGPUBackend.h +0 -49
  183. package/cpp/dawn/include/dawn/native/dawn_native_export.h +0 -49
  184. package/cpp/dawn/include/dawn/platform/DawnPlatform.h +0 -207
  185. package/cpp/dawn/include/dawn/platform/dawn_platform_export.h +0 -49
  186. package/cpp/dawn/include/dawn/replay/Replay.h +0 -99
  187. package/cpp/dawn/include/dawn/replay/dawn_replay_export.h +0 -49
  188. package/cpp/dawn/include/dawn/webgpu_cpp_print.h +0 -2856
  189. package/cpp/dawn/include/tint/tint.h +0 -91
  190. package/cpp/dawn/include/webgpu/webgpu.h +0 -5029
  191. package/cpp/dawn/include/webgpu/webgpu_cpp.h +0 -10353
  192. package/cpp/dawn/include/webgpu/webgpu_cpp_chained_struct.h +0 -57
  193. package/cpp/dawn/include/webgpu/webgpu_enum_class_bitmasks.h +0 -162
  194. package/cpp/dawn/include/webgpu/webgpu_glfw.h +0 -88
  195. package/cpp/jsi/RuntimeAwareCache.cpp +0 -7
  196. package/cpp/jsi/RuntimeAwareCache.h +0 -117
  197. package/cpp/jsi/RuntimeLifecycleMonitor.cpp +0 -72
  198. package/cpp/jsi/RuntimeLifecycleMonitor.h +0 -32
  199. package/cpp/skia/src/gpu/graphite/ContextOptionsPriv.h +0 -45
  200. package/cpp/skia/src/gpu/graphite/ResourceTypes.h +0 -360
  201. package/cpp/skia/src/gpu/graphite/TextureProxyView.h +0 -105
  202. package/libs/.graphite +0 -1
@@ -1 +1 @@
1
- {"version":3,"names":["enumKey","processColor","processRadius","NodeType","BlendMode","BlurStyle","ColorChannel","processUniforms","TileMode","composeDeclarations","CommandType","MorphologyOperator","Black","Float32Array","of","MakeInnerShadow","Skia","shadowOnly","dx","dy","sigmaX","sigmaY","color","input","sourceGraphic","ImageFilter","MakeColorFilter","ColorFilter","MakeBlend","Dst","sourceAlpha","SrcIn","f1","SrcOut","f2","MakeOffset","f3","MakeBlur","Decal","f4","MakeCompose","SrcOver","declareBlurImageFilter","ctx","props","mode","blur","sigma","imgf","x","y","imageFilters","push","declareMorphologyImageFilter","operator","r","radius","Erode","MakeErode","MakeDilate","declareOffsetImageFilter","declareDropShadowImageFilter","cl","inner","factory","bind","MakeDropShadowOnly","MakeDropShadow","declareBlendImageFilter","blend","splice","length","composer","declareDisplacementMapImageFilter","channelX","channelY","scale","shader","shaders","pop","Error","map","MakeShader","MakeDisplacementMap","declareRuntimeShaderImageFilter","source","uniforms","rtb","RuntimeShaderBuilder","MakeRuntimeShader","declareImageFilter","filter","composeImageFilters","outer","setBlurMaskFilter","style","respectCTM","mf","MaskFilter","paint","setMaskFilter","isPushImageFilter","command","type","PushImageFilter","isImageFilter","imageFilterType","pushImageFilter","BlurImageFilter","MorphologyImageFilter","BlendImageFilter","DisplacementMapImageFilter","DropShadowImageFilter","OffsetImageFilter","RuntimeShaderImageFilter"],"sources":["ImageFilters.ts"],"sourcesContent":["import { enumKey, processColor, processRadius } from \"../../../dom/nodes\";\nimport type {\n BlendImageFilterProps,\n BlurImageFilterProps,\n BlurMaskFilterProps,\n DisplacementMapImageFilterProps,\n DropShadowImageFilterProps,\n ImageFilterProps,\n MorphologyImageFilterProps,\n OffsetImageFilterProps,\n RuntimeShaderImageFilterProps,\n} from \"../../../dom/types\";\nimport { NodeType } from \"../../../dom/types\";\nimport type { SkColor, SkImageFilter, Skia } from \"../../../skia/types\";\nimport {\n BlendMode,\n BlurStyle,\n ColorChannel,\n processUniforms,\n TileMode,\n} from \"../../../skia/types\";\nimport { composeDeclarations } from \"../../utils\";\nimport type { Command } from \"../Core\";\nimport { CommandType } from \"../Core\";\nimport type { DrawingContext } from \"../DrawingContext\";\n\nexport enum MorphologyOperator {\n Erode,\n Dilate,\n}\n\nconst Black = Float32Array.of(0, 0, 0, 1);\n\nconst MakeInnerShadow = (\n Skia: Skia,\n shadowOnly: boolean | undefined,\n dx: number,\n dy: number,\n sigmaX: number,\n sigmaY: number,\n color: SkColor,\n input: SkImageFilter | null\n) => {\n \"worklet\";\n const sourceGraphic = Skia.ImageFilter.MakeColorFilter(\n Skia.ColorFilter.MakeBlend(Black, BlendMode.Dst),\n null\n );\n const sourceAlpha = Skia.ImageFilter.MakeColorFilter(\n Skia.ColorFilter.MakeBlend(Black, BlendMode.SrcIn),\n null\n );\n const f1 = Skia.ImageFilter.MakeColorFilter(\n Skia.ColorFilter.MakeBlend(color, BlendMode.SrcOut),\n null\n );\n const f2 = Skia.ImageFilter.MakeOffset(dx, dy, f1);\n const f3 = Skia.ImageFilter.MakeBlur(sigmaX, sigmaY, TileMode.Decal, f2);\n const f4 = Skia.ImageFilter.MakeBlend(BlendMode.SrcIn, sourceAlpha, f3);\n if (shadowOnly) {\n return f4;\n }\n return Skia.ImageFilter.MakeCompose(\n input,\n Skia.ImageFilter.MakeBlend(BlendMode.SrcOver, sourceGraphic, f4)\n );\n};\n\nconst declareBlurImageFilter = (\n ctx: DrawingContext,\n props: BlurImageFilterProps\n) => {\n \"worklet\";\n const { mode, blur } = props;\n const sigma = processRadius(ctx.Skia, blur);\n const imgf = ctx.Skia.ImageFilter.MakeBlur(\n sigma.x,\n sigma.y,\n TileMode[enumKey(mode)],\n null\n );\n ctx.imageFilters.push(imgf);\n};\n\nconst declareMorphologyImageFilter = (\n ctx: DrawingContext,\n props: MorphologyImageFilterProps\n) => {\n \"worklet\";\n const { operator } = props;\n const r = processRadius(ctx.Skia, props.radius);\n let imgf;\n if (MorphologyOperator[enumKey(operator)] === MorphologyOperator.Erode) {\n imgf = ctx.Skia.ImageFilter.MakeErode(r.x, r.y, null);\n } else {\n imgf = ctx.Skia.ImageFilter.MakeDilate(r.x, r.y, null);\n }\n ctx.imageFilters.push(imgf);\n};\n\nconst declareOffsetImageFilter = (\n ctx: DrawingContext,\n props: OffsetImageFilterProps\n) => {\n \"worklet\";\n const { x, y } = props;\n const imgf = ctx.Skia.ImageFilter.MakeOffset(x, y, null);\n ctx.imageFilters.push(imgf);\n};\n\nconst declareDropShadowImageFilter = (\n ctx: DrawingContext,\n props: DropShadowImageFilterProps\n) => {\n \"worklet\";\n const { dx, dy, blur, shadowOnly, color: cl, inner } = props;\n const color = processColor(ctx.Skia, cl);\n let factory;\n if (inner) {\n factory = MakeInnerShadow.bind(null, ctx.Skia, shadowOnly);\n } else {\n factory = shadowOnly\n ? ctx.Skia.ImageFilter.MakeDropShadowOnly.bind(ctx.Skia.ImageFilter)\n : ctx.Skia.ImageFilter.MakeDropShadow.bind(ctx.Skia.ImageFilter);\n }\n const imgf = factory(dx, dy, blur, blur, color, null);\n ctx.imageFilters.push(imgf);\n};\n\nconst declareBlendImageFilter = (\n ctx: DrawingContext,\n props: BlendImageFilterProps\n) => {\n \"worklet\";\n const blend = BlendMode[enumKey(props.mode)];\n // Blend ImageFilters\n const imageFilters = ctx.imageFilters.splice(0, ctx.imageFilters.length);\n const composer = ctx.Skia.ImageFilter.MakeBlend.bind(\n ctx.Skia.ImageFilter,\n blend\n );\n ctx.imageFilters.push(composeDeclarations(imageFilters, composer));\n};\n\nconst declareDisplacementMapImageFilter = (\n ctx: DrawingContext,\n props: DisplacementMapImageFilterProps\n) => {\n \"worklet\";\n const { channelX, channelY, scale } = props;\n const shader = ctx.shaders.pop();\n if (!shader) {\n throw new Error(\"DisplacementMap expects a shader as child\");\n }\n const map = ctx.Skia.ImageFilter.MakeShader(shader);\n const imgf = ctx.Skia.ImageFilter.MakeDisplacementMap(\n ColorChannel[enumKey(channelX)],\n ColorChannel[enumKey(channelY)],\n scale,\n map,\n null\n );\n ctx.imageFilters.push(imgf);\n};\n\nconst declareRuntimeShaderImageFilter = (\n ctx: DrawingContext,\n props: RuntimeShaderImageFilterProps\n) => {\n \"worklet\";\n const { source, uniforms } = props;\n const rtb = ctx.Skia.RuntimeShaderBuilder(source);\n if (uniforms) {\n processUniforms(source, uniforms, rtb);\n }\n const imgf = ctx.Skia.ImageFilter.MakeRuntimeShader(rtb, null, null);\n ctx.imageFilters.push(imgf);\n};\n\nconst declareImageFilter = (ctx: DrawingContext, props: ImageFilterProps) => {\n \"worklet\";\n const { filter } = props;\n ctx.imageFilters.push(filter);\n};\n\nexport const composeImageFilters = (ctx: DrawingContext) => {\n \"worklet\";\n if (ctx.imageFilters.length > 1) {\n const outer = ctx.imageFilters.pop()!;\n const inner = ctx.imageFilters.pop()!;\n ctx.imageFilters.push(ctx.Skia.ImageFilter.MakeCompose(outer, inner));\n }\n};\n\nexport const setBlurMaskFilter = (\n ctx: DrawingContext,\n props: BlurMaskFilterProps\n) => {\n \"worklet\";\n const { blur, style, respectCTM } = props;\n const mf = ctx.Skia.MaskFilter.MakeBlur(\n BlurStyle[enumKey(style)],\n blur,\n respectCTM\n );\n ctx.paint.setMaskFilter(mf);\n};\n\nexport const isPushImageFilter = (\n command: Command\n): command is Command<CommandType.PushImageFilter> => {\n \"worklet\";\n return command.type === CommandType.PushImageFilter;\n};\n\ntype Props = {\n [NodeType.ImageFilter]: ImageFilterProps;\n [NodeType.OffsetImageFilter]: OffsetImageFilterProps;\n [NodeType.DisplacementMapImageFilter]: DisplacementMapImageFilterProps;\n [NodeType.BlurImageFilter]: BlurImageFilterProps;\n [NodeType.DropShadowImageFilter]: DropShadowImageFilterProps;\n [NodeType.MorphologyImageFilter]: MorphologyImageFilterProps;\n [NodeType.BlendImageFilter]: BlendImageFilterProps;\n [NodeType.RuntimeShaderImageFilter]: RuntimeShaderImageFilterProps;\n};\n\ninterface PushImageFilter<\n T extends keyof Props,\n> extends Command<CommandType.PushImageFilter> {\n imageFilterType: T;\n props: Props[T];\n}\n\nconst isImageFilter = <T extends keyof Props>(\n command: Command<CommandType.PushImageFilter>,\n type: T\n): command is PushImageFilter<T> => {\n \"worklet\";\n return command.imageFilterType === type;\n};\n\nexport const pushImageFilter = (\n ctx: DrawingContext,\n command: Command<CommandType.PushImageFilter>\n) => {\n \"worklet\";\n if (isImageFilter(command, NodeType.ImageFilter)) {\n declareImageFilter(ctx, command.props);\n } else if (isImageFilter(command, NodeType.BlurImageFilter)) {\n declareBlurImageFilter(ctx, command.props);\n } else if (isImageFilter(command, NodeType.MorphologyImageFilter)) {\n declareMorphologyImageFilter(ctx, command.props);\n } else if (isImageFilter(command, NodeType.BlendImageFilter)) {\n declareBlendImageFilter(ctx, command.props);\n } else if (isImageFilter(command, NodeType.DisplacementMapImageFilter)) {\n declareDisplacementMapImageFilter(ctx, command.props);\n } else if (isImageFilter(command, NodeType.DropShadowImageFilter)) {\n declareDropShadowImageFilter(ctx, command.props);\n } else if (isImageFilter(command, NodeType.OffsetImageFilter)) {\n declareOffsetImageFilter(ctx, command.props);\n } else if (isImageFilter(command, NodeType.RuntimeShaderImageFilter)) {\n declareRuntimeShaderImageFilter(ctx, command.props);\n } else {\n throw new Error(\"Invalid image filter type: \" + command.imageFilterType);\n }\n};\n"],"mappings":"AAAA,SAASA,OAAO,EAAEC,YAAY,EAAEC,aAAa,QAAQ,oBAAoB;AAYzE,SAASC,QAAQ,QAAQ,oBAAoB;AAE7C,SACEC,SAAS,EACTC,SAAS,EACTC,YAAY,EACZC,eAAe,EACfC,QAAQ,QACH,qBAAqB;AAC5B,SAASC,mBAAmB,QAAQ,aAAa;AAEjD,SAASC,WAAW,QAAQ,SAAS;AAGrC,WAAYC,kBAAkB,0BAAlBA,kBAAkB;EAAlBA,kBAAkB,CAAlBA,kBAAkB;EAAlBA,kBAAkB,CAAlBA,kBAAkB;EAAA,OAAlBA,kBAAkB;AAAA;AAK9B,MAAMC,KAAK,GAAGC,YAAY,CAACC,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC;AAEzC,MAAMC,eAAe,GAAGA,CACtBC,IAAU,EACVC,UAA+B,EAC/BC,EAAU,EACVC,EAAU,EACVC,MAAc,EACdC,MAAc,EACdC,KAAc,EACdC,KAA2B,KACxB;EACH,SAAS;;EACT,MAAMC,aAAa,GAAGR,IAAI,CAACS,WAAW,CAACC,eAAe,CACpDV,IAAI,CAACW,WAAW,CAACC,SAAS,CAAChB,KAAK,EAAER,SAAS,CAACyB,GAAG,CAAC,EAChD,IACF,CAA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AACjB,GAAG,EAAE2D,OAAO,CAAC1D,KAAK,CAAC;EAC9C,CAAC,MAAM,IAAI6D,aAAa,CAACH,OAAO,EAAEnG,QAAQ,CAAC+G,wBAAwB,CAAC,EAAE;IACpE9B,+BAA+B,CAACzC,GAAG,EAAE2D,OAAO,CAAC1D,KAAK,CAAC;EACrD,CAAC,MAAM;IACL,MAAM,IAAIoC,KAAK,CAAC,6BAA6B,GAAGsB,OAAO,CAACI,eAAe,CAAC;EAC1E;AACF,CAAC","ignoreList":[]}
1
+ {"version":3,"names":["enumKey","processColor","processRadius","NodeType","BlendMode","BlurStyle","ColorChannel","processUniforms","TileMode","composeDeclarations","CommandType","MorphologyOperator","Black","Float32Array","of","AlphaSaturate","MakeInnerShadow","Skia","shadowOnly","dx","dy","sigmaX","sigmaY","color","input","sourceGraphic","ImageFilter","MakeColorFilter","ColorFilter","MakeBlend","Dst","sourceAlpha","SrcIn","coverage","MakeMatrix","f1","SrcOut","f2","MakeOffset","f3","MakeBlur","Decal","f4","MakeCompose","SrcOver","declareBlurImageFilter","ctx","props","mode","blur","sigma","imgf","x","y","imageFilters","push","declareMorphologyImageFilter","operator","r","radius","Erode","MakeErode","MakeDilate","declareOffsetImageFilter","declareDropShadowImageFilter","cl","inner","factory","bind","MakeDropShadowOnly","MakeDropShadow","declareBlendImageFilter","blend","splice","length","composer","declareDisplacementMapImageFilter","channelX","channelY","scale","shader","shaders","pop","Error","map","MakeShader","MakeDisplacementMap","declareRuntimeShaderImageFilter","source","uniforms","rtb","RuntimeShaderBuilder","MakeRuntimeShader","declareImageFilter","filter","composeImageFilters","outer","setBlurMaskFilter","style","respectCTM","mf","MaskFilter","paint","setMaskFilter","isPushImageFilter","command","type","PushImageFilter","isImageFilter","imageFilterType","pushImageFilter","BlurImageFilter","MorphologyImageFilter","BlendImageFilter","DisplacementMapImageFilter","DropShadowImageFilter","OffsetImageFilter","RuntimeShaderImageFilter"],"sources":["ImageFilters.ts"],"sourcesContent":["import { enumKey, processColor, processRadius } from \"../../../dom/nodes\";\nimport type {\n BlendImageFilterProps,\n BlurImageFilterProps,\n BlurMaskFilterProps,\n DisplacementMapImageFilterProps,\n DropShadowImageFilterProps,\n ImageFilterProps,\n MorphologyImageFilterProps,\n OffsetImageFilterProps,\n RuntimeShaderImageFilterProps,\n} from \"../../../dom/types\";\nimport { NodeType } from \"../../../dom/types\";\nimport type { SkColor, SkImageFilter, Skia } from \"../../../skia/types\";\nimport {\n BlendMode,\n BlurStyle,\n ColorChannel,\n processUniforms,\n TileMode,\n} from \"../../../skia/types\";\nimport { composeDeclarations } from \"../../utils\";\nimport type { Command } from \"../Core\";\nimport { CommandType } from \"../Core\";\nimport type { DrawingContext } from \"../DrawingContext\";\n\nexport enum MorphologyOperator {\n Erode,\n Dilate,\n}\n\nconst Black = Float32Array.of(0, 0, 0, 1);\n\n// Turns the source graphic into a hard silhouette: alpha is multiplied by 255\n// and clamped, so any pixel the shape covers at all becomes fully opaque, and\n// the colour channels are dropped. 255 is the saturation point of an 8-bit\n// alpha channel, so one unit of coverage is enough to reach 1.\nconst AlphaSaturate = [\n 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 0,\n];\n\nconst MakeInnerShadow = (\n Skia: Skia,\n shadowOnly: boolean | undefined,\n dx: number,\n dy: number,\n sigmaX: number,\n sigmaY: number,\n color: SkColor,\n input: SkImageFilter | null\n) => {\n \"worklet\";\n const sourceGraphic = Skia.ImageFilter.MakeColorFilter(\n Skia.ColorFilter.MakeBlend(Black, BlendMode.Dst),\n null\n );\n const sourceAlpha = Skia.ImageFilter.MakeColorFilter(\n Skia.ColorFilter.MakeBlend(Black, BlendMode.SrcIn),\n null\n );\n // The shadow is generated outside the shape and then clipped back into it, so\n // \"outside\" has to be the complement of the shape's silhouette. Taking SrcOut\n // against the source graphic itself makes it the complement of the source's\n // *alpha*: inside a translucent shape 1 - alpha is non-zero, so the shadow is\n // generated across the whole interior and tints it, no matter how small the\n // blur and the offset are (issue #2990). Saturating alpha first keeps the\n // shadow tied to the shape's outline instead of to its opacity.\n const coverage = Skia.ImageFilter.MakeColorFilter(\n Skia.ColorFilter.MakeMatrix(AlphaSaturate),\n null\n );\n const f1 = Skia.ImageFilter.MakeColorFilter(\n Skia.ColorFilter.MakeBlend(color, BlendMode.SrcOut),\n coverage\n );\n const f2 = Skia.ImageFilter.MakeOffset(dx, dy, f1);\n const f3 = Skia.ImageFilter.MakeBlur(sigmaX, sigmaY, TileMode.Decal, f2);\n const f4 = Skia.ImageFilter.MakeBlend(BlendMode.SrcIn, sourceAlpha, f3);\n if (shadowOnly) {\n return f4;\n }\n return Skia.ImageFilter.MakeCompose(\n input,\n Skia.ImageFilter.MakeBlend(BlendMode.SrcOver, sourceGraphic, f4)\n );\n};\n\nconst declareBlurImageFilter = (\n ctx: DrawingContext,\n props: BlurImageFilterProps\n) => {\n \"worklet\";\n const { mode, blur } = props;\n const sigma = processRadius(ctx.Skia, blur);\n const imgf = ctx.Skia.ImageFilter.MakeBlur(\n sigma.x,\n sigma.y,\n TileMode[enumKey(mode)],\n null\n );\n ctx.imageFilters.push(imgf);\n};\n\nconst declareMorphologyImageFilter = (\n ctx: DrawingContext,\n props: MorphologyImageFilterProps\n) => {\n \"worklet\";\n const { operator } = props;\n const r = processRadius(ctx.Skia, props.radius);\n let imgf;\n if (MorphologyOperator[enumKey(operator)] === MorphologyOperator.Erode) {\n imgf = ctx.Skia.ImageFilter.MakeErode(r.x, r.y, null);\n } else {\n imgf = ctx.Skia.ImageFilter.MakeDilate(r.x, r.y, null);\n }\n ctx.imageFilters.push(imgf);\n};\n\nconst declareOffsetImageFilter = (\n ctx: DrawingContext,\n props: OffsetImageFilterProps\n) => {\n \"worklet\";\n const { x, y } = props;\n const imgf = ctx.Skia.ImageFilter.MakeOffset(x, y, null);\n ctx.imageFilters.push(imgf);\n};\n\nconst declareDropShadowImageFilter = (\n ctx: DrawingContext,\n props: DropShadowImageFilterProps\n) => {\n \"worklet\";\n const { dx, dy, blur, shadowOnly, color: cl, inner } = props;\n const color = processColor(ctx.Skia, cl);\n let factory;\n if (inner) {\n factory = MakeInnerShadow.bind(null, ctx.Skia, shadowOnly);\n } else {\n factory = shadowOnly\n ? ctx.Skia.ImageFilter.MakeDropShadowOnly.bind(ctx.Skia.ImageFilter)\n : ctx.Skia.ImageFilter.MakeDropShadow.bind(ctx.Skia.ImageFilter);\n }\n const imgf = factory(dx, dy, blur, blur, color, null);\n ctx.imageFilters.push(imgf);\n};\n\nconst declareBlendImageFilter = (\n ctx: DrawingContext,\n props: BlendImageFilterProps\n) => {\n \"worklet\";\n const blend = BlendMode[enumKey(props.mode)];\n // Blend ImageFilters\n const imageFilters = ctx.imageFilters.splice(0, ctx.imageFilters.length);\n const composer = ctx.Skia.ImageFilter.MakeBlend.bind(\n ctx.Skia.ImageFilter,\n blend\n );\n ctx.imageFilters.push(composeDeclarations(imageFilters, composer));\n};\n\nconst declareDisplacementMapImageFilter = (\n ctx: DrawingContext,\n props: DisplacementMapImageFilterProps\n) => {\n \"worklet\";\n const { channelX, channelY, scale } = props;\n const shader = ctx.shaders.pop();\n if (!shader) {\n throw new Error(\"DisplacementMap expects a shader as child\");\n }\n const map = ctx.Skia.ImageFilter.MakeShader(shader);\n const imgf = ctx.Skia.ImageFilter.MakeDisplacementMap(\n ColorChannel[enumKey(channelX)],\n ColorChannel[enumKey(channelY)],\n scale,\n map,\n null\n );\n ctx.imageFilters.push(imgf);\n};\n\nconst declareRuntimeShaderImageFilter = (\n ctx: DrawingContext,\n props: RuntimeShaderImageFilterProps\n) => {\n \"worklet\";\n const { source, uniforms } = props;\n const rtb = ctx.Skia.RuntimeShaderBuilder(source);\n if (uniforms) {\n processUniforms(source, uniforms, rtb);\n }\n const imgf = ctx.Skia.ImageFilter.MakeRuntimeShader(rtb, null, null);\n ctx.imageFilters.push(imgf);\n};\n\nconst declareImageFilter = (ctx: DrawingContext, props: ImageFilterProps) => {\n \"worklet\";\n const { filter } = props;\n ctx.imageFilters.push(filter);\n};\n\nexport const composeImageFilters = (ctx: DrawingContext) => {\n \"worklet\";\n if (ctx.imageFilters.length > 1) {\n const outer = ctx.imageFilters.pop()!;\n const inner = ctx.imageFilters.pop()!;\n ctx.imageFilters.push(ctx.Skia.ImageFilter.MakeCompose(outer, inner));\n }\n};\n\nexport const setBlurMaskFilter = (\n ctx: DrawingContext,\n props: BlurMaskFilterProps\n) => {\n \"worklet\";\n const { blur, style, respectCTM } = props;\n const mf = ctx.Skia.MaskFilter.MakeBlur(\n BlurStyle[enumKey(style)],\n blur,\n respectCTM\n );\n ctx.paint.setMaskFilter(mf);\n};\n\nexport const isPushImageFilter = (\n command: Command\n): command is Command<CommandType.PushImageFilter> => {\n \"worklet\";\n return command.type === CommandType.PushImageFilter;\n};\n\ntype Props = {\n [NodeType.ImageFilter]: ImageFilterProps;\n [NodeType.OffsetImageFilter]: OffsetImageFilterProps;\n [NodeType.DisplacementMapImageFilter]: DisplacementMapImageFilterProps;\n [NodeType.BlurImageFilter]: BlurImageFilterProps;\n [NodeType.DropShadowImageFilter]: DropShadowImageFilterProps;\n [NodeType.MorphologyImageFilter]: MorphologyImageFilterProps;\n [NodeType.BlendImageFilter]: BlendImageFilterProps;\n [NodeType.RuntimeShaderImageFilter]: RuntimeShaderImageFilterProps;\n};\n\ninterface PushImageFilter<\n T extends keyof Props,\n> extends Command<CommandType.PushImageFilter> {\n imageFilterType: T;\n props: Props[T];\n}\n\nconst isImageFilter = <T extends keyof Props>(\n command: Command<CommandType.PushImageFilter>,\n type: T\n): command is PushImageFilter<T> => {\n \"worklet\";\n return command.imageFilterType === type;\n};\n\nexport const pushImageFilter = (\n ctx: DrawingContext,\n command: Command<CommandType.PushImageFilter>\n) => {\n \"worklet\";\n if (isImageFilter(command, NodeType.ImageFilter)) {\n declareImageFilter(ctx, command.props);\n } else if (isImageFilter(command, NodeType.BlurImageFilter)) {\n declareBlurImageFilter(ctx, command.props);\n } else if (isImageFilter(command, NodeType.MorphologyImageFilter)) {\n declareMorphologyImageFilter(ctx, command.props);\n } else if (isImageFilter(command, NodeType.BlendImageFilter)) {\n declareBlendImageFilter(ctx, command.props);\n } else if (isImageFilter(command, NodeType.DisplacementMapImageFilter)) {\n declareDisplacementMapImageFilter(ctx, command.props);\n } else if (isImageFilter(command, NodeType.DropShadowImageFilter)) {\n declareDropShadowImageFilter(ctx, command.props);\n } else if (isImageFilter(command, NodeType.OffsetImageFilter)) {\n declareOffsetImageFilter(ctx, command.props);\n } else if (isImageFilter(command, NodeType.RuntimeShaderImageFilter)) {\n declareRuntimeShaderImageFilter(ctx, command.props);\n } else {\n throw new Error(\"Invalid image filter type: \" + command.imageFilterType);\n }\n};\n"],"mappings":"AAAA,SAASA,OAAO,EAAEC,YAAY,EAAEC,aAAa,QAAQ,oBAAoB;AAYzE,SAASC,QAAQ,QAAQ,oBAAoB;AAE7C,SACEC,SAAS,EACTC,SAAS,EACTC,YAAY,EACZC,eAAe,EACfC,QAAQ,QACH,qBAAqB;AAC5B,SAASC,mBAAmB,QAAQ,aAAa;AAEjD,SAASC,WAAW,QAAQ,SAAS;AAGrC,WAAYC,kBAAkB,0BAAlBA,kBAAkB;EAAlBA,kBAAkB,CAAlBA,kBAAkB;EAAlBA,kBAAkB,CAAlBA,kBAAkB;EAAA,OAAlBA,kBAAkB;AAAA;AAK9B,MAAMC,KAAK,GAAGC,YAAY,CAACC,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC;;AAEzC;AACA;AACA;AACA;AACA,MAAMC,aAAa,GAAG,CACpB,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,GAAG,EAAE,CAAC,CAC7D;AAED,MAAMC,eA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GAAG,EAAE2D,OAAO,CAAC1D,KAAK,CAAC;EAC7C,CAAC,MAAM,IAAI6D,aAAa,CAACH,OAAO,EAAEtG,QAAQ,CAAC+G,0BAA0B,CAAC,EAAE;IACtEtC,iCAAiC,CAAC9B,GAAG,EAAE2D,OAAO,CAAC1D,KAAK,CAAC;EACvD,CAAC,MAAM,IAAI6D,aAAa,CAACH,OAAO,EAAEtG,QAAQ,CAACgH,qBAAqB,CAAC,EAAE;IACjEnD,4BAA4B,CAAClB,GAAG,EAAE2D,OAAO,CAAC1D,KAAK,CAAC;EAClD,CAAC,MAAM,IAAI6D,aAAa,CAACH,OAAO,EAAEtG,QAAQ,CAACiH,iBAAiB,CAAC,EAAE;IAC7DrD,wBAAwB,CAACjB,GAAG,EAAE2D,OAAO,CAAC1D,KAAK,CAAC;EAC9C,CAAC,MAAM,IAAI6D,aAAa,CAACH,OAAO,EAAEtG,QAAQ,CAACkH,wBAAwB,CAAC,EAAE;IACpE9B,+BAA+B,CAACzC,GAAG,EAAE2D,OAAO,CAAC1D,KAAK,CAAC;EACrD,CAAC,MAAM;IACL,MAAM,IAAIoC,KAAK,CAAC,6BAA6B,GAAGsB,OAAO,CAACI,eAAe,CAAC;EAC1E;AACF,CAAC","ignoreList":[]}
@@ -159,7 +159,7 @@ const declareImageShader = (ctx, props) => {
159
159
  shader = ctx.track(image.makeShaderCubic(TileMode[enumKey(tx)], TileMode[enumKey(ty)], sampling.B, sampling.C, lm));
160
160
  } else {
161
161
  var _sampling$filter, _sampling$mipmap;
162
- shader = ctx.track(image.makeShaderCubic(TileMode[enumKey(tx)], TileMode[enumKey(ty)], (_sampling$filter = sampling === null || sampling === void 0 ? void 0 : sampling.filter) !== null && _sampling$filter !== void 0 ? _sampling$filter : FilterMode.Linear, (_sampling$mipmap = sampling === null || sampling === void 0 ? void 0 : sampling.mipmap) !== null && _sampling$mipmap !== void 0 ? _sampling$mipmap : MipmapMode.None, lm));
162
+ shader = ctx.track(image.makeShaderOptions(TileMode[enumKey(tx)], TileMode[enumKey(ty)], (_sampling$filter = sampling === null || sampling === void 0 ? void 0 : sampling.filter) !== null && _sampling$filter !== void 0 ? _sampling$filter : FilterMode.Linear, (_sampling$mipmap = sampling === null || sampling === void 0 ? void 0 : sampling.mipmap) !== null && _sampling$mipmap !== void 0 ? _sampling$mipmap : MipmapMode.None, lm));
163
163
  }
164
164
  ctx.shaders.push(shader);
165
165
  };
@@ -1 +1 @@
1
- {"version":3,"names":["enumKey","fitRects","getRect","processColor","processGradientProps","processTransformProps","rect2rect","NodeType","BlendMode","FilterMode","isCubicSampling","MipmapMode","processUniforms","TileMode","composeDeclarations","CommandType","declareShader","ctx","props","children","source","uniforms","transform","m3","Skia","Matrix","shader","track","makeShaderWithChildren","shaders","splice","push","declareColorShader","color","Shader","MakeColor","declareFractalNoiseShader","freqX","freqY","octaves","seed","tileWidth","tileHeight","MakeFractalNoise","declareTwoPointConicalGradientShader","startR","endR","start","end","colors","positions","mode","localMatrix","flags","MakeTwoPointConicalGradient","declareRadialGradientShader","c","r","MakeRadialGradient","declareSweepGradientShader","MakeSweepGradient","x","y","declareLinearGradientShader","MakeLinearGradient","declareTurbulenceShader","MakeTurbulence","declareImageShader","fit","image","tx","ty","sampling","imageShaderProps","rct","rects","width","height","sx","sy","src","dst","translate","translateX","translateY","scale","scaleX","scaleY","lm","concat","makeShaderCubic","B","C","_sampling$filter","_sampling$mipmap","filter","Linear","mipmap","None","declareBlend","blend","length","composer","MakeBlend","bind","isPushShader","command","type","PushShader","isShader","shaderType","pushShader","ImageShader","ColorShader","Turbulence","FractalNoise","LinearGradient","RadialGradient","SweepGradient","TwoPointConicalGradient","Blend","Error"],"sources":["Shaders.ts"],"sourcesContent":["import {\n enumKey,\n fitRects,\n getRect,\n processColor,\n processGradientProps,\n processTransformProps,\n rect2rect,\n} from \"../../../dom/nodes\";\nimport { NodeType } from \"../../../dom/types\";\nimport type {\n BlendProps,\n ColorProps,\n FractalNoiseProps,\n ImageShaderProps,\n LinearGradientProps,\n RadialGradientProps,\n ShaderProps,\n SweepGradientProps,\n TurbulenceProps,\n TwoPointConicalGradientProps,\n} from \"../../../dom/types\";\nimport type { SkShader } from \"../../../skia/types\";\nimport {\n BlendMode,\n FilterMode,\n isCubicSampling,\n MipmapMode,\n processUniforms,\n TileMode,\n} from \"../../../skia/types\";\nimport { composeDeclarations } from \"../../utils\";\nimport type { Command } from \"../Core\";\nimport { CommandType } from \"../Core\";\nimport type { DrawingContext } from \"../DrawingContext\";\n\nconst declareShader = (\n ctx: DrawingContext,\n props: ShaderProps,\n children: number\n) => {\n \"worklet\";\n const { source, uniforms, ...transform } = props;\n const m3 = ctx.Skia.Matrix();\n processTransformProps(m3, transform);\n const shader = ctx.track(\n source.makeShaderWithChildren(\n processUniforms(source, uniforms),\n ctx.shaders.splice(0, children),\n m3\n )\n );\n ctx.shaders.push(shader);\n};\n\nconst declareColorShader = (ctx: DrawingContext, props: ColorProps) => {\n \"worklet\";\n const { color } = props;\n const shader = ctx.Skia.Shader.MakeColor(processColor(ctx.Skia, color));\n ctx.shaders.push(shader);\n};\n\nconst declareFractalNoiseShader = (\n ctx: DrawingContext,\n props: FractalNoiseProps\n) => {\n \"worklet\";\n const { freqX, freqY, octaves, seed, tileWidth, tileHeight } = props;\n const shader = ctx.Skia.Shader.MakeFractalNoise(\n freqX,\n freqY,\n octaves,\n seed,\n tileWidth,\n tileHeight\n );\n ctx.shaders.push(shader);\n};\n\nconst declareTwoPointConicalGradientShader = (\n ctx: DrawingContext,\n props: TwoPointConicalGradientProps\n) => {\n \"worklet\";\n const { startR, endR, start, end } = props;\n const { colors, positions, mode, localMatrix, flags } = processGradientProps(\n ctx.Skia,\n props\n );\n const shader = ctx.Skia.Shader.MakeTwoPointConicalGradient(\n start,\n startR,\n end,\n endR,\n colors,\n positions,\n mode,\n localMatrix,\n flags\n );\n ctx.shaders.push(shader);\n};\n\nconst declareRadialGradientShader = (\n ctx: DrawingContext,\n props: RadialGradientProps\n) => {\n \"worklet\";\n const { c, r } = props;\n const { colors, positions, mode, localMatrix, flags } = processGradientProps(\n ctx.Skia,\n props\n );\n const shader = ctx.Skia.Shader.MakeRadialGradient(\n c,\n r,\n colors,\n positions,\n mode,\n localMatrix,\n flags\n );\n ctx.shaders.push(shader);\n};\n\nconst declareSweepGradientShader = (\n ctx: DrawingContext,\n props: SweepGradientProps\n) => {\n \"worklet\";\n const { c, start, end } = props;\n const { colors, positions, mode, localMatrix, flags } = processGradientProps(\n ctx.Skia,\n props\n );\n const shader = ctx.Skia.Shader.MakeSweepGradient(\n c.x,\n c.y,\n colors,\n positions,\n mode,\n localMatrix,\n flags,\n start,\n end\n );\n ctx.shaders.push(shader);\n};\n\nconst declareLinearGradientShader = (\n ctx: DrawingContext,\n props: LinearGradientProps\n) => {\n \"worklet\";\n const { start, end } = props;\n const { colors, positions, mode, localMatrix, flags } = processGradientProps(\n ctx.Skia,\n props\n );\n const shader = ctx.Skia.Shader.MakeLinearGradient(\n start,\n end,\n colors,\n positions ?? null,\n mode,\n localMatrix,\n flags\n );\n ctx.shaders.push(shader);\n};\n\nconst declareTurbulenceShader = (\n ctx: DrawingContext,\n props: TurbulenceProps\n) => {\n \"worklet\";\n const { freqX, freqY, octaves, seed, tileWidth, tileHeight } = props;\n const shader = ctx.Skia.Shader.MakeTurbulence(\n freqX,\n freqY,\n octaves,\n seed,\n tileWidth,\n tileHeight\n );\n ctx.shaders.push(shader);\n};\n\nconst declareImageShader = (ctx: DrawingContext, props: ImageShaderProps) => {\n \"worklet\";\n const { fit, image, tx, ty, sampling, ...imageShaderProps } = props;\n if (!image) {\n return;\n }\n\n const rct = getRect(ctx.Skia, imageShaderProps);\n const m3 = ctx.Skia.Matrix();\n if (rct) {\n const rects = fitRects(\n fit,\n { x: 0, y: 0, width: image.width(), height: image.height() },\n rct\n );\n const [x, y, sx, sy] = rect2rect(rects.src, rects.dst);\n m3.translate(x.translateX, y.translateY);\n m3.scale(sx.scaleX, sy.scaleY);\n }\n const lm = ctx.Skia.Matrix();\n lm.concat(m3);\n processTransformProps(lm, imageShaderProps);\n let shader: SkShader;\n if (sampling && isCubicSampling(sampling)) {\n shader = ctx.track(\n image.makeShaderCubic(\n TileMode[enumKey(tx)],\n TileMode[enumKey(ty)],\n sampling.B,\n sampling.C,\n lm\n )\n );\n } else {\n shader = ctx.track(\n image.makeShaderCubic(\n TileMode[enumKey(tx)],\n TileMode[enumKey(ty)],\n sampling?.filter ?? FilterMode.Linear,\n sampling?.mipmap ?? MipmapMode.None,\n lm\n )\n );\n }\n ctx.shaders.push(shader);\n};\n\nconst declareBlend = (ctx: DrawingContext, props: BlendProps) => {\n \"worklet\";\n const blend = BlendMode[enumKey(props.mode as BlendProps[\"mode\"])];\n const shaders = ctx.shaders.splice(0, ctx.shaders.length);\n if (shaders.length > 0) {\n const composer = ctx.Skia.Shader.MakeBlend.bind(ctx.Skia.Shader, blend);\n ctx.shaders.push(composeDeclarations(shaders, composer));\n }\n};\n\nexport const isPushShader = (\n command: Command\n): command is Command<CommandType.PushShader> => {\n \"worklet\";\n return command.type === CommandType.PushShader;\n};\n\ntype Props = {\n [NodeType.Shader]: ShaderProps;\n [NodeType.ImageShader]: ImageShaderProps;\n [NodeType.ColorShader]: ColorProps;\n [NodeType.Turbulence]: TurbulenceProps;\n [NodeType.FractalNoise]: FractalNoiseProps;\n [NodeType.LinearGradient]: LinearGradientProps;\n [NodeType.RadialGradient]: RadialGradientProps;\n [NodeType.SweepGradient]: SweepGradientProps;\n [NodeType.TwoPointConicalGradient]: TwoPointConicalGradientProps;\n [NodeType.Blend]: BlendProps;\n};\n\ninterface PushShader<\n T extends keyof Props,\n> extends Command<CommandType.PushShader> {\n shaderType: T;\n props: Props[T];\n children: number;\n}\n\nconst isShader = <T extends keyof Props>(\n command: Command<CommandType.PushShader>,\n type: T\n): command is PushShader<T> => {\n \"worklet\";\n return command.shaderType === type;\n};\n\nexport const pushShader = (\n ctx: DrawingContext,\n command: Command<CommandType.PushShader>\n) => {\n \"worklet\";\n if (isShader(command, NodeType.Shader)) {\n declareShader(ctx, command.props, command.children);\n } else if (isShader(command, NodeType.ImageShader)) {\n declareImageShader(ctx, command.props);\n } else if (isShader(command, NodeType.ColorShader)) {\n declareColorShader(ctx, command.props);\n } else if (isShader(command, NodeType.Turbulence)) {\n declareTurbulenceShader(ctx, command.props);\n } else if (isShader(command, NodeType.FractalNoise)) {\n declareFractalNoiseShader(ctx, command.props);\n } else if (isShader(command, NodeType.LinearGradient)) {\n declareLinearGradientShader(ctx, command.props);\n } else if (isShader(command, NodeType.RadialGradient)) {\n declareRadialGradientShader(ctx, command.props);\n } else if (isShader(command, NodeType.SweepGradient)) {\n declareSweepGradientShader(ctx, command.props);\n } else if (isShader(command, NodeType.TwoPointConicalGradient)) {\n declareTwoPointConicalGradientShader(ctx, command.props);\n } else if (isShader(command, NodeType.Blend)) {\n declareBlend(ctx, command.props);\n } else {\n throw new Error(`Unknown shader type: ${command.shaderType}`);\n }\n};\n"],"mappings":"AAAA,SACEA,OAAO,EACPC,QAAQ,EACRC,OAAO,EACPC,YAAY,EACZC,oBAAoB,EACpBC,qBAAqB,EACrBC,SAAS,QACJ,oBAAoB;AAC3B,SAASC,QAAQ,QAAQ,oBAAoB;AAc7C,SACEC,SAAS,EACTC,UAAU,EACVC,eAAe,EACfC,UAAU,EACVC,eAAe,EACfC,QAAQ,QACH,qBAAqB;AAC5B,SAASC,mBAAmB,QAAQ,aAAa;AAEjD,SAASC,WAAW,QAAQ,SAAS;AAGrC,MAAMC,aAAa,GAAGA,CACpBC,GAAmB,EACnBC,KAAkB,EAClBC,QAAgB,KACb;EACH,SAAS;;EACT,MAAM;IAAEC,MAAM;IAAEC,QAAQ;IAAE,GAAGC;EAAU,CAAC,GAAGJ,KAAK;EAChD,MAAMK,EAAE,GAAGN,GAAG,CAACO,IAAI,CAACC,MAAM,CAAC,CAAC;EAC5BpB,qBAAqB,CAACkB,EAAE,EAAED,SAAS,CAAC;EACpC,MAAMI,MAAM,GAAGT,GAAG,CA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AAEnG,QAAQ,CAAC6G,cAAc,CAAC,EAAE;IACrDrD,2BAA2B,CAAC9C,GAAG,EAAEyF,OAAO,CAACxF,KAAK,CAAC;EACjD,CAAC,MAAM,IAAI2F,QAAQ,CAACH,OAAO,EAAEnG,QAAQ,CAAC8G,cAAc,CAAC,EAAE;IACrD9D,2BAA2B,CAACtC,GAAG,EAAEyF,OAAO,CAACxF,KAAK,CAAC;EACjD,CAAC,MAAM,IAAI2F,QAAQ,CAACH,OAAO,EAAEnG,QAAQ,CAAC+G,aAAa,CAAC,EAAE;IACpD3D,0BAA0B,CAAC1C,GAAG,EAAEyF,OAAO,CAACxF,KAAK,CAAC;EAChD,CAAC,MAAM,IAAI2F,QAAQ,CAACH,OAAO,EAAEnG,QAAQ,CAACgH,uBAAuB,CAAC,EAAE;IAC9D3E,oCAAoC,CAAC3B,GAAG,EAAEyF,OAAO,CAACxF,KAAK,CAAC;EAC1D,CAAC,MAAM,IAAI2F,QAAQ,CAACH,OAAO,EAAEnG,QAAQ,CAACiH,KAAK,CAAC,EAAE;IAC5CrB,YAAY,CAAClF,GAAG,EAAEyF,OAAO,CAACxF,KAAK,CAAC;EAClC,CAAC,MAAM;IACL,MAAM,IAAIuG,KAAK,CAAC,wBAAwBf,OAAO,CAACI,UAAU,EAAE,CAAC;EAC/D;AACF,CAAC","ignoreList":[]}
1
+ {"version":3,"names":["enumKey","fitRects","getRect","processColor","processGradientProps","processTransformProps","rect2rect","NodeType","BlendMode","FilterMode","isCubicSampling","MipmapMode","processUniforms","TileMode","composeDeclarations","CommandType","declareShader","ctx","props","children","source","uniforms","transform","m3","Skia","Matrix","shader","track","makeShaderWithChildren","shaders","splice","push","declareColorShader","color","Shader","MakeColor","declareFractalNoiseShader","freqX","freqY","octaves","seed","tileWidth","tileHeight","MakeFractalNoise","declareTwoPointConicalGradientShader","startR","endR","start","end","colors","positions","mode","localMatrix","flags","MakeTwoPointConicalGradient","declareRadialGradientShader","c","r","MakeRadialGradient","declareSweepGradientShader","MakeSweepGradient","x","y","declareLinearGradientShader","MakeLinearGradient","declareTurbulenceShader","MakeTurbulence","declareImageShader","fit","image","tx","ty","sampling","imageShaderProps","rct","rects","width","height","sx","sy","src","dst","translate","translateX","translateY","scale","scaleX","scaleY","lm","concat","makeShaderCubic","B","C","_sampling$filter","_sampling$mipmap","makeShaderOptions","filter","Linear","mipmap","None","declareBlend","blend","length","composer","MakeBlend","bind","isPushShader","command","type","PushShader","isShader","shaderType","pushShader","ImageShader","ColorShader","Turbulence","FractalNoise","LinearGradient","RadialGradient","SweepGradient","TwoPointConicalGradient","Blend","Error"],"sources":["Shaders.ts"],"sourcesContent":["import {\n enumKey,\n fitRects,\n getRect,\n processColor,\n processGradientProps,\n processTransformProps,\n rect2rect,\n} from \"../../../dom/nodes\";\nimport { NodeType } from \"../../../dom/types\";\nimport type {\n BlendProps,\n ColorProps,\n FractalNoiseProps,\n ImageShaderProps,\n LinearGradientProps,\n RadialGradientProps,\n ShaderProps,\n SweepGradientProps,\n TurbulenceProps,\n TwoPointConicalGradientProps,\n} from \"../../../dom/types\";\nimport type { SkShader } from \"../../../skia/types\";\nimport {\n BlendMode,\n FilterMode,\n isCubicSampling,\n MipmapMode,\n processUniforms,\n TileMode,\n} from \"../../../skia/types\";\nimport { composeDeclarations } from \"../../utils\";\nimport type { Command } from \"../Core\";\nimport { CommandType } from \"../Core\";\nimport type { DrawingContext } from \"../DrawingContext\";\n\nconst declareShader = (\n ctx: DrawingContext,\n props: ShaderProps,\n children: number\n) => {\n \"worklet\";\n const { source, uniforms, ...transform } = props;\n const m3 = ctx.Skia.Matrix();\n processTransformProps(m3, transform);\n const shader = ctx.track(\n source.makeShaderWithChildren(\n processUniforms(source, uniforms),\n ctx.shaders.splice(0, children),\n m3\n )\n );\n ctx.shaders.push(shader);\n};\n\nconst declareColorShader = (ctx: DrawingContext, props: ColorProps) => {\n \"worklet\";\n const { color } = props;\n const shader = ctx.Skia.Shader.MakeColor(processColor(ctx.Skia, color));\n ctx.shaders.push(shader);\n};\n\nconst declareFractalNoiseShader = (\n ctx: DrawingContext,\n props: FractalNoiseProps\n) => {\n \"worklet\";\n const { freqX, freqY, octaves, seed, tileWidth, tileHeight } = props;\n const shader = ctx.Skia.Shader.MakeFractalNoise(\n freqX,\n freqY,\n octaves,\n seed,\n tileWidth,\n tileHeight\n );\n ctx.shaders.push(shader);\n};\n\nconst declareTwoPointConicalGradientShader = (\n ctx: DrawingContext,\n props: TwoPointConicalGradientProps\n) => {\n \"worklet\";\n const { startR, endR, start, end } = props;\n const { colors, positions, mode, localMatrix, flags } = processGradientProps(\n ctx.Skia,\n props\n );\n const shader = ctx.Skia.Shader.MakeTwoPointConicalGradient(\n start,\n startR,\n end,\n endR,\n colors,\n positions,\n mode,\n localMatrix,\n flags\n );\n ctx.shaders.push(shader);\n};\n\nconst declareRadialGradientShader = (\n ctx: DrawingContext,\n props: RadialGradientProps\n) => {\n \"worklet\";\n const { c, r } = props;\n const { colors, positions, mode, localMatrix, flags } = processGradientProps(\n ctx.Skia,\n props\n );\n const shader = ctx.Skia.Shader.MakeRadialGradient(\n c,\n r,\n colors,\n positions,\n mode,\n localMatrix,\n flags\n );\n ctx.shaders.push(shader);\n};\n\nconst declareSweepGradientShader = (\n ctx: DrawingContext,\n props: SweepGradientProps\n) => {\n \"worklet\";\n const { c, start, end } = props;\n const { colors, positions, mode, localMatrix, flags } = processGradientProps(\n ctx.Skia,\n props\n );\n const shader = ctx.Skia.Shader.MakeSweepGradient(\n c.x,\n c.y,\n colors,\n positions,\n mode,\n localMatrix,\n flags,\n start,\n end\n );\n ctx.shaders.push(shader);\n};\n\nconst declareLinearGradientShader = (\n ctx: DrawingContext,\n props: LinearGradientProps\n) => {\n \"worklet\";\n const { start, end } = props;\n const { colors, positions, mode, localMatrix, flags } = processGradientProps(\n ctx.Skia,\n props\n );\n const shader = ctx.Skia.Shader.MakeLinearGradient(\n start,\n end,\n colors,\n positions ?? null,\n mode,\n localMatrix,\n flags\n );\n ctx.shaders.push(shader);\n};\n\nconst declareTurbulenceShader = (\n ctx: DrawingContext,\n props: TurbulenceProps\n) => {\n \"worklet\";\n const { freqX, freqY, octaves, seed, tileWidth, tileHeight } = props;\n const shader = ctx.Skia.Shader.MakeTurbulence(\n freqX,\n freqY,\n octaves,\n seed,\n tileWidth,\n tileHeight\n );\n ctx.shaders.push(shader);\n};\n\nconst declareImageShader = (ctx: DrawingContext, props: ImageShaderProps) => {\n \"worklet\";\n const { fit, image, tx, ty, sampling, ...imageShaderProps } = props;\n if (!image) {\n return;\n }\n\n const rct = getRect(ctx.Skia, imageShaderProps);\n const m3 = ctx.Skia.Matrix();\n if (rct) {\n const rects = fitRects(\n fit,\n { x: 0, y: 0, width: image.width(), height: image.height() },\n rct\n );\n const [x, y, sx, sy] = rect2rect(rects.src, rects.dst);\n m3.translate(x.translateX, y.translateY);\n m3.scale(sx.scaleX, sy.scaleY);\n }\n const lm = ctx.Skia.Matrix();\n lm.concat(m3);\n processTransformProps(lm, imageShaderProps);\n let shader: SkShader;\n if (sampling && isCubicSampling(sampling)) {\n shader = ctx.track(\n image.makeShaderCubic(\n TileMode[enumKey(tx)],\n TileMode[enumKey(ty)],\n sampling.B,\n sampling.C,\n lm\n )\n );\n } else {\n shader = ctx.track(\n image.makeShaderOptions(\n TileMode[enumKey(tx)],\n TileMode[enumKey(ty)],\n sampling?.filter ?? FilterMode.Linear,\n sampling?.mipmap ?? MipmapMode.None,\n lm\n )\n );\n }\n ctx.shaders.push(shader);\n};\n\nconst declareBlend = (ctx: DrawingContext, props: BlendProps) => {\n \"worklet\";\n const blend = BlendMode[enumKey(props.mode as BlendProps[\"mode\"])];\n const shaders = ctx.shaders.splice(0, ctx.shaders.length);\n if (shaders.length > 0) {\n const composer = ctx.Skia.Shader.MakeBlend.bind(ctx.Skia.Shader, blend);\n ctx.shaders.push(composeDeclarations(shaders, composer));\n }\n};\n\nexport const isPushShader = (\n command: Command\n): command is Command<CommandType.PushShader> => {\n \"worklet\";\n return command.type === CommandType.PushShader;\n};\n\ntype Props = {\n [NodeType.Shader]: ShaderProps;\n [NodeType.ImageShader]: ImageShaderProps;\n [NodeType.ColorShader]: ColorProps;\n [NodeType.Turbulence]: TurbulenceProps;\n [NodeType.FractalNoise]: FractalNoiseProps;\n [NodeType.LinearGradient]: LinearGradientProps;\n [NodeType.RadialGradient]: RadialGradientProps;\n [NodeType.SweepGradient]: SweepGradientProps;\n [NodeType.TwoPointConicalGradient]: TwoPointConicalGradientProps;\n [NodeType.Blend]: BlendProps;\n};\n\ninterface PushShader<\n T extends keyof Props,\n> extends Command<CommandType.PushShader> {\n shaderType: T;\n props: Props[T];\n children: number;\n}\n\nconst isShader = <T extends keyof Props>(\n command: Command<CommandType.PushShader>,\n type: T\n): command is PushShader<T> => {\n \"worklet\";\n return command.shaderType === type;\n};\n\nexport const pushShader = (\n ctx: DrawingContext,\n command: Command<CommandType.PushShader>\n) => {\n \"worklet\";\n if (isShader(command, NodeType.Shader)) {\n declareShader(ctx, command.props, command.children);\n } else if (isShader(command, NodeType.ImageShader)) {\n declareImageShader(ctx, command.props);\n } else if (isShader(command, NodeType.ColorShader)) {\n declareColorShader(ctx, command.props);\n } else if (isShader(command, NodeType.Turbulence)) {\n declareTurbulenceShader(ctx, command.props);\n } else if (isShader(command, NodeType.FractalNoise)) {\n declareFractalNoiseShader(ctx, command.props);\n } else if (isShader(command, NodeType.LinearGradient)) {\n declareLinearGradientShader(ctx, command.props);\n } else if (isShader(command, NodeType.RadialGradient)) {\n declareRadialGradientShader(ctx, command.props);\n } else if (isShader(command, NodeType.SweepGradient)) {\n declareSweepGradientShader(ctx, command.props);\n } else if (isShader(command, NodeType.TwoPointConicalGradient)) {\n declareTwoPointConicalGradientShader(ctx, command.props);\n } else if (isShader(command, NodeType.Blend)) {\n declareBlend(ctx, command.props);\n } else {\n throw new Error(`Unknown shader type: ${command.shaderType}`);\n }\n};\n"],"mappings":"AAAA,SACEA,OAAO,EACPC,QAAQ,EACRC,OAAO,EACPC,YAAY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E;IAC5CrB,YAAY,CAACnF,GAAG,EAAE0F,OAAO,CAACzF,KAAK,CAAC;EAClC,CAAC,MAAM;IACL,MAAM,IAAIwG,KAAK,CAAC,wBAAwBf,OAAO,CAACI,UAAU,EAAE,CAAC;EAC/D;AACF,CAAC","ignoreList":[]}
@@ -17,31 +17,189 @@ const dp2Pixel = (pd, rect) => {
17
17
  height: rect.height * pd
18
18
  };
19
19
  };
20
+
21
+ // A <canvas> element owns at most one WebGL context for its whole lifetime.
22
+ // A renderer, on the other hand, lives as long as the layout effect that
23
+ // creates it, which is shorter: React re-runs layout effects on a *preserved*
24
+ // host node under StrictMode's DEV double-invoke and when an Activity/offscreen
25
+ // subtree is hidden and revealed (#3976). What belongs to the element rather
26
+ // than to a renderer is tracked here, per element:
27
+ // - the context, so that a new renderer can tell whether the element already
28
+ // has one (and whether it is lost) without calling getContext() itself,
29
+ // which on a fresh element would create a context with the wrong attributes
30
+ // (CanvasKit.GetWebGLContext requests its own);
31
+ // - the WEBGL_lose_context extension, captured while the context is healthy:
32
+ // getExtension() returns null on a lost context, and this object is the only
33
+ // way to lose a context on purpose or to ask the browser to restore one;
34
+ // - whether the browser has announced the loss of the context yet: a lost
35
+ // context can only be restored once its webglcontextlost event has been
36
+ // dispatched, and that event is asynchronous;
37
+ // - the renderer currently attached to the element, if any.
38
+
39
+ const canvasWebGL = new WeakMap();
40
+
41
+ // Unregisters a context from CanvasKit's registry, which otherwise retains the
42
+ // canvas element (and its detached DOM tree) forever (#3924).
43
+ const deleteContextHandle = handle => {
44
+ CanvasKit.deleteContext(handle);
45
+ // Making the now-deleted handle current clears CanvasKit's current-context
46
+ // globals (GLctx/Module.ctx), which would otherwise keep referencing the
47
+ // context (and the canvas) until another surface becomes current. With a
48
+ // deleted handle this is a no-op that returns null without creating
49
+ // anything.
50
+ CanvasKit.MakeWebGLContext(handle);
51
+ };
20
52
  class WebGLRenderer {
21
- constructor(canvas) {
53
+ constructor(canvas,
54
+ // Called when the renderer becomes able to paint again and the current
55
+ // picture should be drawn.
56
+ requestRedraw) {
22
57
  this.canvas = canvas;
58
+ this.requestRedraw = requestRedraw;
23
59
  _defineProperty(this, "surface", null);
24
60
  _defineProperty(this, "grContext", null);
25
61
  _defineProperty(this, "contextHandle", 0);
26
62
  _defineProperty(this, "pd", 1);
27
- this.contextHandle = CanvasKit.GetWebGLContext(canvas);
28
- if (!this.contextHandle) {
63
+ // Set while the renderer is waiting for a lost context to be restored.
64
+ _defineProperty(this, "restoreWanted", false);
65
+ _defineProperty(this, "restoreRequest", null);
66
+ _defineProperty(this, "onContextLost", () => {
67
+ // The browser already dropped every GL object; drop our references to
68
+ // them. Restoration is left to the browser (it restores an evicted
69
+ // context as soon as a slot frees up), except when this renderer was
70
+ // built on an already-lost context and is waiting to paint for the first
71
+ // time: chasing an eviction from here would evict the next-oldest context
72
+ // in turn, and with more live canvases than the browser allows the
73
+ // canvases would endlessly evict each other.
74
+ this.release();
75
+ if (this.restoreWanted) {
76
+ // The permission granted by preventDefault() is only recorded by the
77
+ // browser once the event dispatch is over: a restoreContext() call
78
+ // from inside the handler is refused, so ask from a later task.
79
+ this.restoreRequest = setTimeout(() => {
80
+ var _canvasWebGL$get;
81
+ this.restoreRequest = null;
82
+ (_canvasWebGL$get = canvasWebGL.get(this.canvas)) === null || _canvasWebGL$get === void 0 || (_canvasWebGL$get = _canvasWebGL$get.loseContext) === null || _canvasWebGL$get === void 0 || _canvasWebGL$get.restoreContext();
83
+ }, 0);
84
+ }
85
+ });
86
+ _defineProperty(this, "onContextRestored", () => {
87
+ this.acquire();
88
+ this.requestRedraw();
89
+ });
90
+ const entry = canvasWebGL.get(canvas);
91
+ if (entry) {
92
+ entry.owner = this;
93
+ }
94
+ canvas.addEventListener("webglcontextlost", this.onContextLost);
95
+ canvas.addEventListener("webglcontextrestored", this.onContextRestored);
96
+ this.acquire();
97
+ }
98
+
99
+ // Builds the GrDirectContext and the surface on the element's WebGL
100
+ // context, creating the context first if the element has none.
101
+ acquire() {
102
+ const {
103
+ canvas
104
+ } = this;
105
+ const known = canvasWebGL.get(canvas);
106
+ if (known !== null && known !== void 0 && known.gl.isContextLost()) {
107
+ // Nothing can be built on a lost context: CanvasKit.GetWebGLContext
108
+ // happily registers it, and MakeWebGLContext then faults inside wasm
109
+ // (#3976). Ask the browser for it back and finish in onContextRestored;
110
+ // if the loss hasn't been announced yet, onContextLost asks.
111
+ this.restoreWanted = true;
112
+ if (known.lossAnnounced) {
113
+ var _known$loseContext;
114
+ (_known$loseContext = known.loseContext) === null || _known$loseContext === void 0 || _known$loseContext.restoreContext();
115
+ }
116
+ return;
117
+ }
118
+ const handle = CanvasKit.GetWebGLContext(canvas);
119
+ if (!handle) {
29
120
  throw new Error("Could not create a WebGL context");
30
121
  }
31
- this.grContext = CanvasKit.MakeWebGLContext(this.contextHandle);
32
- if (!this.grContext) {
33
- CanvasKit.deleteContext(this.contextHandle);
34
- this.contextHandle = 0;
122
+ const entry = known !== null && known !== void 0 ? known : this.trackContext();
123
+ let grContext = null;
124
+ try {
125
+ grContext = CanvasKit.MakeWebGLContext(handle);
126
+ } finally {
127
+ if (!grContext) {
128
+ // Whether it returned null or threw, don't leave the registry
129
+ // holding on to the canvas.
130
+ deleteContextHandle(handle);
131
+ }
132
+ }
133
+ if (!grContext) {
35
134
  throw new Error("Could not create a graphics context");
36
135
  }
37
- const ctx = canvas.getContext("webgl2");
38
- if (ctx) {
39
- ctx.drawingBufferColorSpace = "display-p3";
136
+ this.restoreWanted = false;
137
+ this.contextHandle = handle;
138
+ this.grContext = grContext;
139
+ if (entry) {
140
+ entry.gl.drawingBufferColorSpace = "display-p3";
40
141
  }
41
142
  this.onResize();
42
143
  }
144
+
145
+ // CanvasKit just created the element's context; asking for it again hands
146
+ // back the same object (the attributes are only honored the first time).
147
+ trackContext() {
148
+ var _canvas$getContext;
149
+ const {
150
+ canvas
151
+ } = this;
152
+ const gl = (_canvas$getContext = canvas.getContext("webgl2")) !== null && _canvas$getContext !== void 0 ? _canvas$getContext : canvas.getContext("webgl");
153
+ if (!gl) {
154
+ return null;
155
+ }
156
+ const entry = {
157
+ gl,
158
+ loseContext: gl.getExtension("WEBGL_lose_context"),
159
+ lossAnnounced: false,
160
+ owner: this
161
+ };
162
+ canvasWebGL.set(canvas, entry);
163
+ // Browsers restore a lost context (evicted as the oldest one when the
164
+ // page exceeds the active-context limit, or lost to a GPU reset) only if
165
+ // the page called preventDefault() on the webglcontextlost event. A
166
+ // renderer isn't necessarily attached when that happens (the canvas may
167
+ // be in a hidden Activity), so these listeners live as long as the
168
+ // element does. They are registered ahead of any renderer's, and the
169
+ // loss can't be announced before they exist since the event is
170
+ // asynchronous.
171
+ canvas.addEventListener("webglcontextlost", event => {
172
+ event.preventDefault();
173
+ entry.lossAnnounced = true;
174
+ });
175
+ canvas.addEventListener("webglcontextrestored", () => {
176
+ entry.lossAnnounced = false;
177
+ });
178
+ return entry;
179
+ }
180
+
181
+ // Frees everything built on the context. The context itself belongs to the
182
+ // element, see dispose().
183
+ release() {
184
+ var _this$surface;
185
+ (_this$surface = this.surface) === null || _this$surface === void 0 || _this$surface.ref.delete();
186
+ this.surface = null;
187
+ if (this.grContext) {
188
+ this.grContext.releaseResourcesAndAbandonContext();
189
+ this.grContext.delete();
190
+ this.grContext = null;
191
+ }
192
+ if (this.contextHandle) {
193
+ deleteContextHandle(this.contextHandle);
194
+ this.contextHandle = 0;
195
+ }
196
+ }
197
+ isContextLost() {
198
+ var _canvasWebGL$get$gl$i, _canvasWebGL$get2;
199
+ return (_canvasWebGL$get$gl$i = (_canvasWebGL$get2 = canvasWebGL.get(this.canvas)) === null || _canvasWebGL$get2 === void 0 ? void 0 : _canvasWebGL$get2.gl.isContextLost()) !== null && _canvasWebGL$get$gl$i !== void 0 ? _canvasWebGL$get$gl$i : false;
200
+ }
43
201
  makeImageSnapshot(picture, rect) {
44
- if (!this.surface) {
202
+ if (!this.surface || this.isContextLost()) {
45
203
  return null;
46
204
  }
47
205
  const canvas = this.surface.getCanvas();
@@ -51,17 +209,20 @@ class WebGLRenderer {
51
209
  return this.surface.makeImageSnapshot(dp2Pixel(this.pd, rect));
52
210
  }
53
211
  onResize() {
54
- var _this$surface;
212
+ var _this$surface2;
55
213
  const {
56
214
  canvas
57
215
  } = this;
58
- if (!this.grContext) {
216
+ if (!this.grContext || this.isContextLost()) {
217
+ // Waiting for the context to be restored (the restore path resizes),
218
+ // or the loss hasn't been announced yet and onContextLost is about to
219
+ // release everything: either way there is nothing to build on.
59
220
  return;
60
221
  }
61
222
  this.pd = window.devicePixelRatio;
62
223
  canvas.width = canvas.clientWidth * this.pd;
63
224
  canvas.height = canvas.clientHeight * this.pd;
64
- (_this$surface = this.surface) === null || _this$surface === void 0 || _this$surface.ref.delete();
225
+ (_this$surface2 = this.surface) === null || _this$surface2 === void 0 || _this$surface2.ref.delete();
65
226
  this.surface = null;
66
227
  if (canvas.width === 0 || canvas.height === 0) {
67
228
  // The canvas hasn't been laid out yet (or is hidden). The view's
@@ -77,38 +238,55 @@ class WebGLRenderer {
77
238
  this.surface = new JsiSkSurface(CanvasKit, surface);
78
239
  }
79
240
  draw(picture) {
80
- if (this.surface) {
81
- const canvas = this.surface.getCanvas();
82
- canvas.clear(Float32Array.of(0, 0, 0, 0));
83
- canvas.save();
84
- canvas.scale(this.pd, this.pd);
85
- canvas.drawPicture(picture);
86
- canvas.restore();
87
- this.surface.ref.flush();
241
+ if (!this.surface || this.isContextLost()) {
242
+ return;
88
243
  }
244
+ const canvas = this.surface.getCanvas();
245
+ canvas.clear(Float32Array.of(0, 0, 0, 0));
246
+ canvas.save();
247
+ canvas.scale(this.pd, this.pd);
248
+ canvas.drawPicture(picture);
249
+ canvas.restore();
250
+ this.surface.ref.flush();
89
251
  }
90
252
  dispose() {
91
- var _this$surface2, _this$canvas;
92
- (_this$surface2 = this.surface) === null || _this$surface2 === void 0 || _this$surface2.ref.delete();
93
- this.surface = null;
94
- if (this.grContext) {
95
- this.grContext.releaseResourcesAndAbandonContext();
96
- this.grContext.delete();
97
- this.grContext = null;
253
+ const {
254
+ canvas
255
+ } = this;
256
+ canvas.removeEventListener("webglcontextlost", this.onContextLost);
257
+ canvas.removeEventListener("webglcontextrestored", this.onContextRestored);
258
+ if (this.restoreRequest !== null) {
259
+ clearTimeout(this.restoreRequest);
260
+ this.restoreRequest = null;
98
261
  }
99
- (_this$canvas = this.canvas) === null || _this$canvas === void 0 || (_this$canvas = _this$canvas.getContext("webgl2")) === null || _this$canvas === void 0 || (_this$canvas = _this$canvas.getExtension("WEBGL_lose_context")) === null || _this$canvas === void 0 || _this$canvas.loseContext();
100
- if (this.contextHandle) {
101
- // Unregister the context from CanvasKit's internal registry, otherwise
102
- // it retains the canvas element (and its detached DOM tree) forever.
103
- CanvasKit.deleteContext(this.contextHandle);
104
- // Making the now-deleted handle current clears CanvasKit's
105
- // current-context globals (GLctx/Module.ctx), which would otherwise
106
- // keep referencing the context (and the canvas) until another surface
107
- // becomes current. With a deleted handle this is a no-op that returns
108
- // null without creating anything.
109
- CanvasKit.MakeWebGLContext(this.contextHandle);
110
- this.contextHandle = 0;
262
+ this.restoreWanted = false;
263
+ this.release();
264
+ // Free the drawing buffer, which CanvasKit requests with depth and stencil
265
+ // attachments (about 8 bytes per pixel): a canvas that stays in the
266
+ // document without a renderer, hidden in an Activity say, would otherwise
267
+ // keep a full-size buffer around. The next renderer's onResize() sizes it
268
+ // again.
269
+ canvas.width = 0;
270
+ canvas.height = 0;
271
+ const entry = canvasWebGL.get(canvas);
272
+ if (!entry) {
273
+ return;
111
274
  }
275
+ entry.owner = null;
276
+ // Whether the element is going away is only known once the commit is
277
+ // over: on a real unmount React runs this cleanup *before* removing the
278
+ // node from the document, while StrictMode's double-invoke and an
279
+ // Activity hide keep the node in place (and the former builds the next
280
+ // renderer on it right away). Losing the context of a detached element
281
+ // matters: it would otherwise stay alive until the element is garbage
282
+ // collected, and browsers cap the number of live contexts per page
283
+ // (16 in Chrome, which then evicts the oldest one, visible or not).
284
+ queueMicrotask(() => {
285
+ if (entry.owner === null && !canvas.isConnected && !entry.gl.isContextLost()) {
286
+ var _entry$loseContext;
287
+ (_entry$loseContext = entry.loseContext) === null || _entry$loseContext === void 0 || _entry$loseContext.loseContext();
288
+ }
289
+ });
112
290
  }
113
291
  }
114
292
  class StaticWebGLRenderer {
@@ -283,21 +461,29 @@ export const SkiaPictureView = props => {
283
461
  // - The renderer is created synchronously on mount (the canvas element is
284
462
  // guaranteed to exist in useLayoutEffect; a zero size at that point is
285
463
  // fine, the surface is created once the canvas is measurable).
286
- // - Redraw requests coalesce into a single animation frame. A picture
287
- // dispatched before the canvas has a size stays in pictureRef (drawing
288
- // while unmeasured is a no-op) and is painted by the resize path below
289
- // once the canvas becomes measurable, so it is never lost.
464
+ // - Redraw requests coalesce into a single microtask. A microtask (not an
465
+ // animation frame) so that a picture produced inside a rAF callback (the
466
+ // Reanimated mapper) is drawn before the current frame paints: deferring
467
+ // to the next rAF alternates between "flush pending in this frame" and
468
+ // "flush scheduled for the next frame", drawing on every other frame
469
+ // only and halving the effective frame rate. A picture dispatched before
470
+ // the canvas has a size stays in pictureRef (drawing while unmeasured is
471
+ // a no-op) and is painted by the resize path below once the canvas
472
+ // becomes measurable, so it is never lost.
290
473
  // - A ResizeObserver on the canvas itself recreates the surface and repaints
291
474
  // synchronously (its callbacks run after layout, before paint), and is
292
475
  // also the source of the user-facing onLayout event.
476
+ // - The renderer belongs to the layout effect, the WebGL context to the
477
+ // <canvas> element, whose lifetime is longer; see WebGLRenderer for how
478
+ // the two are reconciled.
293
479
  const redrawPendingRef = useRef(false);
294
- const frameRef = useRef(0);
480
+ const flushScheduledRef = useRef(false);
295
481
  const onLayoutRef = useRef(onLayout);
296
482
  useLayoutEffect(() => {
297
483
  onLayoutRef.current = onLayout;
298
484
  }, [onLayout]);
299
485
  const flushRedraw = useCallback(() => {
300
- frameRef.current = 0;
486
+ flushScheduledRef.current = false;
301
487
  if (redrawPendingRef.current && rendererRef.current && pictureRef.current) {
302
488
  redrawPendingRef.current = false;
303
489
  rendererRef.current.draw(pictureRef.current);
@@ -307,8 +493,9 @@ export const SkiaPictureView = props => {
307
493
  }, []);
308
494
  const redraw = useCallback(() => {
309
495
  redrawPendingRef.current = true;
310
- if (frameRef.current === 0) {
311
- frameRef.current = requestAnimationFrame(flushRedraw);
496
+ if (!flushScheduledRef.current) {
497
+ flushScheduledRef.current = true;
498
+ queueMicrotask(flushRedraw);
312
499
  }
313
500
  }, [flushRedraw]);
314
501
  const getSize = useCallback(() => {
@@ -363,7 +550,7 @@ export const SkiaPictureView = props => {
363
550
  if (!canvas) {
364
551
  return undefined;
365
552
  }
366
- const renderer = isStatic ? new StaticWebGLRenderer(canvas) : new WebGLRenderer(canvas);
553
+ const renderer = isStatic ? new StaticWebGLRenderer(canvas) : new WebGLRenderer(canvas, redraw);
367
554
  rendererRef.current = renderer;
368
555
  const drawPicture = () => {
369
556
  if (pictureRef.current) {
@@ -442,13 +629,12 @@ export const SkiaPictureView = props => {
442
629
  rendererRef.current = null;
443
630
  renderer.dispose();
444
631
  };
445
- }, [isStatic]);
446
- useEffect(() => {
447
- return () => {
448
- cancelAnimationFrame(frameRef.current);
449
- frameRef.current = 0;
450
- };
451
- }, []);
632
+ }, [isStatic, redraw]);
633
+
634
+ // No flush cancellation is needed on unmount: a microtask queued before
635
+ // unmount runs within the same task, and flushRedraw no-ops once the
636
+ // layout-effect cleanup has nulled rendererRef.
637
+
452
638
  useImperativeHandle(ref, () => ({
453
639
  setPicture,
454
640
  getSize,
@@ -490,6 +676,10 @@ export const SkiaPictureView = props => {
490
676
  ...viewProps
491
677
  } = props;
492
678
  return /*#__PURE__*/React.createElement(Platform.View, viewProps, /*#__PURE__*/React.createElement("canvas", {
679
+ // A canvas element is bound to one context kind for life (WebGL for
680
+ // the live renderer, 2D for the static one), so switching renderers
681
+ // needs a fresh element.
682
+ key: isStatic ? "static" : "webgl",
493
683
  ref: canvasRef,
494
684
  style: {
495
685
  display: "block",