Android: Add sustained performance mode option

This commit is contained in:
Connor McLaughlin 2021-01-13 20:09:30 +10:00
parent 93959a9d88
commit 3b433d8d3e
3 changed files with 27 additions and 0 deletions

View file

@ -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;
}
}

View file

@ -193,4 +193,6 @@
<string name="settings_summary_audio_resampling">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.</string>
<string name="settings_general_sync_to_host_refresh_rate">Sync To Host Refresh Rate</string>
<string name="settings_summary_general_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%.</string>
<string name="settings_sustained_performance_mode">Sustained Performance Mode</string>
<string name="settings_summary_sustained_performance_mode">Enables Android\'s sustained performance mode. May result in more consistent framerates for long sessions on some devices.</string>
</resources>

View file

@ -29,6 +29,12 @@
app:defaultValue="false"
app:summary="@string/settings_summary_disable_all_enhancements"
app:iconSpaceReserved="false" />
<SwitchPreferenceCompat
app:key="Main/SustainedPerformanceMode"
app:title="@string/settings_sustained_performance_mode"
app:defaultValue="false"
app:summary="@string/settings_summary_sustained_performance_mode"
app:iconSpaceReserved="false" />
<ListPreference
app:key="CPU/Overclock"
app:title="@string/settings_cpu_overclocking"