2015-05-25 05:11:41 -06:00
|
|
|
// Copyright 2003 Dolphin Emulator Project
|
2015-05-17 17:08:10 -06:00
|
|
|
// Licensed under GPLv2+
|
2015-05-25 05:11:41 -06:00
|
|
|
// Refer to the license.txt file included.
|
2013-02-26 12:49:00 -07:00
|
|
|
|
2014-02-10 23:16:21 -07:00
|
|
|
#include <EGL/egl.h>
|
2018-09-24 19:07:56 -06:00
|
|
|
#include <UICommon/GameFile.h>
|
2014-02-18 18:56:29 -07:00
|
|
|
#include <android/log.h>
|
|
|
|
#include <android/native_window_jni.h>
|
2015-12-07 02:13:25 -07:00
|
|
|
#include <cinttypes>
|
2014-02-18 18:56:29 -07:00
|
|
|
#include <cstdio>
|
|
|
|
#include <cstdlib>
|
|
|
|
#include <jni.h>
|
2015-12-06 21:15:51 -07:00
|
|
|
#include <memory>
|
2016-05-11 19:18:30 -06:00
|
|
|
#include <mutex>
|
2017-12-26 14:08:44 -07:00
|
|
|
#include <optional>
|
2017-05-18 17:33:44 -06:00
|
|
|
#include <string>
|
2016-05-12 03:17:17 -06:00
|
|
|
#include <thread>
|
2017-12-28 02:13:53 -07:00
|
|
|
#include <utility>
|
2015-12-07 02:13:25 -07:00
|
|
|
|
2018-08-19 15:38:29 -06:00
|
|
|
#include "Common/AndroidAnalytics.h"
|
2020-06-24 16:02:02 -06:00
|
|
|
#include "Common/Assert.h"
|
2014-02-18 18:56:29 -07:00
|
|
|
#include "Common/CPUDetect.h"
|
2014-02-22 15:36:30 -07:00
|
|
|
#include "Common/CommonPaths.h"
|
2014-09-07 19:06:58 -06:00
|
|
|
#include "Common/CommonTypes.h"
|
2014-04-13 17:15:23 -06:00
|
|
|
#include "Common/Event.h"
|
2014-02-18 18:56:29 -07:00
|
|
|
#include "Common/FileUtil.h"
|
2019-06-07 16:25:32 -06:00
|
|
|
#include "Common/IniFile.h"
|
2014-06-05 17:29:54 -06:00
|
|
|
#include "Common/Logging/LogManager.h"
|
2017-05-22 02:39:36 -06:00
|
|
|
#include "Common/MsgHandler.h"
|
2020-06-25 11:38:02 -06:00
|
|
|
#include "Common/ScopeGuard.h"
|
2017-09-09 13:52:35 -06:00
|
|
|
#include "Common/Version.h"
|
2018-10-03 07:03:22 -06:00
|
|
|
#include "Common/WindowSystemInfo.h"
|
2015-12-07 02:13:25 -07:00
|
|
|
|
2017-05-27 07:43:40 -06:00
|
|
|
#include "Core/Boot/Boot.h"
|
2014-02-18 18:56:29 -07:00
|
|
|
#include "Core/BootManager.h"
|
2018-02-16 11:47:52 -07:00
|
|
|
#include "Core/ConfigLoaders/GameConfigLoader.h"
|
2014-02-18 18:56:29 -07:00
|
|
|
#include "Core/ConfigManager.h"
|
|
|
|
#include "Core/Core.h"
|
2020-09-15 08:22:32 -06:00
|
|
|
#include "Core/DolphinAnalytics.h"
|
2018-01-20 17:31:53 -07:00
|
|
|
#include "Core/HW/DVD/DVDInterface.h"
|
2014-02-18 18:56:29 -07:00
|
|
|
#include "Core/HW/Wiimote.h"
|
2016-02-04 17:31:36 -07:00
|
|
|
#include "Core/HW/WiimoteReal/WiimoteReal.h"
|
2014-02-18 18:56:29 -07:00
|
|
|
#include "Core/Host.h"
|
2015-05-10 19:03:34 -06:00
|
|
|
#include "Core/PowerPC/JitInterface.h"
|
2017-04-15 08:23:48 -06:00
|
|
|
#include "Core/PowerPC/PowerPC.h"
|
2015-05-10 19:03:34 -06:00
|
|
|
#include "Core/PowerPC/Profiler.h"
|
2014-02-18 18:56:29 -07:00
|
|
|
#include "Core/State.h"
|
2013-04-14 19:39:56 -06:00
|
|
|
|
2020-06-24 16:02:02 -06:00
|
|
|
#include "DiscIO/Blob.h"
|
2016-07-06 12:33:05 -06:00
|
|
|
#include "DiscIO/Enums.h"
|
2020-06-24 16:02:02 -06:00
|
|
|
#include "DiscIO/ScrubbedBlob.h"
|
2015-12-07 02:13:25 -07:00
|
|
|
#include "DiscIO/Volume.h"
|
2013-04-23 13:21:48 -06:00
|
|
|
|
2019-11-20 11:40:47 -07:00
|
|
|
#include "InputCommon/ControllerInterface/Android/Android.h"
|
2019-11-26 23:34:01 -07:00
|
|
|
#include "InputCommon/ControllerInterface/Touch/ButtonManager.h"
|
2020-08-27 05:43:20 -06:00
|
|
|
#include "InputCommon/GCAdapter.h"
|
2019-11-20 11:40:47 -07:00
|
|
|
|
2014-10-04 13:12:15 -06:00
|
|
|
#include "UICommon/UICommon.h"
|
|
|
|
|
2014-02-18 18:56:29 -07:00
|
|
|
#include "VideoCommon/OnScreenDisplay.h"
|
2015-06-18 19:28:40 -06:00
|
|
|
#include "VideoCommon/RenderBase.h"
|
2014-02-18 18:56:29 -07:00
|
|
|
#include "VideoCommon/VideoBackendBase.h"
|
2013-02-26 12:49:00 -07:00
|
|
|
|
2019-01-22 05:45:02 -07:00
|
|
|
#include "../../Core/Common/WindowSystemInfo.h"
|
2018-06-01 01:36:29 -06:00
|
|
|
#include "jni/AndroidCommon/AndroidCommon.h"
|
|
|
|
#include "jni/AndroidCommon/IDCache.h"
|
2015-06-07 18:13:52 -06:00
|
|
|
|
2017-05-18 17:33:44 -06:00
|
|
|
namespace
|
|
|
|
{
|
2020-07-22 13:38:45 -06:00
|
|
|
constexpr char DOLPHIN_TAG[] = "DolphinEmuNative";
|
2017-05-18 17:33:44 -06:00
|
|
|
|
2018-06-01 01:36:29 -06:00
|
|
|
ANativeWindow* s_surf;
|
2017-05-18 17:33:44 -06:00
|
|
|
|
|
|
|
// The Core only supports using a single Host thread.
|
|
|
|
// If multiple threads want to call host functions then they need to queue
|
|
|
|
// sequentially for access.
|
|
|
|
std::mutex s_host_identity_lock;
|
|
|
|
Common::Event s_update_main_frame_event;
|
2020-11-06 13:22:22 -07: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;
|
|
|
|
|
2017-05-18 17:33:44 -06:00
|
|
|
bool s_have_wm_user_stop = false;
|
2020-09-13 05:20:58 -06:00
|
|
|
bool s_game_metadata_is_valid = false;
|
2017-05-18 17:33:44 -06:00
|
|
|
} // Anonymous namespace
|
2013-02-26 12:49:00 -07:00
|
|
|
|
2019-01-28 18:00:13 -07:00
|
|
|
void UpdatePointer()
|
|
|
|
{
|
|
|
|
// Update touch pointer
|
2019-05-29 06:22:26 -06:00
|
|
|
JNIEnv* env = IDCache::GetEnvForThread();
|
2019-01-28 18:00:13 -07:00
|
|
|
env->CallStaticVoidMethod(IDCache::GetNativeLibraryClass(), IDCache::GetUpdateTouchPointer());
|
|
|
|
}
|
|
|
|
|
2020-12-27 15:11:22 -07: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 {};
|
|
|
|
}
|
|
|
|
|
2013-02-26 12:49:00 -07:00
|
|
|
void Host_NotifyMapLoaded()
|
|
|
|
{
|
|
|
|
}
|
2020-12-27 15:11:22 -07:00
|
|
|
|
2013-02-26 12:49:00 -07:00
|
|
|
void Host_RefreshDSPDebuggerWindow()
|
|
|
|
{
|
|
|
|
}
|
2020-12-27 15:11:22 -07:00
|
|
|
|
2019-03-18 10:30:33 -06:00
|
|
|
bool Host_UIBlocksControllerState()
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2013-02-26 12:49:00 -07:00
|
|
|
|
2018-05-28 11:03:29 -06:00
|
|
|
void Host_Message(HostMessageID id)
|
2013-02-26 12:49:00 -07:00
|
|
|
{
|
2018-05-28 11:03:29 -06:00
|
|
|
if (id == HostMessageID::WMUserJobDispatch)
|
2016-05-11 19:18:30 -06:00
|
|
|
{
|
2017-05-18 17:33:44 -06:00
|
|
|
s_update_main_frame_event.Set();
|
2016-05-11 19:18:30 -06:00
|
|
|
}
|
2018-05-28 11:03:29 -06:00
|
|
|
else if (id == HostMessageID::WMUserStop)
|
2016-05-12 03:17:17 -06:00
|
|
|
{
|
|
|
|
s_have_wm_user_stop = true;
|
2016-05-11 19:18:30 -06:00
|
|
|
if (Core::IsRunning())
|
|
|
|
Core::QueueHostJob(&Core::Stop);
|
2016-05-12 03:17:17 -06:00
|
|
|
}
|
2013-02-26 12:49:00 -07:00
|
|
|
}
|
|
|
|
|
2014-03-12 13:33:41 -06:00
|
|
|
void Host_UpdateTitle(const std::string& title)
|
2013-07-27 14:09:18 -06:00
|
|
|
{
|
2014-03-17 17:17:12 -06:00
|
|
|
__android_log_write(ANDROID_LOG_INFO, DOLPHIN_TAG, title.c_str());
|
|
|
|
}
|
2013-02-26 12:49:00 -07:00
|
|
|
|
|
|
|
void Host_UpdateDisasmDialog()
|
2016-06-24 02:43:46 -06:00
|
|
|
{
|
2013-02-26 12:49:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void Host_UpdateMainFrame()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void Host_RequestRenderWindowSize(int width, int height)
|
|
|
|
{
|
2019-01-28 18:00:13 -07:00
|
|
|
std::thread jnicall(UpdatePointer);
|
|
|
|
jnicall.join();
|
2013-02-26 12:49:00 -07:00
|
|
|
}
|
2014-07-16 07:53:33 -06:00
|
|
|
|
2013-02-26 12:49:00 -07:00
|
|
|
bool Host_RendererHasFocus()
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2021-05-09 04:28:04 -06:00
|
|
|
bool Host_RendererHasFullFocus()
|
|
|
|
{
|
|
|
|
// Mouse cursor locking actually exists in Android but we don't implement (nor need) that
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-01-04 09:09:56 -07:00
|
|
|
bool Host_RendererIsFullscreen()
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-11-10 09:55:21 -07:00
|
|
|
void Host_YieldToUI()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2019-02-13 19:31:31 -07:00
|
|
|
void Host_TitleChanged()
|
|
|
|
{
|
2020-09-13 05:20:58 -06:00
|
|
|
s_game_metadata_is_valid = true;
|
|
|
|
|
|
|
|
JNIEnv* env = IDCache::GetEnvForThread();
|
|
|
|
env->CallStaticVoidMethod(IDCache::GetNativeLibraryClass(), IDCache::GetOnTitleChanged());
|
2019-02-13 19:31:31 -07:00
|
|
|
}
|
|
|
|
|
2020-09-25 09:50:59 -06:00
|
|
|
static bool MsgAlert(const char* caption, const char* text, bool yes_no, Common::MsgType style)
|
2015-02-12 17:41:52 -07:00
|
|
|
{
|
2019-05-29 06:22:26 -06:00
|
|
|
JNIEnv* env = IDCache::GetEnvForThread();
|
2015-06-07 18:13:52 -06:00
|
|
|
|
|
|
|
// Execute the Java method.
|
2020-11-06 13:22:22 -07:00
|
|
|
jboolean result =
|
|
|
|
env->CallStaticBooleanMethod(IDCache::GetNativeLibraryClass(), IDCache::GetDisplayAlertMsg(),
|
|
|
|
ToJString(env, caption), ToJString(env, text), yes_no,
|
|
|
|
style == Common::MsgType::Warning, s_need_nonblocking_alert_msg);
|
2015-06-07 18:13:52 -06:00
|
|
|
|
2018-01-07 15:30:28 -07:00
|
|
|
return result != JNI_FALSE;
|
2015-02-12 17:41:52 -07:00
|
|
|
}
|
|
|
|
|
2020-07-22 13:38:45 -06:00
|
|
|
static void ReportSend(const std::string& endpoint, const std::string& report)
|
2018-08-19 15:38:29 -06:00
|
|
|
{
|
2019-05-29 06:22:26 -06:00
|
|
|
JNIEnv* env = IDCache::GetEnvForThread();
|
2018-08-19 15:38:29 -06: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);
|
|
|
|
env->CallStaticVoidMethod(IDCache::GetAnalyticsClass(), IDCache::GetSendAnalyticsReport(),
|
|
|
|
ToJString(env, endpoint), output_array);
|
|
|
|
}
|
|
|
|
|
2020-07-22 13:38:45 -06:00
|
|
|
static std::string GetAnalyticValue(const std::string& key)
|
2018-08-19 15:38:29 -06:00
|
|
|
{
|
2019-05-29 06:22:26 -06:00
|
|
|
JNIEnv* env = IDCache::GetEnvForThread();
|
2018-08-19 15:38:29 -06:00
|
|
|
|
2020-07-22 13:38:45 -06:00
|
|
|
auto value = reinterpret_cast<jstring>(env->CallStaticObjectMethod(
|
2018-08-19 15:38:29 -06:00
|
|
|
IDCache::GetAnalyticsClass(), IDCache::GetAnalyticsValue(), ToJString(env, key)));
|
|
|
|
|
|
|
|
std::string stdvalue = GetJString(env, value);
|
|
|
|
|
|
|
|
return stdvalue;
|
|
|
|
}
|
|
|
|
|
2013-02-26 12:49:00 -07:00
|
|
|
extern "C" {
|
2014-03-14 15:20:44 -06:00
|
|
|
|
2020-11-07 03:57:43 -07:00
|
|
|
JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_UnPauseEmulation(JNIEnv*,
|
|
|
|
jclass)
|
2013-03-19 20:53:09 -06:00
|
|
|
{
|
2016-05-11 19:18:30 -06:00
|
|
|
std::lock_guard<std::mutex> guard(s_host_identity_lock);
|
2017-02-05 05:39:58 -07:00
|
|
|
Core::SetState(Core::State::Running);
|
2013-03-19 20:53:09 -06:00
|
|
|
}
|
2020-06-21 14:40:58 -06:00
|
|
|
|
2020-11-07 03:57:43 -07:00
|
|
|
JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_PauseEmulation(JNIEnv*, jclass)
|
2013-03-19 20:53:09 -06:00
|
|
|
{
|
2016-05-11 19:18:30 -06:00
|
|
|
std::lock_guard<std::mutex> guard(s_host_identity_lock);
|
2017-02-05 05:39:58 -07:00
|
|
|
Core::SetState(Core::State::Paused);
|
2013-03-19 20:53:09 -06:00
|
|
|
}
|
2016-06-24 02:43:46 -06:00
|
|
|
|
2020-11-07 03:57:43 -07:00
|
|
|
JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_StopEmulation(JNIEnv*, jclass)
|
2016-06-24 02:43:46 -06:00
|
|
|
{
|
2020-11-06 11:26:56 -07:00
|
|
|
std::lock_guard<std::mutex> guard(s_host_identity_lock);
|
|
|
|
Core::Stop();
|
2020-07-22 14:26:20 -06:00
|
|
|
|
2020-11-06 11:26:56 -07:00
|
|
|
// Kick the waiting event
|
|
|
|
s_update_main_frame_event.Set();
|
2016-06-24 02:43:46 -06:00
|
|
|
}
|
2017-12-25 05:57:31 -07:00
|
|
|
|
2020-11-06 13:22:22 -07:00
|
|
|
JNIEXPORT jboolean JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_IsRunning(JNIEnv*, jclass)
|
2019-11-04 09:15:13 -07:00
|
|
|
{
|
2020-11-06 13:22:22 -07:00
|
|
|
return static_cast<jboolean>(Core::IsRunning());
|
2019-11-04 09:15:13 -07:00
|
|
|
}
|
|
|
|
|
2020-11-06 13:22:22 -07:00
|
|
|
JNIEXPORT jboolean JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_IsRunningAndStarted(JNIEnv*,
|
|
|
|
jclass)
|
2017-12-25 05:57:31 -07:00
|
|
|
{
|
2020-11-06 13:22:22 -07:00
|
|
|
return static_cast<jboolean>(Core::IsRunningAndStarted());
|
2017-12-25 05:57:31 -07:00
|
|
|
}
|
|
|
|
|
2015-02-22 19:36:30 -07:00
|
|
|
JNIEXPORT jboolean JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_onGamePadEvent(
|
2020-11-07 03:57:43 -07:00
|
|
|
JNIEnv* env, jclass, jstring jDevice, jint Button, jint Action)
|
2016-06-24 02:43:46 -06:00
|
|
|
{
|
2015-02-22 19:36:30 -07:00
|
|
|
return ButtonManager::GamepadEvent(GetJString(env, jDevice), Button, Action);
|
2016-06-24 02:43:46 -06:00
|
|
|
}
|
2017-12-25 05:57:31 -07:00
|
|
|
|
2013-06-18 06:09:20 -06:00
|
|
|
JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_onGamePadMoveEvent(
|
2020-11-07 03:57:43 -07:00
|
|
|
JNIEnv* env, jclass, jstring jDevice, jint Axis, jfloat Value)
|
2016-06-24 02:43:46 -06:00
|
|
|
{
|
2015-05-10 08:46:46 -06:00
|
|
|
ButtonManager::GamepadAxisEvent(GetJString(env, jDevice), Axis, Value);
|
2016-06-24 02:43:46 -06:00
|
|
|
}
|
|
|
|
|
2019-11-20 11:40:47 -07:00
|
|
|
JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_SetMotionSensorsEnabled(
|
2020-11-07 03:57:43 -07:00
|
|
|
JNIEnv*, jclass, jboolean accelerometer_enabled, jboolean gyroscope_enabled)
|
2019-11-20 11:40:47 -07:00
|
|
|
{
|
|
|
|
ciface::Android::SetMotionSensorsEnabled(accelerometer_enabled, gyroscope_enabled);
|
|
|
|
}
|
|
|
|
|
2020-06-28 15:32:36 -06:00
|
|
|
JNIEXPORT double JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_GetInputRadiusAtAngle(
|
2020-11-07 03:57:43 -07:00
|
|
|
JNIEnv*, jclass, int emu_pad_id, int stick, double angle)
|
2020-06-28 15:32:36 -06:00
|
|
|
{
|
|
|
|
const auto casted_stick = static_cast<ButtonManager::ButtonType>(stick);
|
|
|
|
return ButtonManager::GetInputRadiusAtAngle(emu_pad_id, casted_stick, angle);
|
|
|
|
}
|
|
|
|
|
2013-06-22 21:54:28 -06:00
|
|
|
JNIEXPORT jstring JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_GetVersionString(JNIEnv* env,
|
2020-11-07 03:57:43 -07:00
|
|
|
jclass)
|
2013-06-22 21:54:28 -06:00
|
|
|
{
|
2020-07-22 13:38:45 -06:00
|
|
|
return ToJString(env, Common::scm_rev_str);
|
2013-06-22 21:54:28 -06:00
|
|
|
}
|
2013-11-15 13:17:47 -07:00
|
|
|
|
2017-09-10 00:43:12 -06:00
|
|
|
JNIEXPORT jstring JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_GetGitRevision(JNIEnv* env,
|
2020-11-07 03:57:43 -07:00
|
|
|
jclass)
|
2017-09-10 00:43:12 -06:00
|
|
|
{
|
2020-07-22 13:38:45 -06:00
|
|
|
return ToJString(env, Common::scm_rev_git_str);
|
2017-09-10 00:43:12 -06:00
|
|
|
}
|
|
|
|
|
2020-11-07 03:57:43 -07:00
|
|
|
JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_SaveScreenShot(JNIEnv*, jclass)
|
2013-11-15 16:32:50 -07:00
|
|
|
{
|
2016-05-11 19:18:30 -06:00
|
|
|
std::lock_guard<std::mutex> guard(s_host_identity_lock);
|
2015-05-10 08:46:46 -06:00
|
|
|
Core::SaveScreenShot();
|
2013-11-15 16:32:50 -07:00
|
|
|
}
|
|
|
|
|
2020-11-07 03:57:43 -07:00
|
|
|
JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_eglBindAPI(JNIEnv*, jclass,
|
|
|
|
jint api)
|
2014-02-10 23:16:21 -07:00
|
|
|
{
|
2015-05-10 08:46:46 -06:00
|
|
|
eglBindAPI(api);
|
2014-02-10 23:16:21 -07:00
|
|
|
}
|
|
|
|
|
2020-11-07 03:57:43 -07:00
|
|
|
JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_SaveState(JNIEnv*, jclass,
|
|
|
|
jint slot,
|
2017-12-26 14:22:42 -07:00
|
|
|
jboolean wait)
|
2013-08-29 16:47:50 -06:00
|
|
|
{
|
2016-05-11 19:18:30 -06:00
|
|
|
std::lock_guard<std::mutex> guard(s_host_identity_lock);
|
2017-12-26 14:22:42 -07:00
|
|
|
State::Save(slot, wait);
|
2013-08-29 16:47:50 -06:00
|
|
|
}
|
|
|
|
|
2020-11-07 03:57:43 -07:00
|
|
|
JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_SaveStateAs(JNIEnv* env, jclass,
|
2017-12-26 14:22:42 -07:00
|
|
|
jstring path,
|
|
|
|
jboolean wait)
|
2017-12-25 05:50:29 -07:00
|
|
|
{
|
|
|
|
std::lock_guard<std::mutex> guard(s_host_identity_lock);
|
2017-12-26 14:22:42 -07:00
|
|
|
State::SaveAs(GetJString(env, path), wait);
|
2013-08-29 16:47:50 -06:00
|
|
|
}
|
|
|
|
|
2020-11-07 03:57:43 -07:00
|
|
|
JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_LoadState(JNIEnv*, jclass,
|
|
|
|
jint slot)
|
2013-08-29 16:47:50 -06:00
|
|
|
{
|
2016-05-11 19:18:30 -06:00
|
|
|
std::lock_guard<std::mutex> guard(s_host_identity_lock);
|
2015-05-10 08:46:46 -06:00
|
|
|
State::Load(slot);
|
2013-08-29 16:47:50 -06:00
|
|
|
}
|
|
|
|
|
2020-11-07 03:57:43 -07:00
|
|
|
JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_LoadStateAs(JNIEnv* env, jclass,
|
2017-12-25 05:50:29 -07:00
|
|
|
jstring path)
|
|
|
|
{
|
|
|
|
std::lock_guard<std::mutex> guard(s_host_identity_lock);
|
|
|
|
State::LoadAs(GetJString(env, path));
|
|
|
|
}
|
|
|
|
|
2020-11-07 03:57:43 -07:00
|
|
|
JNIEXPORT jlong JNICALL
|
|
|
|
Java_org_dolphinemu_dolphinemu_NativeLibrary_GetUnixTimeOfStateSlot(JNIEnv*, jclass, jint slot)
|
2020-10-21 11:49:56 -06:00
|
|
|
{
|
|
|
|
return static_cast<jlong>(State::GetUnixTimeOfSlot(slot));
|
|
|
|
}
|
|
|
|
|
2018-09-13 22:46:30 -06:00
|
|
|
JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_utils_DirectoryInitialization_SetSysDirectory(
|
2020-11-07 03:57:43 -07:00
|
|
|
JNIEnv* env, jclass, jstring jPath)
|
2017-09-09 03:27:24 -06:00
|
|
|
{
|
|
|
|
const std::string path = GetJString(env, jPath);
|
|
|
|
File::SetSysDirectory(path);
|
|
|
|
}
|
|
|
|
|
|
|
|
JNIEXPORT void JNICALL
|
2020-11-07 03:57:43 -07:00
|
|
|
Java_org_dolphinemu_dolphinemu_utils_DirectoryInitialization_CreateUserDirectories(JNIEnv*, jclass)
|
2017-09-09 03:27:24 -06:00
|
|
|
{
|
|
|
|
UICommon::CreateDirectories();
|
2013-08-29 17:07:32 -06:00
|
|
|
}
|
|
|
|
|
2015-02-25 02:23:42 -07:00
|
|
|
JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_SetUserDirectory(
|
2020-11-07 03:57:43 -07:00
|
|
|
JNIEnv* env, jclass, jstring jDirectory)
|
2015-02-25 02:23:42 -07:00
|
|
|
{
|
2016-05-11 19:18:30 -06:00
|
|
|
std::lock_guard<std::mutex> guard(s_host_identity_lock);
|
2017-12-28 05:34:49 -07:00
|
|
|
UICommon::SetUserDirectory(GetJString(env, jDirectory));
|
2015-02-25 02:23:42 -07:00
|
|
|
}
|
|
|
|
|
2015-02-27 22:20:33 -07:00
|
|
|
JNIEXPORT jstring JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_GetUserDirectory(JNIEnv* env,
|
2020-11-07 03:57:43 -07:00
|
|
|
jclass)
|
2015-02-27 22:20:33 -07:00
|
|
|
{
|
2020-07-22 13:38:45 -06:00
|
|
|
return ToJString(env, File::GetUserPath(D_USER_IDX));
|
2015-02-27 22:20:33 -07:00
|
|
|
}
|
|
|
|
|
2020-07-12 05:12:08 -06:00
|
|
|
JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_SetCacheDirectory(
|
2020-11-07 03:57:43 -07:00
|
|
|
JNIEnv* env, jclass, jstring jDirectory)
|
2020-07-12 05:12:08 -06:00
|
|
|
{
|
|
|
|
std::lock_guard<std::mutex> guard(s_host_identity_lock);
|
|
|
|
File::SetUserPath(D_CACHE_IDX, GetJString(env, jDirectory) + DIR_SEP);
|
|
|
|
}
|
|
|
|
|
2020-11-07 03:57:43 -07:00
|
|
|
JNIEXPORT jint JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_DefaultCPUCore(JNIEnv*, jclass)
|
2017-04-15 08:23:48 -06:00
|
|
|
{
|
2018-06-15 06:11:18 -06:00
|
|
|
return static_cast<jint>(PowerPC::DefaultCPUCore());
|
2017-04-15 08:23:48 -06:00
|
|
|
}
|
|
|
|
|
2020-07-20 09:45:59 -06:00
|
|
|
JNIEXPORT jstring JNICALL
|
2020-11-07 03:57:43 -07:00
|
|
|
Java_org_dolphinemu_dolphinemu_NativeLibrary_GetDefaultGraphicsBackendName(JNIEnv* env, jclass)
|
2020-07-20 09:45:59 -06:00
|
|
|
{
|
|
|
|
return ToJString(env, VideoBackendBase::GetDefaultBackendName());
|
|
|
|
}
|
|
|
|
|
2020-11-07 03:57:43 -07:00
|
|
|
JNIEXPORT jint JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_GetMaxLogLevel(JNIEnv*, jclass)
|
2020-07-24 11:58:46 -06:00
|
|
|
{
|
|
|
|
return static_cast<jint>(MAX_LOGLEVEL);
|
|
|
|
}
|
|
|
|
|
2020-11-07 03:57:43 -07:00
|
|
|
JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_SetProfiling(JNIEnv*, jclass,
|
2015-05-10 19:03:34 -06:00
|
|
|
jboolean enable)
|
|
|
|
{
|
2016-05-11 19:18:30 -06:00
|
|
|
std::lock_guard<std::mutex> guard(s_host_identity_lock);
|
2017-02-05 05:39:58 -07:00
|
|
|
Core::SetState(Core::State::Paused);
|
2015-05-10 19:03:34 -06:00
|
|
|
JitInterface::ClearCache();
|
2018-08-27 09:15:24 -06:00
|
|
|
JitInterface::SetProfilingState(enable ? JitInterface::ProfilingState::Enabled :
|
|
|
|
JitInterface::ProfilingState::Disabled);
|
2017-02-05 05:39:58 -07:00
|
|
|
Core::SetState(Core::State::Running);
|
2015-05-10 19:03:34 -06:00
|
|
|
}
|
|
|
|
|
2020-11-07 03:57:43 -07:00
|
|
|
JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_WriteProfileResults(JNIEnv*,
|
|
|
|
jclass)
|
2015-05-10 19:03:34 -06:00
|
|
|
{
|
2016-05-11 19:18:30 -06:00
|
|
|
std::lock_guard<std::mutex> guard(s_host_identity_lock);
|
2015-05-10 19:03:34 -06:00
|
|
|
std::string filename = File::GetUserPath(D_DUMP_IDX) + "Debug/profiler.txt";
|
|
|
|
File::CreateFullPath(filename);
|
|
|
|
JitInterface::WriteProfileResults(filename);
|
|
|
|
}
|
|
|
|
|
2016-01-10 11:31:49 -07:00
|
|
|
// Surface Handling
|
|
|
|
JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_SurfaceChanged(JNIEnv* env,
|
2020-11-07 03:57:43 -07:00
|
|
|
jclass,
|
2017-05-18 17:33:44 -06:00
|
|
|
jobject surf)
|
2013-07-27 14:09:18 -06:00
|
|
|
{
|
2020-11-06 13:22:22 -07:00
|
|
|
std::lock_guard<std::mutex> guard(s_surface_lock);
|
|
|
|
|
2017-05-18 17:33:44 -06:00
|
|
|
s_surf = ANativeWindow_fromSurface(env, surf);
|
|
|
|
if (s_surf == nullptr)
|
2015-05-24 10:04:32 -06:00
|
|
|
__android_log_print(ANDROID_LOG_ERROR, DOLPHIN_TAG, "Error: Surface is null.");
|
2016-06-24 02:43:46 -06:00
|
|
|
|
2016-08-13 06:08:53 -06:00
|
|
|
if (g_renderer)
|
2017-05-18 17:33:44 -06:00
|
|
|
g_renderer->ChangeSurface(s_surf);
|
2016-06-24 02:43:46 -06:00
|
|
|
}
|
|
|
|
|
2020-11-07 03:57:43 -07:00
|
|
|
JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_SurfaceDestroyed(JNIEnv*,
|
|
|
|
jclass)
|
2016-01-10 11:31:49 -07:00
|
|
|
{
|
2020-11-06 13:22:22 -07:00
|
|
|
std::lock_guard<std::mutex> guard(s_surface_lock);
|
|
|
|
|
2016-08-13 06:08:53 -06:00
|
|
|
if (g_renderer)
|
|
|
|
g_renderer->ChangeSurface(nullptr);
|
|
|
|
|
2017-05-18 17:33:44 -06:00
|
|
|
if (s_surf)
|
2016-01-10 11:31:49 -07:00
|
|
|
{
|
2017-05-18 17:33:44 -06:00
|
|
|
ANativeWindow_release(s_surf);
|
|
|
|
s_surf = nullptr;
|
2016-01-10 11:31:49 -07:00
|
|
|
}
|
2016-06-24 02:43:46 -06:00
|
|
|
}
|
2019-01-19 20:49:04 -07:00
|
|
|
|
2020-11-07 03:57:43 -07:00
|
|
|
JNIEXPORT jfloat JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_GetGameAspectRatio(JNIEnv*,
|
|
|
|
jclass)
|
2019-01-19 20:49:04 -07:00
|
|
|
{
|
|
|
|
return g_renderer->CalculateDrawAspectRatio();
|
|
|
|
}
|
|
|
|
|
2020-11-07 03:57:43 -07:00
|
|
|
JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_RefreshWiimotes(JNIEnv*, jclass)
|
2016-02-04 17:31:36 -07:00
|
|
|
{
|
2016-05-11 19:18:30 -06:00
|
|
|
std::lock_guard<std::mutex> guard(s_host_identity_lock);
|
2016-02-04 17:31:36 -07:00
|
|
|
WiimoteReal::Refresh();
|
|
|
|
}
|
2016-06-24 02:43:46 -06:00
|
|
|
|
2020-11-07 03:57:43 -07:00
|
|
|
JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_ReloadWiimoteConfig(JNIEnv*,
|
|
|
|
jclass)
|
2018-10-13 05:17:14 -06:00
|
|
|
{
|
2020-04-10 08:23:32 -06:00
|
|
|
WiimoteReal::LoadSettings();
|
2018-10-13 05:17:14 -06:00
|
|
|
Wiimote::LoadConfig();
|
|
|
|
}
|
|
|
|
|
2020-11-07 03:57:43 -07:00
|
|
|
JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_ReloadConfig(JNIEnv*, jclass)
|
2019-06-16 06:41:58 -06:00
|
|
|
{
|
|
|
|
SConfig::GetInstance().LoadSettings();
|
|
|
|
}
|
|
|
|
|
2020-08-27 05:43:20 -06:00
|
|
|
JNIEXPORT void JNICALL
|
2020-11-07 03:57:43 -07:00
|
|
|
Java_org_dolphinemu_dolphinemu_NativeLibrary_UpdateGCAdapterScanThread(JNIEnv*, jclass)
|
2020-08-27 05:43:20 -06:00
|
|
|
{
|
|
|
|
if (GCAdapter::UseAdapter())
|
|
|
|
{
|
|
|
|
GCAdapter::StartScanThread();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
GCAdapter::StopScanThread();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-07 03:57:43 -07:00
|
|
|
JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_Initialize(JNIEnv*, jclass)
|
2019-06-16 06:41:58 -06:00
|
|
|
{
|
|
|
|
Common::RegisterMsgAlertHandler(&MsgAlert);
|
|
|
|
Common::AndroidSetReportHandler(&ReportSend);
|
|
|
|
DolphinAnalytics::AndroidSetGetValFunc(&GetAnalyticValue);
|
|
|
|
UICommon::Init();
|
|
|
|
}
|
|
|
|
|
2020-11-07 03:57:43 -07:00
|
|
|
JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_ReportStartToAnalytics(JNIEnv*,
|
|
|
|
jclass)
|
2019-06-16 06:41:58 -06:00
|
|
|
{
|
|
|
|
DolphinAnalytics::Instance().ReportDolphinStart(GetAnalyticValue("DEVICE_TYPE"));
|
|
|
|
}
|
|
|
|
|
2020-11-30 11:20:58 -07:00
|
|
|
JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_GenerateNewStatisticsId(JNIEnv*,
|
|
|
|
jclass)
|
|
|
|
{
|
|
|
|
DolphinAnalytics::Instance().GenerateNewIdentity();
|
|
|
|
}
|
|
|
|
|
2019-01-22 05:45:02 -07: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 13:07:22 -06: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 05:45:02 -07:00
|
|
|
}
|
|
|
|
|
2019-06-16 06:41:58 -06:00
|
|
|
static void Run(JNIEnv* env, const std::vector<std::string>& paths,
|
2020-07-22 13:38:45 -06:00
|
|
|
const std::optional<std::string>& savestate_path = {},
|
|
|
|
bool delete_savestate = false)
|
2016-01-10 11:31:49 -07:00
|
|
|
{
|
2018-12-25 05:33:22 -07:00
|
|
|
ASSERT(!paths.empty());
|
|
|
|
__android_log_print(ANDROID_LOG_INFO, DOLPHIN_TAG, "Running : %s", paths[0].c_str());
|
2016-06-24 02:43:46 -06:00
|
|
|
|
2020-11-06 13:22:22 -07:00
|
|
|
std::unique_lock<std::mutex> host_identity_guard(s_host_identity_lock);
|
2018-08-19 15:38:29 -06:00
|
|
|
|
2016-02-04 17:31:36 -07:00
|
|
|
WiimoteReal::InitAdapterClass();
|
2016-06-24 02:43:46 -06:00
|
|
|
|
2016-05-12 03:17:17 -06:00
|
|
|
s_have_wm_user_stop = false;
|
2020-11-06 01:34:53 -07:00
|
|
|
|
2018-12-25 05:33:22 -07:00
|
|
|
std::unique_ptr<BootParameters> boot = BootParameters::GenerateFromFile(paths, savestate_path);
|
2020-11-06 01:34:53 -07:00
|
|
|
if (boot)
|
|
|
|
boot->delete_savestate = delete_savestate;
|
|
|
|
|
2020-03-11 07:09:28 -06:00
|
|
|
WindowSystemInfo wsi(WindowSystemType::Android, nullptr, s_surf, s_surf);
|
2019-01-22 05:45:02 -07:00
|
|
|
wsi.render_surface_scale = GetRenderSurfaceScale(env);
|
2020-11-06 01:34:53 -07:00
|
|
|
|
2020-11-06 13:22:22 -07:00
|
|
|
s_need_nonblocking_alert_msg = true;
|
|
|
|
std::unique_lock<std::mutex> surface_guard(s_surface_lock);
|
|
|
|
|
|
|
|
bool successful_boot = BootManager::BootCore(std::move(boot), wsi);
|
|
|
|
if (successful_boot)
|
2015-05-24 10:04:32 -06:00
|
|
|
{
|
2018-08-26 16:27:27 -06:00
|
|
|
ButtonManager::Init(SConfig::GetInstance().GetGameID());
|
2020-11-06 13:22:22 -07:00
|
|
|
|
2016-05-12 03:17:17 -06:00
|
|
|
static constexpr int TIMEOUT = 10000;
|
|
|
|
static constexpr int WAIT_STEP = 25;
|
|
|
|
int time_waited = 0;
|
|
|
|
// A Core::CORE_ERROR state would be helpful here.
|
2020-11-06 13:22:22 -07:00
|
|
|
while (!Core::IsRunningAndStarted())
|
2016-05-12 03:17:17 -06:00
|
|
|
{
|
2020-11-06 13:22:22 -07:00
|
|
|
if (time_waited >= TIMEOUT || s_have_wm_user_stop)
|
|
|
|
{
|
|
|
|
successful_boot = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2016-05-12 03:17:17 -06:00
|
|
|
std::this_thread::sleep_for(std::chrono::milliseconds(WAIT_STEP));
|
|
|
|
time_waited += WAIT_STEP;
|
|
|
|
}
|
2020-11-06 13:22:22 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
s_need_nonblocking_alert_msg = false;
|
|
|
|
surface_guard.unlock();
|
|
|
|
|
|
|
|
if (successful_boot)
|
|
|
|
{
|
|
|
|
while (Core::IsRunningAndStarted())
|
2016-05-12 03:17:17 -06:00
|
|
|
{
|
2020-11-06 13:22:22 -07:00
|
|
|
host_identity_guard.unlock();
|
2017-05-18 17:33:44 -06:00
|
|
|
s_update_main_frame_event.Wait();
|
2020-11-06 13:22:22 -07:00
|
|
|
host_identity_guard.lock();
|
2016-05-11 19:18:30 -06:00
|
|
|
Core::HostDispatchJobs();
|
2015-05-24 10:04:32 -06:00
|
|
|
}
|
2016-06-24 02:43:46 -06:00
|
|
|
}
|
|
|
|
|
2020-09-13 05:20:58 -06:00
|
|
|
s_game_metadata_is_valid = false;
|
2015-06-06 06:52:09 -06:00
|
|
|
Core::Shutdown();
|
2018-10-09 08:26:31 -06:00
|
|
|
ButtonManager::Shutdown();
|
2020-11-06 13:22:22 -07:00
|
|
|
host_identity_guard.unlock();
|
2016-06-24 02:43:46 -06:00
|
|
|
|
2020-11-06 11:26:56 -07:00
|
|
|
env->CallStaticVoidMethod(IDCache::GetNativeLibraryClass(),
|
|
|
|
IDCache::GetFinishEmulationActivity());
|
2013-02-26 12:49:00 -07:00
|
|
|
}
|
2013-07-27 14:09:18 -06:00
|
|
|
|
2019-06-16 06:41:58 -06:00
|
|
|
JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_Run___3Ljava_lang_String_2(
|
2020-11-07 03:57:43 -07:00
|
|
|
JNIEnv* env, jclass, jobjectArray jPaths)
|
2017-12-26 14:08:44 -07:00
|
|
|
{
|
2019-06-16 06:41:58 -06:00
|
|
|
Run(env, JStringArrayToVector(env, jPaths));
|
2017-12-26 14:08:44 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
JNIEXPORT void JNICALL
|
2018-12-25 05:33:22 -07:00
|
|
|
Java_org_dolphinemu_dolphinemu_NativeLibrary_Run___3Ljava_lang_String_2Ljava_lang_String_2Z(
|
2020-11-07 03:57:43 -07:00
|
|
|
JNIEnv* env, jclass, jobjectArray jPaths, jstring jSavestate, jboolean jDeleteSavestate)
|
2017-12-26 14:08:44 -07:00
|
|
|
{
|
2019-06-16 06:41:58 -06:00
|
|
|
Run(env, JStringArrayToVector(env, jPaths), GetJString(env, jSavestate), jDeleteSavestate);
|
2017-12-26 14:08:44 -07:00
|
|
|
}
|
|
|
|
|
2020-11-07 03:57:43 -07:00
|
|
|
JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_ChangeDisc(JNIEnv* env, jclass,
|
2018-01-20 17:31:53 -07:00
|
|
|
jstring jFile)
|
|
|
|
{
|
|
|
|
const std::string path = GetJString(env, jFile);
|
|
|
|
__android_log_print(ANDROID_LOG_INFO, DOLPHIN_TAG, "Change Disc: %s", path.c_str());
|
|
|
|
Core::RunAsCPUThread([&path] { DVDInterface::ChangeDisc(path); });
|
|
|
|
}
|
|
|
|
|
2020-07-24 11:58:46 -06:00
|
|
|
JNIEXPORT jobject JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_GetLogTypeNames(JNIEnv* env,
|
2020-11-07 03:57:43 -07:00
|
|
|
jclass)
|
2020-07-24 11:58:46 -06: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)
|
|
|
|
{
|
|
|
|
env->CallObjectMethod(linked_hash_map, IDCache::GetLinkedHashMapPut(),
|
|
|
|
ToJString(env, entry.first), ToJString(env, entry.second));
|
|
|
|
}
|
|
|
|
return linked_hash_map;
|
|
|
|
}
|
|
|
|
|
2020-11-07 03:57:43 -07:00
|
|
|
JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_ReloadLoggerConfig(JNIEnv*,
|
|
|
|
jclass)
|
2020-07-24 11:58:46 -06:00
|
|
|
{
|
|
|
|
Common::Log::LogManager::Init();
|
|
|
|
}
|
|
|
|
|
2020-06-24 16:02:02 -06:00
|
|
|
JNIEXPORT jboolean JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_ConvertDiscImage(
|
2020-11-07 03:57:43 -07:00
|
|
|
JNIEnv* env, jclass, jstring jInPath, jstring jOutPath, jint jPlatform, jint jFormat,
|
2020-06-25 11:38:02 -06:00
|
|
|
jint jBlockSize, jint jCompression, jint jCompressionLevel, jboolean jScrub, jobject jCallback)
|
2020-06-24 16:02:02 -06: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)
|
|
|
|
return static_cast<jboolean>(false);
|
|
|
|
|
2020-06-25 11:38:02 -06: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();
|
|
|
|
return static_cast<bool>(env->CallBooleanMethod(
|
|
|
|
jCallbackGlobal, IDCache::GetCompressCallbackRun(), ToJString(env, text), completion));
|
|
|
|
};
|
2020-06-24 16:02:02 -06: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 12:41:50 -06:00
|
|
|
JNIEXPORT jstring JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_FormatSize(JNIEnv* env,
|
2020-11-07 03:57:43 -07:00
|
|
|
jclass,
|
2020-06-21 12:41:50 -06:00
|
|
|
jlong bytes,
|
|
|
|
jint decimals)
|
|
|
|
{
|
|
|
|
return ToJString(env, UICommon::FormatSize(bytes, decimals));
|
|
|
|
}
|
|
|
|
|
2020-11-07 03:57:43 -07:00
|
|
|
JNIEXPORT void JNICALL
|
|
|
|
Java_org_dolphinemu_dolphinemu_NativeLibrary_SetObscuredPixelsLeft(JNIEnv*, jclass, jint width)
|
2020-09-12 09:56:47 -06:00
|
|
|
{
|
|
|
|
OSD::SetObscuredPixelsLeft(width);
|
|
|
|
}
|
|
|
|
|
2020-11-07 03:57:43 -07:00
|
|
|
JNIEXPORT void JNICALL
|
|
|
|
Java_org_dolphinemu_dolphinemu_NativeLibrary_SetObscuredPixelsTop(JNIEnv*, jclass, jint height)
|
2020-09-12 09:56:47 -06:00
|
|
|
{
|
|
|
|
OSD::SetObscuredPixelsTop(height);
|
|
|
|
}
|
|
|
|
|
2020-11-07 03:57:43 -07:00
|
|
|
JNIEXPORT jboolean JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_IsGameMetadataValid(JNIEnv*,
|
|
|
|
jclass)
|
2020-09-13 05:20:58 -06:00
|
|
|
{
|
|
|
|
return s_game_metadata_is_valid;
|
|
|
|
}
|
|
|
|
|
|
|
|
JNIEXPORT jboolean JNICALL
|
2020-11-07 03:57:43 -07:00
|
|
|
Java_org_dolphinemu_dolphinemu_NativeLibrary_IsEmulatingWiiUnchecked(JNIEnv*, jclass)
|
2020-09-13 05:20:58 -06:00
|
|
|
{
|
|
|
|
return SConfig::GetInstance().bWii;
|
|
|
|
}
|
|
|
|
|
|
|
|
JNIEXPORT jstring JNICALL
|
2020-11-07 03:57:43 -07:00
|
|
|
Java_org_dolphinemu_dolphinemu_NativeLibrary_GetCurrentGameIDUnchecked(JNIEnv* env, jclass)
|
2020-09-13 05:20:58 -06:00
|
|
|
{
|
|
|
|
return ToJString(env, SConfig::GetInstance().GetGameID());
|
|
|
|
}
|
|
|
|
|
|
|
|
JNIEXPORT jstring JNICALL
|
|
|
|
Java_org_dolphinemu_dolphinemu_NativeLibrary_GetCurrentTitleDescriptionUnchecked(JNIEnv* env,
|
2020-11-07 03:57:43 -07:00
|
|
|
jclass)
|
2020-09-13 05:20:58 -06:00
|
|
|
{
|
2020-09-13 07:48:36 -06: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 05:20:58 -06:00
|
|
|
}
|
2013-02-26 12:49:00 -07:00
|
|
|
}
|