diff options
| author | Mai <mai.iam2048@gmail.com> | 2023-12-07 16:48:02 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-12-07 16:48:02 -0500 |
| commit | e0f41115612d0d4279c9037f3f79b68e50809052 (patch) | |
| tree | 90d460da7510b251488321efb81f603fc1c7c0ec /Source/Android/jni/Config/ConfigChangedCallback.cpp | |
| parent | 3a4cf579ff03d872cb64183923e18e17e9a37de6 (diff) | |
| parent | 4203632c93f4b73c8fd1159272f08ca022063b2b (diff) | |
Merge pull request #11663 from JosJuice/android-config-change-callback
Android: Use config changed callback for tracking recursive scan setting
Diffstat (limited to 'Source/Android/jni/Config/ConfigChangedCallback.cpp')
| -rw-r--r-- | Source/Android/jni/Config/ConfigChangedCallback.cpp | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/Source/Android/jni/Config/ConfigChangedCallback.cpp b/Source/Android/jni/Config/ConfigChangedCallback.cpp new file mode 100644 index 0000000000..2ec8b06541 --- /dev/null +++ b/Source/Android/jni/Config/ConfigChangedCallback.cpp @@ -0,0 +1,44 @@ +// Copyright 2023 Dolphin Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later + +#include <jni.h> + +#include "Common/Config/Config.h" +#include "jni/AndroidCommon/AndroidCommon.h" +#include "jni/AndroidCommon/IDCache.h" + +struct ConfigChangedCallbackContext +{ + jobject runnable; + Config::ConfigChangedCallbackID callback_id; +}; + +extern "C" { + +JNIEXPORT jlong JNICALL +Java_org_dolphinemu_dolphinemu_features_settings_model_ConfigChangedCallback_initialize( + JNIEnv* env, jclass, jobject runnable) +{ + auto* context = new ConfigChangedCallbackContext; + + jobject runnable_global = env->NewGlobalRef(runnable); + context->runnable = runnable_global; + context->callback_id = Config::AddConfigChangedCallback([runnable_global] { + IDCache::GetEnvForThread()->CallVoidMethod(runnable_global, IDCache::GetRunnableRun()); + }); + + return reinterpret_cast<jlong>(context); +} + +JNIEXPORT void JNICALL +Java_org_dolphinemu_dolphinemu_features_settings_model_ConfigChangedCallback_deinitialize( + JNIEnv* env, jclass, jlong pointer) +{ + auto* context = reinterpret_cast<ConfigChangedCallbackContext*>(pointer); + + Config::RemoveConfigChangedCallback(context->callback_id); + env->DeleteGlobalRef(context->runnable); + + delete context; +} +} |
