Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set CallInvokator on Android #147

Merged
merged 8 commits into from
Oct 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions packages/webgpu/android/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ target_include_directories(
"${NODE_MODULES_DIR}/react-native/ReactCommon/runtimeexecutor"
"${NODE_MODULES_DIR}/react-native/ReactAndroid/src/main/jni"
"${NODE_MODULES_DIR}/react-native/ReactAndroid/src/main/java/com/facebook/react/turbomodule/core/jni"
"${NODE_MODULES_DIR}/react-native/ReactAndroid/src/main/jni/react/turbomodule"

../cpp
../cpp/rnwgpu
Expand All @@ -84,5 +85,6 @@ target_link_libraries(
android
fbjni::fbjni
ReactAndroid::jsi
ReactAndroid::reactnativejni
webgpu_dawn
)
8 changes: 4 additions & 4 deletions packages/webgpu/android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,10 @@ android {
}

packagingOptions {
exclude "lib/arm64-v8a/libjsi.so"
exclude "lib/x86_64/libjsi.so"
exclude "lib/x86/libjsi.so"
exclude "lib/armeabi-v7a/libjsi.so"
excludes = [
"**/libjsi.so",
"**/libreactnativejni.so",
]
}

buildFeatures {
Expand Down
14 changes: 10 additions & 4 deletions packages/webgpu/android/cpp/cpp-adapter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <jni.h>
#include <jsi/jsi.h>

#include <ReactCommon/CallInvokerHolder.h>
#include <android/native_window_jni.h>
#include <webgpu/webgpu_cpp.h>

Expand All @@ -17,13 +18,18 @@
std::shared_ptr<rnwgpu::RNWebGPUManager> manager;

extern "C" JNIEXPORT void JNICALL Java_com_webgpu_WebGPUModule_initializeNative(
JNIEnv *env, jobject /* this */, jlong jsRuntime, jobject jsInvokerHolder,
jobject blobModule) {
JNIEnv *env, jobject /* this */, jlong jsRuntime,
jobject jsCallInvokerHolder, jobject blobModule) {
auto runtime = reinterpret_cast<facebook::jsi::Runtime *>(jsRuntime);
jobject globalBlobModule = env->NewGlobalRef(blobModule);
auto jsCallInvoker{
facebook::jni::alias_ref<facebook::react::CallInvokerHolder::javaobject>{
reinterpret_cast<facebook::react::CallInvokerHolder::javaobject>(
jsCallInvokerHolder)} -> cthis()
->getCallInvoker()};
auto platformContext =
std::make_shared<rnwgpu::AndroidPlatformContext>(globalBlobModule);
manager = std::make_shared<rnwgpu::RNWebGPUManager>(runtime, nullptr,
manager = std::make_shared<rnwgpu::RNWebGPUManager>(runtime, jsCallInvoker,
platformContext);
}

Expand Down Expand Up @@ -55,7 +61,7 @@ Java_com_webgpu_WebGPUView_switchToOffscreenSurface(JNIEnv *env, jobject thiz,
jint contextId) {
auto &registry = rnwgpu::SurfaceRegistry::getInstance();
auto nativeSurface = registry.getSurfaceInfo(contextId)->switchToOffscreen();
ANativeWindow_release(reinterpret_cast<ANativeWindow *>(nativeSurface));
// ANativeWindow_release(reinterpret_cast<ANativeWindow *>(nativeSurface));
}

extern "C" JNIEXPORT void JNICALL Java_com_webgpu_WebGPUView_onSurfaceDestroy(
Expand Down
5 changes: 3 additions & 2 deletions packages/webgpu/cpp/rnwgpu/api/GPUCanvasContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@ void GPUCanvasContext::configure(
throw std::runtime_error("Error with SurfaceConfiguration");
}
}
if (!conv(surfaceConfiguration.usage, configuration->usage) || !conv(surfaceConfiguration.format, configuration->format)) {
throw std::runtime_error("Error with SurfaceConfiguration");
if (!conv(surfaceConfiguration.usage, configuration->usage) ||
!conv(surfaceConfiguration.format, configuration->format)) {
throw std::runtime_error("Error with SurfaceConfiguration");
}

#ifdef __APPLE__
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,9 @@ struct JSIConverter<std::shared_ptr<rnwgpu::GPUCanvasConfiguration>> {
false);
}
if (value.hasProperty(runtime, "alphaMode")) {
auto prop = value.getProperty(runtime, "alphaMode").asString(runtime).utf8(runtime);
auto prop = value.getProperty(runtime, "alphaMode")
.asString(runtime)
.utf8(runtime);
if (prop == "premultiplied") {
result->alphaMode = wgpu::CompositeAlphaMode::Premultiplied;
}
Expand Down
Loading