mirror of
https://github.com/libretro/RetroArch
synced 2025-03-01 16:13:40 +00:00
Merge pull request #6898 from libretro/android_susperf_setting
android: add configurable setting for Sustained Performance Mode
This commit is contained in:
commit
76d540a075
@ -694,6 +694,9 @@ static const char *midi_input = "Off";
|
||||
static const char *midi_output = "Off";
|
||||
static const unsigned midi_volume = 100;
|
||||
|
||||
/* Only applies to Android 7.0 (API 24) and up */
|
||||
static const bool sustained_performance_mode = true;
|
||||
|
||||
#if defined(ANDROID)
|
||||
#if defined(ANDROID_ARM)
|
||||
static char buildbot_server_url[] = "http://buildbot.libretro.com/nightly/android/latest/armeabi-v7a/";
|
||||
|
@ -1445,6 +1445,8 @@ static struct config_bool_setting *populate_settings_bool(settings_t *settings,
|
||||
SETTING_BOOL("video_msg_bgcolor_enable", &settings->bools.video_msg_bgcolor_enable, true, message_bgcolor_enable, false);
|
||||
SETTING_BOOL("video_window_show_decorations", &settings->bools.video_window_show_decorations, true, window_decorations, false);
|
||||
|
||||
SETTING_BOOL("sustained_performance_mode", &settings->bools.sustained_performance_mode, true, sustained_performance_mode, false);
|
||||
|
||||
*size = count;
|
||||
|
||||
return tmp;
|
||||
@ -2941,8 +2943,10 @@ static bool config_load_file(const char *path, bool set_defaults,
|
||||
settings->arrays.video_driver);
|
||||
settings->paths.path_shader[0] = '\0';
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
frontend_driver_set_sustained_performance_mode(settings->bools.sustained_performance_mode);
|
||||
|
||||
ret = true;
|
||||
|
||||
|
@ -96,7 +96,7 @@ typedef struct settings
|
||||
bool video_statistics_show;
|
||||
bool video_framecount_show;
|
||||
bool video_msg_bgcolor_enable;
|
||||
bool crt_switch_resolution;
|
||||
bool crt_switch_resolution;
|
||||
|
||||
/* Audio */
|
||||
bool audio_enable;
|
||||
@ -275,6 +275,8 @@ typedef struct settings
|
||||
|
||||
bool automatically_add_content_to_playlist;
|
||||
bool video_window_show_decorations;
|
||||
|
||||
bool sustained_performance_mode;
|
||||
} bools;
|
||||
|
||||
struct
|
||||
@ -351,7 +353,7 @@ typedef struct settings
|
||||
unsigned video_window_x;
|
||||
unsigned video_window_y;
|
||||
unsigned video_window_opacity;
|
||||
unsigned crt_switch_resolution_super;
|
||||
unsigned crt_switch_resolution_super;
|
||||
unsigned video_monitor_index;
|
||||
unsigned video_fullscreen_x;
|
||||
unsigned video_fullscreen_y;
|
||||
|
@ -589,5 +589,6 @@ frontend_ctx_driver_t frontend_ctx_ctr =
|
||||
NULL, /* detach_console */
|
||||
NULL, /* watch_path_for_changes */
|
||||
NULL, /* check_for_path_changes */
|
||||
NULL, /* set_sustained_performance_mode */
|
||||
"ctr",
|
||||
};
|
||||
|
@ -70,5 +70,6 @@ frontend_ctx_driver_t frontend_ctx_dos = {
|
||||
NULL, /* detach_console */
|
||||
NULL, /* watch_path_for_changes */
|
||||
NULL, /* check_for_path_changes */
|
||||
NULL, /* set_sustained_performance_mode */
|
||||
"dos",
|
||||
};
|
||||
|
@ -262,5 +262,6 @@ frontend_ctx_driver_t frontend_ctx_emscripten = {
|
||||
NULL, /* detach_console */
|
||||
NULL, /* watch_path_for_changes */
|
||||
NULL, /* check_for_path_changes */
|
||||
NULL, /* set_sustained_performance_mode */
|
||||
"emscripten"
|
||||
};
|
||||
|
@ -559,5 +559,6 @@ frontend_ctx_driver_t frontend_ctx_gx = {
|
||||
NULL, /* detach_console */
|
||||
NULL, /* watch_path_for_changes */
|
||||
NULL, /* check_for_path_changes */
|
||||
NULL, /* set_sustained_performance_mode */
|
||||
"gx",
|
||||
};
|
||||
|
@ -46,5 +46,6 @@ frontend_ctx_driver_t frontend_ctx_null = {
|
||||
#endif
|
||||
NULL, /* watch_path_for_changes */
|
||||
NULL, /* check_for_path_changes */
|
||||
NULL, /* set_sustained_performance_mode */
|
||||
"null",
|
||||
};
|
||||
|
@ -634,5 +634,6 @@ frontend_ctx_driver_t frontend_ctx_ps3 = {
|
||||
NULL, /* detach_console */
|
||||
NULL, /* watch_path_for_changes */
|
||||
NULL, /* check_for_path_changes */
|
||||
NULL, /* set_sustained_performance_mode */
|
||||
"ps3",
|
||||
};
|
||||
|
@ -520,6 +520,7 @@ frontend_ctx_driver_t frontend_ctx_psp = {
|
||||
NULL, /* detach_console */
|
||||
NULL, /* watch_path_for_changes */
|
||||
NULL, /* check_for_path_changes */
|
||||
NULL, /* set_sustained_performance_mode */
|
||||
#ifdef VITA
|
||||
"vita",
|
||||
#else
|
||||
|
@ -204,5 +204,6 @@ frontend_ctx_driver_t frontend_ctx_qnx = {
|
||||
NULL, /* detach_console */
|
||||
NULL, /* watch_path_for_changes */
|
||||
NULL, /* check_for_path_changes */
|
||||
NULL, /* set_sustained_performance_mode */
|
||||
"qnx",
|
||||
};
|
||||
|
@ -95,6 +95,8 @@ enum
|
||||
INTERNAL_STORAGE_NOT_WRITABLE
|
||||
};
|
||||
|
||||
static void frontend_unix_set_sustained_performance_mode(bool on);
|
||||
|
||||
struct android_app *g_android = NULL;
|
||||
|
||||
static pthread_key_t thread_key;
|
||||
@ -1147,11 +1149,13 @@ static enum frontend_powerstate frontend_unix_get_powerstate(
|
||||
if (!env || !g_android)
|
||||
return ret;
|
||||
|
||||
CALL_INT_METHOD(env, powerstate,
|
||||
g_android->activity->clazz, g_android->getPowerstate);
|
||||
if (g_android->getPowerstate)
|
||||
CALL_INT_METHOD(env, powerstate,
|
||||
g_android->activity->clazz, g_android->getPowerstate);
|
||||
|
||||
CALL_INT_METHOD(env, battery_level,
|
||||
g_android->activity->clazz, g_android->getBatteryLevel);
|
||||
if (g_android->getBatteryLevel)
|
||||
CALL_INT_METHOD(env, battery_level,
|
||||
g_android->activity->clazz, g_android->getBatteryLevel);
|
||||
|
||||
*percent = battery_level;
|
||||
|
||||
@ -1283,6 +1287,7 @@ static void frontend_unix_get_env(int *argc,
|
||||
return;
|
||||
|
||||
env = jni_thread_getenv();
|
||||
|
||||
if (!env)
|
||||
return;
|
||||
|
||||
@ -2013,6 +2018,8 @@ static void frontend_unix_init(void *data)
|
||||
"getPowerstate", "()I");
|
||||
GET_METHOD_ID(env, android_app->getBatteryLevel, class,
|
||||
"getBatteryLevel", "()I");
|
||||
GET_METHOD_ID(env, android_app->setSustainedPerformanceMode, class,
|
||||
"setSustainedPerformanceMode", "(Z)V");
|
||||
CALL_OBJ_METHOD(env, obj, android_app->activity->clazz,
|
||||
android_app->getIntent);
|
||||
|
||||
@ -2431,6 +2438,20 @@ static bool frontend_unix_check_for_path_changes(path_change_data_t *change_data
|
||||
#endif
|
||||
}
|
||||
|
||||
static void frontend_unix_set_sustained_performance_mode(bool on)
|
||||
{
|
||||
#ifdef ANDROID
|
||||
JNIEnv *env = jni_thread_getenv();
|
||||
|
||||
if (!env || !g_android)
|
||||
return;
|
||||
|
||||
if (g_android->setSustainedPerformanceMode)
|
||||
CALL_VOID_METHOD_PARAM(env, g_android->activity->clazz,
|
||||
g_android->setSustainedPerformanceMode, on);
|
||||
#endif
|
||||
}
|
||||
|
||||
frontend_ctx_driver_t frontend_ctx_unix = {
|
||||
frontend_unix_get_env, /* environment_get */
|
||||
frontend_unix_init, /* init */
|
||||
@ -2474,6 +2495,7 @@ frontend_ctx_driver_t frontend_ctx_unix = {
|
||||
#endif
|
||||
frontend_unix_watch_path_for_changes,
|
||||
frontend_unix_check_for_path_changes,
|
||||
frontend_unix_set_sustained_performance_mode,
|
||||
#ifdef ANDROID
|
||||
"android"
|
||||
#else
|
||||
|
@ -162,6 +162,7 @@ struct android_app
|
||||
jmethodID isAndroidTV;
|
||||
jmethodID getPowerstate;
|
||||
jmethodID getBatteryLevel;
|
||||
jmethodID setSustainedPerformanceMode;
|
||||
};
|
||||
|
||||
|
||||
|
@ -302,6 +302,7 @@ frontend_ctx_driver_t frontend_ctx_wiiu =
|
||||
NULL, /* detach_console */
|
||||
NULL, /* watch_path_for_changes */
|
||||
NULL, /* check_for_path_changes */
|
||||
NULL, /* set_sustained_performance_mode */
|
||||
"wiiu",
|
||||
NULL, /* get_video_driver */
|
||||
};
|
||||
|
@ -587,5 +587,6 @@ frontend_ctx_driver_t frontend_ctx_win32 = {
|
||||
frontend_win32_detach_console, /* detach_console */
|
||||
NULL, /* watch_path_for_changes */
|
||||
NULL, /* check_for_path_changes */
|
||||
NULL, /* set_sustained_performance_mode */
|
||||
"win32"
|
||||
};
|
||||
|
@ -426,5 +426,6 @@ frontend_ctx_driver_t frontend_ctx_xdk = {
|
||||
NULL, /* detach_console */
|
||||
NULL, /* watch_path_for_changes */
|
||||
NULL, /* check_for_path_changes */
|
||||
NULL, /* set_sustained_performance_mode */
|
||||
"xdk",
|
||||
};
|
||||
|
@ -93,5 +93,6 @@ frontend_ctx_driver_t frontend_ctx_qnx = {
|
||||
NULL, /* detach_console */
|
||||
NULL, /* watch_path_for_changes */
|
||||
NULL, /* check_for_path_changes */
|
||||
NULL, /* set_sustained_performance_mode */
|
||||
"xenon",
|
||||
};
|
||||
|
@ -416,4 +416,12 @@ bool frontend_driver_check_for_path_changes(path_change_data_t *change_data)
|
||||
return frontend->check_for_path_changes(change_data);
|
||||
}
|
||||
|
||||
void frontend_driver_set_sustained_performance_mode(bool on)
|
||||
{
|
||||
frontend_ctx_driver_t *frontend = frontend_get_ptr();
|
||||
if (!frontend || !frontend->set_sustained_performance_mode)
|
||||
return;
|
||||
frontend->set_sustained_performance_mode(on);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@ -105,6 +105,7 @@ typedef struct frontend_ctx_driver
|
||||
#endif
|
||||
void (*watch_path_for_changes)(struct string_list *list, int flags, path_change_data_t **change_data);
|
||||
bool (*check_for_path_changes)(path_change_data_t *change_data);
|
||||
void (*set_sustained_performance_mode)(bool on);
|
||||
|
||||
const char *ident;
|
||||
|
||||
@ -203,6 +204,8 @@ void frontend_driver_watch_path_for_changes(struct string_list *list, int flags,
|
||||
|
||||
bool frontend_driver_check_for_path_changes(path_change_data_t *change_data);
|
||||
|
||||
void frontend_driver_set_sustained_performance_mode(bool on);
|
||||
|
||||
RETRO_END_DECLS
|
||||
|
||||
#endif
|
||||
|
@ -1529,3 +1529,5 @@ MSG_HASH(MENU_ENUM_LABEL_MIDI_OUTPUT,
|
||||
"midi_output")
|
||||
MSG_HASH(MENU_ENUM_LABEL_MIDI_VOLUME,
|
||||
"midi_volume")
|
||||
MSG_HASH(MENU_ENUM_LABEL_SUSTAINED_PERFORMANCE_MODE,
|
||||
"sustained_performance_mode")
|
||||
|
@ -3752,3 +3752,5 @@ MSG_HASH(MENU_ENUM_LABEL_VALUE_POWER_MANAGEMENT_SETTINGS,
|
||||
"Power Management")
|
||||
MSG_HASH(MENU_ENUM_SUBLABEL_POWER_MANAGEMENT_SETTINGS,
|
||||
"Change power management settings.")
|
||||
MSG_HASH(MENU_ENUM_LABEL_VALUE_SUSTAINED_PERFORMANCE_MODE,
|
||||
"Sustained Performance Mode")
|
||||
|
@ -5502,7 +5502,12 @@ bool menu_displaylist_ctl(enum menu_displaylist_ctl_state type, void *data)
|
||||
case DISPLAYLIST_POWER_MANAGEMENT_SETTINGS_LIST:
|
||||
menu_entries_ctl(MENU_ENTRIES_CTL_CLEAR, info->list);
|
||||
|
||||
/* Fill in entry here */
|
||||
#ifdef ANDROID
|
||||
if (menu_displaylist_parse_settings_enum(menu, info,
|
||||
MENU_ENUM_LABEL_SUSTAINED_PERFORMANCE_MODE,
|
||||
PARSE_ONLY_BOOL, false) == 0)
|
||||
count++;
|
||||
#endif
|
||||
|
||||
if (count == 0)
|
||||
menu_entries_append_enum(info->list,
|
||||
|
@ -1633,6 +1633,9 @@ void general_write_handler(void *data)
|
||||
case MENU_ENUM_LABEL_MIDI_VOLUME:
|
||||
midi_driver_set_volume(settings->uints.midi_volume);
|
||||
break;
|
||||
case MENU_ENUM_LABEL_SUSTAINED_PERFORMANCE_MODE:
|
||||
frontend_unix_set_sustained_performance_mode(settings->bools.sustained_performance_mode);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@ -6378,6 +6381,21 @@ static bool setting_append_list(
|
||||
|
||||
START_SUB_GROUP(list, list_info, "State", &group_info, &subgroup_info, parent_group);
|
||||
|
||||
CONFIG_BOOL(
|
||||
list, list_info,
|
||||
&settings->bools.sustained_performance_mode,
|
||||
MENU_ENUM_LABEL_SUSTAINED_PERFORMANCE_MODE,
|
||||
MENU_ENUM_LABEL_VALUE_SUSTAINED_PERFORMANCE_MODE,
|
||||
sustained_performance_mode,
|
||||
MENU_ENUM_LABEL_VALUE_OFF,
|
||||
MENU_ENUM_LABEL_VALUE_ON,
|
||||
&group_info,
|
||||
&subgroup_info,
|
||||
parent_group,
|
||||
general_write_handler,
|
||||
general_read_handler,
|
||||
SD_FLAG_CMD_APPLY_AUTO);
|
||||
|
||||
END_SUB_GROUP(list, list_info, parent_group);
|
||||
END_GROUP(list, list_info, parent_group);
|
||||
break;
|
||||
|
@ -1870,6 +1870,8 @@ enum msg_hash_enums
|
||||
MENU_LABEL(MIDI_OUTPUT),
|
||||
MENU_LABEL(MIDI_VOLUME),
|
||||
|
||||
MENU_LABEL(SUSTAINED_PERFORMANCE_MODE),
|
||||
|
||||
MSG_LAST
|
||||
};
|
||||
|
||||
|
@ -12,6 +12,8 @@ import android.os.Build;
|
||||
import android.os.PowerManager;
|
||||
import android.util.Log;
|
||||
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
|
||||
/**
|
||||
* Class which provides common methods for RetroActivity related classes.
|
||||
*/
|
||||
@ -22,6 +24,7 @@ public class RetroActivityCommon extends RetroActivityLocation
|
||||
public static int FRONTEND_POWERSTATE_CHARGING = 2;
|
||||
public static int FRONTEND_POWERSTATE_CHARGED = 3;
|
||||
public static int FRONTEND_POWERSTATE_ON_POWER_SOURCE = 4;
|
||||
public boolean sustainedPerformanceMode = true;
|
||||
|
||||
// Exiting cleanly from NDK seems to be nearly impossible.
|
||||
// Have to use exit(0) to avoid weird things happening, even with runOnUiThread() approaches.
|
||||
@ -34,10 +37,33 @@ public class RetroActivityCommon extends RetroActivityLocation
|
||||
@TargetApi(24)
|
||||
public void setSustainedPerformanceMode(boolean on)
|
||||
{
|
||||
Log.i("RetroActivity", "setting sustained performance mode to " + on);
|
||||
getWindow().setSustainedPerformanceMode(on);
|
||||
sustainedPerformanceMode = on;
|
||||
|
||||
if (Build.VERSION.SDK_INT >= 24) {
|
||||
if (isSustainedPerformanceModeSupported()) {
|
||||
final CountDownLatch latch = new CountDownLatch(1);
|
||||
|
||||
runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
Log.i("RetroActivity", "setting sustained performance mode to " + sustainedPerformanceMode);
|
||||
|
||||
getWindow().setSustainedPerformanceMode(sustainedPerformanceMode);
|
||||
|
||||
latch.countDown();
|
||||
}
|
||||
});
|
||||
|
||||
try {
|
||||
latch.await();
|
||||
}catch(InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@TargetApi(24)
|
||||
public boolean isSustainedPerformanceModeSupported()
|
||||
{
|
||||
boolean supported = false;
|
||||
|
@ -18,10 +18,7 @@ public final class RetroActivityFuture extends RetroActivityCamera {
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
|
||||
if (Build.VERSION.SDK_INT >= 24) {
|
||||
if (isSustainedPerformanceModeSupported())
|
||||
setSustainedPerformanceMode(true);
|
||||
}
|
||||
setSustainedPerformanceMode(sustainedPerformanceMode);
|
||||
|
||||
if (Build.VERSION.SDK_INT >= 19) {
|
||||
// Immersive mode
|
||||
|
@ -878,3 +878,6 @@
|
||||
# network_cmd_enable = false
|
||||
# network_cmd_port = 55355
|
||||
# stdin_cmd_enable = false
|
||||
|
||||
# Enable Sustained Performance Mode in Android 7.0+
|
||||
# sustained_performance_mode = true
|
||||
|
Loading…
x
Reference in New Issue
Block a user