@shopify/react-native-skia 1.1.0 → 1.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/android/CMakeLists.txt +1 -0
- package/android/build.gradle +1 -0
- package/android/cpp/rnskia-android/AHardwareBufferUtils.cpp +31 -0
- package/android/cpp/rnskia-android/AHardwareBufferUtils.h +13 -0
- package/android/cpp/rnskia-android/RNSkAndroidPlatformContext.h +75 -0
- package/android/cpp/rnskia-android/SkiaOpenGLSurfaceFactory.cpp +29 -11
- package/android/cpp/rnskia-android/SkiaOpenGLSurfaceFactory.h +1 -2
- package/android/src/main/java/com/shopify/reactnative/skia/ViewScreenshotService.java +3 -2
- package/cpp/api/JsiNativeBuffer.h +43 -0
- package/cpp/api/JsiSkApi.h +4 -0
- package/cpp/api/JsiSkImage.h +1 -1
- package/cpp/api/JsiSkImageFactory.h +15 -1
- package/cpp/api/JsiSkSurface.h +9 -1
- package/cpp/rnskia/RNSkPlatformContext.h +13 -0
- package/ios/RNSkia-iOS/RNSkiOSPlatformContext.h +6 -0
- package/ios/RNSkia-iOS/RNSkiOSPlatformContext.mm +98 -2
- package/ios/RNSkia-iOS/SkiaCVPixelBufferUtils.h +84 -0
- package/ios/RNSkia-iOS/SkiaCVPixelBufferUtils.mm +159 -0
- package/ios/RNSkia-iOS/SkiaMetalSurfaceFactory.h +5 -0
- package/ios/RNSkia-iOS/SkiaMetalSurfaceFactory.mm +37 -1
- package/lib/commonjs/external/reanimated/textures.js +11 -2
- package/lib/commonjs/external/reanimated/textures.js.map +1 -1
- package/lib/commonjs/external/reanimated/useAnimatedImageValue.d.ts +2 -1
- package/lib/commonjs/external/reanimated/useAnimatedImageValue.js +8 -4
- package/lib/commonjs/external/reanimated/useAnimatedImageValue.js.map +1 -1
- package/lib/commonjs/renderer/Offscreen.d.ts +2 -2
- package/lib/commonjs/renderer/Offscreen.js +2 -2
- package/lib/commonjs/renderer/Offscreen.js.map +1 -1
- package/lib/commonjs/skia/types/Image/ImageFactory.d.ts +17 -10
- package/lib/commonjs/skia/types/Image/ImageFactory.js +1 -10
- package/lib/commonjs/skia/types/Image/ImageFactory.js.map +1 -1
- package/lib/commonjs/skia/types/NativeBuffer/NativeBufferFactory.d.ts +18 -0
- package/lib/commonjs/skia/types/NativeBuffer/NativeBufferFactory.js +13 -0
- package/lib/commonjs/skia/types/NativeBuffer/NativeBufferFactory.js.map +1 -0
- package/lib/commonjs/skia/types/NativeBuffer/index.d.ts +1 -0
- package/lib/commonjs/skia/types/NativeBuffer/index.js +17 -0
- package/lib/commonjs/skia/types/NativeBuffer/index.js.map +1 -0
- package/lib/commonjs/skia/types/Skia.d.ts +2 -0
- package/lib/commonjs/skia/types/Skia.js.map +1 -1
- package/lib/commonjs/skia/types/Surface/Surface.d.ts +8 -0
- package/lib/commonjs/skia/types/Surface/Surface.js.map +1 -1
- package/lib/commonjs/skia/types/index.d.ts +1 -0
- package/lib/commonjs/skia/types/index.js +11 -0
- package/lib/commonjs/skia/types/index.js.map +1 -1
- package/lib/commonjs/skia/web/JsiSkImage.d.ts +1 -2
- package/lib/commonjs/skia/web/JsiSkImage.js +5 -12
- package/lib/commonjs/skia/web/JsiSkImage.js.map +1 -1
- package/lib/commonjs/skia/web/JsiSkImageFactory.d.ts +3 -2
- package/lib/commonjs/skia/web/JsiSkImageFactory.js +19 -0
- package/lib/commonjs/skia/web/JsiSkImageFactory.js.map +1 -1
- package/lib/commonjs/skia/web/JsiSkNativeBufferFactory.d.ts +8 -0
- package/lib/commonjs/skia/web/JsiSkNativeBufferFactory.js +29 -0
- package/lib/commonjs/skia/web/JsiSkNativeBufferFactory.js.map +1 -0
- package/lib/commonjs/skia/web/JsiSkSurface.d.ts +3 -2
- package/lib/commonjs/skia/web/JsiSkSurface.js +8 -6
- package/lib/commonjs/skia/web/JsiSkSurface.js.map +1 -1
- package/lib/commonjs/skia/web/JsiSkSurfaceFactory.d.ts +1 -1
- package/lib/commonjs/skia/web/JsiSkSurfaceFactory.js +1 -16
- package/lib/commonjs/skia/web/JsiSkSurfaceFactory.js.map +1 -1
- package/lib/commonjs/skia/web/JsiSkia.js +3 -1
- package/lib/commonjs/skia/web/JsiSkia.js.map +1 -1
- package/lib/module/external/reanimated/textures.js +11 -2
- package/lib/module/external/reanimated/textures.js.map +1 -1
- package/lib/module/external/reanimated/useAnimatedImageValue.d.ts +2 -1
- package/lib/module/external/reanimated/useAnimatedImageValue.js +8 -4
- package/lib/module/external/reanimated/useAnimatedImageValue.js.map +1 -1
- package/lib/module/renderer/Offscreen.d.ts +2 -2
- package/lib/module/renderer/Offscreen.js +2 -2
- package/lib/module/renderer/Offscreen.js.map +1 -1
- package/lib/module/skia/types/Image/ImageFactory.d.ts +17 -10
- package/lib/module/skia/types/Image/ImageFactory.js +1 -10
- package/lib/module/skia/types/Image/ImageFactory.js.map +1 -1
- package/lib/module/skia/types/NativeBuffer/NativeBufferFactory.d.ts +18 -0
- package/lib/module/skia/types/NativeBuffer/NativeBufferFactory.js +4 -0
- package/lib/module/skia/types/NativeBuffer/NativeBufferFactory.js.map +1 -0
- package/lib/module/skia/types/NativeBuffer/index.d.ts +1 -0
- package/lib/module/skia/types/NativeBuffer/index.js +2 -0
- package/lib/module/skia/types/NativeBuffer/index.js.map +1 -0
- package/lib/module/skia/types/Skia.d.ts +2 -0
- package/lib/module/skia/types/Skia.js.map +1 -1
- package/lib/module/skia/types/Surface/Surface.d.ts +8 -0
- package/lib/module/skia/types/Surface/Surface.js.map +1 -1
- package/lib/module/skia/types/index.d.ts +1 -0
- package/lib/module/skia/types/index.js +1 -0
- package/lib/module/skia/types/index.js.map +1 -1
- package/lib/module/skia/web/JsiSkImage.d.ts +1 -2
- package/lib/module/skia/web/JsiSkImage.js +5 -12
- package/lib/module/skia/web/JsiSkImage.js.map +1 -1
- package/lib/module/skia/web/JsiSkImageFactory.d.ts +3 -2
- package/lib/module/skia/web/JsiSkImageFactory.js +19 -0
- package/lib/module/skia/web/JsiSkImageFactory.js.map +1 -1
- package/lib/module/skia/web/JsiSkNativeBufferFactory.d.ts +8 -0
- package/lib/module/skia/web/JsiSkNativeBufferFactory.js +22 -0
- package/lib/module/skia/web/JsiSkNativeBufferFactory.js.map +1 -0
- package/lib/module/skia/web/JsiSkSurface.d.ts +3 -2
- package/lib/module/skia/web/JsiSkSurface.js +8 -6
- package/lib/module/skia/web/JsiSkSurface.js.map +1 -1
- package/lib/module/skia/web/JsiSkSurfaceFactory.d.ts +1 -1
- package/lib/module/skia/web/JsiSkSurfaceFactory.js +1 -16
- package/lib/module/skia/web/JsiSkSurfaceFactory.js.map +1 -1
- package/lib/module/skia/web/JsiSkia.js +3 -1
- package/lib/module/skia/web/JsiSkia.js.map +1 -1
- package/lib/typescript/src/external/reanimated/useAnimatedImageValue.d.ts +2 -1
- package/lib/typescript/src/renderer/Offscreen.d.ts +2 -2
- package/lib/typescript/src/skia/types/Image/ImageFactory.d.ts +17 -10
- package/lib/typescript/src/skia/types/NativeBuffer/NativeBufferFactory.d.ts +18 -0
- package/lib/typescript/src/skia/types/NativeBuffer/index.d.ts +1 -0
- package/lib/typescript/src/skia/types/Skia.d.ts +2 -0
- package/lib/typescript/src/skia/types/Surface/Surface.d.ts +8 -0
- package/lib/typescript/src/skia/types/index.d.ts +1 -0
- package/lib/typescript/src/skia/web/JsiSkImage.d.ts +1 -2
- package/lib/typescript/src/skia/web/JsiSkImageFactory.d.ts +3 -2
- package/lib/typescript/src/skia/web/JsiSkNativeBufferFactory.d.ts +8 -0
- package/lib/typescript/src/skia/web/JsiSkSurface.d.ts +3 -2
- package/lib/typescript/src/skia/web/JsiSkSurfaceFactory.d.ts +1 -1
- package/package.json +1 -1
- package/src/external/reanimated/textures.tsx +8 -2
- package/src/external/reanimated/useAnimatedImageValue.ts +12 -6
- package/src/renderer/Offscreen.tsx +3 -3
- package/src/skia/types/Image/ImageFactory.ts +17 -18
- package/src/skia/types/NativeBuffer/NativeBufferFactory.ts +38 -0
- package/src/skia/types/NativeBuffer/index.ts +1 -0
- package/src/skia/types/Skia.ts +2 -1
- package/src/skia/types/Surface/Surface.ts +10 -0
- package/src/skia/types/index.ts +1 -0
- package/src/skia/web/JsiSkImage.ts +5 -22
- package/src/skia/web/JsiSkImageFactory.ts +36 -3
- package/src/skia/web/JsiSkNativeBufferFactory.ts +35 -0
- package/src/skia/web/JsiSkSurface.ts +10 -9
- package/src/skia/web/JsiSkSurfaceFactory.ts +3 -19
- package/src/skia/web/JsiSkia.ts +2 -0
- package/cpp/skia/include/third_party/vulkan/LICENSE +0 -29
- package/cpp/skia/modules/skcms/README.chromium +0 -6
- package/cpp/skia/readme.txt +0 -1
|
@@ -1,11 +1,18 @@
|
|
|
1
|
-
import type { CanvasKit } from "canvaskit-wasm";
|
|
1
|
+
import type { CanvasKit, Image } from "canvaskit-wasm";
|
|
2
2
|
|
|
3
|
-
import
|
|
4
|
-
import type {
|
|
3
|
+
import { isNativeBufferWeb } from "../types";
|
|
4
|
+
import type {
|
|
5
|
+
SkData,
|
|
6
|
+
ImageInfo,
|
|
7
|
+
SkImage,
|
|
8
|
+
NativeBuffer,
|
|
9
|
+
ImageFactory,
|
|
10
|
+
} from "../types";
|
|
5
11
|
|
|
6
12
|
import { Host, getEnum } from "./Host";
|
|
7
13
|
import { JsiSkImage } from "./JsiSkImage";
|
|
8
14
|
import { JsiSkData } from "./JsiSkData";
|
|
15
|
+
import type { JsiSkSurface } from "./JsiSkSurface";
|
|
9
16
|
|
|
10
17
|
export class JsiSkImageFactory extends Host implements ImageFactory {
|
|
11
18
|
constructor(CanvasKit: CanvasKit) {
|
|
@@ -19,6 +26,32 @@ export class JsiSkImageFactory extends Host implements ImageFactory {
|
|
|
19
26
|
return Promise.resolve(null);
|
|
20
27
|
}
|
|
21
28
|
|
|
29
|
+
MakeImageFromNativeBuffer(
|
|
30
|
+
buffer: NativeBuffer,
|
|
31
|
+
surface?: JsiSkSurface,
|
|
32
|
+
image?: JsiSkImage
|
|
33
|
+
) {
|
|
34
|
+
if (!isNativeBufferWeb(buffer)) {
|
|
35
|
+
throw new Error("Invalid NativeBuffer");
|
|
36
|
+
}
|
|
37
|
+
if (!surface) {
|
|
38
|
+
// TODO: this is way to slow
|
|
39
|
+
const img = this.CanvasKit.MakeImageFromCanvasImageSource(buffer);
|
|
40
|
+
return new JsiSkImage(this.CanvasKit, img);
|
|
41
|
+
} else if (!image) {
|
|
42
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
43
|
+
const img = (surface as any).makeImageFromTextureSource(buffer) as Image;
|
|
44
|
+
return new JsiSkImage(this.CanvasKit, img);
|
|
45
|
+
} else {
|
|
46
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
47
|
+
const img = (surface as any).updateTextureFromSource(
|
|
48
|
+
image,
|
|
49
|
+
buffer
|
|
50
|
+
) as Image;
|
|
51
|
+
return new JsiSkImage(this.CanvasKit, img);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
22
55
|
MakeImageFromEncoded(encoded: SkData) {
|
|
23
56
|
const image = this.CanvasKit.MakeImageFromEncoded(
|
|
24
57
|
JsiSkData.fromValue(encoded)
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { CanvasKit } from "canvaskit-wasm";
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
type NativeBuffer,
|
|
5
|
+
type NativeBufferFactory,
|
|
6
|
+
type SkImage,
|
|
7
|
+
} from "../types";
|
|
8
|
+
|
|
9
|
+
import { Host } from "./Host";
|
|
10
|
+
|
|
11
|
+
export class JsiSkNativeBufferFactory
|
|
12
|
+
extends Host
|
|
13
|
+
implements NativeBufferFactory
|
|
14
|
+
{
|
|
15
|
+
constructor(CanvasKit: CanvasKit) {
|
|
16
|
+
super(CanvasKit);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
MakeFromImage(image: SkImage): NativeBuffer {
|
|
20
|
+
const info = image.getImageInfo();
|
|
21
|
+
const uint8ClampedArray = new Uint8ClampedArray(image.readPixels()!);
|
|
22
|
+
const imageData = new ImageData(uint8ClampedArray, info.width, info.height);
|
|
23
|
+
const canvas = new OffscreenCanvas(info.width, info.height);
|
|
24
|
+
const ctx = canvas.getContext("2d");
|
|
25
|
+
if (!ctx) {
|
|
26
|
+
throw new Error("Failed to get 2d context from canvas");
|
|
27
|
+
}
|
|
28
|
+
ctx.putImageData(imageData, 0, 0);
|
|
29
|
+
return canvas;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
Release(_platformBuffer: NativeBuffer) {
|
|
33
|
+
// it's a noop on Web
|
|
34
|
+
}
|
|
35
|
+
}
|
|
@@ -11,25 +11,26 @@ export class JsiSkSurface
|
|
|
11
11
|
extends HostObject<Surface, "Surface">
|
|
12
12
|
implements SkSurface
|
|
13
13
|
{
|
|
14
|
-
constructor(
|
|
15
|
-
CanvasKit: CanvasKit,
|
|
16
|
-
ref: Surface,
|
|
17
|
-
private releaseCtx?: () => void
|
|
18
|
-
) {
|
|
14
|
+
constructor(CanvasKit: CanvasKit, ref: Surface) {
|
|
19
15
|
super(CanvasKit, ref, "Surface");
|
|
20
16
|
}
|
|
21
17
|
|
|
22
18
|
dispose = () => {
|
|
23
|
-
this.ref.
|
|
24
|
-
if (this.releaseCtx) {
|
|
25
|
-
this.releaseCtx();
|
|
26
|
-
}
|
|
19
|
+
this.ref.dispose();
|
|
27
20
|
};
|
|
28
21
|
|
|
29
22
|
flush() {
|
|
30
23
|
this.ref.flush();
|
|
31
24
|
}
|
|
32
25
|
|
|
26
|
+
width() {
|
|
27
|
+
return this.ref.width();
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
height() {
|
|
31
|
+
return this.ref.height();
|
|
32
|
+
}
|
|
33
|
+
|
|
33
34
|
getCanvas(): SkCanvas {
|
|
34
35
|
return new JsiSkCanvas(this.CanvasKit, this.ref.getCanvas());
|
|
35
36
|
}
|
|
@@ -11,26 +11,10 @@ export class JsiSkSurfaceFactory extends Host implements SurfaceFactory {
|
|
|
11
11
|
}
|
|
12
12
|
|
|
13
13
|
Make(width: number, height: number) {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
{
|
|
18
|
-
width: width,
|
|
19
|
-
height: height,
|
|
20
|
-
colorType: this.CanvasKit.ColorType.RGBA_8888,
|
|
21
|
-
alphaType: this.CanvasKit.AlphaType.Unpremul,
|
|
22
|
-
colorSpace: this.CanvasKit.ColorSpace.SRGB,
|
|
23
|
-
},
|
|
24
|
-
pixelPtr,
|
|
25
|
-
width * 4
|
|
14
|
+
return new JsiSkSurface(
|
|
15
|
+
this.CanvasKit,
|
|
16
|
+
this.CanvasKit.MakeSurface(width, height)!
|
|
26
17
|
);
|
|
27
|
-
if (!surface) {
|
|
28
|
-
return null;
|
|
29
|
-
}
|
|
30
|
-
surface.getCanvas().clear(this.CanvasKit.TRANSPARENT);
|
|
31
|
-
return new JsiSkSurface(this.CanvasKit, surface, () => {
|
|
32
|
-
this.CanvasKit.Free(pixelPtr);
|
|
33
|
-
});
|
|
34
18
|
}
|
|
35
19
|
|
|
36
20
|
MakeOffscreen(width: number, height: number) {
|
package/src/skia/web/JsiSkia.ts
CHANGED
|
@@ -41,6 +41,7 @@ import { JsiSkTypefaceFontProviderFactory } from "./JsiSkTypefaceFontProviderFac
|
|
|
41
41
|
import { JsiSkFontMgrFactory } from "./JsiSkFontMgrFactory";
|
|
42
42
|
import { JsiSkAnimatedImageFactory } from "./JsiSkAnimatedImageFactory";
|
|
43
43
|
import { JsiSkParagraphBuilderFactory } from "./JsiSkParagraphBuilderFactory";
|
|
44
|
+
import { JsiSkNativeBufferFactory } from "./JsiSkNativeBufferFactory";
|
|
44
45
|
|
|
45
46
|
export const JsiSkApi = (CanvasKit: CanvasKit): Skia => ({
|
|
46
47
|
Point: (x: number, y: number) =>
|
|
@@ -125,4 +126,5 @@ export const JsiSkApi = (CanvasKit: CanvasKit): Skia => ({
|
|
|
125
126
|
TypefaceFontProvider: new JsiSkTypefaceFontProviderFactory(CanvasKit),
|
|
126
127
|
FontMgr: new JsiSkFontMgrFactory(CanvasKit),
|
|
127
128
|
ParagraphBuilder: new JsiSkParagraphBuilderFactory(CanvasKit),
|
|
129
|
+
NativeBuffer: new JsiSkNativeBufferFactory(CanvasKit),
|
|
128
130
|
});
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
// Copyright (c) 2018 Google Inc. All rights reserved.
|
|
2
|
-
//
|
|
3
|
-
// Redistribution and use in source and binary forms, with or without
|
|
4
|
-
// modification, are permitted provided that the following conditions are
|
|
5
|
-
// met:
|
|
6
|
-
//
|
|
7
|
-
// * Redistributions of source code must retain the above copyright
|
|
8
|
-
// notice, this list of conditions and the following disclaimer.
|
|
9
|
-
// * Redistributions in binary form must reproduce the above
|
|
10
|
-
// copyright notice, this list of conditions and the following disclaimer
|
|
11
|
-
// in the documentation and/or other materials provided with the
|
|
12
|
-
// distribution.
|
|
13
|
-
// * Neither the name of Google Inc. nor the names of its
|
|
14
|
-
// contributors may be used to endorse or promote products derived from
|
|
15
|
-
// this software without specific prior written permission.
|
|
16
|
-
//
|
|
17
|
-
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
18
|
-
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
19
|
-
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
20
|
-
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
21
|
-
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
22
|
-
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
23
|
-
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
24
|
-
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
25
|
-
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
26
|
-
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
27
|
-
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
28
|
-
|
|
29
|
-
--------------------------------------------------------------------------------
|
package/cpp/skia/readme.txt
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
Placeholder for the Skia include files.
|