From dcf25ecd51ab00a29be5b742654211f82991ad07 Mon Sep 17 00:00:00 2001 From: Ryan Tremblay Date: Wed, 10 Feb 2021 16:12:24 -0800 Subject: [PATCH] Add NativeCapture (#156) --- .../BabylonReactNative.vcxproj | 16 ++++++++-- .../windows/CMakeLists.txt | 1 + .../@babylonjs/react-native/NativeCapture.ts | 30 +++++++++++++++++++ .../react-native/android/CMakeLists.txt | 1 + Modules/@babylonjs/react-native/index.ts | 1 + .../react-native/ios/CMakeLists.txt | 1 + .../react-native/react-native-babylon.podspec | 1 + .../react-native/shared/BabylonNative.cpp | 4 ++- .../react-native/submodules/BabylonNative | 2 +- Package/gulpfile.js | 2 ++ Package/iOS/CMakeLists.txt | 1 + 11 files changed, 56 insertions(+), 4 deletions(-) create mode 100644 Modules/@babylonjs/react-native/NativeCapture.ts diff --git a/Modules/@babylonjs/react-native-windows/windows/BabylonReactNative/BabylonReactNative.vcxproj b/Modules/@babylonjs/react-native-windows/windows/BabylonReactNative/BabylonReactNative.vcxproj index ea9733d0d..36917be0c 100644 --- a/Modules/@babylonjs/react-native-windows/windows/BabylonReactNative/BabylonReactNative.vcxproj +++ b/Modules/@babylonjs/react-native-windows/windows/BabylonReactNative/BabylonReactNative.vcxproj @@ -128,7 +128,7 @@ WindowsApp.lib;%(AdditionalDependencies); - arcana.lib;astc.lib;astc-codec.lib;BabylonNative.lib;bgfx.lib;bimg.lib;bx.lib;edtaa3.lib;etc1.lib;etc2.lib;GenericCodeGend.lib;glslangd.lib;Graphics.lib;iqa.lib;jsi.lib;JsRuntime.lib;MachineIndependentd.lib;napi.lib;NativeEngine.lib;NativeInput.lib;NativeXr.lib;nvtt.lib;OGLCompilerd.lib;openxr_loader.lib;OSDependentd.lib;pvrtc.lib;spirv-cross-core.lib;spirv-cross-glsl.lib;spirv-cross-hlsl.lib;SPIRVd.lib;squish.lib;UrlLib.lib;Window.lib;XMLHttpRequest.lib;xr.lib;WindowsApp.lib;%(AdditionalDependencies); + arcana.lib;astc.lib;astc-codec.lib;BabylonNative.lib;bgfx.lib;bimg.lib;bx.lib;edtaa3.lib;etc1.lib;etc2.lib;GenericCodeGend.lib;glslangd.lib;Graphics.lib;iqa.lib;jsi.lib;JsRuntime.lib;MachineIndependentd.lib;napi.lib;NativeCapture.lib;NativeEngine.lib;NativeInput.lib;NativeXr.lib;nvtt.lib;OGLCompilerd.lib;openxr_loader.lib;OSDependentd.lib;pvrtc.lib;spirv-cross-core.lib;spirv-cross-glsl.lib;spirv-cross-hlsl.lib;SPIRVd.lib;squish.lib;UrlLib.lib;Window.lib;XMLHttpRequest.lib;xr.lib;WindowsApp.lib;%(AdditionalDependencies); %(AdditionalOptions) $(BabylonReactNativeDir)\submodules\BabylonNative\Build_uwp_x64\Dependencies\bgfx.cmake\Debug;$(BabylonReactNativeDir)\submodules\BabylonNative\Build_uwp_x64\Dependencies\napi\napi-jsi\Debug;$(BabylonReactNativeDir)\submodules\BabylonNative\Build_uwp_x64\jsi\Debug;$(BabylonReactNativeDir)\submodules\BabylonNative\Build_uwp_x64\Core\JsRuntime\Debug;$(BabylonReactNativeDir)\submodules\BabylonNative\Build_uwp_x64\Core\Graphics\Debug;$(BabylonReactNativeDir)\submodules\BabylonNative\Build_uwp_x64\Plugins\NativeInput\Debug;$(BabylonReactNativeDir)\submodules\BabylonNative\Build_uwp_x64\Debug;%(AdditionalLibraryDirectories) @@ -157,7 +157,7 @@ WindowsApp.lib;%(AdditionalDependencies)" - arcana.lib;astc.lib;astc-codec.lib;BabylonNative.lib;bgfx.lib;bimg.lib;bx.lib;edtaa3.lib;etc1.lib;etc2.lib;GenericCodeGen.lib;glslang.lib;Graphics.lib;iqa.lib;jsi.lib;JsRuntime.lib;MachineIndependent.lib;napi.lib;NativeEngine.lib;NativeInput.lib;NativeXr.lib;nvtt.lib;OGLCompiler.lib;openxr_loader.lib;OSDependent.lib;pvrtc.lib;spirv-cross-core.lib;spirv-cross-glsl.lib;spirv-cross-hlsl.lib;SPIRV.lib;squish.lib;UrlLib.lib;Window.lib;XMLHttpRequest.lib;xr.lib;WindowsApp.lib;%(AdditionalDependencies); + arcana.lib;astc.lib;astc-codec.lib;BabylonNative.lib;bgfx.lib;bimg.lib;bx.lib;edtaa3.lib;etc1.lib;etc2.lib;GenericCodeGen.lib;glslang.lib;Graphics.lib;iqa.lib;jsi.lib;JsRuntime.lib;MachineIndependent.lib;napi.lib;NativeCapture.lib;NativeEngine.lib;NativeInput.lib;NativeXr.lib;nvtt.lib;OGLCompiler.lib;openxr_loader.lib;OSDependent.lib;pvrtc.lib;spirv-cross-core.lib;spirv-cross-glsl.lib;spirv-cross-hlsl.lib;SPIRV.lib;squish.lib;UrlLib.lib;Window.lib;XMLHttpRequest.lib;xr.lib;WindowsApp.lib;%(AdditionalDependencies); %(AdditionalOptions) $(BabylonReactNativeDir)\submodules\BabylonNative\Build_uwp_x64\Dependencies\bgfx.cmake\Release;$(BabylonReactNativeDir)\submodules\BabylonNative\Build_uwp_x64\Dependencies\napi\napi-jsi\Release;$(BabylonReactNativeDir)\submodules\BabylonNative\Build_uwp_x64\jsi\Release;$(BabylonReactNativeDir)\submodules\BabylonNative\Build_uwp_x64\Core\JsRuntime\Release;$(BabylonReactNativeDir)\submodules\BabylonNative\Build_uwp_x64\Core\Graphics\Release;$(BabylonReactNativeDir)\submodules\BabylonNative\Build_uwp_x64\Plugins\NativeInput\Release;$(BabylonReactNativeDir)\submodules\BabylonNative\Build_uwp_x64\Release;%(AdditionalLibraryDirectories) @@ -289,6 +289,9 @@ {bddbd49e-873f-33e4-a99d-9d8e77b16433} + + {20eb2920-32bc-4aa6-9ba0-969a25d6bdb9} + {2c18692b-80ea-335e-a473-15a19374ace0} @@ -397,6 +400,9 @@ {0897d738-8022-3a3d-95b8-2b4ff7f8365e} + + {47771cab-ac3b-4673-b77e-af13a702993a} + {d582c0e4-9a19-3024-8039-2f8ee50bc8de} @@ -505,6 +511,9 @@ {1b2a5e60-84f3-34c9-9318-5cf2ac668433} + + {12221f10-00b8-45b6-8b56-c9b42bb54c6f} + {b9a708f6-9986-3270-b7b4-a3674ffa0053} @@ -613,6 +622,9 @@ {93d05ba2-59b9-3592-ab31-c441fb3d7989} + + {21595e71-26ec-4dd4-85e3-59208622c21d} + {4c5576a1-09a2-3815-8402-1fdc77ecdaf4} diff --git a/Modules/@babylonjs/react-native-windows/windows/CMakeLists.txt b/Modules/@babylonjs/react-native-windows/windows/CMakeLists.txt index 07e4dde8d..c27c56a51 100644 --- a/Modules/@babylonjs/react-native-windows/windows/CMakeLists.txt +++ b/Modules/@babylonjs/react-native-windows/windows/CMakeLists.txt @@ -37,6 +37,7 @@ target_link_libraries(BabylonNative Graphics jsi JsRuntime + NativeCapture NativeEngine NativeInput NativeXr diff --git a/Modules/@babylonjs/react-native/NativeCapture.ts b/Modules/@babylonjs/react-native/NativeCapture.ts new file mode 100644 index 000000000..81e694810 --- /dev/null +++ b/Modules/@babylonjs/react-native/NativeCapture.ts @@ -0,0 +1,30 @@ +export type CapturedFrame = { + width: number; + height: number; + pitch: number; + format: "BGRA8" | undefined; + yFlip: boolean; + data: ArrayBuffer; +}; + +export type CaptureCallback = (capture: CapturedFrame) => void; + +declare class NativeCapture { + public constructor(); + public addCallback(onCaptureCallback: CaptureCallback): void; + public dispose(): void; +}; + +export class CaptureSession { + private readonly nativeCapture: NativeCapture; + + public constructor(onCaptureCallback: CaptureCallback) { + console.warn(`CaptureSession is experimental and likely to change significantly.`); + this.nativeCapture = new NativeCapture(); + this.nativeCapture.addCallback(onCaptureCallback); + } + + public dispose(): void { + this.nativeCapture.dispose(); + } +} \ No newline at end of file diff --git a/Modules/@babylonjs/react-native/android/CMakeLists.txt b/Modules/@babylonjs/react-native/android/CMakeLists.txt index c9d01b8e8..f84974969 100644 --- a/Modules/@babylonjs/react-native/android/CMakeLists.txt +++ b/Modules/@babylonjs/react-native/android/CMakeLists.txt @@ -75,6 +75,7 @@ target_link_libraries(BabylonNative AndroidExtensions Graphics JsRuntime + NativeCapture NativeEngine NativeInput NativeXr diff --git a/Modules/@babylonjs/react-native/index.ts b/Modules/@babylonjs/react-native/index.ts index d7b8934d7..6a7d41c79 100644 --- a/Modules/@babylonjs/react-native/index.ts +++ b/Modules/@babylonjs/react-native/index.ts @@ -1,2 +1,3 @@ export * from './EngineView'; export * from './EngineHook'; +export * from './NativeCapture'; diff --git a/Modules/@babylonjs/react-native/ios/CMakeLists.txt b/Modules/@babylonjs/react-native/ios/CMakeLists.txt index 5b32f7ae4..42e85f974 100644 --- a/Modules/@babylonjs/react-native/ios/CMakeLists.txt +++ b/Modules/@babylonjs/react-native/ios/CMakeLists.txt @@ -43,6 +43,7 @@ target_link_libraries(BabylonNative jsi reactnative JsRuntime + NativeCapture NativeEngine NativeInput NativeXr diff --git a/Modules/@babylonjs/react-native/react-native-babylon.podspec b/Modules/@babylonjs/react-native/react-native-babylon.podspec index 2e9be0360..55637848c 100644 --- a/Modules/@babylonjs/react-native/react-native-babylon.podspec +++ b/Modules/@babylonjs/react-native/react-native-babylon.podspec @@ -30,6 +30,7 @@ Pod::Spec.new do |s| 'OSDependent', 'MachineIndependent', 'napi', + 'NativeCapture', 'NativeEngine', 'NativeInput', 'NativeXR', diff --git a/Modules/@babylonjs/react-native/shared/BabylonNative.cpp b/Modules/@babylonjs/react-native/shared/BabylonNative.cpp index e28d89b22..bac445079 100644 --- a/Modules/@babylonjs/react-native/shared/BabylonNative.cpp +++ b/Modules/@babylonjs/react-native/shared/BabylonNative.cpp @@ -2,6 +2,7 @@ #include #include +#include #include #include #include @@ -52,7 +53,8 @@ namespace Babylon // Initialize Babylon Native plugins Plugins::NativeXr::Initialize(m_env); - m_nativeInput = &Babylon::Plugins::NativeInput::CreateForJavaScript(m_env); + Plugins::NativeCapture::Initialize(m_env); + m_nativeInput = &Plugins::NativeInput::CreateForJavaScript(m_env); // Initialize Babylon Native polyfills Polyfills::Window::Initialize(m_env); diff --git a/Modules/@babylonjs/react-native/submodules/BabylonNative b/Modules/@babylonjs/react-native/submodules/BabylonNative index b4f81771a..5245966cb 160000 --- a/Modules/@babylonjs/react-native/submodules/BabylonNative +++ b/Modules/@babylonjs/react-native/submodules/BabylonNative @@ -1 +1 @@ -Subproject commit b4f81771abb2722c3c18731a59b31c18298fcd40 +Subproject commit 5245966cb1d3b5fd9970c45aad14a76f65372164 diff --git a/Package/gulpfile.js b/Package/gulpfile.js index 531a628db..c70fffd23 100644 --- a/Package/gulpfile.js +++ b/Package/gulpfile.js @@ -244,6 +244,7 @@ Assembled/ios/libs/libOGLCompiler.a Assembled/ios/libs/libastc.a Assembled/ios/libs/libNativeEngine.a Assembled/ios/libs/libNativeXr.a +Assembled/ios/libs/libNativeCapture.a Assembled/ios/libs/libspirv-cross-glsl.a Assembled/ios/libs/libNativeInput.a Assembled/ios/libs/libJsRuntime.a @@ -297,6 +298,7 @@ Assembled/android/src/main/jniLibs/arm64-v8a Assembled/android/src/main/jniLibs/arm64-v8a/libturbomodulejsijni.so Assembled/android/src/main/jniLibs/arm64-v8a/libBabylonNative.so Assembled/react-native-babylon.podspec +Assembled/NativeCapture.ts Assembled/index.ts Assembled/VersionValidation.ts Assembled/BabylonModule.ts diff --git a/Package/iOS/CMakeLists.txt b/Package/iOS/CMakeLists.txt index 7df2c4dde..83348b948 100644 --- a/Package/iOS/CMakeLists.txt +++ b/Package/iOS/CMakeLists.txt @@ -16,6 +16,7 @@ set(PACKAGED_LIBS OSDependent MachineIndependent napi + NativeCapture NativeEngine NativeInput NativeXr