Skip to content

Commit

Permalink
🔧
Browse files Browse the repository at this point in the history
  • Loading branch information
wcandillon committed Jan 7, 2025
1 parent 9d85afb commit c46b7c6
Showing 1 changed file with 21 additions and 18 deletions.
39 changes: 21 additions & 18 deletions packages/skia/src/sksg/Container.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { SharedValue } from "react-native-reanimated";
import { type SharedValue } from "react-native-reanimated";

import Rea from "../external/reanimated/ReanimatedProxy";
import type { Skia, SkCanvas } from "../skia/types";
Expand All @@ -20,6 +20,7 @@ const drawOnscreen = (Skia: Skia, nativeId: number, recording: Recording) => {

// TODO: because the pool is not a shared value here, it is copied on every frame
const ctx = createDrawingContext(Skia, recording.paintPool, canvas);
//console.log(recording.commands);
replay(ctx, recording.commands);
const picture = rec.finishRecordingAsPicture();
//const end = performance.now();
Expand All @@ -43,20 +44,24 @@ export class Container {

set root(root: Node[]) {
const isOnscreen = this.nativeId !== -1;
if (isOnscreen) {
if (HAS_REANIMATED_3) {
if (this.mapperId !== null) {
Rea.stopMapper(this.mapperId);
}
const { nativeId, Skia, _recording } = this;
this.mapperId = Rea.startMapper(() => {
"worklet";
drawOnscreen(Skia, nativeId, _recording!);
}, Array.from(this.values));
} else {
this.redraw();
}
}
this._root = root;
const recorder = new Recorder();
visit(recorder, root);
this._recording = createRecording(recorder.commands);
if (isOnscreen && HAS_REANIMATED_3) {
if (this.mapperId !== null) {
Rea.stopMapper(this.mapperId);
}
const { nativeId, Skia, _recording } = this;
this.mapperId = Rea.startMapper(() => {
"worklet";
drawOnscreen(Skia, nativeId, _recording!);
}, Array.from(this.values));
}
}

clear() {
Expand All @@ -65,15 +70,13 @@ export class Container {

redraw() {
const isOnscreen = this.nativeId !== -1;
if (isOnscreen) {
if (isOnscreen && HAS_REANIMATED_3) {
const { nativeId, Skia, _recording } = this;
if (HAS_REANIMATED_3) {
Rea.runOnUI(() => {
drawOnscreen(Skia, nativeId, _recording!);
})();
} else {
Rea.runOnUI(() => {
drawOnscreen(Skia, nativeId, _recording!);
}
})();
} else if (isOnscreen) {
drawOnscreen(this.Skia, this.nativeId, this._recording!);
}
}

Expand Down

0 comments on commit c46b7c6

Please sign in to comment.