react-native-skia 3.0.0 → 3.0.2
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/Package.swift +14 -13
- package/android/CMakeLists.txt +13 -42
- package/android/build.gradle +55 -47
- package/android/cpp/jni/JniLoad.cpp +2 -4
- package/android/cpp/jni/include/JniSkiaView.h +123 -0
- package/android/cpp/rnskia-android/{RNSkOpenGLCanvasProvider.cpp → RNSkAndroidCanvasProvider.cpp} +45 -100
- package/android/cpp/rnskia-android/{RNSkOpenGLCanvasProvider.h → RNSkAndroidCanvasProvider.h} +24 -22
- package/android/cpp/rnskia-android/RNSkAndroidPlatformContext.h +0 -83
- package/android/cpp/rnskia-android/RNSkAndroidVideo.cpp +0 -8
- package/android/src/main/java/com/reactnative/skia/RNSkiaPackage.java +1 -2
- package/android/src/main/java/com/reactnative/skia/SkiaSurfaceView.java +1 -3
- package/android/src/main/java/com/reactnative/skia/SkiaTextureView.java +1 -17
- package/android/src/main/java/com/reactnative/skia/{SkiaBaseView.java → SkiaView.java} +78 -16
- package/android/src/main/java/com/reactnative/skia/SkiaViewManager.java +85 -0
- package/apple/MetalLayerColorSpace.mm +0 -4
- package/apple/RNSkApplePlatformContext.h +0 -14
- package/apple/RNSkApplePlatformContext.mm +2 -112
- package/apple/RNSkMetalCanvasProvider.h +14 -19
- package/apple/RNSkMetalCanvasProvider.mm +35 -68
- package/apple/SkiaView.h +20 -0
- package/apple/SkiaView.mm +210 -0
- package/cpp/api/JsiSkApi.h +2 -13
- package/cpp/api/JsiSkCanvas.h +4 -18
- package/cpp/api/JsiSkGraphiteContext.h +1 -5
- package/cpp/api/JsiSkGraphiteRecording.h +1 -5
- package/cpp/api/JsiSkImage.h +7 -41
- package/cpp/api/JsiSkImageFactory.h +0 -14
- package/cpp/api/JsiSkSurface.h +2 -16
- package/cpp/api/JsiSkSurfaceFactory.h +0 -8
- package/cpp/rnskia/RNDawnContext.h +6 -0
- package/cpp/rnskia/RNDawnInterop.cpp +0 -4
- package/cpp/rnskia/RNDawnUtils.h +0 -1
- package/cpp/rnskia/RNDawnWindowContext.cpp +10 -0
- package/cpp/rnskia/RNDawnWindowContext.h +4 -0
- package/cpp/rnskia/RNSkCanvasProvider.h +221 -0
- package/cpp/rnskia/RNSkGraphiteProducer.cpp +36 -14
- package/cpp/rnskia/RNSkGraphiteProducer.h +23 -8
- package/cpp/rnskia/RNSkGraphiteTarget.h +383 -0
- package/cpp/rnskia/RNSkJsiViewApi.h +9 -18
- package/cpp/rnskia/RNSkPlatformContext.h +9 -15
- package/cpp/rnskia/RNSkView.h +340 -245
- package/jestSetup.js +1 -3
- package/lib/commonjs/Platform/Platform.web.js +1 -1
- package/lib/commonjs/Platform/Platform.web.js.map +1 -1
- package/lib/commonjs/index.d.ts +1 -3
- package/lib/commonjs/index.js +3 -12
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/mock/index.js +0 -1
- package/lib/commonjs/mock/index.js.map +1 -1
- package/lib/commonjs/renderer/Canvas.d.ts +15 -12
- package/lib/commonjs/renderer/Canvas.js +24 -20
- package/lib/commonjs/renderer/Canvas.js.map +1 -1
- package/lib/commonjs/skia/types/Graphite.d.ts +3 -3
- package/lib/commonjs/skia/types/Graphite.js.map +1 -1
- package/lib/commonjs/skia/types/Image/ImageFactory.d.ts +2 -2
- package/lib/commonjs/skia/types/Image/ImageFactory.js.map +1 -1
- package/lib/commonjs/skia/types/Skia.d.ts +1 -2
- package/lib/commonjs/skia/types/Skia.js.map +1 -1
- package/lib/commonjs/skia/types/Surface/SurfaceFactory.d.ts +1 -1
- package/lib/commonjs/skia/types/Surface/SurfaceFactory.js.map +1 -1
- package/lib/commonjs/specs/NativeSkiaModule.web.d.ts +5 -4
- package/lib/commonjs/specs/NativeSkiaModule.web.js +5 -9
- package/lib/commonjs/specs/NativeSkiaModule.web.js.map +1 -1
- package/lib/{typescript/src/specs/SkiaPictureViewNativeComponent.d.ts → commonjs/specs/SkiaViewNativeComponent.d.ts} +0 -3
- package/lib/commonjs/specs/{SkiaPictureViewNativeComponent.js → SkiaViewNativeComponent.js} +2 -2
- package/lib/commonjs/specs/SkiaViewNativeComponent.js.map +1 -0
- package/lib/commonjs/specs/SkiaViewNativeComponent.web.d.ts +10 -0
- package/lib/commonjs/specs/SkiaViewNativeComponent.web.js +27 -0
- package/lib/commonjs/specs/SkiaViewNativeComponent.web.js.map +1 -0
- package/lib/commonjs/views/SkiaGraphiteView.d.ts +3 -4
- package/lib/commonjs/views/SkiaGraphiteView.js +23 -12
- package/lib/commonjs/views/SkiaGraphiteView.js.map +1 -1
- package/lib/commonjs/views/SkiaPictureView.d.ts +4 -1
- package/lib/commonjs/views/SkiaPictureView.js +12 -10
- package/lib/commonjs/views/SkiaPictureView.js.map +1 -1
- package/lib/commonjs/views/SkiaView.web.d.ts +12 -0
- package/lib/commonjs/views/{SkiaGraphiteView.web.js → SkiaView.web.js} +82 -38
- package/lib/commonjs/views/SkiaView.web.js.map +1 -0
- package/lib/commonjs/views/SkiaWebRenderer.js +1 -1
- package/lib/commonjs/views/SkiaWebRenderer.js.map +1 -1
- package/lib/commonjs/views/android.d.ts +6 -0
- package/lib/commonjs/views/android.js +17 -0
- package/lib/commonjs/views/android.js.map +1 -0
- package/lib/commonjs/views/types.d.ts +3 -12
- package/lib/commonjs/views/types.js.map +1 -1
- package/lib/module/Platform/Platform.web.js +1 -1
- package/lib/module/Platform/Platform.web.js.map +1 -1
- package/lib/module/index.d.ts +1 -3
- package/lib/module/index.js +1 -3
- package/lib/module/index.js.map +1 -1
- package/lib/module/mock/index.js +0 -1
- package/lib/module/mock/index.js.map +1 -1
- package/lib/module/renderer/Canvas.d.ts +15 -12
- package/lib/module/renderer/Canvas.js +24 -19
- package/lib/module/renderer/Canvas.js.map +1 -1
- package/lib/module/skia/types/Graphite.d.ts +3 -3
- package/lib/module/skia/types/Graphite.js.map +1 -1
- package/lib/module/skia/types/Image/ImageFactory.d.ts +2 -2
- package/lib/module/skia/types/Image/ImageFactory.js.map +1 -1
- package/lib/module/skia/types/Skia.d.ts +1 -2
- package/lib/module/skia/types/Skia.js.map +1 -1
- package/lib/module/skia/types/Surface/SurfaceFactory.d.ts +1 -1
- package/lib/module/skia/types/Surface/SurfaceFactory.js.map +1 -1
- package/lib/module/specs/NativeSkiaModule.web.d.ts +5 -4
- package/lib/module/specs/NativeSkiaModule.web.js +5 -9
- package/lib/module/specs/NativeSkiaModule.web.js.map +1 -1
- package/lib/{commonjs/specs/SkiaPictureViewNativeComponent.d.ts → module/specs/SkiaViewNativeComponent.d.ts} +0 -3
- package/lib/module/specs/{SkiaPictureViewNativeComponent.js → SkiaViewNativeComponent.js} +2 -2
- package/lib/module/specs/SkiaViewNativeComponent.js.map +1 -0
- package/lib/module/specs/SkiaViewNativeComponent.web.d.ts +10 -0
- package/lib/module/specs/SkiaViewNativeComponent.web.js +21 -0
- package/lib/module/specs/SkiaViewNativeComponent.web.js.map +1 -0
- package/lib/module/views/SkiaGraphiteView.d.ts +3 -4
- package/lib/module/views/SkiaGraphiteView.js +23 -12
- package/lib/module/views/SkiaGraphiteView.js.map +1 -1
- package/lib/module/views/SkiaPictureView.d.ts +4 -1
- package/lib/module/views/SkiaPictureView.js +12 -10
- package/lib/module/views/SkiaPictureView.js.map +1 -1
- package/lib/module/views/SkiaView.web.d.ts +12 -0
- package/lib/module/views/{SkiaGraphiteView.web.js → SkiaView.web.js} +80 -36
- package/lib/module/views/SkiaView.web.js.map +1 -0
- package/lib/module/views/SkiaWebRenderer.js +1 -1
- package/lib/module/views/SkiaWebRenderer.js.map +1 -1
- package/lib/module/views/android.d.ts +6 -0
- package/lib/module/views/android.js +10 -0
- package/lib/module/views/android.js.map +1 -0
- package/lib/module/views/types.d.ts +3 -12
- package/lib/module/views/types.js.map +1 -1
- package/lib/typescript/src/index.d.ts +1 -3
- package/lib/typescript/src/renderer/Canvas.d.ts +15 -12
- package/lib/typescript/src/skia/types/Graphite.d.ts +3 -3
- package/lib/typescript/src/skia/types/Image/ImageFactory.d.ts +2 -2
- package/lib/typescript/src/skia/types/Skia.d.ts +1 -2
- package/lib/typescript/src/skia/types/Surface/SurfaceFactory.d.ts +1 -1
- package/lib/typescript/src/specs/NativeSkiaModule.web.d.ts +5 -4
- package/lib/{module/specs/SkiaPictureViewNativeComponent.d.ts → typescript/src/specs/SkiaViewNativeComponent.d.ts} +0 -3
- package/lib/typescript/src/specs/SkiaViewNativeComponent.web.d.ts +10 -0
- package/lib/typescript/src/views/SkiaGraphiteView.d.ts +3 -4
- package/lib/typescript/src/views/SkiaPictureView.d.ts +4 -1
- package/lib/typescript/src/views/SkiaView.web.d.ts +12 -0
- package/lib/typescript/src/views/android.d.ts +6 -0
- package/lib/typescript/src/views/types.d.ts +3 -12
- package/package.json +8 -16
- package/react-native-skia.podspec +50 -57
- package/src/Platform/Platform.web.tsx +1 -1
- package/src/index.ts +1 -3
- package/src/mock/index.ts +0 -1
- package/src/renderer/Canvas.tsx +23 -27
- package/src/skia/types/Graphite.ts +3 -3
- package/src/skia/types/Image/ImageFactory.ts +2 -2
- package/src/skia/types/Skia.ts +1 -2
- package/src/skia/types/Surface/SurfaceFactory.ts +1 -1
- package/src/specs/NativeSkiaModule.web.ts +9 -21
- package/src/specs/{SkiaPictureViewNativeComponent.ts → SkiaViewNativeComponent.ts} +1 -4
- package/src/specs/{SkiaPictureViewNativeComponent.web.ts → SkiaViewNativeComponent.web.ts} +8 -10
- package/src/views/SkiaGraphiteView.tsx +27 -16
- package/src/views/SkiaPictureView.tsx +11 -10
- package/src/views/{SkiaGraphiteView.web.tsx → SkiaView.web.tsx} +100 -53
- package/src/views/SkiaWebRenderer.ts +1 -1
- package/src/views/android.ts +16 -0
- package/src/views/types.ts +3 -14
- package/android/cpp/jni/include/JniSkiaBaseView.h +0 -92
- package/android/cpp/jni/include/JniSkiaGraphiteView.h +0 -176
- package/android/cpp/jni/include/JniSkiaPictureView.h +0 -172
- package/android/cpp/rnskia-android/GrAHardwareBufferUtils.cpp +0 -245
- package/android/cpp/rnskia-android/GrAHardwareBufferUtils.h +0 -33
- package/android/cpp/rnskia-android/OpenGLContext.h +0 -248
- package/android/cpp/rnskia-android/OpenGLWindowContext.cpp +0 -67
- package/android/cpp/rnskia-android/OpenGLWindowContext.h +0 -75
- package/android/cpp/rnskia-android/RNSkAndroidView.h +0 -67
- package/android/cpp/rnskia-android/gl/Context.h +0 -80
- package/android/cpp/rnskia-android/gl/Display.h +0 -123
- package/android/cpp/rnskia-android/gl/Error.cpp +0 -45
- package/android/cpp/rnskia-android/gl/Error.h +0 -8
- package/android/cpp/rnskia-android/gl/Surface.h +0 -43
- package/android/src/main/java/com/reactnative/skia/SkiaBaseViewManager.java +0 -65
- package/android/src/main/java/com/reactnative/skia/SkiaGraphiteView.java +0 -78
- package/android/src/main/java/com/reactnative/skia/SkiaGraphiteViewManager.java +0 -32
- package/android/src/main/java/com/reactnative/skia/SkiaPictureView.java +0 -105
- package/android/src/main/java/com/reactnative/skia/SkiaPictureViewManager.java +0 -44
- package/apple/MetalContext.h +0 -116
- package/apple/MetalContext.mm +0 -38
- package/apple/MetalWindowContext.h +0 -42
- package/apple/MetalWindowContext.mm +0 -95
- package/apple/RNSkAppleView.h +0 -49
- package/apple/RNSkAppleView.mm +0 -35
- package/apple/SkiaCVPixelBufferUtils.h +0 -122
- package/apple/SkiaCVPixelBufferUtils.mm +0 -535
- package/apple/SkiaGraphiteView.h +0 -26
- package/apple/SkiaGraphiteView.mm +0 -180
- package/apple/SkiaPictureView.h +0 -7
- package/apple/SkiaPictureView.mm +0 -70
- package/apple/SkiaUIView.h +0 -31
- package/apple/SkiaUIView.mm +0 -164
- package/cpp/rnskia/RNSkGraphiteView.h +0 -708
- package/cpp/rnskia/RNSkPictureView.cpp +0 -69
- package/cpp/rnskia/RNSkPictureView.h +0 -211
- package/cpp/skia/src/gpu/ganesh/gl/GrGLDefines.h +0 -1162
- package/lib/commonjs/renderer/DefaultCanvas.d.ts +0 -8
- package/lib/commonjs/renderer/DefaultCanvas.js +0 -42
- package/lib/commonjs/renderer/DefaultCanvas.js.map +0 -1
- package/lib/commonjs/renderer/GraphiteCanvas.d.ts +0 -22
- package/lib/commonjs/renderer/GraphiteCanvas.js +0 -64
- package/lib/commonjs/renderer/GraphiteCanvas.js.map +0 -1
- package/lib/commonjs/renderer/GraphiteCanvas.web.d.ts +0 -1
- package/lib/commonjs/renderer/GraphiteCanvas.web.js +0 -13
- package/lib/commonjs/renderer/GraphiteCanvas.web.js.map +0 -1
- package/lib/commonjs/specs/SkiaGraphiteViewNativeComponent.d.ts +0 -10
- package/lib/commonjs/specs/SkiaGraphiteViewNativeComponent.js +0 -12
- package/lib/commonjs/specs/SkiaGraphiteViewNativeComponent.js.map +0 -1
- package/lib/commonjs/specs/SkiaGraphiteViewNativeComponent.web.d.ts +0 -9
- package/lib/commonjs/specs/SkiaGraphiteViewNativeComponent.web.js +0 -28
- package/lib/commonjs/specs/SkiaGraphiteViewNativeComponent.web.js.map +0 -1
- package/lib/commonjs/specs/SkiaPictureViewNativeComponent.js.map +0 -1
- package/lib/commonjs/specs/SkiaPictureViewNativeComponent.web.d.ts +0 -10
- package/lib/commonjs/specs/SkiaPictureViewNativeComponent.web.js +0 -29
- package/lib/commonjs/specs/SkiaPictureViewNativeComponent.web.js.map +0 -1
- package/lib/commonjs/views/SkiaGraphiteView.web.d.ts +0 -14
- package/lib/commonjs/views/SkiaGraphiteView.web.js.map +0 -1
- package/lib/commonjs/views/SkiaPictureView.web.d.ts +0 -11
- package/lib/commonjs/views/SkiaPictureView.web.js +0 -165
- package/lib/commonjs/views/SkiaPictureView.web.js.map +0 -1
- package/lib/module/renderer/DefaultCanvas.d.ts +0 -8
- package/lib/module/renderer/DefaultCanvas.js +0 -34
- package/lib/module/renderer/DefaultCanvas.js.map +0 -1
- package/lib/module/renderer/GraphiteCanvas.d.ts +0 -22
- package/lib/module/renderer/GraphiteCanvas.js +0 -57
- package/lib/module/renderer/GraphiteCanvas.js.map +0 -1
- package/lib/module/renderer/GraphiteCanvas.web.d.ts +0 -1
- package/lib/module/renderer/GraphiteCanvas.web.js +0 -4
- package/lib/module/renderer/GraphiteCanvas.web.js.map +0 -1
- package/lib/module/specs/SkiaGraphiteViewNativeComponent.d.ts +0 -10
- package/lib/module/specs/SkiaGraphiteViewNativeComponent.js +0 -8
- package/lib/module/specs/SkiaGraphiteViewNativeComponent.js.map +0 -1
- package/lib/module/specs/SkiaGraphiteViewNativeComponent.web.d.ts +0 -9
- package/lib/module/specs/SkiaGraphiteViewNativeComponent.web.js +0 -22
- package/lib/module/specs/SkiaGraphiteViewNativeComponent.web.js.map +0 -1
- package/lib/module/specs/SkiaPictureViewNativeComponent.js.map +0 -1
- package/lib/module/specs/SkiaPictureViewNativeComponent.web.d.ts +0 -10
- package/lib/module/specs/SkiaPictureViewNativeComponent.web.js +0 -23
- package/lib/module/specs/SkiaPictureViewNativeComponent.web.js.map +0 -1
- package/lib/module/views/SkiaGraphiteView.web.d.ts +0 -14
- package/lib/module/views/SkiaGraphiteView.web.js.map +0 -1
- package/lib/module/views/SkiaPictureView.web.d.ts +0 -11
- package/lib/module/views/SkiaPictureView.web.js +0 -156
- package/lib/module/views/SkiaPictureView.web.js.map +0 -1
- package/lib/typescript/src/renderer/DefaultCanvas.d.ts +0 -8
- package/lib/typescript/src/renderer/GraphiteCanvas.d.ts +0 -22
- package/lib/typescript/src/renderer/GraphiteCanvas.web.d.ts +0 -1
- package/lib/typescript/src/specs/SkiaGraphiteViewNativeComponent.d.ts +0 -10
- package/lib/typescript/src/specs/SkiaGraphiteViewNativeComponent.web.d.ts +0 -9
- package/lib/typescript/src/specs/SkiaPictureViewNativeComponent.web.d.ts +0 -10
- package/lib/typescript/src/views/SkiaGraphiteView.web.d.ts +0 -14
- package/lib/typescript/src/views/SkiaPictureView.web.d.ts +0 -11
- package/libs/.graphite +0 -1
- package/src/renderer/DefaultCanvas.tsx +0 -41
- package/src/renderer/GraphiteCanvas.tsx +0 -61
- package/src/renderer/GraphiteCanvas.web.tsx +0 -3
- package/src/specs/SkiaGraphiteViewNativeComponent.ts +0 -17
- package/src/specs/SkiaGraphiteViewNativeComponent.web.ts +0 -31
- package/src/views/SkiaPictureView.web.tsx +0 -224
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import React from "react";
|
|
2
|
-
|
|
3
|
-
import { Skia } from "../skia";
|
|
4
|
-
import { Platform } from "../Platform";
|
|
5
|
-
|
|
6
|
-
import type { CanvasProps } from "./Canvas";
|
|
7
|
-
import { Canvas as PictureCanvas } from "./Canvas";
|
|
8
|
-
import { GraphiteCanvas } from "./GraphiteCanvas";
|
|
9
|
-
|
|
10
|
-
let useGraphite: boolean | null = null;
|
|
11
|
-
|
|
12
|
-
// Whether this build runs the Graphite backend. Resolved on the first render
|
|
13
|
-
// (the native API is installed by then) and cached: getNativeDevice() throws
|
|
14
|
-
// on Ganesh builds. On the web, GraphiteCanvas is the regular canvas anyway.
|
|
15
|
-
const hasGraphite = () => {
|
|
16
|
-
if (useGraphite === null) {
|
|
17
|
-
if (Platform.OS === "web") {
|
|
18
|
-
useGraphite = false;
|
|
19
|
-
} else {
|
|
20
|
-
try {
|
|
21
|
-
useGraphite = typeof Skia.getNativeDevice() === "bigint";
|
|
22
|
-
} catch {
|
|
23
|
-
useGraphite = false;
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
return useGraphite;
|
|
28
|
-
};
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* `<Canvas>` renders {@link GraphiteCanvas} when React Native Skia is
|
|
32
|
-
* configured with the Graphite backend (install-skia-graphite), and the
|
|
33
|
-
* picture view based canvas otherwise. Both take the same props and ref.
|
|
34
|
-
*/
|
|
35
|
-
export const Canvas = (props: CanvasProps) => {
|
|
36
|
-
return hasGraphite() ? (
|
|
37
|
-
<GraphiteCanvas {...props} />
|
|
38
|
-
) : (
|
|
39
|
-
<PictureCanvas {...props} />
|
|
40
|
-
);
|
|
41
|
-
};
|
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
import React from "react";
|
|
2
|
-
|
|
3
|
-
import SkiaGraphiteViewNativeComponent from "../specs/SkiaGraphiteViewNativeComponent";
|
|
4
|
-
|
|
5
|
-
import type { CanvasProps } from "./Canvas";
|
|
6
|
-
import { useCanvasRoot } from "./Canvas";
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* The declarative canvas on the Graphite view. It takes the same props and
|
|
10
|
-
* exposes the same ref as {@link Canvas}, and draws the same children, but
|
|
11
|
-
* the frames are produced differently:
|
|
12
|
-
*
|
|
13
|
-
* - the JS thread records the scene graph into a native recorder once per
|
|
14
|
-
* React commit and hands it to the view;
|
|
15
|
-
* - the Reanimated UI runtime only reads the shared values into it (the one
|
|
16
|
-
* step that needs a JS runtime), it never replays anything;
|
|
17
|
-
* - a dedicated native thread pool replays the recorder into a Graphite
|
|
18
|
-
* recording whenever the content changed, at most once per presented frame;
|
|
19
|
-
* - the view presents the recording on the next vsync.
|
|
20
|
-
*
|
|
21
|
-
* Neither the JS thread nor the UI thread pays for drawing. It requires the
|
|
22
|
-
* Graphite backend (install-skia-graphite); with the default backend the view
|
|
23
|
-
* renders nothing. `colorSpace`, `android` and `androidWarmup` are accepted
|
|
24
|
-
* for API compatibility and ignored: the Graphite view renders in sRGB and
|
|
25
|
-
* uses its own backing view.
|
|
26
|
-
*/
|
|
27
|
-
export const GraphiteCanvas = ({
|
|
28
|
-
debug,
|
|
29
|
-
opaque,
|
|
30
|
-
children,
|
|
31
|
-
onSize,
|
|
32
|
-
|
|
33
|
-
colorSpace,
|
|
34
|
-
highBitDepth = false,
|
|
35
|
-
|
|
36
|
-
androidWarmup,
|
|
37
|
-
|
|
38
|
-
android,
|
|
39
|
-
ref,
|
|
40
|
-
onLayout,
|
|
41
|
-
...viewProps
|
|
42
|
-
}: CanvasProps) => {
|
|
43
|
-
const { nativeId, viewRef } = useCanvasRoot({
|
|
44
|
-
children,
|
|
45
|
-
onSize,
|
|
46
|
-
ref,
|
|
47
|
-
onLayout,
|
|
48
|
-
});
|
|
49
|
-
return (
|
|
50
|
-
<SkiaGraphiteViewNativeComponent
|
|
51
|
-
ref={viewRef}
|
|
52
|
-
collapsable={false}
|
|
53
|
-
nativeID={`${nativeId}`}
|
|
54
|
-
debug={debug}
|
|
55
|
-
opaque={opaque}
|
|
56
|
-
highBitDepth={highBitDepth}
|
|
57
|
-
onLayout={onLayout}
|
|
58
|
-
{...viewProps}
|
|
59
|
-
/>
|
|
60
|
-
);
|
|
61
|
-
};
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { codegenNativeComponent, type ViewProps } from "react-native";
|
|
2
|
-
import type { WithDefault } from "react-native/Libraries/Types/CodegenTypes";
|
|
3
|
-
|
|
4
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
5
|
-
// @ts-ignore - pointerEvents needs to be redeclared for codegen to generate native bindings
|
|
6
|
-
export interface NativeProps extends ViewProps {
|
|
7
|
-
debug?: boolean;
|
|
8
|
-
opaque?: boolean;
|
|
9
|
-
highBitDepth?: boolean;
|
|
10
|
-
pointerEvents?: WithDefault<
|
|
11
|
-
"auto" | "none" | "box-none" | "box-only",
|
|
12
|
-
"auto"
|
|
13
|
-
>;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
// eslint-disable-next-line import/no-default-export
|
|
17
|
-
export default codegenNativeComponent<NativeProps>("SkiaGraphiteView");
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import type { ViewProps } from "react-native";
|
|
2
|
-
import { createElement } from "react";
|
|
3
|
-
|
|
4
|
-
import { SkiaGraphiteView } from "../views/SkiaGraphiteView.web";
|
|
5
|
-
|
|
6
|
-
export interface NativeProps extends ViewProps {
|
|
7
|
-
debug?: boolean;
|
|
8
|
-
opaque?: boolean;
|
|
9
|
-
highBitDepth?: boolean;
|
|
10
|
-
nativeID: string;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
const SkiaGraphiteViewNativeComponent = ({
|
|
14
|
-
nativeID,
|
|
15
|
-
debug,
|
|
16
|
-
opaque,
|
|
17
|
-
highBitDepth,
|
|
18
|
-
onLayout,
|
|
19
|
-
...viewProps
|
|
20
|
-
}: NativeProps) => {
|
|
21
|
-
return createElement(SkiaGraphiteView, {
|
|
22
|
-
nativeID,
|
|
23
|
-
debug,
|
|
24
|
-
opaque,
|
|
25
|
-
highBitDepth,
|
|
26
|
-
onLayout,
|
|
27
|
-
...viewProps,
|
|
28
|
-
});
|
|
29
|
-
};
|
|
30
|
-
// eslint-disable-next-line import/no-default-export
|
|
31
|
-
export default SkiaGraphiteViewNativeComponent;
|
|
@@ -1,224 +0,0 @@
|
|
|
1
|
-
/* global HTMLCanvasElement */
|
|
2
|
-
import React, {
|
|
3
|
-
useRef,
|
|
4
|
-
useEffect,
|
|
5
|
-
useCallback,
|
|
6
|
-
useImperativeHandle,
|
|
7
|
-
} from "react";
|
|
8
|
-
|
|
9
|
-
import type { SkRect, SkPicture, SkImage } from "../skia/types";
|
|
10
|
-
import { Platform } from "../Platform";
|
|
11
|
-
import type {
|
|
12
|
-
ISkiaViewApiWeb,
|
|
13
|
-
SkiaWebViewHandle,
|
|
14
|
-
} from "../specs/NativeSkiaModule.web";
|
|
15
|
-
|
|
16
|
-
import type { SkiaPictureViewNativeProps } from "./types";
|
|
17
|
-
import { SkiaViewNativeId } from "./SkiaViewNativeId";
|
|
18
|
-
import { useSkiaWebRenderer } from "./SkiaWebRenderer";
|
|
19
|
-
import type { Renderer } from "./SkiaWebRenderer";
|
|
20
|
-
|
|
21
|
-
export interface SkiaPictureViewHandle extends SkiaWebViewHandle {
|
|
22
|
-
setPicture(picture: SkPicture): void;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
export interface SkiaPictureViewProps extends SkiaPictureViewNativeProps {
|
|
26
|
-
ref?: React.Ref<SkiaPictureViewHandle>;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
export const SkiaPictureView = (props: SkiaPictureViewProps) => {
|
|
30
|
-
const { ref, picture, onLayout } = props;
|
|
31
|
-
const canvasRef = useRef<HTMLCanvasElement | null>(null);
|
|
32
|
-
const pictureRef = useRef<SkPicture | null>(null);
|
|
33
|
-
// Redraw requests coalesce into a single microtask. A microtask (not an
|
|
34
|
-
// animation frame) so that a picture produced inside a rAF callback (the
|
|
35
|
-
// Reanimated mapper) is drawn before the current frame paints: deferring
|
|
36
|
-
// to the next rAF alternates between "flush pending in this frame" and
|
|
37
|
-
// "flush scheduled for the next frame", drawing on every other frame
|
|
38
|
-
// only and halving the effective frame rate. A picture dispatched before
|
|
39
|
-
// the canvas has a size stays in pictureRef (drawing while unmeasured is
|
|
40
|
-
// a no-op) and is painted by the resize path once the canvas becomes
|
|
41
|
-
// measurable, so it is never lost.
|
|
42
|
-
const redrawPendingRef = useRef(false);
|
|
43
|
-
const flushScheduledRef = useRef(false);
|
|
44
|
-
|
|
45
|
-
const isStatic = props.__destroyWebGLContextAfterRender === true;
|
|
46
|
-
|
|
47
|
-
const paint = useCallback((renderer: Renderer) => {
|
|
48
|
-
if (pictureRef.current) {
|
|
49
|
-
redrawPendingRef.current = false;
|
|
50
|
-
renderer.draw([pictureRef.current]);
|
|
51
|
-
}
|
|
52
|
-
}, []);
|
|
53
|
-
const rendererRef = useSkiaWebRenderer(canvasRef, isStatic, {
|
|
54
|
-
paint,
|
|
55
|
-
onLayout,
|
|
56
|
-
});
|
|
57
|
-
|
|
58
|
-
const flushRedraw = useCallback(() => {
|
|
59
|
-
flushScheduledRef.current = false;
|
|
60
|
-
if (redrawPendingRef.current && rendererRef.current && pictureRef.current) {
|
|
61
|
-
redrawPendingRef.current = false;
|
|
62
|
-
rendererRef.current.draw([pictureRef.current]);
|
|
63
|
-
}
|
|
64
|
-
// If the renderer or picture isn't available yet, the request stays
|
|
65
|
-
// pending and is flushed by whichever arrives last.
|
|
66
|
-
}, [rendererRef]);
|
|
67
|
-
|
|
68
|
-
const redraw = useCallback(() => {
|
|
69
|
-
redrawPendingRef.current = true;
|
|
70
|
-
if (!flushScheduledRef.current) {
|
|
71
|
-
flushScheduledRef.current = true;
|
|
72
|
-
queueMicrotask(flushRedraw);
|
|
73
|
-
}
|
|
74
|
-
}, [flushRedraw]);
|
|
75
|
-
|
|
76
|
-
const getSize = useCallback(() => {
|
|
77
|
-
return {
|
|
78
|
-
width: canvasRef.current?.clientWidth || 0,
|
|
79
|
-
height: canvasRef.current?.clientHeight || 0,
|
|
80
|
-
};
|
|
81
|
-
}, []);
|
|
82
|
-
|
|
83
|
-
const setPicture = useCallback(
|
|
84
|
-
(newPicture: SkPicture) => {
|
|
85
|
-
pictureRef.current = newPicture;
|
|
86
|
-
redraw();
|
|
87
|
-
},
|
|
88
|
-
[redraw]
|
|
89
|
-
);
|
|
90
|
-
|
|
91
|
-
const makeImageSnapshot = useCallback(
|
|
92
|
-
(rect?: SkRect): SkImage | null => {
|
|
93
|
-
if (rendererRef.current && pictureRef.current) {
|
|
94
|
-
return rendererRef.current.makeImageSnapshot(
|
|
95
|
-
[pictureRef.current],
|
|
96
|
-
rect
|
|
97
|
-
);
|
|
98
|
-
}
|
|
99
|
-
return null;
|
|
100
|
-
},
|
|
101
|
-
[rendererRef]
|
|
102
|
-
);
|
|
103
|
-
|
|
104
|
-
const measure = useCallback(
|
|
105
|
-
(
|
|
106
|
-
callback: (
|
|
107
|
-
x: number,
|
|
108
|
-
y: number,
|
|
109
|
-
width: number,
|
|
110
|
-
height: number,
|
|
111
|
-
pageX: number,
|
|
112
|
-
pageY: number
|
|
113
|
-
) => void
|
|
114
|
-
) => {
|
|
115
|
-
if (canvasRef.current) {
|
|
116
|
-
const rect = canvasRef.current.getBoundingClientRect();
|
|
117
|
-
const parentElement = canvasRef.current.offsetParent as HTMLElement;
|
|
118
|
-
const parentRect = parentElement?.getBoundingClientRect() || {
|
|
119
|
-
left: 0,
|
|
120
|
-
top: 0,
|
|
121
|
-
};
|
|
122
|
-
|
|
123
|
-
// x, y are relative to the parent
|
|
124
|
-
const x = rect.left - parentRect.left;
|
|
125
|
-
const y = rect.top - parentRect.top;
|
|
126
|
-
|
|
127
|
-
// pageX, pageY are absolute screen coordinates
|
|
128
|
-
const pageX = rect.left + window.scrollX;
|
|
129
|
-
const pageY = rect.top + window.scrollY;
|
|
130
|
-
|
|
131
|
-
callback(x, y, rect.width, rect.height, pageX, pageY);
|
|
132
|
-
}
|
|
133
|
-
},
|
|
134
|
-
[]
|
|
135
|
-
);
|
|
136
|
-
|
|
137
|
-
const measureInWindow = useCallback(
|
|
138
|
-
(
|
|
139
|
-
callback: (x: number, y: number, width: number, height: number) => void
|
|
140
|
-
) => {
|
|
141
|
-
if (canvasRef.current) {
|
|
142
|
-
const rect = canvasRef.current.getBoundingClientRect();
|
|
143
|
-
|
|
144
|
-
// x, y are the absolute coordinates in the window
|
|
145
|
-
const x = rect.left;
|
|
146
|
-
const y = rect.top;
|
|
147
|
-
|
|
148
|
-
callback(x, y, rect.width, rect.height);
|
|
149
|
-
}
|
|
150
|
-
},
|
|
151
|
-
[]
|
|
152
|
-
);
|
|
153
|
-
|
|
154
|
-
// No flush cancellation is needed on unmount: a microtask queued before
|
|
155
|
-
// unmount runs within the same task, and flushRedraw no-ops once the
|
|
156
|
-
// layout-effect cleanup has nulled rendererRef.
|
|
157
|
-
|
|
158
|
-
useImperativeHandle(
|
|
159
|
-
ref,
|
|
160
|
-
() => ({
|
|
161
|
-
setPicture,
|
|
162
|
-
getSize,
|
|
163
|
-
redraw,
|
|
164
|
-
makeImageSnapshot,
|
|
165
|
-
measure,
|
|
166
|
-
measureInWindow,
|
|
167
|
-
get canvasRef() {
|
|
168
|
-
return () => canvasRef.current;
|
|
169
|
-
},
|
|
170
|
-
}),
|
|
171
|
-
[setPicture, getSize, redraw, makeImageSnapshot, measure, measureInWindow]
|
|
172
|
-
);
|
|
173
|
-
|
|
174
|
-
useEffect(() => {
|
|
175
|
-
const nativeID = props.nativeID ?? `${SkiaViewNativeId.current++}`;
|
|
176
|
-
const api = global.SkiaViewApi as ISkiaViewApiWeb;
|
|
177
|
-
api.registerView(nativeID, {
|
|
178
|
-
setPicture,
|
|
179
|
-
getSize,
|
|
180
|
-
redraw,
|
|
181
|
-
makeImageSnapshot,
|
|
182
|
-
measure,
|
|
183
|
-
measureInWindow,
|
|
184
|
-
} as SkiaPictureViewHandle);
|
|
185
|
-
return () => {
|
|
186
|
-
api.unregisterView(nativeID);
|
|
187
|
-
};
|
|
188
|
-
}, [
|
|
189
|
-
setPicture,
|
|
190
|
-
getSize,
|
|
191
|
-
redraw,
|
|
192
|
-
makeImageSnapshot,
|
|
193
|
-
measure,
|
|
194
|
-
measureInWindow,
|
|
195
|
-
props.nativeID,
|
|
196
|
-
]);
|
|
197
|
-
|
|
198
|
-
useEffect(() => {
|
|
199
|
-
if (picture) {
|
|
200
|
-
setPicture(picture);
|
|
201
|
-
}
|
|
202
|
-
}, [setPicture, picture]);
|
|
203
|
-
|
|
204
|
-
const {
|
|
205
|
-
debug: _debug,
|
|
206
|
-
ref: _ref,
|
|
207
|
-
onLayout: _onLayout,
|
|
208
|
-
picture: _picture,
|
|
209
|
-
__destroyWebGLContextAfterRender: _isStatic,
|
|
210
|
-
...viewProps
|
|
211
|
-
} = props;
|
|
212
|
-
return (
|
|
213
|
-
<Platform.View {...viewProps}>
|
|
214
|
-
<canvas
|
|
215
|
-
// A canvas element is bound to one context kind for life (WebGL for
|
|
216
|
-
// the live renderer, 2D for the static one), so switching renderers
|
|
217
|
-
// needs a fresh element.
|
|
218
|
-
key={isStatic ? "static" : "webgl"}
|
|
219
|
-
ref={canvasRef}
|
|
220
|
-
style={{ display: "block", width: "100%", height: "100%" }}
|
|
221
|
-
/>
|
|
222
|
-
</Platform.View>
|
|
223
|
-
);
|
|
224
|
-
};
|