@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
@@ -165,7 +165,7 @@ const declareImageShader = (ctx, props) => {
165
165
  shader = ctx.track(image.makeShaderCubic(_types2.TileMode[(0, _nodes.enumKey)(tx)], _types2.TileMode[(0, _nodes.enumKey)(ty)], sampling.B, sampling.C, lm));
166
166
  } else {
167
167
  var _sampling$filter, _sampling$mipmap;
168
- shader = ctx.track(image.makeShaderCubic(_types2.TileMode[(0, _nodes.enumKey)(tx)], _types2.TileMode[(0, _nodes.enumKey)(ty)], (_sampling$filter = sampling === null || sampling === void 0 ? void 0 : sampling.filter) !== null && _sampling$filter !== void 0 ? _sampling$filter : _types2.FilterMode.Linear, (_sampling$mipmap = sampling === null || sampling === void 0 ? void 0 : sampling.mipmap) !== null && _sampling$mipmap !== void 0 ? _sampling$mipmap : _types2.MipmapMode.None, lm));
168
+ shader = ctx.track(image.makeShaderOptions(_types2.TileMode[(0, _nodes.enumKey)(tx)], _types2.TileMode[(0, _nodes.enumKey)(ty)], (_sampling$filter = sampling === null || sampling === void 0 ? void 0 : sampling.filter) !== null && _sampling$filter !== void 0 ? _sampling$filter : _types2.FilterMode.Linear, (_sampling$mipmap = sampling === null || sampling === void 0 ? void 0 : sampling.mipmap) !== null && _sampling$mipmap !== void 0 ? _sampling$mipmap : _types2.MipmapMode.None, lm));
169
169
  }
170
170
  ctx.shaders.push(shader);
171
171
  };
@@ -1 +1 @@
1
- {"version":3,"names":["_nodes","require","_types","_types2","_utils","_Core","declareShader","ctx","props","children","source","uniforms","transform","m3","Skia","Matrix","processTransformProps","shader","track","makeShaderWithChildren","processUniforms","shaders","splice","push","declareColorShader","color","Shader","MakeColor","processColor","declareFractalNoiseShader","freqX","freqY","octaves","seed","tileWidth","tileHeight","MakeFractalNoise","declareTwoPointConicalGradientShader","startR","endR","start","end","colors","positions","mode","localMatrix","flags","processGradientProps","MakeTwoPointConicalGradient","declareRadialGradientShader","c","r","MakeRadialGradient","declareSweepGradientShader","MakeSweepGradient","x","y","declareLinearGradientShader","MakeLinearGradient","declareTurbulenceShader","MakeTurbulence","declareImageShader","fit","image","tx","ty","sampling","imageShaderProps","rct","getRect","rects","fitRects","width","height","sx","sy","rect2rect","src","dst","translate","translateX","translateY","scale","scaleX","scaleY","lm","concat","isCubicSampling","makeShaderCubic","TileMode","enumKey","B","C","_sampling$filter","_sampling$mipmap","filter","FilterMode","Linear","mipmap","MipmapMode","None","declareBlend","blend","BlendMode","length","composer","MakeBlend","bind","composeDeclarations","isPushShader","command","type","CommandType","PushShader","exports","isShader","shaderType","pushShader","NodeType","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,IAAAA,MAAA,GAAAC,OAAA;AASA,IAAAC,MAAA,GAAAD,OAAA;AAcA,IAAAE,OAAA,GAAAF,OAAA;AAQA,IAAAG,MAAA,GAAAH,OAAA;AAEA,IAAAI,KAAA,GAAAJ,OAAA;AAGA,MAAMK,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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AEuG,OAAO,CAACtG,KAAK,CAAC;EAC7C,CAAC,MAAM,IAAI2G,QAAQ,CAACL,OAAO,EAAEQ,eAAQ,CAACI,YAAY,CAAC,EAAE;IACnD7F,yBAAyB,CAACtB,GAAG,EAAEuG,OAAO,CAACtG,KAAK,CAAC;EAC/C,CAAC,MAAM,IAAI2G,QAAQ,CAACL,OAAO,EAAEQ,eAAQ,CAACK,cAAc,CAAC,EAAE;IACrDlE,2BAA2B,CAAClD,GAAG,EAAEuG,OAAO,CAACtG,KAAK,CAAC;EACjD,CAAC,MAAM,IAAI2G,QAAQ,CAACL,OAAO,EAAEQ,eAAQ,CAACM,cAAc,CAAC,EAAE;IACrD3E,2BAA2B,CAAC1C,GAAG,EAAEuG,OAAO,CAACtG,KAAK,CAAC;EACjD,CAAC,MAAM,IAAI2G,QAAQ,CAACL,OAAO,EAAEQ,eAAQ,CAACO,aAAa,CAAC,EAAE;IACpDxE,0BAA0B,CAAC9C,GAAG,EAAEuG,OAAO,CAACtG,KAAK,CAAC;EAChD,CAAC,MAAM,IAAI2G,QAAQ,CAACL,OAAO,EAAEQ,eAAQ,CAACQ,uBAAuB,CAAC,EAAE;IAC9DzF,oCAAoC,CAAC9B,GAAG,EAAEuG,OAAO,CAACtG,KAAK,CAAC;EAC1D,CAAC,MAAM,IAAI2G,QAAQ,CAACL,OAAO,EAAEQ,eAAQ,CAACS,KAAK,CAAC,EAAE;IAC5C1B,YAAY,CAAC9F,GAAG,EAAEuG,OAAO,CAACtG,KAAK,CAAC;EAClC,CAAC,MAAM;IACL,MAAM,IAAIwH,KAAK,CAAC,wBAAwBlB,OAAO,CAACM,UAAU,EAAE,CAAC;EAC/D;AACF,CAAC;AAACF,OAAA,CAAAG,UAAA,GAAAA,UAAA","ignoreList":[]}
1
+ {"version":3,"names":["_nodes","require","_types","_types2","_utils","_Core","declareShader","ctx","props","children","source","uniforms","transform","m3","Skia","Matrix","processTransformProps","shader","track","makeShaderWithChildren","processUniforms","shaders","splice","push","declareColorShader","color","Shader","MakeColor","processColor","declareFractalNoiseShader","freqX","freqY","octaves","seed","tileWidth","tileHeight","MakeFractalNoise","declareTwoPointConicalGradientShader","startR","endR","start","end","colors","positions","mode","localMatrix","flags","processGradientProps","MakeTwoPointConicalGradient","declareRadialGradientShader","c","r","MakeRadialGradient","declareSweepGradientShader","MakeSweepGradient","x","y","declareLinearGradientShader","MakeLinearGradient","declareTurbulenceShader","MakeTurbulence","declareImageShader","fit","image","tx","ty","sampling","imageShaderProps","rct","getRect","rects","fitRects","width","height","sx","sy","rect2rect","src","dst","translate","translateX","translateY","scale","scaleX","scaleY","lm","concat","isCubicSampling","makeShaderCubic","TileMode","enumKey","B","C","_sampling$filter","_sampling$mipmap","makeShaderOptions","filter","FilterMode","Linear","mipmap","MipmapMode","None","declareBlend","blend","BlendMode","length","composer","MakeBlend","bind","composeDeclarations","isPushShader","command","type","CommandType","PushShader","exports","isShader","shaderType","pushShader","NodeType","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,IAAAA,MAAA,GAAAC,OAAA;AASA,IAAAC,MAAA,GAAAD,OAAA;AAcA,IAAAE,OAAA,GAAAF,OAAA;AAQA,IAAAG,MAAA,GAAAH,OAAA;AAEA,IAAAI,KAAA,GAAAJ,OAAA;AAGA,MAAMK,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;EAC5B,IAAAC,4BAAqB,EAACH,EAAE,EAAED,SAAS,CAAC;EACpC,MAAMK,MAAM,GAAGV,GAAG,CAACW,KAAK,CACtBR,MAAM,CAACS,sBAAsB,CAC3B,IAAAC,uBAAe,EAACV,MAAM,EAAEC,QAAQ,CAAC,EACjCJ,GAAG,CAACc,OAAO,CAACC,MAAM,CAAC,CAAC,EAAEb,QAAQ,CAAC,EAC/BI,EACF,CACF,CAAC;EACDN,GAAG,CAACc,OAAO,CAACE,IAAI,CAACN,MAAM,CAAC;AAC1B,CAAC;AAED,MAAMO,kBAAkB,GAAGA,CAACjB,GAAmB,EAAEC,KAAiB,KAAK;EACrE,SAAS;;EACT,MAAM;IAAEiB;EAAM,CAAC,GAAGjB,KAAK;EACvB,MAAMS,MAAM,GAAGV,GAAG,CAACO,IAAI,CAACY,MAAM,CAACC,SAAS,CAAC,IAAAC,mBAAY,EAACrB,GAAG,CAACO,IAAI,EAAEW,KAAK,C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AACvG,KAAK,CAAC;EAChD,CAAC,MAAM,IAAI4G,QAAQ,CAACL,OAAO,EAAEQ,eAAQ,CAACQ,uBAAuB,CAAC,EAAE;IAC9D1F,oCAAoC,CAAC9B,GAAG,EAAEwG,OAAO,CAACvG,KAAK,CAAC;EAC1D,CAAC,MAAM,IAAI4G,QAAQ,CAACL,OAAO,EAAEQ,eAAQ,CAACS,KAAK,CAAC,EAAE;IAC5C1B,YAAY,CAAC/F,GAAG,EAAEwG,OAAO,CAACvG,KAAK,CAAC;EAClC,CAAC,MAAM;IACL,MAAM,IAAIyH,KAAK,CAAC,wBAAwBlB,OAAO,CAACM,UAAU,EAAE,CAAC;EAC/D;AACF,CAAC;AAACF,OAAA,CAAAG,UAAA,GAAAA,UAAA","ignoreList":[]}
@@ -23,31 +23,189 @@ const dp2Pixel = (pd, rect) => {
23
23
  height: rect.height * pd
24
24
  };
25
25
  };
26
+
27
+ // A <canvas> element owns at most one WebGL context for its whole lifetime.
28
+ // A renderer, on the other hand, lives as long as the layout effect that
29
+ // creates it, which is shorter: React re-runs layout effects on a *preserved*
30
+ // host node under StrictMode's DEV double-invoke and when an Activity/offscreen
31
+ // subtree is hidden and revealed (#3976). What belongs to the element rather
32
+ // than to a renderer is tracked here, per element:
33
+ // - the context, so that a new renderer can tell whether the element already
34
+ // has one (and whether it is lost) without calling getContext() itself,
35
+ // which on a fresh element would create a context with the wrong attributes
36
+ // (CanvasKit.GetWebGLContext requests its own);
37
+ // - the WEBGL_lose_context extension, captured while the context is healthy:
38
+ // getExtension() returns null on a lost context, and this object is the only
39
+ // way to lose a context on purpose or to ask the browser to restore one;
40
+ // - whether the browser has announced the loss of the context yet: a lost
41
+ // context can only be restored once its webglcontextlost event has been
42
+ // dispatched, and that event is asynchronous;
43
+ // - the renderer currently attached to the element, if any.
44
+
45
+ const canvasWebGL = new WeakMap();
46
+
47
+ // Unregisters a context from CanvasKit's registry, which otherwise retains the
48
+ // canvas element (and its detached DOM tree) forever (#3924).
49
+ const deleteContextHandle = handle => {
50
+ CanvasKit.deleteContext(handle);
51
+ // Making the now-deleted handle current clears CanvasKit's current-context
52
+ // globals (GLctx/Module.ctx), which would otherwise keep referencing the
53
+ // context (and the canvas) until another surface becomes current. With a
54
+ // deleted handle this is a no-op that returns null without creating
55
+ // anything.
56
+ CanvasKit.MakeWebGLContext(handle);
57
+ };
26
58
  class WebGLRenderer {
27
- constructor(canvas) {
59
+ constructor(canvas,
60
+ // Called when the renderer becomes able to paint again and the current
61
+ // picture should be drawn.
62
+ requestRedraw) {
28
63
  this.canvas = canvas;
64
+ this.requestRedraw = requestRedraw;
29
65
  _defineProperty(this, "surface", null);
30
66
  _defineProperty(this, "grContext", null);
31
67
  _defineProperty(this, "contextHandle", 0);
32
68
  _defineProperty(this, "pd", 1);
33
- this.contextHandle = CanvasKit.GetWebGLContext(canvas);
34
- if (!this.contextHandle) {
69
+ // Set while the renderer is waiting for a lost context to be restored.
70
+ _defineProperty(this, "restoreWanted", false);
71
+ _defineProperty(this, "restoreRequest", null);
72
+ _defineProperty(this, "onContextLost", () => {
73
+ // The browser already dropped every GL object; drop our references to
74
+ // them. Restoration is left to the browser (it restores an evicted
75
+ // context as soon as a slot frees up), except when this renderer was
76
+ // built on an already-lost context and is waiting to paint for the first
77
+ // time: chasing an eviction from here would evict the next-oldest context
78
+ // in turn, and with more live canvases than the browser allows the
79
+ // canvases would endlessly evict each other.
80
+ this.release();
81
+ if (this.restoreWanted) {
82
+ // The permission granted by preventDefault() is only recorded by the
83
+ // browser once the event dispatch is over: a restoreContext() call
84
+ // from inside the handler is refused, so ask from a later task.
85
+ this.restoreRequest = setTimeout(() => {
86
+ var _canvasWebGL$get;
87
+ this.restoreRequest = null;
88
+ (_canvasWebGL$get = canvasWebGL.get(this.canvas)) === null || _canvasWebGL$get === void 0 || (_canvasWebGL$get = _canvasWebGL$get.loseContext) === null || _canvasWebGL$get === void 0 || _canvasWebGL$get.restoreContext();
89
+ }, 0);
90
+ }
91
+ });
92
+ _defineProperty(this, "onContextRestored", () => {
93
+ this.acquire();
94
+ this.requestRedraw();
95
+ });
96
+ const entry = canvasWebGL.get(canvas);
97
+ if (entry) {
98
+ entry.owner = this;
99
+ }
100
+ canvas.addEventListener("webglcontextlost", this.onContextLost);
101
+ canvas.addEventListener("webglcontextrestored", this.onContextRestored);
102
+ this.acquire();
103
+ }
104
+
105
+ // Builds the GrDirectContext and the surface on the element's WebGL
106
+ // context, creating the context first if the element has none.
107
+ acquire() {
108
+ const {
109
+ canvas
110
+ } = this;
111
+ const known = canvasWebGL.get(canvas);
112
+ if (known !== null && known !== void 0 && known.gl.isContextLost()) {
113
+ // Nothing can be built on a lost context: CanvasKit.GetWebGLContext
114
+ // happily registers it, and MakeWebGLContext then faults inside wasm
115
+ // (#3976). Ask the browser for it back and finish in onContextRestored;
116
+ // if the loss hasn't been announced yet, onContextLost asks.
117
+ this.restoreWanted = true;
118
+ if (known.lossAnnounced) {
119
+ var _known$loseContext;
120
+ (_known$loseContext = known.loseContext) === null || _known$loseContext === void 0 || _known$loseContext.restoreContext();
121
+ }
122
+ return;
123
+ }
124
+ const handle = CanvasKit.GetWebGLContext(canvas);
125
+ if (!handle) {
35
126
  throw new Error("Could not create a WebGL context");
36
127
  }
37
- this.grContext = CanvasKit.MakeWebGLContext(this.contextHandle);
38
- if (!this.grContext) {
39
- CanvasKit.deleteContext(this.contextHandle);
40
- this.contextHandle = 0;
128
+ const entry = known !== null && known !== void 0 ? known : this.trackContext();
129
+ let grContext = null;
130
+ try {
131
+ grContext = CanvasKit.MakeWebGLContext(handle);
132
+ } finally {
133
+ if (!grContext) {
134
+ // Whether it returned null or threw, don't leave the registry
135
+ // holding on to the canvas.
136
+ deleteContextHandle(handle);
137
+ }
138
+ }
139
+ if (!grContext) {
41
140
  throw new Error("Could not create a graphics context");
42
141
  }
43
- const ctx = canvas.getContext("webgl2");
44
- if (ctx) {
45
- ctx.drawingBufferColorSpace = "display-p3";
142
+ this.restoreWanted = false;
143
+ this.contextHandle = handle;
144
+ this.grContext = grContext;
145
+ if (entry) {
146
+ entry.gl.drawingBufferColorSpace = "display-p3";
46
147
  }
47
148
  this.onResize();
48
149
  }
150
+
151
+ // CanvasKit just created the element's context; asking for it again hands
152
+ // back the same object (the attributes are only honored the first time).
153
+ trackContext() {
154
+ var _canvas$getContext;
155
+ const {
156
+ canvas
157
+ } = this;
158
+ const gl = (_canvas$getContext = canvas.getContext("webgl2")) !== null && _canvas$getContext !== void 0 ? _canvas$getContext : canvas.getContext("webgl");
159
+ if (!gl) {
160
+ return null;
161
+ }
162
+ const entry = {
163
+ gl,
164
+ loseContext: gl.getExtension("WEBGL_lose_context"),
165
+ lossAnnounced: false,
166
+ owner: this
167
+ };
168
+ canvasWebGL.set(canvas, entry);
169
+ // Browsers restore a lost context (evicted as the oldest one when the
170
+ // page exceeds the active-context limit, or lost to a GPU reset) only if
171
+ // the page called preventDefault() on the webglcontextlost event. A
172
+ // renderer isn't necessarily attached when that happens (the canvas may
173
+ // be in a hidden Activity), so these listeners live as long as the
174
+ // element does. They are registered ahead of any renderer's, and the
175
+ // loss can't be announced before they exist since the event is
176
+ // asynchronous.
177
+ canvas.addEventListener("webglcontextlost", event => {
178
+ event.preventDefault();
179
+ entry.lossAnnounced = true;
180
+ });
181
+ canvas.addEventListener("webglcontextrestored", () => {
182
+ entry.lossAnnounced = false;
183
+ });
184
+ return entry;
185
+ }
186
+
187
+ // Frees everything built on the context. The context itself belongs to the
188
+ // element, see dispose().
189
+ release() {
190
+ var _this$surface;
191
+ (_this$surface = this.surface) === null || _this$surface === void 0 || _this$surface.ref.delete();
192
+ this.surface = null;
193
+ if (this.grContext) {
194
+ this.grContext.releaseResourcesAndAbandonContext();
195
+ this.grContext.delete();
196
+ this.grContext = null;
197
+ }
198
+ if (this.contextHandle) {
199
+ deleteContextHandle(this.contextHandle);
200
+ this.contextHandle = 0;
201
+ }
202
+ }
203
+ isContextLost() {
204
+ var _canvasWebGL$get$gl$i, _canvasWebGL$get2;
205
+ 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;
206
+ }
49
207
  makeImageSnapshot(picture, rect) {
50
- if (!this.surface) {
208
+ if (!this.surface || this.isContextLost()) {
51
209
  return null;
52
210
  }
53
211
  const canvas = this.surface.getCanvas();
@@ -57,17 +215,20 @@ class WebGLRenderer {
57
215
  return this.surface.makeImageSnapshot(dp2Pixel(this.pd, rect));
58
216
  }
59
217
  onResize() {
60
- var _this$surface;
218
+ var _this$surface2;
61
219
  const {
62
220
  canvas
63
221
  } = this;
64
- if (!this.grContext) {
222
+ if (!this.grContext || this.isContextLost()) {
223
+ // Waiting for the context to be restored (the restore path resizes),
224
+ // or the loss hasn't been announced yet and onContextLost is about to
225
+ // release everything: either way there is nothing to build on.
65
226
  return;
66
227
  }
67
228
  this.pd = window.devicePixelRatio;
68
229
  canvas.width = canvas.clientWidth * this.pd;
69
230
  canvas.height = canvas.clientHeight * this.pd;
70
- (_this$surface = this.surface) === null || _this$surface === void 0 || _this$surface.ref.delete();
231
+ (_this$surface2 = this.surface) === null || _this$surface2 === void 0 || _this$surface2.ref.delete();
71
232
  this.surface = null;
72
233
  if (canvas.width === 0 || canvas.height === 0) {
73
234
  // The canvas hasn't been laid out yet (or is hidden). The view's
@@ -83,38 +244,55 @@ class WebGLRenderer {
83
244
  this.surface = new _JsiSkSurface.JsiSkSurface(CanvasKit, surface);
84
245
  }
85
246
  draw(picture) {
86
- if (this.surface) {
87
- const canvas = this.surface.getCanvas();
88
- canvas.clear(Float32Array.of(0, 0, 0, 0));
89
- canvas.save();
90
- canvas.scale(this.pd, this.pd);
91
- canvas.drawPicture(picture);
92
- canvas.restore();
93
- this.surface.ref.flush();
247
+ if (!this.surface || this.isContextLost()) {
248
+ return;
94
249
  }
250
+ const canvas = this.surface.getCanvas();
251
+ canvas.clear(Float32Array.of(0, 0, 0, 0));
252
+ canvas.save();
253
+ canvas.scale(this.pd, this.pd);
254
+ canvas.drawPicture(picture);
255
+ canvas.restore();
256
+ this.surface.ref.flush();
95
257
  }
96
258
  dispose() {
97
- var _this$surface2, _this$canvas;
98
- (_this$surface2 = this.surface) === null || _this$surface2 === void 0 || _this$surface2.ref.delete();
99
- this.surface = null;
100
- if (this.grContext) {
101
- this.grContext.releaseResourcesAndAbandonContext();
102
- this.grContext.delete();
103
- this.grContext = null;
259
+ const {
260
+ canvas
261
+ } = this;
262
+ canvas.removeEventListener("webglcontextlost", this.onContextLost);
263
+ canvas.removeEventListener("webglcontextrestored", this.onContextRestored);
264
+ if (this.restoreRequest !== null) {
265
+ clearTimeout(this.restoreRequest);
266
+ this.restoreRequest = null;
104
267
  }
105
- (_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();
106
- if (this.contextHandle) {
107
- // Unregister the context from CanvasKit's internal registry, otherwise
108
- // it retains the canvas element (and its detached DOM tree) forever.
109
- CanvasKit.deleteContext(this.contextHandle);
110
- // Making the now-deleted handle current clears CanvasKit's
111
- // current-context globals (GLctx/Module.ctx), which would otherwise
112
- // keep referencing the context (and the canvas) until another surface
113
- // becomes current. With a deleted handle this is a no-op that returns
114
- // null without creating anything.
115
- CanvasKit.MakeWebGLContext(this.contextHandle);
116
- this.contextHandle = 0;
268
+ this.restoreWanted = false;
269
+ this.release();
270
+ // Free the drawing buffer, which CanvasKit requests with depth and stencil
271
+ // attachments (about 8 bytes per pixel): a canvas that stays in the
272
+ // document without a renderer, hidden in an Activity say, would otherwise
273
+ // keep a full-size buffer around. The next renderer's onResize() sizes it
274
+ // again.
275
+ canvas.width = 0;
276
+ canvas.height = 0;
277
+ const entry = canvasWebGL.get(canvas);
278
+ if (!entry) {
279
+ return;
117
280
  }
281
+ entry.owner = null;
282
+ // Whether the element is going away is only known once the commit is
283
+ // over: on a real unmount React runs this cleanup *before* removing the
284
+ // node from the document, while StrictMode's double-invoke and an
285
+ // Activity hide keep the node in place (and the former builds the next
286
+ // renderer on it right away). Losing the context of a detached element
287
+ // matters: it would otherwise stay alive until the element is garbage
288
+ // collected, and browsers cap the number of live contexts per page
289
+ // (16 in Chrome, which then evicts the oldest one, visible or not).
290
+ queueMicrotask(() => {
291
+ if (entry.owner === null && !canvas.isConnected && !entry.gl.isContextLost()) {
292
+ var _entry$loseContext;
293
+ (_entry$loseContext = entry.loseContext) === null || _entry$loseContext === void 0 || _entry$loseContext.loseContext();
294
+ }
295
+ });
118
296
  }
119
297
  }
120
298
  class StaticWebGLRenderer {
@@ -289,21 +467,29 @@ const SkiaPictureView = props => {
289
467
  // - The renderer is created synchronously on mount (the canvas element is
290
468
  // guaranteed to exist in useLayoutEffect; a zero size at that point is
291
469
  // fine, the surface is created once the canvas is measurable).
292
- // - Redraw requests coalesce into a single animation frame. A picture
293
- // dispatched before the canvas has a size stays in pictureRef (drawing
294
- // while unmeasured is a no-op) and is painted by the resize path below
295
- // once the canvas becomes measurable, so it is never lost.
470
+ // - Redraw requests coalesce into a single microtask. A microtask (not an
471
+ // animation frame) so that a picture produced inside a rAF callback (the
472
+ // Reanimated mapper) is drawn before the current frame paints: deferring
473
+ // to the next rAF alternates between "flush pending in this frame" and
474
+ // "flush scheduled for the next frame", drawing on every other frame
475
+ // only and halving the effective frame rate. A picture dispatched before
476
+ // the canvas has a size stays in pictureRef (drawing while unmeasured is
477
+ // a no-op) and is painted by the resize path below once the canvas
478
+ // becomes measurable, so it is never lost.
296
479
  // - A ResizeObserver on the canvas itself recreates the surface and repaints
297
480
  // synchronously (its callbacks run after layout, before paint), and is
298
481
  // also the source of the user-facing onLayout event.
482
+ // - The renderer belongs to the layout effect, the WebGL context to the
483
+ // <canvas> element, whose lifetime is longer; see WebGLRenderer for how
484
+ // the two are reconciled.
299
485
  const redrawPendingRef = (0, _react.useRef)(false);
300
- const frameRef = (0, _react.useRef)(0);
486
+ const flushScheduledRef = (0, _react.useRef)(false);
301
487
  const onLayoutRef = (0, _react.useRef)(onLayout);
302
488
  (0, _react.useLayoutEffect)(() => {
303
489
  onLayoutRef.current = onLayout;
304
490
  }, [onLayout]);
305
491
  const flushRedraw = (0, _react.useCallback)(() => {
306
- frameRef.current = 0;
492
+ flushScheduledRef.current = false;
307
493
  if (redrawPendingRef.current && rendererRef.current && pictureRef.current) {
308
494
  redrawPendingRef.current = false;
309
495
  rendererRef.current.draw(pictureRef.current);
@@ -313,8 +499,9 @@ const SkiaPictureView = props => {
313
499
  }, []);
314
500
  const redraw = (0, _react.useCallback)(() => {
315
501
  redrawPendingRef.current = true;
316
- if (frameRef.current === 0) {
317
- frameRef.current = requestAnimationFrame(flushRedraw);
502
+ if (!flushScheduledRef.current) {
503
+ flushScheduledRef.current = true;
504
+ queueMicrotask(flushRedraw);
318
505
  }
319
506
  }, [flushRedraw]);
320
507
  const getSize = (0, _react.useCallback)(() => {
@@ -369,7 +556,7 @@ const SkiaPictureView = props => {
369
556
  if (!canvas) {
370
557
  return undefined;
371
558
  }
372
- const renderer = isStatic ? new StaticWebGLRenderer(canvas) : new WebGLRenderer(canvas);
559
+ const renderer = isStatic ? new StaticWebGLRenderer(canvas) : new WebGLRenderer(canvas, redraw);
373
560
  rendererRef.current = renderer;
374
561
  const drawPicture = () => {
375
562
  if (pictureRef.current) {
@@ -448,13 +635,12 @@ const SkiaPictureView = props => {
448
635
  rendererRef.current = null;
449
636
  renderer.dispose();
450
637
  };
451
- }, [isStatic]);
452
- (0, _react.useEffect)(() => {
453
- return () => {
454
- cancelAnimationFrame(frameRef.current);
455
- frameRef.current = 0;
456
- };
457
- }, []);
638
+ }, [isStatic, redraw]);
639
+
640
+ // No flush cancellation is needed on unmount: a microtask queued before
641
+ // unmount runs within the same task, and flushRedraw no-ops once the
642
+ // layout-effect cleanup has nulled rendererRef.
643
+
458
644
  (0, _react.useImperativeHandle)(ref, () => ({
459
645
  setPicture,
460
646
  getSize,
@@ -496,6 +682,10 @@ const SkiaPictureView = props => {
496
682
  ...viewProps
497
683
  } = props;
498
684
  return /*#__PURE__*/_react.default.createElement(_Platform.Platform.View, viewProps, /*#__PURE__*/_react.default.createElement("canvas", {
685
+ // A canvas element is bound to one context kind for life (WebGL for
686
+ // the live renderer, 2D for the static one), so switching renderers
687
+ // needs a fresh element.
688
+ key: isStatic ? "static" : "webgl",
499
689
  ref: canvasRef,
500
690
  style: {
501
691
  display: "block",