// // SharedArray.mm // VisionCamera // // Created by Marc Rousavy on 12.01.24. // Copyright © 2024 mrousavy. All rights reserved. // #import "SharedArray.h" #import "JSITypedArray.h" #import #import using namespace facebook; @implementation SharedArray { uint8_t* _data; NSInteger _count; std::shared_ptr _array; } vision::TypedArrayKind getTypedArrayKind(int unsafeEnumValue) { return static_cast(unsafeEnumValue); } - (instancetype)initWithProxy:(VisionCameraProxyHolder*)proxy type:(SharedArrayType)type size:(NSInteger)size { if (self = [super init]) { jsi::Runtime& runtime = proxy.proxy->getWorkletRuntime(); vision::TypedArrayKind kind = getTypedArrayKind((int)type); _array = std::make_shared(vision::TypedArrayBase(runtime, size, kind)); _data = _array->getBuffer(runtime).data(runtime); _count = size; } return self; } - (instancetype)initWithRuntime:(jsi::Runtime&)runtime typedArray:(std::shared_ptr)typedArray { if (self = [super init]) { _array = typedArray; _data = _array->getBuffer(runtime).data(runtime); _count = _array->getBuffer(runtime).size(runtime); } return self; } - (std::shared_ptr)typedArray { return _array; } - (uint8_t*)data { return _data; } - (NSInteger)count { return _count; } @end