mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-07-23 06:09:50 -06:00
Merge pull request #7478 from stenzek/imgui
Replace raster font with dear imgui
This commit is contained in:
@ -21,7 +21,16 @@ import java.lang.ref.WeakReference;
|
||||
*/
|
||||
public final class NativeLibrary
|
||||
{
|
||||
public static WeakReference<EmulationActivity> sEmulationActivity = new WeakReference<>(null);
|
||||
private static WeakReference<EmulationActivity> sEmulationActivity = new WeakReference<>(null);
|
||||
|
||||
/**
|
||||
* Returns the current instance of EmulationActivity.
|
||||
* There should only ever be one EmulationActivity instantiated.
|
||||
*/
|
||||
public static EmulationActivity getEmulationActivity()
|
||||
{
|
||||
return sEmulationActivity.get();
|
||||
}
|
||||
|
||||
/**
|
||||
* Button type for use in onTouchEvent
|
||||
|
@ -31,7 +31,7 @@ public class Java_GCAdapter
|
||||
|
||||
private static void RequestPermission()
|
||||
{
|
||||
Context context = NativeLibrary.sEmulationActivity.get();
|
||||
Context context = NativeLibrary.getEmulationActivity();
|
||||
if (context != null)
|
||||
{
|
||||
HashMap<String, UsbDevice> devices = manager.getDeviceList();
|
||||
@ -141,7 +141,7 @@ public class Java_GCAdapter
|
||||
}
|
||||
}
|
||||
|
||||
final Activity emulationActivity = NativeLibrary.sEmulationActivity.get();
|
||||
final Activity emulationActivity = NativeLibrary.getEmulationActivity();
|
||||
if (emulationActivity != null)
|
||||
{
|
||||
emulationActivity.runOnUiThread(() -> Toast.makeText(emulationActivity,
|
||||
|
@ -34,7 +34,7 @@ public class Java_WiimoteAdapter
|
||||
|
||||
private static void RequestPermission()
|
||||
{
|
||||
Context context = NativeLibrary.sEmulationActivity.get();
|
||||
Context context = NativeLibrary.getEmulationActivity();
|
||||
if (context != null)
|
||||
{
|
||||
HashMap<String, UsbDevice> devices = manager.getDeviceList();
|
||||
|
@ -52,6 +52,7 @@
|
||||
#include "VideoCommon/RenderBase.h"
|
||||
#include "VideoCommon/VideoBackendBase.h"
|
||||
|
||||
#include "../../Core/Common/WindowSystemInfo.h"
|
||||
#include "jni/AndroidCommon/AndroidCommon.h"
|
||||
#include "jni/AndroidCommon/IDCache.h"
|
||||
#include "jni/ButtonManager.h"
|
||||
@ -589,15 +590,57 @@ JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_ReloadWiimot
|
||||
Wiimote::LoadConfig();
|
||||
}
|
||||
|
||||
static void Run(const std::vector<std::string>& paths, bool first_open,
|
||||
// Returns the scale factor for imgui rendering.
|
||||
// Based on the scaledDensity of the device's display metrics.
|
||||
static float GetRenderSurfaceScale(JNIEnv* env)
|
||||
{
|
||||
// NativeLibrary emulation_activity = NativeLibrary.getEmulationActivity();
|
||||
jclass native_library_class = env->FindClass("org/dolphinemu/dolphinemu/NativeLibrary");
|
||||
jmethodID get_emulation_activity_method =
|
||||
env->GetStaticMethodID(native_library_class, "getEmulationActivity",
|
||||
"()Lorg/dolphinemu/dolphinemu/activities/EmulationActivity;");
|
||||
jobject emulation_activity =
|
||||
env->CallStaticObjectMethod(native_library_class, get_emulation_activity_method);
|
||||
|
||||
// WindowManager window_manager = emulation_activity.getWindowManager();
|
||||
jmethodID get_window_manager_method =
|
||||
env->GetMethodID(env->GetObjectClass(emulation_activity), "getWindowManager",
|
||||
"()Landroid/view/WindowManager;");
|
||||
jobject window_manager = env->CallObjectMethod(emulation_activity, get_window_manager_method);
|
||||
|
||||
// Display display = window_manager.getDisplay();
|
||||
jmethodID get_display_method = env->GetMethodID(env->GetObjectClass(window_manager),
|
||||
"getDefaultDisplay", "()Landroid/view/Display;");
|
||||
jobject display = env->CallObjectMethod(window_manager, get_display_method);
|
||||
|
||||
// DisplayMetrics metrics = new DisplayMetrics();
|
||||
jclass display_metrics_class = env->FindClass("android/util/DisplayMetrics");
|
||||
jmethodID display_metrics_constructor = env->GetMethodID(display_metrics_class, "<init>", "()V");
|
||||
jobject metrics = env->NewObject(display_metrics_class, display_metrics_constructor);
|
||||
|
||||
// display.getMetrics(metrics);
|
||||
jmethodID get_metrics_method = env->GetMethodID(env->GetObjectClass(display), "getMetrics",
|
||||
"(Landroid/util/DisplayMetrics;)V");
|
||||
env->CallVoidMethod(display, get_metrics_method, metrics);
|
||||
|
||||
// float scaled_density = metrics.scaledDensity;
|
||||
jfieldID scaled_density_field =
|
||||
env->GetFieldID(env->GetObjectClass(metrics), "scaledDensity", "F");
|
||||
float scaled_density = env->GetFloatField(metrics, scaled_density_field);
|
||||
__android_log_print(ANDROID_LOG_INFO, DOLPHIN_TAG, "Using %f for render surface scale.",
|
||||
scaled_density);
|
||||
|
||||
// cleanup
|
||||
env->DeleteLocalRef(metrics);
|
||||
return scaled_density;
|
||||
}
|
||||
|
||||
static void Run(JNIEnv* env, const std::vector<std::string>& paths, bool first_open,
|
||||
std::optional<std::string> savestate_path = {}, bool delete_savestate = false)
|
||||
{
|
||||
ASSERT(!paths.empty());
|
||||
__android_log_print(ANDROID_LOG_INFO, DOLPHIN_TAG, "Running : %s", paths[0].c_str());
|
||||
|
||||
// Install our callbacks
|
||||
OSD::AddCallback(OSD::CallbackType::Shutdown, ButtonManager::Shutdown);
|
||||
|
||||
RegisterMsgAlertHandler(&MsgAlert);
|
||||
Common::AndroidSetReportHandler(&ReportSend);
|
||||
DolphinAnalytics::AndroidSetGetValFunc(&GetAnalyticValue);
|
||||
@ -617,6 +660,7 @@ static void Run(const std::vector<std::string>& paths, bool first_open,
|
||||
std::unique_ptr<BootParameters> boot = BootParameters::GenerateFromFile(paths, savestate_path);
|
||||
boot->delete_savestate = delete_savestate;
|
||||
WindowSystemInfo wsi(WindowSystemType::Android, nullptr, s_surf);
|
||||
wsi.render_surface_scale = GetRenderSurfaceScale(env);
|
||||
if (BootManager::BootCore(std::move(boot), wsi))
|
||||
{
|
||||
ButtonManager::Init(SConfig::GetInstance().GetGameID());
|
||||
@ -639,6 +683,7 @@ static void Run(const std::vector<std::string>& paths, bool first_open,
|
||||
}
|
||||
|
||||
Core::Shutdown();
|
||||
ButtonManager::Shutdown();
|
||||
UICommon::Shutdown();
|
||||
guard.unlock();
|
||||
|
||||
@ -652,14 +697,14 @@ static void Run(const std::vector<std::string>& paths, bool first_open,
|
||||
JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_Run___3Ljava_lang_String_2Z(
|
||||
JNIEnv* env, jobject obj, jobjectArray jPaths, jboolean jfirstOpen)
|
||||
{
|
||||
Run(JStringArrayToVector(env, jPaths), jfirstOpen);
|
||||
Run(env, JStringArrayToVector(env, jPaths), jfirstOpen);
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL
|
||||
Java_org_dolphinemu_dolphinemu_NativeLibrary_Run___3Ljava_lang_String_2Ljava_lang_String_2Z(
|
||||
JNIEnv* env, jobject obj, jobjectArray jPaths, jstring jSavestate, jboolean jDeleteSavestate)
|
||||
{
|
||||
Run(JStringArrayToVector(env, jPaths), false, GetJString(env, jSavestate), jDeleteSavestate);
|
||||
Run(env, JStringArrayToVector(env, jPaths), false, GetJString(env, jSavestate), jDeleteSavestate);
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_ChangeDisc(JNIEnv* env,
|
||||
|
Reference in New Issue
Block a user