From 3b433d8d3ecc883cb31fa7038023f2b2b316bc11 Mon Sep 17 00:00:00 2001 From: Connor McLaughlin Date: Wed, 13 Jan 2021 20:09:30 +1000 Subject: [PATCH] Android: Add sustained performance mode option --- .../duckstation/EmulationActivity.java | 19 +++++++++++++++++++ android/app/src/main/res/values/strings.xml | 2 ++ .../src/main/res/xml/advanced_preferences.xml | 6 ++++++ 3 files changed, 27 insertions(+) diff --git a/android/app/src/main/java/com/github/stenzek/duckstation/EmulationActivity.java b/android/app/src/main/java/com/github/stenzek/duckstation/EmulationActivity.java index 53f9169c7..eb5cdf55d 100644 --- a/android/app/src/main/java/com/github/stenzek/duckstation/EmulationActivity.java +++ b/android/app/src/main/java/com/github/stenzek/duckstation/EmulationActivity.java @@ -16,6 +16,7 @@ import android.view.KeyEvent; import android.view.MotionEvent; import android.view.SurfaceHolder; import android.view.View; +import android.view.Window; import android.view.WindowManager; import android.widget.FrameLayout; import android.widget.Toast; @@ -164,6 +165,7 @@ public class EmulationActivity extends AppCompatActivity implements SurfaceHolde AndroidHostInterface.getInstance().applySettings(); updateRequestedOrientation(); updateControllers(); + updateSustainedPerformanceMode(); } private void applySettings() { @@ -255,6 +257,7 @@ public class EmulationActivity extends AppCompatActivity implements SurfaceHolde // Sort out rotation. updateRequestedOrientation(); updateOrientation(); + updateSustainedPerformanceMode(); // Hook up controller input. updateControllers(); @@ -674,4 +677,20 @@ public class EmulationActivity extends AppCompatActivity implements SurfaceHolde mVibratorService.cancel(); }); } + + private boolean mSustainedPerformanceModeEnabled = false; + private void updateSustainedPerformanceMode() { + final boolean enabled = getBooleanSetting("Main/SustainedPerformanceMode", false); + if (mSustainedPerformanceModeEnabled == enabled) + return; + + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { + getWindow().setSustainedPerformanceMode(enabled); + Log.i("EmulationActivity", String.format("%s sustained performance mode.", enabled ? "enabling" : "disabling")); + } else { + Log.e("EmulationActivity", "Sustained performance mode not supported."); + } + mSustainedPerformanceModeEnabled = enabled; + + } } diff --git a/android/app/src/main/res/values/strings.xml b/android/app/src/main/res/values/strings.xml index 4e9aae80a..8f18a66fc 100644 --- a/android/app/src/main/res/values/strings.xml +++ b/android/app/src/main/res/values/strings.xml @@ -193,4 +193,6 @@ When running outside of 100% speed, resamples audio from the target speed instead of dropping frames. Produces much nicer fast forward/slowdown audio at a small cost to performance. Sync To Host Refresh Rate Adjusts the emulation speed so the console\'s refresh rate matches the host\'s refresh rate, when VSync and Audio Resampling is enabled. This results in the smoothest animations possible, at the cost of potentially increasing the emulation speed by less than 1%. + Sustained Performance Mode + Enables Android\'s sustained performance mode. May result in more consistent framerates for long sessions on some devices. diff --git a/android/app/src/main/res/xml/advanced_preferences.xml b/android/app/src/main/res/xml/advanced_preferences.xml index c392f9219..83dab7b56 100644 --- a/android/app/src/main/res/xml/advanced_preferences.xml +++ b/android/app/src/main/res/xml/advanced_preferences.xml @@ -29,6 +29,12 @@ app:defaultValue="false" app:summary="@string/settings_summary_disable_all_enhancements" app:iconSpaceReserved="false" /> +