2015-05-25 11:11:41 +00:00
|
|
|
// Copyright 2003 Dolphin Emulator Project
|
2021-07-05 01:22:19 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2013-02-26 19:49:00 +00:00
|
|
|
|
2014-02-11 06:16:21 +00:00
|
|
|
#include <EGL/egl.h>
|
2014-02-19 01:56:29 +00:00
|
|
|
#include <android/log.h>
|
|
|
|
#include <android/native_window_jni.h>
|
|
|
|
#include <cstdio>
|
|
|
|
#include <cstdlib>
|
2024-04-05 23:21:10 +00:00
|
|
|
#include <fmt/format.h>
|
2014-02-19 01:56:29 +00:00
|
|
|
#include <jni.h>
|
2015-12-07 04:15:51 +00:00
|
|
|
#include <memory>
|
2016-05-12 01:18:30 +00:00
|
|
|
#include <mutex>
|
2017-12-26 21:08:44 +00:00
|
|
|
#include <optional>
|
2017-05-18 23:33:44 +00:00
|
|
|
#include <string>
|
2016-05-12 09:17:17 +00:00
|
|
|
#include <thread>
|
2017-12-28 09:13:53 +00:00
|
|
|
#include <utility>
|
2015-12-07 09:13:25 +00:00
|
|
|
|
2018-08-19 21:38:29 +00:00
|
|
|
#include "Common/AndroidAnalytics.h"
|
2020-06-24 22:02:02 +00:00
|
|
|
#include "Common/Assert.h"
|
2014-02-19 01:56:29 +00:00
|
|
|
#include "Common/CPUDetect.h"
|
2014-02-22 22:36:30 +00:00
|
|
|
#include "Common/CommonPaths.h"
|
2014-09-08 01:06:58 +00:00
|
|
|
#include "Common/CommonTypes.h"
|
2014-04-13 23:15:23 +00:00
|
|
|
#include "Common/Event.h"
|
2014-02-19 01:56:29 +00:00
|
|
|
#include "Common/FileUtil.h"
|
2021-08-08 12:33:06 +00:00
|
|
|
#include "Common/Flag.h"
|
2024-04-05 23:21:10 +00:00
|
|
|
#include "Common/IOFile.h"
|
2019-06-07 22:25:32 +00:00
|
|
|
#include "Common/IniFile.h"
|
2014-06-05 23:29:54 +00:00
|
|
|
#include "Common/Logging/LogManager.h"
|
2017-05-22 08:39:36 +00:00
|
|
|
#include "Common/MsgHandler.h"
|
2020-06-25 17:38:02 +00:00
|
|
|
#include "Common/ScopeGuard.h"
|
2017-09-09 19:52:35 +00:00
|
|
|
#include "Common/Version.h"
|
2018-10-03 13:03:22 +00:00
|
|
|
#include "Common/WindowSystemInfo.h"
|
2015-12-07 09:13:25 +00:00
|
|
|
|
2017-05-27 13:43:40 +00:00
|
|
|
#include "Core/Boot/Boot.h"
|
2014-02-19 01:56:29 +00:00
|
|
|
#include "Core/BootManager.h"
|
2022-01-09 22:47:30 +00:00
|
|
|
#include "Core/CommonTitles.h"
|
2018-02-16 18:47:52 +00:00
|
|
|
#include "Core/ConfigLoaders/GameConfigLoader.h"
|
2014-02-19 01:56:29 +00:00
|
|
|
#include "Core/ConfigManager.h"
|
|
|
|
#include "Core/Core.h"
|
2020-09-15 14:22:32 +00:00
|
|
|
#include "Core/DolphinAnalytics.h"
|
2018-01-21 00:31:53 +00:00
|
|
|
#include "Core/HW/DVD/DVDInterface.h"
|
2014-02-19 01:56:29 +00:00
|
|
|
#include "Core/HW/Wiimote.h"
|
2016-02-05 00:31:36 +00:00
|
|
|
#include "Core/HW/WiimoteReal/WiimoteReal.h"
|
2014-02-19 01:56:29 +00:00
|
|
|
#include "Core/Host.h"
|
2015-05-11 01:03:34 +00:00
|
|
|
#include "Core/PowerPC/JitInterface.h"
|
2017-04-15 14:23:48 +00:00
|
|
|
#include "Core/PowerPC/PowerPC.h"
|
2014-02-19 01:56:29 +00:00
|
|
|
#include "Core/State.h"
|
2023-03-09 20:43:03 +00:00
|
|
|
#include "Core/System.h"
|
2013-04-15 01:39:56 +00:00
|
|
|
|
2020-06-24 22:02:02 +00:00
|
|
|
#include "DiscIO/Blob.h"
|
2016-07-06 18:33:05 +00:00
|
|
|
#include "DiscIO/Enums.h"
|
2021-10-24 14:29:38 +00:00
|
|
|
#include "DiscIO/RiivolutionParser.h"
|
2020-06-24 22:02:02 +00:00
|
|
|
#include "DiscIO/ScrubbedBlob.h"
|
2015-12-07 09:13:25 +00:00
|
|
|
#include "DiscIO/Volume.h"
|
2013-04-23 19:21:48 +00:00
|
|
|
|
2020-08-27 11:43:20 +00:00
|
|
|
#include "InputCommon/GCAdapter.h"
|
2019-11-20 18:40:47 +00:00
|
|
|
|
2022-06-25 15:31:31 +00:00
|
|
|
#include "UICommon/GameFile.h"
|
2014-10-04 19:12:15 +00:00
|
|
|
#include "UICommon/UICommon.h"
|
|
|
|
|
2014-02-19 01:56:29 +00:00
|
|
|
#include "VideoCommon/OnScreenDisplay.h"
|
2023-01-27 04:03:15 +00:00
|
|
|
#include "VideoCommon/Present.h"
|
2014-02-19 01:56:29 +00:00
|
|
|
#include "VideoCommon/VideoBackendBase.h"
|
2013-02-26 19:49:00 +00:00
|
|
|
|
2018-06-01 07:36:29 +00:00
|
|
|
#include "jni/AndroidCommon/AndroidCommon.h"
|
|
|
|
#include "jni/AndroidCommon/IDCache.h"
|
2023-06-11 10:06:23 +00:00
|
|
|
#include "jni/Host.h"
|
2015-06-08 00:13:52 +00:00
|
|
|
|
2017-05-18 23:33:44 +00:00
|
|
|
namespace
|
|
|
|
{
|
2020-07-22 19:38:45 +00:00
|
|
|
constexpr char DOLPHIN_TAG[] = "DolphinEmuNative";
|
2017-05-18 23:33:44 +00:00
|
|
|
|
2018-06-01 07:36:29 +00:00
|
|
|
ANativeWindow* s_surf;
|
2017-05-18 23:33:44 +00:00
|
|
|
|
|
|
|
Common::Event s_update_main_frame_event;
|
2020-11-06 20:22:22 +00:00
|
|
|
|
|
|
|
// This exists to prevent surfaces from being destroyed during the boot process,
|
|
|
|
// as that can lead to the boot process dereferencing nullptr.
|
|
|
|
std::mutex s_surface_lock;
|
|
|
|
bool s_need_nonblocking_alert_msg;
|
|
|
|
|
2021-08-08 12:33:06 +00:00
|
|
|
Common::Flag s_is_booting;
|
2020-09-13 11:20:58 +00:00
|
|
|
bool s_game_metadata_is_valid = false;
|
2017-05-18 23:33:44 +00:00
|
|
|
} // Anonymous namespace
|
2013-02-26 19:49:00 +00:00
|
|
|
|
2019-01-29 01:00:13 +00:00
|
|
|
void UpdatePointer()
|
|
|
|
{
|
|
|
|
// Update touch pointer
|
2019-05-29 12:22:26 +00:00
|
|
|
JNIEnv* env = IDCache::GetEnvForThread();
|
2019-01-29 01:00:13 +00:00
|
|
|
env->CallStaticVoidMethod(IDCache::GetNativeLibraryClass(), IDCache::GetUpdateTouchPointer());
|
|
|
|
}
|
|
|
|
|
2020-12-27 22:11:22 +00:00
|
|
|
std::vector<std::string> Host_GetPreferredLocales()
|
|
|
|
{
|
|
|
|
// We would like to call ConfigurationCompat.getLocales here, but this function gets called
|
|
|
|
// during dynamic initialization, and it seems like that makes us unable to obtain a JNIEnv.
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
2024-03-17 06:05:56 +00:00
|
|
|
void Host_PPCSymbolsChanged()
|
2013-02-26 19:49:00 +00:00
|
|
|
{
|
|
|
|
}
|
2020-12-27 22:11:22 +00:00
|
|
|
|
2013-02-26 19:49:00 +00:00
|
|
|
void Host_RefreshDSPDebuggerWindow()
|
|
|
|
{
|
|
|
|
}
|
2020-12-27 22:11:22 +00:00
|
|
|
|
2019-03-18 16:30:33 +00:00
|
|
|
bool Host_UIBlocksControllerState()
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2013-02-26 19:49:00 +00:00
|
|
|
|
2018-05-28 17:03:29 +00:00
|
|
|
void Host_Message(HostMessageID id)
|
2013-02-26 19:49:00 +00:00
|
|
|
{
|
2018-05-28 17:03:29 +00:00
|
|
|
if (id == HostMessageID::WMUserJobDispatch)
|
2016-05-12 01:18:30 +00:00
|
|
|
{
|
2017-05-18 23:33:44 +00:00
|
|
|
s_update_main_frame_event.Set();
|
2016-05-12 01:18:30 +00:00
|
|
|
}
|
2018-05-28 17:03:29 +00:00
|
|
|
else if (id == HostMessageID::WMUserStop)
|
2016-05-12 09:17:17 +00:00
|
|
|
{
|
2024-07-02 15:27:04 +00:00
|
|
|
Core::QueueHostJob(&Core::Stop);
|
2016-05-12 09:17:17 +00:00
|
|
|
}
|
2013-02-26 19:49:00 +00:00
|
|
|
}
|
|
|
|
|
2014-03-12 19:33:41 +00:00
|
|
|
void Host_UpdateTitle(const std::string& title)
|
2013-07-27 20:09:18 +00:00
|
|
|
{
|
2014-03-17 23:17:12 +00:00
|
|
|
__android_log_write(ANDROID_LOG_INFO, DOLPHIN_TAG, title.c_str());
|
|
|
|
}
|
2013-02-26 19:49:00 +00:00
|
|
|
|
2022-08-03 04:46:11 +00:00
|
|
|
void Host_UpdateDiscordClientID(const std::string& client_id)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Host_UpdateDiscordPresenceRaw(const std::string& details, const std::string& state,
|
|
|
|
const std::string& large_image_key,
|
|
|
|
const std::string& large_image_text,
|
|
|
|
const std::string& small_image_key,
|
|
|
|
const std::string& small_image_text,
|
|
|
|
const int64_t start_timestamp, const int64_t end_timestamp,
|
|
|
|
const int party_size, const int party_max)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-02-26 19:49:00 +00:00
|
|
|
void Host_UpdateDisasmDialog()
|
2016-06-24 08:43:46 +00:00
|
|
|
{
|
2013-02-26 19:49:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Host_UpdateMainFrame()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void Host_RequestRenderWindowSize(int width, int height)
|
|
|
|
{
|
2019-01-29 01:00:13 +00:00
|
|
|
std::thread jnicall(UpdatePointer);
|
|
|
|
jnicall.join();
|
2013-02-26 19:49:00 +00:00
|
|
|
}
|
2014-07-16 13:53:33 +00:00
|
|
|
|
2013-02-26 19:49:00 +00:00
|
|
|
bool Host_RendererHasFocus()
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2021-05-09 10:28:04 +00:00
|
|
|
bool Host_RendererHasFullFocus()
|
|
|
|
{
|
|
|
|
// Mouse cursor locking actually exists in Android but we don't implement (nor need) that
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-01-04 16:09:56 +00:00
|
|
|
bool Host_RendererIsFullscreen()
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2024-05-26 23:50:12 +00:00
|
|
|
bool Host_TASInputHasFocus()
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-11-10 16:55:21 +00:00
|
|
|
void Host_YieldToUI()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2019-02-14 02:31:31 +00:00
|
|
|
void Host_TitleChanged()
|
|
|
|
{
|
2020-09-13 11:20:58 +00:00
|
|
|
s_game_metadata_is_valid = true;
|
|
|
|
|
|
|
|
JNIEnv* env = IDCache::GetEnvForThread();
|
|
|
|
env->CallStaticVoidMethod(IDCache::GetNativeLibraryClass(), IDCache::GetOnTitleChanged());
|
2019-02-14 02:31:31 +00:00
|
|
|
}
|
|
|
|
|
2021-07-04 11:09:46 +00:00
|
|
|
std::unique_ptr<GBAHostInterface> Host_CreateGBAHost(std::weak_ptr<HW::GBA::Core> core)
|
|
|
|
{
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2020-09-25 15:50:59 +00:00
|
|
|
static bool MsgAlert(const char* caption, const char* text, bool yes_no, Common::MsgType style)
|
2015-02-13 00:41:52 +00:00
|
|
|
{
|
Jit: Don't use a second stack
This second stack leads to JNI problems on Android, because ART fetches
the address and size of the original stack using pthread functions
(see GetThreadStack in art/runtime/thread.cc), and (presumably) treats
stack addresses outside of the original stack as invalid. (What I don't
understand is why some JNI operations on the CPU thread work fine
despite this but others don't.)
Instead of creating a second stack, let's borrow the approach ART uses:
Use pthread functions to find out the stack's address and size, then
install guard pages at an appropriate location. This lets us get rid
of a workaround we had in the MsgAlert function.
Because we're no longer choosing the stack size ourselves, I've made some
tweaks to where the put the guard pages. Previously we had a stack of
2 MiB and a safe zone of 512 KiB. We now accept stacks as small as 512 KiB
(used on macOS) and use a safe zone of 256 KiB. I feel like this should
be fine, but haven't done much testing beyond "it seems to work".
By the way, on Windows it was already the case that we didn't create
a second stack... But there was a bug in the implementation!
The code for protecting the stack has to run on the CPU thread, since
it's the CPU thread's stack we want to protect, but it was actually
running on EmuThread. This commit fixes that, since now this bug
matters on other operating systems too.
2023-01-01 19:18:03 +00:00
|
|
|
JNIEnv* env = IDCache::GetEnvForThread();
|
2015-06-08 00:13:52 +00:00
|
|
|
|
Jit: Don't use a second stack
This second stack leads to JNI problems on Android, because ART fetches
the address and size of the original stack using pthread functions
(see GetThreadStack in art/runtime/thread.cc), and (presumably) treats
stack addresses outside of the original stack as invalid. (What I don't
understand is why some JNI operations on the CPU thread work fine
despite this but others don't.)
Instead of creating a second stack, let's borrow the approach ART uses:
Use pthread functions to find out the stack's address and size, then
install guard pages at an appropriate location. This lets us get rid
of a workaround we had in the MsgAlert function.
Because we're no longer choosing the stack size ourselves, I've made some
tweaks to where the put the guard pages. Previously we had a stack of
2 MiB and a safe zone of 512 KiB. We now accept stacks as small as 512 KiB
(used on macOS) and use a safe zone of 256 KiB. I feel like this should
be fine, but haven't done much testing beyond "it seems to work".
By the way, on Windows it was already the case that we didn't create
a second stack... But there was a bug in the implementation!
The code for protecting the stack has to run on the CPU thread, since
it's the CPU thread's stack we want to protect, but it was actually
running on EmuThread. This commit fixes that, since now this bug
matters on other operating systems too.
2023-01-01 19:18:03 +00:00
|
|
|
jstring j_caption = ToJString(env, caption);
|
|
|
|
jstring j_text = ToJString(env, text);
|
2022-12-25 15:30:51 +00:00
|
|
|
|
Jit: Don't use a second stack
This second stack leads to JNI problems on Android, because ART fetches
the address and size of the original stack using pthread functions
(see GetThreadStack in art/runtime/thread.cc), and (presumably) treats
stack addresses outside of the original stack as invalid. (What I don't
understand is why some JNI operations on the CPU thread work fine
despite this but others don't.)
Instead of creating a second stack, let's borrow the approach ART uses:
Use pthread functions to find out the stack's address and size, then
install guard pages at an appropriate location. This lets us get rid
of a workaround we had in the MsgAlert function.
Because we're no longer choosing the stack size ourselves, I've made some
tweaks to where the put the guard pages. Previously we had a stack of
2 MiB and a safe zone of 512 KiB. We now accept stacks as small as 512 KiB
(used on macOS) and use a safe zone of 256 KiB. I feel like this should
be fine, but haven't done much testing beyond "it seems to work".
By the way, on Windows it was already the case that we didn't create
a second stack... But there was a bug in the implementation!
The code for protecting the stack has to run on the CPU thread, since
it's the CPU thread's stack we want to protect, but it was actually
running on EmuThread. This commit fixes that, since now this bug
matters on other operating systems too.
2023-01-01 19:18:03 +00:00
|
|
|
// Execute the Java method.
|
|
|
|
jboolean result = env->CallStaticBooleanMethod(
|
|
|
|
IDCache::GetNativeLibraryClass(), IDCache::GetDisplayAlertMsg(), j_caption, j_text, yes_no,
|
|
|
|
style == Common::MsgType::Warning, s_need_nonblocking_alert_msg);
|
2022-12-25 15:30:51 +00:00
|
|
|
|
Jit: Don't use a second stack
This second stack leads to JNI problems on Android, because ART fetches
the address and size of the original stack using pthread functions
(see GetThreadStack in art/runtime/thread.cc), and (presumably) treats
stack addresses outside of the original stack as invalid. (What I don't
understand is why some JNI operations on the CPU thread work fine
despite this but others don't.)
Instead of creating a second stack, let's borrow the approach ART uses:
Use pthread functions to find out the stack's address and size, then
install guard pages at an appropriate location. This lets us get rid
of a workaround we had in the MsgAlert function.
Because we're no longer choosing the stack size ourselves, I've made some
tweaks to where the put the guard pages. Previously we had a stack of
2 MiB and a safe zone of 512 KiB. We now accept stacks as small as 512 KiB
(used on macOS) and use a safe zone of 256 KiB. I feel like this should
be fine, but haven't done much testing beyond "it seems to work".
By the way, on Windows it was already the case that we didn't create
a second stack... But there was a bug in the implementation!
The code for protecting the stack has to run on the CPU thread, since
it's the CPU thread's stack we want to protect, but it was actually
running on EmuThread. This commit fixes that, since now this bug
matters on other operating systems too.
2023-01-01 19:18:03 +00:00
|
|
|
env->DeleteLocalRef(j_caption);
|
|
|
|
env->DeleteLocalRef(j_text);
|
2015-06-08 00:13:52 +00:00
|
|
|
|
2018-01-07 22:30:28 +00:00
|
|
|
return result != JNI_FALSE;
|
2015-02-13 00:41:52 +00:00
|
|
|
}
|
|
|
|
|
2020-07-22 19:38:45 +00:00
|
|
|
static void ReportSend(const std::string& endpoint, const std::string& report)
|
2018-08-19 21:38:29 +00:00
|
|
|
{
|
2019-05-29 12:22:26 +00:00
|
|
|
JNIEnv* env = IDCache::GetEnvForThread();
|
2018-08-19 21:38:29 +00:00
|
|
|
|
|
|
|
jbyteArray output_array = env->NewByteArray(report.size());
|
|
|
|
jbyte* output = env->GetByteArrayElements(output_array, nullptr);
|
|
|
|
memcpy(output, report.data(), report.size());
|
|
|
|
env->ReleaseByteArrayElements(output_array, output, 0);
|
2022-12-25 15:30:51 +00:00
|
|
|
|
|
|
|
jstring j_endpoint = ToJString(env, endpoint);
|
|
|
|
|
2018-08-19 21:38:29 +00:00
|
|
|
env->CallStaticVoidMethod(IDCache::GetAnalyticsClass(), IDCache::GetSendAnalyticsReport(),
|
2022-12-25 15:30:51 +00:00
|
|
|
j_endpoint, output_array);
|
|
|
|
|
|
|
|
env->DeleteLocalRef(output_array);
|
|
|
|
env->DeleteLocalRef(j_endpoint);
|
2018-08-19 21:38:29 +00:00
|
|
|
}
|
|
|
|
|
2020-07-22 19:38:45 +00:00
|
|
|
static std::string GetAnalyticValue(const std::string& key)
|
2018-08-19 21:38:29 +00:00
|
|
|
{
|
2019-05-29 12:22:26 +00:00
|
|
|
JNIEnv* env = IDCache::GetEnvForThread();
|
2018-08-19 21:38:29 +00:00
|
|
|
|
2022-12-25 15:30:51 +00:00
|
|
|
jstring j_key = ToJString(env, key);
|
|
|
|
auto j_value = reinterpret_cast<jstring>(env->CallStaticObjectMethod(
|
|
|
|
IDCache::GetAnalyticsClass(), IDCache::GetAnalyticsValue(), j_key));
|
|
|
|
env->DeleteLocalRef(j_key);
|
2018-08-19 21:38:29 +00:00
|
|
|
|
2022-12-25 15:30:51 +00:00
|
|
|
std::string value = GetJString(env, j_value);
|
|
|
|
env->DeleteLocalRef(j_value);
|
2018-08-19 21:38:29 +00:00
|
|
|
|
2022-12-25 15:30:51 +00:00
|
|
|
return value;
|
2018-08-19 21:38:29 +00:00
|
|
|
}
|
|
|
|
|
2013-02-26 19:49:00 +00:00
|
|
|
extern "C" {
|
2014-03-14 21:20:44 +00:00
|
|
|
|
2020-11-07 10:57:43 +00:00
|
|
|
JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_UnPauseEmulation(JNIEnv*,
|
|
|
|
jclass)
|
2013-03-20 02:53:09 +00:00
|
|
|
{
|
2023-06-11 10:06:23 +00:00
|
|
|
HostThreadLock guard;
|
2024-05-04 03:49:48 +00:00
|
|
|
Core::SetState(Core::System::GetInstance(), Core::State::Running);
|
2013-03-20 02:53:09 +00:00
|
|
|
}
|
2020-06-21 20:40:58 +00:00
|
|
|
|
2020-11-07 10:57:43 +00:00
|
|
|
JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_PauseEmulation(JNIEnv*, jclass)
|
2013-03-20 02:53:09 +00:00
|
|
|
{
|
2023-06-11 10:06:23 +00:00
|
|
|
HostThreadLock guard;
|
2024-05-04 03:49:48 +00:00
|
|
|
Core::SetState(Core::System::GetInstance(), Core::State::Paused);
|
2013-03-20 02:53:09 +00:00
|
|
|
}
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2020-11-07 10:57:43 +00:00
|
|
|
JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_StopEmulation(JNIEnv*, jclass)
|
2016-06-24 08:43:46 +00:00
|
|
|
{
|
2023-06-11 10:06:23 +00:00
|
|
|
HostThreadLock guard;
|
2024-03-18 08:35:42 +00:00
|
|
|
Core::Stop(Core::System::GetInstance());
|
2020-07-22 20:26:20 +00:00
|
|
|
|
2020-11-06 18:26:56 +00:00
|
|
|
// Kick the waiting event
|
|
|
|
s_update_main_frame_event.Set();
|
2016-06-24 08:43:46 +00:00
|
|
|
}
|
2017-12-25 12:57:31 +00:00
|
|
|
|
2021-08-08 12:33:06 +00:00
|
|
|
JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_SetIsBooting(JNIEnv*, jclass)
|
|
|
|
{
|
|
|
|
s_is_booting.Set();
|
|
|
|
}
|
|
|
|
|
2020-11-06 20:22:22 +00:00
|
|
|
JNIEXPORT jboolean JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_IsRunning(JNIEnv*, jclass)
|
2019-11-04 16:15:13 +00:00
|
|
|
{
|
2024-06-02 13:10:25 +00:00
|
|
|
return static_cast<jboolean>(Core::IsRunning(Core::System::GetInstance()));
|
2017-12-25 12:57:31 +00:00
|
|
|
}
|
|
|
|
|
2021-08-08 12:33:06 +00:00
|
|
|
JNIEXPORT jboolean JNICALL
|
|
|
|
Java_org_dolphinemu_dolphinemu_NativeLibrary_IsRunningAndUnpaused(JNIEnv*, jclass)
|
|
|
|
{
|
2024-03-28 18:35:13 +00:00
|
|
|
return static_cast<jboolean>(Core::GetState(Core::System::GetInstance()) == Core::State::Running);
|
2021-08-08 12:33:06 +00:00
|
|
|
}
|
|
|
|
|
2024-07-02 15:27:04 +00:00
|
|
|
JNIEXPORT jboolean JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_IsUninitialized(JNIEnv*,
|
|
|
|
jclass)
|
|
|
|
{
|
|
|
|
return static_cast<jboolean>(Core::IsUninitialized(Core::System::GetInstance()) &&
|
|
|
|
!s_is_booting.IsSet());
|
|
|
|
}
|
|
|
|
|
2013-06-23 03:54:28 +00:00
|
|
|
JNIEXPORT jstring JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_GetVersionString(JNIEnv* env,
|
2020-11-07 10:57:43 +00:00
|
|
|
jclass)
|
2013-06-23 03:54:28 +00:00
|
|
|
{
|
2022-01-13 23:04:22 +00:00
|
|
|
return ToJString(env, Common::GetScmRevStr());
|
2013-06-23 03:54:28 +00:00
|
|
|
}
|
2013-11-15 20:17:47 +00:00
|
|
|
|
2017-09-10 06:43:12 +00:00
|
|
|
JNIEXPORT jstring JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_GetGitRevision(JNIEnv* env,
|
2020-11-07 10:57:43 +00:00
|
|
|
jclass)
|
2017-09-10 06:43:12 +00:00
|
|
|
{
|
2022-01-13 23:04:22 +00:00
|
|
|
return ToJString(env, Common::GetScmRevGitStr());
|
2017-09-10 06:43:12 +00:00
|
|
|
}
|
|
|
|
|
2020-11-07 10:57:43 +00:00
|
|
|
JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_SaveScreenShot(JNIEnv*, jclass)
|
2013-11-15 23:32:50 +00:00
|
|
|
{
|
2023-06-11 10:06:23 +00:00
|
|
|
HostThreadLock guard;
|
2015-05-10 14:46:46 +00:00
|
|
|
Core::SaveScreenShot();
|
2013-11-15 23:32:50 +00:00
|
|
|
}
|
|
|
|
|
2020-11-07 10:57:43 +00:00
|
|
|
JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_eglBindAPI(JNIEnv*, jclass,
|
|
|
|
jint api)
|
2014-02-11 06:16:21 +00:00
|
|
|
{
|
2015-05-10 14:46:46 +00:00
|
|
|
eglBindAPI(api);
|
2014-02-11 06:16:21 +00:00
|
|
|
}
|
|
|
|
|
2020-11-07 10:57:43 +00:00
|
|
|
JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_SaveState(JNIEnv*, jclass,
|
|
|
|
jint slot,
|
2017-12-26 21:22:42 +00:00
|
|
|
jboolean wait)
|
2013-08-29 22:47:50 +00:00
|
|
|
{
|
2023-06-11 10:06:23 +00:00
|
|
|
HostThreadLock guard;
|
2024-03-01 18:41:48 +00:00
|
|
|
State::Save(Core::System::GetInstance(), slot, wait);
|
2013-08-29 22:47:50 +00:00
|
|
|
}
|
|
|
|
|
2020-11-07 10:57:43 +00:00
|
|
|
JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_SaveStateAs(JNIEnv* env, jclass,
|
2017-12-26 21:22:42 +00:00
|
|
|
jstring path,
|
|
|
|
jboolean wait)
|
2017-12-25 12:50:29 +00:00
|
|
|
{
|
2023-06-11 10:06:23 +00:00
|
|
|
HostThreadLock guard;
|
2024-03-01 18:41:48 +00:00
|
|
|
State::SaveAs(Core::System::GetInstance(), GetJString(env, path), wait);
|
2013-08-29 22:47:50 +00:00
|
|
|
}
|
|
|
|
|
2020-11-07 10:57:43 +00:00
|
|
|
JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_LoadState(JNIEnv*, jclass,
|
|
|
|
jint slot)
|
2013-08-29 22:47:50 +00:00
|
|
|
{
|
2023-06-11 10:06:23 +00:00
|
|
|
HostThreadLock guard;
|
2024-03-01 18:41:48 +00:00
|
|
|
State::Load(Core::System::GetInstance(), slot);
|
2013-08-29 22:47:50 +00:00
|
|
|
}
|
|
|
|
|
2020-11-07 10:57:43 +00:00
|
|
|
JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_LoadStateAs(JNIEnv* env, jclass,
|
2017-12-25 12:50:29 +00:00
|
|
|
jstring path)
|
|
|
|
{
|
2023-06-11 10:06:23 +00:00
|
|
|
HostThreadLock guard;
|
2024-03-01 18:41:48 +00:00
|
|
|
State::LoadAs(Core::System::GetInstance(), GetJString(env, path));
|
2017-12-25 12:50:29 +00:00
|
|
|
}
|
|
|
|
|
2020-11-07 10:57:43 +00:00
|
|
|
JNIEXPORT jlong JNICALL
|
|
|
|
Java_org_dolphinemu_dolphinemu_NativeLibrary_GetUnixTimeOfStateSlot(JNIEnv*, jclass, jint slot)
|
2020-10-21 17:49:56 +00:00
|
|
|
{
|
|
|
|
return static_cast<jlong>(State::GetUnixTimeOfSlot(slot));
|
|
|
|
}
|
|
|
|
|
2018-09-14 04:46:30 +00:00
|
|
|
JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_utils_DirectoryInitialization_SetSysDirectory(
|
2020-11-07 10:57:43 +00:00
|
|
|
JNIEnv* env, jclass, jstring jPath)
|
2017-09-09 09:27:24 +00:00
|
|
|
{
|
|
|
|
const std::string path = GetJString(env, jPath);
|
|
|
|
File::SetSysDirectory(path);
|
|
|
|
}
|
|
|
|
|
2023-05-31 22:05:06 +00:00
|
|
|
JNIEXPORT void JNICALL
|
|
|
|
Java_org_dolphinemu_dolphinemu_utils_DirectoryInitialization_SetGpuDriverDirectories(
|
|
|
|
JNIEnv* env, jclass, jstring jPath, jstring jLibPath)
|
|
|
|
{
|
|
|
|
const std::string path = GetJString(env, jPath);
|
|
|
|
const std::string lib_path = GetJString(env, jLibPath);
|
|
|
|
File::SetGpuDriverDirectories(path, lib_path);
|
|
|
|
}
|
|
|
|
|
2015-02-25 09:23:42 +00:00
|
|
|
JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_SetUserDirectory(
|
2020-11-07 10:57:43 +00:00
|
|
|
JNIEnv* env, jclass, jstring jDirectory)
|
2015-02-25 09:23:42 +00:00
|
|
|
{
|
2023-06-11 10:06:23 +00:00
|
|
|
HostThreadLock guard;
|
2017-12-28 12:34:49 +00:00
|
|
|
UICommon::SetUserDirectory(GetJString(env, jDirectory));
|
2015-02-25 09:23:42 +00:00
|
|
|
}
|
|
|
|
|
2015-02-28 05:20:33 +00:00
|
|
|
JNIEXPORT jstring JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_GetUserDirectory(JNIEnv* env,
|
2020-11-07 10:57:43 +00:00
|
|
|
jclass)
|
2015-02-28 05:20:33 +00:00
|
|
|
{
|
2020-07-22 19:38:45 +00:00
|
|
|
return ToJString(env, File::GetUserPath(D_USER_IDX));
|
2015-02-28 05:20:33 +00:00
|
|
|
}
|
|
|
|
|
2020-07-12 11:12:08 +00:00
|
|
|
JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_SetCacheDirectory(
|
2020-11-07 10:57:43 +00:00
|
|
|
JNIEnv* env, jclass, jstring jDirectory)
|
2020-07-12 11:12:08 +00:00
|
|
|
{
|
2023-06-11 10:06:23 +00:00
|
|
|
HostThreadLock guard;
|
2021-11-22 02:40:31 +00:00
|
|
|
File::SetUserPath(D_CACHE_IDX, GetJString(env, jDirectory));
|
2020-07-12 11:12:08 +00:00
|
|
|
}
|
|
|
|
|
2023-06-13 18:44:27 +00:00
|
|
|
JNIEXPORT jstring JNICALL
|
|
|
|
Java_org_dolphinemu_dolphinemu_NativeLibrary_GetCacheDirectory(JNIEnv* env, jclass)
|
|
|
|
{
|
|
|
|
return ToJString(env, File::GetUserPath(D_CACHE_IDX));
|
|
|
|
}
|
|
|
|
|
2020-11-07 10:57:43 +00:00
|
|
|
JNIEXPORT jint JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_DefaultCPUCore(JNIEnv*, jclass)
|
2017-04-15 14:23:48 +00:00
|
|
|
{
|
2018-06-15 12:11:18 +00:00
|
|
|
return static_cast<jint>(PowerPC::DefaultCPUCore());
|
2017-04-15 14:23:48 +00:00
|
|
|
}
|
|
|
|
|
2020-07-20 15:45:59 +00:00
|
|
|
JNIEXPORT jstring JNICALL
|
2020-11-07 10:57:43 +00:00
|
|
|
Java_org_dolphinemu_dolphinemu_NativeLibrary_GetDefaultGraphicsBackendName(JNIEnv* env, jclass)
|
2020-07-20 15:45:59 +00:00
|
|
|
{
|
|
|
|
return ToJString(env, VideoBackendBase::GetDefaultBackendName());
|
|
|
|
}
|
|
|
|
|
2020-11-07 10:57:43 +00:00
|
|
|
JNIEXPORT jint JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_GetMaxLogLevel(JNIEnv*, jclass)
|
2020-07-24 17:58:46 +00:00
|
|
|
{
|
2021-10-15 19:45:27 +00:00
|
|
|
return static_cast<jint>(Common::Log::MAX_LOGLEVEL);
|
2020-07-24 17:58:46 +00:00
|
|
|
}
|
|
|
|
|
2024-04-05 23:21:10 +00:00
|
|
|
JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_WriteJitBlockLogDump(
|
|
|
|
JNIEnv* env, jclass native_library_class)
|
2015-05-11 01:03:34 +00:00
|
|
|
{
|
2023-06-11 10:06:23 +00:00
|
|
|
HostThreadLock guard;
|
2024-03-05 03:36:26 +00:00
|
|
|
auto& system = Core::System::GetInstance();
|
|
|
|
auto& jit_interface = system.GetJitInterface();
|
2024-07-28 22:45:52 +00:00
|
|
|
const Core::CPUThreadGuard cpu_guard(system);
|
2024-04-05 23:21:10 +00:00
|
|
|
if (jit_interface.GetCore() == nullptr)
|
|
|
|
{
|
|
|
|
env->CallStaticVoidMethod(native_library_class, IDCache::GetDisplayToastMsg(),
|
2024-07-28 03:22:25 +00:00
|
|
|
ToJString(env, Common::GetStringT("JIT is not active")), JNI_FALSE);
|
2024-04-05 23:21:10 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
const std::string filename = fmt::format("{}{}.txt", File::GetUserPath(D_DUMPDEBUG_JITBLOCKS_IDX),
|
|
|
|
SConfig::GetInstance().GetGameID());
|
|
|
|
File::IOFile f(filename, "w");
|
|
|
|
if (!f)
|
|
|
|
{
|
|
|
|
env->CallStaticVoidMethod(
|
|
|
|
native_library_class, IDCache::GetDisplayToastMsg(),
|
|
|
|
ToJString(env, Common::FmtFormatT("Failed to open \"{0}\" for writing.", filename)),
|
2024-07-28 03:22:25 +00:00
|
|
|
JNI_FALSE);
|
2024-04-05 23:21:10 +00:00
|
|
|
return;
|
|
|
|
}
|
2024-07-28 22:45:52 +00:00
|
|
|
jit_interface.JitBlockLogDump(cpu_guard, f.GetHandle());
|
2024-04-05 23:21:10 +00:00
|
|
|
env->CallStaticVoidMethod(native_library_class, IDCache::GetDisplayToastMsg(),
|
|
|
|
ToJString(env, Common::FmtFormatT("Wrote to \"{0}\".", filename)),
|
2024-07-28 03:22:25 +00:00
|
|
|
JNI_FALSE);
|
2015-05-11 01:03:34 +00:00
|
|
|
}
|
|
|
|
|
2016-01-10 18:31:49 +00:00
|
|
|
// Surface Handling
|
|
|
|
JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_SurfaceChanged(JNIEnv* env,
|
2020-11-07 10:57:43 +00:00
|
|
|
jclass,
|
2017-05-18 23:33:44 +00:00
|
|
|
jobject surf)
|
2013-07-27 20:09:18 +00:00
|
|
|
{
|
2020-11-06 20:22:22 +00:00
|
|
|
std::lock_guard<std::mutex> guard(s_surface_lock);
|
|
|
|
|
2017-05-18 23:33:44 +00:00
|
|
|
s_surf = ANativeWindow_fromSurface(env, surf);
|
|
|
|
if (s_surf == nullptr)
|
2015-05-24 16:04:32 +00:00
|
|
|
__android_log_print(ANDROID_LOG_ERROR, DOLPHIN_TAG, "Error: Surface is null.");
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2023-01-27 04:03:15 +00:00
|
|
|
if (g_presenter)
|
|
|
|
g_presenter->ChangeSurface(s_surf);
|
2016-06-24 08:43:46 +00:00
|
|
|
}
|
|
|
|
|
2020-11-07 10:57:43 +00:00
|
|
|
JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_SurfaceDestroyed(JNIEnv*,
|
|
|
|
jclass)
|
2016-01-10 18:31:49 +00:00
|
|
|
{
|
2021-08-08 14:22:52 +00:00
|
|
|
{
|
|
|
|
// If emulation continues running without a valid surface, we will probably crash,
|
|
|
|
// so pause emulation until we get a valid surface again. EmulationFragment handles resuming.
|
|
|
|
|
2023-06-11 10:06:23 +00:00
|
|
|
HostThreadLock host_identity_guard;
|
2021-08-08 14:22:52 +00:00
|
|
|
|
|
|
|
while (s_is_booting.IsSet())
|
|
|
|
{
|
|
|
|
// Need to wait for boot to finish before we can pause
|
2023-06-11 10:18:16 +00:00
|
|
|
host_identity_guard.Unlock();
|
2021-08-08 14:22:52 +00:00
|
|
|
std::this_thread::sleep_for(std::chrono::milliseconds(1));
|
2023-06-11 10:18:16 +00:00
|
|
|
host_identity_guard.Lock();
|
2021-08-08 14:22:52 +00:00
|
|
|
}
|
|
|
|
|
2024-03-28 18:35:13 +00:00
|
|
|
if (Core::GetState(Core::System::GetInstance()) == Core::State::Running)
|
2024-05-04 03:49:48 +00:00
|
|
|
Core::SetState(Core::System::GetInstance(), Core::State::Paused);
|
2021-08-08 14:22:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
std::lock_guard surface_guard(s_surface_lock);
|
2020-11-06 20:22:22 +00:00
|
|
|
|
2023-01-27 04:03:15 +00:00
|
|
|
if (g_presenter)
|
|
|
|
g_presenter->ChangeSurface(nullptr);
|
2016-08-13 12:08:53 +00:00
|
|
|
|
2017-05-18 23:33:44 +00:00
|
|
|
if (s_surf)
|
2016-01-10 18:31:49 +00:00
|
|
|
{
|
2017-05-18 23:33:44 +00:00
|
|
|
ANativeWindow_release(s_surf);
|
|
|
|
s_surf = nullptr;
|
2016-01-10 18:31:49 +00:00
|
|
|
}
|
2016-06-24 08:43:46 +00:00
|
|
|
}
|
2019-01-20 03:49:04 +00:00
|
|
|
|
2021-08-08 10:10:03 +00:00
|
|
|
JNIEXPORT jboolean JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_HasSurface(JNIEnv*, jclass)
|
|
|
|
{
|
|
|
|
std::lock_guard guard(s_surface_lock);
|
|
|
|
|
|
|
|
return s_surf ? JNI_TRUE : JNI_FALSE;
|
|
|
|
}
|
|
|
|
|
2020-11-07 10:57:43 +00:00
|
|
|
JNIEXPORT jfloat JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_GetGameAspectRatio(JNIEnv*,
|
|
|
|
jclass)
|
2019-01-20 03:49:04 +00:00
|
|
|
{
|
2023-01-27 04:03:15 +00:00
|
|
|
return g_presenter->CalculateDrawAspectRatio();
|
2019-01-20 03:49:04 +00:00
|
|
|
}
|
|
|
|
|
2020-11-07 10:57:43 +00:00
|
|
|
JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_RefreshWiimotes(JNIEnv*, jclass)
|
2016-02-05 00:31:36 +00:00
|
|
|
{
|
2023-06-11 10:06:23 +00:00
|
|
|
HostThreadLock guard;
|
2016-02-05 00:31:36 +00:00
|
|
|
WiimoteReal::Refresh();
|
|
|
|
}
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2020-11-07 10:57:43 +00:00
|
|
|
JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_ReloadConfig(JNIEnv*, jclass)
|
2019-06-16 12:41:58 +00:00
|
|
|
{
|
2023-06-11 11:00:52 +00:00
|
|
|
HostThreadLock guard;
|
2019-06-16 12:41:58 +00:00
|
|
|
SConfig::GetInstance().LoadSettings();
|
|
|
|
}
|
|
|
|
|
2020-08-27 11:43:20 +00:00
|
|
|
JNIEXPORT void JNICALL
|
2020-11-07 10:57:43 +00:00
|
|
|
Java_org_dolphinemu_dolphinemu_NativeLibrary_UpdateGCAdapterScanThread(JNIEnv*, jclass)
|
2020-08-27 11:43:20 +00:00
|
|
|
{
|
2023-06-11 11:00:52 +00:00
|
|
|
HostThreadLock guard;
|
2020-08-27 11:43:20 +00:00
|
|
|
if (GCAdapter::UseAdapter())
|
|
|
|
{
|
|
|
|
GCAdapter::StartScanThread();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
GCAdapter::StopScanThread();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-07 10:57:43 +00:00
|
|
|
JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_Initialize(JNIEnv*, jclass)
|
2019-06-16 12:41:58 +00:00
|
|
|
{
|
2023-06-11 11:00:52 +00:00
|
|
|
HostThreadLock guard;
|
|
|
|
|
2021-12-30 17:37:17 +00:00
|
|
|
UICommon::CreateDirectories();
|
2019-06-16 12:41:58 +00:00
|
|
|
Common::RegisterMsgAlertHandler(&MsgAlert);
|
|
|
|
Common::AndroidSetReportHandler(&ReportSend);
|
|
|
|
DolphinAnalytics::AndroidSetGetValFunc(&GetAnalyticValue);
|
2022-07-19 21:00:21 +00:00
|
|
|
|
|
|
|
WiimoteReal::InitAdapterClass();
|
2019-06-16 12:41:58 +00:00
|
|
|
UICommon::Init();
|
2022-06-25 15:31:31 +00:00
|
|
|
UICommon::InitControllers(WindowSystemInfo(WindowSystemType::Android, nullptr, nullptr, nullptr));
|
2019-06-16 12:41:58 +00:00
|
|
|
}
|
|
|
|
|
2020-11-07 10:57:43 +00:00
|
|
|
JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_ReportStartToAnalytics(JNIEnv*,
|
|
|
|
jclass)
|
2019-06-16 12:41:58 +00:00
|
|
|
{
|
|
|
|
DolphinAnalytics::Instance().ReportDolphinStart(GetAnalyticValue("DEVICE_TYPE"));
|
|
|
|
}
|
|
|
|
|
2020-11-30 18:20:58 +00:00
|
|
|
JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_GenerateNewStatisticsId(JNIEnv*,
|
|
|
|
jclass)
|
|
|
|
{
|
|
|
|
DolphinAnalytics::Instance().GenerateNewIdentity();
|
|
|
|
}
|
|
|
|
|
2019-01-22 12:45:02 +00:00
|
|
|
// Returns the scale factor for imgui rendering.
|
|
|
|
// Based on the scaledDensity of the device's display metrics.
|
|
|
|
static float GetRenderSurfaceScale(JNIEnv* env)
|
|
|
|
{
|
|
|
|
jclass native_library_class = env->FindClass("org/dolphinemu/dolphinemu/NativeLibrary");
|
2020-08-09 19:07:22 +00:00
|
|
|
jmethodID get_render_surface_scale_method =
|
|
|
|
env->GetStaticMethodID(native_library_class, "getRenderSurfaceScale", "()F");
|
|
|
|
return env->CallStaticFloatMethod(native_library_class, get_render_surface_scale_method);
|
2019-01-22 12:45:02 +00:00
|
|
|
}
|
|
|
|
|
2022-01-09 22:47:30 +00:00
|
|
|
static void Run(JNIEnv* env, std::unique_ptr<BootParameters>&& boot, bool riivolution)
|
2016-01-10 18:31:49 +00:00
|
|
|
{
|
2023-06-11 10:06:23 +00:00
|
|
|
HostThreadLock host_identity_guard;
|
2018-08-19 21:38:29 +00:00
|
|
|
|
2021-10-24 14:29:38 +00:00
|
|
|
if (riivolution && std::holds_alternative<BootParameters::Disc>(boot->parameters))
|
|
|
|
{
|
|
|
|
const std::string& riivolution_dir = File::GetUserPath(D_RIIVOLUTION_IDX);
|
|
|
|
const DiscIO::Volume& volume = *std::get<BootParameters::Disc>(boot->parameters).volume;
|
|
|
|
|
|
|
|
AddRiivolutionPatches(boot.get(), DiscIO::Riivolution::GenerateRiivolutionPatchesFromConfig(
|
|
|
|
riivolution_dir, volume.GetGameID(), volume.GetRevision(),
|
|
|
|
volume.GetDiscNumber()));
|
|
|
|
}
|
|
|
|
|
2020-03-11 13:09:28 +00:00
|
|
|
WindowSystemInfo wsi(WindowSystemType::Android, nullptr, s_surf, s_surf);
|
2019-01-22 12:45:02 +00:00
|
|
|
wsi.render_surface_scale = GetRenderSurfaceScale(env);
|
2020-11-06 08:34:53 +00:00
|
|
|
|
2020-11-06 20:22:22 +00:00
|
|
|
s_need_nonblocking_alert_msg = true;
|
|
|
|
std::unique_lock<std::mutex> surface_guard(s_surface_lock);
|
|
|
|
|
2024-03-02 07:39:04 +00:00
|
|
|
if (BootManager::BootCore(Core::System::GetInstance(), std::move(boot), wsi))
|
2015-05-24 16:04:32 +00:00
|
|
|
{
|
2016-05-12 09:17:17 +00:00
|
|
|
static constexpr int WAIT_STEP = 25;
|
2024-03-28 18:35:13 +00:00
|
|
|
while (Core::GetState(Core::System::GetInstance()) == Core::State::Starting)
|
2016-05-12 09:17:17 +00:00
|
|
|
std::this_thread::sleep_for(std::chrono::milliseconds(WAIT_STEP));
|
2020-11-06 20:22:22 +00:00
|
|
|
}
|
|
|
|
|
2021-08-08 12:33:06 +00:00
|
|
|
s_is_booting.Clear();
|
2020-11-06 20:22:22 +00:00
|
|
|
s_need_nonblocking_alert_msg = false;
|
|
|
|
surface_guard.unlock();
|
|
|
|
|
2024-04-09 03:33:55 +00:00
|
|
|
while (Core::IsRunning(Core::System::GetInstance()))
|
2020-11-06 20:22:22 +00:00
|
|
|
{
|
2023-06-11 10:18:16 +00:00
|
|
|
host_identity_guard.Unlock();
|
2022-01-29 10:14:09 +00:00
|
|
|
s_update_main_frame_event.Wait();
|
2023-06-11 10:18:16 +00:00
|
|
|
host_identity_guard.Lock();
|
2024-03-18 08:35:42 +00:00
|
|
|
Core::HostDispatchJobs(Core::System::GetInstance());
|
2016-06-24 08:43:46 +00:00
|
|
|
}
|
|
|
|
|
2020-09-13 11:20:58 +00:00
|
|
|
s_game_metadata_is_valid = false;
|
2024-03-18 08:35:42 +00:00
|
|
|
Core::Shutdown(Core::System::GetInstance());
|
2023-06-11 10:18:16 +00:00
|
|
|
host_identity_guard.Unlock();
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2020-11-06 18:26:56 +00:00
|
|
|
env->CallStaticVoidMethod(IDCache::GetNativeLibraryClass(),
|
|
|
|
IDCache::GetFinishEmulationActivity());
|
2013-02-26 19:49:00 +00:00
|
|
|
}
|
2013-07-27 20:09:18 +00:00
|
|
|
|
2022-01-09 22:47:30 +00:00
|
|
|
static void Run(JNIEnv* env, const std::vector<std::string>& paths, bool riivolution,
|
|
|
|
BootSessionData boot_session_data = BootSessionData())
|
|
|
|
{
|
|
|
|
ASSERT(!paths.empty());
|
|
|
|
__android_log_print(ANDROID_LOG_INFO, DOLPHIN_TAG, "Running : %s", paths[0].c_str());
|
|
|
|
|
|
|
|
Run(env, BootParameters::GenerateFromFile(paths, std::move(boot_session_data)), riivolution);
|
|
|
|
}
|
|
|
|
|
2021-10-24 14:29:38 +00:00
|
|
|
JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_Run___3Ljava_lang_String_2Z(
|
|
|
|
JNIEnv* env, jclass, jobjectArray jPaths, jboolean jRiivolution)
|
2017-12-26 21:08:44 +00:00
|
|
|
{
|
2021-10-24 14:29:38 +00:00
|
|
|
Run(env, JStringArrayToVector(env, jPaths), jRiivolution);
|
2017-12-26 21:08:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
JNIEXPORT void JNICALL
|
2021-10-24 14:29:38 +00:00
|
|
|
Java_org_dolphinemu_dolphinemu_NativeLibrary_Run___3Ljava_lang_String_2ZLjava_lang_String_2Z(
|
|
|
|
JNIEnv* env, jclass, jobjectArray jPaths, jboolean jRiivolution, jstring jSavestate,
|
|
|
|
jboolean jDeleteSavestate)
|
2017-12-26 21:08:44 +00:00
|
|
|
{
|
2021-11-20 18:38:09 +00:00
|
|
|
DeleteSavestateAfterBoot delete_state =
|
|
|
|
jDeleteSavestate ? DeleteSavestateAfterBoot::Yes : DeleteSavestateAfterBoot::No;
|
|
|
|
Run(env, JStringArrayToVector(env, jPaths), jRiivolution,
|
|
|
|
BootSessionData(GetJString(env, jSavestate), delete_state));
|
2017-12-26 21:08:44 +00:00
|
|
|
}
|
|
|
|
|
2022-01-09 22:47:30 +00:00
|
|
|
JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_RunSystemMenu(JNIEnv* env,
|
|
|
|
jclass)
|
|
|
|
{
|
|
|
|
Run(env, std::make_unique<BootParameters>(BootParameters::NANDTitle{Titles::SYSTEM_MENU}), false);
|
|
|
|
}
|
|
|
|
|
2020-11-07 10:57:43 +00:00
|
|
|
JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_ChangeDisc(JNIEnv* env, jclass,
|
2018-01-21 00:31:53 +00:00
|
|
|
jstring jFile)
|
|
|
|
{
|
2023-06-11 11:00:52 +00:00
|
|
|
HostThreadLock guard;
|
2018-01-21 00:31:53 +00:00
|
|
|
const std::string path = GetJString(env, jFile);
|
|
|
|
__android_log_print(ANDROID_LOG_INFO, DOLPHIN_TAG, "Change Disc: %s", path.c_str());
|
2024-03-05 00:45:25 +00:00
|
|
|
auto& system = Core::System::GetInstance();
|
|
|
|
system.GetDVDInterface().ChangeDisc(Core::CPUThreadGuard{system}, path);
|
2018-01-21 00:31:53 +00:00
|
|
|
}
|
|
|
|
|
2020-07-24 17:58:46 +00:00
|
|
|
JNIEXPORT jobject JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_GetLogTypeNames(JNIEnv* env,
|
2020-11-07 10:57:43 +00:00
|
|
|
jclass)
|
2020-07-24 17:58:46 +00:00
|
|
|
{
|
|
|
|
std::map<std::string, std::string> map = Common::Log::LogManager::GetInstance()->GetLogTypes();
|
|
|
|
|
|
|
|
auto map_size = static_cast<jsize>(map.size());
|
|
|
|
jobject linked_hash_map =
|
|
|
|
env->NewObject(IDCache::GetLinkedHashMapClass(), IDCache::GetLinkedHashMapInit(), map_size);
|
|
|
|
for (const auto& entry : map)
|
|
|
|
{
|
2022-12-25 15:30:51 +00:00
|
|
|
jstring key = ToJString(env, entry.first);
|
|
|
|
jstring value = ToJString(env, entry.second);
|
|
|
|
|
|
|
|
jobject result =
|
|
|
|
env->CallObjectMethod(linked_hash_map, IDCache::GetLinkedHashMapPut(), key, value);
|
|
|
|
|
|
|
|
env->DeleteLocalRef(key);
|
|
|
|
env->DeleteLocalRef(value);
|
|
|
|
env->DeleteLocalRef(result);
|
2020-07-24 17:58:46 +00:00
|
|
|
}
|
|
|
|
return linked_hash_map;
|
|
|
|
}
|
|
|
|
|
2020-11-07 10:57:43 +00:00
|
|
|
JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_ReloadLoggerConfig(JNIEnv*,
|
|
|
|
jclass)
|
2020-07-24 17:58:46 +00:00
|
|
|
{
|
|
|
|
Common::Log::LogManager::Init();
|
|
|
|
}
|
|
|
|
|
2020-06-24 22:02:02 +00:00
|
|
|
JNIEXPORT jboolean JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_ConvertDiscImage(
|
2020-11-07 10:57:43 +00:00
|
|
|
JNIEnv* env, jclass, jstring jInPath, jstring jOutPath, jint jPlatform, jint jFormat,
|
2020-06-25 17:38:02 +00:00
|
|
|
jint jBlockSize, jint jCompression, jint jCompressionLevel, jboolean jScrub, jobject jCallback)
|
2020-06-24 22:02:02 +00:00
|
|
|
{
|
|
|
|
const std::string in_path = GetJString(env, jInPath);
|
|
|
|
const std::string out_path = GetJString(env, jOutPath);
|
|
|
|
const DiscIO::Platform platform = static_cast<DiscIO::Platform>(jPlatform);
|
|
|
|
const DiscIO::BlobType format = static_cast<DiscIO::BlobType>(jFormat);
|
|
|
|
const DiscIO::WIARVZCompressionType compression =
|
|
|
|
static_cast<DiscIO::WIARVZCompressionType>(jCompression);
|
|
|
|
const bool scrub = static_cast<bool>(jScrub);
|
|
|
|
|
|
|
|
std::unique_ptr<DiscIO::BlobReader> blob_reader;
|
|
|
|
if (scrub)
|
|
|
|
blob_reader = DiscIO::ScrubbedBlob::Create(in_path);
|
|
|
|
else
|
|
|
|
blob_reader = DiscIO::CreateBlobReader(in_path);
|
|
|
|
|
|
|
|
if (!blob_reader)
|
2024-07-28 03:22:25 +00:00
|
|
|
return JNI_FALSE;
|
2020-06-24 22:02:02 +00:00
|
|
|
|
2020-06-25 17:38:02 +00:00
|
|
|
jobject jCallbackGlobal = env->NewGlobalRef(jCallback);
|
|
|
|
Common::ScopeGuard scope_guard([jCallbackGlobal, env] { env->DeleteGlobalRef(jCallbackGlobal); });
|
|
|
|
|
|
|
|
const auto callback = [&jCallbackGlobal](const std::string& text, float completion) {
|
|
|
|
JNIEnv* env = IDCache::GetEnvForThread();
|
2022-12-25 15:30:51 +00:00
|
|
|
|
|
|
|
jstring j_text = ToJString(env, text);
|
|
|
|
jboolean result = env->CallBooleanMethod(jCallbackGlobal, IDCache::GetCompressCallbackRun(),
|
|
|
|
j_text, completion);
|
|
|
|
env->DeleteLocalRef(j_text);
|
|
|
|
|
|
|
|
return static_cast<bool>(result);
|
2020-06-25 17:38:02 +00:00
|
|
|
};
|
2020-06-24 22:02:02 +00:00
|
|
|
|
|
|
|
bool success = false;
|
|
|
|
|
|
|
|
switch (format)
|
|
|
|
{
|
|
|
|
case DiscIO::BlobType::PLAIN:
|
|
|
|
success = DiscIO::ConvertToPlain(blob_reader.get(), in_path, out_path, callback);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DiscIO::BlobType::GCZ:
|
|
|
|
success =
|
|
|
|
DiscIO::ConvertToGCZ(blob_reader.get(), in_path, out_path,
|
|
|
|
platform == DiscIO::Platform::WiiDisc ? 1 : 0, jBlockSize, callback);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DiscIO::BlobType::WIA:
|
|
|
|
case DiscIO::BlobType::RVZ:
|
|
|
|
success = DiscIO::ConvertToWIAOrRVZ(blob_reader.get(), in_path, out_path,
|
|
|
|
format == DiscIO::BlobType::RVZ, compression,
|
|
|
|
jCompressionLevel, jBlockSize, callback);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
ASSERT(false);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return static_cast<jboolean>(success);
|
|
|
|
}
|
|
|
|
|
2020-06-21 18:41:50 +00:00
|
|
|
JNIEXPORT jstring JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_FormatSize(JNIEnv* env,
|
2020-11-07 10:57:43 +00:00
|
|
|
jclass,
|
2020-06-21 18:41:50 +00:00
|
|
|
jlong bytes,
|
|
|
|
jint decimals)
|
|
|
|
{
|
|
|
|
return ToJString(env, UICommon::FormatSize(bytes, decimals));
|
|
|
|
}
|
|
|
|
|
2020-11-07 10:57:43 +00:00
|
|
|
JNIEXPORT void JNICALL
|
|
|
|
Java_org_dolphinemu_dolphinemu_NativeLibrary_SetObscuredPixelsLeft(JNIEnv*, jclass, jint width)
|
2020-09-12 15:56:47 +00:00
|
|
|
{
|
|
|
|
OSD::SetObscuredPixelsLeft(width);
|
|
|
|
}
|
|
|
|
|
2020-11-07 10:57:43 +00:00
|
|
|
JNIEXPORT void JNICALL
|
|
|
|
Java_org_dolphinemu_dolphinemu_NativeLibrary_SetObscuredPixelsTop(JNIEnv*, jclass, jint height)
|
2020-09-12 15:56:47 +00:00
|
|
|
{
|
|
|
|
OSD::SetObscuredPixelsTop(height);
|
|
|
|
}
|
|
|
|
|
2020-11-07 10:57:43 +00:00
|
|
|
JNIEXPORT jboolean JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_IsGameMetadataValid(JNIEnv*,
|
|
|
|
jclass)
|
2020-09-13 11:20:58 +00:00
|
|
|
{
|
|
|
|
return s_game_metadata_is_valid;
|
|
|
|
}
|
|
|
|
|
|
|
|
JNIEXPORT jboolean JNICALL
|
2020-11-07 10:57:43 +00:00
|
|
|
Java_org_dolphinemu_dolphinemu_NativeLibrary_IsEmulatingWiiUnchecked(JNIEnv*, jclass)
|
2020-09-13 11:20:58 +00:00
|
|
|
{
|
2024-01-31 01:56:56 +00:00
|
|
|
return Core::System::GetInstance().IsWii();
|
2020-09-13 11:20:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
JNIEXPORT jstring JNICALL
|
2020-11-07 10:57:43 +00:00
|
|
|
Java_org_dolphinemu_dolphinemu_NativeLibrary_GetCurrentGameIDUnchecked(JNIEnv* env, jclass)
|
2020-09-13 11:20:58 +00:00
|
|
|
{
|
|
|
|
return ToJString(env, SConfig::GetInstance().GetGameID());
|
|
|
|
}
|
|
|
|
|
|
|
|
JNIEXPORT jstring JNICALL
|
|
|
|
Java_org_dolphinemu_dolphinemu_NativeLibrary_GetCurrentTitleDescriptionUnchecked(JNIEnv* env,
|
2020-11-07 10:57:43 +00:00
|
|
|
jclass)
|
2020-09-13 11:20:58 +00:00
|
|
|
{
|
2020-09-13 13:48:36 +00:00
|
|
|
// Prefer showing just the name. If no name is available, show just the game ID.
|
|
|
|
std::string description = SConfig::GetInstance().GetTitleName();
|
|
|
|
if (description.empty())
|
|
|
|
description = SConfig::GetInstance().GetTitleDescription();
|
|
|
|
|
|
|
|
return ToJString(env, description);
|
2020-09-13 11:20:58 +00:00
|
|
|
}
|
2013-02-26 19:49:00 +00:00
|
|
|
}
|