react-native-skia 3.0.4 → 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/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/PlatformContext.java +0 -5
- 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/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
|
@@ -12,17 +12,6 @@ export interface SkSurface extends SkJSIInstance<"Surface"> {
|
|
|
12
12
|
example: https://fiddle.skia.org/c/@Surface_getCanvas
|
|
13
13
|
*/
|
|
14
14
|
getCanvas(): SkCanvas;
|
|
15
|
-
/**
|
|
16
|
-
* Returns the backend texture of the surface.
|
|
17
|
-
* The returned object can be used to create a Skia Image object.
|
|
18
|
-
* The returned object is backend specific and should be used with caution.
|
|
19
|
-
* It is the caller's responsibility to ensure that the texture is not used after the surface is deleted
|
|
20
|
-
* or draw operations are performed on the surface.
|
|
21
|
-
* The returned object may be null if the surface does not have a backend texture.
|
|
22
|
-
*
|
|
23
|
-
* @return backend texture of the surface or null
|
|
24
|
-
*/
|
|
25
|
-
getNativeTextureUnstable(): unknown;
|
|
26
15
|
/** Returns Image capturing Surface contents. Subsequent drawing to
|
|
27
16
|
Surface contents are not captured.
|
|
28
17
|
|
|
@@ -36,9 +25,9 @@ export interface SkSurface extends SkJSIInstance<"Surface"> {
|
|
|
36
25
|
/**
|
|
37
26
|
* Make sure any queued draws are sent to the screen or the GPU.
|
|
38
27
|
* @param sync - When true, block until the GPU has finished executing the
|
|
39
|
-
* submitted work. Use this before
|
|
40
|
-
*
|
|
41
|
-
* Defaults to false.
|
|
28
|
+
* submitted work. Use this before a consumer on a different command queue
|
|
29
|
+
* reads the texture this surface draws into (see
|
|
30
|
+
* `Skia.Surface.MakeFromGPUTexture`). Defaults to false.
|
|
42
31
|
*/
|
|
43
32
|
flush(sync?: boolean): void;
|
|
44
33
|
/**
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { GPUTextureHandle } from "../GPUTexture";
|
|
1
2
|
import type { SkSurface } from "./Surface";
|
|
2
3
|
export declare const ColorSpace: {
|
|
3
4
|
readonly SRGB: "srgb";
|
|
@@ -25,18 +26,18 @@ export interface SurfaceFactory {
|
|
|
25
26
|
MakeOffscreen: (width: number, height: number, opts?: SurfaceOptions) => SkSurface | null;
|
|
26
27
|
/**
|
|
27
28
|
* Creates a GPU backed surface that draws directly into a WebGPU texture
|
|
28
|
-
* (zero-copy). The texture must be created
|
|
29
|
-
* (importDevice(Skia.getNativeDevice())) with
|
|
30
|
-
* TEXTURE_BINDING to sample what Skia drew
|
|
31
|
-
* The surface holds its own reference to
|
|
32
|
-
* for its lifetime, so the caller may
|
|
33
|
-
* surface exists. Calling destroy() on the
|
|
34
|
-
* the surface.
|
|
29
|
+
* (zero-copy). The texture must be created with React Native WebGPU on
|
|
30
|
+
* the shared device (importDevice(Skia.getNativeDevice())) with the
|
|
31
|
+
* RENDER_ATTACHMENT usage; add TEXTURE_BINDING to sample what Skia drew
|
|
32
|
+
* from WebGPU after each flush(). The surface holds its own reference to
|
|
33
|
+
* the texture and keeps it alive for its lifetime, so the caller may
|
|
34
|
+
* release the GPUTexture once the surface exists. Calling destroy() on the
|
|
35
|
+
* GPUTexture still invalidates the surface.
|
|
35
36
|
*
|
|
36
37
|
* Native only.
|
|
37
38
|
*
|
|
38
|
-
* @param
|
|
39
|
+
* @param texture - The GPUTexture (see {@link GPUTextureHandle})
|
|
39
40
|
* @returns An SkSurface rendering into the texture, or throws if the texture is invalid
|
|
40
41
|
*/
|
|
41
|
-
|
|
42
|
+
MakeFromGPUTexture: (texture: GPUTextureHandle) => SkSurface;
|
|
42
43
|
}
|
|
@@ -29,8 +29,7 @@ export * from "./TextBlob";
|
|
|
29
29
|
export * from "./Size";
|
|
30
30
|
export * from "./Paragraph";
|
|
31
31
|
export * from "./Matrix4";
|
|
32
|
-
export * from "./NativeBuffer";
|
|
33
32
|
export * from "./Recorder";
|
|
34
|
-
export * from "./Video";
|
|
35
33
|
export * from "./Skottie";
|
|
36
34
|
export * from "./Graphite";
|
|
35
|
+
export * from "./GPUTexture";
|
|
@@ -13,5 +13,4 @@ export declare class JsiSkImage extends HostObject<Image, "Image"> implements Sk
|
|
|
13
13
|
encodeToBase64(fmt?: ImageFormat, quality?: number): string;
|
|
14
14
|
readPixels(srcX?: number, srcY?: number, imageInfo?: ImageInfo): Float32Array<ArrayBufferLike> | Uint8Array<ArrayBufferLike> | null;
|
|
15
15
|
makeNonTextureImage(): SkImage;
|
|
16
|
-
getNativeTextureUnstable(): unknown;
|
|
17
16
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { CanvasKit } from "canvaskit-wasm";
|
|
2
|
-
import type { SkData, ImageInfo, SkImage,
|
|
2
|
+
import type { SkData, ImageInfo, SkImage, ImageFactory, GPUTextureHandle } from "../types";
|
|
3
3
|
import { Host } from "./Host";
|
|
4
4
|
import { JsiSkImage } from "./JsiSkImage";
|
|
5
5
|
import type { JsiSkSurface } from "./JsiSkSurface";
|
|
@@ -7,10 +7,9 @@ export declare class JsiSkImageFactory extends Host implements ImageFactory {
|
|
|
7
7
|
constructor(CanvasKit: CanvasKit);
|
|
8
8
|
MakeNull(): JsiSkImage;
|
|
9
9
|
MakeImageFromViewTag(viewTag: number): Promise<SkImage | null>;
|
|
10
|
-
MakeImageFromNativeBuffer(buffer:
|
|
10
|
+
MakeImageFromNativeBuffer(buffer: CanvasImageSource, surface?: JsiSkSurface, image?: JsiSkImage): JsiSkImage;
|
|
11
11
|
MakeImageFromEncoded(encoded: SkData): JsiSkImage | null;
|
|
12
|
-
MakeImageFromNativeTextureUnstable(): SkImage;
|
|
13
12
|
MakeImage(info: ImageInfo, data: SkData, bytesPerRow: number): JsiSkImage | null;
|
|
14
|
-
|
|
15
|
-
|
|
13
|
+
MakeImageFromGPUTexture(_texture: GPUTextureHandle): SkImage;
|
|
14
|
+
MakeGPUTextureFromImage(_image: SkImage): bigint;
|
|
16
15
|
}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import type { CanvasKit } from "canvaskit-wasm";
|
|
2
|
-
import type { SkSurface, SurfaceFactory } from "../types";
|
|
2
|
+
import type { GPUTextureHandle, SkSurface, SurfaceFactory } from "../types";
|
|
3
3
|
import { Host } from "./Host";
|
|
4
4
|
import { JsiSkSurface } from "./JsiSkSurface";
|
|
5
5
|
export declare class JsiSkSurfaceFactory extends Host implements SurfaceFactory {
|
|
6
6
|
constructor(CanvasKit: CanvasKit);
|
|
7
7
|
Make(width: number, height: number): JsiSkSurface;
|
|
8
8
|
MakeOffscreen(width: number, height: number): JsiSkSurface | null;
|
|
9
|
-
|
|
9
|
+
MakeFromGPUTexture(_texture: GPUTextureHandle): SkSurface;
|
|
10
10
|
}
|
package/package.json
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
"setup-skia-web": "scripts/setup-canvaskit.js"
|
|
9
9
|
},
|
|
10
10
|
"title": "React Native Skia",
|
|
11
|
-
"version": "3.0.
|
|
11
|
+
"version": "3.0.5",
|
|
12
12
|
"description": "High-performance React Native Graphics using Skia",
|
|
13
13
|
"main": "lib/module/index.js",
|
|
14
14
|
"react-native": "src/index.ts",
|
package/src/mock/index.ts
CHANGED
|
@@ -0,0 +1,9 @@
|
|
|
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 = { readonly nativePointer: bigint } | bigint;
|
|
@@ -62,17 +62,6 @@ export interface SkImage extends SkJSIInstance<"Image"> {
|
|
|
62
62
|
*/
|
|
63
63
|
getImageInfo(): ImageInfo;
|
|
64
64
|
|
|
65
|
-
/**
|
|
66
|
-
* Returns the backend texture of the image.
|
|
67
|
-
* The returned object can be used to create a Skia Image object.
|
|
68
|
-
* The returned object is backend specific and should be used with caution.
|
|
69
|
-
* It is the caller's responsibility to ensure that the texture is not used after the image is deleted.
|
|
70
|
-
* The returned object may be null if the image does not have a backend texture.
|
|
71
|
-
*
|
|
72
|
-
* @return backend texture of the image or null
|
|
73
|
-
*/
|
|
74
|
-
getNativeTextureUnstable(): unknown;
|
|
75
|
-
|
|
76
65
|
/**
|
|
77
66
|
* Returns this image as a shader with the specified tiling. It will use cubic sampling.
|
|
78
67
|
* @param tx - tile mode in the x direction.
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { SkData } from "../Data";
|
|
2
|
-
import type {
|
|
2
|
+
import type { GPUTextureHandle } from "../GPUTexture";
|
|
3
3
|
|
|
4
4
|
import type { ColorType } from "./ColorType";
|
|
5
5
|
import type { SkImage } from "./Image";
|
|
@@ -35,45 +35,17 @@ export interface ImageFactory {
|
|
|
35
35
|
MakeImageFromEncoded: (encoded: SkData) => SkImage | null;
|
|
36
36
|
|
|
37
37
|
/**
|
|
38
|
-
*
|
|
39
|
-
*
|
|
38
|
+
* Web only. Creates an image from a `CanvasImageSource`: an
|
|
39
|
+
* `HTMLVideoElement`, an `ImageBitmap`, a canvas, an `HTMLImageElement`...
|
|
40
40
|
*
|
|
41
|
-
*
|
|
42
|
-
*
|
|
43
|
-
*
|
|
41
|
+
* On native platforms, camera and video frames are rendered into a texture
|
|
42
|
+
* of the shared device by React Native WebGPU
|
|
43
|
+
* (`queue.copyExternalImageToTexture()`), and the texture is wrapped with
|
|
44
|
+
* {@link MakeImageFromGPUTexture}. Calling this method there throws.
|
|
44
45
|
*
|
|
45
|
-
*
|
|
46
|
-
* - On iOS, this is a `CVPixelBufferRef`
|
|
47
|
-
* @param nativeBuffer A strong `uintptr_t` pointer to the native buffer
|
|
48
|
-
* @throws Throws an error if the Image could not be created, for example when the given
|
|
49
|
-
* native buffer is invalid.
|
|
46
|
+
* @param source The image source
|
|
50
47
|
*/
|
|
51
|
-
MakeImageFromNativeBuffer: (
|
|
52
|
-
|
|
53
|
-
/**
|
|
54
|
-
*
|
|
55
|
-
* Return an Image backed by a given native texture.
|
|
56
|
-
*
|
|
57
|
-
* The native texture must be a valid owning reference.
|
|
58
|
-
*
|
|
59
|
-
* This API might be used to integrate with other libraries using gpu textures,
|
|
60
|
-
* or to transfer images between different threads.
|
|
61
|
-
*
|
|
62
|
-
* @param texture A native texture handle
|
|
63
|
-
* @param width The width of the texture
|
|
64
|
-
* @param height The height of the texture
|
|
65
|
-
* @param mipmapped Whether the texture is mipmapped
|
|
66
|
-
* @throws Throws an error if the Image could not be created, for example when the given native texture is invalid.
|
|
67
|
-
*
|
|
68
|
-
* @returns Returns a valid SkImage, if the texture is invalid, an error is thrown.
|
|
69
|
-
*/
|
|
70
|
-
MakeImageFromNativeTextureUnstable: (
|
|
71
|
-
texture: unknown,
|
|
72
|
-
width: number,
|
|
73
|
-
height: number,
|
|
74
|
-
mipmapped?: boolean,
|
|
75
|
-
outputImage?: SkImage
|
|
76
|
-
) => SkImage;
|
|
48
|
+
MakeImageFromNativeBuffer: (source: CanvasImageSource) => SkImage;
|
|
77
49
|
|
|
78
50
|
/**
|
|
79
51
|
* Returns an image that will be a screenshot of the view represented by
|
|
@@ -96,33 +68,31 @@ export interface ImageFactory {
|
|
|
96
68
|
MakeImage(info: ImageInfo, data: SkData, bytesPerRow: number): SkImage | null;
|
|
97
69
|
|
|
98
70
|
/**
|
|
99
|
-
* Creates an SkImage from a WebGPU texture.
|
|
100
|
-
*
|
|
101
|
-
*
|
|
102
|
-
*
|
|
103
|
-
* the
|
|
104
|
-
*
|
|
105
|
-
*
|
|
106
|
-
* while the image is in use: destroy() releases the underlying GPU
|
|
107
|
-
* resource regardless of reference counts.
|
|
71
|
+
* Creates an SkImage from a WebGPU texture, without copying it.
|
|
72
|
+
* The texture must be created with React Native WebGPU on the shared
|
|
73
|
+
* device (importDevice(Skia.getNativeDevice())) with the TEXTURE_BINDING
|
|
74
|
+
* usage. The image takes its own reference to the texture, so it stays
|
|
75
|
+
* valid even if the JS GPUTexture is garbage collected; do not call
|
|
76
|
+
* texture.destroy() while the image is in use, as destroy() releases the
|
|
77
|
+
* GPU resource regardless of references.
|
|
108
78
|
*
|
|
109
79
|
* Native only.
|
|
110
80
|
*
|
|
111
|
-
* @param
|
|
112
|
-
* @returns An SkImage
|
|
81
|
+
* @param texture - The GPUTexture (see {@link GPUTextureHandle})
|
|
82
|
+
* @returns An SkImage sampling the texture, or throws if the texture is invalid
|
|
113
83
|
*/
|
|
114
|
-
|
|
84
|
+
MakeImageFromGPUTexture(texture: GPUTextureHandle): SkImage;
|
|
115
85
|
|
|
116
86
|
/**
|
|
117
|
-
*
|
|
118
|
-
*
|
|
119
|
-
*
|
|
120
|
-
*
|
|
87
|
+
* Draws an SkImage into a new WebGPU texture on the shared device.
|
|
88
|
+
* The returned pointer carries one reference and must be adopted exactly
|
|
89
|
+
* once with React Native WebGPU's adoptTexture(), which builds the
|
|
90
|
+
* GPUTexture and owns the reference from then on.
|
|
121
91
|
*
|
|
122
92
|
* Native only.
|
|
123
93
|
*
|
|
124
|
-
* @param image -
|
|
94
|
+
* @param image - The SkImage to draw into the texture
|
|
125
95
|
* @returns A WGPUTexture pointer for adoptTexture(), or throws on failure
|
|
126
96
|
*/
|
|
127
|
-
|
|
97
|
+
MakeGPUTextureFromImage(image: SkImage): bigint;
|
|
128
98
|
}
|
package/src/skia/types/Skia.ts
CHANGED
|
@@ -30,8 +30,6 @@ import type { Color, SkColor } from "./Color";
|
|
|
30
30
|
import type { TypefaceFontProviderFactory } from "./Paragraph/TypefaceFontProviderFactory";
|
|
31
31
|
import type { AnimatedImageFactory } from "./AnimatedImage";
|
|
32
32
|
import type { ParagraphBuilderFactory } from "./Paragraph/ParagraphBuilder";
|
|
33
|
-
import type { Video } from "./Video";
|
|
34
|
-
import type { NativeBufferFactory } from "./NativeBuffer";
|
|
35
33
|
import type { JsiRecorder } from "./Recorder";
|
|
36
34
|
import type { SkottieFactory } from "./Skottie";
|
|
37
35
|
|
|
@@ -100,8 +98,6 @@ export interface Skia {
|
|
|
100
98
|
Surface: SurfaceFactory;
|
|
101
99
|
ParagraphBuilder: ParagraphBuilderFactory;
|
|
102
100
|
Skottie: SkottieFactory;
|
|
103
|
-
Video: (url: string) => Promise<Video> | Video;
|
|
104
|
-
NativeBuffer: NativeBufferFactory;
|
|
105
101
|
Recorder(): JsiRecorder;
|
|
106
102
|
/**
|
|
107
103
|
* Raw WGPUDevice pointer of Skia's Graphite device, as a BigInt. Pass it to
|
|
@@ -14,18 +14,6 @@ export interface SkSurface extends SkJSIInstance<"Surface"> {
|
|
|
14
14
|
*/
|
|
15
15
|
getCanvas(): SkCanvas;
|
|
16
16
|
|
|
17
|
-
/**
|
|
18
|
-
* Returns the backend texture of the surface.
|
|
19
|
-
* The returned object can be used to create a Skia Image object.
|
|
20
|
-
* The returned object is backend specific and should be used with caution.
|
|
21
|
-
* It is the caller's responsibility to ensure that the texture is not used after the surface is deleted
|
|
22
|
-
* or draw operations are performed on the surface.
|
|
23
|
-
* The returned object may be null if the surface does not have a backend texture.
|
|
24
|
-
*
|
|
25
|
-
* @return backend texture of the surface or null
|
|
26
|
-
*/
|
|
27
|
-
getNativeTextureUnstable(): unknown;
|
|
28
|
-
|
|
29
17
|
/** Returns Image capturing Surface contents. Subsequent drawing to
|
|
30
18
|
Surface contents are not captured.
|
|
31
19
|
|
|
@@ -40,9 +28,9 @@ export interface SkSurface extends SkJSIInstance<"Surface"> {
|
|
|
40
28
|
/**
|
|
41
29
|
* Make sure any queued draws are sent to the screen or the GPU.
|
|
42
30
|
* @param sync - When true, block until the GPU has finished executing the
|
|
43
|
-
* submitted work. Use this before
|
|
44
|
-
*
|
|
45
|
-
* Defaults to false.
|
|
31
|
+
* submitted work. Use this before a consumer on a different command queue
|
|
32
|
+
* reads the texture this surface draws into (see
|
|
33
|
+
* `Skia.Surface.MakeFromGPUTexture`). Defaults to false.
|
|
46
34
|
*/
|
|
47
35
|
flush(sync?: boolean): void;
|
|
48
36
|
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import type { GPUTextureHandle } from "../GPUTexture";
|
|
2
|
+
|
|
1
3
|
import type { SkSurface } from "./Surface";
|
|
2
4
|
|
|
3
5
|
export const ColorSpace = {
|
|
@@ -35,18 +37,18 @@ export interface SurfaceFactory {
|
|
|
35
37
|
|
|
36
38
|
/**
|
|
37
39
|
* Creates a GPU backed surface that draws directly into a WebGPU texture
|
|
38
|
-
* (zero-copy). The texture must be created
|
|
39
|
-
* (importDevice(Skia.getNativeDevice())) with
|
|
40
|
-
* TEXTURE_BINDING to sample what Skia drew
|
|
41
|
-
* The surface holds its own reference to
|
|
42
|
-
* for its lifetime, so the caller may
|
|
43
|
-
* surface exists. Calling destroy() on the
|
|
44
|
-
* the surface.
|
|
40
|
+
* (zero-copy). The texture must be created with React Native WebGPU on
|
|
41
|
+
* the shared device (importDevice(Skia.getNativeDevice())) with the
|
|
42
|
+
* RENDER_ATTACHMENT usage; add TEXTURE_BINDING to sample what Skia drew
|
|
43
|
+
* from WebGPU after each flush(). The surface holds its own reference to
|
|
44
|
+
* the texture and keeps it alive for its lifetime, so the caller may
|
|
45
|
+
* release the GPUTexture once the surface exists. Calling destroy() on the
|
|
46
|
+
* GPUTexture still invalidates the surface.
|
|
45
47
|
*
|
|
46
48
|
* Native only.
|
|
47
49
|
*
|
|
48
|
-
* @param
|
|
50
|
+
* @param texture - The GPUTexture (see {@link GPUTextureHandle})
|
|
49
51
|
* @returns An SkSurface rendering into the texture, or throws if the texture is invalid
|
|
50
52
|
*/
|
|
51
|
-
|
|
53
|
+
MakeFromGPUTexture: (texture: GPUTextureHandle) => SkSurface;
|
|
52
54
|
}
|
package/src/skia/types/index.ts
CHANGED
|
@@ -29,8 +29,7 @@ export * from "./TextBlob";
|
|
|
29
29
|
export * from "./Size";
|
|
30
30
|
export * from "./Paragraph";
|
|
31
31
|
export * from "./Matrix4";
|
|
32
|
-
export * from "./NativeBuffer";
|
|
33
32
|
export * from "./Recorder";
|
|
34
|
-
export * from "./Video";
|
|
35
33
|
export * from "./Skottie";
|
|
36
34
|
export * from "./Graphite";
|
|
35
|
+
export * from "./GPUTexture";
|
|
@@ -173,9 +173,4 @@ export class JsiSkImage extends HostObject<Image, "Image"> implements SkImage {
|
|
|
173
173
|
}
|
|
174
174
|
return new JsiSkImage(this.CanvasKit, img);
|
|
175
175
|
}
|
|
176
|
-
|
|
177
|
-
getNativeTextureUnstable(): unknown {
|
|
178
|
-
console.warn("getBackendTexture is not implemented on Web");
|
|
179
|
-
return null;
|
|
180
|
-
}
|
|
181
176
|
}
|
|
@@ -1,19 +1,27 @@
|
|
|
1
1
|
import type { CanvasKit, Image } from "canvaskit-wasm";
|
|
2
2
|
|
|
3
|
-
import { CanvasKitWebGLBuffer, isNativeBufferWeb } from "../types";
|
|
4
3
|
import type {
|
|
5
4
|
SkData,
|
|
6
5
|
ImageInfo,
|
|
7
6
|
SkImage,
|
|
8
|
-
NativeBuffer,
|
|
9
7
|
ImageFactory,
|
|
8
|
+
GPUTextureHandle,
|
|
10
9
|
} from "../types";
|
|
11
10
|
|
|
12
11
|
import { Host, getEnum, throwNotImplementedOnRNWeb } from "./Host";
|
|
13
12
|
import { JsiSkImage } from "./JsiSkImage";
|
|
14
13
|
import { JsiSkData } from "./JsiSkData";
|
|
15
14
|
import type { JsiSkSurface } from "./JsiSkSurface";
|
|
16
|
-
|
|
15
|
+
|
|
16
|
+
// The video element of a playing video, an ImageBitmap, a canvas...
|
|
17
|
+
const isCanvasImageSource = (buffer: unknown): buffer is CanvasImageSource =>
|
|
18
|
+
buffer instanceof HTMLVideoElement ||
|
|
19
|
+
buffer instanceof HTMLCanvasElement ||
|
|
20
|
+
buffer instanceof ImageBitmap ||
|
|
21
|
+
buffer instanceof OffscreenCanvas ||
|
|
22
|
+
(typeof VideoFrame !== "undefined" && buffer instanceof VideoFrame) ||
|
|
23
|
+
buffer instanceof HTMLImageElement ||
|
|
24
|
+
buffer instanceof SVGImageElement;
|
|
17
25
|
|
|
18
26
|
export class JsiSkImageFactory extends Host implements ImageFactory {
|
|
19
27
|
constructor(CanvasKit: CanvasKit) {
|
|
@@ -32,12 +40,12 @@ export class JsiSkImageFactory extends Host implements ImageFactory {
|
|
|
32
40
|
}
|
|
33
41
|
|
|
34
42
|
MakeImageFromNativeBuffer(
|
|
35
|
-
buffer:
|
|
43
|
+
buffer: CanvasImageSource,
|
|
36
44
|
surface?: JsiSkSurface,
|
|
37
45
|
image?: JsiSkImage
|
|
38
46
|
) {
|
|
39
|
-
if (!
|
|
40
|
-
throw new Error("
|
|
47
|
+
if (!isCanvasImageSource(buffer)) {
|
|
48
|
+
throw new Error("MakeImageFromNativeBuffer expects a CanvasImageSource");
|
|
41
49
|
}
|
|
42
50
|
if (!surface) {
|
|
43
51
|
let img: Image;
|
|
@@ -47,10 +55,6 @@ export class JsiSkImageFactory extends Host implements ImageFactory {
|
|
|
47
55
|
buffer instanceof ImageBitmap
|
|
48
56
|
) {
|
|
49
57
|
img = this.CanvasKit.MakeLazyImageFromTextureSource(buffer);
|
|
50
|
-
} else if (buffer instanceof CanvasKitWebGLBuffer) {
|
|
51
|
-
img = (
|
|
52
|
-
buffer as CanvasKitWebGLBuffer as CanvasKitWebGLBufferImpl
|
|
53
|
-
).toImage();
|
|
54
58
|
} else {
|
|
55
59
|
img = this.CanvasKit.MakeImageFromCanvasImageSource(buffer);
|
|
56
60
|
}
|
|
@@ -79,10 +83,6 @@ export class JsiSkImageFactory extends Host implements ImageFactory {
|
|
|
79
83
|
return new JsiSkImage(this.CanvasKit, image);
|
|
80
84
|
}
|
|
81
85
|
|
|
82
|
-
MakeImageFromNativeTextureUnstable() {
|
|
83
|
-
return throwNotImplementedOnRNWeb<SkImage>();
|
|
84
|
-
}
|
|
85
|
-
|
|
86
86
|
MakeImage(info: ImageInfo, data: SkData, bytesPerRow: number) {
|
|
87
87
|
// see toSkImageInfo() from canvaskit
|
|
88
88
|
const image = this.CanvasKit.MakeImage(
|
|
@@ -102,11 +102,11 @@ export class JsiSkImageFactory extends Host implements ImageFactory {
|
|
|
102
102
|
return new JsiSkImage(this.CanvasKit, image);
|
|
103
103
|
}
|
|
104
104
|
|
|
105
|
-
|
|
105
|
+
MakeImageFromGPUTexture(_texture: GPUTextureHandle): SkImage {
|
|
106
106
|
return throwNotImplementedOnRNWeb<SkImage>();
|
|
107
107
|
}
|
|
108
108
|
|
|
109
|
-
|
|
109
|
+
MakeGPUTextureFromImage(_image: SkImage): bigint {
|
|
110
110
|
return throwNotImplementedOnRNWeb<bigint>();
|
|
111
111
|
}
|
|
112
112
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { CanvasKit, Surface } from "canvaskit-wasm";
|
|
2
2
|
|
|
3
|
-
import type { SkSurface, SurfaceFactory } from "../types";
|
|
3
|
+
import type { GPUTextureHandle, SkSurface, SurfaceFactory } from "../types";
|
|
4
4
|
|
|
5
5
|
import { Host, throwNotImplementedOnRNWeb } from "./Host";
|
|
6
6
|
import { JsiSkSurface } from "./JsiSkSurface";
|
|
@@ -39,7 +39,7 @@ export class JsiSkSurfaceFactory extends Host implements SurfaceFactory {
|
|
|
39
39
|
return new JsiSkSurface(this.CanvasKit, surface);
|
|
40
40
|
}
|
|
41
41
|
|
|
42
|
-
|
|
42
|
+
MakeFromGPUTexture(_texture: GPUTextureHandle): SkSurface {
|
|
43
43
|
return throwNotImplementedOnRNWeb<SkSurface>();
|
|
44
44
|
}
|
|
45
45
|
}
|
package/src/skia/web/JsiSkia.ts
CHANGED
|
@@ -43,8 +43,6 @@ import { JsiSkTypefaceFontProviderFactory } from "./JsiSkTypefaceFontProviderFac
|
|
|
43
43
|
import { JsiSkFontMgrFactory } from "./JsiSkFontMgrFactory";
|
|
44
44
|
import { JsiSkAnimatedImageFactory } from "./JsiSkAnimatedImageFactory";
|
|
45
45
|
import { JsiSkParagraphBuilderFactory } from "./JsiSkParagraphBuilderFactory";
|
|
46
|
-
import { JsiSkNativeBufferFactory } from "./JsiSkNativeBufferFactory";
|
|
47
|
-
import { createVideo } from "./JsiVideo";
|
|
48
46
|
import { throwNotImplementedOnRNWeb } from "./Host";
|
|
49
47
|
import { JsiSkottieFactory } from "./JsiSkottieFactory";
|
|
50
48
|
|
|
@@ -133,9 +131,7 @@ export const JsiSkApi = (CanvasKit: CanvasKit): Skia => ({
|
|
|
133
131
|
TypefaceFontProvider: new JsiSkTypefaceFontProviderFactory(CanvasKit),
|
|
134
132
|
FontMgr: new JsiSkFontMgrFactory(CanvasKit),
|
|
135
133
|
ParagraphBuilder: new JsiSkParagraphBuilderFactory(CanvasKit),
|
|
136
|
-
NativeBuffer: new JsiSkNativeBufferFactory(CanvasKit),
|
|
137
134
|
Skottie: new JsiSkottieFactory(CanvasKit),
|
|
138
|
-
Video: createVideo.bind(null, CanvasKit),
|
|
139
135
|
Recorder: () => {
|
|
140
136
|
return throwNotImplementedOnRNWeb<JsiRecorder>();
|
|
141
137
|
},
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
#if __ANDROID_API__ >= 26
|
|
2
|
-
|
|
3
|
-
#include "AHardwareBufferUtils.h"
|
|
4
|
-
#include <android/hardware_buffer.h>
|
|
5
|
-
|
|
6
|
-
namespace RNSkia {
|
|
7
|
-
|
|
8
|
-
uint32_t GetBufferFormatFromSkColorType(SkColorType bufferFormat) {
|
|
9
|
-
switch (bufferFormat) {
|
|
10
|
-
case kRGBA_8888_SkColorType:
|
|
11
|
-
return AHARDWAREBUFFER_FORMAT_R8G8B8A8_UNORM;
|
|
12
|
-
case kRGB_888x_SkColorType:
|
|
13
|
-
return AHARDWAREBUFFER_FORMAT_R8G8B8X8_UNORM;
|
|
14
|
-
case kRGBA_F16_SkColorType:
|
|
15
|
-
return AHARDWAREBUFFER_FORMAT_R16G16B16A16_FLOAT;
|
|
16
|
-
case kRGB_565_SkColorType:
|
|
17
|
-
return AHARDWAREBUFFER_FORMAT_R5G6B5_UNORM;
|
|
18
|
-
case kRGBA_1010102_SkColorType:
|
|
19
|
-
return AHARDWAREBUFFER_FORMAT_R10G10B10A2_UNORM;
|
|
20
|
-
#if __ANDROID_API__ >= 33
|
|
21
|
-
case kAlpha_8_SkColorType:
|
|
22
|
-
return AHARDWAREBUFFER_FORMAT_R8_UNORM;
|
|
23
|
-
#endif
|
|
24
|
-
default:
|
|
25
|
-
return AHARDWAREBUFFER_FORMAT_R8G8B8A8_UNORM;
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
} // namespace RNSkia
|
|
30
|
-
|
|
31
|
-
#endif
|