@shopify/react-native-skia 2.6.9 → 2.8.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.
- package/android/cpp/jni/include/JniSkiaBaseView.h +6 -4
- package/android/cpp/jni/include/JniSkiaPictureView.h +8 -6
- package/android/cpp/rnskia-android/OpenGLContext.h +10 -1
- package/android/cpp/rnskia-android/RNSkAndroidView.h +8 -8
- package/android/cpp/rnskia-android/RNSkOpenGLCanvasProvider.cpp +9 -5
- package/android/cpp/rnskia-android/RNSkOpenGLCanvasProvider.h +4 -2
- package/android/src/main/java/com/shopify/reactnative/skia/SkiaBaseView.java +48 -12
- package/android/src/main/java/com/shopify/reactnative/skia/SkiaBaseViewManager.java +5 -0
- package/android/src/main/java/com/shopify/reactnative/skia/SkiaPictureView.java +2 -2
- package/android/src/main/java/com/shopify/reactnative/skia/ViewScreenshotService.java +11 -7
- package/apple/MetalContext.h +7 -6
- package/apple/MetalLayerColorSpace.mm +39 -0
- package/apple/MetalLayerColorSpaceUtils.h +34 -0
- package/apple/MetalWindowContext.h +3 -1
- package/apple/MetalWindowContext.mm +9 -8
- package/apple/RNSkAppleView.h +6 -0
- package/apple/RNSkMetalCanvasProvider.h +2 -0
- package/apple/RNSkMetalCanvasProvider.mm +15 -2
- package/apple/SkiaPictureView.mm +1 -0
- package/apple/SkiaPictureViewManager.mm +5 -0
- package/apple/SkiaUIView.h +1 -0
- package/apple/SkiaUIView.mm +9 -0
- package/cpp/api/JsiSkParagraph.h +114 -0
- package/cpp/api/JsiSkSurface.h +8 -2
- package/cpp/rnskia/RNDawnContext.h +4 -3
- package/cpp/rnskia/RNDawnUtils.h +25 -6
- package/cpp/rnskia/RNDawnWindowContext.h +44 -10
- package/cpp/rnskia/RNMetalLayerColorSpace.h +16 -0
- package/cpp/rnskia/RNSkJsiViewApi.h +46 -24
- package/cpp/rnwgpu/SurfaceRegistry.h +10 -4
- package/lib/commonjs/Platform/Platform.web.js +2 -90
- package/lib/commonjs/Platform/Platform.web.js.map +1 -1
- package/lib/commonjs/external/reanimated/useVideoLoading.js +11 -2
- package/lib/commonjs/external/reanimated/useVideoLoading.js.map +1 -1
- package/lib/commonjs/mock/index.js +1 -0
- package/lib/commonjs/mock/index.js.map +1 -1
- package/lib/commonjs/renderer/Canvas.d.ts +10 -1
- package/lib/commonjs/renderer/Canvas.js +2 -0
- package/lib/commonjs/renderer/Canvas.js.map +1 -1
- package/lib/commonjs/skia/core/SVG.web.js +4 -5
- package/lib/commonjs/skia/core/SVG.web.js.map +1 -1
- package/lib/commonjs/skia/types/Paragraph/Paragraph.d.ts +62 -0
- package/lib/commonjs/skia/types/Paragraph/Paragraph.js.map +1 -1
- package/lib/commonjs/skia/types/Surface/Surface.d.ts +5 -1
- package/lib/commonjs/skia/types/Surface/Surface.js.map +1 -1
- package/lib/commonjs/skia/web/Host.js +7 -0
- package/lib/commonjs/skia/web/Host.js.map +1 -1
- package/lib/commonjs/skia/web/JsiSkPaint.js +5 -0
- package/lib/commonjs/skia/web/JsiSkPaint.js.map +1 -1
- package/lib/commonjs/skia/web/JsiSkParagraph.d.ts +3 -1
- package/lib/commonjs/skia/web/JsiSkParagraph.js +6 -0
- package/lib/commonjs/skia/web/JsiSkParagraph.js.map +1 -1
- package/lib/commonjs/skia/web/JsiSkParagraphStyle.js +14 -3
- package/lib/commonjs/skia/web/JsiSkParagraphStyle.js.map +1 -1
- package/lib/commonjs/skia/web/JsiSkSurface.d.ts +1 -1
- package/lib/commonjs/skia/web/JsiSkSurface.js +2 -1
- package/lib/commonjs/skia/web/JsiSkSurface.js.map +1 -1
- package/lib/commonjs/sksg/Container.native.d.ts +1 -0
- package/lib/commonjs/sksg/Container.native.js +11 -0
- package/lib/commonjs/sksg/Container.native.js.map +1 -1
- package/lib/commonjs/sksg/Container.web.d.ts +1 -0
- package/lib/commonjs/sksg/Container.web.js +45 -3
- package/lib/commonjs/sksg/Container.web.js.map +1 -1
- package/lib/commonjs/sksg/Recorder/DrawingContext.d.ts +2 -0
- package/lib/commonjs/sksg/Recorder/DrawingContext.js +22 -6
- package/lib/commonjs/sksg/Recorder/DrawingContext.js.map +1 -1
- package/lib/commonjs/sksg/Recorder/FrameScope.d.ts +18 -0
- package/lib/commonjs/sksg/Recorder/FrameScope.js +66 -0
- package/lib/commonjs/sksg/Recorder/FrameScope.js.map +1 -0
- package/lib/commonjs/sksg/Recorder/FrameScope.native.d.ts +10 -0
- package/lib/commonjs/sksg/Recorder/FrameScope.native.js +26 -0
- package/lib/commonjs/sksg/Recorder/FrameScope.native.js.map +1 -0
- package/lib/commonjs/sksg/Recorder/Player.js +1 -2
- package/lib/commonjs/sksg/Recorder/Player.js.map +1 -1
- package/lib/commonjs/sksg/Recorder/Recorder.d.ts +3 -1
- package/lib/commonjs/sksg/Recorder/Recorder.js +12 -1
- package/lib/commonjs/sksg/Recorder/Recorder.js.map +1 -1
- package/lib/commonjs/sksg/Recorder/commands/Drawing.js +3 -3
- package/lib/commonjs/sksg/Recorder/commands/Drawing.js.map +1 -1
- package/lib/commonjs/sksg/Recorder/commands/Shaders.js +3 -3
- package/lib/commonjs/sksg/Recorder/commands/Shaders.js.map +1 -1
- package/lib/commonjs/sksg/StaticContainer.d.ts +1 -0
- package/lib/commonjs/sksg/StaticContainer.js +27 -1
- package/lib/commonjs/sksg/StaticContainer.js.map +1 -1
- package/lib/commonjs/specs/NativeSkiaModule.web.d.ts +2 -0
- package/lib/commonjs/specs/NativeSkiaModule.web.js +32 -7
- package/lib/commonjs/specs/NativeSkiaModule.web.js.map +1 -1
- package/lib/commonjs/specs/SkiaPictureViewNativeComponent.d.ts +1 -0
- package/lib/commonjs/specs/SkiaPictureViewNativeComponent.js.map +1 -1
- package/lib/commonjs/views/SkiaPictureView.js +2 -0
- package/lib/commonjs/views/SkiaPictureView.js.map +1 -1
- package/lib/commonjs/views/SkiaPictureView.web.js +279 -94
- package/lib/commonjs/views/SkiaPictureView.web.js.map +1 -1
- package/lib/commonjs/views/formats.d.ts +1 -0
- package/lib/commonjs/views/formats.js +28 -0
- package/lib/commonjs/views/formats.js.map +1 -0
- package/lib/commonjs/views/index.d.ts +1 -0
- package/lib/commonjs/views/index.js +11 -0
- package/lib/commonjs/views/index.js.map +1 -1
- package/lib/commonjs/views/types.d.ts +6 -0
- package/lib/commonjs/views/types.js.map +1 -1
- package/lib/module/Platform/Platform.web.js +3 -91
- package/lib/module/Platform/Platform.web.js.map +1 -1
- package/lib/module/external/reanimated/useVideoLoading.js +12 -2
- package/lib/module/external/reanimated/useVideoLoading.js.map +1 -1
- package/lib/module/mock/index.js +1 -0
- package/lib/module/mock/index.js.map +1 -1
- package/lib/module/renderer/Canvas.d.ts +10 -1
- package/lib/module/renderer/Canvas.js +2 -0
- package/lib/module/renderer/Canvas.js.map +1 -1
- package/lib/module/skia/core/SVG.web.js +4 -5
- package/lib/module/skia/core/SVG.web.js.map +1 -1
- package/lib/module/skia/types/Paragraph/Paragraph.d.ts +62 -0
- package/lib/module/skia/types/Paragraph/Paragraph.js.map +1 -1
- package/lib/module/skia/types/Surface/Surface.d.ts +5 -1
- package/lib/module/skia/types/Surface/Surface.js.map +1 -1
- package/lib/module/skia/web/Host.js +7 -0
- package/lib/module/skia/web/Host.js.map +1 -1
- package/lib/module/skia/web/JsiSkPaint.js +5 -0
- package/lib/module/skia/web/JsiSkPaint.js.map +1 -1
- package/lib/module/skia/web/JsiSkParagraph.d.ts +3 -1
- package/lib/module/skia/web/JsiSkParagraph.js +7 -1
- package/lib/module/skia/web/JsiSkParagraph.js.map +1 -1
- package/lib/module/skia/web/JsiSkParagraphStyle.js +14 -3
- package/lib/module/skia/web/JsiSkParagraphStyle.js.map +1 -1
- package/lib/module/skia/web/JsiSkSurface.d.ts +1 -1
- package/lib/module/skia/web/JsiSkSurface.js +2 -1
- package/lib/module/skia/web/JsiSkSurface.js.map +1 -1
- package/lib/module/sksg/Container.native.d.ts +1 -0
- package/lib/module/sksg/Container.native.js +11 -0
- package/lib/module/sksg/Container.native.js.map +1 -1
- package/lib/module/sksg/Container.web.d.ts +1 -0
- package/lib/module/sksg/Container.web.js +46 -4
- package/lib/module/sksg/Container.web.js.map +1 -1
- package/lib/module/sksg/Recorder/DrawingContext.d.ts +2 -0
- package/lib/module/sksg/Recorder/DrawingContext.js +22 -6
- package/lib/module/sksg/Recorder/DrawingContext.js.map +1 -1
- package/lib/module/sksg/Recorder/FrameScope.d.ts +18 -0
- package/lib/module/sksg/Recorder/FrameScope.js +59 -0
- package/lib/module/sksg/Recorder/FrameScope.js.map +1 -0
- package/lib/module/sksg/Recorder/FrameScope.native.d.ts +10 -0
- package/lib/module/sksg/Recorder/FrameScope.native.js +19 -0
- package/lib/module/sksg/Recorder/FrameScope.native.js.map +1 -0
- package/lib/module/sksg/Recorder/Player.js +1 -2
- package/lib/module/sksg/Recorder/Player.js.map +1 -1
- package/lib/module/sksg/Recorder/Recorder.d.ts +3 -1
- package/lib/module/sksg/Recorder/Recorder.js +10 -0
- package/lib/module/sksg/Recorder/Recorder.js.map +1 -1
- package/lib/module/sksg/Recorder/commands/Drawing.js +3 -3
- package/lib/module/sksg/Recorder/commands/Drawing.js.map +1 -1
- package/lib/module/sksg/Recorder/commands/Shaders.js +3 -3
- package/lib/module/sksg/Recorder/commands/Shaders.js.map +1 -1
- package/lib/module/sksg/StaticContainer.d.ts +1 -0
- package/lib/module/sksg/StaticContainer.js +28 -2
- package/lib/module/sksg/StaticContainer.js.map +1 -1
- package/lib/module/specs/NativeSkiaModule.web.d.ts +2 -0
- package/lib/module/specs/NativeSkiaModule.web.js +32 -7
- package/lib/module/specs/NativeSkiaModule.web.js.map +1 -1
- package/lib/module/specs/SkiaPictureViewNativeComponent.d.ts +1 -0
- package/lib/module/specs/SkiaPictureViewNativeComponent.js.map +1 -1
- package/lib/module/views/SkiaPictureView.js +2 -0
- package/lib/module/views/SkiaPictureView.js.map +1 -1
- package/lib/module/views/SkiaPictureView.web.js +280 -95
- package/lib/module/views/SkiaPictureView.web.js.map +1 -1
- package/lib/module/views/formats.d.ts +1 -0
- package/lib/module/views/formats.js +22 -0
- package/lib/module/views/formats.js.map +1 -0
- package/lib/module/views/index.d.ts +1 -0
- package/lib/module/views/index.js +1 -0
- package/lib/module/views/index.js.map +1 -1
- package/lib/module/views/types.d.ts +6 -0
- package/lib/module/views/types.js.map +1 -1
- package/lib/typescript/lib/commonjs/Platform/Platform.web.d.ts +1 -2
- package/lib/typescript/lib/commonjs/mock/index.d.ts +1 -0
- package/lib/typescript/lib/commonjs/renderer/Canvas.d.ts +2 -1
- package/lib/typescript/lib/commonjs/skia/web/JsiSkParagraph.d.ts +2 -0
- package/lib/typescript/lib/commonjs/skia/web/JsiSkSurface.d.ts +1 -1
- package/lib/typescript/lib/commonjs/sksg/Container.native.d.ts +1 -1
- package/lib/typescript/lib/commonjs/sksg/Container.web.d.ts +3 -3
- package/lib/typescript/lib/commonjs/sksg/Recorder/DrawingContext.d.ts +2 -0
- package/lib/typescript/lib/commonjs/sksg/Recorder/FrameScope.d.ts +17 -0
- package/lib/typescript/lib/commonjs/sksg/Recorder/FrameScope.native.d.ts +13 -0
- package/lib/typescript/lib/commonjs/sksg/Recorder/Recorder.d.ts +1 -0
- package/lib/typescript/lib/commonjs/sksg/StaticContainer.d.ts +2 -2
- package/lib/typescript/lib/commonjs/views/formats.d.ts +2 -0
- package/lib/typescript/lib/module/Platform/Platform.web.d.ts +1 -3
- package/lib/typescript/lib/module/mock/index.d.ts +2 -2
- package/lib/typescript/lib/module/renderer/Canvas.d.ts +2 -1
- package/lib/typescript/lib/module/skia/web/JsiSkParagraph.d.ts +2 -0
- package/lib/typescript/lib/module/skia/web/JsiSkSurface.d.ts +1 -1
- package/lib/typescript/lib/module/sksg/Container.native.d.ts +1 -1
- package/lib/typescript/lib/module/sksg/Container.web.d.ts +3 -3
- package/lib/typescript/lib/module/sksg/Recorder/DrawingContext.d.ts +2 -0
- package/lib/typescript/lib/module/sksg/Recorder/FrameScope.d.ts +5 -0
- package/lib/typescript/lib/module/sksg/Recorder/FrameScope.native.d.ts +5 -0
- package/lib/typescript/lib/module/sksg/Recorder/Recorder.d.ts +1 -0
- package/lib/typescript/lib/module/sksg/StaticContainer.d.ts +2 -2
- package/lib/typescript/lib/module/views/formats.d.ts +1 -0
- package/lib/typescript/lib/module/views/index.d.ts +1 -0
- package/lib/typescript/src/renderer/Canvas.d.ts +10 -1
- package/lib/typescript/src/skia/types/Paragraph/Paragraph.d.ts +62 -0
- package/lib/typescript/src/skia/types/Surface/Surface.d.ts +5 -1
- package/lib/typescript/src/skia/web/JsiSkParagraph.d.ts +3 -1
- package/lib/typescript/src/skia/web/JsiSkSurface.d.ts +1 -1
- package/lib/typescript/src/sksg/Container.native.d.ts +1 -0
- package/lib/typescript/src/sksg/Container.web.d.ts +1 -0
- package/lib/typescript/src/sksg/Recorder/DrawingContext.d.ts +2 -0
- package/lib/typescript/src/sksg/Recorder/FrameScope.d.ts +18 -0
- package/lib/typescript/src/sksg/Recorder/FrameScope.native.d.ts +10 -0
- package/lib/typescript/src/sksg/Recorder/Recorder.d.ts +3 -1
- package/lib/typescript/src/sksg/StaticContainer.d.ts +1 -0
- package/lib/typescript/src/specs/NativeSkiaModule.web.d.ts +2 -0
- package/lib/typescript/src/specs/SkiaPictureViewNativeComponent.d.ts +1 -0
- package/lib/typescript/src/views/formats.d.ts +1 -0
- package/lib/typescript/src/views/index.d.ts +1 -0
- package/lib/typescript/src/views/types.d.ts +6 -0
- package/package.json +4 -1
- package/react-native-skia.podspec +1 -0
- package/src/Platform/Platform.web.tsx +7 -99
- package/src/external/reanimated/useVideoLoading.ts +12 -2
- package/src/mock/index.ts +1 -0
- package/src/renderer/Canvas.tsx +11 -0
- package/src/skia/core/SVG.web.ts +5 -14
- package/src/skia/types/Paragraph/Paragraph.ts +67 -0
- package/src/skia/types/Surface/Surface.ts +5 -1
- package/src/skia/web/Host.ts +7 -0
- package/src/skia/web/JsiSkPaint.ts +5 -0
- package/src/skia/web/JsiSkParagraph.ts +9 -1
- package/src/skia/web/JsiSkParagraphStyle.ts +16 -2
- package/src/skia/web/JsiSkSurface.ts +2 -1
- package/src/sksg/Container.native.ts +12 -0
- package/src/sksg/Container.web.ts +43 -4
- package/src/sksg/Recorder/DrawingContext.ts +19 -6
- package/src/sksg/Recorder/FrameScope.native.ts +21 -0
- package/src/sksg/Recorder/FrameScope.ts +69 -0
- package/src/sksg/Recorder/Player.ts +1 -2
- package/src/sksg/Recorder/Recorder.ts +15 -1
- package/src/sksg/Recorder/commands/Drawing.ts +3 -3
- package/src/sksg/Recorder/commands/Shaders.ts +22 -16
- package/src/sksg/StaticContainer.ts +29 -2
- package/src/specs/NativeSkiaModule.web.ts +39 -7
- package/src/specs/SkiaPictureViewNativeComponent.ts +1 -0
- package/src/views/SkiaPictureView.tsx +2 -0
- package/src/views/SkiaPictureView.web.tsx +318 -106
- package/src/views/formats.ts +21 -0
- package/src/views/index.ts +1 -0
- package/src/views/types.ts +7 -0
|
@@ -5,15 +5,26 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.JsiSkParagraphStyle = void 0;
|
|
7
7
|
var _types = require("../types");
|
|
8
|
+
var _JsiSkTextStyle = require("./JsiSkTextStyle");
|
|
8
9
|
class JsiSkParagraphStyle {
|
|
9
10
|
static toParagraphStyle(ck, value) {
|
|
10
11
|
var _value$disableHinting, _value$ellipsis, _value$heightMultipli, _value$maxLines, _value$replaceTabChar, _ps$strutStyle, _value$strutStyle$fon, _value$strutStyle, _value$strutStyle$fon2, _value$strutStyle2, _value$strutStyle$hei, _value$strutStyle3, _value$strutStyle$lea, _value$strutStyle4, _value$strutStyle$for, _value$strutStyle5, _ps$strutStyle$fontSt, _value$strutStyle6, _value$strutStyle7, _value$strutStyle8, _value$strutStyle$hal, _value$strutStyle9, _value$strutStyle$str, _value$strutStyle0;
|
|
11
12
|
// Seems like we need to provide the textStyle.color value, otherwise
|
|
12
13
|
// the constructor crashes.
|
|
14
|
+
const textStyle = {
|
|
15
|
+
color: ck.BLACK
|
|
16
|
+
};
|
|
17
|
+
if (value.textStyle) {
|
|
18
|
+
// Only merge the properties that are set; toTextStyle() emits undefined
|
|
19
|
+
// for the others and the ParagraphStyle constructor requires a color.
|
|
20
|
+
Object.entries(_JsiSkTextStyle.JsiSkTextStyle.toTextStyle(value.textStyle)).forEach(([key, v]) => {
|
|
21
|
+
if (v !== undefined) {
|
|
22
|
+
textStyle[key] = v;
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
}
|
|
13
26
|
const ps = new ck.ParagraphStyle({
|
|
14
|
-
textStyle
|
|
15
|
-
color: ck.BLACK
|
|
16
|
-
}
|
|
27
|
+
textStyle
|
|
17
28
|
});
|
|
18
29
|
ps.disableHinting = (_value$disableHinting = value.disableHinting) !== null && _value$disableHinting !== void 0 ? _value$disableHinting : ps.disableHinting;
|
|
19
30
|
ps.ellipsis = (_value$ellipsis = value.ellipsis) !== null && _value$ellipsis !== void 0 ? _value$ellipsis : ps.ellipsis;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_types","require","JsiSkParagraphStyle","toParagraphStyle","ck","value","_value$disableHinting","_value$ellipsis","_value$heightMultipli","_value$maxLines","_value$replaceTabChar","_ps$strutStyle","_value$strutStyle$fon","_value$strutStyle","_value$strutStyle$fon2","_value$strutStyle2","_value$strutStyle$hei","_value$strutStyle3","_value$strutStyle$lea","_value$strutStyle4","_value$strutStyle$for","_value$strutStyle5","_ps$strutStyle$fontSt","_value$strutStyle6","_value$strutStyle7","_value$strutStyle8","_value$strutStyle$hal","_value$strutStyle9","_value$strutStyle$str","_value$strutStyle0","
|
|
1
|
+
{"version":3,"names":["_types","require","_JsiSkTextStyle","JsiSkParagraphStyle","toParagraphStyle","ck","value","_value$disableHinting","_value$ellipsis","_value$heightMultipli","_value$maxLines","_value$replaceTabChar","_ps$strutStyle","_value$strutStyle$fon","_value$strutStyle","_value$strutStyle$fon2","_value$strutStyle2","_value$strutStyle$hei","_value$strutStyle3","_value$strutStyle$lea","_value$strutStyle4","_value$strutStyle$for","_value$strutStyle5","_ps$strutStyle$fontSt","_value$strutStyle6","_value$strutStyle7","_value$strutStyle8","_value$strutStyle$hal","_value$strutStyle9","_value$strutStyle$str","_value$strutStyle0","textStyle","color","BLACK","Object","entries","JsiSkTextStyle","toTextStyle","forEach","key","v","undefined","ps","ParagraphStyle","disableHinting","ellipsis","heightMultiplier","maxLines","replaceTabCharacters","textAlign","textDirection","TextDirection","LTR","textHeightBehavior","strutStyle","fontFamilies","fontSize","leading","forceStrutHeight","fontStyle","slant","width","weight","halfLeading","strutEnabled","exports"],"sources":["JsiSkParagraphStyle.ts"],"sourcesContent":["import type { CanvasKit, ParagraphStyle, TextStyle } from \"canvaskit-wasm\";\n\nimport { TextDirection } from \"../types\";\nimport type { SkParagraphStyle } from \"../types\";\n\nimport { JsiSkTextStyle } from \"./JsiSkTextStyle\";\n\nexport class JsiSkParagraphStyle {\n static toParagraphStyle(\n ck: CanvasKit,\n value: SkParagraphStyle\n ): ParagraphStyle {\n // Seems like we need to provide the textStyle.color value, otherwise\n // the constructor crashes.\n const textStyle: TextStyle = { color: ck.BLACK };\n if (value.textStyle) {\n // Only merge the properties that are set; toTextStyle() emits undefined\n // for the others and the ParagraphStyle constructor requires a color.\n Object.entries(JsiSkTextStyle.toTextStyle(value.textStyle)).forEach(\n ([key, v]) => {\n if (v !== undefined) {\n (textStyle as Record<string, unknown>)[key] = v;\n }\n }\n );\n }\n const ps = new ck.ParagraphStyle({ textStyle });\n\n ps.disableHinting = value.disableHinting ?? ps.disableHinting;\n ps.ellipsis = value.ellipsis ?? ps.ellipsis;\n ps.heightMultiplier = value.heightMultiplier ?? ps.heightMultiplier;\n ps.maxLines = value.maxLines ?? ps.maxLines;\n ps.replaceTabCharacters =\n value.replaceTabCharacters ?? ps.replaceTabCharacters;\n ps.textAlign =\n value.textAlign !== undefined ? { value: value.textAlign } : ps.textAlign;\n ps.textDirection =\n value.textDirection !== undefined\n ? { value: value.textDirection === TextDirection.LTR ? 1 : 0 }\n : ps.textDirection;\n ps.textHeightBehavior =\n value.textHeightBehavior !== undefined\n ? { value: value.textHeightBehavior }\n : ps.textHeightBehavior;\n\n ps.strutStyle = ps.strutStyle ?? {};\n ps.strutStyle.fontFamilies =\n value.strutStyle?.fontFamilies ?? ps.strutStyle.fontFamilies;\n ps.strutStyle.fontSize =\n value.strutStyle?.fontSize ?? ps.strutStyle.fontSize;\n ps.strutStyle.heightMultiplier =\n value.strutStyle?.heightMultiplier ?? ps.strutStyle.heightMultiplier;\n ps.strutStyle.leading = value.strutStyle?.leading ?? ps.strutStyle.leading;\n ps.strutStyle.forceStrutHeight =\n value.strutStyle?.forceStrutHeight ?? ps.strutStyle.forceStrutHeight;\n\n ps.strutStyle.fontStyle = ps.strutStyle.fontStyle ?? {};\n\n ps.strutStyle.fontStyle.slant =\n value.strutStyle?.fontStyle?.slant !== undefined\n ? { value: value.strutStyle.fontStyle.slant }\n : ps.strutStyle.fontStyle.slant;\n ps.strutStyle.fontStyle.width =\n value.strutStyle?.fontStyle?.width !== undefined\n ? { value: value.strutStyle.fontStyle.width }\n : ps.strutStyle.fontStyle.width;\n ps.strutStyle.fontStyle.weight =\n value.strutStyle?.fontStyle?.weight !== undefined\n ? { value: value.strutStyle.fontStyle.weight }\n : ps.strutStyle.fontStyle.weight;\n ps.strutStyle.halfLeading =\n value.strutStyle?.halfLeading ?? ps.strutStyle.halfLeading;\n ps.strutStyle.strutEnabled =\n value.strutStyle?.strutEnabled ?? ps.strutStyle.strutEnabled;\n\n return ps;\n }\n}\n"],"mappings":";;;;;;AAEA,IAAAA,MAAA,GAAAC,OAAA;AAGA,IAAAC,eAAA,GAAAD,OAAA;AAEO,MAAME,mBAAmB,CAAC;EAC/B,OAAOC,gBAAgBA,CACrBC,EAAa,EACbC,KAAuB,EACP;IAAA,IAAAC,qBAAA,EAAAC,eAAA,EAAAC,qBAAA,EAAAC,eAAA,EAAAC,qBAAA,EAAAC,cAAA,EAAA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AAA,CAAkBkC,SAAS,cAAAlC,kBAAA,uBAA3BA,kBAAA,CAA6BoC,KAAK,MAAKpB,SAAS,GAC5C;MAAEnC,KAAK,EAAEA,KAAK,CAACgD,UAAU,CAACK,SAAS,CAACE;IAAM,CAAC,GAC3CnB,EAAE,CAACY,UAAU,CAACK,SAAS,CAACE,KAAK;IACnCnB,EAAE,CAACY,UAAU,CAACK,SAAS,CAACG,MAAM,GAC5B,EAAApC,kBAAA,GAAApB,KAAK,CAACgD,UAAU,cAAA5B,kBAAA,gBAAAA,kBAAA,GAAhBA,kBAAA,CAAkBiC,SAAS,cAAAjC,kBAAA,uBAA3BA,kBAAA,CAA6BoC,MAAM,MAAKrB,SAAS,GAC7C;MAAEnC,KAAK,EAAEA,KAAK,CAACgD,UAAU,CAACK,SAAS,CAACG;IAAO,CAAC,GAC5CpB,EAAE,CAACY,UAAU,CAACK,SAAS,CAACG,MAAM;IACpCpB,EAAE,CAACY,UAAU,CAACS,WAAW,IAAApC,qBAAA,IAAAC,kBAAA,GACvBtB,KAAK,CAACgD,UAAU,cAAA1B,kBAAA,uBAAhBA,kBAAA,CAAkBmC,WAAW,cAAApC,qBAAA,cAAAA,qBAAA,GAAIe,EAAE,CAACY,UAAU,CAACS,WAAW;IAC5DrB,EAAE,CAACY,UAAU,CAACU,YAAY,IAAAnC,qBAAA,IAAAC,kBAAA,GACxBxB,KAAK,CAACgD,UAAU,cAAAxB,kBAAA,uBAAhBA,kBAAA,CAAkBkC,YAAY,cAAAnC,qBAAA,cAAAA,qBAAA,GAAIa,EAAE,CAACY,UAAU,CAACU,YAAY;IAE9D,OAAOtB,EAAE;EACX;AACF;AAACuB,OAAA,CAAA9D,mBAAA,GAAAA,mBAAA","ignoreList":[]}
|
|
@@ -5,7 +5,7 @@ import { JsiSkImage } from "./JsiSkImage";
|
|
|
5
5
|
export declare class JsiSkSurface extends HostObject<Surface, "Surface"> implements SkSurface {
|
|
6
6
|
constructor(CanvasKit: CanvasKit, ref: Surface);
|
|
7
7
|
[Symbol.dispose](): void;
|
|
8
|
-
flush(): void;
|
|
8
|
+
flush(_sync?: boolean): void;
|
|
9
9
|
width(): number;
|
|
10
10
|
height(): number;
|
|
11
11
|
getCanvas(): SkCanvas;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_Host","require","_JsiSkCanvas","_JsiSkImage","_JsiSkRect","JsiSkSurface","HostObject","constructor","CanvasKit","ref","Symbol","dispose","flush","width","height","getCanvas","JsiSkCanvas","makeImageSnapshot","bounds","outputImage","image","Array","from","JsiSkRect","fromValue","undefined","JsiSkImage","getNativeTextureUnstable","console","warn","exports"],"sources":["JsiSkSurface.ts"],"sourcesContent":["import type { CanvasKit, Surface } from \"canvaskit-wasm\";\n\nimport type { SkCanvas, SkImage, SkRect, SkSurface } from \"../types\";\n\nimport { HostObject } from \"./Host\";\nimport { JsiSkCanvas } from \"./JsiSkCanvas\";\nimport { JsiSkImage } from \"./JsiSkImage\";\nimport { JsiSkRect } from \"./JsiSkRect\";\n\nexport class JsiSkSurface\n extends HostObject<Surface, \"Surface\">\n implements SkSurface\n{\n constructor(CanvasKit: CanvasKit, ref: Surface) {\n super(CanvasKit, ref, \"Surface\");\n }\n\n [Symbol.dispose]() {\n this.ref.dispose();\n }\n\n flush() {\n this.ref.flush();\n }\n\n width() {\n return this.ref.width();\n }\n\n height() {\n return this.ref.height();\n }\n\n getCanvas(): SkCanvas {\n return new JsiSkCanvas(this.CanvasKit, this.ref.getCanvas());\n }\n\n makeImageSnapshot(bounds?: SkRect, outputImage?: JsiSkImage): SkImage {\n const image = this.ref.makeImageSnapshot(\n bounds\n ? Array.from(JsiSkRect.fromValue(this.CanvasKit, bounds))\n : undefined\n );\n if (outputImage) {\n outputImage.ref = image;\n }\n return new JsiSkImage(this.CanvasKit, image);\n }\n\n getNativeTextureUnstable(): unknown {\n console.warn(\"getBackendTexture is not implemented on Web\");\n return null;\n }\n}\n"],"mappings":";;;;;;AAIA,IAAAA,KAAA,GAAAC,OAAA;AACA,IAAAC,YAAA,GAAAD,OAAA;AACA,IAAAE,WAAA,GAAAF,OAAA;AACA,IAAAG,UAAA,GAAAH,OAAA;AAEO,MAAMI,YAAY,SACfC,gBAAU,CAEpB;EACEC,WAAWA,CAACC,SAAoB,EAAEC,GAAY,EAAE;IAC9C,KAAK,CAACD,SAAS,EAAEC,GAAG,EAAE,SAAS,CAAC;EAClC;EAEA,CAACC,MAAM,CAACC,OAAO,IAAI;IACjB,IAAI,CAACF,GAAG,CAACE,OAAO,CAAC,CAAC;EACpB;EAEAC,KAAKA,
|
|
1
|
+
{"version":3,"names":["_Host","require","_JsiSkCanvas","_JsiSkImage","_JsiSkRect","JsiSkSurface","HostObject","constructor","CanvasKit","ref","Symbol","dispose","flush","_sync","width","height","getCanvas","JsiSkCanvas","makeImageSnapshot","bounds","outputImage","image","Array","from","JsiSkRect","fromValue","undefined","JsiSkImage","getNativeTextureUnstable","console","warn","exports"],"sources":["JsiSkSurface.ts"],"sourcesContent":["import type { CanvasKit, Surface } from \"canvaskit-wasm\";\n\nimport type { SkCanvas, SkImage, SkRect, SkSurface } from \"../types\";\n\nimport { HostObject } from \"./Host\";\nimport { JsiSkCanvas } from \"./JsiSkCanvas\";\nimport { JsiSkImage } from \"./JsiSkImage\";\nimport { JsiSkRect } from \"./JsiSkRect\";\n\nexport class JsiSkSurface\n extends HostObject<Surface, \"Surface\">\n implements SkSurface\n{\n constructor(CanvasKit: CanvasKit, ref: Surface) {\n super(CanvasKit, ref, \"Surface\");\n }\n\n [Symbol.dispose]() {\n this.ref.dispose();\n }\n\n flush(_sync?: boolean) {\n // CanvasKit has no separate CPU sync; flush() is sufficient on the web backend.\n this.ref.flush();\n }\n\n width() {\n return this.ref.width();\n }\n\n height() {\n return this.ref.height();\n }\n\n getCanvas(): SkCanvas {\n return new JsiSkCanvas(this.CanvasKit, this.ref.getCanvas());\n }\n\n makeImageSnapshot(bounds?: SkRect, outputImage?: JsiSkImage): SkImage {\n const image = this.ref.makeImageSnapshot(\n bounds\n ? Array.from(JsiSkRect.fromValue(this.CanvasKit, bounds))\n : undefined\n );\n if (outputImage) {\n outputImage.ref = image;\n }\n return new JsiSkImage(this.CanvasKit, image);\n }\n\n getNativeTextureUnstable(): unknown {\n console.warn(\"getBackendTexture is not implemented on Web\");\n return null;\n }\n}\n"],"mappings":";;;;;;AAIA,IAAAA,KAAA,GAAAC,OAAA;AACA,IAAAC,YAAA,GAAAD,OAAA;AACA,IAAAE,WAAA,GAAAF,OAAA;AACA,IAAAG,UAAA,GAAAH,OAAA;AAEO,MAAMI,YAAY,SACfC,gBAAU,CAEpB;EACEC,WAAWA,CAACC,SAAoB,EAAEC,GAAY,EAAE;IAC9C,KAAK,CAACD,SAAS,EAAEC,GAAG,EAAE,SAAS,CAAC;EAClC;EAEA,CAACC,MAAM,CAACC,OAAO,IAAI;IACjB,IAAI,CAACF,GAAG,CAACE,OAAO,CAAC,CAAC;EACpB;EAEAC,KAAKA,CAACC,KAAe,EAAE;IACrB;IACA,IAAI,CAACJ,GAAG,CAACG,KAAK,CAAC,CAAC;EAClB;EAEAE,KAAKA,CAAA,EAAG;IACN,OAAO,IAAI,CAACL,GAAG,CAACK,KAAK,CAAC,CAAC;EACzB;EAEAC,MAAMA,CAAA,EAAG;IACP,OAAO,IAAI,CAACN,GAAG,CAACM,MAAM,CAAC,CAAC;EAC1B;EAEAC,SAASA,CAAA,EAAa;IACpB,OAAO,IAAIC,wBAAW,CAAC,IAAI,CAACT,SAAS,EAAE,IAAI,CAACC,GAAG,CAACO,SAAS,CAAC,CAAC,CAAC;EAC9D;EAEAE,iBAAiBA,CAACC,MAAe,EAAEC,WAAwB,EAAW;IACpE,MAAMC,KAAK,GAAG,IAAI,CAACZ,GAAG,CAACS,iBAAiB,CACtCC,MAAM,GACFG,KAAK,CAACC,IAAI,CAACC,oBAAS,CAACC,SAAS,CAAC,IAAI,CAACjB,SAAS,EAAEW,MAAM,CAAC,CAAC,GACvDO,SACN,CAAC;IACD,IAAIN,WAAW,EAAE;MACfA,WAAW,CAACX,GAAG,GAAGY,KAAK;IACzB;IACA,OAAO,IAAIM,sBAAU,CAAC,IAAI,CAACnB,SAAS,EAAEa,KAAK,CAAC;EAC9C;EAEAO,wBAAwBA,CAAA,EAAY;IAClCC,OAAO,CAACC,IAAI,CAAC,6CAA6C,CAAC;IAC3D,OAAO,IAAI;EACb;AACF;AAACC,OAAA,CAAA1B,YAAA,GAAAA,YAAA","ignoreList":[]}
|
|
@@ -7,6 +7,7 @@ declare class NativeReanimatedContainer extends Container {
|
|
|
7
7
|
private mapperId;
|
|
8
8
|
private picture;
|
|
9
9
|
constructor(Skia: Skia, nativeId: number);
|
|
10
|
+
unmount(): void;
|
|
10
11
|
redraw(): void;
|
|
11
12
|
}
|
|
12
13
|
export declare const createContainer: (Skia: Skia, nativeId: number) => StaticContainer | NativeReanimatedContainer;
|
|
@@ -36,9 +36,20 @@ class NativeReanimatedContainer extends _StaticContainer.Container {
|
|
|
36
36
|
_defineProperty(this, "picture", void 0);
|
|
37
37
|
this.picture = Skia.Picture.MakePicture(null);
|
|
38
38
|
}
|
|
39
|
+
unmount() {
|
|
40
|
+
super.unmount();
|
|
41
|
+
if (this.mapperId !== null) {
|
|
42
|
+
// The mapper closure retains the recorder and its resources (e.g.
|
|
43
|
+
// images) on the UI runtime and keeps updating the picture of an
|
|
44
|
+
// unmounted view — stop it or it leaks for the lifetime of the app.
|
|
45
|
+
_ReanimatedProxy.default.stopMapper(this.mapperId);
|
|
46
|
+
this.mapperId = null;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
39
49
|
redraw() {
|
|
40
50
|
if (this.mapperId !== null) {
|
|
41
51
|
_ReanimatedProxy.default.stopMapper(this.mapperId);
|
|
52
|
+
this.mapperId = null;
|
|
42
53
|
}
|
|
43
54
|
if (this.unmounted) {
|
|
44
55
|
return;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_ReanimatedProxy","_interopRequireDefault","require","_renderHelpers","_ReanimatedRecorder","_StaticContainer","_Visitor","e","__esModule","default","_defineProperty","r","t","_toPropertyKey","Object","defineProperty","value","enumerable","configurable","writable","i","_toPrimitive","Symbol","toPrimitive","call","TypeError","String","Number","SkiaViewApi","globalThis","nativeDrawOnscreen","nativeId","recorder","picture","play","setJsiProperty","NativeReanimatedContainer","Container","constructor","Skia","Picture","MakePicture","
|
|
1
|
+
{"version":3,"names":["_ReanimatedProxy","_interopRequireDefault","require","_renderHelpers","_ReanimatedRecorder","_StaticContainer","_Visitor","e","__esModule","default","_defineProperty","r","t","_toPropertyKey","Object","defineProperty","value","enumerable","configurable","writable","i","_toPrimitive","Symbol","toPrimitive","call","TypeError","String","Number","SkiaViewApi","globalThis","nativeDrawOnscreen","nativeId","recorder","picture","play","setJsiProperty","NativeReanimatedContainer","Container","constructor","Skia","Picture","MakePicture","unmount","mapperId","Rea","stopMapper","redraw","unmounted","ReanimatedRecorder","visit","root","sharedValues","getSharedValues","sharedRecorder","getRecorder","runOnUI","length","startMapper","applyUpdates","createContainer","HAS_REANIMATED_3","StaticContainer","exports"],"sources":["Container.native.ts"],"sourcesContent":["import Rea from \"../external/reanimated/ReanimatedProxy\";\nimport type { Skia, SkPicture } from \"../skia/types\";\nimport { HAS_REANIMATED_3 } from \"../external/reanimated/renderHelpers\";\nimport type { JsiRecorder } from \"../skia/types/Recorder\";\n\nimport { ReanimatedRecorder } from \"./Recorder/ReanimatedRecorder\";\nimport { Container, StaticContainer } from \"./StaticContainer\";\nimport { visit } from \"./Recorder/Visitor\";\n\nimport \"../skia/NativeSetup\";\nimport \"../views/api\";\n\n// create local reference for `strictGlobal` option in Worklets\nconst { SkiaViewApi } = globalThis;\n\nconst nativeDrawOnscreen = (\n nativeId: number,\n recorder: JsiRecorder,\n picture: SkPicture\n) => {\n \"worklet\";\n\n //const start = performance.now();\n recorder.play(picture);\n //const end = performance.now();\n //console.log(\"Recording time: \", end - start);\n SkiaViewApi.setJsiProperty(nativeId, \"picture\", picture);\n};\n\nclass NativeReanimatedContainer extends Container {\n private mapperId: number | null = null;\n private picture: SkPicture;\n\n constructor(\n Skia: Skia,\n private nativeId: number\n ) {\n super(Skia);\n this.picture = Skia.Picture.MakePicture(null)!;\n }\n\n unmount() {\n super.unmount();\n if (this.mapperId !== null) {\n // The mapper closure retains the recorder and its resources (e.g.\n // images) on the UI runtime and keeps updating the picture of an\n // unmounted view — stop it or it leaks for the lifetime of the app.\n Rea.stopMapper(this.mapperId);\n this.mapperId = null;\n }\n }\n\n redraw() {\n if (this.mapperId !== null) {\n Rea.stopMapper(this.mapperId);\n this.mapperId = null;\n }\n if (this.unmounted) {\n return;\n }\n const recorder = new ReanimatedRecorder(this.Skia);\n const { nativeId, picture } = this;\n visit(recorder, this.root);\n const sharedValues = recorder.getSharedValues();\n const sharedRecorder = recorder.getRecorder();\n // Draw first frame\n Rea.runOnUI(() => {\n \"worklet\";\n nativeDrawOnscreen(nativeId, sharedRecorder, picture);\n })();\n // Animate\n if (sharedValues.length > 0) {\n this.mapperId = Rea.startMapper(() => {\n \"worklet\";\n sharedRecorder.applyUpdates(sharedValues);\n nativeDrawOnscreen(nativeId, sharedRecorder, picture);\n }, sharedValues);\n }\n }\n}\n\nexport const createContainer = (Skia: Skia, nativeId: number) => {\n if (HAS_REANIMATED_3 && nativeId !== -1) {\n return new NativeReanimatedContainer(Skia, nativeId);\n } else {\n return new StaticContainer(Skia, nativeId);\n }\n};\n"],"mappings":";;;;;;AAAA,IAAAA,gBAAA,GAAAC,sBAAA,CAAAC,OAAA;AAEA,IAAAC,cAAA,GAAAD,OAAA;AAGA,IAAAE,mBAAA,GAAAF,OAAA;AACA,IAAAG,gBAAA,GAAAH,OAAA;AACA,IAAAI,QAAA,GAAAJ,OAAA;AAEAA,OAAA;AACAA,OAAA;AAAsB,SAAAD,uBAAAM,CAAA,WAAAA,CAAA,IAAAA,CAAA,CAAAC,UAAA,GAAAD,CAAA,KAAAE,OAAA,EAAAF,CAAA;AAAA,SAAAG,gBAAAH,CAAA,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AAMQ,eAAe,GAAGA,CAACpB,IAAU,EAAER,QAAgB,KAAK;EAC/D,IAAI6B,+BAAgB,IAAI7B,QAAQ,KAAK,CAAC,CAAC,EAAE;IACvC,OAAO,IAAIK,yBAAyB,CAACG,IAAI,EAAER,QAAQ,CAAC;EACtD,CAAC,MAAM;IACL,OAAO,IAAI8B,gCAAe,CAACtB,IAAI,EAAER,QAAQ,CAAC;EAC5C;AACF,CAAC;AAAC+B,OAAA,CAAAH,eAAA,GAAAA,eAAA","ignoreList":[]}
|
|
@@ -6,6 +6,7 @@ declare class ReanimatedContainer extends Container {
|
|
|
6
6
|
private nativeId;
|
|
7
7
|
private mapperId;
|
|
8
8
|
constructor(Skia: Skia, nativeId: number);
|
|
9
|
+
unmount(): void;
|
|
9
10
|
redraw(): void;
|
|
10
11
|
}
|
|
11
12
|
export declare const createContainer: (Skia: Skia, nativeId: number) => StaticContainer | ReanimatedContainer;
|
|
@@ -24,17 +24,30 @@ const {
|
|
|
24
24
|
const drawOnscreen = (Skia, nativeId, recording) => {
|
|
25
25
|
"worklet";
|
|
26
26
|
|
|
27
|
+
var _recording$lastPictur;
|
|
27
28
|
const rec = Skia.PictureRecorder();
|
|
28
29
|
const canvas = rec.beginRecording();
|
|
29
30
|
//const start = performance.now();
|
|
30
31
|
|
|
31
32
|
const ctx = (0, _DrawingContext.createDrawingContext)(Skia, recording.paintPool, canvas);
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
33
|
+
let picture;
|
|
34
|
+
try {
|
|
35
|
+
(0, _Player.replay)(ctx, recording.commands);
|
|
36
|
+
picture = rec.finishRecordingAsPicture();
|
|
37
|
+
} finally {
|
|
38
|
+
// Frame-scoped objects (shaders, filters, paint copies, ...) are
|
|
39
|
+
// referenced by the picture once it is finished — delete the JS handles,
|
|
40
|
+
// otherwise they leak on Web where the GC cannot see WASM memory.
|
|
41
|
+
ctx.dispose();
|
|
42
|
+
rec.dispose();
|
|
43
|
+
}
|
|
35
44
|
//const end = performance.now();
|
|
36
45
|
//console.log("Recording time: ", end - start);
|
|
37
46
|
SkiaViewApi.setJsiProperty(nativeId, "picture", picture);
|
|
47
|
+
// The view now references the new picture; the previous one is ours to
|
|
48
|
+
// delete.
|
|
49
|
+
(_recording$lastPictur = recording.lastPicture) === null || _recording$lastPictur === void 0 || _recording$lastPictur.dispose();
|
|
50
|
+
recording.lastPicture = picture;
|
|
38
51
|
};
|
|
39
52
|
class ReanimatedContainer extends _StaticContainer.Container {
|
|
40
53
|
constructor(Skia, nativeId) {
|
|
@@ -42,13 +55,38 @@ class ReanimatedContainer extends _StaticContainer.Container {
|
|
|
42
55
|
this.nativeId = nativeId;
|
|
43
56
|
_defineProperty(this, "mapperId", null);
|
|
44
57
|
}
|
|
58
|
+
unmount() {
|
|
59
|
+
super.unmount();
|
|
60
|
+
if (this.mapperId !== null) {
|
|
61
|
+
// The mapper closure retains the recording and keeps updating the
|
|
62
|
+
// picture of an unmounted view — stop it or it leaks for the
|
|
63
|
+
// lifetime of the app.
|
|
64
|
+
_ReanimatedProxy.default.stopMapper(this.mapperId);
|
|
65
|
+
this.mapperId = null;
|
|
66
|
+
}
|
|
67
|
+
const {
|
|
68
|
+
recording
|
|
69
|
+
} = this;
|
|
70
|
+
if (recording) {
|
|
71
|
+
this.recording = null;
|
|
72
|
+
// Deferred through the same channel as the draw calls so it runs after
|
|
73
|
+
// any of them that are still queued.
|
|
74
|
+
_ReanimatedProxy.default.runOnUI(() => {
|
|
75
|
+
"worklet";
|
|
76
|
+
|
|
77
|
+
(0, _Recorder.disposeRecording)(recording);
|
|
78
|
+
})();
|
|
79
|
+
}
|
|
80
|
+
}
|
|
45
81
|
redraw() {
|
|
46
82
|
if (this.mapperId !== null) {
|
|
47
83
|
_ReanimatedProxy.default.stopMapper(this.mapperId);
|
|
84
|
+
this.mapperId = null;
|
|
48
85
|
}
|
|
49
86
|
if (this.unmounted) {
|
|
50
87
|
return;
|
|
51
88
|
}
|
|
89
|
+
const previousRecording = this.recording;
|
|
52
90
|
const recorder = new _Recorder.Recorder();
|
|
53
91
|
(0, _Visitor.visit)(recorder, this.root);
|
|
54
92
|
const record = recorder.getRecording();
|
|
@@ -74,6 +112,10 @@ class ReanimatedContainer extends _StaticContainer.Container {
|
|
|
74
112
|
_ReanimatedProxy.default.runOnUI(() => {
|
|
75
113
|
"worklet";
|
|
76
114
|
|
|
115
|
+
if (previousRecording) {
|
|
116
|
+
// Runs after any still-queued draw of the previous recording.
|
|
117
|
+
(0, _Recorder.disposeRecording)(previousRecording);
|
|
118
|
+
}
|
|
77
119
|
drawOnscreen(Skia, nativeId, recording);
|
|
78
120
|
})();
|
|
79
121
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_ReanimatedProxy","_interopRequireDefault","require","_renderHelpers","_Recorder","_Visitor","_Player","_DrawingContext","_StaticContainer","e","__esModule","default","_defineProperty","r","t","_toPropertyKey","Object","defineProperty","value","enumerable","configurable","writable","i","_toPrimitive","Symbol","toPrimitive","call","TypeError","String","Number","SkiaViewApi","globalThis","drawOnscreen","Skia","nativeId","recording","rec","PictureRecorder","canvas","beginRecording","ctx","createDrawingContext","paintPool","
|
|
1
|
+
{"version":3,"names":["_ReanimatedProxy","_interopRequireDefault","require","_renderHelpers","_Recorder","_Visitor","_Player","_DrawingContext","_StaticContainer","e","__esModule","default","_defineProperty","r","t","_toPropertyKey","Object","defineProperty","value","enumerable","configurable","writable","i","_toPrimitive","Symbol","toPrimitive","call","TypeError","String","Number","SkiaViewApi","globalThis","drawOnscreen","Skia","nativeId","recording","_recording$lastPictur","rec","PictureRecorder","canvas","beginRecording","ctx","createDrawingContext","paintPool","picture","replay","commands","finishRecordingAsPicture","dispose","setJsiProperty","lastPicture","ReanimatedContainer","Container","constructor","unmount","mapperId","Rea","stopMapper","runOnUI","disposeRecording","redraw","unmounted","previousRecording","recorder","Recorder","visit","root","record","getRecording","animationValues","size","startMapper","Array","from","createContainer","HAS_REANIMATED_3","StaticContainer","exports"],"sources":["Container.web.ts"],"sourcesContent":["import Rea from \"../external/reanimated/ReanimatedProxy\";\nimport type { Skia } from \"../skia/types\";\nimport { HAS_REANIMATED_3 } from \"../external/reanimated/renderHelpers\";\n\nimport type { Recording } from \"./Recorder/Recorder\";\nimport { Recorder, disposeRecording } from \"./Recorder/Recorder\";\nimport { visit } from \"./Recorder/Visitor\";\nimport { replay } from \"./Recorder/Player\";\nimport { createDrawingContext } from \"./Recorder/DrawingContext\";\nimport { Container, StaticContainer } from \"./StaticContainer\";\n\nimport \"../skia/NativeSetup\";\nimport \"../views/api\";\n\n// create local reference for `strictGlobal` option in Worklets\nconst { SkiaViewApi } = globalThis;\n\nconst drawOnscreen = (Skia: Skia, nativeId: number, recording: Recording) => {\n \"worklet\";\n const rec = Skia.PictureRecorder();\n const canvas = rec.beginRecording();\n //const start = performance.now();\n\n const ctx = createDrawingContext(Skia, recording.paintPool, canvas);\n let picture;\n try {\n replay(ctx, recording.commands);\n picture = rec.finishRecordingAsPicture();\n } finally {\n // Frame-scoped objects (shaders, filters, paint copies, ...) are\n // referenced by the picture once it is finished — delete the JS handles,\n // otherwise they leak on Web where the GC cannot see WASM memory.\n ctx.dispose();\n rec.dispose();\n }\n //const end = performance.now();\n //console.log(\"Recording time: \", end - start);\n SkiaViewApi.setJsiProperty(nativeId, \"picture\", picture);\n // The view now references the new picture; the previous one is ours to\n // delete.\n recording.lastPicture?.dispose();\n recording.lastPicture = picture;\n};\n\nclass ReanimatedContainer extends Container {\n private mapperId: number | null = null;\n\n constructor(\n Skia: Skia,\n private nativeId: number\n ) {\n super(Skia);\n }\n\n unmount() {\n super.unmount();\n if (this.mapperId !== null) {\n // The mapper closure retains the recording and keeps updating the\n // picture of an unmounted view — stop it or it leaks for the\n // lifetime of the app.\n Rea.stopMapper(this.mapperId);\n this.mapperId = null;\n }\n const { recording } = this;\n if (recording) {\n this.recording = null;\n // Deferred through the same channel as the draw calls so it runs after\n // any of them that are still queued.\n Rea.runOnUI(() => {\n \"worklet\";\n disposeRecording(recording);\n })();\n }\n }\n\n redraw() {\n if (this.mapperId !== null) {\n Rea.stopMapper(this.mapperId);\n this.mapperId = null;\n }\n if (this.unmounted) {\n return;\n }\n const previousRecording = this.recording;\n const recorder = new Recorder();\n visit(recorder, this.root);\n const record = recorder.getRecording();\n const { animationValues } = record;\n this.recording = {\n commands: record.commands,\n paintPool: record.paintPool,\n };\n const { nativeId, Skia, recording } = this;\n if (animationValues.size > 0) {\n this.mapperId = Rea.startMapper(() => {\n \"worklet\";\n drawOnscreen(Skia, nativeId, recording!);\n }, Array.from(animationValues));\n }\n Rea.runOnUI(() => {\n \"worklet\";\n if (previousRecording) {\n // Runs after any still-queued draw of the previous recording.\n disposeRecording(previousRecording);\n }\n drawOnscreen(Skia, nativeId, recording!);\n })();\n }\n}\n\nexport const createContainer = (Skia: Skia, nativeId: number) => {\n if (HAS_REANIMATED_3 && nativeId !== -1) {\n return new ReanimatedContainer(Skia, nativeId);\n } else {\n return new StaticContainer(Skia, nativeId);\n }\n};\n"],"mappings":";;;;;;AAAA,IAAAA,gBAAA,GAAAC,sBAAA,CAAAC,OAAA;AAEA,IAAAC,cAAA,GAAAD,OAAA;AAGA,IAAAE,SAAA,GAAAF,OAAA;AACA,IAAAG,QAAA,GAAAH,OAAA;AACA,IAAAI,OAAA,GAAAJ,OAAA;AACA,IAAAK,eAAA,GAAAL,OAAA;AACA,IAAAM,gBAAA,GAAAN,OAAA;AAEAA,OAAA;AACAA,OAAA;AAAsB,SAAAD,uBAAAQ,CAAA,WAAAA,CAAA,IAAAA,CAAA,CAAAC,UAAA,GAAAD,CAAA,KAAAE,OAAA,EAAAF,CAAA;AAAA,SAAAG,gBAAAH,CAAA,EAAAI,CAAA,EAAAC,CAAA,YAAAD,CAAA,GAAAE,cAAA,CAAAF,CAAA,MAAAJ,CAAA,GAAAO,MAAA,CAAAC,cAAA,CAAAR,CAAA,EAAAI,CAAA,IAAAK,KAAA,EAAAJ,CAAA,EAAAK,UAAA,MAAAC,YA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,CAACK,YAAY,CAAC,CAAC;IACtC,MAAM;MAAEC;IAAgB,CAAC,GAAGF,MAAM;IAClC,IAAI,CAAChC,SAAS,GAAG;MACfW,QAAQ,EAAEqB,MAAM,CAACrB,QAAQ;MACzBH,SAAS,EAAEwB,MAAM,CAACxB;IACpB,CAAC;IACD,MAAM;MAAET,QAAQ;MAAED,IAAI;MAAEE;IAAU,CAAC,GAAG,IAAI;IAC1C,IAAIkC,eAAe,CAACC,IAAI,GAAG,CAAC,EAAE;MAC5B,IAAI,CAACf,QAAQ,GAAGC,wBAAG,CAACe,WAAW,CAAC,MAAM;QACpC,SAAS;;QACTvC,YAAY,CAACC,IAAI,EAAEC,QAAQ,EAAEC,SAAU,CAAC;MAC1C,CAAC,EAAEqC,KAAK,CAACC,IAAI,CAACJ,eAAe,CAAC,CAAC;IACjC;IACAb,wBAAG,CAACE,OAAO,CAAC,MAAM;MAChB,SAAS;;MACT,IAAII,iBAAiB,EAAE;QACrB;QACA,IAAAH,0BAAgB,EAACG,iBAAiB,CAAC;MACrC;MACA9B,YAAY,CAACC,IAAI,EAAEC,QAAQ,EAAEC,SAAU,CAAC;IAC1C,CAAC,CAAC,CAAC,CAAC;EACN;AACF;AAEO,MAAMuC,eAAe,GAAGA,CAACzC,IAAU,EAAEC,QAAgB,KAAK;EAC/D,IAAIyC,+BAAgB,IAAIzC,QAAQ,KAAK,CAAC,CAAC,EAAE;IACvC,OAAO,IAAIiB,mBAAmB,CAAClB,IAAI,EAAEC,QAAQ,CAAC;EAChD,CAAC,MAAM;IACL,OAAO,IAAI0C,gCAAe,CAAC3C,IAAI,EAAEC,QAAQ,CAAC;EAC5C;AACF,CAAC;AAAC2C,OAAA,CAAAH,eAAA,GAAAA,eAAA","ignoreList":[]}
|
|
@@ -2,6 +2,8 @@ import type { Skia, SkCanvas, SkColorFilter, SkPaint, SkShader, SkImageFilter, S
|
|
|
2
2
|
export declare const createDrawingContext: (Skia: Skia, paintPool: SkPaint[], canvas: SkCanvas) => {
|
|
3
3
|
Skia: Skia;
|
|
4
4
|
canvas: SkCanvas;
|
|
5
|
+
track: <T>(value: T) => T;
|
|
6
|
+
dispose: () => void;
|
|
5
7
|
paints: SkPaint[];
|
|
6
8
|
colorFilters: SkColorFilter[];
|
|
7
9
|
shaders: SkShader[];
|
|
@@ -4,9 +4,19 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.createDrawingContext = void 0;
|
|
7
|
+
var _FrameScope = require("./FrameScope");
|
|
7
8
|
const createDrawingContext = (Skia, paintPool, canvas) => {
|
|
8
9
|
"worklet";
|
|
9
10
|
|
|
11
|
+
// Everything the renderer creates through frameSkia is frame-scoped and
|
|
12
|
+
// deleted by dispose() once the frame has been recorded. The paint pool is
|
|
13
|
+
// recording-scoped and deliberately allocated with the raw Skia instance.
|
|
14
|
+
const {
|
|
15
|
+
Skia: frameSkia,
|
|
16
|
+
track,
|
|
17
|
+
dispose
|
|
18
|
+
} = (0, _FrameScope.createFrameScope)(Skia);
|
|
19
|
+
|
|
10
20
|
// State (formerly class fields)
|
|
11
21
|
const paints = [];
|
|
12
22
|
const colorFilters = [];
|
|
@@ -18,7 +28,11 @@ const createDrawingContext = (Skia, paintPool, canvas) => {
|
|
|
18
28
|
let nextPaintIndex = 1;
|
|
19
29
|
|
|
20
30
|
// Initialize first paint and opacity
|
|
21
|
-
paintPool
|
|
31
|
+
if (paintPool.length === 0) {
|
|
32
|
+
paintPool.push(Skia.Paint());
|
|
33
|
+
} else {
|
|
34
|
+
paintPool[0].reset();
|
|
35
|
+
}
|
|
22
36
|
paints.push(paintPool[0]);
|
|
23
37
|
opacities.push(1);
|
|
24
38
|
|
|
@@ -48,7 +62,7 @@ const createDrawingContext = (Skia, paintPool, canvas) => {
|
|
|
48
62
|
} else {
|
|
49
63
|
const cf = colorFilters.pop();
|
|
50
64
|
if (cf) {
|
|
51
|
-
imageFilter =
|
|
65
|
+
imageFilter = frameSkia.ImageFilter.MakeColorFilter(cf, null);
|
|
52
66
|
}
|
|
53
67
|
}
|
|
54
68
|
canvas.saveLayer(undefined, null, imageFilter);
|
|
@@ -66,7 +80,7 @@ const createDrawingContext = (Skia, paintPool, canvas) => {
|
|
|
66
80
|
const materializePaint = () => {
|
|
67
81
|
// Color Filters
|
|
68
82
|
if (colorFilters.length > 0) {
|
|
69
|
-
getCurrentPaint().setColorFilter(colorFilters.reduceRight((inner, outer) => inner ?
|
|
83
|
+
getCurrentPaint().setColorFilter(colorFilters.reduceRight((inner, outer) => inner ? frameSkia.ColorFilter.MakeCompose(outer, inner) : outer));
|
|
70
84
|
}
|
|
71
85
|
// Shaders
|
|
72
86
|
if (shaders.length > 0) {
|
|
@@ -74,12 +88,12 @@ const createDrawingContext = (Skia, paintPool, canvas) => {
|
|
|
74
88
|
}
|
|
75
89
|
// Image Filters
|
|
76
90
|
if (imageFilters.length > 0) {
|
|
77
|
-
getCurrentPaint().setImageFilter(imageFilters.reduceRight((inner, outer) => inner ?
|
|
91
|
+
getCurrentPaint().setImageFilter(imageFilters.reduceRight((inner, outer) => inner ? frameSkia.ImageFilter.MakeCompose(outer, inner) : outer));
|
|
78
92
|
}
|
|
79
93
|
|
|
80
94
|
// Path Effects
|
|
81
95
|
if (pathEffects.length > 0) {
|
|
82
|
-
getCurrentPaint().setPathEffect(pathEffects.reduceRight((inner, outer) => inner ?
|
|
96
|
+
getCurrentPaint().setPathEffect(pathEffects.reduceRight((inner, outer) => inner ? frameSkia.PathEffect.MakeCompose(outer, inner) : outer));
|
|
83
97
|
}
|
|
84
98
|
|
|
85
99
|
// Clear arrays
|
|
@@ -92,8 +106,10 @@ const createDrawingContext = (Skia, paintPool, canvas) => {
|
|
|
92
106
|
// Return an object containing the Skia reference, the canvas, and the methods
|
|
93
107
|
return {
|
|
94
108
|
// Public fields
|
|
95
|
-
Skia,
|
|
109
|
+
Skia: frameSkia,
|
|
96
110
|
canvas,
|
|
111
|
+
track,
|
|
112
|
+
dispose,
|
|
97
113
|
paints,
|
|
98
114
|
colorFilters,
|
|
99
115
|
shaders,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["createDrawingContext","Skia","paintPool","canvas","paints","colorFilters","shaders","imageFilters","pathEffects","paintDeclarations","opacities","nextPaintIndex","
|
|
1
|
+
{"version":3,"names":["_FrameScope","require","createDrawingContext","Skia","paintPool","canvas","frameSkia","track","dispose","createFrameScope","paints","colorFilters","shaders","imageFilters","pathEffects","paintDeclarations","opacities","nextPaintIndex","length","push","Paint","reset","savePaint","nextPaint","assign","getCurrentPaint","getOpacity","setOpacity","newOpacity","Math","max","min","saveBackdropFilter","imageFilter","imgf","pop","cf","ImageFilter","MakeColorFilter","saveLayer","undefined","restore","restorePaint","materializePaint","setColorFilter","reduceRight","inner","outer","ColorFilter","MakeCompose","setShader","setImageFilter","setPathEffect","PathEffect","paint","exports"],"sources":["DrawingContext.ts"],"sourcesContent":["import type {\n Skia,\n SkCanvas,\n SkColorFilter,\n SkPaint,\n SkShader,\n SkImageFilter,\n SkPathEffect,\n} from \"../../skia/types\";\n\nimport { createFrameScope } from \"./FrameScope\";\n\nexport const createDrawingContext = (\n Skia: Skia,\n paintPool: SkPaint[],\n canvas: SkCanvas\n) => {\n \"worklet\";\n\n // Everything the renderer creates through frameSkia is frame-scoped and\n // deleted by dispose() once the frame has been recorded. The paint pool is\n // recording-scoped and deliberately allocated with the raw Skia instance.\n const { Skia: frameSkia, track, dispose } = createFrameScope(Skia);\n\n // State (formerly class fields)\n const paints: SkPaint[] = [];\n const colorFilters: SkColorFilter[] = [];\n const shaders: SkShader[] = [];\n const imageFilters: SkImageFilter[] = [];\n const pathEffects: SkPathEffect[] = [];\n const paintDeclarations: SkPaint[] = [];\n const opacities: number[] = [];\n\n let nextPaintIndex = 1;\n\n // Initialize first paint and opacity\n if (paintPool.length === 0) {\n paintPool.push(Skia.Paint());\n } else {\n paintPool[0].reset();\n }\n paints.push(paintPool[0]);\n opacities.push(1);\n\n // Methods (formerly class methods)\n const savePaint = () => {\n // Get next available paint from pool or create new one if needed\n if (nextPaintIndex >= paintPool.length) {\n paintPool.push(Skia.Paint());\n }\n\n const nextPaint = paintPool[nextPaintIndex];\n nextPaint.assign(getCurrentPaint()); // Reuse allocation by copying properties\n paints.push(nextPaint);\n opacities.push(opacities[opacities.length - 1]);\n nextPaintIndex++;\n };\n\n const getOpacity = () => {\n return opacities[opacities.length - 1];\n };\n\n const setOpacity = (newOpacity: number) => {\n opacities[opacities.length - 1] = Math.max(0, Math.min(1, newOpacity));\n };\n\n const saveBackdropFilter = () => {\n let imageFilter: SkImageFilter | null = null;\n const imgf = imageFilters.pop();\n if (imgf) {\n imageFilter = imgf;\n } else {\n const cf = colorFilters.pop();\n if (cf) {\n imageFilter = frameSkia.ImageFilter.MakeColorFilter(cf, null);\n }\n }\n canvas.saveLayer(undefined, null, imageFilter);\n canvas.restore();\n };\n\n // Equivalent to the `get paint()` getter in the original class\n const getCurrentPaint = () => {\n return paints[paints.length - 1];\n };\n\n const restorePaint = () => {\n opacities.pop();\n return paints.pop();\n };\n\n const materializePaint = () => {\n // Color Filters\n if (colorFilters.length > 0) {\n getCurrentPaint().setColorFilter(\n colorFilters.reduceRight((inner, outer) =>\n inner ? frameSkia.ColorFilter.MakeCompose(outer, inner) : outer\n )\n );\n }\n // Shaders\n if (shaders.length > 0) {\n getCurrentPaint().setShader(shaders[shaders.length - 1]);\n }\n // Image Filters\n if (imageFilters.length > 0) {\n getCurrentPaint().setImageFilter(\n imageFilters.reduceRight((inner, outer) =>\n inner ? frameSkia.ImageFilter.MakeCompose(outer, inner) : outer\n )\n );\n }\n\n // Path Effects\n if (pathEffects.length > 0) {\n getCurrentPaint().setPathEffect(\n pathEffects.reduceRight((inner, outer) =>\n inner ? frameSkia.PathEffect.MakeCompose(outer, inner) : outer\n )\n );\n }\n\n // Clear arrays\n colorFilters.length = 0;\n shaders.length = 0;\n imageFilters.length = 0;\n pathEffects.length = 0;\n };\n\n // Return an object containing the Skia reference, the canvas, and the methods\n return {\n // Public fields\n Skia: frameSkia,\n canvas,\n track,\n dispose,\n paints,\n colorFilters,\n shaders,\n imageFilters,\n pathEffects,\n paintDeclarations,\n paintPool,\n\n // Public methods\n savePaint,\n saveBackdropFilter,\n get paint() {\n return paints[paints.length - 1];\n }, // the \"getter\" for the current paint\n restorePaint,\n materializePaint,\n getOpacity,\n setOpacity,\n };\n};\n\nexport type DrawingContext = ReturnType<typeof createDrawingContext>;\n"],"mappings":";;;;;;AAUA,IAAAA,WAAA,GAAAC,OAAA;AAEO,MAAMC,oBAAoB,GAAGA,CAClCC,IAAU,EACVC,SAAoB,EACpBC,MAAgB,KACb;EACH,SAAS;;EAET;EACA;EACA;EACA,MAAM;IAAEF,IAAI,EAAEG,SAAS;IAAEC,KAAK;IAAEC;EAAQ,CAAC,GAAG,IAAAC,4BAAgB,EAACN,IAAI,CAAC;;EAElE;EACA,MAAMO,MAAiB,GAAG,EAAE;EAC5B,MAAMC,YAA6B,GAAG,EAAE;EACxC,MAAMC,OAAmB,GAAG,EAAE;EAC9B,MAAMC,YAA6B,GAAG,EAAE;EACxC,MAAMC,WAA2B,GAAG,EAAE;EACtC,MAAMC,iBAA4B,GAAG,EAAE;EACvC,MAAMC,SAAmB,GAAG,EAAE;EAE9B,IAAIC,cAAc,GAAG,CAAC;;EAEtB;EACA,IAAIb,SAAS,CAACc,MAAM,KAAK,CAAC,EAAE;IAC1Bd,SAAS,CAACe,IAAI,CAAChB,IAAI,CAACiB,KAAK,CAAC,CAAC,CAAC;EAC9B,CAAC,MAAM;IACLhB,SAAS,CAAC,CAAC,CAAC,CAACiB,KAAK,CAAC,CAAC;EACtB;EACAX,MAAM,CAACS,IAAI,CAACf,SAAS,CAAC,CAAC,CAAC,CAAC;EACzBY,SAAS,CAACG,IAAI,CAAC,CAAC,CAAC;;EAEjB;EACA,MAAMG,SAAS,GAAGA,CAAA,KAAM;IACtB;IACA,IAAIL,cAAc,IAAIb,SAAS,CAACc,MAAM,EA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YAAY,CAACO,MAAM,GAAG,CAAC;IACvBN,OAAO,CAACM,MAAM,GAAG,CAAC;IAClBL,YAAY,CAACK,MAAM,GAAG,CAAC;IACvBJ,WAAW,CAACI,MAAM,GAAG,CAAC;EACxB,CAAC;;EAED;EACA,OAAO;IACL;IACAf,IAAI,EAAEG,SAAS;IACfD,MAAM;IACNE,KAAK;IACLC,OAAO;IACPE,MAAM;IACNC,YAAY;IACZC,OAAO;IACPC,YAAY;IACZC,WAAW;IACXC,iBAAiB;IACjBX,SAAS;IAET;IACAkB,SAAS;IACTU,kBAAkB;IAClB,IAAIsB,KAAKA,CAAA,EAAG;MACV,OAAO5C,MAAM,CAACA,MAAM,CAACQ,MAAM,GAAG,CAAC,CAAC;IAClC,CAAC;IAAE;IACHwB,YAAY;IACZC,gBAAgB;IAChBjB,UAAU;IACVC;EACF,CAAC;AACH,CAAC;AAAC4B,OAAA,CAAArD,oBAAA,GAAAA,oBAAA","ignoreList":[]}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { Skia } from "../../skia/types";
|
|
2
|
+
export interface FrameScope {
|
|
3
|
+
Skia: Skia;
|
|
4
|
+
track: <T>(value: T) => T;
|
|
5
|
+
dispose: () => void;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Wraps a Skia instance so that every object created through its factories is
|
|
9
|
+
* collected and deleted when the scope is disposed. The renderer only keeps
|
|
10
|
+
* the objects it creates alive for the duration of a frame: once the frame
|
|
11
|
+
* has been recorded they can be deleted. This is required on Web where
|
|
12
|
+
* CanvasKit objects live in WASM memory that the JS garbage collector does
|
|
13
|
+
* not perceive, so it (almost) never reclaims them on its own.
|
|
14
|
+
*
|
|
15
|
+
* Objects passed in via props are user-owned: they are not created through
|
|
16
|
+
* this facade and are therefore never tracked nor disposed.
|
|
17
|
+
*/
|
|
18
|
+
export declare const createFrameScope: (Skia: Skia) => FrameScope;
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.createFrameScope = void 0;
|
|
7
|
+
const isDisposable = value => {
|
|
8
|
+
"worklet";
|
|
9
|
+
|
|
10
|
+
return value !== null && typeof value === "object" && typeof value.dispose === "function";
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* Wraps a Skia instance so that every object created through its factories is
|
|
14
|
+
* collected and deleted when the scope is disposed. The renderer only keeps
|
|
15
|
+
* the objects it creates alive for the duration of a frame: once the frame
|
|
16
|
+
* has been recorded they can be deleted. This is required on Web where
|
|
17
|
+
* CanvasKit objects live in WASM memory that the JS garbage collector does
|
|
18
|
+
* not perceive, so it (almost) never reclaims them on its own.
|
|
19
|
+
*
|
|
20
|
+
* Objects passed in via props are user-owned: they are not created through
|
|
21
|
+
* this facade and are therefore never tracked nor disposed.
|
|
22
|
+
*/
|
|
23
|
+
const createFrameScope = Skia => {
|
|
24
|
+
"worklet";
|
|
25
|
+
|
|
26
|
+
const disposables = [];
|
|
27
|
+
const track = value => {
|
|
28
|
+
if (isDisposable(value)) {
|
|
29
|
+
disposables.push(value);
|
|
30
|
+
}
|
|
31
|
+
return value;
|
|
32
|
+
};
|
|
33
|
+
const wrap = obj => {
|
|
34
|
+
const cache = new Map();
|
|
35
|
+
return new Proxy(obj, {
|
|
36
|
+
get(target, prop) {
|
|
37
|
+
if (cache.has(prop)) {
|
|
38
|
+
return cache.get(prop);
|
|
39
|
+
}
|
|
40
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
41
|
+
const value = target[prop];
|
|
42
|
+
let wrapped = value;
|
|
43
|
+
if (typeof value === "function") {
|
|
44
|
+
wrapped = (...args) => track(value.apply(target, args));
|
|
45
|
+
} else if (value !== null && typeof value === "object") {
|
|
46
|
+
wrapped = wrap(value);
|
|
47
|
+
}
|
|
48
|
+
cache.set(prop, wrapped);
|
|
49
|
+
return wrapped;
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
};
|
|
53
|
+
const dispose = () => {
|
|
54
|
+
for (let i = 0; i < disposables.length; i++) {
|
|
55
|
+
disposables[i].dispose();
|
|
56
|
+
}
|
|
57
|
+
disposables.length = 0;
|
|
58
|
+
};
|
|
59
|
+
return {
|
|
60
|
+
Skia: wrap(Skia),
|
|
61
|
+
track,
|
|
62
|
+
dispose
|
|
63
|
+
};
|
|
64
|
+
};
|
|
65
|
+
exports.createFrameScope = createFrameScope;
|
|
66
|
+
//# sourceMappingURL=FrameScope.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["isDisposable","value","dispose","createFrameScope","Skia","disposables","track","push","wrap","obj","cache","Map","Proxy","get","target","prop","has","wrapped","args","apply","set","i","length","exports"],"sources":["FrameScope.ts"],"sourcesContent":["import type { Skia } from \"../../skia/types\";\n\ninterface Disposable {\n dispose: () => void;\n}\n\nconst isDisposable = (value: unknown): value is Disposable => {\n \"worklet\";\n return (\n value !== null &&\n typeof value === \"object\" &&\n typeof (value as Disposable).dispose === \"function\"\n );\n};\n\nexport interface FrameScope {\n Skia: Skia;\n track: <T>(value: T) => T;\n dispose: () => void;\n}\n\n/**\n * Wraps a Skia instance so that every object created through its factories is\n * collected and deleted when the scope is disposed. The renderer only keeps\n * the objects it creates alive for the duration of a frame: once the frame\n * has been recorded they can be deleted. This is required on Web where\n * CanvasKit objects live in WASM memory that the JS garbage collector does\n * not perceive, so it (almost) never reclaims them on its own.\n *\n * Objects passed in via props are user-owned: they are not created through\n * this facade and are therefore never tracked nor disposed.\n */\nexport const createFrameScope = (Skia: Skia): FrameScope => {\n \"worklet\";\n const disposables: Disposable[] = [];\n const track = <T>(value: T): T => {\n if (isDisposable(value)) {\n disposables.push(value);\n }\n return value;\n };\n const wrap = <T extends object>(obj: T): T => {\n const cache = new Map<PropertyKey, unknown>();\n return new Proxy(obj, {\n get(target, prop) {\n if (cache.has(prop)) {\n return cache.get(prop);\n }\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const value = (target as any)[prop];\n let wrapped: unknown = value;\n if (typeof value === \"function\") {\n wrapped = (...args: unknown[]) => track(value.apply(target, args));\n } else if (value !== null && typeof value === \"object\") {\n wrapped = wrap(value);\n }\n cache.set(prop, wrapped);\n return wrapped;\n },\n }) as T;\n };\n const dispose = () => {\n for (let i = 0; i < disposables.length; i++) {\n disposables[i].dispose();\n }\n disposables.length = 0;\n };\n return { Skia: wrap(Skia), track, dispose };\n};\n"],"mappings":";;;;;;AAMA,MAAMA,YAAY,GAAIC,KAAc,IAA0B;EAC5D,SAAS;;EACT,OACEA,KAAK,KAAK,IAAI,IACd,OAAOA,KAAK,KAAK,QAAQ,IACzB,OAAQA,KAAK,CAAgBC,OAAO,KAAK,UAAU;AAEvD,CAAC;AAQD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,MAAMC,gBAAgB,GAAIC,IAAU,IAAiB;EAC1D,SAAS;;EACT,MAAMC,WAAyB,GAAG,EAAE;EACpC,MAAMC,KAAK,GAAOL,KAAQ,IAAQ;IAChC,IAAID,YAAY,CAACC,KAAK,CAAC,EAAE;MACvBI,WAAW,CAACE,IAAI,CAACN,KAAK,CAAC;IACzB;IACA,OAAOA,KAAK;EACd,CAAC;EACD,MAAMO,IAAI,GAAsBC,GAAM,IAAQ;IAC5C,MAAMC,KAAK,GAAG,IAAIC,GAAG,CAAuB,CAAC;IAC7C,OAAO,IAAIC,KAAK,CAACH,GAAG,EAAE;MACpBI,GAAGA,CAACC,MAAM,EAAEC,IAAI,EAAE;QAChB,IAAIL,KAAK,CAACM,GAAG,CAACD,IAAI,CAAC,EAAE;UACnB,OAAOL,KAAK,CAACG,GAAG,CAACE,IAAI,CAAC;QACxB;QACA;QACA,MAAMd,KAAK,GAAIa,MAAM,CAASC,IAAI,CAAC;QACnC,IAAIE,OAAgB,GAAGhB,KAAK;QAC5B,IAAI,OAAOA,KAAK,KAAK,UAAU,EAAE;UAC/BgB,OAAO,GAAGA,CAAC,GAAGC,IAAe,KAAKZ,KAAK,CAACL,KAAK,CAACkB,KAAK,CAACL,MAAM,EAAEI,IAAI,CAAC,CAAC;QACpE,CAAC,MAAM,IAAIjB,KAAK,KAAK,IAAI,IAAI,OAAOA,KAAK,KAAK,QAAQ,EAAE;UACtDgB,OAAO,GAAGT,IAAI,CAACP,KAAK,CAAC;QACvB;QACAS,KAAK,CAACU,GAAG,CAACL,IAAI,EAAEE,OAAO,CAAC;QACxB,OAAOA,OAAO;MAChB;IACF,CAAC,CAAC;EACJ,CAAC;EACD,MAAMf,OAAO,GAAGA,CAAA,KAAM;IACpB,KAAK,IAAImB,CAAC,GAAG,CAAC,EAAEA,CAAC,GAAGhB,WAAW,CAACiB,MAAM,EAAED,CAAC,EAAE,EAAE;MAC3ChB,WAAW,CAACgB,CAAC,CAAC,CAACnB,OAAO,CAAC,CAAC;IAC1B;IACAG,WAAW,CAACiB,MAAM,GAAG,CAAC;EACxB,CAAC;EACD,OAAO;IAAElB,IAAI,EAAEI,IAAI,CAACJ,IAAI,CAAC;IAAEE,KAAK;IAAEJ;EAAQ,CAAC;AAC7C,CAAC;AAACqB,OAAA,CAAApB,gBAAA,GAAAA,gBAAA","ignoreList":[]}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { Skia } from "../../skia/types";
|
|
2
|
+
import type { FrameScope } from "./FrameScope";
|
|
3
|
+
/**
|
|
4
|
+
* No-op on native. The JSI wrappers report the size of the native objects
|
|
5
|
+
* they hold to the garbage collector (setExternalMemoryPressure), so the GC
|
|
6
|
+
* is aware of the real cost of the objects the renderer creates and reclaims
|
|
7
|
+
* them on its own. The tracking scope is only needed on Web, where CanvasKit
|
|
8
|
+
* objects live in WASM memory the GC cannot see (see FrameScope.ts).
|
|
9
|
+
*/
|
|
10
|
+
export declare const createFrameScope: (Skia: Skia) => FrameScope;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.createFrameScope = void 0;
|
|
7
|
+
/**
|
|
8
|
+
* No-op on native. The JSI wrappers report the size of the native objects
|
|
9
|
+
* they hold to the garbage collector (setExternalMemoryPressure), so the GC
|
|
10
|
+
* is aware of the real cost of the objects the renderer creates and reclaims
|
|
11
|
+
* them on its own. The tracking scope is only needed on Web, where CanvasKit
|
|
12
|
+
* objects live in WASM memory the GC cannot see (see FrameScope.ts).
|
|
13
|
+
*/
|
|
14
|
+
const createFrameScope = Skia => {
|
|
15
|
+
"worklet";
|
|
16
|
+
|
|
17
|
+
return {
|
|
18
|
+
Skia,
|
|
19
|
+
track: value => value,
|
|
20
|
+
dispose: () => {
|
|
21
|
+
// nothing to dispose: no objects are tracked on native
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
};
|
|
25
|
+
exports.createFrameScope = createFrameScope;
|
|
26
|
+
//# sourceMappingURL=FrameScope.native.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["createFrameScope","Skia","track","value","dispose","exports"],"sources":["FrameScope.native.ts"],"sourcesContent":["import type { Skia } from \"../../skia/types\";\n\nimport type { FrameScope } from \"./FrameScope\";\n\n/**\n * No-op on native. The JSI wrappers report the size of the native objects\n * they hold to the garbage collector (setExternalMemoryPressure), so the GC\n * is aware of the real cost of the objects the renderer creates and reclaims\n * them on its own. The tracking scope is only needed on Web, where CanvasKit\n * objects live in WASM memory the GC cannot see (see FrameScope.ts).\n */\nexport const createFrameScope = (Skia: Skia): FrameScope => {\n \"worklet\";\n return {\n Skia,\n track: <T>(value: T): T => value,\n dispose: () => {\n // nothing to dispose: no objects are tracked on native\n },\n };\n};\n"],"mappings":";;;;;;AAIA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,MAAMA,gBAAgB,GAAIC,IAAU,IAAiB;EAC1D,SAAS;;EACT,OAAO;IACLA,IAAI;IACJC,KAAK,EAAMC,KAAQ,IAAQA,KAAK;IAChCC,OAAO,EAAEA,CAAA,KAAM;MACb;IAAA;EAEJ,CAAC;AACH,CAAC;AAACC,OAAA,CAAAL,gBAAA,GAAAA,gBAAA","ignoreList":[]}
|
|
@@ -116,9 +116,8 @@ const play = (ctx, _command) => {
|
|
|
116
116
|
} else if ((0, _Core.isCommand)(command, _Core.CommandType.RestoreCTM)) {
|
|
117
117
|
ctx.canvas.restore();
|
|
118
118
|
} else {
|
|
119
|
-
// TODO: is a copy needed here?
|
|
120
119
|
// apply opacity to the current paint.
|
|
121
|
-
const paint = ctx.paint.copy();
|
|
120
|
+
const paint = ctx.track(ctx.paint.copy());
|
|
122
121
|
paint.setAlphaf(paint.getAlphaf() * ctx.getOpacity());
|
|
123
122
|
const paints = [paint, ...ctx.paintDeclarations];
|
|
124
123
|
ctx.paintDeclarations = [];
|