This commit is contained in:
Nayla Hanegan 2024-05-12 02:17:59 -04:00
commit 98c174edc4
520 changed files with 74815 additions and 58942 deletions

View file

@ -12,6 +12,7 @@ static JavaVM* s_java_vm;
static jclass s_string_class;
static jclass s_native_library_class;
static jmethodID s_display_toast_msg;
static jmethodID s_display_alert_msg;
static jmethodID s_update_touch_pointer;
static jmethodID s_on_title_changed;
@ -146,6 +147,11 @@ jclass GetNativeLibraryClass()
return s_native_library_class;
}
jmethodID GetDisplayToastMsg()
{
return s_display_toast_msg;
}
jmethodID GetDisplayAlertMsg()
{
return s_display_alert_msg;
@ -528,6 +534,8 @@ JNIEXPORT jint JNI_OnLoad(JavaVM* vm, void* reserved)
const jclass native_library_class = env->FindClass("org/dolphinemu/dolphinemu/NativeLibrary");
s_native_library_class = reinterpret_cast<jclass>(env->NewGlobalRef(native_library_class));
s_display_toast_msg =
env->GetStaticMethodID(s_native_library_class, "displayToastMsg", "(Ljava/lang/String;Z)V");
s_display_alert_msg = env->GetStaticMethodID(s_native_library_class, "displayAlertMsg",
"(Ljava/lang/String;Ljava/lang/String;ZZZ)Z");
s_update_touch_pointer =

View file

@ -12,6 +12,7 @@ JNIEnv* GetEnvForThread();
jclass GetStringClass();
jclass GetNativeLibraryClass();
jmethodID GetDisplayToastMsg();
jmethodID GetDisplayAlertMsg();
jmethodID GetUpdateTouchPointer();
jmethodID GetOnTitleChanged();

View file

@ -6,6 +6,7 @@
#include <android/native_window_jni.h>
#include <cstdio>
#include <cstdlib>
#include <fmt/format.h>
#include <jni.h>
#include <memory>
#include <mutex>
@ -22,6 +23,7 @@
#include "Common/Event.h"
#include "Common/FileUtil.h"
#include "Common/Flag.h"
#include "Common/IOFile.h"
#include "Common/IniFile.h"
#include "Common/Logging/LogManager.h"
#include "Common/MsgHandler.h"
@ -42,7 +44,6 @@
#include "Core/Host.h"
#include "Core/PowerPC/JitInterface.h"
#include "Core/PowerPC/PowerPC.h"
#include "Core/PowerPC/Profiler.h"
#include "Core/State.h"
#include "Core/System.h"
@ -96,7 +97,7 @@ std::vector<std::string> Host_GetPreferredLocales()
return {};
}
void Host_NotifyMapLoaded()
void Host_PPCSymbolsChanged()
{
}
@ -117,7 +118,7 @@ void Host_Message(HostMessageID id)
}
else if (id == HostMessageID::WMUserStop)
{
if (Core::IsRunning())
if (Core::IsRunning(Core::System::GetInstance()))
Core::QueueHostJob(&Core::Stop);
}
}
@ -246,19 +247,19 @@ JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_UnPauseEmula
jclass)
{
HostThreadLock guard;
Core::SetState(Core::State::Running);
Core::SetState(Core::System::GetInstance(), Core::State::Running);
}
JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_PauseEmulation(JNIEnv*, jclass)
{
HostThreadLock guard;
Core::SetState(Core::State::Paused);
Core::SetState(Core::System::GetInstance(), Core::State::Paused);
}
JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_StopEmulation(JNIEnv*, jclass)
{
HostThreadLock guard;
Core::Stop();
Core::Stop(Core::System::GetInstance());
// Kick the waiting event
s_update_main_frame_event.Set();
@ -271,7 +272,8 @@ JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_SetIsBooting
JNIEXPORT jboolean JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_IsRunning(JNIEnv*, jclass)
{
return s_is_booting.IsSet() || static_cast<jboolean>(Core::IsRunning());
return s_is_booting.IsSet() ||
static_cast<jboolean>(Core::IsRunning(Core::System::GetInstance()));
}
JNIEXPORT jboolean JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_IsRunningAndStarted(JNIEnv*,
@ -283,7 +285,7 @@ JNIEXPORT jboolean JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_IsRunnin
JNIEXPORT jboolean JNICALL
Java_org_dolphinemu_dolphinemu_NativeLibrary_IsRunningAndUnpaused(JNIEnv*, jclass)
{
return static_cast<jboolean>(Core::GetState() == Core::State::Running);
return static_cast<jboolean>(Core::GetState(Core::System::GetInstance()) == Core::State::Running);
}
JNIEXPORT jstring JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_GetVersionString(JNIEnv* env,
@ -315,7 +317,7 @@ JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_SaveState(JN
jboolean wait)
{
HostThreadLock guard;
State::Save(slot, wait);
State::Save(Core::System::GetInstance(), slot, wait);
}
JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_SaveStateAs(JNIEnv* env, jclass,
@ -323,21 +325,21 @@ JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_SaveStateAs(
jboolean wait)
{
HostThreadLock guard;
State::SaveAs(GetJString(env, path), wait);
State::SaveAs(Core::System::GetInstance(), GetJString(env, path), wait);
}
JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_LoadState(JNIEnv*, jclass,
jint slot)
{
HostThreadLock guard;
State::Load(slot);
State::Load(Core::System::GetInstance(), slot);
}
JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_LoadStateAs(JNIEnv* env, jclass,
jstring path)
{
HostThreadLock guard;
State::LoadAs(GetJString(env, path));
State::LoadAs(Core::System::GetInstance(), GetJString(env, path));
}
JNIEXPORT jlong JNICALL
@ -404,26 +406,34 @@ JNIEXPORT jint JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_GetMaxLogLev
return static_cast<jint>(Common::Log::MAX_LOGLEVEL);
}
JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_SetProfiling(JNIEnv*, jclass,
jboolean enable)
JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_WriteJitBlockLogDump(
JNIEnv* env, jclass native_library_class)
{
HostThreadLock guard;
Core::SetState(Core::State::Paused);
auto& jit_interface = Core::System::GetInstance().GetJitInterface();
jit_interface.ClearCache();
jit_interface.SetProfilingState(enable ? JitInterface::ProfilingState::Enabled :
JitInterface::ProfilingState::Disabled);
Core::SetState(Core::State::Running);
}
JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_WriteProfileResults(JNIEnv*,
jclass)
{
HostThreadLock guard;
std::string filename = File::GetUserPath(D_DUMP_IDX) + "Debug/profiler.txt";
File::CreateFullPath(filename);
auto& jit_interface = Core::System::GetInstance().GetJitInterface();
jit_interface.WriteProfileResults(filename);
auto& system = Core::System::GetInstance();
auto& jit_interface = system.GetJitInterface();
if (jit_interface.GetCore() == nullptr)
{
env->CallStaticVoidMethod(native_library_class, IDCache::GetDisplayToastMsg(),
ToJString(env, Common::GetStringT("JIT is not active")),
static_cast<jboolean>(false));
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)),
static_cast<jboolean>(false));
return;
}
jit_interface.JitBlockLogDump(Core::CPUThreadGuard{system}, f.GetHandle());
env->CallStaticVoidMethod(native_library_class, IDCache::GetDisplayToastMsg(),
ToJString(env, Common::FmtFormatT("Wrote to \"{0}\".", filename)),
static_cast<jboolean>(false));
}
// Surface Handling
@ -458,8 +468,8 @@ JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_SurfaceDestr
host_identity_guard.Lock();
}
if (Core::GetState() == Core::State::Running)
Core::SetState(Core::State::Paused);
if (Core::GetState(Core::System::GetInstance()) == Core::State::Running)
Core::SetState(Core::System::GetInstance(), Core::State::Paused);
}
std::lock_guard surface_guard(s_surface_lock);
@ -515,7 +525,6 @@ Java_org_dolphinemu_dolphinemu_NativeLibrary_UpdateGCAdapterScanThread(JNIEnv*,
JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_Initialize(JNIEnv*, jclass)
{
// InitControllers ends up calling config code, and some config callbacks use RunAsCPUThread
HostThreadLock guard;
UICommon::CreateDirectories();
@ -570,10 +579,10 @@ static void Run(JNIEnv* env, std::unique_ptr<BootParameters>&& boot, bool riivol
s_need_nonblocking_alert_msg = true;
std::unique_lock<std::mutex> surface_guard(s_surface_lock);
if (BootManager::BootCore(std::move(boot), wsi))
if (BootManager::BootCore(Core::System::GetInstance(), std::move(boot), wsi))
{
static constexpr int WAIT_STEP = 25;
while (Core::GetState() == Core::State::Starting)
while (Core::GetState(Core::System::GetInstance()) == Core::State::Starting)
std::this_thread::sleep_for(std::chrono::milliseconds(WAIT_STEP));
}
@ -581,16 +590,16 @@ static void Run(JNIEnv* env, std::unique_ptr<BootParameters>&& boot, bool riivol
s_need_nonblocking_alert_msg = false;
surface_guard.unlock();
while (Core::IsRunning())
while (Core::IsRunning(Core::System::GetInstance()))
{
host_identity_guard.Unlock();
s_update_main_frame_event.Wait();
host_identity_guard.Lock();
Core::HostDispatchJobs();
Core::HostDispatchJobs(Core::System::GetInstance());
}
s_game_metadata_is_valid = false;
Core::Shutdown();
Core::Shutdown(Core::System::GetInstance());
host_identity_guard.Unlock();
env->CallStaticVoidMethod(IDCache::GetNativeLibraryClass(),
@ -635,7 +644,8 @@ JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_ChangeDisc(J
HostThreadLock guard;
const std::string path = GetJString(env, jFile);
__android_log_print(ANDROID_LOG_INFO, DOLPHIN_TAG, "Change Disc: %s", path.c_str());
Core::RunAsCPUThread([&path] { Core::System::GetInstance().GetDVDInterface().ChangeDisc(path); });
auto& system = Core::System::GetInstance();
system.GetDVDInterface().ChangeDisc(Core::CPUThreadGuard{system}, path);
}
JNIEXPORT jobject JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_GetLogTypeNames(JNIEnv* env,