Skip to content

Commit

Permalink
Merge pull request #7478 from stenzek/imgui
Browse files Browse the repository at this point in the history
Replace raster font with dear imgui
  • Loading branch information
spycrab committed Jan 25, 2019
2 parents e060b13 + 774480b commit 6962d5b
Show file tree
Hide file tree
Showing 61 changed files with 1,148 additions and 2,067 deletions.
Expand Up @@ -21,7 +21,16 @@
*/
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
Expand Down
Expand Up @@ -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();
Expand Down Expand Up @@ -141,7 +141,7 @@ public static boolean OpenAdapter()
}
}

final Activity emulationActivity = NativeLibrary.sEmulationActivity.get();
final Activity emulationActivity = NativeLibrary.getEmulationActivity();
if (emulationActivity != null)
{
emulationActivity.runOnUiThread(() -> Toast.makeText(emulationActivity,
Expand Down
Expand Up @@ -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();
Expand Down
57 changes: 51 additions & 6 deletions Source/Android/jni/MainAndroid.cpp
Expand Up @@ -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"
Expand Down Expand Up @@ -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);
Expand All @@ -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());
Expand All @@ -639,6 +683,7 @@ static void Run(const std::vector<std::string>& paths, bool first_open,
}

Core::Shutdown();
ButtonManager::Shutdown();
UICommon::Shutdown();
guard.unlock();

Expand All @@ -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,
Expand Down
3 changes: 3 additions & 0 deletions Source/Core/Common/WindowSystemInfo.h
Expand Up @@ -32,4 +32,7 @@ struct WindowSystemInfo
// on the platform. e.g. HWND for Windows, Window for X11. If the surface is
// set to nullptr, the video backend will run in headless mode.
void* render_surface = nullptr;

// Scale of the render surface. For hidpi systems, this will be >1.
float render_surface_scale = 1.0f;
};
1 change: 1 addition & 0 deletions Source/Core/DolphinQt/CMakeLists.txt
Expand Up @@ -143,6 +143,7 @@ PRIVATE
core
Qt5::Widgets
uicommon
imgui
)

if(WIN32)
Expand Down
3 changes: 3 additions & 0 deletions Source/Core/DolphinQt/DolphinQt.vcxproj
Expand Up @@ -463,6 +463,9 @@
<ProjectReference Include="$(CoreDir)VideoBackends\Vulkan\Vulkan.vcxproj">
<Project>{29f29a19-f141-45ad-9679-5a2923b49da3}</Project>
</ProjectReference>
<ProjectReference Include="..\..\..\Externals\imgui\imgui.vcxproj">
<Project>{4c3b2264-ea73-4a7b-9cfe-65b0fd635ebb}</Project>
</ProjectReference>
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
Expand Down
90 changes: 69 additions & 21 deletions Source/Core/DolphinQt/HotkeyScheduler.cpp
Expand Up @@ -5,6 +5,7 @@
#include "DolphinQt/HotkeyScheduler.h"

#include <algorithm>
#include <cmath>
#include <thread>

#include <QCoreApplication>
Expand All @@ -26,6 +27,7 @@

#include "InputCommon/ControllerInterface/ControllerInterface.h"

#include "VideoCommon/OnScreenDisplay.h"
#include "VideoCommon/RenderBase.h"
#include "VideoCommon/VertexShaderManager.h"
#include "VideoCommon/VideoConfig.h"
Expand Down Expand Up @@ -286,78 +288,118 @@ void HotkeyScheduler::Run()
else if (IsHotkey(HK_NEXT_GAME_WIIMOTE_PROFILE_4))
m_profile_cycler.NextWiimoteProfileForGame(3);

const auto show_msg = [](OSDMessage message) {
if (g_renderer)
g_renderer->ShowOSDMessage(message);
auto ShowVolume = []() {
OSD::AddMessage(std::string("Volume: ") +
(SConfig::GetInstance().m_IsMuted ?
"Muted" :
std::to_string(SConfig::GetInstance().m_Volume)) +
"%");
};

// Volume
if (IsHotkey(HK_VOLUME_DOWN))
{
show_msg(OSDMessage::VolumeChanged);
settings.DecreaseVolume(3);
ShowVolume();
}

if (IsHotkey(HK_VOLUME_UP))
{
show_msg(OSDMessage::VolumeChanged);
settings.IncreaseVolume(3);
ShowVolume();
}

if (IsHotkey(HK_VOLUME_TOGGLE_MUTE))
{
show_msg(OSDMessage::VolumeChanged);
AudioCommon::ToggleMuteVolume();
ShowVolume();
}

// Graphics
const auto efb_scale = Config::Get(Config::GFX_EFB_SCALE);
auto ShowEFBScale = []() {
switch (Config::Get(Config::GFX_EFB_SCALE))
{
case EFB_SCALE_AUTO_INTEGRAL:
OSD::AddMessage("Internal Resolution: Auto (integral)");
break;
case 1:
OSD::AddMessage("Internal Resolution: Native");
break;
default:
OSD::AddMessage("Internal Resolution: %dx", g_Config.iEFBScale);
break;
}
};

if (IsHotkey(HK_INCREASE_IR))
{
show_msg(OSDMessage::IRChanged);
Config::SetCurrent(Config::GFX_EFB_SCALE, efb_scale + 1);
ShowEFBScale();
}
if (IsHotkey(HK_DECREASE_IR))
{
show_msg(OSDMessage::IRChanged);
if (efb_scale > EFB_SCALE_AUTO_INTEGRAL)
{
Config::SetCurrent(Config::GFX_EFB_SCALE, efb_scale - 1);
ShowEFBScale();
}
}

if (IsHotkey(HK_TOGGLE_CROP))
Config::SetCurrent(Config::GFX_CROP, !Config::Get(Config::GFX_CROP));

if (IsHotkey(HK_TOGGLE_AR))
{
show_msg(OSDMessage::ARToggled);
const int aspect_ratio = (static_cast<int>(Config::Get(Config::GFX_ASPECT_RATIO)) + 1) & 3;
Config::SetCurrent(Config::GFX_ASPECT_RATIO, static_cast<AspectMode>(aspect_ratio));
switch (static_cast<AspectMode>(aspect_ratio))
{
case AspectMode::Stretch:
OSD::AddMessage("Stretch");
break;
case AspectMode::Analog:
OSD::AddMessage("Force 4:3");
break;
case AspectMode::AnalogWide:
OSD::AddMessage("Force 16:9");
break;
case AspectMode::Auto:
default:
OSD::AddMessage("Auto");
break;
}
}
if (IsHotkey(HK_TOGGLE_EFBCOPIES))
{
show_msg(OSDMessage::EFBCopyToggled);
Config::SetCurrent(Config::GFX_HACK_SKIP_EFB_COPY_TO_RAM,
!Config::Get(Config::GFX_HACK_SKIP_EFB_COPY_TO_RAM));
const bool new_value = !Config::Get(Config::GFX_HACK_SKIP_EFB_COPY_TO_RAM);
Config::SetCurrent(Config::GFX_HACK_SKIP_EFB_COPY_TO_RAM, new_value);
OSD::AddMessage(StringFromFormat("Copy EFB: %s", new_value ? "to Texture" : "to RAM"));
}

auto ShowXFBCopies = []() {
OSD::AddMessage(StringFromFormat(
"Copy XFB: %s%s", Config::Get(Config::GFX_HACK_IMMEDIATE_XFB) ? " (Immediate)" : "",
Config::Get(Config::GFX_HACK_SKIP_XFB_COPY_TO_RAM) ? "to Texture" : "to RAM"));
};

if (IsHotkey(HK_TOGGLE_XFBCOPIES))
{
show_msg(OSDMessage::XFBChanged);
Config::SetCurrent(Config::GFX_HACK_SKIP_XFB_COPY_TO_RAM,
!Config::Get(Config::GFX_HACK_SKIP_XFB_COPY_TO_RAM));
ShowXFBCopies();
}
if (IsHotkey(HK_TOGGLE_IMMEDIATE_XFB))
{
show_msg(OSDMessage::XFBChanged);

Config::SetCurrent(Config::GFX_HACK_IMMEDIATE_XFB,
!Config::Get(Config::GFX_HACK_IMMEDIATE_XFB));
ShowXFBCopies();
}
if (IsHotkey(HK_TOGGLE_FOG))
{
show_msg(OSDMessage::FogToggled);
Config::SetCurrent(Config::GFX_DISABLE_FOG, !Config::Get(Config::GFX_DISABLE_FOG));
const bool new_value = !Config::Get(Config::GFX_DISABLE_FOG);
Config::SetCurrent(Config::GFX_DISABLE_FOG, new_value);
OSD::AddMessage(StringFromFormat("Fog: %s", new_value ? "Enabled" : "Disabled"));
}

if (IsHotkey(HK_TOGGLE_DUMPTEXTURES))
Expand All @@ -368,22 +410,28 @@ void HotkeyScheduler::Run()

Core::SetIsThrottlerTempDisabled(IsHotkey(HK_TOGGLE_THROTTLE, true));

auto ShowEmulationSpeed = []() {
OSD::AddMessage(
SConfig::GetInstance().m_EmulationSpeed <= 0 ?
"Speed Limit: Unlimited" :
StringFromFormat("Speed Limit: %li%%",
std::lround(SConfig::GetInstance().m_EmulationSpeed * 100.f)));
};

if (IsHotkey(HK_DECREASE_EMULATION_SPEED))
{
show_msg(OSDMessage::SpeedChanged);

auto speed = SConfig::GetInstance().m_EmulationSpeed - 0.1;
speed = (speed <= 0 || (speed >= 0.95 && speed <= 1.05)) ? 1.0 : speed;
SConfig::GetInstance().m_EmulationSpeed = speed;
ShowEmulationSpeed();
}

if (IsHotkey(HK_INCREASE_EMULATION_SPEED))
{
show_msg(OSDMessage::SpeedChanged);

auto speed = SConfig::GetInstance().m_EmulationSpeed + 0.1;
speed = (speed >= 0.95 && speed <= 1.05) ? 1.0 : speed;
SConfig::GetInstance().m_EmulationSpeed = speed;
ShowEmulationSpeed();
}

// Slot Saving / Loading
Expand Down
1 change: 1 addition & 0 deletions Source/Core/DolphinQt/MainWindow.cpp
Expand Up @@ -164,6 +164,7 @@ static WindowSystemInfo GetWindowSystemInfo(QWindow* window)
else
wsi.render_surface = window ? reinterpret_cast<void*>(window->winId()) : nullptr;
#endif
wsi.render_surface_scale = window ? static_cast<float>(window->devicePixelRatio()) : 1.0f;

return wsi;
}
Expand Down

0 comments on commit 6962d5b

Please sign in to comment.