From a412100a1106dcbd3a50b5cdbc01ca30ad6aa2bd Mon Sep 17 00:00:00 2001 From: Jorys Paulin Date: Wed, 1 May 2024 04:37:52 +0200 Subject: [PATCH] feat: added show performance overlay preference (#1209) --- app/cli/commandlineparser.cpp | 4 ++++ app/gui/SettingsView.qml | 26 ++++++++++++++++++++++++++ app/settings/streamingpreferences.cpp | 3 +++ app/settings/streamingpreferences.h | 3 +++ app/streaming/session.cpp | 3 +++ 5 files changed, 39 insertions(+) diff --git a/app/cli/commandlineparser.cpp b/app/cli/commandlineparser.cpp index 23fc65cd..eca103ba 100644 --- a/app/cli/commandlineparser.cpp +++ b/app/cli/commandlineparser.cpp @@ -371,6 +371,7 @@ void StreamCommandLineParser::parse(const QStringList &args, StreamingPreference parser.addToggleOption("reverse-scroll-direction", "inverted scroll direction"); parser.addToggleOption("swap-gamepad-buttons", "swap A/B and X/Y gamepad buttons (Nintendo-style)"); parser.addToggleOption("keep-awake", "prevent display sleep while streaming"); + parser.addToggleOption("performance-overlay", "show performance overlay"); parser.addChoiceOption("capture-system-keys", "capture system key combos", m_CaptureSysKeysModeMap.keys()); parser.addChoiceOption("video-codec", "video codec", m_VideoCodecMap.keys()); parser.addChoiceOption("video-decoder", "video decoder", m_VideoDecoderMap.keys()); @@ -485,6 +486,9 @@ void StreamCommandLineParser::parse(const QStringList &args, StreamingPreference // Resolve --keep-awake and --no-keep-awake options preferences->keepAwake = parser.getToggleOptionValue("keep-awake", preferences->keepAwake); + // Resolve --performance-overlay option + preferences->showPerformanceOverlay = parser.getToggleOptionValue("performance-overlay", preferences->showPerformanceOverlay); + // Resolve --capture-system-keys option if (parser.isSet("capture-system-keys")) { preferences->captureSysKeysMode = mapValue(m_CaptureSysKeysModeMap, parser.getChoiceOptionValue("capture-system-keys")); diff --git a/app/gui/SettingsView.qml b/app/gui/SettingsView.qml index 57c3ef22..ce0ec355 100644 --- a/app/gui/SettingsView.qml +++ b/app/gui/SettingsView.qml @@ -1632,6 +1632,32 @@ Flickable { StreamingPreferences.detectNetworkBlocking = checked } } + + CheckBox { + id: showPerformanceOverlay + width: parent.width + text: qsTr("Show performance stats while streaming") + font.pointSize: 12 + checked: StreamingPreferences.showPerformanceOverlay + onCheckedChanged: { + // This is called on init, so only do the work if we've + // actually changed the value. + if (StreamingPreferences.showPerformanceOverlay != checked) { + StreamingPreferences.showPerformanceOverlay = checked + + // We must save the updated preference to ensure + // ComputerManager can observe the change internally. + StreamingPreferences.save() + } + } + + ToolTip.delay: 1000 + ToolTip.timeout: 5000 + ToolTip.visible: hovered + ToolTip.text: qsTr("Display real-time stream performance information while streaming.") + "\n\n" + + qsTr("You can toggle it at any time while streaming using Ctrl+Alt+Shift+S or Select+L1+R1+X.") + "\n\n" + + qsTr("The performance overlay is not supported on Steam Link or Raspberry Pi.") + } } } } diff --git a/app/settings/streamingpreferences.cpp b/app/settings/streamingpreferences.cpp index a2539835..87bcb60a 100644 --- a/app/settings/streamingpreferences.cpp +++ b/app/settings/streamingpreferences.cpp @@ -38,6 +38,7 @@ #define SER_DEFAULTVER "defaultver" #define SER_PACKETSIZE "packetsize" #define SER_DETECTNETBLOCKING "detectnetblocking" +#define SER_SHOWPERFOVERLAY "showperfoverlay" #define SER_SWAPMOUSEBUTTONS "swapmousebuttons" #define SER_MUTEONFOCUSLOSS "muteonfocusloss" #define SER_BACKGROUNDGAMEPAD "backgroundgamepad" @@ -130,6 +131,7 @@ void StreamingPreferences::reload() richPresence = settings.value(SER_RICHPRESENCE, true).toBool(); gamepadMouse = settings.value(SER_GAMEPADMOUSE, true).toBool(); detectNetworkBlocking = settings.value(SER_DETECTNETBLOCKING, true).toBool(); + showPerformanceOverlay = settings.value(SER_SHOWPERFOVERLAY, false).toBool(); packetSize = settings.value(SER_PACKETSIZE, 0).toInt(); swapMouseButtons = settings.value(SER_SWAPMOUSEBUTTONS, false).toBool(); muteOnFocusLoss = settings.value(SER_MUTEONFOCUSLOSS, false).toBool(); @@ -313,6 +315,7 @@ void StreamingPreferences::save() settings.setValue(SER_GAMEPADMOUSE, gamepadMouse); settings.setValue(SER_PACKETSIZE, packetSize); settings.setValue(SER_DETECTNETBLOCKING, detectNetworkBlocking); + settings.setValue(SER_SHOWPERFOVERLAY, showPerformanceOverlay); settings.setValue(SER_AUDIOCFG, static_cast(audioConfig)); settings.setValue(SER_HDR, enableHdr); settings.setValue(SER_VIDEOCFG, static_cast(videoCodecConfig)); diff --git a/app/settings/streamingpreferences.h b/app/settings/streamingpreferences.h index 4ca778c4..6cc86ea0 100644 --- a/app/settings/streamingpreferences.h +++ b/app/settings/streamingpreferences.h @@ -119,6 +119,7 @@ public: Q_PROPERTY(bool richPresence MEMBER richPresence NOTIFY richPresenceChanged) Q_PROPERTY(bool gamepadMouse MEMBER gamepadMouse NOTIFY gamepadMouseChanged) Q_PROPERTY(bool detectNetworkBlocking MEMBER detectNetworkBlocking NOTIFY detectNetworkBlockingChanged) + Q_PROPERTY(bool showPerformanceOverlay MEMBER showPerformanceOverlay NOTIFY showPerformanceOverlayChanged) Q_PROPERTY(AudioConfig audioConfig MEMBER audioConfig NOTIFY audioConfigChanged) Q_PROPERTY(VideoCodecConfig videoCodecConfig MEMBER videoCodecConfig NOTIFY videoCodecConfigChanged) Q_PROPERTY(bool enableHdr MEMBER enableHdr NOTIFY enableHdrChanged) @@ -155,6 +156,7 @@ public: bool richPresence; bool gamepadMouse; bool detectNetworkBlocking; + bool showPerformanceOverlay; bool swapMouseButtons; bool muteOnFocusLoss; bool backgroundGamepad; @@ -195,6 +197,7 @@ signals: void richPresenceChanged(); void gamepadMouseChanged(); void detectNetworkBlockingChanged(); + void showPerformanceOverlayChanged(); void mouseButtonsChanged(); void muteOnFocusLossChanged(); void backgroundGamepadChanged(); diff --git a/app/streaming/session.cpp b/app/streaming/session.cpp index c10b97a4..4467d953 100644 --- a/app/streaming/session.cpp +++ b/app/streaming/session.cpp @@ -1821,6 +1821,9 @@ void Session::execInternal() // Start rich presence to indicate we're in game RichPresenceManager presence(*m_Preferences, m_App.name); + // Toggle the stats overlay if requested by the user + m_OverlayManager.setOverlayState(Overlay::OverlayDebug, m_Preferences->showPerformanceOverlay); + // Hijack this thread to be the SDL main thread. We have to do this // because we want to suspend all Qt processing until the stream is over. SDL_Event event;