react-native-webgpu 0.22.0 → 0.23.0
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/README.md +15 -2
- package/android/CMakeLists.txt +2 -1
- package/android/cpp/AndroidAnimationFrameSource.h +136 -0
- package/android/cpp/AndroidPlatformContext.h +55 -0
- package/android/cpp/cpp-adapter.cpp +148 -2
- package/android/src/main/java/com/webgpu/WebGPUModule.java +21 -4
- package/android/src/main/java/com/webgpu/WebGPUNativeBufferView.java +370 -0
- package/android/src/main/java/com/webgpu/WebGPUNativeBufferViewManager.java +56 -0
- package/android/src/main/java/com/webgpu/WebGPUTextureView.java +21 -0
- package/android/src/main/java/com/webgpu/WebGPUVideoPlayer.java +1 -1
- package/android/src/main/java/com/webgpu/WebGPUView.java +19 -3
- package/android/src/main/java/com/webgpu/WebGPUViewPackage.java +2 -2
- package/android/src/newarch/com/webgpu/WebGPUNativeBufferViewManagerSpec.java +24 -0
- package/apple/AppleAnimationFrameSource.mm +208 -0
- package/apple/ApplePlatformContext.h +6 -0
- package/apple/ApplePlatformContext.mm +73 -0
- package/apple/NativeBufferFenceWait.mm +88 -0
- package/apple/WebGPUNativeBufferView.h +15 -0
- package/apple/WebGPUNativeBufferView.mm +200 -0
- package/cpp/rnwgpu/AnimationFrames.cpp +576 -0
- package/cpp/rnwgpu/AnimationFrames.h +233 -0
- package/cpp/rnwgpu/NativeBufferViewRegistry.cpp +396 -0
- package/cpp/rnwgpu/NativeBufferViewRegistry.h +163 -0
- package/cpp/rnwgpu/PlatformContext.h +20 -0
- package/cpp/rnwgpu/RNWebGPUManager.cpp +17 -4
- package/cpp/rnwgpu/api/GPUAdapter.cpp +1 -1
- package/cpp/rnwgpu/api/GPUDevice.cpp +16 -131
- package/cpp/rnwgpu/api/GPUDevice.h +0 -18
- package/cpp/rnwgpu/api/GPUExternalTexture.cpp +35 -3
- package/cpp/rnwgpu/api/GPUExternalTexture.h +4 -4
- package/cpp/rnwgpu/api/GPUQueue.cpp +1 -1
- package/cpp/rnwgpu/api/GPUQueue.h +1 -1
- package/cpp/rnwgpu/api/GPUSharedFence.h +1 -0
- package/cpp/rnwgpu/api/GPUSharedTextureMemory.cpp +11 -5
- package/cpp/rnwgpu/api/GPUSharedTextureMemory.h +21 -2
- package/cpp/rnwgpu/api/GPUTexture.h +18 -0
- package/cpp/rnwgpu/api/NativeFrameFeatures.h +1 -1
- package/cpp/rnwgpu/api/NativeFrameImport.cpp +20 -17
- package/cpp/rnwgpu/api/NativeFrameImport.h +31 -20
- package/cpp/rnwgpu/api/RNWebGPU.h +201 -3
- package/cpp/rnwgpu/api/VideoFrame.h +5 -4
- package/cpp/rnwgpu/api/VideoFrameBlit.h +2 -2
- package/cpp/rnwgpu/api/descriptors/GPUExternalTextureDescriptor.h +21 -14
- package/cpp/rnwgpu/api/descriptors/GPUImageCopyExternalImage.h +1 -1
- package/cpp/rnwgpu/api/descriptors/GPUSharedTextureMemoryDescriptor.h +17 -9
- package/cpp/rnwgpu/async/RuntimeContext.cpp +21 -4
- package/cpp/rnwgpu/async/RuntimeContext.h +8 -0
- package/lib/commonjs/NativeBufferView.js +131 -0
- package/lib/commonjs/NativeBufferView.js.map +1 -0
- package/lib/commonjs/NativeBufferViewNativeComponent.js +10 -0
- package/lib/commonjs/NativeBufferViewNativeComponent.js.map +1 -0
- package/lib/commonjs/animationFrame.js +91 -0
- package/lib/commonjs/animationFrame.js.map +1 -0
- package/lib/commonjs/index.js +16 -1
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/main/index.js +12 -0
- package/lib/commonjs/main/index.js.map +1 -1
- package/lib/commonjs/mock.js +30 -1
- package/lib/commonjs/mock.js.map +1 -1
- package/lib/commonjs/video.js +14 -4
- package/lib/commonjs/video.js.map +1 -1
- package/lib/module/NativeBufferView.js +122 -0
- package/lib/module/NativeBufferView.js.map +1 -0
- package/lib/module/NativeBufferViewNativeComponent.js +4 -0
- package/lib/module/NativeBufferViewNativeComponent.js.map +1 -0
- package/lib/module/animationFrame.js +83 -0
- package/lib/module/animationFrame.js.map +1 -0
- package/lib/module/index.js +1 -0
- package/lib/module/index.js.map +1 -1
- package/lib/module/main/index.js +1 -0
- package/lib/module/main/index.js.map +1 -1
- package/lib/module/mock.js +21 -0
- package/lib/module/mock.js.map +1 -1
- package/lib/module/video.js +11 -2
- package/lib/module/video.js.map +1 -1
- package/lib/typescript/lib/commonjs/NativeBufferView.d.ts +48 -0
- package/lib/typescript/lib/commonjs/NativeBufferView.d.ts.map +1 -0
- package/lib/typescript/lib/commonjs/NativeBufferViewNativeComponent.d.ts +5 -0
- package/lib/typescript/lib/commonjs/NativeBufferViewNativeComponent.d.ts.map +1 -0
- package/lib/typescript/lib/commonjs/animationFrame.d.ts +54 -0
- package/lib/typescript/lib/commonjs/animationFrame.d.ts.map +1 -0
- package/lib/typescript/lib/commonjs/index.d.ts +2 -0
- package/lib/typescript/lib/commonjs/mock.d.ts +12 -0
- package/lib/typescript/lib/commonjs/mock.d.ts.map +1 -1
- package/lib/typescript/lib/commonjs/video.d.ts +3 -2
- package/lib/typescript/lib/commonjs/video.d.ts.map +1 -1
- package/lib/typescript/lib/module/NativeBufferView.d.ts +14 -0
- package/lib/typescript/lib/module/NativeBufferView.d.ts.map +1 -0
- package/lib/typescript/lib/module/NativeBufferViewNativeComponent.d.ts +3 -0
- package/lib/typescript/lib/module/NativeBufferViewNativeComponent.d.ts.map +1 -0
- package/lib/typescript/lib/module/animationFrame.d.ts +3 -0
- package/lib/typescript/lib/module/animationFrame.d.ts.map +1 -0
- package/lib/typescript/lib/module/index.d.ts +1 -0
- package/lib/typescript/lib/module/main/index.d.ts +1 -0
- package/lib/typescript/lib/module/mock.d.ts +14 -0
- package/lib/typescript/lib/module/mock.d.ts.map +1 -1
- package/lib/typescript/lib/module/video.d.ts +3 -2
- package/lib/typescript/lib/module/video.d.ts.map +1 -1
- package/lib/typescript/src/NativeBufferView.d.ts +99 -0
- package/lib/typescript/src/NativeBufferView.d.ts.map +1 -0
- package/lib/typescript/src/NativeBufferViewNativeComponent.d.ts +13 -0
- package/lib/typescript/src/NativeBufferViewNativeComponent.d.ts.map +1 -0
- package/lib/typescript/src/animationFrame.d.ts +59 -0
- package/lib/typescript/src/animationFrame.d.ts.map +1 -0
- package/lib/typescript/src/index.d.ts +18 -8
- package/lib/typescript/src/index.d.ts.map +1 -1
- package/lib/typescript/src/main/index.d.ts +1 -0
- package/lib/typescript/src/main/index.d.ts.map +1 -1
- package/lib/typescript/src/mock.d.ts +11 -0
- package/lib/typescript/src/mock.d.ts.map +1 -1
- package/lib/typescript/src/types.d.ts +32 -31
- package/lib/typescript/src/types.d.ts.map +1 -1
- package/lib/typescript/src/video.d.ts +12 -4
- package/lib/typescript/src/video.d.ts.map +1 -1
- package/package.json +7 -2
- package/react-native-webgpu.podspec +1 -1
- package/src/NativeBufferView.tsx +199 -0
- package/src/NativeBufferViewNativeComponent.ts +20 -0
- package/src/animationFrame.ts +82 -0
- package/src/index.tsx +45 -39
- package/src/main/index.tsx +1 -0
- package/src/mock.ts +35 -0
- package/src/types.ts +61 -87
- package/src/video.ts +20 -7
- package/cpp/rnwgpu/api/GPUNativeBufferExternalTexture.h +0 -60
- package/cpp/rnwgpu/api/GPUNativeBufferTexture.h +0 -52
- package/cpp/rnwgpu/api/GPUNativeBufferWrapper.cpp +0 -144
- package/cpp/rnwgpu/api/GPUNativeBufferWrapper.h +0 -143
- package/cpp/rnwgpu/api/descriptors/GPUNativeBufferTextureDescriptor.h +0 -55
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
|
|
2
|
+
import React, { useCallback, useEffect, useImperativeHandle, useLayoutEffect, useRef, useState } from "react";
|
|
3
|
+
import NativeBufferViewNative from "./NativeBufferViewNativeComponent";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* How a {@link NativeBufferView} fits a buffer whose size differs from its
|
|
7
|
+
* own (in physical pixels), for instance while the producer catches up with
|
|
8
|
+
* a resize. A buffer of exactly the view's size is shown 1:1 in every mode.
|
|
9
|
+
*
|
|
10
|
+
* - `stretch` (the default): scaled to the bounds, ignoring the aspect ratio.
|
|
11
|
+
* - `contain`: scaled to fit inside the bounds, keeping the aspect ratio.
|
|
12
|
+
* - `cover`: scaled to fill the bounds, keeping the aspect ratio; the excess
|
|
13
|
+
* is cropped.
|
|
14
|
+
* - `topLeft`: not scaled; anchored at the top left corner and cropped.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
/** A size in physical pixels. */
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Displays a native buffer (an `AHardwareBuffer` on Android, an `IOSurface`
|
|
21
|
+
* on Apple platforms) with no swap chain, no canvas context and no GPU device
|
|
22
|
+
* on the display side. Meant for content that is static or updated
|
|
23
|
+
* occasionally; animated content belongs in a `Canvas`.
|
|
24
|
+
*
|
|
25
|
+
* The view never allocates buffers. It reports its size in physical pixels
|
|
26
|
+
* ({@link NativeBufferViewProps.onPixelSizeChange}), and any producer
|
|
27
|
+
* (WebGPU, Skia, a camera, a decoder) renders into a buffer and presents it
|
|
28
|
+
* through the ref (frames from a camera or a decoder are copied first, see
|
|
29
|
+
* {@link NativeBufferViewRef.present}). With WebGPU:
|
|
30
|
+
*
|
|
31
|
+
* ```ts
|
|
32
|
+
* const frame = createNativeBuffer(size.width, size.height);
|
|
33
|
+
* const memory = device.importSharedTextureMemory({ source: frame });
|
|
34
|
+
* const texture = memory.createTexture();
|
|
35
|
+
* memory.beginAccess(texture, false);
|
|
36
|
+
* // ... render into texture and submit ...
|
|
37
|
+
* ref.current.present(frame, memory.endAccess(texture));
|
|
38
|
+
* texture.destroy();
|
|
39
|
+
* memory.destroy();
|
|
40
|
+
* frame.release();
|
|
41
|
+
* ```
|
|
42
|
+
*/
|
|
43
|
+
export const NativeBufferView = ({
|
|
44
|
+
resizeMode,
|
|
45
|
+
onPixelSizeChange,
|
|
46
|
+
ref,
|
|
47
|
+
...props
|
|
48
|
+
}) => {
|
|
49
|
+
// Native hands out the id: unique for the life of the process, as the
|
|
50
|
+
// native registry outlives a reload.
|
|
51
|
+
const [viewId] = useState(() => RNWebGPU.allocateNativeBufferViewId());
|
|
52
|
+
useImperativeHandle(ref, () => ({
|
|
53
|
+
viewId,
|
|
54
|
+
present: (frame, done) => RNWebGPU.presentNativeBuffer(viewId, frame, done ?? null)
|
|
55
|
+
}), [viewId]);
|
|
56
|
+
|
|
57
|
+
// The JS side's hold on the native entry; presents to an id nobody holds
|
|
58
|
+
// are dropped. A layout effect, so the entry exists before the ref reaches
|
|
59
|
+
// a parent's effects. Not taken in the useState initializer above: React
|
|
60
|
+
// StrictMode calls it twice and discards one id.
|
|
61
|
+
useLayoutEffect(() => {
|
|
62
|
+
RNWebGPU.retainNativeBufferView(viewId);
|
|
63
|
+
return () => RNWebGPU.releaseNativeBufferView(viewId);
|
|
64
|
+
}, [viewId]);
|
|
65
|
+
const onNativePixelSizeChange = useCallback(event => {
|
|
66
|
+
const {
|
|
67
|
+
width,
|
|
68
|
+
height
|
|
69
|
+
} = event.nativeEvent;
|
|
70
|
+
onPixelSizeChange?.({
|
|
71
|
+
width,
|
|
72
|
+
height
|
|
73
|
+
});
|
|
74
|
+
}, [onPixelSizeChange]);
|
|
75
|
+
return /*#__PURE__*/React.createElement(NativeBufferViewNative, _extends({}, props, {
|
|
76
|
+
viewId: viewId,
|
|
77
|
+
resizeMode: resizeMode,
|
|
78
|
+
onPixelSizeChange: onNativePixelSizeChange
|
|
79
|
+
}));
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Tracks the pixel size of a {@link NativeBufferView}, settling resizes:
|
|
84
|
+
* the first size is reported right away, later ones once the view has kept
|
|
85
|
+
* the same size for `debounceMs` (during an animated resize the view
|
|
86
|
+
* stretches what it shows meanwhile). Pass `onPixelSizeChange` to the view
|
|
87
|
+
* and render a buffer of `size` whenever it changes.
|
|
88
|
+
*/
|
|
89
|
+
export const useNativeBufferSize = (debounceMs = 150) => {
|
|
90
|
+
const [size, setSize] = useState(null);
|
|
91
|
+
const current = useRef(null);
|
|
92
|
+
const timer = useRef(null);
|
|
93
|
+
const onPixelSizeChange = useCallback(next => {
|
|
94
|
+
if (timer.current !== null) {
|
|
95
|
+
clearTimeout(timer.current);
|
|
96
|
+
timer.current = null;
|
|
97
|
+
}
|
|
98
|
+
const settle = () => {
|
|
99
|
+
timer.current = null;
|
|
100
|
+
const previous = current.current;
|
|
101
|
+
if (previous === null || previous.width !== next.width || previous.height !== next.height) {
|
|
102
|
+
current.current = next;
|
|
103
|
+
setSize(next);
|
|
104
|
+
}
|
|
105
|
+
};
|
|
106
|
+
if (current.current === null || debounceMs <= 0) {
|
|
107
|
+
settle();
|
|
108
|
+
} else {
|
|
109
|
+
timer.current = setTimeout(settle, debounceMs);
|
|
110
|
+
}
|
|
111
|
+
}, [debounceMs]);
|
|
112
|
+
useEffect(() => () => {
|
|
113
|
+
if (timer.current !== null) {
|
|
114
|
+
clearTimeout(timer.current);
|
|
115
|
+
}
|
|
116
|
+
}, []);
|
|
117
|
+
return {
|
|
118
|
+
size,
|
|
119
|
+
onPixelSizeChange
|
|
120
|
+
};
|
|
121
|
+
};
|
|
122
|
+
//# sourceMappingURL=NativeBufferView.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["React","useCallback","useEffect","useImperativeHandle","useLayoutEffect","useRef","useState","NativeBufferViewNative","NativeBufferView","resizeMode","onPixelSizeChange","ref","props","viewId","RNWebGPU","allocateNativeBufferViewId","present","frame","done","presentNativeBuffer","retainNativeBufferView","releaseNativeBufferView","onNativePixelSizeChange","event","width","height","nativeEvent","createElement","_extends","useNativeBufferSize","debounceMs","size","setSize","current","timer","next","clearTimeout","settle","previous","setTimeout"],"sourceRoot":"../../src","sources":["NativeBufferView.tsx"],"mappings":";AAAA,OAAOA,KAAK,IACVC,WAAW,EACXC,SAAS,EACTC,mBAAmB,EACnBC,eAAe,EACfC,MAAM,EACNC,QAAQ,QACH,OAAO;AAGd,OAAOC,sBAAsB,MAAM,mCAAmC;;AAGtE;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAIA;;AAmDA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMC,gBAAgB,GAAGA,CAAC;EAC/BC,UAAU;EACVC,iBAAiB;EACjBC,GAAG;EACH,GAAGC;AACkB,CAAC,KAAK;EAC3B;EACA;EACA,MAAM,CAACC,MAAM,CAAC,GAAGP,QAAQ,CAAC,MAAMQ,QAAQ,CAACC,0BAA0B,CAAC,CAAC,CAAC;EAEtEZ,mBAAmB,CACjBQ,GAAG,EACH,OAAO;IACLE,MAAM;IACNG,OAAO,EAAEA,CAACC,KAAK,EAAEC,IAAI,KACnBJ,QAAQ,CAACK,mBAAmB,CAACN,MAAM,EAAEI,KAAK,EAAEC,IAAI,IAAI,IAAI;EAC5D,CAAC,CAAC,EACF,CAACL,MAAM,CACT,CAAC;;EAED;EACA;EACA;EACA;EACAT,eAAe,CAAC,MAAM;IACpBU,QAAQ,CAACM,sBAAsB,CAACP,MAAM,CAAC;IACvC,OAAO,MAAMC,QAAQ,CAACO,uBAAuB,CAACR,MAAM,CAAC;EACvD,CAAC,EAAE,CAACA,MAAM,CAAC,CAAC;EAEZ,MAAMS,uBAAuB,GAAGrB,WAAW,CACxCsB,KAAkD,IAAK;IACtD,MAAM;MAAEC,KAAK;MAAEC;IAAO,CAAC,GAAGF,KAAK,CAACG,WAAW;IAC3ChB,iBAAiB,GAAG;MAAEc,KAAK;MAAEC;IAAO,CAAC,CAAC;EACxC,CAAC,EACD,CAACf,iBAAiB,CACp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CAACA,UAAU,CACb,CAAC;EAED5B,SAAS,CACP,MAAM,MAAM;IACV,IAAIgC,KAAK,CAACD,OAAO,KAAK,IAAI,EAAE;MAC1BG,YAAY,CAACF,KAAK,CAACD,OAAO,CAAC;IAC7B;EACF,CAAC,EACD,EACF,CAAC;EAED,OAAO;IAAEF,IAAI;IAAErB;EAAkB,CAAC;AACpC,CAAC","ignoreList":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["codegenNativeComponent"],"sourceRoot":"../../src","sources":["NativeBufferViewNativeComponent.ts"],"mappings":"AAAA,SAASA,sBAAsB,QAAQ,cAAc;AAkBrD;AACA,eAAeA,sBAAsB,CAAc,wBAAwB,CAAC","ignoreList":[]}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
// The native animation frames (AnimationFramesHostObject in
|
|
2
|
+
// cpp/rnwgpu/AnimationFrames.h), installed on the main runtime. Read at module
|
|
3
|
+
// scope, like the helpers of `./install`, and captured into the worklets
|
|
4
|
+
// below: worklets hands a HostObject to every runtime by reference, and its
|
|
5
|
+
// methods act on the runtime that calls them. Undefined on web and node, where
|
|
6
|
+
// the browser's requestAnimationFrame is the one to use.
|
|
7
|
+
const frames = globalThis.__webgpuAnimationFrames;
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* `requestAnimationFrame`, paced by the display, on any runtime.
|
|
11
|
+
*
|
|
12
|
+
* Drop-in for the global one in a render loop:
|
|
13
|
+
*
|
|
14
|
+
* ```ts
|
|
15
|
+
* import { requestAnimationFrame } from "react-native-webgpu";
|
|
16
|
+
*
|
|
17
|
+
* const render = (timestamp: number) => {
|
|
18
|
+
* draw(timestamp);
|
|
19
|
+
* context.present();
|
|
20
|
+
* requestAnimationFrame(render);
|
|
21
|
+
* };
|
|
22
|
+
* requestAnimationFrame(render);
|
|
23
|
+
* ```
|
|
24
|
+
*
|
|
25
|
+
* React Native's global `requestAnimationFrame` is a timer: on Android it
|
|
26
|
+
* makes the next frame of the display only when it is requested before that
|
|
27
|
+
* frame starts, which leaves a loop that requests its next frame at the end
|
|
28
|
+
* of its work about 6 ms of a 120 Hz frame (past that, it drops to 60 fps),
|
|
29
|
+
* and on iOS it runs at 60 Hz. On a worklet runtime of your own
|
|
30
|
+
* (`createWorkletRuntime`), the global one polls every 16 ms (about 48 fps).
|
|
31
|
+
* This one follows the display wherever it is called:
|
|
32
|
+
*
|
|
33
|
+
* - On the React Native runtime, each frame of the display runs the callbacks
|
|
34
|
+
* requested before it, with the frame's time.
|
|
35
|
+
* - On a worklet runtime of your own, the runtime waits on its thread for the
|
|
36
|
+
* next frame of the display (the rest of the current frame at most), then
|
|
37
|
+
* runs them. Nothing else runs on the runtime during that wait.
|
|
38
|
+
* - On the Reanimated UI runtime, it is worklets' `requestAnimationFrame`,
|
|
39
|
+
* which is paced by the display already.
|
|
40
|
+
*
|
|
41
|
+
* Like a browser's, a callback requested while the frame's callbacks run gets
|
|
42
|
+
* the next frame, and every callback of a frame gets the same timestamp: the
|
|
43
|
+
* time the frame started, on the clock of `performance.now()`. The callbacks
|
|
44
|
+
* run once per frame of the display. A loop that overruns its frame runs
|
|
45
|
+
* again in the frame it overran into rather than waiting for the frame after.
|
|
46
|
+
* On the React Native runtime that run goes behind whatever waits there
|
|
47
|
+
* (React's updates, the app's other tasks), and the run after it waits for a
|
|
48
|
+
* frame of the display: the runtime is never the loop's alone.
|
|
49
|
+
*
|
|
50
|
+
* On the React Native runtime and on a worklet runtime of your own, no frame
|
|
51
|
+
* comes while the app is not in the foreground (the host activity is paused
|
|
52
|
+
* on Android, the app is not active on iOS): a loop stops with the app, and
|
|
53
|
+
* starts again when it is back.
|
|
54
|
+
*
|
|
55
|
+
* On iPhone, an app only gets more than 60 Hz with
|
|
56
|
+
* `CADisableMinimumFrameDurationOnPhone` set to true in its Info.plist. On
|
|
57
|
+
* macOS and on web, this is the runtime's own `requestAnimationFrame`.
|
|
58
|
+
*/
|
|
59
|
+
export const requestAnimationFrame = callback => {
|
|
60
|
+
"worklet";
|
|
61
|
+
|
|
62
|
+
if (frames === undefined) {
|
|
63
|
+
return globalThis.requestAnimationFrame(callback);
|
|
64
|
+
}
|
|
65
|
+
return frames.request(callback);
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Cancels a callback requested with this package's `requestAnimationFrame`,
|
|
70
|
+
* on the runtime it was requested on. Not interchangeable with the global
|
|
71
|
+
* `cancelAnimationFrame`: each cancels the handles of its own
|
|
72
|
+
* `requestAnimationFrame`.
|
|
73
|
+
*/
|
|
74
|
+
export const cancelAnimationFrame = handle => {
|
|
75
|
+
"worklet";
|
|
76
|
+
|
|
77
|
+
if (frames === undefined) {
|
|
78
|
+
globalThis.cancelAnimationFrame(handle);
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
frames.cancel(handle);
|
|
82
|
+
};
|
|
83
|
+
//# sourceMappingURL=animationFrame.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["frames","globalThis","__webgpuAnimationFrames","requestAnimationFrame","callback","undefined","request","cancelAnimationFrame","handle","cancel"],"sourceRoot":"../../src","sources":["animationFrame.ts"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA,MAAMA,MAAM,GAAGC,UAAU,CAACC,uBAAuB;;AAEjD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMC,qBAAqB,GAChCC,QAAqC,IAC1B;EACX,SAAS;;EACT,IAAIJ,MAAM,KAAKK,SAAS,EAAE;IACxB,OAAOJ,UAAU,CAACE,qBAAqB,CAACC,QAAQ,CAAC;EACnD;EACA,OAAOJ,MAAM,CAACM,OAAO,CAACF,QAAQ,CAAC;AACjC,CAAC;;AAED;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMG,oBAAoB,GAAIC,MAAc,IAAW;EAC5D,SAAS;;EACT,IAAIR,MAAM,KAAKK,SAAS,EAAE;IACxBJ,UAAU,CAACM,oBAAoB,CAACC,MAAM,CAAC;IACvC;EACF;EACAR,MAAM,CAACS,MAAM,CAACD,MAAM,CAAC;AACvB,CAAC","ignoreList":[]}
|
package/lib/module/index.js
CHANGED
package/lib/module/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["installWebGPU"],"sourceRoot":"../../src","sources":["index.tsx"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,sBAAsB;
|
|
1
|
+
{"version":3,"names":["installWebGPU","requestAnimationFrame","cancelAnimationFrame"],"sourceRoot":"../../src","sources":["index.tsx"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,sBAAsB;AAqB7B,cAAc,QAAQ;AACtB,cAAc,aAAa;AAC3B,SAASA,aAAa,QAAQ,WAAW;AACzC,SAASC,qBAAqB,EAAEC,oBAAoB,QAAQ,kBAAkB","ignoreList":[]}
|
package/lib/module/main/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["findNodeHandle","registerWebGPUForReanimated","resolveElementSource","source","instance","current","tag","undefined","Error","installDrawElementImageToTexture","GPUQueue","native","prototype","drawElementImageToTexture","destination","call","default","WebGPUModule","RNWebGPU","navigator","gpu","userAgent","global","createImageBitmap","bind"],"sourceRoot":"../../../src","sources":["main/index.tsx"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA,OAAO,iBAAiB;AAExB,SAASA,cAAc,QAAQ,cAAc;AAE7C,SAASC,2BAA2B,QAAQ,aAAa;AAGzD;AACA;AACA;AACA;AACA,MAAMC,oBAAoB,GAAIC,MAAqC,IAAK;EACtE,IAAI,O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IACd;IACAA,SAAS,GAAG;MACVC,GAAG,EAAEF,QAAQ,CAACE,GAAG;MACjBC,SAAS,EAAE;IACb,CAAC;EACH,CAAC,MAAM;IACLF,SAAS,CAACC,GAAG,GAAGF,QAAQ,CAACE,GAAG;IAC5B,IAAI,OAAOD,SAAS,CAACE,SAAS,KAAK,QAAQ,EAAE;MAC3C,IAAI;QACF;QACA;QACAF,SAAS,CAACE,SAAS,GAAG,cAAc;MACtC,CAAC,CAAC,MAAM;QACN;MAAA;IAEJ;EACF;EACAC,MAAM,CAACC,iBAAiB,GACtBD,MAAM,CAACC,iBAAiB,IAAIL,QAAQ,CAACK,iBAAiB,CAACC,IAAI,CAACN,QAAQ,CAAC;EACvET,gCAAgC,CAAC,CAAC;AACpC","ignoreList":[]}
|
|
1
|
+
{"version":3,"names":["findNodeHandle","registerWebGPUForReanimated","resolveElementSource","source","instance","current","tag","undefined","Error","installDrawElementImageToTexture","GPUQueue","native","prototype","drawElementImageToTexture","destination","call","default","WebGPUModule","RNWebGPU","navigator","gpu","userAgent","global","createImageBitmap","bind"],"sourceRoot":"../../../src","sources":["main/index.tsx"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA,OAAO,iBAAiB;AAExB,SAASA,cAAc,QAAQ,cAAc;AAE7C,SAASC,2BAA2B,QAAQ,aAAa;AAGzD;AACA;AACA;AACA;AACA,MAAMC,oBAAoB,GAAIC,MAAqC,IAAK;EACtE,IAAI,OAAOA,MAAM,KAAK,QAAQ,EAAE;IAC9B,OAAOA,MAAM;EACf;EACA,MAAMC,QAAQ,GACZD,MAAM,KAAK,IAAI,IAAI,OAAOA,MAAM,KAAK,QAAQ,IAAI,SAAS,IAAIA,MAAM,GAChEA,MAAM,CAACE,OAAO,GACdF,MAAM;EACZ;EACA,MAAMG,GAAG,GAAGF,QAAQ,IAAI,IAAI,GAAG,IAAI,GAAGJ,cAAc,CAACI,QAAe,CAAC;EACrE,IAAIE,GAAG,KAAK,IAAI,IAAIA,GAAG,KAAKC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F;EACAC,MAAM,CAACC,iBAAiB,GACtBD,MAAM,CAACC,iBAAiB,IAAIL,QAAQ,CAACK,iBAAiB,CAACC,IAAI,CAACN,QAAQ,CAAC;EACvET,gCAAgC,CAAC,CAAC;AACpC","ignoreList":[]}
|
package/lib/module/mock.js
CHANGED
|
@@ -84,6 +84,25 @@ export const Canvas = ({
|
|
|
84
84
|
}));
|
|
85
85
|
return /*#__PURE__*/React.createElement(View, props);
|
|
86
86
|
};
|
|
87
|
+
// Renders as a plain View; present() fails like the other GPU entry points.
|
|
88
|
+
export const NativeBufferView = ({
|
|
89
|
+
resizeMode: _resizeMode,
|
|
90
|
+
onPixelSizeChange: _onPixelSizeChange,
|
|
91
|
+
ref,
|
|
92
|
+
...props
|
|
93
|
+
}) => {
|
|
94
|
+
React.useImperativeHandle(ref, () => ({
|
|
95
|
+
viewId: -1,
|
|
96
|
+
present: () => {
|
|
97
|
+
throw new Error(`NativeBufferView.present() ${NOT_AVAILABLE_UNDER_JEST}`);
|
|
98
|
+
}
|
|
99
|
+
}));
|
|
100
|
+
return /*#__PURE__*/React.createElement(View, props);
|
|
101
|
+
};
|
|
102
|
+
export const useNativeBufferSize = _debounceMs => ({
|
|
103
|
+
size: null,
|
|
104
|
+
onPixelSizeChange: () => undefined
|
|
105
|
+
});
|
|
87
106
|
export const useCanvasRef = () => React.useRef(null);
|
|
88
107
|
export const useSurface = () => ({
|
|
89
108
|
ref: React.useRef(null),
|
|
@@ -107,6 +126,8 @@ export const adoptTexture = _pointer => {
|
|
|
107
126
|
throw new Error(`adoptTexture() ${NOT_AVAILABLE_UNDER_JEST}`);
|
|
108
127
|
};
|
|
109
128
|
export const installWebGPU = () => undefined;
|
|
129
|
+
export const requestAnimationFrame = callback => globalThis.requestAnimationFrame(callback);
|
|
130
|
+
export const cancelAnimationFrame = handle => globalThis.cancelAnimationFrame(handle);
|
|
110
131
|
export const WebGPUModule = {
|
|
111
132
|
install: () => false
|
|
112
133
|
};
|
package/lib/module/mock.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["React","View","GPUBufferUsage","MAP_READ","MAP_WRITE","COPY_SRC","COPY_DST","INDEX","VERTEX","UNIFORM","STORAGE","INDIRECT","QUERY_RESOLVE","GPUTextureUsage","TEXTURE_BINDING","STORAGE_BINDING","RENDER_ATTACHMENT","TRANSIENT_ATTACHMENT","GPUShaderStage","FRAGMENT","COMPUTE","GPUColorWrite","RED","GREEN","BLUE","ALPHA","ALL","GPUMapMode","READ","WRITE","g","globalThis","key","value","Object","entries","undefined","NOT_AVAILABLE_UNDER_JEST","Canvas","android","_android","ref","props","useImperativeHandle","getContextId","getContext","_contextName","getNativeSurface","Error","createElement","useCanvasRef","useRef","useSurface","surface","warnIfNotHardwareAccelerated","useDevice","adapter","device","GPUDeviceProvider","children","useMainDevice","importDevice","_pointer","adoptTexture","installWebGPU","WebGPUModule","install"],"sourceRoot":"../../src","sources":["mock.ts"],"mappings":"AAAA;AACA,OAAOA,KAAK,MAAM,OAAO;AAEzB,SAASC,IAAI,QAAQ,cAAc;
|
|
1
|
+
{"version":3,"names":["React","View","GPUBufferUsage","MAP_READ","MAP_WRITE","COPY_SRC","COPY_DST","INDEX","VERTEX","UNIFORM","STORAGE","INDIRECT","QUERY_RESOLVE","GPUTextureUsage","TEXTURE_BINDING","STORAGE_BINDING","RENDER_ATTACHMENT","TRANSIENT_ATTACHMENT","GPUShaderStage","FRAGMENT","COMPUTE","GPUColorWrite","RED","GREEN","BLUE","ALPHA","ALL","GPUMapMode","READ","WRITE","g","globalThis","key","value","Object","entries","undefined","NOT_AVAILABLE_UNDER_JEST","Canvas","android","_android","ref","props","useImperativeHandle","getContextId","getContext","_contextName","getNativeSurface","Error","createElement","NativeBufferView","resizeMode","_resizeMode","onPixelSizeChange","_onPixelSizeChange","viewId","present","useNativeBufferSize","_debounceMs","size","useCanvasRef","useRef","useSurface","surface","warnIfNotHardwareAccelerated","useDevice","adapter","device","GPUDeviceProvider","children","useMainDevice","importDevice","_pointer","adoptTexture","installWebGPU","requestAnimationFrame","callback","cancelAnimationFrame","handle","WebGPUModule","install"],"sourceRoot":"../../src","sources":["mock.ts"],"mappings":"AAAA;AACA,OAAOA,KAAK,MAAM,OAAO;AAEzB,SAASC,IAAI,QAAQ,cAAc;AAKnC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,cAAc,WAAW;;AAEzB;AACA;AACA;AACA;AACA,OAAO,MAAMC,cAA8B,GAAG;EAC5CC,QAAQ,EAAE,MAAM;EAChBC,SAAS,EAAE,MAAM;EACjBC,QAAQ,EAAE,MAAM;EAChBC,QAAQ,EAAE,MAAM;EAChBC,KAAK,EAAE,MAAM;EACbC,MAAM,EAAE,MAAM;EACdC,OAAO,EAAE,MAAM;EACfC,OAAO,EAAE,MAAM;EACfC,QAAQ,EAAE,MAAM;EAChBC,aAAa,EAAE;AACjB,CAAC;AAED,OAAO,MAAMC,eAAgC,GAAG;EAC9CR,QAAQ,EAAE,IAAI;EACdC,QAAQ,EAAE,IAAI;EACdQ,eAAe,EAAE,IAAI;EACrBC,eAAe,EAAE,IAAI;EACrBC,iBAAiB,EAAE,IAAI;EACvBC,oBAAoB,EAAE;AACxB,CAAC;AAED,OAAO,MAAMC,cAA8B,GAAG;EAC5CV,MAAM,EAAE,GAAG;EACXW,QAAQ,EAAE,GAAG;EACbC,OAAO,EAAE;AACX,CAAC;AAED,OAAO,MAAMC,aAA4B,GAAG;EAC1CC,GAAG,EAAE,GAAG;EACRC,KAAK,EAAE,GAAG;EACVC,IAAI,EAAE,GAAG;EACTC,KAAK,EAAE,GAAG;EACVC,GAAG,EAAE;AACP,CAAC;AAED,OAAO,MAAMC,UAAsB,GAAG;EACpCC,IAAI,EAAE,GAAG;EACTC,KAAK,EAAE;AACT,CAAC;AAED;EACE,MAAMC,CAAC,GAAGC,UAAgD;EAC1D,KAAK,MAAM,CAACC,GAAG,EAAEC,KAAK,CAAC,IAAIC,MAAM,CAACC,OAAO,CAA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
|
@@ -35,10 +35,10 @@ export const createVideoPlayer = (source, options) => native("createVideoPlayer"
|
|
|
35
35
|
/**
|
|
36
36
|
* Wraps a native buffer produced by another library (a `CVPixelBufferRef` on
|
|
37
37
|
* Apple platforms, an `AHardwareBuffer*` on Android, for instance
|
|
38
|
-
* VisionCamera's `frame.getNativeBuffer().pointer`) into a `
|
|
38
|
+
* VisionCamera's `frame.getNativeBuffer().pointer`) into a `NativeBuffer`
|
|
39
39
|
* that keeps it alive until released.
|
|
40
40
|
*/
|
|
41
|
-
export const
|
|
41
|
+
export const createNativeBufferFromPointer = pointer => native("createNativeBufferFromPointer").createNativeBufferFromPointer(pointer);
|
|
42
42
|
|
|
43
43
|
/**
|
|
44
44
|
* Allocates a native frame of the given size filled with a test pattern (a
|
|
@@ -46,4 +46,13 @@ export const createVideoFrameFromNativeBuffer = pointer => native("createVideoFr
|
|
|
46
46
|
* and tests that need a frame without a camera or a video.
|
|
47
47
|
*/
|
|
48
48
|
export const createTestVideoFrame = (width, height) => native("createTestVideoFrame").createTestVideoFrame(width, height);
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Allocates an empty native buffer (an `AHardwareBuffer` on Android, an
|
|
52
|
+
* `IOSurface` on Apple platforms) that the GPU renders into and a
|
|
53
|
+
* `NativeBufferView` displays: import it with
|
|
54
|
+
* `device.importSharedTextureMemory({ source: frame })`, render into
|
|
55
|
+
* `memory.createTexture()` inside an access, then present it.
|
|
56
|
+
*/
|
|
57
|
+
export const createNativeBuffer = (width, height, options) => native("createNativeBuffer").createNativeBuffer(width, height, options);
|
|
49
58
|
//# sourceMappingURL=video.js.map
|
package/lib/module/video.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["native","name","RNWebGPU","Error","createVideoPlayer","source","options","pixelFormat","
|
|
1
|
+
{"version":3,"names":["native","name","RNWebGPU","Error","createVideoPlayer","source","options","pixelFormat","createNativeBufferFromPointer","pointer","createTestVideoFrame","width","height","createNativeBuffer"],"sourceRoot":"../../src","sources":["video.ts"],"mappings":"AAOA,MAAMA,MAAM,GAAIC,IAAY,IAAK;EAC/B,IAAI,OAAOC,QAAQ,KAAK,WAAW,EAAE;IACnC,MAAM,IAAIC,KAAK,CACb,kDAAkDF,IAAI,iBACxD,CAAC;EACH;EACA,OAAOC,QAAQ;AACjB,CAAC;;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAME,iBAAiB,GAAGA,CAC/BC,MAAc,EACdC,OAAkC,KAElCN,MAAM,CAAC,mBAAmB,CAAC,CAACI,iBAAiB,CAACC,MAAM,EAAEC,OAAO,EAAEC,WAAW,CAAC;;AAE7E;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMC,6BAA6B,GAAIC,OAAe,IAC3DT,MAAM,CAAC,+BAA+B,CAAC,CAACQ,6BAA6B,CACnEC,OACF,CAAC;;AAEH;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMC,oBAAoB,GAAGA,CAClCC,KAAa,EACbC,MAAc,KAEdZ,MAAM,CAAC,sBAAsB,CAAC,CAACU,oBAAoB,CAACC,KAAK,EAAEC,MAAM,CAAC;;AAEpE;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMC,kBAAkB,GAAGA,CAChCF,KAAa,EACbC,MAAc,EACdN,OAAmC,KAEnCN,MAAM,CAAC,oBAAoB,CAAC,CAACa,kBAAkB,CAACF,KAAK,EAAEC,MAAM,EAAEN,OAAO,CAAC","ignoreList":[]}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
export const __esModule: boolean;
|
|
2
|
+
/**
|
|
3
|
+
* How a {@link NativeBufferView} fits a buffer whose size differs from its
|
|
4
|
+
* own (in physical pixels), for instance while the producer catches up with
|
|
5
|
+
* a resize. A buffer of exactly the view's size is shown 1:1 in every mode.
|
|
6
|
+
*
|
|
7
|
+
* - `stretch` (the default): scaled to the bounds, ignoring the aspect ratio.
|
|
8
|
+
* - `contain`: scaled to fit inside the bounds, keeping the aspect ratio.
|
|
9
|
+
* - `cover`: scaled to fill the bounds, keeping the aspect ratio; the excess
|
|
10
|
+
* is cropped.
|
|
11
|
+
* - `topLeft`: not scaled; anchored at the top left corner and cropped.
|
|
12
|
+
*/
|
|
13
|
+
/** A size in physical pixels. */
|
|
14
|
+
/**
|
|
15
|
+
* Displays a native buffer (an `AHardwareBuffer` on Android, an `IOSurface`
|
|
16
|
+
* on Apple platforms) with no swap chain, no canvas context and no GPU device
|
|
17
|
+
* on the display side. Meant for content that is static or updated
|
|
18
|
+
* occasionally; animated content belongs in a `Canvas`.
|
|
19
|
+
*
|
|
20
|
+
* The view never allocates buffers. It reports its size in physical pixels
|
|
21
|
+
* ({@link NativeBufferViewProps.onPixelSizeChange}), and any producer
|
|
22
|
+
* (WebGPU, Skia, a camera, a decoder) renders into a buffer and presents it
|
|
23
|
+
* through the ref (frames from a camera or a decoder are copied first, see
|
|
24
|
+
* {@link NativeBufferViewRef.present}). With WebGPU:
|
|
25
|
+
*
|
|
26
|
+
* ```ts
|
|
27
|
+
* const frame = createNativeBuffer(size.width, size.height);
|
|
28
|
+
* const memory = device.importSharedTextureMemory({ source: frame });
|
|
29
|
+
* const texture = memory.createTexture();
|
|
30
|
+
* memory.beginAccess(texture, false);
|
|
31
|
+
* // ... render into texture and submit ...
|
|
32
|
+
* ref.current.present(frame, memory.endAccess(texture));
|
|
33
|
+
* texture.destroy();
|
|
34
|
+
* memory.destroy();
|
|
35
|
+
* frame.release();
|
|
36
|
+
* ```
|
|
37
|
+
*/
|
|
38
|
+
export function NativeBufferView({ resizeMode, onPixelSizeChange, ref, ...props }: {
|
|
39
|
+
[x: string]: any;
|
|
40
|
+
resizeMode: any;
|
|
41
|
+
onPixelSizeChange: any;
|
|
42
|
+
ref: any;
|
|
43
|
+
}): any;
|
|
44
|
+
export function useNativeBufferSize(debounceMs?: number): {
|
|
45
|
+
size: any;
|
|
46
|
+
onPixelSizeChange: any;
|
|
47
|
+
};
|
|
48
|
+
//# sourceMappingURL=NativeBufferView.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"NativeBufferView.d.ts","sourceRoot":"","sources":["../../../commonjs/NativeBufferView.js"],"names":[],"mappings":";AAWA;;;;;;;;;;GAUG;AAEH,iCAAiC;AAEjC;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH;;;;;QAqCC;AAUD;;;EAgCC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"NativeBufferViewNativeComponent.d.ts","sourceRoot":"","sources":["../../../commonjs/NativeBufferViewNativeComponent.js"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
export const __esModule: boolean;
|
|
2
|
+
/**
|
|
3
|
+
* `requestAnimationFrame`, paced by the display, on any runtime.
|
|
4
|
+
*
|
|
5
|
+
* Drop-in for the global one in a render loop:
|
|
6
|
+
*
|
|
7
|
+
* ```ts
|
|
8
|
+
* import { requestAnimationFrame } from "react-native-webgpu";
|
|
9
|
+
*
|
|
10
|
+
* const render = (timestamp: number) => {
|
|
11
|
+
* draw(timestamp);
|
|
12
|
+
* context.present();
|
|
13
|
+
* requestAnimationFrame(render);
|
|
14
|
+
* };
|
|
15
|
+
* requestAnimationFrame(render);
|
|
16
|
+
* ```
|
|
17
|
+
*
|
|
18
|
+
* React Native's global `requestAnimationFrame` is a timer: on Android it
|
|
19
|
+
* makes the next frame of the display only when it is requested before that
|
|
20
|
+
* frame starts, which leaves a loop that requests its next frame at the end
|
|
21
|
+
* of its work about 6 ms of a 120 Hz frame (past that, it drops to 60 fps),
|
|
22
|
+
* and on iOS it runs at 60 Hz. On a worklet runtime of your own
|
|
23
|
+
* (`createWorkletRuntime`), the global one polls every 16 ms (about 48 fps).
|
|
24
|
+
* This one follows the display wherever it is called:
|
|
25
|
+
*
|
|
26
|
+
* - On the React Native runtime, each frame of the display runs the callbacks
|
|
27
|
+
* requested before it, with the frame's time.
|
|
28
|
+
* - On a worklet runtime of your own, the runtime waits on its thread for the
|
|
29
|
+
* next frame of the display (the rest of the current frame at most), then
|
|
30
|
+
* runs them. Nothing else runs on the runtime during that wait.
|
|
31
|
+
* - On the Reanimated UI runtime, it is worklets' `requestAnimationFrame`,
|
|
32
|
+
* which is paced by the display already.
|
|
33
|
+
*
|
|
34
|
+
* Like a browser's, a callback requested while the frame's callbacks run gets
|
|
35
|
+
* the next frame, and every callback of a frame gets the same timestamp: the
|
|
36
|
+
* time the frame started, on the clock of `performance.now()`. The callbacks
|
|
37
|
+
* run once per frame of the display. A loop that overruns its frame runs
|
|
38
|
+
* again in the frame it overran into rather than waiting for the frame after.
|
|
39
|
+
* On the React Native runtime that run goes behind whatever waits there
|
|
40
|
+
* (React's updates, the app's other tasks), and the run after it waits for a
|
|
41
|
+
* frame of the display: the runtime is never the loop's alone.
|
|
42
|
+
*
|
|
43
|
+
* On the React Native runtime and on a worklet runtime of your own, no frame
|
|
44
|
+
* comes while the app is not in the foreground (the host activity is paused
|
|
45
|
+
* on Android, the app is not active on iOS): a loop stops with the app, and
|
|
46
|
+
* starts again when it is back.
|
|
47
|
+
*
|
|
48
|
+
* On iPhone, an app only gets more than 60 Hz with
|
|
49
|
+
* `CADisableMinimumFrameDurationOnPhone` set to true in its Info.plist. On
|
|
50
|
+
* macOS and on web, this is the runtime's own `requestAnimationFrame`.
|
|
51
|
+
*/
|
|
52
|
+
export function requestAnimationFrame(callback: any): number;
|
|
53
|
+
export function cancelAnimationFrame(handle: any): void;
|
|
54
|
+
//# sourceMappingURL=animationFrame.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"animationFrame.d.ts","sourceRoot":"","sources":["../../../commonjs/animationFrame.js"],"names":[],"mappings":";AAcA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiDG;AACH,6DAOC;AASD,wDAQC"}
|
|
@@ -46,6 +46,16 @@ export function Canvas({ android: _android, ref, ...props }: {
|
|
|
46
46
|
android: any;
|
|
47
47
|
ref: any;
|
|
48
48
|
}): any;
|
|
49
|
+
export function NativeBufferView({ resizeMode: _resizeMode, onPixelSizeChange: _onPixelSizeChange, ref, ...props }: {
|
|
50
|
+
[x: string]: any;
|
|
51
|
+
resizeMode: any;
|
|
52
|
+
onPixelSizeChange: any;
|
|
53
|
+
ref: any;
|
|
54
|
+
}): any;
|
|
55
|
+
export function useNativeBufferSize(_debounceMs: any): {
|
|
56
|
+
size: null;
|
|
57
|
+
onPixelSizeChange: () => undefined;
|
|
58
|
+
};
|
|
49
59
|
export function useCanvasRef(): any;
|
|
50
60
|
export function useSurface(): {
|
|
51
61
|
ref: any;
|
|
@@ -63,4 +73,6 @@ export function useMainDevice(): never;
|
|
|
63
73
|
export function importDevice(_pointer: any): never;
|
|
64
74
|
export function adoptTexture(_pointer: any): never;
|
|
65
75
|
export function installWebGPU(): undefined;
|
|
76
|
+
export function requestAnimationFrame(callback: any): number;
|
|
77
|
+
export function cancelAnimationFrame(handle: any): void;
|
|
66
78
|
//# sourceMappingURL=mock.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mock.d.ts","sourceRoot":"","sources":["../../../commonjs/mock.js"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"mock.d.ts","sourceRoot":"","sources":["../../../commonjs/mock.js"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IAyLW,4BAAW;;AAzEtB;;;;QAaC;AAGD;;;;;QAaC;AAED;;;EAGE;AAEF,oCAAsD;AAEtD;;;EAGE;AAEF,0DAAoD;AAEpD;;;EAGE;AAEF;;QAEsB;AAEtB,uCAEC;AAED,mDAEC;AAED,mDAEC;AAED,2CAAqC;AAErC,6DAAoF;AAEpF,wDAA8E"}
|
|
@@ -25,6 +25,7 @@ export const __esModule: boolean;
|
|
|
25
25
|
* native YUV layout, for `importExternalTexture()`.
|
|
26
26
|
*/
|
|
27
27
|
export function createVideoPlayer(source: any, options: any): import("../../src").VideoPlayer;
|
|
28
|
-
export function
|
|
29
|
-
export function createTestVideoFrame(width: any, height: any): import("../../src").
|
|
28
|
+
export function createNativeBufferFromPointer(pointer: any): import("../../src").NativeBuffer;
|
|
29
|
+
export function createTestVideoFrame(width: any, height: any): import("../../src").NativeBuffer;
|
|
30
|
+
export function createNativeBuffer(width: any, height: any, options: any): import("../../src").NativeBuffer;
|
|
30
31
|
//# sourceMappingURL=video.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"video.d.ts","sourceRoot":"","sources":["../../../commonjs/video.js"],"names":[],"mappings":";AAaA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,8FAA0H;AAS1H,
|
|
1
|
+
{"version":3,"file":"video.d.ts","sourceRoot":"","sources":["../../../commonjs/video.js"],"names":[],"mappings":";AAaA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,8FAA0H;AAS1H,8FAA+H;AAQ/H,gGAAkH;AAUlH,4GAA8H"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export function NativeBufferView({ resizeMode, onPixelSizeChange, ref, ...props }: {
|
|
2
|
+
[x: string]: any;
|
|
3
|
+
resizeMode: any;
|
|
4
|
+
onPixelSizeChange: any;
|
|
5
|
+
ref: any;
|
|
6
|
+
}): React.FunctionComponentElement<Omit<{}, "ref"> & {
|
|
7
|
+
ref?: React.Ref<import("react-native").HostInstance> | undefined;
|
|
8
|
+
}>;
|
|
9
|
+
export function useNativeBufferSize(debounceMs?: number): {
|
|
10
|
+
size: null;
|
|
11
|
+
onPixelSizeChange: (next: any) => void;
|
|
12
|
+
};
|
|
13
|
+
import React from "react";
|
|
14
|
+
//# sourceMappingURL=NativeBufferView.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"NativeBufferView.d.ts","sourceRoot":"","sources":["../../../module/NativeBufferView.js"],"names":[],"mappings":"AA0CO;;;;;;;GAqCN;AASM;;;EAgCN;kBAvHqG,OAAO"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"NativeBufferViewNativeComponent.d.ts","sourceRoot":"","sources":["../../../module/NativeBufferViewNativeComponent.js"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"animationFrame.d.ts","sourceRoot":"","sources":["../../../module/animationFrame.js"],"names":[],"mappings":"AA0DO,6DAON;AAQM,wDAQN"}
|
|
@@ -45,6 +45,18 @@ export function Canvas({ android: _android, ref, ...props }: {
|
|
|
45
45
|
}): React.FunctionComponentElement<Omit<import("react-native").ViewProps, "ref"> & {
|
|
46
46
|
ref?: React.Ref<import("react-native").ViewInstance> | undefined;
|
|
47
47
|
}>;
|
|
48
|
+
export function NativeBufferView({ resizeMode: _resizeMode, onPixelSizeChange: _onPixelSizeChange, ref, ...props }: {
|
|
49
|
+
[x: string]: any;
|
|
50
|
+
resizeMode: any;
|
|
51
|
+
onPixelSizeChange: any;
|
|
52
|
+
ref: any;
|
|
53
|
+
}): React.FunctionComponentElement<Omit<import("react-native").ViewProps, "ref"> & {
|
|
54
|
+
ref?: React.Ref<import("react-native").ViewInstance> | undefined;
|
|
55
|
+
}>;
|
|
56
|
+
export function useNativeBufferSize(_debounceMs: any): {
|
|
57
|
+
size: null;
|
|
58
|
+
onPixelSizeChange: () => undefined;
|
|
59
|
+
};
|
|
48
60
|
export function useCanvasRef(): React.RefObject<null>;
|
|
49
61
|
export function useSurface(): {
|
|
50
62
|
ref: React.RefObject<null>;
|
|
@@ -62,6 +74,8 @@ export function useMainDevice(): never;
|
|
|
62
74
|
export function importDevice(_pointer: any): never;
|
|
63
75
|
export function adoptTexture(_pointer: any): never;
|
|
64
76
|
export function installWebGPU(): undefined;
|
|
77
|
+
export function requestAnimationFrame(callback: any): number;
|
|
78
|
+
export function cancelAnimationFrame(handle: any): void;
|
|
65
79
|
export namespace WebGPUModule {
|
|
66
80
|
function install(): boolean;
|
|
67
81
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mock.d.ts","sourceRoot":"","sources":["../../../module/mock.js"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAwEO;;;;;;GAaN;AACM,sDAA6C;AAC7C;;;EAGL;AACK,0DAAoD;AACpD;;;EAGL;AACK;;QAEe;AACf,uCAEN;AACM,mDAEN;AACM,mDAEN;AACM,2CAAqC;;
|
|
1
|
+
{"version":3,"file":"mock.d.ts","sourceRoot":"","sources":["../../../module/mock.js"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAwEO;;;;;;GAaN;AAEM;;;;;;;GAaN;AACM;;;EAGL;AACK,sDAA6C;AAC7C;;;EAGL;AACK,0DAAoD;AACpD;;;EAGL;AACK;;QAEe;AACf,uCAEN;AACM,mDAEN;AACM,mDAEN;AACM,2CAAqC;AACrC,6DAAoF;AACpF,wDAA8E;;IAE1E,4BAAW;;kBAlIJ,OAAO"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export function createVideoPlayer(source: any, options: any): import("../../src").VideoPlayer;
|
|
2
|
-
export function
|
|
3
|
-
export function createTestVideoFrame(width: any, height: any): import("../../src").
|
|
2
|
+
export function createNativeBufferFromPointer(pointer: any): import("../../src").NativeBuffer;
|
|
3
|
+
export function createTestVideoFrame(width: any, height: any): import("../../src").NativeBuffer;
|
|
4
|
+
export function createNativeBuffer(width: any, height: any, options: any): import("../../src").NativeBuffer;
|
|
4
5
|
//# sourceMappingURL=video.d.ts.map
|