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
package/src/renderer/Canvas.tsx
CHANGED
|
@@ -19,8 +19,9 @@ import type { SharedValue } from "react-native-reanimated";
|
|
|
19
19
|
|
|
20
20
|
import Rea from "../external/reanimated/ReanimatedProxy";
|
|
21
21
|
import { SkiaViewNativeId } from "../views/SkiaViewNativeId";
|
|
22
|
-
import
|
|
23
|
-
import
|
|
22
|
+
import { androidNativeProps } from "../views/android";
|
|
23
|
+
import type { AndroidCanvasProps } from "../views/types";
|
|
24
|
+
import SkiaViewNativeComponent from "../specs/SkiaViewNativeComponent";
|
|
24
25
|
import type { SkImage, SkRect, SkSize } from "../skia/types";
|
|
25
26
|
import { SkiaSGRoot } from "../sksg/Reconciler";
|
|
26
27
|
import { Skia } from "../skia";
|
|
@@ -61,7 +62,6 @@ export const useCanvasSize = (userRef?: RefObject<CanvasRef | null>) => {
|
|
|
61
62
|
};
|
|
62
63
|
|
|
63
64
|
export interface CanvasProps extends Omit<ViewProps, "onLayout"> {
|
|
64
|
-
debug?: boolean;
|
|
65
65
|
/** @deprecated Not supported on native. Use `onSize` or `useCanvasSize()` instead. */
|
|
66
66
|
onLayout?: ViewProps["onLayout"];
|
|
67
67
|
/**
|
|
@@ -72,7 +72,6 @@ export interface CanvasProps extends Omit<ViewProps, "onLayout"> {
|
|
|
72
72
|
*/
|
|
73
73
|
opaque?: boolean;
|
|
74
74
|
onSize?: SharedValue<SkSize>;
|
|
75
|
-
colorSpace?: "p3" | "srgb";
|
|
76
75
|
/**
|
|
77
76
|
* Renders into a surface with more than 8 bits per channel (16-bit float on
|
|
78
77
|
* iOS, 10-bit on Android) to avoid banding in subtle gradients. Colors are
|
|
@@ -85,25 +84,14 @@ export interface CanvasProps extends Omit<ViewProps, "onLayout"> {
|
|
|
85
84
|
/** Android-only rendering options. Ignored on iOS and web. */
|
|
86
85
|
android?: AndroidCanvasProps;
|
|
87
86
|
ref?: React.Ref<CanvasRef>;
|
|
88
|
-
androidWarmup?: boolean;
|
|
89
87
|
__destroyWebGLContextAfterRender?: boolean;
|
|
90
88
|
}
|
|
91
89
|
|
|
92
|
-
// Anything else reaching the native component would hit the generated
|
|
93
|
-
// string-enum parser, which aborts on unknown values.
|
|
94
|
-
const resolveSurfaceType = (
|
|
95
|
-
surfaceType: AndroidSurfaceType | undefined
|
|
96
|
-
): "auto" | AndroidSurfaceType =>
|
|
97
|
-
surfaceType === "SurfaceView" || surfaceType === "TextureView"
|
|
98
|
-
? surfaceType
|
|
99
|
-
: "auto";
|
|
100
|
-
|
|
101
90
|
/**
|
|
102
|
-
* What
|
|
103
|
-
*
|
|
104
|
-
* imperative handle of the ref.
|
|
91
|
+
* What the canvas owns: the native id, the scene graph root rendered into it,
|
|
92
|
+
* the `onSize` measurement and the imperative handle of the ref.
|
|
105
93
|
*/
|
|
106
|
-
|
|
94
|
+
const useCanvasRoot = ({
|
|
107
95
|
children,
|
|
108
96
|
onSize,
|
|
109
97
|
ref,
|
|
@@ -186,14 +174,26 @@ export const useCanvasRoot = ({
|
|
|
186
174
|
return { nativeId, viewRef };
|
|
187
175
|
};
|
|
188
176
|
|
|
177
|
+
/**
|
|
178
|
+
* The declarative canvas. Its children are rendered by Skia's own React
|
|
179
|
+
* renderer; the frames are produced off the JS thread:
|
|
180
|
+
*
|
|
181
|
+
* - the JS thread records the scene graph into a native recorder once per
|
|
182
|
+
* React commit and hands it to the view;
|
|
183
|
+
* - the Reanimated UI runtime only reads the shared values into it (the one
|
|
184
|
+
* step that needs a JS runtime), it never replays anything;
|
|
185
|
+
* - a dedicated native thread pool replays the recorder into a Graphite
|
|
186
|
+
* recording whenever the content changed, at most once per presented frame;
|
|
187
|
+
* - the view presents the recording on the next vsync.
|
|
188
|
+
*
|
|
189
|
+
* On the web the scene is drawn into a picture on the JS thread and painted
|
|
190
|
+
* on a WebGL canvas.
|
|
191
|
+
*/
|
|
189
192
|
export const Canvas = ({
|
|
190
|
-
debug,
|
|
191
193
|
opaque,
|
|
192
194
|
children,
|
|
193
195
|
onSize,
|
|
194
|
-
colorSpace = "p3",
|
|
195
196
|
highBitDepth = false,
|
|
196
|
-
androidWarmup = false,
|
|
197
197
|
android,
|
|
198
198
|
ref,
|
|
199
199
|
onLayout,
|
|
@@ -219,17 +219,13 @@ export const Canvas = ({
|
|
|
219
219
|
[onLayout, onSize]
|
|
220
220
|
);
|
|
221
221
|
return (
|
|
222
|
-
<
|
|
222
|
+
<SkiaViewNativeComponent
|
|
223
223
|
ref={viewRef}
|
|
224
224
|
collapsable={false}
|
|
225
225
|
nativeID={`${nativeId}`}
|
|
226
|
-
debug={debug}
|
|
227
226
|
opaque={opaque}
|
|
228
|
-
colorSpace={colorSpace}
|
|
229
227
|
highBitDepth={highBitDepth}
|
|
230
|
-
|
|
231
|
-
androidSurfaceType={resolveSurfaceType(android?.surfaceType)}
|
|
232
|
-
androidZOrderOnTop={!!android?.zOrderOnTop}
|
|
228
|
+
{...androidNativeProps(android)}
|
|
233
229
|
onLayout={
|
|
234
230
|
Platform.OS === "web" && (onSize || onLayout) ? onLayoutWeb : onLayout
|
|
235
231
|
}
|
|
@@ -2,13 +2,13 @@ import type { SkCanvas } from "./Canvas";
|
|
|
2
2
|
import type { SkJSIInstance } from "./JsiInstance";
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
|
-
* A frame recorded for a
|
|
6
|
-
*
|
|
5
|
+
* A frame recorded for a view. Immutable once finished: submit it to the view
|
|
6
|
+
* as many times as needed, from any runtime.
|
|
7
7
|
*/
|
|
8
8
|
export type SkGraphiteRecording = SkJSIInstance<"GraphiteRecording">;
|
|
9
9
|
|
|
10
10
|
/**
|
|
11
|
-
* The recording side of a
|
|
11
|
+
* The recording side of a view, obtained from the ref of a SkiaGraphiteView.
|
|
12
12
|
*
|
|
13
13
|
* Frames are recorded on the calling thread and presented by the view on its
|
|
14
14
|
* display link, so the context can be captured into a worklet and used from
|
|
@@ -106,7 +106,7 @@ export interface ImageFactory {
|
|
|
106
106
|
* while the image is in use: destroy() releases the underlying GPU
|
|
107
107
|
* resource regardless of reference counts.
|
|
108
108
|
*
|
|
109
|
-
*
|
|
109
|
+
* Native only.
|
|
110
110
|
*
|
|
111
111
|
* @param pointer - The WGPUTexture pointer (texture.nativePointer)
|
|
112
112
|
* @returns An SkImage wrapping the texture, or throws if the texture is invalid
|
|
@@ -119,7 +119,7 @@ export interface ImageFactory {
|
|
|
119
119
|
* returned pointer carries one reference and must be adopted exactly once
|
|
120
120
|
* with react-native-webgpu's adoptTexture(), which owns it from then on.
|
|
121
121
|
*
|
|
122
|
-
*
|
|
122
|
+
* Native only.
|
|
123
123
|
*
|
|
124
124
|
* @param image - An SkImage to convert to a texture
|
|
125
125
|
* @returns A WGPUTexture pointer for adoptTexture(), or throws on failure
|
package/src/skia/types/Skia.ts
CHANGED
|
@@ -106,8 +106,7 @@ export interface Skia {
|
|
|
106
106
|
/**
|
|
107
107
|
* Raw WGPUDevice pointer of Skia's Graphite device, as a BigInt. Pass it to
|
|
108
108
|
* react-native-webgpu's importDevice() to get a GPUDevice sharing Skia's
|
|
109
|
-
* device (zero-copy interop).
|
|
110
|
-
* otherwise.
|
|
109
|
+
* device (zero-copy interop). Native only.
|
|
111
110
|
*/
|
|
112
111
|
getNativeDevice(): bigint;
|
|
113
112
|
}
|
|
@@ -43,7 +43,7 @@ export interface SurfaceFactory {
|
|
|
43
43
|
* surface exists. Calling destroy() on the GPUTexture still invalidates
|
|
44
44
|
* the surface.
|
|
45
45
|
*
|
|
46
|
-
*
|
|
46
|
+
* Native only.
|
|
47
47
|
*
|
|
48
48
|
* @param pointer - The WGPUTexture pointer (texture.nativePointer)
|
|
49
49
|
* @returns An SkSurface rendering into the texture, or throws if the texture is invalid
|
|
@@ -7,8 +7,12 @@ import type {
|
|
|
7
7
|
} from "../skia/types";
|
|
8
8
|
import type { ISkiaViewApi } from "../views/types";
|
|
9
9
|
|
|
10
|
-
/** What
|
|
10
|
+
/** What the web view registers under its native id. */
|
|
11
11
|
export interface SkiaWebViewHandle {
|
|
12
|
+
/** Shows a picture: the frame of a <Canvas> or a <SkiaPictureView>. */
|
|
13
|
+
setPicture(picture: SkPicture): void;
|
|
14
|
+
/** The recording side of the view, see SkiaGraphiteView. */
|
|
15
|
+
getContext(): SkGraphiteContext;
|
|
12
16
|
getSize(): { width: number; height: number };
|
|
13
17
|
redraw(): void;
|
|
14
18
|
makeImageSnapshot(rect?: SkRect): SkImage | null;
|
|
@@ -27,20 +31,6 @@ export interface SkiaWebViewHandle {
|
|
|
27
31
|
): void;
|
|
28
32
|
}
|
|
29
33
|
|
|
30
|
-
export interface SkiaGraphiteViewHandle extends SkiaWebViewHandle {
|
|
31
|
-
getContext(): SkGraphiteContext;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
interface PictureHandle extends SkiaWebViewHandle {
|
|
35
|
-
setPicture(picture: SkPicture): void;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
const hasPicture = (view: SkiaWebViewHandle): view is PictureHandle =>
|
|
39
|
-
"setPicture" in view;
|
|
40
|
-
|
|
41
|
-
const hasContext = (view: SkiaWebViewHandle): view is SkiaGraphiteViewHandle =>
|
|
42
|
-
"getContext" in view;
|
|
43
|
-
|
|
44
34
|
export type ISkiaViewApiWeb = ISkiaViewApi & {
|
|
45
35
|
views: Record<string, SkiaWebViewHandle>;
|
|
46
36
|
deferedPictures: Record<string, SkPicture>;
|
|
@@ -58,7 +48,7 @@ global.SkiaViewApi = {
|
|
|
58
48
|
registerView(nativeId: string, view: SkiaWebViewHandle) {
|
|
59
49
|
this.unregisteredViews.delete(nativeId);
|
|
60
50
|
// Maybe a picture for this view was already set
|
|
61
|
-
if (this.deferedPictures[nativeId]
|
|
51
|
+
if (this.deferedPictures[nativeId]) {
|
|
62
52
|
view.setPicture(this.deferedPictures[nativeId] as SkPicture);
|
|
63
53
|
delete this.deferedPictures[nativeId];
|
|
64
54
|
}
|
|
@@ -77,9 +67,7 @@ global.SkiaViewApi = {
|
|
|
77
67
|
const id = `${nativeId}`;
|
|
78
68
|
const view = this.views[id];
|
|
79
69
|
if (view) {
|
|
80
|
-
|
|
81
|
-
view.setPicture(value);
|
|
82
|
-
}
|
|
70
|
+
view.setPicture(value);
|
|
83
71
|
} else if (!this.unregisteredViews.has(id)) {
|
|
84
72
|
this.deferedPictures[id] = value;
|
|
85
73
|
}
|
|
@@ -114,9 +102,9 @@ global.SkiaViewApi = {
|
|
|
114
102
|
},
|
|
115
103
|
makeGraphiteContext(nativeId: number) {
|
|
116
104
|
const view = this.views[`${nativeId}`];
|
|
117
|
-
if (!view
|
|
105
|
+
if (!view) {
|
|
118
106
|
throw new Error(
|
|
119
|
-
`Cannot make a Graphite context: no
|
|
107
|
+
`Cannot make a Graphite context: no view with nativeID ${nativeId} is mounted`
|
|
120
108
|
);
|
|
121
109
|
}
|
|
122
110
|
return view.getContext();
|
|
@@ -4,11 +4,8 @@ import type { WithDefault } from "react-native/Libraries/Types/CodegenTypes";
|
|
|
4
4
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
5
5
|
// @ts-ignore - pointerEvents needs to be redeclared for codegen to generate native bindings
|
|
6
6
|
export interface NativeProps extends ViewProps {
|
|
7
|
-
debug?: boolean;
|
|
8
7
|
opaque?: boolean;
|
|
9
|
-
colorSpace?: string;
|
|
10
8
|
highBitDepth?: boolean;
|
|
11
|
-
androidWarmup?: boolean;
|
|
12
9
|
androidSurfaceType?: WithDefault<
|
|
13
10
|
"auto" | "SurfaceView" | "TextureView",
|
|
14
11
|
"auto"
|
|
@@ -21,4 +18,4 @@ export interface NativeProps extends ViewProps {
|
|
|
21
18
|
}
|
|
22
19
|
|
|
23
20
|
// eslint-disable-next-line import/no-default-export
|
|
24
|
-
export default codegenNativeComponent<NativeProps>("
|
|
21
|
+
export default codegenNativeComponent<NativeProps>("SkiaView");
|
|
@@ -1,33 +1,31 @@
|
|
|
1
1
|
import type { ViewProps } from "react-native";
|
|
2
2
|
import { createElement } from "react";
|
|
3
3
|
|
|
4
|
-
import {
|
|
4
|
+
import { SkiaView } from "../views/SkiaView.web";
|
|
5
5
|
|
|
6
6
|
export interface NativeProps extends ViewProps {
|
|
7
|
-
debug?: boolean;
|
|
8
7
|
opaque?: boolean;
|
|
8
|
+
highBitDepth?: boolean;
|
|
9
9
|
nativeID: string;
|
|
10
10
|
androidSurfaceType?: "auto" | "SurfaceView" | "TextureView";
|
|
11
11
|
androidZOrderOnTop?: boolean;
|
|
12
12
|
}
|
|
13
13
|
|
|
14
|
-
const
|
|
14
|
+
const SkiaViewNativeComponent = ({
|
|
15
15
|
nativeID,
|
|
16
|
-
debug,
|
|
17
|
-
opaque,
|
|
18
16
|
onLayout,
|
|
19
|
-
//
|
|
17
|
+
// Surface settings, never reach the DOM
|
|
18
|
+
opaque: _opaque,
|
|
19
|
+
highBitDepth: _highBitDepth,
|
|
20
20
|
androidSurfaceType: _androidSurfaceType,
|
|
21
21
|
androidZOrderOnTop: _androidZOrderOnTop,
|
|
22
22
|
...viewProps
|
|
23
23
|
}: NativeProps) => {
|
|
24
|
-
return createElement(
|
|
24
|
+
return createElement(SkiaView, {
|
|
25
25
|
nativeID,
|
|
26
|
-
debug,
|
|
27
|
-
opaque,
|
|
28
26
|
onLayout,
|
|
29
27
|
...viewProps,
|
|
30
28
|
});
|
|
31
29
|
};
|
|
32
30
|
// eslint-disable-next-line import/no-default-export
|
|
33
|
-
export default
|
|
31
|
+
export default SkiaViewNativeComponent;
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import React, { useImperativeHandle, useMemo, useRef } from "react";
|
|
2
2
|
|
|
3
3
|
import type { SkGraphiteContext } from "../skia/types";
|
|
4
|
-
import
|
|
4
|
+
import SkiaViewNativeComponent from "../specs/SkiaViewNativeComponent";
|
|
5
|
+
import { Platform } from "../Platform";
|
|
5
6
|
|
|
6
7
|
import { SkiaViewApi } from "./api";
|
|
8
|
+
import { androidNativeProps } from "./android";
|
|
7
9
|
import type { SkiaGraphiteViewNativeProps } from "./types";
|
|
8
10
|
import { SkiaViewNativeId } from "./SkiaViewNativeId";
|
|
9
11
|
|
|
@@ -20,40 +22,49 @@ export interface SkiaGraphiteViewProps extends SkiaGraphiteViewNativeProps {
|
|
|
20
22
|
ref?: React.Ref<SkiaGraphiteViewRef>;
|
|
21
23
|
}
|
|
22
24
|
|
|
25
|
+
// The layout is known synchronously on the new architecture;
|
|
26
|
+
// getBoundingClientRect became stable in React Native 0.83. On the web the
|
|
27
|
+
// view measures itself (see SkiaView.web).
|
|
28
|
+
const measureLayout = (view: unknown) => {
|
|
29
|
+
if (Platform.OS === "web") {
|
|
30
|
+
return { width: 0, height: 0 };
|
|
31
|
+
}
|
|
32
|
+
const host = view as {
|
|
33
|
+
getBoundingClientRect?: () => { width: number; height: number };
|
|
34
|
+
unstable_getBoundingClientRect: () => { width: number; height: number };
|
|
35
|
+
};
|
|
36
|
+
return host.getBoundingClientRect
|
|
37
|
+
? host.getBoundingClientRect()
|
|
38
|
+
: host.unstable_getBoundingClientRect();
|
|
39
|
+
};
|
|
40
|
+
|
|
23
41
|
/**
|
|
24
|
-
* A view
|
|
25
|
-
*
|
|
26
|
-
* nothing. See {@link SkGraphiteContext}.
|
|
42
|
+
* A view whose frames are recorded from JavaScript, on any runtime, through
|
|
43
|
+
* the context of its ref. See {@link SkGraphiteContext}.
|
|
27
44
|
*/
|
|
28
45
|
export const SkiaGraphiteView = ({
|
|
29
|
-
debug = false,
|
|
30
46
|
opaque = false,
|
|
31
47
|
highBitDepth = false,
|
|
48
|
+
android,
|
|
32
49
|
ref,
|
|
33
50
|
...viewProps
|
|
34
51
|
}: SkiaGraphiteViewProps) => {
|
|
35
52
|
const nativeId = useMemo(() => SkiaViewNativeId.current++, []);
|
|
36
53
|
const viewRef =
|
|
37
|
-
useRef<React.ComponentRef<typeof
|
|
54
|
+
useRef<React.ComponentRef<typeof SkiaViewNativeComponent>>(null);
|
|
38
55
|
useImperativeHandle(
|
|
39
56
|
ref,
|
|
40
57
|
() => ({
|
|
41
58
|
getNativeId: () => nativeId,
|
|
42
59
|
getContext: () => {
|
|
43
60
|
assertSkiaViewApi();
|
|
44
|
-
|
|
45
|
-
const view = viewRef.current as any;
|
|
61
|
+
const view = viewRef.current;
|
|
46
62
|
if (!view) {
|
|
47
63
|
throw new Error(
|
|
48
64
|
"SkiaGraphiteView: getContext() was called before the view was mounted."
|
|
49
65
|
);
|
|
50
66
|
}
|
|
51
|
-
|
|
52
|
-
// getBoundingClientRect became stable in React Native 0.83.
|
|
53
|
-
const size =
|
|
54
|
-
"getBoundingClientRect" in view
|
|
55
|
-
? view.getBoundingClientRect()
|
|
56
|
-
: view.unstable_getBoundingClientRect();
|
|
67
|
+
const size = measureLayout(view);
|
|
57
68
|
return SkiaViewApi.makeGraphiteContext(
|
|
58
69
|
nativeId,
|
|
59
70
|
size.width,
|
|
@@ -66,13 +77,13 @@ export const SkiaGraphiteView = ({
|
|
|
66
77
|
[nativeId, opaque, highBitDepth]
|
|
67
78
|
);
|
|
68
79
|
return (
|
|
69
|
-
<
|
|
80
|
+
<SkiaViewNativeComponent
|
|
70
81
|
ref={viewRef}
|
|
71
82
|
collapsable={false}
|
|
72
83
|
nativeID={`${nativeId}`}
|
|
73
|
-
debug={debug}
|
|
74
84
|
opaque={opaque}
|
|
75
85
|
highBitDepth={highBitDepth}
|
|
86
|
+
{...androidNativeProps(android)}
|
|
76
87
|
{...viewProps}
|
|
77
88
|
/>
|
|
78
89
|
);
|
|
@@ -1,19 +1,21 @@
|
|
|
1
1
|
import React from "react";
|
|
2
2
|
|
|
3
3
|
import type { SkRect } from "../skia/types";
|
|
4
|
-
import
|
|
4
|
+
import SkiaViewNativeComponent from "../specs/SkiaViewNativeComponent";
|
|
5
5
|
|
|
6
6
|
import { SkiaViewApi } from "./api";
|
|
7
|
+
import { androidNativeProps } from "./android";
|
|
7
8
|
import type { SkiaPictureViewNativeProps } from "./types";
|
|
8
9
|
import { SkiaViewNativeId } from "./SkiaViewNativeId";
|
|
9
10
|
|
|
10
|
-
const NativeSkiaPictureView = SkiaPictureViewNativeComponent;
|
|
11
|
-
|
|
12
11
|
interface SkiaPictureViewProps extends SkiaPictureViewNativeProps {
|
|
13
12
|
mode?: "default" | "continuous";
|
|
14
|
-
androidWarmup?: boolean;
|
|
15
13
|
}
|
|
16
14
|
|
|
15
|
+
/**
|
|
16
|
+
* A view showing a picture. The picture is handed to the native view, which
|
|
17
|
+
* records it once (and again on every redraw) for its surface.
|
|
18
|
+
*/
|
|
17
19
|
export class SkiaPictureView extends React.Component<SkiaPictureViewProps> {
|
|
18
20
|
private requestId = 0;
|
|
19
21
|
|
|
@@ -76,21 +78,20 @@ export class SkiaPictureView extends React.Component<SkiaPictureViewProps> {
|
|
|
76
78
|
|
|
77
79
|
render() {
|
|
78
80
|
const {
|
|
79
|
-
mode,
|
|
80
|
-
|
|
81
|
+
mode: _mode,
|
|
82
|
+
picture: _picture,
|
|
81
83
|
opaque = false,
|
|
82
84
|
highBitDepth = false,
|
|
83
|
-
|
|
85
|
+
android,
|
|
84
86
|
...viewProps
|
|
85
87
|
} = this.props;
|
|
86
88
|
return (
|
|
87
|
-
<
|
|
89
|
+
<SkiaViewNativeComponent
|
|
88
90
|
collapsable={false}
|
|
89
91
|
nativeID={`${this._nativeId}`}
|
|
90
|
-
debug={debug}
|
|
91
92
|
opaque={opaque}
|
|
92
93
|
highBitDepth={highBitDepth}
|
|
93
|
-
|
|
94
|
+
{...androidNativeProps(android)}
|
|
94
95
|
{...viewProps}
|
|
95
96
|
/>
|
|
96
97
|
);
|