@shopify/react-native-skia 2.11.0 → 2.11.2-next.1
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/rnskia-android/RNSkAndroidPlatformContext.h +0 -10
- package/android/src/main/java/com/shopify/reactnative/skia/ViewScreenshotService.java +9 -12
- package/apple/RNSkApplePlatformContext.h +0 -3
- package/apple/RNSkApplePlatformContext.mm +0 -11
- package/cpp/api/JsiSkApi.h +0 -6
- package/cpp/api/JsiSkFont.h +5 -10
- package/cpp/api/JsiSkMatrix.h +4 -2
- package/cpp/api/recorder/Convertor.h +5 -2
- package/cpp/api/recorder/Drawings.h +13 -3
- package/cpp/api/recorder/ImageFilters.h +15 -1
- package/cpp/api/recorder/Paint.h +8 -1
- package/cpp/dawn/include/dawn/dawn_proc.h +53 -0
- package/cpp/dawn/include/dawn/dawn_proc_table.h +330 -0
- package/cpp/dawn/include/dawn/dawn_thread_dispatch_proc.h +47 -0
- package/cpp/dawn/include/dawn/dawn_version.h +41 -0
- package/cpp/dawn/include/dawn/native/D3D11Backend.h +65 -0
- package/cpp/dawn/include/dawn/native/D3D12Backend.h +103 -0
- package/cpp/dawn/include/dawn/native/D3DBackend.h +56 -0
- package/cpp/dawn/include/dawn/native/DawnNative.h +368 -0
- package/cpp/dawn/include/dawn/native/MetalBackend.h +56 -0
- package/cpp/dawn/include/dawn/native/NullBackend.h +39 -0
- package/cpp/dawn/include/dawn/native/OpenGLBackend.h +89 -0
- package/cpp/dawn/include/dawn/native/VulkanBackend.h +183 -0
- package/cpp/dawn/include/dawn/native/WebGPUBackend.h +49 -0
- package/cpp/dawn/include/dawn/native/dawn_native_export.h +49 -0
- package/cpp/dawn/include/dawn/platform/DawnPlatform.h +207 -0
- package/cpp/dawn/include/dawn/platform/dawn_platform_export.h +49 -0
- package/cpp/dawn/include/dawn/replay/Replay.h +99 -0
- package/cpp/dawn/include/dawn/replay/dawn_replay_export.h +49 -0
- package/cpp/dawn/include/dawn/webgpu_cpp_print.h +2856 -0
- package/cpp/dawn/include/tint/tint.h +91 -0
- package/cpp/dawn/include/webgpu/webgpu.h +5029 -0
- package/cpp/dawn/include/webgpu/webgpu_cpp.h +10353 -0
- package/cpp/dawn/include/webgpu/webgpu_cpp_chained_struct.h +57 -0
- package/cpp/dawn/include/webgpu/webgpu_enum_class_bitmasks.h +162 -0
- package/cpp/dawn/include/webgpu/webgpu_glfw.h +88 -0
- package/cpp/jsi/NativeObject.h +50 -32
- package/cpp/jsi/RuntimeAwareCache.cpp +1 -0
- package/cpp/jsi/RuntimeAwareCache.h +29 -0
- package/cpp/rnskia/RNSkManager.cpp +5 -0
- package/cpp/rnskia/RNSkPlatformContext.h +0 -3
- package/cpp/skia/src/gpu/graphite/ContextOptionsPriv.h +45 -0
- package/cpp/skia/src/gpu/graphite/ResourceTypes.h +360 -0
- package/cpp/skia/src/gpu/graphite/TextureProxyView.h +105 -0
- package/lib/commonjs/dom/nodes/datatypes/Rect.js +5 -1
- package/lib/commonjs/dom/nodes/datatypes/Rect.js.map +1 -1
- package/lib/commonjs/external/reanimated/useVideo.js +8 -2
- package/lib/commonjs/external/reanimated/useVideo.js.map +1 -1
- package/lib/commonjs/renderer/components/Mask.js +3 -9
- package/lib/commonjs/renderer/components/Mask.js.map +1 -1
- package/lib/commonjs/skia/types/JsiInstance.d.ts +1 -0
- package/lib/commonjs/skia/types/JsiInstance.js.map +1 -1
- package/lib/commonjs/skia/types/Matrix4.js +7 -2
- package/lib/commonjs/skia/types/Matrix4.js.map +1 -1
- package/lib/commonjs/skia/types/Skia.d.ts +1 -6
- package/lib/commonjs/skia/types/Skia.js.map +1 -1
- package/lib/commonjs/skia/web/JsiSkia.js +0 -3
- package/lib/commonjs/skia/web/JsiSkia.js.map +1 -1
- package/lib/commonjs/sksg/Recorder/DrawingContext.d.ts +1 -0
- package/lib/commonjs/sksg/Recorder/DrawingContext.js +15 -0
- package/lib/commonjs/sksg/Recorder/DrawingContext.js.map +1 -1
- package/lib/commonjs/sksg/Recorder/Player.js +1 -1
- package/lib/commonjs/sksg/Recorder/Player.js.map +1 -1
- package/lib/commonjs/sksg/Recorder/Visitor.js +6 -1
- package/lib/commonjs/sksg/Recorder/Visitor.js.map +1 -1
- package/lib/commonjs/sksg/Recorder/commands/Drawing.js +10 -8
- package/lib/commonjs/sksg/Recorder/commands/Drawing.js.map +1 -1
- package/lib/commonjs/sksg/Recorder/commands/ImageFilters.js +15 -1
- package/lib/commonjs/sksg/Recorder/commands/ImageFilters.js.map +1 -1
- package/lib/commonjs/sksg/Recorder/commands/Shaders.js +1 -1
- package/lib/commonjs/sksg/Recorder/commands/Shaders.js.map +1 -1
- package/lib/commonjs/views/SkiaPictureView.web.js +19 -14
- package/lib/commonjs/views/SkiaPictureView.web.js.map +1 -1
- package/lib/module/dom/nodes/datatypes/Rect.js +5 -1
- package/lib/module/dom/nodes/datatypes/Rect.js.map +1 -1
- package/lib/module/external/reanimated/useVideo.js +8 -2
- package/lib/module/external/reanimated/useVideo.js.map +1 -1
- package/lib/module/renderer/components/Mask.js +3 -9
- package/lib/module/renderer/components/Mask.js.map +1 -1
- package/lib/module/skia/types/JsiInstance.d.ts +1 -0
- package/lib/module/skia/types/JsiInstance.js.map +1 -1
- package/lib/module/skia/types/Matrix4.js +7 -2
- package/lib/module/skia/types/Matrix4.js.map +1 -1
- package/lib/module/skia/types/Skia.d.ts +1 -6
- package/lib/module/skia/types/Skia.js.map +1 -1
- package/lib/module/skia/web/JsiSkia.js +0 -3
- package/lib/module/skia/web/JsiSkia.js.map +1 -1
- package/lib/module/sksg/Recorder/DrawingContext.d.ts +1 -0
- package/lib/module/sksg/Recorder/DrawingContext.js +15 -0
- package/lib/module/sksg/Recorder/DrawingContext.js.map +1 -1
- package/lib/module/sksg/Recorder/Player.js +1 -1
- package/lib/module/sksg/Recorder/Player.js.map +1 -1
- package/lib/module/sksg/Recorder/Visitor.js +6 -1
- package/lib/module/sksg/Recorder/Visitor.js.map +1 -1
- package/lib/module/sksg/Recorder/commands/Drawing.js +10 -8
- package/lib/module/sksg/Recorder/commands/Drawing.js.map +1 -1
- package/lib/module/sksg/Recorder/commands/ImageFilters.js +15 -1
- package/lib/module/sksg/Recorder/commands/ImageFilters.js.map +1 -1
- package/lib/module/sksg/Recorder/commands/Shaders.js +1 -1
- package/lib/module/sksg/Recorder/commands/Shaders.js.map +1 -1
- package/lib/module/views/SkiaPictureView.web.js +19 -14
- package/lib/module/views/SkiaPictureView.web.js.map +1 -1
- package/lib/typescript/lib/commonjs/skia/web/JsiSkia.d.ts +0 -1
- package/lib/typescript/lib/commonjs/sksg/Recorder/DrawingContext.d.ts +1 -0
- package/lib/typescript/lib/module/skia/Skia.web.d.ts +0 -1
- package/lib/typescript/lib/module/skia/web/JsiSkia.d.ts +0 -1
- package/lib/typescript/lib/module/sksg/Recorder/DrawingContext.d.ts +1 -0
- package/lib/typescript/src/skia/types/JsiInstance.d.ts +1 -0
- package/lib/typescript/src/skia/types/Skia.d.ts +1 -6
- package/lib/typescript/src/sksg/Recorder/DrawingContext.d.ts +1 -0
- package/libs/.graphite +1 -0
- package/package.json +6 -6
- package/src/dom/nodes/datatypes/Rect.ts +6 -1
- package/src/external/reanimated/useVideo.ts +7 -2
- package/src/renderer/components/Mask.tsx +10 -3
- package/src/skia/types/JsiInstance.ts +2 -0
- package/src/skia/types/Matrix4.ts +6 -2
- package/src/skia/types/Skia.ts +1 -7
- package/src/skia/web/JsiSkia.ts +0 -4
- package/src/sksg/Recorder/DrawingContext.ts +15 -0
- package/src/sksg/Recorder/Player.ts +1 -1
- package/src/sksg/Recorder/Visitor.ts +9 -6
- package/src/sksg/Recorder/commands/Drawing.ts +10 -8
- package/src/sksg/Recorder/commands/ImageFilters.ts +20 -1
- package/src/sksg/Recorder/commands/Shaders.ts +1 -1
- package/src/views/SkiaPictureView.web.tsx +17 -14
- package/cpp/api/JsiSkiaContext.h +0 -94
|
@@ -20,17 +20,24 @@ export const Mask = ({
|
|
|
20
20
|
}: MaskProps) => {
|
|
21
21
|
return (
|
|
22
22
|
<Group layer>
|
|
23
|
+
{children}
|
|
24
|
+
{/* The children composite against each other in the layer above; the
|
|
25
|
+
mask is then applied once, when its own layer is restored. A blend
|
|
26
|
+
mode attached to a <Group> without a layer would instead be applied
|
|
27
|
+
per draw call, compositing every child after the first against the
|
|
28
|
+
previous child rather than against the mask (issue #3254).
|
|
29
|
+
dstIn keeps the children where the mask is opaque and erases them
|
|
30
|
+
where it is transparent. Without clip, dstATop additionally keeps
|
|
31
|
+
the mask artwork itself wherever the children leave it uncovered. */}
|
|
23
32
|
<Group
|
|
24
33
|
layer={
|
|
25
|
-
<Paint blendMode="
|
|
34
|
+
<Paint blendMode={clip ? "dstIn" : "dstATop"}>
|
|
26
35
|
{mode === "luminance" && <LumaColorFilter />}
|
|
27
36
|
</Paint>
|
|
28
37
|
}
|
|
29
38
|
>
|
|
30
39
|
{mask}
|
|
31
|
-
{clip && <Group layer={<Paint blendMode="dstIn" />}>{children}</Group>}
|
|
32
40
|
</Group>
|
|
33
|
-
<Group blendMode="srcIn">{children}</Group>
|
|
34
41
|
</Group>
|
|
35
42
|
);
|
|
36
43
|
};
|
|
@@ -190,12 +190,16 @@ export const multiply4 = (a: Matrix4, b: Matrix4): Matrix4 => {
|
|
|
190
190
|
return result as unknown as Matrix4;
|
|
191
191
|
};
|
|
192
192
|
|
|
193
|
-
|
|
193
|
+
// These matrices are row-major, so the shear factor of skewX - which offsets x
|
|
194
|
+
// in proportion to y - belongs in row 0, column 1, and skewY's in row 1,
|
|
195
|
+
// column 0. React Native's MatrixMath stores the same transforms column-major,
|
|
196
|
+
// and porting its indices verbatim is what swapped the two axes here.
|
|
197
|
+
const skewX = (angle: number): Matrix4 => {
|
|
194
198
|
"worklet";
|
|
195
199
|
return [1, Math.tan(angle), 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1];
|
|
196
200
|
};
|
|
197
201
|
|
|
198
|
-
const
|
|
202
|
+
const skewY = (angle: number): Matrix4 => {
|
|
199
203
|
"worklet";
|
|
200
204
|
return [1, 0, 0, 0, Math.tan(angle), 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1];
|
|
201
205
|
};
|
package/src/skia/types/Skia.ts
CHANGED
|
@@ -21,7 +21,7 @@ import type { SkVertices, VertexMode } from "./Vertices/Vertices";
|
|
|
21
21
|
import type { DataFactory } from "./Data";
|
|
22
22
|
import type { SVGFactory } from "./SVG";
|
|
23
23
|
import type { TextBlobFactory } from "./TextBlob";
|
|
24
|
-
import type {
|
|
24
|
+
import type { SurfaceFactory } from "./Surface";
|
|
25
25
|
import type { SkRSXform } from "./RSXform";
|
|
26
26
|
import type { SkPath } from "./Path/Path";
|
|
27
27
|
import type { SkContourMeasureIter } from "./ContourMeasure";
|
|
@@ -35,11 +35,6 @@ import type { NativeBufferFactory } from "./NativeBuffer";
|
|
|
35
35
|
import type { JsiRecorder } from "./Recorder";
|
|
36
36
|
import type { SkottieFactory } from "./Skottie";
|
|
37
37
|
|
|
38
|
-
export interface SkiaContext {
|
|
39
|
-
getSurface(): SkSurface;
|
|
40
|
-
present(): void;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
38
|
/**
|
|
44
39
|
* Declares the interface for the native Skia API
|
|
45
40
|
*/
|
|
@@ -106,7 +101,6 @@ export interface Skia {
|
|
|
106
101
|
ParagraphBuilder: ParagraphBuilderFactory;
|
|
107
102
|
Skottie: SkottieFactory;
|
|
108
103
|
Video: (url: string) => Promise<Video> | Video;
|
|
109
|
-
Context(surface: bigint, width: number, height: number): SkiaContext;
|
|
110
104
|
NativeBuffer: NativeBufferFactory;
|
|
111
105
|
Recorder(): JsiRecorder;
|
|
112
106
|
/**
|
package/src/skia/web/JsiSkia.ts
CHANGED
|
@@ -4,7 +4,6 @@ import type {
|
|
|
4
4
|
JsiRecorder,
|
|
5
5
|
SkContourMeasureIter,
|
|
6
6
|
Skia,
|
|
7
|
-
SkiaContext,
|
|
8
7
|
SkPath,
|
|
9
8
|
SkRect,
|
|
10
9
|
SkRuntimeEffect,
|
|
@@ -137,9 +136,6 @@ export const JsiSkApi = (CanvasKit: CanvasKit): Skia => ({
|
|
|
137
136
|
NativeBuffer: new JsiSkNativeBufferFactory(CanvasKit),
|
|
138
137
|
Skottie: new JsiSkottieFactory(CanvasKit),
|
|
139
138
|
Video: createVideo.bind(null, CanvasKit),
|
|
140
|
-
Context: (_surface: bigint, _width: number, _height: number) => {
|
|
141
|
-
return throwNotImplementedOnRNWeb<SkiaContext>();
|
|
142
|
-
},
|
|
143
139
|
Recorder: () => {
|
|
144
140
|
return throwNotImplementedOnRNWeb<JsiRecorder>();
|
|
145
141
|
},
|
|
@@ -37,7 +37,10 @@ export const createDrawingContext = (
|
|
|
37
37
|
if (paintPool.length === 0) {
|
|
38
38
|
paintPool.push(Skia.Paint());
|
|
39
39
|
} else {
|
|
40
|
+
// reset() produces an anti-alias false paint, unlike the Skia.Paint()
|
|
41
|
+
// factory: restore the default so reused pools render like the first frame.
|
|
40
42
|
paintPool[0].reset();
|
|
43
|
+
paintPool[0].setAntiAlias(true);
|
|
41
44
|
}
|
|
42
45
|
paints.push(paintPool[0]);
|
|
43
46
|
opacities.push(1);
|
|
@@ -56,6 +59,17 @@ export const createDrawingContext = (
|
|
|
56
59
|
nextPaintIndex++;
|
|
57
60
|
};
|
|
58
61
|
|
|
62
|
+
// Pushes an externally owned paint (the `paint` prop) onto the stack. It
|
|
63
|
+
// pushes a frame-scoped copy, like the C++ DrawingCtx: materializePaint()
|
|
64
|
+
// mutates the top of the stack, and those mutations must not leak into the
|
|
65
|
+
// user-owned paint. It must also push an opacity alongside it: restorePaint()
|
|
66
|
+
// pops both, so pushing only the paint would underflow the opacity stack and
|
|
67
|
+
// leak the enclosing group's opacity onto everything drawn afterwards.
|
|
68
|
+
const pushPaint = (paint: SkPaint) => {
|
|
69
|
+
paints.push(track(paint.copy()));
|
|
70
|
+
opacities.push(opacities[opacities.length - 1]);
|
|
71
|
+
};
|
|
72
|
+
|
|
59
73
|
const getOpacity = () => {
|
|
60
74
|
return opacities[opacities.length - 1];
|
|
61
75
|
};
|
|
@@ -144,6 +158,7 @@ export const createDrawingContext = (
|
|
|
144
158
|
|
|
145
159
|
// Public methods
|
|
146
160
|
savePaint,
|
|
161
|
+
pushPaint,
|
|
147
162
|
saveBackdropFilter,
|
|
148
163
|
get paint() {
|
|
149
164
|
return paints[paints.length - 1];
|
|
@@ -123,7 +123,7 @@ const play = (ctx: DrawingContext, _command: Command) => {
|
|
|
123
123
|
ctx.canvas.saveLayer(paint);
|
|
124
124
|
} else if (isDrawCommand(command, CommandType.SavePaint)) {
|
|
125
125
|
if (command.props.paint) {
|
|
126
|
-
ctx.
|
|
126
|
+
ctx.pushPaint(command.props.paint);
|
|
127
127
|
} else {
|
|
128
128
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
129
129
|
const { standalone } = command as any;
|
|
@@ -104,13 +104,16 @@ const processCTM = ({
|
|
|
104
104
|
if (layer) {
|
|
105
105
|
ctm.layer = layer;
|
|
106
106
|
}
|
|
107
|
+
// Only record a CTM command when saveCTM() will actually save the canvas.
|
|
108
|
+
// saveCTM() saves on transform/matrix, clip or layer; restoreCTM() always
|
|
109
|
+
// restores, so recording a CTM that saves nothing - `origin` with no
|
|
110
|
+
// transform, `clip={false}` from a conditional, a bare `invertClip` - pops
|
|
111
|
+
// an enclosing save that belongs to an ancestor.
|
|
107
112
|
if (
|
|
108
|
-
clip !== undefined ||
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
matrix !== undefined ||
|
|
113
|
-
layer !== undefined
|
|
113
|
+
ctm.clip !== undefined ||
|
|
114
|
+
ctm.transform !== undefined ||
|
|
115
|
+
ctm.matrix !== undefined ||
|
|
116
|
+
ctm.layer !== undefined
|
|
114
117
|
) {
|
|
115
118
|
return ctm;
|
|
116
119
|
}
|
|
@@ -217,6 +217,16 @@ export const drawPath = (ctx: DrawingContext, props: PathProps) => {
|
|
|
217
217
|
|
|
218
218
|
let path = processPath(ctx.Skia, pathProps.path);
|
|
219
219
|
|
|
220
|
+
// Trim runs first, so start/end address the path the caller drew. Stroking
|
|
221
|
+
// first would replace it with its outline and leave the offsets walking that
|
|
222
|
+
// outline's perimeter instead. The native recorder orders these the same way.
|
|
223
|
+
if (hasStartOffset || hasEndOffset) {
|
|
224
|
+
const trimmed = ctx.Skia.Path.Trim(path, start, end, false);
|
|
225
|
+
if (trimmed) {
|
|
226
|
+
path = trimmed;
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
|
|
220
230
|
// Apply fill type using PathBuilder
|
|
221
231
|
if (hasFillType) {
|
|
222
232
|
const builder = ctx.Skia.PathBuilder.MakeFromPath(path);
|
|
@@ -232,14 +242,6 @@ export const drawPath = (ctx: DrawingContext, props: PathProps) => {
|
|
|
232
242
|
}
|
|
233
243
|
}
|
|
234
244
|
|
|
235
|
-
// Apply trim using static Path.Trim
|
|
236
|
-
if (hasStartOffset || hasEndOffset) {
|
|
237
|
-
const trimmed = ctx.Skia.Path.Trim(path, start, end, false);
|
|
238
|
-
if (trimmed) {
|
|
239
|
-
path = trimmed;
|
|
240
|
-
}
|
|
241
|
-
}
|
|
242
|
-
|
|
243
245
|
ctx.canvas.drawPath(path, ctx.paint);
|
|
244
246
|
};
|
|
245
247
|
|
|
@@ -31,6 +31,14 @@ export enum MorphologyOperator {
|
|
|
31
31
|
|
|
32
32
|
const Black = Float32Array.of(0, 0, 0, 1);
|
|
33
33
|
|
|
34
|
+
// Turns the source graphic into a hard silhouette: alpha is multiplied by 255
|
|
35
|
+
// and clamped, so any pixel the shape covers at all becomes fully opaque, and
|
|
36
|
+
// the colour channels are dropped. 255 is the saturation point of an 8-bit
|
|
37
|
+
// alpha channel, so one unit of coverage is enough to reach 1.
|
|
38
|
+
const AlphaSaturate = [
|
|
39
|
+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 0,
|
|
40
|
+
];
|
|
41
|
+
|
|
34
42
|
const MakeInnerShadow = (
|
|
35
43
|
Skia: Skia,
|
|
36
44
|
shadowOnly: boolean | undefined,
|
|
@@ -50,9 +58,20 @@ const MakeInnerShadow = (
|
|
|
50
58
|
Skia.ColorFilter.MakeBlend(Black, BlendMode.SrcIn),
|
|
51
59
|
null
|
|
52
60
|
);
|
|
61
|
+
// The shadow is generated outside the shape and then clipped back into it, so
|
|
62
|
+
// "outside" has to be the complement of the shape's silhouette. Taking SrcOut
|
|
63
|
+
// against the source graphic itself makes it the complement of the source's
|
|
64
|
+
// *alpha*: inside a translucent shape 1 - alpha is non-zero, so the shadow is
|
|
65
|
+
// generated across the whole interior and tints it, no matter how small the
|
|
66
|
+
// blur and the offset are (issue #2990). Saturating alpha first keeps the
|
|
67
|
+
// shadow tied to the shape's outline instead of to its opacity.
|
|
68
|
+
const coverage = Skia.ImageFilter.MakeColorFilter(
|
|
69
|
+
Skia.ColorFilter.MakeMatrix(AlphaSaturate),
|
|
70
|
+
null
|
|
71
|
+
);
|
|
53
72
|
const f1 = Skia.ImageFilter.MakeColorFilter(
|
|
54
73
|
Skia.ColorFilter.MakeBlend(color, BlendMode.SrcOut),
|
|
55
|
-
|
|
74
|
+
coverage
|
|
56
75
|
);
|
|
57
76
|
const f2 = Skia.ImageFilter.MakeOffset(dx, dy, f1);
|
|
58
77
|
const f3 = Skia.ImageFilter.MakeBlur(sigmaX, sigmaY, TileMode.Decal, f2);
|
|
@@ -221,7 +221,7 @@ const declareImageShader = (ctx: DrawingContext, props: ImageShaderProps) => {
|
|
|
221
221
|
);
|
|
222
222
|
} else {
|
|
223
223
|
shader = ctx.track(
|
|
224
|
-
image.
|
|
224
|
+
image.makeShaderOptions(
|
|
225
225
|
TileMode[enumKey(tx)],
|
|
226
226
|
TileMode[enumKey(ty)],
|
|
227
227
|
sampling?.filter ?? FilterMode.Linear,
|
|
@@ -370,22 +370,27 @@ export const SkiaPictureView = (props: SkiaPictureViewProps) => {
|
|
|
370
370
|
// - The renderer is created synchronously on mount (the canvas element is
|
|
371
371
|
// guaranteed to exist in useLayoutEffect; a zero size at that point is
|
|
372
372
|
// fine, the surface is created once the canvas is measurable).
|
|
373
|
-
// - Redraw requests coalesce into a single
|
|
374
|
-
//
|
|
375
|
-
//
|
|
376
|
-
//
|
|
373
|
+
// - Redraw requests coalesce into a single microtask. A microtask (not an
|
|
374
|
+
// animation frame) so that a picture produced inside a rAF callback (the
|
|
375
|
+
// Reanimated mapper) is drawn before the current frame paints: deferring
|
|
376
|
+
// to the next rAF alternates between "flush pending in this frame" and
|
|
377
|
+
// "flush scheduled for the next frame", drawing on every other frame
|
|
378
|
+
// only and halving the effective frame rate. A picture dispatched before
|
|
379
|
+
// the canvas has a size stays in pictureRef (drawing while unmeasured is
|
|
380
|
+
// a no-op) and is painted by the resize path below once the canvas
|
|
381
|
+
// becomes measurable, so it is never lost.
|
|
377
382
|
// - A ResizeObserver on the canvas itself recreates the surface and repaints
|
|
378
383
|
// synchronously (its callbacks run after layout, before paint), and is
|
|
379
384
|
// also the source of the user-facing onLayout event.
|
|
380
385
|
const redrawPendingRef = useRef(false);
|
|
381
|
-
const
|
|
386
|
+
const flushScheduledRef = useRef(false);
|
|
382
387
|
const onLayoutRef = useRef(onLayout);
|
|
383
388
|
useLayoutEffect(() => {
|
|
384
389
|
onLayoutRef.current = onLayout;
|
|
385
390
|
}, [onLayout]);
|
|
386
391
|
|
|
387
392
|
const flushRedraw = useCallback(() => {
|
|
388
|
-
|
|
393
|
+
flushScheduledRef.current = false;
|
|
389
394
|
if (redrawPendingRef.current && rendererRef.current && pictureRef.current) {
|
|
390
395
|
redrawPendingRef.current = false;
|
|
391
396
|
rendererRef.current.draw(pictureRef.current);
|
|
@@ -396,8 +401,9 @@ export const SkiaPictureView = (props: SkiaPictureViewProps) => {
|
|
|
396
401
|
|
|
397
402
|
const redraw = useCallback(() => {
|
|
398
403
|
redrawPendingRef.current = true;
|
|
399
|
-
if (
|
|
400
|
-
|
|
404
|
+
if (!flushScheduledRef.current) {
|
|
405
|
+
flushScheduledRef.current = true;
|
|
406
|
+
queueMicrotask(flushRedraw);
|
|
401
407
|
}
|
|
402
408
|
}, [flushRedraw]);
|
|
403
409
|
|
|
@@ -568,12 +574,9 @@ export const SkiaPictureView = (props: SkiaPictureViewProps) => {
|
|
|
568
574
|
};
|
|
569
575
|
}, [isStatic]);
|
|
570
576
|
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
frameRef.current = 0;
|
|
575
|
-
};
|
|
576
|
-
}, []);
|
|
577
|
+
// No flush cancellation is needed on unmount: a microtask queued before
|
|
578
|
+
// unmount runs within the same task, and flushRedraw no-ops once the
|
|
579
|
+
// layout-effect cleanup has nulled rendererRef.
|
|
577
580
|
|
|
578
581
|
useImperativeHandle(
|
|
579
582
|
ref,
|
package/cpp/api/JsiSkiaContext.h
DELETED
|
@@ -1,94 +0,0 @@
|
|
|
1
|
-
#pragma once
|
|
2
|
-
|
|
3
|
-
#include <memory>
|
|
4
|
-
#include <numeric>
|
|
5
|
-
#include <utility>
|
|
6
|
-
#include <variant>
|
|
7
|
-
#include <vector>
|
|
8
|
-
|
|
9
|
-
#include "JsiSkConverters.h"
|
|
10
|
-
#include "JsiSkNativeObjects.h"
|
|
11
|
-
#include "utils/RNSkLog.h"
|
|
12
|
-
#include <jsi/jsi.h>
|
|
13
|
-
|
|
14
|
-
#include "JsiSkPaint.h"
|
|
15
|
-
#include "JsiSkPoint.h"
|
|
16
|
-
#include "JsiSkRect.h"
|
|
17
|
-
#include "JsiSkSurface.h"
|
|
18
|
-
#include "JsiSkTypeface.h"
|
|
19
|
-
|
|
20
|
-
#include "rnskia/RNWindowContext.h"
|
|
21
|
-
|
|
22
|
-
#pragma clang diagnostic push
|
|
23
|
-
#pragma clang diagnostic ignored "-Wdocumentation"
|
|
24
|
-
|
|
25
|
-
#include "include/core/SkFont.h"
|
|
26
|
-
#include "include/core/SkFontMetrics.h"
|
|
27
|
-
|
|
28
|
-
#pragma clang diagnostic pop
|
|
29
|
-
|
|
30
|
-
namespace RNSkia {
|
|
31
|
-
|
|
32
|
-
namespace jsi = facebook::jsi;
|
|
33
|
-
|
|
34
|
-
class JsiSkiaContext
|
|
35
|
-
: public JsiSkWrappingSharedPtrNativeObject<JsiSkiaContext, WindowContext> {
|
|
36
|
-
public:
|
|
37
|
-
static constexpr const char *CLASS_NAME = "SkiaContext";
|
|
38
|
-
|
|
39
|
-
std::variant<std::nullptr_t, std::shared_ptr<JsiSkSurface>> getSurface() {
|
|
40
|
-
auto surface = getObject()->getSurface();
|
|
41
|
-
if (surface == nullptr) {
|
|
42
|
-
return nullptr;
|
|
43
|
-
}
|
|
44
|
-
return std::make_shared<JsiSkSurface>(getContext(), std::move(surface));
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
void present() { getObject()->present(); }
|
|
48
|
-
|
|
49
|
-
static void definePrototype(jsi::Runtime &runtime, jsi::Object &prototype) {
|
|
50
|
-
installCommon(runtime, prototype);
|
|
51
|
-
installMethod(runtime, prototype, "getSurface",
|
|
52
|
-
&JsiSkiaContext::getSurface);
|
|
53
|
-
installMethod(runtime, prototype, "present", &JsiSkiaContext::present);
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
JsiSkiaContext(std::shared_ptr<RNSkPlatformContext> context,
|
|
57
|
-
std::shared_ptr<WindowContext> ctx)
|
|
58
|
-
: JsiSkWrappingSharedPtrNativeObject<JsiSkiaContext, WindowContext>(
|
|
59
|
-
std::move(context), std::move(ctx)) {}
|
|
60
|
-
|
|
61
|
-
size_t getMemoryPressure() override { return 10 * 1024 * 1024; }
|
|
62
|
-
|
|
63
|
-
/**
|
|
64
|
-
* Creates the function for construction a new instance of the SkFont
|
|
65
|
-
* wrapper
|
|
66
|
-
* @param context Platform context
|
|
67
|
-
* @return A function for creating a new host object wrapper for the SkFont
|
|
68
|
-
* class
|
|
69
|
-
*/
|
|
70
|
-
static const jsi::HostFunctionType
|
|
71
|
-
createCtor(std::shared_ptr<RNSkPlatformContext> context) {
|
|
72
|
-
return JSI_HOST_FUNCTION_LAMBDA {
|
|
73
|
-
jsi::BigInt pointer = arguments[0].asBigInt(runtime);
|
|
74
|
-
const uintptr_t nativeBufferPointer = pointer.asUint64(runtime);
|
|
75
|
-
void *surface = reinterpret_cast<void *>(nativeBufferPointer);
|
|
76
|
-
auto width = static_cast<int>(arguments[1].asNumber());
|
|
77
|
-
auto height = static_cast<int>(arguments[2].asNumber());
|
|
78
|
-
if (surface == nullptr) {
|
|
79
|
-
throw std::runtime_error("Surface is null");
|
|
80
|
-
}
|
|
81
|
-
auto result =
|
|
82
|
-
context->makeContextFromNativeSurface(surface, width, height);
|
|
83
|
-
if (result == nullptr) {
|
|
84
|
-
throw std::runtime_error(
|
|
85
|
-
"Couldn't create a Skia context from the native surface");
|
|
86
|
-
}
|
|
87
|
-
// Return the newly constructed object
|
|
88
|
-
return makeJsiObject(runtime, std::make_shared<JsiSkiaContext>(
|
|
89
|
-
context, std::move(result)));
|
|
90
|
-
};
|
|
91
|
-
}
|
|
92
|
-
};
|
|
93
|
-
|
|
94
|
-
} // namespace RNSkia
|