From 79a5406fc15a9e9efe76b2c61ab7067379833daa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hanno=20J=2E=20G=C3=B6decke?= Date: Tue, 6 Aug 2024 09:54:29 +0200 Subject: [PATCH 1/3] wip: nitrogen --- package/android/CMakeLists.txt | 13 ++- package/cpp/core/RNFSwapChainWrapper.h | 22 +++-- .../example/AppExamplePaper/ios/Podfile.lock | 80 +++++++++++----- package/example/AppExamplePaper/package.json | 1 + package/nitro.json | 11 +++ .../generated/android/RNF+autolinking.cmake | 46 ++++++++++ .../generated/android/RNF+autolinking.gradle | 26 ++++++ .../nitrogen/generated/ios/RNF+autolinking.rb | 55 +++++++++++ .../shared/c++/HybridSwapChainSpec.cpp | 20 ++++ .../shared/c++/HybridSwapChainSpec.hpp | 60 ++++++++++++ package/package.json | 4 + package/react-native-filament.podspec | 4 + package/src/specs/SwapChain.nitro.ts | 3 + package/yarn.lock | 91 ++++++++++++++++++- 14 files changed, 400 insertions(+), 36 deletions(-) create mode 100644 package/nitro.json create mode 100644 package/nitrogen/generated/android/RNF+autolinking.cmake create mode 100644 package/nitrogen/generated/android/RNF+autolinking.gradle create mode 100644 package/nitrogen/generated/ios/RNF+autolinking.rb create mode 100644 package/nitrogen/generated/shared/c++/HybridSwapChainSpec.cpp create mode 100644 package/nitrogen/generated/shared/c++/HybridSwapChainSpec.hpp create mode 100644 package/src/specs/SwapChain.nitro.ts diff --git a/package/android/CMakeLists.txt b/package/android/CMakeLists.txt index c65328cf..9deb327e 100644 --- a/package/android/CMakeLists.txt +++ b/package/android/CMakeLists.txt @@ -24,6 +24,8 @@ find_package(ReactAndroid REQUIRED CONFIG) find_package(fbjni REQUIRED CONFIG) find_library(LOG_LIB log) +include(${CMAKE_SOURCE_DIR}/../nitrogen/generated/android/RNF+autolinking.cmake) + # Add react-native-filament sources add_library( ${PACKAGE_NAME} @@ -127,7 +129,7 @@ target_link_libraries( ) # Link with RNWC: -if (IS_OLD_ARCHITECTURE_ENABLED) +if(IS_OLD_ARCHITECTURE_ENABLED) # On the old arch RNWC publishes a prefab that we need to find (and it has a different name): find_package(react-native-worklets-core REQUIRED CONFIG) message("RN Filament: react-native-worklets core found! Enabling Worklets support...") @@ -136,13 +138,14 @@ if (IS_OLD_ARCHITECTURE_ENABLED) ${PACKAGE_NAME} react-native-worklets-core::rnworklets ) -else () +else() target_link_libraries( - ${PACKAGE_NAME} - react_codegen_rnfilament # link against the codegen generated library of rnf (needed so this module is compiled correctly) - react-native-worklets-core + ${PACKAGE_NAME} + react_codegen_rnfilament # link against the codegen generated library of rnf (needed so this module is compiled correctly) + react-native-worklets-core ) endif() + add_definitions(-DHAS_WORKLETS=1) # Filament (local CMake project as a git submodule) diff --git a/package/cpp/core/RNFSwapChainWrapper.h b/package/cpp/core/RNFSwapChainWrapper.h index 5ac4cb51..0525b10c 100644 --- a/package/cpp/core/RNFSwapChainWrapper.h +++ b/package/cpp/core/RNFSwapChainWrapper.h @@ -1,20 +1,26 @@ #pragma once -#include "jsi/RNFPointerHolder.h" +#include "HybridSwapChainSpec.hpp" #include namespace margelo { using namespace filament; +using namespace nitro::RNF; -class SwapChainWrapper : public PointerHolder { +class SwapChainWrapper : public HybridSwapChainSpec { public: - explicit SwapChainWrapper(std::shared_ptr swapChain) : PointerHolder("SwapChainWrapper", swapChain) {} + explicit SwapChainWrapper(std::shared_ptr swapChain) : _swapChain(swapChain) {} - void loadHybridMethods() override {} - - std::shared_ptr getSwapChain() { - return pointee(); - } + std::shared_ptr getSwapChain() { + return _swapChain; + } + + size_t getExternalMemorySize() noexcept override { + return sizeof(std::shared_ptr); + } + +private: + std::shared_ptr _swapChain; }; } // namespace margelo diff --git a/package/example/AppExamplePaper/ios/Podfile.lock b/package/example/AppExamplePaper/ios/Podfile.lock index 1b556e7a..9141b0a2 100644 --- a/package/example/AppExamplePaper/ios/Podfile.lock +++ b/package/example/AppExamplePaper/ios/Podfile.lock @@ -7,6 +7,27 @@ PODS: - hermes-engine (0.74.1): - hermes-engine/Pre-built (= 0.74.1) - hermes-engine/Pre-built (0.74.1) + - NitroModules (0.1.3): + - DoubleConversion + - glog + - hermes-engine + - RCT-Folly (= 2024.01.01.00) + - RCTRequired + - RCTTypeSafety + - React-Codegen + - React-Core + - React-debug + - React-Fabric + - React-featureflags + - React-graphics + - React-ImageManager + - React-NativeModulesApple + - React-RCTFabric + - React-rendererdebug + - React-utils + - ReactCommon/turbomodule/bridging + - ReactCommon/turbomodule/core + - Yoga - RCT-Folly (2024.01.01.00): - boost - DoubleConversion @@ -935,10 +956,11 @@ PODS: - React-Mapbuffer (0.74.1): - glog - React-debug - - react-native-filament (1.4.1): + - react-native-filament (1.5.1): - DoubleConversion - glog - hermes-engine + - NitroModules - RCT-Folly (= 2024.01.01.00) - RCTRequired - RCTTypeSafety @@ -949,16 +971,16 @@ PODS: - React-featureflags - React-graphics - React-ImageManager - - react-native-filament/camutils (= 1.4.1) - - react-native-filament/filamat (= 1.4.1) - - react-native-filament/filament (= 1.4.1) - - react-native-filament/gltfio_core (= 1.4.1) - - react-native-filament/image (= 1.4.1) - - react-native-filament/ktxreader (= 1.4.1) - - react-native-filament/math (= 1.4.1) - - react-native-filament/tsl (= 1.4.1) - - react-native-filament/uberz (= 1.4.1) - - react-native-filament/utils (= 1.4.1) + - react-native-filament/camutils (= 1.5.1) + - react-native-filament/filamat (= 1.5.1) + - react-native-filament/filament (= 1.5.1) + - react-native-filament/gltfio_core (= 1.5.1) + - react-native-filament/image (= 1.5.1) + - react-native-filament/ktxreader (= 1.5.1) + - react-native-filament/math (= 1.5.1) + - react-native-filament/tsl (= 1.5.1) + - react-native-filament/uberz (= 1.5.1) + - react-native-filament/utils (= 1.5.1) - react-native-worklets-core - React-NativeModulesApple - React-RCTFabric @@ -967,10 +989,11 @@ PODS: - ReactCommon/turbomodule/bridging - ReactCommon/turbomodule/core - Yoga - - react-native-filament/camutils (1.4.1): + - react-native-filament/camutils (1.5.1): - DoubleConversion - glog - hermes-engine + - NitroModules - RCT-Folly (= 2024.01.01.00) - RCTRequired - RCTTypeSafety @@ -990,10 +1013,11 @@ PODS: - ReactCommon/turbomodule/bridging - ReactCommon/turbomodule/core - Yoga - - react-native-filament/filamat (1.4.1): + - react-native-filament/filamat (1.5.1): - DoubleConversion - glog - hermes-engine + - NitroModules - RCT-Folly (= 2024.01.01.00) - RCTRequired - RCTTypeSafety @@ -1014,10 +1038,11 @@ PODS: - ReactCommon/turbomodule/bridging - ReactCommon/turbomodule/core - Yoga - - react-native-filament/filament (1.4.1): + - react-native-filament/filament (1.5.1): - DoubleConversion - glog - hermes-engine + - NitroModules - RCT-Folly (= 2024.01.01.00) - RCTRequired - RCTTypeSafety @@ -1038,10 +1063,11 @@ PODS: - ReactCommon/turbomodule/bridging - ReactCommon/turbomodule/core - Yoga - - react-native-filament/gltfio_core (1.4.1): + - react-native-filament/gltfio_core (1.5.1): - DoubleConversion - glog - hermes-engine + - NitroModules - RCT-Folly (= 2024.01.01.00) - RCTRequired - RCTTypeSafety @@ -1063,10 +1089,11 @@ PODS: - ReactCommon/turbomodule/bridging - ReactCommon/turbomodule/core - Yoga - - react-native-filament/image (1.4.1): + - react-native-filament/image (1.5.1): - DoubleConversion - glog - hermes-engine + - NitroModules - RCT-Folly (= 2024.01.01.00) - RCTRequired - RCTTypeSafety @@ -1086,10 +1113,11 @@ PODS: - ReactCommon/turbomodule/bridging - ReactCommon/turbomodule/core - Yoga - - react-native-filament/ktxreader (1.4.1): + - react-native-filament/ktxreader (1.5.1): - DoubleConversion - glog - hermes-engine + - NitroModules - RCT-Folly (= 2024.01.01.00) - RCTRequired - RCTTypeSafety @@ -1110,10 +1138,11 @@ PODS: - ReactCommon/turbomodule/bridging - ReactCommon/turbomodule/core - Yoga - - react-native-filament/math (1.4.1): + - react-native-filament/math (1.5.1): - DoubleConversion - glog - hermes-engine + - NitroModules - RCT-Folly (= 2024.01.01.00) - RCTRequired - RCTTypeSafety @@ -1132,10 +1161,11 @@ PODS: - ReactCommon/turbomodule/bridging - ReactCommon/turbomodule/core - Yoga - - react-native-filament/tsl (1.4.1): + - react-native-filament/tsl (1.5.1): - DoubleConversion - glog - hermes-engine + - NitroModules - RCT-Folly (= 2024.01.01.00) - RCTRequired - RCTTypeSafety @@ -1154,10 +1184,11 @@ PODS: - ReactCommon/turbomodule/bridging - ReactCommon/turbomodule/core - Yoga - - react-native-filament/uberz (1.4.1): + - react-native-filament/uberz (1.5.1): - DoubleConversion - glog - hermes-engine + - NitroModules - RCT-Folly (= 2024.01.01.00) - RCTRequired - RCTTypeSafety @@ -1179,10 +1210,11 @@ PODS: - ReactCommon/turbomodule/bridging - ReactCommon/turbomodule/core - Yoga - - react-native-filament/utils (1.4.1): + - react-native-filament/utils (1.5.1): - DoubleConversion - glog - hermes-engine + - NitroModules - RCT-Folly (= 2024.01.01.00) - RCTRequired - RCTTypeSafety @@ -1556,6 +1588,7 @@ DEPENDENCIES: - fmt (from `../node_modules/react-native/third-party-podspecs/fmt.podspec`) - glog (from `../node_modules/react-native/third-party-podspecs/glog.podspec`) - hermes-engine (from `../node_modules/react-native/sdks/hermes-engine/hermes-engine.podspec`) + - NitroModules (from `../node_modules/react-native-nitro-modules`) - RCT-Folly (from `../node_modules/react-native/third-party-podspecs/RCT-Folly.podspec`) - RCT-Folly/Fabric (from `../node_modules/react-native/third-party-podspecs/RCT-Folly.podspec`) - RCTDeprecation (from `../node_modules/react-native/ReactApple/Libraries/RCTFoundation/RCTDeprecation`) @@ -1633,6 +1666,8 @@ EXTERNAL SOURCES: hermes-engine: :podspec: "../node_modules/react-native/sdks/hermes-engine/hermes-engine.podspec" :tag: hermes-2024-04-25-RNv0.74.1-b54a3a01c531f4f5f1904cb0770033e8b7153dff + NitroModules: + :path: "../node_modules/react-native-nitro-modules" RCT-Folly: :podspec: "../node_modules/react-native/third-party-podspecs/RCT-Folly.podspec" RCTDeprecation: @@ -1753,6 +1788,7 @@ SPEC CHECKSUMS: fmt: 4c2741a687cc09f0634a2e2c72a838b99f1ff120 glog: c5d68082e772fa1c511173d6b30a9de2c05a69a2 hermes-engine: 16b8530de1b383cdada1476cf52d1b52f0692cbc + NitroModules: 8bb3abc20b1907912f0cbd44fd2e76bd7018e309 RCT-Folly: 02617c592a293bd6d418e0a88ff4ee1f88329b47 RCTDeprecation: efb313d8126259e9294dc4ee0002f44a6f676aba RCTRequired: f49ea29cece52aee20db633ae7edc4b271435562 @@ -1777,7 +1813,7 @@ SPEC CHECKSUMS: React-jsitracing: 233d1a798fe0ff33b8e630b8f00f62c4a8115fbc React-logger: 7e7403a2b14c97f847d90763af76b84b152b6fce React-Mapbuffer: 11029dcd47c5c9e057a4092ab9c2a8d10a496a33 - react-native-filament: 04ef2c32e88eec8f22b545029962f2b4af48e059 + react-native-filament: 0daffa159656bd7ad44b46775c0ebd24c0427d97 react-native-safe-area-context: dcab599c527c2d7de2d76507a523d20a0b83823d react-native-video: 9f29aee2feb9e42da24cb40b70d005d38a1a132f react-native-worklets-core: f51430dd07bf5343d4918d28a4bb00fe8f98b982 diff --git a/package/example/AppExamplePaper/package.json b/package/example/AppExamplePaper/package.json index 93676c62..f7810eab 100644 --- a/package/example/AppExamplePaper/package.json +++ b/package/example/AppExamplePaper/package.json @@ -17,6 +17,7 @@ "@react-navigation/native-stack": "^6.9.26", "react-native": "0.74.1", "react-native-gesture-handler": "^2.16.2", + "react-native-nitro-modules": "^0.1.3", "react-native-reanimated": "^3.11.0", "react-native-safe-area-context": "^4.10.1", "react-native-screens": "^3.31.1", diff --git a/package/nitro.json b/package/nitro.json new file mode 100644 index 00000000..14d84825 --- /dev/null +++ b/package/nitro.json @@ -0,0 +1,11 @@ +{ + "logLevel": "debug", + "cxxNamespace": ["RNF"], + "ios": { + "iosModulename": "RNF" + }, + "android": { + "androidNamespace": ["RNF"], + "androidCxxLibName": "RNF" + } +} diff --git a/package/nitrogen/generated/android/RNF+autolinking.cmake b/package/nitrogen/generated/android/RNF+autolinking.cmake new file mode 100644 index 00000000..938743a6 --- /dev/null +++ b/package/nitrogen/generated/android/RNF+autolinking.cmake @@ -0,0 +1,46 @@ +# +# RNF+autolinking.cmake +# Mon Aug 05 2024 +# This file was generated by nitrogen. DO NOT MODIFY THIS FILE. +# https://github.com/mrousavy/react-native-nitro +# Copyright © 2024 Marc Rousavy @ Margelo +# + +# This is a CMake file that adds all files generated by Nitrogen +# to the current CMake project. +# +# To use it, add this to your CMakeLists.txt: +# ```cmake +# include(${CMAKE_SOURCE_DIR}/../nitrogen/generated/android/RNF+autolinking.cmake) +# ``` + +# Add all headers that were generated by Nitrogen +include_directories( + "../nitrogen/generated/shared/c++" + "../nitrogen/generated/android/c++" +) + +# Add all .cpp sources that were generated by Nitrogen +target_sources( + # CMake project name (Android C++ library name) + RNF + # Shared Nitrogen C++ sources + ../nitrogen/generated/shared/HybridSwapChainSpec.cpp + ../nitrogen/generated/shared/HybridSwapChainSpec.cpp + # Android-specific Nitrogen C++ sources + +) + +# Add all libraries required by the generated specs +find_package(fbjni REQUIRED) # <-- Used for communication between Java <-> C++ +find_package(ReactAndroid REQUIRED) # <-- Used to set up React Native bindings (e.g. CallInvoker/TurboModule) +find_package(react-native-nitro-modules REQUIRED) # <-- Used to create all HybridObjects and use the Nitro core library + +# Link all libraries together +target_link_libraries( + RNF + fbjni::fbjni # <-- Facebook C++ JNI helpers + ReactAndroid::jsi # <-- RN: JSI + ReactAndroid::react_nativemodule_core # <-- RN: TurboModules Core + react-native-nitro-modules::NitroModules # <-- NitroModules Core :) +) diff --git a/package/nitrogen/generated/android/RNF+autolinking.gradle b/package/nitrogen/generated/android/RNF+autolinking.gradle new file mode 100644 index 00000000..55cff77a --- /dev/null +++ b/package/nitrogen/generated/android/RNF+autolinking.gradle @@ -0,0 +1,26 @@ +/// +/// RNF+autolinking.gradle +/// Mon Aug 05 2024 +/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. +/// https://github.com/mrousavy/react-native-nitro +/// Copyright © 2024 Marc Rousavy @ Margelo +/// + +/// This is a Gradle file that adds all files generated by Nitrogen +/// to the current Gradle project. +/// +/// To use it, add this to your build.gradle: +/// ```gradle +/// apply from: '../nitrogen/generated/android/RNF+autolinking.gradle' +/// ``` + +android { + sourceSets { + main { + java.srcDirs += [ + // Nitrogen files + "${project.projectDir}/../nitrogen/generated/android/kotlin" + ] + } + } +} diff --git a/package/nitrogen/generated/ios/RNF+autolinking.rb b/package/nitrogen/generated/ios/RNF+autolinking.rb new file mode 100644 index 00000000..96f53828 --- /dev/null +++ b/package/nitrogen/generated/ios/RNF+autolinking.rb @@ -0,0 +1,55 @@ +# +# RNF+autolinking.rb +# Mon Aug 05 2024 +# This file was generated by nitrogen. DO NOT MODIFY THIS FILE. +# https://github.com/mrousavy/react-native-nitro +# Copyright © 2024 Marc Rousavy @ Margelo +# + +# This is a Ruby script that adds all files generated by Nitrogen +# to the given podspec. +# +# To use it, add this to your .podspec: +# ```ruby +# Pod::Spec.new do |spec| +# # ... +# +# # Add all files generated by Nitrogen +# load 'nitrogen/generated/ios/RNF+autolinking.rb' +# add_nitrogen_files(spec) +# end +# ``` + +def add_nitrogen_files(spec) + Pod::UI.puts "[NitroModules] Adding RNF specs..." + + spec.dependency "NitroModules" + + current_source_files = spec.attributes_hash['source_files'] || [] + spec.source_files = current_source_files + [ + # Generated cross-platform specs + "nitrogen/generated/shared/**/*.{h,hpp,c,cpp,swift}", + # Generated bridges for the cross-platform specs + "nitrogen/generated/ios/**/*.{h,hpp,c,cpp,swift}", + ] + + current_public_header_files = spec.attributes_hash['public_header_files'] || [] + spec.public_header_files = current_public_header_files + [ + # Generated specs + "nitrogen/generated/shared/**/*.{h,hpp}", + ] + + current_private_header_files = spec.attributes_hash['private_header_files'] || [] + spec.private_header_files = current_private_header_files + [ + # iOS specific specs + "nitrogen/generated/ios/c++/**/*.{h,hpp}", + ] + + current_pod_target_xcconfig = spec.attributes_hash['pod_target_xcconfig'] || {} + spec.pod_target_xcconfig = current_pod_target_xcconfig.merge({ + # Use C++ 20 + "CLANG_CXX_LANGUAGE_STANDARD" => "c++20", + # Enables C++ <-> Swift interop (by default it's only C) + "SWIFT_OBJC_INTEROP_MODE" => "objcxx", + }) +end diff --git a/package/nitrogen/generated/shared/c++/HybridSwapChainSpec.cpp b/package/nitrogen/generated/shared/c++/HybridSwapChainSpec.cpp new file mode 100644 index 00000000..a26d1135 --- /dev/null +++ b/package/nitrogen/generated/shared/c++/HybridSwapChainSpec.cpp @@ -0,0 +1,20 @@ +/// +/// HybridSwapChainSpec.cpp +/// Mon Aug 05 2024 +/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. +/// https://github.com/mrousavy/react-native-nitro +/// Copyright © 2024 Marc Rousavy @ Margelo +/// + +#include "HybridSwapChainSpec.hpp" + +namespace margelo::nitro::RNF { + + void HybridSwapChainSpec::loadHybridMethods() { + // load base methods/properties + HybridObject::loadHybridMethods(); + // load custom methods/properties + + } + +} // namespace margelo::nitro::RNF diff --git a/package/nitrogen/generated/shared/c++/HybridSwapChainSpec.hpp b/package/nitrogen/generated/shared/c++/HybridSwapChainSpec.hpp new file mode 100644 index 00000000..e9f34327 --- /dev/null +++ b/package/nitrogen/generated/shared/c++/HybridSwapChainSpec.hpp @@ -0,0 +1,60 @@ +/// +/// HybridSwapChainSpec.hpp +/// Mon Aug 05 2024 +/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. +/// https://github.com/mrousavy/react-native-nitro +/// Copyright © 2024 Marc Rousavy @ Margelo +/// + +#pragma once + +#if __has_include() +#include +#else +#error NitroModules cannot be found! Are you sure you installed NitroModules properly? +#endif + + + + + +namespace margelo::nitro::RNF { + + using namespace margelo::nitro; + + /** + * An abstract base class for `SwapChain` + * Inherit this class to create instances of `HybridSwapChainSpec` in C++. + * @example + * ```cpp + * class HybridSwapChain: public HybridSwapChainSpec { + * // ... + * }; + * ``` + */ + class HybridSwapChainSpec: public HybridObject { + public: + // Constructor + explicit HybridSwapChainSpec(): HybridObject(TAG) { } + + // Destructor + ~HybridSwapChainSpec() { } + + public: + // Properties + + + public: + // Methods + + + protected: + // Hybrid Setup + void loadHybridMethods() override; + + protected: + // Tag for logging + static constexpr auto TAG = "SwapChain"; + }; + +} // namespace margelo::nitro::RNF diff --git a/package/package.json b/package/package.json index d4a06118..f7c3f068 100644 --- a/package/package.json +++ b/package/package.json @@ -80,6 +80,9 @@ "publishConfig": { "registry": "https://registry.npmjs.org/" }, + "dependencies": { + "react-native-nitro-modules": "^0.1.3" + }, "devDependencies": { "@jamesacarr/eslint-formatter-github-actions": "^0.2.0", "@react-native/eslint-config": "^0.73.1", @@ -88,6 +91,7 @@ "eslint": "^8.51.0", "eslint-config-prettier": "^9.0.0", "eslint-plugin-prettier": "^5.0.1", + "nitro-codegen": "^0.1.3", "prettier": "^3.0.3", "react": "18.2.0", "react-native": "0.74.1", diff --git a/package/react-native-filament.podspec b/package/react-native-filament.podspec index a3253c4f..6b8962e8 100644 --- a/package/react-native-filament.podspec +++ b/package/react-native-filament.podspec @@ -157,6 +157,10 @@ Pod::Spec.new do |s| s.resources = ["assets/*"] end + # Add all files generated by Nitrogen + load 'nitrogen/generated/ios/RNF+autolinking.rb' + add_nitrogen_files(s) + # Use install_modules_dependencies helper to install the dependencies if React Native version >=0.71.0. # See https://github.com/facebook/react-native/blob/febf6b7f33fdb4904669f99d795eba4c0f95d7bf/scripts/cocoapods/new_architecture.rb#L79. if respond_to?(:install_modules_dependencies, true) diff --git a/package/src/specs/SwapChain.nitro.ts b/package/src/specs/SwapChain.nitro.ts new file mode 100644 index 00000000..b0af7d64 --- /dev/null +++ b/package/src/specs/SwapChain.nitro.ts @@ -0,0 +1,3 @@ +import { type HybridObject } from 'react-native-nitro-modules' + +export interface SwapChain extends HybridObject<{ android: 'c++'; ios: 'c++' }> {} diff --git a/package/yarn.lock b/package/yarn.lock index 725ee14a..b6058fad 100644 --- a/package/yarn.lock +++ b/package/yarn.lock @@ -3875,6 +3875,18 @@ __metadata: languageName: node linkType: hard +"@ts-morph/common@npm:~0.24.0": + version: 0.24.0 + resolution: "@ts-morph/common@npm:0.24.0" + dependencies: + fast-glob: ^3.3.2 + minimatch: ^9.0.4 + mkdirp: ^3.0.1 + path-browserify: ^1.0.1 + checksum: 793bc8a47c93ab55c6c036f94480d3b0e948661aef4bb7dbc29279b1dda2fc4fce809a88e221537867a313541842e12d1ecbd32b4769688abe1303807ec09db6 + languageName: node + linkType: hard + "@types/hammerjs@npm:^2.0.36": version: 2.0.45 resolution: "@types/hammerjs@npm:2.0.45" @@ -5009,7 +5021,7 @@ __metadata: languageName: node linkType: hard -"chalk@npm:^5.0.0, chalk@npm:^5.0.1, chalk@npm:^5.2.0": +"chalk@npm:^5.0.0, chalk@npm:^5.0.1, chalk@npm:^5.2.0, chalk@npm:^5.3.0": version: 5.3.0 resolution: "chalk@npm:5.3.0" checksum: 623922e077b7d1e9dedaea6f8b9e9352921f8ae3afe739132e0e00c275971bdd331268183b2628cf4ab1727c45ea1f28d7e24ac23ce1db1eb653c414ca8a5a80 @@ -5155,6 +5167,13 @@ __metadata: languageName: node linkType: hard +"code-block-writer@npm:^13.0.1": + version: 13.0.2 + resolution: "code-block-writer@npm:13.0.2" + checksum: 8052ae6f27ef73366bd5df04b6f9beced493261fcaef5cbd0f3853644b5e0aa5af18d099b96448be88ea3d000c7b180207d371044edd9fcf98fea22c9f8ba3a1 + languageName: node + linkType: hard + "color-convert@npm:^1.9.0": version: 1.9.3 resolution: "color-convert@npm:1.9.3" @@ -9458,6 +9477,15 @@ __metadata: languageName: node linkType: hard +"mkdirp@npm:^3.0.1": + version: 3.0.1 + resolution: "mkdirp@npm:3.0.1" + bin: + mkdirp: dist/cjs/src/bin.js + checksum: 972deb188e8fb55547f1e58d66bd6b4a3623bf0c7137802582602d73e6480c1c2268dcbafbfb1be466e00cc7e56ac514d7fd9334b7cf33e3e2ab547c16f83a8d + languageName: node + linkType: hard + "modify-values@npm:^1.0.0": version: 1.0.1 resolution: "modify-values@npm:1.0.1" @@ -9546,6 +9574,20 @@ __metadata: languageName: node linkType: hard +"nitro-codegen@npm:^0.1.3": + version: 0.1.3 + resolution: "nitro-codegen@npm:0.1.3" + dependencies: + chalk: ^5.3.0 + react-native-nitro-modules: ^0.0.7 + ts-morph: ^23.0.0 + zod: ^3.23.8 + bin: + nitro-codegen: lib/index.js + checksum: f6bb85254daf07ef7994a0ab3459eedd6fa7dbb0e413e6dc27a7aae905d609445d6b25a6e77a64b74fa25ef82b25eec3852b1b1c69af37a29e0199aa63a45ffa + languageName: node + linkType: hard + "nocache@npm:^3.0.1": version: 3.0.4 resolution: "nocache@npm:3.0.4" @@ -10114,6 +10156,7 @@ __metadata: babel-plugin-module-resolver: ^5.0.0 react-native: 0.74.1 react-native-gesture-handler: ^2.16.2 + react-native-nitro-modules: ^0.1.3 react-native-reanimated: ^3.11.0 react-native-safe-area-context: ^4.10.1 react-native-screens: ^3.31.1 @@ -10181,6 +10224,13 @@ __metadata: languageName: node linkType: hard +"path-browserify@npm:^1.0.1": + version: 1.0.1 + resolution: "path-browserify@npm:1.0.1" + checksum: c6d7fa376423fe35b95b2d67990060c3ee304fc815ff0a2dc1c6c3cfaff2bd0d572ee67e18f19d0ea3bbe32e8add2a05021132ac40509416459fffee35200699 + languageName: node + linkType: hard + "path-exists@npm:^3.0.0": version: 3.0.0 resolution: "path-exists@npm:3.0.0" @@ -10697,10 +10747,12 @@ __metadata: eslint: ^8.51.0 eslint-config-prettier: ^9.0.0 eslint-plugin-prettier: ^5.0.1 + nitro-codegen: ^0.1.3 prettier: ^3.0.3 react: 18.2.0 react-native: 0.74.1 react-native-builder-bob: ^0.20.0 + react-native-nitro-modules: ^0.1.3 react-native-worklets-core: ^2.0.0-beta.4 release-it: ^15.0.0 typescript: ^5.2.2 @@ -10727,6 +10779,26 @@ __metadata: languageName: node linkType: hard +"react-native-nitro-modules@npm:^0.0.7": + version: 0.0.7 + resolution: "react-native-nitro-modules@npm:0.0.7" + peerDependencies: + react: "*" + react-native: "*" + checksum: 7389dca0f30daa282356631614a8a87afbed83800b76b6fdd1c2dc91c662fa69ba7022a0f42a7937ce9b5022cd3d07b32dcd2f3b5a1f25bb0813955f627147e0 + languageName: node + linkType: hard + +"react-native-nitro-modules@npm:^0.1.3": + version: 0.1.3 + resolution: "react-native-nitro-modules@npm:0.1.3" + peerDependencies: + react: "*" + react-native: "*" + checksum: 2dd1e292a786b0b909e5b82cde28f6bb6a1930cd74f803995c1de2bb584f9b2fb8b9546361f1ddc9cbc0bc6f8fc99f48ff1a5697475e9fd4b79da561822d1b93 + languageName: node + linkType: hard + "react-native-reanimated@npm:^3.11.0": version: 3.11.0 resolution: "react-native-reanimated@npm:3.11.0" @@ -12281,6 +12353,16 @@ __metadata: languageName: node linkType: hard +"ts-morph@npm:^23.0.0": + version: 23.0.0 + resolution: "ts-morph@npm:23.0.0" + dependencies: + "@ts-morph/common": ~0.24.0 + code-block-writer: ^13.0.1 + checksum: 3282eb0f8bd4577770874736c3259b97501da9a86137160b5d68f106b7848ea7b1fbccf9e198a3d930ec40c993e9951d4bfae31e2562dac8f3de0d7bb0e23615 + languageName: node + linkType: hard + "tslib@npm:^1.8.1": version: 1.14.1 resolution: "tslib@npm:1.14.1" @@ -13162,3 +13244,10 @@ __metadata: checksum: f77b3d8d00310def622123df93d4ee654fc6a0096182af8bd60679ddcdfb3474c56c6c7190817c84a2785648cdee9d721c0154eb45698c62176c322fb46fc700 languageName: node linkType: hard + +"zod@npm:^3.23.8": + version: 3.23.8 + resolution: "zod@npm:3.23.8" + checksum: 15949ff82118f59c893dacd9d3c766d02b6fa2e71cf474d5aa888570c469dbf5446ac5ad562bb035bf7ac9650da94f290655c194f4a6de3e766f43febd432c5c + languageName: node + linkType: hard From 2a2c94e235ad46262e28eea280ed5788af5607c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hanno=20J=2E=20G=C3=B6decke?= Date: Mon, 19 Aug 2024 11:51:22 +0200 Subject: [PATCH 2/3] update nitrogen version --- .../example/AppExamplePaper/ios/Podfile.lock | 6 +-- package/example/AppExamplePaper/package.json | 2 +- .../generated/android/RNF+autolinking.cmake | 7 ++-- .../generated/android/RNF+autolinking.gradle | 2 +- .../nitrogen/generated/ios/RNF+autolinking.rb | 4 +- .../generated/ios/RNF-Swift-Cxx-Bridge.cpp | 9 +++++ .../generated/ios/RNF-Swift-Cxx-Bridge.hpp | 25 +++++++++++++ .../generated/ios/RNF-Swift-Cxx-Umbrella.hpp | 34 +++++++++++++++++ .../shared/c++/HybridSwapChainSpec.cpp | 6 ++- .../shared/c++/HybridSwapChainSpec.hpp | 4 +- package/package.json | 5 ++- package/src/specs/SwapChain.nitro.ts | 5 ++- package/yarn.lock | 37 +++++++------------ 13 files changed, 106 insertions(+), 40 deletions(-) create mode 100644 package/nitrogen/generated/ios/RNF-Swift-Cxx-Bridge.cpp create mode 100644 package/nitrogen/generated/ios/RNF-Swift-Cxx-Bridge.hpp create mode 100644 package/nitrogen/generated/ios/RNF-Swift-Cxx-Umbrella.hpp diff --git a/package/example/AppExamplePaper/ios/Podfile.lock b/package/example/AppExamplePaper/ios/Podfile.lock index 9141b0a2..3c29ba82 100644 --- a/package/example/AppExamplePaper/ios/Podfile.lock +++ b/package/example/AppExamplePaper/ios/Podfile.lock @@ -7,7 +7,7 @@ PODS: - hermes-engine (0.74.1): - hermes-engine/Pre-built (= 0.74.1) - hermes-engine/Pre-built (0.74.1) - - NitroModules (0.1.3): + - NitroModules (0.5.0): - DoubleConversion - glog - hermes-engine @@ -1788,7 +1788,7 @@ SPEC CHECKSUMS: fmt: 4c2741a687cc09f0634a2e2c72a838b99f1ff120 glog: c5d68082e772fa1c511173d6b30a9de2c05a69a2 hermes-engine: 16b8530de1b383cdada1476cf52d1b52f0692cbc - NitroModules: 8bb3abc20b1907912f0cbd44fd2e76bd7018e309 + NitroModules: 4f1ee46199d395b4fe0da7b819a61a37cc955add RCT-Folly: 02617c592a293bd6d418e0a88ff4ee1f88329b47 RCTDeprecation: efb313d8126259e9294dc4ee0002f44a6f676aba RCTRequired: f49ea29cece52aee20db633ae7edc4b271435562 @@ -1813,7 +1813,7 @@ SPEC CHECKSUMS: React-jsitracing: 233d1a798fe0ff33b8e630b8f00f62c4a8115fbc React-logger: 7e7403a2b14c97f847d90763af76b84b152b6fce React-Mapbuffer: 11029dcd47c5c9e057a4092ab9c2a8d10a496a33 - react-native-filament: 0daffa159656bd7ad44b46775c0ebd24c0427d97 + react-native-filament: e232d14507d95e4f6331b0cb9d276931785e5913 react-native-safe-area-context: dcab599c527c2d7de2d76507a523d20a0b83823d react-native-video: 9f29aee2feb9e42da24cb40b70d005d38a1a132f react-native-worklets-core: f51430dd07bf5343d4918d28a4bb00fe8f98b982 diff --git a/package/example/AppExamplePaper/package.json b/package/example/AppExamplePaper/package.json index f7810eab..c41361fb 100644 --- a/package/example/AppExamplePaper/package.json +++ b/package/example/AppExamplePaper/package.json @@ -17,7 +17,7 @@ "@react-navigation/native-stack": "^6.9.26", "react-native": "0.74.1", "react-native-gesture-handler": "^2.16.2", - "react-native-nitro-modules": "^0.1.3", + "react-native-nitro-modules": "^0.5.0", "react-native-reanimated": "^3.11.0", "react-native-safe-area-context": "^4.10.1", "react-native-screens": "^3.31.1", diff --git a/package/nitrogen/generated/android/RNF+autolinking.cmake b/package/nitrogen/generated/android/RNF+autolinking.cmake index 938743a6..15f17128 100644 --- a/package/nitrogen/generated/android/RNF+autolinking.cmake +++ b/package/nitrogen/generated/android/RNF+autolinking.cmake @@ -1,6 +1,6 @@ # # RNF+autolinking.cmake -# Mon Aug 05 2024 +# Mon Aug 19 2024 # This file was generated by nitrogen. DO NOT MODIFY THIS FILE. # https://github.com/mrousavy/react-native-nitro # Copyright © 2024 Marc Rousavy @ Margelo @@ -23,10 +23,9 @@ include_directories( # Add all .cpp sources that were generated by Nitrogen target_sources( # CMake project name (Android C++ library name) - RNF + RNF PRIVATE # Shared Nitrogen C++ sources - ../nitrogen/generated/shared/HybridSwapChainSpec.cpp - ../nitrogen/generated/shared/HybridSwapChainSpec.cpp + ../nitrogen/generated/shared/c++/HybridSwapChainSpec.cpp # Android-specific Nitrogen C++ sources ) diff --git a/package/nitrogen/generated/android/RNF+autolinking.gradle b/package/nitrogen/generated/android/RNF+autolinking.gradle index 55cff77a..2dcf4e7f 100644 --- a/package/nitrogen/generated/android/RNF+autolinking.gradle +++ b/package/nitrogen/generated/android/RNF+autolinking.gradle @@ -1,6 +1,6 @@ /// /// RNF+autolinking.gradle -/// Mon Aug 05 2024 +/// Mon Aug 19 2024 /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. /// https://github.com/mrousavy/react-native-nitro /// Copyright © 2024 Marc Rousavy @ Margelo diff --git a/package/nitrogen/generated/ios/RNF+autolinking.rb b/package/nitrogen/generated/ios/RNF+autolinking.rb index 96f53828..718c858d 100644 --- a/package/nitrogen/generated/ios/RNF+autolinking.rb +++ b/package/nitrogen/generated/ios/RNF+autolinking.rb @@ -1,6 +1,6 @@ # # RNF+autolinking.rb -# Mon Aug 05 2024 +# Mon Aug 19 2024 # This file was generated by nitrogen. DO NOT MODIFY THIS FILE. # https://github.com/mrousavy/react-native-nitro # Copyright © 2024 Marc Rousavy @ Margelo @@ -37,6 +37,8 @@ def add_nitrogen_files(spec) spec.public_header_files = current_public_header_files + [ # Generated specs "nitrogen/generated/shared/**/*.{h,hpp}", + # Swift to C++ bridging helpers + "nitrogen/generated/ios/RNF-Swift-Cxx-Bridge.hpp" ] current_private_header_files = spec.attributes_hash['private_header_files'] || [] diff --git a/package/nitrogen/generated/ios/RNF-Swift-Cxx-Bridge.cpp b/package/nitrogen/generated/ios/RNF-Swift-Cxx-Bridge.cpp new file mode 100644 index 00000000..a8dbe9c5 --- /dev/null +++ b/package/nitrogen/generated/ios/RNF-Swift-Cxx-Bridge.cpp @@ -0,0 +1,9 @@ +/// +/// RNF-Swift-Cxx-Bridge.cpp +/// Mon Aug 19 2024 +/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. +/// https://github.com/mrousavy/react-native-nitro +/// Copyright © 2024 Marc Rousavy @ Margelo +/// + +#include "RNF-Swift-Cxx-Bridge.hpp" diff --git a/package/nitrogen/generated/ios/RNF-Swift-Cxx-Bridge.hpp b/package/nitrogen/generated/ios/RNF-Swift-Cxx-Bridge.hpp new file mode 100644 index 00000000..a904e808 --- /dev/null +++ b/package/nitrogen/generated/ios/RNF-Swift-Cxx-Bridge.hpp @@ -0,0 +1,25 @@ +/// +/// RNF-Swift-Cxx-Bridge.hpp +/// Mon Aug 19 2024 +/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. +/// https://github.com/mrousavy/react-native-nitro +/// Copyright © 2024 Marc Rousavy @ Margelo +/// + +#pragma once + +// Forward declarations of C++ defined types + + +// Include C++ defined types + + +/** + * Contains specialized versions of C++ templated types so they can be accessed from Swift, + * as well as helper functions to interact with those C++ types from Swift. + */ +namespace margelo::nitro::RNF::bridge::swift { + + + +} // namespace margelo::nitro::RNF::bridge::swift diff --git a/package/nitrogen/generated/ios/RNF-Swift-Cxx-Umbrella.hpp b/package/nitrogen/generated/ios/RNF-Swift-Cxx-Umbrella.hpp new file mode 100644 index 00000000..27f31649 --- /dev/null +++ b/package/nitrogen/generated/ios/RNF-Swift-Cxx-Umbrella.hpp @@ -0,0 +1,34 @@ +/// +/// RNF-Swift-Cxx-Umbrella.hpp +/// Mon Aug 19 2024 +/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. +/// https://github.com/mrousavy/react-native-nitro +/// Copyright © 2024 Marc Rousavy @ Margelo +/// + +#pragma once + +// Forward declarations of C++ defined types + + +// Include C++ defined types + + +// C++ helpers for Swift +#include "RNF-Swift-Cxx-Bridge.hpp" + +// Common Swift bridges for C++ types +#include +#include + +// Forward declarations of Swift defined types + + +// Include Swift defined types +#if __has_include("RNF-Swift.h") +// This header is generated by Xcode/Swift on every app build. +// If it cannot be found, make sure the Swift module's name (= podspec name) is actually "RNF". +#include "RNF-Swift.h" +#else +#error RNF's autogenerated Swift header cannot be found! Make sure the Swift module's name (= podspec name) is actually "RNF", and try building the app first. +#endif diff --git a/package/nitrogen/generated/shared/c++/HybridSwapChainSpec.cpp b/package/nitrogen/generated/shared/c++/HybridSwapChainSpec.cpp index a26d1135..b0323edd 100644 --- a/package/nitrogen/generated/shared/c++/HybridSwapChainSpec.cpp +++ b/package/nitrogen/generated/shared/c++/HybridSwapChainSpec.cpp @@ -1,6 +1,6 @@ /// /// HybridSwapChainSpec.cpp -/// Mon Aug 05 2024 +/// Mon Aug 19 2024 /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. /// https://github.com/mrousavy/react-native-nitro /// Copyright © 2024 Marc Rousavy @ Margelo @@ -14,7 +14,9 @@ namespace margelo::nitro::RNF { // load base methods/properties HybridObject::loadHybridMethods(); // load custom methods/properties - + registerHybrids(this, [](Prototype& prototype) { + prototype.registerHybridMethod("release", &HybridSwapChainSpec::release); + }); } } // namespace margelo::nitro::RNF diff --git a/package/nitrogen/generated/shared/c++/HybridSwapChainSpec.hpp b/package/nitrogen/generated/shared/c++/HybridSwapChainSpec.hpp index e9f34327..71568a7f 100644 --- a/package/nitrogen/generated/shared/c++/HybridSwapChainSpec.hpp +++ b/package/nitrogen/generated/shared/c++/HybridSwapChainSpec.hpp @@ -1,6 +1,6 @@ /// /// HybridSwapChainSpec.hpp -/// Mon Aug 05 2024 +/// Mon Aug 19 2024 /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE. /// https://github.com/mrousavy/react-native-nitro /// Copyright © 2024 Marc Rousavy @ Margelo @@ -46,7 +46,7 @@ namespace margelo::nitro::RNF { public: // Methods - + virtual void release() = 0; protected: // Hybrid Setup diff --git a/package/package.json b/package/package.json index f7c3f068..edbd2dfd 100644 --- a/package/package.json +++ b/package/package.json @@ -41,6 +41,7 @@ "build-bullet3": "scripts/build-bullet3.sh", "release": "yarn build-filament:release && yarn build-bullet3 && release-it && npm publish", "codegen": "react-native codegen", + "nitrogen": "nitro-codegen", "prepack": "cp ../README.md ./README.md", "postpack": "rm ./README.md" }, @@ -81,7 +82,7 @@ "registry": "https://registry.npmjs.org/" }, "dependencies": { - "react-native-nitro-modules": "^0.1.3" + "react-native-nitro-modules": "^0.5.0" }, "devDependencies": { "@jamesacarr/eslint-formatter-github-actions": "^0.2.0", @@ -91,7 +92,7 @@ "eslint": "^8.51.0", "eslint-config-prettier": "^9.0.0", "eslint-plugin-prettier": "^5.0.1", - "nitro-codegen": "^0.1.3", + "nitro-codegen": "^0.5.0", "prettier": "^3.0.3", "react": "18.2.0", "react-native": "0.74.1", diff --git a/package/src/specs/SwapChain.nitro.ts b/package/src/specs/SwapChain.nitro.ts index b0af7d64..d6372218 100644 --- a/package/src/specs/SwapChain.nitro.ts +++ b/package/src/specs/SwapChain.nitro.ts @@ -1,3 +1,6 @@ import { type HybridObject } from 'react-native-nitro-modules' -export interface SwapChain extends HybridObject<{ android: 'c++'; ios: 'c++' }> {} +export interface SwapChain extends HybridObject<{ android: 'c++'; ios: 'c++' }> { + // TODO: Inheritance is not yet supported by nitrogen + release(): void +} diff --git a/package/yarn.lock b/package/yarn.lock index b6058fad..098e67f7 100644 --- a/package/yarn.lock +++ b/package/yarn.lock @@ -9574,17 +9574,18 @@ __metadata: languageName: node linkType: hard -"nitro-codegen@npm:^0.1.3": - version: 0.1.3 - resolution: "nitro-codegen@npm:0.1.3" +"nitro-codegen@npm:^0.5.0": + version: 0.5.0 + resolution: "nitro-codegen@npm:0.5.0" dependencies: chalk: ^5.3.0 - react-native-nitro-modules: ^0.0.7 + react-native-nitro-modules: ^0.5.0 ts-morph: ^23.0.0 + yargs: ^17.7.2 zod: ^3.23.8 bin: nitro-codegen: lib/index.js - checksum: f6bb85254daf07ef7994a0ab3459eedd6fa7dbb0e413e6dc27a7aae905d609445d6b25a6e77a64b74fa25ef82b25eec3852b1b1c69af37a29e0199aa63a45ffa + checksum: 1eeec973638300bb509cf529b2a5ecf16fbe86f59f965fa649024c5a46ad3de95f293879c787b16331aa24581ddfdba2dc1469a5a7a024adad76dc3f084ba960 languageName: node linkType: hard @@ -10156,7 +10157,7 @@ __metadata: babel-plugin-module-resolver: ^5.0.0 react-native: 0.74.1 react-native-gesture-handler: ^2.16.2 - react-native-nitro-modules: ^0.1.3 + react-native-nitro-modules: ^0.5.0 react-native-reanimated: ^3.11.0 react-native-safe-area-context: ^4.10.1 react-native-screens: ^3.31.1 @@ -10747,12 +10748,12 @@ __metadata: eslint: ^8.51.0 eslint-config-prettier: ^9.0.0 eslint-plugin-prettier: ^5.0.1 - nitro-codegen: ^0.1.3 + nitro-codegen: ^0.5.0 prettier: ^3.0.3 react: 18.2.0 react-native: 0.74.1 react-native-builder-bob: ^0.20.0 - react-native-nitro-modules: ^0.1.3 + react-native-nitro-modules: ^0.5.0 react-native-worklets-core: ^2.0.0-beta.4 release-it: ^15.0.0 typescript: ^5.2.2 @@ -10779,23 +10780,13 @@ __metadata: languageName: node linkType: hard -"react-native-nitro-modules@npm:^0.0.7": - version: 0.0.7 - resolution: "react-native-nitro-modules@npm:0.0.7" - peerDependencies: - react: "*" - react-native: "*" - checksum: 7389dca0f30daa282356631614a8a87afbed83800b76b6fdd1c2dc91c662fa69ba7022a0f42a7937ce9b5022cd3d07b32dcd2f3b5a1f25bb0813955f627147e0 - languageName: node - linkType: hard - -"react-native-nitro-modules@npm:^0.1.3": - version: 0.1.3 - resolution: "react-native-nitro-modules@npm:0.1.3" +"react-native-nitro-modules@npm:^0.5.0": + version: 0.5.0 + resolution: "react-native-nitro-modules@npm:0.5.0" peerDependencies: react: "*" react-native: "*" - checksum: 2dd1e292a786b0b909e5b82cde28f6bb6a1930cd74f803995c1de2bb584f9b2fb8b9546361f1ddc9cbc0bc6f8fc99f48ff1a5697475e9fd4b79da561822d1b93 + checksum: 17b100320c14f6d2fcf4e2b36299b5e0d8af42719b3baca4236fc971b416b43f9c0001e019035080e1448eb09e763099b28009f2be4c8af254cd6cfa6339aa2c languageName: node linkType: hard @@ -13223,7 +13214,7 @@ __metadata: languageName: node linkType: hard -"yargs@npm:^17.5.1, yargs@npm:^17.6.2": +"yargs@npm:^17.5.1, yargs@npm:^17.6.2, yargs@npm:^17.7.2": version: 17.7.2 resolution: "yargs@npm:17.7.2" dependencies: From 2b39aea4051149bf13659fb3e1ae8e0738432402 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hanno=20J=2E=20G=C3=B6decke?= Date: Mon, 19 Aug 2024 13:45:43 +0200 Subject: [PATCH 3/3] hm, not working yet --- package/cpp/RNFFilamentProxy.cpp | 30 ++--- package/cpp/RNFFilamentProxy.h | 10 +- package/cpp/RNFFilamentRecorder.h | 6 +- package/cpp/RNFSurface.h | 2 +- package/cpp/RNFSurfaceProvider.h | 6 +- package/cpp/bullet/RNFRigidBodyWrapper.h | 2 +- package/cpp/core/RNFAABBWrapper.h | 2 +- .../core/RNFAmbientOcclusionOptionsWrapper.h | 2 +- .../cpp/core/RNFDynamicResolutionOptions.h | 2 +- package/cpp/core/RNFEngineImpl.h | 4 +- package/cpp/core/RNFEngineWrapper.cpp | 4 +- package/cpp/core/RNFFilamentInstanceWrapper.h | 2 +- package/cpp/core/RNFRenderableManagerImpl.cpp | 8 +- package/cpp/core/RNFSwapChainWrapper.h | 16 +-- package/cpp/core/math/RNFTMat44Wrapper.h | 2 +- package/cpp/core/utils/RNFEntityWrapper.h | 2 +- package/cpp/jsi/RNFHybridObject.h | 8 +- package/cpp/jsi/RNFJSIConverter.h | 32 +++--- package/cpp/jsi/RNFPointerHolder.h | 6 +- package/cpp/jsi/RNFPointerHolderNitro.h | 106 ++++++++++++++++++ package/cpp/jsi/RNFPromiseFactory.h | 2 +- package/cpp/test/RNFTestHybridObject.h | 2 +- .../cpp/threading/RNFCallInvokerDispatcher.h | 4 +- package/ios/src/RNFAppleDispatcher.h | 2 +- package/ios/src/RNFAppleFilamentProxy.h | 18 +-- package/ios/src/RNFAppleFilamentProxy.mm | 12 +- package/ios/src/RNFAppleFilamentRecorder.h | 2 +- package/ios/src/RNFFilamentInstaller.mm | 4 +- package/ios/src/RNFNSThreadDispatcher.h | 2 +- .../shared/c++/HybridSwapChainSpec.cpp | 1 + .../shared/c++/HybridSwapChainSpec.hpp | 2 +- package/src/react/FilamentView.tsx | 1 + package/src/specs/SwapChain.nitro.ts | 2 +- 33 files changed, 208 insertions(+), 98 deletions(-) create mode 100644 package/cpp/jsi/RNFPointerHolderNitro.h diff --git a/package/cpp/RNFFilamentProxy.cpp b/package/cpp/RNFFilamentProxy.cpp index c881994d..b5d7bf3b 100644 --- a/package/cpp/RNFFilamentProxy.cpp +++ b/package/cpp/RNFFilamentProxy.cpp @@ -45,18 +45,18 @@ bool FilamentProxy::getHasWorklets() { #if HAS_WORKLETS std::shared_ptr FilamentProxy::createWorkletContext() { - Logger::log(TAG, "Creating Worklet Context..."); + margelo::Logger::log(TAG, "Creating Worklet Context..."); auto jsDispatcher = getJSDispatcher(); auto runOnJS = [=](std::function&& function) { jsDispatcher->runAsync(std::move(function)); }; auto renderThreadDispatcher = getRenderThreadDispatcher(); auto runOnWorklet = [=](std::function&& function) { renderThreadDispatcher->runAsync(std::move(function)); }; auto& runtime = getMainJSRuntime(); auto workletContext = std::make_shared("FilamentRenderer", &runtime, runOnJS, runOnWorklet); - Logger::log(TAG, "Successfully created WorkletContext! Installing global Dispatcher..."); + margelo::Logger::log(TAG, "Successfully created WorkletContext! Installing global Dispatcher..."); workletContext->invokeOnWorkletThread([=](RNWorklet::JsiWorkletContext*, jsi::Runtime& runtime) { - Dispatcher::installRuntimeGlobalDispatcher(runtime, renderThreadDispatcher); - Logger::log(TAG, "Successfully installed global Dispatcher in WorkletContext!"); + margelo::Dispatcher::installRuntimeGlobalDispatcher(runtime, renderThreadDispatcher); + margelo::Logger::log(TAG, "Successfully installed global Dispatcher in WorkletContext!"); }); return workletContext; @@ -64,11 +64,11 @@ std::shared_ptr FilamentProxy::createWorkletContex #endif jsi::Value FilamentProxy::getCurrentDispatcher(jsi::Runtime& runtime, const jsi::Value&, const jsi::Value*, size_t) { - return Dispatcher::getRuntimeGlobalDispatcherHolder(runtime); + return margelo::Dispatcher::getRuntimeGlobalDispatcherHolder(runtime); } std::future> FilamentProxy::loadAssetAsync(const std::string& path) { - Logger::log(TAG, "Loading asset %s...", path.c_str()); + margelo::Logger::log(TAG, "Loading asset %s...", path.c_str()); auto weakThis = std::weak_ptr(shared()); auto dispatcher = getBackgroundDispatcher(); return dispatcher->runAsyncAwaitable>([weakThis, path]() { @@ -82,7 +82,7 @@ std::future> FilamentProxy::loadAssetAsync(const } std::future> FilamentProxy::findFilamentViewAsync(int id) { - Logger::log(TAG, "Finding FilamentView #%i...", id); + margelo::Logger::log(TAG, "Finding FilamentView #%i...", id); auto weakThis = std::weak_ptr(shared()); auto dispatcher = getUIDispatcher(); return dispatcher->runAsyncAwaitable>([weakThis, id]() { @@ -96,15 +96,15 @@ std::future> FilamentProxy::findFilamentViewAsync( } std::shared_ptr FilamentProxy::createTestObject() { - Logger::log(TAG, "Creating TestObject..."); + margelo::Logger::log(TAG, "Creating TestObject..."); return std::make_shared(); } std::shared_ptr FilamentProxy::createEngine(std::optional backend, std::optional> arguments) { - Logger::log(TAG, "Creating Engine..."); + margelo::Logger::log(TAG, "Creating Engine..."); - std::shared_ptr renderThread = getRenderThreadDispatcher(); + std::shared_ptr renderThread = getRenderThreadDispatcher(); Engine::Config config = EngineConfigHelper::makeConfigFromUserParams(arguments); Engine::Backend backendEnum = Engine::Backend::DEFAULT; @@ -118,14 +118,14 @@ std::shared_ptr FilamentProxy::createEngine(std::optionalrunAsync([engine]() { - Logger::log(TAG, "Destroying engine..."); + margelo::Logger::log(TAG, "Destroying engine..."); Engine::destroy(engine); }); }); // Get screen refresh rate float refreshRate = getDisplayRefreshRate(); - Logger::log(TAG, "Display refresh rate: %f Hz", refreshRate); + margelo::Logger::log(TAG, "Display refresh rate: %f Hz", refreshRate); float densityPixelRatio = getDensityPixelRatio(); @@ -136,13 +136,13 @@ std::shared_ptr FilamentProxy::createEngine(std::optional FilamentProxy::createBullet() { - Logger::log(TAG, "Creating Bullet..."); + margelo::Logger::log(TAG, "Creating Bullet..."); return std::make_shared(); } jsi::Value FilamentProxy::createChoreographerWrapper(jsi::Runtime& runtime, const jsi::Value&, const jsi::Value*, size_t) { - Logger::log(TAG, "Creating Choreographer..."); + margelo::Logger::log(TAG, "Creating Choreographer..."); std::shared_ptr choreographer = createChoreographer(); ChoreographerWrapper* choreographerWrapperPtr = new ChoreographerWrapper(choreographer); @@ -157,7 +157,7 @@ jsi::Value FilamentProxy::createChoreographerWrapper(jsi::Runtime& runtime, cons delete ptr; }); - return JSIConverter>::toJSI(runtime, choreographerWrapper); + return margelo::JSIConverter>::toJSI(runtime, choreographerWrapper); } } // namespace margelo diff --git a/package/cpp/RNFFilamentProxy.h b/package/cpp/RNFFilamentProxy.h index 6cf84b00..7fd9eb81 100644 --- a/package/cpp/RNFFilamentProxy.h +++ b/package/cpp/RNFFilamentProxy.h @@ -37,7 +37,7 @@ namespace margelo { using namespace facebook; -class FilamentProxy : public HybridObject { +class FilamentProxy : public margelo::HybridObject { public: explicit FilamentProxy() : HybridObject(TAG) {} @@ -51,22 +51,22 @@ class FilamentProxy : public HybridObject { /** * Get the Dispatcher for the main react JS thread. */ - virtual std::shared_ptr getJSDispatcher() = 0; + virtual std::shared_ptr getJSDispatcher() = 0; /** * Get the Dispatcher that is responsible for rendering to Filament. * This is guaranteed to only use a single Thread, as opposed to a Thread-pool. */ - virtual std::shared_ptr getRenderThreadDispatcher() = 0; + virtual std::shared_ptr getRenderThreadDispatcher() = 0; /** * Get the Dispatcher for the platform-default UI Thread. * This is guaranteed to only use a single Thread, as opposed to a Thread-pool. */ - virtual std::shared_ptr getUIDispatcher() = 0; + virtual std::shared_ptr getUIDispatcher() = 0; /** * Get a Dispatcher that uses a Thread-pool for background operations such as File I/O. * This Dispatcher may use multiple Threads to run code. */ - virtual std::shared_ptr getBackgroundDispatcher() = 0; + virtual std::shared_ptr getBackgroundDispatcher() = 0; /** * Get the refresh rate of the display in Hz. * Needed for correct frame pacing and dynamic resolution calculations. diff --git a/package/cpp/RNFFilamentRecorder.h b/package/cpp/RNFFilamentRecorder.h index fd5e1762..f4d880d1 100644 --- a/package/cpp/RNFFilamentRecorder.h +++ b/package/cpp/RNFFilamentRecorder.h @@ -18,12 +18,12 @@ namespace margelo { using namespace facebook; -class FilamentRecorder : public HybridObject { +class FilamentRecorder : public margelo::HybridObject { public: using ReadyForMoreDataCallback = std::function; public: - explicit FilamentRecorder(std::shared_ptr renderThreadDispatcher, int width, int height, int fps, double bitRate); + explicit FilamentRecorder(std::shared_ptr renderThreadDispatcher, int width, int height, int fps, double bitRate); ~FilamentRecorder(); public: @@ -77,7 +77,7 @@ class FilamentRecorder : public HybridObject { static constexpr auto TAG = "FilamentRecorder"; protected: - std::shared_ptr _renderThreadDispatcher; + std::shared_ptr _renderThreadDispatcher; int _width; int _height; int _fps; diff --git a/package/cpp/RNFSurface.h b/package/cpp/RNFSurface.h index 3e04f2e2..a5c0b221 100644 --- a/package/cpp/RNFSurface.h +++ b/package/cpp/RNFSurface.h @@ -10,7 +10,7 @@ namespace margelo { -class Surface : public HybridObject { +class Surface : public margelo::HybridObject { public: explicit Surface() : HybridObject("Surface") {} diff --git a/package/cpp/RNFSurfaceProvider.h b/package/cpp/RNFSurfaceProvider.h index 9b5c1c93..78f00369 100644 --- a/package/cpp/RNFSurfaceProvider.h +++ b/package/cpp/RNFSurfaceProvider.h @@ -15,7 +15,7 @@ namespace margelo { -class SurfaceProvider : public HybridObject { +class SurfaceProvider : public margelo::HybridObject { public: using TOnCreate = std::function surface)>; using TOnResize = std::function surface, int width, int height)>; @@ -32,8 +32,8 @@ class SurfaceProvider : public HybridObject { public: std::shared_ptr addOnSurfaceChangedListener(Callbacks&& callbacks); - std::shared_ptr addOnSurfaceCreatedListener(TOnCreate callback, std::shared_ptr dispatcher); - std::shared_ptr addOnSurfaceDestroyedListener(TOnDestroy callback, std::shared_ptr dispatcher); + std::shared_ptr addOnSurfaceCreatedListener(TOnCreate callback, std::shared_ptr dispatcher); + std::shared_ptr addOnSurfaceDestroyedListener(TOnDestroy callback, std::shared_ptr dispatcher); virtual std::shared_ptr getSurfaceOrNull() = 0; std::optional> getSurface(); diff --git a/package/cpp/bullet/RNFRigidBodyWrapper.h b/package/cpp/bullet/RNFRigidBodyWrapper.h index a01161d1..fe8710f3 100644 --- a/package/cpp/bullet/RNFRigidBodyWrapper.h +++ b/package/cpp/bullet/RNFRigidBodyWrapper.h @@ -21,7 +21,7 @@ class RigidBodyWrapper; */ using CollisionCallback = std::function&, const std::shared_ptr)>; -class RigidBodyWrapper : public HybridObject { +class RigidBodyWrapper : public margelo::HybridObject { public: explicit RigidBodyWrapper(double mass, std::shared_ptr shape, std::unique_ptr motionState, std::string id, std::optional collisionCallback); diff --git a/package/cpp/core/RNFAABBWrapper.h b/package/cpp/core/RNFAABBWrapper.h index 0c3fc8a7..65eb2e3d 100644 --- a/package/cpp/core/RNFAABBWrapper.h +++ b/package/cpp/core/RNFAABBWrapper.h @@ -11,7 +11,7 @@ namespace margelo { using namespace filament; -class AABBWrapper : public HybridObject { +class AABBWrapper : public margelo::HybridObject { public: explicit AABBWrapper(const Aabb& aabb) : HybridObject("AABBWrapper"), _aabb(aabb) {} void loadHybridMethods() override; diff --git a/package/cpp/core/RNFAmbientOcclusionOptionsWrapper.h b/package/cpp/core/RNFAmbientOcclusionOptionsWrapper.h index 2cc83612..88635ce7 100644 --- a/package/cpp/core/RNFAmbientOcclusionOptionsWrapper.h +++ b/package/cpp/core/RNFAmbientOcclusionOptionsWrapper.h @@ -12,7 +12,7 @@ namespace margelo { using namespace filament; -class AmbientOcclusionOptionsWrapper : public HybridObject, public AmbientOcclusionOptions { +class AmbientOcclusionOptionsWrapper : public margelo::HybridObject, public AmbientOcclusionOptions { public: explicit AmbientOcclusionOptionsWrapper() : HybridObject("AmbientOcclusionOptionsWrapper") {} explicit AmbientOcclusionOptionsWrapper(const AmbientOcclusionOptions& options) diff --git a/package/cpp/core/RNFDynamicResolutionOptions.h b/package/cpp/core/RNFDynamicResolutionOptions.h index b01b2c8f..90c9ff7f 100644 --- a/package/cpp/core/RNFDynamicResolutionOptions.h +++ b/package/cpp/core/RNFDynamicResolutionOptions.h @@ -12,7 +12,7 @@ namespace margelo { using namespace filament; -class DynamicResolutionOptionsWrapper : public HybridObject, public DynamicResolutionOptions { +class DynamicResolutionOptionsWrapper : public margelo::HybridObject, public DynamicResolutionOptions { public: explicit DynamicResolutionOptionsWrapper() : HybridObject("DynamicResolutionOptions") {} explicit DynamicResolutionOptionsWrapper(const DynamicResolutionOptions& options) diff --git a/package/cpp/core/RNFEngineImpl.h b/package/cpp/core/RNFEngineImpl.h index 4a42677a..9aef57a7 100644 --- a/package/cpp/core/RNFEngineImpl.h +++ b/package/cpp/core/RNFEngineImpl.h @@ -45,7 +45,7 @@ using ManipulatorBuilder = Manipulator::Builder; // If you add a new method that you want to expose to JS, you need to add it to the EngineWrapper as well. class EngineImpl : public std::enable_shared_from_this { public: - explicit EngineImpl(std::shared_ptr rendererDispatcher, std::shared_ptr engine, float displayRefreshRate, + explicit EngineImpl(std::shared_ptr rendererDispatcher, std::shared_ptr engine, float displayRefreshRate, float densityPixelRatio); // First a surface provider must be set, then once we have a surface a swapchain can be created and finally the swapchain can be set @@ -73,7 +73,7 @@ class EngineImpl : public std::enable_shared_from_this { private: std::mutex _mutex; std::shared_ptr _engine; - std::shared_ptr _rendererDispatcher; + std::shared_ptr _rendererDispatcher; std::shared_ptr _surfaceProvider; std::shared_ptr _surfaceListener; std::shared_ptr _materialProvider; diff --git a/package/cpp/core/RNFEngineWrapper.cpp b/package/cpp/core/RNFEngineWrapper.cpp index 5960f930..bcc4273b 100644 --- a/package/cpp/core/RNFEngineWrapper.cpp +++ b/package/cpp/core/RNFEngineWrapper.cpp @@ -60,7 +60,7 @@ void EngineWrapper::setSurfaceProvider(std::shared_ptr surfaceP } std::shared_ptr EngineWrapper::createSwapChainForSurface(std::shared_ptr surfaceProvider, bool enableTransparentRendering) { - Logger::log(TAG, "Creating swapchain for surface ..."); + margelo::Logger::log(TAG, "Creating swapchain for surface ..."); std::shared_ptr surface = surfaceProvider->getSurfaceOrNull(); if (surface == nullptr) { @@ -74,7 +74,7 @@ std::shared_ptr EngineWrapper::createSwapChainForSurface(std:: return std::make_shared(swapChain); } std::shared_ptr EngineWrapper::createSwapChainForRecorder(std::shared_ptr recorder) { - Logger::log(TAG, "Creating swapchain for recorder ..."); + margelo::Logger::log(TAG, "Creating swapchain for recorder ..."); if (recorder == nullptr) { throw std::invalid_argument("Recorder is null"); diff --git a/package/cpp/core/RNFFilamentInstanceWrapper.h b/package/cpp/core/RNFFilamentInstanceWrapper.h index 51a0b13c..83369c0c 100644 --- a/package/cpp/core/RNFFilamentInstanceWrapper.h +++ b/package/cpp/core/RNFFilamentInstanceWrapper.h @@ -18,7 +18,7 @@ using namespace gltfio; class AnimatorWrapper; -class FilamentInstanceWrapper : public HybridObject { +class FilamentInstanceWrapper : public margelo::HybridObject { public: explicit FilamentInstanceWrapper(FilamentInstance* instance) : HybridObject("FilamentInstanceWrapper"), _instance(instance) {} diff --git a/package/cpp/core/RNFRenderableManagerImpl.cpp b/package/cpp/core/RNFRenderableManagerImpl.cpp index fd7d57ba..4e2ef1bf 100644 --- a/package/cpp/core/RNFRenderableManagerImpl.cpp +++ b/package/cpp/core/RNFRenderableManagerImpl.cpp @@ -94,7 +94,7 @@ Texture* RenderableManagerImpl::createTextureFromBuffer(std::shared_ptrgetPushMessage(); - Logger::log(TAG, "Error loading texture: %s", error.c_str()); + margelo::Logger::log(TAG, "Error loading texture: %s", error.c_str()); throw std::runtime_error("Error loading texture: " + error); } @@ -143,7 +143,7 @@ void RenderableManagerImpl::changeMaterialTextureMap(std::shared_ptr newInstance = std::shared_ptr(MaterialInstance::duplicate(materialInstance), [engine, dispatcher](MaterialInstance* instance) { dispatcher->runAsync([engine, instance]() { - Logger::log(TAG, "Destroying material instance %p", instance); + margelo::Logger::log(TAG, "Destroying material instance %p", instance); engine->destroy(instance); }); }); @@ -166,7 +166,7 @@ void RenderableManagerImpl::startUpdateResourceLoading() { // Check for textures that now have all their miplevels initialized. while (Texture* _texture = _textureProvider->popTexture()) { - Logger::log(TAG, "%p has all its miplevels ready.", _texture); + margelo::Logger::log(TAG, "%p has all its miplevels ready.", _texture); } } } @@ -282,7 +282,7 @@ void RenderableManagerImpl::scaleBoundingBox(std::shared_ptr @@ -8,19 +9,20 @@ namespace margelo { using namespace filament; using namespace nitro::RNF; -class SwapChainWrapper : public HybridSwapChainSpec { +class SwapChainWrapper : public HybridSwapChainSpec, public PointerHolderNitro { public: - explicit SwapChainWrapper(std::shared_ptr swapChain) : _swapChain(swapChain) {} + explicit SwapChainWrapper(std::shared_ptr swapChain) : HybridSwapChainSpec(), PointerHolderNitro(HybridSwapChainSpec::TAG, swapChain) {} std::shared_ptr getSwapChain() { - return _swapChain; + return pointee(); } - size_t getExternalMemorySize() noexcept override { - return sizeof(std::shared_ptr); + bool getIsValid() override { + return PointerHolderNitro::getIsValid(); } -private: - std::shared_ptr _swapChain; + void release() override { + PointerHolderNitro::release(); + } }; } // namespace margelo diff --git a/package/cpp/core/math/RNFTMat44Wrapper.h b/package/cpp/core/math/RNFTMat44Wrapper.h index 55584b63..bb067926 100644 --- a/package/cpp/core/math/RNFTMat44Wrapper.h +++ b/package/cpp/core/math/RNFTMat44Wrapper.h @@ -10,7 +10,7 @@ namespace margelo { using namespace filament; -class TMat44Wrapper : public HybridObject { +class TMat44Wrapper : public margelo::HybridObject { public: explicit TMat44Wrapper(math::mat4f matrix) : HybridObject("TMat44Wrapper"), _matrix(matrix) {} diff --git a/package/cpp/core/utils/RNFEntityWrapper.h b/package/cpp/core/utils/RNFEntityWrapper.h index a5743dc9..b3e79ce4 100644 --- a/package/cpp/core/utils/RNFEntityWrapper.h +++ b/package/cpp/core/utils/RNFEntityWrapper.h @@ -11,7 +11,7 @@ namespace margelo { using namespace utils; using namespace filament; -class EntityWrapper : public HybridObject { +class EntityWrapper : public margelo::HybridObject { public: explicit EntityWrapper(Entity entity) : HybridObject("EntityWrapper"), _entity(entity) {} explicit EntityWrapper(const VertexEntity& vertexEntity) diff --git a/package/cpp/jsi/RNFHybridObject.h b/package/cpp/jsi/RNFHybridObject.h index ef6d81b0..ed6b0e86 100644 --- a/package/cpp/jsi/RNFHybridObject.h +++ b/package/cpp/jsi/RNFHybridObject.h @@ -18,7 +18,7 @@ namespace margelo { using namespace facebook; -class HybridObject : public jsi::HostObject, public std::enable_shared_from_this { +class HybridObject : public jsi::HostObject, public std::enable_shared_from_this { public: struct HybridFunction { jsi::HostFunctionType function; @@ -84,12 +84,12 @@ class HybridObject : public jsi::HostObject, public std::enable_shared_from_this std::index_sequence) { if constexpr (std::is_same_v) { // It's a void method. - (obj->*method)(JSIConverter>::fromJSI(runtime, args[Is])...); + (obj->*method)(margelo::JSIConverter>::fromJSI(runtime, args[Is])...); return jsi::Value::undefined(); } else { // It's returning some C++ type, we need to convert that to a JSI value now. - ReturnType result = (obj->*method)(JSIConverter>::fromJSI(runtime, args[Is])...); - return JSIConverter>::toJSI(runtime, std::move(result)); + ReturnType result = (obj->*method)(margelo::JSIConverter>::fromJSI(runtime, args[Is])...); + return margelo::JSIConverter>::toJSI(runtime, std::move(result)); } } diff --git a/package/cpp/jsi/RNFJSIConverter.h b/package/cpp/jsi/RNFJSIConverter.h index 686003f0..36269569 100644 --- a/package/cpp/jsi/RNFJSIConverter.h +++ b/package/cpp/jsi/RNFJSIConverter.h @@ -42,7 +42,7 @@ template struct JSIConverter { }; // int <> number -template <> struct JSIConverter { +template <> struct margelo::JSIConverter { static int fromJSI(jsi::Runtime&, const jsi::Value& arg) { return static_cast(arg.asNumber()); } @@ -52,7 +52,7 @@ template <> struct JSIConverter { }; // double <> number -template <> struct JSIConverter { +template <> struct margelo::JSIConverter { static double fromJSI(jsi::Runtime&, const jsi::Value& arg) { return arg.asNumber(); } @@ -62,7 +62,7 @@ template <> struct JSIConverter { }; // float <> number -template <> struct JSIConverter { +template <> struct margelo::JSIConverter { static float fromJSI(jsi::Runtime&, const jsi::Value& arg) { return static_cast(arg.asNumber()); } @@ -72,7 +72,7 @@ template <> struct JSIConverter { }; // int64_t <> BigInt -template <> struct JSIConverter { +template <> struct margelo::JSIConverter { static double fromJSI(jsi::Runtime& runtime, const jsi::Value& arg) { return arg.asBigInt(runtime).asInt64(runtime); } @@ -82,7 +82,7 @@ template <> struct JSIConverter { }; // uint64_t <> BigInt -template <> struct JSIConverter { +template <> struct margelo::JSIConverter { static double fromJSI(jsi::Runtime& runtime, const jsi::Value& arg) { return arg.asBigInt(runtime).asUint64(runtime); } @@ -92,7 +92,7 @@ template <> struct JSIConverter { }; // bool <> boolean -template <> struct JSIConverter { +template <> struct margelo::JSIConverter { static bool fromJSI(jsi::Runtime&, const jsi::Value& arg) { return arg.asBool(); } @@ -102,7 +102,7 @@ template <> struct JSIConverter { }; // std::string <> string -template <> struct JSIConverter { +template <> struct margelo::JSIConverter { static std::string fromJSI(jsi::Runtime& runtime, const jsi::Value& arg) { return arg.asString(runtime).utf8(runtime); } @@ -112,7 +112,7 @@ template <> struct JSIConverter { }; // std::optional <> T | undefined -template struct JSIConverter> { +template struct margelo::JSIConverter> { static std::optional fromJSI(jsi::Runtime& runtime, const jsi::Value& arg) { if (arg.isUndefined() || arg.isNull()) { return std::nullopt; @@ -130,7 +130,7 @@ template struct JSIConverter> { }; // Enum <> Union -template struct JSIConverter::value>> { +template struct margelo::JSIConverter::value>> { static TEnum fromJSI(jsi::Runtime& runtime, const jsi::Value& arg) { std::string string = arg.asString(runtime).utf8(runtime); TEnum outEnum; @@ -145,7 +145,7 @@ template struct JSIConverter <> Promise -template struct JSIConverter> { +template struct margelo::JSIConverter> { static std::future fromJSI(jsi::Runtime&, const jsi::Value&) { throw std::runtime_error("Promise cannot be converted to a native type - it needs to be awaited first!"); } @@ -153,7 +153,7 @@ template struct JSIConverter> { auto sharedFuture = std::make_shared>(std::move(arg)); return PromiseFactory::createPromise(runtime, [sharedFuture = std::move(sharedFuture)](jsi::Runtime& runtime, std::shared_ptr promise, - std::shared_ptr dispatcher) { + std::shared_ptr dispatcher) { // Spawn new async thread to wait for the result std::thread waiterThread([promise, &runtime, dispatcher, sharedFuture = std::move(sharedFuture)]() { // wait until the future completes. we are running on a background task here. @@ -198,7 +198,7 @@ template struct JSIConverter> { }; // [](Args...) -> T {} <> (Args...) => T -template struct JSIConverter> { +template struct margelo::JSIConverter> { static std::function fromJSI(jsi::Runtime& runtime, const jsi::Value& arg) { jsi::Function function = arg.asObject(runtime).asFunction(runtime); @@ -243,7 +243,7 @@ template struct JSIConverter <> T[] -template struct JSIConverter> { +template struct margelo::JSIConverter> { static std::vector fromJSI(jsi::Runtime& runtime, const jsi::Value& arg) { jsi::Array array = arg.asObject(runtime).asArray(runtime); size_t length = array.size(runtime); @@ -267,7 +267,7 @@ template struct JSIConverter> { }; // std::unordered_map <> Record -template struct JSIConverter> { +template struct margelo::JSIConverter> { static std::unordered_map fromJSI(jsi::Runtime& runtime, const jsi::Value& arg) { jsi::Object object = arg.asObject(runtime); jsi::Array propertyNames = object.getPropertyNames(runtime); @@ -298,7 +298,7 @@ template struct is_shared_ptr_to_host_object : std::false_type {}; template struct is_shared_ptr_to_host_object> : std::is_base_of {}; -template struct JSIConverter::value>> { +template struct margelo::JSIConverter::value>> { using TPointee = typename T::element_type; #if DEBUG @@ -358,7 +358,7 @@ template struct is_shared_ptr_to_native_state : std::false_type {}; template struct is_shared_ptr_to_native_state> : std::is_base_of {}; -template struct JSIConverter::value>> { +template struct margelo::JSIConverter::value>> { using TPointee = typename T::element_type; #if DEBUG diff --git a/package/cpp/jsi/RNFPointerHolder.h b/package/cpp/jsi/RNFPointerHolder.h index ce67fc00..e1f1144a 100644 --- a/package/cpp/jsi/RNFPointerHolder.h +++ b/package/cpp/jsi/RNFPointerHolder.h @@ -13,7 +13,7 @@ namespace margelo { using namespace facebook; -template class PointerHolder : public HybridObject { +template class PointerHolder : public margelo::HybridObject { protected: // no default constructor PointerHolder() = delete; @@ -42,7 +42,7 @@ template class PointerHolder : public HybridObject { */ ~PointerHolder() { if (_pointer != nullptr) { - Logger::log(TAG, "Automatically releasing %s... (~PointerHolder())", _name.c_str()); + margelo::Logger::log(TAG, "Automatically releasing %s... (~PointerHolder())", _name.c_str()); } } @@ -57,7 +57,7 @@ template class PointerHolder : public HybridObject { if (_pointer == nullptr) { throw std::runtime_error("Pointer " + _name + " has already been manually released!"); } - Logger::log(TAG, "Manually releasing %s... (PointerHolder::release())", _name.c_str()); + margelo::Logger::log(TAG, "Manually releasing %s... (PointerHolder::release())", _name.c_str()); _pointer = nullptr; } diff --git a/package/cpp/jsi/RNFPointerHolderNitro.h b/package/cpp/jsi/RNFPointerHolderNitro.h new file mode 100644 index 00000000..cf4b37fd --- /dev/null +++ b/package/cpp/jsi/RNFPointerHolderNitro.h @@ -0,0 +1,106 @@ +// +// Created by Marc Rousavy on 16.04.24. +// + +#pragma once + +#if __has_include() +#include +#else +#error NitroModules cannot be found! Are you sure you installed NitroModules properly? +#endif + +#include "RNFLogger.h" +#include +#include + +namespace margelo { + +using namespace facebook; + +template class PointerHolderNitro { +protected: + // no default constructor + PointerHolderNitro() = delete; + + /** + * Create a new instance of a pointer holder which holds the given shared_ptr. + * @param name The name of the implementing class, for example "ViewWrapper". + * @param pointer The pointer this class will hold. It might be released from JS at any point via `release()`. + */ + PointerHolderNitro(const char* name, std::shared_ptr pointer) : _name(name), _pointer(pointer) {} + + /** + * Create a new instance of a pointer holder which holds a shared_ptr of the given value. + * The shared_ptr will be move-constructed. + * @param name The name of the implementing class, for example "ViewWrapper". + * @param value The value this class will hold as a shared_ptr. It might be destroyed from JS at any point via `release()`. + */ + PointerHolderNitro(const char* name, T&& value) : PointerHolderNitro(name, std::make_shared(std::move(value))) {} + + /** + * Called when the PointerHolder gets automatically destroyed (e.g. via GC) and the shared_ptr will be destroyed. + */ + ~PointerHolderNitro() { + if (_pointer != nullptr) { + Logger::log(TAG, "Automatically releasing %s... (~PointerHolder())", _name.c_str()); + } + } + +protected: + /** + * Manually release this reference to the pointer. + * If there are any other references to this pointer, no memory will be force-deleted. + */ + virtual void release() { + std::unique_lock lock(_mutex); + + if (_pointer == nullptr) { + throw std::runtime_error("Pointer " + _name + " has already been manually released!"); + } + Logger::log(TAG, "Manually releasing %s... (PointerHolder::release())", _name.c_str()); + _pointer = nullptr; + } + + /** + * Get the shared_ptr this class is holding. + * If it has already been manually released from JS, this method will throw a runtime_error. + */ + std::shared_ptr pointee() { + std::unique_lock lock(_mutex); + + if (_pointer == nullptr) { + throw std::runtime_error("Pointer " + _name + " has already been manually released!"); + } + return _pointer; + } + + /** + * Get if the pointer is still valid and strong. + */ + bool getIsValid() { + std::unique_lock lock(_mutex); + + return _pointer != nullptr; + } + +protected: + // Hybrid Setup +// void loadHybridMethods() override { +// // load base methods/properties +// HybridObject::loadHybridMethods(); +// // load custom methods/properties +// registerHybrids(this, [](nitro::Prototype& prototype) { +// prototype.registerHybridMethod("release", &PointerHolderNitro::release); +// prototype.registerHybridGetter("isValid", &PointerHolderNitro::getIsValid); +// }); +// } + +private: + std::string _name; + std::shared_ptr _pointer; + std::mutex _mutex; + static constexpr auto TAG = "PointerHolder"; +}; + +} // namespace margelo diff --git a/package/cpp/jsi/RNFPromiseFactory.h b/package/cpp/jsi/RNFPromiseFactory.h index 2127d538..d4d55efb 100644 --- a/package/cpp/jsi/RNFPromiseFactory.h +++ b/package/cpp/jsi/RNFPromiseFactory.h @@ -16,7 +16,7 @@ namespace margelo { class PromiseFactory { public: - using RunPromise = std::function promise, std::shared_ptr dispatcher)>; + using RunPromise = std::function promise, std::shared_ptr dispatcher)>; /** Create a new promise and run the given function. diff --git a/package/cpp/test/RNFTestHybridObject.h b/package/cpp/test/RNFTestHybridObject.h index d3fa91d9..383c0165 100644 --- a/package/cpp/test/RNFTestHybridObject.h +++ b/package/cpp/test/RNFTestHybridObject.h @@ -12,7 +12,7 @@ namespace margelo { -class TestHybridObject : public HybridObject { +class TestHybridObject : public margelo::HybridObject { public: explicit TestHybridObject() : HybridObject("TestHybridObject") {} diff --git a/package/cpp/threading/RNFCallInvokerDispatcher.h b/package/cpp/threading/RNFCallInvokerDispatcher.h index e9a4fb1e..4bb22a60 100644 --- a/package/cpp/threading/RNFCallInvokerDispatcher.h +++ b/package/cpp/threading/RNFCallInvokerDispatcher.h @@ -14,7 +14,7 @@ using namespace facebook; /** * A Dispatcher that uses react::CallInvoker for it's implementation */ -class CallInvokerDispatcher : public Dispatcher { +class CallInvokerDispatcher : public margelo::Dispatcher { public: explicit CallInvokerDispatcher(std::shared_ptr callInvoker) : _callInvoker(callInvoker) {} @@ -30,4 +30,4 @@ class CallInvokerDispatcher : public Dispatcher { std::shared_ptr _callInvoker; }; -} // namespace margelo \ No newline at end of file +} // namespace margelo diff --git a/package/ios/src/RNFAppleDispatcher.h b/package/ios/src/RNFAppleDispatcher.h index 5d4ba918..c563afcd 100644 --- a/package/ios/src/RNFAppleDispatcher.h +++ b/package/ios/src/RNFAppleDispatcher.h @@ -15,7 +15,7 @@ namespace margelo { /** A [Dispatcher] implementation that uses iOS dispatch_queues to schedule calls. */ -class AppleDispatcher : public Dispatcher { +class AppleDispatcher : public margelo::Dispatcher { public: explicit AppleDispatcher(dispatch_queue_t dispatchQueue) : _dispatchQueue(dispatchQueue) {} diff --git a/package/ios/src/RNFAppleFilamentProxy.h b/package/ios/src/RNFAppleFilamentProxy.h index 3509742b..9646d15f 100644 --- a/package/ios/src/RNFAppleFilamentProxy.h +++ b/package/ios/src/RNFAppleFilamentProxy.h @@ -28,7 +28,7 @@ class AppleFilamentProxy : public FilamentProxy { explicit AppleFilamentProxy(jsi::Runtime* runtime, std::shared_ptr jsDispatcher, __weak RCTSurfacePresenter* surfacePresenter); #else - explicit AppleFilamentProxy(jsi::Runtime* runtime, std::shared_ptr jsDispatcher); + explicit AppleFilamentProxy(jsi::Runtime* runtime, std::shared_ptr jsDispatcher); #endif public: @@ -36,10 +36,10 @@ class AppleFilamentProxy : public FilamentProxy { std::shared_ptr findFilamentView(int modelId) override; std::shared_ptr createChoreographer() override; std::shared_ptr createRecorder(int width, int height, int fps, double bitRate) override; - std::shared_ptr getJSDispatcher() override; - std::shared_ptr getRenderThreadDispatcher() override; - std::shared_ptr getUIDispatcher() override; - std::shared_ptr getBackgroundDispatcher() override; + std::shared_ptr getJSDispatcher() override; + std::shared_ptr getRenderThreadDispatcher() override; + std::shared_ptr getUIDispatcher() override; + std::shared_ptr getBackgroundDispatcher() override; float getDisplayRefreshRate() override; float getDensityPixelRatio() override; @@ -48,10 +48,10 @@ class AppleFilamentProxy : public FilamentProxy { private: // The runtime the proxy has been installed on jsi::Runtime* _runtime; - std::shared_ptr _jsDispatcher; - std::shared_ptr _renderThreadDispatcher; - std::shared_ptr _uiDispatcher; - std::shared_ptr _backgroundDispatcher; + std::shared_ptr _jsDispatcher; + std::shared_ptr _renderThreadDispatcher; + std::shared_ptr _uiDispatcher; + std::shared_ptr _backgroundDispatcher; #ifdef RCT_NEW_ARCH_ENABLED __weak RCTSurfacePresenter* _surfacePresenter; #endif diff --git a/package/ios/src/RNFAppleFilamentProxy.mm b/package/ios/src/RNFAppleFilamentProxy.mm index 7923259e..52015161 100644 --- a/package/ios/src/RNFAppleFilamentProxy.mm +++ b/package/ios/src/RNFAppleFilamentProxy.mm @@ -32,7 +32,7 @@ __weak RCTSurfacePresenter* surfacePresenter) : _runtime(runtime), _jsDispatcher(jsDispatcher), _surfacePresenter(surfacePresenter) {} #else -AppleFilamentProxy::AppleFilamentProxy(jsi::Runtime* runtime, std::shared_ptr jsDispatcher) +AppleFilamentProxy::AppleFilamentProxy(jsi::Runtime* runtime, std::shared_ptr jsDispatcher) : _runtime(runtime), _jsDispatcher(jsDispatcher) {} #endif @@ -40,7 +40,7 @@ NSString* filePath = [NSString stringWithUTF8String:path.c_str()]; // Check if its a web uri, if so load using NSData if ([filePath hasPrefix:@"http://"] || [filePath hasPrefix:@"https://"]) { - Logger::log(TAG, "Fetching %s...", [filePath cStringUsingEncoding:NSUTF8StringEncoding]); + margelo::Logger::log(TAG, "Fetching %s...", [filePath cStringUsingEncoding:NSUTF8StringEncoding]); NSURL* url = [NSURL URLWithString:filePath]; NSData* data = [NSData dataWithContentsOfURL:url]; if (data == nil) { @@ -88,11 +88,11 @@ return std::make_shared(managedBuffer); } -std::shared_ptr AppleFilamentProxy::getJSDispatcher() { +std::shared_ptr AppleFilamentProxy::getJSDispatcher() { return _jsDispatcher; } -std::shared_ptr AppleFilamentProxy::getRenderThreadDispatcher() { +std::shared_ptr AppleFilamentProxy::getRenderThreadDispatcher() { if (_renderThreadDispatcher == nullptr) { // Filament has a strong requirement that you can only render from one single Thread. // iOS dispatch_queues may use multiple Threads, so we need to use NSThreadDispatcher instead of @@ -102,14 +102,14 @@ return _renderThreadDispatcher; } -std::shared_ptr AppleFilamentProxy::getUIDispatcher() { +std::shared_ptr AppleFilamentProxy::getUIDispatcher() { if (_uiDispatcher == nullptr) { _uiDispatcher = std::make_shared(dispatch_get_main_queue()); } return _uiDispatcher; } -std::shared_ptr AppleFilamentProxy::getBackgroundDispatcher() { +std::shared_ptr AppleFilamentProxy::getBackgroundDispatcher() { if (_backgroundDispatcher == nullptr) { dispatch_queue_attr_t qos = dispatch_queue_attr_make_with_qos_class(DISPATCH_QUEUE_CONCURRENT, QOS_CLASS_USER_INITIATED, -1); dispatch_queue_t queue = dispatch_queue_create("filament.background.queue", qos); diff --git a/package/ios/src/RNFAppleFilamentRecorder.h b/package/ios/src/RNFAppleFilamentRecorder.h index a40b9521..5b4b33a1 100644 --- a/package/ios/src/RNFAppleFilamentRecorder.h +++ b/package/ios/src/RNFAppleFilamentRecorder.h @@ -17,7 +17,7 @@ namespace margelo { class AppleFilamentRecorder : public FilamentRecorder { public: - explicit AppleFilamentRecorder(std::shared_ptr renderThreadDispatcher, int width, int height, int fps, double bitRate); + explicit AppleFilamentRecorder(std::shared_ptr renderThreadDispatcher, int width, int height, int fps, double bitRate); void* getNativeWindow() override; std::string getOutputFile() override; diff --git a/package/ios/src/RNFFilamentInstaller.mm b/package/ios/src/RNFFilamentInstaller.mm index af9f5482..c5ce85cb 100644 --- a/package/ios/src/RNFFilamentInstaller.mm +++ b/package/ios/src/RNFFilamentInstaller.mm @@ -46,8 +46,8 @@ + (BOOL)installToBridge:(jsi::Runtime*)runtime } // global.__globalDispatcher - std::shared_ptr jsDispatcher = std::make_shared(callInvoker); - Dispatcher::installRuntimeGlobalDispatcher(*runtime, jsDispatcher); + std::shared_ptr jsDispatcher = std::make_shared(callInvoker); + margelo::Dispatcher::installRuntimeGlobalDispatcher(*runtime, jsDispatcher); // global.FilamentProxy #ifdef RCT_NEW_ARCH_ENABLED diff --git a/package/ios/src/RNFNSThreadDispatcher.h b/package/ios/src/RNFNSThreadDispatcher.h index 2e1e9f51..14b991bc 100644 --- a/package/ios/src/RNFNSThreadDispatcher.h +++ b/package/ios/src/RNFNSThreadDispatcher.h @@ -16,7 +16,7 @@ namespace margelo { /** A [Dispatcher] implementation that uses an Objective-C NSThread. */ -class NSThreadDispatcher : public Dispatcher { +class NSThreadDispatcher : public margelo::Dispatcher { public: explicit NSThreadDispatcher(const std::string& name); diff --git a/package/nitrogen/generated/shared/c++/HybridSwapChainSpec.cpp b/package/nitrogen/generated/shared/c++/HybridSwapChainSpec.cpp index b0323edd..99152019 100644 --- a/package/nitrogen/generated/shared/c++/HybridSwapChainSpec.cpp +++ b/package/nitrogen/generated/shared/c++/HybridSwapChainSpec.cpp @@ -15,6 +15,7 @@ namespace margelo::nitro::RNF { HybridObject::loadHybridMethods(); // load custom methods/properties registerHybrids(this, [](Prototype& prototype) { + prototype.registerHybridGetter("isValid", &HybridSwapChainSpec::getIsValid); prototype.registerHybridMethod("release", &HybridSwapChainSpec::release); }); } diff --git a/package/nitrogen/generated/shared/c++/HybridSwapChainSpec.hpp b/package/nitrogen/generated/shared/c++/HybridSwapChainSpec.hpp index 71568a7f..1c47267f 100644 --- a/package/nitrogen/generated/shared/c++/HybridSwapChainSpec.hpp +++ b/package/nitrogen/generated/shared/c++/HybridSwapChainSpec.hpp @@ -42,7 +42,7 @@ namespace margelo::nitro::RNF { public: // Properties - + virtual bool getIsValid() = 0; public: // Methods diff --git a/package/src/react/FilamentView.tsx b/package/src/react/FilamentView.tsx index 84afe747..66c1e79c 100644 --- a/package/src/react/FilamentView.tsx +++ b/package/src/react/FilamentView.tsx @@ -258,6 +258,7 @@ export class FilamentView extends React.PureComponent { return null } }) + console.log({ swapChain: swapChain }) if (swapChain == null) { isSurfaceAlive.value = false diff --git a/package/src/specs/SwapChain.nitro.ts b/package/src/specs/SwapChain.nitro.ts index d6372218..04039890 100644 --- a/package/src/specs/SwapChain.nitro.ts +++ b/package/src/specs/SwapChain.nitro.ts @@ -1,6 +1,6 @@ import { type HybridObject } from 'react-native-nitro-modules' export interface SwapChain extends HybridObject<{ android: 'c++'; ios: 'c++' }> { - // TODO: Inheritance is not yet supported by nitrogen + readonly isValid: boolean release(): void }