Skip to content

Commit bc2e18a

Browse files
committed
Update tests
1 parent 4c76dce commit bc2e18a

File tree

4 files changed

+30
-44
lines changed

4 files changed

+30
-44
lines changed

fabricexample/src/Tests/Tests.tsx

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import {
66
Canvas,
77
Skia,
88
makeImageFromView,
9-
Paragraph,
109
} from "@shopify/react-native-skia";
1110
import React, { useEffect, useRef, useState } from "react";
1211
import { PixelRatio, Platform, Text, View } from "react-native";
@@ -48,21 +47,6 @@ export const Tests = ({ assets }: TestsProps) => {
4847
})
4948
)
5049
);
51-
} else if (tree.paragraph) {
52-
const paragraph = eval(
53-
`(function Main(){return (${tree.paragraph})(this.Skia, this.ctx); })`
54-
).call({
55-
Skia,
56-
ctx: parseProps(tree.ctx, assets),
57-
});
58-
setDrawing(
59-
<Paragraph
60-
paragraph={paragraph}
61-
width={tree.paragraphWidth}
62-
x={0}
63-
y={0}
64-
/>
65-
);
6650
} else if (typeof tree.screen === "string") {
6751
const Screen = Screens[tree.screen];
6852
if (!Screen) {
3.09 KB
Loading
Lines changed: 23 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,45 @@
1-
import { importSkia, surface } from "../setup";
1+
import { surface } from "../setup";
22
import { checkImage } from "../../../__tests__/setup";
33
import { BlendMode } from "../../../skia/types";
44

55
describe("Pictures", () => {
66
it("Should draw a simple picture", async () => {
7-
const { Skia } = importSkia();
8-
const str = await surface.eval((Sk) => {
9-
const size = 256;
10-
const surf = Sk.Surface.MakeOffscreen(size, size)!;
11-
const canvas = surf.getCanvas();
12-
const recorder = Sk.PictureRecorder();
13-
const canvas2 = recorder.beginRecording(Sk.XYWHRect(0, 0, size, size));
14-
canvas2.drawColor(Sk.Color("cyan"));
15-
const picture = recorder.finishRecordingAsPicture();
16-
canvas.drawPicture(picture);
17-
return surf.makeImageSnapshot().encodeToBase64();
18-
});
19-
const image = Skia.Image.MakeImageFromEncoded(Skia.Data.fromBase64(str))!;
7+
const image = await surface.drawOffscreen(
8+
(Skia, canvas, { size }) => {
9+
const recorder = Skia.PictureRecorder();
10+
const canvas2 = recorder.beginRecording(
11+
Skia.XYWHRect(0, 0, size, size)
12+
);
13+
canvas2.drawColor(Skia.Color("cyan"));
14+
const picture = recorder.finishRecordingAsPicture();
15+
canvas.drawPicture(picture);
16+
},
17+
{ size: surface.width }
18+
);
2019
checkImage(image, "snapshots/pictures/simple-picture.png");
2120
});
2221
it("Should draw the hello world example as picture", async () => {
23-
const { Skia } = importSkia();
24-
const str = await surface.eval(
25-
(Sk, ctx) => {
22+
const image = await surface.drawOffscreen(
23+
(Skia, canvas, ctx) => {
2624
const { size } = ctx;
2725
const r = size * 0.33;
28-
const surf = Sk.Surface.MakeOffscreen(size, size)!;
29-
const canvas = surf.getCanvas();
30-
const recorder = Sk.PictureRecorder();
31-
const canvas2 = recorder.beginRecording(Sk.XYWHRect(0, 0, size, size));
32-
const paint = Sk.Paint();
26+
const recorder = Skia.PictureRecorder();
27+
const canvas2 = recorder.beginRecording(
28+
Skia.XYWHRect(0, 0, size, size)
29+
);
30+
const paint = Skia.Paint();
3331
paint.setBlendMode(ctx.BlendMode);
34-
paint.setColor(Sk.Color("cyan"));
32+
paint.setColor(Skia.Color("cyan"));
3533
canvas2.drawCircle(r, r, r, paint);
36-
paint.setColor(Sk.Color("magenta"));
34+
paint.setColor(Skia.Color("magenta"));
3735
canvas2.drawCircle(size - r, r, r, paint);
38-
paint.setColor(Sk.Color("yellow"));
36+
paint.setColor(Skia.Color("yellow"));
3937
canvas2.drawCircle(size / 2, size - r, r, paint);
4038
const picture = recorder.finishRecordingAsPicture();
4139
canvas.drawPicture(picture);
42-
surf.flush();
43-
return surf.makeImageSnapshot().encodeToBase64();
4440
},
4541
{ BlendMode: BlendMode.Multiply, size: surface.width }
4642
);
47-
const image = Skia.Image.MakeImageFromEncoded(Skia.Data.fromBase64(str))!;
4843
checkImage(image, "snapshots/pictures/hello-world.png");
4944
});
5045
});

package/src/skia/types/Canvas.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import type { SkMatrix } from "./Matrix";
1212
import type { SkImageFilter } from "./ImageFilter";
1313
import type { SkVertices } from "./Vertices";
1414
import type { SkTextBlob } from "./TextBlob";
15+
import type { SkPicture } from "./Picture";
1516

1617
export enum ClipOp {
1718
Difference,
@@ -486,6 +487,12 @@ export interface SkCanvas {
486487
*/
487488
concat(m: SkMatrix | number[]): void;
488489

490+
/**
491+
* Draws the given picture using the current clip, current matrix, and the provided paint.
492+
* @param skp
493+
*/
494+
drawPicture(skp: SkPicture): void;
495+
489496
/** Read Image pixels
490497
*
491498
* @param srcX - x-axis upper left corner of the rectangle to read from

0 commit comments

Comments
 (0)