react-native-skia 3.0.3 → 3.0.5
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/CMakeLists.txt +0 -2
- package/android/build.gradle +15 -7
- package/android/cpp/jni/JniPlatformContext.cpp +0 -24
- package/android/cpp/jni/include/JniPlatformContext.h +0 -2
- package/android/cpp/rnskia-android/RNSkAndroidPlatformContext.h +0 -140
- package/android/src/main/java/com/reactnative/skia/BackingViewKind.java +24 -0
- package/android/src/main/java/com/reactnative/skia/FrameScheduler.java +104 -0
- package/android/src/main/java/com/reactnative/skia/PlatformContext.java +0 -5
- package/android/src/main/java/com/reactnative/skia/SkiaView.java +55 -44
- package/android/src/test/java/com/reactnative/skia/FrameSchedulerTest.java +186 -0
- package/apple/RNSkApplePlatformContext.h +0 -10
- package/apple/RNSkApplePlatformContext.mm +0 -182
- package/cpp/api/JsiGPUTexture.h +48 -0
- package/cpp/api/JsiSkApi.h +1 -16
- package/cpp/api/JsiSkImage.h +0 -12
- package/cpp/api/JsiSkImageFactory.h +36 -57
- package/cpp/api/JsiSkSurface.h +3 -10
- package/cpp/api/JsiSkSurfaceFactory.h +13 -18
- package/cpp/rnskia/RNDawnContext.h +5 -113
- package/cpp/rnskia/RNDawnUtils.h +33 -0
- package/cpp/rnskia/RNSkPlatformContext.h +0 -54
- package/cpp/rnskia/RNSkView.h +10 -7
- package/lib/commonjs/external/reanimated/index.d.ts +0 -1
- package/lib/commonjs/external/reanimated/index.js +0 -11
- package/lib/commonjs/external/reanimated/index.js.map +1 -1
- package/lib/commonjs/mock/index.js +1 -2
- package/lib/commonjs/mock/index.js.map +1 -1
- package/lib/commonjs/skia/types/GPUTexture.d.ts +11 -0
- package/lib/commonjs/skia/types/GPUTexture.js +2 -0
- package/lib/commonjs/skia/types/GPUTexture.js.map +1 -0
- package/lib/commonjs/skia/types/Image/Image.d.ts +0 -10
- package/lib/commonjs/skia/types/Image/Image.js.map +1 -1
- package/lib/commonjs/skia/types/Image/ImageFactory.d.ts +25 -48
- package/lib/commonjs/skia/types/Image/ImageFactory.js.map +1 -1
- package/lib/commonjs/skia/types/Skia.d.ts +0 -4
- package/lib/commonjs/skia/types/Skia.js.map +1 -1
- package/lib/commonjs/skia/types/Surface/Surface.d.ts +3 -14
- package/lib/commonjs/skia/types/Surface/Surface.js.map +1 -1
- package/lib/commonjs/skia/types/Surface/SurfaceFactory.d.ts +10 -9
- package/lib/commonjs/skia/types/Surface/SurfaceFactory.js.map +1 -1
- package/lib/commonjs/skia/types/index.d.ts +1 -2
- package/lib/commonjs/skia/types/index.js +11 -22
- package/lib/commonjs/skia/types/index.js.map +1 -1
- package/lib/commonjs/skia/web/JsiSkImage.d.ts +0 -1
- package/lib/commonjs/skia/web/JsiSkImage.js +0 -4
- package/lib/commonjs/skia/web/JsiSkImage.js.map +1 -1
- package/lib/commonjs/skia/web/JsiSkImageFactory.d.ts +4 -5
- package/lib/commonjs/skia/web/JsiSkImageFactory.js +6 -10
- package/lib/commonjs/skia/web/JsiSkImageFactory.js.map +1 -1
- package/lib/commonjs/skia/web/JsiSkSurface.d.ts +0 -1
- package/lib/commonjs/skia/web/JsiSkSurface.js +0 -4
- package/lib/commonjs/skia/web/JsiSkSurface.js.map +1 -1
- package/lib/commonjs/skia/web/JsiSkSurfaceFactory.d.ts +2 -2
- package/lib/commonjs/skia/web/JsiSkSurfaceFactory.js +1 -1
- package/lib/commonjs/skia/web/JsiSkSurfaceFactory.js.map +1 -1
- package/lib/commonjs/skia/web/JsiSkia.js +0 -4
- package/lib/commonjs/skia/web/JsiSkia.js.map +1 -1
- package/lib/module/external/reanimated/index.d.ts +0 -1
- package/lib/module/external/reanimated/index.js +0 -1
- package/lib/module/external/reanimated/index.js.map +1 -1
- package/lib/module/mock/index.js +1 -2
- package/lib/module/mock/index.js.map +1 -1
- package/lib/module/skia/types/GPUTexture.d.ts +11 -0
- package/lib/module/skia/types/GPUTexture.js +2 -0
- package/lib/module/skia/types/GPUTexture.js.map +1 -0
- package/lib/module/skia/types/Image/Image.d.ts +0 -10
- package/lib/module/skia/types/Image/Image.js.map +1 -1
- package/lib/module/skia/types/Image/ImageFactory.d.ts +25 -48
- package/lib/module/skia/types/Image/ImageFactory.js.map +1 -1
- package/lib/module/skia/types/Skia.d.ts +0 -4
- package/lib/module/skia/types/Skia.js.map +1 -1
- package/lib/module/skia/types/Surface/Surface.d.ts +3 -14
- package/lib/module/skia/types/Surface/Surface.js.map +1 -1
- package/lib/module/skia/types/Surface/SurfaceFactory.d.ts +10 -9
- package/lib/module/skia/types/Surface/SurfaceFactory.js.map +1 -1
- package/lib/module/skia/types/index.d.ts +1 -2
- package/lib/module/skia/types/index.js +1 -2
- package/lib/module/skia/types/index.js.map +1 -1
- package/lib/module/skia/web/JsiSkImage.d.ts +0 -1
- package/lib/module/skia/web/JsiSkImage.js +0 -4
- package/lib/module/skia/web/JsiSkImage.js.map +1 -1
- package/lib/module/skia/web/JsiSkImageFactory.d.ts +4 -5
- package/lib/module/skia/web/JsiSkImageFactory.js +6 -10
- package/lib/module/skia/web/JsiSkImageFactory.js.map +1 -1
- package/lib/module/skia/web/JsiSkSurface.d.ts +0 -1
- package/lib/module/skia/web/JsiSkSurface.js +0 -4
- package/lib/module/skia/web/JsiSkSurface.js.map +1 -1
- package/lib/module/skia/web/JsiSkSurfaceFactory.d.ts +2 -2
- package/lib/module/skia/web/JsiSkSurfaceFactory.js +1 -1
- package/lib/module/skia/web/JsiSkSurfaceFactory.js.map +1 -1
- package/lib/module/skia/web/JsiSkia.js +0 -4
- package/lib/module/skia/web/JsiSkia.js.map +1 -1
- package/lib/typescript/src/external/reanimated/index.d.ts +0 -1
- package/lib/typescript/src/skia/types/GPUTexture.d.ts +11 -0
- package/lib/typescript/src/skia/types/Image/Image.d.ts +0 -10
- package/lib/typescript/src/skia/types/Image/ImageFactory.d.ts +25 -48
- package/lib/typescript/src/skia/types/Skia.d.ts +0 -4
- package/lib/typescript/src/skia/types/Surface/Surface.d.ts +3 -14
- package/lib/typescript/src/skia/types/Surface/SurfaceFactory.d.ts +10 -9
- package/lib/typescript/src/skia/types/index.d.ts +1 -2
- package/lib/typescript/src/skia/web/JsiSkImage.d.ts +0 -1
- package/lib/typescript/src/skia/web/JsiSkImageFactory.d.ts +4 -5
- package/lib/typescript/src/skia/web/JsiSkSurface.d.ts +0 -1
- package/lib/typescript/src/skia/web/JsiSkSurfaceFactory.d.ts +2 -2
- package/package.json +1 -1
- package/src/external/reanimated/index.ts +0 -1
- package/src/mock/index.ts +0 -1
- package/src/skia/types/GPUTexture.ts +9 -0
- package/src/skia/types/Image/Image.ts +0 -11
- package/src/skia/types/Image/ImageFactory.ts +25 -55
- package/src/skia/types/Skia.ts +0 -4
- package/src/skia/types/Surface/Surface.ts +3 -15
- package/src/skia/types/Surface/SurfaceFactory.ts +11 -9
- package/src/skia/types/index.ts +1 -2
- package/src/skia/web/JsiSkImage.ts +0 -5
- package/src/skia/web/JsiSkImageFactory.ts +16 -16
- package/src/skia/web/JsiSkSurface.ts +0 -5
- package/src/skia/web/JsiSkSurfaceFactory.ts +2 -2
- package/src/skia/web/JsiSkia.ts +0 -4
- package/android/cpp/rnskia-android/AHardwareBufferUtils.cpp +0 -31
- package/android/cpp/rnskia-android/AHardwareBufferUtils.h +0 -13
- package/android/cpp/rnskia-android/RNSkAndroidVideo.cpp +0 -200
- package/android/cpp/rnskia-android/RNSkAndroidVideo.h +0 -44
- package/android/src/main/java/com/reactnative/skia/RNSkVideo.java +0 -320
- package/apple/RNSkAppleVideo.h +0 -78
- package/apple/RNSkAppleVideo.mm +0 -292
- package/cpp/api/JsiNativeBuffer.h +0 -56
- package/cpp/api/JsiTextureInfo.h +0 -53
- package/cpp/api/JsiVideo.h +0 -101
- package/cpp/rnskia/RNSkVideo.h +0 -31
- package/lib/commonjs/external/reanimated/useVideo.d.ts +0 -21
- package/lib/commonjs/external/reanimated/useVideo.js +0 -150
- package/lib/commonjs/external/reanimated/useVideo.js.map +0 -1
- package/lib/commonjs/external/reanimated/useVideoLoading.d.ts +0 -4
- package/lib/commonjs/external/reanimated/useVideoLoading.js +0 -40
- package/lib/commonjs/external/reanimated/useVideoLoading.js.map +0 -1
- package/lib/commonjs/external/reanimated/useVideoLoading.web.d.ts +0 -4
- package/lib/commonjs/external/reanimated/useVideoLoading.web.js +0 -20
- package/lib/commonjs/external/reanimated/useVideoLoading.web.js.map +0 -1
- package/lib/commonjs/skia/types/NativeBuffer/NativeBufferFactory.d.ts +0 -29
- package/lib/commonjs/skia/types/NativeBuffer/NativeBufferFactory.js +0 -15
- package/lib/commonjs/skia/types/NativeBuffer/NativeBufferFactory.js.map +0 -1
- package/lib/commonjs/skia/types/NativeBuffer/index.d.ts +0 -1
- package/lib/commonjs/skia/types/NativeBuffer/index.js +0 -17
- package/lib/commonjs/skia/types/NativeBuffer/index.js.map +0 -1
- package/lib/commonjs/skia/types/Video/Video.d.ts +0 -20
- package/lib/commonjs/skia/types/Video/Video.js +0 -6
- package/lib/commonjs/skia/types/Video/Video.js.map +0 -1
- package/lib/commonjs/skia/types/Video/index.d.ts +0 -1
- package/lib/commonjs/skia/types/Video/index.js +0 -17
- package/lib/commonjs/skia/types/Video/index.js.map +0 -1
- package/lib/commonjs/skia/web/CanvasKitWebGLBufferImpl.d.ts +0 -9
- package/lib/commonjs/skia/web/CanvasKitWebGLBufferImpl.js +0 -30
- package/lib/commonjs/skia/web/CanvasKitWebGLBufferImpl.js.map +0 -1
- package/lib/commonjs/skia/web/JsiSkNativeBufferFactory.d.ts +0 -9
- package/lib/commonjs/skia/web/JsiSkNativeBufferFactory.js +0 -48
- package/lib/commonjs/skia/web/JsiSkNativeBufferFactory.js.map +0 -1
- package/lib/commonjs/skia/web/JsiVideo.d.ts +0 -28
- package/lib/commonjs/skia/web/JsiVideo.js +0 -96
- package/lib/commonjs/skia/web/JsiVideo.js.map +0 -1
- package/lib/module/external/reanimated/useVideo.d.ts +0 -21
- package/lib/module/external/reanimated/useVideo.js +0 -142
- package/lib/module/external/reanimated/useVideo.js.map +0 -1
- package/lib/module/external/reanimated/useVideoLoading.d.ts +0 -4
- package/lib/module/external/reanimated/useVideoLoading.js +0 -33
- package/lib/module/external/reanimated/useVideoLoading.js.map +0 -1
- package/lib/module/external/reanimated/useVideoLoading.web.d.ts +0 -4
- package/lib/module/external/reanimated/useVideoLoading.web.js +0 -13
- package/lib/module/external/reanimated/useVideoLoading.web.js.map +0 -1
- package/lib/module/skia/types/NativeBuffer/NativeBufferFactory.d.ts +0 -29
- package/lib/module/skia/types/NativeBuffer/NativeBufferFactory.js +0 -5
- package/lib/module/skia/types/NativeBuffer/NativeBufferFactory.js.map +0 -1
- package/lib/module/skia/types/NativeBuffer/index.d.ts +0 -1
- package/lib/module/skia/types/NativeBuffer/index.js +0 -2
- package/lib/module/skia/types/NativeBuffer/index.js.map +0 -1
- package/lib/module/skia/types/Video/Video.d.ts +0 -20
- package/lib/module/skia/types/Video/Video.js +0 -2
- package/lib/module/skia/types/Video/Video.js.map +0 -1
- package/lib/module/skia/types/Video/index.d.ts +0 -1
- package/lib/module/skia/types/Video/index.js +0 -2
- package/lib/module/skia/types/Video/index.js.map +0 -1
- package/lib/module/skia/web/CanvasKitWebGLBufferImpl.d.ts +0 -9
- package/lib/module/skia/web/CanvasKitWebGLBufferImpl.js +0 -23
- package/lib/module/skia/web/CanvasKitWebGLBufferImpl.js.map +0 -1
- package/lib/module/skia/web/JsiSkNativeBufferFactory.d.ts +0 -9
- package/lib/module/skia/web/JsiSkNativeBufferFactory.js +0 -41
- package/lib/module/skia/web/JsiSkNativeBufferFactory.js.map +0 -1
- package/lib/module/skia/web/JsiVideo.d.ts +0 -28
- package/lib/module/skia/web/JsiVideo.js +0 -88
- package/lib/module/skia/web/JsiVideo.js.map +0 -1
- package/lib/typescript/src/external/reanimated/useVideo.d.ts +0 -21
- package/lib/typescript/src/external/reanimated/useVideoLoading.d.ts +0 -4
- package/lib/typescript/src/external/reanimated/useVideoLoading.web.d.ts +0 -4
- package/lib/typescript/src/skia/types/NativeBuffer/NativeBufferFactory.d.ts +0 -29
- package/lib/typescript/src/skia/types/NativeBuffer/index.d.ts +0 -1
- package/lib/typescript/src/skia/types/Video/Video.d.ts +0 -20
- package/lib/typescript/src/skia/types/Video/index.d.ts +0 -1
- package/lib/typescript/src/skia/web/CanvasKitWebGLBufferImpl.d.ts +0 -9
- package/lib/typescript/src/skia/web/JsiSkNativeBufferFactory.d.ts +0 -9
- package/lib/typescript/src/skia/web/JsiVideo.d.ts +0 -28
- package/src/external/reanimated/useVideo.ts +0 -161
- package/src/external/reanimated/useVideoLoading.ts +0 -39
- package/src/external/reanimated/useVideoLoading.web.ts +0 -17
- package/src/skia/types/NativeBuffer/NativeBufferFactory.ts +0 -52
- package/src/skia/types/NativeBuffer/index.ts +0 -1
- package/src/skia/types/Video/Video.ts +0 -19
- package/src/skia/types/Video/index.ts +0 -1
- package/src/skia/web/CanvasKitWebGLBufferImpl.ts +0 -25
- package/src/skia/web/JsiSkNativeBufferFactory.ts +0 -51
- package/src/skia/web/JsiVideo.ts +0 -113
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
|
|
7
7
|
#include <jsi/jsi.h>
|
|
8
8
|
|
|
9
|
+
#include "JsiGPUTexture.h"
|
|
9
10
|
#include "JsiSkConverters.h"
|
|
10
11
|
#include "JsiSkData.h"
|
|
11
12
|
#include "JsiSkImage.h"
|
|
@@ -36,12 +37,17 @@ public:
|
|
|
36
37
|
return std::make_shared<JsiSkImage>(getContext(), std::move(image));
|
|
37
38
|
}
|
|
38
39
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
40
|
+
// Native buffers (camera and video frames) are not imported by Skia: they
|
|
41
|
+
// are rendered into a texture of the shared device by react-native-webgpu,
|
|
42
|
+
// and the texture is wrapped with MakeImageFromGPUTexture. The method
|
|
43
|
+
// only exists on Web, where it draws a CanvasImageSource; on native it
|
|
44
|
+
// points callers at the texture path.
|
|
45
|
+
JSI_HOST_FUNCTION(MakeImageFromNativeBuffer) {
|
|
46
|
+
throw std::runtime_error(
|
|
47
|
+
"MakeImageFromNativeBuffer is only available on Web. On native "
|
|
48
|
+
"platforms, copy the frame into a texture with react-native-webgpu's "
|
|
49
|
+
"queue.copyExternalImageToTexture() and wrap the texture with "
|
|
50
|
+
"Skia.Image.MakeImageFromGPUTexture()");
|
|
45
51
|
}
|
|
46
52
|
|
|
47
53
|
std::variant<std::nullptr_t, std::shared_ptr<JsiSkImage>>
|
|
@@ -81,65 +87,38 @@ public:
|
|
|
81
87
|
});
|
|
82
88
|
}
|
|
83
89
|
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
if (image == nullptr) {
|
|
90
|
-
throw std::runtime_error("Failed to convert native texture to SkImage!");
|
|
91
|
-
}
|
|
92
|
-
if (count > 4) {
|
|
93
|
-
auto jsiImage = tryGetJsiObject<JsiSkImage>(runtime, arguments[4]);
|
|
94
|
-
if (jsiImage) {
|
|
95
|
-
jsiImage->setObject(image);
|
|
96
|
-
return jsi::Value(runtime, arguments[4]);
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
return makeJsiObject(
|
|
100
|
-
runtime, std::make_shared<JsiSkImage>(getContext(), std::move(image)));
|
|
101
|
-
}
|
|
90
|
+
// Texture interop with react-native-webgpu. Both packages link one Dawn and
|
|
91
|
+
// share one device, so a GPUTexture created on the shared device
|
|
92
|
+
// (importDevice(Skia.getNativeDevice())) can be wrapped as is. The texture
|
|
93
|
+
// crosses the package boundary through its nativePointer (see
|
|
94
|
+
// JsiGPUTexture.h); the device handoff works the same way.
|
|
102
95
|
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
// boundary as raw WGPUTexture pointers (BigInt), exactly like the device
|
|
106
|
-
// handoff (Skia.getNativeDevice / importDevice). Only sound on the shared
|
|
107
|
-
// device: both packages link one Dawn and share one wgpu::Instance.
|
|
108
|
-
|
|
109
|
-
JSI_HOST_FUNCTION(MakeImageFromNativeTexture) {
|
|
110
|
-
if (count < 1 || !arguments[0].isBigInt()) {
|
|
111
|
-
throw std::runtime_error("MakeImageFromNativeTexture requires a "
|
|
112
|
-
"WGPUTexture pointer (BigInt), e.g. "
|
|
113
|
-
"texture.nativePointer");
|
|
114
|
-
}
|
|
115
|
-
auto raw = reinterpret_cast<WGPUTexture>(
|
|
116
|
-
arguments[0].asBigInt(runtime).asUint64(runtime));
|
|
117
|
-
if (raw == nullptr) {
|
|
96
|
+
JSI_HOST_FUNCTION(MakeImageFromGPUTexture) {
|
|
97
|
+
if (count < 1) {
|
|
118
98
|
throw std::runtime_error(
|
|
119
|
-
"
|
|
99
|
+
"MakeImageFromGPUTexture requires a GPUTexture argument");
|
|
120
100
|
}
|
|
121
|
-
//
|
|
122
|
-
// wrapped SkImage retains the texture for its lifetime (see
|
|
101
|
+
// The wrapped SkImage retains the texture for its lifetime (see
|
|
123
102
|
// DawnContext::MakeImageFromTexture) and the caller keeps ownership of
|
|
124
103
|
// the JS GPUTexture.
|
|
125
|
-
|
|
126
|
-
|
|
104
|
+
wgpu::Texture texture =
|
|
105
|
+
gpuTextureFromValue(runtime, arguments[0], "MakeImageFromGPUTexture");
|
|
127
106
|
auto &dawnContext = DawnContext::getInstance();
|
|
128
107
|
auto image = dawnContext.MakeImageFromTexture(
|
|
129
108
|
texture, static_cast<int>(texture.GetWidth()),
|
|
130
109
|
static_cast<int>(texture.GetHeight()), texture.GetFormat());
|
|
131
110
|
if (image == nullptr) {
|
|
132
111
|
throw std::runtime_error(
|
|
133
|
-
"
|
|
112
|
+
"MakeImageFromGPUTexture: failed to wrap the texture");
|
|
134
113
|
}
|
|
135
114
|
return makeJsiObject(
|
|
136
115
|
runtime, std::make_shared<JsiSkImage>(getContext(), std::move(image)));
|
|
137
116
|
}
|
|
138
117
|
|
|
139
|
-
JSI_HOST_FUNCTION(
|
|
118
|
+
JSI_HOST_FUNCTION(MakeGPUTextureFromImage) {
|
|
140
119
|
if (count < 1) {
|
|
141
120
|
throw std::runtime_error(
|
|
142
|
-
"
|
|
121
|
+
"MakeGPUTextureFromImage requires an SkImage argument");
|
|
143
122
|
}
|
|
144
123
|
auto image = JsiSkImage::fromValue(runtime, arguments[0]);
|
|
145
124
|
if (!image) {
|
|
@@ -149,11 +128,13 @@ public:
|
|
|
149
128
|
wgpu::Texture texture = dawnContext.MakeTextureFromImage(image);
|
|
150
129
|
if (!texture) {
|
|
151
130
|
throw std::runtime_error(
|
|
152
|
-
"
|
|
131
|
+
"MakeGPUTextureFromImage: failed to create the texture");
|
|
153
132
|
}
|
|
154
133
|
// Transfer ownership: the returned pointer carries one reference and must
|
|
155
134
|
// be adopted exactly once (react-native-webgpu's adoptTexture()), which
|
|
156
|
-
// releases it when the JS GPUTexture is destroyed.
|
|
135
|
+
// releases it when the JS GPUTexture is destroyed. Only react-native-webgpu
|
|
136
|
+
// can build the typed GPUTexture object, which is why this returns a
|
|
137
|
+
// pointer while MakeImageFromGPUTexture takes the object.
|
|
157
138
|
return jsi::BigInt::fromUint64(
|
|
158
139
|
runtime, reinterpret_cast<uint64_t>(texture.MoveToCHandle()));
|
|
159
140
|
}
|
|
@@ -165,17 +146,15 @@ public:
|
|
|
165
146
|
&JsiSkImageFactory::MakeImageFromEncoded);
|
|
166
147
|
installHostMethod(runtime, prototype, "MakeImageFromViewTag",
|
|
167
148
|
&JsiSkImageFactory::MakeImageFromViewTag);
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
installHostMethod(runtime, prototype, "MakeImageFromNativeTextureUnstable",
|
|
171
|
-
&JsiSkImageFactory::MakeImageFromNativeTextureUnstable);
|
|
149
|
+
installHostMethod(runtime, prototype, "MakeImageFromNativeBuffer",
|
|
150
|
+
&JsiSkImageFactory::MakeImageFromNativeBuffer);
|
|
172
151
|
installMethod(runtime, prototype, "MakeImage",
|
|
173
152
|
&JsiSkImageFactory::MakeImage);
|
|
174
153
|
installMethod(runtime, prototype, "MakeNull", &JsiSkImageFactory::MakeNull);
|
|
175
|
-
installHostMethod(runtime, prototype, "
|
|
176
|
-
&JsiSkImageFactory::
|
|
177
|
-
installHostMethod(runtime, prototype, "
|
|
178
|
-
&JsiSkImageFactory::
|
|
154
|
+
installHostMethod(runtime, prototype, "MakeImageFromGPUTexture",
|
|
155
|
+
&JsiSkImageFactory::MakeImageFromGPUTexture);
|
|
156
|
+
installHostMethod(runtime, prototype, "MakeGPUTextureFromImage",
|
|
157
|
+
&JsiSkImageFactory::MakeGPUTextureFromImage);
|
|
179
158
|
}
|
|
180
159
|
|
|
181
160
|
explicit JsiSkImageFactory(std::shared_ptr<RNSkPlatformContext> context)
|
package/cpp/api/JsiSkSurface.h
CHANGED
|
@@ -10,7 +10,6 @@
|
|
|
10
10
|
#include "JsiSkConverters.h"
|
|
11
11
|
#include "JsiSkDispatcher.h"
|
|
12
12
|
#include "JsiSkNativeObjects.h"
|
|
13
|
-
#include "JsiTextureInfo.h"
|
|
14
13
|
|
|
15
14
|
#include "JsiSkCanvas.h"
|
|
16
15
|
#include "JsiSkImage.h"
|
|
@@ -81,8 +80,9 @@ public:
|
|
|
81
80
|
void flush(JsiOptional<bool> syncParam) {
|
|
82
81
|
auto surface = getObject();
|
|
83
82
|
// When `sync` is true, block until the GPU has finished executing the
|
|
84
|
-
// submitted work. Required before a
|
|
85
|
-
//
|
|
83
|
+
// submitted work. Required before a consumer on a different command queue
|
|
84
|
+
// (a secondary Dawn device, for instance) reads the texture this surface
|
|
85
|
+
// draws into (see Surface.MakeFromGPUTexture). #3916
|
|
86
86
|
bool sync = syncParam.has_value() && *syncParam;
|
|
87
87
|
// A raster surface (e.g. Skia.Surface.Make) has no Graphite recorder;
|
|
88
88
|
// only Graphite-backed surfaces need to snap and submit a recording.
|
|
@@ -119,11 +119,6 @@ public:
|
|
|
119
119
|
runtime, std::make_shared<JsiSkImage>(getContext(), std::move(image)));
|
|
120
120
|
}
|
|
121
121
|
|
|
122
|
-
JSI_HOST_FUNCTION(getNativeTextureUnstable) {
|
|
123
|
-
auto texInfo = getContext()->getTexture(getObject());
|
|
124
|
-
return JsiTextureInfo::toValue(runtime, texInfo);
|
|
125
|
-
}
|
|
126
|
-
|
|
127
122
|
size_t getMemoryPressure() override {
|
|
128
123
|
if (isDisposed()) {
|
|
129
124
|
return 0;
|
|
@@ -185,8 +180,6 @@ public:
|
|
|
185
180
|
installHostMethod(runtime, prototype, "makeImageSnapshot",
|
|
186
181
|
&JsiSkSurface::makeImageSnapshot);
|
|
187
182
|
installMethod(runtime, prototype, "flush", &JsiSkSurface::flush);
|
|
188
|
-
installHostMethod(runtime, prototype, "getNativeTextureUnstable",
|
|
189
|
-
&JsiSkSurface::getNativeTextureUnstable);
|
|
190
183
|
}
|
|
191
184
|
};
|
|
192
185
|
|
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
|
|
7
7
|
#include <jsi/jsi.h>
|
|
8
8
|
|
|
9
|
+
#include "JsiGPUTexture.h"
|
|
9
10
|
#include "JsiSkNativeObjects.h"
|
|
10
11
|
|
|
11
12
|
#include "JsiSkSurface.h"
|
|
@@ -62,29 +63,23 @@ public:
|
|
|
62
63
|
}
|
|
63
64
|
|
|
64
65
|
// Pointer-based texture interop with react-native-webgpu, the surface
|
|
65
|
-
// counterpart of JsiSkImageFactory::
|
|
66
|
+
// counterpart of JsiSkImageFactory::MakeImageFromGPUTexture: Skia draws
|
|
66
67
|
// directly into a texture created on the shared device, so WebGPU can
|
|
67
68
|
// sample what Skia drew without any copy.
|
|
68
|
-
JSI_HOST_FUNCTION(
|
|
69
|
-
if (count < 1
|
|
70
|
-
throw std::runtime_error("MakeFromNativeTexture requires a WGPUTexture "
|
|
71
|
-
"pointer (BigInt), e.g. texture.nativePointer");
|
|
72
|
-
}
|
|
73
|
-
auto raw = reinterpret_cast<WGPUTexture>(
|
|
74
|
-
arguments[0].asBigInt(runtime).asUint64(runtime));
|
|
75
|
-
if (raw == nullptr) {
|
|
69
|
+
JSI_HOST_FUNCTION(MakeFromGPUTexture) {
|
|
70
|
+
if (count < 1) {
|
|
76
71
|
throw std::runtime_error(
|
|
77
|
-
"
|
|
72
|
+
"MakeFromGPUTexture requires a GPUTexture argument");
|
|
78
73
|
}
|
|
79
|
-
//
|
|
80
|
-
//
|
|
81
|
-
//
|
|
82
|
-
|
|
83
|
-
|
|
74
|
+
// The surface keeps the texture alive for its lifetime, and the JS
|
|
75
|
+
// GPUTexture keeps its own reference, which the caller may release once
|
|
76
|
+
// the surface exists.
|
|
77
|
+
wgpu::Texture texture =
|
|
78
|
+
gpuTextureFromValue(runtime, arguments[0], "MakeFromGPUTexture");
|
|
84
79
|
auto surface = DawnContext::getInstance().MakeSurfaceFromTexture(texture);
|
|
85
80
|
if (surface == nullptr) {
|
|
86
81
|
throw std::runtime_error(
|
|
87
|
-
"
|
|
82
|
+
"MakeFromGPUTexture: failed to wrap the texture");
|
|
88
83
|
}
|
|
89
84
|
return makeJsiObject(runtime, std::make_shared<JsiSkSurface>(
|
|
90
85
|
getContext(), std::move(surface)));
|
|
@@ -96,8 +91,8 @@ public:
|
|
|
96
91
|
installMethod(runtime, prototype, "Make", &JsiSkSurfaceFactory::Make);
|
|
97
92
|
installHostMethod(runtime, prototype, "MakeOffscreen",
|
|
98
93
|
&JsiSkSurfaceFactory::MakeOffscreen);
|
|
99
|
-
installHostMethod(runtime, prototype, "
|
|
100
|
-
&JsiSkSurfaceFactory::
|
|
94
|
+
installHostMethod(runtime, prototype, "MakeFromGPUTexture",
|
|
95
|
+
&JsiSkSurfaceFactory::MakeFromGPUTexture);
|
|
101
96
|
}
|
|
102
97
|
|
|
103
98
|
explicit JsiSkSurfaceFactory(std::shared_ptr<RNSkPlatformContext> context)
|
|
@@ -25,13 +25,6 @@
|
|
|
25
25
|
|
|
26
26
|
#include "src/gpu/graphite/ContextOptionsPriv.h"
|
|
27
27
|
|
|
28
|
-
#ifdef __APPLE__
|
|
29
|
-
#include <CoreVideo/CVPixelBuffer.h>
|
|
30
|
-
#else
|
|
31
|
-
#include <android/hardware_buffer.h>
|
|
32
|
-
#include <android/hardware_buffer_jni.h>
|
|
33
|
-
#endif
|
|
34
|
-
|
|
35
28
|
namespace RNSkia {
|
|
36
29
|
|
|
37
30
|
struct AsyncContext {
|
|
@@ -39,11 +32,6 @@ struct AsyncContext {
|
|
|
39
32
|
std::unique_ptr<const SkSurface::AsyncReadResult> fResult;
|
|
40
33
|
};
|
|
41
34
|
|
|
42
|
-
struct SharedTextureContext {
|
|
43
|
-
wgpu::SharedTextureMemory sharedTextureMemory;
|
|
44
|
-
wgpu::Texture texture;
|
|
45
|
-
};
|
|
46
|
-
|
|
47
35
|
static void
|
|
48
36
|
async_callback(void *c,
|
|
49
37
|
std::unique_ptr<const SkImage::AsyncReadResult> result) {
|
|
@@ -54,9 +42,6 @@ async_callback(void *c,
|
|
|
54
42
|
|
|
55
43
|
class DawnContext {
|
|
56
44
|
public:
|
|
57
|
-
// TODO: remove
|
|
58
|
-
friend class RNSkApplePlatformContext;
|
|
59
|
-
|
|
60
45
|
DawnContext(const DawnContext &) = delete;
|
|
61
46
|
DawnContext &operator=(const DawnContext &) = delete;
|
|
62
47
|
|
|
@@ -143,84 +128,6 @@ public:
|
|
|
143
128
|
fGraphiteContext->submit(syncToCpu);
|
|
144
129
|
}
|
|
145
130
|
|
|
146
|
-
sk_sp<SkImage> MakeImageFromBuffer(void *buffer) {
|
|
147
|
-
#if defined(__ANDROID__) && __ANDROID_API__ < 26
|
|
148
|
-
// AHardwareBuffer is only available from API 26
|
|
149
|
-
(void)buffer;
|
|
150
|
-
return nullptr;
|
|
151
|
-
#else
|
|
152
|
-
#ifdef __APPLE__
|
|
153
|
-
wgpu::SharedTextureMemoryIOSurfaceDescriptor platformDesc;
|
|
154
|
-
auto ioSurface = CVPixelBufferGetIOSurface((CVPixelBufferRef)buffer);
|
|
155
|
-
platformDesc.ioSurface = ioSurface;
|
|
156
|
-
int width = static_cast<int>(IOSurfaceGetWidth(ioSurface));
|
|
157
|
-
int height = static_cast<int>(IOSurfaceGetHeight(ioSurface));
|
|
158
|
-
#else
|
|
159
|
-
wgpu::SharedTextureMemoryAHardwareBufferDescriptor platformDesc;
|
|
160
|
-
auto ahb = reinterpret_cast<AHardwareBuffer *>(buffer);
|
|
161
|
-
platformDesc.handle = ahb;
|
|
162
|
-
AHardwareBuffer_Desc adesc;
|
|
163
|
-
AHardwareBuffer_describe(ahb, &adesc);
|
|
164
|
-
int width = adesc.width;
|
|
165
|
-
int height = adesc.height;
|
|
166
|
-
#endif
|
|
167
|
-
|
|
168
|
-
wgpu::SharedTextureMemoryDescriptor desc = {};
|
|
169
|
-
desc.nextInChain = &platformDesc;
|
|
170
|
-
wgpu::SharedTextureMemory memory =
|
|
171
|
-
backendContext.fDevice.ImportSharedTextureMemory(&desc);
|
|
172
|
-
|
|
173
|
-
wgpu::TextureDescriptor textureDesc;
|
|
174
|
-
textureDesc.format = DawnUtils::PreferredTextureFormat;
|
|
175
|
-
textureDesc.dimension = wgpu::TextureDimension::e2D;
|
|
176
|
-
textureDesc.usage =
|
|
177
|
-
wgpu::TextureUsage::TextureBinding | wgpu::TextureUsage::CopySrc;
|
|
178
|
-
textureDesc.size = {static_cast<uint32_t>(width),
|
|
179
|
-
static_cast<uint32_t>(height), 1};
|
|
180
|
-
|
|
181
|
-
wgpu::Texture texture = memory.CreateTexture(&textureDesc);
|
|
182
|
-
|
|
183
|
-
wgpu::SharedTextureMemoryBeginAccessDescriptor beginAccessDesc;
|
|
184
|
-
beginAccessDesc.initialized = true;
|
|
185
|
-
beginAccessDesc.fenceCount = 0;
|
|
186
|
-
#if defined(__ANDROID__)
|
|
187
|
-
// Dawn's Vulkan backend requires the acquired VkImageLayout to be chained.
|
|
188
|
-
// UNDEFINED (= 0) on both ends is the canonical "no prior GPU producer"
|
|
189
|
-
// pattern (matches GPUSharedTextureMemory::beginAccess).
|
|
190
|
-
wgpu::SharedTextureMemoryVkImageLayoutBeginState vkBegin = {};
|
|
191
|
-
vkBegin.oldLayout = 0;
|
|
192
|
-
vkBegin.newLayout = 0;
|
|
193
|
-
beginAccessDesc.nextInChain = &vkBegin;
|
|
194
|
-
#endif
|
|
195
|
-
bool success =
|
|
196
|
-
memory.BeginAccess(texture, &beginAccessDesc) == wgpu::Status::Success;
|
|
197
|
-
|
|
198
|
-
if (success) {
|
|
199
|
-
skgpu::graphite::BackendTexture betFromView =
|
|
200
|
-
skgpu::graphite::BackendTextures::MakeDawn(texture.Get());
|
|
201
|
-
auto result = SkImages::WrapTexture(
|
|
202
|
-
getRecorder(), betFromView, DawnUtils::PreferedColorType,
|
|
203
|
-
kPremul_SkAlphaType, nullptr,
|
|
204
|
-
[](void *context) {
|
|
205
|
-
auto ctx = static_cast<SharedTextureContext *>(context);
|
|
206
|
-
wgpu::SharedTextureMemoryEndAccessState endState = {};
|
|
207
|
-
#if defined(__ANDROID__)
|
|
208
|
-
wgpu::SharedTextureMemoryVkImageLayoutEndState vkEnd = {};
|
|
209
|
-
endState.nextInChain = &vkEnd;
|
|
210
|
-
#endif
|
|
211
|
-
ctx->sharedTextureMemory.EndAccess(ctx->texture, &endState);
|
|
212
|
-
delete ctx;
|
|
213
|
-
},
|
|
214
|
-
new SharedTextureContext{memory, texture});
|
|
215
|
-
return result;
|
|
216
|
-
}
|
|
217
|
-
if (!success) {
|
|
218
|
-
return nullptr;
|
|
219
|
-
}
|
|
220
|
-
return nullptr;
|
|
221
|
-
#endif
|
|
222
|
-
}
|
|
223
|
-
|
|
224
131
|
// Create offscreen surface
|
|
225
132
|
sk_sp<SkSurface> MakeOffscreen(int width, int height,
|
|
226
133
|
bool useP3ColorSpace = false) {
|
|
@@ -276,26 +183,11 @@ public:
|
|
|
276
183
|
return nullptr;
|
|
277
184
|
}
|
|
278
185
|
|
|
279
|
-
// Map WebGPU format to Skia color type
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
break;
|
|
285
|
-
case wgpu::TextureFormat::BGRA8Unorm:
|
|
286
|
-
colorType = kBGRA_8888_SkColorType;
|
|
287
|
-
break;
|
|
288
|
-
case wgpu::TextureFormat::RGBA16Float:
|
|
289
|
-
colorType = kRGBA_F16_SkColorType;
|
|
290
|
-
break;
|
|
291
|
-
case wgpu::TextureFormat::R8Unorm:
|
|
292
|
-
colorType = kGray_8_SkColorType;
|
|
293
|
-
break;
|
|
294
|
-
default:
|
|
295
|
-
// Use preferred color type for unsupported formats
|
|
296
|
-
colorType = DawnUtils::PreferedColorType;
|
|
297
|
-
break;
|
|
298
|
-
}
|
|
186
|
+
// Map the WebGPU format to a Skia color type; fall back to the preferred
|
|
187
|
+
// color type for formats Skia does not sample.
|
|
188
|
+
SkColorType colorType =
|
|
189
|
+
DawnUtils::colorTypeForTextureFormat(format).value_or(
|
|
190
|
+
DawnUtils::PreferedColorType);
|
|
299
191
|
|
|
300
192
|
skgpu::graphite::BackendTexture backendTexture =
|
|
301
193
|
skgpu::graphite::BackendTextures::MakeDawn(texture.Get());
|
package/cpp/rnskia/RNDawnUtils.h
CHANGED
|
@@ -4,6 +4,8 @@
|
|
|
4
4
|
#include <TargetConditionals.h>
|
|
5
5
|
#endif
|
|
6
6
|
|
|
7
|
+
#include <optional>
|
|
8
|
+
|
|
7
9
|
#include "webgpu/webgpu_cpp.h"
|
|
8
10
|
|
|
9
11
|
#include "dawn/native/DawnNative.h"
|
|
@@ -79,6 +81,28 @@ inline wgpu::TextureFormat textureFormatForColorType(SkColorType colorType) {
|
|
|
79
81
|
}
|
|
80
82
|
}
|
|
81
83
|
|
|
84
|
+
// The color type Skia samples a texture of the given format with, or none
|
|
85
|
+
// when Skia cannot sample the format: multi-planar YUV (the biplanar
|
|
86
|
+
// 4:2:0 formats of an NV12 IOSurface, OpaqueYCbCrAndroid), depth/stencil and
|
|
87
|
+
// compressed formats.
|
|
88
|
+
inline std::optional<SkColorType>
|
|
89
|
+
colorTypeForTextureFormat(wgpu::TextureFormat format) {
|
|
90
|
+
switch (format) {
|
|
91
|
+
case wgpu::TextureFormat::RGBA8Unorm:
|
|
92
|
+
return kRGBA_8888_SkColorType;
|
|
93
|
+
case wgpu::TextureFormat::BGRA8Unorm:
|
|
94
|
+
return kBGRA_8888_SkColorType;
|
|
95
|
+
case wgpu::TextureFormat::RGBA16Float:
|
|
96
|
+
return kRGBA_F16_SkColorType;
|
|
97
|
+
case wgpu::TextureFormat::RGB10A2Unorm:
|
|
98
|
+
return kRGBA_1010102_SkColorType;
|
|
99
|
+
case wgpu::TextureFormat::R8Unorm:
|
|
100
|
+
return kGray_8_SkColorType;
|
|
101
|
+
default:
|
|
102
|
+
return std::nullopt;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
82
106
|
// Find the best matching GPU adapter for the current platform.
|
|
83
107
|
// Sorts by adapter type (DiscreteGPU > IntegratedGPU > CPU) and selects the
|
|
84
108
|
// first adapter matching the platform backend (Metal on Apple, Vulkan on
|
|
@@ -294,6 +318,15 @@ createDawnBackendContext(dawn::native::Instance *instance) {
|
|
|
294
318
|
// Vulkan equivalent of the above: EndAccess exports a sync-fd fence.
|
|
295
319
|
wgpu::FeatureName::SharedFenceSyncFD,
|
|
296
320
|
wgpu::FeatureName::SharedFenceVkSemaphoreOpaqueFD,
|
|
321
|
+
// Video and camera frames are YUV AHardwareBuffers. Dawn imports them
|
|
322
|
+
// as OpaqueYCbCrAndroid textures, a format it only accepts on a device
|
|
323
|
+
// with one of its two YCbCr features, and react-native-webgpu samples
|
|
324
|
+
// them as external textures (importExternalTexture,
|
|
325
|
+
// copyExternalImageToTexture), which needs this one in particular.
|
|
326
|
+
// Without it, importing a frame on the shared device fails with
|
|
327
|
+
// "Unsupported texture format TextureFormat::OpaqueYCbCrAndroid".
|
|
328
|
+
// Experimental in Dawn, hence the allow_unsafe_apis instance toggle.
|
|
329
|
+
wgpu::FeatureName::OpaqueYCbCrAndroidForExternalTexture,
|
|
297
330
|
#endif
|
|
298
331
|
};
|
|
299
332
|
|
|
@@ -10,7 +10,6 @@
|
|
|
10
10
|
#include <utility>
|
|
11
11
|
#include <vector>
|
|
12
12
|
|
|
13
|
-
#include "RNSkVideo.h"
|
|
14
13
|
#include "RNWindowContext.h"
|
|
15
14
|
|
|
16
15
|
#pragma clang diagnostic push
|
|
@@ -30,14 +29,6 @@ namespace RNSkia {
|
|
|
30
29
|
|
|
31
30
|
namespace react = facebook::react;
|
|
32
31
|
|
|
33
|
-
struct TextureInfo {
|
|
34
|
-
const void *mtlTexture = nullptr;
|
|
35
|
-
unsigned int glTarget = 0;
|
|
36
|
-
unsigned int glID = 0;
|
|
37
|
-
unsigned int glFormat = 0;
|
|
38
|
-
bool glProtected = false;
|
|
39
|
-
};
|
|
40
|
-
|
|
41
32
|
class RNSkPlatformContext {
|
|
42
33
|
public:
|
|
43
34
|
/**
|
|
@@ -96,51 +87,6 @@ public:
|
|
|
96
87
|
virtual sk_sp<SkSurface>
|
|
97
88
|
makeOffscreenSurface(int width, int height, bool useP3ColorSpace = false) = 0;
|
|
98
89
|
|
|
99
|
-
/**
|
|
100
|
-
* Creates an image from a native buffer.
|
|
101
|
-
* - On iOS, this is a `CVPixelBufferRef`
|
|
102
|
-
* - On Android, this is a `AHardwareBuffer*`
|
|
103
|
-
* @param buffer The native buffer.
|
|
104
|
-
* @return sk_sp<SkImage>
|
|
105
|
-
*/
|
|
106
|
-
virtual sk_sp<SkImage> makeImageFromNativeBuffer(void *buffer) = 0;
|
|
107
|
-
|
|
108
|
-
// The handle-based texture interop of the Ganesh era (Metal and OpenGL
|
|
109
|
-
// texture handles). Graphite textures cross the package boundary as
|
|
110
|
-
// WGPUTexture pointers instead (see JsiSkImageFactory).
|
|
111
|
-
sk_sp<SkImage> makeImageFromNativeTexture(const TextureInfo &textureInfo,
|
|
112
|
-
int width, int height,
|
|
113
|
-
bool mipMapped) {
|
|
114
|
-
throw std::runtime_error(
|
|
115
|
-
"makeImageFromNativeTexture is not available on Graphite, use "
|
|
116
|
-
"Skia.Image.MakeImageFromNativeTexture(pointer)");
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
const TextureInfo getTexture(sk_sp<SkSurface> image) {
|
|
120
|
-
throw std::runtime_error(
|
|
121
|
-
"getTexture(surface) is not available on Graphite, use "
|
|
122
|
-
"Skia.Surface.MakeFromNativeTexture(pointer)");
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
const TextureInfo getTexture(sk_sp<SkImage> image) {
|
|
126
|
-
throw std::runtime_error(
|
|
127
|
-
"getTexture(image) is not available on Graphite, use "
|
|
128
|
-
"Skia.Image.MakeNativeTextureFromImage(image)");
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
virtual void releaseNativeBuffer(uint64_t pointer) = 0;
|
|
132
|
-
|
|
133
|
-
virtual uint64_t makeNativeBuffer(sk_sp<SkImage> image) = 0;
|
|
134
|
-
|
|
135
|
-
// Allocate a platform native buffer (IOSurface on Apple, AHardwareBuffer on
|
|
136
|
-
// Android) of the given size filled with a procedural test pattern (RGB
|
|
137
|
-
// gradient + diagonal stripes), entirely on the CPU. Intended for examples
|
|
138
|
-
// and tests that need a buffer to feed into importExternalTexture without a
|
|
139
|
-
// camera/video source. Release it with releaseNativeBuffer().
|
|
140
|
-
virtual uint64_t makeTestNativeBuffer(int width, int height) = 0;
|
|
141
|
-
|
|
142
|
-
virtual std::shared_ptr<RNSkVideo> createVideo(const std::string &url) = 0;
|
|
143
|
-
|
|
144
90
|
/**
|
|
145
91
|
* Return the Platform specific font manager
|
|
146
92
|
*/
|
package/cpp/rnskia/RNSkView.h
CHANGED
|
@@ -38,7 +38,8 @@ namespace jsi = facebook::jsi;
|
|
|
38
38
|
* (SkiaViewApi.makeGraphiteContext), or <Canvas> hands over a recorder (or a
|
|
39
39
|
* picture) that the render thread pool records for the view. Either way the
|
|
40
40
|
* recordings are queued on the target; the view presents them onto its canvas
|
|
41
|
-
* provider on the main thread,
|
|
41
|
+
* provider on the main thread, once the platform view's surface can show a new
|
|
42
|
+
* frame (see setFrameScheduler).
|
|
42
43
|
*
|
|
43
44
|
* Threading: the registry side (RNSkJsiViewApi) runs on the JS thread, except
|
|
44
45
|
* applyUpdates() which a Reanimated mapper calls on the UI runtime; snapshots
|
|
@@ -248,8 +249,10 @@ public:
|
|
|
248
249
|
// Platform view side -------------------------------------------------------
|
|
249
250
|
|
|
250
251
|
/**
|
|
251
|
-
Installed by the platform view
|
|
252
|
-
|
|
252
|
+
Installed by the platform view, which calls presentFrame() once its surface
|
|
253
|
+
can show a new frame: on the display link on iOS, straight away on macOS,
|
|
254
|
+
and on Android as its FrameScheduler decides. Main thread. Without one,
|
|
255
|
+
frames are presented as soon as the main thread gets to them.
|
|
253
256
|
*/
|
|
254
257
|
void setFrameScheduler(std::function<void()> scheduler) {
|
|
255
258
|
_frameScheduler = std::move(scheduler);
|
|
@@ -265,10 +268,10 @@ public:
|
|
|
265
268
|
}
|
|
266
269
|
|
|
267
270
|
/**
|
|
268
|
-
|
|
269
|
-
are waiting, so that the
|
|
270
|
-
present failed (the app is in the background), so that the recordings
|
|
271
|
-
tried again on the next frame rather than left waiting for a redraw.
|
|
271
|
+
Presents the queued recordings (see setFrameScheduler for when). Returns
|
|
272
|
+
whether more are waiting, so that the platform view asks again: also when
|
|
273
|
+
the present failed (the app is in the background), so that the recordings
|
|
274
|
+
are tried again on the next frame rather than left waiting for a redraw.
|
|
272
275
|
Without a surface the queue is left alone: the surface presents it when
|
|
273
276
|
it appears.
|
|
274
277
|
*/
|
|
@@ -58,15 +58,4 @@ Object.keys(_buffers).forEach(function (key) {
|
|
|
58
58
|
}
|
|
59
59
|
});
|
|
60
60
|
});
|
|
61
|
-
var _useVideo = require("./useVideo");
|
|
62
|
-
Object.keys(_useVideo).forEach(function (key) {
|
|
63
|
-
if (key === "default" || key === "__esModule") return;
|
|
64
|
-
if (key in exports && exports[key] === _useVideo[key]) return;
|
|
65
|
-
Object.defineProperty(exports, key, {
|
|
66
|
-
enumerable: true,
|
|
67
|
-
get: function () {
|
|
68
|
-
return _useVideo[key];
|
|
69
|
-
}
|
|
70
|
-
});
|
|
71
|
-
});
|
|
72
61
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_useAnimatedImageValue","require","Object","keys","forEach","key","exports","defineProperty","enumerable","get","_renderHelpers","_interpolators","_textures","_buffers"
|
|
1
|
+
{"version":3,"names":["_useAnimatedImageValue","require","Object","keys","forEach","key","exports","defineProperty","enumerable","get","_renderHelpers","_interpolators","_textures","_buffers"],"sources":["index.ts"],"sourcesContent":["export * from \"./useAnimatedImageValue\";\nexport * from \"./renderHelpers\";\nexport * from \"./interpolators\";\nexport * from \"./textures\";\nexport * from \"./buffers\";\n"],"mappings":";;;;;AAAA,IAAAA,sBAAA,GAAAC,OAAA;AAAAC,MAAA,CAAAC,IAAA,CAAAH,sBAAA,EAAAI,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAA,GAAA,IAAAC,OAAA,IAAAA,OAAA,CAAAD,GAAA,MAAAL,sBAAA,CAAAK,GAAA;EAAAH,MAAA,CAAAK,cAAA,CAAAD,OAAA,EAAAD,GAAA;IAAAG,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAT,sBAAA,CAAAK,GAAA;IAAA;EAAA;AAAA;AACA,IAAAK,cAAA,GAAAT,OAAA;AAAAC,MAAA,CAAAC,IAAA,CAAAO,cAAA,EAAAN,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAA,GAAA,IAAAC,OAAA,IAAAA,OAAA,CAAAD,GAAA,MAAAK,cAAA,CAAAL,GAAA;EAAAH,MAAA,CAAAK,cAAA,CAAAD,OAAA,EAAAD,GAAA;IAAAG,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAC,cAAA,CAAAL,GAAA;IAAA;EAAA;AAAA;AACA,IAAAM,cAAA,GAAAV,OAAA;AAAAC,MAAA,CAAAC,IAAA,CAAAQ,cAAA,EAAAP,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAA,GAAA,IAAAC,OAAA,IAAAA,OAAA,CAAAD,GAAA,MAAAM,cAAA,CAAAN,GAAA;EAAAH,MAAA,CAAAK,cAAA,CAAAD,OAAA,EAAAD,GAAA;IAAAG,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAE,cAAA,CAAAN,GAAA;IAAA;EAAA;AAAA;AACA,IAAAO,SAAA,GAAAX,OAAA;AAAAC,MAAA,CAAAC,IAAA,CAAAS,SAAA,EAAAR,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAA,GAAA,IAAAC,OAAA,IAAAA,OAAA,CAAAD,GAAA,MAAAO,SAAA,CAAAP,GAAA;EAAAH,MAAA,CAAAK,cAAA,CAAAD,OAAA,EAAAD,GAAA;IAAAG,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAG,SAAA,CAAAP,GAAA;IAAA;EAAA;AAAA;AACA,IAAAQ,QAAA,GAAAZ,OAAA;AAAAC,MAAA,CAAAC,IAAA,CAAAU,QAAA,EAAAT,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAA,GAAA,IAAAC,OAAA,IAAAA,OAAA,CAAAD,GAAA,MAAAQ,QAAA,CAAAR,GAAA;EAAAH,MAAA,CAAAK,cAAA,CAAAD,OAAA,EAAAD,GAAA;IAAAG,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAI,QAAA,CAAAR,GAAA;IAAA;EAAA;AAAA","ignoreList":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_web","require","_JsiSkImage","Noop","undefined","NoopValue","current","NoopSharedValue","value","Mock","CanvasKit","global","SkiaApi","JsiSkApi","Skia","Canvas","View","getPreferredHighBitDepthCanvasFormat","SkiaPictureView","SkiaGraphiteView","JsiSkImage","drawAsPicture","drawAsImage","drawAsImageFromPicture","useCanvasRef","useCanvasSize","ref","size","width","height","useValue","useComputedValue","useTiming","useLoop","useSpring","useClockValue","useValueEffect","isOnMainThread","useClock","usePathInterpolation","useImageAsTexture","useTextureValue","useTextureValueFromPicture","useRSXformBuffer","usePointBuffer","useColorBuffer","useRectBuffer","useBuffer","useRawData","useData","useFont","Font","useFonts","useTypeface","useImage","useSVG","
|
|
1
|
+
{"version":3,"names":["_web","require","_JsiSkImage","Noop","undefined","NoopValue","current","NoopSharedValue","value","Mock","CanvasKit","global","SkiaApi","JsiSkApi","Skia","Canvas","View","getPreferredHighBitDepthCanvasFormat","SkiaPictureView","SkiaGraphiteView","JsiSkImage","drawAsPicture","drawAsImage","drawAsImageFromPicture","useCanvasRef","useCanvasSize","ref","size","width","height","useValue","useComputedValue","useTiming","useLoop","useSpring","useClockValue","useValueEffect","isOnMainThread","useClock","usePathInterpolation","useImageAsTexture","useTextureValue","useTextureValueFromPicture","useRSXformBuffer","usePointBuffer","useColorBuffer","useRectBuffer","useBuffer","useRawData","useData","useFont","Font","useFonts","useTypeface","useImage","useSVG","exports"],"sources":["index.ts"],"sourcesContent":["import type { CanvasKit } from \"canvaskit-wasm\";\n\nimport { JsiSkApi } from \"../skia/web\";\nimport { JsiSkImage } from \"../skia/web/JsiSkImage\";\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nconst Noop: () => any = () => undefined;\nconst NoopValue = () => ({ current: 0 });\nconst NoopSharedValue = () => ({ value: 0 });\n\nexport const Mock = (CanvasKit: CanvasKit) => {\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n global.SkiaApi = JsiSkApi(CanvasKit);\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n const Skia = global.SkiaApi;\n return {\n Skia,\n ...require(\"../renderer/components\"),\n ...require(\"../skia\"),\n ...require(\"../animation\"),\n ...require(\"../dom/types\"),\n ...require(\"../dom/nodes\"),\n Canvas: require(\"react-native\").View,\n getPreferredHighBitDepthCanvasFormat: () => \"rgba16float\",\n SkiaPictureView: require(\"react-native\").View,\n SkiaGraphiteView: require(\"react-native\").View,\n JsiSkImage: JsiSkImage,\n drawAsPicture: Noop,\n drawAsImage: Noop,\n drawAsImageFromPicture: Noop,\n useCanvasRef: NoopValue,\n useCanvasSize: () => ({\n ref: {\n current: 0,\n },\n size: {\n width: 0,\n height: 0,\n },\n }),\n // Skia Animations\n useValue: NoopValue,\n useComputedValue: NoopValue,\n useTiming: NoopValue,\n useLoop: NoopValue,\n useSpring: NoopValue,\n useClockValue: NoopValue,\n useValueEffect: Noop,\n // Reanimated hooks\n isOnMainThread: () => true,\n useClock: NoopSharedValue,\n usePathInterpolation: NoopSharedValue,\n useImageAsTexture: NoopSharedValue,\n useTextureValue: NoopSharedValue,\n useTextureValueFromPicture: NoopSharedValue,\n useRSXformBuffer: NoopSharedValue,\n usePointBuffer: NoopSharedValue,\n useColorBuffer: NoopSharedValue,\n useRectBuffer: NoopSharedValue,\n useBuffer: NoopSharedValue,\n useRawData: Noop,\n useData: Noop,\n useFont: () => Skia.Font(undefined, 0),\n useFonts: Noop,\n useTypeface: () => null,\n useImage: () => null,\n useSVG: () => null,\n };\n};\n"],"mappings":";;;;;;AAEA,IAAAA,IAAA,GAAAC,OAAA;AACA,IAAAC,WAAA,GAAAD,OAAA;AAEA;AACA,MAAME,IAAe,GAAGA,CAAA,KAAMC,SAAS;AACvC,MAAMC,SAAS,GAAGA,CAAA,MAAO;EAAEC,OAAO,EAAE;AAAE,CAAC,CAAC;AACxC,MAAMC,eAAe,GAAGA,CAAA,MAAO;EAAEC,KAAK,EAAE;AAAE,CAAC,CAAC;AAErC,MAAMC,IAAI,GAAIC,SAAoB,IAAK;EAC5C;EACA;EACAC,MAAM,CAACC,OAAO,GAAG,IAAAC,aAAQ,EAACH,SAAS,CAAC;EACpC;EACA;EACA,MAAMI,IAAI,GAAGH,MAAM,CAACC,OAAO;EAC3B,OAAO;IACLE,IAAI;IACJ,GAAGb,OAAO,CAAC,wBAAwB,CAAC;IACpC,GAAGA,OAAO,CAAC,SAAS,CAAC;IACrB,GAAGA,OAAO,CAAC,cAAc,CAAC;IAC1B,GAAGA,OAAO,CAAC,cAAc,CAAC;IAC1B,GAAGA,OAAO,CAAC,cAAc,CAAC;IAC1Bc,MAAM,EAAEd,OAAO,CAAC,cAAc,CAAC,CAACe,IAAI;IACpCC,oCAAoC,EAAEA,CAAA,KAAM,aAAa;IACzDC,eAAe,EAAEjB,OAAO,CAAC,cAAc,CAAC,CAACe,IAAI;IAC7CG,gBAAgB,EAAElB,OAAO,CAAC,cAAc,CAAC,CAACe,IAAI;IAC9CI,UAAU,EAAEA,sBAAU;IACtBC,aAAa,EAAElB,IAAI;IACnBmB,WAAW,EAAEnB,IAAI;IACjBoB,sBAAsB,EAAEpB,IAAI;IAC5BqB,YAAY,EAAEnB,SAAS;IACvBoB,aAAa,EAAEA,CAAA,MAAO;MACpBC,GAAG,EAAE;QACHpB,OAAO,EAAE;MACX,CAAC;MACDqB,IAAI,EAAE;QACJC,KAAK,EAAE,CAAC;QACRC,MAAM,EAAE;MACV;IACF,CAAC,CAAC;IACF;IACAC,QAAQ,EAAEzB,SAAS;IACnB0B,gBAAgB,EAAE1B,SAAS;IAC3B2B,SAAS,EAAE3B,SAAS;IACpB4B,OAAO,EAAE5B,SAAS;IAClB6B,SAAS,EAAE7B,SAAS;IACpB8B,aAAa,EAAE9B,SAAS;IACxB+B,cAAc,EAAEjC,IAAI;IACpB;IACAkC,cAAc,EAAEA,CAAA,KAAM,IAAI;IAC1BC,QAAQ,EAAE/B,eAAe;IACzBgC,oBAAoB,EAAEhC,eAAe;IACrCiC,iBAAiB,EAAEjC,eAAe;IAClCkC,eAAe,EAAElC,eAAe;IAChCmC,0BAA0B,EAAEnC,eAAe;IAC3CoC,gBAAgB,EAAEpC,eAAe;IACjCqC,cAAc,EAAErC,eAAe;IAC/BsC,cAAc,EAAEtC,eAAe;IAC/BuC,aAAa,EAAEvC,eAAe;IAC9BwC,SAAS,EAAExC,eAAe;IAC1ByC,UAAU,EAAE7C,IAAI;IAChB8C,OAAO,EAAE9C,IAAI;IACb+C,OAAO,EAAEA,CAAA,KAAMpC,IAAI,CAACqC,IAAI,CAAC/C,SAAS,EAAE,CAAC,CAAC;IACtCgD,QAAQ,EAAEjD,IAAI;IACdkD,WAAW,EAAEA,CAAA,KAAM,IAAI;IACvBC,QAAQ,EAAEA,CAAA,KAAM,IAAI;IACpBC,MAAM,EAAEA,CAAA,KAAM;EAChB,CAAC;AACH,CAAC;AAACC,OAAA,CAAA/C,IAAA,GAAAA,IAAA","ignoreList":[]}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A WebGPU texture, as accepted by `Skia.Image.MakeImageFromGPUTexture` and
|
|
3
|
+
* `Skia.Surface.MakeFromGPUTexture`: a `GPUTexture` created with React Native
|
|
4
|
+
* WebGPU on the shared device, whose `nativePointer` (a non-spec extension)
|
|
5
|
+
* holds the `WGPUTexture` handle. The handle itself, as a `BigInt`, is
|
|
6
|
+
* accepted too for libraries that export textures without React Native
|
|
7
|
+
* WebGPU.
|
|
8
|
+
*/
|
|
9
|
+
export type GPUTextureHandle = {
|
|
10
|
+
readonly nativePointer: bigint;
|
|
11
|
+
} | bigint;
|