react-native-wgpu 0.1.8 → 0.1.10
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/cpp/cpp-adapter.cpp +23 -36
- package/android/src/main/java/com/webgpu/WebGPUModule.java +0 -37
- package/android/src/main/java/com/webgpu/WebGPUView.java +10 -2
- package/android/src/main/java/com/webgpu/WebGPUViewPackage.java +1 -1
- package/cpp/rnwgpu/RNWebGPUManager.cpp +1 -0
- package/cpp/rnwgpu/RNWebGPUManager.h +3 -2
- package/cpp/rnwgpu/SurfaceRegistry.h +196 -14
- package/cpp/rnwgpu/api/Canvas.h +15 -15
- package/cpp/rnwgpu/api/GPUCanvasContext.cpp +15 -25
- package/cpp/rnwgpu/api/GPUCanvasContext.h +12 -9
- package/cpp/rnwgpu/api/GPUDevice.cpp +3 -2
- package/cpp/rnwgpu/api/RNWebGPU.h +25 -10
- package/ios/MetalView.mm +13 -0
- package/ios/SurfaceUtils.h +2 -0
- package/ios/SurfaceUtils.mm +16 -5
- package/ios/WebGPUModule.mm +8 -25
- package/ios/WebGPUView.mm +9 -6
- package/lib/commonjs/Canvas.js +79 -18
- package/lib/commonjs/Canvas.js.map +1 -1
- package/lib/commonjs/Offscreen.js +3 -0
- package/lib/commonjs/Offscreen.js.map +1 -1
- package/lib/commonjs/hooks.js +56 -0
- package/lib/commonjs/hooks.js.map +1 -0
- package/lib/commonjs/index.js +12 -4
- package/lib/commonjs/index.js.map +1 -1
- package/lib/module/Canvas.js +80 -19
- package/lib/module/Canvas.js.map +1 -1
- package/lib/module/Offscreen.js +3 -0
- package/lib/module/Offscreen.js.map +1 -1
- package/lib/module/hooks.js +47 -0
- package/lib/module/hooks.js.map +1 -0
- package/lib/module/index.js +6 -1
- package/lib/module/index.js.map +1 -1
- package/lib/typescript/lib/commonjs/Offscreen.d.ts +1 -0
- package/lib/typescript/lib/commonjs/Offscreen.d.ts.map +1 -1
- package/lib/typescript/lib/commonjs/hooks.d.ts +12 -0
- package/lib/typescript/lib/commonjs/hooks.d.ts.map +1 -0
- package/lib/typescript/lib/commonjs/index.d.ts +1 -0
- package/lib/typescript/lib/commonjs/index.d.ts.map +1 -1
- package/lib/typescript/lib/module/Canvas.d.ts.map +1 -1
- package/lib/typescript/lib/module/Offscreen.d.ts +1 -0
- package/lib/typescript/lib/module/Offscreen.d.ts.map +1 -1
- package/lib/typescript/lib/module/hooks.d.ts +10 -0
- package/lib/typescript/lib/module/hooks.d.ts.map +1 -0
- package/lib/typescript/lib/module/index.d.ts +2 -1
- package/lib/typescript/lib/module/index.d.ts.map +1 -1
- package/lib/typescript/src/Canvas.d.ts +4 -2
- package/lib/typescript/src/Canvas.d.ts.map +1 -1
- package/lib/typescript/src/Offscreen.d.ts +16 -1
- package/lib/typescript/src/Offscreen.d.ts.map +1 -1
- package/lib/typescript/src/hooks.d.ts +13 -0
- package/lib/typescript/src/hooks.d.ts.map +1 -0
- package/lib/typescript/src/index.d.ts +2 -1
- package/lib/typescript/src/index.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/Canvas.tsx +99 -35
- package/src/Offscreen.ts +6 -2
- package/src/hooks.ts +53 -0
- package/src/index.tsx +9 -1
- package/lib/commonjs/utils.js +0 -39
- package/lib/commonjs/utils.js.map +0 -1
- package/lib/module/utils.js +0 -31
- package/lib/module/utils.js.map +0 -1
- package/lib/typescript/lib/commonjs/utils.d.ts +0 -5
- package/lib/typescript/lib/commonjs/utils.d.ts.map +0 -1
- package/lib/typescript/lib/module/utils.d.ts +0 -3
- package/lib/typescript/lib/module/utils.d.ts.map +0 -1
- package/lib/typescript/src/utils.d.ts +0 -7
- package/lib/typescript/src/utils.d.ts.map +0 -1
- package/src/utils.ts +0 -42
package/lib/commonjs/utils.js
DELETED
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.warnIfNotHardwareAccelerated = exports.useCanvasEffect = void 0;
|
|
7
|
-
var _react = require("react");
|
|
8
|
-
const warnIfNotHardwareAccelerated = adapter => {
|
|
9
|
-
if (adapter.info.architecture === "swiftshader") {
|
|
10
|
-
console.warn("GPUAdapter is not hardware accelerated. This is common on Android emulators. Rendering will be slow.");
|
|
11
|
-
}
|
|
12
|
-
};
|
|
13
|
-
exports.warnIfNotHardwareAccelerated = warnIfNotHardwareAccelerated;
|
|
14
|
-
const useCanvasEffect = (effect, deps = []) => {
|
|
15
|
-
const ref = (0, _react.useRef)(null);
|
|
16
|
-
const unsubscribe = (0, _react.useRef)();
|
|
17
|
-
(0, _react.useEffect)(() => {
|
|
18
|
-
requestAnimationFrame(async () => {
|
|
19
|
-
// const adapter = await navigator.gpu.requestAdapter();
|
|
20
|
-
// if (!adapter) {
|
|
21
|
-
// return;
|
|
22
|
-
// }
|
|
23
|
-
// const device = await adapter.requestDevice();
|
|
24
|
-
const unsub = await effect();
|
|
25
|
-
if (unsub) {
|
|
26
|
-
unsubscribe.current = unsub;
|
|
27
|
-
}
|
|
28
|
-
});
|
|
29
|
-
return () => {
|
|
30
|
-
if (unsubscribe.current) {
|
|
31
|
-
unsubscribe.current();
|
|
32
|
-
}
|
|
33
|
-
};
|
|
34
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
35
|
-
}, deps);
|
|
36
|
-
return ref;
|
|
37
|
-
};
|
|
38
|
-
exports.useCanvasEffect = useCanvasEffect;
|
|
39
|
-
//# sourceMappingURL=utils.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":["_react","require","warnIfNotHardwareAccelerated","adapter","info","architecture","console","warn","exports","useCanvasEffect","effect","deps","ref","useRef","unsubscribe","useEffect","requestAnimationFrame","unsub","current"],"sourceRoot":"../../src","sources":["utils.ts"],"mappings":";;;;;;AACA,IAAAA,MAAA,GAAAC,OAAA;AAMO,MAAMC,4BAA4B,GAAIC,OAAmB,IAAK;EACnE,IAAIA,OAAO,CAACC,IAAI,CAACC,YAAY,KAAK,aAAa,EAAE;IAC/CC,OAAO,CAACC,IAAI,CACV,sGACF,CAAC;EACH;AACF,CAAC;AAACC,OAAA,CAAAN,4BAAA,GAAAA,4BAAA;AAEK,MAAMO,eAAe,GAAGA,CAC7BC,MAA8D,EAC9DC,IAAoB,GAAG,EAAE,KACtB;EACH,MAAMC,GAAG,GAAG,IAAAC,aAAM,EAAY,IAAI,CAAC;EACnC,MAAMC,WAAW,GAAG,IAAAD,aAAM,EAAc,CAAC;EACzC,IAAAE,gBAAS,EAAC,MAAM;IACdC,qBAAqB,CAAC,YAAY;MAChC;MACA;MACA;MACA;MACA;MACA,MAAMC,KAAK,GAAG,MAAMP,MAAM,CAAC,CAAC;MAC5B,IAAIO,KAAK,EAAE;QACTH,WAAW,CAACI,OAAO,GAAGD,KAAK;MAC7B;IACF,CAAC,CAAC;IACF,OAAO,MAAM;MACX,IAAIH,WAAW,CAACI,OAAO,EAAE;QACvBJ,WAAW,CAACI,OAAO,CAAC,CAAC;MACvB;IACF,CAAC;IACD;EACF,CAAC,EAAEP,IAAI,CAAC;EACR,OAAOC,GAAG;AACZ,CAAC;AAACJ,OAAA,CAAAC,eAAA,GAAAA,eAAA","ignoreList":[]}
|
package/lib/module/utils.js
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import { useEffect, useRef } from "react";
|
|
2
|
-
export const warnIfNotHardwareAccelerated = adapter => {
|
|
3
|
-
if (adapter.info.architecture === "swiftshader") {
|
|
4
|
-
console.warn("GPUAdapter is not hardware accelerated. This is common on Android emulators. Rendering will be slow.");
|
|
5
|
-
}
|
|
6
|
-
};
|
|
7
|
-
export const useCanvasEffect = (effect, deps = []) => {
|
|
8
|
-
const ref = useRef(null);
|
|
9
|
-
const unsubscribe = useRef();
|
|
10
|
-
useEffect(() => {
|
|
11
|
-
requestAnimationFrame(async () => {
|
|
12
|
-
// const adapter = await navigator.gpu.requestAdapter();
|
|
13
|
-
// if (!adapter) {
|
|
14
|
-
// return;
|
|
15
|
-
// }
|
|
16
|
-
// const device = await adapter.requestDevice();
|
|
17
|
-
const unsub = await effect();
|
|
18
|
-
if (unsub) {
|
|
19
|
-
unsubscribe.current = unsub;
|
|
20
|
-
}
|
|
21
|
-
});
|
|
22
|
-
return () => {
|
|
23
|
-
if (unsubscribe.current) {
|
|
24
|
-
unsubscribe.current();
|
|
25
|
-
}
|
|
26
|
-
};
|
|
27
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
28
|
-
}, deps);
|
|
29
|
-
return ref;
|
|
30
|
-
};
|
|
31
|
-
//# sourceMappingURL=utils.js.map
|
package/lib/module/utils.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":["useEffect","useRef","warnIfNotHardwareAccelerated","adapter","info","architecture","console","warn","useCanvasEffect","effect","deps","ref","unsubscribe","requestAnimationFrame","unsub","current"],"sourceRoot":"../../src","sources":["utils.ts"],"mappings":"AACA,SAASA,SAAS,EAAEC,MAAM,QAAQ,OAAO;AAMzC,OAAO,MAAMC,4BAA4B,GAAIC,OAAmB,IAAK;EACnE,IAAIA,OAAO,CAACC,IAAI,CAACC,YAAY,KAAK,aAAa,EAAE;IAC/CC,OAAO,CAACC,IAAI,CACV,sGACF,CAAC;EACH;AACF,CAAC;AAED,OAAO,MAAMC,eAAe,GAAGA,CAC7BC,MAA8D,EAC9DC,IAAoB,GAAG,EAAE,KACtB;EACH,MAAMC,GAAG,GAAGV,MAAM,CAAY,IAAI,CAAC;EACnC,MAAMW,WAAW,GAAGX,MAAM,CAAc,CAAC;EACzCD,SAAS,CAAC,MAAM;IACda,qBAAqB,CAAC,YAAY;MAChC;MACA;MACA;MACA;MACA;MACA,MAAMC,KAAK,GAAG,MAAML,MAAM,CAAC,CAAC;MAC5B,IAAIK,KAAK,EAAE;QACTF,WAAW,CAACG,OAAO,GAAGD,KAAK;MAC7B;IACF,CAAC,CAAC;IACF,OAAO,MAAM;MACX,IAAIF,WAAW,CAACG,OAAO,EAAE;QACvBH,WAAW,CAACG,OAAO,CAAC,CAAC;MACvB;IACF,CAAC;IACD;EACF,CAAC,EAAEL,IAAI,CAAC;EACR,OAAOC,GAAG;AACZ,CAAC","ignoreList":[]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../commonjs/utils.js"],"names":[],"mappings":";AAOA,iEAIC;AAED,0FAuBC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../module/utils.js"],"names":[],"mappings":"AACO,iEAIN;AACM,mGAuBN"}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import type { DependencyList } from "react";
|
|
2
|
-
import type { CanvasRef } from "./Canvas";
|
|
3
|
-
type Unsubscribe = () => void;
|
|
4
|
-
export declare const warnIfNotHardwareAccelerated: (adapter: GPUAdapter) => void;
|
|
5
|
-
export declare const useCanvasEffect: (effect: () => void | Unsubscribe | Promise<void | Unsubscribe>, deps?: DependencyList) => import("react").RefObject<CanvasRef>;
|
|
6
|
-
export {};
|
|
7
|
-
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,OAAO,CAAC;AAG5C,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AAE1C,KAAK,WAAW,GAAG,MAAM,IAAI,CAAC;AAE9B,eAAO,MAAM,4BAA4B,YAAa,UAAU,SAM/D,CAAC;AAEF,eAAO,MAAM,eAAe,WAClB,MAAM,IAAI,GAAG,WAAW,GAAG,OAAO,CAAC,IAAI,GAAG,WAAW,CAAC,SACxD,cAAc,yCAwBrB,CAAC"}
|
package/src/utils.ts
DELETED
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import type { DependencyList } from "react";
|
|
2
|
-
import { useEffect, useRef } from "react";
|
|
3
|
-
|
|
4
|
-
import type { CanvasRef } from "./Canvas";
|
|
5
|
-
|
|
6
|
-
type Unsubscribe = () => void;
|
|
7
|
-
|
|
8
|
-
export const warnIfNotHardwareAccelerated = (adapter: GPUAdapter) => {
|
|
9
|
-
if (adapter.info.architecture === "swiftshader") {
|
|
10
|
-
console.warn(
|
|
11
|
-
"GPUAdapter is not hardware accelerated. This is common on Android emulators. Rendering will be slow.",
|
|
12
|
-
);
|
|
13
|
-
}
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
export const useCanvasEffect = (
|
|
17
|
-
effect: () => void | Unsubscribe | Promise<void | Unsubscribe>,
|
|
18
|
-
deps: DependencyList = [],
|
|
19
|
-
) => {
|
|
20
|
-
const ref = useRef<CanvasRef>(null);
|
|
21
|
-
const unsubscribe = useRef<Unsubscribe>();
|
|
22
|
-
useEffect(() => {
|
|
23
|
-
requestAnimationFrame(async () => {
|
|
24
|
-
// const adapter = await navigator.gpu.requestAdapter();
|
|
25
|
-
// if (!adapter) {
|
|
26
|
-
// return;
|
|
27
|
-
// }
|
|
28
|
-
// const device = await adapter.requestDevice();
|
|
29
|
-
const unsub = await effect();
|
|
30
|
-
if (unsub) {
|
|
31
|
-
unsubscribe.current = unsub;
|
|
32
|
-
}
|
|
33
|
-
});
|
|
34
|
-
return () => {
|
|
35
|
-
if (unsubscribe.current) {
|
|
36
|
-
unsubscribe.current();
|
|
37
|
-
}
|
|
38
|
-
};
|
|
39
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
40
|
-
}, deps);
|
|
41
|
-
return ref;
|
|
42
|
-
};
|