| 
									
										
										
										
											2023-07-20 15:30:04 +02:00
										 |  |  | // | 
					
						
							|  |  |  | //  FrameProcessor.mm | 
					
						
							|  |  |  | //  VisionCamera | 
					
						
							|  |  |  | // | 
					
						
							|  |  |  | //  Created by Marc Rousavy on 13.07.23. | 
					
						
							|  |  |  | //  Copyright © 2023 mrousavy. All rights reserved. | 
					
						
							|  |  |  | // | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #import "FrameProcessor.h" | 
					
						
							| 
									
										
										
										
											2023-09-01 12:58:32 +02:00
										 |  |  | #import <Foundation/Foundation.h> | 
					
						
							| 
									
										
										
										
											2023-07-20 15:30:04 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | #import "FrameHostObject.h" | 
					
						
							| 
									
										
										
										
											2023-09-01 12:58:32 +02:00
										 |  |  | #import "WKTJsiWorklet.h" | 
					
						
							|  |  |  | #import <jsi/jsi.h> | 
					
						
							|  |  |  | #import <memory> | 
					
						
							| 
									
										
										
										
											2023-07-20 15:30:04 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | using namespace facebook; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | @implementation FrameProcessor { | 
					
						
							|  |  |  |   std::shared_ptr<RNWorklet::JsiWorkletContext> _workletContext; | 
					
						
							|  |  |  |   std::shared_ptr<RNWorklet::WorkletInvoker> _workletInvoker; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-07-21 17:52:30 +02:00
										 |  |  | - (instancetype)initWithWorklet:(std::shared_ptr<RNWorklet::JsiWorklet>)worklet | 
					
						
							|  |  |  |                         context:(std::shared_ptr<RNWorklet::JsiWorkletContext>)context { | 
					
						
							| 
									
										
										
										
											2023-07-20 15:30:04 +02:00
										 |  |  |   if (self = [super init]) { | 
					
						
							|  |  |  |     _workletInvoker = std::make_shared<RNWorklet::WorkletInvoker>(worklet); | 
					
						
							| 
									
										
										
										
											2023-07-21 17:52:30 +02:00
										 |  |  |     _workletContext = context; | 
					
						
							| 
									
										
										
										
											2023-07-20 15:30:04 +02:00
										 |  |  |   } | 
					
						
							|  |  |  |   return self; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | - (void)callWithFrameHostObject:(std::shared_ptr<FrameHostObject>)frameHostObject { | 
					
						
							|  |  |  |   // Call the Frame Processor on the Worklet Runtime | 
					
						
							|  |  |  |   jsi::Runtime& runtime = _workletContext->getWorkletRuntime(); | 
					
						
							| 
									
										
										
										
											2023-09-01 12:58:32 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-01-11 17:23:38 +01:00
										 |  |  |   // Wrap HostObject as JSI Value | 
					
						
							|  |  |  |   auto argument = jsi::Object::createFromHostObject(runtime, frameHostObject); | 
					
						
							|  |  |  |   jsi::Value jsValue(std::move(argument)); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   // Call the Worklet with the Frame JS Host Object as an argument | 
					
						
							|  |  |  |   _workletInvoker->call(runtime, jsi::Value::undefined(), &jsValue, 1); | 
					
						
							| 
									
										
										
										
											2023-07-20 15:30:04 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | - (void)call:(Frame* _Nonnull)frame { | 
					
						
							|  |  |  |   // Create the Frame Host Object wrapping the internal Frame | 
					
						
							|  |  |  |   auto frameHostObject = std::make_shared<FrameHostObject>(frame); | 
					
						
							|  |  |  |   [self callWithFrameHostObject:frameHostObject]; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | @end |