Skip to content

Commit 2c988e4

Browse files
committed
chore: Update WebGPU example code
1 parent 48da41b commit 2c988e4

2 files changed

Lines changed: 10 additions & 9 deletions

File tree

packages/react-native-vision-camera/src/specs/common-types/NativeBuffer.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,10 @@ import type { UInt64 } from 'react-native-nitro-modules'
66
* This is a shared contract between libraries to interact
77
* with native buffers without natively typed bindings.
88
*
9-
* Consumers, like react-native-skia or react-native-wgpu
10-
* can accept a `NativeBuffer`-shaped object that has a
11-
* {@linkcode pointer} and a {@linkcode release} function
12-
* to unwrap the native buffer from it, load it as a GPU
13-
* Texture, and release it once it has been rendered.
9+
* Consumers, like react-native-skia or react-native-wgpu,
10+
* can use the {@linkcode pointer} to unwrap the native buffer,
11+
* load it as a GPU Texture, and release it once it has been
12+
* rendered via the {@linkcode release} function.
1413
*
1514
* @example
1615
* ```ts

packages/react-native-vision-camera/src/specs/instances/Frame.nitro.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -362,12 +362,14 @@ export interface Frame
362362
* const device = ... // WebGPU device
363363
* if (frame.hasNativeBuffer) {
364364
* const nativeBuffer = frame.getNativeBuffer()
365-
* const image = device.importExternalTexture({
366-
* source: nativeBuffer,
365+
* const videoFrame = RNWebGPU.createVideoFrameFromNativeBuffer(nativeBuffer.pointer)
366+
* const externalTexture = device.importExternalTexture({
367+
* source: videoFrame,
367368
* label: 'camera-frame'
368369
* })
369-
* // Render `image` via Skia APIs
370-
* image.dispose()
370+
* // After submitting commands that sample `externalTexture`:
371+
* externalTexture.destroy()
372+
* videoFrame.release()
371373
* nativeBuffer.release()
372374
* }
373375
* ```

0 commit comments

Comments
 (0)