[client] renderer: add ability to toggle the FPS display

Before, if you want to see the FPS, you need to close the client and
restart it with the -k switch to see the FPS. This is annoying.

This PR introduces a new keybind, ScrollLock+D, which, when pressed,
toggles the display of the FPS.

This is implemented for both EGL and OpenGL backends.
This commit is contained in:
Quantum
2021-01-31 22:09:03 -05:00
committed by Geoffrey McRae
parent b45f7a6733
commit 89b73512ad
10 changed files with 57 additions and 9 deletions

View File

@@ -552,3 +552,11 @@ void app_showHelp(bool show)
g_state.lgr->on_help(g_state.lgrData, help);
free(help);
}
void app_showFPS(bool showFPS)
{
if (!g_state.lgr)
return;
g_state.lgr->on_show_fps(g_state.lgrData, showFPS);
}

View File

@@ -47,6 +47,12 @@ static void bind_video(int sc, void * opaque)
core_startFrameThread();
}
static void bind_showFPS(int sc, void * opaque)
{
g_state.showFPS = !g_state.showFPS;
app_showFPS(g_state.showFPS);
}
static void bind_rotate(int sc, void * opaque)
{
if (g_params.winRotate == LG_ROTATE_MAX-1)
@@ -126,6 +132,7 @@ void keybind_register(void)
{
app_registerKeybind(KEY_F, bind_fullscreen, NULL, "Full screen toggle");
app_registerKeybind(KEY_V, bind_video , NULL, "Video stream toggle");
app_registerKeybind(KEY_D, bind_showFPS , NULL, "FPS display toggle");
app_registerKeybind(KEY_R, bind_rotate , NULL, "Rotate the output clockwise by 90° increments");
app_registerKeybind(KEY_Q, bind_quit , NULL, "Quit");

View File

@@ -104,6 +104,8 @@ static int renderThread(void * unused)
return 1;
}
g_state.lgr->on_show_fps(g_state.lgrData, g_state.showFPS);
/* signal to other threads that the renderer is ready */
lgSignalEvent(e_startup);
@@ -131,7 +133,7 @@ static int renderThread(void * unused)
if (!g_state.lgr->render(g_state.lgrData, g_params.winRotate))
break;
if (g_params.showFPS)
if (g_state.showFPS)
{
const uint64_t t = nanotime();
g_state.renderTime += t - g_state.lastFrameTime;
@@ -629,6 +631,8 @@ static int lg_run(void)
if (g_cursor.sens < -9) g_cursor.sens = -9;
else if (g_cursor.sens > 9) g_cursor.sens = 9;
g_state.showFPS = g_params.showFPS;
// search for the best displayserver ops to use
for(int i = 0; i < LG_DISPLAYSERVER_COUNT; ++i)
if (LG_DisplayServers[i]->probe())
@@ -693,7 +697,6 @@ static int lg_run(void)
// select and init a renderer
bool needsOpenGL;
LG_RendererParams lgrParams;
lgrParams.showFPS = g_params.showFPS;
lgrParams.quickSplash = g_params.quickSplash;
if (g_params.forceRenderer)

View File

@@ -47,6 +47,7 @@ struct AppState
bool stopVideo;
bool ignoreInput;
bool showFPS;
bool escapeActive;
int escapeAction;
KeybindHandle bindings[KEY_MAX];