Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 64 additions & 9 deletions apps/example/src/Examples/API/StressTest4.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useState } from "react";
import React, { useEffect, useState } from "react";
import {
Alert,
Button,
Expand All @@ -18,13 +18,35 @@ import {
withTiming,
} from "react-native-reanimated";

const logMemoryStats = () => {
"worklet";
if (
typeof HermesInternal !== "undefined" &&
// @ts-expect-error - HermesInternal is available in Hermes runtime
HermesInternal?.getInstrumentedStats
) {
// // @ts-expect-error - HermesInternal is available in Hermes runtime
// const stats = HermesInternal.getInstrumentedStats();
// const externalMB = (stats.js_externalBytes / (1024 * 1024)).toFixed(2);
// const totalAllocatedMB = (
// stats.js_totalAllocatedBytes /
// (1024 * 1024)
// ).toFixed(2);
// const heapSizeMB = (stats.js_heapSize / (1024 * 1024)).toFixed(2);
// console.log(
// `External: ${externalMB} MB, Total Allocated: ${totalAllocatedMB} MB, Heap Size: ${heapSizeMB} MB`
// );
}
};

const drawFrame = (
surface: SharedValue<SkSurface | null>,
image: SharedValue<SkImage | null>,
x: SharedValue<number>,
pixelRatio: number
) => {
"worklet";
logMemoryStats();
if (!surface.value) {
Alert.alert("surface is null");
return false;
Expand Down Expand Up @@ -56,11 +78,16 @@ function continueBlink(
blinkCnt: SharedValue<number>,
isLeft: SharedValue<boolean>,
pixelRatio: number,
revert: (d: string) => void
revert: (d: string) => void,
shouldContinue: SharedValue<boolean>
) {
"worklet";
if (!shouldContinue.value) {
return;
}
blinkCnt.value++;
looper.value = withTiming(1 - looper.value, { duration: 10 }, () => {
if (!shouldContinue.value) return;
if (!drawFrame(surface, image, x, pixelRatio)) return;
if (blinkCnt.value < 20) {
continueBlink(
Expand All @@ -71,13 +98,16 @@ function continueBlink(
blinkCnt,
isLeft,
pixelRatio,
revert
revert,
shouldContinue
);
} else {
if (!shouldContinue.value) return;
runOnJS(revert)(isLeft.value ? "right" : "left");
isLeft.value = !isLeft.value;
blinkCnt.value = 0;
x.value = withTiming(400 - x.value, { duration: 200 }, () => {
if (!shouldContinue.value) return;
continueBlink(
surface,
image,
Expand All @@ -86,7 +116,8 @@ function continueBlink(
blinkCnt,
isLeft,
pixelRatio,
revert
revert,
shouldContinue
);
});
}
Expand All @@ -101,9 +132,11 @@ const startBlink = (
blinkCnt: SharedValue<number>,
isLeft: SharedValue<boolean>,
pixelRatio: number,
revert: (d: string) => void
revert: (d: string) => void,
shouldContinue: SharedValue<boolean>
) => {
"worklet";
if (!shouldContinue.value) return;
blinkCnt.value = 0;
if (drawFrame(surface, image, x, pixelRatio)) {
continueBlink(
Expand All @@ -114,7 +147,8 @@ const startBlink = (
blinkCnt,
isLeft,
pixelRatio,
revert
revert,
shouldContinue
);
}
};
Expand All @@ -127,7 +161,8 @@ const startAnimation = (
blinkCnt: SharedValue<number>,
isLeft: SharedValue<boolean>,
pixelRatio: number,
revert: (d: string) => void
revert: (d: string) => void,
shouldContinue: SharedValue<boolean>
) => {
"worklet";
if (!surface.value) {
Expand All @@ -136,7 +171,17 @@ const startAnimation = (
pixelRatio * 400
);
}
startBlink(surface, image, x, looper, blinkCnt, isLeft, pixelRatio, revert);
startBlink(
surface,
image,
x,
looper,
blinkCnt,
isLeft,
pixelRatio,
revert,
shouldContinue
);
};

export const StressTest4 = () => {
Expand All @@ -149,10 +194,12 @@ export const StressTest4 = () => {
const [direction, setDirection] = useState("left");
const isLeft = useSharedValue(true);
const blinkCnt = useSharedValue(0);
const shouldContinue = useSharedValue(true);

const imageX = useDerivedValue(() => -x.value);

const handleStart = () => {
shouldContinue.value = true;
runOnUI(startAnimation)(
surface,
image,
Expand All @@ -161,10 +208,18 @@ export const StressTest4 = () => {
blinkCnt,
isLeft,
pixelRatio,
setDirection
setDirection,
shouldContinue
);
};

useEffect(() => {
// Stop animation on unmount
return () => {
shouldContinue.value = false;
};
}, [shouldContinue]);

return (
<SafeAreaView style={styles.container}>
<Text>Direction: {direction}</Text>
Expand Down
5 changes: 0 additions & 5 deletions apps/example/src/Home/HomeScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,6 @@ export const HomeScreen = () => {
description="Simple declarative example"
route="Breathe"
/>
<HomeScreenButton
title="đź–Ľ Image Loading"
description="Load and edit an image"
route="ImageLoading"
/>
<HomeScreenButton
title="🏞 Filters"
description="Simple Image Filters"
Expand Down
2 changes: 1 addition & 1 deletion externals/depot_tools
Submodule depot_tools updated from abc510 to 8a1ec6
4 changes: 4 additions & 0 deletions packages/skia/cpp/api/JsiNativeBuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ class JsiNativeBufferFactory : public JsiSkHostObject {

size_t getMemoryPressure() const override { return 1024; }

std::string getObjectType() const override {
return "JsiNativeBufferFactory";
}

explicit JsiNativeBufferFactory(std::shared_ptr<RNSkPlatformContext> context)
: JsiSkHostObject(std::move(context)) {}
};
Expand Down
2 changes: 2 additions & 0 deletions packages/skia/cpp/api/JsiSkAnimatedImage.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ class JsiSkAnimatedImage
std::move(image)) {}

size_t getMemoryPressure() const override { return 8192; }

std::string getObjectType() const override { return "JsiSkAnimatedImage"; }
};

} // namespace RNSkia
4 changes: 4 additions & 0 deletions packages/skia/cpp/api/JsiSkAnimatedImageFactory.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ class JsiSkAnimatedImageFactory : public JsiSkHostObject {

size_t getMemoryPressure() const override { return 1024; }

std::string getObjectType() const override {
return "JsiSkAnimatedImageFactory";
}

JSI_EXPORT_FUNCTIONS(JSI_EXPORT_FUNC(JsiSkAnimatedImageFactory,
MakeAnimatedImageFromEncoded))

Expand Down
2 changes: 2 additions & 0 deletions packages/skia/cpp/api/JsiSkApi.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ class JsiSkApi : public JsiSkHostObject {
public:
size_t getMemoryPressure() const override { return 8192; }

std::string getObjectType() const override { return "JsiSkApi"; }

/**
* Constructs the Skia Api object that can be installed into a runtime
* and provide functions for accessing and creating the Skia wrapper objects
Expand Down
2 changes: 2 additions & 0 deletions packages/skia/cpp/api/JsiSkCanvas.h
Original file line number Diff line number Diff line change
Expand Up @@ -695,6 +695,8 @@ class JsiSkCanvas : public JsiSkHostObject {

size_t getMemoryPressure() const override { return 1024; }

std::string getObjectType() const override { return "JsiSkCanvas"; }

explicit JsiSkCanvas(std::shared_ptr<RNSkPlatformContext> context)
: JsiSkHostObject(std::move(context)) {}

Expand Down
2 changes: 2 additions & 0 deletions packages/skia/cpp/api/JsiSkColorFilter.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ class JsiSkColorFilter : public JsiSkWrappingSkPtrHostObject<SkColorFilter> {

size_t getMemoryPressure() const override { return 2048; }

std::string getObjectType() const override { return "JsiSkColorFilter"; }

EXPORT_JSI_API_TYPENAME(JsiSkColorFilter, ColorFilter)
JSI_EXPORT_FUNCTIONS(JSI_EXPORT_FUNC(JsiSkColorFilter, dispose))
};
Expand Down
4 changes: 4 additions & 0 deletions packages/skia/cpp/api/JsiSkColorFilterFactory.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,10 @@ class JsiSkColorFilterFactory : public JsiSkHostObject {

size_t getMemoryPressure() const override { return 1024; }

std::string getObjectType() const override {
return "JsiSkColorFilterFactory";
}

JSI_EXPORT_FUNCTIONS(
JSI_EXPORT_FUNC(JsiSkColorFilterFactory, MakeMatrix),
JSI_EXPORT_FUNC(JsiSkColorFilterFactory, MakeBlend),
Expand Down
2 changes: 2 additions & 0 deletions packages/skia/cpp/api/JsiSkContourMeasure.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ class JsiSkContourMeasure

size_t getMemoryPressure() const override { return 1024; }

std::string getObjectType() const override { return "JsiSkContourMeasure"; }

EXPORT_JSI_API_TYPENAME(JsiSkContourMeasure, ContourMeasure)

JSI_EXPORT_FUNCTIONS(JSI_EXPORT_FUNC(JsiSkContourMeasure, getPosTan),
Expand Down
4 changes: 4 additions & 0 deletions packages/skia/cpp/api/JsiSkContourMeasureIter.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ class JsiSkContourMeasureIter
return sizeof(SkContourMeasureIter);
}

std::string getObjectType() const override {
return "JsiSkContourMeasureIter";
}

/**
* Creates the function for construction a new instance of the
* SkContourMeasureIter wrapper
Expand Down
2 changes: 2 additions & 0 deletions packages/skia/cpp/api/JsiSkData.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ class JsiSkData : public JsiSkWrappingSkPtrHostObject<SkData> {
return data ? data->size() : 0;
}

std::string getObjectType() const override { return "JsiSkData"; }

EXPORT_JSI_API_TYPENAME(JsiSkData, Data)
JSI_EXPORT_FUNCTIONS(JSI_EXPORT_FUNC(JsiSkData, dispose))
};
Expand Down
2 changes: 2 additions & 0 deletions packages/skia/cpp/api/JsiSkDataFactory.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@ class JsiSkDataFactory : public JsiSkHostObject {

size_t getMemoryPressure() const override { return 1024; }

std::string getObjectType() const override { return "JsiSkDataFactory"; }

JSI_EXPORT_FUNCTIONS(JSI_EXPORT_FUNC(JsiSkDataFactory, fromURI),
JSI_EXPORT_FUNC(JsiSkDataFactory, fromBytes),
JSI_EXPORT_FUNC(JsiSkDataFactory, fromBase64))
Expand Down
2 changes: 2 additions & 0 deletions packages/skia/cpp/api/JsiSkFont.h
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,8 @@ class JsiSkFont : public JsiSkWrappingSharedPtrHostObject<SkFont> {

size_t getMemoryPressure() const override { return sizeof(SkFont); }

std::string getObjectType() const override { return "JsiSkFont"; }

/**
* Creates the function for construction a new instance of the SkFont
* wrapper
Expand Down
2 changes: 2 additions & 0 deletions packages/skia/cpp/api/JsiSkFontMgr.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ class JsiSkFontMgr : public JsiSkWrappingSkPtrHostObject<SkFontMgr> {

size_t getMemoryPressure() const override { return 2048; }

std::string getObjectType() const override { return "JsiSkFontMgr"; }

JSI_EXPORT_FUNCTIONS(JSI_EXPORT_FUNC(JsiSkFontMgr, countFamilies),
JSI_EXPORT_FUNC(JsiSkFontMgr, getFamilyName),
JSI_EXPORT_FUNC(JsiSkFontMgr, matchFamilyStyle))
Expand Down
2 changes: 2 additions & 0 deletions packages/skia/cpp/api/JsiSkFontMgrFactory.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ class JsiSkFontMgrFactory : public JsiSkHostObject {

size_t getMemoryPressure() const override { return 1024; }

std::string getObjectType() const override { return "JsiSkFontMgrFactory"; }

explicit JsiSkFontMgrFactory(std::shared_ptr<RNSkPlatformContext> context)
: JsiSkHostObject(std::move(context)) {}
};
Expand Down
2 changes: 2 additions & 0 deletions packages/skia/cpp/api/JsiSkFontStyle.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ class JsiSkFontStyle : public JsiSkWrappingSharedPtrHostObject<SkFontStyle> {

size_t getMemoryPressure() const override { return sizeof(SkFontStyle); }

std::string getObjectType() const override { return "JsiSkFontStyle"; }

/**
Returns the jsi object from a host object of this type
*/
Expand Down
Loading
Loading