mirror of
https://github.com/libretro/RetroArch.git
synced 2024-11-23 07:59:42 +00:00
Add Linux GameMode support (#13339)
This can fix a lot of performance issues, like audio crackling and frame time spikes. This requires the GameMode package to be installed. See: https://github.com/FeralInteractive/gamemode This commit adds a "Game Mode" bool option to the "Power Management" and "Latency" settings sections, and it can be toggled on/off without restarting RA. The actual toggling of game mode happens in a new frontend platform interface function. Perhaps this will become useful for other platforms that provide some equivalent of Linux GameMode. Since the GameMode ABI is fixed, and the API comes as a single, header-only file with no actual deps, we simply bundle the header (deps/feralgamemode/gamemode_client.h.) That way, all Linux builds will have support for GameMode regardless of whether the GameMode development package is installed or not.
This commit is contained in:
parent
fd8aa7a9cc
commit
430baf7c21
@ -1,4 +1,5 @@
|
||||
# Future
|
||||
- LINUX: Added support for Linux GameMode (https://github.com/FeralInteractive/gamemode), which can be toggled on/off in the Power Management or Latency settings menus.
|
||||
|
||||
# 1.9.14
|
||||
- ANDROID/PLAYSTORE: Implement MANAGE_EXTERNAL_STORAGE permission
|
||||
|
@ -173,6 +173,8 @@
|
||||
|
||||
#define DEFAULT_USER_LANGUAGE 0
|
||||
|
||||
#define DEFAULT_GAMEMODE_ENABLE true
|
||||
|
||||
#if (defined(_WIN32) && !defined(_XBOX)) || (defined(__linux) && !defined(ANDROID) && !defined(HAVE_LAKKA)) || (defined(__MACH__) && !defined(IOS)) || defined(EMSCRIPTEN)
|
||||
#define DEFAULT_MOUSE_ENABLE true
|
||||
#else
|
||||
|
@ -1993,6 +1993,7 @@ static struct config_bool_setting *populate_settings_bool(
|
||||
SETTING_BOOL("ai_service_enable", &settings->bools.ai_service_enable, true, DEFAULT_AI_SERVICE_ENABLE, false);
|
||||
SETTING_BOOL("ai_service_pause", &settings->bools.ai_service_pause, true, DEFAULT_AI_SERVICE_PAUSE, false);
|
||||
SETTING_BOOL("wifi_enabled", &settings->bools.wifi_enabled, true, DEFAULT_WIFI_ENABLE, false);
|
||||
SETTING_BOOL("gamemode_enable", &settings->bools.gamemode_enable, true, DEFAULT_GAMEMODE_ENABLE, false);
|
||||
|
||||
*size = count;
|
||||
|
||||
@ -3725,6 +3726,8 @@ static bool config_load_file(global_t *global,
|
||||
if (!config_entry_exists(conf, "user_language"))
|
||||
msg_hash_set_uint(MSG_HASH_USER_LANGUAGE, frontend_driver_get_user_language());
|
||||
|
||||
frontend_driver_set_gamemode(settings->bools.gamemode_enable);
|
||||
|
||||
/* If this is the first run of an existing installation
|
||||
* after the independent favourites playlist size limit was
|
||||
* added, set the favourites limit according to the current
|
||||
|
@ -905,6 +905,8 @@ typedef struct settings
|
||||
|
||||
bool ai_service_enable;
|
||||
bool ai_service_pause;
|
||||
|
||||
bool gamemode_enable;
|
||||
} bools;
|
||||
|
||||
} settings_t;
|
||||
|
365
deps/feralgamemode/gamemode_client.h
vendored
Normal file
365
deps/feralgamemode/gamemode_client.h
vendored
Normal file
@ -0,0 +1,365 @@
|
||||
/*
|
||||
|
||||
Copyright (c) 2017-2019, Feral Interactive
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright notice,
|
||||
this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in the
|
||||
documentation and/or other materials provided with the distribution.
|
||||
* Neither the name of Feral Interactive nor the names of its contributors
|
||||
may be used to endorse or promote products derived from this software
|
||||
without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
||||
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
*/
|
||||
#ifndef CLIENT_GAMEMODE_H
|
||||
#define CLIENT_GAMEMODE_H
|
||||
/*
|
||||
* GameMode supports the following client functions
|
||||
* Requests are refcounted in the daemon
|
||||
*
|
||||
* int gamemode_request_start() - Request gamemode starts
|
||||
* 0 if the request was sent successfully
|
||||
* -1 if the request failed
|
||||
*
|
||||
* int gamemode_request_end() - Request gamemode ends
|
||||
* 0 if the request was sent successfully
|
||||
* -1 if the request failed
|
||||
*
|
||||
* GAMEMODE_AUTO can be defined to make the above two functions apply during static init and
|
||||
* destruction, as appropriate. In this configuration, errors will be printed to stderr
|
||||
*
|
||||
* int gamemode_query_status() - Query the current status of gamemode
|
||||
* 0 if gamemode is inactive
|
||||
* 1 if gamemode is active
|
||||
* 2 if gamemode is active and this client is registered
|
||||
* -1 if the query failed
|
||||
*
|
||||
* int gamemode_request_start_for(pid_t pid) - Request gamemode starts for another process
|
||||
* 0 if the request was sent successfully
|
||||
* -1 if the request failed
|
||||
* -2 if the request was rejected
|
||||
*
|
||||
* int gamemode_request_end_for(pid_t pid) - Request gamemode ends for another process
|
||||
* 0 if the request was sent successfully
|
||||
* -1 if the request failed
|
||||
* -2 if the request was rejected
|
||||
*
|
||||
* int gamemode_query_status_for(pid_t pid) - Query status of gamemode for another process
|
||||
* 0 if gamemode is inactive
|
||||
* 1 if gamemode is active
|
||||
* 2 if gamemode is active and this client is registered
|
||||
* -1 if the query failed
|
||||
*
|
||||
* const char* gamemode_error_string() - Get an error string
|
||||
* returns a string describing any of the above errors
|
||||
*
|
||||
* Note: All the above requests can be blocking - dbus requests can and will block while the daemon
|
||||
* handles the request. It is not recommended to make these calls in performance critical code
|
||||
*/
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include <dlfcn.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
static char internal_gamemode_client_error_string[512] = { 0 };
|
||||
|
||||
/**
|
||||
* Load libgamemode dynamically to dislodge us from most dependencies.
|
||||
* This allows clients to link and/or use this regardless of runtime.
|
||||
* See SDL2 for an example of the reasoning behind this in terms of
|
||||
* dynamic versioning as well.
|
||||
*/
|
||||
static volatile int internal_libgamemode_loaded = 1;
|
||||
|
||||
/* Typedefs for the functions to load */
|
||||
typedef int (*api_call_return_int)(void);
|
||||
typedef const char *(*api_call_return_cstring)(void);
|
||||
typedef int (*api_call_pid_return_int)(pid_t);
|
||||
|
||||
/* Storage for functors */
|
||||
static api_call_return_int REAL_internal_gamemode_request_start = NULL;
|
||||
static api_call_return_int REAL_internal_gamemode_request_end = NULL;
|
||||
static api_call_return_int REAL_internal_gamemode_query_status = NULL;
|
||||
static api_call_return_cstring REAL_internal_gamemode_error_string = NULL;
|
||||
static api_call_pid_return_int REAL_internal_gamemode_request_start_for = NULL;
|
||||
static api_call_pid_return_int REAL_internal_gamemode_request_end_for = NULL;
|
||||
static api_call_pid_return_int REAL_internal_gamemode_query_status_for = NULL;
|
||||
|
||||
/**
|
||||
* Internal helper to perform the symbol binding safely.
|
||||
*
|
||||
* Returns 0 on success and -1 on failure
|
||||
*/
|
||||
__attribute__((always_inline)) static inline int internal_bind_libgamemode_symbol(
|
||||
void *handle, const char *name, void **out_func, size_t func_size, bool required)
|
||||
{
|
||||
void *symbol_lookup = NULL;
|
||||
char *dl_error = NULL;
|
||||
|
||||
/* Safely look up the symbol */
|
||||
symbol_lookup = dlsym(handle, name);
|
||||
dl_error = dlerror();
|
||||
if (required && (dl_error || !symbol_lookup)) {
|
||||
snprintf(internal_gamemode_client_error_string,
|
||||
sizeof(internal_gamemode_client_error_string),
|
||||
"dlsym failed - %s",
|
||||
dl_error);
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Have the symbol correctly, copy it to make it usable */
|
||||
memcpy(out_func, &symbol_lookup, func_size);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads libgamemode and needed functions
|
||||
*
|
||||
* Returns 0 on success and -1 on failure
|
||||
*/
|
||||
__attribute__((always_inline)) static inline int internal_load_libgamemode(void)
|
||||
{
|
||||
/* We start at 1, 0 is a success and -1 is a fail */
|
||||
if (internal_libgamemode_loaded != 1) {
|
||||
return internal_libgamemode_loaded;
|
||||
}
|
||||
|
||||
/* Anonymous struct type to define our bindings */
|
||||
struct binding {
|
||||
const char *name;
|
||||
void **functor;
|
||||
size_t func_size;
|
||||
bool required;
|
||||
} bindings[] = {
|
||||
{ "real_gamemode_request_start",
|
||||
(void **)&REAL_internal_gamemode_request_start,
|
||||
sizeof(REAL_internal_gamemode_request_start),
|
||||
true },
|
||||
{ "real_gamemode_request_end",
|
||||
(void **)&REAL_internal_gamemode_request_end,
|
||||
sizeof(REAL_internal_gamemode_request_end),
|
||||
true },
|
||||
{ "real_gamemode_query_status",
|
||||
(void **)&REAL_internal_gamemode_query_status,
|
||||
sizeof(REAL_internal_gamemode_query_status),
|
||||
false },
|
||||
{ "real_gamemode_error_string",
|
||||
(void **)&REAL_internal_gamemode_error_string,
|
||||
sizeof(REAL_internal_gamemode_error_string),
|
||||
true },
|
||||
{ "real_gamemode_request_start_for",
|
||||
(void **)&REAL_internal_gamemode_request_start_for,
|
||||
sizeof(REAL_internal_gamemode_request_start_for),
|
||||
false },
|
||||
{ "real_gamemode_request_end_for",
|
||||
(void **)&REAL_internal_gamemode_request_end_for,
|
||||
sizeof(REAL_internal_gamemode_request_end_for),
|
||||
false },
|
||||
{ "real_gamemode_query_status_for",
|
||||
(void **)&REAL_internal_gamemode_query_status_for,
|
||||
sizeof(REAL_internal_gamemode_query_status_for),
|
||||
false },
|
||||
};
|
||||
|
||||
void *libgamemode = NULL;
|
||||
|
||||
/* Try and load libgamemode */
|
||||
libgamemode = dlopen("libgamemode.so.0", RTLD_NOW);
|
||||
if (!libgamemode) {
|
||||
/* Attempt to load unversioned library for compatibility with older
|
||||
* versions (as of writing, there are no ABI changes between the two -
|
||||
* this may need to change if ever ABI-breaking changes are made) */
|
||||
libgamemode = dlopen("libgamemode.so", RTLD_NOW);
|
||||
if (!libgamemode) {
|
||||
snprintf(internal_gamemode_client_error_string,
|
||||
sizeof(internal_gamemode_client_error_string),
|
||||
"dlopen failed - %s",
|
||||
dlerror());
|
||||
internal_libgamemode_loaded = -1;
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
/* Attempt to bind all symbols */
|
||||
for (size_t i = 0; i < sizeof(bindings) / sizeof(bindings[0]); i++) {
|
||||
struct binding *binder = &bindings[i];
|
||||
|
||||
if (internal_bind_libgamemode_symbol(libgamemode,
|
||||
binder->name,
|
||||
binder->functor,
|
||||
binder->func_size,
|
||||
binder->required)) {
|
||||
internal_libgamemode_loaded = -1;
|
||||
return -1;
|
||||
};
|
||||
}
|
||||
|
||||
/* Success */
|
||||
internal_libgamemode_loaded = 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Redirect to the real libgamemode
|
||||
*/
|
||||
__attribute__((always_inline)) static inline const char *gamemode_error_string(void)
|
||||
{
|
||||
/* If we fail to load the system gamemode, or we have an error string already, return our error
|
||||
* string instead of diverting to the system version */
|
||||
if (internal_load_libgamemode() < 0 || internal_gamemode_client_error_string[0] != '\0') {
|
||||
return internal_gamemode_client_error_string;
|
||||
}
|
||||
|
||||
return REAL_internal_gamemode_error_string();
|
||||
}
|
||||
|
||||
/**
|
||||
* Redirect to the real libgamemode
|
||||
* Allow automatically requesting game mode
|
||||
* Also prints errors as they happen.
|
||||
*/
|
||||
#ifdef GAMEMODE_AUTO
|
||||
__attribute__((constructor))
|
||||
#else
|
||||
__attribute__((always_inline)) static inline
|
||||
#endif
|
||||
int gamemode_request_start(void)
|
||||
{
|
||||
/* Need to load gamemode */
|
||||
if (internal_load_libgamemode() < 0) {
|
||||
#ifdef GAMEMODE_AUTO
|
||||
fprintf(stderr, "gamemodeauto: %s\n", gamemode_error_string());
|
||||
#endif
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (REAL_internal_gamemode_request_start() < 0) {
|
||||
#ifdef GAMEMODE_AUTO
|
||||
fprintf(stderr, "gamemodeauto: %s\n", gamemode_error_string());
|
||||
#endif
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Redirect to the real libgamemode */
|
||||
#ifdef GAMEMODE_AUTO
|
||||
__attribute__((destructor))
|
||||
#else
|
||||
__attribute__((always_inline)) static inline
|
||||
#endif
|
||||
int gamemode_request_end(void)
|
||||
{
|
||||
/* Need to load gamemode */
|
||||
if (internal_load_libgamemode() < 0) {
|
||||
#ifdef GAMEMODE_AUTO
|
||||
fprintf(stderr, "gamemodeauto: %s\n", gamemode_error_string());
|
||||
#endif
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (REAL_internal_gamemode_request_end() < 0) {
|
||||
#ifdef GAMEMODE_AUTO
|
||||
fprintf(stderr, "gamemodeauto: %s\n", gamemode_error_string());
|
||||
#endif
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Redirect to the real libgamemode */
|
||||
__attribute__((always_inline)) static inline int gamemode_query_status(void)
|
||||
{
|
||||
/* Need to load gamemode */
|
||||
if (internal_load_libgamemode() < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (REAL_internal_gamemode_query_status == NULL) {
|
||||
snprintf(internal_gamemode_client_error_string,
|
||||
sizeof(internal_gamemode_client_error_string),
|
||||
"gamemode_query_status missing (older host?)");
|
||||
return -1;
|
||||
}
|
||||
|
||||
return REAL_internal_gamemode_query_status();
|
||||
}
|
||||
|
||||
/* Redirect to the real libgamemode */
|
||||
__attribute__((always_inline)) static inline int gamemode_request_start_for(pid_t pid)
|
||||
{
|
||||
/* Need to load gamemode */
|
||||
if (internal_load_libgamemode() < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (REAL_internal_gamemode_request_start_for == NULL) {
|
||||
snprintf(internal_gamemode_client_error_string,
|
||||
sizeof(internal_gamemode_client_error_string),
|
||||
"gamemode_request_start_for missing (older host?)");
|
||||
return -1;
|
||||
}
|
||||
|
||||
return REAL_internal_gamemode_request_start_for(pid);
|
||||
}
|
||||
|
||||
/* Redirect to the real libgamemode */
|
||||
__attribute__((always_inline)) static inline int gamemode_request_end_for(pid_t pid)
|
||||
{
|
||||
/* Need to load gamemode */
|
||||
if (internal_load_libgamemode() < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (REAL_internal_gamemode_request_end_for == NULL) {
|
||||
snprintf(internal_gamemode_client_error_string,
|
||||
sizeof(internal_gamemode_client_error_string),
|
||||
"gamemode_request_end_for missing (older host?)");
|
||||
return -1;
|
||||
}
|
||||
|
||||
return REAL_internal_gamemode_request_end_for(pid);
|
||||
}
|
||||
|
||||
/* Redirect to the real libgamemode */
|
||||
__attribute__((always_inline)) static inline int gamemode_query_status_for(pid_t pid)
|
||||
{
|
||||
/* Need to load gamemode */
|
||||
if (internal_load_libgamemode() < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (REAL_internal_gamemode_query_status_for == NULL) {
|
||||
snprintf(internal_gamemode_client_error_string,
|
||||
sizeof(internal_gamemode_client_error_string),
|
||||
"gamemode_query_status_for missing (older host?)");
|
||||
return -1;
|
||||
}
|
||||
|
||||
return REAL_internal_gamemode_query_status_for(pid);
|
||||
}
|
||||
|
||||
#endif // CLIENT_GAMEMODE_H
|
@ -688,6 +688,7 @@ frontend_ctx_driver_t frontend_ctx_ctr =
|
||||
NULL, /* get_user_language */
|
||||
NULL, /* is_narrator_running */
|
||||
NULL, /* accessibility_speak */
|
||||
NULL, /* set_gamemode */
|
||||
"ctr", /* ident */
|
||||
NULL /* get_video_driver */
|
||||
};
|
||||
|
@ -1008,6 +1008,7 @@ frontend_ctx_driver_t frontend_ctx_darwin = {
|
||||
NULL, /* is_narrator_running */
|
||||
NULL, /* accessibility_speak */
|
||||
#endif
|
||||
NULL, /* set_gamemode */
|
||||
"darwin", /* ident */
|
||||
NULL /* get_video_driver */
|
||||
};
|
||||
|
@ -210,6 +210,7 @@ frontend_ctx_driver_t frontend_ctx_dos = {
|
||||
NULL, /* get_user_language */
|
||||
NULL, /* is_narrator_running */
|
||||
NULL, /* accessibility_speak */
|
||||
NULL, /* set_gamemode */
|
||||
"dos", /* ident */
|
||||
NULL /* get_video_driver */
|
||||
};
|
||||
|
@ -203,6 +203,7 @@ frontend_ctx_driver_t frontend_ctx_emscripten = {
|
||||
NULL, /* get_user_language */
|
||||
NULL, /* is_narrator_running */
|
||||
NULL, /* accessibility_speak */
|
||||
NULL, /* set_gamemode */
|
||||
"emscripten", /* ident */
|
||||
NULL /* get_video_driver */
|
||||
};
|
||||
|
@ -578,6 +578,7 @@ frontend_ctx_driver_t frontend_ctx_gx = {
|
||||
NULL, /* get_user_language */
|
||||
NULL, /* is_narrator_running */
|
||||
NULL, /* accessibility_speak */
|
||||
NULL, /* set_gamemode */
|
||||
"gx", /* ident */
|
||||
NULL /* get_video_driver */
|
||||
};
|
||||
|
@ -372,6 +372,7 @@ frontend_ctx_driver_t frontend_ctx_orbis = {
|
||||
NULL, /* get_user_language */
|
||||
NULL, /* is_narrator_running */
|
||||
NULL, /* accessibility_speak */
|
||||
NULL, /* set_gamemode */
|
||||
"orbis", /* ident */
|
||||
NULL /* get_video_driver */
|
||||
};
|
||||
|
@ -552,6 +552,7 @@ frontend_ctx_driver_t frontend_ctx_ps2 = {
|
||||
NULL, /* get_user_language */
|
||||
NULL, /* is_narrator_running */
|
||||
NULL, /* accessibility_speak */
|
||||
NULL, /* set_gamemode */
|
||||
"ps2", /* ident */
|
||||
NULL /* get_video_driver */
|
||||
};
|
||||
|
@ -711,6 +711,7 @@ frontend_ctx_driver_t frontend_ctx_ps3 = {
|
||||
NULL, /* get_user_language */
|
||||
NULL, /* is_narrator_running */
|
||||
NULL, /* accessibility_speak */
|
||||
NULL, /* set_gamemode */
|
||||
"ps3", /* ident */
|
||||
NULL /* get_video_driver */
|
||||
};
|
||||
|
@ -662,6 +662,7 @@ frontend_ctx_driver_t frontend_ctx_psp = {
|
||||
NULL, /* get_user_language */
|
||||
NULL, /* is_narrator_running */
|
||||
NULL, /* accessibility_speak */
|
||||
NULL, /* set_gamemode */
|
||||
"psp", /* ident */
|
||||
#endif
|
||||
NULL /* get_video_driver */
|
||||
|
@ -209,6 +209,7 @@ frontend_ctx_driver_t frontend_ctx_qnx = {
|
||||
NULL, /* get_user_language */
|
||||
NULL, /* is_narrator_running */
|
||||
NULL, /* accessibility_speak */
|
||||
NULL, /* set_gamemode */
|
||||
"qnx", /* ident */
|
||||
NULL /* get_video_driver */
|
||||
};
|
||||
|
@ -768,6 +768,7 @@ frontend_ctx_driver_t frontend_ctx_switch =
|
||||
NULL, /* get_user_language */
|
||||
NULL, /* is_narrator_running */
|
||||
NULL, /* accessibility_speak */
|
||||
NULL, /* set_gamemode */
|
||||
"switch", /* ident */
|
||||
NULL /* get_video_driver */
|
||||
};
|
||||
|
@ -30,6 +30,10 @@
|
||||
|
||||
#ifdef __linux__
|
||||
#include <linux/version.h>
|
||||
#if __STDC_VERSION__ >= 199901L
|
||||
#include "feralgamemode/gamemode_client.h"
|
||||
#define FERAL_GAMEMODE
|
||||
#endif
|
||||
/* inotify API was added in 2.6.13 */
|
||||
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,13)
|
||||
#define HAS_INOTIFY
|
||||
@ -1989,6 +1993,44 @@ static void android_app_destroy(struct android_app *android_app)
|
||||
}
|
||||
#endif
|
||||
|
||||
static bool frontend_unix_set_gamemode(bool on)
|
||||
{
|
||||
#ifdef FERAL_GAMEMODE
|
||||
const int gamemode_status = gamemode_query_status();
|
||||
|
||||
if (gamemode_status < 0)
|
||||
{
|
||||
if (on)
|
||||
{
|
||||
RARCH_WARN("[GameMode]: GameMode cannot be enabled on this system (\"%s.\") "
|
||||
"https://github.com/FeralInteractive/gamemode needs to be installed.\n",
|
||||
gamemode_error_string());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
if (on)
|
||||
{
|
||||
if (gamemode_status != 2 && gamemode_request_start() != 0)
|
||||
{
|
||||
RARCH_WARN("[GameMode]: Failed to enter GameMode: %s.\n", gamemode_error_string());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (gamemode_status == 2 && gamemode_request_end() != 0)
|
||||
{
|
||||
RARCH_WARN("[GameMode]: Failed to exit GameMode: %s.\n", gamemode_error_string());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
#else
|
||||
(void)on;
|
||||
#endif
|
||||
}
|
||||
|
||||
static void frontend_unix_deinit(void *data)
|
||||
{
|
||||
settings_t *settings = config_get_ptr();
|
||||
@ -2006,6 +2048,8 @@ static void frontend_unix_deinit(void *data)
|
||||
if (settings->uints.screen_brightness != DEFAULT_SCREEN_BRIGHTNESS)
|
||||
frontend_unix_set_screen_brightness(DEFAULT_SCREEN_BRIGHTNESS);
|
||||
#endif
|
||||
|
||||
frontend_unix_set_gamemode(false);
|
||||
}
|
||||
|
||||
static void frontend_unix_init(void *data)
|
||||
@ -2853,6 +2897,11 @@ frontend_ctx_driver_t frontend_ctx_unix = {
|
||||
NULL, /* is_narrator_running */
|
||||
NULL, /* accessibility_speak */
|
||||
#endif
|
||||
#ifdef FERAL_GAMEMODE
|
||||
frontend_unix_set_gamemode,
|
||||
#else
|
||||
NULL,
|
||||
#endif
|
||||
#ifdef ANDROID
|
||||
"android", /* ident */
|
||||
#else
|
||||
|
@ -479,6 +479,7 @@ frontend_ctx_driver_t frontend_ctx_uwp = {
|
||||
frontend_uwp_get_user_language, /* get_user_language */
|
||||
NULL, /* is_narrator_running */
|
||||
NULL, /* accessibility_speak */
|
||||
NULL, /* set_gamemode */
|
||||
"uwp", /* ident */
|
||||
NULL /* get_video_driver */
|
||||
};
|
||||
|
@ -328,6 +328,7 @@ frontend_ctx_driver_t frontend_ctx_wiiu =
|
||||
NULL, /* get_user_language */
|
||||
NULL, /* is_narrator_running */
|
||||
NULL, /* accessibility_speak */
|
||||
NULL, /* set_gamemode */
|
||||
"wiiu", /* ident */
|
||||
NULL /* get_video_driver */
|
||||
};
|
||||
|
@ -1170,6 +1170,7 @@ frontend_ctx_driver_t frontend_ctx_win32 = {
|
||||
NULL, /* is_narrator_running */
|
||||
NULL, /* accessibility_speak */
|
||||
#endif
|
||||
NULL, /* set_gamemode */
|
||||
"win32", /* ident */
|
||||
NULL /* get_video_driver */
|
||||
};
|
||||
|
@ -445,6 +445,7 @@ frontend_ctx_driver_t frontend_ctx_xdk = {
|
||||
NULL, /* get_user_language */
|
||||
NULL, /* is_narrator_running */
|
||||
NULL, /* accessibility_speak */
|
||||
NULL, /* set_gamemode */
|
||||
"xdk", /* ident */
|
||||
NULL /* get_video_driver */
|
||||
};
|
||||
|
@ -100,6 +100,7 @@ frontend_ctx_driver_t frontend_ctx_qnx = {
|
||||
NULL, /* get_user_language */
|
||||
NULL, /* is_narrator_running */
|
||||
NULL, /* accessibility_speak */
|
||||
NULL, /* set_gamemode */
|
||||
"xenon", /* ident */
|
||||
NULL /* get_video_driver */
|
||||
};
|
||||
|
@ -71,6 +71,7 @@ static frontend_ctx_driver_t frontend_ctx_null = {
|
||||
NULL, /* get_user_language */
|
||||
NULL, /* is_narrator_running */
|
||||
NULL, /* accessibility_speak */
|
||||
NULL, /* set_gamemode */
|
||||
"null",
|
||||
NULL, /* get_video_driver */
|
||||
};
|
||||
@ -588,3 +589,12 @@ enum retro_language frontend_driver_get_user_language(void)
|
||||
return frontend->get_user_language();
|
||||
return RETRO_LANGUAGE_ENGLISH;
|
||||
}
|
||||
|
||||
bool frontend_driver_set_gamemode(bool on)
|
||||
{
|
||||
frontend_state_t *frontend_st = &frontend_driver_st;
|
||||
frontend_ctx_driver_t *frontend = frontend_st->current_frontend_ctx;
|
||||
if (frontend && frontend->set_gamemode)
|
||||
return frontend->set_gamemode(on);
|
||||
return false;
|
||||
}
|
||||
|
@ -113,6 +113,7 @@ typedef struct frontend_ctx_driver
|
||||
bool (*is_narrator_running)(void);
|
||||
bool (*accessibility_speak)(int speed,
|
||||
const char* speak_text, int priority);
|
||||
bool (*set_gamemode)(bool on);
|
||||
|
||||
const char *ident;
|
||||
|
||||
@ -231,6 +232,8 @@ const char* frontend_driver_get_cpu_model_name(void);
|
||||
|
||||
enum retro_language frontend_driver_get_user_language(void);
|
||||
|
||||
bool frontend_driver_set_gamemode(bool on);
|
||||
|
||||
frontend_state_t *frontend_state_get_ptr(void);
|
||||
|
||||
RETRO_END_DECLS
|
||||
|
@ -5144,3 +5144,7 @@ MSG_HASH(
|
||||
MENU_ENUM_LABEL_MIXER_ACTION_VOLUME,
|
||||
"mixer_action_volume"
|
||||
)
|
||||
MSG_HASH(
|
||||
MENU_ENUM_LABEL_GAMEMODE_ENABLE,
|
||||
"game_mode_enable"
|
||||
)
|
||||
|
@ -2374,6 +2374,19 @@ int msg_hash_get_help_us_enum(enum msg_hash_enums msg, char *s, size_t len)
|
||||
snprintf(s, len,
|
||||
"Sets the master volume of the output device.");
|
||||
break;
|
||||
#ifdef __linux__
|
||||
case MENU_ENUM_LABEL_GAMEMODE_ENABLE:
|
||||
snprintf(s, len,
|
||||
"Enabling Linux GameMode can improve latency, fix audio\n"
|
||||
"crackling issues and maximize overall performance by\n"
|
||||
"automatically configuring your CPU and GPU for best\n"
|
||||
"performance.\n"
|
||||
" \n"
|
||||
"The GameMode software needs to be installed for this to\n"
|
||||
"work. See https://github.com/FeralInteractive/gamemode for\n"
|
||||
"information on how to install GameMode.");
|
||||
break;
|
||||
#endif
|
||||
default:
|
||||
if (string_is_empty(s))
|
||||
strlcpy(s, msg_hash_to_str(MENU_ENUM_LABEL_VALUE_NO_INFORMATION_AVAILABLE), len);
|
||||
|
@ -12595,6 +12595,14 @@ MSG_HASH(
|
||||
MENU_ENUM_LABEL_VALUE_CPU_POLICY_MENU_GOVERNOR,
|
||||
"Menu Governor"
|
||||
)
|
||||
MSG_HASH(
|
||||
MENU_ENUM_LABEL_VALUE_GAMEMODE_ENABLE,
|
||||
"Game Mode"
|
||||
)
|
||||
MSG_HASH(
|
||||
MENU_ENUM_SUBLABEL_GAMEMODE_ENABLE_LINUX,
|
||||
"Can improve performance, reduce latency and fix audio crackling issues. You need https://github.com/FeralInteractive/gamemode for this to work."
|
||||
)
|
||||
MSG_HASH(
|
||||
MENU_ENUM_LABEL_VALUE_PAL60_ENABLE,
|
||||
"Use PAL60 Mode"
|
||||
|
@ -943,6 +943,12 @@ DEFAULT_SUBLABEL_MACRO(action_bind_sublabel_switch_cpu_profile, MENU
|
||||
DEFAULT_SUBLABEL_MACRO(action_bind_sublabel_switch_gpu_profile, MENU_ENUM_SUBLABEL_SWITCH_GPU_PROFILE)
|
||||
#endif
|
||||
|
||||
#ifdef __linux__
|
||||
DEFAULT_SUBLABEL_MACRO(action_bind_sublabel_gamemode_enable, MENU_ENUM_SUBLABEL_GAMEMODE_ENABLE_LINUX)
|
||||
#else
|
||||
DEFAULT_SUBLABEL_MACRO(action_bind_sublabel_gamemode_enable, MENU_ENUM_SUBLABEL_GAMEMODE_ENABLE)
|
||||
#endif
|
||||
|
||||
DEFAULT_SUBLABEL_MACRO(action_bind_sublabel_brightness_control, MENU_ENUM_SUBLABEL_BRIGHTNESS_CONTROL)
|
||||
|
||||
#if defined(_3DS)
|
||||
@ -4292,6 +4298,9 @@ int menu_cbs_init_bind_sublabel(menu_file_list_cbs_t *cbs,
|
||||
BIND_ACTION_SUBLABEL(cbs, action_bind_sublabel_switch_gpu_profile);
|
||||
break;
|
||||
#endif
|
||||
case MENU_ENUM_LABEL_GAMEMODE_ENABLE:
|
||||
BIND_ACTION_SUBLABEL(cbs, action_bind_sublabel_gamemode_enable);
|
||||
break;
|
||||
case MENU_ENUM_LABEL_BRIGHTNESS_CONTROL:
|
||||
BIND_ACTION_SUBLABEL(cbs, action_bind_sublabel_brightness_control);
|
||||
break;
|
||||
|
@ -8508,6 +8508,10 @@ unsigned menu_displaylist_build_list(
|
||||
false) == 0)
|
||||
count++;
|
||||
}
|
||||
|
||||
if (MENU_DISPLAYLIST_PARSE_SETTINGS_ENUM(list,
|
||||
MENU_ENUM_LABEL_GAMEMODE_ENABLE, PARSE_ONLY_BOOL, false) == 0)
|
||||
count++;
|
||||
}
|
||||
break;
|
||||
case DISPLAYLIST_ONSCREEN_NOTIFICATIONS_SETTINGS_LIST:
|
||||
@ -8936,6 +8940,7 @@ unsigned menu_displaylist_build_list(
|
||||
menu_displaylist_build_info_t build_list[] = {
|
||||
{MENU_ENUM_LABEL_SUSTAINED_PERFORMANCE_MODE, PARSE_ONLY_BOOL},
|
||||
{MENU_ENUM_LABEL_CPU_PERFPOWER, PARSE_ACTION},
|
||||
{MENU_ENUM_LABEL_GAMEMODE_ENABLE, PARSE_ONLY_BOOL},
|
||||
};
|
||||
|
||||
for (i = 0; i < ARRAY_SIZE(build_list); i++)
|
||||
|
@ -7594,6 +7594,9 @@ static void general_write_handler(rarch_setting_t *setting)
|
||||
task_queue_unset_threaded();
|
||||
}
|
||||
break;
|
||||
case MENU_ENUM_LABEL_GAMEMODE_ENABLE:
|
||||
frontend_driver_set_gamemode(config_get_ptr()->bools.gamemode_enable);
|
||||
break;
|
||||
case MENU_ENUM_LABEL_INPUT_POLL_TYPE_BEHAVIOR:
|
||||
core_set_poll_type(*setting->value.target.integer);
|
||||
break;
|
||||
@ -17273,6 +17276,22 @@ static bool setting_append_list(
|
||||
#endif
|
||||
#endif
|
||||
|
||||
if (frontend_get_ptr()->set_gamemode)
|
||||
CONFIG_BOOL(
|
||||
list, list_info,
|
||||
&settings->bools.gamemode_enable,
|
||||
MENU_ENUM_LABEL_GAMEMODE_ENABLE,
|
||||
MENU_ENUM_LABEL_VALUE_GAMEMODE_ENABLE,
|
||||
DEFAULT_GAMEMODE_ENABLE,
|
||||
MENU_ENUM_LABEL_VALUE_OFF,
|
||||
MENU_ENUM_LABEL_VALUE_ON,
|
||||
&group_info,
|
||||
&subgroup_info,
|
||||
parent_group,
|
||||
general_write_handler,
|
||||
general_read_handler,
|
||||
SD_FLAG_NONE);
|
||||
|
||||
END_SUB_GROUP(list, list_info, parent_group);
|
||||
END_GROUP(list, list_info, parent_group);
|
||||
break;
|
||||
|
@ -3037,6 +3037,7 @@ enum msg_hash_enums
|
||||
MENU_LABEL(MIDI_OUTPUT),
|
||||
MENU_LABEL(MIDI_VOLUME),
|
||||
|
||||
/* Power Management */
|
||||
MENU_LABEL(SUSTAINED_PERFORMANCE_MODE),
|
||||
MENU_LABEL(CPU_PERF_MODE),
|
||||
MENU_LABEL(CPU_PERFPOWER),
|
||||
@ -3048,6 +3049,8 @@ enum msg_hash_enums
|
||||
MENU_LABEL(CPU_POLICY_MENU_GOVERNOR),
|
||||
MENU_LABEL(CPU_MANAGED_MIN_FREQ),
|
||||
MENU_LABEL(CPU_MANAGED_MAX_FREQ),
|
||||
MENU_LABEL(GAMEMODE_ENABLE),
|
||||
MENU_ENUM_SUBLABEL_GAMEMODE_ENABLE_LINUX,
|
||||
|
||||
MENU_ENUM_LABEL_VALUE_CPU_PERF_MODE_MANAGED_PERF,
|
||||
MENU_ENUM_LABEL_VALUE_CPU_PERF_MODE_MANAGED_PER_CONTEXT,
|
||||
|
Loading…
Reference in New Issue
Block a user