From 2415e1feaa1a75f0e1318c1fea348ba0d31b850e Mon Sep 17 00:00:00 2001 From: Marc Rousavy Date: Tue, 7 May 2024 16:27:25 +0200 Subject: [PATCH] fix: Make `withBaseClass` private, and `getNativeBuffer` public (#2852) --- package/src/skia/useSkiaFrameProcessor.ts | 2 +- package/src/types/Frame.ts | 44 ++++++++++++----------- 2 files changed, 24 insertions(+), 22 deletions(-) diff --git a/package/src/skia/useSkiaFrameProcessor.ts b/package/src/skia/useSkiaFrameProcessor.ts index ecadcdf922..30efc014ca 100644 --- a/package/src/skia/useSkiaFrameProcessor.ts +++ b/package/src/skia/useSkiaFrameProcessor.ts @@ -187,7 +187,7 @@ export function createSkiaFrameProcessor( }, }) - return frame.withBaseClass(canvasProxy) + return (frame as FrameInternal).withBaseClass(canvasProxy) } return { diff --git a/package/src/types/Frame.ts b/package/src/types/Frame.ts index 11026c8a42..f558c51bf3 100644 --- a/package/src/types/Frame.ts +++ b/package/src/types/Frame.ts @@ -86,29 +86,22 @@ export interface Frame { */ toString(): string /** - * Assign a new base instance to this Frame, and have all properties and methods of - * {@linkcode baseInstance} also be a part of this Frame. + * Get the native platform buffer of the Frame. + * - On Android, this is a `AHardwareBuffer*` + * - On iOS, this is a `CVPixelBufferRef` * - * This is useful if you need to pass this {@linkcode Frame} to another consumer - * (e.g. a native Frame Processor Plugin) and still need it to be a `jsi::HostObject` of - * type `FrameHostObject` while containing properties of another instance ({@linkcode baseInstance}) - * @param baseInstance The base instance to use. - * @internal - * @example ```ts - * const canvas = skSurface.getCanvas() - * const drawableFrame = frame.withBaseClass(canvas) - * // now `drawableFrame` has all methods from `canvas`, as well as `frame`. - * // it's actual type is still `FrameHostObject`, no `Proxy`, no `Object`, no `Canvas`. - * drawableFrame.drawRect(...) - * ``` + * The native buffer needs to be manually deleted using + * {@linkcode NativeBuffer.delete()}, and this {@linkcode Frame} + * needs to be kept alive as long as-, or longer than + * the {@linkcode NativeBuffer}. */ - withBaseClass(baseInstance: T): T & Frame + getNativeBuffer(): NativeBuffer } /** * A managed memory pointer to a native platform buffer */ -interface NativeBuffer { +export interface NativeBuffer { /** * A uint64_t/uintptr_t to the native platform buffer. * - On iOS; this points to a `CVPixelBufferRef` @@ -141,12 +134,21 @@ export interface FrameInternal extends Frame { */ decrementRefCount(): void /** - * Get the native platform buffer of the Frame. - * - On Android, this is a `AHardwareBuffer*` - * - On iOS, this is a `CVPixelBufferRef` + * Assign a new base instance to this Frame, and have all properties and methods of + * {@linkcode baseInstance} also be a part of this Frame. * - * This is a private API, do not use this. + * This is useful if you need to pass this {@linkcode Frame} to another consumer + * (e.g. a native Frame Processor Plugin) and still need it to be a `jsi::HostObject` of + * type `FrameHostObject` while containing properties of another instance ({@linkcode baseInstance}) + * @param baseInstance The base instance to use. * @internal + * @example ```ts + * const canvas = skSurface.getCanvas() + * const drawableFrame = frame.withBaseClass(canvas) + * // now `drawableFrame` has all methods from `canvas`, as well as `frame`. + * // it's actual type is still `FrameHostObject`, no `Proxy`, no `Object`, no `Canvas`. + * drawableFrame.drawRect(...) + * ``` */ - getNativeBuffer(): NativeBuffer + withBaseClass(baseInstance: T): T & Frame }